Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGCircleElement.cpp
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include "config.h"
22
23 #include "core/svg/SVGCircleElement.h"
24
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"
29
30 namespace WebCore {
31
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))
37 {
38     ScriptWrappable::init(this);
39
40     addToPropertyMap(m_cx);
41     addToPropertyMap(m_cy);
42     addToPropertyMap(m_r);
43 }
44
45 PassRefPtr<SVGCircleElement> SVGCircleElement::create(Document& document)
46 {
47     return adoptRef(new SVGCircleElement(document));
48 }
49
50 bool SVGCircleElement::isSupportedAttribute(const QualifiedName& attrName)
51 {
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);
57     }
58     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
59 }
60
61 void SVGCircleElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
62 {
63     SVGParsingError parseError = NoError;
64
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);
73     else
74         ASSERT_NOT_REACHED();
75
76     reportAttributeParsingError(parseError, name, value);
77 }
78
79 void SVGCircleElement::svgAttributeChanged(const QualifiedName& attrName)
80 {
81     if (!isSupportedAttribute(attrName)) {
82         SVGGeometryElement::svgAttributeChanged(attrName);
83         return;
84     }
85
86     SVGElementInstance::InvalidationGuard invalidationGuard(this);
87
88     bool isLengthAttribute = attrName == SVGNames::cxAttr
89                           || attrName == SVGNames::cyAttr
90                           || attrName == SVGNames::rAttr;
91
92     if (isLengthAttribute)
93         updateRelativeLengthsInformation();
94
95     RenderSVGShape* renderer = toRenderSVGShape(this->renderer());
96     if (!renderer)
97         return;
98
99     if (isLengthAttribute) {
100         renderer->setNeedsShapeUpdate();
101         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
102         return;
103     }
104
105     ASSERT_NOT_REACHED();
106 }
107
108 bool SVGCircleElement::selfHasRelativeLengths() const
109 {
110     return m_cx->currentValue()->isRelative()
111         || m_cy->currentValue()->isRelative()
112         || m_r->currentValue()->isRelative();
113 }
114
115 RenderObject* SVGCircleElement::createRenderer(RenderStyle*)
116 {
117     return new RenderSVGEllipse(this);
118 }
119
120 }