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 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public License |
17 | * along with this library; see the file COPYING.LIB. If not, write to |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | * Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #include "config.h" |
23 | #include "SVGCircleElement.h" |
24 | |
25 | #include "RenderSVGEllipse.h" |
26 | #include "RenderSVGResource.h" |
27 | #include <wtf/IsoMallocInlines.h> |
28 | |
29 | namespace WebCore { |
30 | |
31 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGCircleElement); |
32 | |
33 | inline SVGCircleElement::SVGCircleElement(const QualifiedName& tagName, Document& document) |
34 | : SVGGeometryElement(tagName, document) |
35 | , SVGExternalResourcesRequired(this) |
36 | { |
37 | ASSERT(hasTagName(SVGNames::circleTag)); |
38 | |
39 | static std::once_flag onceFlag; |
40 | std::call_once(onceFlag, [] { |
41 | PropertyRegistry::registerProperty<SVGNames::cxAttr, &SVGCircleElement::m_cx>(); |
42 | PropertyRegistry::registerProperty<SVGNames::cyAttr, &SVGCircleElement::m_cy>(); |
43 | PropertyRegistry::registerProperty<SVGNames::rAttr, &SVGCircleElement::m_r>(); |
44 | }); |
45 | } |
46 | |
47 | Ref<SVGCircleElement> SVGCircleElement::create(const QualifiedName& tagName, Document& document) |
48 | { |
49 | return adoptRef(*new SVGCircleElement(tagName, document)); |
50 | } |
51 | |
52 | void SVGCircleElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
53 | { |
54 | SVGParsingError parseError = NoError; |
55 | |
56 | if (name == SVGNames::cxAttr) |
57 | m_cx->setBaseValInternal(SVGLengthValue::construct(LengthModeWidth, value, parseError)); |
58 | else if (name == SVGNames::cyAttr) |
59 | m_cy->setBaseValInternal(SVGLengthValue::construct(LengthModeHeight, value, parseError)); |
60 | else if (name == SVGNames::rAttr) |
61 | m_r->setBaseValInternal(SVGLengthValue::construct(LengthModeOther, value, parseError, ForbidNegativeLengths)); |
62 | |
63 | reportAttributeParsingError(parseError, name, value); |
64 | |
65 | SVGGeometryElement::parseAttribute(name, value); |
66 | SVGExternalResourcesRequired::parseAttribute(name, value); |
67 | } |
68 | |
69 | void SVGCircleElement::svgAttributeChanged(const QualifiedName& attrName) |
70 | { |
71 | if (PropertyRegistry::isKnownAttribute(attrName)) { |
72 | InstanceInvalidationGuard guard(*this); |
73 | invalidateSVGPresentationAttributeStyle(); |
74 | return; |
75 | } |
76 | |
77 | SVGGeometryElement::svgAttributeChanged(attrName); |
78 | SVGExternalResourcesRequired::svgAttributeChanged(attrName); |
79 | } |
80 | |
81 | RenderPtr<RenderElement> SVGCircleElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) |
82 | { |
83 | return createRenderer<RenderSVGEllipse>(*this, WTFMove(style)); |
84 | } |
85 | |
86 | } |
87 | |