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 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.
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 /* class for maintaining a linked list of child frames */
40 #ifndef nsFrameList_h___
41 #define nsFrameList_h___
46 * A class for managing a singly linked list of frames. Frames are
47 * linked together through their next-sibling pointer.
56 nsFrameList(nsIFrame
* aHead
) {
68 // Delete this and destroy all its frames
71 void SetFrames(nsIFrame
* aFrameList
) {
72 mFirstChild
= aFrameList
;
78 // Appends frames from aFrameList to this list. If aParent
79 // is not null, reparents the newly-added frames.
80 void AppendFrames(nsIFrame
* aParent
, nsIFrame
* aFrameList
);
82 void AppendFrames(nsIFrame
* aParent
, nsFrameList
& aFrameList
) {
83 AppendFrames(aParent
, aFrameList
.mFirstChild
);
84 aFrameList
.mFirstChild
= nsnull
;
87 void AppendFrame(nsIFrame
* aParent
, nsIFrame
* aFrame
);
89 // Take aFrame out of the frame list. This also disconnects aFrame
90 // from the sibling list. This will return PR_FALSE if aFrame is
91 // nsnull or if aFrame is not in the list. The second frame is
92 // a hint for the prev-sibling of aFrame; if the hint is correct,
93 // then this is O(1) time. If successfully removed, the child's
94 // NextSibling pointer is cleared.
95 PRBool
RemoveFrame(nsIFrame
* aFrame
, nsIFrame
* aPrevSiblingHint
= nsnull
);
97 // Remove the first child from the list. The caller is assumed to be
98 // holding a reference to the first child. This call is equivalent
99 // in behavior to calling RemoveFrame(FirstChild()). If successfully
100 // removed the first child's NextSibling pointer is cleared.
101 PRBool
RemoveFirstChild();
103 // Take aFrame out of the frame list and then destroy it. This also
104 // disconnects aFrame from the sibling list. This will return
105 // PR_FALSE if aFrame is nsnull or if aFrame is not in the list.
106 PRBool
DestroyFrame(nsIFrame
* aFrame
);
108 // Inserts aNewFrame right after aPrevSibling, or prepends to
109 // list if aPrevSibling is null. If aParent is not null, also
110 // reparents newly-added frame. Note that this method always
111 // sets the frame's nextSibling pointer.
112 void InsertFrame(nsIFrame
* aParent
,
113 nsIFrame
* aPrevSibling
,
114 nsIFrame
* aNewFrame
);
116 // Inserts aFrameList right after aPrevSibling, or prepends to
117 // list if aPrevSibling is null. If aParent is not null, also
118 // reparents newly-added frame.
119 void InsertFrames(nsIFrame
* aParent
,
120 nsIFrame
* aPrevSibling
,
121 nsIFrame
* aFrameList
);
123 void InsertFrames(nsIFrame
* aParent
, nsIFrame
* aPrevSibling
,
124 nsFrameList
& aFrameList
) {
125 InsertFrames(aParent
, aPrevSibling
, aFrameList
.FirstChild());
126 aFrameList
.mFirstChild
= nsnull
;
129 PRBool
Split(nsIFrame
* aAfterFrame
, nsIFrame
** aNextFrameResult
);
132 * Sort the frames according to content order so that the first
133 * frame in the list is the first in content order. Frames for
134 * the same content will be ordered so that a prev in flow
135 * comes before its next in flow.
137 void SortByContentOrder();
139 nsIFrame
* FirstChild() const {
143 nsIFrame
* LastChild() const;
145 nsIFrame
* FrameAt(PRInt32 aIndex
) const;
147 PRBool
IsEmpty() const {
148 return nsnull
== mFirstChild
;
151 PRBool
NotEmpty() const {
152 return nsnull
!= mFirstChild
;
155 PRBool
ContainsFrame(const nsIFrame
* aFrame
) const;
156 PRBool
ContainsFrameBefore(const nsIFrame
* aFrame
, const nsIFrame
* aEnd
) const;
158 PRInt32
GetLength() const;
160 nsIFrame
* GetPrevSiblingFor(nsIFrame
* aFrame
) const;
164 * Return the frame before this frame in visual order (after Bidi reordering).
165 * If aFrame is null, return the last frame in visual order.
167 nsIFrame
* GetPrevVisualFor(nsIFrame
* aFrame
) const;
170 * Return the frame after this frame in visual order (after Bidi reordering).
171 * If aFrame is null, return the first frame in visual order.
173 nsIFrame
* GetNextVisualFor(nsIFrame
* aFrame
) const;
176 void VerifyParent(nsIFrame
* aParent
) const;
179 void List(FILE* out
) const;
184 void CheckForLoops();
188 nsIFrame
* mFirstChild
;
191 #endif /* nsFrameList_h___ */