Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLReflowCommand.cpp
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.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) 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 #include "nsCOMPtr.h"
00038 #include "nsHTMLReflowCommand.h"
00039 #include "nsHTMLParts.h"
00040 #include "nsIFrame.h"
00041 #include "nsPresContext.h"
00042 #include "nsIPresShell.h"
00043 #include "nsIContent.h"
00044 #include "nsStyleConsts.h"
00045 #include "nsFrame.h"
00046 #include "nsContainerFrame.h"
00047 #include "nsLayoutAtoms.h"
00048 
00049 #ifdef DEBUG_jesup
00050 PRInt32 gReflows;
00051 PRInt32 gReflowsInUse;
00052 PRInt32 gReflowsInUseMax;
00053 PRInt32 gReflowsZero;
00054 PRInt32 gReflowsAuto;
00055 PRInt32 gReflowsLarger;
00056 PRInt32 gReflowsMaxZero;
00057 PRInt32 gReflowsMaxAuto;
00058 PRInt32 gReflowsMaxLarger;
00059 class mPathStats {
00060 public:
00061   mPathStats();
00062   ~mPathStats();
00063 };
00064 mPathStats::mPathStats()
00065 {
00066 }
00067 mPathStats::~mPathStats()
00068 {
00069   printf("nsHTMLReflowCommand->mPath stats:\n");
00070   printf("\tNumber created:   %d\n",gReflows);
00071   printf("\tNumber in-use:    %d\n",gReflowsInUseMax);
00072 
00073   printf("\tNumber size == 0: %d\n",gReflowsZero);
00074   printf("\tNumber size <= 8: %d\n",gReflowsAuto);
00075   printf("\tNumber size  > 8: %d\n",gReflowsLarger);
00076   printf("\tNum max size == 0: %d\n",gReflowsMaxZero);
00077   printf("\tNum max size <= 8: %d\n",gReflowsMaxAuto);
00078   printf("\tNum max size  > 8: %d\n",gReflowsMaxLarger);
00079 }
00080 
00081 // Just so constructor/destructor's get called
00082 mPathStats gmPathStats;
00083 #endif
00084 
00085 // Construct a reflow command given a target frame, reflow command type,
00086 // and optional child frame
00087 nsHTMLReflowCommand::nsHTMLReflowCommand(nsIFrame*    aTargetFrame,
00088                                          nsReflowType aReflowType,
00089                                          nsIAtom*     aChildListName)
00090   : mType(aReflowType), mTargetFrame(aTargetFrame), mListName(aChildListName),
00091     mFlags(0)
00092 {
00093   MOZ_COUNT_CTOR(nsHTMLReflowCommand);
00094   NS_PRECONDITION(mTargetFrame != nsnull, "null target frame");
00095 #ifdef DEBUG_jesup
00096   gReflows++;
00097   gReflowsInUse++;
00098   if (gReflowsInUse > gReflowsInUseMax)
00099     gReflowsInUseMax = gReflowsInUse;
00100 #endif
00101 }
00102 
00103 nsHTMLReflowCommand::~nsHTMLReflowCommand()
00104 {
00105   MOZ_COUNT_DTOR(nsHTMLReflowCommand);
00106 #ifdef DEBUG_jesup
00107   if (mPath.GetArraySize() == 0)
00108     gReflowsMaxZero++;
00109   else if (mPath.GetArraySize() <= 8)
00110     gReflowsMaxAuto++;
00111   else
00112     gReflowsMaxLarger++;
00113   gReflowsInUse--;
00114 #endif
00115 }
00116 
00117 nsresult
00118 nsHTMLReflowCommand::List(FILE* out) const
00119 {
00120 #ifdef DEBUG
00121   static const char* kReflowCommandType[] = {
00122     "ContentChanged",
00123     "StyleChanged",
00124     "ReflowDirty",
00125     "UserDefined",
00126   };
00127 
00128   fprintf(out, "ReflowCommand@%p[%s]:",
00129           this, kReflowCommandType[mType]);
00130   if (mTargetFrame) {
00131     fprintf(out, " target=");
00132     nsFrame::ListTag(out, mTargetFrame);
00133   }
00134   if (mListName) {
00135     fprintf(out, " list=");
00136     nsAutoString attr;
00137     mListName->ToString(attr);
00138     fputs(NS_LossyConvertUCS2toASCII(attr).get(), out);
00139   }
00140   fprintf(out, "\n");
00141 
00142   // Show the path, but without using mPath which is in an undefined
00143   // state at this point.
00144   if (mTargetFrame) {
00145     PRBool didOne = PR_FALSE;
00146     for (nsIFrame* f = mTargetFrame; f; f = f->GetParent()) {
00147       if (f != mTargetFrame) {
00148         fprintf(out, " ");
00149         nsFrame::ListTag(out, f);
00150         didOne = PR_TRUE;
00151       }
00152     }
00153     if (didOne) {
00154       fprintf(out, "\n");
00155     }
00156   }
00157 #endif
00158   return NS_OK;
00159 }