1998-06-18 20:25:41 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1998-06-18 20:25:41 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03: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-06-18 20:25:41 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 06:40:37 +03:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-04-17 18:40:46 +04:00
|
|
|
* Steve Clark <buster@netscape.com>
|
|
|
|
* Robert O'Callahan <roc+moz@cs.cmu.edu>
|
2000-09-05 01:44:48 +04:00
|
|
|
* L. David Baron <dbaron@fas.harvard.edu>
|
1998-06-18 20:25:41 +04:00
|
|
|
*/
|
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"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include "nsBlockDebugFlags.h"
|
|
|
|
#endif
|
1998-06-24 21:52:42 +04:00
|
|
|
|
1999-03-05 07:21:32 +03:00
|
|
|
nsBlockReflowState::nsBlockReflowState(const nsHTMLReflowState& aReflowState,
|
1999-04-20 04:27:43 +04:00
|
|
|
nsIPresContext* aPresContext,
|
1999-03-05 07:21:32 +03:00
|
|
|
nsBlockFrame* aFrame,
|
2000-01-03 07:32:13 +03:00
|
|
|
const nsHTMLReflowMetrics& aMetrics,
|
|
|
|
PRBool aBlockMarginRoot)
|
1999-04-03 22:59:01 +04:00
|
|
|
: mBlock(aFrame),
|
|
|
|
mPresContext(aPresContext),
|
1999-03-05 07:21:32 +03:00
|
|
|
mReflowState(aReflowState),
|
2001-05-22 03:03:46 +04:00
|
|
|
mLastFloaterY(0),
|
1999-04-03 22:59:01 +04:00
|
|
|
mNextRCFrame(nsnull),
|
1999-08-28 01:45:37 +04:00
|
|
|
mPrevBottomMargin(0),
|
2000-04-17 18:40:46 +04:00
|
|
|
mLineNumber(0),
|
|
|
|
mFlags(0)
|
1998-11-15 00:01:26 +03:00
|
|
|
{
|
2000-01-18 18:36:36 +03:00
|
|
|
const nsMargin& borderPadding = BorderPadding();
|
|
|
|
|
2000-01-03 07:32:13 +03:00
|
|
|
if (aBlockMarginRoot) {
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(BRS_ISTOPMARGINROOT, PR_TRUE);
|
|
|
|
SetFlag(BRS_ISBOTTOMMARGINROOT, PR_TRUE);
|
2000-01-03 07:32:13 +03:00
|
|
|
}
|
2000-01-13 05:05:31 +03:00
|
|
|
if (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
|
|
|
}
|
|
|
|
if (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
|
|
|
|
2000-01-18 18:36:36 +03:00
|
|
|
NS_ASSERTION( nsnull != mSpaceManager, "SpaceManager should be set in nsBlockReflowState" );
|
|
|
|
if( nsnull != mSpaceManager ) {
|
|
|
|
// 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;
|
1999-02-24 07:48:08 +03:00
|
|
|
mBlock->GetNextInFlow((nsIFrame**)&mNextInFlow);
|
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;
|
|
|
|
mContentArea.width = aReflowState.availableWidth - lr;
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
|
|
|
}
|
1999-10-15 03:10:03 +04:00
|
|
|
mHaveRightFloaters = PR_FALSE;
|
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;
|
|
|
|
mContentArea.height = 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;
|
1999-02-09 20:31:33 +03:00
|
|
|
mCurrentLine = nsnull;
|
1998-12-05 19:02:08 +03:00
|
|
|
mPrevLine = nsnull;
|
1999-03-05 07:21:32 +03:00
|
|
|
|
|
|
|
const nsStyleText* styleText;
|
|
|
|
mBlock->GetStyleData(eStyleStruct_Text,
|
|
|
|
(const nsStyleStruct*&) styleText);
|
|
|
|
switch (styleText->mWhiteSpace) {
|
|
|
|
case NS_STYLE_WHITESPACE_PRE:
|
|
|
|
case NS_STYLE_WHITESPACE_NOWRAP:
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(BRS_NOWRAP, PR_TRUE);
|
1999-03-05 07:21:32 +03:00
|
|
|
break;
|
|
|
|
default:
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(BRS_NOWRAP, PR_FALSE);
|
1999-03-05 07:21:32 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(BRS_COMPUTEMAXELEMENTSIZE, (nsnull != aMetrics.maxElementSize));
|
2000-05-14 08:56:25 +04:00
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("BRS: setting compute-MES to %d\n", (nsnull != aMetrics.maxElementSize));
|
2000-05-14 08:56:25 +04:00
|
|
|
#endif
|
1999-03-05 07:21:32 +03:00
|
|
|
mMaxElementSize.SizeTo(0, 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
|
|
|
{
|
1998-12-05 19:02:08 +03:00
|
|
|
// Restore the coordinate system
|
1999-03-05 07:21:32 +03:00
|
|
|
const nsMargin& borderPadding = BorderPadding();
|
|
|
|
mSpaceManager->Translate(-borderPadding.left, -borderPadding.top);
|
1999-10-20 03:04:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsLineBox*
|
|
|
|
nsBlockReflowState::NewLineBox(nsIFrame* aFrame,
|
|
|
|
PRInt32 aCount,
|
|
|
|
PRBool aIsBlock)
|
|
|
|
{
|
2000-03-12 06:00:51 +03:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
|
|
|
|
return NS_NewLineBox(shell, aFrame, aCount, aIsBlock);
|
1999-10-20 03:04:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBlockReflowState::FreeLineBox(nsLineBox* aLine)
|
|
|
|
{
|
|
|
|
if (aLine) {
|
2000-03-12 06:00:51 +03:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
|
|
|
|
aLine->Destroy(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
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("CBAS frame=%p has floater count %d\n", aFrame, mBand.GetFloaterCount());
|
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 */
|
|
|
|
PRBool treatAsNotSplittable=PR_FALSE;
|
|
|
|
nsCOMPtr<nsIAtom>frameType;
|
|
|
|
aFrame->GetFrameType(getter_AddRefs(frameType));
|
2001-07-04 06:00:05 +04:00
|
|
|
if (frameType) {
|
|
|
|
// text controls are not splittable, so make a special case here
|
|
|
|
// XXXldb Why not just set the frame state bit?
|
2000-09-15 10:20:07 +04:00
|
|
|
if (nsLayoutAtoms::textInputFrame == frameType.get())
|
|
|
|
treatAsNotSplittable = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
1999-09-16 23:56:36 +04:00
|
|
|
if (mBand.GetFloaterCount()) {
|
|
|
|
// Use the float-edge property to determine how the child block
|
|
|
|
// will interact with the floater.
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleBorder* borderStyle;
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Border,
|
|
|
|
(const nsStyleStruct*&) borderStyle);
|
|
|
|
switch (borderStyle->mFloatEdge) {
|
1999-09-16 23:56:36 +04:00
|
|
|
default:
|
2000-03-23 02:19:10 +03:00
|
|
|
case NS_STYLE_FLOAT_EDGE_CONTENT: // content and only content does runaround of floaters
|
1999-09-16 23:56:36 +04:00
|
|
|
// The child block will flow around the floater. Therefore
|
|
|
|
// 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,
|
|
|
|
// but not overlap the floater(s).
|
|
|
|
nsMargin m(0, 0, 0, 0);
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleMargin* styleMargin;
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Margin,
|
|
|
|
(const nsStyleStruct*&) styleMargin);
|
|
|
|
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
|
|
|
|
if (mBand.GetLeftFloaterCount()) {
|
|
|
|
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 {
|
|
|
|
if (mBand.GetRightFloaterCount()) {
|
|
|
|
if (mBand.GetLeftFloaterCount()) {
|
|
|
|
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,
|
|
|
|
// but not overlap the floater.
|
|
|
|
aResult.x = mAvailSpaceRect.x + borderPadding.left;
|
|
|
|
aResult.width = mAvailSpaceRect.width;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Since there are no floaters present the float-edge property
|
|
|
|
// doesn't matter therefore give the block element all of the
|
|
|
|
// available space since it will flow around the floater itself.
|
|
|
|
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
|
|
|
|
// tables do not flow around floaters.
|
|
|
|
aResult.x = mAvailSpaceRect.x + borderPadding.left;
|
|
|
|
aResult.width = mAvailSpaceRect.width;
|
1999-04-03 22:59:01 +04: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
|
|
|
|
}
|
|
|
|
|
1999-04-03 22:59:01 +04:00
|
|
|
PRBool
|
|
|
|
nsBlockReflowState::ClearPastFloaters(PRUint8 aBreakType)
|
|
|
|
{
|
|
|
|
nscoord saveY, deltaY;
|
|
|
|
|
|
|
|
PRBool applyTopMargin = PR_FALSE;
|
|
|
|
switch (aBreakType) {
|
|
|
|
case NS_STYLE_CLEAR_LEFT:
|
|
|
|
case NS_STYLE_CLEAR_RIGHT:
|
|
|
|
case NS_STYLE_CLEAR_LEFT_AND_RIGHT:
|
|
|
|
// Apply the previous margin before clearing
|
|
|
|
saveY = mY + mPrevBottomMargin;
|
|
|
|
ClearFloaters(saveY, aBreakType);
|
1999-09-16 23:56:36 +04:00
|
|
|
#ifdef NOISY_FLOATER_CLEARING
|
|
|
|
nsFrame::ListTag(stdout, mBlock);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": ClearPastFloaters: mPrevBottomMargin=%d saveY=%d oldY=%d newY=%d deltaY=%d\n",
|
1999-09-16 23:56:36 +04:00
|
|
|
mPrevBottomMargin, saveY, saveY - mPrevBottomMargin, mY,
|
|
|
|
mY - saveY);
|
|
|
|
#endif
|
1999-04-03 22:59:01 +04:00
|
|
|
|
|
|
|
// Determine how far we just moved. If we didn't move then there
|
|
|
|
// was nothing to clear to don't mess with the normal margin
|
|
|
|
// collapsing behavior. In either case we need to restore the Y
|
|
|
|
// coordinate to what it was before the clear.
|
|
|
|
deltaY = mY - saveY;
|
|
|
|
if (0 != deltaY) {
|
|
|
|
// Pretend that the distance we just moved is a previous
|
|
|
|
// blocks bottom margin. Note that GetAvailableSpace has been
|
|
|
|
// done so that the available space calculations will be done
|
|
|
|
// after clearing the appropriate floaters.
|
|
|
|
//
|
|
|
|
// What we are doing here is applying CSS2 section 9.5.2's
|
|
|
|
// rules for clearing - "The top margin of the generated box
|
|
|
|
// is increased enough that the top border edge is below the
|
|
|
|
// bottom outer edge of the floating boxes..."
|
|
|
|
//
|
|
|
|
// What this will do is cause the top-margin of the block
|
|
|
|
// frame we are about to reflow to be collapsed with that
|
|
|
|
// distance.
|
2001-07-04 06:00:05 +04:00
|
|
|
|
|
|
|
// XXXldb This doesn't handle collapsing with negative margins
|
|
|
|
// correctly, although it's arguable what "correct" is.
|
|
|
|
|
1999-04-03 22:59:01 +04:00
|
|
|
mPrevBottomMargin = deltaY;
|
|
|
|
mY = saveY;
|
|
|
|
|
|
|
|
// Force margin to be applied in this circumstance
|
|
|
|
applyTopMargin = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
2001-07-04 06:00:05 +04:00
|
|
|
// Put mY back to its original value since no clearing
|
1999-04-03 22:59:01 +04:00
|
|
|
// happened. That way the previous blocks bottom margin will
|
|
|
|
// be applied properly.
|
|
|
|
mY = saveY - mPrevBottomMargin;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return applyTopMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recover the collapsed vertical margin values for aLine. Note that
|
|
|
|
// the values are not collapsed with aState.mPrevBottomMargin, nor are
|
|
|
|
// they collapsed with each other when the line height is zero.
|
|
|
|
void
|
|
|
|
nsBlockReflowState::RecoverVerticalMargins(nsLineBox* aLine,
|
|
|
|
PRBool aApplyTopMargin,
|
|
|
|
nscoord* aTopMarginResult,
|
|
|
|
nscoord* aBottomMarginResult)
|
|
|
|
{
|
|
|
|
if (aLine->IsBlock()) {
|
|
|
|
// Update band data
|
|
|
|
GetAvailableSpace();
|
|
|
|
|
|
|
|
// Setup reflow state to compute the block childs top and bottom
|
|
|
|
// margins
|
|
|
|
nsIFrame* frame = aLine->mFirstChild;
|
1999-08-28 01:45:37 +04:00
|
|
|
nsRect availSpaceRect;
|
|
|
|
const nsStyleDisplay* display;
|
|
|
|
frame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&) display);
|
1999-04-03 22:59:01 +04:00
|
|
|
nsSplittableType splitType = NS_FRAME_NOT_SPLITTABLE;
|
|
|
|
frame->IsSplittable(splitType);
|
1999-08-28 01:45:37 +04:00
|
|
|
ComputeBlockAvailSpace(frame, splitType, display, availSpaceRect);
|
1999-04-03 22:59:01 +04:00
|
|
|
nsSize availSpace(availSpaceRect.width, availSpaceRect.height);
|
1999-11-24 09:03:41 +03:00
|
|
|
nsHTMLReflowState reflowState(mPresContext, mReflowState,
|
1999-04-03 22:59:01 +04:00
|
|
|
frame, availSpace);
|
|
|
|
|
|
|
|
// Compute collapsed top margin
|
|
|
|
nscoord topMargin = 0;
|
|
|
|
if (aApplyTopMargin) {
|
|
|
|
topMargin =
|
|
|
|
nsBlockReflowContext::ComputeCollapsedTopMargin(mPresContext,
|
|
|
|
reflowState);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute collapsed bottom margin
|
1999-07-20 07:41:03 +04:00
|
|
|
nscoord bottomMargin = reflowState.mComputedMargin.bottom;
|
1999-04-03 22:59:01 +04:00
|
|
|
bottomMargin =
|
|
|
|
nsBlockReflowContext::MaxMargin(bottomMargin,
|
1999-10-15 03:10:03 +04:00
|
|
|
aLine->GetCarriedOutBottomMargin());
|
1999-04-03 22:59:01 +04:00
|
|
|
*aTopMarginResult = topMargin;
|
|
|
|
*aBottomMarginResult = bottomMargin;
|
|
|
|
}
|
|
|
|
else {
|
2001-04-28 06:34:58 +04:00
|
|
|
// XXX_ib, see bug 44188
|
1999-04-03 22:59:01 +04:00
|
|
|
*aTopMarginResult = 0;
|
|
|
|
*aBottomMarginResult = 0;
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBlockReflowState::RecoverStateFrom(nsLineBox* aLine,
|
|
|
|
PRBool aApplyTopMargin,
|
1999-07-14 19:16:56 +04:00
|
|
|
nsRect* aDamageRect)
|
1999-04-03 22:59:01 +04:00
|
|
|
{
|
|
|
|
// Make the line being recovered the current line
|
|
|
|
mCurrentLine = aLine;
|
|
|
|
|
|
|
|
// Update aState.mPrevChild as if we had reflowed all of the frames
|
|
|
|
// in this line.
|
|
|
|
mPrevChild = aLine->LastChild();
|
|
|
|
|
1999-12-30 07:15:45 +03:00
|
|
|
// Recover mKidXMost and mMaxElementSize
|
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;
|
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
if (GetFlag(BRS_COMPUTEMAXELEMENTSIZE)) {
|
2000-05-14 08:56:25 +04:00
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsBlockReflowState::RecoverStateFrom block %p caching max width %d\n", mBlock, aLine->mMaxElementWidth);
|
2000-05-14 08:56:25 +04:00
|
|
|
#endif
|
1999-08-28 04:39:55 +04:00
|
|
|
UpdateMaxElementSize(nsSize(aLine->mMaxElementWidth, aLine->mBounds.height));
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
1999-04-03 22:59:01 +04:00
|
|
|
// The line may have clear before semantics.
|
1999-10-13 03:24:22 +04:00
|
|
|
if (aLine->IsBlock() && aLine->HasBreak()) {
|
1999-04-03 22:59:01 +04:00
|
|
|
// Clear past floaters before the block if the clear style is not none
|
1999-10-13 03:24:22 +04:00
|
|
|
aApplyTopMargin = ClearPastFloaters(aLine->GetBreakType());
|
1999-09-16 23:56:36 +04:00
|
|
|
#ifdef NOISY_VERTICAL_MARGINS
|
|
|
|
nsFrame::ListTag(stdout, mBlock);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": RecoverStateFrom: y=%d child ", mY);
|
1999-09-16 23:56:36 +04:00
|
|
|
nsFrame::ListTag(stdout, aLine->mFirstChild);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" has clear of %d => %s, mPrevBottomMargin=%d\n", aLine->mBreakType,
|
1999-09-16 23:56:36 +04:00
|
|
|
aApplyTopMargin ? "applyTopMargin" : "nope", mPrevBottomMargin);
|
|
|
|
#endif
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Recover mPrevBottomMargin and calculate the line's new Y
|
1999-04-04 01:54:00 +04:00
|
|
|
// coordinate (newLineY)
|
|
|
|
nscoord newLineY = mY;
|
1999-10-15 03:10:03 +04:00
|
|
|
nsRect lineCombinedArea;
|
|
|
|
aLine->GetCombinedArea(&lineCombinedArea);
|
1999-10-16 03:35:10 +04:00
|
|
|
if (aLine->IsBlock()) {
|
|
|
|
if ((0 == aLine->mBounds.height) && (0 == lineCombinedArea.height)) {
|
2000-06-30 02:03:42 +04:00
|
|
|
// The line's top and bottom margin values need to be collapsed
|
|
|
|
// with the mPrevBottomMargin to determine a new
|
|
|
|
// mPrevBottomMargin value.
|
|
|
|
nscoord topMargin, bottomMargin;
|
|
|
|
RecoverVerticalMargins(aLine, aApplyTopMargin,
|
|
|
|
&topMargin, &bottomMargin);
|
|
|
|
nscoord m = nsBlockReflowContext::MaxMargin(bottomMargin,
|
|
|
|
mPrevBottomMargin);
|
|
|
|
m = nsBlockReflowContext::MaxMargin(m, topMargin);
|
|
|
|
mPrevBottomMargin = m;
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-10-16 03:35:10 +04:00
|
|
|
// Recover the top and bottom margins for this line
|
1999-04-03 22:59:01 +04:00
|
|
|
nscoord topMargin, bottomMargin;
|
|
|
|
RecoverVerticalMargins(aLine, aApplyTopMargin,
|
|
|
|
&topMargin, &bottomMargin);
|
1999-10-16 03:35:10 +04:00
|
|
|
|
|
|
|
// Compute the collapsed top margin value
|
|
|
|
nscoord collapsedTopMargin =
|
|
|
|
nsBlockReflowContext::MaxMargin(topMargin, mPrevBottomMargin);
|
|
|
|
|
|
|
|
// The lineY is just below the collapsed top margin value. The
|
|
|
|
// mPrevBottomMargin gets set to the bottom margin value for the
|
|
|
|
// line.
|
|
|
|
newLineY += collapsedTopMargin;
|
|
|
|
mPrevBottomMargin = bottomMargin;
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-16 03:35:10 +04:00
|
|
|
else if (0 == aLine->GetHeight()) {
|
|
|
|
// For empty inline lines we leave the previous bottom margin
|
|
|
|
// alone so that it's collpased with the next line.
|
|
|
|
}
|
1999-04-03 22:59:01 +04:00
|
|
|
else {
|
1999-10-16 03:35:10 +04:00
|
|
|
// For non-empty inline lines the previous margin is applied
|
|
|
|
// before the line. Therefore apply it now and zero it out.
|
|
|
|
newLineY += mPrevBottomMargin;
|
|
|
|
mPrevBottomMargin = 0;
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
1999-09-15 04:28:10 +04:00
|
|
|
|
|
|
|
// Save away the old combined area for later
|
1999-10-15 03:10:03 +04:00
|
|
|
nsRect oldCombinedArea = lineCombinedArea;
|
1999-09-15 04:28:10 +04:00
|
|
|
|
|
|
|
// Slide the frames in the line by the computed delta. This also
|
|
|
|
// updates the lines Y coordinate and the combined area's Y
|
|
|
|
// coordinate.
|
1999-04-04 01:54:00 +04:00
|
|
|
nscoord finalDeltaY = newLineY - aLine->mBounds.y;
|
1999-09-16 23:56:36 +04:00
|
|
|
mBlock->SlideLine(*this, aLine, finalDeltaY);
|
2000-06-05 12:24:18 +04:00
|
|
|
// aLine has been slided, but...
|
|
|
|
// XXX it is not necessary to worry about the ascent of mBlock here, right?
|
|
|
|
// Indeed, depending on the status of the first line of mBlock, we can either have:
|
|
|
|
// case first line of mBlock is dirty : it will be reflowed by mBlock and so
|
|
|
|
// mBlock->mAscent will be recomputed by the block frame, and we will
|
|
|
|
// never enter into this RecoverStateFrom(aLine) function.
|
|
|
|
// case first line of mBlock is clean : it is untouched by the incremental reflow.
|
|
|
|
// In other words, aLine is never equals to mBlock->mLines in this function.
|
|
|
|
// so mBlock->mAscent will remain unchanged.
|
1999-04-03 22:59:01 +04:00
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
// Place floaters for this line into the space manager
|
1999-10-15 03:10:03 +04:00
|
|
|
if (aLine->HasFloaters()) {
|
1999-09-16 23:56:36 +04:00
|
|
|
// Undo border/padding translation since the nsFloaterCache's
|
|
|
|
// coordinates are relative to the frame not relative to the
|
|
|
|
// border/padding.
|
|
|
|
const nsMargin& bp = BorderPadding();
|
|
|
|
mSpaceManager->Translate(-bp.left, -bp.top);
|
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
// Place the floaters into the space-manager again. Also slide
|
|
|
|
// them, just like the regular frames on the line.
|
|
|
|
nsRect r;
|
1999-10-15 03:10:03 +04:00
|
|
|
nsFloaterCache* fc = aLine->GetFirstFloater();
|
1999-09-15 04:28:10 +04:00
|
|
|
while (fc) {
|
|
|
|
fc->mRegion.y += finalDeltaY;
|
|
|
|
fc->mCombinedArea.y += finalDeltaY;
|
|
|
|
nsIFrame* floater = fc->mPlaceholder->GetOutOfFlowFrame();
|
|
|
|
floater->GetRect(r);
|
1999-10-26 08:44:41 +04:00
|
|
|
floater->MoveTo(mPresContext, r.x, r.y + finalDeltaY);
|
1999-10-16 03:35:10 +04:00
|
|
|
#ifdef DEBUG
|
2001-05-01 08:22:57 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow || nsBlockFrame::gNoisySpaceManager) {
|
1999-10-16 03:35:10 +04:00
|
|
|
nscoord tx, ty;
|
|
|
|
mSpaceManager->GetTranslation(tx, ty);
|
2001-05-01 08:22:57 +04:00
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("RecoverState: txy=%d,%d (%d,%d) ",
|
1999-10-16 03:35:10 +04:00
|
|
|
tx, ty, mSpaceManagerX, mSpaceManagerY);
|
|
|
|
nsFrame::ListTag(stdout, floater);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" r.y=%d finalDeltaY=%d (sum=%d) region={%d,%d,%d,%d}\n",
|
1999-10-16 03:35:10 +04:00
|
|
|
r.y, finalDeltaY, r.y + finalDeltaY,
|
|
|
|
fc->mRegion.x, fc->mRegion.y,
|
|
|
|
fc->mRegion.width, fc->mRegion.height);
|
|
|
|
}
|
1999-09-15 04:28:10 +04:00
|
|
|
#endif
|
|
|
|
mSpaceManager->AddRectRegion(floater, fc->mRegion);
|
2001-05-22 03:03:46 +04:00
|
|
|
mLastFloaterY = fc->mRegion.y;
|
1999-09-15 04:28:10 +04:00
|
|
|
fc = fc->Next();
|
1999-04-03 22:59:01 +04: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
|
|
|
}
|
|
|
|
|
|
|
|
// Recover mY
|
|
|
|
mY = aLine->mBounds.YMost();
|
|
|
|
|
1999-07-14 19:16:56 +04:00
|
|
|
// Compute the damage area
|
|
|
|
if (aDamageRect) {
|
|
|
|
if (0 == finalDeltaY) {
|
|
|
|
aDamageRect->Empty();
|
|
|
|
} else {
|
1999-12-10 00:40:37 +03:00
|
|
|
aLine->GetCombinedArea(&lineCombinedArea);
|
1999-10-15 03:10:03 +04:00
|
|
|
aDamageRect->UnionRect(oldCombinedArea, lineCombinedArea);
|
1999-07-14 19:16:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-05 01:44:48 +04:00
|
|
|
// XXX Does this do anything? It doesn't seem to work.... (bug 29413)
|
1999-04-03 22:59:01 +04:00
|
|
|
// It's possible that the line has clear after semantics
|
1999-10-13 03:24:22 +04:00
|
|
|
if (!aLine->IsBlock() && aLine->HasBreak()) {
|
|
|
|
PRUint8 breakType = aLine->GetBreakType();
|
|
|
|
switch (breakType) {
|
1999-04-03 22:59:01 +04:00
|
|
|
case NS_STYLE_CLEAR_LEFT:
|
|
|
|
case NS_STYLE_CLEAR_RIGHT:
|
|
|
|
case NS_STYLE_CLEAR_LEFT_AND_RIGHT:
|
1999-10-13 03:24:22 +04:00
|
|
|
ClearFloaters(mY, breakType);
|
1999-04-03 22:59:01 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
nsBlockReflowState::IsImpactedByFloater() const
|
|
|
|
{
|
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
|
|
|
printf("nsBlockReflowState::IsImpactedByFloater %p returned %d\n",
|
|
|
|
this, mBand.GetFloaterCount());
|
|
|
|
#endif
|
|
|
|
return mBand.GetFloaterCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
void
|
1999-08-28 01:45:37 +04:00
|
|
|
nsBlockReflowState::InitFloater(nsLineLayout& aLineLayout,
|
|
|
|
nsPlaceholderFrame* aPlaceholder)
|
1998-09-23 06:25:26 +04:00
|
|
|
{
|
1998-12-15 07:20:54 +03:00
|
|
|
// Set the geometric parent of the floater
|
1999-04-23 18:34:48 +04:00
|
|
|
nsIFrame* floater = aPlaceholder->GetOutOfFlowFrame();
|
1999-01-14 08:16:23 +03:00
|
|
|
floater->SetParent(mBlock);
|
1998-10-10 02:58:25 +04:00
|
|
|
|
1998-12-15 07:20:54 +03:00
|
|
|
// Then add the floater to the current line and place it when
|
|
|
|
// appropriate
|
1999-08-28 01:45:37 +04:00
|
|
|
AddFloater(aLineLayout, aPlaceholder, PR_TRUE);
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-06-24 21:52:42 +04:00
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
// This is called by the line layout's AddFloater method when a
|
|
|
|
// place-holder frame is reflowed in a line. If the floater is a
|
|
|
|
// left-most child (it's x coordinate is at the line's left margin)
|
|
|
|
// then the floater is place immediately, otherwise the floater
|
|
|
|
// 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...
|
1998-12-05 19:02:08 +03:00
|
|
|
void
|
1999-08-28 01:45:37 +04:00
|
|
|
nsBlockReflowState::AddFloater(nsLineLayout& aLineLayout,
|
|
|
|
nsPlaceholderFrame* aPlaceholder,
|
1998-12-15 07:20:54 +03:00
|
|
|
PRBool aInitialReflow)
|
1998-12-05 19:02:08 +03:00
|
|
|
{
|
1999-03-23 07:28:20 +03:00
|
|
|
NS_PRECONDITION(nsnull != mCurrentLine, "null ptr");
|
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
// Allocate a nsFloaterCache for the floater
|
|
|
|
nsFloaterCache* fc = mFloaterCacheFreeList.Alloc();
|
|
|
|
fc->mPlaceholder = aPlaceholder;
|
|
|
|
fc->mIsCurrentLineFloater = aLineLayout.CanPlaceFloaterNow();
|
1998-09-23 06:25:26 +04:00
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
// Now place the floater immediately if possible. Otherwise stash it
|
|
|
|
// away in mPendingFloaters and place it later.
|
1999-09-15 04:28:10 +04:00
|
|
|
if (fc->mIsCurrentLineFloater) {
|
|
|
|
// Record this floater in the current-line list
|
|
|
|
mCurrentLineFloaters.Append(fc);
|
|
|
|
|
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
|
|
|
|
// before placing the floater.
|
|
|
|
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
|
1999-09-10 22:52:56 +04:00
|
|
|
PRBool isLeftFloater;
|
2001-05-22 03:03:46 +04:00
|
|
|
FlowAndPlaceFloater(fc, &isLeftFloater);
|
1998-10-03 01:50:53 +04:00
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
// Pass on updated available space to the current inline reflow engine
|
|
|
|
GetAvailableSpace();
|
1999-08-28 01:45:37 +04:00
|
|
|
aLineLayout.UpdateBand(mAvailSpaceRect.x + BorderPadding().left, mY,
|
2000-04-17 18:40:46 +04:00
|
|
|
GetFlag(BRS_UNCONSTRAINEDWIDTH) ? NS_UNCONSTRAINEDSIZE : mAvailSpaceRect.width,
|
1999-08-28 01:45:37 +04:00
|
|
|
mAvailSpaceRect.height,
|
1999-10-29 18:34:53 +04:00
|
|
|
isLeftFloater,
|
|
|
|
aPlaceholder->GetOutOfFlowFrame());
|
1998-10-03 01:50:53 +04:00
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
// Restore coordinate system
|
|
|
|
mSpaceManager->Translate(dx, dy);
|
1998-06-18 20:25:41 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
else {
|
|
|
|
// This floater will be placed after the line is done (it is a
|
1999-09-15 04:28:10 +04:00
|
|
|
// below-current-line floater).
|
|
|
|
mBelowCurrentLineFloaters.Append(fc);
|
1998-06-25 20:33:10 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-06-25 20:33:10 +04:00
|
|
|
|
2001-05-01 08:22:57 +04:00
|
|
|
void
|
|
|
|
nsBlockReflowState::UpdateMaxElementSize(const nsSize& aMaxElementSize)
|
|
|
|
{
|
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
|
|
|
nsSize oldSize = mMaxElementSize;
|
|
|
|
#endif
|
|
|
|
if (aMaxElementSize.width > mMaxElementSize.width) {
|
|
|
|
mMaxElementSize.width = aMaxElementSize.width;
|
|
|
|
}
|
|
|
|
if (aMaxElementSize.height > mMaxElementSize.height) {
|
|
|
|
mMaxElementSize.height = aMaxElementSize.height;
|
|
|
|
}
|
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
|
|
|
if ((mMaxElementSize.width != oldSize.width) ||
|
|
|
|
(mMaxElementSize.height != oldSize.height)) {
|
|
|
|
nsFrame::IndentBy(stdout, mBlock->GetDepth());
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == mReflowState.availableWidth) {
|
|
|
|
printf("PASS1 ");
|
|
|
|
}
|
|
|
|
nsFrame::ListTag(stdout, mBlock);
|
|
|
|
printf(": old max-element-size=%d,%d new=%d,%d\n",
|
|
|
|
oldSize.width, oldSize.height,
|
|
|
|
mMaxElementSize.width, mMaxElementSize.height);
|
|
|
|
}
|
|
|
|
#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
|
|
|
|
nsBlockReflowState::CanPlaceFloater(const nsRect& aFloaterRect,
|
|
|
|
PRUint8 aFloats)
|
|
|
|
{
|
|
|
|
// If the current Y coordinate is not impacted by any floaters
|
|
|
|
// then by definition the floater fits.
|
|
|
|
PRBool result = PR_TRUE;
|
1999-04-03 22:59:01 +04:00
|
|
|
if (0 != mBand.GetFloaterCount()) {
|
2001-07-19 06:33:43 +04:00
|
|
|
// XXX We should allow overflow by up to half a pixel here (bug 21193).
|
1999-03-31 08:10:27 +04:00
|
|
|
if (mAvailSpaceRect.width < aFloaterRect.width) {
|
|
|
|
// The available width is too narrow (and its been impacted by a
|
|
|
|
// prior floater)
|
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// At this point we know that there is enough horizontal space for
|
|
|
|
// the floater (somewhere). Lets see if there is enough vertical
|
|
|
|
// space.
|
|
|
|
if (mAvailSpaceRect.height < aFloaterRect.height) {
|
|
|
|
// The available height is too short. However, its possible that
|
|
|
|
// there is enough open space below which is not impacted by a
|
|
|
|
// floater.
|
|
|
|
//
|
|
|
|
// Compute the X coordinate for the floater based on its float
|
|
|
|
// type, assuming its placed on the current line. This is
|
|
|
|
// where the floater will be placed horizontally if it can go
|
|
|
|
// 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 {
|
1999-05-13 04:55:38 +04:00
|
|
|
xa = mAvailSpaceRect.XMost() - aFloaterRect.width;
|
1999-03-31 08:10:27 +04:00
|
|
|
|
|
|
|
// In case the floater is too big, don't go past the left edge
|
1999-05-13 04:55:38 +04:00
|
|
|
if (xa < mAvailSpaceRect.x) {
|
|
|
|
xa = mAvailSpaceRect.x;
|
1999-03-31 08:10:27 +04:00
|
|
|
}
|
|
|
|
}
|
1999-05-13 04:55:38 +04:00
|
|
|
nscoord xb = xa + aFloaterRect.width;
|
1999-03-31 08:10:27 +04:00
|
|
|
|
|
|
|
// Calculate the top and bottom y coordinates, again assuming
|
|
|
|
// that the floater is placed on the current line.
|
|
|
|
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
|
|
|
|
// means the margin edge of the floater can't be higher than the
|
|
|
|
// 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
|
|
|
}
|
1999-05-13 04:55:38 +04:00
|
|
|
nscoord yb = ya + aFloaterRect.height;
|
1999-03-31 08:10:27 +04:00
|
|
|
|
|
|
|
nscoord saveY = mY;
|
|
|
|
for (;;) {
|
|
|
|
// Get the available space at the new Y coordinate
|
|
|
|
mY += mAvailSpaceRect.height;
|
|
|
|
GetAvailableSpace();
|
|
|
|
|
1999-04-03 22:59:01 +04:00
|
|
|
if (0 == mBand.GetFloaterCount()) {
|
1999-03-31 08:10:27 +04:00
|
|
|
// Winner. This band has no floaters on it, therefore
|
|
|
|
// there can be no overlap.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check and make sure the floater won't intersect any
|
|
|
|
// floaters on this band. The floaters starting and ending
|
|
|
|
// coordinates must be entirely in the available space.
|
1999-05-13 04:55:38 +04:00
|
|
|
if ((xa < mAvailSpaceRect.x) || (xb > mAvailSpaceRect.XMost())) {
|
1999-03-31 08:10:27 +04:00
|
|
|
// The floater can't go here.
|
|
|
|
result = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if there is now enough height for the floater.
|
1999-05-13 04:55:38 +04:00
|
|
|
if (yb < mY + mAvailSpaceRect.height) {
|
1999-03-31 08:10:27 +04:00
|
|
|
// Winner. The bottom Y coordinate of the floater is in
|
|
|
|
// this band.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore Y coordinate and available space information
|
|
|
|
// regardless of the outcome.
|
|
|
|
mY = saveY;
|
|
|
|
GetAvailableSpace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
void
|
2001-05-22 03:03:46 +04:00
|
|
|
nsBlockReflowState::FlowAndPlaceFloater(nsFloaterCache* aFloaterCache,
|
|
|
|
PRBool* aIsLeftFloater)
|
1998-06-18 20:25:41 +04:00
|
|
|
{
|
1998-12-12 22:19:11 +03:00
|
|
|
// Save away the Y coordinate before placing the floater. We will
|
|
|
|
// restore mY at the end after placing the floater. This is
|
|
|
|
// necessary because any adjustments to mY during the floater
|
|
|
|
// placement are for the floater only, not for any non-floating
|
|
|
|
// content.
|
|
|
|
nscoord saveY = mY;
|
2001-05-22 03:03:46 +04:00
|
|
|
|
|
|
|
// Grab the compatibility mode
|
|
|
|
nsCompatibility mode;
|
|
|
|
mPresContext->GetCompatibilityMode(&mode);
|
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
nsIFrame* floater = aFloaterCache->mPlaceholder->GetOutOfFlowFrame();
|
1998-07-29 08:03:12 +04:00
|
|
|
|
2001-05-22 03:03:46 +04:00
|
|
|
// Grab the floater's display information
|
1998-12-05 19:02:08 +03:00
|
|
|
const nsStyleDisplay* floaterDisplay;
|
|
|
|
floater->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&)floaterDisplay);
|
|
|
|
|
2001-05-22 03:03:46 +04:00
|
|
|
// This will hold the floater's geometry when we've found a place
|
|
|
|
// for it to live.
|
1998-12-05 19:02:08 +03:00
|
|
|
nsRect region;
|
2001-05-22 03:03:46 +04:00
|
|
|
|
|
|
|
// Advance mY to mLastFloaterY (if it's not past it already) to
|
|
|
|
// enforce 9.5.1 rule [2]; i.e., make sure that a float isn't
|
|
|
|
// ``above'' another float that preceded it in the flow.
|
|
|
|
mY = NS_MAX(mLastFloaterY, mY);
|
|
|
|
|
2001-07-19 06:33:43 +04:00
|
|
|
// See if the floater should clear any preceeding floaters...
|
|
|
|
if (NS_STYLE_CLEAR_NONE != floaterDisplay->mBreakType) {
|
|
|
|
// XXXldb Does this handle vertical margins correctly?
|
|
|
|
ClearFloaters(mY, floaterDisplay->mBreakType);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Get the band of available space
|
|
|
|
GetAvailableSpace();
|
|
|
|
}
|
2001-05-22 03:03:46 +04:00
|
|
|
|
2001-07-19 06:33:43 +04:00
|
|
|
// Reflow the floater
|
|
|
|
mBlock->ReflowFloater(*this, aFloaterCache->mPlaceholder, aFloaterCache->mCombinedArea,
|
|
|
|
aFloaterCache->mMargins, aFloaterCache->mOffsets);
|
2001-05-22 03:03:46 +04:00
|
|
|
|
2001-07-19 06:33:43 +04:00
|
|
|
// Get the floaters bounding box and margin information
|
|
|
|
floater->GetRect(region);
|
2001-05-22 03:03:46 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2001-07-19 06:33:43 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
|
|
|
printf("flowed floater: ");
|
|
|
|
nsFrame::ListTag(stdout, floater);
|
|
|
|
printf(" (%d,%d,%d,%d)\n",
|
|
|
|
region.x, region.y, region.width, region.height);
|
|
|
|
}
|
2001-05-22 03:03:46 +04:00
|
|
|
#endif
|
|
|
|
|
2001-07-19 06:33:43 +04:00
|
|
|
// Adjust the floater size by its margin. That's the area that will
|
|
|
|
// impact the space manager.
|
|
|
|
region.width += aFloaterCache->mMargins.left + aFloaterCache->mMargins.right;
|
|
|
|
region.height += aFloaterCache->mMargins.top + aFloaterCache->mMargins.bottom;
|
|
|
|
|
|
|
|
// Find a place to place the floater. The CSS2 spec doesn't want
|
|
|
|
// floaters overlapping each other or sticking out of the containing
|
|
|
|
// block if possible (CSS2 spec section 9.5.1, see the rule list).
|
|
|
|
NS_ASSERTION((NS_STYLE_FLOAT_LEFT == floaterDisplay->mFloats) ||
|
|
|
|
(NS_STYLE_FLOAT_RIGHT == floaterDisplay->mFloats),
|
|
|
|
"invalid float type");
|
|
|
|
|
|
|
|
// In backwards compatibility mode, we don't bother to see if a
|
|
|
|
// floated table can ``really'' fit: in old browsers, floating
|
|
|
|
// tables are horizontally stacked regardless of available space.
|
|
|
|
// (See bug 43086 about tables vs. non-tables.)
|
|
|
|
if ((eCompatibility_NavQuirks != mode) ||
|
|
|
|
(NS_STYLE_DISPLAY_TABLE != floaterDisplay->mDisplay)) {
|
2001-05-22 03:03:46 +04:00
|
|
|
// Can the floater fit here?
|
2001-07-19 06:33:43 +04:00
|
|
|
while (! CanPlaceFloater(region, floaterDisplay->mFloats)) {
|
|
|
|
// Nope. Advance to the next band.
|
|
|
|
mY += mAvailSpaceRect.height;
|
|
|
|
GetAvailableSpace();
|
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-11-15 00:01:26 +03:00
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
// Assign an x and y coordinate to the floater. Note that the x,y
|
|
|
|
// 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.
|
1999-09-18 03:16:43 +04:00
|
|
|
PRBool okToAddRectRegion = PR_TRUE;
|
1999-10-15 03:10:03 +04:00
|
|
|
PRBool isLeftFloater;
|
1998-12-05 19:02:08 +03:00
|
|
|
if (NS_STYLE_FLOAT_LEFT == floaterDisplay->mFloats) {
|
1999-10-15 03:10:03 +04:00
|
|
|
isLeftFloater = PR_TRUE;
|
1998-12-09 00:43:15 +03:00
|
|
|
region.x = mAvailSpaceRect.x;
|
1998-06-28 02:56:09 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-10-15 03:10:03 +04:00
|
|
|
isLeftFloater = PR_FALSE;
|
2000-04-17 18:40:46 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != mAvailSpaceRect.XMost())
|
|
|
|
region.x = mAvailSpaceRect.XMost() - region.width;
|
|
|
|
else {
|
|
|
|
okToAddRectRegion = PR_FALSE;
|
|
|
|
region.x = mAvailSpaceRect.x;
|
|
|
|
}
|
1998-06-24 21:52:42 +04:00
|
|
|
}
|
1999-10-15 03:10:03 +04:00
|
|
|
*aIsLeftFloater = isLeftFloater;
|
1999-03-05 07:21:32 +03:00
|
|
|
const nsMargin& borderPadding = BorderPadding();
|
|
|
|
region.y = mY - borderPadding.top;
|
1998-12-05 19:02:08 +03:00
|
|
|
if (region.y < 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
|
|
|
|
// means the margin edge of the floater can't be higher than the
|
|
|
|
// content edge of the block that contains it.)
|
1998-12-05 19:02:08 +03:00
|
|
|
region.y = 0;
|
1998-06-28 02:56:09 +04:00
|
|
|
}
|
1998-06-18 20:25:41 +04:00
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
// Place the floater in the space manager
|
1999-09-18 03:16:43 +04:00
|
|
|
if (okToAddRectRegion) {
|
1999-10-29 18:34:53 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
2000-01-03 07:32:13 +03:00
|
|
|
mSpaceManager->AddRectRegion(floater, region);
|
1999-10-29 18:34:53 +04:00
|
|
|
NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "bad floater placement");
|
1999-09-18 03:16:43 +04:00
|
|
|
}
|
1998-11-05 22:33:01 +03:00
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
// Save away the floaters region in the spacemanager, after making
|
|
|
|
// it relative to the containing block's frame instead of relative
|
|
|
|
// to the spacemanager translation (which is inset by the
|
|
|
|
// border+padding).
|
|
|
|
aFloaterCache->mRegion.x = region.x + borderPadding.left;
|
|
|
|
aFloaterCache->mRegion.y = region.y + borderPadding.top;
|
|
|
|
aFloaterCache->mRegion.width = region.width;
|
|
|
|
aFloaterCache->mRegion.height = region.height;
|
|
|
|
#ifdef NOISY_SPACEMANAGER
|
|
|
|
nscoord tx, ty;
|
|
|
|
mSpaceManager->GetTranslation(tx, ty);
|
|
|
|
nsFrame::ListTag(stdout, mBlock);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": PlaceFloater: AddRectRegion: txy=%d,%d (%d,%d) {%d,%d,%d,%d}\n",
|
1999-09-15 04:28:10 +04:00
|
|
|
tx, ty, mSpaceManagerX, mSpaceManagerY,
|
1999-09-16 23:56:36 +04:00
|
|
|
aFloaterCache->mRegion.x, aFloaterCache->mRegion.y,
|
|
|
|
aFloaterCache->mRegion.width, aFloaterCache->mRegion.height);
|
1999-09-15 04:28:10 +04:00
|
|
|
#endif
|
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
// Set the origin of the floater frame, in frame coordinates. These
|
|
|
|
// coordinates are <b>not</b> relative to the spacemanager
|
|
|
|
// translation, therefore we have to factor in our border/padding.
|
1999-09-15 04:28:10 +04:00
|
|
|
nscoord x = borderPadding.left + aFloaterCache->mMargins.left + region.x;
|
|
|
|
nscoord y = borderPadding.top + aFloaterCache->mMargins.top + region.y;
|
1999-07-14 21:26:20 +04:00
|
|
|
|
|
|
|
// If floater 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?
|
2001-06-01 02:19:43 +04:00
|
|
|
if (NS_STYLE_POSITION_RELATIVE == floaterDisplay->mPosition) {
|
1999-09-15 04:28:10 +04:00
|
|
|
x += aFloaterCache->mOffsets.left;
|
|
|
|
y += aFloaterCache->mOffsets.top;
|
1999-07-14 21:26:20 +04:00
|
|
|
}
|
1999-11-30 08:09:08 +03:00
|
|
|
|
|
|
|
// Position the floater and make sure and views are properly positioned
|
1999-10-26 08:44:41 +04:00
|
|
|
floater->MoveTo(mPresContext, x, y);
|
2001-09-06 00:27:19 +04:00
|
|
|
nsContainerFrame::PositionFrameView(mPresContext, floater);
|
1999-10-15 03:10:03 +04:00
|
|
|
|
|
|
|
// Update the floater combined area state
|
|
|
|
nsRect combinedArea = aFloaterCache->mCombinedArea;
|
|
|
|
combinedArea.x += x;
|
|
|
|
combinedArea.y += y;
|
2000-04-17 18:40:46 +04:00
|
|
|
if (!isLeftFloater &&
|
|
|
|
(GetFlag(BRS_UNCONSTRAINEDWIDTH) || GetFlag(BRS_SHRINKWRAPWIDTH))) {
|
2000-01-03 07:32:13 +03:00
|
|
|
// When we are placing a right floater in an unconstrained situation or
|
|
|
|
// when shrink wrapping, we don't apply it to the floater combined area
|
|
|
|
// immediately. Otherwise we end up with an infinitely wide combined
|
|
|
|
// area. Instead, we save it away in mRightFloaterCombinedArea so that
|
|
|
|
// later on when we know the width of a line we can compute a better value.
|
1999-10-15 03:10:03 +04:00
|
|
|
if (!mHaveRightFloaters) {
|
|
|
|
mRightFloaterCombinedArea = combinedArea;
|
|
|
|
mHaveRightFloaters = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
2001-05-01 08:22:57 +04:00
|
|
|
nsBlockFrame::CombineRects(combinedArea, mRightFloaterCombinedArea);
|
1999-10-15 03:10:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-05-01 08:22:57 +04:00
|
|
|
nsBlockFrame::CombineRects(combinedArea, mFloaterCombinedArea);
|
1999-03-24 18:42:19 +03:00
|
|
|
}
|
1998-12-12 22:19:11 +03:00
|
|
|
|
2001-05-22 03:03:46 +04:00
|
|
|
// Remember the y-coordinate of the floater we've just placed
|
|
|
|
mLastFloaterY = mY;
|
|
|
|
|
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) {
|
1998-12-05 19:02:08 +03:00
|
|
|
nsRect r;
|
|
|
|
floater->GetRect(r);
|
2001-05-01 08:22:57 +04:00
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("placed floater: ");
|
2001-05-22 03:03:46 +04:00
|
|
|
nsFrame::ListTag(stdout, floater);
|
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
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-11-05 22:33:01 +03:00
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
/**
|
|
|
|
* Place below-current-line floaters.
|
|
|
|
*/
|
|
|
|
void
|
1999-09-15 04:28:10 +04:00
|
|
|
nsBlockReflowState::PlaceBelowCurrentLineFloaters(nsFloaterCacheList& aList)
|
1998-12-05 19:02:08 +03:00
|
|
|
{
|
1999-09-15 04:28:10 +04:00
|
|
|
nsFloaterCache* fc = aList.Head();
|
|
|
|
while (fc) {
|
|
|
|
if (!fc->mIsCurrentLineFloater) {
|
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);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("placing bcl floater: ");
|
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
|
|
|
|
1999-09-15 04:28:10 +04:00
|
|
|
// Place the floater
|
1999-04-01 05:37:36 +04:00
|
|
|
PRBool isLeftFloater;
|
2001-05-22 03:03:46 +04:00
|
|
|
FlowAndPlaceFloater(fc, &isLeftFloater);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
void
|
|
|
|
nsBlockReflowState::ClearFloaters(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);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("clear floaters: in: mY=%d aY=%d(%d)\n",
|
1999-10-16 03:35:10 +04:00
|
|
|
mY, aY, aY - BorderPadding().top);
|
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
#endif
|
1998-10-27 19:51:02 +03:00
|
|
|
|
1999-09-16 23:56:36 +04:00
|
|
|
#ifdef NOISY_FLOATER_CLEARING
|
2001-05-01 08:22:57 +04:00
|
|
|
printf("nsBlockReflowState::ClearFloaters: aY=%d breakType=%d\n",
|
1999-09-16 23:56:36 +04:00
|
|
|
aY, aBreakType);
|
|
|
|
mSpaceManager->List(stdout);
|
|
|
|
#endif
|
1999-03-05 07:21:32 +03:00
|
|
|
const nsMargin& bp = BorderPadding();
|
1999-04-03 22:59:01 +04:00
|
|
|
nscoord newY = mBand.ClearFloaters(aY - bp.top, aBreakType);
|
1999-03-05 07:21:32 +03:00
|
|
|
mY = newY + bp.top;
|
1998-12-05 19:02:08 +03:00
|
|
|
GetAvailableSpace();
|
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);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("clear floaters: out: mY=%d(%d)\n", mY, mY - bp.top);
|
1999-10-16 03:35:10 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
#endif
|
|
|
|
}
|
2001-05-01 08:22:57 +04:00
|
|
|
|