Chromium Code Reviews| Index: Source/core/svg/SVGLengthContext.cpp |
| diff --git a/Source/core/svg/SVGLengthContext.cpp b/Source/core/svg/SVGLengthContext.cpp |
| index 4bffd9cae72f1001a0be6c2596c167ac4e3d2c4d..c72611e191ae10752f41fce7780b4357ab67853f 100644 |
| --- a/Source/core/svg/SVGLengthContext.cpp |
| +++ b/Source/core/svg/SVGLengthContext.cpp |
| @@ -52,10 +52,10 @@ FloatRect SVGLengthContext::resolveRectangle(const SVGElement* context, SVGUnitT |
| if (type != SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE && !viewport.isEmpty()) { |
| const FloatSize& viewportSize = viewport.size(); |
| return FloatRect( |
| - convertValueFromPercentageToUserUnits(x->valueAsPercentage(), x->unitMode(), viewportSize) + viewport.x(), |
| - convertValueFromPercentageToUserUnits(y->valueAsPercentage(), y->unitMode(), viewportSize) + viewport.y(), |
| - convertValueFromPercentageToUserUnits(width->valueAsPercentage(), width->unitMode(), viewportSize), |
| - convertValueFromPercentageToUserUnits(height->valueAsPercentage(), height->unitMode(), viewportSize)); |
| + convertValueFromPercentageToUserUnits(*x, viewportSize) + viewport.x(), |
| + convertValueFromPercentageToUserUnits(*y, viewportSize) + viewport.y(), |
| + convertValueFromPercentageToUserUnits(*width, viewportSize), |
| + convertValueFromPercentageToUserUnits(*height, viewportSize)); |
| } |
| SVGLengthContext lengthContext(context); |
| @@ -102,7 +102,7 @@ float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, |
| case LengthTypePX: |
| return value; |
| case LengthTypePercentage: |
| - return convertValueFromPercentageToUserUnits(value / 100, mode, exceptionState); |
| + return convertValueFromPercentageToUserUnits(value, mode, exceptionState) / 100; |
| case LengthTypeEMS: |
| return convertValueFromEMSToUserUnits(value, exceptionState); |
| case LengthTypeEXS: |
| @@ -201,6 +201,27 @@ float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe |
| return 0; |
| } |
| +float SVGLengthContext::convertValueFromPercentageToUserUnits(const SVGLength& value, const FloatSize& viewportSize) |
| +{ |
| + float resultValue; |
| + switch (value.unitMode()) { |
| + default: |
| + 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
|
| + // Fall through. |
| + case LengthModeWidth: |
| + resultValue = value.scaleByPercentage(viewportSize.width()); |
| + break; |
| + case LengthModeHeight: |
| + resultValue = value.scaleByPercentage(viewportSize.height()); |
| + break; |
| + case LengthModeOther: |
| + resultValue = value.scaleByPercentage(sqrtf(viewportSize.diagonalLengthSquared() / 2)); |
| + break; |
| + }; |
| + |
| + return resultValue; |
| +} |
| + |
| static inline RenderStyle* renderStyleForLengthResolving(const SVGElement* context) |
| { |
| if (!context) |