Bug 1418905 - Move nsRuleNode::ComputeComputedCalc() into nsStyleCoord.
MozReview-Commit-ID: LFxZGzyyii6
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -4822,17 +4822,17 @@ nsLayoutUtils::IsViewportScrollbarFrame(
// negative calc() results to 0.
static bool GetAbsoluteCoord(const nsStyleCoord& aStyle, nscoord& aResult)
{
if (aStyle.IsCalcUnit()) {
if (aStyle.CalcHasPercent()) {
return false;
}
// If it has no percents, we can pass 0 for the percentage basis.
- aResult = nsRuleNode::ComputeComputedCalc(aStyle, 0);
+ aResult = aStyle.ComputeComputedCalc(0);
if (aResult < 0)
aResult = 0;
return true;
}
if (eStyleUnit_Coord != aStyle.GetUnit())
return false;
@@ -4935,17 +4935,17 @@ GetPercentBSize(const nsStyleCoord& aSty
// here. That could conceivably cause some problems with fieldsets (which are
// the one place that wants to ignore padding), but solving that here without
// hardcoding a check for f being a fieldset-content frame is a bit of a pain.
nscoord bSizeTakenByBoxSizing =
GetBSizeTakenByBoxSizing(pos->mBoxSizing, f, aHorizontalAxis, false);
h = std::max(0, h - bSizeTakenByBoxSizing);
if (aStyle.IsCalcUnit()) {
- aResult = std::max(nsRuleNode::ComputeComputedCalc(aStyle, h), 0);
+ aResult = std::max(aStyle.ComputeComputedCalc(h), 0);
return true;
}
aResult = NSToCoordRound(aStyle.GetPercentValue() * h);
return true;
}
// Return true if aStyle can be resolved to a definite value and if so
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -843,38 +843,27 @@ nsRuleNode::SpecifiedCalcToComputedCalc(
aConditions);
nsRuleNode::ComputedCalc result;
if (!ComputeCalc(result, aValue, ops)) {
MOZ_ASSERT_UNREACHABLE("unexpected ComputeCalc failure");
}
return result;
}
-// This is our public API for handling calc() expressions that involve
-// percentages.
-/* static */ nscoord
-nsRuleNode::ComputeComputedCalc(const nsStyleCoord& aValue,
- nscoord aPercentageBasis)
-{
- nsStyleCoord::Calc* calc = aValue.GetCalcValue();
- return calc->mLength +
- NSToCoordFloorClamped(aPercentageBasis * calc->mPercent);
-}
-
/* static */ nscoord
nsRuleNode::ComputeCoordPercentCalc(const nsStyleCoord& aCoord,
nscoord aPercentageBasis)
{
switch (aCoord.GetUnit()) {
case eStyleUnit_Coord:
return aCoord.GetCoordValue();
case eStyleUnit_Percent:
return NSToCoordFloorClamped(aPercentageBasis * aCoord.GetPercentValue());
case eStyleUnit_Calc:
- return ComputeComputedCalc(aCoord, aPercentageBasis);
+ return aCoord.ComputeComputedCalc(aPercentageBasis);
default:
MOZ_ASSERT(false, "unexpected unit");
return 0;
}
}
/* Given an enumerated value that represents a box position, converts it to
* a float representing the percentage of the box it corresponds to. For
--- a/layout/style/nsRuleNode.h
+++ b/layout/style/nsRuleNode.h
@@ -1039,25 +1039,16 @@ public:
: mLength(aLength), mPercent(aPercent) {}
};
static ComputedCalc
SpecifiedCalcToComputedCalc(const nsCSSValue& aValue,
nsStyleContext* aStyleContext,
nsPresContext* aPresContext,
mozilla::RuleNodeCacheConditions& aConditions);
- // Compute the value of an nsStyleCoord that IsCalcUnit().
- // (Values that don't require aPercentageBasis should be handled
- // inside nsRuleNode rather than through this API.)
- // @note the caller is expected to handle percentage of an indefinite size
- // and NOT call this method with aPercentageBasis == NS_UNCONSTRAINEDSIZE.
- // @note the return value may be negative, e.g. for "calc(a - b%)"
- 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.
// @note the caller is expected to handle percentage of an indefinite size
// and NOT call this method with aPercentageBasis == NS_UNCONSTRAINEDSIZE.
// @note the return value may be negative, e.g. for "calc(a - b%)"
static nscoord ComputeCoordPercentCalc(const nsStyleCoord& aCoord,
nscoord aPercentageBasis);
--- a/layout/style/nsStyleCoord.cpp
+++ b/layout/style/nsStyleCoord.cpp
@@ -193,16 +193,24 @@ nsStyleCoord::GetAngleValueInRadians() c
case eStyleUnit_Grad: return angle * M_PI / 200.0;
default:
NS_NOTREACHED("unrecognized angular unit");
return 0.0;
}
}
+nscoord
+nsStyleCoord::ComputeComputedCalc(nscoord aPercentageBasis) const
+{
+ Calc* calc = GetCalcValue();
+ return calc->mLength +
+ NSToCoordFloorClamped(aPercentageBasis * calc->mPercent);
+}
+
nsStyleSides::nsStyleSides()
{
NS_FOR_CSS_SIDES(i) {
mUnits[i] = eStyleUnit_Null;
}
mozilla::PodArrayZero(mValues);
}
--- a/layout/style/nsStyleCoord.h
+++ b/layout/style/nsStyleCoord.h
@@ -210,16 +210,22 @@ public:
return ToLength(GetUnit(), mValue);
}
// Callers must verify IsCalcUnit before calling this function.
static Calc* AsCalcValue(nsStyleUnion aValue) {
return static_cast<Calc*>(aValue.mPointer);
}
+ // Compute the value that IsCalcUnit().
+ // @note the caller is expected to handle percentage of an indefinite size
+ // and NOT call this method with aPercentageBasis == NS_UNCONSTRAINEDSIZE.
+ // @note the return value may be negative, e.g. for "calc(a - b%)"
+ nscoord ComputeComputedCalc(nscoord aPercentageBasis) const;
+
nscoord GetCoordValue() const;
int32_t GetIntValue() const;
float GetPercentValue() const;
float GetFactorValue() const;
float GetFactorOrPercentValue() const;
float GetAngleValue() const;
double GetAngleValueInDegrees() const;
double GetAngleValueInRadians() const;
--- a/layout/xul/nsBox.cpp
+++ b/layout/xul/nsBox.cpp
@@ -602,31 +602,31 @@ nsIFrame::AddXULPrefSize(nsIFrame* aBox,
// (min-/max-/)(width/height) properties.)
const nsStyleCoord &width = position->mWidth;
if (width.GetUnit() == eStyleUnit_Coord) {
aSize.width = width.GetCoordValue();
aWidthSet = true;
} else if (width.IsCalcUnit()) {
if (!width.CalcHasPercent()) {
// pass 0 for percentage basis since we know there are no %s
- aSize.width = nsRuleNode::ComputeComputedCalc(width, 0);
+ aSize.width = width.ComputeComputedCalc(0);
if (aSize.width < 0)
aSize.width = 0;
aWidthSet = true;
}
}
const nsStyleCoord &height = position->mHeight;
if (height.GetUnit() == eStyleUnit_Coord) {
aSize.height = height.GetCoordValue();
aHeightSet = true;
} else if (height.IsCalcUnit()) {
if (!height.CalcHasPercent()) {
// pass 0 for percentage basis since we know there are no %s
- aSize.height = nsRuleNode::ComputeComputedCalc(height, 0);
+ aSize.height = height.ComputeComputedCalc(0);
if (aSize.height < 0)
aSize.height = 0;
aHeightSet = true;
}
}
nsIContent* content = aBox->GetContent();
// ignore 'height' and 'width' attributes if the actual element is not XUL