2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-10-25 05:08:40 +04:00
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-15 04:19:49 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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/
|
1998-09-15 04:19:49 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
1998-09-15 04:19:49 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2000-04-17 18:40:46 +04:00
|
|
|
* Steve Clark <buster@netscape.com>
|
|
|
|
* Robert O'Callahan <roc+moz@cs.cmu.edu>
|
2003-01-02 02:53:20 +03:00
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-09-24 00:10:40 +04:00
|
|
|
|
2001-05-01 08:22:57 +04:00
|
|
|
#include "nsBlockReflowContext.h"
|
|
|
|
#include "nsBlockReflowState.h"
|
|
|
|
#include "nsBlockFrame.h"
|
|
|
|
#include "nsLineLayout.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2001-05-01 08:22:57 +04:00
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
#include "nsIFrame.h"
|
2004-02-24 00:29:06 +03:00
|
|
|
#include "nsFrameManager.h"
|
2001-05-01 08:22:57 +04:00
|
|
|
|
2002-03-08 23:25:54 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
|
|
|
|
|
2001-05-01 08:22:57 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include "nsBlockDebugFlags.h"
|
|
|
|
#endif
|
1998-09-15 04:19:49 +04:00
|
|
|
|
1999-03-05 07:21:32 +03:00
|
|
|
nsBlockReflowState::nsBlockReflowState(const nsHTMLReflowState& aReflowState,
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* aPresContext,
|
1999-03-05 07:21:32 +03:00
|
|
|
nsBlockFrame* aFrame,
|
2000-01-03 07:32:13 +03:00
|
|
|
const nsHTMLReflowMetrics& aMetrics,
|
2004-11-25 17:51:00 +03:00
|
|
|
PRBool aTopMarginRoot,
|
|
|
|
PRBool aBottomMarginRoot)
|
1999-04-03 22:59:01 +04:00
|
|
|
: mBlock(aFrame),
|
|
|
|
mPresContext(aPresContext),
|
1999-03-05 07:21:32 +03:00
|
|
|
mReflowState(aReflowState),
|
2001-10-25 05:08:40 +04:00
|
|
|
mPrevBottomMargin(),
|
2000-04-17 18:40:46 +04:00
|
|
|
mLineNumber(0),
|
2002-07-17 05:48:56 +04:00
|
|
|
mFlags(0),
|
2003-10-14 01:51:02 +04:00
|
|
|
mFloatBreakType(NS_STYLE_CLEAR_NONE)
|
1998-11-15 00:01:26 +03:00
|
|
|
{
|
2000-01-18 18:36:36 +03:00
|
|
|
const nsMargin& borderPadding = BorderPadding();
|
|
|
|
|
2005-03-23 06:35:08 +03:00
|
|
|
if (aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
mBlock->SetProperty(nsLayoutAtoms::overflowPlaceholdersProperty,
|
|
|
|
&mOverflowPlaceholders, nsnull);
|
|
|
|
mBlock->AddStateBits(NS_BLOCK_HAS_OVERFLOW_PLACEHOLDERS);
|
|
|
|
}
|
|
|
|
|
2004-11-25 17:51:00 +03:00
|
|
|
if (aTopMarginRoot || 0 != aReflowState.mComputedBorderPadding.top) {
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(BRS_ISTOPMARGINROOT, PR_TRUE);
|
2000-01-13 05:05:31 +03:00
|
|
|
}
|
2004-11-25 17:51:00 +03:00
|
|
|
if (aBottomMarginRoot || 0 != aReflowState.mComputedBorderPadding.bottom) {
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(BRS_ISBOTTOMMARGINROOT, PR_TRUE);
|
2000-01-13 05:05:31 +03:00
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
if (GetFlag(BRS_ISTOPMARGINROOT)) {
|
|
|
|
SetFlag(BRS_APPLYTOPMARGIN, PR_TRUE);
|
2000-01-03 07:32:13 +03:00
|
|
|
}
|
|
|
|
|
1999-07-20 07:41:03 +04:00
|
|
|
mSpaceManager = aReflowState.mSpaceManager;
|
1998-09-24 00:10:40 +04:00
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
NS_ASSERTION(mSpaceManager,
|
|
|
|
"SpaceManager should be set in nsBlockReflowState" );
|
|
|
|
if (mSpaceManager) {
|
2000-01-18 18:36:36 +03:00
|
|
|
// Translate into our content area and then save the
|
|
|
|
// coordinate system origin for later.
|
|
|
|
mSpaceManager->Translate(borderPadding.left, borderPadding.top);
|
|
|
|
mSpaceManager->GetTranslation(mSpaceManagerX, mSpaceManagerY);
|
|
|
|
}
|
1998-09-24 00:10:40 +04:00
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
mReflowStatus = NS_FRAME_COMPLETE;
|
1998-09-24 00:10:40 +04:00
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
mPresContext = aPresContext;
|
2004-09-14 06:28:03 +04:00
|
|
|
mNextInFlow = NS_STATIC_CAST(nsBlockFrame*, mBlock->GetNextInFlow());
|
1998-12-05 19:02:08 +03:00
|
|
|
mKidXMost = 0;
|
1998-09-24 00:10:40 +04:00
|
|
|
|
1999-03-05 07:21:32 +03:00
|
|
|
// Compute content area width (the content area is inside the border
|
|
|
|
// and padding)
|
1999-07-20 07:41:03 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedWidth) {
|
|
|
|
mContentArea.width = aReflowState.mComputedWidth;
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-03-05 07:21:32 +03:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aReflowState.availableWidth) {
|
1998-12-05 19:02:08 +03:00
|
|
|
mContentArea.width = NS_UNCONSTRAINEDSIZE;
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(BRS_UNCONSTRAINEDWIDTH, PR_TRUE);
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
2000-01-03 07:32:13 +03:00
|
|
|
else if (NS_UNCONSTRAINEDSIZE != aReflowState.mComputedMaxWidth) {
|
|
|
|
// Choose a width based on the content (shrink wrap width) up
|
|
|
|
// to the maximum width
|
|
|
|
mContentArea.width = aReflowState.mComputedMaxWidth;
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(BRS_SHRINKWRAPWIDTH, PR_TRUE);
|
2000-01-03 07:32:13 +03:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
else {
|
1999-03-05 07:21:32 +03:00
|
|
|
nscoord lr = borderPadding.left + borderPadding.right;
|
2002-09-25 01:02:20 +04:00
|
|
|
mContentArea.width = PR_MAX(0, aReflowState.availableWidth - lr);
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
|
|
|
}
|
1998-12-30 20:50:00 +03:00
|
|
|
|
1999-03-05 07:21:32 +03:00
|
|
|
// Compute content area height. Unlike the width, if we have a
|
|
|
|
// specified style height we ignore it since extra content is
|
|
|
|
// managed by the "overflow" property. When we don't have a
|
|
|
|
// specified style height then we may end up limiting our height if
|
|
|
|
// the availableHeight is constrained (this situation occurs when we
|
|
|
|
// are paginated).
|
1999-03-23 07:28:20 +03:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.availableHeight) {
|
1999-04-03 22:59:01 +04:00
|
|
|
// We are in a paginated situation. The bottom edge is just inside
|
|
|
|
// the bottom border and padding. The content area height doesn't
|
|
|
|
// include either border or padding edge.
|
|
|
|
mBottomEdge = aReflowState.availableHeight - borderPadding.bottom;
|
2002-09-25 01:02:20 +04:00
|
|
|
mContentArea.height = PR_MAX(0, mBottomEdge - borderPadding.top);
|
1999-03-23 07:28:20 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// When we are not in a paginated situation then we always use
|
|
|
|
// an constrained height.
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(BRS_UNCONSTRAINEDHEIGHT, PR_TRUE);
|
1999-04-03 22:59:01 +04:00
|
|
|
mContentArea.height = mBottomEdge = NS_UNCONSTRAINEDSIZE;
|
1999-03-05 07:21:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mY = borderPadding.top;
|
1999-04-03 22:59:01 +04:00
|
|
|
mBand.Init(mSpaceManager, mContentArea);
|
1998-12-05 19:02:08 +03:00
|
|
|
|
|
|
|
mPrevChild = nsnull;
|
2001-10-25 05:08:40 +04:00
|
|
|
mCurrentLine = aFrame->end_lines();
|
1999-03-05 07:21:32 +03:00
|
|
|
|
2003-01-09 17:26:32 +03:00
|
|
|
SetFlag(BRS_COMPUTEMAXELEMENTWIDTH, aMetrics.mComputeMEW);
|
2002-07-01 21:43:02 +04:00
|
|
|
#ifdef DEBUG
|
2003-01-09 17:26:32 +03:00
|
|
|
if (nsBlockFrame::gNoisyMaxElementWidth) {
|
2002-07-01 21:43:02 +04:00
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2003-01-09 17:26:32 +03:00
|
|
|
printf("BRS: setting compute-MEW to %d\n", aMetrics.mComputeMEW);
|
2002-07-01 21:43:02 +04:00
|
|
|
}
|
2000-05-14 08:56:25 +04:00
|
|
|
#endif
|
2003-01-09 17:26:32 +03:00
|
|
|
mMaxElementWidth = 0;
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(BRS_COMPUTEMAXWIDTH,
|
|
|
|
(NS_REFLOW_CALC_MAX_WIDTH == (aMetrics.mFlags & NS_REFLOW_CALC_MAX_WIDTH)));
|
1999-12-30 07:15:45 +03:00
|
|
|
mMaximumWidth = 0;
|
1999-03-05 07:21:32 +03:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
mMinLineHeight = nsHTMLReflowState::CalcLineHeight(mPresContext,
|
1999-09-10 00:53:32 +04:00
|
|
|
aReflowState.rendContext,
|
1999-08-28 01:45:37 +04:00
|
|
|
aReflowState.frame);
|
1998-09-24 00:10:40 +04:00
|
|
|
}
|
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
nsBlockReflowState::~nsBlockReflowState()
|
1998-09-24 00:10:40 +04:00
|
|
|
{
|
2001-11-03 08:18:39 +03:00
|
|
|
// Restore the coordinate system, unless the space manager is null,
|
|
|
|
// which means it was just destroyed.
|
|
|
|
if (mSpaceManager) {
|
|
|
|
const nsMargin& borderPadding = BorderPadding();
|
|
|
|
mSpaceManager->Translate(-borderPadding.left, -borderPadding.top);
|
|
|
|
}
|
2005-03-23 06:35:08 +03:00
|
|
|
|
|
|
|
if (mReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
mBlock->UnsetProperty(nsLayoutAtoms::overflowPlaceholdersProperty);
|
|
|
|
mBlock->RemoveStateBits(NS_BLOCK_HAS_OVERFLOW_PLACEHOLDERS);
|
|
|
|
}
|
1999-10-20 03:04:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsLineBox*
|
|
|
|
nsBlockReflowState::NewLineBox(nsIFrame* aFrame,
|
|
|
|
PRInt32 aCount,
|
|
|
|
PRBool aIsBlock)
|
|
|
|
{
|
2003-12-21 08:36:36 +03:00
|
|
|
return NS_NewLineBox(mPresContext->PresShell(), aFrame, aCount, aIsBlock);
|
1999-10-20 03:04:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBlockReflowState::FreeLineBox(nsLineBox* aLine)
|
|
|
|
{
|
|
|
|
if (aLine) {
|
2003-12-21 08:36:36 +03:00
|
|
|
aLine->Destroy(mPresContext->PresShell());
|
1999-10-20 03:04:19 +04:00
|
|
|
}
|
1998-09-24 00:10:40 +04:00
|
|
|
}
|
|
|
|
|
1999-04-03 22:59:01 +04:00
|
|
|
// Compute the amount of available space for reflowing a block frame
|
|
|
|
// at the current Y coordinate. This method assumes that
|
|
|
|
// GetAvailableSpace has already been called.
|
1998-12-05 19:02:08 +03:00
|
|
|
void
|
1999-08-28 01:45:37 +04:00
|
|
|
nsBlockReflowState::ComputeBlockAvailSpace(nsIFrame* aFrame,
|
|
|
|
nsSplittableType aSplitType,
|
|
|
|
const nsStyleDisplay* aDisplay,
|
1999-04-03 22:59:01 +04:00
|
|
|
nsRect& aResult)
|
1998-09-24 00:10:40 +04:00
|
|
|
{
|
2000-04-17 18:40:46 +04:00
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
2003-10-14 01:51:02 +04:00
|
|
|
printf("CBAS frame=%p has float count %d\n", aFrame, mBand.GetFloatCount());
|
2000-04-17 18:40:46 +04:00
|
|
|
mBand.List();
|
|
|
|
#endif
|
1999-09-16 23:56:36 +04:00
|
|
|
aResult.y = mY;
|
2000-04-17 18:40:46 +04:00
|
|
|
aResult.height = GetFlag(BRS_UNCONSTRAINEDHEIGHT)
|
1999-04-03 22:59:01 +04:00
|
|
|
? NS_UNCONSTRAINEDSIZE
|
|
|
|
: mBottomEdge - mY;
|
1998-09-24 00:10:40 +04:00
|
|
|
|
1999-04-03 22:59:01 +04:00
|
|
|
const nsMargin& borderPadding = BorderPadding();
|
1999-08-28 01:45:37 +04:00
|
|
|
|
2000-09-15 10:20:07 +04:00
|
|
|
/* bug 18445: treat elements mapped to display: block such as text controls
|
|
|
|
* just like normal blocks */
|
2003-10-31 23:19:18 +03:00
|
|
|
// text controls are not splittable, so make a special case here
|
|
|
|
// XXXldb Why not just set the frame state bit?
|
|
|
|
PRBool treatAsNotSplittable =
|
|
|
|
nsLayoutAtoms::textInputFrame == aFrame->GetType();
|
2000-09-15 10:20:07 +04:00
|
|
|
|
|
|
|
if (NS_FRAME_SPLITTABLE_NON_RECTANGULAR == aSplitType || // normal blocks
|
|
|
|
NS_FRAME_NOT_SPLITTABLE == aSplitType || // things like images mapped to display: block
|
|
|
|
PR_TRUE == treatAsNotSplittable) // text input controls mapped to display: block (special case)
|
2000-09-12 00:46:44 +04:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
if (mBand.GetFloatCount()) {
|
1999-09-16 23:56:36 +04:00
|
|
|
// Use the float-edge property to determine how the child block
|
2003-10-14 01:51:02 +04:00
|
|
|
// will interact with the float.
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleBorder* borderStyle = aFrame->GetStyleBorder();
|
2001-02-07 12:57:26 +03:00
|
|
|
switch (borderStyle->mFloatEdge) {
|
1999-09-16 23:56:36 +04:00
|
|
|
default:
|
2003-10-14 01:51:02 +04:00
|
|
|
case NS_STYLE_FLOAT_EDGE_CONTENT: // content and only content does runaround of floats
|
|
|
|
// The child block will flow around the float. Therefore
|
1999-09-16 23:56:36 +04:00
|
|
|
// give it all of the available space.
|
|
|
|
aResult.x = borderPadding.left;
|
2000-04-17 18:40:46 +04:00
|
|
|
aResult.width = GetFlag(BRS_UNCONSTRAINEDWIDTH)
|
1999-09-16 23:56:36 +04:00
|
|
|
? NS_UNCONSTRAINEDSIZE
|
|
|
|
: mContentArea.width;
|
2000-03-23 02:19:10 +03:00
|
|
|
break;
|
|
|
|
case NS_STYLE_FLOAT_EDGE_BORDER:
|
1999-09-16 23:56:36 +04:00
|
|
|
case NS_STYLE_FLOAT_EDGE_PADDING:
|
|
|
|
{
|
|
|
|
// The child block's border should be placed adjacent to,
|
2003-10-14 01:51:02 +04:00
|
|
|
// but not overlap the float(s).
|
1999-09-16 23:56:36 +04:00
|
|
|
nsMargin m(0, 0, 0, 0);
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleMargin* styleMargin = aFrame->GetStyleMargin();
|
2001-02-07 12:57:26 +03:00
|
|
|
styleMargin->GetMargin(m); // XXX percentage margins
|
|
|
|
if (NS_STYLE_FLOAT_EDGE_PADDING == borderStyle->mFloatEdge) {
|
1999-09-16 23:56:36 +04:00
|
|
|
// Add in border too
|
|
|
|
nsMargin b;
|
2001-02-07 12:57:26 +03:00
|
|
|
borderStyle->GetBorder(b);
|
1999-09-16 23:56:36 +04:00
|
|
|
m += b;
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine left edge
|
2003-10-14 01:51:02 +04:00
|
|
|
if (mBand.GetLeftFloatCount()) {
|
1999-09-16 23:56:36 +04:00
|
|
|
aResult.x = mAvailSpaceRect.x + borderPadding.left - m.left;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aResult.x = borderPadding.left;
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine width
|
2000-04-17 18:40:46 +04:00
|
|
|
if (GetFlag(BRS_UNCONSTRAINEDWIDTH)) {
|
1999-09-16 23:56:36 +04:00
|
|
|
aResult.width = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
else {
|
2003-10-14 01:51:02 +04:00
|
|
|
if (mBand.GetRightFloatCount()) {
|
|
|
|
if (mBand.GetLeftFloatCount()) {
|
1999-09-16 23:56:36 +04:00
|
|
|
aResult.width = mAvailSpaceRect.width + m.left + m.right;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aResult.width = mAvailSpaceRect.width + m.right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aResult.width = mAvailSpaceRect.width + m.left;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_FLOAT_EDGE_MARGIN:
|
|
|
|
{
|
|
|
|
// The child block's margins should be placed adjacent to,
|
2003-10-14 01:51:02 +04:00
|
|
|
// but not overlap the float.
|
1999-09-16 23:56:36 +04:00
|
|
|
aResult.x = mAvailSpaceRect.x + borderPadding.left;
|
|
|
|
aResult.width = mAvailSpaceRect.width;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-10-14 01:51:02 +04:00
|
|
|
// Since there are no floats present the float-edge property
|
1999-09-16 23:56:36 +04:00
|
|
|
// doesn't matter therefore give the block element all of the
|
2003-10-14 01:51:02 +04:00
|
|
|
// available space since it will flow around the float itself.
|
1999-09-16 23:56:36 +04:00
|
|
|
aResult.x = borderPadding.left;
|
2000-04-17 18:40:46 +04:00
|
|
|
aResult.width = GetFlag(BRS_UNCONSTRAINEDWIDTH)
|
1999-09-16 23:56:36 +04:00
|
|
|
? NS_UNCONSTRAINEDSIZE
|
|
|
|
: mContentArea.width;
|
|
|
|
}
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-09-16 23:56:36 +04:00
|
|
|
// The frame is clueless about the space manager and therefore we
|
|
|
|
// only give it free space. An example is a table frame - the
|
2003-10-14 01:51:02 +04:00
|
|
|
// tables do not flow around floats.
|
1999-09-16 23:56:36 +04:00
|
|
|
aResult.x = mAvailSpaceRect.x + borderPadding.left;
|
|
|
|
aResult.width = mAvailSpaceRect.width;
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
2003-01-09 05:24:10 +03:00
|
|
|
|
2000-03-23 02:19:10 +03:00
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" CBAS: result %d %d %d %d\n", aResult.x, aResult.y, aResult.width, aResult.height);
|
2000-03-23 02:19:10 +03:00
|
|
|
#endif
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
1998-09-24 00:10:40 +04:00
|
|
|
|
2001-05-01 08:22:57 +04:00
|
|
|
void
|
|
|
|
nsBlockReflowState::GetAvailableSpace(nscoord aY)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Verify that the caller setup the coordinate system properly
|
|
|
|
nscoord wx, wy;
|
|
|
|
mSpaceManager->GetTranslation(wx, wy);
|
|
|
|
NS_ASSERTION((wx == mSpaceManagerX) && (wy == mSpaceManagerY),
|
|
|
|
"bad coord system");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mBand.GetAvailableSpace(aY - BorderPadding().top, mAvailSpaceRect);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
|
|
|
printf("GetAvailableSpace: band=%d,%d,%d,%d count=%d\n",
|
|
|
|
mAvailSpaceRect.x, mAvailSpaceRect.y,
|
|
|
|
mAvailSpaceRect.width, mAvailSpaceRect.height,
|
|
|
|
mBand.GetTrapezoidCount());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
/*
|
|
|
|
* Reconstruct the vertical margin before the line |aLine| in order to
|
|
|
|
* do an incremental reflow that begins with |aLine| without reflowing
|
|
|
|
* the line before it. |aLine| may point to the fencepost at the end of
|
|
|
|
* the line list, and it is used this way since we (for now, anyway)
|
|
|
|
* always need to recover margins at the end of a block.
|
|
|
|
*
|
|
|
|
* The reconstruction involves walking backward through the line list to
|
|
|
|
* find any collapsed margins preceding the line that would have been in
|
|
|
|
* the reflow state's |mPrevBottomMargin| when we reflowed that line in
|
|
|
|
* a full reflow (under the rule in CSS2 that all adjacent vertical
|
|
|
|
* margins of blocks collapse).
|
|
|
|
*/
|
1999-04-03 22:59:01 +04:00
|
|
|
void
|
2001-10-25 05:08:40 +04:00
|
|
|
nsBlockReflowState::ReconstructMarginAbove(nsLineList::iterator aLine)
|
1999-04-03 22:59:01 +04:00
|
|
|
{
|
2001-10-25 05:08:40 +04:00
|
|
|
mPrevBottomMargin.Zero();
|
|
|
|
nsBlockFrame *block = mBlock;
|
|
|
|
|
|
|
|
nsLineList::iterator firstLine = block->begin_lines();
|
|
|
|
for (;;) {
|
|
|
|
--aLine;
|
|
|
|
if (aLine->IsBlock()) {
|
|
|
|
mPrevBottomMargin = aLine->GetCarriedOutBottomMargin();
|
|
|
|
break;
|
|
|
|
}
|
2003-11-11 02:36:06 +03:00
|
|
|
if (!aLine->IsEmpty()) {
|
2001-10-25 05:08:40 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (aLine == firstLine) {
|
|
|
|
// If the top margin was carried out (and thus already applied),
|
|
|
|
// set it to zero. Either way, we're done.
|
|
|
|
if ((0 == mReflowState.mComputedBorderPadding.top) &&
|
|
|
|
!(block->mState & NS_BLOCK_MARGIN_ROOT)) {
|
|
|
|
mPrevBottomMargin.Zero();
|
|
|
|
}
|
|
|
|
break;
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
|
|
|
|
2002-01-06 21:14:00 +03:00
|
|
|
/**
|
2003-10-14 01:51:02 +04:00
|
|
|
* Restore information about floats into the space manager for an
|
|
|
|
* incremental reflow, and simultaneously push the floats by
|
2002-01-06 21:14:00 +03:00
|
|
|
* |aDeltaY|, which is the amount |aLine| was pushed relative to its
|
|
|
|
* parent. The recovery of state is one of the things that makes
|
|
|
|
* incremental reflow O(N^2) and this state should really be kept
|
|
|
|
* around, attached to the frame tree.
|
|
|
|
*/
|
2001-11-15 10:28:46 +03:00
|
|
|
void
|
2003-10-14 01:51:02 +04:00
|
|
|
nsBlockReflowState::RecoverFloats(nsLineList::iterator aLine,
|
|
|
|
nscoord aDeltaY)
|
2001-11-15 10:28:46 +03:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
if (aLine->HasFloats()) {
|
|
|
|
// Place the floats into the space-manager again. Also slide
|
2001-11-15 10:28:46 +03:00
|
|
|
// them, just like the regular frames on the line.
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache* fc = aLine->GetFirstFloat();
|
2001-11-15 10:28:46 +03:00
|
|
|
while (fc) {
|
2003-10-14 01:51:02 +04:00
|
|
|
nsIFrame* floatFrame = fc->mPlaceholder->GetOutOfFlowFrame();
|
2002-01-06 21:14:00 +03:00
|
|
|
if (aDeltaY != 0) {
|
|
|
|
fc->mRegion.y += aDeltaY;
|
|
|
|
fc->mCombinedArea.y += aDeltaY;
|
2003-10-14 01:51:02 +04:00
|
|
|
nsPoint p = floatFrame->GetPosition();
|
|
|
|
floatFrame->SetPosition(nsPoint(p.x, p.y + aDeltaY));
|
2002-01-06 21:14:00 +03:00
|
|
|
}
|
2001-11-15 10:28:46 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (nsBlockFrame::gNoisyReflow || nsBlockFrame::gNoisySpaceManager) {
|
|
|
|
nscoord tx, ty;
|
|
|
|
mSpaceManager->GetTranslation(tx, ty);
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2003-10-14 01:51:02 +04:00
|
|
|
printf("RecoverFloats: txy=%d,%d (%d,%d) ",
|
2001-11-15 10:28:46 +03:00
|
|
|
tx, ty, mSpaceManagerX, mSpaceManagerY);
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFrame::ListTag(stdout, floatFrame);
|
2002-01-06 21:14:00 +03:00
|
|
|
printf(" aDeltaY=%d region={%d,%d,%d,%d}\n",
|
|
|
|
aDeltaY, fc->mRegion.x, fc->mRegion.y,
|
2001-11-15 10:28:46 +03:00
|
|
|
fc->mRegion.width, fc->mRegion.height);
|
|
|
|
}
|
|
|
|
#endif
|
2003-10-14 01:51:02 +04:00
|
|
|
mSpaceManager->AddRectRegion(floatFrame, fc->mRegion);
|
2001-11-15 10:28:46 +03:00
|
|
|
fc = fc->Next();
|
|
|
|
}
|
|
|
|
} else if (aLine->IsBlock()) {
|
|
|
|
nsBlockFrame *kid = nsnull;
|
|
|
|
aLine->mFirstChild->QueryInterface(kBlockFrameCID, (void**)&kid);
|
2004-01-11 07:29:09 +03:00
|
|
|
// don't recover any state inside a block that has its own space
|
|
|
|
// manager (we don't currently have any blocks like this, though,
|
|
|
|
// thanks to our use of extra frames for 'overflow')
|
|
|
|
if (kid && !(kid->GetStateBits() & NS_BLOCK_SPACE_MGR)) {
|
|
|
|
nscoord tx = kid->mRect.x, ty = kid->mRect.y;
|
|
|
|
|
|
|
|
// If the element is relatively positioned, then adjust x and y
|
|
|
|
// accordingly so that we consider relatively positioned frames
|
|
|
|
// at their original position.
|
|
|
|
if (NS_STYLE_POSITION_RELATIVE == kid->GetStyleDisplay()->mPosition) {
|
2004-02-24 00:29:06 +03:00
|
|
|
nsPoint *offsets = NS_STATIC_CAST(nsPoint*,
|
2004-08-25 01:47:04 +04:00
|
|
|
mPresContext->PropertyTable()->GetProperty(kid,
|
|
|
|
nsLayoutAtoms::computedOffsetProperty));
|
2004-02-24 00:29:06 +03:00
|
|
|
|
|
|
|
if (offsets) {
|
2004-01-11 07:29:09 +03:00
|
|
|
tx -= offsets->x;
|
|
|
|
ty -= offsets->y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mSpaceManager->Translate(tx, ty);
|
2001-11-15 10:28:46 +03:00
|
|
|
for (nsBlockFrame::line_iterator line = kid->begin_lines(),
|
|
|
|
line_end = kid->end_lines();
|
|
|
|
line != line_end;
|
|
|
|
++line)
|
2003-10-14 01:51:02 +04:00
|
|
|
// Pass 0, not the real DeltaY, since these floats aren't
|
2002-01-06 21:14:00 +03:00
|
|
|
// moving relative to their parent block, only relative to
|
|
|
|
// the space manager.
|
2003-10-14 01:51:02 +04:00
|
|
|
RecoverFloats(line, 0);
|
2004-01-11 07:29:09 +03:00
|
|
|
mSpaceManager->Translate(-tx, -ty);
|
2001-11-15 10:28:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-03 08:18:39 +03:00
|
|
|
/**
|
|
|
|
* Everything done in this function is done O(N) times for each pass of
|
|
|
|
* reflow so it is O(N*M) where M is the number of incremental reflow
|
|
|
|
* passes. That's bad. Don't do stuff here.
|
|
|
|
*
|
|
|
|
* When this function is called, |aLine| has just been slid by |aDeltaY|
|
|
|
|
* and the purpose of RecoverStateFrom is to ensure that the
|
|
|
|
* nsBlockReflowState is in the same state that it would have been in
|
|
|
|
* had the line just been reflowed.
|
|
|
|
*
|
2003-10-14 01:51:02 +04:00
|
|
|
* Most of the state recovery that we have to do involves floats.
|
2001-11-03 08:18:39 +03:00
|
|
|
*/
|
1999-04-03 22:59:01 +04:00
|
|
|
void
|
2001-10-25 05:08:40 +04:00
|
|
|
nsBlockReflowState::RecoverStateFrom(nsLineList::iterator aLine,
|
|
|
|
nscoord aDeltaY)
|
1999-04-03 22:59:01 +04:00
|
|
|
{
|
|
|
|
// Make the line being recovered the current line
|
|
|
|
mCurrentLine = aLine;
|
|
|
|
|
2003-01-09 17:26:32 +03:00
|
|
|
// Recover mKidXMost and mMaxElementWidth
|
1999-04-03 22:59:01 +04:00
|
|
|
nscoord xmost = aLine->mBounds.XMost();
|
|
|
|
if (xmost > mKidXMost) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (CRAZY_WIDTH(xmost)) {
|
|
|
|
nsFrame::ListTag(stdout, mBlock);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": WARNING: xmost:%d\n", xmost);
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
#endif
|
2000-06-12 02:14:33 +04:00
|
|
|
#ifdef NOISY_KIDXMOST
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("%p RecoverState block %p aState.mKidXMost=%d\n", this, mBlock, xmost);
|
2000-06-12 02:14:33 +04:00
|
|
|
#endif
|
1999-04-03 22:59:01 +04:00
|
|
|
mKidXMost = xmost;
|
|
|
|
}
|
2003-01-09 17:26:32 +03:00
|
|
|
if (GetFlag(BRS_COMPUTEMAXELEMENTWIDTH)) {
|
2002-07-01 21:43:02 +04:00
|
|
|
#ifdef DEBUG
|
2003-01-09 17:26:32 +03:00
|
|
|
if (nsBlockFrame::gNoisyMaxElementWidth) {
|
2002-07-01 21:43:02 +04:00
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
|
|
|
printf("nsBlockReflowState::RecoverStateFrom block %p caching max width %d\n", mBlock, aLine->mMaxElementWidth);
|
|
|
|
}
|
2000-05-14 08:56:25 +04:00
|
|
|
#endif
|
2003-01-09 17:26:32 +03:00
|
|
|
UpdateMaxElementWidth(aLine->mMaxElementWidth);
|
2003-02-22 19:19:31 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Recover the float MEWs for floats in this line (but not in
|
2003-02-22 19:19:31 +03:00
|
|
|
// blocks within it, since their MEWs are already part of the block's
|
|
|
|
// MEW).
|
2003-10-14 01:51:02 +04:00
|
|
|
if (aLine->HasFloats()) {
|
|
|
|
for (nsFloatCache* fc = aLine->GetFirstFloat(); fc; fc = fc->Next())
|
2003-02-22 19:19:31 +03:00
|
|
|
UpdateMaxElementWidth(fc->mMaxElementWidth);
|
|
|
|
}
|
1999-08-28 04:39:55 +04:00
|
|
|
}
|
1999-04-03 22:59:01 +04:00
|
|
|
|
1999-12-30 07:15:45 +03:00
|
|
|
// If computing the maximum width, then update mMaximumWidth
|
2000-04-17 18:40:46 +04:00
|
|
|
if (GetFlag(BRS_COMPUTEMAXWIDTH)) {
|
2000-05-14 08:56:25 +04:00
|
|
|
#ifdef NOISY_MAXIMUM_WIDTH
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsBlockReflowState::RecoverStateFrom block %p caching max width %d\n", mBlock, aLine->mMaximumWidth);
|
2000-05-14 08:56:25 +04:00
|
|
|
#endif
|
1999-12-30 07:15:45 +03:00
|
|
|
UpdateMaximumWidth(aLine->mMaximumWidth);
|
|
|
|
}
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Place floats for this line into the space manager
|
|
|
|
if (aLine->HasFloats() || aLine->IsBlock()) {
|
|
|
|
// Undo border/padding translation since the nsFloatCache's
|
1999-09-16 23:56:36 +04:00
|
|
|
// coordinates are relative to the frame not relative to the
|
|
|
|
// border/padding.
|
|
|
|
const nsMargin& bp = BorderPadding();
|
|
|
|
mSpaceManager->Translate(-bp.left, -bp.top);
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
RecoverFloats(aLine, aDeltaY);
|
2001-11-15 10:28:46 +03:00
|
|
|
|
2000-03-23 02:19:10 +03:00
|
|
|
#ifdef DEBUG
|
2001-05-01 08:22:57 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow || nsBlockFrame::gNoisySpaceManager) {
|
2000-03-23 02:19:10 +03:00
|
|
|
mSpaceManager->List(stdout);
|
|
|
|
}
|
|
|
|
#endif
|
1999-09-16 23:56:36 +04:00
|
|
|
// And then put the translation back again
|
|
|
|
mSpaceManager->Translate(bp.left, bp.top);
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-09-24 00:10:40 +04:00
|
|
|
|
2001-05-01 08:22:57 +04:00
|
|
|
PRBool
|
2003-10-14 01:51:02 +04:00
|
|
|
nsBlockReflowState::IsImpactedByFloat() const
|
2001-05-01 08:22:57 +04:00
|
|
|
{
|
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
2003-10-14 01:51:02 +04:00
|
|
|
printf("nsBlockReflowState::IsImpactedByFloat %p returned %d\n",
|
|
|
|
this, mBand.GetFloatCount());
|
2001-05-01 08:22:57 +04:00
|
|
|
#endif
|
2003-10-14 01:51:02 +04:00
|
|
|
return mBand.GetFloatCount() > 0;
|
2001-05-01 08:22:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-23 06:35:08 +03:00
|
|
|
PRBool
|
2003-10-14 01:51:02 +04:00
|
|
|
nsBlockReflowState::InitFloat(nsLineLayout& aLineLayout,
|
|
|
|
nsPlaceholderFrame* aPlaceholder,
|
|
|
|
nsReflowStatus& aReflowStatus)
|
1998-09-23 06:25:26 +04:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
// Set the geometric parent of the float
|
|
|
|
nsIFrame* floatFrame = aPlaceholder->GetOutOfFlowFrame();
|
|
|
|
floatFrame->SetParent(mBlock);
|
1998-10-10 02:58:25 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Then add the float to the current line and place it when
|
1998-12-15 07:20:54 +03:00
|
|
|
// appropriate
|
2005-03-23 06:35:08 +03:00
|
|
|
return AddFloat(aLineLayout, aPlaceholder, PR_TRUE, aReflowStatus);
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-09-15 04:19:49 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// This is called by the line layout's AddFloat method when a
|
|
|
|
// place-holder frame is reflowed in a line. If the float is a
|
1998-12-05 19:02:08 +03:00
|
|
|
// left-most child (it's x coordinate is at the line's left margin)
|
2003-10-14 01:51:02 +04:00
|
|
|
// then the float is place immediately, otherwise the float
|
1998-12-05 19:02:08 +03:00
|
|
|
// placement is deferred until the line has been reflowed.
|
2001-07-04 06:00:05 +04:00
|
|
|
|
|
|
|
// XXXldb This behavior doesn't quite fit with CSS1 and CSS2 --
|
|
|
|
// technically we're supposed let the current line flow around the
|
|
|
|
// float as well unless it won't fit next to what we already have.
|
|
|
|
// But nobody else implements it that way...
|
2005-03-23 06:35:08 +03:00
|
|
|
PRBool
|
2003-10-14 01:51:02 +04:00
|
|
|
nsBlockReflowState::AddFloat(nsLineLayout& aLineLayout,
|
|
|
|
nsPlaceholderFrame* aPlaceholder,
|
|
|
|
PRBool aInitialReflow,
|
|
|
|
nsReflowStatus& aReflowStatus)
|
1998-12-05 19:02:08 +03:00
|
|
|
{
|
2001-10-25 05:08:40 +04:00
|
|
|
NS_PRECONDITION(mBlock->end_lines() != mCurrentLine, "null ptr");
|
1999-03-23 07:28:20 +03:00
|
|
|
|
2002-05-29 02:50:43 +04:00
|
|
|
aReflowStatus = NS_FRAME_COMPLETE;
|
2003-10-14 01:51:02 +04:00
|
|
|
// Allocate a nsFloatCache for the float
|
|
|
|
nsFloatCache* fc = mFloatCacheFreeList.Alloc();
|
1999-09-15 04:28:10 +04:00
|
|
|
fc->mPlaceholder = aPlaceholder;
|
2003-10-14 01:51:02 +04:00
|
|
|
fc->mIsCurrentLineFloat = aLineLayout.CanPlaceFloatNow();
|
2003-02-22 19:19:31 +03:00
|
|
|
fc->mMaxElementWidth = 0;
|
1998-09-23 06:25:26 +04:00
|
|
|
|
2005-03-23 06:35:08 +03:00
|
|
|
PRBool placed;
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Now place the float immediately if possible. Otherwise stash it
|
|
|
|
// away in mPendingFloats and place it later.
|
|
|
|
if (fc->mIsCurrentLineFloat) {
|
1998-12-05 19:02:08 +03:00
|
|
|
// Because we are in the middle of reflowing a placeholder frame
|
|
|
|
// within a line (and possibly nested in an inline frame or two
|
|
|
|
// that's a child of our block) we need to restore the space
|
|
|
|
// manager's translation to the space that the block resides in
|
2003-10-14 01:51:02 +04:00
|
|
|
// before placing the float.
|
1998-12-05 19:02:08 +03:00
|
|
|
nscoord ox, oy;
|
|
|
|
mSpaceManager->GetTranslation(ox, oy);
|
|
|
|
nscoord dx = ox - mSpaceManagerX;
|
|
|
|
nscoord dy = oy - mSpaceManagerY;
|
|
|
|
mSpaceManager->Translate(-dx, -dy);
|
1999-09-10 22:52:56 +04:00
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
// And then place it
|
2003-10-14 01:51:02 +04:00
|
|
|
PRBool isLeftFloat;
|
2005-03-23 06:35:08 +03:00
|
|
|
placed = FlowAndPlaceFloat(fc, &isLeftFloat, aReflowStatus);
|
|
|
|
if (placed) {
|
|
|
|
// Pass on updated available space to the current inline reflow engine
|
|
|
|
GetAvailableSpace();
|
|
|
|
aLineLayout.UpdateBand(mAvailSpaceRect.x + BorderPadding().left, mY,
|
|
|
|
GetFlag(BRS_UNCONSTRAINEDWIDTH) ? NS_UNCONSTRAINEDSIZE : mAvailSpaceRect.width,
|
|
|
|
mAvailSpaceRect.height,
|
|
|
|
isLeftFloat,
|
|
|
|
aPlaceholder->GetOutOfFlowFrame());
|
|
|
|
|
|
|
|
// Record this float in the current-line list
|
|
|
|
mCurrentLineFloats.Append(fc);
|
|
|
|
}
|
1998-10-03 01:50:53 +04:00
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
// Restore coordinate system
|
|
|
|
mSpaceManager->Translate(dx, dy);
|
1998-09-15 04:19:49 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
else {
|
2003-10-14 01:51:02 +04:00
|
|
|
// This float will be placed after the line is done (it is a
|
|
|
|
// below-current-line float).
|
|
|
|
mBelowCurrentLineFloats.Append(fc);
|
2005-03-23 06:35:08 +03:00
|
|
|
if (mReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
// If the float might not be complete, mark it incomplete now to
|
|
|
|
// prevent the placeholders being torn down. We will destroy any
|
|
|
|
// placeholders later if PlaceBelowCurrentLineFloats finds the
|
|
|
|
// float is complete.
|
|
|
|
aReflowStatus = NS_FRAME_NOT_COMPLETE;
|
|
|
|
}
|
|
|
|
placed = PR_TRUE;
|
1998-09-15 04:19:49 +04:00
|
|
|
}
|
2005-03-23 06:35:08 +03:00
|
|
|
return placed;
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-09-15 04:19:49 +04:00
|
|
|
|
2001-05-01 08:22:57 +04:00
|
|
|
void
|
2003-01-09 17:26:32 +03:00
|
|
|
nsBlockReflowState::UpdateMaxElementWidth(nscoord aMaxElementWidth)
|
2001-05-01 08:22:57 +04:00
|
|
|
{
|
2002-07-01 21:43:02 +04:00
|
|
|
#ifdef DEBUG
|
2003-01-09 17:26:32 +03:00
|
|
|
nscoord oldWidth = mMaxElementWidth;
|
2001-05-01 08:22:57 +04:00
|
|
|
#endif
|
2003-01-09 17:26:32 +03:00
|
|
|
if (aMaxElementWidth > mMaxElementWidth) {
|
|
|
|
mMaxElementWidth = aMaxElementWidth;
|
2001-05-01 08:22:57 +04:00
|
|
|
}
|
2002-07-01 21:43:02 +04:00
|
|
|
#ifdef DEBUG
|
2003-01-09 17:26:32 +03:00
|
|
|
if (nsBlockFrame::gNoisyMaxElementWidth) {
|
|
|
|
if (mMaxElementWidth != oldWidth) {
|
2002-07-01 21:43:02 +04:00
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == mReflowState.availableWidth) {
|
|
|
|
printf("PASS1 ");
|
|
|
|
}
|
|
|
|
nsFrame::ListTag(stdout, mBlock);
|
2003-01-09 17:26:32 +03:00
|
|
|
printf(": old max-element-width=%d new=%d\n",
|
|
|
|
oldWidth, mMaxElementWidth);
|
2001-05-01 08:22:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBlockReflowState::UpdateMaximumWidth(nscoord aMaximumWidth)
|
|
|
|
{
|
|
|
|
if (aMaximumWidth > mMaximumWidth) {
|
|
|
|
#ifdef NOISY_MAXIMUM_WIDTH
|
|
|
|
printf("nsBlockReflowState::UpdateMaximumWidth block %p caching max width %d\n", mBlock, aMaximumWidth);
|
|
|
|
#endif
|
|
|
|
mMaximumWidth = aMaximumWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-31 08:10:27 +04:00
|
|
|
PRBool
|
2005-03-07 05:30:14 +03:00
|
|
|
nsBlockReflowState::CanPlaceFloat(const nsSize& aFloatSize,
|
2003-10-14 01:51:02 +04:00
|
|
|
PRUint8 aFloats)
|
1999-03-31 08:10:27 +04:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
// If the current Y coordinate is not impacted by any floats
|
|
|
|
// then by definition the float fits.
|
1999-03-31 08:10:27 +04:00
|
|
|
PRBool result = PR_TRUE;
|
2003-10-14 01:51:02 +04:00
|
|
|
if (0 != mBand.GetFloatCount()) {
|
2001-07-19 06:33:43 +04:00
|
|
|
// XXX We should allow overflow by up to half a pixel here (bug 21193).
|
2005-03-07 05:30:14 +03:00
|
|
|
if (mAvailSpaceRect.width < aFloatSize.width) {
|
1999-03-31 08:10:27 +04:00
|
|
|
// The available width is too narrow (and its been impacted by a
|
2003-10-14 01:51:02 +04:00
|
|
|
// prior float)
|
1999-03-31 08:10:27 +04:00
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// At this point we know that there is enough horizontal space for
|
2003-10-14 01:51:02 +04:00
|
|
|
// the float (somewhere). Lets see if there is enough vertical
|
1999-03-31 08:10:27 +04:00
|
|
|
// space.
|
2005-03-07 05:30:14 +03:00
|
|
|
if (mAvailSpaceRect.height < aFloatSize.height) {
|
1999-03-31 08:10:27 +04:00
|
|
|
// The available height is too short. However, its possible that
|
|
|
|
// there is enough open space below which is not impacted by a
|
2003-10-14 01:51:02 +04:00
|
|
|
// float.
|
1999-03-31 08:10:27 +04:00
|
|
|
//
|
2003-10-14 01:51:02 +04:00
|
|
|
// Compute the X coordinate for the float based on its float
|
1999-03-31 08:10:27 +04:00
|
|
|
// type, assuming its placed on the current line. This is
|
2003-10-14 01:51:02 +04:00
|
|
|
// where the float will be placed horizontally if it can go
|
1999-03-31 08:10:27 +04:00
|
|
|
// here.
|
1999-05-13 04:55:38 +04:00
|
|
|
nscoord xa;
|
1999-03-31 08:10:27 +04:00
|
|
|
if (NS_STYLE_FLOAT_LEFT == aFloats) {
|
1999-05-13 04:55:38 +04:00
|
|
|
xa = mAvailSpaceRect.x;
|
1999-03-31 08:10:27 +04:00
|
|
|
}
|
|
|
|
else {
|
2005-03-07 05:30:14 +03:00
|
|
|
xa = mAvailSpaceRect.XMost() - aFloatSize.width;
|
1999-03-31 08:10:27 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// In case the float is too big, don't go past the left edge
|
2003-03-12 02:56:49 +03:00
|
|
|
// XXXldb This seems wrong, but we might want to fix bug 6976
|
|
|
|
// first.
|
1999-05-13 04:55:38 +04:00
|
|
|
if (xa < mAvailSpaceRect.x) {
|
|
|
|
xa = mAvailSpaceRect.x;
|
1999-03-31 08:10:27 +04:00
|
|
|
}
|
|
|
|
}
|
2005-03-07 05:30:14 +03:00
|
|
|
nscoord xb = xa + aFloatSize.width;
|
1999-03-31 08:10:27 +04:00
|
|
|
|
|
|
|
// Calculate the top and bottom y coordinates, again assuming
|
2003-10-14 01:51:02 +04:00
|
|
|
// that the float is placed on the current line.
|
1999-03-31 08:10:27 +04:00
|
|
|
const nsMargin& borderPadding = BorderPadding();
|
1999-05-13 04:55:38 +04:00
|
|
|
nscoord ya = mY - borderPadding.top;
|
|
|
|
if (ya < 0) {
|
2001-07-04 06:00:05 +04:00
|
|
|
// CSS2 spec, 9.5.1 rule [4]: "A floating box's outer top may not
|
|
|
|
// be higher than the top of its containing block." (Since the
|
|
|
|
// containing block is the content edge of the block box, this
|
2003-10-14 01:51:02 +04:00
|
|
|
// means the margin edge of the float can't be higher than the
|
2001-07-04 06:00:05 +04:00
|
|
|
// content edge of the block that contains it.)
|
1999-05-13 04:55:38 +04:00
|
|
|
ya = 0;
|
1999-03-31 08:10:27 +04:00
|
|
|
}
|
2005-03-07 05:30:14 +03:00
|
|
|
nscoord yb = ya + aFloatSize.height;
|
1999-03-31 08:10:27 +04:00
|
|
|
|
|
|
|
nscoord saveY = mY;
|
|
|
|
for (;;) {
|
|
|
|
// Get the available space at the new Y coordinate
|
2005-03-23 06:35:08 +03:00
|
|
|
if (mAvailSpaceRect.height <= 0) {
|
|
|
|
// there is no more available space. We lose.
|
|
|
|
result = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-03-31 08:10:27 +04:00
|
|
|
mY += mAvailSpaceRect.height;
|
|
|
|
GetAvailableSpace();
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
if (0 == mBand.GetFloatCount()) {
|
|
|
|
// Winner. This band has no floats on it, therefore
|
1999-03-31 08:10:27 +04:00
|
|
|
// there can be no overlap.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Check and make sure the float won't intersect any
|
|
|
|
// floats on this band. The floats starting and ending
|
1999-03-31 08:10:27 +04:00
|
|
|
// coordinates must be entirely in the available space.
|
1999-05-13 04:55:38 +04:00
|
|
|
if ((xa < mAvailSpaceRect.x) || (xb > mAvailSpaceRect.XMost())) {
|
2003-10-14 01:51:02 +04:00
|
|
|
// The float can't go here.
|
1999-03-31 08:10:27 +04:00
|
|
|
result = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// See if there is now enough height for the float.
|
1999-05-13 04:55:38 +04:00
|
|
|
if (yb < mY + mAvailSpaceRect.height) {
|
2003-10-14 01:51:02 +04:00
|
|
|
// Winner. The bottom Y coordinate of the float is in
|
1999-03-31 08:10:27 +04:00
|
|
|
// this band.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore Y coordinate and available space information
|
|
|
|
// regardless of the outcome.
|
|
|
|
mY = saveY;
|
|
|
|
GetAvailableSpace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-03-23 06:35:08 +03:00
|
|
|
PRBool
|
2004-09-13 17:35:46 +04:00
|
|
|
nsBlockReflowState::FlowAndPlaceFloat(nsFloatCache* aFloatCache,
|
2003-10-14 01:51:02 +04:00
|
|
|
PRBool* aIsLeftFloat,
|
|
|
|
nsReflowStatus& aReflowStatus)
|
1998-09-15 04:19:49 +04:00
|
|
|
{
|
2002-05-29 02:50:43 +04:00
|
|
|
aReflowStatus = NS_FRAME_COMPLETE;
|
2003-10-14 01:51:02 +04:00
|
|
|
// Save away the Y coordinate before placing the float. We will
|
|
|
|
// restore mY at the end after placing the float. This is
|
|
|
|
// necessary because any adjustments to mY during the float
|
|
|
|
// placement are for the float only, not for any non-floating
|
1998-12-12 22:19:11 +03:00
|
|
|
// content.
|
|
|
|
nscoord saveY = mY;
|
2001-05-22 03:03:46 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
nsPlaceholderFrame* placeholder = aFloatCache->mPlaceholder;
|
|
|
|
nsIFrame* floatFrame = placeholder->GetOutOfFlowFrame();
|
1998-09-15 04:19:49 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Grab the float's display information
|
|
|
|
const nsStyleDisplay* floatDisplay = floatFrame->GetStyleDisplay();
|
1998-12-05 19:02:08 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// The float's old region, so we can propagate damage.
|
|
|
|
nsRect oldRegion = floatFrame->GetRect();
|
|
|
|
oldRegion.Inflate(aFloatCache->mMargins);
|
2002-04-26 23:19:39 +04:00
|
|
|
|
2003-03-12 02:56:49 +03:00
|
|
|
// Enforce CSS2 9.5.1 rule [2], i.e., make sure that a float isn't
|
2001-05-22 03:03:46 +04:00
|
|
|
// ``above'' another float that preceded it in the flow.
|
2003-04-15 07:10:50 +04:00
|
|
|
mY = NS_MAX(mSpaceManager->GetLowestRegionTop() + BorderPadding().top, mY);
|
2001-05-22 03:03:46 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// See if the float should clear any preceeding floats...
|
|
|
|
if (NS_STYLE_CLEAR_NONE != floatDisplay->mBreakType) {
|
2001-07-19 06:33:43 +04:00
|
|
|
// XXXldb Does this handle vertical margins correctly?
|
2004-11-25 17:51:00 +03:00
|
|
|
mY = ClearFloats(mY, floatDisplay->mBreakType);
|
2001-07-19 06:33:43 +04:00
|
|
|
}
|
|
|
|
// Get the band of available space
|
|
|
|
GetAvailableSpace();
|
2001-05-22 03:03:46 +04:00
|
|
|
|
2004-09-13 17:35:46 +04:00
|
|
|
NS_ASSERTION(floatFrame->GetParent() == mBlock,
|
|
|
|
"Float frame has wrong parent");
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Reflow the float
|
|
|
|
mBlock->ReflowFloat(*this, placeholder, aFloatCache, aReflowStatus);
|
2001-05-22 03:03:46 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-07-19 06:33:43 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
2005-03-07 05:30:14 +03:00
|
|
|
nsRect region = floatFrame->GetRect();
|
2001-07-19 06:33:43 +04:00
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2003-10-14 01:51:02 +04:00
|
|
|
printf("flowed float: ");
|
|
|
|
nsFrame::ListTag(stdout, floatFrame);
|
2001-07-19 06:33:43 +04:00
|
|
|
printf(" (%d,%d,%d,%d)\n",
|
|
|
|
region.x, region.y, region.width, region.height);
|
|
|
|
}
|
2001-05-22 03:03:46 +04:00
|
|
|
#endif
|
|
|
|
|
2005-03-07 05:30:14 +03:00
|
|
|
nsSize floatSize = floatFrame->GetSize();
|
2003-10-14 01:51:02 +04:00
|
|
|
// Adjust the float size by its margin. That's the area that will
|
2001-07-19 06:33:43 +04:00
|
|
|
// impact the space manager.
|
2005-03-07 05:30:14 +03:00
|
|
|
floatSize.width += aFloatCache->mMargins.left + aFloatCache->mMargins.right;
|
|
|
|
floatSize.height += aFloatCache->mMargins.top + aFloatCache->mMargins.bottom;
|
2001-07-19 06:33:43 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Find a place to place the float. The CSS2 spec doesn't want
|
|
|
|
// floats overlapping each other or sticking out of the containing
|
2001-07-19 06:33:43 +04:00
|
|
|
// block if possible (CSS2 spec section 9.5.1, see the rule list).
|
2003-10-14 01:51:02 +04:00
|
|
|
NS_ASSERTION((NS_STYLE_FLOAT_LEFT == floatDisplay->mFloats) ||
|
|
|
|
(NS_STYLE_FLOAT_RIGHT == floatDisplay->mFloats),
|
2001-07-19 06:33:43 +04:00
|
|
|
"invalid float type");
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Can the float fit here?
|
|
|
|
PRBool keepFloatOnSameLine = PR_FALSE;
|
2002-03-08 23:25:54 +03:00
|
|
|
|
2005-03-07 05:30:14 +03:00
|
|
|
while (! CanPlaceFloat(floatSize, floatDisplay->mFloats)) {
|
2005-03-23 06:35:08 +03:00
|
|
|
if (mAvailSpaceRect.height <= 0) {
|
|
|
|
// No space, nowhere to put anything.
|
|
|
|
mY = saveY;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-08 23:25:54 +03:00
|
|
|
// Nope. try to advance to the next band.
|
2003-10-14 01:51:02 +04:00
|
|
|
if (NS_STYLE_DISPLAY_TABLE != floatDisplay->mDisplay ||
|
2003-12-25 00:51:50 +03:00
|
|
|
eCompatibility_NavQuirks != mPresContext->CompatibilityMode() ) {
|
2002-03-08 23:25:54 +03:00
|
|
|
|
|
|
|
mY += mAvailSpaceRect.height;
|
|
|
|
GetAvailableSpace();
|
|
|
|
} else {
|
2003-11-16 21:49:00 +03:00
|
|
|
// This quirk matches the one in nsBlockFrame::ReflowFloat
|
2003-10-14 01:51:02 +04:00
|
|
|
// IE handles float tables in a very special way
|
2002-03-08 23:25:54 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// see if the previous float is also a table and has "align"
|
|
|
|
nsFloatCache* fc = mCurrentLineFloats.Head();
|
2002-03-08 23:25:54 +03:00
|
|
|
nsIFrame* prevFrame = nsnull;
|
|
|
|
while (fc) {
|
2003-10-14 01:51:02 +04:00
|
|
|
if (fc->mPlaceholder->GetOutOfFlowFrame() == floatFrame) {
|
2002-03-08 23:25:54 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
prevFrame = fc->mPlaceholder->GetOutOfFlowFrame();
|
|
|
|
fc = fc->Next();
|
|
|
|
}
|
|
|
|
|
2002-03-09 00:23:55 +03:00
|
|
|
if(prevFrame) {
|
|
|
|
//get the frame type
|
2003-10-31 23:19:18 +03:00
|
|
|
if (nsLayoutAtoms::tableOuterFrame == prevFrame->GetType()) {
|
2002-03-09 00:23:55 +03:00
|
|
|
//see if it has "align="
|
|
|
|
// IE makes a difference between align and he float property
|
2003-06-27 22:13:48 +04:00
|
|
|
nsIContent* content = prevFrame->GetContent();
|
2002-03-09 00:23:55 +03:00
|
|
|
if (content) {
|
|
|
|
nsAutoString value;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsHTMLAtoms::align, value)) {
|
|
|
|
// we're interested only if previous frame is align=left
|
|
|
|
// IE messes things up when "right" (overlapping frames)
|
2004-06-17 04:13:25 +04:00
|
|
|
if (value.LowerCaseEqualsLiteral("left")) {
|
2003-10-14 01:51:02 +04:00
|
|
|
keepFloatOnSameLine = PR_TRUE;
|
2002-03-09 00:23:55 +03:00
|
|
|
// don't advance to next line (IE quirkie behaviour)
|
|
|
|
// it breaks rule CSS2/9.5.1/1, but what the hell
|
|
|
|
// since we cannot evangelize the world
|
|
|
|
break;
|
|
|
|
}
|
2002-03-08 23:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-11-15 00:01:26 +03:00
|
|
|
|
2002-03-08 23:25:54 +03:00
|
|
|
// the table does not fit anymore in this line so advance to next band
|
|
|
|
mY += mAvailSpaceRect.height;
|
|
|
|
GetAvailableSpace();
|
2003-10-14 01:51:02 +04:00
|
|
|
// reflow the float again now since we have more space
|
|
|
|
mBlock->ReflowFloat(*this, placeholder, aFloatCache, aReflowStatus);
|
|
|
|
// Get the floats bounding box and margin information
|
2005-03-07 05:30:14 +03:00
|
|
|
floatSize = floatFrame->GetSize();
|
2003-10-14 01:51:02 +04:00
|
|
|
// Adjust the float size by its margin. That's the area that will
|
2002-03-08 23:25:54 +03:00
|
|
|
// impact the space manager.
|
2005-03-07 05:30:14 +03:00
|
|
|
floatSize.width += aFloatCache->mMargins.left + aFloatCache->mMargins.right;
|
|
|
|
floatSize.height += aFloatCache->mMargins.top + aFloatCache->mMargins.bottom;
|
2002-03-08 23:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
2003-10-14 01:51:02 +04:00
|
|
|
// If the float is continued, it will get the same absolute x value as its prev-in-flow
|
2002-12-04 03:58:52 +03:00
|
|
|
nsRect prevRect(0,0,0,0);
|
2005-03-23 06:35:08 +03:00
|
|
|
|
|
|
|
// We don't worry about the geometry of the prev in flow, let the continuation
|
|
|
|
// place and size itself as required.
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Assign an x and y coordinate to the float. Note that the x,y
|
1998-12-05 19:02:08 +03:00
|
|
|
// coordinates are computed <b>relative to the translation in the
|
|
|
|
// spacemanager</b> which means that the impacted region will be
|
|
|
|
// <b>inside</b> the border/padding area.
|
2003-10-14 01:51:02 +04:00
|
|
|
PRBool isLeftFloat;
|
2005-03-07 05:30:14 +03:00
|
|
|
nscoord floatX, floatY;
|
2003-10-14 01:51:02 +04:00
|
|
|
if (NS_STYLE_FLOAT_LEFT == floatDisplay->mFloats) {
|
|
|
|
isLeftFloat = PR_TRUE;
|
2005-03-23 06:35:08 +03:00
|
|
|
floatX = mAvailSpaceRect.x;
|
1998-09-15 04:19:49 +04:00
|
|
|
}
|
|
|
|
else {
|
2003-10-14 01:51:02 +04:00
|
|
|
isLeftFloat = PR_FALSE;
|
2002-09-20 17:19:54 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != mAvailSpaceRect.width) {
|
2005-03-23 06:35:08 +03:00
|
|
|
if (!keepFloatOnSameLine) {
|
2005-03-07 05:30:14 +03:00
|
|
|
floatX = mAvailSpaceRect.XMost() - floatSize.width;
|
2002-05-29 02:50:43 +04:00
|
|
|
}
|
|
|
|
else {
|
2002-03-08 23:25:54 +03:00
|
|
|
// this is the IE quirk (see few lines above)
|
2003-10-14 01:51:02 +04:00
|
|
|
// the table is keept in the same line: don't let it overlap the previous float
|
2005-03-07 05:30:14 +03:00
|
|
|
floatX = mAvailSpaceRect.x;
|
2002-03-08 23:25:54 +03:00
|
|
|
}
|
2002-05-29 02:50:43 +04:00
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
else {
|
2003-10-14 01:51:02 +04:00
|
|
|
// For unconstrained reflows, pretend that a right float is
|
|
|
|
// instead a left float. This will make us end up with the
|
2002-12-19 03:12:08 +03:00
|
|
|
// correct unconstrained width, and we'll place it later.
|
2005-03-07 05:30:14 +03:00
|
|
|
floatX = mAvailSpaceRect.x;
|
2000-04-17 18:40:46 +04:00
|
|
|
}
|
1998-09-15 04:19:49 +04:00
|
|
|
}
|
2003-10-14 01:51:02 +04:00
|
|
|
*aIsLeftFloat = isLeftFloat;
|
1999-03-05 07:21:32 +03:00
|
|
|
const nsMargin& borderPadding = BorderPadding();
|
2005-03-07 05:30:14 +03:00
|
|
|
floatY = mY - borderPadding.top;
|
|
|
|
if (floatY < 0) {
|
2001-07-04 06:00:05 +04:00
|
|
|
// CSS2 spec, 9.5.1 rule [4]: "A floating box's outer top may not
|
|
|
|
// be higher than the top of its containing block." (Since the
|
|
|
|
// containing block is the content edge of the block box, this
|
2003-10-14 01:51:02 +04:00
|
|
|
// means the margin edge of the float can't be higher than the
|
2001-07-04 06:00:05 +04:00
|
|
|
// content edge of the block that contains it.)
|
2005-03-07 05:30:14 +03:00
|
|
|
floatY = 0;
|
1998-09-15 04:19:49 +04:00
|
|
|
}
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Place the float in the space manager
|
|
|
|
// if the float split, then take up all of the vertical height
|
2002-12-19 03:12:08 +03:00
|
|
|
if (NS_FRAME_IS_NOT_COMPLETE(aReflowStatus) &&
|
|
|
|
(NS_UNCONSTRAINEDSIZE != mContentArea.height)) {
|
2005-03-23 06:35:08 +03:00
|
|
|
floatSize.height = PR_MAX(floatSize.height, mContentArea.height - floatY);
|
2002-12-19 03:12:08 +03:00
|
|
|
}
|
2005-03-07 05:30:14 +03:00
|
|
|
|
|
|
|
nsRect region(floatX, floatY, floatSize.width, floatSize.height);
|
1999-10-29 18:34:53 +04:00
|
|
|
#ifdef DEBUG
|
2002-12-19 03:12:08 +03:00
|
|
|
nsresult rv =
|
1999-10-29 18:34:53 +04:00
|
|
|
#endif
|
2003-10-14 01:51:02 +04:00
|
|
|
mSpaceManager->AddRectRegion(floatFrame, region);
|
|
|
|
NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "bad float placement");
|
1998-11-05 22:33:01 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// If the float's dimensions have changed, note the damage in the
|
2002-04-26 23:19:39 +04:00
|
|
|
// space manager.
|
|
|
|
if (region != oldRegion) {
|
|
|
|
// XXXwaterson conservative: we could probably get away with noting
|
|
|
|
// less damage; e.g., if only height has changed, then only note the
|
|
|
|
// area into which the float has grown or from which the float has
|
|
|
|
// shrunk.
|
|
|
|
nscoord top = NS_MIN(region.y, oldRegion.y);
|
|
|
|
nscoord bottom = NS_MAX(region.YMost(), oldRegion.YMost());
|
|
|
|
mSpaceManager->IncludeInDamage(top, bottom);
|
|
|
|
}
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Save away the floats region in the spacemanager, after making
|
1999-09-15 04:28:10 +04:00
|
|
|
// it relative to the containing block's frame instead of relative
|
|
|
|
// to the spacemanager translation (which is inset by the
|
|
|
|
// border+padding).
|
2003-10-14 01:51:02 +04:00
|
|
|
aFloatCache->mRegion.x = region.x + borderPadding.left;
|
|
|
|
aFloatCache->mRegion.y = region.y + borderPadding.top;
|
|
|
|
aFloatCache->mRegion.width = region.width;
|
|
|
|
aFloatCache->mRegion.height = region.height;
|
1999-09-15 04:28:10 +04:00
|
|
|
#ifdef NOISY_SPACEMANAGER
|
|
|
|
nscoord tx, ty;
|
|
|
|
mSpaceManager->GetTranslation(tx, ty);
|
|
|
|
nsFrame::ListTag(stdout, mBlock);
|
2003-10-14 01:51:02 +04:00
|
|
|
printf(": FlowAndPlaceFloat: AddRectRegion: txy=%d,%d (%d,%d) {%d,%d,%d,%d}\n",
|
1999-09-15 04:28:10 +04:00
|
|
|
tx, ty, mSpaceManagerX, mSpaceManagerY,
|
2003-10-14 01:51:02 +04:00
|
|
|
aFloatCache->mRegion.x, aFloatCache->mRegion.y,
|
|
|
|
aFloatCache->mRegion.width, aFloatCache->mRegion.height);
|
1999-09-15 04:28:10 +04:00
|
|
|
#endif
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Set the origin of the float frame, in frame coordinates. These
|
1998-12-05 19:02:08 +03:00
|
|
|
// coordinates are <b>not</b> relative to the spacemanager
|
|
|
|
// translation, therefore we have to factor in our border/padding.
|
2003-10-14 01:51:02 +04:00
|
|
|
nscoord x = borderPadding.left + aFloatCache->mMargins.left + region.x;
|
|
|
|
nscoord y = borderPadding.top + aFloatCache->mMargins.top + region.y;
|
1999-07-14 21:26:20 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// If float is relatively positioned, factor that in as well
|
2001-07-04 06:00:05 +04:00
|
|
|
// XXXldb Should this be done after handling the combined area
|
|
|
|
// below?
|
2003-10-14 01:51:02 +04:00
|
|
|
if (NS_STYLE_POSITION_RELATIVE == floatDisplay->mPosition) {
|
|
|
|
x += aFloatCache->mOffsets.left;
|
|
|
|
y += aFloatCache->mOffsets.top;
|
1999-07-14 21:26:20 +04:00
|
|
|
}
|
1999-11-30 08:09:08 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Position the float and make sure and views are properly
|
2001-09-21 04:53:29 +04:00
|
|
|
// positioned. We need to explicitly position its child views as
|
2003-10-14 01:51:02 +04:00
|
|
|
// well, since we're moving the float after flowing it.
|
|
|
|
floatFrame->SetPosition(nsPoint(x, y));
|
2004-12-27 18:05:18 +03:00
|
|
|
nsContainerFrame::PositionFrameView(floatFrame);
|
|
|
|
nsContainerFrame::PositionChildViews(floatFrame);
|
1999-10-15 03:10:03 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Update the float combined area state
|
|
|
|
nsRect combinedArea = aFloatCache->mCombinedArea;
|
1999-10-15 03:10:03 +04:00
|
|
|
combinedArea.x += x;
|
|
|
|
combinedArea.y += y;
|
2003-10-14 01:51:02 +04:00
|
|
|
// When we are placing a right float in an unconstrained situation or
|
|
|
|
// when shrink wrapping, we don't apply it to the float combined area
|
2002-12-19 03:12:08 +03:00
|
|
|
// immediately, since there's no need to since we're guaranteed another
|
|
|
|
// reflow, and since there's no need to change the code that was
|
2003-10-14 01:51:02 +04:00
|
|
|
// necessary back when the float was positioned relative to
|
2002-12-19 03:12:08 +03:00
|
|
|
// NS_UNCONSTRAINEDSIZE.
|
2003-10-14 01:51:02 +04:00
|
|
|
if (isLeftFloat ||
|
2002-12-19 03:12:08 +03:00
|
|
|
!GetFlag(BRS_UNCONSTRAINEDWIDTH) ||
|
|
|
|
!GetFlag(BRS_SHRINKWRAPWIDTH)) {
|
2003-10-14 01:51:02 +04:00
|
|
|
mFloatCombinedArea.UnionRect(combinedArea, mFloatCombinedArea);
|
2002-12-19 03:12:08 +03:00
|
|
|
} else if (GetFlag(BRS_SHRINKWRAPWIDTH)) {
|
2003-10-14 01:51:02 +04:00
|
|
|
// Mark the line dirty so we come back and re-place the float once
|
2002-12-19 03:12:08 +03:00
|
|
|
// the shrink wrap width is determined
|
|
|
|
mCurrentLine->MarkDirty();
|
|
|
|
SetFlag(BRS_NEEDRESIZEREFLOW, PR_TRUE);
|
1999-03-24 18:42:19 +03:00
|
|
|
}
|
1998-12-12 22:19:11 +03:00
|
|
|
|
|
|
|
// Now restore mY
|
|
|
|
mY = saveY;
|
|
|
|
|
1999-10-16 03:35:10 +04:00
|
|
|
#ifdef DEBUG
|
2001-05-01 08:22:57 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
2003-10-14 01:51:02 +04:00
|
|
|
nsRect r = floatFrame->GetRect();
|
2001-05-01 08:22:57 +04:00
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2003-10-14 01:51:02 +04:00
|
|
|
printf("placed float: ");
|
|
|
|
nsFrame::ListTag(stdout, floatFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" %d,%d,%d,%d\n", r.x, r.y, r.width, r.height);
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-11-05 22:33:01 +03:00
|
|
|
#endif
|
2005-03-23 06:35:08 +03:00
|
|
|
|
|
|
|
return PR_TRUE;
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-11-05 22:33:01 +03:00
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
/**
|
2003-10-14 01:51:02 +04:00
|
|
|
* Place below-current-line floats.
|
1998-12-05 19:02:08 +03:00
|
|
|
*/
|
2002-05-29 02:50:43 +04:00
|
|
|
PRBool
|
2003-10-14 01:51:02 +04:00
|
|
|
nsBlockReflowState::PlaceBelowCurrentLineFloats(nsFloatCacheList& aList)
|
1998-12-05 19:02:08 +03:00
|
|
|
{
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache* fc = aList.Head();
|
1999-09-15 04:28:10 +04:00
|
|
|
while (fc) {
|
2003-10-14 01:51:02 +04:00
|
|
|
NS_ASSERTION(!fc->mIsCurrentLineFloat,
|
|
|
|
"A cl float crept into the bcl float list.");
|
|
|
|
if (!fc->mIsCurrentLineFloat) {
|
1999-10-29 18:34:53 +04:00
|
|
|
#ifdef DEBUG
|
2001-05-01 08:22:57 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2003-10-14 01:51:02 +04:00
|
|
|
printf("placing bcl float: ");
|
1999-10-29 18:34:53 +04:00
|
|
|
nsFrame::ListTag(stdout, fc->mPlaceholder->GetOutOfFlowFrame());
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("\n");
|
1999-10-29 18:34:53 +04:00
|
|
|
}
|
|
|
|
#endif
|
1999-03-23 07:28:20 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Place the float
|
|
|
|
PRBool isLeftFloat;
|
2002-05-29 02:50:43 +04:00
|
|
|
nsReflowStatus reflowStatus;
|
2005-03-23 06:35:08 +03:00
|
|
|
PRBool placed = FlowAndPlaceFloat(fc, &isLeftFloat, reflowStatus);
|
2002-05-29 02:50:43 +04:00
|
|
|
|
2005-03-23 06:35:08 +03:00
|
|
|
if (!placed || NS_FRAME_IS_TRUNCATED(reflowStatus)) {
|
2003-10-14 01:51:02 +04:00
|
|
|
// return before processing all of the floats, since the line will be pushed.
|
2002-05-29 02:50:43 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
else if (NS_FRAME_IS_NOT_COMPLETE(reflowStatus)) {
|
2003-10-14 01:51:02 +04:00
|
|
|
// Create a continuation for the incomplete float and its placeholder.
|
2005-03-23 06:35:08 +03:00
|
|
|
nsresult rv = mBlock->SplitPlaceholder(*this, fc->mPlaceholder);
|
2002-05-29 02:50:43 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_FALSE;
|
2005-03-23 06:35:08 +03:00
|
|
|
} else {
|
|
|
|
// Float is complete. We need to delete any leftover placeholders now.
|
|
|
|
nsIFrame* nextPlaceholder = fc->mPlaceholder->GetNextInFlow();
|
|
|
|
if (nextPlaceholder) {
|
|
|
|
nsHTMLContainerFrame* parent =
|
|
|
|
NS_STATIC_CAST(nsHTMLContainerFrame*, nextPlaceholder->GetParent());
|
|
|
|
parent->DeleteNextInFlowChild(mPresContext, nextPlaceholder);
|
|
|
|
}
|
2002-05-29 02:50:43 +04:00
|
|
|
}
|
1999-02-09 20:31:33 +03:00
|
|
|
}
|
1999-09-15 04:28:10 +04:00
|
|
|
fc = fc->Next();
|
1999-02-09 20:31:33 +03:00
|
|
|
}
|
2002-05-29 02:50:43 +04:00
|
|
|
return PR_TRUE;
|
1999-02-09 20:31:33 +03:00
|
|
|
}
|
|
|
|
|
2004-11-25 17:51:00 +03:00
|
|
|
nscoord
|
2003-10-14 01:51:02 +04:00
|
|
|
nsBlockReflowState::ClearFloats(nscoord aY, PRUint8 aBreakType)
|
1998-10-27 19:51:02 +03:00
|
|
|
{
|
1999-10-16 03:35:10 +04:00
|
|
|
#ifdef DEBUG
|
2001-05-01 08:22:57 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2004-11-25 17:51:00 +03:00
|
|
|
printf("clear floats: in: aY=%d(%d)\n",
|
|
|
|
aY, aY - BorderPadding().top);
|
1999-10-16 03:35:10 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
#endif
|
1998-10-27 19:51:02 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
#ifdef NOISY_FLOAT_CLEARING
|
|
|
|
printf("nsBlockReflowState::ClearFloats: aY=%d breakType=%d\n",
|
1999-09-16 23:56:36 +04:00
|
|
|
aY, aBreakType);
|
|
|
|
mSpaceManager->List(stdout);
|
|
|
|
#endif
|
2004-06-08 23:18:30 +04:00
|
|
|
|
1999-03-05 07:21:32 +03:00
|
|
|
const nsMargin& bp = BorderPadding();
|
2004-06-08 23:18:30 +04:00
|
|
|
nscoord newY = mSpaceManager->ClearFloats(aY - bp.top, aBreakType);
|
2004-11-25 17:51:00 +03:00
|
|
|
newY += bp.top;
|
1998-09-23 06:25:26 +04:00
|
|
|
|
1999-10-16 03:35:10 +04:00
|
|
|
#ifdef DEBUG
|
2001-05-01 08:22:57 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2004-11-25 17:51:00 +03:00
|
|
|
printf("clear floats: out: y=%d(%d)\n", newY, newY - bp.top);
|
1999-10-16 03:35:10 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
#endif
|
2004-11-25 17:51:00 +03:00
|
|
|
|
|
|
|
return newY;
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
2001-05-01 08:22:57 +04:00
|
|
|
|