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#pragma once
23
24#include "Path.h"
25#include "SVGExternalResourcesRequired.h"
26#include "SVGGeometryElement.h"
27#include "SVGNames.h"
28#include "SVGPathByteStream.h"
29#include "SVGPathSegImpl.h"
30
31namespace WebCore {
32
33class SVGPathSegList;
34class SVGPoint;
35
36class SVGPathElement final : public SVGGeometryElement, public SVGExternalResourcesRequired {
37 WTF_MAKE_ISO_ALLOCATED(SVGPathElement);
38public:
39 static Ref<SVGPathElement> create(const QualifiedName&, Document&);
40
41 static Ref<SVGPathSegClosePath> createSVGPathSegClosePath() { return SVGPathSegClosePath::create(); }
42 static Ref<SVGPathSegMovetoAbs> createSVGPathSegMovetoAbs(float x, float y) { return SVGPathSegMovetoAbs::create(x, y); }
43 static Ref<SVGPathSegMovetoRel> createSVGPathSegMovetoRel(float x, float y) { return SVGPathSegMovetoRel::create(x, y); }
44 static Ref<SVGPathSegLinetoAbs> createSVGPathSegLinetoAbs(float x, float y) { return SVGPathSegLinetoAbs::create(x, y); }
45 static Ref<SVGPathSegLinetoRel> createSVGPathSegLinetoRel(float x, float y) { return SVGPathSegLinetoRel::create(x, y); }
46 static Ref<SVGPathSegCurvetoCubicAbs> createSVGPathSegCurvetoCubicAbs(float x, float y, float x1, float y1, float x2, float y2)
47 {
48 return SVGPathSegCurvetoCubicAbs::create(x, y, x1, y1, x2, y2);
49 }
50 static Ref<SVGPathSegCurvetoCubicRel> createSVGPathSegCurvetoCubicRel(float x, float y, float x1, float y1, float x2, float y2)
51 {
52 return SVGPathSegCurvetoCubicRel::create(x, y, x1, y1, x2, y2);
53 }
54 static Ref<SVGPathSegCurvetoQuadraticAbs> createSVGPathSegCurvetoQuadraticAbs(float x, float y, float x1, float y1)
55 {
56 return SVGPathSegCurvetoQuadraticAbs::create(x, y, x1, y1);
57 }
58 static Ref<SVGPathSegCurvetoQuadraticRel> createSVGPathSegCurvetoQuadraticRel(float x, float y, float x1, float y1)
59 {
60 return SVGPathSegCurvetoQuadraticRel::create(x, y, x1, y1);
61 }
62 static Ref<SVGPathSegArcAbs> createSVGPathSegArcAbs(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag)
63 {
64 return SVGPathSegArcAbs::create(x, y, r1, r2, angle, largeArcFlag, sweepFlag);
65 }
66 static Ref<SVGPathSegArcRel> createSVGPathSegArcRel(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag)
67 {
68 return SVGPathSegArcRel::create(x, y, r1, r2, angle, largeArcFlag, sweepFlag);
69 }
70 static Ref<SVGPathSegLinetoHorizontalAbs> createSVGPathSegLinetoHorizontalAbs(float x) { return SVGPathSegLinetoHorizontalAbs::create(x); }
71 static Ref<SVGPathSegLinetoHorizontalRel> createSVGPathSegLinetoHorizontalRel(float x) { return SVGPathSegLinetoHorizontalRel::create(x); }
72 static Ref<SVGPathSegLinetoVerticalAbs> createSVGPathSegLinetoVerticalAbs(float y) { return SVGPathSegLinetoVerticalAbs::create(y); }
73 static Ref<SVGPathSegLinetoVerticalRel> createSVGPathSegLinetoVerticalRel(float y) { return SVGPathSegLinetoVerticalRel::create(y); }
74 static Ref<SVGPathSegCurvetoCubicSmoothAbs> createSVGPathSegCurvetoCubicSmoothAbs(float x, float y, float x2, float y2)
75 {
76 return SVGPathSegCurvetoCubicSmoothAbs::create(x, y, x2, y2);
77 }
78 static Ref<SVGPathSegCurvetoCubicSmoothRel> createSVGPathSegCurvetoCubicSmoothRel(float x, float y, float x2, float y2)
79 {
80 return SVGPathSegCurvetoCubicSmoothRel::create(x, y, x2, y2);
81 }
82 static Ref<SVGPathSegCurvetoQuadraticSmoothAbs> createSVGPathSegCurvetoQuadraticSmoothAbs(float x, float y)
83 {
84 return SVGPathSegCurvetoQuadraticSmoothAbs::create(x, y);
85 }
86 static Ref<SVGPathSegCurvetoQuadraticSmoothRel> createSVGPathSegCurvetoQuadraticSmoothRel(float x, float y)
87 {
88 return SVGPathSegCurvetoQuadraticSmoothRel::create(x, y);
89 }
90
91 float getTotalLength() const final;
92 Ref<SVGPoint> getPointAtLength(float distance) const final;
93 unsigned getPathSegAtLength(float distance) const;
94
95 FloatRect getBBox(StyleUpdateStrategy = AllowStyleUpdate) final;
96
97 Ref<SVGPathSegList>& pathSegList() { return m_pathSegList->baseVal(); }
98 RefPtr<SVGPathSegList>& animatedPathSegList() { return m_pathSegList->animVal(); }
99
100 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=15412 - Implement normalized path segment lists!
101 RefPtr<SVGPathSegList> normalizedPathSegList() { return nullptr; }
102 RefPtr<SVGPathSegList> animatedNormalizedPathSegList() { return nullptr; }
103
104 const SVGPathByteStream& pathByteStream() const { return m_pathSegList->currentPathByteStream(); }
105 Path path() const { return m_pathSegList->currentPath(); }
106 size_t approximateMemoryCost() const final { return m_pathSegList->approximateMemoryCost(); }
107
108private:
109 SVGPathElement(const QualifiedName&, Document&);
110
111 using PropertyRegistry = SVGPropertyOwnerRegistry<SVGPathElement, SVGGeometryElement, SVGExternalResourcesRequired>;
112 const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; }
113
114 void parseAttribute(const QualifiedName&, const AtomicString&) final;
115 void svgAttributeChanged(const QualifiedName&) final;
116
117 bool isValid() const final { return SVGTests::isValid(); }
118 bool supportsMarkers() const final { return true; }
119
120 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
121
122 Node::InsertedIntoAncestorResult insertedIntoAncestor(InsertionType, ContainerNode&) final;
123 void removedFromAncestor(RemovalType, ContainerNode&) final;
124
125 void invalidateMPathDependencies();
126
127private:
128 PropertyRegistry m_propertyRegistry { *this };
129 Ref<SVGAnimatedPathSegList> m_pathSegList { SVGAnimatedPathSegList::create(this) };
130};
131
132} // namespace WebCore
133