Back to index

lightning-sunbird  0.9+nobinonly
nsBlockReflowState.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  *   Steve Clark <buster@netscape.com>
00024  *   Robert O'Callahan <roc+moz@cs.cmu.edu>
00025  *   L. David Baron <dbaron@dbaron.org>
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 nsBlockReflowState_h__
00042 #define nsBlockReflowState_h__
00043 
00044 #include "nsBlockBandData.h"
00045 #include "nsLineBox.h"
00046 #include "nsFrameList.h"
00047 
00048 class nsBlockFrame;
00049 
00050   // block reflow state flags
00051 #define BRS_UNCONSTRAINEDWIDTH    0x00000001
00052 #define BRS_UNCONSTRAINEDHEIGHT   0x00000002
00053 #define BRS_SHRINKWRAPWIDTH       0x00000004
00054 #define BRS_NEEDRESIZEREFLOW      0x00000008
00055 #define BRS_ISTOPMARGINROOT       0x00000020  // Is this frame a root for top/bottom margin collapsing?
00056 #define BRS_ISBOTTOMMARGINROOT    0x00000040
00057 #define BRS_APPLYTOPMARGIN        0x00000080  // See ShouldApplyTopMargin
00058 #define BRS_COMPUTEMAXELEMENTWIDTH 0x00000100
00059 #define BRS_COMPUTEMAXWIDTH       0x00000200
00060 #define BRS_ISFIRSTINFLOW         0x00000400
00061 #define BRS_LASTFLAG              BRS_ISFIRSTINFLOW
00062 
00063 class nsBlockReflowState {
00064 public:
00065   nsBlockReflowState(const nsHTMLReflowState& aReflowState,
00066                      nsPresContext* aPresContext,
00067                      nsBlockFrame* aFrame,
00068                      const nsHTMLReflowMetrics& aMetrics,
00069                      PRBool aTopMarginRoot, PRBool aBottomMarginRoot);
00070 
00071   ~nsBlockReflowState();
00072 
00073   // Set up a property on the block that points to our temporary mOverflowPlaceholders
00074   // list, if that list is or could become non-empty during this reflow. Must be
00075   // called after the block has done DrainOverflowLines because DrainOverflowLines
00076   // can setup mOverflowPlaceholders even if the block is in unconstrained height
00077   // reflow (it may have previously been reflowed with constrained height).
00078   void SetupOverflowPlaceholdersProperty();
00079 
00085   void GetAvailableSpace() { GetAvailableSpace(mY, PR_FALSE); }
00086   void GetAvailableSpace(nscoord aY, PRBool aRelaxHeightConstraint);
00087 
00088   /*
00089    * The following functions all return PR_TRUE if they were able to
00090    * place the float, PR_FALSE if the float did not fit in available
00091    * space.
00092    */
00093   PRBool InitFloat(nsLineLayout&       aLineLayout,
00094                    nsPlaceholderFrame* aPlaceholderFrame,
00095                    nsReflowStatus&     aReflowStatus);
00096   PRBool AddFloat(nsLineLayout&       aLineLayout,
00097                   nsPlaceholderFrame* aPlaceholderFrame,
00098                   PRBool              aInitialReflow,
00099                   nsReflowStatus&     aReflowStatus);
00100   PRBool CanPlaceFloat(const nsSize& aFloatSize, PRUint8 aFloats, PRBool aForceFit);
00101   PRBool FlowAndPlaceFloat(nsFloatCache*   aFloatCache,
00102                            PRBool*         aIsLeftFloat,
00103                            nsReflowStatus& aReflowStatus,
00104                            PRBool          aForceFit);
00105   PRBool PlaceBelowCurrentLineFloats(nsFloatCacheList& aFloats, PRBool aForceFit);
00106 
00107   // Returns the first coordinate >= aY that clears the
00108   // indicated floats.
00109   nscoord ClearFloats(nscoord aY, PRUint8 aBreakType);
00110 
00111   PRBool IsAdjacentWithTop() const {
00112     return mY ==
00113       ((mFlags & BRS_ISFIRSTINFLOW) ? mReflowState.mComputedBorderPadding.top : 0);
00114   }
00115 
00120   nsMargin BorderPadding() const {
00121     nsMargin result = mReflowState.mComputedBorderPadding;
00122     if (!(mFlags & BRS_ISFIRSTINFLOW)) {
00123       result.top = 0;
00124     }
00125     return result;
00126   }
00127 
00128   // XXX maybe we should do the same adjustment for continuations here
00129   const nsMargin& Margin() const {
00130     return mReflowState.mComputedMargin;
00131   }
00132 
00133   void UpdateMaxElementWidth(nscoord aMaxElementWidth);
00134 
00135   void UpdateMaximumWidth(nscoord aMaximumWidth);
00136 
00137   // Reconstruct the previous bottom margin that goes above |aLine|.
00138   void ReconstructMarginAbove(nsLineList::iterator aLine);
00139 
00140   void ComputeBlockAvailSpace(nsIFrame* aFrame,
00141                               nsSplittableType aSplitType,
00142                               const nsStyleDisplay* aDisplay,
00143                               nsRect& aResult);
00144 
00145 protected:
00146   void RecoverFloats(nsLineList::iterator aLine, nscoord aDeltaY);
00147 
00148 public:
00149   void RecoverStateFrom(nsLineList::iterator aLine, nscoord aDeltaY);
00150 
00151   void AdvanceToNextLine() {
00152     mLineNumber++;
00153   }
00154 
00155   PRBool IsImpactedByFloat() const;
00156 
00157   nsLineBox* NewLineBox(nsIFrame* aFrame, PRInt32 aCount, PRBool aIsBlock);
00158 
00159   void FreeLineBox(nsLineBox* aLine);
00160 
00161   //----------------------------------------
00162 
00163   // This state is the "global" state computed once for the reflow of
00164   // the block.
00165 
00166   // The block frame that is using this object
00167   nsBlockFrame* mBlock;
00168 
00169   nsPresContext* mPresContext;
00170 
00171   const nsHTMLReflowState& mReflowState;
00172 
00173   nsSpaceManager* mSpaceManager;
00174 
00175   // The coordinates within the spacemanager where the block is being
00176   // placed <b>after</b> taking into account the blocks border and
00177   // padding. This, therefore, represents the inner "content area" (in
00178   // spacemanager coordinates) where child frames will be placed,
00179   // including child blocks and floats.
00180   nscoord mSpaceManagerX, mSpaceManagerY;
00181 
00182   // XXX get rid of this
00183   nsReflowStatus mReflowStatus;
00184 
00185   nscoord mBottomEdge;
00186 
00187   // The content area to reflow child frames within. The x/y
00188   // coordinates are known to be mBorderPadding.left and
00189   // mBorderPadding.top. The width/height may be NS_UNCONSTRAINEDSIZE
00190   // if the container reflowing this frame has given the frame an
00191   // unconstrained area.
00192   nsSize mContentArea;
00193 
00194   // Placeholders for continuation out-of-flow frames that need to
00195   // move to our next in flow are placed here during reflow. At the end of reflow
00196   // they move to the end of the overflow lines.
00197   // Their out-of-flows are not in any child list during reflow, but are added
00198   // to the overflow-out-of-flow list when the placeholders are appended to
00199   // the overflow lines.
00200   nsFrameList mOverflowPlaceholders;
00201 
00202   //----------------------------------------
00203 
00204   // This state is "running" state updated by the reflow of each line
00205   // in the block. This same state is "recovered" when a line is not
00206   // dirty and is passed over during incremental reflow.
00207 
00208   // The current line being reflowed
00209   // If it is mBlock->end_lines(), then it is invalid.
00210   nsLineList::iterator mCurrentLine;
00211 
00212   // The current Y coordinate in the block
00213   nscoord mY;
00214 
00215   // The available space within the current band.
00216   nsRect mAvailSpaceRect;
00217 
00218   // The maximum x-most of each line
00219   nscoord mKidXMost;
00220 
00221   // The combined area of all floats placed so far
00222   nsRect mFloatCombinedArea;
00223 
00224   nsFloatCacheFreeList mFloatCacheFreeList;
00225 
00226   // Previous child. This is used when pulling up a frame to update
00227   // the sibling list.
00228   nsIFrame* mPrevChild;
00229 
00230   // The previous child frames collapsed bottom margin value.
00231   nsCollapsingMargin mPrevBottomMargin;
00232 
00233   // The current next-in-flow for the block. When lines are pulled
00234   // from a next-in-flow, this is used to know which next-in-flow to
00235   // pull from. When a next-in-flow is emptied of lines, we advance
00236   // this to the next next-in-flow.
00237   nsBlockFrame* mNextInFlow;
00238 
00239   // The current band data for the current Y coordinate
00240   nsBlockBandData mBand;
00241 
00242   //----------------------------------------
00243 
00244   // Temporary line-reflow state. This state is used during the reflow
00245   // of a given line, but doesn't have meaning before or after.
00246 
00247   // The list of floats that are "current-line" floats. These are
00248   // added to the line after the line has been reflowed, to keep the
00249   // list fiddling from being N^2.
00250   nsFloatCacheFreeList mCurrentLineFloats;
00251 
00252   // The list of floats which are "below current-line"
00253   // floats. These are reflowed/placed after the line is reflowed
00254   // and placed. Again, this is done to keep the list fiddling from
00255   // being N^2.
00256   nsFloatCacheFreeList mBelowCurrentLineFloats;
00257 
00258   nscoord mMaxElementWidth;
00259 
00260   // maximum width includes the left border/padding but not the right
00261   nscoord mMaximumWidth;
00262 
00263   nscoord mMinLineHeight;
00264 
00265   PRInt32 mLineNumber;
00266 
00267   PRInt16 mFlags;
00268  
00269   PRUint8 mFloatBreakType;
00270 
00271   void SetFlag(PRUint32 aFlag, PRBool aValue)
00272   {
00273     NS_ASSERTION(aFlag<=BRS_LASTFLAG, "bad flag");
00274     NS_ASSERTION(aValue==PR_FALSE || aValue==PR_TRUE, "bad value");
00275     if (aValue) { // set flag
00276       mFlags |= aFlag;
00277     }
00278     else {        // unset flag
00279       mFlags &= ~aFlag;
00280     }
00281   }
00282 
00283   PRBool GetFlag(PRUint32 aFlag) const
00284   {
00285     NS_ASSERTION(aFlag<=BRS_LASTFLAG, "bad flag");
00286     PRBool result = (mFlags & aFlag);
00287     if (result) return PR_TRUE;
00288     return PR_FALSE;
00289   }
00290 };
00291 
00292 #endif // nsBlockReflowState_h__