Bug 508473 part III: Pass destruction root to frame destruction methods r=bz sr=roc
[gecko.git] / layout / generic / nsInlineFrame.h
blob0d18d125b0b356d7fc9042776f40877e4fc81ac8
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 Communicator client 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 ***** */
38 /* rendering object for CSS display:inline objects */
40 #ifndef nsInlineFrame_h___
41 #define nsInlineFrame_h___
43 #include "nsHTMLContainerFrame.h"
44 #include "nsAbsoluteContainingBlock.h"
45 #include "nsLineLayout.h"
47 class nsAnonymousBlockFrame;
49 #define nsInlineFrameSuper nsHTMLContainerFrame
51 // NS_INLINE_FRAME_HARD_TEXT_OFFSETS is used for access keys, where what
52 // would normally be 1 text frame is split into 3 sets of an inline parent
53 // and text child (the pre access key text, the underlined key text, and
54 // the post access key text). The offsets of the 3 text frame children
55 // are set in nsCSSFrameConstructor
57 #define NS_INLINE_FRAME_HARD_TEXT_OFFSETS 0x00100000
59 /** In Bidi left (or right) margin/padding/border should be applied to left
60 * (or right) most frame (or a continuation frame).
61 * This state value shows if this frame is left (or right) most continuation
62 * or not.
64 #define NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET 0x00200000
66 #define NS_INLINE_FRAME_BIDI_VISUAL_IS_LEFT_MOST 0x00400000
68 #define NS_INLINE_FRAME_BIDI_VISUAL_IS_RIGHT_MOST 0x00800000
70 /**
71 * Inline frame class.
73 * This class manages a list of child frames that are inline frames. Working with
74 * nsLineLayout, the class will reflow and place inline frames on a line.
76 class nsInlineFrame : public nsInlineFrameSuper
78 public:
79 NS_DECL_QUERYFRAME_TARGET(nsInlineFrame)
80 NS_DECL_QUERYFRAME
81 NS_DECL_FRAMEARENA_HELPERS
83 friend nsIFrame* NS_NewInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
85 // nsIFrame overrides
86 NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
87 const nsRect& aDirtyRect,
88 const nsDisplayListSet& aLists);
90 #ifdef ACCESSIBILITY
91 NS_IMETHODIMP GetAccessible(nsIAccessible** aAccessible);
92 #endif
94 #ifdef DEBUG
95 NS_IMETHOD GetFrameName(nsAString& aResult) const;
96 #endif
97 virtual nsIAtom* GetType() const;
99 virtual PRBool IsFrameOfType(PRUint32 aFlags) const
101 return nsInlineFrameSuper::IsFrameOfType(aFlags &
102 ~(nsIFrame::eBidiInlineContainer | nsIFrame::eLineParticipant));
105 virtual PRBool IsEmpty();
106 virtual PRBool IsSelfEmpty();
108 virtual PRBool PeekOffsetCharacter(PRBool aForward, PRInt32* aOffset);
110 // nsIHTMLReflow overrides
111 virtual void AddInlineMinWidth(nsIRenderingContext *aRenderingContext,
112 InlineMinWidthData *aData);
113 virtual void AddInlinePrefWidth(nsIRenderingContext *aRenderingContext,
114 InlinePrefWidthData *aData);
115 virtual nsSize ComputeSize(nsIRenderingContext *aRenderingContext,
116 nsSize aCBSize, nscoord aAvailableWidth,
117 nsSize aMargin, nsSize aBorder, nsSize aPadding,
118 PRBool aShrinkWrap);
119 virtual nsRect ComputeTightBounds(gfxContext* aContext) const;
120 NS_IMETHOD Reflow(nsPresContext* aPresContext,
121 nsHTMLReflowMetrics& aDesiredSize,
122 const nsHTMLReflowState& aReflowState,
123 nsReflowStatus& aStatus);
125 virtual PRBool CanContinueTextRun() const;
127 virtual void PullOverflowsFromPrevInFlow();
130 * Return true if the frame is leftmost frame or continuation.
132 PRBool IsLeftMost() const {
133 // If the frame's bidi visual state is set, return is-leftmost state
134 // else return true if it's the first continuation.
135 return (GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET)
136 ? !!(GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_IS_LEFT_MOST)
137 : (!GetPrevInFlow());
141 * Return true if the frame is rightmost frame or continuation.
143 PRBool IsRightMost() const {
144 // If the frame's bidi visual state is set, return is-rightmost state
145 // else return true if it's the last continuation.
146 return (GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET)
147 ? !!(GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_IS_RIGHT_MOST)
148 : (!GetNextInFlow());
151 protected:
152 // Additional reflow state used during our reflow methods
153 struct InlineReflowState {
154 nsIFrame* mPrevFrame;
155 nsInlineFrame* mNextInFlow;
156 nsIFrame* mLineContainer;
157 nsLineLayout* mLineLayout;
158 PRPackedBool mSetParentPointer; // when reflowing child frame first set its
159 // parent frame pointer
161 InlineReflowState() {
162 mPrevFrame = nsnull;
163 mNextInFlow = nsnull;
164 mLineContainer = nsnull;
165 mLineLayout = nsnull;
166 mSetParentPointer = PR_FALSE;
170 nsInlineFrame(nsStyleContext* aContext) : nsInlineFrameSuper(aContext) {}
172 virtual PRIntn GetSkipSides() const;
174 nsresult ReflowFrames(nsPresContext* aPresContext,
175 const nsHTMLReflowState& aReflowState,
176 InlineReflowState& rs,
177 nsHTMLReflowMetrics& aMetrics,
178 nsReflowStatus& aStatus);
180 nsresult ReflowInlineFrame(nsPresContext* aPresContext,
181 const nsHTMLReflowState& aReflowState,
182 InlineReflowState& rs,
183 nsIFrame* aFrame,
184 nsReflowStatus& aStatus);
187 * Reparent floats whose placeholders are inline descendants of aFrame from
188 * whatever block they're currently parented by to aOurBlock.
189 * @param aReparentSiblings if this is true, we follow aFrame's
190 * GetNextSibling chain reparenting them all
192 void ReparentFloatsForInlineChild(nsIFrame* aOurBlock, nsIFrame* aFrame,
193 PRBool aReparentSiblings);
195 virtual nsIFrame* PullOneFrame(nsPresContext* aPresContext,
196 InlineReflowState& rs,
197 PRBool* aIsComplete);
199 virtual void PushFrames(nsPresContext* aPresContext,
200 nsIFrame* aFromChild,
201 nsIFrame* aPrevSibling,
202 InlineReflowState& aState);
206 //----------------------------------------------------------------------
209 * Variation on inline-frame used to manage lines for line layout in
210 * special situations (:first-line style in particular).
212 class nsFirstLineFrame : public nsInlineFrame {
213 public:
214 NS_DECL_FRAMEARENA_HELPERS
216 friend nsIFrame* NS_NewFirstLineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
218 #ifdef DEBUG
219 NS_IMETHOD GetFrameName(nsAString& aResult) const;
220 #endif
221 virtual nsIAtom* GetType() const;
222 NS_IMETHOD Reflow(nsPresContext* aPresContext,
223 nsHTMLReflowMetrics& aDesiredSize,
224 const nsHTMLReflowState& aReflowState,
225 nsReflowStatus& aStatus);
227 virtual void PullOverflowsFromPrevInFlow();
229 protected:
230 nsFirstLineFrame(nsStyleContext* aContext) : nsInlineFrame(aContext) {}
232 virtual nsIFrame* PullOneFrame(nsPresContext* aPresContext,
233 InlineReflowState& rs,
234 PRBool* aIsComplete);
237 //----------------------------------------------------------------------
239 // Derived class created for relatively positioned inline-level elements
240 // that acts as a containing block for child absolutely positioned
241 // elements
243 class nsPositionedInlineFrame : public nsInlineFrame
245 public:
246 NS_DECL_FRAMEARENA_HELPERS
248 nsPositionedInlineFrame(nsStyleContext* aContext)
249 : nsInlineFrame(aContext)
250 , mAbsoluteContainer(nsGkAtoms::absoluteList)
253 virtual ~nsPositionedInlineFrame() { } // useful for debugging
255 virtual void DestroyFrom(nsIFrame* aDestructRoot);
257 NS_IMETHOD SetInitialChildList(nsIAtom* aListName,
258 nsFrameList& aChildList);
259 NS_IMETHOD AppendFrames(nsIAtom* aListName,
260 nsFrameList& aFrameList);
261 NS_IMETHOD InsertFrames(nsIAtom* aListName,
262 nsIFrame* aPrevFrame,
263 nsFrameList& aFrameList);
264 NS_IMETHOD RemoveFrame(nsIAtom* aListName,
265 nsIFrame* aOldFrame);
267 NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
268 const nsRect& aDirtyRect,
269 const nsDisplayListSet& aLists);
271 virtual nsIAtom* GetAdditionalChildListName(PRInt32 aIndex) const;
273 virtual nsFrameList GetChildList(nsIAtom* aListName) const;
275 NS_IMETHOD Reflow(nsPresContext* aPresContext,
276 nsHTMLReflowMetrics& aDesiredSize,
277 const nsHTMLReflowState& aReflowState,
278 nsReflowStatus& aStatus);
280 virtual nsIAtom* GetType() const;
282 virtual PRBool NeedsView() { return PR_TRUE; }
284 protected:
285 nsAbsoluteContainingBlock mAbsoluteContainer;
288 #endif /* nsInlineFrame_h___ */