Bug 574454 - Cleanup nsNativeThemeWin's GetMinimumWidgetSize a bit. r=roc.
[mozilla-central.git] / layout / generic / nsPlaceholderFrame.cpp
blobf3d1cbe6c6ef426f2f98b7c6a691b5924f3da2c4
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):
23 * Mats Palmgren <mats.palmgren@bredband.net>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 * rendering object for the point that anchors out-of-flow rendering
41 * objects such as floats and absolutely positioned elements
44 #include "nsLayoutUtils.h"
45 #include "nsPlaceholderFrame.h"
46 #include "nsLineLayout.h"
47 #include "nsIContent.h"
48 #include "nsPresContext.h"
49 #include "nsIRenderingContext.h"
50 #include "nsGkAtoms.h"
51 #include "nsFrameManager.h"
52 #include "nsDisplayList.h"
54 nsIFrame*
55 NS_NewPlaceholderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
56 nsFrameState aTypeBit)
58 return new (aPresShell) nsPlaceholderFrame(aContext, aTypeBit);
61 NS_IMPL_FRAMEARENA_HELPERS(nsPlaceholderFrame)
63 nsPlaceholderFrame::~nsPlaceholderFrame()
67 /* virtual */ nscoord
68 nsPlaceholderFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
70 nscoord result = 0;
71 DISPLAY_MIN_WIDTH(this, result);
72 return result;
75 /* virtual */ nscoord
76 nsPlaceholderFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
78 nscoord result = 0;
79 DISPLAY_PREF_WIDTH(this, result);
80 return result;
83 /* virtual */ nsSize
84 nsPlaceholderFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState)
86 nsSize size(0, 0);
87 DISPLAY_MIN_SIZE(this, size);
88 return size;
91 /* virtual */ nsSize
92 nsPlaceholderFrame::GetPrefSize(nsBoxLayoutState& aBoxLayoutState)
94 nsSize size(0, 0);
95 DISPLAY_PREF_SIZE(this, size);
96 return size;
99 /* virtual */ nsSize
100 nsPlaceholderFrame::GetMaxSize(nsBoxLayoutState& aBoxLayoutState)
102 nsSize size(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
103 DISPLAY_MAX_SIZE(this, size);
104 return size;
107 /* virtual */ void
108 nsPlaceholderFrame::AddInlineMinWidth(nsIRenderingContext *aRenderingContext,
109 nsIFrame::InlineMinWidthData *aData)
111 // Override AddInlineMinWith so that *nothing* happens. In
112 // particular, we don't want to zero out |aData->trailingWhitespace|,
113 // since nsLineLayout skips placeholders when trimming trailing
114 // whitespace, and we don't want to set aData->skipWhitespace to
115 // false.
117 // ...but push floats onto the list
118 if (mOutOfFlowFrame->GetStyleDisplay()->mFloats != NS_STYLE_FLOAT_NONE)
119 aData->floats.AppendElement(mOutOfFlowFrame);
122 /* virtual */ void
123 nsPlaceholderFrame::AddInlinePrefWidth(nsIRenderingContext *aRenderingContext,
124 nsIFrame::InlinePrefWidthData *aData)
126 // Override AddInlinePrefWith so that *nothing* happens. In
127 // particular, we don't want to zero out |aData->trailingWhitespace|,
128 // since nsLineLayout skips placeholders when trimming trailing
129 // whitespace, and we don't want to set aData->skipWhitespace to
130 // false.
132 // ...but push floats onto the list
133 if (mOutOfFlowFrame->GetStyleDisplay()->mFloats != NS_STYLE_FLOAT_NONE)
134 aData->floats.AppendElement(mOutOfFlowFrame);
137 NS_IMETHODIMP
138 nsPlaceholderFrame::Reflow(nsPresContext* aPresContext,
139 nsHTMLReflowMetrics& aDesiredSize,
140 const nsHTMLReflowState& aReflowState,
141 nsReflowStatus& aStatus)
143 DO_GLOBAL_REFLOW_COUNT("nsPlaceholderFrame");
144 DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
145 aDesiredSize.width = 0;
146 aDesiredSize.height = 0;
148 aStatus = NS_FRAME_COMPLETE;
149 NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
150 return NS_OK;
153 void
154 nsPlaceholderFrame::DestroyFrom(nsIFrame* aDestructRoot)
156 nsIPresShell* shell = PresContext()->GetPresShell();
157 nsIFrame* oof = mOutOfFlowFrame;
158 if (oof) {
159 // Unregister out-of-flow frame
160 shell->FrameManager()->UnregisterPlaceholderFrame(this);
161 mOutOfFlowFrame = nsnull;
162 // If aDestructRoot is not an ancestor of the out-of-flow frame,
163 // then call RemoveFrame on it here.
164 // Also destroy it here if it's a popup frame. (Bug 96291)
165 if (shell->FrameManager() &&
166 ((GetStateBits() & PLACEHOLDER_FOR_FLOAT) ||
167 !nsLayoutUtils::IsProperAncestorFrame(aDestructRoot, oof))) {
168 nsIAtom* listName = nsLayoutUtils::GetChildListNameFor(oof);
169 shell->FrameManager()->RemoveFrame(listName, oof);
171 // else oof will be destroyed by its parent
174 nsFrame::DestroyFrom(aDestructRoot);
177 nsIAtom*
178 nsPlaceholderFrame::GetType() const
180 return nsGkAtoms::placeholderFrame;
183 /* virtual */ PRBool
184 nsPlaceholderFrame::CanContinueTextRun() const
186 if (!mOutOfFlowFrame) {
187 return PR_FALSE;
189 // first-letter frames can continue text runs, and placeholders for floated
190 // first-letter frames can too
191 return mOutOfFlowFrame->CanContinueTextRun();
194 NS_IMETHODIMP
195 nsPlaceholderFrame::GetParentStyleContextFrame(nsPresContext* aPresContext,
196 nsIFrame** aProviderFrame,
197 PRBool* aIsChild)
199 NS_PRECONDITION(GetParent(), "How can we not have a parent here?");
200 *aIsChild = PR_FALSE;
202 // Lie about our pseudo so we can step out of all anon boxes and
203 // pseudo-elements. The other option would be to reimplement the
204 // {ib} split gunk here.
205 *aProviderFrame =
206 CorrectStyleParentFrame(GetParent(), nsGkAtoms::placeholderFrame);
207 return NS_OK;
211 #ifdef DEBUG
212 static void
213 PaintDebugPlaceholder(nsIFrame* aFrame, nsIRenderingContext* aCtx,
214 const nsRect& aDirtyRect, nsPoint aPt)
216 aCtx->SetColor(NS_RGB(0, 255, 255));
217 nscoord x = nsPresContext::CSSPixelsToAppUnits(-5);
218 aCtx->FillRect(aPt.x + x, aPt.y,
219 nsPresContext::CSSPixelsToAppUnits(13), nsPresContext::CSSPixelsToAppUnits(3));
220 nscoord y = nsPresContext::CSSPixelsToAppUnits(-10);
221 aCtx->FillRect(aPt.x, aPt.y + y,
222 nsPresContext::CSSPixelsToAppUnits(3), nsPresContext::CSSPixelsToAppUnits(10));
224 #endif // DEBUG
226 #if defined(DEBUG) || (defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF))
228 NS_IMETHODIMP
229 nsPlaceholderFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
230 const nsRect& aDirtyRect,
231 const nsDisplayListSet& aLists)
233 DO_GLOBAL_REFLOW_COUNT_DSP("nsPlaceholderFrame");
235 #ifdef DEBUG
236 if (!GetShowFrameBorders())
237 return NS_OK;
239 return aLists.Outlines()->AppendNewToTop(new (aBuilder)
240 nsDisplayGeneric(this, PaintDebugPlaceholder, "DebugPlaceholder",
241 nsDisplayItem::TYPE_DEBUG_PLACEHOLDER));
242 #else // DEBUG
243 return NS_OK;
244 #endif // DEBUG
246 #endif // DEBUG || (MOZ_REFLOW_PERF_DSP && MOZ_REFLOW_PERF)
248 #ifdef DEBUG
249 NS_IMETHODIMP
250 nsPlaceholderFrame::GetFrameName(nsAString& aResult) const
252 return MakeFrameName(NS_LITERAL_STRING("Placeholder"), aResult);
255 NS_IMETHODIMP
256 nsPlaceholderFrame::List(FILE* out, PRInt32 aIndent) const
258 IndentBy(out, aIndent);
259 ListTag(out);
260 #ifdef DEBUG_waterson
261 fprintf(out, " [parent=%p]", static_cast<void*>(mParent));
262 #endif
263 if (HasView()) {
264 fprintf(out, " [view=%p]", (void*)GetView());
266 fprintf(out, " {%d,%d,%d,%d}", mRect.x, mRect.y, mRect.width, mRect.height);
267 if (0 != mState) {
268 fprintf(out, " [state=%016llx]", mState);
270 nsIFrame* prevInFlow = GetPrevInFlow();
271 nsIFrame* nextInFlow = GetNextInFlow();
272 if (nsnull != prevInFlow) {
273 fprintf(out, " prev-in-flow=%p", static_cast<void*>(prevInFlow));
275 if (nsnull != nextInFlow) {
276 fprintf(out, " next-in-flow=%p", static_cast<void*>(nextInFlow));
278 if (nsnull != mContent) {
279 fprintf(out, " [content=%p]", static_cast<void*>(mContent));
281 if (nsnull != mStyleContext) {
282 fprintf(out, " [sc=%p]", static_cast<void*>(mStyleContext));
284 if (mOutOfFlowFrame) {
285 fprintf(out, " outOfFlowFrame=");
286 nsFrame::ListTag(out, mOutOfFlowFrame);
288 fputs("\n", out);
289 return NS_OK;
291 #endif