06038ca758330e271d815bbaeccc0065a0d5b84f
[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/SVGLength.h"
28
29 namespace blink {
30
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))
36 {
37     ScriptWrappable::init(this);
38
39     addToPropertyMap(m_cx);
40     addToPropertyMap(m_cy);
41     addToPropertyMap(m_r);
42 }
43
44 DEFINE_NODE_FACTORY(SVGCircleElement)
45
46 bool SVGCircleElement::isSupportedAttribute(const QualifiedName& attrName)
47 {
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);
53     }
54     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
55 }
56
57 void SVGCircleElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
58 {
59     parseAttributeNew(name, value);
60 }
61
62 void SVGCircleElement::svgAttributeChanged(const QualifiedName& attrName)
63 {
64     if (!isSupportedAttribute(attrName)) {
65         SVGGeometryElement::svgAttributeChanged(attrName);
66         return;
67     }
68
69     SVGElement::InvalidationGuard invalidationGuard(this);
70
71     bool isLengthAttribute = attrName == SVGNames::cxAttr
72                           || attrName == SVGNames::cyAttr
73                           || attrName == SVGNames::rAttr;
74
75     if (isLengthAttribute)
76         updateRelativeLengthsInformation();
77
78     RenderSVGShape* renderer = toRenderSVGShape(this->renderer());
79     if (!renderer)
80         return;
81
82     if (isLengthAttribute) {
83         renderer->setNeedsShapeUpdate();
84         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
85         return;
86     }
87
88     ASSERT_NOT_REACHED();
89 }
90
91 bool SVGCircleElement::selfHasRelativeLengths() const
92 {
93     return m_cx->currentValue()->isRelative()
94         || m_cy->currentValue()->isRelative()
95         || m_r->currentValue()->isRelative();
96 }
97
98 RenderObject* SVGCircleElement::createRenderer(RenderStyle*)
99 {
100     return new RenderSVGEllipse(this);
101 }
102
103 }