From 6d89485bb69b69a7d8e48400a33f29e139a2c168 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Fri, 2 Jul 2010 21:18:55 -0700 Subject: [PATCH] Add API to compute length, percentage or calc() style coords. (Bug 363249) r=bzbarsky --- layout/style/nsRuleNode.cpp | 16 ++++++++++++++++ layout/style/nsRuleNode.h | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index b046b0d8393..c9431b167aa 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -559,6 +559,22 @@ nsRuleNode::ComputeComputedCalc(const nsStyleCoord& aValue, return css::ComputeCalc(aValue, ops); } +/* static */ nscoord +nsRuleNode::ComputeCoordPercentCalc(const nsStyleCoord& aCoord, + nscoord aPercentageBasis) +{ + switch (aCoord.GetUnit()) { + case eStyleUnit_Coord: + return aCoord.GetCoordValue(); + case eStyleUnit_Percent: + return NSCoordSaturatingMultiply(aPercentageBasis, + aCoord.GetPercentValue()); + default: + NS_ABORT_IF_FALSE(aCoord.IsCalcUnit(), "unexpected unit"); + return nsRuleNode::ComputeComputedCalc(aCoord, aPercentageBasis); + } +} + #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 6ac659b3091..5d9a0c92fb0 100644 --- a/layout/style/nsRuleNode.h +++ b/layout/style/nsRuleNode.h @@ -62,6 +62,8 @@ struct nsRuleDataFont; class nsCSSValue; struct nsCSSRect; +class nsStyleCoord; + struct nsInheritedStyleData { @@ -762,6 +764,11 @@ public: static nscoord ComputeComputedCalc(const nsStyleCoord& aCoord, nscoord aPercentageBasis); + // Compute the value of an nsStyleCoord that is either a coord, a + // percent, or a calc expression. + static nscoord ComputeCoordPercentCalc(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