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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 { | 45 { |
| 46 RefPtrWillBeRawPtr<SVGLength> x = passX; | 46 RefPtrWillBeRawPtr<SVGLength> x = passX; |
| 47 RefPtrWillBeRawPtr<SVGLength> y = passY; | 47 RefPtrWillBeRawPtr<SVGLength> y = passY; |
| 48 RefPtrWillBeRawPtr<SVGLength> width = passWidth; | 48 RefPtrWillBeRawPtr<SVGLength> width = passWidth; |
| 49 RefPtrWillBeRawPtr<SVGLength> height = passHeight; | 49 RefPtrWillBeRawPtr<SVGLength> height = passHeight; |
| 50 | 50 |
| 51 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN); | 51 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN); |
| 52 if (type != SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE && !viewport.isEmpty( )) { | 52 if (type != SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE && !viewport.isEmpty( )) { |
| 53 const FloatSize& viewportSize = viewport.size(); | 53 const FloatSize& viewportSize = viewport.size(); |
| 54 return FloatRect( | 54 return FloatRect( |
| 55 convertValueFromPercentageToUserUnits(x->valueAsPercentage(), x->uni tMode(), viewportSize) + viewport.x(), | 55 convertValueFromPercentageToUserUnits(*x, viewportSize) + viewport.x (), |
| 56 convertValueFromPercentageToUserUnits(y->valueAsPercentage(), y->uni tMode(), viewportSize) + viewport.y(), | 56 convertValueFromPercentageToUserUnits(*y, viewportSize) + viewport.y (), |
| 57 convertValueFromPercentageToUserUnits(width->valueAsPercentage(), wi dth->unitMode(), viewportSize), | 57 convertValueFromPercentageToUserUnits(*width, viewportSize), |
| 58 convertValueFromPercentageToUserUnits(height->valueAsPercentage(), h eight->unitMode(), viewportSize)); | 58 convertValueFromPercentageToUserUnits(*height, viewportSize)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 SVGLengthContext lengthContext(context); | 61 SVGLengthContext lengthContext(context); |
| 62 return FloatRect(x->value(lengthContext), y->value(lengthContext), width->va lue(lengthContext), height->value(lengthContext)); | 62 return FloatRect(x->value(lengthContext), y->value(lengthContext), width->va lue(lengthContext), height->value(lengthContext)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 FloatPoint SVGLengthContext::resolvePoint(const SVGElement* context, SVGUnitType s::SVGUnitType type, PassRefPtrWillBeRawPtr<SVGLength> passX, PassRefPtrWillBeRa wPtr<SVGLength> passY) | 65 FloatPoint SVGLengthContext::resolvePoint(const SVGElement* context, SVGUnitType s::SVGUnitType type, PassRefPtrWillBeRawPtr<SVGLength> passX, PassRefPtrWillBeRa wPtr<SVGLength> passY) |
| 66 { | 66 { |
| 67 RefPtrWillBeRawPtr<SVGLength> x = passX; | 67 RefPtrWillBeRawPtr<SVGLength> x = passX; |
| 68 RefPtrWillBeRawPtr<SVGLength> y = passY; | 68 RefPtrWillBeRawPtr<SVGLength> y = passY; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 95 { | 95 { |
| 96 switch (fromUnit) { | 96 switch (fromUnit) { |
| 97 case LengthTypeUnknown: | 97 case LengthTypeUnknown: |
| 98 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::a rgumentNullOrIncorrectType(3, "SVGLengthType")); | 98 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::a rgumentNullOrIncorrectType(3, "SVGLengthType")); |
| 99 return 0; | 99 return 0; |
| 100 case LengthTypeNumber: | 100 case LengthTypeNumber: |
| 101 return value; | 101 return value; |
| 102 case LengthTypePX: | 102 case LengthTypePX: |
| 103 return value; | 103 return value; |
| 104 case LengthTypePercentage: | 104 case LengthTypePercentage: |
| 105 return convertValueFromPercentageToUserUnits(value / 100, mode, exceptio nState); | 105 return convertValueFromPercentageToUserUnits(value, mode, exceptionState ) / 100; |
| 106 case LengthTypeEMS: | 106 case LengthTypeEMS: |
| 107 return convertValueFromEMSToUserUnits(value, exceptionState); | 107 return convertValueFromEMSToUserUnits(value, exceptionState); |
| 108 case LengthTypeEXS: | 108 case LengthTypeEXS: |
| 109 return convertValueFromEXSToUserUnits(value, exceptionState); | 109 return convertValueFromEXSToUserUnits(value, exceptionState); |
| 110 case LengthTypeCM: | 110 case LengthTypeCM: |
| 111 return value * cssPixelsPerCentimeter; | 111 return value * cssPixelsPerCentimeter; |
| 112 case LengthTypeMM: | 112 case LengthTypeMM: |
| 113 return value * cssPixelsPerMillimeter; | 113 return value * cssPixelsPerMillimeter; |
| 114 case LengthTypeIN: | 114 case LengthTypeIN: |
| 115 return value * cssPixelsPerInch; | 115 return value * cssPixelsPerInch; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 case LengthModeHeight: | 194 case LengthModeHeight: |
| 195 return value * viewportSize.height(); | 195 return value * viewportSize.height(); |
| 196 case LengthModeOther: | 196 case LengthModeOther: |
| 197 return value * sqrtf(viewportSize.diagonalLengthSquared() / 2); | 197 return value * sqrtf(viewportSize.diagonalLengthSquared() / 2); |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 ASSERT_NOT_REACHED(); | 200 ASSERT_NOT_REACHED(); |
| 201 return 0; | 201 return 0; |
| 202 } | 202 } |
| 203 | 203 |
| 204 float SVGLengthContext::convertValueFromPercentageToUserUnits(const SVGLength& v alue, const FloatSize& viewportSize) | |
| 205 { | |
| 206 float resultValue; | |
| 207 switch (value.unitMode()) { | |
| 208 default: | |
| 209 ASSERT_NOT_REACHED(); | |
|
fs
2015/01/22 12:37:36
I'd prefer to structure this new function like the
Daniel Bratell
2015/01/22 13:13:44
Ok.
I do like this structure though because it ge
fs
2015/01/22 14:06:35
Well saying that it generates better code is a bol
| |
| 210 // Fall through. | |
| 211 case LengthModeWidth: | |
| 212 resultValue = value.scaleByPercentage(viewportSize.width()); | |
| 213 break; | |
| 214 case LengthModeHeight: | |
| 215 resultValue = value.scaleByPercentage(viewportSize.height()); | |
| 216 break; | |
| 217 case LengthModeOther: | |
| 218 resultValue = value.scaleByPercentage(sqrtf(viewportSize.diagonalLengthS quared() / 2)); | |
| 219 break; | |
| 220 }; | |
| 221 | |
| 222 return resultValue; | |
| 223 } | |
| 224 | |
| 204 static inline RenderStyle* renderStyleForLengthResolving(const SVGElement* conte xt) | 225 static inline RenderStyle* renderStyleForLengthResolving(const SVGElement* conte xt) |
| 205 { | 226 { |
| 206 if (!context) | 227 if (!context) |
| 207 return 0; | 228 return 0; |
| 208 | 229 |
| 209 const ContainerNode* currentContext = context; | 230 const ContainerNode* currentContext = context; |
| 210 do { | 231 do { |
| 211 if (currentContext->renderer()) | 232 if (currentContext->renderer()) |
| 212 return currentContext->renderer()->style(); | 233 return currentContext->renderer()->style(); |
| 213 currentContext = currentContext->parentNode(); | 234 currentContext = currentContext->parentNode(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 | 317 |
| 297 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); | 318 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); |
| 298 viewportSize = svg.currentViewBoxRect().size(); | 319 viewportSize = svg.currentViewBoxRect().size(); |
| 299 if (viewportSize.isEmpty()) | 320 if (viewportSize.isEmpty()) |
| 300 viewportSize = svg.currentViewportSize(); | 321 viewportSize = svg.currentViewportSize(); |
| 301 | 322 |
| 302 return true; | 323 return true; |
| 303 } | 324 } |
| 304 | 325 |
| 305 } | 326 } |
| OLD | NEW |