Bug 958714 part 2: Simplify percent-margin/padding resolution code to pass around a single length as the percent basis. r?mats
MozReview-Commit-ID: J1EPYMQ5lP4
--- a/layout/generic/ReflowInput.cpp
+++ b/layout/generic/ReflowInput.cpp
@@ -170,20 +170,19 @@ SizeComputationInput::SizeComputationInp
, mWritingMode(aFrame->GetWritingMode())
{
MOZ_ASSERT(!aFrame->IsFlexOrGridItem(),
"We're about to resolve percent margin & padding "
"values against CB inline size, which is incorrect for "
"flex/grid items. "
"Additionally for grid items, this path doesn't handle baseline "
"padding contribution - see SizeComputationInput::InitOffsets");
- LogicalSize cbSize(aContainingBlockWritingMode, aContainingBlockISize,
- aContainingBlockISize);
ReflowInputFlags flags;
- InitOffsets(aContainingBlockWritingMode, cbSize, mFrame->Type(), flags);
+ InitOffsets(aContainingBlockWritingMode, aContainingBlockISize,
+ mFrame->Type(), flags);
}
// Initialize a reflow state for a child frame's reflow. Some state
// is copied from the parent reflow state; the remaining state is
// computed.
ReflowInput::ReflowInput(
nsPresContext* aPresContext,
const ReflowInput& aParentReflowInput,
@@ -2203,34 +2202,16 @@ IsSideCaption(nsIFrame* aFrame, const ns
if (aStyleDisplay->mDisplay != StyleDisplay::TableCaption) {
return false;
}
uint8_t captionSide = aFrame->StyleTableBorder()->mCaptionSide;
return captionSide == NS_STYLE_CAPTION_SIDE_LEFT ||
captionSide == NS_STYLE_CAPTION_SIDE_RIGHT;
}
-// Flex/grid items resolve block-axis percentage margin & padding against the
-// containing block block-size (also for abs/fixed-pos child frames).
-// For everything else: the CSS21 spec requires that margin and padding
-// percentage values are calculated with respect to the inline-size of the
-// containing block, even for margin & padding in the block axis.
-static LogicalSize
-OffsetPercentBasis(const nsIFrame* aFrame,
- WritingMode aWM,
- const LogicalSize& aContainingBlockSize)
-{
- // XXX The next patch in this series will get rid of this function and have
- // the upstream/downstream code just work with the one nscoord value that
- // we'll be dealing with now (which is aContainingBlockSize.ISize(aWM)).
- LogicalSize offsetPercentBasis = aContainingBlockSize;
- offsetPercentBasis.BSize(aWM) = offsetPercentBasis.ISize(aWM);
- return offsetPercentBasis;
-}
-
// XXX refactor this code to have methods for each set of properties
// we are computing: width,height,line-height; margin; offsets
void
ReflowInput::InitConstraints(nsPresContext* aPresContext,
const LogicalSize& aContainingBlockSize,
const nsMargin* aBorder,
const nsMargin* aPadding,
@@ -2241,17 +2222,17 @@ ReflowInput::InitConstraints(nsPresConte
aContainingBlockSize.ISize(wm),
aContainingBlockSize.BSize(wm),
aBorder, aPadding);
// If this is a reflow root, then set the computed width and
// height equal to the available space
if (nullptr == mParentReflowInput || mFlags.mDummyParentReflowInput) {
// XXXldb This doesn't mean what it used to!
- InitOffsets(wm, OffsetPercentBasis(mFrame, wm, aContainingBlockSize),
+ InitOffsets(wm, aContainingBlockSize.ISize(wm),
aFrameType, mFlags, aBorder, aPadding, mStyleDisplay);
// Override mComputedMargin since reflow roots start from the
// frame's boundary, which is inside the margin.
ComputedPhysicalMargin().SizeTo(0, 0, 0, 0);
ComputedPhysicalOffsets().SizeTo(0, 0, 0, 0);
ComputedISize() =
AvailableISize() - ComputedLogicalBorderPadding().IStartEnd(wm);
@@ -2299,18 +2280,17 @@ ReflowInput::InitConstraints(nsPresConte
}
// XXX Might need to also pass the CB height (not width) for page boxes,
// too, if we implement them.
// For calculating positioning offsets, margins, borders and
// padding, we use the writing mode of the containing block
WritingMode cbwm = cbri->GetWritingMode();
- InitOffsets(cbwm, OffsetPercentBasis(mFrame, cbwm,
- cbSize.ConvertTo(cbwm, wm)),
+ InitOffsets(cbwm, cbSize.ConvertTo(cbwm, wm).ISize(cbwm),
aFrameType, mFlags, aBorder, aPadding, mStyleDisplay);
// For calculating the size of this box, we use its own writing mode
const nsStyleCoord &blockSize = mStylePosition->BSize(wm);
nsStyleUnit blockSizeUnit = blockSize.GetUnit();
// Check for a percentage based block size and a containing block
// block size that depends on the content block size
@@ -2574,17 +2554,17 @@ UpdateProp(nsIFrame* aFrame,
}
} else {
aFrame->DeleteProperty(aProperty);
}
}
void
SizeComputationInput::InitOffsets(WritingMode aWM,
- const LogicalSize& aPercentBasis,
+ nscoord aPercentBasis,
LayoutFrameType aFrameType,
ReflowInputFlags aFlags,
const nsMargin* aBorder,
const nsMargin* aPadding,
const nsStyleDisplay* aDisplay)
{
DISPLAY_INIT_OFFSETS(mFrame, this, aPercentBasis, aWM, aBorder, aPadding);
@@ -2945,44 +2925,44 @@ ReflowInput::CalcLineHeight(nsIContent*
}
}
return lineHeight;
}
bool
SizeComputationInput::ComputeMargin(WritingMode aWM,
- const LogicalSize& aPercentBasis)
+ nscoord aPercentBasis)
{
// SVG text frames have no margin.
if (nsSVGUtils::IsInSVGTextSubtree(mFrame)) {
return false;
}
// If style style can provide us the margin directly, then use it.
const nsStyleMargin *styleMargin = mFrame->StyleMargin();
bool isCBDependent = !styleMargin->GetMargin(ComputedPhysicalMargin());
if (isCBDependent) {
// We have to compute the value. Note that this calculation is
// performed according to the writing mode of the containing block
// (http://dev.w3.org/csswg/css-writing-modes-3/#orthogonal-flows)
LogicalMargin m(aWM);
m.IStart(aWM) = nsLayoutUtils::
- ComputeCBDependentValue(aPercentBasis.ISize(aWM),
+ ComputeCBDependentValue(aPercentBasis,
styleMargin->mMargin.GetIStart(aWM));
m.IEnd(aWM) = nsLayoutUtils::
- ComputeCBDependentValue(aPercentBasis.ISize(aWM),
+ ComputeCBDependentValue(aPercentBasis,
styleMargin->mMargin.GetIEnd(aWM));
m.BStart(aWM) = nsLayoutUtils::
- ComputeCBDependentValue(aPercentBasis.BSize(aWM),
+ ComputeCBDependentValue(aPercentBasis,
styleMargin->mMargin.GetBStart(aWM));
m.BEnd(aWM) = nsLayoutUtils::
- ComputeCBDependentValue(aPercentBasis.BSize(aWM),
+ ComputeCBDependentValue(aPercentBasis,
styleMargin->mMargin.GetBEnd(aWM));
SetComputedLogicalMargin(aWM, m);
}
// ... but font-size-inflation-based margin adjustment uses the
// frame's writing mode
nscoord marginAdjustment = FontSizeInflationListMarginAdjustment(mFrame);
@@ -2993,17 +2973,17 @@ SizeComputationInput::ComputeMargin(Writ
SetComputedLogicalMargin(m);
}
return isCBDependent;
}
bool
SizeComputationInput::ComputePadding(WritingMode aWM,
- const LogicalSize& aPercentBasis,
+ nscoord aPercentBasis,
LayoutFrameType aFrameType)
{
// If style can provide us the padding directly, then use it.
const nsStylePadding *stylePadding = mFrame->StylePadding();
bool isCBDependent = !stylePadding->GetPadding(ComputedPhysicalPadding());
// a table row/col group, row/col doesn't have padding
// XXXldb Neither do border-collapse tables.
if (LayoutFrameType::TableRowGroup == aFrameType ||
@@ -3014,27 +2994,27 @@ SizeComputationInput::ComputePadding(Wri
}
else if (isCBDependent) {
// We have to compute the value. This calculation is performed
// according to the writing mode of the containing block
// (http://dev.w3.org/csswg/css-writing-modes-3/#orthogonal-flows)
// clamp negative calc() results to 0
LogicalMargin p(aWM);
p.IStart(aWM) = std::max(0, nsLayoutUtils::
- ComputeCBDependentValue(aPercentBasis.ISize(aWM),
+ ComputeCBDependentValue(aPercentBasis,
stylePadding->mPadding.GetIStart(aWM)));
p.IEnd(aWM) = std::max(0, nsLayoutUtils::
- ComputeCBDependentValue(aPercentBasis.ISize(aWM),
+ ComputeCBDependentValue(aPercentBasis,
stylePadding->mPadding.GetIEnd(aWM)));
p.BStart(aWM) = std::max(0, nsLayoutUtils::
- ComputeCBDependentValue(aPercentBasis.BSize(aWM),
+ ComputeCBDependentValue(aPercentBasis,
stylePadding->mPadding.GetBStart(aWM)));
p.BEnd(aWM) = std::max(0, nsLayoutUtils::
- ComputeCBDependentValue(aPercentBasis.BSize(aWM),
+ ComputeCBDependentValue(aPercentBasis,
stylePadding->mPadding.GetBEnd(aWM)));
SetComputedLogicalPadding(aWM, p);
}
return isCBDependent;
}
void
--- a/layout/generic/ReflowInput.h
+++ b/layout/generic/ReflowInput.h
@@ -242,70 +242,56 @@ public:
};
#ifdef DEBUG
// Reflow trace methods. Defined in nsFrame.cpp so they have access
// to the display-reflow infrastructure.
static void* DisplayInitOffsetsEnter(
nsIFrame* aFrame,
SizeComputationInput* aState,
- const mozilla::LogicalSize& aPercentBasis,
+ nscoord aPercentBasis,
WritingMode aCBWritingMode,
const nsMargin* aBorder,
const nsMargin* aPadding);
static void DisplayInitOffsetsExit(nsIFrame* aFrame,
SizeComputationInput* aState,
void* aValue);
#endif
private:
/**
* Computes margin values from the specified margin style information, and
* fills in the mComputedMargin member.
*
* @param aWM Writing mode of the containing block
* @param aPercentBasis
- * Logical size in the writing mode of the containing block to use
- * for resolving percentage margin values in the inline and block
- * axes.
- * The inline size is usually the containing block inline-size
- * (width if writing mode is horizontal, and height if vertical).
- * The block size is usually the containing block inline-size, per
- * CSS21 sec 8.3 (read in conjunction with CSS Writing Modes sec
- * 7.2), but may be the containing block block-size, e.g. in CSS3
- * Flexbox and Grid.
+ * Inline size of the containing block (in its own writing mode), to use
+ * for resolving percentage margin values in the inline and block axes.
* @return true if the margin is dependent on the containing block size.
*/
bool ComputeMargin(mozilla::WritingMode aWM,
- const mozilla::LogicalSize& aPercentBasis);
+ nscoord aPercentBasis);
/**
* Computes padding values from the specified padding style information, and
* fills in the mComputedPadding member.
*
* @param aWM Writing mode of the containing block
* @param aPercentBasis
- * Logical size in the writing mode of the containing block to use
- * for resolving percentage padding values in the inline and block
- * axes.
- * The inline size is usually the containing block inline-size
- * (width if writing mode is horizontal, and height if vertical).
- * The block size is usually the containing block inline-size, per
- * CSS21 sec 8.3 (read in conjunction with CSS Writing Modes sec
- * 7.2), but may be the containing block block-size, e.g. in CSS3
- * Flexbox and Grid.
+ * Inline size of the containing block (in its own writing mode), to use
+ * for resolving percentage padding values in the inline and block axes.
* @return true if the padding is dependent on the containing block size.
*/
bool ComputePadding(mozilla::WritingMode aWM,
- const mozilla::LogicalSize& aPercentBasis,
+ nscoord aPercentBasis,
mozilla::LayoutFrameType aFrameType);
protected:
void InitOffsets(mozilla::WritingMode aWM,
- const mozilla::LogicalSize& aPercentBasis,
+ nscoord aPercentBasis,
mozilla::LayoutFrameType aFrameType,
ReflowInputFlags aFlags,
const nsMargin* aBorder = nullptr,
const nsMargin* aPadding = nullptr,
const nsStyleDisplay* aDisplay = nullptr);
/*
* Convert nsStyleCoord to nscoord when percentages depend on the
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -11558,17 +11558,17 @@ DR_init_constraints_cookie::~DR_init_con
{
MOZ_COUNT_DTOR(DR_init_constraints_cookie);
ReflowInput::DisplayInitConstraintsExit(mFrame, mState, mValue);
}
DR_init_offsets_cookie::DR_init_offsets_cookie(
nsIFrame* aFrame,
SizeComputationInput* aState,
- const LogicalSize& aPercentBasis,
+ nscoord aPercentBasis,
WritingMode aCBWritingMode,
const nsMargin* aMargin,
const nsMargin* aPadding)
: mFrame(aFrame)
, mState(aState)
{
MOZ_COUNT_CTOR(DR_init_offsets_cookie);
mValue = SizeComputationInput::DisplayInitOffsetsEnter(mFrame, mState,
@@ -12518,39 +12518,35 @@ ReflowInput::DisplayInitConstraintsExit(
}
DR_state->DeleteTreeNode(*treeNode);
}
/* static */ void*
SizeComputationInput::DisplayInitOffsetsEnter(nsIFrame* aFrame,
SizeComputationInput* aState,
- const LogicalSize& aPercentBasis,
+ nscoord aPercentBasis,
WritingMode aCBWritingMode,
const nsMargin* aBorder,
const nsMargin* aPadding)
{
NS_PRECONDITION(aFrame, "non-null frame required");
NS_PRECONDITION(aState, "non-null state required");
if (!DR_state->mInited) DR_state->Init();
if (!DR_state->mActive) return nullptr;
// aState is not necessarily a ReflowInput
DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr);
if (treeNode && treeNode->mDisplay) {
DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
- char horizPctBasisStr[16];
- char vertPctBasisStr[16];
- DR_state->PrettyUC(aPercentBasis.ISize(aCBWritingMode),
- horizPctBasisStr, 16);
- DR_state->PrettyUC(aPercentBasis.BSize(aCBWritingMode),
- vertPctBasisStr, 16);
- printf("InitOffsets pct_basis=%s,%s", horizPctBasisStr, vertPctBasisStr);
+ char pctBasisStr[16];
+ DR_state->PrettyUC(aPercentBasis, pctBasisStr, 16);
+ printf("InitOffsets pct_basis=%s", pctBasisStr);
DR_state->PrintMargin("b", aBorder);
DR_state->PrintMargin("p", aPadding);
putchar('\n');
}
return treeNode;
}
--- a/layout/generic/nsFrame.h
+++ b/layout/generic/nsFrame.h
@@ -830,17 +830,17 @@ public:
nsIFrame* mFrame;
mozilla::ReflowInput* mState;
void* mValue;
};
struct DR_init_offsets_cookie {
DR_init_offsets_cookie(nsIFrame* aFrame, mozilla::SizeComputationInput* aState,
- const mozilla::LogicalSize& aPercentBasis,
+ nscoord aPercentBasis,
mozilla::WritingMode aCBWritingMode,
const nsMargin* aBorder,
const nsMargin* aPadding);
~DR_init_offsets_cookie();
nsIFrame* mFrame;
mozilla::SizeComputationInput* mState;
void* mValue;