• 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
SVGElementInstance.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 
4  This file is part of the KDE project
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "config.h"
23 #include "wtf/Platform.h"
24 
25 #if ENABLE(SVG)
26 #include "SVGElementInstance.h"
27 
28 /*#include "Event.h"
29 #include "EventListener.h"*/
30 #include "SVGElementInstanceList.h"
31 #include "SVGUseElement.h"
32 
33 #include <wtf/Assertions.h>
34 
35 namespace WebCore {
36 
37 SVGElementInstance::SVGElementInstance(SVGUseElement* useElement, PassRefPtr<SVGElement> originalElement)
38  : m_refCount(0)
39  , m_parent(0)
40  , m_useElement(useElement)
41  , m_element(originalElement)
42  , m_shadowTreeElement(0)
43  , m_previousSibling(0)
44  , m_nextSibling(0)
45  , m_firstChild(0)
46  , m_lastChild(0)
47 {
48  ASSERT(m_useElement);
49  ASSERT(m_element);
50 
51  // Register as instance for passed element.
52  m_element->document()->accessSVGExtensions()->mapInstanceToElement(this, m_element.get());
53 }
54 
55 SVGElementInstance::~SVGElementInstance()
56 {
57  for (RefPtr<SVGElementInstance> child = m_firstChild; child; child = child->m_nextSibling)
58  child->setParent(0);
59 
60  // Deregister as instance for passed element.
61  m_element->document()->accessSVGExtensions()->removeInstanceMapping(this, m_element.get());
62 }
63 
64 SVGElement* SVGElementInstance::correspondingElement() const
65 {
66  return m_element.get();
67 }
68 
69 SVGUseElement* SVGElementInstance::correspondingUseElement() const
70 {
71  return m_useElement;
72 }
73 
74 SVGElementInstance* SVGElementInstance::parentNode() const
75 {
76  return parent();
77 }
78 
79 PassRefPtr<SVGElementInstanceList> SVGElementInstance::childNodes()
80 {
81  return SVGElementInstanceList::create(this);
82 }
83 
84 SVGElementInstance* SVGElementInstance::previousSibling() const
85 {
86  return m_previousSibling;
87 }
88 
89 SVGElementInstance* SVGElementInstance::nextSibling() const
90 {
91  return m_nextSibling;
92 }
93 
94 SVGElementInstance* SVGElementInstance::firstChild() const
95 {
96  return m_firstChild;
97 }
98 
99 SVGElementInstance* SVGElementInstance::lastChild() const
100 {
101  return m_lastChild;
102 }
103 
104 SVGElement* SVGElementInstance::shadowTreeElement() const
105 {
106  return m_shadowTreeElement;
107 }
108 
109 void SVGElementInstance::setShadowTreeElement(SVGElement* element)
110 {
111  ASSERT(element);
112  m_shadowTreeElement = element;
113 }
114 
115 void SVGElementInstance::appendChild(PassRefPtr<SVGElementInstance> child)
116 {
117  child->setParent(this);
118 
119  if (m_lastChild) {
120  child->m_previousSibling = m_lastChild;
121  m_lastChild->m_nextSibling = child.get();
122  } else
123  m_firstChild = child.get();
124 
125  m_lastChild = child.get();
126 }
127 
128 // Helper function for updateInstance
129 static bool containsUseChildNode(Node* start)
130 {
131  if (start->hasTagName(SVGNames::useTag))
132  return true;
133 
134  for (Node* current = start->firstChild(); current; current = current->nextSibling()) {
135  if (containsUseChildNode(current))
136  return true;
137  }
138 
139  return false;
140 }
141 
142 void SVGElementInstance::updateInstance(SVGElement* element)
143 {
144  ASSERT(element == m_element);
145  ASSERT(m_shadowTreeElement);
146  Q_UNUSED(element);
147 
148  // TODO: Eventually come up with a more optimized updating logic for the cases below:
149  //
150  // <symbol>: We can't just clone the original element, we need to apply
151  // the same "replace by generated content" logic that SVGUseElement does.
152  //
153  // <svg>: <use> on <svg> is too rare to actually implement it faster.
154  // If someone still wants to do it: recloning, adjusting width/height attributes is enough.
155  //
156  // <use>: Too hard to get it right in a fast way. Recloning seems the only option.
157 
158  if (m_element->hasTagName(SVGNames::symbolTag) ||
159  m_element->hasTagName(SVGNames::svgTag) ||
160  containsUseChildNode(m_element.get())) {
161  m_useElement->buildPendingResource();
162  return;
163  }
164 
165  // For all other nodes this logic is sufficient.
166  WTF::PassRefPtr<Node> clone = m_element->cloneNode(true);
167  SVGUseElement::removeDisallowedElementsFromSubtree(clone.get());
168  SVGElement* svgClone = 0;
169  if (clone && clone->isSVGElement())
170  svgClone = static_cast<SVGElement*>(clone.get());
171  ASSERT(svgClone);
172 
173  // Replace node in the <use> shadow tree
174  /*ExceptionCode*//*khtml*/int ec = 0;
175  m_shadowTreeElement->parentNode()->replaceChild(clone.releaseRef(), m_shadowTreeElement, ec);
176  ASSERT(ec == 0);
177 
178  m_shadowTreeElement = svgClone;
179 }
180 
181 SVGElementInstance* SVGElementInstance::toSVGElementInstance()
182 {
183  return this;
184 }
185 
186 EventTargetNode* SVGElementInstance::toNode()
187 {
188  return m_element.get();
189 }
190 
191 void SVGElementInstance::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> eventListener, bool useCapture)
192 {
193  Q_UNUSED(eventType);
194  Q_UNUSED(eventListener);
195  Q_UNUSED(useCapture);
196  // FIXME!
197 }
198 
199 void SVGElementInstance::removeEventListener(const AtomicString& eventType, EventListener* eventListener, bool useCapture)
200 {
201  Q_UNUSED(eventType);
202  Q_UNUSED(eventListener);
203  Q_UNUSED(useCapture);
204  // FIXME!
205 }
206 
207 bool SVGElementInstance::dispatchEvent(PassRefPtr<Event>, ExceptionCode& ec, bool tempEvent)
208 {
209  Q_UNUSED(ec);
210  Q_UNUSED(tempEvent);
211  // FIXME!
212  return false;
213 }
214 
215 }
216 
217 #endif // ENABLE(SVG)
218 
219 // vim:ts=4:noet
WebCore::SVGNames::useTag
DOM::QualifiedName useTag
Definition: SVGNames.cpp:99
WebCore::SVGNames::svgTag
DOM::QualifiedName svgTag
Definition: SVGNames.cpp:91
SVGUseElement.h
SVGElementInstanceList.h
SVGElementInstance.h
WebCore::SVGNames::symbolTag
DOM::QualifiedName symbolTag
Definition: SVGNames.cpp:93
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