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.
22 #include "core/svg/SVGEllipseElement.h"
24 #include "core/rendering/svg/RenderSVGEllipse.h"
25 #include "core/svg/SVGLength.h"
29 inline SVGEllipseElement::SVGEllipseElement(Document& document)
30 : SVGGeometryElement(SVGNames::ellipseTag, document)
31 , m_cx(SVGAnimatedLength::create(this, SVGNames::cxAttr, SVGLength::create(LengthModeWidth), AllowNegativeLengths))
32 , m_cy(SVGAnimatedLength::create(this, SVGNames::cyAttr, SVGLength::create(LengthModeHeight), AllowNegativeLengths))
33 , m_rx(SVGAnimatedLength::create(this, SVGNames::rxAttr, SVGLength::create(LengthModeWidth), ForbidNegativeLengths))
34 , m_ry(SVGAnimatedLength::create(this, SVGNames::ryAttr, SVGLength::create(LengthModeHeight), ForbidNegativeLengths))
36 addToPropertyMap(m_cx);
37 addToPropertyMap(m_cy);
38 addToPropertyMap(m_rx);
39 addToPropertyMap(m_ry);
42 DEFINE_NODE_FACTORY(SVGEllipseElement)
44 bool SVGEllipseElement::isSupportedAttribute(const QualifiedName& attrName)
46 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
47 if (supportedAttributes.isEmpty()) {
48 supportedAttributes.add(SVGNames::cxAttr);
49 supportedAttributes.add(SVGNames::cyAttr);
50 supportedAttributes.add(SVGNames::rxAttr);
51 supportedAttributes.add(SVGNames::ryAttr);
53 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
56 void SVGEllipseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
58 parseAttributeNew(name, value);
61 void SVGEllipseElement::svgAttributeChanged(const QualifiedName& attrName)
63 if (!isSupportedAttribute(attrName)) {
64 SVGGeometryElement::svgAttributeChanged(attrName);
68 SVGElement::InvalidationGuard invalidationGuard(this);
70 bool isLengthAttribute = attrName == SVGNames::cxAttr
71 || attrName == SVGNames::cyAttr
72 || attrName == SVGNames::rxAttr
73 || attrName == SVGNames::ryAttr;
75 if (isLengthAttribute)
76 updateRelativeLengthsInformation();
78 RenderSVGShape* renderer = toRenderSVGShape(this->renderer());
82 if (isLengthAttribute) {
83 renderer->setNeedsShapeUpdate();
84 markForLayoutAndParentResourceInvalidation(renderer);
91 bool SVGEllipseElement::selfHasRelativeLengths() const
93 return m_cx->currentValue()->isRelative()
94 || m_cy->currentValue()->isRelative()
95 || m_rx->currentValue()->isRelative()
96 || m_ry->currentValue()->isRelative();
99 RenderObject* SVGEllipseElement::createRenderer(RenderStyle*)
101 return new RenderSVGEllipse(this);