2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-10-25 01:08:40 +00:00
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2001-09-28 20:14:13 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-12-01 16:13:49 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00: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-12-01 16:13:49 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00: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-12-01 16:13:49 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
2003-01-01 23:53:20 +00:00
|
|
|
* David Baron <dbaron@dbaron.org>
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00: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-28 20:14:13 +00: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 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00: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 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-12-01 16:13:49 +00:00
|
|
|
#include "nsBlockReflowContext.h"
|
|
|
|
#include "nsLineLayout.h"
|
2001-10-26 05:06:07 +00:00
|
|
|
#include "nsSpaceManager.h"
|
1998-12-01 16:13:49 +00:00
|
|
|
#include "nsIFontMetrics.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2004-02-23 21:29:06 +00:00
|
|
|
#include "nsFrameManager.h"
|
1999-04-13 01:15:16 +00:00
|
|
|
#include "nsIContent.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
2001-12-17 22:39:59 +00:00
|
|
|
#include "nsHTMLReflowCommand.h"
|
1998-12-01 16:13:49 +00:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
1999-03-27 01:22:45 +00:00
|
|
|
#include "nsBlockFrame.h"
|
2002-11-28 19:29:28 +00:00
|
|
|
#include "nsLineBox.h"
|
2000-06-14 23:15:59 +00:00
|
|
|
#include "nsIDOMHTMLTableCellElement.h"
|
|
|
|
#include "nsIDOMHTMLBodyElement.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
1999-07-14 17:27:24 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2004-11-25 14:51:00 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
1998-12-01 16:13:49 +00:00
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
#ifdef NS_DEBUG
|
1999-03-20 19:38:50 +00:00
|
|
|
#undef NOISY_MAX_ELEMENT_SIZE
|
1999-03-24 15:42:38 +00:00
|
|
|
#undef REALLY_NOISY_MAX_ELEMENT_SIZE
|
1999-03-27 01:22:45 +00:00
|
|
|
#undef NOISY_VERTICAL_MARGINS
|
1999-02-12 17:45:58 +00:00
|
|
|
#else
|
1999-03-20 19:38:50 +00:00
|
|
|
#undef NOISY_MAX_ELEMENT_SIZE
|
1999-03-24 15:42:38 +00:00
|
|
|
#undef REALLY_NOISY_MAX_ELEMENT_SIZE
|
1999-03-27 01:22:45 +00:00
|
|
|
#undef NOISY_VERTICAL_MARGINS
|
1999-02-12 17:45:58 +00:00
|
|
|
#endif
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
nsBlockReflowContext::nsBlockReflowContext(nsPresContext* aPresContext,
|
1999-03-05 04:22:11 +00:00
|
|
|
const nsHTMLReflowState& aParentRS,
|
2003-01-09 14:26:32 +00:00
|
|
|
PRBool aComputeMaxElementWidth,
|
1999-12-30 04:15:45 +00:00
|
|
|
PRBool aComputeMaximumWidth)
|
1998-12-01 16:13:49 +00:00
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mOuterReflowState(aParentRS),
|
2003-01-09 14:26:32 +00:00
|
|
|
mMetrics(aComputeMaxElementWidth),
|
2003-07-15 00:04:43 +00:00
|
|
|
mComputeMaximumWidth(aComputeMaximumWidth)
|
1998-12-01 16:13:49 +00:00
|
|
|
{
|
2001-02-07 09:57:26 +00:00
|
|
|
mStyleBorder = nsnull;
|
|
|
|
mStyleMargin = nsnull;
|
|
|
|
mStylePadding = nsnull;
|
2000-05-14 04:56:25 +00:00
|
|
|
if (mComputeMaximumWidth)
|
|
|
|
mMetrics.mFlags |= NS_REFLOW_CALC_MAX_WIDTH;
|
1999-03-27 01:22:45 +00:00
|
|
|
}
|
|
|
|
|
2005-08-02 20:05:52 +00:00
|
|
|
static nsIFrame* DescendIntoBlockLevelFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIAtom* type = aFrame->GetType();
|
|
|
|
if (type == nsLayoutAtoms::columnSetFrame)
|
|
|
|
return DescendIntoBlockLevelFrame(aFrame->GetFirstChild(nsnull));
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
2004-11-25 14:51:00 +00:00
|
|
|
PRBool
|
|
|
|
nsBlockReflowContext::ComputeCollapsedTopMargin(const nsHTMLReflowState& aRS,
|
2006-02-27 04:15:05 +00:00
|
|
|
nsCollapsingMargin* aMargin, nsIFrame* aClearanceFrame,
|
|
|
|
PRBool* aMayNeedRetry, PRBool* aBlockIsEmpty)
|
1999-03-27 01:22:45 +00:00
|
|
|
{
|
2004-11-25 14:51:00 +00:00
|
|
|
// Include frame's top margin
|
|
|
|
aMargin->Include(aRS.mComputedMargin.top);
|
2001-10-25 01:08:40 +00:00
|
|
|
|
2002-11-28 19:29:28 +00:00
|
|
|
// The inclusion of the bottom margin when empty is done by the caller
|
|
|
|
// since it doesn't need to be done by the top-level (non-recursive)
|
|
|
|
// caller.
|
|
|
|
|
2001-10-25 01:08:40 +00:00
|
|
|
#ifdef NOISY_VERTICAL_MARGINS
|
|
|
|
nsFrame::ListTag(stdout, aRS.frame);
|
2004-11-25 14:51:00 +00:00
|
|
|
printf(": %d => %d\n", aRS.mComputedMargin.top, aMargin->get());
|
2001-10-25 01:08:40 +00:00
|
|
|
#endif
|
1999-03-27 01:22:45 +00:00
|
|
|
|
2004-11-25 14:51:00 +00:00
|
|
|
PRBool dirtiedLine = PR_FALSE;
|
2006-02-27 04:15:05 +00:00
|
|
|
PRBool setBlockIsEmpty = PR_FALSE;
|
2004-11-25 14:51:00 +00:00
|
|
|
|
|
|
|
// Calculate the frame's generational top-margin from its child
|
|
|
|
// blocks. Note that if the frame has a non-zero top-border or
|
1999-03-27 01:22:45 +00:00
|
|
|
// top-padding then this step is skipped because it will be a margin
|
2000-06-29 22:03:42 +00:00
|
|
|
// root. It is also skipped if the frame is a margin root for other
|
|
|
|
// reasons.
|
2004-11-25 14:51:00 +00:00
|
|
|
void* bf;
|
2005-08-02 20:05:52 +00:00
|
|
|
nsIFrame* frame = DescendIntoBlockLevelFrame(aRS.frame);
|
|
|
|
nsPresContext* prescontext = frame->GetPresContext();
|
2002-11-28 19:29:28 +00:00
|
|
|
if (0 == aRS.mComputedBorderPadding.top &&
|
2005-08-02 20:05:52 +00:00
|
|
|
!(frame->GetStateBits() & NS_BLOCK_MARGIN_ROOT) &&
|
|
|
|
NS_SUCCEEDED(frame->QueryInterface(kBlockFrameCID, &bf))) {
|
2005-03-23 03:35:08 +00:00
|
|
|
// iterate not just through the lines of 'block' but also its
|
|
|
|
// overflow lines and the normal and overflow lines of its next in
|
|
|
|
// flows. Note that this will traverse some frames more than once:
|
|
|
|
// for example, if A contains B and A->nextinflow contains
|
|
|
|
// B->nextinflow, we'll traverse B->nextinflow twice. But this is
|
|
|
|
// OK because our traversal is idempotent.
|
2005-08-02 20:05:52 +00:00
|
|
|
for (nsBlockFrame* block = NS_STATIC_CAST(nsBlockFrame*, frame);
|
2005-03-23 03:35:08 +00:00
|
|
|
block; block = NS_STATIC_CAST(nsBlockFrame*, block->GetNextInFlow())) {
|
|
|
|
for (PRBool overflowLines = PR_FALSE; overflowLines <= PR_TRUE; ++overflowLines) {
|
|
|
|
nsBlockFrame::line_iterator line;
|
|
|
|
nsBlockFrame::line_iterator line_end;
|
|
|
|
PRBool anyLines = PR_TRUE;
|
|
|
|
if (overflowLines) {
|
|
|
|
nsLineList* lines = block->GetOverflowLines();
|
|
|
|
if (!lines) {
|
|
|
|
anyLines = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
line = lines->begin();
|
|
|
|
line_end = lines->end();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
line = block->begin_lines();
|
|
|
|
line_end = block->end_lines();
|
2004-11-25 14:51:00 +00:00
|
|
|
}
|
2005-03-23 03:35:08 +00:00
|
|
|
for (; anyLines && line != line_end; ++line) {
|
|
|
|
if (!aClearanceFrame && line->HasClearance()) {
|
|
|
|
// If we don't have a clearance frame, then we're computing
|
|
|
|
// the collapsed margin in the first pass, assuming that all
|
|
|
|
// lines have no clearance. So clear their clearance flags.
|
|
|
|
line->ClearHasClearance();
|
|
|
|
line->MarkDirty();
|
|
|
|
dirtiedLine = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-02-27 04:15:05 +00:00
|
|
|
PRBool isEmpty;
|
|
|
|
if (line->IsInline()) {
|
|
|
|
isEmpty = line->IsEmpty();
|
|
|
|
} else {
|
2005-08-02 20:05:52 +00:00
|
|
|
nsIFrame* kid = line->mFirstChild;
|
|
|
|
if (kid == aClearanceFrame) {
|
2005-03-23 03:35:08 +00:00
|
|
|
line->SetHasClearance();
|
|
|
|
line->MarkDirty();
|
|
|
|
dirtiedLine = PR_TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
// Here is where we recur. Now that we have determined that a
|
|
|
|
// generational collapse is required we need to compute the
|
|
|
|
// child blocks margin and so in so that we can look into
|
|
|
|
// it. For its margins to be computed we need to have a reflow
|
|
|
|
// state for it. Since the reflow reason is irrelevant, we'll
|
|
|
|
// arbitrarily make it a `resize' to avoid the path-plucking
|
|
|
|
// behavior if we're in an incremental reflow.
|
2005-08-02 20:05:52 +00:00
|
|
|
|
|
|
|
// We may have to construct an extra reflow state here if
|
|
|
|
// we drilled down through a block wrapper. At the moment
|
|
|
|
// we can only drill down one level so we only have to support
|
|
|
|
// one extra reflow state.
|
|
|
|
const nsHTMLReflowState* outerReflowState = &aRS;
|
|
|
|
if (frame != aRS.frame) {
|
|
|
|
NS_ASSERTION(frame->GetParent() == aRS.frame,
|
|
|
|
"Can only drill through one level of block wrapper");
|
|
|
|
nsSize availSpace(aRS.mComputedWidth, aRS.mComputedHeight);
|
|
|
|
outerReflowState = new nsHTMLReflowState(prescontext,
|
|
|
|
aRS, frame,
|
|
|
|
availSpace, eReflowReason_Resize);
|
|
|
|
if (!outerReflowState)
|
|
|
|
goto done;
|
2005-03-23 03:35:08 +00:00
|
|
|
}
|
2005-08-02 20:05:52 +00:00
|
|
|
{
|
|
|
|
nsSize availSpace(outerReflowState->mComputedWidth,
|
|
|
|
outerReflowState->mComputedHeight);
|
|
|
|
nsHTMLReflowState innerReflowState(prescontext,
|
|
|
|
*outerReflowState, kid,
|
|
|
|
availSpace, eReflowReason_Resize);
|
|
|
|
// Record that we're being optimistic by assuming the kid
|
|
|
|
// has no clearance
|
|
|
|
if (kid->GetStyleDisplay()->mBreakType != NS_STYLE_CLEAR_NONE) {
|
|
|
|
*aMayNeedRetry = PR_TRUE;
|
|
|
|
}
|
2006-02-27 04:15:05 +00:00
|
|
|
if (ComputeCollapsedTopMargin(innerReflowState, aMargin, aClearanceFrame, aMayNeedRetry, &isEmpty)) {
|
2005-08-02 20:05:52 +00:00
|
|
|
line->MarkDirty();
|
|
|
|
dirtiedLine = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (isEmpty)
|
|
|
|
aMargin->Include(innerReflowState.mComputedMargin.bottom);
|
|
|
|
}
|
|
|
|
if (outerReflowState != &aRS) {
|
|
|
|
delete NS_CONST_CAST(nsHTMLReflowState*, outerReflowState);
|
2005-03-23 03:35:08 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-27 04:15:05 +00:00
|
|
|
if (!isEmpty) {
|
|
|
|
if (!setBlockIsEmpty && aBlockIsEmpty) {
|
|
|
|
setBlockIsEmpty = PR_TRUE;
|
|
|
|
*aBlockIsEmpty = PR_FALSE;
|
|
|
|
}
|
2005-03-23 03:35:08 +00:00
|
|
|
goto done;
|
2006-02-27 04:15:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!setBlockIsEmpty && aBlockIsEmpty) {
|
|
|
|
// The first time we reach here is when this is the first block
|
|
|
|
// and we have processed all its normal lines.
|
|
|
|
setBlockIsEmpty = PR_TRUE;
|
|
|
|
// All lines are empty, or we wouldn't be here!
|
|
|
|
*aBlockIsEmpty = aRS.frame->IsSelfEmpty();
|
2004-11-25 14:51:00 +00:00
|
|
|
}
|
1999-03-27 01:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-23 03:35:08 +00:00
|
|
|
done:
|
|
|
|
;
|
1999-03-27 01:22:45 +00:00
|
|
|
}
|
2006-02-27 04:15:05 +00:00
|
|
|
|
|
|
|
if (!setBlockIsEmpty && aBlockIsEmpty) {
|
|
|
|
*aBlockIsEmpty = aRS.frame->IsEmpty();
|
|
|
|
}
|
2004-11-25 14:51:00 +00:00
|
|
|
|
1999-03-27 01:22:45 +00:00
|
|
|
#ifdef NOISY_VERTICAL_MARGINS
|
|
|
|
nsFrame::ListTag(stdout, aRS.frame);
|
2005-01-27 20:54:27 +00:00
|
|
|
printf(": => %d\n", aMargin->get());
|
1999-03-27 01:22:45 +00:00
|
|
|
#endif
|
2004-11-25 14:51:00 +00:00
|
|
|
|
|
|
|
return dirtiedLine;
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2000-01-26 01:45:47 +00:00
|
|
|
struct nsBlockHorizontalAlign {
|
|
|
|
nscoord mXOffset; // left edge
|
|
|
|
nscoord mLeftMargin;
|
|
|
|
nscoord mRightMargin;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Given the width of the block frame and a suggested x-offset calculate
|
|
|
|
// the actual x-offset taking into account horizontal alignment. Also returns
|
|
|
|
// the actual left and right margin
|
|
|
|
void
|
|
|
|
nsBlockReflowContext::AlignBlockHorizontally(nscoord aWidth,
|
|
|
|
nsBlockHorizontalAlign &aAlign)
|
|
|
|
{
|
|
|
|
// Initialize OUT parameters
|
|
|
|
aAlign.mLeftMargin = mMargin.left;
|
|
|
|
aAlign.mRightMargin = mMargin.right;
|
|
|
|
|
|
|
|
// Get style unit associated with the left and right margins
|
2001-02-07 09:57:26 +00:00
|
|
|
nsStyleUnit leftUnit = mStyleMargin->mMargin.GetLeftUnit();
|
|
|
|
nsStyleUnit rightUnit = mStyleMargin->mMargin.GetRightUnit();
|
2000-01-26 01:45:47 +00:00
|
|
|
|
|
|
|
// Apply post-reflow horizontal alignment. When a block element
|
|
|
|
// doesn't use it all of the available width then we need to
|
|
|
|
// align it using the text-align property.
|
2004-02-09 05:22:23 +00:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != mSpace.width &&
|
|
|
|
NS_UNCONSTRAINEDSIZE != mOuterReflowState.mComputedWidth) {
|
2000-01-26 01:45:47 +00:00
|
|
|
// It is possible that the object reflowed was given a
|
|
|
|
// constrained width and ended up picking a different width
|
|
|
|
// (e.g. a table width a set width that ended up larger
|
|
|
|
// because its contents required it). When this happens we
|
|
|
|
// need to recompute auto margins because the reflow state's
|
|
|
|
// computations are no longer valid.
|
|
|
|
if (aWidth != mComputedWidth) {
|
|
|
|
if (eStyleUnit_Auto == leftUnit) {
|
2001-11-28 01:17:51 +00:00
|
|
|
aAlign.mXOffset = mSpace.x;
|
2000-01-26 01:45:47 +00:00
|
|
|
aAlign.mLeftMargin = 0;
|
|
|
|
}
|
|
|
|
if (eStyleUnit_Auto == rightUnit) {
|
|
|
|
aAlign.mRightMargin = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute how much remaining space there is, and in special
|
|
|
|
// cases apply it (normally we should get zero here because of
|
|
|
|
// the logic in nsHTMLReflowState).
|
|
|
|
nscoord remainingSpace = mSpace.XMost() - (aAlign.mXOffset + aWidth +
|
|
|
|
aAlign.mRightMargin);
|
|
|
|
if (remainingSpace > 0) {
|
|
|
|
// The block/table frame didn't use all of the available
|
|
|
|
// space. Synthesize margins for its horizontal placement.
|
|
|
|
if (eStyleUnit_Auto == leftUnit) {
|
|
|
|
if (eStyleUnit_Auto == rightUnit) {
|
|
|
|
// When both margins are auto, we center the block
|
|
|
|
aAlign.mXOffset += remainingSpace / 2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// When the left margin is auto we right align the block
|
|
|
|
aAlign.mXOffset += remainingSpace;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eStyleUnit_Auto != rightUnit) {
|
|
|
|
// The block/table doesn't have auto margins.
|
2000-07-27 23:37:44 +00:00
|
|
|
|
|
|
|
// For normal (non-table) blocks we don't get here because
|
|
|
|
// nsHTMLReflowState::CalculateBlockSideMargins handles this.
|
|
|
|
// (I think there may be an exception to that, though...)
|
|
|
|
|
|
|
|
// We use a special value of the text-align property for
|
|
|
|
// HTML alignment (the CENTER element and DIV ALIGN=...)
|
|
|
|
// since it acts on blocks and tables rather than just
|
|
|
|
// being a text-align.
|
|
|
|
// So, check the text-align value from the parent to see if
|
|
|
|
// it has one of these special values.
|
|
|
|
const nsStyleText* styleText = mOuterReflowState.mStyleText;
|
|
|
|
if (styleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT) {
|
|
|
|
aAlign.mXOffset += remainingSpace;
|
|
|
|
} else if (styleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) {
|
|
|
|
aAlign.mXOffset += remainingSpace / 2;
|
2005-06-15 23:45:06 +00:00
|
|
|
} else if (styleText->mTextAlign != NS_STYLE_TEXT_ALIGN_MOZ_LEFT) {
|
2000-07-27 23:37:44 +00:00
|
|
|
// If we don't have a special text-align value indicating
|
|
|
|
// HTML alignment, then use the CSS rules.
|
|
|
|
|
2000-01-26 01:45:47 +00:00
|
|
|
// When neither margin is auto then the block is said to
|
|
|
|
// be over constrained, Depending on the direction, choose
|
|
|
|
// which margin to treat as auto.
|
2001-05-31 22:19:43 +00:00
|
|
|
PRUint8 direction = mOuterReflowState.mStyleVisibility->mDirection;
|
2000-01-26 01:45:47 +00:00
|
|
|
if (NS_STYLE_DIRECTION_RTL == direction) {
|
|
|
|
// The left margin becomes auto
|
|
|
|
aAlign.mXOffset += remainingSpace;
|
|
|
|
}
|
2000-07-27 23:37:44 +00:00
|
|
|
//else {
|
2000-01-26 01:45:47 +00:00
|
|
|
// The right margin becomes auto which is a no-op
|
2000-07-27 23:37:44 +00:00
|
|
|
//}
|
2000-01-26 01:45:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-11 20:08:15 +00:00
|
|
|
static void
|
2004-01-27 06:46:33 +00:00
|
|
|
ComputeShrinkwrapMargins(const nsStyleMargin* aStyleMargin, nscoord aWidth,
|
|
|
|
nsMargin& aMargin, nscoord& aXToUpdate)
|
|
|
|
{
|
2000-08-11 20:08:15 +00:00
|
|
|
nscoord boxWidth = aWidth;
|
2004-01-27 06:46:33 +00:00
|
|
|
float leftPct = 0.0, rightPct = 0.0;
|
|
|
|
const nsStyleSides& margin = aStyleMargin->mMargin;
|
2000-08-11 20:08:15 +00:00
|
|
|
|
2004-01-27 06:46:33 +00:00
|
|
|
if (eStyleUnit_Percent == margin.GetLeftUnit()) {
|
|
|
|
nsStyleCoord coord;
|
|
|
|
leftPct = margin.GetLeft(coord).GetPercentValue();
|
2000-08-11 20:08:15 +00:00
|
|
|
} else {
|
|
|
|
boxWidth += aMargin.left;
|
|
|
|
}
|
|
|
|
|
2004-01-27 06:46:33 +00:00
|
|
|
if (eStyleUnit_Percent == margin.GetRightUnit()) {
|
|
|
|
nsStyleCoord coord;
|
|
|
|
rightPct = margin.GetRight(coord).GetPercentValue();
|
2000-08-11 20:08:15 +00:00
|
|
|
} else {
|
|
|
|
boxWidth += aMargin.right;
|
|
|
|
}
|
|
|
|
|
2004-01-27 06:46:33 +00:00
|
|
|
// The total shrink wrap width "sww" (i.e., the width that the
|
|
|
|
// containing block needs to be to shrink-wrap this block) is
|
|
|
|
// calculated by the expression:
|
2000-08-11 20:08:15 +00:00
|
|
|
// sww = bw + (mp * sww)
|
2004-01-27 06:46:33 +00:00
|
|
|
// where "bw" is the box width (frame width plus margins that aren't
|
|
|
|
// percentage based) and "mp" are the total margin percentages (i.e.,
|
|
|
|
// the left percentage value plus the right percentage value).
|
|
|
|
// Solving for "sww" gives:
|
2000-08-11 20:08:15 +00:00
|
|
|
// sww = bw / (1 - mp)
|
2004-01-27 06:46:33 +00:00
|
|
|
// Note that this is only well defined for "mp" less than 100% and
|
|
|
|
// greater than -100% (XXXldb but we only accept 0 to 100%).
|
2001-07-04 02:00:05 +00:00
|
|
|
|
2000-08-11 20:08:15 +00:00
|
|
|
float marginPct = leftPct + rightPct;
|
|
|
|
if (marginPct >= 1.0) {
|
|
|
|
// Ignore the right percentage and just use the left percentage
|
|
|
|
// XXX Pay attention to direction property...
|
|
|
|
marginPct = leftPct;
|
|
|
|
rightPct = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((marginPct > 0.0) && (marginPct < 1.0)) {
|
|
|
|
double shrinkWrapWidth = float(boxWidth) / (1.0 - marginPct);
|
|
|
|
|
2004-01-27 06:46:33 +00:00
|
|
|
if (eStyleUnit_Percent == margin.GetLeftUnit()) {
|
2000-08-11 20:08:15 +00:00
|
|
|
aMargin.left = NSToCoordFloor((float)(shrinkWrapWidth * leftPct));
|
|
|
|
aXToUpdate += aMargin.left;
|
|
|
|
}
|
2004-01-27 06:46:33 +00:00
|
|
|
if (eStyleUnit_Percent == margin.GetRightUnit()) {
|
2000-08-11 20:08:15 +00:00
|
|
|
aMargin.right = NSToCoordFloor((float)(shrinkWrapWidth * rightPct));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-11 04:29:09 +00:00
|
|
|
static void
|
2004-08-24 18:50:29 +00:00
|
|
|
nsPointDtor(void *aFrame, nsIAtom *aPropertyName,
|
|
|
|
void *aPropertyValue, void *aDtorData)
|
2004-01-11 04:29:09 +00:00
|
|
|
{
|
|
|
|
nsPoint *point = NS_STATIC_CAST(nsPoint*, aPropertyValue);
|
|
|
|
delete point;
|
|
|
|
}
|
|
|
|
|
2000-06-20 03:47:49 +00:00
|
|
|
nsresult
|
2002-09-04 06:55:40 +00:00
|
|
|
nsBlockReflowContext::ReflowBlock(const nsRect& aSpace,
|
|
|
|
PRBool aApplyTopMargin,
|
2004-11-25 14:51:00 +00:00
|
|
|
nsCollapsingMargin& aPrevMargin,
|
|
|
|
nscoord aClearance,
|
2002-09-04 06:55:40 +00:00
|
|
|
PRBool aIsAdjacentWithTop,
|
|
|
|
nsMargin& aComputedOffsets,
|
|
|
|
nsHTMLReflowState& aFrameRS,
|
|
|
|
nsReflowStatus& aFrameReflowStatus)
|
2000-06-20 03:47:49 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2002-09-04 06:55:40 +00:00
|
|
|
mFrame = aFrameRS.frame;
|
|
|
|
mSpace = aSpace;
|
|
|
|
|
|
|
|
// Get reflow reason set correctly. It's possible that a child was
|
|
|
|
// created and then it was decided that it could not be reflowed
|
|
|
|
// (for example, a block frame that isn't at the start of a
|
|
|
|
// line). In this case the reason will be wrong so we need to check
|
|
|
|
// the frame state.
|
|
|
|
aFrameRS.reason = eReflowReason_Resize;
|
2003-06-27 18:13:48 +00:00
|
|
|
if (NS_FRAME_FIRST_REFLOW & mFrame->GetStateBits()) {
|
2002-09-04 06:55:40 +00:00
|
|
|
aFrameRS.reason = eReflowReason_Initial;
|
|
|
|
}
|
|
|
|
else if (mOuterReflowState.reason == eReflowReason_Incremental) {
|
|
|
|
// If the frame we're about to reflow is on the reflow path, then
|
|
|
|
// propagate the reflow as `incremental' so it unwinds correctly
|
|
|
|
// to the target frames below us.
|
|
|
|
PRBool frameIsOnReflowPath = mOuterReflowState.path->HasChild(mFrame);
|
|
|
|
if (frameIsOnReflowPath)
|
|
|
|
aFrameRS.reason = eReflowReason_Incremental;
|
|
|
|
|
|
|
|
// But...if the incremental reflow command is a StyleChanged
|
|
|
|
// reflow and its target is the current block, change the reason
|
|
|
|
// to `style change', so that it propagates through the entire
|
|
|
|
// subtree.
|
|
|
|
nsHTMLReflowCommand* rc = mOuterReflowState.path->mReflowCommand;
|
|
|
|
if (rc) {
|
|
|
|
nsReflowType type;
|
|
|
|
rc->GetType(type);
|
|
|
|
if (type == eReflowType_StyleChanged)
|
|
|
|
aFrameRS.reason = eReflowReason_StyleChange;
|
|
|
|
else if (type == eReflowType_ReflowDirty &&
|
2003-06-27 18:13:48 +00:00
|
|
|
(mFrame->GetStateBits() & NS_FRAME_IS_DIRTY) &&
|
2002-09-04 06:55:40 +00:00
|
|
|
!frameIsOnReflowPath) {
|
|
|
|
aFrameRS.reason = eReflowReason_Dirty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mOuterReflowState.reason == eReflowReason_StyleChange) {
|
|
|
|
aFrameRS.reason = eReflowReason_StyleChange;
|
|
|
|
}
|
|
|
|
else if (mOuterReflowState.reason == eReflowReason_Dirty) {
|
2003-06-27 18:13:48 +00:00
|
|
|
if (mFrame->GetStateBits() & NS_FRAME_IS_DIRTY)
|
2002-09-04 06:55:40 +00:00
|
|
|
aFrameRS.reason = eReflowReason_Dirty;
|
|
|
|
}
|
|
|
|
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleDisplay* display = mFrame->GetStyleDisplay();
|
2002-09-04 06:55:40 +00:00
|
|
|
|
|
|
|
aComputedOffsets = aFrameRS.mComputedOffsets;
|
2004-01-11 04:29:09 +00:00
|
|
|
if (NS_STYLE_POSITION_RELATIVE == display->mPosition) {
|
2004-08-24 18:50:29 +00:00
|
|
|
nsPropertyTable *propTable = mPresContext->PropertyTable();
|
2004-08-22 07:10:50 +00:00
|
|
|
|
2004-02-23 21:29:06 +00:00
|
|
|
nsPoint *offsets = NS_STATIC_CAST(nsPoint*,
|
2004-08-24 18:50:29 +00:00
|
|
|
propTable->GetProperty(mFrame, nsLayoutAtoms::computedOffsetProperty));
|
2004-02-23 21:29:06 +00:00
|
|
|
|
2004-01-11 04:29:09 +00:00
|
|
|
if (offsets)
|
|
|
|
offsets->MoveTo(aComputedOffsets.left, aComputedOffsets.top);
|
|
|
|
else {
|
|
|
|
offsets = new nsPoint(aComputedOffsets.left, aComputedOffsets.top);
|
|
|
|
if (offsets)
|
2004-08-24 18:50:29 +00:00
|
|
|
propTable->SetProperty(mFrame, nsLayoutAtoms::computedOffsetProperty,
|
|
|
|
offsets, nsPointDtor, nsnull);
|
2004-01-11 04:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-04 06:55:40 +00:00
|
|
|
aFrameRS.mLineLayout = nsnull;
|
1998-12-12 17:59:30 +00:00
|
|
|
if (!aIsAdjacentWithTop) {
|
2002-09-04 06:55:40 +00:00
|
|
|
aFrameRS.mFlags.mIsTopOfPage = PR_FALSE; // make sure this is cleared
|
1998-12-12 17:59:30 +00:00
|
|
|
}
|
2002-09-04 06:55:40 +00:00
|
|
|
mComputedWidth = aFrameRS.mComputedWidth;
|
1999-03-05 04:22:11 +00:00
|
|
|
|
1999-03-27 01:22:45 +00:00
|
|
|
if (aApplyTopMargin) {
|
2004-11-25 14:51:00 +00:00
|
|
|
mTopMargin = aPrevMargin;
|
1999-09-10 18:52:56 +00:00
|
|
|
|
1999-03-27 01:22:45 +00:00
|
|
|
#ifdef NOISY_VERTICAL_MARGINS
|
|
|
|
nsFrame::ListTag(stdout, mOuterReflowState.frame);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf(": reflowing ");
|
2002-09-04 06:55:40 +00:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2004-11-25 14:51:00 +00:00
|
|
|
printf(" margin => %d, clearance => %d\n", mTopMargin.get(), aClearance);
|
1999-03-27 01:22:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Adjust the available height if its constrained so that the
|
|
|
|
// child frame doesn't think it can reflow into its margin area.
|
2002-09-04 06:55:40 +00:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != aFrameRS.availableHeight) {
|
2004-11-25 14:51:00 +00:00
|
|
|
aFrameRS.availableHeight -= mTopMargin.get() + aClearance;
|
1999-03-27 01:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-05 04:22:11 +00:00
|
|
|
// Compute x/y coordinate where reflow will begin. Use the rules
|
|
|
|
// from 10.3.3 to determine what to apply. At this point in the
|
|
|
|
// reflow auto left/right margins will have a zero value.
|
2002-09-04 06:55:40 +00:00
|
|
|
mMargin = aFrameRS.mComputedMargin;
|
|
|
|
mStyleBorder = aFrameRS.mStyleBorder;
|
|
|
|
mStyleMargin = aFrameRS.mStyleMargin;
|
|
|
|
mStylePadding = aFrameRS.mStylePadding;
|
2000-01-29 00:47:33 +00:00
|
|
|
nscoord x;
|
2004-11-25 14:51:00 +00:00
|
|
|
nscoord y = mSpace.y + mTopMargin.get() + aClearance;
|
2000-01-29 00:47:33 +00:00
|
|
|
|
|
|
|
// If it's a right floated element, then calculate the x-offset
|
|
|
|
// differently
|
2002-09-04 06:55:40 +00:00
|
|
|
if (NS_STYLE_FLOAT_RIGHT == aFrameRS.mStyleDisplay->mFloats) {
|
2000-01-29 00:47:33 +00:00
|
|
|
nscoord frameWidth;
|
|
|
|
|
2002-09-04 06:55:40 +00:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aFrameRS.mComputedWidth) {
|
2000-01-29 00:47:33 +00:00
|
|
|
// Use the current frame width
|
2003-06-27 18:13:48 +00:00
|
|
|
frameWidth = mFrame->GetSize().width;
|
2000-01-29 00:47:33 +00:00
|
|
|
} else {
|
2002-09-04 06:55:40 +00:00
|
|
|
frameWidth = aFrameRS.mComputedWidth +
|
|
|
|
aFrameRS.mComputedBorderPadding.left +
|
|
|
|
aFrameRS.mComputedBorderPadding.right;
|
2000-01-29 00:47:33 +00:00
|
|
|
}
|
|
|
|
|
2003-10-13 21:51:02 +00:00
|
|
|
// if this is an unconstrained width reflow, then just place the float at the left margin
|
2002-09-04 06:55:40 +00:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == mSpace.width)
|
|
|
|
x = mSpace.x;
|
2000-04-17 14:40:46 +00:00
|
|
|
else
|
2002-09-04 06:55:40 +00:00
|
|
|
x = mSpace.XMost() - mMargin.right - frameWidth;
|
2000-01-29 00:47:33 +00:00
|
|
|
|
|
|
|
} else {
|
2002-09-04 06:55:40 +00:00
|
|
|
x = mSpace.x + mMargin.left;
|
2000-01-29 00:47:33 +00:00
|
|
|
}
|
1999-03-05 04:22:11 +00:00
|
|
|
mX = x;
|
|
|
|
mY = y;
|
1998-12-01 16:13:49 +00:00
|
|
|
|
2000-01-26 01:45:47 +00:00
|
|
|
// If it's an auto-width table, then it doesn't behave like other blocks
|
2001-07-04 02:00:05 +00:00
|
|
|
// XXX why not for a floating table too?
|
2003-11-16 21:12:17 +00:00
|
|
|
if (aFrameRS.mStyleDisplay->mDisplay == NS_STYLE_DISPLAY_TABLE &&
|
|
|
|
!aFrameRS.mStyleDisplay->IsFloating()) {
|
2000-01-26 01:45:47 +00:00
|
|
|
// If this isn't the table's initial reflow, then use its existing
|
|
|
|
// width to determine where it will be placed horizontally
|
2002-09-04 06:55:40 +00:00
|
|
|
if (aFrameRS.reason != eReflowReason_Initial) {
|
2000-01-26 01:45:47 +00:00
|
|
|
nsBlockHorizontalAlign align;
|
|
|
|
|
|
|
|
align.mXOffset = x;
|
2003-06-27 18:13:48 +00:00
|
|
|
AlignBlockHorizontally(mFrame->GetSize().width, align);
|
2000-01-26 03:44:36 +00:00
|
|
|
// Don't reset "mX". because PlaceBlock() will recompute the
|
2000-01-26 01:45:47 +00:00
|
|
|
// x-offset and expects "mX" to be at the left margin edge
|
|
|
|
x = align.mXOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-11 04:29:09 +00:00
|
|
|
// Compute the translation to be used for adjusting the spacemanagager
|
|
|
|
// coordinate system for the frame. The spacemanager coordinates are
|
|
|
|
// <b>inside</b> the callers border+padding, but the x/y coordinates
|
|
|
|
// are not (recall that frame coordinates are relative to the parents
|
|
|
|
// origin and that the parents border/padding is <b>inside</b> the
|
|
|
|
// parent frame. Therefore we have to subtract out the parents
|
|
|
|
// border+padding before translating.
|
|
|
|
nscoord tx = x - mOuterReflowState.mComputedBorderPadding.left;
|
|
|
|
nscoord ty = y - mOuterReflowState.mComputedBorderPadding.top;
|
|
|
|
|
2000-01-26 03:44:36 +00:00
|
|
|
// If the element is relatively positioned, then adjust x and y accordingly
|
2002-09-04 06:55:40 +00:00
|
|
|
if (NS_STYLE_POSITION_RELATIVE == aFrameRS.mStyleDisplay->mPosition) {
|
|
|
|
x += aFrameRS.mComputedOffsets.left;
|
|
|
|
y += aFrameRS.mComputedOffsets.top;
|
2000-01-26 03:44:36 +00:00
|
|
|
}
|
|
|
|
|
1998-12-01 16:13:49 +00:00
|
|
|
// Let frame know that we are reflowing it
|
2002-09-04 06:55:40 +00:00
|
|
|
mFrame->WillReflow(mPresContext);
|
1998-12-01 16:13:49 +00:00
|
|
|
|
1999-11-19 15:33:29 +00:00
|
|
|
// Position it and its view (if it has one)
|
2000-01-26 03:44:36 +00:00
|
|
|
// Note: Use "x" and "y" and not "mX" and "mY" because they more accurately
|
|
|
|
// represents where we think the block will be placed
|
2003-06-27 18:13:48 +00:00
|
|
|
mFrame->SetPosition(nsPoint(x, y));
|
2004-12-27 15:05:18 +00:00
|
|
|
nsContainerFrame::PositionFrameView(mFrame);
|
1999-11-19 15:33:29 +00:00
|
|
|
|
1999-03-08 19:25:03 +00:00
|
|
|
#ifdef DEBUG
|
1999-03-19 23:06:20 +00:00
|
|
|
mMetrics.width = nscoord(0xdeadbeef);
|
|
|
|
mMetrics.height = nscoord(0xdeadbeef);
|
|
|
|
mMetrics.ascent = nscoord(0xdeadbeef);
|
|
|
|
mMetrics.descent = nscoord(0xdeadbeef);
|
2003-01-09 14:26:32 +00:00
|
|
|
if (mMetrics.mComputeMEW) {
|
|
|
|
mMetrics.mMaxElementWidth = nscoord(0xdeadbeef);
|
1999-03-08 19:25:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-07-20 03:41:03 +00:00
|
|
|
mOuterReflowState.mSpaceManager->Translate(tx, ty);
|
2000-01-08 03:58:27 +00:00
|
|
|
|
|
|
|
// See if this is the child's initial reflow and we are supposed to
|
|
|
|
// compute our maximum width
|
2002-09-04 06:55:40 +00:00
|
|
|
if (mComputeMaximumWidth && (eReflowReason_Initial == aFrameRS.reason)) {
|
2002-08-19 04:41:57 +00:00
|
|
|
mOuterReflowState.mSpaceManager->PushState();
|
|
|
|
|
2002-09-04 06:55:40 +00:00
|
|
|
nscoord oldAvailableWidth = aFrameRS.availableWidth;
|
|
|
|
nscoord oldComputedWidth = aFrameRS.mComputedWidth;
|
2000-01-08 03:58:27 +00:00
|
|
|
|
2002-09-04 06:55:40 +00:00
|
|
|
aFrameRS.availableWidth = NS_UNCONSTRAINEDSIZE;
|
2005-06-29 04:17:21 +00:00
|
|
|
// XXX Is this really correct? This means we don't compute the
|
|
|
|
// correct maximum width if the element's width is determined by
|
|
|
|
// its 'width' style
|
2002-09-04 06:55:40 +00:00
|
|
|
aFrameRS.mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
rv = mFrame->Reflow(mPresContext, mMetrics, aFrameRS, aFrameReflowStatus);
|
2000-01-08 03:58:27 +00:00
|
|
|
|
|
|
|
// Update the reflow metrics with the maximum width
|
|
|
|
mMetrics.mMaximumWidth = mMetrics.width;
|
2000-05-14 04:56:25 +00:00
|
|
|
#ifdef NOISY_REFLOW
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("*** nsBlockReflowContext::ReflowBlock block %p returning max width %d\n",
|
2002-09-04 06:55:40 +00:00
|
|
|
mFrame, mMetrics.mMaximumWidth);
|
2000-05-14 04:56:25 +00:00
|
|
|
#endif
|
2000-01-08 03:58:27 +00:00
|
|
|
// The second reflow is just as a resize reflow with the constrained
|
|
|
|
// width
|
2002-09-04 06:55:40 +00:00
|
|
|
aFrameRS.availableWidth = oldAvailableWidth;
|
|
|
|
aFrameRS.mComputedWidth = oldComputedWidth;
|
|
|
|
aFrameRS.reason = eReflowReason_Resize;
|
2002-08-19 04:41:57 +00:00
|
|
|
|
|
|
|
mOuterReflowState.mSpaceManager->PopState();
|
2000-01-08 03:58:27 +00:00
|
|
|
}
|
2000-05-14 04:56:25 +00:00
|
|
|
|
2002-09-04 06:55:40 +00:00
|
|
|
rv = mFrame->Reflow(mPresContext, mMetrics, aFrameRS, aFrameReflowStatus);
|
1999-07-20 03:41:03 +00:00
|
|
|
mOuterReflowState.mSpaceManager->Translate(-tx, -ty);
|
1998-12-01 16:13:49 +00:00
|
|
|
|
1999-03-08 19:25:03 +00:00
|
|
|
#ifdef DEBUG
|
1999-03-24 15:42:38 +00:00
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus)) {
|
|
|
|
if (CRAZY_WIDTH(mMetrics.width) || CRAZY_HEIGHT(mMetrics.height)) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("nsBlockReflowContext: ");
|
2002-09-04 06:55:40 +00:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf(" metrics=%d,%d!\n", mMetrics.width, mMetrics.height);
|
1999-03-24 15:42:38 +00:00
|
|
|
}
|
2003-01-09 14:26:32 +00:00
|
|
|
if (mMetrics.mComputeMEW &&
|
|
|
|
(nscoord(0xdeadbeef) == mMetrics.mMaxElementWidth)) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("nsBlockReflowContext: ");
|
2002-09-04 06:55:40 +00:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf(" didn't set max-element-size!\n");
|
1999-03-24 15:42:38 +00:00
|
|
|
}
|
|
|
|
#ifdef REALLY_NOISY_MAX_ELEMENT_SIZE
|
|
|
|
// Note: there are common reflow situations where this *correctly*
|
|
|
|
// occurs; so only enable this debug noise when you really need to
|
|
|
|
// analyze in detail.
|
2003-01-09 14:26:32 +00:00
|
|
|
if (mMetrics.mComputeMEW &&
|
|
|
|
(mMetrics.mMaxElementWidth > mMetrics.width)) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("nsBlockReflowContext: ");
|
2002-09-04 06:55:40 +00:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2003-01-09 14:26:32 +00:00
|
|
|
printf(": WARNING: maxElementWidth=%d > metrics=%d\n",
|
|
|
|
mMetrics.mMaxElementWidth, mMetrics.width);
|
1999-03-24 15:42:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if ((mMetrics.width == nscoord(0xdeadbeef)) ||
|
|
|
|
(mMetrics.height == nscoord(0xdeadbeef)) ||
|
|
|
|
(mMetrics.ascent == nscoord(0xdeadbeef)) ||
|
|
|
|
(mMetrics.descent == nscoord(0xdeadbeef))) {
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("nsBlockReflowContext: ");
|
2002-09-04 06:55:40 +00:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf(" didn't set whad %d,%d,%d,%d!\n",
|
1999-03-24 15:42:38 +00:00
|
|
|
mMetrics.width, mMetrics.height,
|
|
|
|
mMetrics.ascent, mMetrics.descent);
|
|
|
|
}
|
1999-03-19 23:06:20 +00:00
|
|
|
}
|
1999-03-08 19:25:03 +00:00
|
|
|
#endif
|
2002-07-01 17:43:02 +00:00
|
|
|
#ifdef DEBUG
|
2003-01-09 14:26:32 +00:00
|
|
|
if (nsBlockFrame::gNoisyMaxElementWidth) {
|
2002-07-01 17:43:02 +00:00
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus)) {
|
2003-01-09 14:26:32 +00:00
|
|
|
if (mMetrics.mComputeMEW) {
|
2002-07-01 17:43:02 +00:00
|
|
|
printf(" ");
|
2002-09-04 06:55:40 +00:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2003-01-09 14:26:32 +00:00
|
|
|
printf(": maxElementSize=%d wh=%d,%d\n",
|
|
|
|
mMetrics.mMaxElementWidth,
|
2002-07-01 17:43:02 +00:00
|
|
|
mMetrics.width, mMetrics.height);
|
|
|
|
}
|
1999-03-24 15:42:38 +00:00
|
|
|
}
|
1999-03-20 19:38:50 +00:00
|
|
|
}
|
|
|
|
#endif
|
1999-03-05 04:22:11 +00:00
|
|
|
|
2003-06-27 18:13:48 +00:00
|
|
|
if (!(NS_FRAME_OUTSIDE_CHILDREN & mFrame->GetStateBits())) {
|
1999-12-06 15:49:53 +00:00
|
|
|
// Provide overflow area for child that doesn't have any
|
|
|
|
mMetrics.mOverflowArea.x = 0;
|
|
|
|
mMetrics.mOverflowArea.y = 0;
|
|
|
|
mMetrics.mOverflowArea.width = mMetrics.width;
|
|
|
|
mMetrics.mOverflowArea.height = mMetrics.height;
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now that frame has been reflowed at least one time make sure that
|
|
|
|
// the NS_FRAME_FIRST_REFLOW bit is cleared so that never give it an
|
|
|
|
// initial reflow reason again.
|
2002-09-04 06:55:40 +00:00
|
|
|
if (eReflowReason_Initial == aFrameRS.reason) {
|
2003-06-27 18:13:48 +00:00
|
|
|
mFrame->RemoveStateBits(NS_FRAME_FIRST_REFLOW);
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2002-05-28 22:50:43 +00:00
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus) ||
|
2003-06-27 18:13:48 +00:00
|
|
|
(mFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) {
|
1998-12-01 16:13:49 +00:00
|
|
|
// If frame is complete and has a next-in-flow, we need to delete
|
|
|
|
// them now. Do not do this when a break-before is signaled because
|
|
|
|
// the frame is going to get reflowed again (and may end up wanting
|
2002-05-28 22:50:43 +00:00
|
|
|
// a next-in-flow where it ends up), unless it is an out of flow frame.
|
1998-12-05 16:01:11 +00:00
|
|
|
if (NS_FRAME_IS_COMPLETE(aFrameReflowStatus)) {
|
2004-09-14 02:28:03 +00:00
|
|
|
nsIFrame* kidNextInFlow = mFrame->GetNextInFlow();
|
1998-12-01 16:13:49 +00:00
|
|
|
if (nsnull != kidNextInFlow) {
|
|
|
|
// Remove all of the childs next-in-flows. Make sure that we ask
|
|
|
|
// the right parent to do the removal (it's possible that the
|
2005-03-23 03:35:08 +00:00
|
|
|
// parent is not this because we are executing pullup code).
|
|
|
|
// Floats will eventually be removed via nsBlockFrame::RemoveFloat
|
|
|
|
// which detaches the placeholder from the float.
|
1998-12-01 16:13:49 +00:00
|
|
|
/* XXX promote DeleteChildsNextInFlow to nsIFrame to elminate this cast */
|
2003-06-27 18:13:48 +00:00
|
|
|
NS_STATIC_CAST(nsHTMLContainerFrame*, kidNextInFlow->GetParent())
|
|
|
|
->DeleteNextInFlowChild(mPresContext, kidNextInFlow);
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-03 04:32:13 +00:00
|
|
|
// If the block is shrink wrapping its width, then see if we have percentage
|
|
|
|
// based margins. If so, we can calculate them now that we know the shrink
|
|
|
|
// wrap width
|
2002-09-04 06:55:40 +00:00
|
|
|
if (NS_SHRINKWRAPWIDTH == aFrameRS.mComputedWidth) {
|
|
|
|
ComputeShrinkwrapMargins(aFrameRS.mStyleMargin, mMetrics.width, mMargin, mX);
|
2000-01-03 04:32:13 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:01:11 +00:00
|
|
|
return rv;
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to place the block frame within the available space. If
|
|
|
|
* it fits, apply horizontal positioning (CSS 10.3.3), collapse
|
|
|
|
* margins (CSS2 8.3.1). Also apply relative positioning.
|
|
|
|
*/
|
|
|
|
PRBool
|
2001-12-07 14:51:12 +00:00
|
|
|
nsBlockReflowContext::PlaceBlock(const nsHTMLReflowState& aReflowState,
|
|
|
|
PRBool aForceFit,
|
2004-11-25 14:51:00 +00:00
|
|
|
nsLineBox* aLine,
|
2001-12-07 14:51:12 +00:00
|
|
|
const nsMargin& aComputedOffsets,
|
|
|
|
nsCollapsingMargin& aBottomMarginResult,
|
|
|
|
nsRect& aInFlowBounds,
|
2005-03-23 03:35:08 +00:00
|
|
|
nsRect& aCombinedRect,
|
|
|
|
nsReflowStatus aReflowStatus)
|
1998-12-01 16:13:49 +00:00
|
|
|
{
|
2005-03-23 03:35:08 +00:00
|
|
|
// Compute collapsed bottom margin value.
|
|
|
|
if (NS_FRAME_IS_COMPLETE(aReflowStatus)) {
|
|
|
|
aBottomMarginResult = mMetrics.mCarriedOutBottomMargin;
|
|
|
|
aBottomMarginResult.Include(mMargin.bottom);
|
|
|
|
} else {
|
|
|
|
// The used bottom-margin is set to zero above a break.
|
|
|
|
aBottomMarginResult.Zero();
|
|
|
|
}
|
1998-12-01 16:13:49 +00:00
|
|
|
|
1999-03-22 20:45:26 +00:00
|
|
|
nscoord x = mX;
|
|
|
|
nscoord y = mY;
|
2005-02-02 01:33:20 +00:00
|
|
|
nscoord backupContainingBlockAdvance = 0;
|
|
|
|
|
2004-11-25 14:51:00 +00:00
|
|
|
// Check whether the block's bottom margin collapses with its top
|
|
|
|
// margin. See CSS 2.1 section 8.3.1; those rules seem to match
|
|
|
|
// nsBlockFrame::IsEmpty(). Any such block must have zero height so
|
2005-01-27 20:54:27 +00:00
|
|
|
// check that first. Note that a block can have clearance and still
|
|
|
|
// have adjoining top/bottom margins, because the clearance goes
|
|
|
|
// above the top margin.
|
2005-03-23 03:35:08 +00:00
|
|
|
PRBool empty = 0 == mMetrics.height && aLine->CachedIsEmpty();
|
|
|
|
if (empty) {
|
2000-06-29 22:03:42 +00:00
|
|
|
// Collapse the bottom margin with the top margin that was already
|
|
|
|
// applied.
|
2001-10-25 01:08:40 +00:00
|
|
|
aBottomMarginResult.Include(mTopMargin);
|
2005-03-23 03:35:08 +00:00
|
|
|
|
1999-05-10 22:28:04 +00:00
|
|
|
#ifdef NOISY_VERTICAL_MARGINS
|
2000-10-28 22:17:53 +00:00
|
|
|
printf(" ");
|
2000-06-29 22:03:42 +00:00
|
|
|
nsFrame::ListTag(stdout, mOuterReflowState.frame);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf(": ");
|
2000-06-29 22:03:42 +00:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf(" -- collapsing top & bottom margin together; y=%d spaceY=%d\n",
|
2000-06-29 22:03:42 +00:00
|
|
|
y, mSpace.y);
|
1999-05-10 22:28:04 +00:00
|
|
|
#endif
|
2005-01-27 20:54:27 +00:00
|
|
|
// Section 8.3.1 of CSS 2.1 says that blocks with adjoining
|
|
|
|
// top/bottom margins whose top margin collapses with their
|
|
|
|
// parent's top margin should have their top border-edge at the
|
|
|
|
// top border-edge of their parent. We actually don't have to do
|
|
|
|
// anything special to make this happen. In that situation,
|
|
|
|
// nsBlockFrame::ShouldApplyTopMargin will have returned PR_FALSE,
|
|
|
|
// and mTopMargin and aClearance will have been zero in
|
|
|
|
// ReflowBlock.
|
2005-02-02 01:33:20 +00:00
|
|
|
|
|
|
|
// If we did apply our top margin, but now we're collapsing it
|
|
|
|
// into the bottom margin, we need to back up the containing
|
|
|
|
// block's y-advance by our top margin so that it doesn't get
|
|
|
|
// counted twice. Note that here we're allowing the line's bounds
|
|
|
|
// to become different from the block's position; we do this
|
|
|
|
// because the containing block will place the next line at the
|
|
|
|
// line's YMost, and it must place the next line at a different
|
|
|
|
// point from where this empty block will be.
|
|
|
|
backupContainingBlockAdvance = mTopMargin.get();
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
2000-08-11 20:08:15 +00:00
|
|
|
|
2005-03-23 03:35:08 +00:00
|
|
|
// See if the frame fit. If it's the first frame or empty then it
|
|
|
|
// always fits. If the height is unconstrained then it always fits,
|
|
|
|
// even if there's some sort of integer overflow that makes y +
|
|
|
|
// mMetrics.height appear to go beyond the available height.
|
|
|
|
if (!empty && !aForceFit && mSpace.height != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
nscoord yMost = y - backupContainingBlockAdvance + mMetrics.height;
|
|
|
|
if (yMost > mSpace.YMost()) {
|
|
|
|
// didn't fit, we must acquit.
|
2001-12-07 14:51:12 +00:00
|
|
|
mFrame->DidReflow(mPresContext, &aReflowState, NS_FRAME_REFLOW_FINISHED);
|
2005-03-23 03:35:08 +00:00
|
|
|
return PR_FALSE;
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-23 03:35:08 +00:00
|
|
|
if (!empty)
|
|
|
|
{
|
|
|
|
// Adjust the max-element-size in the metrics to take into
|
|
|
|
// account the margins around the block element.
|
|
|
|
// Do not allow auto margins to impact the max-element size
|
|
|
|
// since they are springy and don't really count!
|
|
|
|
if (mMetrics.mComputeMEW) {
|
|
|
|
nsMargin maxElemMargin;
|
|
|
|
const nsStyleSides &styleMargin = mStyleMargin->mMargin;
|
|
|
|
nsStyleCoord coord;
|
|
|
|
if (styleMargin.GetLeftUnit() == eStyleUnit_Coord)
|
|
|
|
maxElemMargin.left = styleMargin.GetLeft(coord).GetCoordValue();
|
|
|
|
else
|
|
|
|
maxElemMargin.left = 0;
|
|
|
|
if (styleMargin.GetRightUnit() == eStyleUnit_Coord)
|
|
|
|
maxElemMargin.right = styleMargin.GetRight(coord).GetCoordValue();
|
|
|
|
else
|
|
|
|
maxElemMargin.right = 0;
|
|
|
|
|
|
|
|
nscoord dummyXOffset;
|
|
|
|
// Base the margins on the max-element size
|
|
|
|
ComputeShrinkwrapMargins(mStyleMargin, mMetrics.mMaxElementWidth,
|
|
|
|
maxElemMargin, dummyXOffset);
|
|
|
|
|
|
|
|
mMetrics.mMaxElementWidth += maxElemMargin.left + maxElemMargin.right;
|
|
|
|
}
|
2005-01-25 22:29:59 +00:00
|
|
|
|
2005-03-23 03:35:08 +00:00
|
|
|
// do the same for the maximum width
|
|
|
|
if (mComputeMaximumWidth) {
|
|
|
|
nsMargin maxWidthMargin;
|
|
|
|
const nsStyleSides &styleMargin = mStyleMargin->mMargin;
|
|
|
|
nsStyleCoord coord;
|
|
|
|
if (styleMargin.GetLeftUnit() == eStyleUnit_Coord)
|
|
|
|
maxWidthMargin.left = styleMargin.GetLeft(coord).GetCoordValue();
|
|
|
|
else
|
|
|
|
maxWidthMargin.left = 0;
|
|
|
|
if (styleMargin.GetRightUnit() == eStyleUnit_Coord)
|
|
|
|
maxWidthMargin.right = styleMargin.GetRight(coord).GetCoordValue();
|
|
|
|
else
|
|
|
|
maxWidthMargin.right = 0;
|
|
|
|
|
|
|
|
nscoord dummyXOffset;
|
|
|
|
// Base the margins on the maximum width
|
|
|
|
ComputeShrinkwrapMargins(mStyleMargin, mMetrics.mMaximumWidth,
|
|
|
|
maxWidthMargin, dummyXOffset);
|
|
|
|
|
|
|
|
mMetrics.mMaximumWidth += maxWidthMargin.left + maxWidthMargin.right;
|
2005-01-25 22:29:59 +00:00
|
|
|
}
|
2005-03-23 03:35:08 +00:00
|
|
|
}
|
2005-01-25 22:29:59 +00:00
|
|
|
|
2005-03-23 03:35:08 +00:00
|
|
|
// Calculate the actual x-offset and left and right margin
|
|
|
|
nsBlockHorizontalAlign align;
|
|
|
|
align.mXOffset = x;
|
|
|
|
AlignBlockHorizontally(mMetrics.width, align);
|
|
|
|
x = align.mXOffset;
|
|
|
|
mMargin.left = align.mLeftMargin;
|
|
|
|
mMargin.right = align.mRightMargin;
|
|
|
|
|
|
|
|
aInFlowBounds = nsRect(x, y - backupContainingBlockAdvance,
|
|
|
|
mMetrics.width, mMetrics.height);
|
|
|
|
|
|
|
|
// Apply CSS relative positioning
|
|
|
|
const nsStyleDisplay* styleDisp = mFrame->GetStyleDisplay();
|
|
|
|
if (NS_STYLE_POSITION_RELATIVE == styleDisp->mPosition) {
|
|
|
|
x += aComputedOffsets.left;
|
|
|
|
y += aComputedOffsets.top;
|
2005-01-25 22:29:59 +00:00
|
|
|
}
|
2005-03-23 03:35:08 +00:00
|
|
|
|
|
|
|
// Now place the frame and complete the reflow process
|
|
|
|
nsContainerFrame::FinishReflowChild(mFrame, mPresContext, &aReflowState, mMetrics, x, y, 0);
|
|
|
|
|
|
|
|
aCombinedRect = mMetrics.mOverflowArea + nsPoint(x, y);
|
2005-01-25 22:29:59 +00:00
|
|
|
|
2005-03-23 03:35:08 +00:00
|
|
|
return PR_TRUE;
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|