OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> | |
3 * Copyright (C) 2004, 2005, 2006, 2008 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 #ifndef SVGPathSeg_h | |
22 #define SVGPathSeg_h | |
23 | |
24 #include "bindings/core/v8/ScriptWrappable.h" | |
25 #include "platform/geometry/FloatPoint.h" | |
26 #include "platform/heap/Handle.h" | |
27 #include "wtf/Allocator.h" | |
28 #include "wtf/RefCounted.h" | |
29 #include "wtf/text/WTFString.h" | |
30 | |
31 namespace blink { | |
32 | |
33 enum ListModification { | |
34 ListModificationUnknown = 0, | |
35 ListModificationInsert = 1, | |
36 ListModificationReplace = 2, | |
37 ListModificationRemove = 3, | |
38 ListModificationAppend = 4 | |
39 }; | |
40 | |
41 enum SVGPathSegType { | |
42 PathSegUnknown = 0, | |
43 PathSegClosePath = 1, | |
44 PathSegMoveToAbs = 2, | |
45 PathSegMoveToRel = 3, | |
46 PathSegLineToAbs = 4, | |
47 PathSegLineToRel = 5, | |
48 PathSegCurveToCubicAbs = 6, | |
49 PathSegCurveToCubicRel = 7, | |
50 PathSegCurveToQuadraticAbs = 8, | |
51 PathSegCurveToQuadraticRel = 9, | |
52 PathSegArcAbs = 10, | |
53 PathSegArcRel = 11, | |
54 PathSegLineToHorizontalAbs = 12, | |
55 PathSegLineToHorizontalRel = 13, | |
56 PathSegLineToVerticalAbs = 14, | |
57 PathSegLineToVerticalRel = 15, | |
58 PathSegCurveToCubicSmoothAbs = 16, | |
59 PathSegCurveToCubicSmoothRel = 17, | |
60 PathSegCurveToQuadraticSmoothAbs = 18, | |
61 PathSegCurveToQuadraticSmoothRel = 19 | |
62 }; | |
63 | |
64 static inline SVGPathSegType toAbsolutePathSegType(const SVGPathSegType type) | |
65 { | |
66 // Clear the LSB to get the absolute command. | |
67 return type >= PathSegMoveToAbs ? static_cast<SVGPathSegType>(type & ~1u) :
type; | |
68 } | |
69 | |
70 static inline bool isAbsolutePathSegType(const SVGPathSegType type) | |
71 { | |
72 // For commands with an ordinal >= PathSegMoveToAbs, and odd number => relat
ive command. | |
73 return type < PathSegMoveToAbs || type % 2 == 0; | |
74 } | |
75 | |
76 struct PathSegmentData { | |
77 STACK_ALLOCATED(); | |
78 PathSegmentData() | |
79 : command(PathSegUnknown) | |
80 , arcSweep(false) | |
81 , arcLarge(false) | |
82 { | |
83 } | |
84 | |
85 const FloatPoint& arcRadii() const { return point1; } | |
86 float arcAngle() const { return point2.x(); } | |
87 | |
88 SVGPathSegType command; | |
89 FloatPoint targetPoint; | |
90 FloatPoint point1; | |
91 FloatPoint point2; | |
92 bool arcSweep; | |
93 bool arcLarge; | |
94 }; | |
95 | |
96 class SVGPropertyBase; | |
97 class SVGPathElement; | |
98 class SVGElement; | |
99 | |
100 class SVGPathSeg : public RefCountedWillBeGarbageCollectedFinalized<SVGPathSeg>,
public ScriptWrappable { | |
101 DEFINE_WRAPPERTYPEINFO(); | |
102 public: | |
103 // SVGPathSeg itself is used as a tear-off type. | |
104 // FIXME: A tear-off type should be introduced to distinguish animVal/baseVa
l | |
105 typedef SVGPathSeg TearOffType; | |
106 | |
107 explicit SVGPathSeg(SVGPathElement* contextElement); | |
108 | |
109 virtual ~SVGPathSeg() { } | |
110 | |
111 // Forward declare these enums in the w3c naming scheme, for IDL generation | |
112 enum { | |
113 PATHSEG_UNKNOWN = PathSegUnknown, | |
114 PATHSEG_CLOSEPATH = PathSegClosePath, | |
115 PATHSEG_MOVETO_ABS = PathSegMoveToAbs, | |
116 PATHSEG_MOVETO_REL = PathSegMoveToRel, | |
117 PATHSEG_LINETO_ABS = PathSegLineToAbs, | |
118 PATHSEG_LINETO_REL = PathSegLineToRel, | |
119 PATHSEG_CURVETO_CUBIC_ABS = PathSegCurveToCubicAbs, | |
120 PATHSEG_CURVETO_CUBIC_REL = PathSegCurveToCubicRel, | |
121 PATHSEG_CURVETO_QUADRATIC_ABS = PathSegCurveToQuadraticAbs, | |
122 PATHSEG_CURVETO_QUADRATIC_REL = PathSegCurveToQuadraticRel, | |
123 PATHSEG_ARC_ABS = PathSegArcAbs, | |
124 PATHSEG_ARC_REL = PathSegArcRel, | |
125 PATHSEG_LINETO_HORIZONTAL_ABS = PathSegLineToHorizontalAbs, | |
126 PATHSEG_LINETO_HORIZONTAL_REL = PathSegLineToHorizontalRel, | |
127 PATHSEG_LINETO_VERTICAL_ABS = PathSegLineToVerticalAbs, | |
128 PATHSEG_LINETO_VERTICAL_REL = PathSegLineToVerticalRel, | |
129 PATHSEG_CURVETO_CUBIC_SMOOTH_ABS = PathSegCurveToCubicSmoothAbs, | |
130 PATHSEG_CURVETO_CUBIC_SMOOTH_REL = PathSegCurveToCubicSmoothRel, | |
131 PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS = PathSegCurveToQuadraticSmoothAbs, | |
132 PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL = PathSegCurveToQuadraticSmoothRel | |
133 }; | |
134 | |
135 virtual unsigned short pathSegType() const = 0; | |
136 virtual String pathSegTypeAsLetter() const = 0; | |
137 | |
138 SVGPropertyBase* ownerList() const | |
139 { | |
140 return m_ownerList; | |
141 } | |
142 | |
143 void setOwnerList(SVGPropertyBase* ownerList) | |
144 { | |
145 // Previous owner list must be cleared before setting new owner list. | |
146 ASSERT((!ownerList && m_ownerList) || (ownerList && !m_ownerList)); | |
147 | |
148 m_ownerList = ownerList; | |
149 } | |
150 | |
151 void setContextElement(SVGElement* contextElement) | |
152 { | |
153 m_contextElement = contextElement; | |
154 } | |
155 | |
156 static PassRefPtrWillBeRawPtr<SVGPathSeg> create() { ASSERT_NOT_REACHED(); r
eturn nullptr; } | |
157 virtual PassRefPtrWillBeRawPtr<SVGPathSeg> clone() = 0; | |
158 | |
159 DECLARE_VIRTUAL_TRACE(); | |
160 | |
161 protected: | |
162 void commitChange(); | |
163 | |
164 private: | |
165 RawPtrWillBeMember<SVGPropertyBase> m_ownerList; | |
166 GC_PLUGIN_IGNORE("528275") | |
167 SVGElement* m_contextElement; | |
168 }; | |
169 | |
170 class SVGPathSegSingleCoordinate : public SVGPathSeg { | |
171 public: | |
172 float x() const { return m_x; } | |
173 void setX(float x) | |
174 { | |
175 m_x = x; | |
176 commitChange(); | |
177 } | |
178 | |
179 float y() const { return m_y; } | |
180 void setY(float y) | |
181 { | |
182 m_y = y; | |
183 commitChange(); | |
184 } | |
185 | |
186 protected: | |
187 SVGPathSegSingleCoordinate(SVGPathElement* element, float x, float y) | |
188 : SVGPathSeg(element) | |
189 , m_x(x) | |
190 , m_y(y) | |
191 { | |
192 } | |
193 | |
194 private: | |
195 float m_x; | |
196 float m_y; | |
197 }; | |
198 | |
199 } // namespace blink | |
200 | |
201 #endif // SVGPathSeg_h | |
OLD | NEW |