From 7589e34b758622dbb9903cee7d53ae947acc7858 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Tue, 6 Mar 2012 13:47:13 -0500 Subject: [PATCH] Bug 719173 - handle pixels and numbers specially in ProcessTranslatePart; r=bz, f=mattwoodrow --- layout/style/nsStyleTransformMatrix.cpp | 38 ++++++++++--------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/layout/style/nsStyleTransformMatrix.cpp b/layout/style/nsStyleTransformMatrix.cpp index 88d480804c74..5a1c8983da6d 100644 --- a/layout/style/nsStyleTransformMatrix.cpp +++ b/layout/style/nsStyleTransformMatrix.cpp @@ -39,27 +39,6 @@ static double FlushToZero(double aVal) return aVal; } -/* Helper function to fill in an nscoord with the specified nsCSSValue. */ -static nscoord CalcLength(const nsCSSValue &aValue, - nsStyleContext* aContext, - nsPresContext* aPresContext, - bool &aCanStoreInRuleTree) -{ - if (aValue.GetUnit() == eCSSUnit_Pixel || - aValue.GetUnit() == eCSSUnit_Number) { - // Handle this here (even though nsRuleNode::CalcLength handles it - // fine) so that callers are allowed to pass a null style context - // and pres context to SetToTransformFunction if they know (as - // nsStyleAnimation does) that all lengths within the transform - // function have already been computed to pixels and percents. - // - // Raw numbers are treated as being pixels. - return nsPresContext::CSSPixelsToAppUnits(aValue.GetFloatValue()); - } - return nsRuleNode::CalcLength(aValue, aContext, aPresContext, - aCanStoreInRuleTree); -} - static float ProcessTranslatePart(const nsCSSValue& aValue, nsStyleContext* aContext, @@ -72,6 +51,19 @@ ProcessTranslatePart(const nsCSSValue& aValue, if (aValue.GetUnit() == eCSSUnit_Percent) { percent = aValue.GetPercentValue(); + } else if (aValue.GetUnit() == eCSSUnit_Pixel || + aValue.GetUnit() == eCSSUnit_Number) { + // Handle this here (even though nsRuleNode::CalcLength handles it + // fine) so that callers are allowed to pass a null style context + // and pres context to SetToTransformFunction if they know (as + // nsStyleAnimation does) that all lengths within the transform + // function have already been computed to pixels and percents. + // + // Raw numbers are treated as being pixels. + // + // Don't convert to aValue to AppUnits here to avoid precision issues. + return aValue.GetFloatValue() * + (float(nsPresContext::AppUnitsPerCSSPixel()) / aAppUnitsPerMatrixUnit); } else if (aValue.IsCalcUnit()) { nsRuleNode::ComputedCalc result = nsRuleNode::SpecifiedCalcToComputedCalc(aValue, aContext, aPresContext, @@ -79,8 +71,8 @@ ProcessTranslatePart(const nsCSSValue& aValue, percent = result.mPercent; offset = result.mLength; } else { - offset = CalcLength(aValue, aContext, aPresContext, - aCanStoreInRuleTree); + offset = nsRuleNode::CalcLength(aValue, aContext, aPresContext, + aCanStoreInRuleTree); } return (percent * NSAppUnitsToFloatPixels(aSize, aAppUnitsPerMatrixUnit)) +