2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-10-25 05:08:40 +04:00
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-12-01 19:13:49 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-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.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
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
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
|
|
|
/* class that a parent frame uses to reflow a block frame */
|
|
|
|
|
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"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2004-02-24 00:29:06 +03:00
|
|
|
#include "nsFrameManager.h"
|
1999-04-13 05:15:16 +04:00
|
|
|
#include "nsIContent.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.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"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1999-07-14 21:27:24 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2004-11-25 17:51:00 +03:00
|
|
|
#include "nsLayoutUtils.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
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBlockReflowContext::nsBlockReflowContext(nsPresContext* aPresContext,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
const nsHTMLReflowState& aParentRS)
|
1998-12-01 19:13:49 +03:00
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mOuterReflowState(aParentRS),
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
mMetrics()
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
1999-03-27 04:22:45 +03:00
|
|
|
}
|
|
|
|
|
2005-08-03 00:05:52 +04:00
|
|
|
static nsIFrame* DescendIntoBlockLevelFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIAtom* type = aFrame->GetType();
|
2006-12-26 20:47:52 +03:00
|
|
|
if (type == nsGkAtoms::columnSetFrame)
|
2005-08-03 00:05:52 +04:00
|
|
|
return DescendIntoBlockLevelFrame(aFrame->GetFirstChild(nsnull));
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
2004-11-25 17:51:00 +03:00
|
|
|
PRBool
|
|
|
|
nsBlockReflowContext::ComputeCollapsedTopMargin(const nsHTMLReflowState& aRS,
|
2006-02-27 07:15:05 +03:00
|
|
|
nsCollapsingMargin* aMargin, nsIFrame* aClearanceFrame,
|
|
|
|
PRBool* aMayNeedRetry, PRBool* aBlockIsEmpty)
|
1999-03-27 04:22:45 +03:00
|
|
|
{
|
2004-11-25 17:51:00 +03:00
|
|
|
// Include frame's top margin
|
|
|
|
aMargin->Include(aRS.mComputedMargin.top);
|
2001-10-25 05:08:40 +04:00
|
|
|
|
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);
|
2004-11-25 17:51:00 +03:00
|
|
|
printf(": %d => %d\n", aRS.mComputedMargin.top, aMargin->get());
|
2001-10-25 05:08:40 +04:00
|
|
|
#endif
|
1999-03-27 04:22:45 +03:00
|
|
|
|
2004-11-25 17:51:00 +03:00
|
|
|
PRBool dirtiedLine = PR_FALSE;
|
2006-02-27 07:15:05 +03:00
|
|
|
PRBool setBlockIsEmpty = PR_FALSE;
|
2004-11-25 17:51:00 +03: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 04:22:45 +03:00
|
|
|
// 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.
|
2005-08-03 00:05:52 +04:00
|
|
|
nsIFrame* frame = DescendIntoBlockLevelFrame(aRS.frame);
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* prescontext = frame->PresContext();
|
2002-11-28 22:29:28 +03:00
|
|
|
if (0 == aRS.mComputedBorderPadding.top &&
|
2008-07-14 02:10:23 +04:00
|
|
|
nsLayoutUtils::GetAsBlock(frame) &&
|
2007-02-19 02:53:25 +03:00
|
|
|
!nsBlockFrame::BlockIsMarginRoot(frame)) {
|
2005-03-23 06:35:08 +03: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.
|
2007-07-08 11:08:04 +04:00
|
|
|
for (nsBlockFrame* block = static_cast<nsBlockFrame*>(frame);
|
|
|
|
block; block = static_cast<nsBlockFrame*>(block->GetNextInFlow())) {
|
2005-03-23 06:35:08 +03:00
|
|
|
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 17:51:00 +03:00
|
|
|
}
|
2005-03-23 06:35:08 +03: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 07:15:05 +03:00
|
|
|
PRBool isEmpty;
|
|
|
|
if (line->IsInline()) {
|
|
|
|
isEmpty = line->IsEmpty();
|
|
|
|
} else {
|
2005-08-03 00:05:52 +04:00
|
|
|
nsIFrame* kid = line->mFirstChild;
|
|
|
|
if (kid == aClearanceFrame) {
|
2005-03-23 06:35:08 +03: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
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// state for it.
|
2005-08-03 00:05:52 +04: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");
|
2007-08-02 22:08:05 +04:00
|
|
|
nsSize availSpace(aRS.ComputedWidth(), aRS.ComputedHeight());
|
2005-08-03 00:05:52 +04:00
|
|
|
outerReflowState = new nsHTMLReflowState(prescontext,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
aRS, frame, availSpace);
|
2005-08-03 00:05:52 +04:00
|
|
|
if (!outerReflowState)
|
|
|
|
goto done;
|
2005-03-23 06:35:08 +03:00
|
|
|
}
|
2005-08-03 00:05:52 +04:00
|
|
|
{
|
2007-01-26 03:05:12 +03:00
|
|
|
nsSize availSpace(outerReflowState->ComputedWidth(),
|
2007-08-02 22:08:05 +04:00
|
|
|
outerReflowState->ComputedHeight());
|
2005-08-03 00:05:52 +04:00
|
|
|
nsHTMLReflowState innerReflowState(prescontext,
|
|
|
|
*outerReflowState, kid,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
availSpace);
|
2005-08-03 00:05:52 +04:00
|
|
|
// 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 07:15:05 +03:00
|
|
|
if (ComputeCollapsedTopMargin(innerReflowState, aMargin, aClearanceFrame, aMayNeedRetry, &isEmpty)) {
|
2005-08-03 00:05:52 +04:00
|
|
|
line->MarkDirty();
|
|
|
|
dirtiedLine = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (isEmpty)
|
|
|
|
aMargin->Include(innerReflowState.mComputedMargin.bottom);
|
|
|
|
}
|
|
|
|
if (outerReflowState != &aRS) {
|
2007-07-08 11:08:04 +04:00
|
|
|
delete const_cast<nsHTMLReflowState*>(outerReflowState);
|
2005-03-23 06:35:08 +03:00
|
|
|
}
|
|
|
|
}
|
2006-02-27 07:15:05 +03:00
|
|
|
if (!isEmpty) {
|
|
|
|
if (!setBlockIsEmpty && aBlockIsEmpty) {
|
|
|
|
setBlockIsEmpty = PR_TRUE;
|
|
|
|
*aBlockIsEmpty = PR_FALSE;
|
|
|
|
}
|
2005-03-23 06:35:08 +03:00
|
|
|
goto done;
|
2006-02-27 07:15:05 +03: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 17:51:00 +03:00
|
|
|
}
|
1999-03-27 04:22:45 +03:00
|
|
|
}
|
|
|
|
}
|
2005-03-23 06:35:08 +03:00
|
|
|
done:
|
|
|
|
;
|
1999-03-27 04:22:45 +03:00
|
|
|
}
|
2006-02-27 07:15:05 +03:00
|
|
|
|
|
|
|
if (!setBlockIsEmpty && aBlockIsEmpty) {
|
|
|
|
*aBlockIsEmpty = aRS.frame->IsEmpty();
|
|
|
|
}
|
2004-11-25 17:51:00 +03:00
|
|
|
|
1999-03-27 04:22:45 +03:00
|
|
|
#ifdef NOISY_VERTICAL_MARGINS
|
|
|
|
nsFrame::ListTag(stdout, aRS.frame);
|
2005-01-27 23:54:27 +03:00
|
|
|
printf(": => %d\n", aMargin->get());
|
1999-03-27 04:22:45 +03:00
|
|
|
#endif
|
2004-11-25 17:51:00 +03:00
|
|
|
|
|
|
|
return dirtiedLine;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2000-06-20 07:47:49 +04:00
|
|
|
nsresult
|
2002-09-04 10:55:40 +04:00
|
|
|
nsBlockReflowContext::ReflowBlock(const nsRect& aSpace,
|
|
|
|
PRBool aApplyTopMargin,
|
2004-11-25 17:51:00 +03:00
|
|
|
nsCollapsingMargin& aPrevMargin,
|
|
|
|
nscoord aClearance,
|
2002-09-04 10:55:40 +04:00
|
|
|
PRBool aIsAdjacentWithTop,
|
2007-08-21 00:07:50 +04:00
|
|
|
nsLineBox* aLine,
|
2002-09-04 10:55:40 +04:00
|
|
|
nsHTMLReflowState& aFrameRS,
|
2007-10-02 09:57:45 +04:00
|
|
|
nsReflowStatus& aFrameReflowStatus,
|
|
|
|
nsBlockReflowState& aState)
|
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;
|
|
|
|
|
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
|
|
|
}
|
1999-03-05 07:22:11 +03:00
|
|
|
|
1999-03-27 04:22:45 +03:00
|
|
|
if (aApplyTopMargin) {
|
2004-11-25 17:51:00 +03:00
|
|
|
mTopMargin = aPrevMargin;
|
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);
|
2004-11-25 17:51:00 +03:00
|
|
|
printf(" margin => %d, clearance => %d\n", mTopMargin.get(), aClearance);
|
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) {
|
2004-11-25 17:51:00 +03:00
|
|
|
aFrameRS.availableHeight -= mTopMargin.get() + aClearance;
|
1999-03-27 04:22:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-21 00:07:50 +04:00
|
|
|
nscoord tx = 0, ty = 0;
|
|
|
|
// The values of x and y do not matter for floats, so don't bother calculating
|
|
|
|
// them. Floats are guaranteed to have their own space manager, so tx and ty
|
|
|
|
// don't matter. mX and mY don't matter becacuse they are only used in
|
|
|
|
// PlaceBlock, which is not used for floats.
|
|
|
|
if (aLine) {
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
nscoord x = mSpace.x + aFrameRS.mComputedMargin.left;
|
|
|
|
nscoord y = mSpace.y + mTopMargin.get() + aClearance;
|
|
|
|
|
|
|
|
if ((mFrame->GetStateBits() & NS_BLOCK_SPACE_MGR) == 0)
|
|
|
|
aFrameRS.mBlockDelta = mOuterReflowState.mBlockDelta + y - aLine->mBounds.y;
|
|
|
|
|
|
|
|
mX = x;
|
|
|
|
mY = y;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
tx = x - mOuterReflowState.mComputedBorderPadding.left;
|
|
|
|
ty = y - mOuterReflowState.mComputedBorderPadding.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-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);
|
1999-03-08 22:25:03 +03:00
|
|
|
#endif
|
|
|
|
|
1999-07-20 07:41:03 +04:00
|
|
|
mOuterReflowState.mSpaceManager->Translate(tx, ty);
|
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 ((mMetrics.width == nscoord(0xdeadbeef)) ||
|
2007-01-23 07:06:56 +03:00
|
|
|
(mMetrics.height == nscoord(0xdeadbeef))) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsBlockReflowContext: ");
|
2002-09-04 10:55:40 +04:00
|
|
|
nsFrame::ListTag(stdout, mFrame);
|
2007-01-23 07:06:56 +03:00
|
|
|
printf(" didn't set w/h %d,%d!\n", mMetrics.width, mMetrics.height);
|
1999-03-24 18:42:38 +03:00
|
|
|
}
|
1999-03-20 02:06:20 +03:00
|
|
|
}
|
1999-03-08 22:25:03 +03:00
|
|
|
#endif
|
1999-03-05 07:22:11 +03:00
|
|
|
|
2003-06-27 22:13:48 +04:00
|
|
|
if (!(NS_FRAME_OUTSIDE_CHILDREN & mFrame->GetStateBits())) {
|
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
|
|
|
}
|
|
|
|
|
2002-05-29 02:50:43 +04:00
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus) ||
|
2003-06-27 22:13:48 +04:00
|
|
|
(mFrame->GetStateBits() & 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.
|
2007-07-26 08:03:29 +04:00
|
|
|
if (NS_FRAME_IS_FULLY_COMPLETE(aFrameReflowStatus)) {
|
2004-09-14 06:28:03 +04:00
|
|
|
nsIFrame* kidNextInFlow = mFrame->GetNextInFlow();
|
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
|
2005-03-23 06:35:08 +03: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 19:13:49 +03:00
|
|
|
/* XXX promote DeleteChildsNextInFlow to nsIFrame to elminate this cast */
|
2007-10-02 09:57:45 +04:00
|
|
|
aState.mOverflowTracker.Finish(mFrame);
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsHTMLContainerFrame*>(kidNextInFlow->GetParent())
|
2003-06-27 22:13:48 +04:00
|
|
|
->DeleteNextInFlowChild(mPresContext, kidNextInFlow);
|
1998-12-01 19:13:49 +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,
|
2004-11-25 17:51:00 +03:00
|
|
|
nsLineBox* aLine,
|
2001-12-07 17:51:12 +03:00
|
|
|
nsCollapsingMargin& aBottomMarginResult,
|
|
|
|
nsRect& aInFlowBounds,
|
2005-03-23 06:35:08 +03:00
|
|
|
nsRect& aCombinedRect,
|
|
|
|
nsReflowStatus aReflowStatus)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
2005-03-23 06:35:08 +03:00
|
|
|
// Compute collapsed bottom margin value.
|
|
|
|
if (NS_FRAME_IS_COMPLETE(aReflowStatus)) {
|
|
|
|
aBottomMarginResult = mMetrics.mCarriedOutBottomMargin;
|
2007-08-21 00:07:50 +04:00
|
|
|
aBottomMarginResult.Include(aReflowState.mComputedMargin.bottom);
|
2005-03-23 06:35:08 +03:00
|
|
|
} else {
|
|
|
|
// The used bottom-margin is set to zero above a break.
|
|
|
|
aBottomMarginResult.Zero();
|
|
|
|
}
|
1998-12-01 19:13:49 +03:00
|
|
|
|
1999-03-22 23:45:26 +03:00
|
|
|
nscoord x = mX;
|
|
|
|
nscoord y = mY;
|
2005-02-02 04:33:20 +03:00
|
|
|
nscoord backupContainingBlockAdvance = 0;
|
|
|
|
|
2004-11-25 17:51:00 +03: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 23:54:27 +03: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.
|
2006-03-27 01:02:19 +04:00
|
|
|
// Mark the frame as non-dirty; it has been reflowed (or we wouldn't
|
|
|
|
// be here), and we don't want to assert in CachedIsEmpty()
|
|
|
|
mFrame->RemoveStateBits(NS_FRAME_IS_DIRTY);
|
2005-03-23 06:35:08 +03:00
|
|
|
PRBool empty = 0 == mMetrics.height && aLine->CachedIsEmpty();
|
|
|
|
if (empty) {
|
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);
|
2005-03-23 06:35:08 +03:00
|
|
|
|
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
|
2005-01-27 23:54:27 +03: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 04:33:20 +03: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 19:13:49 +03:00
|
|
|
}
|
2000-08-12 00:08:15 +04:00
|
|
|
|
2005-03-23 06:35:08 +03: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 17:51:12 +03:00
|
|
|
mFrame->DidReflow(mPresContext, &aReflowState, NS_FRAME_REFLOW_FINISHED);
|
2005-03-23 06:35:08 +03:00
|
|
|
return PR_FALSE;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-23 06:35:08 +03:00
|
|
|
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) {
|
2008-04-18 11:40:35 +04:00
|
|
|
x += aReflowState.mComputedOffsets.left;
|
|
|
|
y += aReflowState.mComputedOffsets.top;
|
2005-01-26 01:29:59 +03:00
|
|
|
}
|
2005-03-23 06:35:08 +03: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-26 01:29:59 +03:00
|
|
|
|
2005-03-23 06:35:08 +03:00
|
|
|
return PR_TRUE;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|