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

KHTML

  • 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
35namespace WebCore {
36
37SVGElementInstance::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
55SVGElementInstance::~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
64SVGElement* SVGElementInstance::correspondingElement() const
65{
66 return m_element.get();
67}
68
69SVGUseElement* SVGElementInstance::correspondingUseElement() const
70{
71 return m_useElement;
72}
73
74SVGElementInstance* SVGElementInstance::parentNode() const
75{
76 return parent();
77}
78
79PassRefPtr<SVGElementInstanceList> SVGElementInstance::childNodes()
80{
81 return SVGElementInstanceList::create(this);
82}
83
84SVGElementInstance* SVGElementInstance::previousSibling() const
85{
86 return m_previousSibling;
87}
88
89SVGElementInstance* SVGElementInstance::nextSibling() const
90{
91 return m_nextSibling;
92}
93
94SVGElementInstance* SVGElementInstance::firstChild() const
95{
96 return m_firstChild;
97}
98
99SVGElementInstance* SVGElementInstance::lastChild() const
100{
101 return m_lastChild;
102}
103
104SVGElement* SVGElementInstance::shadowTreeElement() const
105{
106 return m_shadowTreeElement;
107}
108
109void SVGElementInstance::setShadowTreeElement(SVGElement* element)
110{
111 ASSERT(element);
112 m_shadowTreeElement = element;
113}
114
115void 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
129static 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
142void 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
181SVGElementInstance* SVGElementInstance::toSVGElementInstance()
182{
183 return this;
184}
185
186EventTargetNode* SVGElementInstance::toNode()
187{
188 return m_element.get();
189}
190
191void 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
199void 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
207bool 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
SVGElementInstanceList.h
SVGElementInstance.h
SVGUseElement.h
WebCore
Definition: CSSHelper.h:7
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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