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 Apple Inc. All rights reserved.
5 * Copyright (C) 2018 Adobe Systems Incorporated. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#include "config.h"
24#include "SVGGeometryElement.h"
25
26#include "RenderSVGPath.h"
27#include "RenderSVGResource.h"
28#include "SVGDocumentExtensions.h"
29#include "SVGMPathElement.h"
30#include "SVGNames.h"
31#include "SVGPathUtilities.h"
32#include "SVGPoint.h"
33#include <wtf/IsoMallocInlines.h>
34#include <wtf/NeverDestroyed.h>
35
36namespace WebCore {
37
38WTF_MAKE_ISO_ALLOCATED_IMPL(SVGGeometryElement);
39
40// Animated property definitions
41DEFINE_ANIMATED_NUMBER(SVGGeometryElement, SVGNames::pathLengthAttr, PathLength, pathLength)
42
43BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGGeometryElement)
44 REGISTER_LOCAL_ANIMATED_PROPERTY(pathLength)
45 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement)
46END_REGISTER_ANIMATED_PROPERTIES
47
48SVGGeometryElement::SVGGeometryElement(const QualifiedName& tagName, Document& document)
49 : SVGGraphicsElement(tagName, document)
50{
51 registerAnimatedPropertiesForSVGGeometryElement();
52}
53
54bool SVGGeometryElement::isSupportedAttribute(const QualifiedName& attrName)
55{
56 static const auto supportedAttributes = makeNeverDestroyed([] {
57 HashSet<QualifiedName> set;
58 SVGLangSpace::addSupportedAttributes(set);
59 SVGExternalResourcesRequired::addSupportedAttributes(set);
60 set.add({ SVGNames::pathLengthAttr.get() });
61 return set;
62 }());
63 return supportedAttributes.get().contains<SVGAttributeHashTranslator>(attrName);
64}
65
66void SVGGeometryElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
67{
68 if (name == SVGNames::pathLengthAttr) {
69 setPathLengthBaseValue(value.toFloat());
70 if (pathLengthBaseValue() < 0)
71 document().accessSVGExtensions().reportError("A negative value for path attribute <pathLength> is not allowed");
72 return;
73 }
74
75 SVGGraphicsElement::parseAttribute(name, value);
76}
77
78void SVGGeometryElement::svgAttributeChanged(const QualifiedName& attrName)
79{
80 if (!isSupportedAttribute(attrName)) {
81 SVGGraphicsElement::svgAttributeChanged(attrName);
82 return;
83 }
84
85 InstanceInvalidationGuard guard(*this);
86
87 ASSERT_NOT_REACHED();
88}
89
90RenderPtr<RenderElement> SVGGeometryElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
91{
92 return createRenderer<RenderSVGPath>(*this, WTFMove(style));
93}
94
95}