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
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.
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"
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()
68 nsPlaceholderFrame::GetMinWidth(nsIRenderingContext
*aRenderingContext
)
71 DISPLAY_MIN_WIDTH(this, result
);
76 nsPlaceholderFrame::GetPrefWidth(nsIRenderingContext
*aRenderingContext
)
79 DISPLAY_PREF_WIDTH(this, result
);
84 nsPlaceholderFrame::GetMinSize(nsBoxLayoutState
& aBoxLayoutState
)
87 DISPLAY_MIN_SIZE(this, size
);
92 nsPlaceholderFrame::GetPrefSize(nsBoxLayoutState
& aBoxLayoutState
)
95 DISPLAY_PREF_SIZE(this, size
);
100 nsPlaceholderFrame::GetMaxSize(nsBoxLayoutState
& aBoxLayoutState
)
102 nsSize
size(NS_INTRINSICSIZE
, NS_INTRINSICSIZE
);
103 DISPLAY_MAX_SIZE(this, size
);
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
117 // ...but push floats onto the list
118 if (mOutOfFlowFrame
->GetStyleDisplay()->mFloats
!= NS_STYLE_FLOAT_NONE
)
119 aData
->floats
.AppendElement(mOutOfFlowFrame
);
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
132 // ...but push floats onto the list
133 if (mOutOfFlowFrame
->GetStyleDisplay()->mFloats
!= NS_STYLE_FLOAT_NONE
)
134 aData
->floats
.AppendElement(mOutOfFlowFrame
);
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
);
154 nsPlaceholderFrame::DestroyFrom(nsIFrame
* aDestructRoot
)
156 nsIPresShell
* shell
= PresContext()->GetPresShell();
157 nsIFrame
* oof
= mOutOfFlowFrame
;
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
);
178 nsPlaceholderFrame::GetType() const
180 return nsGkAtoms::placeholderFrame
;
184 nsPlaceholderFrame::CanContinueTextRun() const
186 if (!mOutOfFlowFrame
) {
189 // first-letter frames can continue text runs, and placeholders for floated
190 // first-letter frames can too
191 return mOutOfFlowFrame
->CanContinueTextRun();
195 nsPlaceholderFrame::GetParentStyleContextFrame(nsPresContext
* aPresContext
,
196 nsIFrame
** aProviderFrame
,
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.
206 CorrectStyleParentFrame(GetParent(), nsGkAtoms::placeholderFrame
);
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));
226 #if defined(DEBUG) || (defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF))
229 nsPlaceholderFrame::BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
230 const nsRect
& aDirtyRect
,
231 const nsDisplayListSet
& aLists
)
233 DO_GLOBAL_REFLOW_COUNT_DSP("nsPlaceholderFrame");
236 if (!GetShowFrameBorders())
239 return aLists
.Outlines()->AppendNewToTop(new (aBuilder
)
240 nsDisplayGeneric(this, PaintDebugPlaceholder
, "DebugPlaceholder",
241 nsDisplayItem::TYPE_DEBUG_PLACEHOLDER
));
246 #endif // DEBUG || (MOZ_REFLOW_PERF_DSP && MOZ_REFLOW_PERF)
250 nsPlaceholderFrame::GetFrameName(nsAString
& aResult
) const
252 return MakeFrameName(NS_LITERAL_STRING("Placeholder"), aResult
);
256 nsPlaceholderFrame::List(FILE* out
, PRInt32 aIndent
) const
258 IndentBy(out
, aIndent
);
260 #ifdef DEBUG_waterson
261 fprintf(out
, " [parent=%p]", static_cast<void*>(mParent
));
264 fprintf(out
, " [view=%p]", (void*)GetView());
266 fprintf(out
, " {%d,%d,%d,%d}", mRect
.x
, mRect
.y
, mRect
.width
, mRect
.height
);
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
);