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