2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* 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"
|
2013-02-11 17:52:55 -08:00
|
|
|
#include "nsHTMLReflowState.h"
|
|
|
|
|
|
|
|
class nsBlockFrame;
|
2013-08-22 11:32:52 -07:00
|
|
|
class nsFrameList;
|
2013-02-11 17:52:55 -08:00
|
|
|
class nsOverflowContinuationTracker;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// block reflow state flags
|
2014-06-20 02:55:35 -07:00
|
|
|
#define BRS_UNCONSTRAINEDBSIZE 0x00000001
|
|
|
|
#define BRS_ISBSTARTMARGINROOT 0x00000002 // Is this frame a root for block
|
|
|
|
#define BRS_ISBENDMARGINROOT 0x00000004 // direction start/end margin collapsing?
|
|
|
|
#define BRS_APPLYBSTARTMARGIN 0x00000008 // See ShouldApplyTopMargin
|
2007-03-22 10:30:00 -07:00
|
|
|
#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,
|
2014-06-20 02:55:35 -07:00
|
|
|
bool aBStartMarginRoot, bool aBEndMarginRoot,
|
2013-07-25 08:34:12 -07:00
|
|
|
bool aBlockNeedsFloatManager,
|
2014-06-20 02:55:35 -07:00
|
|
|
nscoord aConsumedBSize = NS_INTRINSICSIZE);
|
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.
|
|
|
|
*
|
2014-06-20 02:55:35 -07:00
|
|
|
* Returns whether there are floats present at the given block-direction
|
|
|
|
* coordinate and within the inline size of the content rect.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2009-04-08 13:52:37 -07:00
|
|
|
nsFlowAreaRect GetFloatAvailableSpace() const
|
2014-06-20 02:55:35 -07:00
|
|
|
{ return GetFloatAvailableSpace(mBCoord); }
|
|
|
|
nsFlowAreaRect GetFloatAvailableSpace(nscoord aBCoord) const
|
|
|
|
{ return GetFloatAvailableSpaceWithState(aBCoord, nullptr); }
|
2009-04-08 13:52:37 -07:00
|
|
|
nsFlowAreaRect
|
2014-06-20 02:55:35 -07:00
|
|
|
GetFloatAvailableSpaceWithState(nscoord aBCoord,
|
2009-04-08 13:52:37 -07:00
|
|
|
nsFloatManager::SavedState *aState) const;
|
2009-05-20 04:21:34 -07:00
|
|
|
nsFlowAreaRect
|
2014-06-20 02:55:35 -07:00
|
|
|
GetFloatAvailableSpaceForBSize(nscoord aBCoord, nscoord aBSize,
|
|
|
|
nsFloatManager::SavedState *aState) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
2011-10-17 07:59:28 -07:00
|
|
|
* The following functions all return true if they were able to
|
|
|
|
* place the float, false if the float did not fit in available
|
2007-03-22 10:30:00 -07:00
|
|
|
* 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
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AddFloat(nsLineLayout* aLineLayout,
|
2014-06-20 02:55:35 -07:00
|
|
|
nsIFrame* aFloat,
|
|
|
|
nscoord aAvailableISize);
|
2010-08-05 21:59:19 -07:00
|
|
|
private:
|
2014-06-20 02:55:35 -07:00
|
|
|
bool CanPlaceFloat(nscoord aFloatISize,
|
|
|
|
const nsFlowAreaRect& aFloatAvailableSpace);
|
2010-08-05 21:59:19 -07:00
|
|
|
public:
|
2011-09-28 23:19:26 -07:00
|
|
|
bool 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
|
|
|
|
2014-06-20 02:55:35 -07:00
|
|
|
// Returns the first coordinate >= aBCoord that clears the
|
|
|
|
// floats indicated by aBreakType and has enough inline size between floats
|
2008-05-03 16:33:36 -07:00
|
|
|
// (or no floats remaining) to accomodate aReplacedBlock.
|
2014-06-20 02:55:35 -07:00
|
|
|
nscoord ClearFloats(nscoord aBCoord, uint8_t aBreakType,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFrame *aReplacedBlock = nullptr,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags = 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsAdjacentWithTop() const {
|
2014-06-20 02:55:35 -07:00
|
|
|
return mBCoord == mBorderPadding.BStart(mReflowState.GetWritingMode());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-12 04:45:28 -07:00
|
|
|
* Return mBlock's computed physical border+padding with GetSkipSides applied.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2014-06-20 02:55:35 -07:00
|
|
|
const mozilla::LogicalMargin& BorderPadding() const {
|
2014-05-12 04:45:28 -07:00
|
|
|
return mBorderPadding;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-25 08:34:12 -07:00
|
|
|
/**
|
2014-06-20 02:55:35 -07:00
|
|
|
* Retrieve the block-direction size "consumed" by any previous-in-flows.
|
2013-07-25 08:34:12 -07:00
|
|
|
*/
|
2014-06-20 02:55:35 -07:00
|
|
|
nscoord GetConsumedBSize();
|
2013-07-25 08:34:12 -07:00
|
|
|
|
2014-06-20 02:55:35 -07:00
|
|
|
// Reconstruct the previous block-end margin that goes before |aLine|.
|
|
|
|
void ReconstructMarginBefore(nsLineList::iterator aLine);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-05-03 16:33:36 -07:00
|
|
|
// Caller must have called GetAvailableSpace for the correct position
|
2014-06-20 02:55:35 -07:00
|
|
|
// (which need not be the current mBCoord).
|
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,
|
Bug 659828 - Part 1: Apply table margins to the outer table frame instead of the inner table frame (also fixes bug 87277); r=dbaron
Outer table frames act as CSS2.1 table wrapper boxes. We used to lay them out
without taking their margins into the account, which meant that their width was
always equal to the available width. This breaks horizontal positioning of
absolutely positioned kids of a table frame.
The main purpose of this patch is to apply the margins of tables to their outer
frame, instead of the inner frame. This means that the inner table frame will
always have a zero margin, which means that a lot of the stuff which used to
rely on the fact that table margins are applied to the inner frame need to
change.
In particular, in order to get the computed margins of a table, we used to query
the inner table frame, and this patch corrects that. Also, when shrink wrapping
tables, we used to not take the margins of the inner table frame into account,
which is fixed by this patch too. nsBlockReflowState::
ComputeReplacedBlockOffsetsForFloats also needed to be changed to read the
margin values from the outer frame too.
Also, as part of this patch, we start to respect the CSS2.1 margin model for
captions on all sides. This means that in particular, the top/bottom margins on
the top-outside and bottom-outside captions will not be collapsed with the
top/bottom margins of the table, and that the margins of the caption element
contribute to the width and height of the outer table frame. The
427129-table-caption reftest has been modified to match this new behavior.
Another side effect of this bug is fixing bug 87277, and the reftests for that
bug are marked as passing in this patch.
2011-05-31 16:02:56 -07:00
|
|
|
nscoord& aRightResult);
|
2008-04-14 18:05:17 -07:00
|
|
|
|
2014-06-20 02:55:35 -07:00
|
|
|
// Caller must have called GetAvailableSpace for the current mBCoord
|
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,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aBlockAvoidsFloats,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRect& aResult);
|
|
|
|
|
|
|
|
protected:
|
2014-06-20 02:55:35 -07:00
|
|
|
void RecoverFloats(nsLineList::iterator aLine, nscoord aDeltaBCoord);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
2014-06-20 02:55:35 -07:00
|
|
|
void RecoverStateFrom(nsLineList::iterator aLine, nscoord aDeltaBCoord);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void AdvanceToNextLine() {
|
2008-11-27 10:44:47 -08:00
|
|
|
if (GetFlag(BRS_LINE_LAYOUT_EMPTY)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
SetFlag(BRS_LINE_LAYOUT_EMPTY, false);
|
2008-11-27 10:44:47 -08:00
|
|
|
} else {
|
|
|
|
mLineNumber++;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2014-06-20 02:55:35 -07:00
|
|
|
nscoord mBEndEdge;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-11 12:32:53 -07:00
|
|
|
// The content area to reflow child frames within. This is within
|
2014-06-20 02:55:35 -07:00
|
|
|
// this frame's coordinate system and writing mode, which means
|
|
|
|
// mContentArea.IStart == BorderPadding().IStart and
|
|
|
|
// mContentArea.BStart == BorderPadding().BStart.
|
|
|
|
// The block size may be NS_UNCONSTRAINEDSIZE, which indicates that there
|
2010-08-11 12:32:53 -07:00
|
|
|
// is no page/column boundary below (the common case).
|
2014-06-20 02:55:35 -07:00
|
|
|
// mContentArea.BEnd() should only be called after checking that
|
|
|
|
// mContentArea.BSize is not NS_UNCONSTRAINEDSIZE; otherwise
|
2010-08-11 12:32:53 -07:00
|
|
|
// coordinate overflow may occur.
|
2014-06-20 02:55:35 -07:00
|
|
|
mozilla::LogicalRect mContentArea;
|
2014-06-30 11:05:28 -07:00
|
|
|
nscoord ContentIStart() const {
|
2014-06-20 02:55:35 -07:00
|
|
|
return mContentArea.IStart(mReflowState.GetWritingMode());
|
|
|
|
}
|
2014-06-30 11:05:28 -07:00
|
|
|
nscoord ContentISize() const {
|
2014-06-20 02:55:35 -07:00
|
|
|
return mContentArea.ISize(mReflowState.GetWritingMode());
|
|
|
|
}
|
2014-06-30 11:05:28 -07:00
|
|
|
nscoord ContentIEnd() const {
|
2014-06-20 02:55:35 -07:00
|
|
|
return mContentArea.IEnd(mReflowState.GetWritingMode());
|
|
|
|
}
|
2014-06-30 11:05:28 -07:00
|
|
|
nscoord ContentBStart() const {
|
2014-06-20 02:55:35 -07:00
|
|
|
return mContentArea.BStart(mReflowState.GetWritingMode());
|
|
|
|
}
|
2014-06-30 11:05:28 -07:00
|
|
|
nscoord ContentBSize() const {
|
2014-06-20 02:55:35 -07:00
|
|
|
return mContentArea.BSize(mReflowState.GetWritingMode());
|
|
|
|
}
|
2014-06-30 11:05:28 -07:00
|
|
|
nscoord ContentBEnd() const {
|
2014-06-20 02:55:35 -07:00
|
|
|
return mContentArea.BEnd(mReflowState.GetWritingMode());
|
|
|
|
}
|
2014-07-24 01:28:46 -07:00
|
|
|
mozilla::LogicalSize ContentSize(mozilla::WritingMode aWM) const {
|
|
|
|
mozilla::WritingMode wm = mReflowState.GetWritingMode();
|
|
|
|
return mContentArea.Size(wm).ConvertTo(aWM, wm);
|
|
|
|
}
|
2014-04-16 01:03:28 -07:00
|
|
|
nscoord mContainerWidth;
|
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.
|
2013-02-11 17:52:55 -08:00
|
|
|
void AppendPushedFloat(nsIFrame* aFloatCont);
|
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;
|
|
|
|
|
2014-06-20 02:55:35 -07:00
|
|
|
// The current block-direction coordinate in the block
|
|
|
|
nscoord mBCoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-12 04:45:28 -07:00
|
|
|
// mBlock's computed physical border+padding with GetSkipSides applied.
|
2014-06-20 02:55:35 -07:00
|
|
|
mozilla::LogicalMargin mBorderPadding;
|
2014-05-12 04:45:28 -07:00
|
|
|
|
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.
|
2014-06-20 02:55:35 -07:00
|
|
|
nsCollapsingMargin mPrevBEndMargin;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mLineNumber;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int16_t mFlags;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mFloatBreakType;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-20 02:55:35 -07:00
|
|
|
// The amount of computed block-direction size "consumed" by previous-in-flows.
|
|
|
|
nscoord mConsumedBSize;
|
2013-07-25 08:34:12 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetFlag(uint32_t aFlag, bool aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aFlag<=BRS_LASTFLAG, "bad flag");
|
|
|
|
if (aValue) { // set flag
|
|
|
|
mFlags |= aFlag;
|
|
|
|
}
|
|
|
|
else { // unset flag
|
|
|
|
mFlags &= ~aFlag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool GetFlag(uint32_t aFlag) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
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__
|