mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 13:25:37 +00:00
Bug 47710. Fix padding inside scrollframes. r+sr=dbaron,a=chofmann
This commit is contained in:
parent
d28dce547b
commit
4a070ac8cf
@ -255,6 +255,7 @@ struct ScrollReflowState {
|
||||
nsBoxLayoutState mBoxState;
|
||||
nsGfxScrollFrameInner::ScrollbarStyles mStyles;
|
||||
nsReflowReason mNewReason;
|
||||
nsMargin mComputedBorder;
|
||||
|
||||
// === Filled in when TryLayout succeeds ===
|
||||
// The area of the scrollport, in coordinates relative to the scrollframe
|
||||
@ -283,20 +284,25 @@ struct ScrollReflowState {
|
||||
};
|
||||
|
||||
static nsSize ComputeInsideBorderSize(ScrollReflowState* aState,
|
||||
const nsSize& aDesiredInsideBorderSize,
|
||||
const nsMargin& aKidPadding)
|
||||
const nsSize& aDesiredInsideBorderSize)
|
||||
{
|
||||
nscoord width = aState->mReflowState.mComputedWidth;
|
||||
if (width == NS_UNCONSTRAINEDSIZE) {
|
||||
width = aDesiredInsideBorderSize.width - aKidPadding.left - aKidPadding.right;
|
||||
// aDesiredInsideBorderSize is the frame size; i.e., it includes
|
||||
// borders and padding (but the scrolled child doesn't have
|
||||
// borders). The scrolled child has the same padding as us.
|
||||
nscoord contentWidth = aState->mReflowState.mComputedWidth;
|
||||
if (contentWidth == NS_UNCONSTRAINEDSIZE) {
|
||||
contentWidth = aDesiredInsideBorderSize.width -
|
||||
aState->mReflowState.mComputedPadding.LeftRight();
|
||||
}
|
||||
nscoord height = aState->mReflowState.mComputedHeight;
|
||||
if (height == NS_UNCONSTRAINEDSIZE) {
|
||||
height = aDesiredInsideBorderSize.height - aKidPadding.top - aKidPadding.bottom;
|
||||
nscoord contentHeight = aState->mReflowState.mComputedHeight;
|
||||
if (contentHeight == NS_UNCONSTRAINEDSIZE) {
|
||||
contentHeight = aDesiredInsideBorderSize.height -
|
||||
aState->mReflowState.mComputedPadding.TopBottom();
|
||||
}
|
||||
aState->mReflowState.ApplyMinMaxConstraints(&width, &height);
|
||||
return nsSize(width + aKidPadding.left + aKidPadding.right,
|
||||
height + aKidPadding.top + aKidPadding.bottom);
|
||||
|
||||
aState->mReflowState.ApplyMinMaxConstraints(&contentWidth, &contentHeight);
|
||||
return nsSize(contentWidth + aState->mReflowState.mComputedPadding.LeftRight(),
|
||||
contentHeight + aState->mReflowState.mComputedPadding.TopBottom());
|
||||
}
|
||||
|
||||
static void
|
||||
@ -348,7 +354,6 @@ GetScrollbarMetrics(nsBoxLayoutState& aState, nsIBox* aBox, nsSize* aMin, PRBool
|
||||
PRBool
|
||||
nsHTMLScrollFrame::TryLayout(ScrollReflowState* aState,
|
||||
const nsHTMLReflowMetrics& aKidMetrics,
|
||||
const nsMargin& aKidPadding,
|
||||
PRBool aAssumeVScroll, PRBool aAssumeHScroll,
|
||||
PRBool aForce)
|
||||
{
|
||||
@ -381,7 +386,7 @@ nsHTMLScrollFrame::TryLayout(ScrollReflowState* aState,
|
||||
desiredInsideBorderSize.height = hScrollbarActualHeight +
|
||||
PR_MAX(aKidMetrics.height, vScrollbarRequiredHeight);
|
||||
aState->mInsideBorderSize =
|
||||
ComputeInsideBorderSize(aState, desiredInsideBorderSize, aKidPadding);
|
||||
ComputeInsideBorderSize(aState, desiredInsideBorderSize);
|
||||
nsSize scrollPortSize = nsSize(aState->mInsideBorderSize.width - vScrollbarActualWidth,
|
||||
aState->mInsideBorderSize.height - hScrollbarActualHeight);
|
||||
|
||||
@ -411,21 +416,34 @@ nsHTMLScrollFrame::TryLayout(ScrollReflowState* aState,
|
||||
|
||||
aState->mShowHScrollbar = aAssumeHScroll;
|
||||
aState->mShowVScrollbar = aAssumeVScroll;
|
||||
nsPoint scrollPortOrigin(aState->mReflowState.mComputedBorderPadding.left,
|
||||
aState->mReflowState.mComputedBorderPadding.top);
|
||||
nsPoint scrollPortOrigin(aState->mComputedBorder.left,
|
||||
aState->mComputedBorder.top);
|
||||
if (!mInner.IsScrollbarOnRight()) {
|
||||
scrollPortOrigin.x += vScrollbarActualWidth;
|
||||
}
|
||||
aState->mScrollPortRect = nsRect(scrollPortOrigin, scrollPortSize);
|
||||
aState->mAscent = aKidMetrics.ascent;
|
||||
if (aKidMetrics.mComputeMEW) {
|
||||
aState->mMaxElementWidth = aKidMetrics.mMaxElementWidth + vScrollbarActualWidth;
|
||||
nscoord kidContentMEW = aKidMetrics.mMaxElementWidth -
|
||||
aState->mReflowState.mComputedPadding.LeftRight();
|
||||
NS_ASSERTION(kidContentMEW >= 0, "MEW didn't include padding?");
|
||||
aState->mMaxElementWidth = vScrollbarActualWidth +
|
||||
aState->mReflowState.mComputedPadding.LeftRight() +
|
||||
aState->mReflowState.AdjustIntrinsicMinContentWidthForStyle(kidContentMEW);
|
||||
// borders get added on the way out of Reflow()
|
||||
}
|
||||
if (aKidMetrics.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {
|
||||
aState->mMaximumWidth = aKidMetrics.mMaximumWidth;
|
||||
if (aState->mMaximumWidth != NS_UNCONSTRAINEDSIZE) {
|
||||
aState->mMaximumWidth += vScrollbarActualWidth;
|
||||
nscoord kidMaxWidth = aKidMetrics.mMaximumWidth;
|
||||
if (kidMaxWidth != NS_UNCONSTRAINEDSIZE) {
|
||||
nscoord kidContentMaxWidth = kidMaxWidth -
|
||||
aState->mReflowState.mComputedPadding.LeftRight();
|
||||
NS_ASSERTION(kidContentMaxWidth >= 0, "max-width didn't include padding?");
|
||||
kidMaxWidth = vScrollbarActualWidth +
|
||||
aState->mReflowState.mComputedPadding.LeftRight() +
|
||||
aState->mReflowState.AdjustIntrinsicContentWidthForStyle(kidContentMaxWidth);
|
||||
}
|
||||
aState->mMaximumWidth = kidMaxWidth;
|
||||
// borders get added on the way out of Reflow()
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
@ -434,24 +452,38 @@ nsresult
|
||||
nsHTMLScrollFrame::ReflowScrolledFrame(const ScrollReflowState& aState,
|
||||
PRBool aAssumeVScroll,
|
||||
nsHTMLReflowMetrics* aMetrics,
|
||||
nsMargin* aKidPadding,
|
||||
PRBool aFirstPass)
|
||||
{
|
||||
// these could be NS_UNCONSTRAINEDSIZE ... PR_MIN arithmetic should
|
||||
// be OK
|
||||
nscoord availWidth = PR_MIN(aState.mReflowState.mComputedMaxWidth,
|
||||
PR_MIN(aState.mReflowState.mComputedWidth,
|
||||
aState.mReflowState.availableWidth));
|
||||
nscoord paddingLR = aState.mReflowState.mComputedPadding.LeftRight();
|
||||
|
||||
nscoord availWidth = aState.mReflowState.availableWidth;
|
||||
if (aState.mReflowState.mComputedWidth != NS_UNCONSTRAINEDSIZE) {
|
||||
availWidth = aState.mReflowState.mComputedWidth + paddingLR;
|
||||
} else {
|
||||
if (aState.mReflowState.mComputedMaxWidth != NS_UNCONSTRAINEDSIZE) {
|
||||
availWidth = PR_MIN(availWidth,
|
||||
aState.mReflowState.mComputedMaxWidth + paddingLR);
|
||||
}
|
||||
if (aState.mReflowState.mComputedWidth != NS_UNCONSTRAINEDSIZE) {
|
||||
availWidth = PR_MIN(availWidth,
|
||||
aState.mReflowState.mComputedWidth + paddingLR);
|
||||
}
|
||||
}
|
||||
|
||||
if (availWidth != NS_UNCONSTRAINEDSIZE && aAssumeVScroll) {
|
||||
nsSize vScrollbarMinSize;
|
||||
mInner.mVScrollbarBox->GetMinSize(NS_CONST_CAST(nsBoxLayoutState&, aState.mBoxState),
|
||||
vScrollbarMinSize);
|
||||
availWidth = PR_MAX(0, availWidth - vScrollbarMinSize.width);
|
||||
}
|
||||
|
||||
nsHTMLReflowState kidReflowState(GetPresContext(), aState.mReflowState,
|
||||
mInner.mScrolledFrame,
|
||||
nsSize(availWidth, NS_UNCONSTRAINEDSIZE),
|
||||
aFirstPass ? aState.mNewReason : eReflowReason_Resize);
|
||||
|
||||
if (IsRTLTextControl()) {
|
||||
kidReflowState.mRightEdge = mInner.GetScrolledSize().width;
|
||||
}
|
||||
@ -462,7 +494,6 @@ nsHTMLScrollFrame::ReflowScrolledFrame(const ScrollReflowState& aState,
|
||||
FinishReflowChild(mInner.mScrolledFrame, GetPresContext(),
|
||||
&kidReflowState, *aMetrics, 0, 0,
|
||||
NS_FRAME_NO_MOVE_FRAME | NS_FRAME_NO_MOVE_VIEW);
|
||||
*aKidPadding = kidReflowState.mComputedPadding;
|
||||
|
||||
// XXX Some frames (e.g., nsObjectFrame, nsFrameFrame, nsTextFrame) don't bother
|
||||
// setting their mOverflowArea. This is wrong because every frame should
|
||||
@ -507,9 +538,8 @@ nsHTMLScrollFrame::ReflowContents(ScrollReflowState* aState,
|
||||
currentlyUsingVScrollbar = PR_FALSE;
|
||||
|
||||
nsHTMLReflowMetrics kidDesiredSize(aDesiredSize.mComputeMEW, aDesiredSize.mFlags);
|
||||
nsMargin kidPadding;
|
||||
nsresult rv = ReflowScrolledFrame(*aState, currentlyUsingVScrollbar,
|
||||
&kidDesiredSize, &kidPadding, PR_TRUE);
|
||||
&kidDesiredSize, PR_TRUE);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool didUseScrollbar = currentlyUsingVScrollbar;
|
||||
@ -534,14 +564,14 @@ nsHTMLScrollFrame::ReflowContents(ScrollReflowState* aState,
|
||||
aState->mStyles.mVertical != NS_STYLE_OVERFLOW_SCROLL &&
|
||||
aState->mStyles.mHorizontal != NS_STYLE_OVERFLOW_SCROLL) {
|
||||
nsSize insideBorderSize =
|
||||
ComputeInsideBorderSize(aState, nsSize(kidDesiredSize.width, kidDesiredSize.height),
|
||||
kidPadding);
|
||||
ComputeInsideBorderSize(aState,
|
||||
nsSize(kidDesiredSize.width, kidDesiredSize.height));
|
||||
if (kidDesiredSize.mOverflowArea.XMost() <= insideBorderSize.width &&
|
||||
kidDesiredSize.mOverflowArea.YMost() <= insideBorderSize.height) {
|
||||
// Let's pretend we had no vertical scrollbar coming in here
|
||||
currentlyUsingVScrollbar = PR_FALSE;
|
||||
rv = ReflowScrolledFrame(*aState, currentlyUsingVScrollbar,
|
||||
&kidDesiredSize, &kidPadding, PR_FALSE);
|
||||
&kidDesiredSize, PR_FALSE);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
didUseScrollbar = PR_FALSE;
|
||||
@ -549,9 +579,9 @@ nsHTMLScrollFrame::ReflowContents(ScrollReflowState* aState,
|
||||
}
|
||||
|
||||
// First try a layout without a horizontal scrollbar, then with.
|
||||
if (TryLayout(aState, kidDesiredSize, kidPadding, didUseScrollbar, PR_FALSE, PR_FALSE))
|
||||
if (TryLayout(aState, kidDesiredSize, didUseScrollbar, PR_FALSE, PR_FALSE))
|
||||
return NS_OK;
|
||||
if (TryLayout(aState, kidDesiredSize, kidPadding, didUseScrollbar, PR_TRUE, PR_FALSE))
|
||||
if (TryLayout(aState, kidDesiredSize, didUseScrollbar, PR_TRUE, PR_FALSE))
|
||||
return NS_OK;
|
||||
|
||||
// That didn't work. Try the other setting for the vertical scrollbar.
|
||||
@ -559,13 +589,13 @@ nsHTMLScrollFrame::ReflowContents(ScrollReflowState* aState,
|
||||
if (currentlyUsingVScrollbar || canHaveVerticalScrollbar) {
|
||||
nsHTMLReflowMetrics kidRetrySize(aDesiredSize.mComputeMEW, aDesiredSize.mFlags);
|
||||
rv = ReflowScrolledFrame(*aState, !currentlyUsingVScrollbar,
|
||||
&kidRetrySize, &kidPadding, PR_FALSE);
|
||||
&kidRetrySize, PR_FALSE);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
didUseScrollbar = !currentlyUsingVScrollbar;
|
||||
if (TryLayout(aState, kidRetrySize, kidPadding, didUseScrollbar, PR_FALSE, PR_FALSE))
|
||||
if (TryLayout(aState, kidRetrySize, didUseScrollbar, PR_FALSE, PR_FALSE))
|
||||
return NS_OK;
|
||||
if (TryLayout(aState, kidRetrySize, kidPadding, didUseScrollbar, PR_TRUE, PR_FALSE))
|
||||
if (TryLayout(aState, kidRetrySize, didUseScrollbar, PR_TRUE, PR_FALSE))
|
||||
return NS_OK;
|
||||
|
||||
NS_WARNING("Strange content ... we can't find logically consistent scrollbar settings");
|
||||
@ -576,11 +606,11 @@ nsHTMLScrollFrame::ReflowContents(ScrollReflowState* aState,
|
||||
// Fall back to no scrollbars --- even if NS_STYLE_OVERFLOW_SCROLL is
|
||||
// in effect. They might not fit anyway.
|
||||
if (didUseScrollbar) {
|
||||
rv = ReflowScrolledFrame(*aState, PR_FALSE, &kidDesiredSize, &kidPadding, PR_FALSE);
|
||||
rv = ReflowScrolledFrame(*aState, PR_FALSE, &kidDesiredSize, PR_FALSE);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
TryLayout(aState, kidDesiredSize, kidPadding, PR_FALSE, PR_FALSE, PR_TRUE);
|
||||
TryLayout(aState, kidDesiredSize, PR_FALSE, PR_FALSE, PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -693,7 +723,8 @@ nsHTMLScrollFrame::Reflow(nsPresContext* aPresContext,
|
||||
|
||||
nsRect oldScrollAreaBounds = mInner.mScrollableView->View()->GetBounds();
|
||||
nsRect oldScrolledAreaBounds = mInner.mScrolledFrame->GetView()->GetBounds();
|
||||
const nsMargin& borderPadding = aReflowState.mComputedBorderPadding;
|
||||
state.mComputedBorder = aReflowState.mComputedBorderPadding -
|
||||
aReflowState.mComputedPadding;
|
||||
|
||||
nsresult rv = ReflowContents(&state, aDesiredSize);
|
||||
if (NS_FAILED(rv))
|
||||
@ -712,9 +743,8 @@ nsHTMLScrollFrame::Reflow(nsPresContext* aPresContext,
|
||||
// is deleted, because the XMost of the frame's overflow area is always
|
||||
// at least the right edge. But it looks like it has always worked this way.
|
||||
nsHTMLReflowMetrics kidDesiredSize(aDesiredSize.mComputeMEW, aDesiredSize.mFlags);
|
||||
nsMargin kidPadding;
|
||||
rv = ReflowScrolledFrame(state, state.mShowVScrollbar,
|
||||
&kidDesiredSize, &kidPadding, PR_FALSE);
|
||||
&kidDesiredSize, PR_FALSE);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
@ -742,25 +772,26 @@ nsHTMLScrollFrame::Reflow(nsPresContext* aPresContext,
|
||||
mInner.SetScrollbarVisibility(mInner.mVScrollbarBox, state.mShowVScrollbar);
|
||||
// place and reflow scrollbars
|
||||
nsRect insideBorderArea =
|
||||
nsRect(nsPoint(borderPadding.left, borderPadding.top), state.mInsideBorderSize);
|
||||
nsRect(nsPoint(state.mComputedBorder.left, state.mComputedBorder.top),
|
||||
state.mInsideBorderSize);
|
||||
mInner.LayoutScrollbars(state.mBoxState, insideBorderArea,
|
||||
oldScrollAreaBounds, state.mScrollPortRect);
|
||||
}
|
||||
ScrollToRestoredPosition();
|
||||
|
||||
aDesiredSize.width = state.mInsideBorderSize.width +
|
||||
borderPadding.left + borderPadding.right;
|
||||
state.mComputedBorder.LeftRight();
|
||||
aDesiredSize.height = state.mInsideBorderSize.height +
|
||||
borderPadding.top + borderPadding.bottom;
|
||||
aDesiredSize.ascent = state.mAscent + borderPadding.top;
|
||||
state.mComputedBorder.TopBottom();
|
||||
aDesiredSize.ascent = state.mAscent + state.mComputedBorder.top;
|
||||
if (aDesiredSize.mComputeMEW) {
|
||||
aDesiredSize.mMaxElementWidth = state.mMaxElementWidth +
|
||||
borderPadding.left + borderPadding.right;
|
||||
state.mComputedBorder.LeftRight();
|
||||
}
|
||||
if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {
|
||||
aDesiredSize.mMaximumWidth = state.mMaximumWidth;
|
||||
if (aDesiredSize.mMaximumWidth != NS_UNCONSTRAINEDSIZE) {
|
||||
aDesiredSize.mMaximumWidth += borderPadding.left + borderPadding.right;
|
||||
aDesiredSize.mMaximumWidth += state.mComputedBorder.LeftRight();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -183,13 +183,11 @@ public:
|
||||
|
||||
PRBool TryLayout(ScrollReflowState* aState,
|
||||
const nsHTMLReflowMetrics& aKidMetrics,
|
||||
const nsMargin& aKidPadding,
|
||||
PRBool aAssumeVScroll, PRBool aAssumeHScroll,
|
||||
PRBool aForce);
|
||||
nsresult ReflowScrolledFrame(const ScrollReflowState& aState,
|
||||
PRBool aAssumeVScroll,
|
||||
nsHTMLReflowMetrics* aMetrics,
|
||||
nsMargin* aKidPadding,
|
||||
PRBool aFirstPass);
|
||||
nsresult ReflowContents(ScrollReflowState* aState,
|
||||
const nsHTMLReflowMetrics& aDesiredSize);
|
||||
|
@ -379,6 +379,64 @@ nsHTMLReflowState::GetContainingBlockContentWidth(const nsHTMLReflowState* aRefl
|
||||
return rs->mComputedWidth;
|
||||
}
|
||||
|
||||
nscoord
|
||||
nsHTMLReflowState::AdjustIntrinsicMinContentWidthForStyle(nscoord aWidth) const
|
||||
{
|
||||
nsStyleUnit widthUnit = mStylePosition->mWidth.GetUnit();
|
||||
if (eStyleUnit_Percent == widthUnit) {
|
||||
aWidth = 0;
|
||||
} else if (eStyleUnit_Coord == widthUnit) {
|
||||
NS_ASSERTION(NS_UNCONSTRAINEDSIZE != mComputedWidth,
|
||||
"Should be a computed width here");
|
||||
aWidth = mComputedWidth;
|
||||
}
|
||||
|
||||
nsStyleUnit maxWidthUnit = mStylePosition->mMaxWidth.GetUnit();
|
||||
if (eStyleUnit_Percent == maxWidthUnit) {
|
||||
aWidth = 0;
|
||||
} else if (eStyleUnit_Coord == maxWidthUnit) {
|
||||
NS_ASSERTION(NS_UNCONSTRAINEDSIZE != mComputedMaxWidth,
|
||||
"Should be a computed max-width here");
|
||||
aWidth = PR_MIN(aWidth, mComputedMaxWidth);
|
||||
}
|
||||
|
||||
nsStyleUnit minWidthUnit = mStylePosition->mMinWidth.GetUnit();
|
||||
if (eStyleUnit_Coord == minWidthUnit) {
|
||||
NS_ASSERTION(NS_UNCONSTRAINEDSIZE != mComputedMinWidth,
|
||||
"Should be a computed max-width here");
|
||||
aWidth = PR_MAX(aWidth, mComputedMinWidth);
|
||||
}
|
||||
|
||||
return aWidth;
|
||||
}
|
||||
|
||||
nscoord
|
||||
nsHTMLReflowState::AdjustIntrinsicContentWidthForStyle(nscoord aWidth) const
|
||||
{
|
||||
nsStyleUnit widthUnit = mStylePosition->mWidth.GetUnit();
|
||||
if (eStyleUnit_Coord == widthUnit) {
|
||||
NS_ASSERTION(NS_UNCONSTRAINEDSIZE != mComputedWidth,
|
||||
"Should be a computed width here");
|
||||
aWidth = mComputedWidth;
|
||||
}
|
||||
|
||||
nsStyleUnit maxWidthUnit = mStylePosition->mMaxWidth.GetUnit();
|
||||
if (eStyleUnit_Coord == maxWidthUnit) {
|
||||
NS_ASSERTION(NS_UNCONSTRAINEDSIZE != mComputedMaxWidth,
|
||||
"Should be a computed max-width here");
|
||||
aWidth = PR_MIN(aWidth, mComputedMaxWidth);
|
||||
}
|
||||
|
||||
nsStyleUnit minWidthUnit = mStylePosition->mMinWidth.GetUnit();
|
||||
if (eStyleUnit_Coord == minWidthUnit) {
|
||||
NS_ASSERTION(NS_UNCONSTRAINEDSIZE != mComputedMinWidth,
|
||||
"Should be a computed max-width here");
|
||||
aWidth = PR_MAX(aWidth, mComputedMinWidth);
|
||||
}
|
||||
|
||||
return aWidth;
|
||||
}
|
||||
|
||||
/* static */
|
||||
nsIFrame*
|
||||
nsHTMLReflowState::GetContainingBlockFor(const nsIFrame* aFrame)
|
||||
@ -1708,11 +1766,7 @@ nsHTMLReflowState::InitConstraints(nsPresContext* aPresContext,
|
||||
mComputedPadding.left = aPadding->left;
|
||||
}
|
||||
else {
|
||||
if (frame->GetType() == nsLayoutAtoms::scrollFrame) {
|
||||
mComputedPadding.SizeTo(0, 0, 0, 0);
|
||||
} else {
|
||||
ComputePadding(aContainingBlockWidth, cbrs);
|
||||
}
|
||||
ComputePadding(aContainingBlockWidth, cbrs);
|
||||
}
|
||||
if (aBorder) { // border is an input arg
|
||||
mComputedBorderPadding = *aBorder;
|
||||
|
Loading…
Reference in New Issue
Block a user