2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Steve Clark <buster@netscape.com>
|
|
|
|
* Robert O'Callahan <roc+moz@cs.cmu.edu>
|
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/* state used in reflow of block frames */
|
|
|
|
|
|
|
|
#ifndef nsBlockReflowState_h__
|
|
|
|
#define nsBlockReflowState_h__
|
|
|
|
|
2009-01-04 16:39:54 -08:00
|
|
|
#include "nsFloatManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsLineBox.h"
|
|
|
|
#include "nsFrameList.h"
|
2008-04-14 18:05:17 -07:00
|
|
|
#include "nsBlockFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// block reflow state flags
|
|
|
|
#define BRS_UNCONSTRAINEDHEIGHT 0x00000001
|
|
|
|
#define BRS_ISTOPMARGINROOT 0x00000002 // Is this frame a root for top/bottom margin collapsing?
|
|
|
|
#define BRS_ISBOTTOMMARGINROOT 0x00000004
|
|
|
|
#define BRS_APPLYTOPMARGIN 0x00000008 // See ShouldApplyTopMargin
|
|
|
|
#define BRS_ISFIRSTINFLOW 0x00000010
|
|
|
|
// Set when mLineAdjacentToTop is valid
|
|
|
|
#define BRS_HAVELINEADJACENTTOTOP 0x00000020
|
2009-01-04 16:39:54 -08:00
|
|
|
// Set when the block has the equivalent of NS_BLOCK_FLOAT_MGR
|
|
|
|
#define BRS_FLOAT_MGR 0x00000040
|
2008-11-27 10:44:47 -08:00
|
|
|
// Set when nsLineLayout::LineIsEmpty was true at the end of reflowing
|
|
|
|
// the current line
|
|
|
|
#define BRS_LINE_LAYOUT_EMPTY 0x00000080
|
2007-07-25 21:03:29 -07:00
|
|
|
#define BRS_ISOVERFLOWCONTAINER 0x00000100
|
2010-08-05 21:59:20 -07:00
|
|
|
// Our mPushedFloats list is stored on the blocks' proptable
|
2009-08-31 11:25:36 -07:00
|
|
|
#define BRS_PROPTABLE_FLOATCLIST 0x00000200
|
|
|
|
#define BRS_LASTFLAG BRS_PROPTABLE_FLOATCLIST
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsBlockReflowState {
|
|
|
|
public:
|
|
|
|
nsBlockReflowState(const nsHTMLReflowState& aReflowState,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsBlockFrame* aFrame,
|
|
|
|
const nsHTMLReflowMetrics& aMetrics,
|
|
|
|
PRBool aTopMarginRoot, PRBool aBottomMarginRoot,
|
2009-01-04 16:39:54 -08:00
|
|
|
PRBool aBlockNeedsFloatManager);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2009-04-08 13:52:36 -07:00
|
|
|
* Get the available reflow space (the area not occupied by floats)
|
|
|
|
* for the current y coordinate. The available space is relative to
|
|
|
|
* our coordinate system, which is the content box, with (0, 0) in the
|
|
|
|
* upper left.
|
|
|
|
*
|
|
|
|
* Returns whether there are floats present at the given vertical
|
|
|
|
* coordinate and within the width of the content rect.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2009-04-08 13:52:37 -07:00
|
|
|
nsFlowAreaRect GetFloatAvailableSpace() const
|
2010-08-05 21:59:18 -07:00
|
|
|
{ return GetFloatAvailableSpace(mY); }
|
|
|
|
nsFlowAreaRect GetFloatAvailableSpace(nscoord aY) const
|
|
|
|
{ return GetFloatAvailableSpaceWithState(aY, nsnull); }
|
2009-04-08 13:52:37 -07:00
|
|
|
nsFlowAreaRect
|
2010-08-05 21:59:18 -07:00
|
|
|
GetFloatAvailableSpaceWithState(nscoord aY,
|
2009-04-08 13:52:37 -07:00
|
|
|
nsFloatManager::SavedState *aState) const;
|
2009-05-20 04:21:34 -07:00
|
|
|
nsFlowAreaRect
|
|
|
|
GetFloatAvailableSpaceForHeight(nscoord aY, nscoord aHeight,
|
|
|
|
nsFloatManager::SavedState *aState) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The following functions all return PR_TRUE if they were able to
|
|
|
|
* place the float, PR_FALSE if the float did not fit in available
|
|
|
|
* space.
|
2010-08-05 21:59:20 -07:00
|
|
|
* aLineLayout is null when we are reflowing pushed floats (because
|
2009-08-31 11:25:36 -07:00
|
|
|
* they are not associated with a line box).
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2009-08-31 11:25:36 -07:00
|
|
|
PRBool AddFloat(nsLineLayout* aLineLayout,
|
2009-08-31 11:25:35 -07:00
|
|
|
nsIFrame* aFloat,
|
2010-08-05 21:59:20 -07:00
|
|
|
nscoord aAvailableWidth);
|
2010-08-05 21:59:19 -07:00
|
|
|
private:
|
2010-08-05 21:59:18 -07:00
|
|
|
PRBool CanPlaceFloat(nscoord aFloatWidth,
|
2010-08-05 21:59:18 -07:00
|
|
|
const nsFlowAreaRect& aFloatAvailableSpace);
|
2010-08-05 21:59:19 -07:00
|
|
|
public:
|
2010-08-05 21:59:20 -07:00
|
|
|
PRBool FlowAndPlaceFloat(nsIFrame* aFloat);
|
2010-08-05 21:59:19 -07:00
|
|
|
private:
|
|
|
|
void PushFloatPastBreak(nsIFrame* aFloat);
|
|
|
|
public:
|
2010-08-05 21:59:20 -07:00
|
|
|
void PlaceBelowCurrentLineFloats(nsFloatCacheFreeList& aFloats,
|
|
|
|
nsLineBox* aLine);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Returns the first coordinate >= aY that clears the
|
2008-01-28 23:40:05 -08:00
|
|
|
// floats indicated by aBreakType and has enough width between floats
|
2008-05-03 16:33:36 -07:00
|
|
|
// (or no floats remaining) to accomodate aReplacedBlock.
|
2008-04-14 18:05:17 -07:00
|
|
|
nscoord ClearFloats(nscoord aY, PRUint8 aBreakType,
|
2010-08-05 21:59:19 -07:00
|
|
|
nsIFrame *aReplacedBlock = nsnull,
|
|
|
|
PRUint32 aFlags = 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRBool IsAdjacentWithTop() const {
|
|
|
|
return mY ==
|
|
|
|
((mFlags & BRS_ISFIRSTINFLOW) ? mReflowState.mComputedBorderPadding.top : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adjusts the border/padding to return 0 for the top if
|
2007-07-03 15:49:00 -07:00
|
|
|
* we are not the first in flow.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
nsMargin BorderPadding() const {
|
|
|
|
nsMargin result = mReflowState.mComputedBorderPadding;
|
|
|
|
if (!(mFlags & BRS_ISFIRSTINFLOW)) {
|
|
|
|
result.top = 0;
|
2007-07-25 21:03:29 -07:00
|
|
|
if (mFlags & BRS_ISOVERFLOWCONTAINER) {
|
|
|
|
result.bottom = 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX maybe we should do the same adjustment for continuations here
|
|
|
|
const nsMargin& Margin() const {
|
|
|
|
return mReflowState.mComputedMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reconstruct the previous bottom margin that goes above |aLine|.
|
|
|
|
void ReconstructMarginAbove(nsLineList::iterator aLine);
|
|
|
|
|
2008-05-03 16:33:36 -07:00
|
|
|
// Caller must have called GetAvailableSpace for the correct position
|
|
|
|
// (which need not be the current mY). Callers need only pass
|
|
|
|
// aReplacedWidth for outer table frames.
|
2008-04-14 18:05:17 -07:00
|
|
|
void ComputeReplacedBlockOffsetsForFloats(nsIFrame* aFrame,
|
2009-04-08 13:52:37 -07:00
|
|
|
const nsRect& aFloatAvailableSpace,
|
2008-04-14 18:05:17 -07:00
|
|
|
nscoord& aLeftResult,
|
|
|
|
nscoord& aRightResult,
|
2008-05-03 16:33:36 -07:00
|
|
|
nsBlockFrame::ReplacedElementWidthToClear
|
|
|
|
*aReplacedWidth = nsnull);
|
2008-04-14 18:05:17 -07:00
|
|
|
|
|
|
|
// Caller must have called GetAvailableSpace for the current mY
|
2007-03-22 10:30:00 -07:00
|
|
|
void ComputeBlockAvailSpace(nsIFrame* aFrame,
|
|
|
|
const nsStyleDisplay* aDisplay,
|
2009-04-08 13:52:37 -07:00
|
|
|
const nsFlowAreaRect& aFloatAvailableSpace,
|
2008-05-03 16:33:36 -07:00
|
|
|
PRBool aBlockAvoidsFloats,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRect& aResult);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void RecoverFloats(nsLineList::iterator aLine, nscoord aDeltaY);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void RecoverStateFrom(nsLineList::iterator aLine, nscoord aDeltaY);
|
|
|
|
|
|
|
|
void AdvanceToNextLine() {
|
2008-11-27 10:44:47 -08:00
|
|
|
if (GetFlag(BRS_LINE_LAYOUT_EMPTY)) {
|
|
|
|
SetFlag(BRS_LINE_LAYOUT_EMPTY, PR_FALSE);
|
|
|
|
} else {
|
|
|
|
mLineNumber++;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsLineBox* NewLineBox(nsIFrame* aFrame, PRInt32 aCount, PRBool aIsBlock);
|
|
|
|
|
|
|
|
void FreeLineBox(nsLineBox* aLine);
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// This state is the "global" state computed once for the reflow of
|
|
|
|
// the block.
|
|
|
|
|
|
|
|
// The block frame that is using this object
|
|
|
|
nsBlockFrame* mBlock;
|
|
|
|
|
|
|
|
nsPresContext* mPresContext;
|
|
|
|
|
|
|
|
const nsHTMLReflowState& mReflowState;
|
|
|
|
|
2009-01-04 16:39:54 -08:00
|
|
|
nsFloatManager* mFloatManager;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-04 16:39:54 -08:00
|
|
|
// The coordinates within the float manager where the block is being
|
2007-03-22 10:30:00 -07:00
|
|
|
// placed <b>after</b> taking into account the blocks border and
|
|
|
|
// padding. This, therefore, represents the inner "content area" (in
|
|
|
|
// spacemanager coordinates) where child frames will be placed,
|
|
|
|
// including child blocks and floats.
|
2009-01-04 16:39:54 -08:00
|
|
|
nscoord mFloatManagerX, mFloatManagerY;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX get rid of this
|
|
|
|
nsReflowStatus mReflowStatus;
|
|
|
|
|
2009-04-08 13:52:36 -07:00
|
|
|
// The float manager state as it was before the contents of this
|
|
|
|
// block. This is needed for positioning bullets, since we only want
|
|
|
|
// to move the bullet to flow around floats that were before this
|
|
|
|
// block, not floats inside of it.
|
|
|
|
nsFloatManager::SavedState mFloatManagerStateBefore;
|
2008-04-13 10:43:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord mBottomEdge;
|
|
|
|
|
2010-08-11 12:32:53 -07:00
|
|
|
// The content area to reflow child frames within. This is within
|
|
|
|
// this frame's coordinate system, which means mContentArea.x ==
|
|
|
|
// BorderPadding().left and mContentArea.y == BorderPadding().top.
|
|
|
|
// The height may be NS_UNCONSTRAINEDSIZE, which indicates that there
|
|
|
|
// is no page/column boundary below (the common case).
|
|
|
|
// mContentArea.YMost() should only be called after checking that
|
|
|
|
// mContentArea.height is not NS_UNCONSTRAINEDSIZE; otherwise
|
|
|
|
// coordinate overflow may occur.
|
|
|
|
nsRect mContentArea;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-31 11:25:36 -07:00
|
|
|
// Continuation out-of-flow float frames that need to move to our
|
2010-08-05 21:59:19 -07:00
|
|
|
// next in flow are placed here during reflow. It's a pointer to
|
|
|
|
// a frame list stored in the block's property table.
|
2010-08-05 21:59:20 -07:00
|
|
|
nsFrameList *mPushedFloats;
|
|
|
|
// This method makes sure pushed floats are accessible to
|
|
|
|
// StealFrame. Call it before adding any frames to mPushedFloats.
|
|
|
|
void SetupPushedFloatList();
|
|
|
|
// Use this method to append to mPushedFloats.
|
|
|
|
void AppendPushedFloat(nsIFrame* aFloatCont) {
|
|
|
|
SetupPushedFloatList();
|
|
|
|
aFloatCont->AddStateBits(NS_FRAME_IS_PUSHED_FLOAT);
|
|
|
|
mPushedFloats->AppendFrame(mBlock, aFloatCont);
|
2009-08-31 11:25:36 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-25 21:03:29 -07:00
|
|
|
// Track child overflow continuations.
|
2009-09-13 17:26:01 -07:00
|
|
|
nsOverflowContinuationTracker* mOverflowTracker;
|
2007-07-25 21:03:29 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// This state is "running" state updated by the reflow of each line
|
|
|
|
// in the block. This same state is "recovered" when a line is not
|
|
|
|
// dirty and is passed over during incremental reflow.
|
|
|
|
|
|
|
|
// The current line being reflowed
|
|
|
|
// If it is mBlock->end_lines(), then it is invalid.
|
|
|
|
nsLineList::iterator mCurrentLine;
|
|
|
|
|
|
|
|
// When BRS_HAVELINEADJACENTTOTOP is set, this refers to a line
|
|
|
|
// which we know is adjacent to the top of the block (in other words,
|
|
|
|
// all lines before it are empty and do not have clearance. This line is
|
|
|
|
// always before the current line.
|
|
|
|
nsLineList::iterator mLineAdjacentToTop;
|
|
|
|
|
|
|
|
// The current Y coordinate in the block
|
|
|
|
nscoord mY;
|
|
|
|
|
2010-10-06 21:25:45 -07:00
|
|
|
// The overflow areas of all floats placed so far
|
|
|
|
nsOverflowAreas mFloatOverflowAreas;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsFloatCacheFreeList mFloatCacheFreeList;
|
|
|
|
|
|
|
|
// Previous child. This is used when pulling up a frame to update
|
|
|
|
// the sibling list.
|
|
|
|
nsIFrame* mPrevChild;
|
|
|
|
|
|
|
|
// The previous child frames collapsed bottom margin value.
|
|
|
|
nsCollapsingMargin mPrevBottomMargin;
|
|
|
|
|
|
|
|
// The current next-in-flow for the block. When lines are pulled
|
|
|
|
// from a next-in-flow, this is used to know which next-in-flow to
|
|
|
|
// pull from. When a next-in-flow is emptied of lines, we advance
|
|
|
|
// this to the next next-in-flow.
|
|
|
|
nsBlockFrame* mNextInFlow;
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// Temporary line-reflow state. This state is used during the reflow
|
|
|
|
// of a given line, but doesn't have meaning before or after.
|
|
|
|
|
|
|
|
// The list of floats that are "current-line" floats. These are
|
|
|
|
// added to the line after the line has been reflowed, to keep the
|
|
|
|
// list fiddling from being N^2.
|
|
|
|
nsFloatCacheFreeList mCurrentLineFloats;
|
|
|
|
|
|
|
|
// The list of floats which are "below current-line"
|
|
|
|
// floats. These are reflowed/placed after the line is reflowed
|
|
|
|
// and placed. Again, this is done to keep the list fiddling from
|
|
|
|
// being N^2.
|
|
|
|
nsFloatCacheFreeList mBelowCurrentLineFloats;
|
|
|
|
|
|
|
|
nscoord mMinLineHeight;
|
|
|
|
|
|
|
|
PRInt32 mLineNumber;
|
|
|
|
|
|
|
|
PRInt16 mFlags;
|
|
|
|
|
|
|
|
PRUint8 mFloatBreakType;
|
|
|
|
|
|
|
|
void SetFlag(PRUint32 aFlag, PRBool aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFlag<=BRS_LASTFLAG, "bad flag");
|
|
|
|
NS_ASSERTION(aValue==PR_FALSE || aValue==PR_TRUE, "bad value");
|
|
|
|
if (aValue) { // set flag
|
|
|
|
mFlags |= aFlag;
|
|
|
|
}
|
|
|
|
else { // unset flag
|
|
|
|
mFlags &= ~aFlag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool GetFlag(PRUint32 aFlag) const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFlag<=BRS_LASTFLAG, "bad flag");
|
2007-10-09 17:00:05 -07:00
|
|
|
return !!(mFlags & aFlag);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsBlockReflowState_h__
|