CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / layout / generic / nsPlaceholderFrame.h
blob2fc3c1d618c14a961cd5c99c3771595f871d8b25
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 ***** */
39 * rendering object for the point that anchors out-of-flow rendering
40 * objects such as floats and absolutely positioned elements
44 * Destruction of a placeholder and its out-of-flow must observe the
45 * following constraints:
47 * - The mapping from the out-of-flow to the placeholder must be
48 * removed from the frame manager before the placeholder is destroyed.
49 * - The mapping from the out-of-flow to the placeholder must be
50 * removed from the frame manager before the out-of-flow is destroyed.
51 * - The placeholder must be removed from the frame tree, or have the
52 * mapping from it to its out-of-flow cleared, before the out-of-flow
53 * is destroyed (so that the placeholder will not point to a destroyed
54 * frame while it's in the frame tree).
56 * Furthermore, some code assumes that placeholders point to something
57 * useful, so placeholders without an associated out-of-flow should not
58 * remain in the tree.
60 * The placeholder's Destroy() implementation handles the destruction of
61 * the placeholder and its out-of-flow. To avoid crashes, frame removal
62 * and destruction code that works with placeholders must not assume
63 * that the placeholder points to its out-of-flow.
66 #ifndef nsPlaceholderFrame_h___
67 #define nsPlaceholderFrame_h___
69 #include "nsFrame.h"
70 #include "nsGkAtoms.h"
72 nsIFrame* NS_NewPlaceholderFrame(nsIPresShell* aPresShell,
73 nsStyleContext* aContext,
74 nsFrameState aTypeBit);
76 // Frame state bits that are used to keep track of what this is a
77 // placeholder for.
78 #define PLACEHOLDER_FOR_FLOAT NS_FRAME_STATE_BIT(20)
79 #define PLACEHOLDER_FOR_ABSPOS NS_FRAME_STATE_BIT(21)
80 #define PLACEHOLDER_FOR_FIXEDPOS NS_FRAME_STATE_BIT(22)
81 #define PLACEHOLDER_FOR_POPUP NS_FRAME_STATE_BIT(23)
82 #define PLACEHOLDER_TYPE_MASK (PLACEHOLDER_FOR_FLOAT | \
83 PLACEHOLDER_FOR_ABSPOS | \
84 PLACEHOLDER_FOR_FIXEDPOS | \
85 PLACEHOLDER_FOR_POPUP)
87 /**
88 * Implementation of a frame that's used as a placeholder for a frame that
89 * has been moved out of the flow
91 class nsPlaceholderFrame : public nsFrame {
92 public:
93 NS_DECL_FRAMEARENA_HELPERS
95 /**
96 * Create a new placeholder frame. aTypeBit must be one of the
97 * PLACEHOLDER_FOR_* constants above.
99 friend nsIFrame* NS_NewPlaceholderFrame(nsIPresShell* aPresShell,
100 nsStyleContext* aContext,
101 nsFrameState aTypeBit);
102 nsPlaceholderFrame(nsStyleContext* aContext, nsFrameState aTypeBit) :
103 nsFrame(aContext)
105 NS_PRECONDITION(aTypeBit == PLACEHOLDER_FOR_FLOAT ||
106 aTypeBit == PLACEHOLDER_FOR_ABSPOS ||
107 aTypeBit == PLACEHOLDER_FOR_FIXEDPOS ||
108 aTypeBit == PLACEHOLDER_FOR_POPUP,
109 "Unexpected type bit");
110 AddStateBits(aTypeBit);
112 virtual ~nsPlaceholderFrame();
114 // Get/Set the associated out of flow frame
115 nsIFrame* GetOutOfFlowFrame() const {return mOutOfFlowFrame;}
116 void SetOutOfFlowFrame(nsIFrame* aFrame) {
117 NS_ASSERTION(!aFrame || !aFrame->GetPrevContinuation(),
118 "OOF must be first continuation");
119 mOutOfFlowFrame = aFrame;
122 // nsIHTMLReflow overrides
123 // We need to override GetMinWidth and GetPrefWidth because XUL uses
124 // placeholders not within lines.
125 virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext);
126 virtual nscoord GetPrefWidth(nsIRenderingContext *aRenderingContext);
127 virtual void AddInlineMinWidth(nsIRenderingContext *aRenderingContext,
128 InlineMinWidthData *aData);
129 virtual void AddInlinePrefWidth(nsIRenderingContext *aRenderingContext,
130 InlinePrefWidthData *aData);
131 virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState);
132 virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState);
133 virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState);
134 NS_IMETHOD Reflow(nsPresContext* aPresContext,
135 nsHTMLReflowMetrics& aDesiredSize,
136 const nsHTMLReflowState& aReflowState,
137 nsReflowStatus& aStatus);
139 virtual void DestroyFrom(nsIFrame* aDestructRoot);
141 // nsIFrame overrides
142 #if defined(DEBUG) || (defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF))
143 NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
144 const nsRect& aDirtyRect,
145 const nsDisplayListSet& aLists);
146 #endif // DEBUG || (MOZ_REFLOW_PERF_DSP && MOZ_REFLOW_PERF)
148 #ifdef DEBUG
149 NS_IMETHOD List(FILE* out, PRInt32 aIndent) const;
150 #endif // DEBUG
153 * Get the "type" of the frame
155 * @see nsGkAtoms::placeholderFrame
157 virtual nsIAtom* GetType() const;
159 #ifdef DEBUG
160 NS_IMETHOD GetFrameName(nsAString& aResult) const;
161 #endif
163 virtual PRBool IsEmpty() { return PR_TRUE; }
164 virtual PRBool IsSelfEmpty() { return PR_TRUE; }
166 virtual PRBool CanContinueTextRun() const;
168 #ifdef ACCESSIBILITY
169 virtual already_AddRefed<nsAccessible> CreateAccessible()
171 nsIFrame* realFrame = GetRealFrameForPlaceholder(this);
172 return realFrame ? realFrame->CreateAccessible() :
173 nsFrame::CreateAccessible();
175 #endif
177 NS_IMETHOD GetParentStyleContextFrame(nsPresContext* aPresContext,
178 nsIFrame** aProviderFrame,
179 PRBool* aIsChild);
181 * @return the out-of-flow for aFrame if aFrame is a placeholder; otherwise
182 * aFrame
184 static nsIFrame* GetRealFrameFor(nsIFrame* aFrame) {
185 NS_PRECONDITION(aFrame, "Must have a frame to work with");
186 if (aFrame->GetType() == nsGkAtoms::placeholderFrame) {
187 return GetRealFrameForPlaceholder(aFrame);
189 return aFrame;
193 * @return the out-of-flow for aFrame, which is known to be a placeholder
195 static nsIFrame* GetRealFrameForPlaceholder(nsIFrame* aFrame) {
196 NS_PRECONDITION(aFrame->GetType() == nsGkAtoms::placeholderFrame,
197 "Must have placeholder frame as input");
198 nsIFrame* outOfFlow =
199 static_cast<nsPlaceholderFrame*>(aFrame)->GetOutOfFlowFrame();
200 NS_ASSERTION(outOfFlow, "Null out-of-flow for placeholder?");
201 return outOfFlow;
204 protected:
205 nsIFrame* mOutOfFlowFrame;
208 #endif /* nsPlaceholderFrame_h___ */