KHtml

SVGForeignObjectElement.cpp
1 /*
2  Copyright (C) 2006 Apple Computer, Inc.
3  (C) 2008 Nikolas Zimmermann <[email protected]>
4 
5  This file is part of the WebKit 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 #if ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)
24 #include "SVGForeignObjectElement.h"
25 
26 #include "CSSPropertyNames.h"
27 #include "RenderForeignObject.h"
28 #include "SVGNames.h"
29 #include "SVGLength.h"
30 
31 #include <wtf/Assertions.h>
32 
33 namespace WebCore
34 {
35 
36 SVGForeignObjectElement::SVGForeignObjectElement(const QualifiedName &tagName, Document *doc)
37  : SVGStyledTransformableElement(tagName, doc)
38  , SVGTests()
39  , SVGLangSpace()
40  , SVGExternalResourcesRequired()
41  , m_x(this, LengthModeWidth)
42  , m_y(this, LengthModeHeight)
43  , m_width(this, LengthModeWidth)
44  , m_height(this, LengthModeHeight)
45 {
46 }
47 
48 SVGForeignObjectElement::~SVGForeignObjectElement()
49 {
50 }
51 
52 ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
53 ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
54 ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
55 ANIMATED_PROPERTY_DEFINITIONS(SVGForeignObjectElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
56 
57 void SVGForeignObjectElement::parseMappedAttribute(MappedAttribute *attr)
58 {
59  const AtomicString &value = attr->value();
60  if (attr->name() == SVGNames::xAttr) {
61  setXBaseValue(SVGLength(this, LengthModeWidth, value));
62  } else if (attr->name() == SVGNames::yAttr) {
63  setYBaseValue(SVGLength(this, LengthModeHeight, value));
64  } else if (attr->name() == SVGNames::widthAttr) {
65  setWidthBaseValue(SVGLength(this, LengthModeWidth, value));
66  } else if (attr->name() == SVGNames::heightAttr) {
67  setHeightBaseValue(SVGLength(this, LengthModeHeight, value));
68  } else {
69  if (SVGTests::parseMappedAttribute(attr)) {
70  return;
71  }
72  if (SVGLangSpace::parseMappedAttribute(attr)) {
73  return;
74  }
75  if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
76  return;
77  }
78  SVGStyledTransformableElement::parseMappedAttribute(attr);
79  }
80 }
81 
82 // TODO: Move this function in some SVG*Element base class, as SVGSVGElement / SVGImageElement will need the same logic!
83 
84 // This function mimics addCSSProperty and StyledElement::attributeChanged.
85 // In HTML code, you'd always call addCSSProperty from your derived parseMappedAttribute()
86 // function - though in SVG code we need to move this logic into svgAttributeChanged, in
87 // order to support SVG DOM changes (which don't use the parseMappedAttribute/attributeChanged).
88 // If we'd ignore SVG DOM, we could use _exactly_ the same logic as HTML.
89 static inline void addCSSPropertyAndNotifyAttributeMap(StyledElement *element, const QualifiedName &name, int cssProperty, const String &value)
90 {
91  ASSERT(element);
92 
93  if (!element) {
94  return;
95  }
96 
97  NamedMappedAttrMap *attrs = element->mappedAttributes();
98  ASSERT(attrs);
99 
100  if (!attrs) {
101  return;
102  }
103 
104  MappedAttribute *mappedAttr = attrs->getAttributeItem(name);
105  if (!mappedAttr) {
106  return;
107  }
108 
109  // This logic is only meant to be used for entries that have to be parsed and are mapped to eNone. Assert that.
110  MappedAttributeEntry entry;
111  bool needToParse = element->mapToEntry(mappedAttr->name(), entry);
112 
113  ASSERT(needToParse);
114  ASSERT(entry == eNone);
115 
116  if (!needToParse || entry != eNone) {
117  return;
118  }
119 
120  if (mappedAttr->decl()) {
121  mappedAttr->setDecl(0);
122  attrs->declRemoved();
123  }
124 
125  element->setChanged();
126  element->addCSSProperty(mappedAttr, cssProperty, value);
127 
128  if (CSSMappedAttributeDeclaration *decl = mappedAttr->decl()) {
129  // Add the decl to the table in the appropriate spot.
130  element->setMappedAttributeDecl(entry, mappedAttr, decl);
131 
132  decl->setMappedState(entry, mappedAttr->name(), mappedAttr->value());
133  decl->setParent(0);
134  decl->setNode(0);
135 
136  attrs->declAdded();
137  }
138 }
139 
140 void SVGForeignObjectElement::svgAttributeChanged(const QualifiedName &attrName)
141 {
142  SVGStyledTransformableElement::svgAttributeChanged(attrName);
143 
144  if (attrName == SVGNames::widthAttr) {
145  addCSSPropertyAndNotifyAttributeMap(this, attrName, CSSPropertyWidth, width().valueAsString());
146  return;
147  } else if (attrName == SVGNames::heightAttr) {
148  addCSSPropertyAndNotifyAttributeMap(this, attrName, CSSPropertyHeight, height().valueAsString());
149  return;
150  }
151 
152  if (!renderer()) {
153  return;
154  }
155 
156  if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
157  SVGTests::isKnownAttribute(attrName) ||
158  SVGLangSpace::isKnownAttribute(attrName) ||
159  SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
160  SVGStyledTransformableElement::isKnownAttribute(attrName)) {
161  renderer()->setNeedsLayout(true);
162  }
163 }
164 
165 RenderObject *SVGForeignObjectElement::createRenderer(RenderArena *arena, RenderStyle *style)
166 {
167  return new(arena) RenderForeignObject(this);
168 }
169 
170 bool SVGForeignObjectElement::childShouldCreateRenderer(Node *child) const
171 {
172  // Skip over SVG rules which disallow non-SVG kids
173  return StyledElement::childShouldCreateRenderer(child);
174 }
175 
176 } // namespace WebCore
177 
178 #endif // ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.