Back to index

lightning-sunbird  0.9+nobinonly
nsReflowPath.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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.org 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) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Mike Shaver <shaver@mozilla.org>
00024  *   Randell Jesup <rjesup@wgate.com>
00025  *   Chris Waterson <waterson@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #ifndef nsReflowPath_h__
00042 #define nsReflowPath_h__
00043 
00044 #include "nscore.h"
00045 #include "pldhash.h"
00046 #include "nsReflowType.h"
00047 #include "nsVoidArray.h"
00048 
00049 #ifdef DEBUG
00050 #include <stdio.h>
00051 #endif
00052 
00053 class nsIFrame;
00054 class nsHTMLReflowCommand;
00055 class nsPresContext;
00056 
00062 class nsReflowPath
00063 {
00064 public:
00069     nsReflowPath(nsIFrame *aFrame)
00070         : mFrame(aFrame),
00071           mReflowCommand(nsnull) {}
00072 
00073     ~nsReflowPath();
00074 
00079     class iterator
00080     {
00081     protected:
00082         nsReflowPath *mNode;
00083         PRInt32 mIndex;
00084 
00085         friend class nsReflowPath;
00086 
00087         iterator(nsReflowPath *aNode, PRInt32 aIndex)
00088             : mNode(aNode), mIndex(aIndex) {}
00089 
00090         void
00091         Advance() { --mIndex; }
00092 
00093     public:
00094         iterator()
00095             : mNode(nsnull) {}
00096 
00097         iterator(const iterator &iter)
00098             : mNode(iter.mNode), mIndex(iter.mIndex) {}
00099 
00100         iterator &
00101         operator=(const iterator &iter) {
00102             mNode = iter.mNode;
00103             mIndex = iter.mIndex;
00104             return *this; }
00105 
00106         nsReflowPath *
00107         get() const {
00108             return NS_STATIC_CAST(nsReflowPath *, mNode->mChildren[mIndex]); }
00109 
00110         nsReflowPath *
00111         get() {
00112             return NS_STATIC_CAST(nsReflowPath *, mNode->mChildren[mIndex]); }
00113 
00114         nsIFrame *
00115         operator*() const {
00116             return get()->mFrame; }
00117 
00118         nsIFrame *&
00119         operator*() {
00120             return get()->mFrame; }
00121 
00122         iterator &
00123         operator++() { Advance(); return *this; }
00124 
00125         iterator
00126         operator++(int) {
00127             iterator temp(*this);
00128             Advance();
00129             return temp; }
00130 
00131         PRBool
00132         operator==(const iterator &iter) const {
00133             return (mNode == iter.mNode) && (mIndex == iter.mIndex); }
00134 
00135         PRBool
00136         operator!=(const iterator &iter) const {
00137             return !iter.operator==(*this); }
00138     };
00139 
00144     iterator FirstChild() { return iterator(this, mChildren.Count() - 1); }
00145 
00150     iterator EndChildren() { return iterator(this, -1); }
00151 
00156     PRBool
00157     HasChild(nsIFrame *aFrame) const {
00158         return GetSubtreeFor(aFrame) != nsnull; }
00159 
00165     iterator
00166     FindChild(nsIFrame *aFrame);
00167 
00173     void
00174     RemoveChild(nsIFrame *aFrame) { 
00175         iterator iter = FindChild(aFrame);
00176         Remove(iter); }
00177 
00182     nsReflowPath *
00183     GetSubtreeFor(nsIFrame *aFrame) const;
00184 
00190     nsReflowPath *
00191     EnsureSubtreeFor(nsIFrame *aFrame);
00192 
00197     void
00198     Remove(iterator &aIterator);
00199 
00200 #ifdef DEBUG
00201 
00204     void
00205     Dump(nsPresContext *aPresContext, FILE *aFile, int aDepth);
00206 #endif
00207 
00211     nsIFrame            *mFrame;
00212 
00220     nsHTMLReflowCommand *mReflowCommand;
00221 
00222 protected:
00227     nsSmallVoidArray     mChildren;
00228 
00229     friend class iterator;
00230 };
00231 
00232 #endif