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