Bug 1279354 part 2 - Make the nsProgressFrame code a bit more idiomatic by processing its actual child frames. r=dholbert

This commit is contained in:
Mats Palmgren 2016-11-28 23:00:20 +01:00
parent 7c01c6afca
commit 046c6cd826
2 changed files with 28 additions and 26 deletions

View File

@ -118,6 +118,9 @@ nsProgressFrame::Reflow(nsPresContext* aPresContext,
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
NS_ASSERTION(mBarDiv, "Progress bar div must exist!");
NS_ASSERTION(PrincipalChildList().GetLength() == 1 &&
PrincipalChildList().FirstChild() == mBarDiv->GetPrimaryFrame(),
"unexpected child frames");
NS_ASSERTION(!GetPrevContinuation(),
"nsProgressFrame should not have continuations; if it does we "
"need to call RegUnregAccessKey only for the first.");
@ -126,15 +129,15 @@ nsProgressFrame::Reflow(nsPresContext* aPresContext,
nsFormControlFrame::RegUnRegAccessKey(this, true);
}
nsIFrame* barFrame = mBarDiv->GetPrimaryFrame();
NS_ASSERTION(barFrame, "The progress frame should have a child with a frame!");
ReflowBarFrame(barFrame, aPresContext, aReflowInput, aStatus);
aDesiredSize.SetSize(aReflowInput.GetWritingMode(),
aReflowInput.ComputedSizeWithBorderPadding());
aDesiredSize.SetOverflowAreasToDesiredBounds();
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, barFrame);
for (auto childFrame : PrincipalChildList()) {
ReflowChildFrame(childFrame, aPresContext, aReflowInput, aStatus);
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, childFrame);
}
FinishAndStoreOverflow(&aDesiredSize);
aStatus = NS_FRAME_COMPLETE;
@ -143,17 +146,16 @@ nsProgressFrame::Reflow(nsPresContext* aPresContext,
}
void
nsProgressFrame::ReflowBarFrame(nsIFrame* aBarFrame,
nsPresContext* aPresContext,
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus)
nsProgressFrame::ReflowChildFrame(nsIFrame* aChild,
nsPresContext* aPresContext,
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus)
{
bool vertical = ResolvedOrientationIsVertical();
WritingMode wm = aBarFrame->GetWritingMode();
WritingMode wm = aChild->GetWritingMode();
LogicalSize availSize = aReflowInput.ComputedSize(wm);
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
ReflowInput reflowInput(aPresContext, aReflowInput,
aBarFrame, availSize);
ReflowInput reflowInput(aPresContext, aReflowInput, aChild, availSize);
nscoord size = vertical ? aReflowInput.ComputedHeight()
: aReflowInput.ComputedWidth();
nscoord xoffset = aReflowInput.ComputedPhysicalBorderPadding().left;
@ -204,9 +206,9 @@ nsProgressFrame::ReflowBarFrame(nsIFrame* aBarFrame,
yoffset += reflowInput.ComputedPhysicalMargin().top;
ReflowOutput barDesiredSize(aReflowInput);
ReflowChild(aBarFrame, aPresContext, barDesiredSize, reflowInput, xoffset,
ReflowChild(aChild, aPresContext, barDesiredSize, reflowInput, xoffset,
yoffset, 0, aStatus);
FinishReflowChild(aBarFrame, aPresContext, barDesiredSize, &reflowInput,
FinishReflowChild(aChild, aPresContext, barDesiredSize, &reflowInput,
xoffset, yoffset, 0);
}
@ -219,10 +221,11 @@ nsProgressFrame::AttributeChanged(int32_t aNameSpaceID,
if (aNameSpaceID == kNameSpaceID_None &&
(aAttribute == nsGkAtoms::value || aAttribute == nsGkAtoms::max)) {
nsIFrame* barFrame = mBarDiv->GetPrimaryFrame();
NS_ASSERTION(barFrame, "The progress frame should have a child with a frame!");
PresContext()->PresShell()->FrameNeedsReflow(barFrame, nsIPresShell::eResize,
NS_FRAME_IS_DIRTY);
auto shell = PresContext()->PresShell();
for (auto childFrame : PrincipalChildList()) {
shell->FrameNeedsReflow(childFrame, nsIPresShell::eResize,
NS_FRAME_IS_DIRTY);
}
InvalidateFrame();
}
@ -279,7 +282,7 @@ nsProgressFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
bool
nsProgressFrame::ShouldUseNativeStyle() const
{
nsIFrame* barFrame = mBarDiv->GetPrimaryFrame();
nsIFrame* barFrame = PrincipalChildList().FirstChild();
// Use the native style if these conditions are satisfied:
// - both frames use the native appearance;

View File

@ -86,11 +86,11 @@ public:
virtual Element* GetPseudoElement(CSSPseudoElementType aType) override;
protected:
// Helper function which reflow the anonymous div frame.
void ReflowBarFrame(nsIFrame* aBarFrame,
nsPresContext* aPresContext,
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus);
// Helper function to reflow a child frame.
void ReflowChildFrame(nsIFrame* aChild,
nsPresContext* aPresContext,
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus);
/**
* The div used to show the progress bar.
@ -100,4 +100,3 @@ protected:
};
#endif