don't discard iframe children.
[kdelibs.git] / khtml / svg / SVGImageElement.cpp
blob894f5609dba52d77e18e8f8799b86b78729e6df6
1 /*
2 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org>
4 2006 Alexander Kellett <lypanov@kde.org>
6 This file is part of the KDE project
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
24 #include "config.h"
26 #if ENABLE(SVG)
27 #include "SVGImageElement.h"
29 #include "CSSPropertyNames.h"
30 #include "RenderSVGImage.h"
31 #include "SVGDocument.h"
32 #include "SVGLength.h"
33 #include "SVGNames.h"
34 #include "SVGPreserveAspectRatio.h"
35 #include "SVGSVGElement.h"
36 #include "XLinkNames.h"
38 namespace WebCore {
40 SVGImageElement::SVGImageElement(const QualifiedName& tagName, Document* doc)
41 : SVGStyledTransformableElement(tagName, doc)
42 , SVGTests()
43 , SVGLangSpace()
44 , SVGExternalResourcesRequired()
45 , SVGURIReference()
46 , m_x(this, LengthModeWidth)
47 , m_y(this, LengthModeHeight)
48 , m_width(this, LengthModeWidth)
49 , m_height(this, LengthModeHeight)
50 , m_preserveAspectRatio(SVGPreserveAspectRatio::create())
51 , m_imageLoader(this)
55 SVGImageElement::~SVGImageElement()
59 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
60 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
61 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
62 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
63 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGPreserveAspectRatio*, PreserveAspectRatio, preserveAspectRatio, PreserveAspectRatio, preserveAspectRatio, SVGNames::preserveAspectRatioAttr, m_preserveAspectRatio.get())
65 void SVGImageElement::parseMappedAttribute(MappedAttribute *attr)
67 if (attr->name() == SVGNames::xAttr)
68 setXBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
69 else if (attr->name() == SVGNames::yAttr)
70 setYBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
71 else if (attr->name() == SVGNames::preserveAspectRatioAttr) {
72 const UChar* c = attr->value().characters();
73 const UChar* end = c + attr->value().length();
74 preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
75 } else if (attr->name() == SVGNames::widthAttr) {
76 setWidthBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
77 addCSSProperty(attr, CSSPropertyWidth, attr->value());
78 if (width().value() < 0.0)
79 document()->accessSVGExtensions()->reportError("A negative value for image attribute <width> is not allowed");
80 } else if (attr->name() == SVGNames::heightAttr) {
81 setHeightBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
82 addCSSProperty(attr, CSSPropertyHeight, attr->value());
83 if (height().value() < 0.0)
84 document()->accessSVGExtensions()->reportError("A negative value for image attribute <height> is not allowed");
85 } else {
86 if (SVGTests::parseMappedAttribute(attr))
87 return;
88 if (SVGLangSpace::parseMappedAttribute(attr))
89 return;
90 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
91 return;
92 if (SVGURIReference::parseMappedAttribute(attr))
93 return;
94 SVGStyledTransformableElement::parseMappedAttribute(attr);
98 void SVGImageElement::svgAttributeChanged(const QualifiedName& attrName)
100 SVGStyledTransformableElement::svgAttributeChanged(attrName);
102 if (!renderer())
103 return;
105 bool isURIAttribute = SVGURIReference::isKnownAttribute(attrName);
107 if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
108 attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr ||
109 SVGTests::isKnownAttribute(attrName) ||
110 SVGLangSpace::isKnownAttribute(attrName) ||
111 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
112 isURIAttribute ||
113 SVGStyledTransformableElement::isKnownAttribute(attrName)) {
114 renderer()->setNeedsLayout(true);
116 if (isURIAttribute)
117 m_imageLoader.updateFromElement();
121 bool SVGImageElement::hasRelativeValues() const
123 return (x().isRelative() || width().isRelative() ||
124 y().isRelative() || height().isRelative());
127 RenderObject* SVGImageElement::createRenderer(RenderArena* arena, RenderStyle* style)
129 return new (arena) RenderSVGImage(this);
132 bool SVGImageElement::haveLoadedRequiredResources()
134 return !externalResourcesRequiredBaseValue() || m_imageLoader.haveFiredLoadEvent();
137 void SVGImageElement::attach()
139 SVGStyledTransformableElement::attach();
140 m_imageLoader.updateFromElement();
141 if (RenderSVGImage* imageObj = static_cast<RenderSVGImage*>(renderer()))
142 imageObj->setCachedImage(m_imageLoader.image());
145 void SVGImageElement::getSubresourceAttributeStrings(Vector<String>& urls) const
147 urls.append(href());
152 #endif // ENABLE(SVG)