2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-09-24 00:10:40 +04:00
|
|
|
|
2006-03-29 22:29:03 +04:00
|
|
|
/* state used in reflow of block frames */
|
|
|
|
|
2016-07-21 13:36:36 +03:00
|
|
|
#include "BlockReflowInput.h"
|
2013-09-25 05:43:43 +04:00
|
|
|
|
2017-04-15 01:31:43 +03:00
|
|
|
#include <algorithm>
|
2015-06-16 02:36:11 +03:00
|
|
|
#include "LayoutLogging.h"
|
2001-05-01 08:22:57 +04:00
|
|
|
#include "nsBlockFrame.h"
|
|
|
|
#include "nsLineLayout.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2013-10-02 01:00:38 +04:00
|
|
|
#include "nsIFrameInlines.h"
|
2010-08-06 08:59:19 +04:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2015-06-16 02:36:11 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2014-12-19 19:28:43 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-09-09 20:42:14 +03:00
|
|
|
#include "mozilla/StaticPrefs_layout.h"
|
2017-04-15 01:31:43 +03:00
|
|
|
#include "TextOverflow.h"
|
2002-03-08 23:25:54 +03:00
|
|
|
|
2001-05-01 08:22:57 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
# include "nsBlockDebugFlags.h"
|
|
|
|
#endif
|
1998-06-24 21:52:42 +04:00
|
|
|
|
2010-08-06 08:59:19 +04:00
|
|
|
using namespace mozilla;
|
2012-01-25 05:21:29 +04:00
|
|
|
using namespace mozilla::layout;
|
2010-08-06 08:59:19 +04:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
BlockReflowInput::BlockReflowInput(const ReflowInput& aReflowInput,
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* aPresContext,
|
2014-06-20 13:55:35 +04:00
|
|
|
nsBlockFrame* aFrame, bool aBStartMarginRoot,
|
|
|
|
bool aBEndMarginRoot,
|
2013-07-25 19:34:12 +04:00
|
|
|
bool aBlockNeedsFloatManager,
|
2014-06-20 13:55:35 +04:00
|
|
|
nscoord aConsumedBSize)
|
1999-04-03 22:59:01 +04:00
|
|
|
: mBlock(aFrame),
|
|
|
|
mPresContext(aPresContext),
|
2016-07-21 13:36:39 +03:00
|
|
|
mReflowInput(aReflowInput),
|
|
|
|
mContentArea(aReflowInput.GetWritingMode()),
|
2012-07-30 18:20:58 +04:00
|
|
|
mPushedFloats(nullptr),
|
|
|
|
mOverflowTracker(nullptr),
|
2020-04-07 21:44:17 +03:00
|
|
|
mBorderPadding(mReflowInput.ComputedLogicalBorderPadding().ApplySkipSides(
|
|
|
|
aFrame->GetLogicalSkipSides(&aReflowInput))),
|
2014-06-20 13:55:35 +04:00
|
|
|
mPrevBEndMargin(),
|
2000-04-17 18:40:46 +04:00
|
|
|
mLineNumber(0),
|
2016-09-03 21:46:58 +03:00
|
|
|
mFloatBreakType(StyleClear::None),
|
2014-06-20 13:55:35 +04:00
|
|
|
mConsumedBSize(aConsumedBSize) {
|
2019-08-15 19:49:14 +03:00
|
|
|
NS_ASSERTION(mConsumedBSize != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"The consumed block-size should be constrained!");
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = aReflowInput.GetWritingMode();
|
2005-04-26 06:26:12 +04:00
|
|
|
|
2015-02-11 12:43:03 +03:00
|
|
|
// Note that mContainerSize is the physical size, needed to
|
|
|
|
// convert logical block-coordinates in vertical-rl writing mode
|
|
|
|
// (measured from a RHS origin) to physical coordinates within the
|
|
|
|
// containing block.
|
2016-07-21 13:36:39 +03:00
|
|
|
// If aReflowInput doesn't have a constrained ComputedWidth(), we set
|
2015-02-11 12:43:03 +03:00
|
|
|
// mContainerSize.width to zero, which means lines will be positioned
|
|
|
|
// (physically) incorrectly; we will fix them up at the end of
|
|
|
|
// nsBlockFrame::Reflow, after we know the total block-size of the
|
|
|
|
// frame.
|
2016-07-21 13:36:39 +03:00
|
|
|
mContainerSize.width = aReflowInput.ComputedWidth();
|
2015-02-11 12:43:03 +03:00
|
|
|
if (mContainerSize.width == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
mContainerSize.width = 0;
|
2014-11-13 11:58:03 +03:00
|
|
|
}
|
|
|
|
|
2015-02-11 12:43:03 +03:00
|
|
|
mContainerSize.width += mBorderPadding.LeftRight(wm);
|
|
|
|
|
|
|
|
// For now at least, we don't do that fix-up for mContainerHeight.
|
|
|
|
// It's only used in nsBidiUtils::ReorderFrames for vertical rtl
|
|
|
|
// writing modes, which aren't fully supported for the time being.
|
2016-07-21 13:36:39 +03:00
|
|
|
mContainerSize.height =
|
|
|
|
aReflowInput.ComputedHeight() + mBorderPadding.TopBottom(wm);
|
2014-06-20 13:55:35 +04:00
|
|
|
|
2019-10-10 16:38:07 +03:00
|
|
|
if (aBStartMarginRoot || 0 != mBorderPadding.BStart(wm)) {
|
2016-08-12 10:28:45 +03:00
|
|
|
mFlags.mIsBStartMarginRoot = true;
|
|
|
|
mFlags.mShouldApplyBStartMargin = true;
|
2000-01-13 05:05:31 +03:00
|
|
|
}
|
2019-10-10 16:38:07 +03:00
|
|
|
if (aBEndMarginRoot || 0 != mBorderPadding.BEnd(wm)) {
|
2016-08-12 10:28:45 +03:00
|
|
|
mFlags.mIsBEndMarginRoot = true;
|
2000-01-13 05:05:31 +03:00
|
|
|
}
|
2009-01-05 03:39:54 +03:00
|
|
|
if (aBlockNeedsFloatManager) {
|
2016-08-12 10:28:45 +03:00
|
|
|
mFlags.mBlockNeedsFloatManager = true;
|
2007-02-19 02:53:25 +03:00
|
|
|
}
|
2019-05-09 05:32:30 +03:00
|
|
|
|
|
|
|
// We need to check mInsideLineClamp here since we are here before the block
|
|
|
|
// has been reflowed, and CanHaveOverflowMarkers() relies on the block's
|
|
|
|
// NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS state bit to know if a -webkit-line-clamp
|
|
|
|
// ellipsis is set on one of the block's lines. And that state bit is only
|
|
|
|
// set after we do the bsize measuring reflow of the flex item.
|
|
|
|
mFlags.mCanHaveOverflowMarkers =
|
|
|
|
aReflowInput.mFlags.mInsideLineClamp ||
|
|
|
|
css::TextOverflow::CanHaveOverflowMarkers(mBlock);
|
2016-08-12 10:28:45 +03:00
|
|
|
|
2017-02-09 11:59:07 +03:00
|
|
|
MOZ_ASSERT(FloatManager(),
|
|
|
|
"Float manager should be valid when creating BlockReflowInput!");
|
|
|
|
|
|
|
|
// Save the coordinate system origin for later.
|
|
|
|
FloatManager()->GetTranslation(mFloatManagerI, mFloatManagerB);
|
|
|
|
FloatManager()->PushState(&mFloatManagerStateBefore); // never popped
|
1998-09-24 00:10:40 +04:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
mNextInFlow = static_cast<nsBlockFrame*>(mBlock->GetNextInFlow());
|
1998-09-24 00:10:40 +04:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
LAYOUT_WARN_IF_FALSE(NS_UNCONSTRAINEDSIZE != aReflowInput.ComputedISize(),
|
2015-06-16 02:36:12 +03:00
|
|
|
"have unconstrained width; this should only result "
|
|
|
|
"from very large sizes, not attempts at intrinsic "
|
|
|
|
"width calculation");
|
2016-07-21 13:36:39 +03:00
|
|
|
mContentArea.ISize(wm) = aReflowInput.ComputedISize();
|
1998-12-30 20:50:00 +03:00
|
|
|
|
2019-08-21 22:53:08 +03:00
|
|
|
// Compute content area block-size. Unlike the inline-size, if we have a
|
|
|
|
// specified style block-size, we ignore it since extra content is managed by
|
|
|
|
// the "overflow" property. When we don't have a specified style block-size,
|
|
|
|
// then we may end up limiting our block-size if the available block-size is
|
|
|
|
// constrained (this situation occurs when we are paginated).
|
2016-07-21 13:36:39 +03:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowInput.AvailableBSize()) {
|
2019-08-21 22:53:08 +03:00
|
|
|
// We are in a paginated situation. The block-end edge is just inside the
|
|
|
|
// block-end border and padding. The content area block-size doesn't include
|
|
|
|
// either border or padding edge.
|
2020-03-30 21:03:49 +03:00
|
|
|
mContentArea.BSize(wm) = std::max(
|
|
|
|
0, aReflowInput.AvailableBSize() - mBorderPadding.BStartEnd(wm));
|
1999-03-23 07:28:20 +03:00
|
|
|
} else {
|
2019-08-21 22:53:08 +03:00
|
|
|
// When we are not in a paginated situation, then we always use a
|
|
|
|
// unconstrained block-size.
|
2020-03-30 21:03:49 +03:00
|
|
|
mContentArea.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
1999-03-05 07:21:32 +03:00
|
|
|
}
|
2014-06-20 13:55:35 +04:00
|
|
|
mContentArea.IStart(wm) = mBorderPadding.IStart(wm);
|
|
|
|
mBCoord = mContentArea.BStart(wm) = mBorderPadding.BStart(wm);
|
1998-12-05 19:02:08 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mPrevChild = nullptr;
|
2016-10-24 10:01:25 +03:00
|
|
|
mCurrentLine = aFrame->LinesEnd();
|
1999-03-05 07:21:32 +03:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
mMinLineHeight = aReflowInput.CalcLineHeight();
|
1998-09-24 00:10:40 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:36 +03:00
|
|
|
void BlockReflowInput::ComputeReplacedBlockOffsetsForFloats(
|
2014-10-22 02:16:13 +04:00
|
|
|
nsIFrame* aFrame, const LogicalRect& aFloatAvailableSpace,
|
2015-08-03 07:03:09 +03:00
|
|
|
nscoord& aIStartResult, nscoord& aIEndResult) const {
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = mReflowInput.GetWritingMode();
|
2009-01-05 03:39:54 +03:00
|
|
|
// The frame is clueless about the float manager and therefore we
|
2008-04-15 05:05:17 +04:00
|
|
|
// only give it free space. An example is a table frame - the
|
|
|
|
// tables do not flow around floats.
|
|
|
|
// However, we can let its margins intersect floats.
|
2014-10-22 02:16:13 +04:00
|
|
|
NS_ASSERTION(aFloatAvailableSpace.IStart(wm) >= mContentArea.IStart(wm),
|
|
|
|
"bad avail space rect inline-coord");
|
|
|
|
NS_ASSERTION(aFloatAvailableSpace.ISize(wm) == 0 ||
|
|
|
|
aFloatAvailableSpace.IEnd(wm) <= mContentArea.IEnd(wm),
|
|
|
|
"bad avail space rect inline-size");
|
|
|
|
|
|
|
|
nscoord iStartOffset, iEndOffset;
|
|
|
|
if (aFloatAvailableSpace.ISize(wm) == mContentArea.ISize(wm)) {
|
2008-04-15 05:05:17 +04:00
|
|
|
// We don't need to compute margins when there are no floats around.
|
2014-10-22 02:16:13 +04:00
|
|
|
iStartOffset = 0;
|
|
|
|
iEndOffset = 0;
|
2008-04-15 05:05:17 +04:00
|
|
|
} else {
|
2014-10-22 02:16:13 +04:00
|
|
|
LogicalMargin frameMargin(wm);
|
2016-07-21 13:36:39 +03:00
|
|
|
SizeComputationInput os(aFrame, mReflowInput.mRenderingContext, wm,
|
2015-06-11 09:42:56 +03:00
|
|
|
mContentArea.ISize(wm));
|
2014-10-22 02:16:13 +04:00
|
|
|
frameMargin =
|
|
|
|
os.ComputedLogicalMargin().ConvertTo(wm, aFrame->GetWritingMode());
|
|
|
|
|
|
|
|
nscoord iStartFloatIOffset =
|
|
|
|
aFloatAvailableSpace.IStart(wm) - mContentArea.IStart(wm);
|
|
|
|
iStartOffset = std::max(iStartFloatIOffset, frameMargin.IStart(wm)) -
|
|
|
|
frameMargin.IStart(wm);
|
|
|
|
iStartOffset = std::max(iStartOffset, 0); // in case of negative margin
|
|
|
|
nscoord iEndFloatIOffset =
|
|
|
|
mContentArea.IEnd(wm) - aFloatAvailableSpace.IEnd(wm);
|
|
|
|
iEndOffset =
|
|
|
|
std::max(iEndFloatIOffset, frameMargin.IEnd(wm)) - frameMargin.IEnd(wm);
|
|
|
|
iEndOffset = std::max(iEndOffset, 0); // in case of negative margin
|
2008-04-15 05:05:17 +04:00
|
|
|
}
|
2014-10-22 02:16:13 +04:00
|
|
|
aIStartResult = iStartOffset;
|
|
|
|
aIEndResult = iEndOffset;
|
2008-04-15 05:05:17 +04:00
|
|
|
}
|
|
|
|
|
1999-04-03 22:59:01 +04:00
|
|
|
// Compute the amount of available space for reflowing a block frame
|
2019-05-11 00:06:48 +03:00
|
|
|
// at the current block-direction coordinate. This method assumes that
|
|
|
|
// GetFloatAvailableSpace has already been called.
|
2016-07-21 13:36:36 +03:00
|
|
|
void BlockReflowInput::ComputeBlockAvailSpace(
|
2016-08-22 14:39:54 +03:00
|
|
|
nsIFrame* aFrame, const nsFlowAreaRect& aFloatAvailableSpace,
|
|
|
|
bool aBlockAvoidsFloats, LogicalRect& aResult) {
|
2000-04-17 18:40:46 +04:00
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
2009-04-09 00:52:37 +04:00
|
|
|
printf("CBAS frame=%p has floats %d\n", aFrame,
|
2018-05-30 21:07:18 +03:00
|
|
|
aFloatAvailableSpace.HasFloats());
|
2000-04-17 18:40:46 +04:00
|
|
|
#endif
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = mReflowInput.GetWritingMode();
|
2019-08-21 22:53:08 +03:00
|
|
|
const nscoord availBSize = mReflowInput.AvailableBSize();
|
2014-10-22 02:16:13 +04:00
|
|
|
aResult.BStart(wm) = mBCoord;
|
2019-10-10 16:38:07 +03:00
|
|
|
aResult.BSize(wm) = availBSize == NS_UNCONSTRAINEDSIZE ? NS_UNCONSTRAINEDSIZE
|
|
|
|
: availBSize - mBCoord;
|
2020-03-30 21:03:49 +03:00
|
|
|
// mBCoord might be greater than ContentBEnd() if the block's top margin
|
|
|
|
// pushes it off the page/column. Negative available block-size can confuse
|
|
|
|
// other code and is nonsense in principle.
|
1998-09-24 00:10:40 +04:00
|
|
|
|
2008-01-29 10:40:05 +03:00
|
|
|
// XXX Do we really want this condition to be this restrictive (i.e.,
|
|
|
|
// more restrictive than it used to be)? The |else| here is allowed
|
|
|
|
// by the CSS spec, but only out of desperation given implementations,
|
|
|
|
// and the behavior it leads to is quite undesirable (it can cause
|
|
|
|
// things to become extremely narrow when they'd fit quite well a
|
|
|
|
// little bit lower). Should the else be a quirk or something that
|
|
|
|
// applies to a specific set of frame classes and no new ones?
|
|
|
|
// If we did that, then for those frames where the condition below is
|
|
|
|
// true but nsBlockFrame::BlockCanIntersectFloats is false,
|
2014-10-22 02:16:13 +04:00
|
|
|
// nsBlockFrame::ISizeToClearPastFloats would need to use the
|
2014-07-24 21:03:26 +04:00
|
|
|
// shrink-wrap formula, max(MIN_ISIZE, min(avail width, PREF_ISIZE))
|
|
|
|
// rather than just using MIN_ISIZE.
|
2008-05-04 03:33:36 +04:00
|
|
|
NS_ASSERTION(
|
|
|
|
nsBlockFrame::BlockCanIntersectFloats(aFrame) == !aBlockAvoidsFloats,
|
2008-04-15 05:05:17 +04:00
|
|
|
"unexpected replaced width");
|
2008-05-04 03:33:36 +04:00
|
|
|
if (!aBlockAvoidsFloats) {
|
2018-05-30 21:07:18 +03:00
|
|
|
if (aFloatAvailableSpace.HasFloats()) {
|
1999-09-16 23:56:36 +04:00
|
|
|
// Use the float-edge property to determine how the child block
|
2003-10-14 01:51:02 +04:00
|
|
|
// will interact with the float.
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleBorder* borderStyle = aFrame->StyleBorder();
|
2001-02-07 12:57:26 +03:00
|
|
|
switch (borderStyle->mFloatEdge) {
|
1999-09-16 23:56:36 +04:00
|
|
|
default:
|
2016-07-25 09:26:05 +03:00
|
|
|
case StyleFloatEdge::ContentBox: // content and only content does
|
|
|
|
// runaround of floats
|
2003-10-14 01:51:02 +04:00
|
|
|
// The child block will flow around the float. Therefore
|
1999-09-16 23:56:36 +04:00
|
|
|
// give it all of the available space.
|
2014-10-22 02:16:13 +04:00
|
|
|
aResult.IStart(wm) = mContentArea.IStart(wm);
|
|
|
|
aResult.ISize(wm) = mContentArea.ISize(wm);
|
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
|
|
|
break;
|
2016-07-25 09:26:05 +03:00
|
|
|
case StyleFloatEdge::MarginBox: {
|
1999-09-16 23:56:36 +04:00
|
|
|
// The child block's margins should be placed adjacent to,
|
2003-10-14 01:51:02 +04:00
|
|
|
// but not overlap the float.
|
2014-10-22 02:16:13 +04:00
|
|
|
aResult.IStart(wm) = aFloatAvailableSpace.mRect.IStart(wm);
|
|
|
|
aResult.ISize(wm) = aFloatAvailableSpace.mRect.ISize(wm);
|
1999-09-16 23:56:36 +04:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} else {
|
2003-10-14 01:51:02 +04:00
|
|
|
// Since there are no floats present the float-edge property
|
1999-09-16 23:56:36 +04:00
|
|
|
// doesn't matter therefore give the block element all of the
|
2003-10-14 01:51:02 +04:00
|
|
|
// available space since it will flow around the float itself.
|
2014-10-22 02:16:13 +04:00
|
|
|
aResult.IStart(wm) = mContentArea.IStart(wm);
|
|
|
|
aResult.ISize(wm) = mContentArea.ISize(wm);
|
1999-09-16 23:56:36 +04:00
|
|
|
}
|
1999-04-03 22:59:01 +04:00
|
|
|
} else {
|
2014-10-22 02:16:13 +04:00
|
|
|
nscoord iStartOffset, iEndOffset;
|
2009-04-09 00:52:37 +04:00
|
|
|
ComputeReplacedBlockOffsetsForFloats(aFrame, aFloatAvailableSpace.mRect,
|
2014-10-22 02:16:13 +04:00
|
|
|
iStartOffset, iEndOffset);
|
|
|
|
aResult.IStart(wm) = mContentArea.IStart(wm) + iStartOffset;
|
|
|
|
aResult.ISize(wm) = mContentArea.ISize(wm) - iStartOffset - iEndOffset;
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
2003-01-09 05:24:10 +03:00
|
|
|
|
2000-03-23 02:19:10 +03:00
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
2014-10-22 02:16:13 +04:00
|
|
|
printf(" CBAS: result %d %d %d %d\n", aResult.IStart(wm), aResult.BStart(wm),
|
|
|
|
aResult.ISize(wm), aResult.BSize(wm));
|
2000-03-23 02:19:10 +03:00
|
|
|
#endif
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
1998-09-24 00:10:40 +04:00
|
|
|
|
2016-07-21 13:36:36 +03:00
|
|
|
bool BlockReflowInput::ReplacedBlockFitsInAvailSpace(
|
|
|
|
nsIFrame* aReplacedBlock,
|
2015-08-03 07:03:09 +03:00
|
|
|
const nsFlowAreaRect& aFloatAvailableSpace) const {
|
2018-05-30 21:07:18 +03:00
|
|
|
if (!aFloatAvailableSpace.HasFloats()) {
|
2015-08-03 07:03:09 +03:00
|
|
|
// If there aren't any floats here, then we always fit.
|
|
|
|
// We check this before calling ISizeToClearPastFloats, which is
|
|
|
|
// somewhat expensive.
|
|
|
|
return true;
|
|
|
|
}
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = mReflowInput.GetWritingMode();
|
2015-08-03 07:03:09 +03:00
|
|
|
nsBlockFrame::ReplacedElementISizeToClear replacedISize =
|
|
|
|
nsBlockFrame::ISizeToClearPastFloats(*this, aFloatAvailableSpace.mRect,
|
|
|
|
aReplacedBlock);
|
2015-09-27 12:19:14 +03:00
|
|
|
// The inline-start side of the replaced element should be offset by
|
|
|
|
// the larger of the float intrusion or the replaced element's own
|
|
|
|
// start margin. The inline-end side is similar, except for Web
|
|
|
|
// compatibility we ignore the margin.
|
2015-08-03 07:03:09 +03:00
|
|
|
return std::max(
|
|
|
|
aFloatAvailableSpace.mRect.IStart(wm) - mContentArea.IStart(wm),
|
|
|
|
replacedISize.marginIStart) +
|
|
|
|
replacedISize.borderBoxISize +
|
2015-09-27 12:19:14 +03:00
|
|
|
(mContentArea.IEnd(wm) - aFloatAvailableSpace.mRect.IEnd(wm)) <=
|
2015-08-03 07:03:09 +03:00
|
|
|
mContentArea.ISize(wm);
|
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:36 +03:00
|
|
|
nsFlowAreaRect BlockReflowInput::GetFloatAvailableSpaceWithState(
|
2016-10-12 11:06:25 +03:00
|
|
|
nscoord aBCoord, ShapeType aShapeType,
|
|
|
|
nsFloatManager::SavedState* aState) const {
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = mReflowInput.GetWritingMode();
|
2001-05-01 08:22:57 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Verify that the caller setup the coordinate system properly
|
2015-03-22 12:44:48 +03:00
|
|
|
nscoord wI, wB;
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->GetTranslation(wI, wB);
|
2014-10-22 02:16:12 +04:00
|
|
|
|
2015-03-22 12:44:48 +03:00
|
|
|
NS_ASSERTION((wI == mFloatManagerI) && (wB == mFloatManagerB),
|
|
|
|
"bad coord system");
|
2001-05-01 08:22:57 +04:00
|
|
|
#endif
|
|
|
|
|
2014-10-22 02:16:12 +04:00
|
|
|
nscoord blockSize = (mContentArea.BSize(wm) == nscoord_MAX)
|
|
|
|
? nscoord_MAX
|
|
|
|
: std::max(mContentArea.BEnd(wm) - aBCoord, 0);
|
2017-02-09 11:59:07 +03:00
|
|
|
nsFlowAreaRect result = FloatManager()->GetFlowArea(
|
|
|
|
wm, aBCoord, blockSize, BandInfoType::BandFromPoint, aShapeType,
|
|
|
|
mContentArea, aState, ContainerSize());
|
2014-10-22 02:16:13 +04:00
|
|
|
// Keep the inline size >= 0 for compatibility with nsSpaceManager.
|
|
|
|
if (result.mRect.ISize(wm) < 0) {
|
|
|
|
result.mRect.ISize(wm) = 0;
|
|
|
|
}
|
2001-05-01 08:22:57 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2016-08-22 14:41:53 +03:00
|
|
|
printf("%s: band=%d,%d,%d,%d hasfloats=%d\n", __func__,
|
2014-10-22 02:16:13 +04:00
|
|
|
result.mRect.IStart(wm), result.mRect.BStart(wm),
|
2018-05-30 21:07:18 +03:00
|
|
|
result.mRect.ISize(wm), result.mRect.BSize(wm), result.HasFloats());
|
2001-05-01 08:22:57 +04:00
|
|
|
}
|
|
|
|
#endif
|
2009-04-09 00:52:37 +04:00
|
|
|
return result;
|
2001-05-01 08:22:57 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:36 +03:00
|
|
|
nsFlowAreaRect BlockReflowInput::GetFloatAvailableSpaceForBSize(
|
2009-05-20 15:21:34 +04:00
|
|
|
nscoord aBCoord, nscoord aBSize, nsFloatManager::SavedState* aState) const {
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = mReflowInput.GetWritingMode();
|
2009-05-20 15:21:34 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Verify that the caller setup the coordinate system properly
|
2015-03-22 12:44:48 +03:00
|
|
|
nscoord wI, wB;
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->GetTranslation(wI, wB);
|
2015-03-22 12:44:48 +03:00
|
|
|
|
|
|
|
NS_ASSERTION((wI == mFloatManagerI) && (wB == mFloatManagerB),
|
|
|
|
"bad coord system");
|
2009-05-20 15:21:34 +04:00
|
|
|
#endif
|
2017-02-09 11:59:07 +03:00
|
|
|
nsFlowAreaRect result = FloatManager()->GetFlowArea(
|
|
|
|
wm, aBCoord, aBSize, BandInfoType::WidthWithinHeight,
|
|
|
|
ShapeType::ShapeOutside, mContentArea, aState, ContainerSize());
|
2009-05-20 15:21:34 +04:00
|
|
|
// Keep the width >= 0 for compatibility with nsSpaceManager.
|
2014-10-22 02:16:13 +04:00
|
|
|
if (result.mRect.ISize(wm) < 0) {
|
|
|
|
result.mRect.ISize(wm) = 0;
|
|
|
|
}
|
2009-05-20 15:21:34 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2016-08-22 14:41:53 +03:00
|
|
|
printf("%s: space=%d,%d,%d,%d hasfloats=%d\n", __func__,
|
2014-10-22 02:16:13 +04:00
|
|
|
result.mRect.IStart(wm), result.mRect.BStart(wm),
|
2018-05-30 21:07:18 +03:00
|
|
|
result.mRect.ISize(wm), result.mRect.BSize(wm), result.HasFloats());
|
2009-05-20 15:21:34 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
/*
|
|
|
|
* Reconstruct the vertical margin before the line |aLine| in order to
|
|
|
|
* do an incremental reflow that begins with |aLine| without reflowing
|
|
|
|
* the line before it. |aLine| may point to the fencepost at the end of
|
|
|
|
* the line list, and it is used this way since we (for now, anyway)
|
|
|
|
* always need to recover margins at the end of a block.
|
|
|
|
*
|
|
|
|
* The reconstruction involves walking backward through the line list to
|
|
|
|
* find any collapsed margins preceding the line that would have been in
|
2019-04-11 23:27:37 +03:00
|
|
|
* the reflow input's |mPrevBEndMargin| when we reflowed that line in
|
2001-10-25 05:08:40 +04:00
|
|
|
* a full reflow (under the rule in CSS2 that all adjacent vertical
|
|
|
|
* margins of blocks collapse).
|
|
|
|
*/
|
2016-07-21 13:36:36 +03:00
|
|
|
void BlockReflowInput::ReconstructMarginBefore(nsLineList::iterator aLine) {
|
2014-06-20 13:55:35 +04:00
|
|
|
mPrevBEndMargin.Zero();
|
2001-10-25 05:08:40 +04:00
|
|
|
nsBlockFrame* block = mBlock;
|
|
|
|
|
2016-10-24 10:01:25 +03:00
|
|
|
nsLineList::iterator firstLine = block->LinesBegin();
|
2001-10-25 05:08:40 +04:00
|
|
|
for (;;) {
|
|
|
|
--aLine;
|
|
|
|
if (aLine->IsBlock()) {
|
2014-06-20 13:55:35 +04:00
|
|
|
mPrevBEndMargin = aLine->GetCarriedOutBEndMargin();
|
2001-10-25 05:08:40 +04:00
|
|
|
break;
|
|
|
|
}
|
2003-11-11 02:36:06 +03:00
|
|
|
if (!aLine->IsEmpty()) {
|
2001-10-25 05:08:40 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (aLine == firstLine) {
|
|
|
|
// If the top margin was carried out (and thus already applied),
|
|
|
|
// set it to zero. Either way, we're done.
|
2016-08-12 10:28:45 +03:00
|
|
|
if (!mFlags.mIsBStartMarginRoot) {
|
2014-06-20 13:55:35 +04:00
|
|
|
mPrevBEndMargin.Zero();
|
2001-10-25 05:08:40 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:36 +03:00
|
|
|
void BlockReflowInput::SetupPushedFloatList() {
|
2016-08-12 10:28:45 +03:00
|
|
|
MOZ_ASSERT(!mFlags.mIsFloatListInBlockPropertyTable == !mPushedFloats,
|
2015-02-10 01:34:50 +03:00
|
|
|
"flag mismatch");
|
2016-08-12 10:28:45 +03:00
|
|
|
if (!mFlags.mIsFloatListInBlockPropertyTable) {
|
2010-08-06 08:59:19 +04:00
|
|
|
// If we're being re-Reflow'd without our next-in-flow having been
|
2010-08-06 08:59:20 +04:00
|
|
|
// reflowed, some pushed floats from our previous reflow might
|
|
|
|
// still be on our pushed floats list. However, that's
|
2010-08-06 08:59:19 +04:00
|
|
|
// actually fine, since they'll all end up being stolen and
|
|
|
|
// reordered into the correct order again.
|
2010-08-06 08:59:20 +04:00
|
|
|
// (nsBlockFrame::ReflowDirtyLines ensures that any lines with
|
|
|
|
// pushed floats are reflowed.)
|
2010-08-06 08:59:20 +04:00
|
|
|
mPushedFloats = mBlock->EnsurePushedFloats();
|
2016-08-12 10:28:45 +03:00
|
|
|
mFlags.mIsFloatListInBlockPropertyTable = true;
|
2009-08-31 22:25:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:36 +03:00
|
|
|
void BlockReflowInput::AppendPushedFloatChain(nsIFrame* aFloatCont) {
|
2013-02-12 05:52:55 +04:00
|
|
|
SetupPushedFloatList();
|
2014-12-19 19:28:43 +03:00
|
|
|
while (true) {
|
|
|
|
aFloatCont->AddStateBits(NS_FRAME_IS_PUSHED_FLOAT);
|
|
|
|
mPushedFloats->AppendFrame(mBlock, aFloatCont);
|
|
|
|
aFloatCont = aFloatCont->GetNextInFlow();
|
|
|
|
if (!aFloatCont || aFloatCont->GetParent() != mBlock) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DebugOnly<nsresult> rv = mBlock->StealFrame(aFloatCont);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "StealFrame should succeed");
|
|
|
|
}
|
2013-02-12 05:52:55 +04:00
|
|
|
}
|
|
|
|
|
2002-01-06 21:14:00 +03:00
|
|
|
/**
|
2009-01-05 03:39:54 +03:00
|
|
|
* Restore information about floats into the float manager for an
|
2003-10-14 01:51:02 +04:00
|
|
|
* incremental reflow, and simultaneously push the floats by
|
2014-06-20 13:55:35 +04:00
|
|
|
* |aDeltaBCoord|, which is the amount |aLine| was pushed relative to its
|
2002-01-06 21:14:00 +03:00
|
|
|
* parent. The recovery of state is one of the things that makes
|
|
|
|
* incremental reflow O(N^2) and this state should really be kept
|
|
|
|
* around, attached to the frame tree.
|
|
|
|
*/
|
2016-07-21 13:36:36 +03:00
|
|
|
void BlockReflowInput::RecoverFloats(nsLineList::iterator aLine,
|
2014-06-20 13:55:35 +04:00
|
|
|
nscoord aDeltaBCoord) {
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = mReflowInput.GetWritingMode();
|
2003-10-14 01:51:02 +04:00
|
|
|
if (aLine->HasFloats()) {
|
2018-06-05 08:33:42 +03:00
|
|
|
// Place the floats into the float manager again. Also slide
|
2001-11-15 10:28:46 +03:00
|
|
|
// them, just like the regular frames on the line.
|
2003-10-14 01:51:02 +04:00
|
|
|
nsFloatCache* fc = aLine->GetFirstFloat();
|
2001-11-15 10:28:46 +03:00
|
|
|
while (fc) {
|
2009-08-31 22:25:35 +04:00
|
|
|
nsIFrame* floatFrame = fc->mFloat;
|
2014-06-20 13:55:35 +04:00
|
|
|
if (aDeltaBCoord != 0) {
|
|
|
|
floatFrame->MovePositionBy(nsPoint(0, aDeltaBCoord));
|
2007-07-02 09:19:57 +04:00
|
|
|
nsContainerFrame::PositionFrameView(floatFrame);
|
|
|
|
nsContainerFrame::PositionChildViews(floatFrame);
|
2002-01-06 21:14:00 +03:00
|
|
|
}
|
2001-11-15 10:28:46 +03:00
|
|
|
#ifdef DEBUG
|
2009-01-05 03:39:54 +03:00
|
|
|
if (nsBlockFrame::gNoisyReflow || nsBlockFrame::gNoisyFloatManager) {
|
2015-03-22 12:44:48 +03:00
|
|
|
nscoord tI, tB;
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->GetTranslation(tI, tB);
|
2001-11-15 10:28:46 +03:00
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2015-03-22 12:44:48 +03:00
|
|
|
printf("RecoverFloats: tIB=%d,%d (%d,%d) ", tI, tB, mFloatManagerI,
|
|
|
|
mFloatManagerB);
|
2019-01-30 00:22:14 +03:00
|
|
|
floatFrame->ListTag(stdout);
|
2014-10-22 02:16:12 +04:00
|
|
|
LogicalRect region =
|
|
|
|
nsFloatManager::GetRegionFor(wm, floatFrame, ContainerSize());
|
2014-06-20 13:55:35 +04:00
|
|
|
printf(" aDeltaBCoord=%d region={%d,%d,%d,%d}\n", aDeltaBCoord,
|
2014-10-22 02:16:12 +04:00
|
|
|
region.IStart(wm), region.BStart(wm), region.ISize(wm),
|
|
|
|
region.BSize(wm));
|
2001-11-15 10:28:46 +03:00
|
|
|
}
|
|
|
|
#endif
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->AddFloat(
|
|
|
|
floatFrame,
|
|
|
|
nsFloatManager::GetRegionFor(wm, floatFrame, ContainerSize()), wm,
|
|
|
|
ContainerSize());
|
2001-11-15 10:28:46 +03:00
|
|
|
fc = fc->Next();
|
|
|
|
}
|
|
|
|
} else if (aLine->IsBlock()) {
|
2017-02-09 11:59:07 +03:00
|
|
|
nsBlockFrame::RecoverFloatsFor(aLine->mFirstChild, *FloatManager(), wm,
|
2015-07-16 12:07:57 +03:00
|
|
|
ContainerSize());
|
2001-11-15 10:28:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-03 08:18:39 +03:00
|
|
|
/**
|
|
|
|
* Everything done in this function is done O(N) times for each pass of
|
|
|
|
* reflow so it is O(N*M) where M is the number of incremental reflow
|
|
|
|
* passes. That's bad. Don't do stuff here.
|
|
|
|
*
|
2014-06-20 13:55:35 +04:00
|
|
|
* When this function is called, |aLine| has just been slid by |aDeltaBCoord|
|
2001-11-03 08:18:39 +03:00
|
|
|
* and the purpose of RecoverStateFrom is to ensure that the
|
2016-07-21 13:36:36 +03:00
|
|
|
* BlockReflowInput is in the same state that it would have been in
|
2001-11-03 08:18:39 +03:00
|
|
|
* had the line just been reflowed.
|
|
|
|
*
|
2003-10-14 01:51:02 +04:00
|
|
|
* Most of the state recovery that we have to do involves floats.
|
2001-11-03 08:18:39 +03:00
|
|
|
*/
|
2016-07-21 13:36:36 +03:00
|
|
|
void BlockReflowInput::RecoverStateFrom(nsLineList::iterator aLine,
|
2014-06-20 13:55:35 +04:00
|
|
|
nscoord aDeltaBCoord) {
|
1999-04-03 22:59:01 +04:00
|
|
|
// Make the line being recovered the current line
|
|
|
|
mCurrentLine = aLine;
|
|
|
|
|
2009-01-05 03:39:54 +03:00
|
|
|
// Place floats for this line into the float manager
|
2003-10-14 01:51:02 +04:00
|
|
|
if (aLine->HasFloats() || aLine->IsBlock()) {
|
2014-06-20 13:55:35 +04:00
|
|
|
RecoverFloats(aLine, aDeltaBCoord);
|
2001-11-15 10:28:46 +03:00
|
|
|
|
2000-03-23 02:19:10 +03:00
|
|
|
#ifdef DEBUG
|
2009-01-05 03:39:54 +03:00
|
|
|
if (nsBlockFrame::gNoisyReflow || nsBlockFrame::gNoisyFloatManager) {
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->List(stdout);
|
2000-03-23 02:19:10 +03:00
|
|
|
}
|
|
|
|
#endif
|
1999-04-03 22:59:01 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-09-24 00:10:40 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// This is called by the line layout's AddFloat method when a
|
|
|
|
// place-holder frame is reflowed in a line. If the float is a
|
1998-12-05 19:02:08 +03:00
|
|
|
// left-most child (it's x coordinate is at the line's left margin)
|
2003-10-14 01:51:02 +04:00
|
|
|
// then the float is place immediately, otherwise the float
|
1998-12-05 19:02:08 +03:00
|
|
|
// placement is deferred until the line has been reflowed.
|
2001-07-04 06:00:05 +04:00
|
|
|
|
|
|
|
// XXXldb This behavior doesn't quite fit with CSS1 and CSS2 --
|
|
|
|
// technically we're supposed let the current line flow around the
|
|
|
|
// float as well unless it won't fit next to what we already have.
|
|
|
|
// But nobody else implements it that way...
|
2016-07-21 13:36:36 +03:00
|
|
|
bool BlockReflowInput::AddFloat(nsLineLayout* aLineLayout, nsIFrame* aFloat,
|
2014-10-22 02:16:13 +04:00
|
|
|
nscoord aAvailableISize) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aLineLayout, "must have line layout");
|
|
|
|
MOZ_ASSERT(mBlock->LinesEnd() != mCurrentLine, "null ptr");
|
|
|
|
MOZ_ASSERT(aFloat->GetStateBits() & NS_FRAME_OUT_OF_FLOW,
|
|
|
|
"aFloat must be an out-of-flow frame");
|
1999-03-23 07:28:20 +03:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aFloat->GetParent(), "float must have parent");
|
2019-02-21 00:18:14 +03:00
|
|
|
MOZ_ASSERT(aFloat->GetParent()->IsBlockFrameOrSubclass(),
|
2015-02-10 01:34:50 +03:00
|
|
|
"float's parent must be block");
|
2018-11-09 00:37:16 +03:00
|
|
|
if (aFloat->HasAnyStateBits(NS_FRAME_IS_PUSHED_FLOAT) ||
|
|
|
|
aFloat->GetParent() != mBlock) {
|
|
|
|
MOZ_ASSERT(aFloat->HasAnyStateBits(NS_FRAME_IS_PUSHED_FLOAT |
|
|
|
|
NS_FRAME_FIRST_REFLOW),
|
|
|
|
"float should be in this block unless it was marked as "
|
|
|
|
"pushed float, or just inserted");
|
|
|
|
MOZ_ASSERT(aFloat->GetParent()->FirstContinuation() ==
|
|
|
|
mBlock->FirstContinuation());
|
2010-08-06 08:59:19 +04:00
|
|
|
// If, in a previous reflow, the float was pushed entirely to
|
|
|
|
// another column/page, we need to steal it back. (We might just
|
|
|
|
// push it again, though.) Likewise, if that previous reflow
|
|
|
|
// reflowed this block but not its next continuation, we might need
|
|
|
|
// to steal it from our own float-continuations list.
|
2013-01-12 02:51:21 +04:00
|
|
|
//
|
|
|
|
// For more about pushed floats, see the comment above
|
|
|
|
// nsBlockFrame::DrainPushedFloats.
|
2018-11-09 00:37:16 +03:00
|
|
|
auto* floatParent = static_cast<nsBlockFrame*>(aFloat->GetParent());
|
2014-02-07 02:07:47 +04:00
|
|
|
floatParent->StealFrame(aFloat);
|
2010-08-06 08:59:19 +04:00
|
|
|
|
2010-08-06 08:59:20 +04:00
|
|
|
aFloat->RemoveStateBits(NS_FRAME_IS_PUSHED_FLOAT);
|
2010-08-06 08:59:19 +04:00
|
|
|
|
|
|
|
// Appending is fine, since if a float was pushed to the next
|
|
|
|
// page/column, all later floats were also pushed.
|
|
|
|
mBlock->mFloats.AppendFrame(mBlock, aFloat);
|
|
|
|
}
|
2009-05-20 15:21:34 +04:00
|
|
|
|
2009-04-09 00:52:36 +04:00
|
|
|
// Because we are in the middle of reflowing a placeholder frame
|
|
|
|
// within a line (and possibly nested in an inline frame or two
|
|
|
|
// that's a child of our block) we need to restore the space
|
|
|
|
// manager's translation to the space that the block resides in
|
|
|
|
// before placing the float.
|
2015-03-22 12:44:48 +03:00
|
|
|
nscoord oI, oB;
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->GetTranslation(oI, oB);
|
2015-03-22 12:44:48 +03:00
|
|
|
nscoord dI = oI - mFloatManagerI;
|
|
|
|
nscoord dB = oB - mFloatManagerB;
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->Translate(-dI, -dB);
|
2009-04-09 00:52:36 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool placed;
|
2005-03-23 06:35:08 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Now place the float immediately if possible. Otherwise stash it
|
2016-08-22 14:41:53 +03:00
|
|
|
// away in mBelowCurrentLineFloats and place it later.
|
2008-06-11 03:53:22 +04:00
|
|
|
// If one or more floats has already been pushed to the next line,
|
|
|
|
// don't let this one go on the current line, since that would violate
|
|
|
|
// float ordering.
|
2016-10-12 11:06:25 +03:00
|
|
|
LogicalRect floatAvailableSpace =
|
|
|
|
GetFloatAvailableSpaceForPlacingFloat(mBCoord).mRect;
|
2010-08-06 08:59:19 +04:00
|
|
|
if (mBelowCurrentLineFloats.IsEmpty() &&
|
|
|
|
(aLineLayout->LineIsEmpty() ||
|
2014-10-22 02:16:13 +04:00
|
|
|
mBlock->ComputeFloatISize(*this, floatAvailableSpace, aFloat) <=
|
|
|
|
aAvailableISize)) {
|
1999-09-15 04:28:10 +04:00
|
|
|
// And then place it
|
2010-08-06 08:59:20 +04:00
|
|
|
placed = FlowAndPlaceFloat(aFloat);
|
2010-08-06 08:59:19 +04:00
|
|
|
if (placed) {
|
2005-03-23 06:35:08 +03:00
|
|
|
// Pass on updated available space to the current inline reflow engine
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = mReflowInput.GetWritingMode();
|
2016-08-22 14:42:37 +03:00
|
|
|
// If we have mLineBSize, we are reflowing the line again due to
|
|
|
|
// LineReflowStatus::RedoMoreFloats. We should use mLineBSize to query the
|
|
|
|
// correct available space.
|
|
|
|
nsFlowAreaRect floatAvailSpace =
|
|
|
|
mLineBSize.isNothing() ? GetFloatAvailableSpace(mBCoord)
|
|
|
|
: GetFloatAvailableSpaceForBSize(
|
|
|
|
mBCoord, mLineBSize.value(), nullptr);
|
2014-10-22 02:16:13 +04:00
|
|
|
LogicalRect availSpace(wm, floatAvailSpace.mRect.IStart(wm), mBCoord,
|
|
|
|
floatAvailSpace.mRect.ISize(wm),
|
|
|
|
floatAvailSpace.mRect.BSize(wm));
|
|
|
|
aLineLayout->UpdateBand(wm, availSpace, aFloat);
|
2010-08-06 08:59:19 +04:00
|
|
|
// Record this float in the current-line list
|
|
|
|
mCurrentLineFloats.Append(mFloatCacheFreeList.Alloc(aFloat));
|
2010-08-06 08:59:20 +04:00
|
|
|
} else {
|
|
|
|
(*aLineLayout->GetLine())->SetHadFloatPushed();
|
2005-03-23 06:35:08 +03:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
} else {
|
2007-06-27 20:35:31 +04:00
|
|
|
// Always claim to be placed; we don't know whether we fit yet, so we
|
|
|
|
// deal with this in PlaceBelowCurrentLineFloats
|
2011-10-17 18:59:28 +04:00
|
|
|
placed = true;
|
2003-10-14 01:51:02 +04:00
|
|
|
// This float will be placed after the line is done (it is a
|
|
|
|
// below-current-line float).
|
2009-08-31 22:25:36 +04:00
|
|
|
mBelowCurrentLineFloats.Append(mFloatCacheFreeList.Alloc(aFloat));
|
1998-06-25 20:33:10 +04:00
|
|
|
}
|
2009-04-09 00:52:36 +04:00
|
|
|
|
|
|
|
// Restore coordinate system
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->Translate(dI, dB);
|
2009-04-09 00:52:36 +04:00
|
|
|
|
2005-03-23 06:35:08 +03:00
|
|
|
return placed;
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-06-25 20:33:10 +04:00
|
|
|
|
2016-07-21 13:36:36 +03:00
|
|
|
bool BlockReflowInput::CanPlaceFloat(
|
2010-08-06 08:59:18 +04:00
|
|
|
nscoord aFloatISize, const nsFlowAreaRect& aFloatAvailableSpace) {
|
2014-10-22 02:16:13 +04:00
|
|
|
// A float fits at a given block-dir position if there are no floats
|
|
|
|
// at its inline-dir position (no matter what its inline size) or if
|
|
|
|
// its inline size fits in the space remaining after prior floats have
|
|
|
|
// been placed.
|
2010-08-06 08:59:18 +04:00
|
|
|
// FIXME: We should allow overflow by up to half a pixel here (bug 21193).
|
2018-05-30 21:07:18 +03:00
|
|
|
return !aFloatAvailableSpace.HasFloats() ||
|
2016-07-21 13:36:39 +03:00
|
|
|
aFloatAvailableSpace.mRect.ISize(mReflowInput.GetWritingMode()) >=
|
2014-10-22 02:16:13 +04:00
|
|
|
aFloatISize;
|
1999-03-31 08:10:27 +04:00
|
|
|
}
|
|
|
|
|
2015-04-09 10:41:49 +03:00
|
|
|
// Return the inline-size that the float (including margins) will take up
|
2015-04-09 12:08:17 +03:00
|
|
|
// in the writing mode of the containing block. If this returns
|
|
|
|
// NS_UNCONSTRAINEDSIZE, we're dealing with an orthogonal block that
|
|
|
|
// has block-size:auto, and we'll need to actually reflow it to find out
|
|
|
|
// how much inline-size it will occupy in the containing block's mode.
|
2016-07-21 13:36:39 +03:00
|
|
|
static nscoord FloatMarginISize(const ReflowInput& aCBReflowInput,
|
2014-10-22 02:16:13 +04:00
|
|
|
nscoord aFloatAvailableISize, nsIFrame* aFloat,
|
2016-07-21 13:36:35 +03:00
|
|
|
const SizeComputationInput& aFloatOffsetState) {
|
2012-05-21 09:18:27 +04:00
|
|
|
AutoMaybeDisableFontInflation an(aFloat);
|
2014-10-22 02:16:13 +04:00
|
|
|
WritingMode wm = aFloatOffsetState.GetWritingMode();
|
|
|
|
|
|
|
|
LogicalSize floatSize = aFloat->ComputeSize(
|
2016-07-21 13:36:39 +03:00
|
|
|
aCBReflowInput.mRenderingContext, wm, aCBReflowInput.ComputedSize(wm),
|
2014-10-22 02:16:13 +04:00
|
|
|
aFloatAvailableISize, aFloatOffsetState.ComputedLogicalMargin().Size(wm),
|
|
|
|
aFloatOffsetState.ComputedLogicalBorderPadding().Size(wm) -
|
|
|
|
aFloatOffsetState.ComputedLogicalPadding().Size(wm),
|
|
|
|
aFloatOffsetState.ComputedLogicalPadding().Size(wm),
|
2014-11-11 14:02:41 +03:00
|
|
|
nsIFrame::ComputeSizeFlags::eShrinkWrap);
|
2014-10-22 02:16:13 +04:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode cbwm = aCBReflowInput.GetWritingMode();
|
2015-04-09 12:08:17 +03:00
|
|
|
nscoord floatISize = floatSize.ConvertTo(cbwm, wm).ISize(cbwm);
|
|
|
|
if (floatISize == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
return NS_UNCONSTRAINEDSIZE; // reflow is needed to get the true size
|
|
|
|
}
|
|
|
|
|
|
|
|
return floatISize +
|
|
|
|
aFloatOffsetState.ComputedLogicalMargin()
|
|
|
|
.Size(wm)
|
|
|
|
.ConvertTo(cbwm, wm)
|
|
|
|
.ISize(cbwm) +
|
|
|
|
aFloatOffsetState.ComputedLogicalBorderPadding()
|
|
|
|
.Size(wm)
|
|
|
|
.ConvertTo(cbwm, wm)
|
|
|
|
.ISize(cbwm);
|
2010-08-06 08:59:18 +04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:41:22 +03:00
|
|
|
// A frame property that stores the last shape source / margin / etc. if there's
|
|
|
|
// any shape, in order to invalidate the float area properly when it changes.
|
|
|
|
//
|
|
|
|
// TODO(emilio): This could really belong to GetRegionFor / StoreRegionFor, but
|
|
|
|
// when I tried it was a bit awkward because of the logical -> physical
|
|
|
|
// conversion that happens there.
|
|
|
|
//
|
|
|
|
// Maybe all this code could be refactored to make this cleaner, but keeping the
|
|
|
|
// two properties separated was slightly nicer.
|
|
|
|
struct ShapeInvalidationData {
|
2020-02-12 02:34:53 +03:00
|
|
|
StyleShapeOutside mShapeOutside{StyleShapeOutside::None()};
|
2018-10-04 20:41:22 +03:00
|
|
|
float mShapeImageThreshold = 0.0;
|
2020-02-12 01:03:53 +03:00
|
|
|
LengthPercentage mShapeMargin;
|
2018-10-04 20:41:22 +03:00
|
|
|
|
|
|
|
ShapeInvalidationData() = default;
|
|
|
|
|
|
|
|
explicit ShapeInvalidationData(const nsStyleDisplay& aDisplay) {
|
|
|
|
Update(aDisplay);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsNeeded(const nsStyleDisplay& aDisplay) {
|
2020-02-12 01:03:53 +03:00
|
|
|
return !aDisplay.mShapeOutside.IsNone();
|
2018-10-04 20:41:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Update(const nsStyleDisplay& aDisplay) {
|
|
|
|
MOZ_ASSERT(IsNeeded(aDisplay));
|
|
|
|
mShapeOutside = aDisplay.mShapeOutside;
|
|
|
|
mShapeImageThreshold = aDisplay.mShapeImageThreshold;
|
|
|
|
mShapeMargin = aDisplay.mShapeMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Matches(const nsStyleDisplay& aDisplay) const {
|
|
|
|
return mShapeOutside == aDisplay.mShapeOutside &&
|
|
|
|
mShapeImageThreshold == aDisplay.mShapeImageThreshold &&
|
|
|
|
mShapeMargin == aDisplay.mShapeMargin;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(ShapeInvalidationDataProperty,
|
|
|
|
ShapeInvalidationData)
|
|
|
|
|
2016-07-21 13:36:36 +03:00
|
|
|
bool BlockReflowInput::FlowAndPlaceFloat(nsIFrame* aFloat) {
|
2017-10-19 05:31:14 +03:00
|
|
|
MOZ_ASSERT(aFloat->GetParent() == mBlock);
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = mReflowInput.GetWritingMode();
|
2003-10-14 01:51:02 +04:00
|
|
|
// Save away the Y coordinate before placing the float. We will
|
2014-06-20 13:55:35 +04:00
|
|
|
// restore mBCoord at the end after placing the float. This is
|
|
|
|
// necessary because any adjustments to mBCoord during the float
|
2003-10-14 01:51:02 +04:00
|
|
|
// placement are for the float only, not for any non-floating
|
1998-12-12 22:19:11 +03:00
|
|
|
// content.
|
2014-06-20 13:55:35 +04:00
|
|
|
AutoRestore<nscoord> restoreBCoord(mBCoord);
|
2001-05-22 03:03:46 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Grab the float's display information
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleDisplay* floatDisplay = aFloat->StyleDisplay();
|
1998-12-05 19:02:08 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// The float's old region, so we can propagate damage.
|
2014-10-22 02:16:12 +04:00
|
|
|
LogicalRect oldRegion =
|
|
|
|
nsFloatManager::GetRegionFor(wm, aFloat, ContainerSize());
|
2002-04-26 23:19:39 +04:00
|
|
|
|
2018-10-04 20:41:22 +03:00
|
|
|
ShapeInvalidationData* invalidationData =
|
|
|
|
aFloat->GetProperty(ShapeInvalidationDataProperty());
|
|
|
|
|
2003-03-12 02:56:49 +03:00
|
|
|
// Enforce CSS2 9.5.1 rule [2], i.e., make sure that a float isn't
|
2001-05-22 03:03:46 +04:00
|
|
|
// ``above'' another float that preceded it in the flow.
|
2017-02-09 11:59:07 +03:00
|
|
|
mBCoord = std::max(FloatManager()->GetLowestFloatTop(), mBCoord);
|
2001-05-22 03:03:46 +04:00
|
|
|
|
2005-11-21 01:05:24 +03:00
|
|
|
// See if the float should clear any preceding floats...
|
2007-06-17 00:27:46 +04:00
|
|
|
// XXX We need to mark this float somehow so that it gets reflowed
|
|
|
|
// when floats are inserted before it.
|
2016-09-03 21:46:58 +03:00
|
|
|
if (StyleClear::None != floatDisplay->mBreakType) {
|
2001-07-19 06:33:43 +04:00
|
|
|
// XXXldb Does this handle vertical margins correctly?
|
2018-07-16 20:01:24 +03:00
|
|
|
mBCoord = ClearFloats(mBCoord, floatDisplay->mBreakType);
|
2001-07-19 06:33:43 +04:00
|
|
|
}
|
2016-10-12 11:06:25 +03:00
|
|
|
// Get the band of available space with respect to margin box.
|
|
|
|
nsFlowAreaRect floatAvailableSpace =
|
|
|
|
GetFloatAvailableSpaceForPlacingFloat(mBCoord);
|
2014-10-22 02:16:13 +04:00
|
|
|
LogicalRect adjustedAvailableSpace = mBlock->AdjustFloatAvailableSpace(
|
|
|
|
*this, floatAvailableSpace.mRect, aFloat);
|
2001-05-22 03:03:46 +04:00
|
|
|
|
2009-08-31 22:25:35 +04:00
|
|
|
NS_ASSERTION(aFloat->GetParent() == mBlock, "Float frame has wrong parent");
|
2004-09-13 17:35:46 +04:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
SizeComputationInput offsets(aFloat, mReflowInput.mRenderingContext, wm,
|
|
|
|
mReflowInput.ComputedISize());
|
2001-05-22 03:03:46 +04:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
nscoord floatMarginISize = FloatMarginISize(
|
2014-10-22 02:16:13 +04:00
|
|
|
mReflowInput, adjustedAvailableSpace.ISize(wm), aFloat, offsets);
|
2001-07-19 06:33:43 +04:00
|
|
|
|
2014-10-22 02:16:13 +04:00
|
|
|
LogicalMargin floatMargin(wm); // computed margin
|
|
|
|
LogicalMargin floatOffsets(wm);
|
2010-10-07 08:25:47 +04:00
|
|
|
nsReflowStatus reflowStatus;
|
|
|
|
|
|
|
|
// If it's a floating first-letter, we need to reflow it before we
|
|
|
|
// know how wide it is (since we don't compute which letters are part
|
|
|
|
// of the first letter until reflow!).
|
2015-04-09 12:08:17 +03:00
|
|
|
// We also need to do this early reflow if FloatMarginISize returned
|
|
|
|
// an unconstrained inline-size, which can occur if the float had an
|
|
|
|
// orthogonal writing mode and 'auto' block-size (in its mode).
|
|
|
|
bool earlyFloatReflow =
|
2017-04-30 18:30:08 +03:00
|
|
|
aFloat->IsLetterFrame() || floatMarginISize == NS_UNCONSTRAINEDSIZE;
|
2015-04-09 12:08:17 +03:00
|
|
|
if (earlyFloatReflow) {
|
2013-07-30 08:53:13 +04:00
|
|
|
mBlock->ReflowFloat(*this, adjustedAvailableSpace, aFloat, floatMargin,
|
|
|
|
floatOffsets, false, reflowStatus);
|
2014-10-22 02:16:13 +04:00
|
|
|
floatMarginISize = aFloat->ISize(wm) + floatMargin.IStartEnd(wm);
|
2017-02-11 17:45:07 +03:00
|
|
|
NS_ASSERTION(reflowStatus.IsComplete(),
|
2015-04-09 12:08:17 +03:00
|
|
|
"letter frames and orthogonal floats with auto block-size "
|
|
|
|
"shouldn't break, and if they do now, then they're breaking "
|
|
|
|
"at the wrong point");
|
2010-10-07 08:25:47 +04:00
|
|
|
}
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Find a place to place the float. The CSS2 spec doesn't want
|
|
|
|
// floats overlapping each other or sticking out of the containing
|
2001-07-19 06:33:43 +04:00
|
|
|
// block if possible (CSS2 spec section 9.5.1, see the rule list).
|
2018-07-16 19:50:18 +03:00
|
|
|
StyleFloat floatStyle = floatDisplay->mFloat;
|
2016-08-09 12:32:54 +03:00
|
|
|
MOZ_ASSERT(StyleFloat::Left == floatStyle || StyleFloat::Right == floatStyle,
|
|
|
|
"Invalid float type!");
|
2001-07-19 06:33:43 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// Can the float fit here?
|
2011-09-29 10:19:26 +04:00
|
|
|
bool keepFloatOnSameLine = false;
|
2002-03-08 23:25:54 +03:00
|
|
|
|
2010-08-19 17:38:00 +04:00
|
|
|
// Are we required to place at least part of the float because we're
|
|
|
|
// at the top of the page (to avoid an infinite loop of pushing and
|
|
|
|
// breaking).
|
2016-07-21 13:36:39 +03:00
|
|
|
bool mustPlaceFloat = mReflowInput.mFlags.mIsTopOfPage && IsAdjacentWithTop();
|
2010-08-19 17:38:00 +04:00
|
|
|
|
2010-08-06 08:59:18 +04:00
|
|
|
for (;;) {
|
2016-07-21 13:36:39 +03:00
|
|
|
if (mReflowInput.AvailableHeight() != NS_UNCONSTRAINEDSIZE &&
|
2014-10-22 02:16:13 +04:00
|
|
|
floatAvailableSpace.mRect.BSize(wm) <= 0 && !mustPlaceFloat) {
|
2005-03-23 06:35:08 +03:00
|
|
|
// No space, nowhere to put anything.
|
2010-08-06 08:59:19 +04:00
|
|
|
PushFloatPastBreak(aFloat);
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2005-03-23 06:35:08 +03:00
|
|
|
}
|
|
|
|
|
2014-10-22 02:16:13 +04:00
|
|
|
if (CanPlaceFloat(floatMarginISize, floatAvailableSpace)) {
|
2010-08-06 08:59:18 +04:00
|
|
|
// We found an appropriate place.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-03-08 23:25:54 +03:00
|
|
|
// Nope. try to advance to the next band.
|
2016-08-28 05:31:50 +03:00
|
|
|
if (StyleDisplay::Table != floatDisplay->mDisplay ||
|
2003-12-25 00:51:50 +03:00
|
|
|
eCompatibility_NavQuirks != mPresContext->CompatibilityMode()) {
|
2014-10-22 02:16:13 +04:00
|
|
|
mBCoord += floatAvailableSpace.mRect.BSize(wm);
|
|
|
|
if (adjustedAvailableSpace.BSize(wm) != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
adjustedAvailableSpace.BSize(wm) -= floatAvailableSpace.mRect.BSize(wm);
|
2010-08-06 08:59:18 +04:00
|
|
|
}
|
2016-10-12 11:06:25 +03:00
|
|
|
floatAvailableSpace = GetFloatAvailableSpaceForPlacingFloat(mBCoord);
|
2002-03-08 23:25:54 +03:00
|
|
|
} else {
|
2010-08-06 08:59:18 +04:00
|
|
|
// This quirk matches the one in nsBlockFrame::AdjustFloatAvailableSpace
|
2003-10-14 01:51:02 +04:00
|
|
|
// IE handles float tables in a very special way
|
2002-03-08 23:25:54 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// see if the previous float is also a table and has "align"
|
|
|
|
nsFloatCache* fc = mCurrentLineFloats.Head();
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame* prevFrame = nullptr;
|
2002-03-08 23:25:54 +03:00
|
|
|
while (fc) {
|
2009-08-31 22:25:35 +04:00
|
|
|
if (fc->mFloat == aFloat) {
|
2002-03-08 23:25:54 +03:00
|
|
|
break;
|
|
|
|
}
|
2009-08-31 22:25:35 +04:00
|
|
|
prevFrame = fc->mFloat;
|
2002-03-08 23:25:54 +03:00
|
|
|
fc = fc->Next();
|
|
|
|
}
|
2017-04-30 18:30:08 +03:00
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
if (prevFrame) {
|
2002-03-09 00:23:55 +03:00
|
|
|
// get the frame type
|
2017-04-30 18:30:08 +03:00
|
|
|
if (prevFrame->IsTableWrapperFrame()) {
|
2002-03-09 00:23:55 +03:00
|
|
|
// see if it has "align="
|
2017-12-07 21:13:50 +03:00
|
|
|
// IE makes a difference between align and the float property.
|
|
|
|
//
|
|
|
|
// We're interested only if previous frame is align=left IE messes
|
|
|
|
// things up when "right" (overlapping frames).
|
|
|
|
//
|
|
|
|
// FIXME(emilio, bug 1426747): This looks fishy.
|
2003-06-27 22:13:48 +04:00
|
|
|
nsIContent* content = prevFrame->GetContent();
|
2017-12-07 21:13:50 +03:00
|
|
|
if (content && content->IsElement() &&
|
|
|
|
content->AsElement()->AttrValueIs(
|
|
|
|
kNameSpaceID_None, nsGkAtoms::align,
|
|
|
|
NS_LITERAL_STRING("left"), eIgnoreCase)) {
|
|
|
|
keepFloatOnSameLine = true;
|
|
|
|
// don't advance to next line (IE quirkie behaviour)
|
|
|
|
// it breaks rule CSS2/9.5.1/1, but what the hell
|
|
|
|
// since we cannot evangelize the world
|
|
|
|
break;
|
2002-03-08 23:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-11-15 00:01:26 +03:00
|
|
|
|
2002-03-08 23:25:54 +03:00
|
|
|
// the table does not fit anymore in this line so advance to next band
|
2014-10-22 02:16:13 +04:00
|
|
|
mBCoord += floatAvailableSpace.mRect.BSize(wm);
|
2010-08-06 08:59:18 +04:00
|
|
|
// To match nsBlockFrame::AdjustFloatAvailableSpace, we have to
|
|
|
|
// get a new width for the new band.
|
2016-10-12 11:06:25 +03:00
|
|
|
floatAvailableSpace = GetFloatAvailableSpaceForPlacingFloat(mBCoord);
|
2010-08-06 08:59:18 +04:00
|
|
|
adjustedAvailableSpace = mBlock->AdjustFloatAvailableSpace(
|
|
|
|
*this, floatAvailableSpace.mRect, aFloat);
|
2016-07-21 13:36:39 +03:00
|
|
|
floatMarginISize = FloatMarginISize(
|
2014-10-22 02:16:13 +04:00
|
|
|
mReflowInput, adjustedAvailableSpace.ISize(wm), aFloat, offsets);
|
2002-03-08 23:25:54 +03:00
|
|
|
}
|
2010-08-19 17:38:00 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mustPlaceFloat = false;
|
2002-03-08 23:25:54 +03:00
|
|
|
}
|
2010-08-06 08:59:18 +04:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
// If the float is continued, it will get the same absolute x value as its
|
|
|
|
// prev-in-flow
|
2005-03-23 06:35:08 +03:00
|
|
|
|
|
|
|
// We don't worry about the geometry of the prev in flow, let the continuation
|
|
|
|
// place and size itself as required.
|
|
|
|
|
2015-03-22 12:44:48 +03:00
|
|
|
// Assign inline and block dir coordinates to the float. We don't use
|
|
|
|
// LineLeft() and LineRight() here, because we would only have to
|
|
|
|
// convert the result back into this block's writing mode.
|
2014-10-22 02:16:13 +04:00
|
|
|
LogicalPoint floatPos(wm);
|
2016-08-09 12:32:54 +03:00
|
|
|
bool leftFloat = floatStyle == StyleFloat::Left;
|
2015-05-03 11:33:31 +03:00
|
|
|
|
2015-07-16 12:08:05 +03:00
|
|
|
if (leftFloat == wm.IsBidiLTR()) {
|
2014-10-22 02:16:13 +04:00
|
|
|
floatPos.I(wm) = floatAvailableSpace.mRect.IStart(wm);
|
1998-06-28 02:56:09 +04:00
|
|
|
} else {
|
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
|
|
|
if (!keepFloatOnSameLine) {
|
2014-10-22 02:16:13 +04:00
|
|
|
floatPos.I(wm) = floatAvailableSpace.mRect.IEnd(wm) - floatMarginISize;
|
2000-04-17 18:40:46 +04:00
|
|
|
} else {
|
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
|
|
|
// this is the IE quirk (see few lines above)
|
|
|
|
// the table is kept in the same line: don't let it overlap the
|
2014-10-22 02:16:13 +04:00
|
|
|
// previous float
|
|
|
|
floatPos.I(wm) = floatAvailableSpace.mRect.IStart(wm);
|
2000-04-17 18:40:46 +04:00
|
|
|
}
|
1998-06-24 21:52:42 +04:00
|
|
|
}
|
2010-08-11 23:32:53 +04:00
|
|
|
// CSS2 spec, 9.5.1 rule [4]: "A floating box's outer top may not
|
|
|
|
// be higher than the top of its containing block." (Since the
|
|
|
|
// containing block is the content edge of the block box, this
|
|
|
|
// means the margin edge of the float can't be higher than the
|
|
|
|
// content edge of the block that contains it.)
|
2014-10-22 02:16:13 +04:00
|
|
|
floatPos.B(wm) = std::max(mBCoord, ContentBStart());
|
1998-06-18 20:25:41 +04:00
|
|
|
|
2010-08-06 08:59:18 +04:00
|
|
|
// Reflow the float after computing its vertical position so it knows
|
|
|
|
// where to break.
|
2015-04-09 12:08:17 +03:00
|
|
|
if (!earlyFloatReflow) {
|
2016-05-14 04:47:14 +03:00
|
|
|
bool pushedDown = mBCoord != restoreBCoord.SavedValue();
|
2013-07-30 08:53:13 +04:00
|
|
|
mBlock->ReflowFloat(*this, adjustedAvailableSpace, aFloat, floatMargin,
|
|
|
|
floatOffsets, pushedDown, reflowStatus);
|
2010-10-07 08:25:47 +04:00
|
|
|
}
|
2019-08-05 20:39:19 +03:00
|
|
|
if (aFloat->GetPrevInFlow()) {
|
|
|
|
floatMargin.BStart(wm) = 0;
|
|
|
|
}
|
|
|
|
if (reflowStatus.IsIncomplete()) {
|
|
|
|
floatMargin.BEnd(wm) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If none of the float fit, and it needs to be pushed in its entirety to the
|
|
|
|
// next page, we need to bail.
|
|
|
|
if (reflowStatus.IsTruncated() || reflowStatus.IsInlineBreakBefore()) {
|
2012-11-08 20:09:38 +04:00
|
|
|
PushFloatPastBreak(aFloat);
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-06 08:59:19 +04:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
// We can't use aFloat->ShouldAvoidBreakInside(mReflowInput) here since
|
2012-11-08 20:09:38 +04:00
|
|
|
// its mIsTopOfPage may be true even though the float isn't at the
|
2014-10-22 02:16:13 +04:00
|
|
|
// top when floatPos.B(wm) > 0.
|
2014-06-20 13:55:35 +04:00
|
|
|
if (ContentBSize() != NS_UNCONSTRAINEDSIZE && !mustPlaceFloat &&
|
2016-07-21 13:36:39 +03:00
|
|
|
(!mReflowInput.mFlags.mIsTopOfPage || floatPos.B(wm) > 0) &&
|
2018-11-15 11:16:23 +03:00
|
|
|
StyleBreakWithin::Avoid == aFloat->StyleDisplay()->mBreakInside &&
|
2017-02-11 17:38:48 +03:00
|
|
|
(!reflowStatus.IsFullyComplete() ||
|
2014-10-22 02:16:13 +04:00
|
|
|
aFloat->BSize(wm) + floatMargin.BStartEnd(wm) >
|
|
|
|
ContentBEnd() - floatPos.B(wm)) &&
|
2012-11-08 20:09:38 +04:00
|
|
|
!aFloat->GetPrevInFlow()) {
|
2010-08-06 08:59:19 +04:00
|
|
|
PushFloatPastBreak(aFloat);
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-08-06 08:59:19 +04:00
|
|
|
}
|
|
|
|
|
2009-07-15 09:19:31 +04:00
|
|
|
// Calculate the actual origin of the float frame's border rect
|
2010-08-11 23:32:53 +04:00
|
|
|
// relative to the parent block; the margin must be added in
|
2009-07-15 09:19:31 +04:00
|
|
|
// to get the border rect
|
2015-01-07 10:10:07 +03:00
|
|
|
LogicalPoint origin(wm, floatMargin.IStart(wm) + floatPos.I(wm),
|
|
|
|
floatMargin.BStart(wm) + floatPos.B(wm));
|
2009-07-15 09:19:31 +04:00
|
|
|
|
|
|
|
// If float is relatively positioned, factor that in as well
|
2016-07-21 13:36:35 +03:00
|
|
|
ReflowInput::ApplyRelativePositioning(aFloat, wm, floatOffsets, &origin,
|
2015-07-16 12:07:57 +03:00
|
|
|
ContainerSize());
|
2009-07-15 09:19:31 +04:00
|
|
|
|
|
|
|
// Position the float and make sure and views are properly
|
|
|
|
// positioned. We need to explicitly position its child views as
|
|
|
|
// well, since we're moving the float after flowing it.
|
2015-07-16 12:07:57 +03:00
|
|
|
bool moved = aFloat->GetLogicalPosition(wm, ContainerSize()) != origin;
|
2010-12-20 04:37:43 +03:00
|
|
|
if (moved) {
|
2015-07-16 12:07:57 +03:00
|
|
|
aFloat->SetPosition(wm, origin, ContainerSize());
|
2010-12-20 04:37:43 +03:00
|
|
|
nsContainerFrame::PositionFrameView(aFloat);
|
|
|
|
nsContainerFrame::PositionChildViews(aFloat);
|
|
|
|
}
|
2009-07-15 09:19:31 +04:00
|
|
|
|
|
|
|
// Update the float combined area state
|
|
|
|
// XXX Floats should really just get invalidated here if necessary
|
2015-01-07 10:10:07 +03:00
|
|
|
mFloatOverflowAreas.UnionWith(aFloat->GetOverflowAreas() +
|
|
|
|
aFloat->GetPosition());
|
2009-07-15 09:19:31 +04:00
|
|
|
|
2009-01-05 03:39:54 +03:00
|
|
|
// Place the float in the float manager
|
2009-07-15 09:19:31 +04:00
|
|
|
// calculate region
|
2014-10-22 02:16:13 +04:00
|
|
|
LogicalRect region = nsFloatManager::CalculateRegionFor(
|
|
|
|
wm, aFloat, floatMargin, ContainerSize());
|
2009-07-15 09:19:31 +04:00
|
|
|
// if the float split, then take up all of the vertical height
|
2014-06-20 13:55:35 +04:00
|
|
|
if (reflowStatus.IsIncomplete() && (NS_UNCONSTRAINEDSIZE != ContentBSize())) {
|
2014-10-22 02:16:13 +04:00
|
|
|
region.BSize(wm) =
|
|
|
|
std::max(region.BSize(wm), ContentBSize() - floatPos.B(wm));
|
2005-11-01 04:16:45 +03:00
|
|
|
}
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->AddFloat(aFloat, region, wm, ContainerSize());
|
2017-01-06 11:36:19 +03:00
|
|
|
|
2009-07-15 09:19:31 +04:00
|
|
|
// store region
|
2015-07-16 12:07:57 +03:00
|
|
|
nsFloatManager::StoreRegionFor(wm, aFloat, region, ContainerSize());
|
2007-06-17 00:27:46 +04:00
|
|
|
|
2018-10-04 20:41:22 +03:00
|
|
|
const bool invalidationDataNeeded =
|
|
|
|
ShapeInvalidationData::IsNeeded(*floatDisplay);
|
|
|
|
|
|
|
|
// If the float's dimensions or shape have changed, note the damage in the
|
2009-01-05 03:39:54 +03:00
|
|
|
// float manager.
|
2018-10-04 20:41:22 +03:00
|
|
|
if (!region.IsEqualEdges(oldRegion) ||
|
|
|
|
!!invalidationData != invalidationDataNeeded ||
|
|
|
|
(invalidationData && !invalidationData->Matches(*floatDisplay))) {
|
2002-04-26 23:19:39 +04:00
|
|
|
// XXXwaterson conservative: we could probably get away with noting
|
|
|
|
// less damage; e.g., if only height has changed, then only note the
|
|
|
|
// area into which the float has grown or from which the float has
|
|
|
|
// shrunk.
|
2014-10-22 02:16:12 +04:00
|
|
|
nscoord blockStart = std::min(region.BStart(wm), oldRegion.BStart(wm));
|
|
|
|
nscoord blockEnd = std::max(region.BEnd(wm), oldRegion.BEnd(wm));
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->IncludeInDamage(blockStart, blockEnd);
|
2002-04-26 23:19:39 +04:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:41:22 +03:00
|
|
|
if (invalidationDataNeeded) {
|
|
|
|
if (invalidationData) {
|
|
|
|
invalidationData->Update(*floatDisplay);
|
|
|
|
} else {
|
|
|
|
aFloat->SetProperty(ShapeInvalidationDataProperty(),
|
|
|
|
new ShapeInvalidationData(*floatDisplay));
|
|
|
|
}
|
|
|
|
} else if (invalidationData) {
|
|
|
|
invalidationData = nullptr;
|
2020-02-06 19:06:49 +03:00
|
|
|
aFloat->RemoveProperty(ShapeInvalidationDataProperty());
|
2018-10-04 20:41:22 +03:00
|
|
|
}
|
|
|
|
|
2017-02-11 17:38:48 +03:00
|
|
|
if (!reflowStatus.IsFullyComplete()) {
|
2010-08-06 08:59:19 +04:00
|
|
|
mBlock->SplitFloat(*this, aFloat, reflowStatus);
|
2014-12-19 19:28:43 +03:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(!aFloat->GetNextInFlow());
|
2010-08-06 08:59:19 +04:00
|
|
|
}
|
|
|
|
|
1999-10-16 03:35:10 +04:00
|
|
|
#ifdef DEBUG
|
2016-09-15 09:32:12 +03:00
|
|
|
if (nsBlockFrame::gNoisyFloatManager) {
|
|
|
|
nscoord tI, tB;
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->GetTranslation(tI, tB);
|
2019-01-30 00:22:14 +03:00
|
|
|
mBlock->ListTag(stdout);
|
2016-09-15 09:32:12 +03:00
|
|
|
printf(": FlowAndPlaceFloat: AddFloat: tIB=%d,%d (%d,%d) {%d,%d,%d,%d}\n",
|
|
|
|
tI, tB, mFloatManagerI, mFloatManagerB, region.IStart(wm),
|
|
|
|
region.BStart(wm), region.ISize(wm), region.BSize(wm));
|
|
|
|
}
|
|
|
|
|
2001-05-01 08:22:57 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
2009-08-31 22:25:35 +04:00
|
|
|
nsRect r = aFloat->GetRect();
|
2001-05-01 08:22:57 +04:00
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2003-10-14 01:51:02 +04:00
|
|
|
printf("placed float: ");
|
2019-01-30 00:22:14 +03:00
|
|
|
aFloat->ListTag(stdout);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" %d,%d,%d,%d\n", r.x, r.y, r.width, r.height);
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-11-05 22:33:01 +03:00
|
|
|
#endif
|
2005-03-23 06:35:08 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|
1998-11-05 22:33:01 +03:00
|
|
|
|
2016-07-21 13:36:36 +03:00
|
|
|
void BlockReflowInput::PushFloatPastBreak(nsIFrame* aFloat) {
|
2010-08-06 08:59:19 +04:00
|
|
|
// This ensures that we:
|
|
|
|
// * don't try to place later but smaller floats (which CSS says
|
|
|
|
// must have their tops below the top of this float)
|
|
|
|
// * don't waste much time trying to reflow this float again until
|
|
|
|
// after the break
|
2018-07-16 19:50:18 +03:00
|
|
|
StyleFloat floatStyle = aFloat->StyleDisplay()->mFloat;
|
2016-08-09 12:32:54 +03:00
|
|
|
if (floatStyle == StyleFloat::Left) {
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->SetPushedLeftFloatPastBreak();
|
2010-08-06 08:59:19 +04:00
|
|
|
} else {
|
2016-08-09 12:32:54 +03:00
|
|
|
MOZ_ASSERT(floatStyle == StyleFloat::Right, "Unexpected float value!");
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->SetPushedRightFloatPastBreak();
|
2010-08-06 08:59:19 +04:00
|
|
|
}
|
|
|
|
|
2010-08-06 08:59:20 +04:00
|
|
|
// Put the float on the pushed floats list, even though it
|
2010-08-06 08:59:19 +04:00
|
|
|
// isn't actually a continuation.
|
2014-02-07 02:07:47 +04:00
|
|
|
DebugOnly<nsresult> rv = mBlock->StealFrame(aFloat);
|
2010-08-06 08:59:19 +04:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "StealFrame should succeed");
|
2014-12-19 19:28:43 +03:00
|
|
|
AppendPushedFloatChain(aFloat);
|
2017-02-11 18:18:04 +03:00
|
|
|
mReflowStatus.SetOverflowIncomplete();
|
2010-08-06 08:59:19 +04:00
|
|
|
}
|
|
|
|
|
1998-12-05 19:02:08 +03:00
|
|
|
/**
|
2003-10-14 01:51:02 +04:00
|
|
|
* Place below-current-line floats.
|
1998-12-05 19:02:08 +03:00
|
|
|
*/
|
2018-08-23 02:29:22 +03:00
|
|
|
void BlockReflowInput::PlaceBelowCurrentLineFloats(nsLineBox* aLine) {
|
|
|
|
MOZ_ASSERT(mBelowCurrentLineFloats.NotEmpty());
|
|
|
|
nsFloatCache* fc = mBelowCurrentLineFloats.Head();
|
1999-09-15 04:28:10 +04:00
|
|
|
while (fc) {
|
1999-10-29 18:34:53 +04:00
|
|
|
#ifdef DEBUG
|
2010-08-06 08:59:20 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
|
|
|
printf("placing bcl float: ");
|
2019-01-30 00:22:14 +03:00
|
|
|
fc->mFloat->ListTag(stdout);
|
2010-08-06 08:59:20 +04:00
|
|
|
printf("\n");
|
|
|
|
}
|
1999-10-29 18:34:53 +04:00
|
|
|
#endif
|
2010-08-06 08:59:20 +04:00
|
|
|
// Place the float
|
2011-09-29 10:19:26 +04:00
|
|
|
bool placed = FlowAndPlaceFloat(fc->mFloat);
|
2010-08-06 08:59:20 +04:00
|
|
|
nsFloatCache* next = fc->Next();
|
|
|
|
if (!placed) {
|
2018-08-23 02:29:22 +03:00
|
|
|
mBelowCurrentLineFloats.Remove(fc);
|
2010-08-06 08:59:20 +04:00
|
|
|
delete fc;
|
2010-08-06 08:59:20 +04:00
|
|
|
aLine->SetHadFloatPushed();
|
1999-02-09 20:31:33 +03:00
|
|
|
}
|
2010-08-06 08:59:20 +04:00
|
|
|
fc = next;
|
1999-02-09 20:31:33 +03:00
|
|
|
}
|
2018-08-23 02:29:22 +03:00
|
|
|
aLine->AppendFloats(mBelowCurrentLineFloats);
|
1999-02-09 20:31:33 +03:00
|
|
|
}
|
|
|
|
|
2016-09-07 05:20:17 +03:00
|
|
|
nscoord BlockReflowInput::ClearFloats(nscoord aBCoord, StyleClear aBreakType,
|
2010-08-06 08:59:19 +04:00
|
|
|
nsIFrame* aReplacedBlock,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags) {
|
1999-10-16 03:35:10 +04:00
|
|
|
#ifdef DEBUG
|
2001-05-01 08:22:57 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2014-06-20 13:55:35 +04:00
|
|
|
printf("clear floats: in: aBCoord=%d\n", aBCoord);
|
1999-10-16 03:35:10 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
#endif
|
1998-10-27 19:51:02 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
#ifdef NOISY_FLOAT_CLEARING
|
2016-09-07 05:20:17 +03:00
|
|
|
printf("BlockReflowInput::ClearFloats: aBCoord=%d breakType=%s\n", aBCoord,
|
|
|
|
nsLineBox::BreakTypeToString(aBreakType));
|
2017-02-09 11:59:07 +03:00
|
|
|
FloatManager()->List(stdout);
|
1999-09-16 23:56:36 +04:00
|
|
|
#endif
|
2013-03-31 11:50:29 +04:00
|
|
|
|
2017-02-09 11:59:07 +03:00
|
|
|
if (!FloatManager()->HasAnyFloats()) {
|
2014-06-20 13:55:35 +04:00
|
|
|
return aBCoord;
|
2013-03-31 11:50:29 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 13:55:35 +04:00
|
|
|
nscoord newBCoord = aBCoord;
|
2008-01-29 10:40:05 +03:00
|
|
|
|
2016-09-03 21:46:58 +03:00
|
|
|
if (aBreakType != StyleClear::None) {
|
2017-02-09 11:59:07 +03:00
|
|
|
newBCoord = FloatManager()->ClearFloats(newBCoord, aBreakType, aFlags);
|
2008-01-29 10:40:05 +03:00
|
|
|
}
|
|
|
|
|
2008-05-04 03:33:36 +04:00
|
|
|
if (aReplacedBlock) {
|
2008-01-29 10:40:05 +03:00
|
|
|
for (;;) {
|
2014-06-20 13:55:35 +04:00
|
|
|
nsFlowAreaRect floatAvailableSpace = GetFloatAvailableSpace(newBCoord);
|
2015-08-03 07:03:09 +03:00
|
|
|
if (ReplacedBlockFitsInAvailSpace(aReplacedBlock, floatAvailableSpace)) {
|
2008-01-29 10:40:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// See the analogous code for inlines in
|
|
|
|
// nsBlockFrame::DoReflowInlineFrames
|
2015-08-03 07:03:09 +03:00
|
|
|
if (!AdvanceToNextBand(floatAvailableSpace.mRect, &newBCoord)) {
|
|
|
|
// Stop trying to clear here; we'll just get pushed to the
|
|
|
|
// next column or page and try again there.
|
|
|
|
break;
|
2008-01-29 10:40:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-09-23 06:25:26 +04:00
|
|
|
|
1999-10-16 03:35:10 +04:00
|
|
|
#ifdef DEBUG
|
2001-05-01 08:22:57 +04:00
|
|
|
if (nsBlockFrame::gNoisyReflow) {
|
|
|
|
nsFrame::IndentBy(stdout, nsBlockFrame::gNoiseIndent);
|
2014-06-20 13:55:35 +04:00
|
|
|
printf("clear floats: out: y=%d\n", newBCoord);
|
1999-10-16 03:35:10 +04:00
|
|
|
}
|
1998-12-05 19:02:08 +03:00
|
|
|
#endif
|
2004-11-25 17:51:00 +03:00
|
|
|
|
2014-06-20 13:55:35 +04:00
|
|
|
return newBCoord;
|
1998-12-05 19:02:08 +03:00
|
|
|
}
|