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/dom/NodeLayoutStyle.h" | |
28 #include "core/layout/LayoutObject.h" | 29 #include "core/layout/LayoutObject.h" |
29 #include "core/layout/style/LayoutStyle.h" | 30 #include "core/layout/style/LayoutStyle.h" |
30 #include "core/svg/SVGSVGElement.h" | 31 #include "core/svg/SVGSVGElement.h" |
31 #include "platform/LengthFunctions.h" | 32 #include "platform/LengthFunctions.h" |
32 #include "platform/fonts/FontMetrics.h" | 33 #include "platform/fonts/FontMetrics.h" |
33 | 34 |
34 namespace blink { | 35 namespace blink { |
35 | 36 |
36 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize) | 37 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize) |
37 { | 38 { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 break; | 162 break; |
162 case LengthTypeIN: | 163 case LengthTypeIN: |
163 userUnits = value * cssPixelsPerInch; | 164 userUnits = value * cssPixelsPerInch; |
164 break; | 165 break; |
165 case LengthTypePT: | 166 case LengthTypePT: |
166 userUnits = value * cssPixelsPerPoint; | 167 userUnits = value * cssPixelsPerPoint; |
167 break; | 168 break; |
168 case LengthTypePC: | 169 case LengthTypePC: |
169 userUnits = value * cssPixelsPerPica; | 170 userUnits = value * cssPixelsPerPica; |
170 break; | 171 break; |
172 case LengthTypeREMS: | |
173 userUnits = convertValueFromREMSToUserUnits(value); | |
174 break; | |
171 default: | 175 default: |
172 ASSERT_NOT_REACHED(); | 176 ASSERT_NOT_REACHED(); |
173 break; | 177 break; |
174 } | 178 } |
175 | 179 |
176 // Since we mix css <length> values with svg's length values we need to | 180 // Since we mix css <length> values with svg's length values we need to |
177 // clamp values to the narrowest range, otherwise it can result in | 181 // clamp values to the narrowest range, otherwise it can result in |
178 // rendering issues. | 182 // rendering issues. |
179 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits); | 183 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits); |
180 } | 184 } |
(...skipping 10 matching lines...) Expand all Loading... | |
191 if (!determineViewport(viewportSize)) | 195 if (!determineViewport(viewportSize)) |
192 return 0; | 196 return 0; |
193 // LengthTypePercentage is represented with 100% = 100.0. | 197 // LengthTypePercentage is represented with 100% = 100.0. |
194 // Good for accuracy but could eventually be changed. | 198 // Good for accuracy but could eventually be changed. |
195 return value * 100 / dimensionForLengthMode(mode, viewportSize); | 199 return value * 100 / dimensionForLengthMode(mode, viewportSize); |
196 } | 200 } |
197 case LengthTypeEMS: | 201 case LengthTypeEMS: |
198 return convertValueFromUserUnitsToEMS(value); | 202 return convertValueFromUserUnitsToEMS(value); |
199 case LengthTypeEXS: | 203 case LengthTypeEXS: |
200 return convertValueFromUserUnitsToEXS(value); | 204 return convertValueFromUserUnitsToEXS(value); |
205 case LengthTypeREMS: | |
206 return convertValueFromUserUnitsToREMS(value); | |
201 case LengthTypePX: | 207 case LengthTypePX: |
202 return value; | 208 return value; |
203 case LengthTypeCM: | 209 case LengthTypeCM: |
204 return value / cssPixelsPerCentimeter; | 210 return value / cssPixelsPerCentimeter; |
205 case LengthTypeMM: | 211 case LengthTypeMM: |
206 return value / cssPixelsPerMillimeter; | 212 return value / cssPixelsPerMillimeter; |
207 case LengthTypeIN: | 213 case LengthTypeIN: |
208 return value / cssPixelsPerInch; | 214 return value / cssPixelsPerInch; |
209 case LengthTypePT: | 215 case LengthTypePT: |
210 return value / cssPixelsPerPoint; | 216 return value / cssPixelsPerPoint; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 } | 253 } |
248 | 254 |
249 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const | 255 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const |
250 { | 256 { |
251 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 257 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); |
252 if (!style) | 258 if (!style) |
253 return 0; | 259 return 0; |
254 return value * style->specifiedFontSize(); | 260 return value * style->specifiedFontSize(); |
255 } | 261 } |
256 | 262 |
263 float SVGLengthContext::convertValueFromUserUnitsToREMS(float value) const | |
264 { | |
265 if (!m_context) | |
266 return 0; | |
267 | |
268 const LayoutStyle* style = 0; | |
269 const ContainerNode* currentContext = m_context; | |
270 | |
271 do { | |
272 if (currentContext->layoutObject()) { | |
Erik Dahlström (inactive)
2015/04/02 07:58:41
Do we really need this loop? Why not just fetch th
Shanmuga Pandi
2015/04/02 13:06:51
Done.
| |
273 const Document& document = currentContext->layoutObject()->document( ); | |
274 Node* documentElement = document.documentElement(); | |
275 const LayoutStyle* documentStyle = document.layoutStyle(); | |
276 style = documentElement && !currentContext->layoutObject()->isDocume ntElement() ? documentElement->layoutStyle() : documentStyle; | |
277 if (!style) | |
278 style = documentStyle; | |
279 break; | |
280 } | |
281 currentContext = currentContext->parentNode(); | |
282 } while (currentContext); | |
283 | |
284 if (!style) | |
285 return 0; | |
286 | |
287 float fontSize = style->specifiedFontSize(); | |
288 if (!fontSize) | |
289 return 0; | |
290 | |
291 return value / fontSize; | |
292 } | |
293 | |
294 float SVGLengthContext::convertValueFromREMSToUserUnits(float value) const | |
295 { | |
296 if (!m_context) | |
297 return 0; | |
298 | |
299 const LayoutStyle* style = 0; | |
300 const ContainerNode* currentContext = m_context; | |
301 | |
302 do { | |
303 if (currentContext->layoutObject()) { | |
304 const Document& document = currentContext->layoutObject()->document( ); | |
305 Node* documentElement = document.documentElement(); | |
306 const LayoutStyle* documentStyle = document.layoutStyle(); | |
307 style = documentElement && !currentContext->layoutObject()->isDocume ntElement() ? documentElement->layoutStyle() : documentStyle; | |
308 if (!style) | |
309 style = documentStyle; | |
310 break; | |
311 } | |
312 currentContext = currentContext->parentNode(); | |
313 } while (currentContext); | |
314 | |
315 if (!style) | |
316 return 0; | |
317 return value * style->specifiedFontSize(); | |
318 } | |
319 | |
257 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const | 320 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const |
258 { | 321 { |
259 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); | 322 const LayoutStyle* style = layoutStyleForLengthResolving(m_context); |
260 if (!style) | 323 if (!style) |
261 return 0; | 324 return 0; |
262 | 325 |
263 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg | 326 // 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 | 327 // if this causes problems in real world cases maybe it would be best to rem ove this |
265 float xHeight = ceilf(style->fontMetrics().xHeight()); | 328 float xHeight = ceilf(style->fontMetrics().xHeight()); |
266 if (!xHeight) | 329 if (!xHeight) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 | 361 |
299 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); | 362 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); |
300 viewportSize = svg.currentViewBoxRect().size(); | 363 viewportSize = svg.currentViewBoxRect().size(); |
301 if (viewportSize.isEmpty()) | 364 if (viewportSize.isEmpty()) |
302 viewportSize = svg.currentViewportSize(); | 365 viewportSize = svg.currentViewportSize(); |
303 | 366 |
304 return true; | 367 return true; |
305 } | 368 } |
306 | 369 |
307 } | 370 } |
OLD | NEW |