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 |
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 "core/svg/SVGViewSpec.h" | 20 #include "core/svg/SVGViewSpec.h" |
21 | 21 |
22 #include "bindings/core/v8/ExceptionMessages.h" | |
23 #include "bindings/core/v8/ExceptionState.h" | |
24 #include "core/SVGNames.h" | |
25 #include "core/dom/ExceptionCode.h" | |
26 #include "core/svg/SVGAnimatedTransformList.h" | |
27 #include "core/svg/SVGParserUtilities.h" | 22 #include "core/svg/SVGParserUtilities.h" |
| 23 #include "core/svg/SVGPreserveAspectRatio.h" |
| 24 #include "core/svg/SVGRect.h" |
| 25 #include "core/svg/SVGTransformList.h" |
28 #include "wtf/text/ParsingUtilities.h" | 26 #include "wtf/text/ParsingUtilities.h" |
29 | 27 |
30 namespace blink { | 28 namespace blink { |
31 | 29 |
32 SVGViewSpec::SVGViewSpec(SVGSVGElement* contextElement) | 30 SVGViewSpec::SVGViewSpec() |
33 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to | 31 : m_viewBox(SVGRect::createInvalid()), |
34 // an element. We make tear-offs' contextElement the target element of | 32 m_preserveAspectRatio(SVGPreserveAspectRatio::create()), |
35 // SVGViewSpec. This contextElement will be only used for keeping this | 33 m_transform(SVGTransformList::create()) {} |
36 // alive from the tearoff. SVGSVGElement holds a strong-ref to this | |
37 // SVGViewSpec, so this is kept alive as: | |
38 // AnimatedProperty tearoff -(contextElement)-> SVGSVGElement -(RefPtr)-> | |
39 // SVGViewSpec. | |
40 : SVGFitToViewBox(contextElement, PropertyMapPolicySkip), | |
41 m_contextElement(contextElement), | |
42 m_transform(SVGAnimatedTransformList::create(contextElement, | |
43 SVGNames::transformAttr)) { | |
44 ASSERT(m_contextElement); | |
45 | |
46 viewBox()->setReadOnly(); | |
47 preserveAspectRatio()->setReadOnly(); | |
48 m_transform->setReadOnly(); | |
49 // Note: addToPropertyMap is not needed, as SVGViewSpec do not correspond to | |
50 // an element. | |
51 } | |
52 | 34 |
53 DEFINE_TRACE(SVGViewSpec) { | 35 DEFINE_TRACE(SVGViewSpec) { |
54 visitor->trace(m_contextElement); | 36 visitor->trace(m_viewBox); |
| 37 visitor->trace(m_preserveAspectRatio); |
55 visitor->trace(m_transform); | 38 visitor->trace(m_transform); |
56 SVGFitToViewBox::trace(visitor); | |
57 } | 39 } |
58 | 40 |
59 bool SVGViewSpec::parseViewSpec(const String& spec) { | 41 bool SVGViewSpec::parseViewSpec(const String& spec) { |
60 if (spec.isEmpty() || !m_contextElement) | 42 if (spec.isEmpty()) |
61 return false; | 43 return false; |
62 if (spec.is8Bit()) { | 44 if (spec.is8Bit()) { |
63 const LChar* ptr = spec.characters8(); | 45 const LChar* ptr = spec.characters8(); |
64 const LChar* end = ptr + spec.length(); | 46 const LChar* end = ptr + spec.length(); |
65 return parseViewSpecInternal(ptr, end); | 47 return parseViewSpecInternal(ptr, end); |
66 } | 48 } |
67 const UChar* ptr = spec.characters16(); | 49 const UChar* ptr = spec.characters16(); |
68 const UChar* end = ptr + spec.length(); | 50 const UChar* end = ptr + spec.length(); |
69 return parseViewSpecInternal(ptr, end); | 51 return parseViewSpecInternal(ptr, end); |
70 } | 52 } |
71 | 53 |
| 54 void SVGViewSpec::setViewBox(const FloatRect& rect) { |
| 55 viewBox()->setValue(rect); |
| 56 } |
| 57 |
| 58 void SVGViewSpec::setPreserveAspectRatio(const SVGPreserveAspectRatio& other) { |
| 59 preserveAspectRatio()->setAlign(other.align()); |
| 60 preserveAspectRatio()->setMeetOrSlice(other.meetOrSlice()); |
| 61 } |
| 62 |
72 void SVGViewSpec::reset() { | 63 void SVGViewSpec::reset() { |
73 resetZoomAndPan(); | 64 resetZoomAndPan(); |
74 m_transform->baseValue()->clear(); | 65 m_transform->clear(); |
75 updateViewBox(FloatRect()); | 66 setViewBox(FloatRect()); |
76 ASSERT(preserveAspectRatio()); | 67 preserveAspectRatio()->setDefault(); |
77 preserveAspectRatio()->baseValue()->setAlign( | |
78 SVGPreserveAspectRatio::kSvgPreserveaspectratioXmidymid); | |
79 preserveAspectRatio()->baseValue()->setMeetOrSlice( | |
80 SVGPreserveAspectRatio::kSvgMeetorsliceMeet); | |
81 m_viewTargetString = emptyString(); | |
82 } | 68 } |
83 | 69 |
84 namespace { | 70 namespace { |
85 | 71 |
86 enum ViewSpecFunctionType { | 72 enum ViewSpecFunctionType { |
87 Unknown, | 73 Unknown, |
88 PreserveAspectRatio, | 74 PreserveAspectRatio, |
89 Transform, | 75 Transform, |
90 ViewBox, | 76 ViewBox, |
91 ViewTarget, | 77 ViewTarget, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 switch (functionType) { | 127 switch (functionType) { |
142 case ViewBox: { | 128 case ViewBox: { |
143 float x = 0.0f; | 129 float x = 0.0f; |
144 float y = 0.0f; | 130 float y = 0.0f; |
145 float width = 0.0f; | 131 float width = 0.0f; |
146 float height = 0.0f; | 132 float height = 0.0f; |
147 if (!(parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && | 133 if (!(parseNumber(ptr, end, x) && parseNumber(ptr, end, y) && |
148 parseNumber(ptr, end, width) && | 134 parseNumber(ptr, end, width) && |
149 parseNumber(ptr, end, height, DisallowWhitespace))) | 135 parseNumber(ptr, end, height, DisallowWhitespace))) |
150 return false; | 136 return false; |
151 updateViewBox(FloatRect(x, y, width, height)); | 137 setViewBox(FloatRect(x, y, width, height)); |
152 break; | 138 break; |
153 } | 139 } |
154 case ViewTarget: { | 140 case ViewTarget: { |
155 const CharType* viewTargetStart = ptr; | 141 // Ignore arguments. |
156 skipUntil<CharType>(ptr, end, ')'); | 142 skipUntil<CharType>(ptr, end, ')'); |
157 if (ptr == viewTargetStart) | |
158 return false; | |
159 m_viewTargetString = String(viewTargetStart, ptr - viewTargetStart); | |
160 break; | 143 break; |
161 } | 144 } |
162 case ZoomAndPan: | 145 case ZoomAndPan: |
163 if (!parseZoomAndPan(ptr, end)) | 146 if (!parseZoomAndPan(ptr, end)) |
164 return false; | 147 return false; |
165 break; | 148 break; |
166 case PreserveAspectRatio: | 149 case PreserveAspectRatio: |
167 if (!preserveAspectRatio()->baseValue()->parse(ptr, end, false)) | 150 if (!preserveAspectRatio()->parse(ptr, end, false)) |
168 return false; | 151 return false; |
169 break; | 152 break; |
170 case Transform: | 153 case Transform: |
171 m_transform->baseValue()->parse(ptr, end); | 154 m_transform->parse(ptr, end); |
172 break; | 155 break; |
173 default: | 156 default: |
174 NOTREACHED(); | 157 NOTREACHED(); |
175 break; | 158 break; |
176 } | 159 } |
177 | 160 |
178 if (!skipExactly<CharType>(ptr, end, ')')) | 161 if (!skipExactly<CharType>(ptr, end, ')')) |
179 return false; | 162 return false; |
180 | 163 |
181 skipExactly<CharType>(ptr, end, ';'); | 164 skipExactly<CharType>(ptr, end, ';'); |
182 } | 165 } |
183 return skipExactly<CharType>(ptr, end, ')'); | 166 return skipExactly<CharType>(ptr, end, ')'); |
184 } | 167 } |
185 | 168 |
186 } // namespace blink | 169 } // namespace blink |
OLD | NEW |