2 Copyright (C) 2006 Apple Computer, Inc.
3 (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
5 This file is part of the WebKit project
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.
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.
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.
25 #if ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)
26 #include "SVGForeignObjectElement.h"
28 #include "CSSPropertyNames.h"
29 #include "MappedAttribute.h"
30 #include "RenderForeignObject.h"
31 #include "SVGLength.h"
33 #include <wtf/Assertions.h>
37 SVGForeignObjectElement::SVGForeignObjectElement(const QualifiedName
& tagName
, Document
*doc
)
38 : SVGStyledTransformableElement(tagName
, doc
)
41 , SVGExternalResourcesRequired()
42 , m_x(this, SVGNames::xAttr
, LengthModeWidth
)
43 , m_y(this, SVGNames::yAttr
, LengthModeHeight
)
44 , m_width(this, SVGNames::widthAttr
, LengthModeWidth
)
45 , m_height(this, SVGNames::heightAttr
, LengthModeHeight
)
46 , m_href(this, XLinkNames::hrefAttr
)
47 , m_externalResourcesRequired(this, SVGNames::externalResourcesRequiredAttr
, false)
51 SVGForeignObjectElement::~SVGForeignObjectElement()
55 void SVGForeignObjectElement::parseMappedAttribute(MappedAttribute
* attr
)
57 const AtomicString
& value
= attr
->value();
58 if (attr
->name() == SVGNames::xAttr
)
59 setXBaseValue(SVGLength(LengthModeWidth
, value
));
60 else if (attr
->name() == SVGNames::yAttr
)
61 setYBaseValue(SVGLength(LengthModeHeight
, value
));
62 else if (attr
->name() == SVGNames::widthAttr
)
63 setWidthBaseValue(SVGLength(LengthModeWidth
, value
));
64 else if (attr
->name() == SVGNames::heightAttr
)
65 setHeightBaseValue(SVGLength(LengthModeHeight
, value
));
67 if (SVGTests::parseMappedAttribute(attr
))
69 if (SVGLangSpace::parseMappedAttribute(attr
))
71 if (SVGExternalResourcesRequired::parseMappedAttribute(attr
))
73 SVGStyledTransformableElement::parseMappedAttribute(attr
);
77 // TODO: Move this function in some SVG*Element base class, as SVGSVGElement / SVGImageElement will need the same logic!
79 // This function mimics addCSSProperty and StyledElement::attributeChanged.
80 // In HTML code, you'd always call addCSSProperty from your derived parseMappedAttribute()
81 // function - though in SVG code we need to move this logic into svgAttributeChanged, in
82 // order to support SVG DOM changes (which don't use the parseMappedAttribute/attributeChanged).
83 // If we'd ignore SVG DOM, we could use _exactly_ the same logic as HTML.
84 static inline void addCSSPropertyAndNotifyAttributeMap(StyledElement
* element
, const QualifiedName
& name
, int cssProperty
, const String
& value
)
91 NamedMappedAttrMap
* attrs
= element
->mappedAttributes();
97 Attribute
* attr
= attrs
->getAttributeItem(name
);
98 if (!attr
|| !attr
->isMappedAttribute())
101 MappedAttribute
* mappedAttr
= static_cast<MappedAttribute
*>(attr
);
103 // This logic is only meant to be used for entries that have to be parsed and are mapped to eNone. Assert that.
104 MappedAttributeEntry entry
;
105 bool needToParse
= element
->mapToEntry(mappedAttr
->name(), entry
);
108 ASSERT(entry
== eNone
);
110 if (!needToParse
|| entry
!= eNone
)
113 if (mappedAttr
->decl()) {
114 mappedAttr
->setDecl(0);
115 attrs
->declRemoved();
118 element
->setNeedsStyleRecalc();
119 element
->addCSSProperty(mappedAttr
, cssProperty
, value
);
121 if (CSSMappedAttributeDeclaration
* decl
= mappedAttr
->decl()) {
122 // Add the decl to the table in the appropriate spot.
123 element
->setMappedAttributeDecl(entry
, mappedAttr
, decl
);
125 decl
->setMappedState(entry
, mappedAttr
->name(), mappedAttr
->value());
133 void SVGForeignObjectElement::svgAttributeChanged(const QualifiedName
& attrName
)
135 SVGStyledTransformableElement::svgAttributeChanged(attrName
);
137 if (attrName
== SVGNames::widthAttr
) {
138 addCSSPropertyAndNotifyAttributeMap(this, attrName
, CSSPropertyWidth
, width().valueAsString());
140 } else if (attrName
== SVGNames::heightAttr
) {
141 addCSSPropertyAndNotifyAttributeMap(this, attrName
, CSSPropertyHeight
, height().valueAsString());
148 if (attrName
== SVGNames::xAttr
|| attrName
== SVGNames::yAttr
||
149 SVGTests::isKnownAttribute(attrName
) ||
150 SVGLangSpace::isKnownAttribute(attrName
) ||
151 SVGExternalResourcesRequired::isKnownAttribute(attrName
) ||
152 SVGStyledTransformableElement::isKnownAttribute(attrName
))
153 renderer()->setNeedsLayout(true);
156 RenderObject
* SVGForeignObjectElement::createRenderer(RenderArena
* arena
, RenderStyle
*)
158 return new (arena
) RenderForeignObject(this);
161 bool SVGForeignObjectElement::childShouldCreateRenderer(Node
* child
) const
163 // Skip over SVG rules which disallow non-SVG kids
164 return StyledElement::childShouldCreateRenderer(child
);
167 } // namespace WebCore
169 #endif // ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)