Add WTF::move()
[WebKit-https.git] / Source / WebCore / 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 "SVGEllipseElement.h"
23
24 #include "Attribute.h"
25 #include "FloatPoint.h"
26 #include "RenderSVGEllipse.h"
27 #include "RenderSVGPath.h"
28 #include "RenderSVGResource.h"
29 #include "SVGElementInstance.h"
30 #include "SVGLength.h"
31 #include "SVGNames.h"
32 #include <wtf/NeverDestroyed.h>
33
34 namespace WebCore {
35
36 // Animated property definitions
37 DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::cxAttr, Cx, cx)
38 DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::cyAttr, Cy, cy)
39 DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::rxAttr, Rx, rx)
40 DEFINE_ANIMATED_LENGTH(SVGEllipseElement, SVGNames::ryAttr, Ry, ry)
41 DEFINE_ANIMATED_BOOLEAN(SVGEllipseElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
42
43 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGEllipseElement)
44     REGISTER_LOCAL_ANIMATED_PROPERTY(cx)
45     REGISTER_LOCAL_ANIMATED_PROPERTY(cy)
46     REGISTER_LOCAL_ANIMATED_PROPERTY(rx)
47     REGISTER_LOCAL_ANIMATED_PROPERTY(ry)
48     REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
49     REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement)
50 END_REGISTER_ANIMATED_PROPERTIES
51
52 inline SVGEllipseElement::SVGEllipseElement(const QualifiedName& tagName, Document& document)
53     : SVGGraphicsElement(tagName, document)
54     , m_cx(LengthModeWidth)
55     , m_cy(LengthModeHeight)
56     , m_rx(LengthModeWidth)
57     , m_ry(LengthModeHeight)
58 {
59     ASSERT(hasTagName(SVGNames::ellipseTag));
60     registerAnimatedPropertiesForSVGEllipseElement();
61 }    
62
63 PassRefPtr<SVGEllipseElement> SVGEllipseElement::create(const QualifiedName& tagName, Document& document)
64 {
65     return adoptRef(new SVGEllipseElement(tagName, document));
66 }
67
68 bool SVGEllipseElement::isSupportedAttribute(const QualifiedName& attrName)
69 {
70     static NeverDestroyed<HashSet<QualifiedName>> supportedAttributes;
71     if (supportedAttributes.get().isEmpty()) {
72         SVGLangSpace::addSupportedAttributes(supportedAttributes);
73         SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
74         supportedAttributes.get().add(SVGNames::cxAttr);
75         supportedAttributes.get().add(SVGNames::cyAttr);
76         supportedAttributes.get().add(SVGNames::rxAttr);
77         supportedAttributes.get().add(SVGNames::ryAttr);
78     }
79     return supportedAttributes.get().contains<SVGAttributeHashTranslator>(attrName);
80 }
81
82 void SVGEllipseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
83 {
84     SVGParsingError parseError = NoError;
85
86     if (!isSupportedAttribute(name))
87         SVGGraphicsElement::parseAttribute(name, value);
88     else if (name == SVGNames::cxAttr)
89         setCxBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
90     else if (name == SVGNames::cyAttr)
91         setCyBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
92     else if (name == SVGNames::rxAttr)
93         setRxBaseValue(SVGLength::construct(LengthModeWidth, value, parseError, ForbidNegativeLengths));
94     else if (name == SVGNames::ryAttr)
95         setRyBaseValue(SVGLength::construct(LengthModeHeight, value, parseError, ForbidNegativeLengths));
96     else if (SVGLangSpace::parseAttribute(name, value)
97              || SVGExternalResourcesRequired::parseAttribute(name, value)) {
98     } else
99         ASSERT_NOT_REACHED();
100
101     reportAttributeParsingError(parseError, name, value);
102 }
103
104 void SVGEllipseElement::svgAttributeChanged(const QualifiedName& attrName)
105 {
106     if (!isSupportedAttribute(attrName)) {
107         SVGGraphicsElement::svgAttributeChanged(attrName);
108         return;
109     }
110
111     SVGElementInstance::InvalidationGuard invalidationGuard(this);
112
113     bool isLengthAttribute = attrName == SVGNames::cxAttr
114                           || attrName == SVGNames::cyAttr
115                           || attrName == SVGNames::rxAttr
116                           || attrName == SVGNames::ryAttr;
117
118     if (isLengthAttribute)
119         updateRelativeLengthsInformation();
120
121     RenderSVGShape* renderer = toRenderSVGShape(this->renderer());
122     if (!renderer)
123         return;
124
125     if (isLengthAttribute) {
126         renderer->setNeedsShapeUpdate();
127         RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
128         return;
129     }
130
131     if (SVGLangSpace::isKnownAttribute(attrName) || SVGExternalResourcesRequired::isKnownAttribute(attrName)) {
132         RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
133         return;
134     }
135
136     ASSERT_NOT_REACHED();
137 }
138  
139 bool SVGEllipseElement::selfHasRelativeLengths() const
140 {
141     return cx().isRelative()
142         || cy().isRelative()
143         || rx().isRelative()
144         || ry().isRelative();
145 }
146
147 RenderPtr<RenderElement> SVGEllipseElement::createElementRenderer(PassRef<RenderStyle> style)
148 {
149     return createRenderer<RenderSVGEllipse>(*this, WTF::move(style));
150 }
151
152 }