• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • svg
SVGElement.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3  2004, 2005, 2006, 2008 Rob Buis <buis@kde.org>
4 
5  This file is part of the KDE project
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "config.h"
24 #include "wtf/Platform.h"
25 
26 #if ENABLE(SVG)
27 #include "SVGElement.h"
28 
29 /*#include "DOMImplementation.h"*/
30 #include "Document.h"
31 /*#include "Event.h"
32 #include "EventListener.h"
33 #include "EventNames.h"
34 #include "FrameView.h"
35 #include "HTMLNames.h"
36 #include "PlatformString.h"
37 #include "RenderObject.h"
38 #include "SVGDocumentExtensions.h"
39 #include "SVGElementInstance.h"*/
40 #include "SVGNames.h"
41 #include "SVGSVGElement.h"
42 /*#include "SVGURIReference.h"
43 #include "SVGUseElement.h"
44 #include "RegisteredEventListener.h"*/
45 
46 namespace WebCore {
47 
48 using namespace DOM;
49 
50 //using namespace HTMLNames;
51 //using namespace EventNames;
52 
53 SVGElement::SVGElement(const QualifiedName& tagName, Document* doc)
54  : StyledElement(doc) // it's wrong, remove it!!! FIXME: vtokarev
55 // : StyledElement(tagName, doc)
56 // , m_shadowParent(0)
57 {
58  m_prefix = tagName.prefixId();
59 }
60 
61 SVGElement::~SVGElement()
62 {
63 }
64 
65 bool SVGElement::isSupported(StringImpl* feature, StringImpl* version) const
66 {
67  return DOMImplementation::hasFeature(feature, version);
68 }
69 
70 
71 String SVGElement::attrid() const
72 {
73  return getAttribute(idAttr);
74 }
75 
76 
77 void SVGElement::setId(const String& value, ExceptionCode&)
78 {
79  setAttribute(idAttr, value);
80 }
81 
82 
83 String SVGElement::xmlbase() const
84 {
85  return getAttribute(ATTR_XML_BASE);
86 }
87 
88 void SVGElement::setXmlbase(const String& value, ExceptionCode&)
89 {
90  setAttribute(ATTR_XML_BASE, value);
91 }
92 
93 SVGSVGElement* SVGElement::ownerSVGElement() const
94 {
95  Node* n = isShadowNode() ? const_cast<SVGElement*>(this)->shadowParentNode() : parentNode();
96  while (n) {
97  if (/*n->hasTagName(SVGNames::svgTag)*/n->id() == SVGNames::svgTag.id())
98  return static_cast<SVGSVGElement*>(n);
99 
100  n = n->isShadowNode() ? n->shadowParentNode() : n->parentNode();
101  }
102 
103  return 0;
104 }
105 
106 SVGElement* SVGElement::viewportElement() const
107 {
108  // This function needs shadow tree support - as RenderSVGContainer uses this function
109  // to determine the "overflow" property. <use> on <symbol> wouldn't work otherwhise.
110  /*Node* n = isShadowNode() ? const_cast<SVGElement*>(this)->shadowParentNode() : parentNode();
111  while (n) {
112  if (n->hasTagName(SVGNames::svgTag) || n->hasTagName(SVGNames::imageTag) || n->hasTagName(SVGNames::symbolTag))
113  return static_cast<SVGElement*>(n);
114 
115  n = n->isShadowNode() ? n->shadowParentNode() : n->parentNode();
116  }*/
117 
118  return 0;
119 }
120 
121 void SVGElement::addSVGEventListener(/*const AtomicString& eventType*/const EventImpl::EventId& eventType, const Attribute* attr)
122 {
123  kDebug() << "add listener for: " << EventName::fromId(eventType).toString() << endl;
124  Element::setHTMLEventListener(EventName::fromId(eventType), document()->accessSVGExtensions()->
125  createSVGEventListener(attr->localName().string(), attr->value(), this));
126 }
127 
128 void SVGElement::parseMappedAttribute(MappedAttribute* attr)
129 {
130  // standard events
131  if (/*attr->name() == onloadAttr*/attr->id() == ATTR_ONLOAD)
132  addSVGEventListener(/*loadEvent*/EventImpl::LOAD_EVENT, attr);
133  else if (/*attr->name() == onclickAttr*/attr->id() == ATTR_ONCLICK)
134  addSVGEventListener(/*clickEvent*/EventImpl::CLICK_EVENT, attr);
135  else /*if (attr->name() == onmousedownAttr)
136  addSVGEventListener(mousedownEvent, attr);
137  else if (attr->name() == onmousemoveAttr)
138  addSVGEventListener(mousemoveEvent, attr);
139  else if (attr->name() == onmouseoutAttr)
140  addSVGEventListener(mouseoutEvent, attr);
141  else if (attr->name() == onmouseoverAttr)
142  addSVGEventListener(mouseoverEvent, attr);
143  else if (attr->name() == onmouseupAttr)
144  addSVGEventListener(mouseupEvent, attr);
145  else if (attr->name() == SVGNames::onfocusinAttr)
146  addSVGEventListener(DOMFocusInEvent, attr);
147  else if (attr->name() == SVGNames::onfocusoutAttr)
148  addSVGEventListener(DOMFocusOutEvent, attr);
149  else if (attr->name() == SVGNames::onactivateAttr)
150  addSVGEventListener(DOMActivateEvent, attr);
151  else*/
152  if (attr->id() == ATTR_ID) {
153  setHasID();
154  document()->incDOMTreeVersion(DocumentImpl::TV_IDNameHref);
155  } else
156  StyledElement::parseAttribute(attr);
157 }
158 
159 bool SVGElement::haveLoadedRequiredResources()
160 {
161  Node* child = firstChild();
162  while (child) {
163  if (child->isSVGElement() && !static_cast<SVGElement*>(child)->haveLoadedRequiredResources())
164  return false;
165  child = child->nextSibling();
166  }
167  return true;
168 }
169 
170 static bool hasLoadListener(SVGElement* node)
171 {
172  Node* currentNode = node;
173  while (currentNode && currentNode->isElementNode()) {
174  QList<RegisteredEventListener> *list = static_cast<Element*>(currentNode)->localEventListeners();
175  if (list) {
176  QList<RegisteredEventListener>::Iterator end = list->end();
177  for (QList<RegisteredEventListener>::Iterator it = list->begin(); it != end; ++it)
178  if ((*it).useCapture || (*it).eventName.id() == EventImpl::LOAD_EVENT/* || currentNode == node*/)
179  return true;
180  /*if ((*it)->eventType() == loadEvent &&
181  (*it)->useCapture() == true || currentNode == node)
182  return true;*/
183  }
184  currentNode = currentNode->parentNode();
185  }
186 
187  return false;
188 }
189 
190 void SVGElement::sendSVGLoadEventIfPossible(bool sendParentLoadEvents)
191 {
192  kDebug() << "send svg load event" << endl;
193  RefPtr<SVGElement> currentTarget = this;
194  kDebug() << currentTarget << currentTarget->haveLoadedRequiredResources() << endl;
195  while (currentTarget && currentTarget->haveLoadedRequiredResources()) {
196  RefPtr<Node> parent;
197  if (sendParentLoadEvents)
198  parent = currentTarget->parentNode(); // save the next parent to dispatch too incase dispatching the event changes the tree
199  kDebug() << hasLoadListener(currentTarget.get()) << endl;
200  if (hasLoadListener(currentTarget.get())) {
201  //Event* event = new Event(EventImpl::LOAD_EVENT, true/*false*/, false);
202  //event->setTarget(currentTarget.get());
203  //ExceptionCode ignored = 0;
204  //dispatchGenericEvent(/*currentTarget.get(), */event, ignored/*, false*/);
205  dispatchHTMLEvent(EventImpl::LOAD_EVENT, false, false);
206  }
207  currentTarget = (parent && parent->isSVGElement()) ? static_pointer_cast<SVGElement>(parent) : RefPtr<SVGElement>();
208  }
209 }
210 
211 void SVGElement::finishParsingChildren()
212 {
213  // finishParsingChildren() is called when the close tag is reached for an element (e.g. </svg>)
214  // we send SVGLoad events here if we can, otherwise they'll be sent when any required loads finish
215  sendSVGLoadEventIfPossible();
216 }
217 
218 bool SVGElement::childShouldCreateRenderer(Node* child) const
219 {
220  if (child->isSVGElement())
221  return static_cast<SVGElement*>(child)->isValid();
222  return false;
223 }
224 
225 void SVGElement::insertedIntoDocument()
226 {
227  StyledElement::insertedIntoDocument();
228  /*SVGDocumentExtensions* extensions = document()->accessSVGExtensions();
229 
230  String resourceId = SVGURIReference::getTarget(id());
231  if (extensions->isPendingResource(resourceId)) {
232  std::auto_ptr<HashSet<SVGStyledElement*> > clients(extensions->removePendingResource(resourceId));
233  if (clients->isEmpty())
234  return;
235 
236  HashSet<SVGStyledElement*>::const_iterator it = clients->begin();
237  const HashSet<SVGStyledElement*>::const_iterator end = clients->end();
238 
239  for (; it != end; ++it)
240  (*it)->buildPendingResource();
241 
242  SVGResource::invalidateClients(*clients);
243  }*/
244 }
245 
246 static Node* shadowTreeParentElementForShadowTreeElement(Node* node)
247 {
248  for (Node* n = node; n; n = n->parentNode()) {
249  /*if (n->isShadowNode())
250  return n->shadowParentNode();*/
251  }
252 
253  return 0;
254 }
255 
256 bool SVGElement::dispatchEvent(Event* e, ExceptionCode& ec, bool tempEvent)
257 {
258  Q_UNUSED(e);
259  Q_UNUSED(ec);
260  Q_UNUSED(tempEvent);
261  kDebug() << "dispatch event" << endl;
262  // TODO: This function will be removed in a follow-up patch!
263 
264  /*EventTarget* target = this;
265  Node* useNode = shadowTreeParentElementForShadowTreeElement(this);
266 
267  // If we are a hidden shadow tree element, the target must
268  // point to our corresponding SVGElementInstance object
269  if (useNode) {
270  ASSERT(useNode->hasTagName(SVGNames::useTag));
271  SVGUseElement* use = static_cast<SVGUseElement*>(useNode);
272 
273  SVGElementInstance* instance = use->instanceForShadowTreeElement(this);
274 
275  if (instance)
276  target = instance;
277  }
278 
279  e->setTarget(target);
280 
281  RefPtr<FrameView> view = document()->view();
282  return EventTargetNode::dispatchGenericEvent(this, e, ec, tempEvent);*/
283  ASSERT(false);
284  return false;
285 }
286 
287 void SVGElement::attributeChanged(Attribute* attr, bool preserveDecls)
288 {
289  ASSERT(attr);
290  if (!attr)
291  return;
292 
293  StyledElement::attributeChanged(attr, preserveDecls);
294  svgAttributeChanged(attr->name());
295 }
296 
297 // for KHTML compatibility
298 void SVGElement::addCSSProperty(Attribute* attr, int id, const String& value)
299 {
300  Q_UNUSED(attr);
301  kDebug() << "called with: " << id << " " << value << endl;
302  /* WARNING: copy&past'ed from HTMLElementImpl class */
303  if (!m_hasCombinedStyle) createNonCSSDecl();
304  nonCSSStyleDecls()->setProperty(id, value, false);
305  setChanged();
306 }
307 
308 void SVGElement::addCSSProperty(Attribute* attr, int id, int value)
309 {
310  Q_UNUSED(attr);
311  kDebug() << "called with: " << id << " " << value << endl;
312  /* WARNING: copy&past'ed from HTMLElementImpl class */
313  if (!m_hasCombinedStyle) createNonCSSDecl();
314  nonCSSStyleDecls()->setProperty(id, value, false);
315  setChanged();
316 }
317 
318 
319 }
320 
321 #endif // ENABLE(SVG)
DOM::Node
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:270
DOM::QualifiedName
Definition: QualifiedName.h:36
DOM::QualifiedName::id
unsigned id() const
Definition: QualifiedName.cpp:90
WebCore::SVGNames::svgTag
DOM::QualifiedName svgTag
Definition: SVGNames.cpp:91
idAttr
#define idAttr
Definition: SVGNames.h:8
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
DOM::Element
By far the vast majority of objects (apart from text) that authors encounter when traversing a docume...
Definition: dom_element.h:209
SVGSVGElement.h
DOM::Node::parentNode
Node parentNode() const
The parent of this node.
Definition: dom_node.cpp:199
DOM::Document
The Document interface represents the entire HTML or XML document.
Definition: dom_doc.h:245
SVGNames.h
SVGElement.h
DOM::Event
Introduced in DOM Level 2.
Definition: dom2_events.h:117
DOM::QualifiedName::prefixId
PrefixName prefixId() const
Definition: QualifiedName.h:58
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
end
const KShortcut & end()
DOM::Node::nextSibling
Node nextSibling() const
The node immediately following this node.
Definition: dom_node.cpp:229
QList
list
QStringList list(const QString &fileClass)
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal