OLD | NEW |
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 27 matching lines...) Expand all Loading... |
38 PropertyIsReadOnly, | 38 PropertyIsReadOnly, |
39 SVGNames::transformAttr, | 39 SVGNames::transformAttr, |
40 transformIdentifier(), | 40 transformIdentifier(), |
41 0, | 41 0, |
42 0); | 42 0); |
43 } | 43 } |
44 return s_propertyInfo; | 44 return s_propertyInfo; |
45 } | 45 } |
46 | 46 |
47 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement) | 47 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement) |
48 : m_contextElement(contextElement) | |
49 , m_zoomAndPan(SVGZoomAndPanMagnify) | |
50 // Note: We make |viewBox| and |preserveAspectRatio|'s contextElement the ta
rget element of SVGViewSpec. | 48 // 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. | 49 // 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: | 50 // SVGSVGElement holds a strong-ref to this SVGViewSpec, so this is kept ali
ve as: |
53 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> SV
GViewSpec. | 51 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> SV
GViewSpec. |
54 , m_viewBox(SVGAnimatedRect::create(contextElement, SVGNames::viewBoxAttr)) | 52 : SVGFitToViewBox(contextElement, PropertyMapPolicySkip) // Note: addToPrope
rtyMap is not needed, as SVGViewSpec do not correspond to an element. |
55 , m_preserveAspectRatio(SVGAnimatedPreserveAspectRatio::create(contextElemen
t, SVGNames::preserveAspectRatioAttr, SVGPreserveAspectRatio::create())) | 53 , m_contextElement(contextElement) |
| 54 , m_zoomAndPan(SVGZoomAndPanMagnify) |
56 { | 55 { |
57 ASSERT(m_contextElement); | 56 ASSERT(m_contextElement); |
58 ScriptWrappable::init(this); | 57 ScriptWrappable::init(this); |
59 | 58 |
60 m_viewBox->setReadOnly(); | 59 viewBox()->setReadOnly(); |
61 m_preserveAspectRatio->setReadOnly(); | 60 preserveAspectRatio()->setReadOnly(); |
62 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to
an element. | |
63 } | 61 } |
64 | 62 |
65 const AtomicString& SVGViewSpec::transformIdentifier() | 63 const AtomicString& SVGViewSpec::transformIdentifier() |
66 { | 64 { |
67 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecTransformAttrib
ute", AtomicString::ConstructFromLiteral)); | 65 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGViewSpecTransformAttrib
ute", AtomicString::ConstructFromLiteral)); |
68 return s_identifier; | 66 return s_identifier; |
69 } | 67 } |
70 | 68 |
71 void SVGViewSpec::setZoomAndPan(unsigned short, ExceptionState& exceptionState) | 69 void SVGViewSpec::setZoomAndPan(unsigned short, ExceptionState& exceptionState) |
72 { | 70 { |
73 // SVGViewSpec and all of its content is read-only. | 71 // SVGViewSpec and all of its content is read-only. |
74 exceptionState.throwDOMException(NoModificationAllowedError, ExceptionMessag
es::readOnly()); | 72 exceptionState.throwDOMException(NoModificationAllowedError, ExceptionMessag
es::readOnly()); |
75 } | 73 } |
76 | 74 |
77 String SVGViewSpec::preserveAspectRatioString() const | 75 String SVGViewSpec::preserveAspectRatioString() const |
78 { | 76 { |
79 return m_preserveAspectRatio->baseValue()->valueAsString(); | 77 return preserveAspectRatio()->baseValue()->valueAsString(); |
80 } | 78 } |
81 | 79 |
82 void SVGViewSpec::setTransformString(const String& transform) | 80 void SVGViewSpec::setTransformString(const String& transform) |
83 { | 81 { |
84 if (!m_contextElement) | 82 if (!m_contextElement) |
85 return; | 83 return; |
86 | 84 |
87 SVGTransformList newList; | 85 SVGTransformList newList; |
88 newList.parse(transform); | 86 newList.parse(transform); |
89 | 87 |
90 if (SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGEle
ment, SVGAnimatedTransformList>(m_contextElement, transformPropertyInfo())) | 88 if (SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGEle
ment, SVGAnimatedTransformList>(m_contextElement, transformPropertyInfo())) |
91 static_cast<SVGAnimatedTransformList*>(wrapper)->detachListWrappers(newL
ist.size()); | 89 static_cast<SVGAnimatedTransformList*>(wrapper)->detachListWrappers(newL
ist.size()); |
92 | 90 |
93 m_transform = newList; | 91 m_transform = newList; |
94 } | 92 } |
95 | 93 |
96 String SVGViewSpec::transformString() const | 94 String SVGViewSpec::transformString() const |
97 { | 95 { |
98 return SVGPropertyTraits<SVGTransformList>::toString(m_transform); | 96 return SVGPropertyTraits<SVGTransformList>::toString(m_transform); |
99 } | 97 } |
100 | 98 |
101 String SVGViewSpec::viewBoxString() const | 99 String SVGViewSpec::viewBoxString() const |
102 { | 100 { |
103 return m_viewBox->currentValue()->valueAsString(); | 101 return viewBox()->currentValue()->valueAsString(); |
104 } | 102 } |
105 | 103 |
106 SVGElement* SVGViewSpec::viewTarget() const | 104 SVGElement* SVGViewSpec::viewTarget() const |
107 { | 105 { |
108 if (!m_contextElement) | 106 if (!m_contextElement) |
109 return 0; | 107 return 0; |
110 Element* element = m_contextElement->treeScope().getElementById(AtomicString
(m_viewTargetString)); | 108 Element* element = m_contextElement->treeScope().getElementById(AtomicString
(m_viewTargetString)); |
111 if (!element || !element->isSVGElement()) | 109 if (!element || !element->isSVGElement()) |
112 return 0; | 110 return 0; |
113 return toSVGElement(element); | 111 return toSVGElement(element); |
114 } | 112 } |
115 | 113 |
116 SVGTransformListPropertyTearOff* SVGViewSpec::transform() | 114 SVGTransformListPropertyTearOff* SVGViewSpec::transform() |
117 { | 115 { |
118 if (!m_contextElement) | 116 if (!m_contextElement) |
119 return 0; | 117 return 0; |
120 // Return the animVal here, as its readonly by default - which is exactly wh
at we want here. | 118 // 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()); | 119 return static_cast<SVGTransformListPropertyTearOff*>(static_pointer_cast<SVG
AnimatedTransformList>(lookupOrCreateTransformWrapper(this))->animVal()); |
122 } | 120 } |
123 | 121 |
124 PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreateTransformWrapper(SVGV
iewSpec* ownerType) | 122 PassRefPtr<SVGAnimatedProperty> SVGViewSpec::lookupOrCreateTransformWrapper(SVGV
iewSpec* ownerType) |
125 { | 123 { |
126 ASSERT(ownerType); | 124 ASSERT(ownerType); |
127 ASSERT(ownerType->contextElement()); | 125 ASSERT(ownerType->contextElement()); |
128 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedTra
nsformList, SVGTransformList>(ownerType->contextElement(), transformPropertyInfo
(), ownerType->m_transform); | 126 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGElement, SVGAnimatedTra
nsformList, SVGTransformList>(ownerType->contextElement(), transformPropertyInfo
(), ownerType->m_transform); |
129 } | 127 } |
130 | 128 |
131 void SVGViewSpec::detachContextElement() | 129 void SVGViewSpec::detachContextElement() |
132 { | 130 { |
133 m_viewBox = 0; | 131 clearViewBox(); |
134 m_preserveAspectRatio = 0; | 132 clearPreserveAspectRatio(); |
135 m_contextElement = 0; | 133 m_contextElement = 0; |
136 } | 134 } |
137 | 135 |
138 void SVGViewSpec::reset() | 136 void SVGViewSpec::reset() |
139 { | 137 { |
140 m_zoomAndPan = SVGZoomAndPanMagnify; | 138 m_zoomAndPan = SVGZoomAndPanMagnify; |
141 m_transform.clear(); | 139 m_transform.clear(); |
142 ASSERT(m_viewBox); | 140 updateViewBox(FloatRect()); |
143 m_viewBox->baseValue()->setValue(FloatRect()); | 141 ASSERT(preserveAspectRatio()); |
144 ASSERT(m_preserveAspectRatio); | 142 preserveAspectRatio()->baseValue()->setAlign(SVGPreserveAspectRatio::SVG_PRE
SERVEASPECTRATIO_XMIDYMID); |
145 m_preserveAspectRatio->baseValue()->setAlign(SVGPreserveAspectRatio::SVG_PRE
SERVEASPECTRATIO_XMIDYMID); | 143 preserveAspectRatio()->baseValue()->setMeetOrSlice(SVGPreserveAspectRatio::S
VG_MEETORSLICE_MEET); |
146 m_preserveAspectRatio->baseValue()->setMeetOrSlice(SVGPreserveAspectRatio::S
VG_MEETORSLICE_MEET); | |
147 m_viewTargetString = emptyString(); | 144 m_viewTargetString = emptyString(); |
148 } | 145 } |
149 | 146 |
150 static const LChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'}; | 147 static const LChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'}; |
151 static const LChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'}; | 148 static const LChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'}; |
152 static const LChar preserveAspectRatioSpec[] = {'p', 'r', 'e', 's', 'e', 'r', 'v
', 'e', 'A', 's', 'p', 'e', 'c', 't', 'R', 'a', 't', 'i', 'o'}; | 149 static const LChar preserveAspectRatioSpec[] = {'p', 'r', 'e', 's', 'e', 'r', 'v
', 'e', 'A', 's', 'p', 'e', 'c', 't', 'R', 'a', 't', 'i', 'o'}; |
153 static const LChar transformSpec[] = {'t', 'r', 'a', 'n', 's', 'f', 'o', 'r', 'm
'}; | 150 static const LChar transformSpec[] = {'t', 'r', 'a', 'n', 's', 'f', 'o', 'r', 'm
'}; |
154 static const LChar zoomAndPanSpec[] = {'z', 'o', 'o', 'm', 'A', 'n', 'd', 'P', '
a', 'n'}; | 151 static const LChar zoomAndPanSpec[] = {'z', 'o', 'o', 'm', 'A', 'n', 'd', 'P', '
a', 'n'}; |
155 static const LChar viewTargetSpec[] = {'v', 'i', 'e', 'w', 'T', 'a', 'r', 'g',
'e', 't'}; | 152 static const LChar viewTargetSpec[] = {'v', 'i', 'e', 'w', 'T', 'a', 'r', 'g',
'e', 't'}; |
156 | 153 |
(...skipping 12 matching lines...) Expand all Loading... |
169 if (skipString(ptr, end, viewBoxSpec, WTF_ARRAY_LENGTH(viewBoxSpec))
) { | 166 if (skipString(ptr, end, viewBoxSpec, WTF_ARRAY_LENGTH(viewBoxSpec))
) { |
170 if (ptr >= end || *ptr != '(') | 167 if (ptr >= end || *ptr != '(') |
171 return false; | 168 return false; |
172 ptr++; | 169 ptr++; |
173 float x = 0.0f; | 170 float x = 0.0f; |
174 float y = 0.0f; | 171 float y = 0.0f; |
175 float width = 0.0f; | 172 float width = 0.0f; |
176 float height = 0.0f; | 173 float height = 0.0f; |
177 if (!(parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && pa
rseNumber(ptr, end, width) && parseNumber(ptr, end, height, false))) | 174 if (!(parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && pa
rseNumber(ptr, end, width) && parseNumber(ptr, end, height, false))) |
178 return false; | 175 return false; |
179 m_viewBox->baseValue()->setValue(FloatRect(x, y, width, height))
; | 176 updateViewBox(FloatRect(x, y, width, height)); |
180 if (ptr >= end || *ptr != ')') | 177 if (ptr >= end || *ptr != ')') |
181 return false; | 178 return false; |
182 ptr++; | 179 ptr++; |
183 } else if (skipString(ptr, end, viewTargetSpec, WTF_ARRAY_LENGTH(vie
wTargetSpec))) { | 180 } else if (skipString(ptr, end, viewTargetSpec, WTF_ARRAY_LENGTH(vie
wTargetSpec))) { |
184 if (ptr >= end || *ptr != '(') | 181 if (ptr >= end || *ptr != '(') |
185 return false; | 182 return false; |
186 const CharType* viewTargetStart = ++ptr; | 183 const CharType* viewTargetStart = ++ptr; |
187 while (ptr < end && *ptr != ')') | 184 while (ptr < end && *ptr != ')') |
188 ptr++; | 185 ptr++; |
189 if (ptr >= end) | 186 if (ptr >= end) |
(...skipping 12 matching lines...) Expand all Loading... |
202 return false; | 199 return false; |
203 if (ptr >= end || *ptr != ')') | 200 if (ptr >= end || *ptr != ')') |
204 return false; | 201 return false; |
205 ptr++; | 202 ptr++; |
206 } else if (*ptr == 'p') { | 203 } else if (*ptr == 'p') { |
207 if (!skipString(ptr, end, preserveAspectRatioSpec, WTF_ARRAY_LENGTH(
preserveAspectRatioSpec))) | 204 if (!skipString(ptr, end, preserveAspectRatioSpec, WTF_ARRAY_LENGTH(
preserveAspectRatioSpec))) |
208 return false; | 205 return false; |
209 if (ptr >= end || *ptr != '(') | 206 if (ptr >= end || *ptr != '(') |
210 return false; | 207 return false; |
211 ptr++; | 208 ptr++; |
212 if (!m_preserveAspectRatio->baseValue()->parse(ptr, end, false)) | 209 if (!preserveAspectRatio()->baseValue()->parse(ptr, end, false)) |
213 return false; | 210 return false; |
214 if (ptr >= end || *ptr != ')') | 211 if (ptr >= end || *ptr != ')') |
215 return false; | 212 return false; |
216 ptr++; | 213 ptr++; |
217 } else if (*ptr == 't') { | 214 } else if (*ptr == 't') { |
218 if (!skipString(ptr, end, transformSpec, WTF_ARRAY_LENGTH(transformS
pec))) | 215 if (!skipString(ptr, end, transformSpec, WTF_ARRAY_LENGTH(transformS
pec))) |
219 return false; | 216 return false; |
220 if (ptr >= end || *ptr != '(') | 217 if (ptr >= end || *ptr != '(') |
221 return false; | 218 return false; |
222 ptr++; | 219 ptr++; |
(...skipping 22 matching lines...) Expand all Loading... |
245 const LChar* ptr = spec.characters8(); | 242 const LChar* ptr = spec.characters8(); |
246 const LChar* end = ptr + spec.length(); | 243 const LChar* end = ptr + spec.length(); |
247 return parseViewSpecInternal(ptr, end); | 244 return parseViewSpecInternal(ptr, end); |
248 } | 245 } |
249 const UChar* ptr = spec.characters16(); | 246 const UChar* ptr = spec.characters16(); |
250 const UChar* end = ptr + spec.length(); | 247 const UChar* end = ptr + spec.length(); |
251 return parseViewSpecInternal(ptr, end); | 248 return parseViewSpecInternal(ptr, end); |
252 } | 249 } |
253 | 250 |
254 } | 251 } |
OLD | NEW |