2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
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.
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.
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.
24 #include "SVGEllipseElement.h"
26 #include "Attribute.h"
27 #include "FloatPoint.h"
28 #include "RenderSVGPath.h"
29 #include "RenderSVGResource.h"
30 #include "SVGElementInstance.h"
31 #include "SVGLength.h"
36 // Animated property definitions
37 DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::cxAttr, Cx, cx)
38 DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::cyAttr, Cy, cy)
39 DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::rxAttr, Rx, rx)
40 DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::ryAttr, Ry, ry)
41 DEFINE_ANIMATED_BOOLEAN(SVGEllipseElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
43 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGEllipseElement)
44 REGISTER_LOCAL_ANIMATED_PROPERTY(cx)
45 REGISTER_LOCAL_ANIMATED_PROPERTY(cy)
46 REGISTER_LOCAL_ANIMATED_PROPERTY(rx)
47 REGISTER_LOCAL_ANIMATED_PROPERTY(ry)
48 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
49 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledTransformableElement)
50 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTests)
51 END_REGISTER_ANIMATED_PROPERTIES
53 inline SVGEllipseElement::SVGEllipseElement(const QualifiedName& tagName, Document* document)
54 : SVGStyledTransformableElement(tagName, document)
55 , m_cx(LengthModeWidth)
56 , m_cy(LengthModeHeight)
57 , m_rx(LengthModeWidth)
58 , m_ry(LengthModeHeight)
60 ASSERT(hasTagName(SVGNames::ellipseTag));
61 registerAnimatedPropertiesForSVGEllipseElement();
64 PassRefPtr<SVGEllipseElement> SVGEllipseElement::create(const QualifiedName& tagName, Document* document)
66 return adoptRef(new SVGEllipseElement(tagName, document));
69 bool SVGEllipseElement::isSupportedAttribute(const QualifiedName& attrName)
71 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
72 if (supportedAttributes.isEmpty()) {
73 SVGTests::addSupportedAttributes(supportedAttributes);
74 SVGLangSpace::addSupportedAttributes(supportedAttributes);
75 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
76 supportedAttributes.add(SVGNames::cxAttr);
77 supportedAttributes.add(SVGNames::cyAttr);
78 supportedAttributes.add(SVGNames::rxAttr);
79 supportedAttributes.add(SVGNames::ryAttr);
81 return supportedAttributes.contains(attrName);
84 void SVGEllipseElement::parseMappedAttribute(Attribute* attr)
86 SVGParsingError parseError = NoError;
88 if (!isSupportedAttribute(attr->name()))
89 SVGStyledTransformableElement::parseMappedAttribute(attr);
90 else if (attr->name() == SVGNames::cxAttr)
91 setCxBaseValue(SVGLength::construct(LengthModeWidth, attr->value(), parseError));
92 else if (attr->name() == SVGNames::cyAttr)
93 setCyBaseValue(SVGLength::construct(LengthModeHeight, attr->value(), parseError));
94 else if (attr->name() == SVGNames::rxAttr)
95 setRxBaseValue(SVGLength::construct(LengthModeWidth, attr->value(), parseError, ForbidNegativeLengths));
96 else if (attr->name() == SVGNames::ryAttr)
97 setRyBaseValue(SVGLength::construct(LengthModeHeight, attr->value(), parseError, ForbidNegativeLengths));
98 else if (SVGTests::parseMappedAttribute(attr)
99 || SVGLangSpace::parseMappedAttribute(attr)
100 || SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
102 ASSERT_NOT_REACHED();
104 reportAttributeParsingError(parseError, attr);
107 void SVGEllipseElement::svgAttributeChanged(const QualifiedName& attrName)
109 if (!isSupportedAttribute(attrName)) {
110 SVGStyledTransformableElement::svgAttributeChanged(attrName);
114 SVGElementInstance::InvalidationGuard invalidationGuard(this);
116 bool isLengthAttribute = attrName == SVGNames::cxAttr
117 || attrName == SVGNames::cyAttr
118 || attrName == SVGNames::rxAttr
119 || attrName == SVGNames::ryAttr;
121 if (isLengthAttribute)
122 updateRelativeLengthsInformation();
124 if (SVGTests::handleAttributeChange(this, attrName))
127 RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer());
131 if (isLengthAttribute) {
132 renderer->setNeedsPathUpdate();
133 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
137 if (SVGLangSpace::isKnownAttribute(attrName) || SVGExternalResourcesRequired::isKnownAttribute(attrName)) {
138 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
142 ASSERT_NOT_REACHED();
145 void SVGEllipseElement::toPathData(Path& path) const
147 ASSERT(path.isEmpty());
149 float radiusX = rx().value(this);
153 float radiusY = ry().value(this);
157 path.addEllipse(FloatRect(cx().value(this) - radiusX, cy().value(this) - radiusY, radiusX * 2, radiusY * 2));
160 bool SVGEllipseElement::selfHasRelativeLengths() const
162 return cx().isRelative()
165 || ry().isRelative();
170 #endif // ENABLE(SVG)