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.
23 #include "core/svg/SVGEllipseElement.h"
25 #include "core/rendering/svg/RenderSVGEllipse.h"
26 #include "core/rendering/svg/RenderSVGResource.h"
27 #include "core/svg/SVGElementInstance.h"
28 #include "core/svg/SVGLength.h"
32 inline SVGEllipseElement::SVGEllipseElement(Document& document)
33 : SVGGeometryElement(SVGNames::ellipseTag, document)
34 , m_cx(SVGAnimatedLength::create(this, SVGNames::cxAttr, SVGLength::create(LengthModeWidth), AllowNegativeLengths))
35 , m_cy(SVGAnimatedLength::create(this, SVGNames::cyAttr, SVGLength::create(LengthModeHeight), AllowNegativeLengths))
36 , m_rx(SVGAnimatedLength::create(this, SVGNames::rxAttr, SVGLength::create(LengthModeWidth), ForbidNegativeLengths))
37 , m_ry(SVGAnimatedLength::create(this, SVGNames::ryAttr, SVGLength::create(LengthModeHeight), ForbidNegativeLengths))
39 ScriptWrappable::init(this);
41 addToPropertyMap(m_cx);
42 addToPropertyMap(m_cy);
43 addToPropertyMap(m_rx);
44 addToPropertyMap(m_ry);
47 PassRefPtr<SVGEllipseElement> SVGEllipseElement::create(Document& document)
49 return adoptRef(new SVGEllipseElement(document));
52 bool SVGEllipseElement::isSupportedAttribute(const QualifiedName& attrName)
54 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
55 if (supportedAttributes.isEmpty()) {
56 supportedAttributes.add(SVGNames::cxAttr);
57 supportedAttributes.add(SVGNames::cyAttr);
58 supportedAttributes.add(SVGNames::rxAttr);
59 supportedAttributes.add(SVGNames::ryAttr);
61 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
64 void SVGEllipseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
66 SVGParsingError parseError = NoError;
68 if (!isSupportedAttribute(name))
69 SVGGeometryElement::parseAttribute(name, value);
70 else if (name == SVGNames::cxAttr)
71 m_cx->setBaseValueAsString(value, parseError);
72 else if (name == SVGNames::cyAttr)
73 m_cy->setBaseValueAsString(value, parseError);
74 else if (name == SVGNames::rxAttr)
75 m_rx->setBaseValueAsString(value, parseError);
76 else if (name == SVGNames::ryAttr)
77 m_ry->setBaseValueAsString(value, parseError);
81 reportAttributeParsingError(parseError, name, value);
84 void SVGEllipseElement::svgAttributeChanged(const QualifiedName& attrName)
86 if (!isSupportedAttribute(attrName)) {
87 SVGGeometryElement::svgAttributeChanged(attrName);
91 SVGElementInstance::InvalidationGuard invalidationGuard(this);
93 bool isLengthAttribute = attrName == SVGNames::cxAttr
94 || attrName == SVGNames::cyAttr
95 || attrName == SVGNames::rxAttr
96 || attrName == SVGNames::ryAttr;
98 if (isLengthAttribute)
99 updateRelativeLengthsInformation();
101 RenderSVGShape* renderer = toRenderSVGShape(this->renderer());
105 if (isLengthAttribute) {
106 renderer->setNeedsShapeUpdate();
107 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
111 ASSERT_NOT_REACHED();
114 bool SVGEllipseElement::selfHasRelativeLengths() const
116 return m_cx->currentValue()->isRelative()
117 || m_cy->currentValue()->isRelative()
118 || m_rx->currentValue()->isRelative()
119 || m_ry->currentValue()->isRelative();
122 RenderObject* SVGEllipseElement::createRenderer(RenderStyle*)
124 return new RenderSVGEllipse(this);