Back to index

lightning-sunbird  0.9+nobinonly
nsReflowPath.cpp
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 #include <stdio.h>
00042 #include "pldhash.h"
00043 #include "prenv.h"
00044 #include "nsReflowPath.h"
00045 #include "nsFrame.h"
00046 #include "nsIFrame.h"
00047 #include "nsHTMLReflowCommand.h"
00048 
00049 nsReflowPath::~nsReflowPath()
00050 {
00051     for (PRInt32 i = mChildren.Count() - 1; i >= 0; --i)
00052         delete NS_STATIC_CAST(nsReflowPath *, mChildren[i]);
00053 
00054     delete mReflowCommand;
00055 }
00056 
00057 nsReflowPath::iterator
00058 nsReflowPath::FindChild(nsIFrame *aFrame)
00059 {
00060     for (PRInt32 i = mChildren.Count() - 1; i >= 0; --i) {
00061         nsReflowPath *subtree = NS_STATIC_CAST(nsReflowPath *, mChildren[i]);
00062         if (subtree->mFrame == aFrame)
00063             return iterator(this, i);
00064     }
00065 
00066     return iterator(this, -1);
00067 }
00068 
00069 nsReflowPath *
00070 nsReflowPath::GetSubtreeFor(nsIFrame *aFrame) const
00071 {
00072     for (PRInt32 i = mChildren.Count() - 1; i >= 0; --i) {
00073         nsReflowPath *subtree = NS_STATIC_CAST(nsReflowPath *, mChildren[i]);
00074         if (subtree->mFrame == aFrame)
00075             return subtree;
00076     }
00077 
00078     return nsnull;
00079 }
00080 
00081 nsReflowPath *
00082 nsReflowPath::EnsureSubtreeFor(nsIFrame *aFrame)
00083 {
00084     for (PRInt32 i = mChildren.Count() - 1; i >= 0; --i) {
00085         nsReflowPath *subtree = NS_STATIC_CAST(nsReflowPath *, mChildren[i]);
00086         if (subtree->mFrame == aFrame)
00087             return subtree;
00088     }
00089 
00090     nsReflowPath *subtree = new nsReflowPath(aFrame);
00091     mChildren.AppendElement(subtree);
00092 
00093     return subtree;
00094 }
00095 
00096 void
00097 nsReflowPath::Remove(iterator &aIterator)
00098 {
00099     NS_ASSERTION(aIterator.mNode == this, "inconsistent iterator");
00100 
00101     if (aIterator.mIndex >= 0 && aIterator.mIndex < mChildren.Count()) {
00102         delete NS_STATIC_CAST(nsReflowPath *, mChildren[aIterator.mIndex]);
00103         mChildren.RemoveElementAt(aIterator.mIndex);
00104     }
00105 }
00106 
00107 #ifdef DEBUG
00108 void
00109 DebugListReflowPath(nsPresContext *aPresContext, nsReflowPath *aReflowPath)
00110 {
00111     aReflowPath->Dump(aPresContext, stdout, 0);
00112 }
00113 
00114 void
00115 nsReflowPath::Dump(nsPresContext *aPresContext, FILE *aFile, int depth)
00116 {
00117     fprintf(aFile, "%*s nsReflowPath(%p): ", depth, "", this);
00118 
00119     nsFrame::ListTag(aFile, mFrame);
00120 
00121     if (mReflowCommand) {
00122         fprintf(aFile, " <- ");
00123         mReflowCommand->List(aFile);
00124     }
00125 
00126     fprintf(aFile, "\n");
00127 
00128     for (PRInt32 i = 0; i < mChildren.Count(); ++i) {
00129         nsReflowPath *child = NS_STATIC_CAST(nsReflowPath *, mChildren[i]);
00130         child->Dump(aPresContext, aFile, depth + 1);
00131     }
00132 }
00133 #endif