mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1159305 - patch 2 - Clean up layout code by using the new accessors. r=smontagu
This commit is contained in:
parent
28d878bacb
commit
0b6c2066f3
@ -4145,10 +4145,10 @@ GetPercentBSize(const nsStyleCoord& aStyle,
|
||||
f = f->GetParent();
|
||||
}
|
||||
|
||||
bool isVertical = f->GetWritingMode().IsVertical();
|
||||
WritingMode wm = f->GetWritingMode();
|
||||
|
||||
const nsStylePosition *pos = f->StylePosition();
|
||||
const nsStyleCoord bSizeCoord = isVertical ? pos->mWidth : pos->mHeight;
|
||||
const nsStyleCoord& bSizeCoord = pos->BSize(wm);
|
||||
nscoord h;
|
||||
if (!GetAbsoluteCoord(bSizeCoord, h) &&
|
||||
!GetPercentBSize(bSizeCoord, f, h)) {
|
||||
@ -4169,16 +4169,15 @@ GetPercentBSize(const nsStyleCoord& aStyle,
|
||||
NS_ASSERTION(bSizeCoord.GetUnit() == eStyleUnit_Auto,
|
||||
"Unexpected block-size unit for viewport or canvas or page-content");
|
||||
// For the viewport, canvas, and page-content kids, the percentage
|
||||
// basis is just the parent height.
|
||||
h = isVertical ? f->GetSize().width : f->GetSize().height;
|
||||
// basis is just the parent block-size.
|
||||
h = f->BSize(wm);
|
||||
if (h == NS_UNCONSTRAINEDSIZE) {
|
||||
// We don't have a percentage basis after all
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const nsStyleCoord& maxBSizeCoord =
|
||||
isVertical ? pos->mMaxWidth : pos->mMaxHeight;
|
||||
const nsStyleCoord& maxBSizeCoord = pos->MaxBSize(wm);
|
||||
|
||||
nscoord maxh;
|
||||
if (GetAbsoluteCoord(maxBSizeCoord, maxh) ||
|
||||
@ -4191,8 +4190,7 @@ GetPercentBSize(const nsStyleCoord& aStyle,
|
||||
"unknown max block-size unit");
|
||||
}
|
||||
|
||||
const nsStyleCoord& minBSizeCoord =
|
||||
isVertical ? pos->mMinWidth : pos->mMinHeight;
|
||||
const nsStyleCoord& minBSizeCoord = pos->MinBSize(wm);
|
||||
|
||||
nscoord minh;
|
||||
if (GetAbsoluteCoord(minBSizeCoord, minh) ||
|
||||
@ -4306,12 +4304,9 @@ nsLayoutUtils::IntrinsicForContainer(nsRenderingContext *aRenderingContext,
|
||||
const nsStylePosition *stylePos = aFrame->StylePosition();
|
||||
uint8_t boxSizing = stylePos->mBoxSizing;
|
||||
|
||||
const nsStyleCoord &styleISize =
|
||||
isVertical ? stylePos->mHeight : stylePos->mWidth;
|
||||
const nsStyleCoord &styleMinISize =
|
||||
isVertical ? stylePos->mMinHeight : stylePos->mMinWidth;
|
||||
const nsStyleCoord &styleMaxISize =
|
||||
isVertical ? stylePos->mMaxHeight : stylePos->mMaxWidth;
|
||||
const nsStyleCoord& styleISize = stylePos->ISize(wm);
|
||||
const nsStyleCoord& styleMinISize = stylePos->MinISize(wm);
|
||||
const nsStyleCoord& styleMaxISize = stylePos->MaxISize(wm);
|
||||
|
||||
// We build up two values starting with the content box, and then
|
||||
// adding padding, border and margin. The result is normally
|
||||
@ -4390,12 +4385,9 @@ nsLayoutUtils::IntrinsicForContainer(nsRenderingContext *aRenderingContext,
|
||||
// since that's what it means in all cases except for on flex items -- and
|
||||
// even there, we're supposed to ignore it (i.e. treat it as 0) until the
|
||||
// flex container explicitly considers it.
|
||||
const nsStyleCoord &styleBSize =
|
||||
isVertical ? stylePos->mWidth : stylePos->mHeight;
|
||||
const nsStyleCoord &styleMinBSize =
|
||||
isVertical ? stylePos->mMinWidth : stylePos->mMinHeight;
|
||||
const nsStyleCoord &styleMaxBSize =
|
||||
isVertical ? stylePos->mMaxWidth : stylePos->mMaxHeight;
|
||||
const nsStyleCoord& styleBSize = stylePos->BSize(wm);
|
||||
const nsStyleCoord& styleMinBSize = stylePos->MinBSize(wm);
|
||||
const nsStyleCoord& styleMaxBSize = stylePos->MaxBSize(wm);
|
||||
|
||||
if (styleBSize.GetUnit() != eStyleUnit_Auto ||
|
||||
!(styleMinBSize.GetUnit() == eStyleUnit_Auto ||
|
||||
@ -4411,23 +4403,16 @@ nsLayoutUtils::IntrinsicForContainer(nsRenderingContext *aRenderingContext,
|
||||
case NS_STYLE_BOX_SIZING_BORDER: {
|
||||
const nsStyleBorder* styleBorder = aFrame->StyleBorder();
|
||||
bSizeTakenByBoxSizing +=
|
||||
isVertical ? styleBorder->GetComputedBorder().LeftRight()
|
||||
: styleBorder->GetComputedBorder().TopBottom();
|
||||
wm.IsVertical() ? styleBorder->GetComputedBorder().LeftRight()
|
||||
: styleBorder->GetComputedBorder().TopBottom();
|
||||
// fall through
|
||||
}
|
||||
case NS_STYLE_BOX_SIZING_PADDING: {
|
||||
if (!(aFlags & IGNORE_PADDING)) {
|
||||
const nsStylePadding* stylePadding = aFrame->StylePadding();
|
||||
const nsStyleCoord& paddingStart =
|
||||
isVertical ? wm.IsVerticalRL()
|
||||
? stylePadding->mPadding.GetRight()
|
||||
: stylePadding->mPadding.GetLeft()
|
||||
: stylePadding->mPadding.GetTop();
|
||||
const nsStyleCoord& paddingEnd =
|
||||
isVertical ? wm.IsVerticalRL()
|
||||
? stylePadding->mPadding.GetLeft()
|
||||
: stylePadding->mPadding.GetRight()
|
||||
: stylePadding->mPadding.GetBottom();
|
||||
const nsStyleSides& stylePadding =
|
||||
aFrame->StylePadding()->mPadding;
|
||||
const nsStyleCoord& paddingStart = stylePadding.GetBStart(wm);
|
||||
const nsStyleCoord& paddingEnd = stylePadding.GetBEnd(wm);
|
||||
nscoord pad;
|
||||
if (GetAbsoluteCoord(paddingStart, pad) ||
|
||||
GetPercentBSize(paddingStart, aFrame, pad)) {
|
||||
@ -4760,10 +4745,8 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(WritingMode aWM,
|
||||
|
||||
// If we're a flex item, we'll compute our size a bit differently.
|
||||
bool isVertical = aWM.IsVertical();
|
||||
const nsStyleCoord* inlineStyleCoord =
|
||||
isVertical ? &stylePos->mHeight : &stylePos->mWidth;
|
||||
const nsStyleCoord* blockStyleCoord =
|
||||
isVertical ? &stylePos->mWidth : &stylePos->mHeight;
|
||||
const nsStyleCoord* inlineStyleCoord = &stylePos->ISize(aWM);
|
||||
const nsStyleCoord* blockStyleCoord = &stylePos->BSize(aWM);
|
||||
|
||||
bool isFlexItem = aFrame->IsFlexItem();
|
||||
bool isInlineFlexItem = false;
|
||||
@ -4831,8 +4814,7 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(WritingMode aWM,
|
||||
boxSizingToMarginEdgeISize, *inlineStyleCoord);
|
||||
}
|
||||
|
||||
const nsStyleCoord& maxISizeCoord =
|
||||
isVertical ? stylePos->mMaxHeight : stylePos->mMaxWidth;
|
||||
const nsStyleCoord& maxISizeCoord = stylePos->MaxISize(aWM);
|
||||
|
||||
if (maxISizeCoord.GetUnit() != eStyleUnit_None &&
|
||||
!(isFlexItem && isInlineFlexItem)) {
|
||||
@ -4847,8 +4829,7 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(WritingMode aWM,
|
||||
// flex container's main-axis. (Those properties get applied later in
|
||||
// the flexbox algorithm.)
|
||||
|
||||
const nsStyleCoord& minISizeCoord =
|
||||
isVertical ? stylePos->mMinHeight : stylePos->mMinWidth;
|
||||
const nsStyleCoord& minISizeCoord = stylePos->MinISize(aWM);
|
||||
|
||||
if (minISizeCoord.GetUnit() != eStyleUnit_Auto &&
|
||||
!(isFlexItem && isInlineFlexItem)) {
|
||||
@ -4870,8 +4851,7 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(WritingMode aWM,
|
||||
*blockStyleCoord);
|
||||
}
|
||||
|
||||
const nsStyleCoord& maxBSizeCoord =
|
||||
isVertical ? stylePos->mMaxWidth : stylePos->mMaxHeight;
|
||||
const nsStyleCoord& maxBSizeCoord = stylePos->MaxBSize(aWM);
|
||||
|
||||
if (!IsAutoBSize(maxBSizeCoord, aCBSize.BSize(aWM)) &&
|
||||
!(isFlexItem && !isInlineFlexItem)) {
|
||||
@ -4881,8 +4861,7 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(WritingMode aWM,
|
||||
maxBSize = nscoord_MAX;
|
||||
}
|
||||
|
||||
const nsStyleCoord& minBSizeCoord =
|
||||
isVertical ? stylePos->mMinWidth : stylePos->mMinHeight;
|
||||
const nsStyleCoord& minBSizeCoord = stylePos->MinBSize(aWM);
|
||||
|
||||
if (!IsAutoBSize(minBSizeCoord, aCBSize.BSize(aWM)) &&
|
||||
!(isFlexItem && !isInlineFlexItem)) {
|
||||
|
@ -2966,38 +2966,22 @@ nsBlockFrame::IsSelfEmpty()
|
||||
return false;
|
||||
}
|
||||
|
||||
WritingMode wm = GetWritingMode();
|
||||
const nsStylePosition* position = StylePosition();
|
||||
bool vertical = GetWritingMode().IsVertical();
|
||||
|
||||
if (vertical) {
|
||||
if (IsNonAutoNonZeroBSize(position->mMinWidth) ||
|
||||
IsNonAutoNonZeroBSize(position->mWidth)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (IsNonAutoNonZeroBSize(position->mMinHeight) ||
|
||||
IsNonAutoNonZeroBSize(position->mHeight)) {
|
||||
return false;
|
||||
}
|
||||
if (IsNonAutoNonZeroBSize(position->MinBSize(wm)) ||
|
||||
IsNonAutoNonZeroBSize(position->BSize(wm))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const nsStyleBorder* border = StyleBorder();
|
||||
const nsStylePadding* padding = StylePadding();
|
||||
|
||||
if (vertical) {
|
||||
if (border->GetComputedBorderWidth(NS_SIDE_LEFT) != 0 ||
|
||||
border->GetComputedBorderWidth(NS_SIDE_RIGHT) != 0 ||
|
||||
!nsLayoutUtils::IsPaddingZero(padding->mPadding.GetLeft()) ||
|
||||
!nsLayoutUtils::IsPaddingZero(padding->mPadding.GetRight())) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (border->GetComputedBorderWidth(NS_SIDE_TOP) != 0 ||
|
||||
border->GetComputedBorderWidth(NS_SIDE_BOTTOM) != 0 ||
|
||||
!nsLayoutUtils::IsPaddingZero(padding->mPadding.GetTop()) ||
|
||||
!nsLayoutUtils::IsPaddingZero(padding->mPadding.GetBottom())) {
|
||||
return false;
|
||||
}
|
||||
if (border->GetComputedBorderWidth(wm.PhysicalSide(eLogicalSideBStart)) != 0 ||
|
||||
border->GetComputedBorderWidth(wm.PhysicalSide(eLogicalSideBEnd)) != 0 ||
|
||||
!nsLayoutUtils::IsPaddingZero(padding->mPadding.GetBStart(wm)) ||
|
||||
!nsLayoutUtils::IsPaddingZero(padding->mPadding.GetBEnd(wm))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HasOutsideBullet() && !BulletIsEmpty()) {
|
||||
|
@ -910,9 +910,7 @@ nsContainerFrame::ComputeAutoSize(nsRenderingContext* aRenderingContext,
|
||||
// replaced elements always shrink-wrap
|
||||
if (aShrinkWrap || IsFrameOfType(eReplaced)) {
|
||||
// don't bother setting it if the result won't be used
|
||||
const nsStyleCoord& inlineStyleCoord =
|
||||
aWM.IsVertical() ? StylePosition()->mHeight : StylePosition()->mWidth;
|
||||
if (inlineStyleCoord.GetUnit() == eStyleUnit_Auto) {
|
||||
if (StylePosition()->ISize(aWM).GetUnit() == eStyleUnit_Auto) {
|
||||
result.ISize(aWM) = ShrinkWidthToFit(aRenderingContext, availBased);
|
||||
}
|
||||
} else {
|
||||
|
@ -4190,12 +4190,8 @@ nsFrame::ComputeSize(nsRenderingContext *aRenderingContext,
|
||||
aMargin.ISize(aWM) + aBorder.ISize(aWM) + aPadding.ISize(aWM) -
|
||||
boxSizingAdjust.ISize(aWM);
|
||||
|
||||
bool isVertical = aWM.IsVertical();
|
||||
|
||||
const nsStyleCoord* inlineStyleCoord =
|
||||
isVertical ? &(stylePos->mHeight) : &(stylePos->mWidth);
|
||||
const nsStyleCoord* blockStyleCoord =
|
||||
isVertical ? &(stylePos->mWidth) : &(stylePos->mHeight);
|
||||
const nsStyleCoord* inlineStyleCoord = &stylePos->ISize(aWM);
|
||||
const nsStyleCoord* blockStyleCoord = &stylePos->BSize(aWM);
|
||||
|
||||
bool isFlexItem = IsFlexItem();
|
||||
bool isInlineFlexItem = false;
|
||||
@ -4241,8 +4237,7 @@ nsFrame::ComputeSize(nsRenderingContext *aRenderingContext,
|
||||
*inlineStyleCoord);
|
||||
}
|
||||
|
||||
const nsStyleCoord& maxISizeCoord =
|
||||
isVertical ? stylePos->mMaxHeight : stylePos->mMaxWidth;
|
||||
const nsStyleCoord& maxISizeCoord = stylePos->MaxISize(aWM);
|
||||
|
||||
// Flex items ignore their min & max sizing properties in their
|
||||
// flex container's main-axis. (Those properties get applied later in
|
||||
@ -4256,8 +4251,7 @@ nsFrame::ComputeSize(nsRenderingContext *aRenderingContext,
|
||||
result.ISize(aWM) = std::min(maxISize, result.ISize(aWM));
|
||||
}
|
||||
|
||||
const nsStyleCoord& minISizeCoord =
|
||||
isVertical ? stylePos->mMinHeight : stylePos->mMinWidth;
|
||||
const nsStyleCoord& minISizeCoord = stylePos->MinISize(aWM);
|
||||
|
||||
nscoord minISize;
|
||||
if (minISizeCoord.GetUnit() != eStyleUnit_Auto &&
|
||||
@ -4288,8 +4282,7 @@ nsFrame::ComputeSize(nsRenderingContext *aRenderingContext,
|
||||
*blockStyleCoord);
|
||||
}
|
||||
|
||||
const nsStyleCoord& maxBSizeCoord =
|
||||
isVertical ? stylePos->mMaxWidth : stylePos->mMaxHeight;
|
||||
const nsStyleCoord& maxBSizeCoord = stylePos->MaxBSize(aWM);
|
||||
|
||||
if (result.BSize(aWM) != NS_UNCONSTRAINEDSIZE) {
|
||||
if (!nsLayoutUtils::IsAutoBSize(maxBSizeCoord, aCBSize.BSize(aWM)) &&
|
||||
@ -4301,8 +4294,7 @@ nsFrame::ComputeSize(nsRenderingContext *aRenderingContext,
|
||||
result.BSize(aWM) = std::min(maxBSize, result.BSize(aWM));
|
||||
}
|
||||
|
||||
const nsStyleCoord& minBSizeCoord =
|
||||
isVertical ? stylePos->mMinWidth : stylePos->mMinHeight;
|
||||
const nsStyleCoord& minBSizeCoord = stylePos->MinBSize(aWM);
|
||||
|
||||
if (!nsLayoutUtils::IsAutoBSize(minBSizeCoord, aCBSize.BSize(aWM)) &&
|
||||
!(isFlexItem && !isInlineFlexItem)) {
|
||||
@ -4398,9 +4390,7 @@ nsFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
|
||||
LogicalSize result(aWM, 0xdeadbeef, NS_UNCONSTRAINEDSIZE);
|
||||
|
||||
// don't bother setting it if the result won't be used
|
||||
const nsStyleCoord& inlineStyleCoord =
|
||||
aWM.IsVertical() ? StylePosition()->mHeight : StylePosition()->mWidth;
|
||||
if (inlineStyleCoord.GetUnit() == eStyleUnit_Auto) {
|
||||
if (StylePosition()->ISize(aWM).GetUnit() == eStyleUnit_Auto) {
|
||||
nscoord availBased = aAvailableISize - aMargin.ISize(aWM) -
|
||||
aBorder.ISize(aWM) - aPadding.ISize(aWM);
|
||||
result.ISize(aWM) = ShrinkWidthToFit(aRenderingContext, availBased);
|
||||
|
@ -394,11 +394,8 @@ nsHTMLReflowState::Init(nsPresContext* aPresContext,
|
||||
// An SVG foreignObject frame is inherently constrained block-size.
|
||||
frame->AddStateBits(NS_FRAME_IN_CONSTRAINED_BSIZE);
|
||||
} else {
|
||||
const bool vertical = mWritingMode.IsVertical();
|
||||
const nsStyleCoord& bSizeCoord =
|
||||
vertical ? mStylePosition->mWidth : mStylePosition->mHeight;
|
||||
const nsStyleCoord& maxBSizeCoord =
|
||||
vertical ? mStylePosition->mMaxWidth : mStylePosition->mMaxHeight;
|
||||
const nsStyleCoord& bSizeCoord = mStylePosition->BSize(mWritingMode);
|
||||
const nsStyleCoord& maxBSizeCoord = mStylePosition->MaxBSize(mWritingMode);
|
||||
if ((bSizeCoord.GetUnit() != eStyleUnit_Auto ||
|
||||
maxBSizeCoord.GetUnit() != eStyleUnit_None) &&
|
||||
// Don't set NS_FRAME_IN_CONSTRAINED_BSIZE on body or html elements.
|
||||
@ -412,10 +409,8 @@ nsHTMLReflowState::Init(nsPresContext* aPresContext,
|
||||
nsIFrame* containingBlk = frame;
|
||||
while (containingBlk) {
|
||||
const nsStylePosition* stylePos = containingBlk->StylePosition();
|
||||
const nsStyleCoord& bSizeCoord =
|
||||
vertical ? stylePos->mWidth : stylePos->mHeight;
|
||||
const nsStyleCoord& maxBSizeCoord =
|
||||
vertical ? stylePos->mMaxWidth : stylePos->mMaxHeight;
|
||||
const nsStyleCoord& bSizeCoord = stylePos->BSize(mWritingMode);
|
||||
const nsStyleCoord& maxBSizeCoord = stylePos->MaxBSize(mWritingMode);
|
||||
if ((bSizeCoord.IsCoordPercentCalcUnit() &&
|
||||
!bSizeCoord.HasPercent()) ||
|
||||
(maxBSizeCoord.IsCoordPercentCalcUnit() &&
|
||||
@ -2429,25 +2424,9 @@ nsHTMLReflowState::CalculateBlockSideMargins(nsIAtom* aFrameType)
|
||||
|
||||
// The css2 spec clearly defines how block elements should behave
|
||||
// in section 10.3.3.
|
||||
bool isAutoStartMargin, isAutoEndMargin;
|
||||
const nsStyleSides& styleSides = mStyleMargin->mMargin;
|
||||
if (cbWM.IsVertical()) {
|
||||
if (cbWM.IsBidiLTR()) {
|
||||
isAutoStartMargin = eStyleUnit_Auto == styleSides.GetTopUnit();
|
||||
isAutoEndMargin = eStyleUnit_Auto == styleSides.GetBottomUnit();
|
||||
} else {
|
||||
isAutoStartMargin = eStyleUnit_Auto == styleSides.GetBottomUnit();
|
||||
isAutoEndMargin = eStyleUnit_Auto == styleSides.GetTopUnit();
|
||||
}
|
||||
} else {
|
||||
if (cbWM.IsBidiLTR()) {
|
||||
isAutoStartMargin = eStyleUnit_Auto == styleSides.GetLeftUnit();
|
||||
isAutoEndMargin = eStyleUnit_Auto == styleSides.GetRightUnit();
|
||||
} else {
|
||||
isAutoStartMargin = eStyleUnit_Auto == styleSides.GetRightUnit();
|
||||
isAutoEndMargin = eStyleUnit_Auto == styleSides.GetLeftUnit();
|
||||
}
|
||||
}
|
||||
bool isAutoStartMargin = eStyleUnit_Auto == styleSides.GetIStartUnit(cbWM);
|
||||
bool isAutoEndMargin = eStyleUnit_Auto == styleSides.GetIEndUnit(cbWM);
|
||||
if (!isAutoStartMargin && !isAutoEndMargin) {
|
||||
// Neither margin is 'auto' so we're over constrained. Use the
|
||||
// 'direction' property of the parent to tell which margin to
|
||||
|
Loading…
Reference in New Issue
Block a user