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

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: haraken review 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
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 11 matching lines...) Expand all
22 22
23 #include "SVGNames.h" 23 #include "SVGNames.h"
24 #include "bindings/v8/ExceptionMessages.h" 24 #include "bindings/v8/ExceptionMessages.h"
25 #include "bindings/v8/ExceptionState.h" 25 #include "bindings/v8/ExceptionState.h"
26 #include "core/dom/Document.h" 26 #include "core/dom/Document.h"
27 #include "core/svg/SVGAnimatedTransformList.h" 27 #include "core/svg/SVGAnimatedTransformList.h"
28 #include "core/svg/SVGParserUtilities.h" 28 #include "core/svg/SVGParserUtilities.h"
29 29
30 namespace WebCore { 30 namespace WebCore {
31 31
32 // Define custom non-animated property 'transform'.
33 const SVGPropertyInfo* SVGViewSpec::transformPropertyInfo()
34 {
35 static const SVGPropertyInfo* s_propertyInfo = 0;
36 if (!s_propertyInfo) {
37 s_propertyInfo = new SVGPropertyInfo(AnimatedTransformList,
38 PropertyIsReadOnly,
39 SVGNames::transformAttr,
40 transformIdentifier(),
41 0,
42 0);
43 }
44 return s_propertyInfo;
45 }
46
47 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement) 32 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement)
48 : m_contextElement(contextElement) 33 : m_contextElement(contextElement)
49 , m_zoomAndPan(SVGZoomAndPanMagnify) 34 , m_zoomAndPan(SVGZoomAndPanMagnify)
50 // Note: We make |viewBox| and |preserveAspectRatio|'s contextElement the ta rget element of SVGViewSpec. 35 // Note: We make |viewBox| and |preserveAspectRatio|'s contextElement the ta rget element of SVGViewSpec.
51 // This contextElement will be only used for keeping this alive from the tea roff. 36 // This contextElement will be only used for keeping this alive from the tea roff.
52 // SVGSVGElement holds a strong-ref to this SVGViewSpec, so this is kept ali ve as: 37 // SVGSVGElement holds a strong-ref to this SVGViewSpec, so this is kept ali ve as:
53 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> SV GViewSpec. 38 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> SV GViewSpec.
39 , m_transform(SVGAnimatedTransformList::create(contextElement, SVGNames::tra nsformAttr, SVGTransformList::create()))
54 , m_viewBox(SVGAnimatedRect::create(contextElement, SVGNames::viewBoxAttr)) 40 , m_viewBox(SVGAnimatedRect::create(contextElement, SVGNames::viewBoxAttr))
55 , m_preserveAspectRatio(SVGAnimatedPreserveAspectRatio::create(contextElemen t, SVGNames::preserveAspectRatioAttr, SVGPreserveAspectRatio::create())) 41 , m_preserveAspectRatio(SVGAnimatedPreserveAspectRatio::create(contextElemen t, SVGNames::preserveAspectRatioAttr, SVGPreserveAspectRatio::create()))
56 { 42 {
57 ASSERT(m_contextElement); 43 ASSERT(m_contextElement);
58 ScriptWrappable::init(this); 44 ScriptWrappable::init(this);
59 45
46 m_transform->setReadOnly();
60 m_viewBox->setReadOnly(); 47 m_viewBox->setReadOnly();
61 m_preserveAspectRatio->setReadOnly(); 48 m_preserveAspectRatio->setReadOnly();
62 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to an element. 49 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to an element.
63 } 50 }
64 51
65 const AtomicString& SVGViewSpec::transformIdentifier()
66 {
67 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecTransformAttrib ute", AtomicString::ConstructFromLiteral));
68 return s_identifier;
69 }
70
71 void SVGViewSpec::setZoomAndPan(unsigned short, ExceptionState& exceptionState) 52 void SVGViewSpec::setZoomAndPan(unsigned short, ExceptionState& exceptionState)
72 { 53 {
73 // SVGViewSpec and all of its content is read-only. 54 // SVGViewSpec and all of its content is read-only.
74 exceptionState.throwDOMException(NoModificationAllowedError, ExceptionMessag es::readOnly()); 55 exceptionState.throwDOMException(NoModificationAllowedError, ExceptionMessag es::readOnly());
75 } 56 }
76 57
77 String SVGViewSpec::preserveAspectRatioString() const 58 String SVGViewSpec::preserveAspectRatioString() const
78 { 59 {
79 return m_preserveAspectRatio->baseValue()->valueAsString(); 60 return m_preserveAspectRatio->baseValue()->valueAsString();
80 } 61 }
81 62
82 void SVGViewSpec::setTransformString(const String& transform)
83 {
84 if (!m_contextElement)
85 return;
86
87 SVGTransformList newList;
88 newList.parse(transform);
89
90 if (SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGEle ment, SVGAnimatedTransformList>(m_contextElement, transformPropertyInfo()))
91 static_cast<SVGAnimatedTransformList*>(wrapper)->detachListWrappers(newL ist.size());
92
93 m_transform = newList;
94 }
95
96 String SVGViewSpec::transformString() const 63 String SVGViewSpec::transformString() const
97 { 64 {
98 return SVGPropertyTraits<SVGTransformList>::toString(m_transform); 65 if (!m_transform)
66 return String();
67
68 return m_transform->baseValue()->valueAsString();
99 } 69 }
100 70
101 String SVGViewSpec::viewBoxString() const 71 String SVGViewSpec::viewBoxString() const
102 { 72 {
103 return m_viewBox->currentValue()->valueAsString(); 73 return m_viewBox->currentValue()->valueAsString();
104 } 74 }
105 75
106 SVGElement* SVGViewSpec::viewTarget() const 76 SVGElement* SVGViewSpec::viewTarget() const
107 { 77 {
108 if (!m_contextElement) 78 if (!m_contextElement)
109 return 0; 79 return 0;
110 Element* element = m_contextElement->treeScope().getElementById(AtomicString (m_viewTargetString)); 80 Element* element = m_contextElement->treeScope().getElementById(AtomicString (m_viewTargetString));
111 if (!element || !element->isSVGElement()) 81 if (!element || !element->isSVGElement())
112 return 0; 82 return 0;
113 return toSVGElement(element); 83 return toSVGElement(element);
114 } 84 }
115 85
116 SVGTransformListPropertyTearOff* SVGViewSpec::transform()
117 {
118 if (!m_contextElement)
119 return 0;
120 // Return the animVal here, as its readonly by default - which is exactly wh at we want here.
121 return static_cast<SVGTransformListPropertyTearOff*>(static_pointer_cast<SVG AnimatedTransformList>(lookupOrCreateTransformWrapper(this))->animVal());
122 }
123
124 PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreateTransformWrapper(SVGV iewSpec* ownerType)
125 {
126 ASSERT(ownerType);
127 ASSERT(ownerType->contextElement());
128 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedTra nsformList, SVGTransformList>(ownerType->contextElement(), transformPropertyInfo (), ownerType->m_transform);
129 }
130
131 void SVGViewSpec::detachContextElement() 86 void SVGViewSpec::detachContextElement()
132 { 87 {
88 m_transform = 0;
fs 2014/02/17 14:14:31 Any reason we can't hold on to these when the cont
kouhei (in TOK) 2014/02/18 02:09:15 These tear-offs' wrappers keep context element ali
133 m_viewBox = 0; 89 m_viewBox = 0;
134 m_preserveAspectRatio = 0; 90 m_preserveAspectRatio = 0;
135 m_contextElement = 0; 91 m_contextElement = 0;
136 } 92 }
137 93
138 void SVGViewSpec::reset() 94 void SVGViewSpec::reset()
139 { 95 {
140 m_zoomAndPan = SVGZoomAndPanMagnify; 96 m_zoomAndPan = SVGZoomAndPanMagnify;
141 m_transform.clear(); 97 m_transform->baseValue()->clear();
142 ASSERT(m_viewBox); 98 ASSERT(m_viewBox);
143 m_viewBox->baseValue()->setValue(FloatRect()); 99 m_viewBox->baseValue()->setValue(FloatRect());
144 ASSERT(m_preserveAspectRatio); 100 ASSERT(m_preserveAspectRatio);
145 m_preserveAspectRatio->baseValue()->setAlign(SVGPreserveAspectRatio::SVG_PRE SERVEASPECTRATIO_XMIDYMID); 101 m_preserveAspectRatio->baseValue()->setAlign(SVGPreserveAspectRatio::SVG_PRE SERVEASPECTRATIO_XMIDYMID);
146 m_preserveAspectRatio->baseValue()->setMeetOrSlice(SVGPreserveAspectRatio::S VG_MEETORSLICE_MEET); 102 m_preserveAspectRatio->baseValue()->setMeetOrSlice(SVGPreserveAspectRatio::S VG_MEETORSLICE_MEET);
147 m_viewTargetString = emptyString(); 103 m_viewTargetString = emptyString();
148 } 104 }
149 105
150 static const LChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'}; 106 static const LChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'};
151 static const LChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'}; 107 static const LChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'};
(...skipping 29 matching lines...) Expand all
181 return false; 137 return false;
182 ptr++; 138 ptr++;
183 } else if (skipString(ptr, end, viewTargetSpec, WTF_ARRAY_LENGTH(vie wTargetSpec))) { 139 } else if (skipString(ptr, end, viewTargetSpec, WTF_ARRAY_LENGTH(vie wTargetSpec))) {
184 if (ptr >= end || *ptr != '(') 140 if (ptr >= end || *ptr != '(')
185 return false; 141 return false;
186 const CharType* viewTargetStart = ++ptr; 142 const CharType* viewTargetStart = ++ptr;
187 while (ptr < end && *ptr != ')') 143 while (ptr < end && *ptr != ')')
188 ptr++; 144 ptr++;
189 if (ptr >= end) 145 if (ptr >= end)
190 return false; 146 return false;
191 setViewTargetString(String(viewTargetStart, ptr - viewTargetStar t)); 147 m_viewTargetString = String(viewTargetStart, ptr - viewTargetSta rt);
192 ptr++; 148 ptr++;
193 } else 149 } else
194 return false; 150 return false;
195 } else if (*ptr == 'z') { 151 } else if (*ptr == 'z') {
196 if (!skipString(ptr, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPa nSpec))) 152 if (!skipString(ptr, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPa nSpec)))
197 return false; 153 return false;
198 if (ptr >= end || *ptr != '(') 154 if (ptr >= end || *ptr != '(')
199 return false; 155 return false;
200 ptr++; 156 ptr++;
201 if (!parseZoomAndPan(ptr, end, m_zoomAndPan)) 157 if (!parseZoomAndPan(ptr, end, m_zoomAndPan))
(...skipping 11 matching lines...) Expand all
213 return false; 169 return false;
214 if (ptr >= end || *ptr != ')') 170 if (ptr >= end || *ptr != ')')
215 return false; 171 return false;
216 ptr++; 172 ptr++;
217 } else if (*ptr == 't') { 173 } else if (*ptr == 't') {
218 if (!skipString(ptr, end, transformSpec, WTF_ARRAY_LENGTH(transformS pec))) 174 if (!skipString(ptr, end, transformSpec, WTF_ARRAY_LENGTH(transformS pec)))
219 return false; 175 return false;
220 if (ptr >= end || *ptr != '(') 176 if (ptr >= end || *ptr != '(')
221 return false; 177 return false;
222 ptr++; 178 ptr++;
223 parseTransformAttribute(m_transform, ptr, end, DoNotClearList); 179 m_transform->baseValue()->parse(ptr, end);
fs 2014/02/17 14:14:31 This appears to drop the "DoNotClearList"-semantic
kouhei (in TOK) 2014/02/18 02:09:15 True, added to description. I think this is a corr
224 if (ptr >= end || *ptr != ')') 180 if (ptr >= end || *ptr != ')')
225 return false; 181 return false;
226 ptr++; 182 ptr++;
227 } else 183 } else
228 return false; 184 return false;
229 185
230 if (ptr < end && *ptr == ';') 186 if (ptr < end && *ptr == ';')
231 ptr++; 187 ptr++;
232 } 188 }
233 189
(...skipping 11 matching lines...) Expand all
245 const LChar* ptr = spec.characters8(); 201 const LChar* ptr = spec.characters8();
246 const LChar* end = ptr + spec.length(); 202 const LChar* end = ptr + spec.length();
247 return parseViewSpecInternal(ptr, end); 203 return parseViewSpecInternal(ptr, end);
248 } 204 }
249 const UChar* ptr = spec.characters16(); 205 const UChar* ptr = spec.characters16();
250 const UChar* end = ptr + spec.length(); 206 const UChar* end = ptr + spec.length();
251 return parseViewSpecInternal(ptr, end); 207 return parseViewSpecInternal(ptr, end);
252 } 208 }
253 209
254 } 210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698