OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2007 Apple Inc. All rights reserved. | 4 * Copyright (C) 2007 Apple Inc. All rights reserved. |
5 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 5 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
21 */ | 21 */ |
22 | 22 |
23 #include "config.h" | 23 #include "config.h" |
24 #include "core/svg/SVGLengthContext.h" | 24 #include "core/svg/SVGLengthContext.h" |
25 | 25 |
26 #include "core/css/CSSHelper.h" | 26 #include "core/css/CSSHelper.h" |
27 #include "core/css/CSSPrimitiveValue.h" | 27 #include "core/css/CSSPrimitiveValue.h" |
28 #include "core/layout/LayoutObject.h" | 28 #include "core/layout/LayoutObject.h" |
29 #include "core/layout/style/LayoutStyle.h" | 29 #include "core/layout/style/ComputedStyle.h" |
30 #include "core/svg/SVGSVGElement.h" | 30 #include "core/svg/SVGSVGElement.h" |
31 #include "platform/LengthFunctions.h" | 31 #include "platform/LengthFunctions.h" |
32 #include "platform/fonts/FontMetrics.h" | 32 #include "platform/fonts/FontMetrics.h" |
33 | 33 |
34 namespace blink { | 34 namespace blink { |
35 | 35 |
36 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize&
viewportSize) | 36 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize&
viewportSize) |
37 { | 37 { |
38 switch (mode) { | 38 switch (mode) { |
39 case SVGLengthMode::Width: | 39 case SVGLengthMode::Width: |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 // FIXME: valueAsPercentage() won't be correct for eg. cm units. They need t
o be resolved in user space and then be considered in objectBoundingBox space. | 96 // FIXME: valueAsPercentage() won't be correct for eg. cm units. They need t
o be resolved in user space and then be considered in objectBoundingBox space. |
97 return x.valueAsPercentage(); | 97 return x.valueAsPercentage(); |
98 } | 98 } |
99 | 99 |
100 float SVGLengthContext::valueForLength(const UnzoomedLength& unzoomedLength, SVG
LengthMode mode) const | 100 float SVGLengthContext::valueForLength(const UnzoomedLength& unzoomedLength, SVG
LengthMode mode) const |
101 { | 101 { |
102 return valueForLength(unzoomedLength.length(), 1, mode); | 102 return valueForLength(unzoomedLength.length(), 1, mode); |
103 } | 103 } |
104 | 104 |
105 float SVGLengthContext::valueForLength(const Length& length, const LayoutStyle&
style, SVGLengthMode mode) const | 105 float SVGLengthContext::valueForLength(const Length& length, const ComputedStyle
& style, SVGLengthMode mode) const |
106 { | 106 { |
107 return valueForLength(length, style.effectiveZoom(), mode); | 107 return valueForLength(length, style.effectiveZoom(), mode); |
108 } | 108 } |
109 | 109 |
110 float SVGLengthContext::valueForLength(const Length& length, float zoom, SVGLeng
thMode mode) const | 110 float SVGLengthContext::valueForLength(const Length& length, float zoom, SVGLeng
thMode mode) const |
111 { | 111 { |
112 float dimension = 0; | 112 float dimension = 0; |
113 if (length.isPercent()) { | 113 if (length.isPercent()) { |
114 FloatSize viewportSize; | 114 FloatSize viewportSize; |
115 determineViewport(viewportSize); | 115 determineViewport(viewportSize); |
116 // The viewport will be unaffected by zoom. | 116 // The viewport will be unaffected by zoom. |
117 dimension = dimensionForLengthMode(mode, viewportSize); | 117 dimension = dimensionForLengthMode(mode, viewportSize); |
118 } | 118 } |
119 return valueForLength(length, zoom, dimension); | 119 return valueForLength(length, zoom, dimension); |
120 } | 120 } |
121 | 121 |
122 float SVGLengthContext::valueForLength(const Length& length, const LayoutStyle&
style, float dimension) | 122 float SVGLengthContext::valueForLength(const Length& length, const ComputedStyle
& style, float dimension) |
123 { | 123 { |
124 return valueForLength(length, style.effectiveZoom(), dimension); | 124 return valueForLength(length, style.effectiveZoom(), dimension); |
125 } | 125 } |
126 | 126 |
127 float SVGLengthContext::valueForLength(const Length& length, float zoom, float d
imension) | 127 float SVGLengthContext::valueForLength(const Length& length, float zoom, float d
imension) |
128 { | 128 { |
129 ASSERT(zoom != 0); | 129 ASSERT(zoom != 0); |
130 return floatValueForLength(length, dimension * zoom) / zoom; | 130 return floatValueForLength(length, dimension * zoom) / zoom; |
131 } | 131 } |
132 | 132 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 case LengthTypePT: | 209 case LengthTypePT: |
210 return value / cssPixelsPerPoint; | 210 return value / cssPixelsPerPoint; |
211 case LengthTypePC: | 211 case LengthTypePC: |
212 return value / cssPixelsPerPica; | 212 return value / cssPixelsPerPica; |
213 } | 213 } |
214 | 214 |
215 ASSERT_NOT_REACHED(); | 215 ASSERT_NOT_REACHED(); |
216 return 0; | 216 return 0; |
217 } | 217 } |
218 | 218 |
219 static inline const LayoutStyle* layoutStyleForLengthResolving(const SVGElement*
context) | 219 static inline const ComputedStyle* computedStyleForLengthResolving(const SVGElem
ent* context) |
220 { | 220 { |
221 if (!context) | 221 if (!context) |
222 return 0; | 222 return 0; |
223 | 223 |
224 const ContainerNode* currentContext = context; | 224 const ContainerNode* currentContext = context; |
225 do { | 225 do { |
226 if (currentContext->layoutObject()) | 226 if (currentContext->layoutObject()) |
227 return currentContext->layoutObject()->style(); | 227 return currentContext->layoutObject()->style(); |
228 currentContext = currentContext->parentNode(); | 228 currentContext = currentContext->parentNode(); |
229 } while (currentContext); | 229 } while (currentContext); |
230 | 230 |
231 // There must be at least a LayoutSVGRoot renderer, carrying a style. | 231 // There must be at least a LayoutSVGRoot renderer, carrying a style. |
232 ASSERT_NOT_REACHED(); | 232 ASSERT_NOT_REACHED(); |
233 return 0; | 233 return 0; |
234 } | 234 } |
235 | 235 |
236 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value) const | 236 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value) const |
237 { | 237 { |
238 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 238 const ComputedStyle* style = computedStyleForLengthResolving(m_context); |
239 if (!style) | 239 if (!style) |
240 return 0; | 240 return 0; |
241 | 241 |
242 float fontSize = style->specifiedFontSize(); | 242 float fontSize = style->specifiedFontSize(); |
243 if (!fontSize) | 243 if (!fontSize) |
244 return 0; | 244 return 0; |
245 | 245 |
246 return value / fontSize; | 246 return value / fontSize; |
247 } | 247 } |
248 | 248 |
249 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const | 249 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const |
250 { | 250 { |
251 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 251 const ComputedStyle* style = computedStyleForLengthResolving(m_context); |
252 if (!style) | 252 if (!style) |
253 return 0; | 253 return 0; |
254 return value * style->specifiedFontSize(); | 254 return value * style->specifiedFontSize(); |
255 } | 255 } |
256 | 256 |
257 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const | 257 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const |
258 { | 258 { |
259 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 259 const ComputedStyle* style = computedStyleForLengthResolving(m_context); |
260 if (!style) | 260 if (!style) |
261 return 0; | 261 return 0; |
262 | 262 |
263 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg | 263 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg |
264 // if this causes problems in real world cases maybe it would be best to rem
ove this | 264 // if this causes problems in real world cases maybe it would be best to rem
ove this |
265 float xHeight = ceilf(style->fontMetrics().xHeight()); | 265 float xHeight = ceilf(style->fontMetrics().xHeight()); |
266 if (!xHeight) | 266 if (!xHeight) |
267 return 0; | 267 return 0; |
268 | 268 |
269 return value / xHeight; | 269 return value / xHeight; |
270 } | 270 } |
271 | 271 |
272 float SVGLengthContext::convertValueFromEXSToUserUnits(float value) const | 272 float SVGLengthContext::convertValueFromEXSToUserUnits(float value) const |
273 { | 273 { |
274 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 274 const ComputedStyle* style = computedStyleForLengthResolving(m_context); |
275 if (!style) | 275 if (!style) |
276 return 0; | 276 return 0; |
277 | 277 |
278 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg | 278 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un
its-03-b.svg |
279 // if this causes problems in real world cases maybe it would be best to rem
ove this | 279 // if this causes problems in real world cases maybe it would be best to rem
ove this |
280 return value * ceilf(style->fontMetrics().xHeight()); | 280 return value * ceilf(style->fontMetrics().xHeight()); |
281 } | 281 } |
282 | 282 |
283 bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const | 283 bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const |
284 { | 284 { |
(...skipping 13 matching lines...) Expand all Loading... |
298 | 298 |
299 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); | 299 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); |
300 viewportSize = svg.currentViewBoxRect().size(); | 300 viewportSize = svg.currentViewBoxRect().size(); |
301 if (viewportSize.isEmpty()) | 301 if (viewportSize.isEmpty()) |
302 viewportSize = svg.currentViewportSize(); | 302 viewportSize = svg.currentViewportSize(); |
303 | 303 |
304 return true; | 304 return true; |
305 } | 305 } |
306 | 306 |
307 } | 307 } |
OLD | NEW |