diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 51f1bc200a7..b046b0d8393 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -509,6 +509,56 @@ SpecifiedCalcToComputedCalc(const nsCSSValue& aValue, nsStyleCoord& aCoord, aCoord = ComputeCalc(aValue, ops); } +struct ComputeComputedCalcCalcOps : public css::BasicCoordCalcOps +{ + typedef nsStyleCoord input_type; + typedef nsStyleCoord::Array input_array_type; + + static nsCSSUnit GetUnit(const nsStyleCoord& aValue) + { + if (aValue.IsCalcUnit()) { + return css::ConvertCalcUnit(aValue.GetUnit()); + } + return eCSSUnit_Null; + } + + const nscoord mPercentageBasis; + + ComputeComputedCalcCalcOps(nscoord aPercentageBasis) + : mPercentageBasis(aPercentageBasis) + { + } + + result_type ComputeLeafValue(const nsStyleCoord& aValue) + { + nscoord result; + if (aValue.GetUnit() == eStyleUnit_Percent) { + result = NSCoordSaturatingMultiply(mPercentageBasis, + aValue.GetPercentValue()); + } else { + result = aValue.GetCoordValue(); + } + return result; + } + + float ComputeNumber(const nsStyleCoord& aValue) + { + NS_ABORT_IF_FALSE(PR_FALSE, "SpecifiedToComputedCalcOps should not " + "leave numbers in structure"); + return 0.0f; + } +}; + +// This is our public API for handling calc() expressions that involve +// percentages. +/* static */ nscoord +nsRuleNode::ComputeComputedCalc(const nsStyleCoord& aValue, + nscoord aPercentageBasis) +{ + ComputeComputedCalcCalcOps ops(aPercentageBasis); + return css::ComputeCalc(aValue, ops); +} + #define SETCOORD_NORMAL 0x01 // N #define SETCOORD_AUTO 0x02 // A #define SETCOORD_INHERIT 0x04 // H diff --git a/layout/style/nsRuleNode.h b/layout/style/nsRuleNode.h index 6f6c230df35..6ac659b3091 100644 --- a/layout/style/nsRuleNode.h +++ b/layout/style/nsRuleNode.h @@ -756,6 +756,12 @@ public: nsPresContext* aPresContext, PRBool& aCanStoreInRuleTree); + // Compute the value of an nsStyleCoord that IsCalcUnit(). + // (Values that don't require aPercentageBasis should be handled + // inside nsRuleNode rather than through this API.) + static nscoord ComputeComputedCalc(const nsStyleCoord& aCoord, + nscoord aPercentageBasis); + // Return whether the rule tree for which this node is the root has // cached data such that we need to do dynamic change handling for // changes that change the results of media queries or require