Bug 54488 - "[Mac] Non-draggable widgets in background windows should look disabled...
[mozilla-central.git] / layout / generic / nsPageContentFrame.cpp
blob83602d45c37346419303ef8b100141a66c3f4d08
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 #include "nsPageContentFrame.h"
38 #include "nsPageFrame.h"
39 #include "nsPlaceholderFrame.h"
40 #include "nsCSSFrameConstructor.h"
41 #include "nsHTMLContainerFrame.h"
42 #include "nsHTMLParts.h"
43 #include "nsIContent.h"
44 #include "nsPresContext.h"
45 #include "nsIRenderingContext.h"
46 #include "nsGkAtoms.h"
47 #include "nsIPresShell.h"
48 #include "nsIDeviceContext.h"
49 #include "nsReadableUtils.h"
50 #include "nsSimplePageSequence.h"
51 #include "nsDisplayList.h"
53 nsIFrame*
54 NS_NewPageContentFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
56 return new (aPresShell) nsPageContentFrame(aContext);
59 /* virtual */ nsSize
60 nsPageContentFrame::ComputeSize(nsIRenderingContext *aRenderingContext,
61 nsSize aCBSize, nscoord aAvailableWidth,
62 nsSize aMargin, nsSize aBorder, nsSize aPadding,
63 PRBool aShrinkWrap)
65 NS_ASSERTION(mPD, "Pages are supposed to have page data");
66 nscoord height = (!mPD || mPD->mReflowSize.height == NS_UNCONSTRAINEDSIZE)
67 ? NS_UNCONSTRAINEDSIZE
68 : (mPD->mReflowSize.height - mPD->mReflowMargin.TopBottom());
69 return nsSize(aAvailableWidth, height);
72 NS_IMETHODIMP
73 nsPageContentFrame::Reflow(nsPresContext* aPresContext,
74 nsHTMLReflowMetrics& aDesiredSize,
75 const nsHTMLReflowState& aReflowState,
76 nsReflowStatus& aStatus)
78 DO_GLOBAL_REFLOW_COUNT("nsPageContentFrame");
79 DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
80 aStatus = NS_FRAME_COMPLETE; // initialize out parameter
81 nsresult rv = NS_OK;
83 if (GetPrevInFlow() && (GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
84 nsresult rv = aPresContext->PresShell()->FrameConstructor()
85 ->ReplicateFixedFrames(this);
86 NS_ENSURE_SUCCESS(rv, rv);
89 // A PageContentFrame must always have one child: the canvas frame.
90 // Resize our frame allowing it only to be as big as we are
91 // XXX Pay attention to the page's border and padding...
92 if (mFrames.NotEmpty()) {
93 nsIFrame* frame = mFrames.FirstChild();
94 nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
95 nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame, maxSize);
96 kidReflowState.SetComputedHeight(aReflowState.availableHeight);
98 mPD->mPageContentSize = aReflowState.availableWidth;
100 // Reflow the page content area
101 rv = ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, 0, 0, 0, aStatus);
102 NS_ENSURE_SUCCESS(rv, rv);
104 // The document element's background should cover the entire canvas, so
105 // take into account the combined area and any space taken up by
106 // absolutely positioned elements
107 nsMargin padding(0,0,0,0);
109 // XXXbz this screws up percentage padding (sets padding to zero
110 // in the percentage padding case)
111 kidReflowState.mStylePadding->GetPadding(padding);
113 // First check the combined area
114 if (NS_FRAME_OUTSIDE_CHILDREN & frame->GetStateBits()) {
115 // The background covers the content area and padding area, so check
116 // for children sticking outside the child frame's padding edge
117 if (aDesiredSize.mOverflowArea.XMost() > aDesiredSize.width) {
118 mPD->mPageContentXMost =
119 aDesiredSize.mOverflowArea.XMost() +
120 kidReflowState.mStyleBorder->GetActualBorderWidth(NS_SIDE_RIGHT) +
121 padding.right;
125 // Place and size the child
126 FinishReflowChild(frame, aPresContext, &kidReflowState, aDesiredSize, 0, 0, 0);
128 NS_ASSERTION(aPresContext->IsDynamic() || !NS_FRAME_IS_FULLY_COMPLETE(aStatus) ||
129 !frame->GetNextInFlow(), "bad child flow list");
131 // Reflow our fixed frames
132 nsReflowStatus fixedStatus = NS_FRAME_COMPLETE;
133 mFixedContainer.Reflow(this, aPresContext, aReflowState, fixedStatus,
134 aReflowState.availableWidth,
135 aReflowState.availableHeight,
136 PR_FALSE, PR_TRUE, PR_TRUE); // XXX could be optimized
137 NS_ASSERTION(NS_FRAME_IS_COMPLETE(fixedStatus), "fixed frames can be truncated, but not incomplete");
139 // Return our desired size
140 aDesiredSize.width = aReflowState.availableWidth;
141 if (aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) {
142 aDesiredSize.height = aReflowState.availableHeight;
145 NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
146 return NS_OK;
149 nsIAtom*
150 nsPageContentFrame::GetType() const
152 return nsGkAtoms::pageContentFrame;
155 #ifdef DEBUG
156 NS_IMETHODIMP
157 nsPageContentFrame::GetFrameName(nsAString& aResult) const
159 return MakeFrameName(NS_LITERAL_STRING("PageContent"), aResult);
161 #endif
163 /* virtual */ PRBool
164 nsPageContentFrame::IsContainingBlock() const
166 return PR_TRUE;