Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / nsPageContentFrame.cpp
blob57b8b17507e65a2add13caefa5bf90fb1b02a191
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsPageContentFrame.h"
6 #include "nsCSSFrameConstructor.h"
7 #include "nsPresContext.h"
8 #include "nsGkAtoms.h"
9 #include "nsIPresShell.h"
10 #include "nsSimplePageSequenceFrame.h"
12 using mozilla::LogicalSize;
13 using mozilla::WritingMode;
15 nsPageContentFrame*
16 NS_NewPageContentFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
18 return new (aPresShell) nsPageContentFrame(aContext);
21 NS_IMPL_FRAMEARENA_HELPERS(nsPageContentFrame)
23 void
24 nsPageContentFrame::Reflow(nsPresContext* aPresContext,
25 nsHTMLReflowMetrics& aDesiredSize,
26 const nsHTMLReflowState& aReflowState,
27 nsReflowStatus& aStatus)
29 DO_GLOBAL_REFLOW_COUNT("nsPageContentFrame");
30 DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
31 aStatus = NS_FRAME_COMPLETE; // initialize out parameter
33 if (GetPrevInFlow() && (GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
34 nsresult rv = aPresContext->PresShell()->FrameConstructor()
35 ->ReplicateFixedFrames(this);
36 if (NS_FAILED(rv)) {
37 return;
41 // Set our size up front, since some parts of reflow depend on it
42 // being already set. Note that the computed height may be
43 // unconstrained; that's ok. Consumers should watch out for that.
44 nsSize maxSize(aReflowState.ComputedWidth(),
45 aReflowState.ComputedHeight());
46 SetSize(maxSize);
48 // A PageContentFrame must always have one child: the canvas frame.
49 // Resize our frame allowing it only to be as big as we are
50 // XXX Pay attention to the page's border and padding...
51 if (mFrames.NotEmpty()) {
52 nsIFrame* frame = mFrames.FirstChild();
53 WritingMode wm = frame->GetWritingMode();
54 LogicalSize logicalSize(wm, maxSize);
55 nsHTMLReflowState kidReflowState(aPresContext, aReflowState,
56 frame, logicalSize);
57 kidReflowState.SetComputedBSize(logicalSize.BSize(wm));
59 // Reflow the page content area
60 ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, 0, 0, 0, aStatus);
62 // The document element's background should cover the entire canvas, so
63 // take into account the combined area and any space taken up by
64 // absolutely positioned elements
65 nsMargin padding(0,0,0,0);
67 // XXXbz this screws up percentage padding (sets padding to zero
68 // in the percentage padding case)
69 kidReflowState.mStylePadding->GetPadding(padding);
71 // This is for shrink-to-fit, and therefore we want to use the
72 // scrollable overflow, since the purpose of shrink to fit is to
73 // make the content that ought to be reachable (represented by the
74 // scrollable overflow) fit in the page.
75 if (frame->HasOverflowAreas()) {
76 // The background covers the content area and padding area, so check
77 // for children sticking outside the child frame's padding edge
78 nscoord xmost = aDesiredSize.ScrollableOverflow().XMost();
79 if (xmost > aDesiredSize.Width()) {
80 nscoord widthToFit = xmost + padding.right +
81 kidReflowState.mStyleBorder->GetComputedBorderWidth(NS_SIDE_RIGHT);
82 float ratio = float(maxSize.width) / widthToFit;
83 NS_ASSERTION(ratio >= 0.0 && ratio < 1.0, "invalid shrink-to-fit ratio");
84 mPD->mShrinkToFitRatio = std::min(mPD->mShrinkToFitRatio, ratio);
88 // Place and size the child
89 FinishReflowChild(frame, aPresContext, aDesiredSize, &kidReflowState, 0, 0, 0);
91 NS_ASSERTION(aPresContext->IsDynamic() || !NS_FRAME_IS_FULLY_COMPLETE(aStatus) ||
92 !frame->GetNextInFlow(), "bad child flow list");
95 // Reflow our fixed frames
96 nsReflowStatus fixedStatus = NS_FRAME_COMPLETE;
97 ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowState, fixedStatus);
98 NS_ASSERTION(NS_FRAME_IS_COMPLETE(fixedStatus), "fixed frames can be truncated, but not incomplete");
100 // Return our desired size
101 WritingMode wm = aReflowState.GetWritingMode();
102 aDesiredSize.ISize(wm) = aReflowState.ComputedISize();
103 if (aReflowState.ComputedBSize() != NS_UNCONSTRAINEDSIZE) {
104 aDesiredSize.BSize(wm) = aReflowState.ComputedBSize();
106 FinishAndStoreOverflow(&aDesiredSize);
108 NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
111 nsIAtom*
112 nsPageContentFrame::GetType() const
114 return nsGkAtoms::pageContentFrame;
117 #ifdef DEBUG_FRAME_DUMP
118 nsresult
119 nsPageContentFrame::GetFrameName(nsAString& aResult) const
121 return MakeFrameName(NS_LITERAL_STRING("PageContent"), aResult);
123 #endif