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/SVGCircleElement.h"
25 #include "core/rendering/svg/RenderSVGEllipse.h"
26 #include "core/rendering/svg/RenderSVGResource.h"
27 #include "core/svg/SVGLength.h"
31 inline SVGCircleElement::SVGCircleElement(Document& document)
32 : SVGGeometryElement(SVGNames::circleTag, document)
33 , m_cx(SVGAnimatedLength::create(this, SVGNames::cxAttr, SVGLength::create(LengthModeWidth), AllowNegativeLengths))
34 , m_cy(SVGAnimatedLength::create(this, SVGNames::cyAttr, SVGLength::create(LengthModeHeight), AllowNegativeLengths))
35 , m_r(SVGAnimatedLength::create(this, SVGNames::rAttr, SVGLength::create(LengthModeOther), ForbidNegativeLengths))
37 ScriptWrappable::init(this);
39 addToPropertyMap(m_cx);
40 addToPropertyMap(m_cy);
41 addToPropertyMap(m_r);
44 DEFINE_NODE_FACTORY(SVGCircleElement)
46 bool SVGCircleElement::isSupportedAttribute(const QualifiedName& attrName)
48 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
49 if (supportedAttributes.isEmpty()) {
50 supportedAttributes.add(SVGNames::cxAttr);
51 supportedAttributes.add(SVGNames::cyAttr);
52 supportedAttributes.add(SVGNames::rAttr);
54 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
57 void SVGCircleElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
59 parseAttributeNew(name, value);
62 void SVGCircleElement::svgAttributeChanged(const QualifiedName& attrName)
64 if (!isSupportedAttribute(attrName)) {
65 SVGGeometryElement::svgAttributeChanged(attrName);
69 SVGElement::InvalidationGuard invalidationGuard(this);
71 bool isLengthAttribute = attrName == SVGNames::cxAttr
72 || attrName == SVGNames::cyAttr
73 || attrName == SVGNames::rAttr;
75 if (isLengthAttribute)
76 updateRelativeLengthsInformation();
78 RenderSVGShape* renderer = toRenderSVGShape(this->renderer());
82 if (isLengthAttribute) {
83 renderer->setNeedsShapeUpdate();
84 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
91 bool SVGCircleElement::selfHasRelativeLengths() const
93 return m_cx->currentValue()->isRelative()
94 || m_cy->currentValue()->isRelative()
95 || m_r->currentValue()->isRelative();
98 RenderObject* SVGCircleElement::createRenderer(RenderStyle*)
100 return new RenderSVGEllipse(this);