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/SVGElementInstance.h"
28 #include "core/svg/SVGLength.h"
32 inline SVGCircleElement::SVGCircleElement(Document& document)
33 : SVGGeometryElement(SVGNames::circleTag, 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_r(SVGAnimatedLength::create(this, SVGNames::rAttr, SVGLength::create(LengthModeOther), ForbidNegativeLengths))
38 ScriptWrappable::init(this);
40 addToPropertyMap(m_cx);
41 addToPropertyMap(m_cy);
42 addToPropertyMap(m_r);
45 PassRefPtr<SVGCircleElement> SVGCircleElement::create(Document& document)
47 return adoptRef(new SVGCircleElement(document));
50 bool SVGCircleElement::isSupportedAttribute(const QualifiedName& attrName)
52 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
53 if (supportedAttributes.isEmpty()) {
54 supportedAttributes.add(SVGNames::cxAttr);
55 supportedAttributes.add(SVGNames::cyAttr);
56 supportedAttributes.add(SVGNames::rAttr);
58 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
61 void SVGCircleElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
63 SVGParsingError parseError = NoError;
65 if (!isSupportedAttribute(name))
66 SVGGeometryElement::parseAttribute(name, value);
67 else if (name == SVGNames::cxAttr)
68 m_cx->setBaseValueAsString(value, parseError);
69 else if (name == SVGNames::cyAttr)
70 m_cy->setBaseValueAsString(value, parseError);
71 else if (name == SVGNames::rAttr)
72 m_r->setBaseValueAsString(value, parseError);
76 reportAttributeParsingError(parseError, name, value);
79 void SVGCircleElement::svgAttributeChanged(const QualifiedName& attrName)
81 if (!isSupportedAttribute(attrName)) {
82 SVGGeometryElement::svgAttributeChanged(attrName);
86 SVGElement::InvalidationGuard invalidationGuard(this);
88 bool isLengthAttribute = attrName == SVGNames::cxAttr
89 || attrName == SVGNames::cyAttr
90 || attrName == SVGNames::rAttr;
92 if (isLengthAttribute)
93 updateRelativeLengthsInformation();
95 RenderSVGShape* renderer = toRenderSVGShape(this->renderer());
99 if (isLengthAttribute) {
100 renderer->setNeedsShapeUpdate();
101 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
105 ASSERT_NOT_REACHED();
108 bool SVGCircleElement::selfHasRelativeLengths() const
110 return m_cx->currentValue()->isRelative()
111 || m_cy->currentValue()->isRelative()
112 || m_r->currentValue()->isRelative();
115 RenderObject* SVGCircleElement::createRenderer(RenderStyle*)
117 return new RenderSVGEllipse(this);