Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: Source/core/svg/SVGViewSpec.cpp

Issue 153883003: [SVG] SVGAnimatedTransform{,List} migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: remove m_zoomAndPan Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/svg/SVGViewSpec.h ('k') | Source/core/svg/SVGViewSpec.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2010 Rob Buis <buis@kde.org> 2 * Copyright (C) 2007, 2010 Rob Buis <buis@kde.org>
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #include "config.h" 20 #include "config.h"
21 #include "core/svg/SVGViewSpec.h" 21 #include "core/svg/SVGViewSpec.h"
22 22
23 #include "SVGNames.h" 23 #include "SVGNames.h"
24 #include "core/dom/Document.h" 24 #include "core/dom/Document.h"
25 #include "core/svg/SVGAnimatedTransformList.h" 25 #include "core/svg/SVGAnimatedTransformList.h"
26 #include "core/svg/SVGParserUtilities.h" 26 #include "core/svg/SVGParserUtilities.h"
27 27
28 namespace WebCore { 28 namespace WebCore {
29 29
30 // Define custom non-animated property 'transform'.
31 const SVGPropertyInfo* SVGViewSpec::transformPropertyInfo()
32 {
33 static const SVGPropertyInfo* s_propertyInfo = 0;
34 if (!s_propertyInfo) {
35 s_propertyInfo = new SVGPropertyInfo(AnimatedTransformList,
36 PropertyIsReadOnly,
37 SVGNames::transformAttr,
38 transformIdentifier(),
39 0,
40 0);
41 }
42 return s_propertyInfo;
43 }
44
45 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement) 30 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement)
46 // Note: We make |viewBox| and |preserveAspectRatio|'s contextElement the ta rget element of SVGViewSpec. 31 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to an element.
32 // Note: We make tear-offs' contextElement the target element of SVGViewSpec .
47 // This contextElement will be only used for keeping this alive from the tea roff. 33 // This contextElement will be only used for keeping this alive from the tea roff.
48 // SVGSVGElement holds a strong-ref to this SVGViewSpec, so this is kept ali ve as: 34 // SVGSVGElement holds a strong-ref to this SVGViewSpec, so this is kept ali ve as:
49 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> SV GViewSpec. 35 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> SV GViewSpec.
50 : SVGFitToViewBox(contextElement, PropertyMapPolicySkip) // Note: addToPrope rtyMap is not needed, as SVGViewSpec do not correspond to an element. 36 : SVGFitToViewBox(contextElement, PropertyMapPolicySkip)
51 , m_contextElement(contextElement) 37 , m_contextElement(contextElement)
38 , m_transform(SVGAnimatedTransformList::create(contextElement, SVGNames::tra nsformAttr, SVGTransformList::create()))
52 { 39 {
53 ASSERT(m_contextElement); 40 ASSERT(m_contextElement);
54 ScriptWrappable::init(this); 41 ScriptWrappable::init(this);
55 42
56 viewBox()->setReadOnly(); 43 viewBox()->setReadOnly();
57 preserveAspectRatio()->setReadOnly(); 44 preserveAspectRatio()->setReadOnly();
58 } 45 m_transform->setReadOnly();
59 46 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to an element.
60 const AtomicString& SVGViewSpec::transformIdentifier()
61 {
62 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecTransformAttrib ute", AtomicString::ConstructFromLiteral));
63 return s_identifier;
64 } 47 }
65 48
66 String SVGViewSpec::preserveAspectRatioString() const 49 String SVGViewSpec::preserveAspectRatioString() const
67 { 50 {
68 return preserveAspectRatio()->baseValue()->valueAsString(); 51 return preserveAspectRatio()->baseValue()->valueAsString();
69 } 52 }
70 53
71 void SVGViewSpec::setTransformString(const String& transform)
72 {
73 if (!m_contextElement)
74 return;
75
76 SVGTransformList newList;
77 newList.parse(transform);
78
79 if (SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGEle ment, SVGAnimatedTransformList>(m_contextElement, transformPropertyInfo()))
80 static_cast<SVGAnimatedTransformList*>(wrapper)->detachListWrappers(newL ist.size());
81
82 m_transform = newList;
83 }
84
85 String SVGViewSpec::transformString() const 54 String SVGViewSpec::transformString() const
86 { 55 {
87 return SVGPropertyTraits<SVGTransformList>::toString(m_transform); 56 if (!m_transform)
57 return String();
58
59 return m_transform->baseValue()->valueAsString();
88 } 60 }
89 61
90 String SVGViewSpec::viewBoxString() const 62 String SVGViewSpec::viewBoxString() const
91 { 63 {
92 return viewBox()->currentValue()->valueAsString(); 64 return viewBox()->currentValue()->valueAsString();
93 } 65 }
94 66
95 SVGElement* SVGViewSpec::viewTarget() const 67 SVGElement* SVGViewSpec::viewTarget() const
96 { 68 {
97 if (!m_contextElement) 69 if (!m_contextElement)
98 return 0; 70 return 0;
99 Element* element = m_contextElement->treeScope().getElementById(AtomicString (m_viewTargetString)); 71 Element* element = m_contextElement->treeScope().getElementById(AtomicString (m_viewTargetString));
100 if (!element || !element->isSVGElement()) 72 if (!element || !element->isSVGElement())
101 return 0; 73 return 0;
102 return toSVGElement(element); 74 return toSVGElement(element);
103 } 75 }
104 76
105 SVGTransformListPropertyTearOff* SVGViewSpec::transform()
106 {
107 if (!m_contextElement)
108 return 0;
109 // Return the animVal here, as its readonly by default - which is exactly wh at we want here.
110 return static_cast<SVGTransformListPropertyTearOff*>(static_pointer_cast<SVG AnimatedTransformList>(lookupOrCreateTransformWrapper(this))->animVal());
111 }
112
113 PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreateTransformWrapper(SVGV iewSpec* ownerType)
114 {
115 ASSERT(ownerType);
116 ASSERT(ownerType->contextElement());
117 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedTra nsformList, SVGTransformList>(ownerType->contextElement(), transformPropertyInfo (), ownerType->m_transform);
118 }
119
120 void SVGViewSpec::detachContextElement() 77 void SVGViewSpec::detachContextElement()
121 { 78 {
79 m_transform = 0;
122 clearViewBox(); 80 clearViewBox();
123 clearPreserveAspectRatio(); 81 clearPreserveAspectRatio();
124 m_contextElement = 0; 82 m_contextElement = 0;
125 } 83 }
126 84
127 void SVGViewSpec::reset() 85 void SVGViewSpec::reset()
128 { 86 {
129 resetZoomAndPan(); 87 resetZoomAndPan();
130 m_transform.clear(); 88 m_transform->baseValue()->clear();
131 updateViewBox(FloatRect()); 89 updateViewBox(FloatRect());
132 ASSERT(preserveAspectRatio()); 90 ASSERT(preserveAspectRatio());
133 preserveAspectRatio()->baseValue()->setAlign(SVGPreserveAspectRatio::SVG_PRE SERVEASPECTRATIO_XMIDYMID); 91 preserveAspectRatio()->baseValue()->setAlign(SVGPreserveAspectRatio::SVG_PRE SERVEASPECTRATIO_XMIDYMID);
134 preserveAspectRatio()->baseValue()->setMeetOrSlice(SVGPreserveAspectRatio::S VG_MEETORSLICE_MEET); 92 preserveAspectRatio()->baseValue()->setMeetOrSlice(SVGPreserveAspectRatio::S VG_MEETORSLICE_MEET);
135 m_viewTargetString = emptyString(); 93 m_viewTargetString = emptyString();
136 } 94 }
137 95
138 static const LChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'}; 96 static const LChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'};
139 static const LChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'}; 97 static const LChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'};
140 static const LChar preserveAspectRatioSpec[] = {'p', 'r', 'e', 's', 'e', 'r', 'v ', 'e', 'A', 's', 'p', 'e', 'c', 't', 'R', 'a', 't', 'i', 'o'}; 98 static const LChar preserveAspectRatioSpec[] = {'p', 'r', 'e', 's', 'e', 'r', 'v ', 'e', 'A', 's', 'p', 'e', 'c', 't', 'R', 'a', 't', 'i', 'o'};
(...skipping 28 matching lines...) Expand all
169 return false; 127 return false;
170 ptr++; 128 ptr++;
171 } else if (skipString(ptr, end, viewTargetSpec, WTF_ARRAY_LENGTH(vie wTargetSpec))) { 129 } else if (skipString(ptr, end, viewTargetSpec, WTF_ARRAY_LENGTH(vie wTargetSpec))) {
172 if (ptr >= end || *ptr != '(') 130 if (ptr >= end || *ptr != '(')
173 return false; 131 return false;
174 const CharType* viewTargetStart = ++ptr; 132 const CharType* viewTargetStart = ++ptr;
175 while (ptr < end && *ptr != ')') 133 while (ptr < end && *ptr != ')')
176 ptr++; 134 ptr++;
177 if (ptr >= end) 135 if (ptr >= end)
178 return false; 136 return false;
179 setViewTargetString(String(viewTargetStart, ptr - viewTargetStar t)); 137 m_viewTargetString = String(viewTargetStart, ptr - viewTargetSta rt);
180 ptr++; 138 ptr++;
181 } else 139 } else
182 return false; 140 return false;
183 } else if (*ptr == 'z') { 141 } else if (*ptr == 'z') {
184 if (!skipString(ptr, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPa nSpec))) 142 if (!skipString(ptr, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPa nSpec)))
185 return false; 143 return false;
186 if (ptr >= end || *ptr != '(') 144 if (ptr >= end || *ptr != '(')
187 return false; 145 return false;
188 ptr++; 146 ptr++;
189 if (!parseZoomAndPan(ptr, end)) 147 if (!parseZoomAndPan(ptr, end))
(...skipping 11 matching lines...) Expand all
201 return false; 159 return false;
202 if (ptr >= end || *ptr != ')') 160 if (ptr >= end || *ptr != ')')
203 return false; 161 return false;
204 ptr++; 162 ptr++;
205 } else if (*ptr == 't') { 163 } else if (*ptr == 't') {
206 if (!skipString(ptr, end, transformSpec, WTF_ARRAY_LENGTH(transformS pec))) 164 if (!skipString(ptr, end, transformSpec, WTF_ARRAY_LENGTH(transformS pec)))
207 return false; 165 return false;
208 if (ptr >= end || *ptr != '(') 166 if (ptr >= end || *ptr != '(')
209 return false; 167 return false;
210 ptr++; 168 ptr++;
211 parseTransformAttribute(m_transform, ptr, end, DoNotClearList); 169 m_transform->baseValue()->parse(ptr, end);
212 if (ptr >= end || *ptr != ')') 170 if (ptr >= end || *ptr != ')')
213 return false; 171 return false;
214 ptr++; 172 ptr++;
215 } else 173 } else
216 return false; 174 return false;
217 175
218 if (ptr < end && *ptr == ';') 176 if (ptr < end && *ptr == ';')
219 ptr++; 177 ptr++;
220 } 178 }
221 179
(...skipping 11 matching lines...) Expand all
233 const LChar* ptr = spec.characters8(); 191 const LChar* ptr = spec.characters8();
234 const LChar* end = ptr + spec.length(); 192 const LChar* end = ptr + spec.length();
235 return parseViewSpecInternal(ptr, end); 193 return parseViewSpecInternal(ptr, end);
236 } 194 }
237 const UChar* ptr = spec.characters16(); 195 const UChar* ptr = spec.characters16();
238 const UChar* end = ptr + spec.length(); 196 const UChar* end = ptr + spec.length();
239 return parseViewSpecInternal(ptr, end); 197 return parseViewSpecInternal(ptr, end);
240 } 198 }
241 199
242 } 200 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGViewSpec.h ('k') | Source/core/svg/SVGViewSpec.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698