--- a/layout/base/ShapeUtils.cpp
+++ b/layout/base/ShapeUtils.cpp
@@ -5,17 +5,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ShapeUtils.h"
#include <cstdlib>
#include "nsCSSRendering.h"
#include "nsMargin.h"
-#include "nsRuleNode.h"
#include "nsStyleCoord.h"
#include "nsStyleStruct.h"
#include "SVGContentUtils.h"
namespace mozilla {
nscoord
ShapeUtils::ComputeShapeRadius(const StyleShapeRadius aType,
@@ -74,18 +73,17 @@ ShapeUtils::ComputeCircleRadius(const Un
? std::max(horizontal, vertical)
: std::min(horizontal, vertical);
} else {
// We resolve percent <shape-radius> value for circle() as defined here:
// https://drafts.csswg.org/css-shapes/#funcdef-circle
double referenceLength =
SVGContentUtils::ComputeNormalizedHypotenuse(aRefBox.width,
aRefBox.height);
- r = nsRuleNode::ComputeCoordPercentCalc(coords[0],
- NSToCoordRound(referenceLength));
+ r = coords[0].ComputeCoordPercentCalc(NSToCoordRound(referenceLength));
}
return r;
}
nsSize
ShapeUtils::ComputeEllipseRadii(const UniquePtr<StyleBasicShape>& aBasicShape,
const nsPoint& aCenter,
const nsRect& aRefBox)
@@ -97,44 +95,44 @@ ShapeUtils::ComputeEllipseRadii(const Un
MOZ_ASSERT(coords.Length() == 2, "wrong number of arguments");
nsSize radii;
if (coords[0].GetUnit() == eStyleUnit_Enumerated) {
const StyleShapeRadius radiusX = coords[0].GetEnumValue<StyleShapeRadius>();
radii.width = ComputeShapeRadius(radiusX, aCenter.x, aRefBox.x,
aRefBox.XMost());
} else {
- radii.width = nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.width);
+ radii.width = coords[0].ComputeCoordPercentCalc(aRefBox.width);
}
if (coords[1].GetUnit() == eStyleUnit_Enumerated) {
const StyleShapeRadius radiusY = coords[1].GetEnumValue<StyleShapeRadius>();
radii.height = ComputeShapeRadius(radiusY, aCenter.y, aRefBox.y,
aRefBox.YMost());
} else {
- radii.height = nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.height);
+ radii.height = coords[1].ComputeCoordPercentCalc(aRefBox.height);
}
return radii;
}
/* static */ nsRect
ShapeUtils::ComputeInsetRect(const UniquePtr<StyleBasicShape>& aBasicShape,
const nsRect& aRefBox)
{
MOZ_ASSERT(aBasicShape->GetShapeType() == StyleBasicShapeType::Inset,
"The basic shape must be inset()!");
const nsTArray<nsStyleCoord>& coords = aBasicShape->Coordinates();
MOZ_ASSERT(coords.Length() == 4, "wrong number of arguments");
- nsMargin inset(nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.height),
- nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.width),
- nsRuleNode::ComputeCoordPercentCalc(coords[2], aRefBox.height),
- nsRuleNode::ComputeCoordPercentCalc(coords[3], aRefBox.width));
+ nsMargin inset(coords[0].ComputeCoordPercentCalc(aRefBox.height),
+ coords[1].ComputeCoordPercentCalc(aRefBox.width),
+ coords[2].ComputeCoordPercentCalc(aRefBox.height),
+ coords[3].ComputeCoordPercentCalc(aRefBox.width));
nsRect insetRect(aRefBox);
insetRect.Deflate(inset);
return insetRect;
}
/* static */ bool
@@ -158,16 +156,16 @@ ShapeUtils::ComputePolygonVertices(const
const nsTArray<nsStyleCoord>& coords = aBasicShape->Coordinates();
MOZ_ASSERT(coords.Length() % 2 == 0 &&
coords.Length() >= 2, "Wrong number of arguments!");
nsTArray<nsPoint> vertices(coords.Length() / 2);
for (size_t i = 0; i + 1 < coords.Length(); i += 2) {
vertices.AppendElement(
- nsPoint(nsRuleNode::ComputeCoordPercentCalc(coords[i], aRefBox.width),
- nsRuleNode::ComputeCoordPercentCalc(coords[i + 1], aRefBox.height))
+ nsPoint(coords[i].ComputeCoordPercentCalc(aRefBox.width),
+ coords[i + 1].ComputeCoordPercentCalc(aRefBox.height))
+ aRefBox.TopLeft());
}
return vertices;
}
} // namespace mozilla
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -5719,17 +5719,17 @@ nsLayoutUtils::ComputeCBDependentValue(n
const nsStyleCoord& aCoord)
{
NS_WARNING_ASSERTION(
aPercentBasis != NS_UNCONSTRAINEDSIZE,
"have unconstrained width or height; this should only result from very "
"large sizes, not attempts at intrinsic size calculation");
if (aCoord.IsCoordPercentCalcUnit()) {
- return nsRuleNode::ComputeCoordPercentCalc(aCoord, aPercentBasis);
+ return aCoord.ComputeCoordPercentCalc(aPercentBasis);
}
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
aCoord.GetUnit() == eStyleUnit_Auto,
"unexpected width value");
return 0;
}
/* static */ nscoord
@@ -5744,17 +5744,17 @@ nsLayoutUtils::ComputeBSizeDependentValu
// the unit conditions.
// XXXldb Many callers pass a non-'auto' containing block height when
// according to CSS2.1 they should be passing 'auto'.
NS_PRECONDITION(NS_AUTOHEIGHT != aContainingBlockBSize ||
!aCoord.HasPercent(),
"unexpected containing block block-size");
if (aCoord.IsCoordPercentCalcUnit()) {
- return nsRuleNode::ComputeCoordPercentCalc(aCoord, aContainingBlockBSize);
+ return aCoord.ComputeCoordPercentCalc(aContainingBlockBSize);
}
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
aCoord.GetUnit() == eStyleUnit_Auto,
"unexpected block-size value");
return 0;
}
@@ -7216,18 +7216,18 @@ nsLayoutUtils::OrientImage(imgIContainer
return img.forget();
}
static bool NonZeroStyleCoord(const nsStyleCoord& aCoord)
{
if (aCoord.IsCoordPercentCalcUnit()) {
// Since negative results are clamped to 0, check > 0.
- return nsRuleNode::ComputeCoordPercentCalc(aCoord, nscoord_MAX) > 0 ||
- nsRuleNode::ComputeCoordPercentCalc(aCoord, 0) > 0;
+ return aCoord.ComputeCoordPercentCalc(nscoord_MAX) > 0 ||
+ aCoord.ComputeCoordPercentCalc(0) > 0;
}
return true;
}
/* static */ bool
nsLayoutUtils::HasNonZeroCorner(const nsStyleCorners& aCorners)
{
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -1488,18 +1488,17 @@ public:
static nscoord ComputeBSizeValue(nscoord aContainingBlockBSize,
nscoord aContentEdgeToBoxSizingBoxEdge,
const nsStyleCoord& aCoord)
{
MOZ_ASSERT(aContainingBlockBSize != nscoord_MAX || !aCoord.HasPercent(),
"caller must deal with %% of unconstrained block-size");
MOZ_ASSERT(aCoord.IsCoordPercentCalcUnit());
- nscoord result =
- nsRuleNode::ComputeCoordPercentCalc(aCoord, aContainingBlockBSize);
+ nscoord result = aCoord.ComputeCoordPercentCalc(aContainingBlockBSize);
// Clamp calc(), and the subtraction for box-sizing.
return std::max(0, result - aContentEdgeToBoxSizingBoxEdge);
}
// XXX to be removed
static bool IsAutoHeight(const nsStyleCoord &aCoord, nscoord aCBHeight)
{
return IsAutoBSize(aCoord, aCBHeight);
@@ -1526,29 +1525,29 @@ public:
static bool IsPaddingZero(const nsStyleCoord &aCoord)
{
return (aCoord.GetUnit() == eStyleUnit_Coord &&
aCoord.GetCoordValue() == 0) ||
(aCoord.GetUnit() == eStyleUnit_Percent &&
aCoord.GetPercentValue() == 0.0f) ||
(aCoord.IsCalcUnit() &&
// clamp negative calc() to 0
- nsRuleNode::ComputeCoordPercentCalc(aCoord, nscoord_MAX) <= 0 &&
- nsRuleNode::ComputeCoordPercentCalc(aCoord, 0) <= 0);
+ aCoord.ComputeCoordPercentCalc(nscoord_MAX) <= 0 &&
+ aCoord.ComputeCoordPercentCalc(0) <= 0);
}
static bool IsMarginZero(const nsStyleCoord &aCoord)
{
return (aCoord.GetUnit() == eStyleUnit_Coord &&
aCoord.GetCoordValue() == 0) ||
(aCoord.GetUnit() == eStyleUnit_Percent &&
aCoord.GetPercentValue() == 0.0f) ||
(aCoord.IsCalcUnit() &&
- nsRuleNode::ComputeCoordPercentCalc(aCoord, nscoord_MAX) == 0 &&
- nsRuleNode::ComputeCoordPercentCalc(aCoord, 0) == 0);
+ aCoord.ComputeCoordPercentCalc(nscoord_MAX) == 0 &&
+ aCoord.ComputeCoordPercentCalc(0) == 0);
}
static void MarkDescendantsDirty(nsIFrame *aSubtreeRoot);
static void MarkIntrinsicISizesDirtyIfDependentOnBSize(nsIFrame* aFrame);
/*
* Calculate the used values for 'width' and 'height' when width
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -754,17 +754,17 @@ nsBlockFrame::GetMinISize(gfxContext *aR
} else {
if (!curFrame->GetPrevContinuation() &&
line == curFrame->LinesBegin()) {
// Only add text-indent if it has no percentages; using a
// percentage basis of 0 unconditionally would give strange
// behavior for calc(10%-3px).
const nsStyleCoord &indent = StyleText()->mTextIndent;
if (indent.ConvertsToLength())
- data.mCurrentLine += nsRuleNode::ComputeCoordPercentCalc(indent, 0);
+ data.mCurrentLine += indent.ComputeCoordPercentCalc(0);
}
// XXX Bug NNNNNN Should probably handle percentage text-indent.
data.mLine = &line;
data.SetLineContainer(curFrame);
nsIFrame *kid = line->mFirstChild;
for (int32_t i = 0, i_end = line->GetChildCount(); i != i_end;
++i, kid = kid->GetNextSibling()) {
@@ -927,17 +927,17 @@ nsBlockFrame::GetPrefWidthTightBounds(gf
} else {
if (!curFrame->GetPrevContinuation() &&
line == curFrame->LinesBegin()) {
// Only add text-indent if it has no percentages; using a
// percentage basis of 0 unconditionally would give strange
// behavior for calc(10%-3px).
const nsStyleCoord &indent = StyleText()->mTextIndent;
if (indent.ConvertsToLength()) {
- data.mCurrentLine += nsRuleNode::ComputeCoordPercentCalc(indent, 0);
+ data.mCurrentLine += indent.ComputeCoordPercentCalc(0);
}
}
// XXX Bug NNNNNN Should probably handle percentage text-indent.
data.mLine = &line;
data.SetLineContainer(curFrame);
nsIFrame *kid = line->mFirstChild;
for (int32_t i = 0, i_end = line->GetChildCount(); i != i_end;
@@ -3068,18 +3068,18 @@ IsNonAutoNonZeroBSize(const nsStyleCoord
unit == eStyleUnit_Enumerated) {
return false;
}
if (aCoord.IsCoordPercentCalcUnit()) {
// If we evaluate the length/percent/calc at a percentage basis of
// both nscoord_MAX and 0, and it's zero both ways, then it's a zero
// length, percent, or combination thereof. Test > 0 so we clamp
// negative calc() results to 0.
- return nsRuleNode::ComputeCoordPercentCalc(aCoord, nscoord_MAX) > 0 ||
- nsRuleNode::ComputeCoordPercentCalc(aCoord, 0) > 0;
+ return aCoord.ComputeCoordPercentCalc(nscoord_MAX) > 0 ||
+ aCoord.ComputeCoordPercentCalc(0) > 0;
}
MOZ_ASSERT(false, "unexpected unit for height or min-height");
return true;
}
/* virtual */ bool
nsBlockFrame::IsSelfEmpty()
{
--- a/layout/generic/nsContainerFrame.cpp
+++ b/layout/generic/nsContainerFrame.cpp
@@ -718,17 +718,17 @@ nsContainerFrame::SyncFrameViewAfterRefl
vm->ResizeView(aView, aVisualOverflowArea, true);
}
}
static nscoord GetCoord(const nsStyleCoord& aCoord, nscoord aIfNotCoord)
{
if (aCoord.ConvertsToLength()) {
- return nsRuleNode::ComputeCoordPercentCalc(aCoord, 0);
+ return aCoord.ComputeCoordPercentCalc(0);
}
return aIfNotCoord;
}
void
nsContainerFrame::DoInlineIntrinsicISize(gfxContext *aRenderingContext,
InlineIntrinsicISizeData *aData,
nsLayoutUtils::IntrinsicISizeType aType)
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -1653,17 +1653,17 @@ nsIFrame::ComputeBorderRadii(const nsSty
{
// Percentages are relative to whichever side they're on.
NS_FOR_CSS_HALF_CORNERS(i) {
const nsStyleCoord c = aBorderRadius.Get(i);
nscoord axis =
HalfCornerIsX(i) ? aFrameSize.width : aFrameSize.height;
if (c.IsCoordPercentCalcUnit()) {
- aRadii[i] = nsRuleNode::ComputeCoordPercentCalc(c, axis);
+ aRadii[i] = c.ComputeCoordPercentCalc(axis);
if (aRadii[i] < 0) {
// clamp calc()
aRadii[i] = 0;
}
} else {
NS_NOTREACHED("ComputeBorderRadii: bad unit");
aRadii[i] = 0;
}
@@ -6296,18 +6296,17 @@ nsIFrame::ComputeISizeValue(gfxContext*
"have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size "
"calculation");
NS_PRECONDITION(aContainingBlockISize >= 0,
"inline-size less than zero");
nscoord result;
if (aCoord.IsCoordPercentCalcUnit()) {
- result = nsRuleNode::ComputeCoordPercentCalc(aCoord,
- aContainingBlockISize);
+ result = aCoord.ComputeCoordPercentCalc(aContainingBlockISize);
// The result of a calc() expression might be less than 0; we
// should clamp at runtime (below). (Percentages and coords that
// are less than 0 have already been dropped by the parser.)
result -= aContentEdgeToBoxSizing;
} else {
MOZ_ASSERT(eStyleUnit_Enumerated == aCoord.GetUnit());
// If 'this' is a container for font size inflation, then shrink
// wrapping inside of it should not apply font size inflation.
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -6262,22 +6262,22 @@ ComputeScrollSnapInfo(const ScrollFrameH
}
if (styles.mScrollSnapDestinationY.mHasPercent) {
result.mScrollSnapDestination.y +=
NSToCoordFloorClamped(styles.mScrollSnapDestinationY.mPercent *
scrollPortSize.height);
}
if (styles.mScrollSnapPointsX.GetUnit() != eStyleUnit_None) {
- result.mScrollSnapIntervalX = Some(nsRuleNode::ComputeCoordPercentCalc(
- styles.mScrollSnapPointsX, scrollPortSize.width));
+ result.mScrollSnapIntervalX = Some(
+ styles.mScrollSnapPointsX.ComputeCoordPercentCalc(scrollPortSize.width));
}
if (styles.mScrollSnapPointsY.GetUnit() != eStyleUnit_None) {
- result.mScrollSnapIntervalY = Some(nsRuleNode::ComputeCoordPercentCalc(
- styles.mScrollSnapPointsY, scrollPortSize.height));
+ result.mScrollSnapIntervalY = Some(
+ styles.mScrollSnapPointsY.ComputeCoordPercentCalc(scrollPortSize.height));
}
CollectScrollSnapCoordinates(aScrollFrame.GetScrolledFrame(),
aScrollFrame.GetScrolledFrame(),
result.mScrollSnapCoordinates);
return result;
}
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -115,18 +115,17 @@ IsPercentOfIndefiniteSize(const nsStyleC
static nscoord
ResolveToDefiniteSize(const nsStyleCoord& aCoord, nscoord aPercentBasis)
{
MOZ_ASSERT(aCoord.IsCoordPercentCalcUnit());
if (::IsPercentOfIndefiniteSize(aCoord, aPercentBasis)) {
return nscoord(0);
}
- return std::max(nscoord(0),
- nsRuleNode::ComputeCoordPercentCalc(aCoord, aPercentBasis));
+ return std::max(nscoord(0), aCoord.ComputeCoordPercentCalc(aPercentBasis));
}
static bool
GetPercentSizeParts(const nsStyleCoord& aCoord, nscoord* aLength, float* aPercent)
{
switch (aCoord.GetUnit()) {
case eStyleUnit_Percent:
*aLength = 0;
@@ -145,18 +144,17 @@ GetPercentSizeParts(const nsStyleCoord&
static void
ResolvePercentSizeParts(const nsStyleCoord& aCoord, nscoord aPercentBasis,
nscoord* aLength, float* aPercent)
{
MOZ_ASSERT(aCoord.IsCoordPercentCalcUnit());
if (aPercentBasis != NS_UNCONSTRAINEDSIZE) {
*aLength = std::max(nscoord(0),
- nsRuleNode::ComputeCoordPercentCalc(aCoord,
- aPercentBasis));
+ aCoord.ComputeCoordPercentCalc(aPercentBasis));
*aPercent = 0.0f;
return;
}
if (!GetPercentSizeParts(aCoord, aLength, aPercent)) {
*aLength = aCoord.ToLength();
*aPercent = 0.0f;
}
}
@@ -3777,18 +3775,17 @@ nsGridContainerFrame::Tracks::ResolveInt
WritingMode wm = aState.mWM;
// Calculate data for "Automatic Minimum Size" clamping, if needed.
bool needed = ((sz.mState & TrackSize::eIntrinsicMinSizing) ||
aConstraint == SizingConstraint::eNoConstraint) &&
(aGridItem.mState[mAxis] & ItemState::eApplyAutoMinSize);
if (needed && TrackSize::IsDefiniteMaxSizing(sz.mState)) {
if (sz.mState & TrackSize::eIntrinsicMinSizing) {
auto maxCoord = aFunctions.MaxSizingFor(aRange.mStart);
- cache.mMinSizeClamp =
- nsRuleNode::ComputeCoordPercentCalc(maxCoord, aPercentageBasis);
+ cache.mMinSizeClamp = maxCoord.ComputeCoordPercentCalc(aPercentageBasis);
}
aGridItem.mState[mAxis] |= ItemState::eClampMarginBoxMinSize;
}
// min sizing
gfxContext* rc = &aState.mRenderingContext;
if (sz.mState & TrackSize::eAutoMinSizing) {
nscoord s;
if (aConstraint == SizingConstraint::eMinContent) {
@@ -3822,17 +3819,17 @@ nsGridContainerFrame::Tracks::ResolveInt
sz.mLimit = s;
} else {
sz.mLimit = std::max(sz.mLimit, s);
}
if (MOZ_UNLIKELY(sz.mState & TrackSize::eFitContent)) {
// Clamp mLimit to the fit-content() size, for ยง12.5.1.
auto maxCoord = aFunctions.MaxSizingFor(aRange.mStart);
nscoord fitContentClamp =
- nsRuleNode::ComputeCoordPercentCalc(maxCoord, aPercentageBasis);
+ maxCoord.ComputeCoordPercentCalc(aPercentageBasis);
sz.mLimit = std::min(sz.mLimit, fitContentClamp);
}
}
if (sz.mLimit < sz.mBase) {
sz.mLimit = sz.mBase;
}
return sz.mState & TrackSize::eFlexMaxSizing;
}
@@ -4216,18 +4213,17 @@ nsGridContainerFrame::Tracks::ResolveInt
// Calculate data for "Automatic Minimum Size" clamping, if needed.
bool needed = ((state & TrackSize::eIntrinsicMinSizing) ||
aConstraint == SizingConstraint::eNoConstraint) &&
(gridItem.mState[mAxis] & ItemState::eApplyAutoMinSize);
if (needed && TrackSize::IsDefiniteMaxSizing(state)) {
nscoord minSizeClamp = 0;
for (auto i = lineRange.mStart, end = lineRange.mEnd; i < end; ++i) {
auto maxCoord = aFunctions.MaxSizingFor(i);
- minSizeClamp +=
- nsRuleNode::ComputeCoordPercentCalc(maxCoord, aPercentageBasis);
+ minSizeClamp += maxCoord.ComputeCoordPercentCalc(aPercentageBasis);
}
minSizeClamp += mGridGap * (span - 1);
cache.mMinSizeClamp = minSizeClamp;
gridItem.mState[mAxis] |= ItemState::eClampMarginBoxMinSize;
}
// Collect the various grid item size contributions we need.
nscoord minSize = 0;
if (state & (TrackSize::eIntrinsicMinSizing | // for 2.1
--- a/layout/generic/nsLineLayout.cpp
+++ b/layout/generic/nsLineLayout.cpp
@@ -210,17 +210,17 @@ nsLineLayout::BeginLineReflow(nscoord aI
if (0 == mLineNumber && !HasPrevInFlow(mBlockReflowInput->mFrame)) {
const nsStyleCoord &textIndent = mStyleText->mTextIndent;
nscoord pctBasis = 0;
if (textIndent.HasPercent()) {
pctBasis =
mBlockReflowInput->GetContainingBlockContentISize(aWritingMode);
}
- nscoord indent = nsRuleNode::ComputeCoordPercentCalc(textIndent, pctBasis);
+ nscoord indent = textIndent.ComputeCoordPercentCalc(pctBasis);
mTextIndent = indent;
psd->mICoord += indent;
}
PerFrameData* pfd = NewPerFrameData(mBlockReflowInput->mFrame);
pfd->mAscent = 0;
@@ -2170,18 +2170,17 @@ nsLineLayout::VerticalAlignFrames(PerSpa
// Percentages are like lengths, except treated as a percentage
// of the elements line block size value.
float inflation =
GetInflationForBlockDirAlignment(frame, mInflationMinFontSize);
pctBasis = ReflowInput::CalcLineHeight(frame->GetContent(),
frame->StyleContext(), mBlockReflowInput->ComputedBSize(),
inflation);
}
- nscoord offset =
- nsRuleNode::ComputeCoordPercentCalc(verticalAlign, pctBasis);
+ nscoord offset = verticalAlign.ComputeCoordPercentCalc(pctBasis);
// According to the CSS2 spec (10.8.1), a positive value
// "raises" the box by the given distance while a negative value
// "lowers" the box by the given distance (with zero being the
// baseline). Since Y coordinates increase towards the bottom of
// the screen we reverse the sign, unless the line orientation is
// inverted relative to block direction.
nscoord revisedBaselineBCoord = baselineBCoord - offset *
lineWM.FlowRelativeToLineRelativeFactor();
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -1815,17 +1815,17 @@ WordSpacing(nsIFrame* aFrame, const gfxT
}
if (!aStyleText) {
aStyleText = aFrame->StyleText();
}
const nsStyleCoord& coord = aStyleText->mWordSpacing;
if (coord.IsCoordPercentCalcUnit()) {
nscoord pctBasis = coord.HasPercent() ? GetSpaceWidthAppUnits(aTextRun) : 0;
- return nsRuleNode::ComputeCoordPercentCalc(coord, pctBasis);
+ return coord.ComputeCoordPercentCalc(pctBasis);
}
return 0;
}
// Returns gfxTextRunFactory::TEXT_ENABLE_SPACING if non-standard
// letter-spacing or word-spacing is present.
static gfx::ShapedTextFlags
GetSpacingFlags(nsIFrame* aFrame, const nsStyleText* aStyleText = nullptr)
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -5750,27 +5750,26 @@ nsComputedDOMStyle::SetValueToCoord(nsRO
case eStyleUnit_None:
aValue->SetIdent(eCSSKeyword_none);
break;
case eStyleUnit_Calc:
nscoord percentageBase;
if (!aCoord.CalcHasPercent()) {
- nscoord val = nsRuleNode::ComputeCoordPercentCalc(aCoord, 0);
+ nscoord val = aCoord.ComputeCoordPercentCalc(0);
if (aClampNegativeCalc && val < 0) {
MOZ_ASSERT(aCoord.IsCalcUnit(),
"parser should have rejected value");
val = 0;
}
aValue->SetAppUnits(std::max(aMinAppUnits, std::min(val, aMaxAppUnits)));
} else if (aPercentageBaseGetter &&
(this->*aPercentageBaseGetter)(percentageBase)) {
- nscoord val =
- nsRuleNode::ComputeCoordPercentCalc(aCoord, percentageBase);
+ nscoord val = aCoord.ComputeCoordPercentCalc(percentageBase);
if (aClampNegativeCalc && val < 0) {
MOZ_ASSERT(aCoord.IsCalcUnit(),
"parser should have rejected value");
val = 0;
}
aValue->SetAppUnits(std::max(aMinAppUnits, std::min(val, aMaxAppUnits)));
} else {
nsStyleCoord::Calc *calc = aCoord.GetCalcValue();
@@ -5816,18 +5815,17 @@ nsComputedDOMStyle::StyleCoordToNSCoord(
{
NS_PRECONDITION(aPercentageBaseGetter, "Must have a percentage base getter");
if (aCoord.GetUnit() == eStyleUnit_Coord) {
return aCoord.GetCoordValue();
}
if (aCoord.GetUnit() == eStyleUnit_Percent || aCoord.IsCalcUnit()) {
nscoord percentageBase;
if ((this->*aPercentageBaseGetter)(percentageBase)) {
- nscoord result =
- nsRuleNode::ComputeCoordPercentCalc(aCoord, percentageBase);
+ nscoord result = aCoord.ComputeCoordPercentCalc(percentageBase);
if (aClampNegativeCalc && result < 0) {
// It's expected that we can get a negative value here with calc().
// We can also get a negative value with a percentage value if
// percentageBase is negative; this isn't expected, but can happen
// when large length values overflow.
NS_WARNING_ASSERTION(
percentageBase >= 0,
"percentage base value overflowed to become negative for a property "
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -843,33 +843,16 @@ nsRuleNode::SpecifiedCalcToComputedCalc(
aConditions);
nsRuleNode::ComputedCalc result;
if (!ComputeCalc(result, aValue, ops)) {
MOZ_ASSERT_UNREACHABLE("unexpected ComputeCalc failure");
}
return result;
}
-/* 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 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
* example, "center" becomes 0.5f.
*
* @param aEnumValue The enumerated value.
* @return The float percent it corresponds to.
*/
static float
--- a/layout/style/nsRuleNode.h
+++ b/layout/style/nsRuleNode.h
@@ -1039,24 +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 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);
-
// 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
// rebuilding all style data.
bool TreeHasCachedData() const {
NS_ASSERTION(IsRoot(), "should only be called on root of rule tree");
return HaveChildren() || mStyleData.mInheritedData || mStyleData.mResetData;
}
--- a/layout/style/nsStyleCoord.cpp
+++ b/layout/style/nsStyleCoord.cpp
@@ -201,16 +201,32 @@ nsStyleCoord::GetAngleValueInRadians() c
nscoord
nsStyleCoord::ComputeComputedCalc(nscoord aPercentageBasis) const
{
Calc* calc = GetCalcValue();
return calc->mLength +
NSToCoordFloorClamped(aPercentageBasis * calc->mPercent);
}
+nscoord
+nsStyleCoord::ComputeCoordPercentCalc(nscoord aPercentageBasis) const
+{
+ switch (GetUnit()) {
+ case eStyleUnit_Coord:
+ return GetCoordValue();
+ case eStyleUnit_Percent:
+ return NSToCoordFloorClamped(aPercentageBasis * GetPercentValue());
+ case eStyleUnit_Calc:
+ return ComputeComputedCalc(aPercentageBasis);
+ default:
+ MOZ_ASSERT_UNREACHABLE("Unexpected unit!");
+ return 0;
+ }
+}
+
nsStyleSides::nsStyleSides()
{
NS_FOR_CSS_SIDES(i) {
mUnits[i] = eStyleUnit_Null;
}
mozilla::PodArrayZero(mValues);
}
--- a/layout/style/nsStyleCoord.h
+++ b/layout/style/nsStyleCoord.h
@@ -216,16 +216,22 @@ public:
}
// 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;
+ // Compute the value 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%)"
+ nscoord ComputeCoordPercentCalc(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/tables/nsTableRowFrame.cpp
+++ b/layout/tables/nsTableRowFrame.cpp
@@ -544,17 +544,17 @@ nsTableRowFrame::CalcBSize(const ReflowI
nscoord computedBSize = (NS_UNCONSTRAINEDSIZE == aReflowInput.ComputedBSize())
? 0 : aReflowInput.ComputedBSize();
ResetBSize(computedBSize);
WritingMode wm = aReflowInput.GetWritingMode();
const nsStylePosition* position = StylePosition();
const nsStyleCoord& bsizeStyleCoord = position->BSize(wm);
if (bsizeStyleCoord.ConvertsToLength()) {
- SetFixedBSize(nsRuleNode::ComputeCoordPercentCalc(bsizeStyleCoord, 0));
+ SetFixedBSize(bsizeStyleCoord.ComputeCoordPercentCalc(0));
}
else if (eStyleUnit_Percent == bsizeStyleCoord.GetUnit()) {
SetPctBSize(bsizeStyleCoord.GetPercentValue());
}
// calc() with percentages is treated like 'auto' on table rows.
for (nsIFrame* kidFrame : mFrames) {
nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);
@@ -628,17 +628,17 @@ nsTableRowFrame::CalculateCellActualBSiz
MOZ_FALLTHROUGH;
}
case eStyleUnit_Coord: {
// In quirks mode, table cell isize should be content-box, but bsize
// should be border-box.
// Because of this historic anomaly, we do not use quirk.css
// (since we can't specify one value of box-sizing for isize and another
// for bsize)
- specifiedBSize = nsRuleNode::ComputeCoordPercentCalc(bsizeStyleCoord, 0);
+ specifiedBSize = bsizeStyleCoord.ComputeCoordPercentCalc(0);
if (PresContext()->CompatibilityMode() != eCompatibility_NavQuirks &&
position->mBoxSizing == StyleBoxSizing::Content) {
specifiedBSize +=
aCellFrame->GetLogicalUsedBorderAndPadding(aWM).BStartEnd(aWM);
}
if (1 == rowSpan) {
SetFixedBSize(specifiedBSize);
--- a/layout/xul/nsBox.cpp
+++ b/layout/xul/nsBox.cpp
@@ -691,17 +691,17 @@ nsIFrame::AddXULMinSize(nsBoxLayoutState
const nsStylePosition* position = aBox->StylePosition();
// same for min size. Unfortunately min size is always set to 0. So for now
// we will assume 0 (as a coord) means not set.
const nsStyleCoord &minWidth = position->mMinWidth;
if ((minWidth.GetUnit() == eStyleUnit_Coord &&
minWidth.GetCoordValue() != 0) ||
(minWidth.IsCalcUnit() && !minWidth.CalcHasPercent())) {
- nscoord min = nsRuleNode::ComputeCoordPercentCalc(minWidth, 0);
+ nscoord min = minWidth.ComputeCoordPercentCalc(0);
if (!aWidthSet || (min > aSize.width && canOverride)) {
aSize.width = min;
aWidthSet = true;
}
} else if (minWidth.GetUnit() == eStyleUnit_Percent) {
NS_ASSERTION(minWidth.GetPercentValue() == 0.0f,
"Non-zero percentage values not currently supported");
aSize.width = 0;
@@ -713,17 +713,17 @@ nsIFrame::AddXULMinSize(nsBoxLayoutState
// GetXULPrefSize/GetXULMinSize methods that don't consider
// (min-/max-/)(width/height) properties.
// calc() with percentage is treated like '0' (unset)
const nsStyleCoord &minHeight = position->mMinHeight;
if ((minHeight.GetUnit() == eStyleUnit_Coord &&
minHeight.GetCoordValue() != 0) ||
(minHeight.IsCalcUnit() && !minHeight.CalcHasPercent())) {
- nscoord min = nsRuleNode::ComputeCoordPercentCalc(minHeight, 0);
+ nscoord min = minHeight.ComputeCoordPercentCalc(0);
if (!aHeightSet || (min > aSize.height && canOverride)) {
aSize.height = min;
aHeightSet = true;
}
} else if (minHeight.GetUnit() == eStyleUnit_Percent) {
NS_ASSERTION(position->mMinHeight.GetPercentValue() == 0.0f,
"Non-zero percentage values not currently supported");
aSize.height = 0;
@@ -778,24 +778,24 @@ nsIFrame::AddXULMaxSize(nsIFrame* aBox,
// and max
// see if the width or height was specifically set
// XXX Handle eStyleUnit_Enumerated?
// (Handling the eStyleUnit_Enumerated types requires
// GetXULPrefSize/GetXULMinSize methods that don't consider
// (min-/max-/)(width/height) properties.)
const nsStyleCoord maxWidth = position->mMaxWidth;
if (maxWidth.ConvertsToLength()) {
- aSize.width = nsRuleNode::ComputeCoordPercentCalc(maxWidth, 0);
+ aSize.width = maxWidth.ComputeCoordPercentCalc(0);
aWidthSet = true;
}
// percentages and calc() with percentages are treated like 'none'
const nsStyleCoord &maxHeight = position->mMaxHeight;
if (maxHeight.ConvertsToLength()) {
- aSize.height = nsRuleNode::ComputeCoordPercentCalc(maxHeight, 0);
+ aSize.height = maxHeight.ComputeCoordPercentCalc(0);
aHeightSet = true;
}
// percentages and calc() with percentages are treated like 'none'
nsIContent* content = aBox->GetContent();
if (content && content->IsXULElement()) {
nsAutoString value;
nsresult error;