Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGEllipseElement.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/SVGEllipseElement.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 SVGEllipseElement::SVGEllipseElement(Document& document)
33     : SVGGeometryElement(SVGNames::ellipseTag, 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_rx(SVGAnimatedLength::create(this, SVGNames::rxAttr, SVGLength::create(LengthModeWidth), ForbidNegativeLengths))
37     , m_ry(SVGAnimatedLength::create(this, SVGNames::ryAttr, SVGLength::create(LengthModeHeight), ForbidNegativeLengths))
38 {
39     ScriptWrappable::init(this);
40
41     addToPropertyMap(m_cx);
42     addToPropertyMap(m_cy);
43     addToPropertyMap(m_rx);
44     addToPropertyMap(m_ry);
45 }
46
47 PassRefPtr<SVGEllipseElement> SVGEllipseElement::create(Document& document)
48 {
49     return adoptRef(new SVGEllipseElement(document));
50 }
51
52 bool SVGEllipseElement::isSupportedAttribute(const QualifiedName& attrName)
53 {
54     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
55     if (supportedAttributes.isEmpty()) {
56         supportedAttributes.add(SVGNames::cxAttr);
57         supportedAttributes.add(SVGNames::cyAttr);
58         supportedAttributes.add(SVGNames::rxAttr);
59         supportedAttributes.add(SVGNames::ryAttr);
60     }
61     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
62 }
63
64 void SVGEllipseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
65 {
66     SVGParsingError parseError = NoError;
67
68     if (!isSupportedAttribute(name))
69         SVGGeometryElement::parseAttribute(name, value);
70     else if (name == SVGNames::cxAttr)
71         m_cx->setBaseValueAsString(value, parseError);
72     else if (name == SVGNames::cyAttr)
73         m_cy->setBaseValueAsString(value, parseError);
74     else if (name == SVGNames::rxAttr)
75         m_rx->setBaseValueAsString(value, parseError);
76     else if (name == SVGNames::ryAttr)
77         m_ry->setBaseValueAsString(value, parseError);
78     else
79         ASSERT_NOT_REACHED();
80
81     reportAttributeParsingError(parseError, name, value);
82 }
83
84 void SVGEllipseElement::svgAttributeChanged(const QualifiedName& attrName)
85 {
86     if (!isSupportedAttribute(attrName)) {
87         SVGGeometryElement::svgAttributeChanged(attrName);
88         return;
89     }
90
91     SVGElementInstance::InvalidationGuard invalidationGuard(this);
92
93     bool isLengthAttribute = attrName == SVGNames::cxAttr
94                           || attrName == SVGNames::cyAttr
95                           || attrName == SVGNames::rxAttr
96                           || attrName == SVGNames::ryAttr;
97
98     if (isLengthAttribute)
99         updateRelativeLengthsInformation();
100
101     RenderSVGShape* renderer = toRenderSVGShape(this->renderer());
102     if (!renderer)
103         return;
104
105     if (isLengthAttribute) {
106         renderer->setNeedsShapeUpdate();
107         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
108         return;
109     }
110
111     ASSERT_NOT_REACHED();
112 }
113
114 bool SVGEllipseElement::selfHasRelativeLengths() const
115 {
116     return m_cx->currentValue()->isRelative()
117         || m_cy->currentValue()->isRelative()
118         || m_rx->currentValue()->isRelative()
119         || m_ry->currentValue()->isRelative();
120 }
121
122 RenderObject* SVGEllipseElement::createRenderer(RenderStyle*)
123 {
124     return new RenderSVGEllipse(this);
125 }
126
127 }