Chromium Code Reviews| 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. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 break; | 165 break; |
| 166 case LengthTypePT: | 166 case LengthTypePT: |
| 167 userUnits = value * cssPixelsPerPoint; | 167 userUnits = value * cssPixelsPerPoint; |
| 168 break; | 168 break; |
| 169 case LengthTypePC: | 169 case LengthTypePC: |
| 170 userUnits = value * cssPixelsPerPica; | 170 userUnits = value * cssPixelsPerPica; |
| 171 break; | 171 break; |
| 172 case LengthTypeREMS: | 172 case LengthTypeREMS: |
| 173 userUnits = convertValueFromREMSToUserUnits(value); | 173 userUnits = convertValueFromREMSToUserUnits(value); |
| 174 break; | 174 break; |
| 175 case LengthTypeCHS: | |
| 176 userUnits = convertValueFromCHSToUserUnits(value); | |
| 177 break; | |
| 175 default: | 178 default: |
| 176 ASSERT_NOT_REACHED(); | 179 ASSERT_NOT_REACHED(); |
| 177 break; | 180 break; |
| 178 } | 181 } |
| 179 | 182 |
| 180 // Since we mix css <length> values with svg's length values we need to | 183 // Since we mix css <length> values with svg's length values we need to |
| 181 // clamp values to the narrowest range, otherwise it can result in | 184 // clamp values to the narrowest range, otherwise it can result in |
| 182 // rendering issues. | 185 // rendering issues. |
| 183 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits); | 186 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits); |
| 184 } | 187 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 197 // LengthTypePercentage is represented with 100% = 100.0. | 200 // LengthTypePercentage is represented with 100% = 100.0. |
| 198 // Good for accuracy but could eventually be changed. | 201 // Good for accuracy but could eventually be changed. |
| 199 return value * 100 / dimensionForLengthMode(mode, viewportSize); | 202 return value * 100 / dimensionForLengthMode(mode, viewportSize); |
| 200 } | 203 } |
| 201 case LengthTypeEMS: | 204 case LengthTypeEMS: |
| 202 return convertValueFromUserUnitsToEMS(value); | 205 return convertValueFromUserUnitsToEMS(value); |
| 203 case LengthTypeEXS: | 206 case LengthTypeEXS: |
| 204 return convertValueFromUserUnitsToEXS(value); | 207 return convertValueFromUserUnitsToEXS(value); |
| 205 case LengthTypeREMS: | 208 case LengthTypeREMS: |
| 206 return convertValueFromUserUnitsToREMS(value); | 209 return convertValueFromUserUnitsToREMS(value); |
| 210 case LengthTypeCHS: | |
| 211 return convertValueFromUserUnitsToCHS(value); | |
| 207 case LengthTypePX: | 212 case LengthTypePX: |
| 208 return value; | 213 return value; |
| 209 case LengthTypeCM: | 214 case LengthTypeCM: |
| 210 return value / cssPixelsPerCentimeter; | 215 return value / cssPixelsPerCentimeter; |
| 211 case LengthTypeMM: | 216 case LengthTypeMM: |
| 212 return value / cssPixelsPerMillimeter; | 217 return value / cssPixelsPerMillimeter; |
| 213 case LengthTypeIN: | 218 case LengthTypeIN: |
| 214 return value / cssPixelsPerInch; | 219 return value / cssPixelsPerInch; |
| 215 case LengthTypePT: | 220 case LengthTypePT: |
| 216 return value / cssPixelsPerPoint; | 221 return value / cssPixelsPerPoint; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 style = documentElement && (static_cast<const Node*>(m_context.get()) != doc umentElement) ? documentElement->computedStyle() : documentStyle; | 300 style = documentElement && (static_cast<const Node*>(m_context.get()) != doc umentElement) ? documentElement->computedStyle() : documentStyle; |
| 296 if (!style) | 301 if (!style) |
| 297 style = documentStyle; | 302 style = documentStyle; |
| 298 | 303 |
| 299 if (!style) | 304 if (!style) |
| 300 return 0; | 305 return 0; |
| 301 | 306 |
| 302 return value * style->specifiedFontSize(); | 307 return value * style->specifiedFontSize(); |
| 303 } | 308 } |
| 304 | 309 |
| 310 float SVGLengthContext::convertValueFromUserUnitsToCHS(float value) const | |
| 311 { | |
| 312 const ComputedStyle* style = computedStyleForLengthResolving(m_context); | |
| 313 if (!style) | |
| 314 return 0; | |
| 315 | |
| 316 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg | |
|
Erik Dahlström (inactive)
2015/04/10 08:43:18
This test doesn't use ch units, so this comment do
Shanmuga Pandi
2015/04/10 11:46:15
Removed comment and ceilf
| |
| 317 // if this causes problems in real world cases maybe it would be best to rem ove this | |
| 318 float zeroWidth = ceilf(style->fontMetrics().zeroWidth()); | |
| 319 if (!zeroWidth) | |
| 320 return 0; | |
| 321 | |
| 322 return value / zeroWidth; | |
| 323 } | |
| 324 | |
| 325 float SVGLengthContext::convertValueFromCHSToUserUnits(float value) const | |
| 326 { | |
| 327 const ComputedStyle* style = computedStyleForLengthResolving(m_context); | |
| 328 if (!style) | |
| 329 return 0; | |
| 330 | |
| 331 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg | |
|
Erik Dahlström (inactive)
2015/04/10 08:43:18
Same as above.
Shanmuga Pandi
2015/04/10 11:46:15
Done.
| |
| 332 // if this causes problems in real world cases maybe it would be best to rem ove this | |
| 333 return value * ceilf(style->fontMetrics().zeroWidth()); | |
| 334 } | |
| 335 | |
| 305 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const | 336 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const |
| 306 { | 337 { |
| 307 const ComputedStyle* style = computedStyleForLengthResolving(m_context); | 338 const ComputedStyle* style = computedStyleForLengthResolving(m_context); |
| 308 if (!style) | 339 if (!style) |
| 309 return 0; | 340 return 0; |
| 310 | 341 |
| 311 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg | 342 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg |
| 312 // if this causes problems in real world cases maybe it would be best to rem ove this | 343 // if this causes problems in real world cases maybe it would be best to rem ove this |
| 313 float xHeight = ceilf(style->fontMetrics().xHeight()); | 344 float xHeight = ceilf(style->fontMetrics().xHeight()); |
| 314 if (!xHeight) | 345 if (!xHeight) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 | 377 |
| 347 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); | 378 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); |
| 348 viewportSize = svg.currentViewBoxRect().size(); | 379 viewportSize = svg.currentViewBoxRect().size(); |
| 349 if (viewportSize.isEmpty()) | 380 if (viewportSize.isEmpty()) |
| 350 viewportSize = svg.currentViewportSize(); | 381 viewportSize = svg.currentViewportSize(); |
| 351 | 382 |
| 352 return true; | 383 return true; |
| 353 } | 384 } |
| 354 | 385 |
| 355 } | 386 } |
| OLD | NEW |