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

KHTML

  • khtml
  • svg
SVGStyledElement.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2007 Rob Buis <buis@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "config.h"
22#include "wtf/Platform.h"
23
24#if ENABLE(SVG)
25#include "SVGStyledElement.h"
26
27/*#include "Attr.h"
28#include "CSSParser.h"
29#include "CSSStyleSelector.h"
30#include "CString.h"*/
31#include "cssstyleselector.h"
32#include "Document.h"
33/*#include "HTMLNames.h"*/
34#include "PlatformString.h"
35#include "SVGElement.h"
36/*#include "SVGElementInstance.h"*/
37#include "SVGNames.h"
38#include "RenderObject.h"
39#include "SVGRenderStyle.h"
40/*#include "SVGResource.h"*/
41#include "SVGSVGElement.h"
42#include <wtf/Assertions.h>
43
44// khtml
45#include "css_base.h"
46
47
48namespace WebCore {
49
50using namespace SVGNames;
51using namespace DOM;
52
53static HashSet<const SVGStyledElement*>* gElementsWithInstanceUpdatesBlocked = 0;
54
55SVGStyledElement::SVGStyledElement(const QualifiedName& tagName, Document* doc)
56 : SVGElement(tagName, doc)
57{
58}
59
60SVGStyledElement::~SVGStyledElement()
61{
62// SVGResource::removeClient(this);
63}
64
65ANIMATED_PROPERTY_DEFINITIONS(SVGStyledElement, String, String, string, ClassName, className, HTMLNames::classAttr, m_className)
66
67bool SVGStyledElement::rendererIsNeeded(RenderStyle* style)
68{
69 // http://www.w3.org/TR/SVG/extend.html#PrivateData
70 // Prevent anything other than SVG renderers from appearing in our render tree
71 // Spec: SVG allows inclusion of elements from foreign namespaces anywhere
72 // with the SVG content. In general, the SVG user agent will include the unknown
73 // elements in the DOM but will otherwise ignore unknown elements.
74 if (!parentNode() || parentNode()->isSVGElement())
75 return StyledElement::rendererIsNeeded(style);
76
77 return false;
78}
79
80static void mapAttributeToCSSProperty(HashMap<DOMStringImpl*, int>* propertyNameToIdMap, const QualifiedName& attrName)
81{
82 /*int propertyId = cssPropertyID(attrName.localName());*/
83 QString propName = attrName.localName().string();
84 int propertyId = DOM::getPropertyID(propName.toLatin1(), propName.length());
85 ASSERT(propertyId > 0);
86 propertyNameToIdMap->set(attrName.localName().implementation(), propertyId);
87}
88
89int SVGStyledElement::cssPropertyIdForSVGAttributeName(const QualifiedName& attrName)
90{
91 if (!attrName.namespaceURI().isEmpty()/*khtml fix, was isNull()*/)
92 return 0;
93
94 // ### I think this is better redone as a switch.
95 static HashMap<DOMStringImpl*, int>* propertyNameToIdMap = 0;
96 if (!propertyNameToIdMap) {
97 propertyNameToIdMap = new HashMap<DOMStringImpl*, int>;
98 // This is a list of all base CSS and SVG CSS properties which are exposed as SVG XML attributes
99 mapAttributeToCSSProperty(propertyNameToIdMap, alignment_baselineAttr);
100 mapAttributeToCSSProperty(propertyNameToIdMap, baseline_shiftAttr);
101 mapAttributeToCSSProperty(propertyNameToIdMap, clipAttr);
102 mapAttributeToCSSProperty(propertyNameToIdMap, clip_pathAttr);
103 mapAttributeToCSSProperty(propertyNameToIdMap, clip_ruleAttr);
104 mapAttributeToCSSProperty(propertyNameToIdMap, colorAttr);
105 mapAttributeToCSSProperty(propertyNameToIdMap, color_interpolationAttr);
106 mapAttributeToCSSProperty(propertyNameToIdMap, color_interpolation_filtersAttr);
107 mapAttributeToCSSProperty(propertyNameToIdMap, color_profileAttr);
108 mapAttributeToCSSProperty(propertyNameToIdMap, color_renderingAttr);
109 mapAttributeToCSSProperty(propertyNameToIdMap, cursorAttr);
110 mapAttributeToCSSProperty(propertyNameToIdMap, directionAttr);
111 mapAttributeToCSSProperty(propertyNameToIdMap, displayAttr);
112 mapAttributeToCSSProperty(propertyNameToIdMap, dominant_baselineAttr);
113 mapAttributeToCSSProperty(propertyNameToIdMap, enable_backgroundAttr);
114 mapAttributeToCSSProperty(propertyNameToIdMap, fillAttr);
115 mapAttributeToCSSProperty(propertyNameToIdMap, fill_opacityAttr);
116 mapAttributeToCSSProperty(propertyNameToIdMap, fill_ruleAttr);
117 mapAttributeToCSSProperty(propertyNameToIdMap, filterAttr);
118 mapAttributeToCSSProperty(propertyNameToIdMap, flood_colorAttr);
119 mapAttributeToCSSProperty(propertyNameToIdMap, flood_opacityAttr);
120 mapAttributeToCSSProperty(propertyNameToIdMap, font_familyAttr);
121 mapAttributeToCSSProperty(propertyNameToIdMap, font_sizeAttr);
122 mapAttributeToCSSProperty(propertyNameToIdMap, font_stretchAttr);
123 mapAttributeToCSSProperty(propertyNameToIdMap, font_styleAttr);
124 mapAttributeToCSSProperty(propertyNameToIdMap, font_variantAttr);
125 mapAttributeToCSSProperty(propertyNameToIdMap, font_weightAttr);
126 mapAttributeToCSSProperty(propertyNameToIdMap, glyph_orientation_horizontalAttr);
127 mapAttributeToCSSProperty(propertyNameToIdMap, glyph_orientation_verticalAttr);
128 mapAttributeToCSSProperty(propertyNameToIdMap, image_renderingAttr);
129 mapAttributeToCSSProperty(propertyNameToIdMap, kerningAttr);
130 mapAttributeToCSSProperty(propertyNameToIdMap, letter_spacingAttr);
131 mapAttributeToCSSProperty(propertyNameToIdMap, lighting_colorAttr);
132 mapAttributeToCSSProperty(propertyNameToIdMap, marker_endAttr);
133 mapAttributeToCSSProperty(propertyNameToIdMap, marker_midAttr);
134 mapAttributeToCSSProperty(propertyNameToIdMap, marker_startAttr);
135 mapAttributeToCSSProperty(propertyNameToIdMap, maskAttr);
136 mapAttributeToCSSProperty(propertyNameToIdMap, opacityAttr);
137 mapAttributeToCSSProperty(propertyNameToIdMap, overflowAttr);
138 mapAttributeToCSSProperty(propertyNameToIdMap, pointer_eventsAttr);
139 mapAttributeToCSSProperty(propertyNameToIdMap, shape_renderingAttr);
140 mapAttributeToCSSProperty(propertyNameToIdMap, stop_colorAttr);
141 mapAttributeToCSSProperty(propertyNameToIdMap, stop_opacityAttr);
142 mapAttributeToCSSProperty(propertyNameToIdMap, strokeAttr);
143 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_dasharrayAttr);
144 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_dashoffsetAttr);
145 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_linecapAttr);
146 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_linejoinAttr);
147 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_miterlimitAttr);
148 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_opacityAttr);
149 mapAttributeToCSSProperty(propertyNameToIdMap, stroke_widthAttr);
150 mapAttributeToCSSProperty(propertyNameToIdMap, text_anchorAttr);
151 mapAttributeToCSSProperty(propertyNameToIdMap, text_decorationAttr);
152 mapAttributeToCSSProperty(propertyNameToIdMap, text_renderingAttr);
153 mapAttributeToCSSProperty(propertyNameToIdMap, unicode_bidiAttr);
154 mapAttributeToCSSProperty(propertyNameToIdMap, visibilityAttr);
155 mapAttributeToCSSProperty(propertyNameToIdMap, word_spacingAttr);
156 mapAttributeToCSSProperty(propertyNameToIdMap, writing_modeAttr);
157 }
158 return propertyNameToIdMap->get(attrName.localName().implementation());
159}
160
161/*bool SVGStyledElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
162{
163 if (SVGStyledElement::cssPropertyIdForSVGAttributeName(attrName) > 0) {
164 result = eSVG;
165 return false;
166 }
167 return SVGElement::mapToEntry(attrName, result);
168}*/
169
170void SVGStyledElement::parseMappedAttribute(MappedAttribute* attr)
171{
172 // NOTE: Any subclass which overrides parseMappedAttribute for a property handled by
173 // cssPropertyIdForSVGAttributeName will also have to override mapToEntry to disable the default eSVG mapping
174 int id = attr->id();
175 if (id == ATTR_STYLE) {
176 if (inlineStyleDecls()) {
177 inlineStyleDecls()->clear();
178 } else {
179 createInlineDecl();
180 }
181 inlineStyleDecls()->setProperty(attr->value());
182 setChanged();
183 return;
184 }
185 int propId = SVGStyledElement::cssPropertyIdForSVGAttributeName(attr->name());
186 if (propId > 0) {
187 addCSSProperty(attr, propId, attr->value());
188 setChanged();
189 return;
190 }
191
192 // id and class are handled by StyledElement
193 SVGElement::parseMappedAttribute(attr);
194}
195
196bool SVGStyledElement::isKnownAttribute(const QualifiedName& attrName)
197{
198 // Recognize all style related SVG CSS properties
199 int propId = SVGStyledElement::cssPropertyIdForSVGAttributeName(attrName);
200 if (propId > 0)
201 return true;
202 return (attrName.id() == ATTR_ID || attrName.id() == ATTR_STYLE);
203 /*return (attrName == HTMLNames::idAttr || attrName == HTMLNames::styleAttr); */
204}
205
206void SVGStyledElement::svgAttributeChanged(const QualifiedName& attrName)
207{
208 SVGElement::svgAttributeChanged(attrName);
209
210 // If we're the child of a resource element, be sure to invalidate it.
211 invalidateResourcesInAncestorChain();
212
213 SVGDocumentExtensions* extensions = document()->accessSVGExtensions();
214 if (!extensions)
215 return;
216
217 // TODO: Fix bug http://bugs.webkit.org/show_bug.cgi?id=15430 (SVGElementInstances should rebuild themselves lazily)
218
219 // In case we're referenced by a <use> element, we have element instances registered
220 // to us in the SVGDocumentExtensions. If notifyAttributeChange() is called, we need
221 // to recursively update all children including ourselves.
222 updateElementInstance(extensions);
223}
224
225void SVGStyledElement::invalidateResourcesInAncestorChain() const
226{
227 Node* node = parentNode();
228 while (node) {
229 if (!node->isSVGElement())
230 break;
231
232 SVGElement* element = static_cast<SVGElement*>(node);
233 if (SVGStyledElement* styledElement = static_cast<SVGStyledElement*>(element->isStyled() ? element : 0)) {
234 /*if (SVGResource* resource = styledElement->canvasResource())
235 resource->invalidate();*/
236 }
237
238 node = node->parentNode();
239 }
240}
241
242void SVGStyledElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
243{
244 Q_UNUSED(changedByParser);
245 Q_UNUSED(beforeChange);
246 Q_UNUSED(afterChange);
247 Q_UNUSED(childCountDelta);
248 SVGElement::childrenChanged();
249 /*SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
250 if (document()->parsing())
251 return;
252
253 SVGDocumentExtensions* extensions = document()->accessSVGExtensions();
254 if (!extensions)
255 return;
256
257 // TODO: Fix bug http://bugs.webkit.org/show_bug.cgi?id=15430 (SVGElementInstances should rebuild themselves lazily)
258
259 // In case we're referenced by a <use> element, we have element instances registered
260 // to us in the SVGDocumentExtensions. If childrenChanged() is called, we need
261 // to recursively update all children including ourselves.
262 updateElementInstance(extensions);*/
263}
264
265void SVGStyledElement::updateElementInstance(SVGDocumentExtensions* extensions) const
266{
267 Q_UNUSED(extensions);
268 /*if (gElementsWithInstanceUpdatesBlocked && gElementsWithInstanceUpdatesBlocked->contains(this))
269 return;
270
271 SVGStyledElement* nonConstThis = const_cast<SVGStyledElement*>(this);
272 HashSet<SVGElementInstance*>* set = extensions->instancesForElement(nonConstThis);
273 if (!set || set->isEmpty())
274 return;
275
276 // We need to be careful here, as the instancesForElement
277 // hash set may be modified after we call updateInstance!
278 HashSet<SVGElementInstance*> localCopy;
279
280 // First create a local copy of the hashset
281 HashSet<SVGElementInstance*>::const_iterator it1 = set->begin();
282 const HashSet<SVGElementInstance*>::const_iterator end1 = set->end();
283
284 for (; it1 != end1; ++it1)
285 localCopy.add(*it1);
286
287 // Actually nofify instances to update
288 HashSet<SVGElementInstance*>::const_iterator it2 = localCopy.begin();
289 const HashSet<SVGElementInstance*>::const_iterator end2 = localCopy.end();
290
291 for (; it2 != end2; ++it2)
292 (*it2)->updateInstance(nonConstThis);*/
293}
294
295RenderStyle* SVGStyledElement::resolveStyle(RenderStyle* parentStyle)
296{
297 Q_UNUSED(parentStyle);
298 if (renderer()) {
299 RenderStyle* renderStyle = renderer()->style();
300 renderStyle->ref();
301 return renderStyle;
302 }
303
304 return document()->styleSelector()->styleForElement(this/*, parentStyle*/);
305}
306
307PassRefPtr<DOM::CSSValueImpl> SVGStyledElement::getPresentationAttribute(const String& name)
308{
309 Q_UNUSED(name);
310 /*MappedAttribute* cssSVGAttr = mappedAttributes()->getAttributeItem(name);
311 if (!cssSVGAttr || !cssSVGAttr->style())
312 return 0;
313 return cssSVGAttr->style()->getPropertyCSSValue(name);*/
314 Q_ASSERT(false);
315 return new CSSPrimitiveValueImpl(0);
316}
317
318void SVGStyledElement::detach()
319{
320 /*SVGResource::removeClient(this);*/
321 SVGElement::detach();
322}
323
324void SVGStyledElement::setInstanceUpdatesBlocked(bool blockUpdates)
325{
326 if (blockUpdates) {
327 if (!gElementsWithInstanceUpdatesBlocked)
328 gElementsWithInstanceUpdatesBlocked = new HashSet<const SVGStyledElement*>;
329 gElementsWithInstanceUpdatesBlocked->add(this);
330 } else {
331 ASSERT(gElementsWithInstanceUpdatesBlocked);
332 ASSERT(gElementsWithInstanceUpdatesBlocked->contains(this));
333 gElementsWithInstanceUpdatesBlocked->remove(this);
334 }
335}
336
337}
338
339#endif // ENABLE(SVG)
PlatformString.h
RenderObject.h
SVGElement.h
SVGNames.h
SVGSVGElement.h
SVGStyledElement.h
DOM::DOMString::implementation
DOMStringImpl * implementation() const
Definition: dom_string.h:147
DOM::DOMString::string
QString string() const
Definition: dom_string.cpp:236
DOM::DOMString::isEmpty
bool isEmpty() const
Definition: dom_string.cpp:368
DOM::Document
The Document interface represents the entire HTML or XML document.
Definition: dom_doc.h:246
DOM::Node
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:271
DOM::Node::parentNode
Node parentNode() const
The parent of this node.
Definition: dom_node.cpp:199
DOM::QualifiedName
Definition: QualifiedName.h:36
DOM::QualifiedName::namespaceURI
DOMString namespaceURI() const
Definition: QualifiedName.cpp:114
DOM::QualifiedName::id
unsigned id() const
Definition: QualifiedName.cpp:90
DOM::QualifiedName::localName
DOMString localName() const
Definition: QualifiedName.cpp:109
DOM
This library provides a full-featured HTML parser and widget.
Definition: design.h:55
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