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

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

Issue 132233010: [SVG] SVGAnimatedRect migration to new SVG property impl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: comment fixes Created 6 years, 11 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
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
(...skipping 10 matching lines...) Expand all
21 #include "core/svg/SVGViewSpec.h" 21 #include "core/svg/SVGViewSpec.h"
22 22
23 #include "SVGNames.h" 23 #include "SVGNames.h"
24 #include "bindings/v8/ExceptionState.h" 24 #include "bindings/v8/ExceptionState.h"
25 #include "core/dom/Document.h" 25 #include "core/dom/Document.h"
26 #include "core/svg/SVGAnimatedTransformList.h" 26 #include "core/svg/SVGAnimatedTransformList.h"
27 #include "core/svg/SVGParserUtilities.h" 27 #include "core/svg/SVGParserUtilities.h"
28 28
29 namespace WebCore { 29 namespace WebCore {
30 30
31 // Define custom animated property 'viewBox'.
32 const SVGPropertyInfo* SVGViewSpec::viewBoxPropertyInfo()
33 {
34 static const SVGPropertyInfo* s_propertyInfo = 0;
35 if (!s_propertyInfo) {
36 s_propertyInfo = new SVGPropertyInfo(AnimatedRect,
37 PropertyIsReadOnly,
38 SVGNames::viewBoxAttr,
39 viewBoxIdentifier(),
40 0,
41 0);
42 }
43 return s_propertyInfo;
44 }
45
46 // Define custom animated property 'preserveAspectRatio'. 31 // Define custom animated property 'preserveAspectRatio'.
47 const SVGPropertyInfo* SVGViewSpec::preserveAspectRatioPropertyInfo() 32 const SVGPropertyInfo* SVGViewSpec::preserveAspectRatioPropertyInfo()
48 { 33 {
49 static const SVGPropertyInfo* s_propertyInfo = 0; 34 static const SVGPropertyInfo* s_propertyInfo = 0;
50 if (!s_propertyInfo) { 35 if (!s_propertyInfo) {
51 s_propertyInfo = new SVGPropertyInfo(AnimatedPreserveAspectRatio, 36 s_propertyInfo = new SVGPropertyInfo(AnimatedPreserveAspectRatio,
52 PropertyIsReadOnly, 37 PropertyIsReadOnly,
53 SVGNames::preserveAspectRatioAttr, 38 SVGNames::preserveAspectRatioAttr,
54 preserveAspectRatioIdentifier(), 39 preserveAspectRatioIdentifier(),
55 0, 40 0,
(...skipping 14 matching lines...) Expand all
70 transformIdentifier(), 55 transformIdentifier(),
71 0, 56 0,
72 0); 57 0);
73 } 58 }
74 return s_propertyInfo; 59 return s_propertyInfo;
75 } 60 }
76 61
77 SVGViewSpec::SVGViewSpec(WeakPtr<SVGSVGElement> contextElement) 62 SVGViewSpec::SVGViewSpec(WeakPtr<SVGSVGElement> contextElement)
78 : m_contextElement(contextElement) 63 : m_contextElement(contextElement)
79 , m_zoomAndPan(SVGZoomAndPanMagnify) 64 , m_zoomAndPan(SVGZoomAndPanMagnify)
65 // Note: We make |viewBox|'s contextElement the target element of SVGViewSpe c.
66 // This contextElement will be only used for keeping this alive from the tea roff.
67 // SVGSVGElement holds a strong-ref to this SVGViewSpec, so this is kept ali ve as:
68 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> SV GViewSpec.
69 , m_viewBox(SVGAnimatedRect::create(contextElement.get(), SVGNames::viewBoxA ttr))
80 { 70 {
81 ASSERT(m_contextElement); 71 ASSERT(m_contextElement);
82 ScriptWrappable::init(this); 72 ScriptWrappable::init(this);
83 }
84 73
85 const AtomicString& SVGViewSpec::viewBoxIdentifier() 74 m_viewBox->setReadOnly();
86 { 75 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to an element.
87 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecViewBoxAttribut e", AtomicString::ConstructFromLiteral));
88 return s_identifier;
89 } 76 }
90 77
91 const AtomicString& SVGViewSpec::preserveAspectRatioIdentifier() 78 const AtomicString& SVGViewSpec::preserveAspectRatioIdentifier()
92 { 79 {
93 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecPreserveAspectR atioAttribute", AtomicString::ConstructFromLiteral)); 80 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecPreserveAspectR atioAttribute", AtomicString::ConstructFromLiteral));
94 return s_identifier; 81 return s_identifier;
95 } 82 }
96 83
97 const AtomicString& SVGViewSpec::transformIdentifier() 84 const AtomicString& SVGViewSpec::transformIdentifier()
98 { 85 {
(...skipping 19 matching lines...) Expand all
118 static_cast<SVGAnimatedTransformList*>(wrapper)->detachListWrappers(newL ist.size()); 105 static_cast<SVGAnimatedTransformList*>(wrapper)->detachListWrappers(newL ist.size());
119 106
120 m_transform = newList; 107 m_transform = newList;
121 } 108 }
122 109
123 String SVGViewSpec::transformString() const 110 String SVGViewSpec::transformString() const
124 { 111 {
125 return SVGPropertyTraits<SVGTransformList>::toString(m_transform); 112 return SVGPropertyTraits<SVGTransformList>::toString(m_transform);
126 } 113 }
127 114
128 String SVGViewSpec::viewBoxString() const
129 {
130 return SVGPropertyTraits<SVGRect>::toString(viewBoxBaseValue());
131 }
132
133 String SVGViewSpec::preserveAspectRatioString() const 115 String SVGViewSpec::preserveAspectRatioString() const
134 { 116 {
135 return SVGPropertyTraits<SVGPreserveAspectRatio>::toString(preserveAspectRat ioBaseValue()); 117 return SVGPropertyTraits<SVGPreserveAspectRatio>::toString(preserveAspectRat ioBaseValue());
136 } 118 }
137 119
120 String SVGViewSpec::viewBoxString() const
121 {
122 return m_viewBox->currentValue()->valueAsString();
123 }
124
138 SVGElement* SVGViewSpec::viewTarget() const 125 SVGElement* SVGViewSpec::viewTarget() const
139 { 126 {
140 if (!m_contextElement) 127 if (!m_contextElement)
141 return 0; 128 return 0;
142 Element* element = m_contextElement.get()->treeScope().getElementById(Atomic String(m_viewTargetString)); 129 Element* element = m_contextElement.get()->treeScope().getElementById(Atomic String(m_viewTargetString));
143 if (!element || !element->isSVGElement()) 130 if (!element || !element->isSVGElement())
144 return 0; 131 return 0;
145 return toSVGElement(element); 132 return toSVGElement(element);
146 } 133 }
147 134
148 SVGTransformListPropertyTearOff* SVGViewSpec::transform() 135 SVGTransformListPropertyTearOff* SVGViewSpec::transform()
149 { 136 {
150 if (!m_contextElement) 137 if (!m_contextElement)
151 return 0; 138 return 0;
152 // Return the animVal here, as its readonly by default - which is exactly wh at we want here. 139 // Return the animVal here, as its readonly by default - which is exactly wh at we want here.
153 return static_cast<SVGTransformListPropertyTearOff*>(static_pointer_cast<SVG AnimatedTransformList>(lookupOrCreateTransformWrapper(this))->animVal()); 140 return static_cast<SVGTransformListPropertyTearOff*>(static_pointer_cast<SVG AnimatedTransformList>(lookupOrCreateTransformWrapper(this))->animVal());
154 } 141 }
155 142
156 PassRefPtr<SVGAnimatedRect> SVGViewSpec::viewBox()
157 {
158 if (!m_contextElement)
159 return 0;
160 return static_pointer_cast<SVGAnimatedRect>(lookupOrCreateViewBoxWrapper(thi s));
161 }
162
163 PassRefPtr<SVGAnimatedPreserveAspectRatio> SVGViewSpec::preserveAspectRatio() 143 PassRefPtr<SVGAnimatedPreserveAspectRatio> SVGViewSpec::preserveAspectRatio()
164 { 144 {
165 if (!m_contextElement) 145 if (!m_contextElement)
166 return 0; 146 return 0;
167 return static_pointer_cast<SVGAnimatedPreserveAspectRatio>(lookupOrCreatePre serveAspectRatioWrapper(this)); 147 return static_pointer_cast<SVGAnimatedPreserveAspectRatio>(lookupOrCreatePre serveAspectRatioWrapper(this));
168 } 148 }
169 149
170 PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreateViewBoxWrapper(SVGVie wSpec* ownerType)
171 {
172 ASSERT(ownerType);
173 ASSERT(ownerType->contextElement());
174 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedRec t, SVGRect>(ownerType->contextElement(), viewBoxPropertyInfo(), ownerType->m_vie wBox);
175 }
176
177 PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreatePreserveAspectRatioWr apper(SVGViewSpec* ownerType) 150 PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreatePreserveAspectRatioWr apper(SVGViewSpec* ownerType)
178 { 151 {
179 ASSERT(ownerType); 152 ASSERT(ownerType);
180 ASSERT(ownerType->contextElement()); 153 ASSERT(ownerType->contextElement());
181 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedPre serveAspectRatio, SVGPreserveAspectRatio>(ownerType->contextElement(), preserveA spectRatioPropertyInfo(), ownerType->m_preserveAspectRatio); 154 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedPre serveAspectRatio, SVGPreserveAspectRatio>(ownerType->contextElement(), preserveA spectRatioPropertyInfo(), ownerType->m_preserveAspectRatio);
182 } 155 }
183 156
184 PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreateTransformWrapper(SVGV iewSpec* ownerType) 157 PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreateTransformWrapper(SVGV iewSpec* ownerType)
185 { 158 {
186 ASSERT(ownerType); 159 ASSERT(ownerType);
187 ASSERT(ownerType->contextElement()); 160 ASSERT(ownerType->contextElement());
188 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedTra nsformList, SVGTransformList>(ownerType->contextElement(), transformPropertyInfo (), ownerType->m_transform); 161 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedTra nsformList, SVGTransformList>(ownerType->contextElement(), transformPropertyInfo (), ownerType->m_transform);
189 } 162 }
190 163
191 void SVGViewSpec::reset() 164 void SVGViewSpec::reset()
192 { 165 {
193 m_zoomAndPan = SVGZoomAndPanMagnify; 166 m_zoomAndPan = SVGZoomAndPanMagnify;
194 m_transform.clear(); 167 m_transform.clear();
195 m_viewBox = SVGRect(); 168 m_viewBox->baseValue()->setValue(FloatRect());
196 m_preserveAspectRatio = SVGPreserveAspectRatio(); 169 m_preserveAspectRatio = SVGPreserveAspectRatio();
197 m_viewTargetString = emptyString(); 170 m_viewTargetString = emptyString();
198 } 171 }
199 172
200 static const LChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'}; 173 static const LChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'};
201 static const LChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'}; 174 static const LChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'};
202 static const LChar preserveAspectRatioSpec[] = {'p', 'r', 'e', 's', 'e', 'r', 'v ', 'e', 'A', 's', 'p', 'e', 'c', 't', 'R', 'a', 't', 'i', 'o'}; 175 static const LChar preserveAspectRatioSpec[] = {'p', 'r', 'e', 's', 'e', 'r', 'v ', 'e', 'A', 's', 'p', 'e', 'c', 't', 'R', 'a', 't', 'i', 'o'};
203 static const LChar transformSpec[] = {'t', 'r', 'a', 'n', 's', 'f', 'o', 'r', 'm '}; 176 static const LChar transformSpec[] = {'t', 'r', 'a', 'n', 's', 'f', 'o', 'r', 'm '};
204 static const LChar zoomAndPanSpec[] = {'z', 'o', 'o', 'm', 'A', 'n', 'd', 'P', ' a', 'n'}; 177 static const LChar zoomAndPanSpec[] = {'z', 'o', 'o', 'm', 'A', 'n', 'd', 'P', ' a', 'n'};
205 static const LChar viewTargetSpec[] = {'v', 'i', 'e', 'w', 'T', 'a', 'r', 'g', 'e', 't'}; 178 static const LChar viewTargetSpec[] = {'v', 'i', 'e', 'w', 'T', 'a', 'r', 'g', 'e', 't'};
206 179
207 template<typename CharType> 180 template<typename CharType>
208 bool SVGViewSpec::parseViewSpecInternal(const CharType* ptr, const CharType* end ) 181 bool SVGViewSpec::parseViewSpecInternal(const CharType* ptr, const CharType* end )
209 { 182 {
210 if (!skipString(ptr, end, svgViewSpec, WTF_ARRAY_LENGTH(svgViewSpec))) 183 if (!skipString(ptr, end, svgViewSpec, WTF_ARRAY_LENGTH(svgViewSpec)))
211 return false; 184 return false;
212 185
213 if (ptr >= end || *ptr != '(') 186 if (ptr >= end || *ptr != '(')
214 return false; 187 return false;
215 ptr++; 188 ptr++;
216 189
217 while (ptr < end && *ptr != ')') { 190 while (ptr < end && *ptr != ')') {
218 if (*ptr == 'v') { 191 if (*ptr == 'v') {
219 if (skipString(ptr, end, viewBoxSpec, WTF_ARRAY_LENGTH(viewBoxSpec)) ) { 192 if (skipString(ptr, end, viewBoxSpec, WTF_ARRAY_LENGTH(viewBoxSpec)) ) {
220 if (ptr >= end || *ptr != '(') 193 if (ptr >= end || *ptr != '(')
221 return false; 194 return false;
222 ptr++; 195 ptr++;
223 SVGRect viewBox; 196 float x = 0.0f;
224 if (!SVGFitToViewBox::parseViewBox(&m_contextElement.get()->docu ment(), ptr, end, viewBox, false)) 197 float y = 0.0f;
198 float width = 0.0f;
199 float height = 0.0f;
200 if (!(parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && pa rseNumber(ptr, end, width) && parseNumber(ptr, end, height, false)))
haraken 2014/01/16 04:56:43 Nit: Why do we need 'false' when parsing 'height'?
kouhei (in TOK) 2014/01/16 05:12:37 This skips removing spaces at the end.
225 return false; 201 return false;
226 setViewBoxBaseValue(viewBox); 202 m_viewBox->baseValue()->setValue(FloatRect(x, y, width, height)) ;
227 if (ptr >= end || *ptr != ')') 203 if (ptr >= end || *ptr != ')')
228 return false; 204 return false;
229 ptr++; 205 ptr++;
230 } else if (skipString(ptr, end, viewTargetSpec, WTF_ARRAY_LENGTH(vie wTargetSpec))) { 206 } else if (skipString(ptr, end, viewTargetSpec, WTF_ARRAY_LENGTH(vie wTargetSpec))) {
231 if (ptr >= end || *ptr != '(') 207 if (ptr >= end || *ptr != '(')
232 return false; 208 return false;
233 const CharType* viewTargetStart = ++ptr; 209 const CharType* viewTargetStart = ++ptr;
234 while (ptr < end && *ptr != ')') 210 while (ptr < end && *ptr != ')')
235 ptr++; 211 ptr++;
236 if (ptr >= end) 212 if (ptr >= end)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 const LChar* ptr = spec.characters8(); 270 const LChar* ptr = spec.characters8();
295 const LChar* end = ptr + spec.length(); 271 const LChar* end = ptr + spec.length();
296 return parseViewSpecInternal(ptr, end); 272 return parseViewSpecInternal(ptr, end);
297 } 273 }
298 const UChar* ptr = spec.characters16(); 274 const UChar* ptr = spec.characters16();
299 const UChar* end = ptr + spec.length(); 275 const UChar* end = ptr + spec.length();
300 return parseViewSpecInternal(ptr, end); 276 return parseViewSpecInternal(ptr, end);
301 } 277 }
302 278
303 } 279 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698