2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-10-25 05:08:40 +04:00
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-12-01 19:13:49 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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-12-01 19:13:49 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-12-01 19:13:49 +03:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2003-01-02 02:53:20 +03:00
|
|
|
* David Baron <dbaron@dbaron.org>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-12-01 19:13:49 +03:00
|
|
|
#include "nsBlockReflowContext.h"
|
|
|
|
#include "nsLineLayout.h"
|
2001-10-26 09:06:07 +04:00
|
|
|
#include "nsSpaceManager.h"
|
1998-12-01 19:13:49 +03:00
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsIPresContext.h"
|
1999-04-13 05:15:16 +04:00
|
|
|
#include "nsIContent.h"
|
1998-12-01 19:13:49 +03:00
|
|
|
#include "nsIStyleContext.h"
|
2001-12-18 01:39:59 +03:00
|
|
|
#include "nsHTMLReflowCommand.h"
|
1998-12-01 19:13:49 +03:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
1999-03-27 04:22:45 +03:00
|
|
|
#include "nsBlockFrame.h"
|
2002-11-28 22:29:28 +03:00
|
|
|
#include "nsLineBox.h"
|
2000-06-15 03:15:59 +04:00
|
|
|
#include "nsIDOMHTMLTableCellElement.h"
|
|
|
|
#include "nsIDOMHTMLBodyElement.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
1999-07-14 21:27:24 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1998-12-01 19:13:49 +03:00
|
|
|
|
1999-02-12 20:45:58 +03:00
|
|
|
#ifdef NS_DEBUG
|
1999-03-20 22:38:50 +03:00
|
|
|
#undef NOISY_MAX_ELEMENT_SIZE
|
1999-03-24 18:42:38 +03:00
|
|
|
#undef REALLY_NOISY_MAX_ELEMENT_SIZE
|
1999-03-27 04:22:45 +03:00
|
|
|
#undef NOISY_VERTICAL_MARGINS
|
1999-02-12 20:45:58 +03:00
|
|
|
#else
|
1999-03-20 22:38:50 +03:00
|
|
|
#undef NOISY_MAX_ELEMENT_SIZE
|
1999-03-24 18:42:38 +03:00
|
|
|
#undef REALLY_NOISY_MAX_ELEMENT_SIZE
|
1999-03-27 04:22:45 +03:00
|
|
|
#undef NOISY_VERTICAL_MARGINS
|
1999-02-12 20:45:58 +03:00
|
|
|
#endif
|
|
|
|
|
1999-04-20 04:27:08 +04:00
|
|
|
nsBlockReflowContext::nsBlockReflowContext(nsIPresContext* aPresContext,
|
1999-03-05 07:22:11 +03:00
|
|
|
const nsHTMLReflowState& aParentRS,
|
1999-12-30 07:15:45 +03:00
|
|
|
PRBool aComputeMaxElementSize,
|
|
|
|
PRBool aComputeMaximumWidth)
|
1998-12-01 19:13:49 +03:00
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mOuterReflowState(aParentRS),
|
1999-04-10 21:32:04 +04:00
|
|
|
mMetrics(aComputeMaxElementSize ? &mMaxElementSize : nsnull),
|
1999-12-30 07:15:45 +03:00
|
|
|
mMaxElementSize(0, 0),
|
2000-05-09 09:08:02 +04:00
|
|
|
mIsTable(PR_FALSE),
|
|
|
|
mComputeMaximumWidth(aComputeMaximumWidth),
|
|
|
|
mBlockShouldInvalidateItself(PR_FALSE)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
2001-02-07 12:57:26 +03:00
|
|
|
mStyleBorder = nsnull;
|
|
|
|
mStyleMargin = nsnull;
|
|
|
|
mStylePadding = nsnull;
|
2000-05-14 08:56:25 +04:00
|
|
|
if (mComputeMaximumWidth)
|
|
|
|
mMetrics.mFlags |= NS_REFLOW_CALC_MAX_WIDTH;
|
1999-03-27 04:22:45 +03:00
|
|
|
}
|
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
void
|
1999-04-20 04:27:08 +04:00
|
|
|
nsBlockReflowContext::ComputeCollapsedTopMargin(nsIPresContext* aPresContext,
|
2001-10-25 05:08:40 +04:00
|
|
|
nsHTMLReflowState& aRS,
|
|
|
|
/* inout */ nsCollapsingMargin& aMargin)
|
1999-03-27 04:22:45 +03:00
|
|
|
{
|
|
|
|
// Get aFrame's top margin
|
2001-10-25 05:08:40 +04:00
|
|
|
aMargin.Include(aRS.mComputedMargin.top);
|
|
|
|
|
2002-11-28 22:29:28 +03: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 05:08:40 +04:00
|
|
|
#ifdef NOISY_VERTICAL_MARGINS
|
|
|
|
nsFrame::ListTag(stdout, aRS.frame);
|
|
|
|
printf(": %d => %d\n", aRS.mComputedMargin.top, aMargin.get());
|
|
|
|
#endif
|
1999-03-27 04:22:45 +03:00
|
|
|
|
|
|
|
// Calculate aFrame's generational top-margin from its child
|
|
|
|
// blocks. Note that if aFrame has a non-zero top-border or
|
|
|
|
// top-padding then this step is skipped because it will be a margin
|
2000-06-30 02:03:42 +04:00
|
|
|
// root. It is also skipped if the frame is a margin root for other
|
|
|
|
// reasons.
|
2002-11-28 22:29:28 +03:00
|
|
|
nsFrameState state;
|
|
|
|
if (0 == aRS.mComputedBorderPadding.top &&
|
|
|
|
(aRS.frame->GetFrameState(&state), !(state & NS_BLOCK_MARGIN_ROOT))) {
|
|
|
|
nsBlockFrame* bf;
|
|
|
|
if (NS_SUCCEEDED(aRS.frame->QueryInterface(kBlockFrameCID,
|
|
|
|
NS_REINTERPRET_CAST(void**, &bf)))) {
|
|
|
|
nsCompatibility compat;
|
|
|
|
aPresContext->GetCompatibilityMode(&compat);
|
2000-06-30 02:03:42 +04:00
|
|
|
|
2002-11-28 22:29:28 +03:00
|
|
|
const nsStyleText* text;
|
|
|
|
::GetStyleData(bf, &text);
|
|
|
|
PRBool isPre = NS_STYLE_WHITESPACE_PRE == text->mWhiteSpace ||
|
|
|
|
NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == text->mWhiteSpace;
|
2000-06-30 02:03:42 +04:00
|
|
|
|
2002-11-28 22:29:28 +03:00
|
|
|
for (nsBlockFrame::line_iterator line = bf->begin_lines(),
|
|
|
|
line_end = bf->end_lines();
|
|
|
|
line != line_end; ++line) {
|
|
|
|
PRBool isEmpty;
|
|
|
|
line->IsEmpty(compat, isPre, &isEmpty);
|
|
|
|
if (line->IsBlock()) {
|
2001-10-25 05:08:40 +04:00
|
|
|
// Here is where we recur. Now that we have determined that a
|
2000-06-30 02:03:42 +04:00
|
|
|
// 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
|
2002-05-10 22:22:41 +04:00
|
|
|
// 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.
|
2000-06-30 02:03:42 +04:00
|
|
|
nsSize availSpace(aRS.mComputedWidth, aRS.mComputedHeight);
|
2002-11-28 22:29:28 +03:00
|
|
|
nsHTMLReflowState reflowState(aPresContext, aRS, line->mFirstChild,
|
2002-05-10 22:22:41 +04:00
|
|
|
availSpace, eReflowReason_Resize);
|
2001-10-25 05:08:40 +04:00
|
|
|
ComputeCollapsedTopMargin(aPresContext, reflowState, aMargin);
|
2002-11-28 22:29:28 +03:00
|
|
|
if (isEmpty)
|
|
|
|
aMargin.Include(reflowState.mComputedMargin.bottom);
|
2000-06-30 02:03:42 +04:00
|
|
|
}
|
2002-11-28 22:29:28 +03:00
|
|
|
if (!isEmpty)
|
|
|
|
break;
|
1999-03-27 04:22:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NOISY_VERTICAL_MARGINS
|
|
|
|
nsFrame::ListTag(stdout, aRS.frame);
|
2001-10-25 05:08:40 +04:00
|
|
|
printf(": => %d\n", aMargin.get());
|
1999-03-27 04:22:45 +03:00
|
|
|
#endif
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2000-01-26 04:45:47 +03: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 12:57:26 +03:00
|
|
|
nsStyleUnit leftUnit = mStyleMargin->mMargin.GetLeftUnit();
|
2000-01-26 04:45:47 +03:00
|
|
|
if (eStyleUnit_Inherit == leftUnit) {
|
|
|
|
leftUnit = GetRealMarginLeftUnit();
|
|
|
|
}
|
2001-02-07 12:57:26 +03:00
|
|
|
nsStyleUnit rightUnit = mStyleMargin->mMargin.GetRightUnit();
|
2000-01-26 04:45:47 +03:00
|
|
|
if (eStyleUnit_Inherit == rightUnit) {
|
|
|
|
rightUnit = GetRealMarginRightUnit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != mSpace.width) {
|
|
|
|
// 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 04:17:51 +03:00
|
|
|
aAlign.mXOffset = mSpace.x;
|
2000-01-26 04:45:47 +03: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-28 03:37:44 +04: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;
|
|
|
|
} else {
|
|
|
|
// If we don't have a special text-align value indicating
|
|
|
|
// HTML alignment, then use the CSS rules.
|
|
|
|
|
2000-01-26 04:45:47 +03: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-06-01 02:19:43 +04:00
|
|
|
PRUint8 direction = mOuterReflowState.mStyleVisibility->mDirection;
|
2000-01-26 04:45:47 +03:00
|
|
|
if (NS_STYLE_DIRECTION_RTL == direction) {
|
|
|
|
// The left margin becomes auto
|
|
|
|
aAlign.mXOffset += remainingSpace;
|
|
|
|
}
|
2000-07-28 03:37:44 +04:00
|
|
|
//else {
|
2000-01-26 04:45:47 +03:00
|
|
|
// The right margin becomes auto which is a no-op
|
2000-07-28 03:37:44 +04:00
|
|
|
//}
|
2000-01-26 04:45:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-12 00:08:15 +04:00
|
|
|
static void
|
2001-02-07 12:57:26 +03:00
|
|
|
ComputeShrinkwrapMargins(const nsStyleMargin* aStyleMargin, nscoord aWidth, nsMargin& aMargin, nscoord& aXToUpdate) {
|
2000-08-12 00:08:15 +04:00
|
|
|
nscoord boxWidth = aWidth;
|
|
|
|
float leftPct = 0.0;
|
|
|
|
float rightPct = 0.0;
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
if (eStyleUnit_Percent == aStyleMargin->mMargin.GetLeftUnit()) {
|
2000-08-12 00:08:15 +04:00
|
|
|
nsStyleCoord leftCoord;
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
aStyleMargin->mMargin.GetLeft(leftCoord);
|
2000-08-12 00:08:15 +04:00
|
|
|
leftPct = leftCoord.GetPercentValue();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
boxWidth += aMargin.left;
|
|
|
|
}
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
if (eStyleUnit_Percent == aStyleMargin->mMargin.GetRightUnit()) {
|
2000-08-12 00:08:15 +04:00
|
|
|
nsStyleCoord rightCoord;
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
aStyleMargin->mMargin.GetRight(rightCoord);
|
2000-08-12 00:08:15 +04:00
|
|
|
rightPct = rightCoord.GetPercentValue();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
boxWidth += aMargin.right;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The total shrink wrap width "sww" is calculated by the expression:
|
|
|
|
// sww = bw + (mp * sww)
|
|
|
|
// 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 us:
|
|
|
|
// sww = bw / (1 - mp)
|
|
|
|
// Note that this is only well defined for "mp" less than 100%
|
2001-07-04 06:00:05 +04:00
|
|
|
|
|
|
|
// XXXldb Um... percentage margins are based on the containing block width.
|
2000-08-12 00:08:15 +04: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);
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
if (eStyleUnit_Percent == aStyleMargin->mMargin.GetLeftUnit()) {
|
2000-08-12 00:08:15 +04:00
|
|
|
aMargin.left = NSToCoordFloor((float)(shrinkWrapWidth * leftPct));
|
|
|
|
aXToUpdate += aMargin.left;
|
|
|
|
}
|
2001-02-07 12:57:26 +03:00
|
|
|
if (eStyleUnit_Percent == aStyleMargin->mMargin.GetRightUnit()) {
|
2000-08-12 00:08:15 +04:00
|
|
|
aMargin.right = NSToCoordFloor((float)(shrinkWrapWidth * rightPct));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-20 07:47:49 +04:00
|
|
|
nsresult
|
2002-09-04 10:55:40 +04:00
|
|
|
nsBlockReflowContext::ReflowBlock(const nsRect& aSpace,
|
|
|
|
PRBool aApplyTopMargin,
|
|
|
|
nsCollapsingMargin& aPrevBottomMargin,
|
|
|
|
PRBool aIsAdjacentWithTop,
|
|
|
|
nsMargin& aComputedOffsets,
|
|
|
|
nsHTMLReflowState& aFrameRS,
|
|
|
|
nsReflowStatus& aFrameReflowStatus)
|
2000-06-20 07:47:49 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2002-09-04 10:55:40 +04: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;
|
2000-06-20 07:47:49 +04:00
|
|
|
nsFrameState state;
|
2002-09-04 10:55:40 +04:00
|
|
|
mFrame->GetFrameState(&state);
|
|
|
|
if (NS_FRAME_FIRST_REFLOW & state) {
|
|
|
|
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 &&
|
|
|
|
(state & NS_FRAME_IS_DIRTY) &&
|
|
|
|
!frameIsOnReflowPath) {
|
|
|
|
aFrameRS.reason = eReflowReason_Dirty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mOuterReflowState.reason == eReflowReason_StyleChange) {
|
|
|
|
aFrameRS.reason = eReflowReason_StyleChange;
|
|
|
|
}
|
|
|
|
else if (mOuterReflowState.reason == eReflowReason_Dirty) {
|
|
|
|
if (state & NS_FRAME_IS_DIRTY)
|
|
|
|
aFrameRS.reason = eReflowReason_Dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We build a different reflow context based on the width attribute of the block,
|
|
|
|
* if it's a floater.
|
|
|
|
* Auto-width floaters need to have their containing-block size set explicitly,
|
|
|
|
* factoring in other floaters that impact it.
|
|
|
|
* It's possible this should be quirks-only.
|
|
|
|
* All other blocks proceed normally.
|
|
|
|
*/
|
|
|
|
// XXXldb We should really fix this in nsHTMLReflowState::InitConstraints instead.
|
|
|
|
const nsStylePosition* position;
|
|
|
|
mFrame->GetStyleData(eStyleStruct_Position, (const nsStyleStruct*&)position);
|
|
|
|
nsStyleUnit widthUnit = position->mWidth.GetUnit();
|
|
|
|
const nsStyleDisplay* display;
|
|
|
|
mFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
|
|
|
|
|
|
|
|
if ((eStyleUnit_Auto == widthUnit) &&
|
|
|
|
((NS_STYLE_FLOAT_LEFT == display->mFloats) ||
|
|
|
|
(NS_STYLE_FLOAT_RIGHT == display->mFloats))) {
|
|
|
|
// Initialize the reflow state and constrain the containing block's
|
|
|
|
// width and height to the available width and height.
|
|
|
|
aFrameRS.Init(mPresContext, mSpace.width, mSpace.height);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Initialize the reflow state and use the containing block's computed
|
|
|
|
// width and height (or derive appropriate values for an
|
|
|
|
// absolutely positioned frame).
|
|
|
|
aFrameRS.Init(mPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
aComputedOffsets = aFrameRS.mComputedOffsets;
|
|
|
|
aFrameRS.mLineLayout = nsnull;
|
1998-12-12 20:59:30 +03:00
|
|
|
if (!aIsAdjacentWithTop) {
|
2002-09-04 10:55:40 +04:00
|
|
|
aFrameRS.mFlags.mIsTopOfPage = PR_FALSE; // make sure this is cleared
|
1998-12-12 20:59:30 +03:00
|
|
|
}
|
2002-09-04 10:55:40 +04:00
|
|
|
mIsTable = NS_STYLE_DISPLAY_TABLE == aFrameRS.mStyleDisplay->mDisplay;
|
|
|
|
mComputedWidth = aFrameRS.mComputedWidth;
|
1999-03-05 07:22:11 +03:00
|
|
|
|
1999-03-27 04:22:45 +03:00
|
|
|
if (aApplyTopMargin) {
|
|
|
|
// Compute the childs collapsed top margin (its margin collpased
|
|
|
|
// with its first childs top-margin -- recursively).
|
2002-09-04 10:55:40 +04:00
|
|
|
ComputeCollapsedTopMargin(mPresContext, aFrameRS, aPrevBottomMargin);
|
1999-09-10 22:52:56 +04:00
|
|
|
|
1999-03-27 04:22:45 +03:00
|
|
|
#ifdef NOISY_VERTICAL_MARGINS
|
|
|
|
nsFrame::ListTag(stdout, mOuterReflowState.frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": reflowing ");
|
2002-09-04 10:55:40 +04:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2001-10-25 05:08:40 +04:00
|
|
|
printf(" margin => %d\n", aPrevBottomMargin.get());
|
1999-03-27 04:22:45 +03: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 10:55:40 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != aFrameRS.availableHeight) {
|
|
|
|
aFrameRS.availableHeight -= aPrevBottomMargin.get();
|
1999-03-27 04:22:45 +03:00
|
|
|
}
|
2002-11-28 22:29:28 +03:00
|
|
|
mTopMargin = aPrevBottomMargin;
|
1999-03-27 04:22:45 +03:00
|
|
|
}
|
|
|
|
|
1999-03-05 07:22:11 +03: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 10:55:40 +04:00
|
|
|
mMargin = aFrameRS.mComputedMargin;
|
|
|
|
mStyleBorder = aFrameRS.mStyleBorder;
|
|
|
|
mStyleMargin = aFrameRS.mStyleMargin;
|
|
|
|
mStylePadding = aFrameRS.mStylePadding;
|
2000-01-29 03:47:33 +03:00
|
|
|
nscoord x;
|
2002-10-08 05:52:34 +04:00
|
|
|
nscoord y = mSpace.y + mTopMargin.get();
|
2000-01-29 03:47:33 +03:00
|
|
|
|
|
|
|
// If it's a right floated element, then calculate the x-offset
|
|
|
|
// differently
|
2002-09-04 10:55:40 +04:00
|
|
|
if (NS_STYLE_FLOAT_RIGHT == aFrameRS.mStyleDisplay->mFloats) {
|
2000-01-29 03:47:33 +03:00
|
|
|
nscoord frameWidth;
|
|
|
|
|
2002-09-04 10:55:40 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aFrameRS.mComputedWidth) {
|
2000-01-29 03:47:33 +03:00
|
|
|
nsSize frameSize;
|
|
|
|
|
|
|
|
// Use the current frame width
|
2002-09-04 10:55:40 +04:00
|
|
|
mFrame->GetSize(frameSize);
|
2000-01-29 03:47:33 +03:00
|
|
|
frameWidth = frameSize.width;
|
|
|
|
|
|
|
|
} else {
|
2002-09-04 10:55:40 +04:00
|
|
|
frameWidth = aFrameRS.mComputedWidth +
|
|
|
|
aFrameRS.mComputedBorderPadding.left +
|
|
|
|
aFrameRS.mComputedBorderPadding.right;
|
2000-01-29 03:47:33 +03:00
|
|
|
}
|
|
|
|
|
2000-04-17 18:40:46 +04:00
|
|
|
// if this is an unconstrained width reflow, then just place the floater at the left margin
|
2002-09-04 10:55:40 +04:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == mSpace.width)
|
|
|
|
x = mSpace.x;
|
2000-04-17 18:40:46 +04:00
|
|
|
else
|
2002-09-04 10:55:40 +04:00
|
|
|
x = mSpace.XMost() - mMargin.right - frameWidth;
|
2000-01-29 03:47:33 +03:00
|
|
|
|
|
|
|
} else {
|
2002-09-04 10:55:40 +04:00
|
|
|
x = mSpace.x + mMargin.left;
|
2000-01-29 03:47:33 +03:00
|
|
|
}
|
1999-03-05 07:22:11 +03:00
|
|
|
mX = x;
|
|
|
|
mY = y;
|
1998-12-01 19:13:49 +03:00
|
|
|
|
2000-01-26 04:45:47 +03:00
|
|
|
// If it's an auto-width table, then it doesn't behave like other blocks
|
2001-07-04 06:00:05 +04:00
|
|
|
// XXX why not for a floating table too?
|
2002-09-04 10:55:40 +04:00
|
|
|
if (mIsTable && !aFrameRS.mStyleDisplay->IsFloating()) {
|
2000-01-26 04:45:47 +03: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 10:55:40 +04:00
|
|
|
if (aFrameRS.reason != eReflowReason_Initial) {
|
2000-01-26 04:45:47 +03:00
|
|
|
nsBlockHorizontalAlign align;
|
|
|
|
nsSize size;
|
|
|
|
|
2002-09-04 10:55:40 +04:00
|
|
|
mFrame->GetSize(size);
|
2000-01-26 04:45:47 +03:00
|
|
|
align.mXOffset = x;
|
|
|
|
AlignBlockHorizontally(size.width, align);
|
2000-01-26 06:44:36 +03:00
|
|
|
// Don't reset "mX". because PlaceBlock() will recompute the
|
2000-01-26 04:45:47 +03:00
|
|
|
// x-offset and expects "mX" to be at the left margin edge
|
|
|
|
x = align.mXOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-26 06:44:36 +03:00
|
|
|
// If the element is relatively positioned, then adjust x and y accordingly
|
2002-09-04 10:55:40 +04:00
|
|
|
if (NS_STYLE_POSITION_RELATIVE == aFrameRS.mStyleDisplay->mPosition) {
|
|
|
|
x += aFrameRS.mComputedOffsets.left;
|
|
|
|
y += aFrameRS.mComputedOffsets.top;
|
2000-01-26 06:44:36 +03:00
|
|
|
}
|
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
// Let frame know that we are reflowing it
|
2002-09-04 10:55:40 +04:00
|
|
|
mFrame->WillReflow(mPresContext);
|
1998-12-01 19:13:49 +03:00
|
|
|
|
1999-11-19 18:33:29 +03:00
|
|
|
// Position it and its view (if it has one)
|
2000-01-26 06:44:36 +03:00
|
|
|
// Note: Use "x" and "y" and not "mX" and "mY" because they more accurately
|
|
|
|
// represents where we think the block will be placed
|
2002-09-04 10:55:40 +04:00
|
|
|
mFrame->MoveTo(mPresContext, x, y);
|
|
|
|
nsContainerFrame::PositionFrameView(mPresContext, mFrame);
|
1999-11-19 18:33:29 +03:00
|
|
|
|
1999-03-08 22:25:03 +03:00
|
|
|
#ifdef DEBUG
|
1999-03-20 02:06:20 +03:00
|
|
|
mMetrics.width = nscoord(0xdeadbeef);
|
|
|
|
mMetrics.height = nscoord(0xdeadbeef);
|
|
|
|
mMetrics.ascent = nscoord(0xdeadbeef);
|
|
|
|
mMetrics.descent = nscoord(0xdeadbeef);
|
1999-03-08 22:25:03 +03:00
|
|
|
if (nsnull != mMetrics.maxElementSize) {
|
|
|
|
mMetrics.maxElementSize->width = nscoord(0xdeadbeef);
|
|
|
|
mMetrics.maxElementSize->height = nscoord(0xdeadbeef);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
// Adjust spacemanager 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.
|
1999-03-05 07:22:11 +03:00
|
|
|
nscoord tx = x - mOuterReflowState.mComputedBorderPadding.left;
|
|
|
|
nscoord ty = y - mOuterReflowState.mComputedBorderPadding.top;
|
1999-07-20 07:41:03 +04:00
|
|
|
mOuterReflowState.mSpaceManager->Translate(tx, ty);
|
2000-01-08 06:58:27 +03:00
|
|
|
|
|
|
|
// See if this is the child's initial reflow and we are supposed to
|
|
|
|
// compute our maximum width
|
2002-09-04 10:55:40 +04:00
|
|
|
if (mComputeMaximumWidth && (eReflowReason_Initial == aFrameRS.reason)) {
|
2002-08-19 08:41:57 +04:00
|
|
|
mOuterReflowState.mSpaceManager->PushState();
|
|
|
|
|
2002-09-04 10:55:40 +04:00
|
|
|
nscoord oldAvailableWidth = aFrameRS.availableWidth;
|
|
|
|
nscoord oldComputedWidth = aFrameRS.mComputedWidth;
|
2000-01-08 06:58:27 +03:00
|
|
|
|
2002-09-04 10:55:40 +04:00
|
|
|
aFrameRS.availableWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
aFrameRS.mComputedWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
rv = mFrame->Reflow(mPresContext, mMetrics, aFrameRS, aFrameReflowStatus);
|
2000-01-08 06:58:27 +03:00
|
|
|
|
|
|
|
// Update the reflow metrics with the maximum width
|
|
|
|
mMetrics.mMaximumWidth = mMetrics.width;
|
2000-05-14 08:56:25 +04:00
|
|
|
#ifdef NOISY_REFLOW
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("*** nsBlockReflowContext::ReflowBlock block %p returning max width %d\n",
|
2002-09-04 10:55:40 +04:00
|
|
|
mFrame, mMetrics.mMaximumWidth);
|
2000-05-14 08:56:25 +04:00
|
|
|
#endif
|
2000-01-08 06:58:27 +03:00
|
|
|
// The second reflow is just as a resize reflow with the constrained
|
|
|
|
// width
|
2002-09-04 10:55:40 +04:00
|
|
|
aFrameRS.availableWidth = oldAvailableWidth;
|
|
|
|
aFrameRS.mComputedWidth = oldComputedWidth;
|
|
|
|
aFrameRS.reason = eReflowReason_Resize;
|
2002-08-19 08:41:57 +04:00
|
|
|
|
|
|
|
mOuterReflowState.mSpaceManager->PopState();
|
2000-01-08 06:58:27 +03:00
|
|
|
}
|
2000-05-14 08:56:25 +04:00
|
|
|
|
2002-09-04 10:55:40 +04:00
|
|
|
rv = mFrame->Reflow(mPresContext, mMetrics, aFrameRS, aFrameReflowStatus);
|
1999-07-20 07:41:03 +04:00
|
|
|
mOuterReflowState.mSpaceManager->Translate(-tx, -ty);
|
1998-12-01 19:13:49 +03:00
|
|
|
|
1999-03-08 22:25:03 +03:00
|
|
|
#ifdef DEBUG
|
1999-03-24 18:42:38 +03:00
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus)) {
|
|
|
|
if (CRAZY_WIDTH(mMetrics.width) || CRAZY_HEIGHT(mMetrics.height)) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsBlockReflowContext: ");
|
2002-09-04 10:55:40 +04:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" metrics=%d,%d!\n", mMetrics.width, mMetrics.height);
|
1999-03-24 18:42:38 +03:00
|
|
|
}
|
|
|
|
if ((nsnull != mMetrics.maxElementSize) &&
|
|
|
|
((nscoord(0xdeadbeef) == mMetrics.maxElementSize->width) ||
|
|
|
|
(nscoord(0xdeadbeef) == mMetrics.maxElementSize->height))) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsBlockReflowContext: ");
|
2002-09-04 10:55:40 +04:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" didn't set max-element-size!\n");
|
1999-03-24 18:42:38 +03:00
|
|
|
mMetrics.maxElementSize->width = 0;
|
|
|
|
mMetrics.maxElementSize->height = 0;
|
|
|
|
}
|
|
|
|
#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.
|
|
|
|
if ((nsnull != mMetrics.maxElementSize) &&
|
|
|
|
((mMetrics.maxElementSize->width > mMetrics.width) ||
|
|
|
|
(mMetrics.maxElementSize->height > mMetrics.height))) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsBlockReflowContext: ");
|
2002-09-04 10:55:40 +04:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": WARNING: maxElementSize=%d,%d > metrics=%d,%d\n",
|
1999-03-24 18:42:38 +03:00
|
|
|
mMetrics.maxElementSize->width,
|
|
|
|
mMetrics.maxElementSize->height,
|
|
|
|
mMetrics.width, mMetrics.height);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if ((mMetrics.width == nscoord(0xdeadbeef)) ||
|
|
|
|
(mMetrics.height == nscoord(0xdeadbeef)) ||
|
|
|
|
(mMetrics.ascent == nscoord(0xdeadbeef)) ||
|
|
|
|
(mMetrics.descent == nscoord(0xdeadbeef))) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsBlockReflowContext: ");
|
2002-09-04 10:55:40 +04:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" didn't set whad %d,%d,%d,%d!\n",
|
1999-03-24 18:42:38 +03:00
|
|
|
mMetrics.width, mMetrics.height,
|
|
|
|
mMetrics.ascent, mMetrics.descent);
|
|
|
|
}
|
1999-03-20 02:06:20 +03:00
|
|
|
}
|
1999-03-08 22:25:03 +03:00
|
|
|
#endif
|
2002-07-01 21:43:02 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (nsBlockFrame::gNoisyMaxElementSize) {
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus)) {
|
|
|
|
if (nsnull != mMetrics.maxElementSize) {
|
|
|
|
printf(" ");
|
2002-09-04 10:55:40 +04:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2002-07-01 21:43:02 +04:00
|
|
|
printf(": maxElementSize=%d,%d wh=%d,%d\n",
|
|
|
|
mMetrics.maxElementSize->width,
|
|
|
|
mMetrics.maxElementSize->height,
|
|
|
|
mMetrics.width, mMetrics.height);
|
|
|
|
}
|
1999-03-24 18:42:38 +03:00
|
|
|
}
|
1999-03-20 22:38:50 +03:00
|
|
|
}
|
|
|
|
#endif
|
1999-03-05 07:22:11 +03:00
|
|
|
|
2002-09-04 10:55:40 +04:00
|
|
|
mFrame->GetFrameState(&state);
|
1998-12-01 19:13:49 +03:00
|
|
|
if (0 == (NS_FRAME_OUTSIDE_CHILDREN & state)) {
|
1999-12-06 18:49:53 +03: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 19:13:49 +03: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 10:55:40 +04:00
|
|
|
if (eReflowReason_Initial == aFrameRS.reason) {
|
|
|
|
mFrame->SetFrameState(state & ~NS_FRAME_FIRST_REFLOW);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2002-05-29 02:50:43 +04:00
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus) ||
|
2002-06-14 18:40:02 +04:00
|
|
|
(state & NS_FRAME_OUT_OF_FLOW)) {
|
1998-12-01 19:13:49 +03: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-29 02:50:43 +04:00
|
|
|
// a next-in-flow where it ends up), unless it is an out of flow frame.
|
1998-12-05 19:01:11 +03:00
|
|
|
if (NS_FRAME_IS_COMPLETE(aFrameReflowStatus)) {
|
1998-12-01 19:13:49 +03:00
|
|
|
nsIFrame* kidNextInFlow;
|
2002-09-04 10:55:40 +04:00
|
|
|
mFrame->GetNextInFlow(&kidNextInFlow);
|
1998-12-01 19:13:49 +03: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
|
|
|
|
// parent is not this because we are executing pullup code)
|
|
|
|
/* XXX promote DeleteChildsNextInFlow to nsIFrame to elminate this cast */
|
|
|
|
nsHTMLContainerFrame* parent;
|
2002-10-09 00:35:26 +04:00
|
|
|
kidNextInFlow->GetParent((nsIFrame**)&parent);
|
|
|
|
parent->DeleteNextInFlowChild(mPresContext, kidNextInFlow);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-03 07:32:13 +03: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 10:55:40 +04:00
|
|
|
if (NS_SHRINKWRAPWIDTH == aFrameRS.mComputedWidth) {
|
|
|
|
ComputeShrinkwrapMargins(aFrameRS.mStyleMargin, mMetrics.width, mMargin, mX);
|
2000-01-03 07:32:13 +03:00
|
|
|
}
|
|
|
|
|
1998-12-05 19:01:11 +03:00
|
|
|
return rv;
|
1998-12-01 19:13:49 +03: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 17:51:12 +03:00
|
|
|
nsBlockReflowContext::PlaceBlock(const nsHTMLReflowState& aReflowState,
|
|
|
|
PRBool aForceFit,
|
|
|
|
const nsMargin& aComputedOffsets,
|
|
|
|
nsCollapsingMargin& aBottomMarginResult,
|
|
|
|
nsRect& aInFlowBounds,
|
|
|
|
nsRect& aCombinedRect)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
1999-03-27 04:22:45 +03:00
|
|
|
// Compute collapsed bottom margin value
|
2001-10-25 05:08:40 +04:00
|
|
|
aBottomMarginResult = mMetrics.mCarriedOutBottomMargin;
|
|
|
|
aBottomMarginResult.Include(mMargin.bottom);
|
1998-12-01 19:13:49 +03:00
|
|
|
|
|
|
|
// See if the block will fit in the available space
|
1999-03-22 23:45:26 +03:00
|
|
|
PRBool fits = PR_TRUE;
|
|
|
|
nscoord x = mX;
|
|
|
|
nscoord y = mY;
|
2000-06-30 02:03:42 +04:00
|
|
|
// When deciding whether it's empty we also need to take into
|
1999-12-06 18:49:53 +03:00
|
|
|
// account the overflow area
|
2001-07-04 06:00:05 +04:00
|
|
|
|
|
|
|
// XXXldb What should really matter is whether there exist non-
|
|
|
|
// empty frames in the block (with appropriate whitespace munging).
|
|
|
|
// Consider the case where we clip off the overflow with
|
|
|
|
// 'overflow: hidden' (which doesn't currently affect mOverflowArea,
|
|
|
|
// but probably should.
|
2000-06-15 03:15:59 +04:00
|
|
|
if ((0 == mMetrics.height) && (0 == mMetrics.mOverflowArea.height))
|
|
|
|
{
|
2000-06-30 02:03:42 +04:00
|
|
|
// Collapse the bottom margin with the top margin that was already
|
|
|
|
// applied.
|
2001-10-25 05:08:40 +04:00
|
|
|
aBottomMarginResult.Include(mTopMargin);
|
1999-05-11 02:28:04 +04:00
|
|
|
#ifdef NOISY_VERTICAL_MARGINS
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ");
|
2000-06-30 02:03:42 +04:00
|
|
|
nsFrame::ListTag(stdout, mOuterReflowState.frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": ");
|
2000-06-30 02:03:42 +04:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" -- collapsing top & bottom margin together; y=%d spaceY=%d\n",
|
2000-06-30 02:03:42 +04:00
|
|
|
y, mSpace.y);
|
1999-05-11 02:28:04 +04:00
|
|
|
#endif
|
1999-03-30 03:45:36 +04:00
|
|
|
|
1999-05-11 02:28:04 +04:00
|
|
|
y = mSpace.y;
|
|
|
|
|
1999-11-19 18:33:29 +03:00
|
|
|
// Now place the frame and complete the reflow process
|
2001-12-07 17:51:12 +03:00
|
|
|
nsContainerFrame::FinishReflowChild(mFrame, mPresContext, &aReflowState, mMetrics, x, y, 0);
|
2002-10-08 05:52:34 +04:00
|
|
|
|
|
|
|
// Empty blocks do not have anything special done to them and they
|
|
|
|
// always fit. Note: don't force the width to 0
|
|
|
|
aInFlowBounds = nsRect(x, y, mMetrics.width, 0);
|
1999-03-30 03:45:36 +04:00
|
|
|
|
1999-03-27 04:22:45 +03:00
|
|
|
// Retain combined area information in case we contain a floater
|
|
|
|
// and nothing else.
|
1999-12-06 18:49:53 +03:00
|
|
|
aCombinedRect = mMetrics.mOverflowArea;
|
1999-03-22 23:45:26 +03:00
|
|
|
aCombinedRect.x += x;
|
|
|
|
aCombinedRect.y += y;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-03-05 07:22:11 +03:00
|
|
|
// See if the frame fit. If its the first frame then it always
|
|
|
|
// fits.
|
2000-06-15 03:15:59 +04:00
|
|
|
if (aForceFit || (y + mMetrics.height <= mSpace.YMost()))
|
|
|
|
{
|
2000-01-26 04:45:47 +03: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;
|
1998-12-01 19:13:49 +03:00
|
|
|
|
1999-10-13 03:24:51 +04:00
|
|
|
// Update the in-flow bounds rectangle
|
1998-12-17 21:52:45 +03:00
|
|
|
aInFlowBounds.SetRect(x, y,
|
1999-10-13 03:24:51 +04:00
|
|
|
mMetrics.width,
|
1998-12-17 21:52:45 +03:00
|
|
|
mMetrics.height);
|
1998-12-01 19:13:49 +03:00
|
|
|
|
|
|
|
// Apply CSS relative positioning to update x,y coordinates
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleDisplay* styleDisp;
|
|
|
|
mFrame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&)styleDisp);
|
|
|
|
if (NS_STYLE_POSITION_RELATIVE == styleDisp->mPosition) {
|
1999-01-22 07:12:03 +03:00
|
|
|
x += aComputedOffsets.left;
|
|
|
|
y += aComputedOffsets.top;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2002-12-19 03:23:00 +03:00
|
|
|
// Compute combined-rect in callers coordinate system. The value
|
|
|
|
// returned in the reflow metrics is relative to the child
|
|
|
|
// frame. This includes relative positioning and the result should
|
|
|
|
// be used only for painting and for 'overflow' handling.
|
|
|
|
aCombinedRect.x = mMetrics.mOverflowArea.x + x;
|
|
|
|
aCombinedRect.y = mMetrics.mOverflowArea.y + y;
|
|
|
|
aCombinedRect.width = mMetrics.mOverflowArea.width;
|
|
|
|
aCombinedRect.height = mMetrics.mOverflowArea.height;
|
|
|
|
|
1999-11-19 18:33:29 +03:00
|
|
|
// Now place the frame and complete the reflow process
|
2001-12-07 17:51:12 +03:00
|
|
|
nsContainerFrame::FinishReflowChild(mFrame, mPresContext, &aReflowState, mMetrics, x, y, 0);
|
1998-12-01 19:13:49 +03:00
|
|
|
|
1998-12-17 21:52:45 +03:00
|
|
|
// Adjust the max-element-size in the metrics to take into
|
|
|
|
// account the margins around the block element. Note that we
|
|
|
|
// use the collapsed top and bottom margin values.
|
1999-03-05 07:22:11 +03:00
|
|
|
if (nsnull != mMetrics.maxElementSize) {
|
1998-12-17 21:52:45 +03:00
|
|
|
nsSize* m = mMetrics.maxElementSize;
|
2000-08-12 00:08:15 +04:00
|
|
|
nsMargin maxElemMargin = mMargin;
|
|
|
|
|
|
|
|
if (NS_SHRINKWRAPWIDTH == mComputedWidth) {
|
|
|
|
nscoord dummyXOffset;
|
|
|
|
// Base the margins on the max-element size
|
2001-02-07 12:57:26 +03:00
|
|
|
ComputeShrinkwrapMargins(mStyleMargin, m->width, maxElemMargin, dummyXOffset);
|
2000-08-12 00:08:15 +04:00
|
|
|
}
|
|
|
|
|
1999-03-05 07:22:11 +03:00
|
|
|
// Do not allow auto margins to impact the max-element size
|
|
|
|
// since they are springy and don't really count!
|
2002-09-04 04:10:43 +04:00
|
|
|
if ((eStyleUnit_Auto != mStyleMargin->mMargin.GetLeftUnit()) &&
|
|
|
|
(eStyleUnit_Null != mStyleMargin->mMargin.GetLeftUnit())) {
|
2000-08-12 00:08:15 +04:00
|
|
|
m->width += maxElemMargin.left;
|
1999-03-05 07:22:11 +03:00
|
|
|
}
|
2002-09-04 04:10:43 +04:00
|
|
|
if ((eStyleUnit_Auto != mStyleMargin->mMargin.GetRightUnit()) &&
|
|
|
|
(eStyleUnit_Null != mStyleMargin->mMargin.GetRightUnit())) {
|
2000-08-12 00:08:15 +04:00
|
|
|
m->width += maxElemMargin.right;
|
1999-03-05 07:22:11 +03:00
|
|
|
}
|
|
|
|
|
2001-07-04 06:00:05 +04:00
|
|
|
#if 0 // XXX_fix_me
|
1999-03-05 07:22:11 +03:00
|
|
|
// Margin height should affect the max-element height (since
|
|
|
|
// auto top/bottom margins are always zero)
|
2001-07-04 06:00:05 +04:00
|
|
|
|
|
|
|
// XXXldb Should it?
|
2002-10-08 05:52:34 +04:00
|
|
|
m->height += mTopMargin.get() + mBottomMargin;
|
1999-03-27 04:22:45 +03:00
|
|
|
#endif
|
1998-12-17 21:52:45 +03:00
|
|
|
}
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-11-19 18:33:29 +03:00
|
|
|
// Send the DidReflow() notification, but don't bother placing
|
|
|
|
// the frame
|
2001-12-07 17:51:12 +03:00
|
|
|
mFrame->DidReflow(mPresContext, &aReflowState, NS_FRAME_REFLOW_FINISHED);
|
1998-12-01 19:13:49 +03:00
|
|
|
fits = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fits;
|
|
|
|
}
|
|
|
|
|
1999-03-05 07:22:11 +03:00
|
|
|
// If we have an inherited margin its possible that its auto all the
|
|
|
|
// way up to the top of the tree. If that is the case, we need to know
|
|
|
|
// it.
|
|
|
|
nsStyleUnit
|
|
|
|
nsBlockReflowContext::GetRealMarginLeftUnit()
|
|
|
|
{
|
|
|
|
nsStyleUnit unit = eStyleUnit_Inherit;
|
2002-10-09 05:46:15 +04:00
|
|
|
nsCOMPtr<nsIStyleContext> sc;
|
|
|
|
mFrame->GetStyleContext(getter_AddRefs(sc));
|
|
|
|
while (sc && eStyleUnit_Inherit == unit) {
|
1999-03-05 07:22:11 +03:00
|
|
|
// Get parent style context
|
2002-10-09 05:46:15 +04:00
|
|
|
sc = sc->GetParent();
|
|
|
|
if (sc) {
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleMargin* margin = (const nsStyleMargin*)
|
|
|
|
sc->GetStyleData(eStyleStruct_Margin);
|
|
|
|
unit = margin->mMargin.GetLeftUnit();
|
1999-03-05 07:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have an inherited margin its possible that its auto all the
|
|
|
|
// way up to the top of the tree. If that is the case, we need to know
|
|
|
|
// it.
|
|
|
|
nsStyleUnit
|
|
|
|
nsBlockReflowContext::GetRealMarginRightUnit()
|
|
|
|
{
|
|
|
|
nsStyleUnit unit = eStyleUnit_Inherit;
|
2002-10-09 05:46:15 +04:00
|
|
|
nsCOMPtr<nsIStyleContext> sc;
|
|
|
|
mFrame->GetStyleContext(getter_AddRefs(sc));
|
|
|
|
while (sc && eStyleUnit_Inherit == unit) {
|
1999-03-05 07:22:11 +03:00
|
|
|
// Get parent style context
|
2002-10-09 05:46:15 +04:00
|
|
|
sc = sc->GetParent();
|
|
|
|
if (sc) {
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleMargin* margin = (const nsStyleMargin*)
|
|
|
|
sc->GetStyleData(eStyleStruct_Margin);
|
|
|
|
unit = margin->mMargin.GetRightUnit();
|
1999-03-05 07:22:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return unit;
|
|
|
|
}
|