Bug 1418905 - Move nsRuleNode::ComputeComputedCalc() into nsStyleCoord. r=heycam

MozReview-Commit-ID: LFxZGzyyii6

--HG--
extra : rebase_source : 516a8ed1a372d483f4c96cd392c1d382b0b4e38a
This commit is contained in:
Ting-Yu Lin 2017-11-20 13:30:27 +08:00
Родитель c949aef52f
Коммит 320b123d4b
6 изменённых файлов: 19 добавлений и 25 удалений

Просмотреть файл

@ -4859,7 +4859,7 @@ static bool GetAbsoluteCoord(const nsStyleCoord& aStyle, nscoord& aResult)
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;
@ -4972,7 +4972,7 @@ GetPercentBSize(const nsStyleCoord& aStyle,
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;
}

Просмотреть файл

@ -848,17 +848,6 @@ nsRuleNode::SpecifiedCalcToComputedCalc(const nsCSSValue& aValue,
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)
@ -869,7 +858,7 @@ nsRuleNode::ComputeCoordPercentCalc(const nsStyleCoord& aCoord,
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;

Просмотреть файл

@ -1044,15 +1044,6 @@ public:
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

Просмотреть файл

@ -198,6 +198,14 @@ nsStyleCoord::GetAngleValueInRadians() const
}
}
nscoord
nsStyleCoord::ComputeComputedCalc(nscoord aPercentageBasis) const
{
Calc* calc = GetCalcValue();
return calc->mLength +
NSToCoordFloorClamped(aPercentageBasis * calc->mPercent);
}
nsStyleSides::nsStyleSides()
{
NS_FOR_CSS_SIDES(i) {

Просмотреть файл

@ -215,6 +215,12 @@ public:
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;

Просмотреть файл

@ -607,7 +607,7 @@ nsIFrame::AddXULPrefSize(nsIFrame* aBox, nsSize& aSize, bool &aWidthSet, bool &a
} 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;
@ -621,7 +621,7 @@ nsIFrame::AddXULPrefSize(nsIFrame* aBox, nsSize& aSize, bool &aWidthSet, bool &a
} 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;