Update To 11.40.268.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 #include "core/svg/SVGEllipseElement.h"
23
24 #include "core/rendering/svg/RenderSVGEllipse.h"
25 #include "core/svg/SVGLength.h"
26
27 namespace blink {
28
29 inline SVGEllipseElement::SVGEllipseElement(Document& document)
30     : SVGGeometryElement(SVGNames::ellipseTag, document)
31     , m_cx(SVGAnimatedLength::create(this, SVGNames::cxAttr, SVGLength::create(LengthModeWidth), AllowNegativeLengths))
32     , m_cy(SVGAnimatedLength::create(this, SVGNames::cyAttr, SVGLength::create(LengthModeHeight), AllowNegativeLengths))
33     , m_rx(SVGAnimatedLength::create(this, SVGNames::rxAttr, SVGLength::create(LengthModeWidth), ForbidNegativeLengths))
34     , m_ry(SVGAnimatedLength::create(this, SVGNames::ryAttr, SVGLength::create(LengthModeHeight), ForbidNegativeLengths))
35 {
36     addToPropertyMap(m_cx);
37     addToPropertyMap(m_cy);
38     addToPropertyMap(m_rx);
39     addToPropertyMap(m_ry);
40 }
41
42 DEFINE_NODE_FACTORY(SVGEllipseElement)
43
44 bool SVGEllipseElement::isSupportedAttribute(const QualifiedName& attrName)
45 {
46     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
47     if (supportedAttributes.isEmpty()) {
48         supportedAttributes.add(SVGNames::cxAttr);
49         supportedAttributes.add(SVGNames::cyAttr);
50         supportedAttributes.add(SVGNames::rxAttr);
51         supportedAttributes.add(SVGNames::ryAttr);
52     }
53     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
54 }
55
56 void SVGEllipseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
57 {
58     parseAttributeNew(name, value);
59 }
60
61 void SVGEllipseElement::svgAttributeChanged(const QualifiedName& attrName)
62 {
63     if (!isSupportedAttribute(attrName)) {
64         SVGGeometryElement::svgAttributeChanged(attrName);
65         return;
66     }
67
68     SVGElement::InvalidationGuard invalidationGuard(this);
69
70     bool isLengthAttribute = attrName == SVGNames::cxAttr
71                           || attrName == SVGNames::cyAttr
72                           || attrName == SVGNames::rxAttr
73                           || attrName == SVGNames::ryAttr;
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         markForLayoutAndParentResourceInvalidation(renderer);
85         return;
86     }
87
88     ASSERT_NOT_REACHED();
89 }
90
91 bool SVGEllipseElement::selfHasRelativeLengths() const
92 {
93     return m_cx->currentValue()->isRelative()
94         || m_cy->currentValue()->isRelative()
95         || m_rx->currentValue()->isRelative()
96         || m_ry->currentValue()->isRelative();
97 }
98
99 RenderObject* SVGEllipseElement::createRenderer(RenderStyle*)
100 {
101     return new RenderSVGEllipse(this);
102 }
103
104 } // namespace blink