Back to index

lightning-sunbird  0.9+nobinonly
nsFrameList.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsFrameList_h___
00038 #define nsFrameList_h___
00039 
00040 #include "nsIFrame.h"
00041 
00046 class nsFrameList {
00047 public:
00048   nsFrameList() {
00049     mFirstChild = nsnull;
00050   }
00051 
00052   nsFrameList(nsIFrame* aHead) {
00053     mFirstChild = aHead;
00054 #ifdef DEBUG
00055     CheckForLoops();
00056 #endif
00057   }
00058 
00059   ~nsFrameList() {
00060   }
00061 
00062   void DestroyFrames(nsPresContext* aPresContext);
00063 
00064   void SetFrames(nsIFrame* aFrameList) {
00065     mFirstChild = aFrameList;
00066 #ifdef DEBUG
00067     CheckForLoops();
00068 #endif
00069   }
00070 
00071   void AppendFrames(nsIFrame* aParent, nsIFrame* aFrameList);
00072 
00073   void AppendFrames(nsIFrame* aParent, nsFrameList& aFrameList) {
00074     AppendFrames(aParent, aFrameList.mFirstChild);
00075     aFrameList.mFirstChild = nsnull;
00076   }
00077 
00078   void AppendFrame(nsIFrame* aParent, nsIFrame* aFrame);
00079 
00080   // Take aFrame out of the frame list. This also disconnects aFrame
00081   // from the sibling list. This will return PR_FALSE if aFrame is
00082   // nsnull or if aFrame is not in the list. The second frame is
00083   // a hint for the prev-sibling of aFrame; if the hint is correct,
00084   // then this is O(1) time.
00085   PRBool RemoveFrame(nsIFrame* aFrame, nsIFrame* aPrevSiblingHint = nsnull);
00086 
00087   // Remove the first child from the list. The caller is assumed to be
00088   // holding a reference to the first child. This call is equivalent
00089   // in behavior to calling RemoveFrame(FirstChild()).
00090   PRBool RemoveFirstChild();
00091 
00092   // Take aFrame out of the frame list and then destroy it. This also
00093   // disconnects aFrame from the sibling list. This will return
00094   // PR_FALSE if aFrame is nsnull or if aFrame is not in the list.
00095   PRBool DestroyFrame(nsPresContext* aPresContext, nsIFrame* aFrame);
00096 
00097   void InsertFrame(nsIFrame* aParent,
00098                    nsIFrame* aPrevSibling,
00099                    nsIFrame* aNewFrame);
00100 
00101   void InsertFrames(nsIFrame* aParent,
00102                     nsIFrame* aPrevSibling,
00103                     nsIFrame* aFrameList);
00104 
00105   void InsertFrames(nsIFrame* aParent, nsIFrame* aPrevSibling,
00106                     nsFrameList& aFrameList) {
00107     InsertFrames(aParent, aPrevSibling, aFrameList.FirstChild());
00108     aFrameList.mFirstChild = nsnull;
00109   }
00110 
00111   PRBool ReplaceFrame(nsIFrame* aParent,
00112                       nsIFrame* aOldFrame,
00113                       nsIFrame* aNewFrame,
00114                       PRBool aDestroy);
00115 
00116   PRBool Split(nsIFrame* aAfterFrame, nsIFrame** aNextFrameResult);
00117 
00124   void SortByContentOrder();
00125 
00126   nsIFrame* FirstChild() const {
00127     return mFirstChild;
00128   }
00129 
00130   nsIFrame* LastChild() const;
00131 
00132   nsIFrame* FrameAt(PRInt32 aIndex) const;
00133 
00134   PRBool IsEmpty() const {
00135     return nsnull == mFirstChild;
00136   }
00137 
00138   PRBool NotEmpty() const {
00139     return nsnull != mFirstChild;
00140   }
00141 
00142   PRBool ContainsFrame(const nsIFrame* aFrame) const;
00143 
00144   PRInt32 GetLength() const;
00145 
00146   nsIFrame* GetPrevSiblingFor(nsIFrame* aFrame) const;
00147 
00148 #ifdef IBMBIDI
00149 
00152   nsIFrame* GetPrevVisualFor(nsIFrame* aFrame) const;
00153 
00157   nsIFrame* GetNextVisualFor(nsIFrame* aFrame) const;
00158 #endif // IBMBIDI
00159 
00160   void VerifyParent(nsIFrame* aParent) const;
00161 
00162 #ifdef NS_DEBUG
00163   void List(nsPresContext* aPresContext, FILE* out) const;
00164 #endif
00165 
00166 private:
00167   PRBool DoReplaceFrame(nsIFrame* aParent,
00168                         nsIFrame* aOldFrame,
00169                         nsIFrame* aNewFrame);
00170 
00171 #ifdef DEBUG
00172   void CheckForLoops();
00173 #endif
00174   
00175 protected:
00176   nsIFrame* mFirstChild;
00177 };
00178 
00179 #endif /* nsFrameList_h___ */