Bug 1177614 - Provide a utility method on nsHTMLReflowState to return the computed size including border-padding, for use as a container for logical coordinate conversions, or zero if unconstrained. r=dholbert

This commit is contained in:
Jonathan Kew
2015-07-16 10:07:46 +01:00
parent 60de05da69
commit f5df4578f3
7 changed files with 28 additions and 45 deletions

View File

@@ -866,8 +866,8 @@ nsComboboxControlFrame::Reflow(nsPresContext* aPresContext,
// The button should occupy the same space as a scrollbar
WritingMode wm = aReflowState.GetWritingMode();
nscoord containerWidth = aReflowState.ComputedWidth() +
aReflowState.ComputedPhysicalBorderPadding().LeftRight();
nscoord containerWidth =
aReflowState.ComputedSizeAsContainerIfConstrained().width;
LogicalRect buttonRect = mButtonFrame->GetLogicalRect(containerWidth);
buttonRect.IStart(wm) =

View File

@@ -1266,8 +1266,7 @@ nsHTMLReflowState::CalculateHypotheticalBox(nsPresContext* aPresContext,
// relatively positioned...
WritingMode cbwm = cbrs->GetWritingMode();
nscoord containerWidth = containingBlock->GetStateBits() & NS_FRAME_IN_REFLOW
? cbrs->ComputedWidth() +
cbrs->ComputedLogicalBorderPadding().LeftRight(cbwm)
? cbrs->ComputedSizeAsContainerIfConstrained().width
: containingBlock->GetSize().width;
LogicalPoint placeholderOffset(wm, aPlaceholderFrame->GetOffsetTo(containingBlock),
containerWidth);

View File

@@ -447,6 +447,17 @@ struct nsHTMLReflowState : public nsCSSOffsetState {
void SetComputedLogicalOffsets(const LogicalMargin& aOffsets)
{ mComputedOffsets = aOffsets.GetPhysicalMargin(mWritingMode); }
// Return the state's computed size including border-padding, with
// unconstrained dimensions replaced by zero.
nsSize ComputedSizeAsContainerIfConstrained() const {
const nscoord wd = ComputedWidth();
const nscoord ht = ComputedHeight();
return nsSize(wd == NS_UNCONSTRAINEDSIZE
? 0 : wd + ComputedPhysicalBorderPadding().LeftRight(),
ht == NS_UNCONSTRAINEDSIZE
? 0 : ht + ComputedPhysicalBorderPadding().TopBottom());
}
private:
// the available width in which to reflow the frame. The space
// represents the amount of room for the frame's margin, border,

View File

@@ -944,14 +944,9 @@ nsTableCellFrame::Reflow(nsPresContext* aPresContext,
kidReflowState.SetBResize(true);
}
nscoord containerWidth;
if (aReflowState.ComputedWidth() == NS_UNCONSTRAINEDSIZE) {
containerWidth = 0; // avoid passing unconstrained container width to
// ReflowChild; but position will not be valid
} else {
containerWidth = aReflowState.ComputedWidth() +
aReflowState.ComputedPhysicalBorderPadding().LeftRight();
}
nscoord containerWidth =
aReflowState.ComputedSizeAsContainerIfConstrained().width;
LogicalPoint kidOrigin(wm, borderPadding.IStart(wm),
borderPadding.BStart(wm));
nsRect origRect = firstKid->GetRect();

View File

@@ -2973,19 +2973,11 @@ nsTableFrame::ReflowChildren(nsTableReflowState& aReflowState,
nsIFrame* prevKidFrame = nullptr;
WritingMode wm = aReflowState.reflowState.GetWritingMode();
nscoord containerWidth = aReflowState.reflowState.ComputedWidth();
if (containerWidth == NS_UNCONSTRAINEDSIZE) {
NS_WARN_IF_FALSE(wm.IsVertical(),
"shouldn't have unconstrained width in horizontal mode");
// We won't know the containerWidth until we've reflowed our contents,
// so use zero for now; in vertical-rl mode, this will mean the children
// are misplaced in the block-direction, and will need to be moved
// rightwards by the true containerWidth once we know it.
containerWidth = 0;
} else {
containerWidth +=
aReflowState.reflowState.ComputedPhysicalBorderPadding().LeftRight();
}
NS_WARN_IF_FALSE(wm.IsVertical() || NS_UNCONSTRAINEDSIZE !=
aReflowState.reflowState.ComputedWidth(),
"shouldn't have unconstrained width in horizontal mode");
nscoord containerWidth =
aReflowState.reflowState.ComputedSizeAsContainerIfConstrained().width;
nsPresContext* presContext = PresContext();
// XXXldb Should we be checking constrained height instead?
@@ -3388,12 +3380,8 @@ nsTableFrame::DistributeBSizeToRows(const nsHTMLReflowState& aReflowState,
WritingMode wm = aReflowState.GetWritingMode();
LogicalMargin borderPadding = GetChildAreaOffset(wm, &aReflowState);
nscoord containerWidth = aReflowState.ComputedWidth();
if (containerWidth == NS_UNCONSTRAINEDSIZE) {
containerWidth = 0;
} else {
containerWidth += aReflowState.ComputedPhysicalBorderPadding().LeftRight();
}
nscoord containerWidth =
aReflowState.ComputedSizeAsContainerIfConstrained().width;
RowGroupArray rowGroups;
OrderRowGroups(rowGroups);

View File

@@ -817,12 +817,8 @@ nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext,
// Reflow each of our existing cell frames
WritingMode wm = aReflowState.GetWritingMode();
nscoord containerWidth = aReflowState.ComputedWidth();
if (containerWidth == NS_UNCONSTRAINEDSIZE) {
containerWidth = 0; // cell positions will not yet be correct
} else {
containerWidth += aReflowState.ComputedPhysicalBorderPadding().LeftRight();
}
nscoord containerWidth =
aReflowState.ComputedSizeAsContainerIfConstrained().width;
for (nsIFrame* kidFrame : mFrames) {
nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);

View File

@@ -346,14 +346,8 @@ nsTableRowGroupFrame::ReflowChildren(nsPresContext* aPresContext,
// get the necessary containerWidth for placing our kids
bool needToCalcRowBSizes = reflowAllKids || wm.IsVerticalRL();
nscoord containerWidth = aReflowState.reflowState.ComputedWidth();
if (containerWidth == NS_UNCONSTRAINEDSIZE) {
containerWidth = 0; // we can't position frames correctly in RTL yet,
// so they will need to be adjusted later
} else {
containerWidth +=
aReflowState.reflowState.ComputedPhysicalBorderPadding().LeftRight();
}
nscoord containerWidth =
aReflowState.reflowState.ComputedSizeAsContainerIfConstrained().width;
nsIFrame *prevKidFrame = nullptr;
for (nsIFrame* kidFrame = mFrames.FirstChild(); kidFrame;