2009-01-04 16:39:54 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2009-01-04 16:39:54 -08:00
|
|
|
|
|
|
|
/* class that manages rules for positioning floats */
|
|
|
|
|
|
|
|
#include "nsFloatManager.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "nsHTMLReflowState.h"
|
|
|
|
#include "nsBlockDebugFlags.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2009-01-04 16:39:54 -08:00
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nsFloatManager::sCachedFloatManagerCount = 0;
|
2009-01-04 16:39:54 -08:00
|
|
|
void* nsFloatManager::sCachedFloatManagers[NS_FLOAT_MANAGER_CACHE_SIZE];
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// PresShell Arena allocate callback (for nsIntervalSet use below)
|
|
|
|
static void*
|
|
|
|
PSArenaAllocCB(size_t aSize, void* aClosure)
|
|
|
|
{
|
2009-08-17 20:21:06 -07:00
|
|
|
return static_cast<nsIPresShell*>(aClosure)->AllocateMisc(aSize);
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// PresShell Arena free callback (for nsIntervalSet use below)
|
|
|
|
static void
|
|
|
|
PSArenaFreeCB(size_t aSize, void* aPtr, void* aClosure)
|
|
|
|
{
|
2009-08-17 20:21:06 -07:00
|
|
|
static_cast<nsIPresShell*>(aClosure)->FreeMisc(aSize, aPtr);
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsFloatManager
|
|
|
|
|
2014-10-21 15:16:12 -07:00
|
|
|
nsFloatManager::nsFloatManager(nsIPresShell* aPresShell,
|
|
|
|
mozilla::WritingMode aWM)
|
2015-04-01 08:43:58 -07:00
|
|
|
:
|
|
|
|
#ifdef DEBUG
|
|
|
|
mWritingMode(aWM),
|
|
|
|
#endif
|
2015-03-22 02:44:48 -07:00
|
|
|
mLineLeft(0), mBlockStart(0),
|
2010-08-05 21:59:19 -07:00
|
|
|
mFloatDamage(PSArenaAllocCB, PSArenaFreeCB, aPresShell),
|
2011-10-17 07:59:28 -07:00
|
|
|
mPushedLeftFloatPastBreak(false),
|
|
|
|
mPushedRightFloatPastBreak(false),
|
|
|
|
mSplitLeftFloatAcrossBreak(false),
|
|
|
|
mSplitRightFloatAcrossBreak(false)
|
2009-01-04 16:39:54 -08:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsFloatManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFloatManager::~nsFloatManager()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsFloatManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void* nsFloatManager::operator new(size_t aSize) CPP_THROW_NEW
|
|
|
|
{
|
|
|
|
if (sCachedFloatManagerCount > 0) {
|
|
|
|
// We have cached unused instances of this class, return a cached
|
|
|
|
// instance in stead of always creating a new one.
|
|
|
|
return sCachedFloatManagers[--sCachedFloatManagerCount];
|
|
|
|
}
|
|
|
|
|
|
|
|
// The cache is empty, this means we haveto create a new instance using
|
|
|
|
// the global |operator new|.
|
2015-03-26 17:01:12 -07:00
|
|
|
return moz_xmalloc(aSize);
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFloatManager::operator delete(void* aPtr, size_t aSize)
|
|
|
|
{
|
|
|
|
if (!aPtr)
|
|
|
|
return;
|
|
|
|
// This float manager is no longer used, if there's still room in
|
|
|
|
// the cache we'll cache this float manager, unless the layout
|
|
|
|
// module was already shut down.
|
|
|
|
|
|
|
|
if (sCachedFloatManagerCount < NS_FLOAT_MANAGER_CACHE_SIZE &&
|
|
|
|
sCachedFloatManagerCount >= 0) {
|
|
|
|
// There's still space in the cache for more instances, put this
|
|
|
|
// instance in the cache in stead of deleting it.
|
|
|
|
|
|
|
|
sCachedFloatManagers[sCachedFloatManagerCount++] = aPtr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The cache is full, or the layout module has been shut down,
|
|
|
|
// delete this float manager.
|
2015-03-26 17:01:12 -07:00
|
|
|
free(aPtr);
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void nsFloatManager::Shutdown()
|
|
|
|
{
|
|
|
|
// The layout module is being shut down, clean up the cache and
|
|
|
|
// disable further caching.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t i;
|
2009-01-04 16:39:54 -08:00
|
|
|
|
|
|
|
for (i = 0; i < sCachedFloatManagerCount; i++) {
|
|
|
|
void* floatManager = sCachedFloatManagers[i];
|
|
|
|
if (floatManager)
|
2015-03-26 17:01:12 -07:00
|
|
|
free(floatManager);
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disable further caching.
|
|
|
|
sCachedFloatManagerCount = -1;
|
|
|
|
}
|
|
|
|
|
2015-04-01 08:43:58 -07:00
|
|
|
#define CHECK_BLOCK_DIR(aWM) \
|
|
|
|
NS_ASSERTION(aWM.GetBlockDir() == mWritingMode.value.GetBlockDir(), \
|
|
|
|
"incompatible writing modes")
|
|
|
|
|
2009-04-08 13:52:37 -07:00
|
|
|
nsFlowAreaRect
|
2014-10-21 15:16:12 -07:00
|
|
|
nsFloatManager::GetFlowArea(WritingMode aWM, nscoord aBOffset,
|
|
|
|
BandInfoType aInfoType, nscoord aBSize,
|
|
|
|
LogicalRect aContentArea, SavedState* aState,
|
2015-07-16 02:07:57 -07:00
|
|
|
const nsSize& aContainerSize) const
|
2009-01-04 16:39:54 -08:00
|
|
|
{
|
2015-04-01 08:43:58 -07:00
|
|
|
CHECK_BLOCK_DIR(aWM);
|
2014-10-21 15:16:12 -07:00
|
|
|
NS_ASSERTION(aBSize >= 0, "unexpected max block size");
|
|
|
|
NS_ASSERTION(aContentArea.ISize(aWM) >= 0,
|
|
|
|
"unexpected content area inline size");
|
2009-01-04 16:39:54 -08:00
|
|
|
|
2015-03-22 02:44:48 -07:00
|
|
|
nscoord blockStart = aBOffset + mBlockStart;
|
2014-10-21 15:16:12 -07:00
|
|
|
if (blockStart < nscoord_MIN) {
|
2009-01-06 15:21:00 -08:00
|
|
|
NS_WARNING("bad value");
|
2014-10-21 15:16:12 -07:00
|
|
|
blockStart = nscoord_MIN;
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
2009-04-08 13:52:36 -07:00
|
|
|
// Determine the last float that we should consider.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t floatCount;
|
2009-04-08 13:52:36 -07:00
|
|
|
if (aState) {
|
|
|
|
// Use the provided state.
|
|
|
|
floatCount = aState->mFloatInfoCount;
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(floatCount <= mFloats.Length(), "bad state");
|
2009-04-08 13:52:36 -07:00
|
|
|
} else {
|
|
|
|
// Use our current state.
|
|
|
|
floatCount = mFloats.Length();
|
|
|
|
}
|
|
|
|
|
2009-01-04 16:39:54 -08:00
|
|
|
// If there are no floats at all, or we're below the last one, return
|
|
|
|
// quickly.
|
|
|
|
if (floatCount == 0 ||
|
2014-10-21 15:16:12 -07:00
|
|
|
(mFloats[floatCount-1].mLeftBEnd <= blockStart &&
|
|
|
|
mFloats[floatCount-1].mRightBEnd <= blockStart)) {
|
2014-10-21 15:16:13 -07:00
|
|
|
return nsFlowAreaRect(aWM, aContentArea.IStart(aWM), aBOffset,
|
|
|
|
aContentArea.ISize(aWM), aBSize, false);
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
2014-10-21 15:16:12 -07:00
|
|
|
nscoord blockEnd;
|
|
|
|
if (aBSize == nscoord_MAX) {
|
2009-07-08 18:10:29 -07:00
|
|
|
// This warning (and the two below) are possible to hit on pages
|
|
|
|
// with really large objects.
|
|
|
|
NS_WARN_IF_FALSE(aInfoType == BAND_FROM_POINT,
|
|
|
|
"bad height");
|
2014-10-21 15:16:12 -07:00
|
|
|
blockEnd = nscoord_MAX;
|
2009-01-04 16:39:54 -08:00
|
|
|
} else {
|
2014-10-21 15:16:12 -07:00
|
|
|
blockEnd = blockStart + aBSize;
|
|
|
|
if (blockEnd < blockStart || blockEnd > nscoord_MAX) {
|
2009-01-06 15:21:00 -08:00
|
|
|
NS_WARNING("bad value");
|
2014-10-21 15:16:12 -07:00
|
|
|
blockEnd = nscoord_MAX;
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
}
|
2015-07-16 02:07:57 -07:00
|
|
|
nscoord lineLeft = mLineLeft + aContentArea.LineLeft(aWM, aContainerSize);
|
|
|
|
nscoord lineRight = mLineLeft + aContentArea.LineRight(aWM, aContainerSize);
|
2015-03-22 02:44:48 -07:00
|
|
|
if (lineRight < lineLeft) {
|
2009-01-06 15:21:00 -08:00
|
|
|
NS_WARNING("bad value");
|
2015-03-22 02:44:48 -07:00
|
|
|
lineRight = lineLeft;
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Walk backwards through the floats until we either hit the front of
|
2014-10-21 15:16:12 -07:00
|
|
|
// the list or we're above |blockStart|.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool haveFloats = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = floatCount; i > 0; --i) {
|
2009-01-04 16:39:54 -08:00
|
|
|
const FloatInfo &fi = mFloats[i-1];
|
2014-10-21 15:16:12 -07:00
|
|
|
if (fi.mLeftBEnd <= blockStart && fi.mRightBEnd <= blockStart) {
|
2009-01-04 16:39:54 -08:00
|
|
|
// There aren't any more floats that could intersect this band.
|
|
|
|
break;
|
|
|
|
}
|
2015-03-22 02:44:48 -07:00
|
|
|
if (fi.IsEmpty()) {
|
2009-01-04 16:39:54 -08:00
|
|
|
// For compatibility, ignore floats with empty rects, even though it
|
|
|
|
// disagrees with the spec. (We might want to fix this in the
|
|
|
|
// future, though.)
|
|
|
|
continue;
|
|
|
|
}
|
2014-10-21 15:16:12 -07:00
|
|
|
|
2015-03-22 02:44:48 -07:00
|
|
|
nscoord floatBStart = fi.BStart();
|
|
|
|
nscoord floatBEnd = fi.BEnd();
|
2014-10-21 15:16:12 -07:00
|
|
|
if (blockStart < floatBStart && aInfoType == BAND_FROM_POINT) {
|
2009-01-04 16:39:54 -08:00
|
|
|
// This float is below our band. Shrink our band's height if needed.
|
2014-10-21 15:16:12 -07:00
|
|
|
if (floatBStart < blockEnd) {
|
|
|
|
blockEnd = floatBStart;
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
2009-05-20 04:21:34 -07:00
|
|
|
}
|
2014-10-21 15:16:12 -07:00
|
|
|
// If blockStart == blockEnd (which happens only with WIDTH_WITHIN_HEIGHT),
|
2009-05-20 04:21:34 -07:00
|
|
|
// we include floats that begin at our 0-height vertical area. We
|
|
|
|
// need to to this to satisfy the invariant that a
|
|
|
|
// WIDTH_WITHIN_HEIGHT call is at least as narrow on both sides as a
|
2014-10-21 15:16:12 -07:00
|
|
|
// BAND_WITHIN_POINT call beginning at its blockStart.
|
|
|
|
else if (blockStart < floatBEnd &&
|
|
|
|
(floatBStart < blockEnd ||
|
|
|
|
(floatBStart == blockEnd && blockStart == blockEnd))) {
|
2009-01-04 16:39:54 -08:00
|
|
|
// This float is in our band.
|
|
|
|
|
|
|
|
// Shrink our band's height if needed.
|
2014-10-21 15:16:12 -07:00
|
|
|
if (floatBEnd < blockEnd && aInfoType == BAND_FROM_POINT) {
|
|
|
|
blockEnd = floatBEnd;
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shrink our band's width if needed.
|
2015-09-18 08:25:21 -07:00
|
|
|
uint8_t floatStyle = fi.mFrame->StyleDisplay()->PhysicalFloats(aWM);
|
|
|
|
if (floatStyle == NS_STYLE_FLOAT_LEFT) {
|
2015-03-22 02:44:48 -07:00
|
|
|
// A left float
|
|
|
|
nscoord lineRightEdge = fi.LineRight();
|
|
|
|
if (lineRightEdge > lineLeft) {
|
|
|
|
lineLeft = lineRightEdge;
|
2009-01-06 15:21:00 -08:00
|
|
|
// Only set haveFloats to true if the float is inside our
|
|
|
|
// containing block. This matches the spec for what some
|
|
|
|
// callers want and disagrees for other callers, so we should
|
|
|
|
// probably provide better information at some point.
|
2011-10-17 07:59:28 -07:00
|
|
|
haveFloats = true;
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
} else {
|
2015-03-22 02:44:48 -07:00
|
|
|
// A right float
|
|
|
|
nscoord lineLeftEdge = fi.LineLeft();
|
|
|
|
if (lineLeftEdge < lineRight) {
|
|
|
|
lineRight = lineLeftEdge;
|
2009-01-06 15:21:00 -08:00
|
|
|
// See above.
|
2011-10-17 07:59:28 -07:00
|
|
|
haveFloats = true;
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-21 15:16:13 -07:00
|
|
|
nscoord blockSize = (blockEnd == nscoord_MAX) ?
|
|
|
|
nscoord_MAX : (blockEnd - blockStart);
|
2015-03-22 02:44:48 -07:00
|
|
|
// convert back from LineLeft/Right to IStart
|
2015-07-16 02:08:05 -07:00
|
|
|
nscoord inlineStart = aWM.IsBidiLTR()
|
2015-07-16 02:07:57 -07:00
|
|
|
? lineLeft - mLineLeft
|
2015-07-16 02:08:05 -07:00
|
|
|
: mLineLeft - lineRight +
|
|
|
|
LogicalSize(aWM, aContainerSize).ISize(aWM);
|
2015-03-22 02:44:48 -07:00
|
|
|
|
|
|
|
return nsFlowAreaRect(aWM, inlineStart, blockStart - mBlockStart,
|
|
|
|
lineRight - lineLeft, blockSize, haveFloats);
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-10-21 15:16:12 -07:00
|
|
|
nsFloatManager::AddFloat(nsIFrame* aFloatFrame, const LogicalRect& aMarginRect,
|
2015-07-16 02:07:57 -07:00
|
|
|
WritingMode aWM, const nsSize& aContainerSize)
|
2009-01-04 16:39:54 -08:00
|
|
|
{
|
2015-04-01 08:43:58 -07:00
|
|
|
CHECK_BLOCK_DIR(aWM);
|
2014-10-21 15:16:12 -07:00
|
|
|
NS_ASSERTION(aMarginRect.ISize(aWM) >= 0, "negative inline size!");
|
|
|
|
NS_ASSERTION(aMarginRect.BSize(aWM) >= 0, "negative block size!");
|
2009-01-04 16:39:54 -08:00
|
|
|
|
2015-03-22 02:44:48 -07:00
|
|
|
FloatInfo info(aFloatFrame,
|
2015-07-16 02:07:57 -07:00
|
|
|
aMarginRect.LineLeft(aWM, aContainerSize) + mLineLeft,
|
2015-03-22 02:44:48 -07:00
|
|
|
aMarginRect.BStart(aWM) + mBlockStart,
|
|
|
|
aMarginRect.ISize(aWM),
|
|
|
|
aMarginRect.BSize(aWM));
|
2009-01-04 16:39:54 -08:00
|
|
|
|
2014-10-21 15:16:12 -07:00
|
|
|
// Set mLeftBEnd and mRightBEnd.
|
2009-01-04 16:39:54 -08:00
|
|
|
if (HasAnyFloats()) {
|
|
|
|
FloatInfo &tail = mFloats[mFloats.Length() - 1];
|
2014-10-21 15:16:12 -07:00
|
|
|
info.mLeftBEnd = tail.mLeftBEnd;
|
|
|
|
info.mRightBEnd = tail.mRightBEnd;
|
2009-01-04 16:39:54 -08:00
|
|
|
} else {
|
2014-10-21 15:16:12 -07:00
|
|
|
info.mLeftBEnd = nscoord_MIN;
|
|
|
|
info.mRightBEnd = nscoord_MIN;
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
2015-09-18 08:25:21 -07:00
|
|
|
uint8_t floatStyle = aFloatFrame->StyleDisplay()->PhysicalFloats(aWM);
|
2009-01-04 16:39:54 -08:00
|
|
|
NS_ASSERTION(floatStyle == NS_STYLE_FLOAT_LEFT ||
|
|
|
|
floatStyle == NS_STYLE_FLOAT_RIGHT, "unexpected float");
|
2015-03-22 02:44:48 -07:00
|
|
|
nscoord& sideBEnd = floatStyle == NS_STYLE_FLOAT_LEFT ? info.mLeftBEnd
|
|
|
|
: info.mRightBEnd;
|
|
|
|
nscoord thisBEnd = info.BEnd();
|
2014-10-21 15:16:12 -07:00
|
|
|
if (thisBEnd > sideBEnd)
|
|
|
|
sideBEnd = thisBEnd;
|
2009-01-04 16:39:54 -08:00
|
|
|
|
|
|
|
if (!mFloats.AppendElement(info))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-22 02:44:48 -07:00
|
|
|
// static
|
2014-10-21 15:16:12 -07:00
|
|
|
LogicalRect
|
|
|
|
nsFloatManager::CalculateRegionFor(WritingMode aWM,
|
|
|
|
nsIFrame* aFloat,
|
|
|
|
const LogicalMargin& aMargin,
|
2015-07-16 02:07:57 -07:00
|
|
|
const nsSize& aContainerSize)
|
2009-07-14 22:19:31 -07:00
|
|
|
{
|
2013-08-08 17:20:17 -07:00
|
|
|
// We consider relatively positioned frames at their original position.
|
2014-10-21 15:16:12 -07:00
|
|
|
LogicalRect region(aWM, nsRect(aFloat->GetNormalPosition(),
|
|
|
|
aFloat->GetSize()),
|
2015-07-16 02:07:57 -07:00
|
|
|
aContainerSize);
|
2009-07-14 22:19:31 -07:00
|
|
|
|
|
|
|
// Float region includes its margin
|
2014-10-21 15:16:12 -07:00
|
|
|
region.Inflate(aWM, aMargin);
|
2009-07-14 22:19:31 -07:00
|
|
|
|
|
|
|
// Don't store rectangles with negative margin-box width or height in
|
|
|
|
// the float manager; it can't deal with them.
|
2014-10-21 15:16:12 -07:00
|
|
|
if (region.ISize(aWM) < 0) {
|
2009-07-14 22:19:31 -07:00
|
|
|
// Preserve the right margin-edge for left floats and the left
|
|
|
|
// margin-edge for right floats
|
2013-08-08 17:20:17 -07:00
|
|
|
const nsStyleDisplay* display = aFloat->StyleDisplay();
|
2015-09-18 08:25:21 -07:00
|
|
|
uint8_t floatStyle = display->PhysicalFloats(aWM);
|
|
|
|
if ((NS_STYLE_FLOAT_LEFT == floatStyle) == aWM.IsBidiLTR()) {
|
2014-10-21 15:16:12 -07:00
|
|
|
region.IStart(aWM) = region.IEnd(aWM);
|
2009-07-14 22:19:31 -07:00
|
|
|
}
|
2014-10-21 15:16:12 -07:00
|
|
|
region.ISize(aWM) = 0;
|
2009-07-14 22:19:31 -07:00
|
|
|
}
|
2014-10-21 15:16:12 -07:00
|
|
|
if (region.BSize(aWM) < 0) {
|
|
|
|
region.BSize(aWM) = 0;
|
2009-07-14 22:19:31 -07:00
|
|
|
}
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
2015-02-04 15:22:27 -08:00
|
|
|
NS_DECLARE_FRAME_PROPERTY(FloatRegionProperty, DeleteValue<nsMargin>)
|
2010-03-28 18:46:55 -07:00
|
|
|
|
2014-10-21 15:16:12 -07:00
|
|
|
LogicalRect
|
|
|
|
nsFloatManager::GetRegionFor(WritingMode aWM, nsIFrame* aFloat,
|
2015-07-16 02:07:57 -07:00
|
|
|
const nsSize& aContainerSize)
|
2009-07-14 22:19:31 -07:00
|
|
|
{
|
2015-07-16 02:07:57 -07:00
|
|
|
LogicalRect region = aFloat->GetLogicalRect(aWM, aContainerSize);
|
2010-03-28 18:46:55 -07:00
|
|
|
void* storedRegion = aFloat->Properties().Get(FloatRegionProperty());
|
2009-07-14 22:19:31 -07:00
|
|
|
if (storedRegion) {
|
|
|
|
nsMargin margin = *static_cast<nsMargin*>(storedRegion);
|
2014-10-21 15:16:12 -07:00
|
|
|
region.Inflate(aWM, LogicalMargin(aWM, margin));
|
2009-07-14 22:19:31 -07:00
|
|
|
}
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
2011-05-08 01:00:29 -07:00
|
|
|
void
|
2014-10-21 15:16:12 -07:00
|
|
|
nsFloatManager::StoreRegionFor(WritingMode aWM, nsIFrame* aFloat,
|
|
|
|
const LogicalRect& aRegion,
|
2015-07-16 02:07:57 -07:00
|
|
|
const nsSize& aContainerSize)
|
2009-07-14 22:19:31 -07:00
|
|
|
{
|
2015-07-16 02:07:57 -07:00
|
|
|
nsRect region = aRegion.GetPhysicalRect(aWM, aContainerSize);
|
2009-07-14 22:19:31 -07:00
|
|
|
nsRect rect = aFloat->GetRect();
|
2010-03-28 18:46:55 -07:00
|
|
|
FrameProperties props = aFloat->Properties();
|
2014-10-21 15:16:12 -07:00
|
|
|
if (region.IsEqualEdges(rect)) {
|
2010-03-28 18:46:55 -07:00
|
|
|
props.Delete(FloatRegionProperty());
|
2009-07-14 22:19:31 -07:00
|
|
|
}
|
|
|
|
else {
|
2010-03-28 18:46:55 -07:00
|
|
|
nsMargin* storedMargin = static_cast<nsMargin*>
|
|
|
|
(props.Get(FloatRegionProperty()));
|
2009-07-14 22:19:31 -07:00
|
|
|
if (!storedMargin) {
|
|
|
|
storedMargin = new nsMargin();
|
2010-03-28 18:46:55 -07:00
|
|
|
props.Set(FloatRegionProperty(), storedMargin);
|
2009-07-14 22:19:31 -07:00
|
|
|
}
|
2014-10-21 15:16:12 -07:00
|
|
|
*storedMargin = region - rect;
|
2009-07-14 22:19:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-04 16:39:54 -08:00
|
|
|
nsresult
|
|
|
|
nsFloatManager::RemoveTrailingRegions(nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
if (!aFrameList) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// This could be a good bit simpler if we could guarantee that the
|
|
|
|
// floats given were at the end of our list, so we could just search
|
|
|
|
// for the head of aFrameList. (But we can't;
|
|
|
|
// layout/reftests/bugs/421710-1.html crashes.)
|
2013-09-02 01:41:57 -07:00
|
|
|
nsTHashtable<nsPtrHashKey<nsIFrame> > frameSet(1);
|
2009-01-04 16:39:54 -08:00
|
|
|
|
|
|
|
for (nsIFrame* f = aFrameList; f; f = f->GetNextSibling()) {
|
2011-11-08 12:24:37 -08:00
|
|
|
frameSet.PutEntry(f);
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t newLength = mFloats.Length();
|
2009-01-04 16:39:54 -08:00
|
|
|
while (newLength > 0) {
|
|
|
|
if (!frameSet.Contains(mFloats[newLength - 1].mFrame)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
--newLength;
|
|
|
|
}
|
2009-01-06 15:21:00 -08:00
|
|
|
mFloats.TruncateLength(newLength);
|
2009-01-04 16:39:54 -08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mFloats.Length(); ++i) {
|
2009-01-04 16:39:54 -08:00
|
|
|
NS_ASSERTION(!frameSet.Contains(mFloats[i].mFrame),
|
|
|
|
"Frame region deletion was requested but we couldn't delete it");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFloatManager::PushState(SavedState* aState)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aState, "Need a place to save state");
|
|
|
|
|
|
|
|
// This is a cheap push implementation, which
|
|
|
|
// only saves the (x,y) and last frame in the mFrameInfoMap
|
|
|
|
// which is enough info to get us back to where we should be
|
|
|
|
// when pop is called.
|
|
|
|
//
|
|
|
|
// This push/pop mechanism is used to undo any
|
|
|
|
// floats that were added during the unconstrained reflow
|
|
|
|
// in nsBlockReflowContext::DoReflowBlock(). (See bug 96736)
|
|
|
|
//
|
|
|
|
// It should also be noted that the state for mFloatDamage is
|
|
|
|
// intentionally not saved or restored in PushState() and PopState(),
|
|
|
|
// since that could lead to bugs where damage is missed/dropped when
|
|
|
|
// we move from position A to B (during the intermediate incremental
|
|
|
|
// reflow mentioned above) and then from B to C during the subsequent
|
|
|
|
// reflow. In the typical case A and C will be the same, but not always.
|
|
|
|
// Allowing mFloatDamage to accumulate the damage incurred during both
|
|
|
|
// reflows ensures that nothing gets missed.
|
2015-03-22 02:44:48 -07:00
|
|
|
aState->mLineLeft = mLineLeft;
|
|
|
|
aState->mBlockStart = mBlockStart;
|
2010-08-05 21:59:19 -07:00
|
|
|
aState->mPushedLeftFloatPastBreak = mPushedLeftFloatPastBreak;
|
|
|
|
aState->mPushedRightFloatPastBreak = mPushedRightFloatPastBreak;
|
2010-08-05 21:59:19 -07:00
|
|
|
aState->mSplitLeftFloatAcrossBreak = mSplitLeftFloatAcrossBreak;
|
|
|
|
aState->mSplitRightFloatAcrossBreak = mSplitRightFloatAcrossBreak;
|
2009-01-04 16:39:54 -08:00
|
|
|
aState->mFloatInfoCount = mFloats.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFloatManager::PopState(SavedState* aState)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aState, "No state to restore?");
|
|
|
|
|
2015-03-22 02:44:48 -07:00
|
|
|
mLineLeft = aState->mLineLeft;
|
|
|
|
mBlockStart = aState->mBlockStart;
|
2010-08-05 21:59:19 -07:00
|
|
|
mPushedLeftFloatPastBreak = aState->mPushedLeftFloatPastBreak;
|
|
|
|
mPushedRightFloatPastBreak = aState->mPushedRightFloatPastBreak;
|
2010-08-05 21:59:19 -07:00
|
|
|
mSplitLeftFloatAcrossBreak = aState->mSplitLeftFloatAcrossBreak;
|
|
|
|
mSplitRightFloatAcrossBreak = aState->mSplitRightFloatAcrossBreak;
|
2009-01-04 16:39:54 -08:00
|
|
|
|
|
|
|
NS_ASSERTION(aState->mFloatInfoCount <= mFloats.Length(),
|
|
|
|
"somebody misused PushState/PopState");
|
2009-01-06 15:21:00 -08:00
|
|
|
mFloats.TruncateLength(aState->mFloatInfoCount);
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
2015-03-22 02:44:48 -07:00
|
|
|
nsFloatManager::GetLowestFloatTop() const
|
2009-01-04 16:39:54 -08:00
|
|
|
{
|
2010-08-05 21:59:19 -07:00
|
|
|
if (mPushedLeftFloatPastBreak || mPushedRightFloatPastBreak) {
|
|
|
|
return nscoord_MAX;
|
|
|
|
}
|
2009-01-04 16:39:54 -08:00
|
|
|
if (!HasAnyFloats()) {
|
|
|
|
return nscoord_MIN;
|
|
|
|
}
|
2015-03-22 02:44:48 -07:00
|
|
|
return mFloats[mFloats.Length() -1].BStart() - mBlockStart;
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2009-01-04 16:39:54 -08:00
|
|
|
void
|
|
|
|
DebugListFloatManager(const nsFloatManager *aFloatManager)
|
|
|
|
{
|
|
|
|
aFloatManager->List(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFloatManager::List(FILE* out) const
|
|
|
|
{
|
|
|
|
if (!HasAnyFloats())
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mFloats.Length(); ++i) {
|
2009-01-04 16:39:54 -08:00
|
|
|
const FloatInfo &fi = mFloats[i];
|
2014-01-26 14:07:02 -08:00
|
|
|
fprintf_stderr(out, "Float %u: frame=%p rect={%d,%d,%d,%d} ymost={l:%d, r:%d}\n",
|
|
|
|
i, static_cast<void*>(fi.mFrame),
|
2015-03-22 02:44:48 -07:00
|
|
|
fi.LineLeft(), fi.BStart(), fi.ISize(), fi.BSize(),
|
2014-10-21 15:16:12 -07:00
|
|
|
fi.mLeftBEnd, fi.mRightBEnd);
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nscoord
|
2015-03-22 02:44:48 -07:00
|
|
|
nsFloatManager::ClearFloats(nscoord aBCoord, uint8_t aBreakType,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags) const
|
2009-01-04 16:39:54 -08:00
|
|
|
{
|
2010-08-05 21:59:19 -07:00
|
|
|
if (!(aFlags & DONT_CLEAR_PUSHED_FLOATS) && ClearContinues(aBreakType)) {
|
2010-08-05 21:59:19 -07:00
|
|
|
return nscoord_MAX;
|
|
|
|
}
|
2009-01-04 16:39:54 -08:00
|
|
|
if (!HasAnyFloats()) {
|
2014-10-21 15:16:12 -07:00
|
|
|
return aBCoord;
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
2015-03-22 02:44:48 -07:00
|
|
|
nscoord blockEnd = aBCoord + mBlockStart;
|
2009-01-04 16:39:54 -08:00
|
|
|
|
|
|
|
const FloatInfo &tail = mFloats[mFloats.Length() - 1];
|
|
|
|
switch (aBreakType) {
|
2014-03-02 09:42:16 -08:00
|
|
|
case NS_STYLE_CLEAR_BOTH:
|
2014-10-21 15:16:12 -07:00
|
|
|
blockEnd = std::max(blockEnd, tail.mLeftBEnd);
|
|
|
|
blockEnd = std::max(blockEnd, tail.mRightBEnd);
|
2009-01-04 16:39:54 -08:00
|
|
|
break;
|
|
|
|
case NS_STYLE_CLEAR_LEFT:
|
2015-03-22 02:44:48 -07:00
|
|
|
blockEnd = std::max(blockEnd, tail.mLeftBEnd);
|
2009-01-04 16:39:54 -08:00
|
|
|
break;
|
|
|
|
case NS_STYLE_CLEAR_RIGHT:
|
2015-03-22 02:44:48 -07:00
|
|
|
blockEnd = std::max(blockEnd, tail.mRightBEnd);
|
2009-01-04 16:39:54 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Do nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-22 02:44:48 -07:00
|
|
|
blockEnd -= mBlockStart;
|
2009-01-04 16:39:54 -08:00
|
|
|
|
2014-10-21 15:16:12 -07:00
|
|
|
return blockEnd;
|
2009-01-04 16:39:54 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsFloatManager::ClearContinues(uint8_t aBreakType) const
|
2009-08-31 11:25:36 -07:00
|
|
|
{
|
2010-08-05 21:59:19 -07:00
|
|
|
return ((mPushedLeftFloatPastBreak || mSplitLeftFloatAcrossBreak) &&
|
2014-03-02 09:42:16 -08:00
|
|
|
(aBreakType == NS_STYLE_CLEAR_BOTH ||
|
2010-08-05 21:59:19 -07:00
|
|
|
aBreakType == NS_STYLE_CLEAR_LEFT)) ||
|
|
|
|
((mPushedRightFloatPastBreak || mSplitRightFloatAcrossBreak) &&
|
2014-03-02 09:42:16 -08:00
|
|
|
(aBreakType == NS_STYLE_CLEAR_BOTH ||
|
2010-08-05 21:59:19 -07:00
|
|
|
aBreakType == NS_STYLE_CLEAR_RIGHT));
|
2009-08-31 11:25:36 -07:00
|
|
|
}
|
|
|
|
|
2009-01-04 16:39:54 -08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FloatInfo
|
|
|
|
|
2015-03-22 02:44:48 -07:00
|
|
|
nsFloatManager::FloatInfo::FloatInfo(nsIFrame* aFrame,
|
|
|
|
nscoord aLineLeft, nscoord aBStart,
|
|
|
|
nscoord aISize, nscoord aBSize)
|
|
|
|
: mFrame(aFrame)
|
|
|
|
, mRect(aLineLeft, aBStart, aISize, aBSize)
|
2009-01-04 16:39:54 -08:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsFloatManager::FloatInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2009-01-04 17:25:58 -08:00
|
|
|
nsFloatManager::FloatInfo::FloatInfo(const FloatInfo& aOther)
|
|
|
|
: mFrame(aOther.mFrame),
|
2014-10-21 15:16:12 -07:00
|
|
|
mLeftBEnd(aOther.mLeftBEnd),
|
2015-03-22 02:44:48 -07:00
|
|
|
mRightBEnd(aOther.mRightBEnd),
|
|
|
|
mRect(aOther.mRect)
|
2009-01-04 17:25:58 -08:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsFloatManager::FloatInfo);
|
|
|
|
}
|
|
|
|
|
2009-01-04 16:39:54 -08:00
|
|
|
nsFloatManager::FloatInfo::~FloatInfo()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsFloatManager::FloatInfo);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsAutoFloatManager::~nsAutoFloatManager()
|
|
|
|
{
|
|
|
|
// Restore the old float manager in the reflow state if necessary.
|
|
|
|
if (mNew) {
|
|
|
|
#ifdef NOISY_FLOATMANAGER
|
|
|
|
printf("restoring old float manager %p\n", mOld);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mReflowState.mFloatManager = mOld;
|
|
|
|
|
|
|
|
#ifdef NOISY_FLOATMANAGER
|
|
|
|
if (mOld) {
|
|
|
|
static_cast<nsFrame *>(mReflowState.frame)->ListTag(stdout);
|
|
|
|
printf(": space-manager %p after reflow\n", mOld);
|
|
|
|
mOld->List(stdout);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
delete mNew;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsAutoFloatManager::CreateFloatManager(nsPresContext *aPresContext)
|
|
|
|
{
|
|
|
|
// Create a new float manager and install it in the reflow
|
|
|
|
// state. `Remember' the old float manager so we can restore it
|
|
|
|
// later.
|
2014-10-21 15:16:12 -07:00
|
|
|
mNew = new nsFloatManager(aPresContext->PresShell(),
|
|
|
|
mReflowState.GetWritingMode());
|
2009-01-04 16:39:54 -08:00
|
|
|
if (! mNew)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
#ifdef NOISY_FLOATMANAGER
|
|
|
|
printf("constructed new float manager %p (replacing %p)\n",
|
|
|
|
mNew, mReflowState.mFloatManager);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Set the float manager in the existing reflow state
|
|
|
|
mOld = mReflowState.mFloatManager;
|
|
|
|
mReflowState.mFloatManager = mNew;
|
|
|
|
return NS_OK;
|
|
|
|
}
|