2009-01-05 03:39:54 +03:00
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
|
|
|
|
/* class that manages rules for positioning floats */
|
|
|
|
|
|
|
|
|
|
#include "nsFloatManager.h"
|
2016-09-15 06:29:14 +03:00
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
2017-03-13 07:03:40 +03:00
|
|
|
|
#include <initializer_list>
|
2016-09-15 06:29:14 +03:00
|
|
|
|
|
2016-07-21 13:36:34 +03:00
|
|
|
|
#include "mozilla/ReflowInput.h"
|
2017-01-06 11:36:43 +03:00
|
|
|
|
#include "mozilla/ShapeUtils.h"
|
2016-09-15 09:32:12 +03:00
|
|
|
|
#include "nsBlockFrame.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
|
#include "nsError.h"
|
2016-09-15 06:29:14 +03:00
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
|
#include "nsMemory.h"
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t nsFloatManager::sCachedFloatManagerCount = 0;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
void* nsFloatManager::sCachedFloatManagers[NS_FLOAT_MANAGER_CACHE_SIZE];
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// nsFloatManager
|
|
|
|
|
|
2014-10-22 02:16:12 +04:00
|
|
|
|
nsFloatManager::nsFloatManager(nsIPresShell* aPresShell,
|
|
|
|
|
mozilla::WritingMode aWM)
|
2015-04-01 18:43:58 +03:00
|
|
|
|
:
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
mWritingMode(aWM),
|
|
|
|
|
#endif
|
2015-03-22 12:44:48 +03:00
|
|
|
|
mLineLeft(0), mBlockStart(0),
|
2017-05-24 16:35:26 +03:00
|
|
|
|
mFloatDamage(aPresShell),
|
2011-10-17 18:59:28 +04:00
|
|
|
|
mPushedLeftFloatPastBreak(false),
|
|
|
|
|
mPushedRightFloatPastBreak(false),
|
|
|
|
|
mSplitLeftFloatAcrossBreak(false),
|
|
|
|
|
mSplitRightFloatAcrossBreak(false)
|
2009-01-05 03:39:54 +03: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];
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-24 12:47:33 +03:00
|
|
|
|
// The cache is empty, this means we have to create a new instance using
|
2009-01-05 03:39:54 +03:00
|
|
|
|
// the global |operator new|.
|
2015-03-27 03:01:12 +03:00
|
|
|
|
return moz_xmalloc(aSize);
|
2009-01-05 03:39:54 +03: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-27 03:01:12 +03:00
|
|
|
|
free(aPtr);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
|
void nsFloatManager::Shutdown()
|
|
|
|
|
{
|
|
|
|
|
// The layout module is being shut down, clean up the cache and
|
|
|
|
|
// disable further caching.
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
int32_t i;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < sCachedFloatManagerCount; i++) {
|
|
|
|
|
void* floatManager = sCachedFloatManagers[i];
|
|
|
|
|
if (floatManager)
|
2015-03-27 03:01:12 +03:00
|
|
|
|
free(floatManager);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Disable further caching.
|
|
|
|
|
sCachedFloatManagerCount = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 13:10:23 +03:00
|
|
|
|
#define CHECK_BLOCK_AND_LINE_DIR(aWM) \
|
|
|
|
|
NS_ASSERTION((aWM).GetBlockDir() == mWritingMode.GetBlockDir() && \
|
|
|
|
|
(aWM).IsLineInverted() == mWritingMode.IsLineInverted(), \
|
|
|
|
|
"incompatible writing modes")
|
2015-04-01 18:43:58 +03:00
|
|
|
|
|
2009-04-09 00:52:37 +04:00
|
|
|
|
nsFlowAreaRect
|
2016-10-12 08:26:17 +03:00
|
|
|
|
nsFloatManager::GetFlowArea(WritingMode aWM, nscoord aBCoord, nscoord aBSize,
|
2016-10-12 11:06:25 +03:00
|
|
|
|
BandInfoType aBandInfoType, ShapeType aShapeType,
|
2014-10-22 02:16:12 +04:00
|
|
|
|
LogicalRect aContentArea, SavedState* aState,
|
2015-07-16 12:07:57 +03:00
|
|
|
|
const nsSize& aContainerSize) const
|
2009-01-05 03:39:54 +03:00
|
|
|
|
{
|
2016-11-23 13:10:23 +03:00
|
|
|
|
CHECK_BLOCK_AND_LINE_DIR(aWM);
|
2014-10-22 02:16:12 +04:00
|
|
|
|
NS_ASSERTION(aBSize >= 0, "unexpected max block size");
|
|
|
|
|
NS_ASSERTION(aContentArea.ISize(aWM) >= 0,
|
|
|
|
|
"unexpected content area inline size");
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
2016-10-12 08:01:19 +03:00
|
|
|
|
nscoord blockStart = aBCoord + mBlockStart;
|
2014-10-22 02:16:12 +04:00
|
|
|
|
if (blockStart < nscoord_MIN) {
|
2009-01-07 02:21:00 +03:00
|
|
|
|
NS_WARNING("bad value");
|
2014-10-22 02:16:12 +04:00
|
|
|
|
blockStart = nscoord_MIN;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-09 00:52:36 +04:00
|
|
|
|
// Determine the last float that we should consider.
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t floatCount;
|
2009-04-09 00:52:36 +04:00
|
|
|
|
if (aState) {
|
|
|
|
|
// Use the provided state.
|
|
|
|
|
floatCount = aState->mFloatInfoCount;
|
2015-02-10 01:34:50 +03:00
|
|
|
|
MOZ_ASSERT(floatCount <= mFloats.Length(), "bad state");
|
2009-04-09 00:52:36 +04:00
|
|
|
|
} else {
|
|
|
|
|
// Use our current state.
|
|
|
|
|
floatCount = mFloats.Length();
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-05 03:39:54 +03:00
|
|
|
|
// If there are no floats at all, or we're below the last one, return
|
|
|
|
|
// quickly.
|
|
|
|
|
if (floatCount == 0 ||
|
2014-10-22 02:16:12 +04:00
|
|
|
|
(mFloats[floatCount-1].mLeftBEnd <= blockStart &&
|
|
|
|
|
mFloats[floatCount-1].mRightBEnd <= blockStart)) {
|
2016-10-12 08:01:19 +03:00
|
|
|
|
return nsFlowAreaRect(aWM, aContentArea.IStart(aWM), aBCoord,
|
2014-10-22 02:16:13 +04:00
|
|
|
|
aContentArea.ISize(aWM), aBSize, false);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 02:16:12 +04:00
|
|
|
|
nscoord blockEnd;
|
|
|
|
|
if (aBSize == nscoord_MAX) {
|
2009-07-09 05:10:29 +04:00
|
|
|
|
// This warning (and the two below) are possible to hit on pages
|
|
|
|
|
// with really large objects.
|
2016-10-12 08:26:17 +03:00
|
|
|
|
NS_WARNING_ASSERTION(aBandInfoType == BandInfoType::BandFromPoint, "bad height");
|
2014-10-22 02:16:12 +04:00
|
|
|
|
blockEnd = nscoord_MAX;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
} else {
|
2014-10-22 02:16:12 +04:00
|
|
|
|
blockEnd = blockStart + aBSize;
|
|
|
|
|
if (blockEnd < blockStart || blockEnd > nscoord_MAX) {
|
2009-01-07 02:21:00 +03:00
|
|
|
|
NS_WARNING("bad value");
|
2014-10-22 02:16:12 +04:00
|
|
|
|
blockEnd = nscoord_MAX;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-16 12:07:57 +03:00
|
|
|
|
nscoord lineLeft = mLineLeft + aContentArea.LineLeft(aWM, aContainerSize);
|
|
|
|
|
nscoord lineRight = mLineLeft + aContentArea.LineRight(aWM, aContainerSize);
|
2015-03-22 12:44:48 +03:00
|
|
|
|
if (lineRight < lineLeft) {
|
2009-01-07 02:21:00 +03:00
|
|
|
|
NS_WARNING("bad value");
|
2015-03-22 12:44:48 +03:00
|
|
|
|
lineRight = lineLeft;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Walk backwards through the floats until we either hit the front of
|
2014-10-22 02:16:12 +04:00
|
|
|
|
// the list or we're above |blockStart|.
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool haveFloats = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (uint32_t i = floatCount; i > 0; --i) {
|
2009-01-05 03:39:54 +03:00
|
|
|
|
const FloatInfo &fi = mFloats[i-1];
|
2014-10-22 02:16:12 +04:00
|
|
|
|
if (fi.mLeftBEnd <= blockStart && fi.mRightBEnd <= blockStart) {
|
2009-01-05 03:39:54 +03:00
|
|
|
|
// There aren't any more floats that could intersect this band.
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-01-06 11:36:43 +03:00
|
|
|
|
if (fi.IsEmpty(aShapeType)) {
|
2009-01-05 03:39:54 +03: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-22 02:16:12 +04:00
|
|
|
|
|
2016-10-12 11:06:25 +03:00
|
|
|
|
nscoord floatBStart = fi.BStart(aShapeType);
|
|
|
|
|
nscoord floatBEnd = fi.BEnd(aShapeType);
|
2016-10-12 08:26:17 +03:00
|
|
|
|
if (blockStart < floatBStart && aBandInfoType == BandInfoType::BandFromPoint) {
|
2009-01-05 03:39:54 +03:00
|
|
|
|
// This float is below our band. Shrink our band's height if needed.
|
2014-10-22 02:16:12 +04:00
|
|
|
|
if (floatBStart < blockEnd) {
|
|
|
|
|
blockEnd = floatBStart;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
2009-05-20 15:21:34 +04:00
|
|
|
|
}
|
2016-10-12 08:26:17 +03:00
|
|
|
|
// If blockStart == blockEnd (which happens only with WidthWithinHeight),
|
2009-05-20 15:21:34 +04:00
|
|
|
|
// we include floats that begin at our 0-height vertical area. We
|
2016-10-12 08:26:17 +03:00
|
|
|
|
// need to do this to satisfy the invariant that a
|
|
|
|
|
// WidthWithinHeight call is at least as narrow on both sides as a
|
|
|
|
|
// BandFromPoint call beginning at its blockStart.
|
2014-10-22 02:16:12 +04:00
|
|
|
|
else if (blockStart < floatBEnd &&
|
|
|
|
|
(floatBStart < blockEnd ||
|
|
|
|
|
(floatBStart == blockEnd && blockStart == blockEnd))) {
|
2009-01-05 03:39:54 +03:00
|
|
|
|
// This float is in our band.
|
|
|
|
|
|
|
|
|
|
// Shrink our band's width if needed.
|
2016-08-09 12:32:54 +03:00
|
|
|
|
StyleFloat floatStyle = fi.mFrame->StyleDisplay()->PhysicalFloats(aWM);
|
2016-10-13 11:28:38 +03:00
|
|
|
|
|
|
|
|
|
// When aBandInfoType is BandFromPoint, we're only intended to
|
|
|
|
|
// consider a point along the y axis rather than a band.
|
|
|
|
|
const nscoord bandBlockEnd =
|
|
|
|
|
aBandInfoType == BandInfoType::BandFromPoint ? blockStart : blockEnd;
|
2016-08-09 12:32:54 +03:00
|
|
|
|
if (floatStyle == StyleFloat::Left) {
|
2015-03-22 12:44:48 +03:00
|
|
|
|
// A left float
|
2016-10-13 11:28:38 +03:00
|
|
|
|
nscoord lineRightEdge =
|
2017-03-13 07:03:39 +03:00
|
|
|
|
fi.LineRight(aShapeType, blockStart, bandBlockEnd);
|
2015-03-22 12:44:48 +03:00
|
|
|
|
if (lineRightEdge > lineLeft) {
|
|
|
|
|
lineLeft = lineRightEdge;
|
2009-01-07 02:21:00 +03: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 18:59:28 +04:00
|
|
|
|
haveFloats = true;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-03-22 12:44:48 +03:00
|
|
|
|
// A right float
|
2016-10-13 11:28:38 +03:00
|
|
|
|
nscoord lineLeftEdge =
|
2017-03-13 07:03:39 +03:00
|
|
|
|
fi.LineLeft(aShapeType, blockStart, bandBlockEnd);
|
2015-03-22 12:44:48 +03:00
|
|
|
|
if (lineLeftEdge < lineRight) {
|
|
|
|
|
lineRight = lineLeftEdge;
|
2009-01-07 02:21:00 +03:00
|
|
|
|
// See above.
|
2011-10-17 18:59:28 +04:00
|
|
|
|
haveFloats = true;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-13 11:28:38 +03:00
|
|
|
|
|
|
|
|
|
// Shrink our band's height if needed.
|
|
|
|
|
if (floatBEnd < blockEnd && aBandInfoType == BandInfoType::BandFromPoint) {
|
|
|
|
|
blockEnd = floatBEnd;
|
|
|
|
|
}
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-22 02:16:13 +04:00
|
|
|
|
nscoord blockSize = (blockEnd == nscoord_MAX) ?
|
|
|
|
|
nscoord_MAX : (blockEnd - blockStart);
|
2015-03-22 12:44:48 +03:00
|
|
|
|
// convert back from LineLeft/Right to IStart
|
2015-07-16 12:08:05 +03:00
|
|
|
|
nscoord inlineStart = aWM.IsBidiLTR()
|
2015-07-16 12:07:57 +03:00
|
|
|
|
? lineLeft - mLineLeft
|
2015-07-16 12:08:05 +03:00
|
|
|
|
: mLineLeft - lineRight +
|
|
|
|
|
LogicalSize(aWM, aContainerSize).ISize(aWM);
|
2015-03-22 12:44:48 +03:00
|
|
|
|
|
|
|
|
|
return nsFlowAreaRect(aWM, inlineStart, blockStart - mBlockStart,
|
|
|
|
|
lineRight - lineLeft, blockSize, haveFloats);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 11:36:19 +03:00
|
|
|
|
void
|
2014-10-22 02:16:12 +04:00
|
|
|
|
nsFloatManager::AddFloat(nsIFrame* aFloatFrame, const LogicalRect& aMarginRect,
|
2015-07-16 12:07:57 +03:00
|
|
|
|
WritingMode aWM, const nsSize& aContainerSize)
|
2009-01-05 03:39:54 +03:00
|
|
|
|
{
|
2016-11-23 13:10:23 +03:00
|
|
|
|
CHECK_BLOCK_AND_LINE_DIR(aWM);
|
2014-10-22 02:16:12 +04:00
|
|
|
|
NS_ASSERTION(aMarginRect.ISize(aWM) >= 0, "negative inline size!");
|
|
|
|
|
NS_ASSERTION(aMarginRect.BSize(aWM) >= 0, "negative block size!");
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
2016-10-12 09:26:26 +03:00
|
|
|
|
FloatInfo info(aFloatFrame, mLineLeft, mBlockStart, aMarginRect, aWM,
|
|
|
|
|
aContainerSize);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
2014-10-22 02:16:12 +04:00
|
|
|
|
// Set mLeftBEnd and mRightBEnd.
|
2009-01-05 03:39:54 +03:00
|
|
|
|
if (HasAnyFloats()) {
|
|
|
|
|
FloatInfo &tail = mFloats[mFloats.Length() - 1];
|
2014-10-22 02:16:12 +04:00
|
|
|
|
info.mLeftBEnd = tail.mLeftBEnd;
|
|
|
|
|
info.mRightBEnd = tail.mRightBEnd;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
} else {
|
2014-10-22 02:16:12 +04:00
|
|
|
|
info.mLeftBEnd = nscoord_MIN;
|
|
|
|
|
info.mRightBEnd = nscoord_MIN;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
2016-08-09 12:32:54 +03:00
|
|
|
|
StyleFloat floatStyle = aFloatFrame->StyleDisplay()->PhysicalFloats(aWM);
|
|
|
|
|
MOZ_ASSERT(floatStyle == StyleFloat::Left || floatStyle == StyleFloat::Right,
|
|
|
|
|
"Unexpected float style!");
|
|
|
|
|
nscoord& sideBEnd =
|
|
|
|
|
floatStyle == StyleFloat::Left ? info.mLeftBEnd : info.mRightBEnd;
|
2015-03-22 12:44:48 +03:00
|
|
|
|
nscoord thisBEnd = info.BEnd();
|
2014-10-22 02:16:12 +04:00
|
|
|
|
if (thisBEnd > sideBEnd)
|
|
|
|
|
sideBEnd = thisBEnd;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
2017-01-06 11:36:19 +03:00
|
|
|
|
mFloats.AppendElement(Move(info));
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-22 12:44:48 +03:00
|
|
|
|
// static
|
2014-10-22 02:16:12 +04:00
|
|
|
|
LogicalRect
|
|
|
|
|
nsFloatManager::CalculateRegionFor(WritingMode aWM,
|
|
|
|
|
nsIFrame* aFloat,
|
|
|
|
|
const LogicalMargin& aMargin,
|
2015-07-16 12:07:57 +03:00
|
|
|
|
const nsSize& aContainerSize)
|
2009-07-15 09:19:31 +04:00
|
|
|
|
{
|
2013-08-09 04:20:17 +04:00
|
|
|
|
// We consider relatively positioned frames at their original position.
|
2014-10-22 02:16:12 +04:00
|
|
|
|
LogicalRect region(aWM, nsRect(aFloat->GetNormalPosition(),
|
|
|
|
|
aFloat->GetSize()),
|
2015-07-16 12:07:57 +03:00
|
|
|
|
aContainerSize);
|
2009-07-15 09:19:31 +04:00
|
|
|
|
|
|
|
|
|
// Float region includes its margin
|
2014-10-22 02:16:12 +04:00
|
|
|
|
region.Inflate(aWM, aMargin);
|
2009-07-15 09:19:31 +04:00
|
|
|
|
|
|
|
|
|
// Don't store rectangles with negative margin-box width or height in
|
|
|
|
|
// the float manager; it can't deal with them.
|
2014-10-22 02:16:12 +04:00
|
|
|
|
if (region.ISize(aWM) < 0) {
|
2009-07-15 09:19:31 +04:00
|
|
|
|
// Preserve the right margin-edge for left floats and the left
|
|
|
|
|
// margin-edge for right floats
|
2013-08-09 04:20:17 +04:00
|
|
|
|
const nsStyleDisplay* display = aFloat->StyleDisplay();
|
2016-08-09 12:32:54 +03:00
|
|
|
|
StyleFloat floatStyle = display->PhysicalFloats(aWM);
|
|
|
|
|
if ((StyleFloat::Left == floatStyle) == aWM.IsBidiLTR()) {
|
2014-10-22 02:16:12 +04:00
|
|
|
|
region.IStart(aWM) = region.IEnd(aWM);
|
2009-07-15 09:19:31 +04:00
|
|
|
|
}
|
2014-10-22 02:16:12 +04:00
|
|
|
|
region.ISize(aWM) = 0;
|
2009-07-15 09:19:31 +04:00
|
|
|
|
}
|
2014-10-22 02:16:12 +04:00
|
|
|
|
if (region.BSize(aWM) < 0) {
|
|
|
|
|
region.BSize(aWM) = 0;
|
2009-07-15 09:19:31 +04:00
|
|
|
|
}
|
|
|
|
|
return region;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-28 06:23:59 +03:00
|
|
|
|
NS_DECLARE_FRAME_PROPERTY_DELETABLE(FloatRegionProperty, nsMargin)
|
2010-03-29 05:46:55 +04:00
|
|
|
|
|
2014-10-22 02:16:12 +04:00
|
|
|
|
LogicalRect
|
|
|
|
|
nsFloatManager::GetRegionFor(WritingMode aWM, nsIFrame* aFloat,
|
2015-07-16 12:07:57 +03:00
|
|
|
|
const nsSize& aContainerSize)
|
2009-07-15 09:19:31 +04:00
|
|
|
|
{
|
2015-07-16 12:07:57 +03:00
|
|
|
|
LogicalRect region = aFloat->GetLogicalRect(aWM, aContainerSize);
|
2017-05-27 14:36:00 +03:00
|
|
|
|
void* storedRegion = aFloat->GetProperty(FloatRegionProperty());
|
2009-07-15 09:19:31 +04:00
|
|
|
|
if (storedRegion) {
|
|
|
|
|
nsMargin margin = *static_cast<nsMargin*>(storedRegion);
|
2014-10-22 02:16:12 +04:00
|
|
|
|
region.Inflate(aWM, LogicalMargin(aWM, margin));
|
2009-07-15 09:19:31 +04:00
|
|
|
|
}
|
|
|
|
|
return region;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-08 12:00:29 +04:00
|
|
|
|
void
|
2014-10-22 02:16:12 +04:00
|
|
|
|
nsFloatManager::StoreRegionFor(WritingMode aWM, nsIFrame* aFloat,
|
|
|
|
|
const LogicalRect& aRegion,
|
2015-07-16 12:07:57 +03:00
|
|
|
|
const nsSize& aContainerSize)
|
2009-07-15 09:19:31 +04:00
|
|
|
|
{
|
2015-07-16 12:07:57 +03:00
|
|
|
|
nsRect region = aRegion.GetPhysicalRect(aWM, aContainerSize);
|
2009-07-15 09:19:31 +04:00
|
|
|
|
nsRect rect = aFloat->GetRect();
|
2014-10-22 02:16:12 +04:00
|
|
|
|
if (region.IsEqualEdges(rect)) {
|
2017-05-27 14:36:00 +03:00
|
|
|
|
aFloat->DeleteProperty(FloatRegionProperty());
|
2009-07-15 09:19:31 +04:00
|
|
|
|
}
|
|
|
|
|
else {
|
2017-05-27 14:36:00 +03:00
|
|
|
|
nsMargin* storedMargin = aFloat->GetProperty(FloatRegionProperty());
|
2009-07-15 09:19:31 +04:00
|
|
|
|
if (!storedMargin) {
|
|
|
|
|
storedMargin = new nsMargin();
|
2017-05-27 14:36:00 +03:00
|
|
|
|
aFloat->SetProperty(FloatRegionProperty(), storedMargin);
|
2009-07-15 09:19:31 +04:00
|
|
|
|
}
|
2014-10-22 02:16:12 +04:00
|
|
|
|
*storedMargin = region - rect;
|
2009-07-15 09:19:31 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-05 03:39:54 +03: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 12:41:57 +04:00
|
|
|
|
nsTHashtable<nsPtrHashKey<nsIFrame> > frameSet(1);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
|
|
|
|
for (nsIFrame* f = aFrameList; f; f = f->GetNextSibling()) {
|
2011-11-09 00:24:37 +04:00
|
|
|
|
frameSet.PutEntry(f);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t newLength = mFloats.Length();
|
2009-01-05 03:39:54 +03:00
|
|
|
|
while (newLength > 0) {
|
|
|
|
|
if (!frameSet.Contains(mFloats[newLength - 1].mFrame)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
--newLength;
|
|
|
|
|
}
|
2009-01-07 02:21:00 +03:00
|
|
|
|
mFloats.TruncateLength(newLength);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (uint32_t i = 0; i < mFloats.Length(); ++i) {
|
2009-01-05 03:39:54 +03: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 12:44:48 +03:00
|
|
|
|
aState->mLineLeft = mLineLeft;
|
|
|
|
|
aState->mBlockStart = mBlockStart;
|
2010-08-06 08:59:19 +04:00
|
|
|
|
aState->mPushedLeftFloatPastBreak = mPushedLeftFloatPastBreak;
|
|
|
|
|
aState->mPushedRightFloatPastBreak = mPushedRightFloatPastBreak;
|
2010-08-06 08:59:19 +04:00
|
|
|
|
aState->mSplitLeftFloatAcrossBreak = mSplitLeftFloatAcrossBreak;
|
|
|
|
|
aState->mSplitRightFloatAcrossBreak = mSplitRightFloatAcrossBreak;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
aState->mFloatInfoCount = mFloats.Length();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsFloatManager::PopState(SavedState* aState)
|
|
|
|
|
{
|
|
|
|
|
NS_PRECONDITION(aState, "No state to restore?");
|
|
|
|
|
|
2015-03-22 12:44:48 +03:00
|
|
|
|
mLineLeft = aState->mLineLeft;
|
|
|
|
|
mBlockStart = aState->mBlockStart;
|
2010-08-06 08:59:19 +04:00
|
|
|
|
mPushedLeftFloatPastBreak = aState->mPushedLeftFloatPastBreak;
|
|
|
|
|
mPushedRightFloatPastBreak = aState->mPushedRightFloatPastBreak;
|
2010-08-06 08:59:19 +04:00
|
|
|
|
mSplitLeftFloatAcrossBreak = aState->mSplitLeftFloatAcrossBreak;
|
|
|
|
|
mSplitRightFloatAcrossBreak = aState->mSplitRightFloatAcrossBreak;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
|
|
|
|
NS_ASSERTION(aState->mFloatInfoCount <= mFloats.Length(),
|
|
|
|
|
"somebody misused PushState/PopState");
|
2009-01-07 02:21:00 +03:00
|
|
|
|
mFloats.TruncateLength(aState->mFloatInfoCount);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord
|
2015-03-22 12:44:48 +03:00
|
|
|
|
nsFloatManager::GetLowestFloatTop() const
|
2009-01-05 03:39:54 +03:00
|
|
|
|
{
|
2010-08-06 08:59:19 +04:00
|
|
|
|
if (mPushedLeftFloatPastBreak || mPushedRightFloatPastBreak) {
|
|
|
|
|
return nscoord_MAX;
|
|
|
|
|
}
|
2009-01-05 03:39:54 +03:00
|
|
|
|
if (!HasAnyFloats()) {
|
|
|
|
|
return nscoord_MIN;
|
|
|
|
|
}
|
2015-03-22 12:44:48 +03:00
|
|
|
|
return mFloats[mFloats.Length() -1].BStart() - mBlockStart;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2009-01-05 03:39:54 +03:00
|
|
|
|
void
|
|
|
|
|
DebugListFloatManager(const nsFloatManager *aFloatManager)
|
|
|
|
|
{
|
|
|
|
|
aFloatManager->List(stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
|
nsFloatManager::List(FILE* out) const
|
|
|
|
|
{
|
|
|
|
|
if (!HasAnyFloats())
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
|
for (uint32_t i = 0; i < mFloats.Length(); ++i) {
|
2009-01-05 03:39:54 +03:00
|
|
|
|
const FloatInfo &fi = mFloats[i];
|
2016-09-15 06:29:14 +03:00
|
|
|
|
fprintf_stderr(out, "Float %u: frame=%p rect={%d,%d,%d,%d} BEnd={l:%d, r:%d}\n",
|
2014-01-27 02:07:02 +04:00
|
|
|
|
i, static_cast<void*>(fi.mFrame),
|
2015-03-22 12:44:48 +03:00
|
|
|
|
fi.LineLeft(), fi.BStart(), fi.ISize(), fi.BSize(),
|
2014-10-22 02:16:12 +04:00
|
|
|
|
fi.mLeftBEnd, fi.mRightBEnd);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
nscoord
|
2016-09-07 05:20:17 +03:00
|
|
|
|
nsFloatManager::ClearFloats(nscoord aBCoord, StyleClear aBreakType,
|
2012-08-22 19:56:38 +04:00
|
|
|
|
uint32_t aFlags) const
|
2009-01-05 03:39:54 +03:00
|
|
|
|
{
|
2010-08-06 08:59:19 +04:00
|
|
|
|
if (!(aFlags & DONT_CLEAR_PUSHED_FLOATS) && ClearContinues(aBreakType)) {
|
2010-08-06 08:59:19 +04:00
|
|
|
|
return nscoord_MAX;
|
|
|
|
|
}
|
2009-01-05 03:39:54 +03:00
|
|
|
|
if (!HasAnyFloats()) {
|
2014-10-22 02:16:12 +04:00
|
|
|
|
return aBCoord;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-22 12:44:48 +03:00
|
|
|
|
nscoord blockEnd = aBCoord + mBlockStart;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
|
|
|
|
const FloatInfo &tail = mFloats[mFloats.Length() - 1];
|
|
|
|
|
switch (aBreakType) {
|
2016-09-07 05:20:17 +03:00
|
|
|
|
case StyleClear::Both:
|
2014-10-22 02:16:12 +04:00
|
|
|
|
blockEnd = std::max(blockEnd, tail.mLeftBEnd);
|
|
|
|
|
blockEnd = std::max(blockEnd, tail.mRightBEnd);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
break;
|
2016-09-07 05:20:17 +03:00
|
|
|
|
case StyleClear::Left:
|
2015-03-22 12:44:48 +03:00
|
|
|
|
blockEnd = std::max(blockEnd, tail.mLeftBEnd);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
break;
|
2016-09-07 05:20:17 +03:00
|
|
|
|
case StyleClear::Right:
|
2015-03-22 12:44:48 +03:00
|
|
|
|
blockEnd = std::max(blockEnd, tail.mRightBEnd);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// Do nothing
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-22 12:44:48 +03:00
|
|
|
|
blockEnd -= mBlockStart;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
2014-10-22 02:16:12 +04:00
|
|
|
|
return blockEnd;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
|
bool
|
2016-09-07 05:20:17 +03:00
|
|
|
|
nsFloatManager::ClearContinues(StyleClear aBreakType) const
|
2009-08-31 22:25:36 +04:00
|
|
|
|
{
|
2010-08-06 08:59:19 +04:00
|
|
|
|
return ((mPushedLeftFloatPastBreak || mSplitLeftFloatAcrossBreak) &&
|
2016-09-07 05:20:17 +03:00
|
|
|
|
(aBreakType == StyleClear::Both ||
|
|
|
|
|
aBreakType == StyleClear::Left)) ||
|
2010-08-06 08:59:19 +04:00
|
|
|
|
((mPushedRightFloatPastBreak || mSplitRightFloatAcrossBreak) &&
|
2016-09-07 05:20:17 +03:00
|
|
|
|
(aBreakType == StyleClear::Both ||
|
|
|
|
|
aBreakType == StyleClear::Right));
|
2009-08-31 22:25:36 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 11:36:30 +03:00
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2017-02-16 05:51:48 +03:00
|
|
|
|
// RoundedBoxShapeInfo
|
2017-01-06 11:36:30 +03:00
|
|
|
|
|
|
|
|
|
nscoord
|
2017-03-13 07:03:39 +03:00
|
|
|
|
nsFloatManager::RoundedBoxShapeInfo::LineLeft(const nscoord aBStart,
|
2017-02-16 05:51:48 +03:00
|
|
|
|
const nscoord aBEnd) const
|
2017-01-06 11:36:30 +03:00
|
|
|
|
{
|
2017-02-16 05:51:48 +03:00
|
|
|
|
if (!mRadii) {
|
2017-02-16 05:51:48 +03:00
|
|
|
|
return mRect.x;
|
2017-01-06 11:36:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord lineLeftDiff =
|
|
|
|
|
ComputeEllipseLineInterceptDiff(
|
2017-02-16 05:51:48 +03:00
|
|
|
|
mRect.y, mRect.YMost(),
|
2017-02-16 05:51:48 +03:00
|
|
|
|
mRadii[eCornerTopLeftX], mRadii[eCornerTopLeftY],
|
|
|
|
|
mRadii[eCornerBottomLeftX], mRadii[eCornerBottomLeftY],
|
2017-01-06 11:36:30 +03:00
|
|
|
|
aBStart, aBEnd);
|
2017-02-16 05:51:48 +03:00
|
|
|
|
return mRect.x + lineLeftDiff;
|
2017-01-06 11:36:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord
|
2017-03-13 07:03:39 +03:00
|
|
|
|
nsFloatManager::RoundedBoxShapeInfo::LineRight(const nscoord aBStart,
|
2017-02-16 05:51:48 +03:00
|
|
|
|
const nscoord aBEnd) const
|
2017-01-06 11:36:30 +03:00
|
|
|
|
{
|
2017-02-16 05:51:48 +03:00
|
|
|
|
if (!mRadii) {
|
2017-02-16 05:51:48 +03:00
|
|
|
|
return mRect.XMost();
|
2017-01-06 11:36:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord lineRightDiff =
|
|
|
|
|
ComputeEllipseLineInterceptDiff(
|
2017-02-16 05:51:48 +03:00
|
|
|
|
mRect.y, mRect.YMost(),
|
2017-02-16 05:51:48 +03:00
|
|
|
|
mRadii[eCornerTopRightX], mRadii[eCornerTopRightY],
|
|
|
|
|
mRadii[eCornerBottomRightX], mRadii[eCornerBottomRightY],
|
2017-01-06 11:36:30 +03:00
|
|
|
|
aBStart, aBEnd);
|
2017-02-16 05:51:48 +03:00
|
|
|
|
return mRect.XMost() - lineRightDiff;
|
2017-01-06 11:36:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 12:18:07 +03:00
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// EllipseShapeInfo
|
2017-03-13 07:03:40 +03:00
|
|
|
|
|
2017-01-23 12:18:07 +03:00
|
|
|
|
nscoord
|
2017-03-13 07:03:39 +03:00
|
|
|
|
nsFloatManager::EllipseShapeInfo::LineLeft(const nscoord aBStart,
|
2017-01-23 12:18:07 +03:00
|
|
|
|
const nscoord aBEnd) const
|
|
|
|
|
{
|
|
|
|
|
nscoord lineLeftDiff =
|
|
|
|
|
ComputeEllipseLineInterceptDiff(BStart(), BEnd(),
|
|
|
|
|
mRadii.width, mRadii.height,
|
|
|
|
|
mRadii.width, mRadii.height,
|
|
|
|
|
aBStart, aBEnd);
|
|
|
|
|
return mCenter.x - mRadii.width + lineLeftDiff;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord
|
2017-03-13 07:03:39 +03:00
|
|
|
|
nsFloatManager::EllipseShapeInfo::LineRight(const nscoord aBStart,
|
2017-01-23 12:18:07 +03:00
|
|
|
|
const nscoord aBEnd) const
|
|
|
|
|
{
|
|
|
|
|
nscoord lineRightDiff =
|
|
|
|
|
ComputeEllipseLineInterceptDiff(BStart(), BEnd(),
|
|
|
|
|
mRadii.width, mRadii.height,
|
|
|
|
|
mRadii.width, mRadii.height,
|
|
|
|
|
aBStart, aBEnd);
|
|
|
|
|
return mCenter.x + mRadii.width - lineRightDiff;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-13 07:03:40 +03:00
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// PolygonShapeInfo
|
|
|
|
|
|
|
|
|
|
nsFloatManager::PolygonShapeInfo::PolygonShapeInfo(nsTArray<nsPoint>&& aVertices)
|
|
|
|
|
: mVertices(aVertices)
|
|
|
|
|
{
|
|
|
|
|
// Polygons with fewer than three vertices result in an empty area.
|
|
|
|
|
// https://drafts.csswg.org/css-shapes/#funcdef-polygon
|
|
|
|
|
if (mVertices.Length() < 3) {
|
|
|
|
|
mEmpty = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto Determinant = [] (const nsPoint& aP0, const nsPoint& aP1) {
|
|
|
|
|
// Returns the determinant of the 2x2 matrix [aP0 aP1].
|
|
|
|
|
// https://en.wikipedia.org/wiki/Determinant#2_.C3.97_2_matrices
|
|
|
|
|
return aP0.x * aP1.y - aP0.y * aP1.x;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// See if we have any vertices that are non-collinear with the first two.
|
|
|
|
|
// (If a polygon's vertices are all collinear, it encloses no area.)
|
|
|
|
|
bool isEntirelyCollinear = true;
|
|
|
|
|
const nsPoint& p0 = mVertices[0];
|
|
|
|
|
const nsPoint& p1 = mVertices[1];
|
|
|
|
|
for (size_t i = 2; i < mVertices.Length(); ++i) {
|
|
|
|
|
const nsPoint& p2 = mVertices[i];
|
|
|
|
|
|
|
|
|
|
// If the determinant of the matrix formed by two points is 0, that
|
|
|
|
|
// means they're collinear with respect to the origin. Here, if it's
|
|
|
|
|
// nonzero, then p1 and p2 are non-collinear with respect to p0, i.e.
|
|
|
|
|
// the three points are non-collinear.
|
|
|
|
|
if (Determinant(p2 - p0, p1 - p0) != 0) {
|
|
|
|
|
isEntirelyCollinear = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isEntirelyCollinear) {
|
|
|
|
|
mEmpty = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mBStart and mBEnd are the lower and the upper bounds of all the
|
|
|
|
|
// vertex.y, respectively. The vertex.y is actually on the block-axis of
|
|
|
|
|
// the float manager's writing mode.
|
|
|
|
|
for (const nsPoint& vertex : mVertices) {
|
|
|
|
|
mBStart = std::min(mBStart, vertex.y);
|
|
|
|
|
mBEnd = std::max(mBEnd, vertex.y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
|
nsFloatManager::PolygonShapeInfo::LineLeft(const nscoord aBStart,
|
|
|
|
|
const nscoord aBEnd) const
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(!mEmpty, "Shouldn't be called if the polygon encloses no area.");
|
|
|
|
|
|
|
|
|
|
// We want the line-left-most inline-axis coordinate where the
|
|
|
|
|
// (block-axis) aBStart/aBEnd band crosses a line segment of the polygon.
|
|
|
|
|
// To get that, we start as line-right as possible (at nscoord_MAX). Then
|
|
|
|
|
// we iterate each line segment to compute its intersection point with the
|
|
|
|
|
// band (if any) and using std::min() successively to get the smallest
|
|
|
|
|
// inline-coordinates among those intersection points.
|
|
|
|
|
//
|
|
|
|
|
// Note: std::min<nscoord> means the function std::min() with template
|
|
|
|
|
// parameter nscoord, not the minimum value of nscoord.
|
|
|
|
|
return ComputeLineIntercept(aBStart, aBEnd, std::min<nscoord>, nscoord_MAX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
|
nsFloatManager::PolygonShapeInfo::LineRight(const nscoord aBStart,
|
|
|
|
|
const nscoord aBEnd) const
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(!mEmpty, "Shouldn't be called if the polygon encloses no area.");
|
|
|
|
|
|
|
|
|
|
// Similar to LineLeft(). Though here, we want the line-right-most
|
|
|
|
|
// inline-axis coordinate, so we instead start at nscoord_MIN and use
|
|
|
|
|
// std::max() to get the biggest inline-coordinate among those
|
|
|
|
|
// intersection points.
|
|
|
|
|
return ComputeLineIntercept(aBStart, aBEnd, std::max<nscoord>, nscoord_MIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
|
nsFloatManager::PolygonShapeInfo::ComputeLineIntercept(
|
|
|
|
|
const nscoord aBStart,
|
|
|
|
|
const nscoord aBEnd,
|
|
|
|
|
nscoord (*aCompareOp) (std::initializer_list<nscoord>),
|
|
|
|
|
const nscoord aLineInterceptInitialValue) const
|
|
|
|
|
{
|
|
|
|
|
MOZ_ASSERT(aBStart <= aBEnd,
|
|
|
|
|
"The band's block start is greater than its block end?");
|
|
|
|
|
|
|
|
|
|
const size_t len = mVertices.Length();
|
|
|
|
|
nscoord lineIntercept = aLineInterceptInitialValue;
|
|
|
|
|
|
|
|
|
|
// Iterate each line segment {p0, p1}, {p1, p2}, ..., {pn, p0}.
|
|
|
|
|
for (size_t i = 0; i < len; ++i) {
|
|
|
|
|
const nsPoint* smallYVertex = &mVertices[i];
|
|
|
|
|
const nsPoint* bigYVertex = &mVertices[(i + 1) % len];
|
|
|
|
|
|
|
|
|
|
// Swap the two points to satisfy the requirement for calling
|
|
|
|
|
// XInterceptAtY.
|
|
|
|
|
if (smallYVertex->y > bigYVertex->y) {
|
|
|
|
|
std::swap(smallYVertex, bigYVertex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aBStart >= bigYVertex->y || aBEnd <= smallYVertex->y ||
|
|
|
|
|
smallYVertex->y == bigYVertex->y) {
|
|
|
|
|
// Skip computing the intercept if a) the band doesn't intersect the
|
|
|
|
|
// line segment (even if it crosses one of two the vertices); or b)
|
|
|
|
|
// the line segment is horizontal. It's OK because the two end points
|
|
|
|
|
// forming this horizontal segment will still be considered if each of
|
|
|
|
|
// them is forming another non-horizontal segment with other points.
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord bStartLineIntercept =
|
|
|
|
|
aBStart <= smallYVertex->y
|
|
|
|
|
? smallYVertex->x
|
|
|
|
|
: XInterceptAtY(aBStart, *smallYVertex, *bigYVertex);
|
|
|
|
|
nscoord bEndLineIntercept =
|
|
|
|
|
aBEnd >= bigYVertex->y
|
|
|
|
|
? bigYVertex->x
|
|
|
|
|
: XInterceptAtY(aBEnd, *smallYVertex, *bigYVertex);
|
|
|
|
|
|
|
|
|
|
// If either new intercept is more extreme than lineIntercept (per
|
|
|
|
|
// aCompareOp), then update lineIntercept to that value.
|
|
|
|
|
lineIntercept =
|
|
|
|
|
aCompareOp({lineIntercept, bStartLineIntercept, bEndLineIntercept});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lineIntercept;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nsFloatManager::PolygonShapeInfo::Translate(nscoord aLineLeft,
|
|
|
|
|
nscoord aBlockStart)
|
|
|
|
|
{
|
|
|
|
|
for (nsPoint& vertex : mVertices) {
|
|
|
|
|
vertex.MoveBy(aLineLeft, aBlockStart);
|
|
|
|
|
}
|
|
|
|
|
mBStart += aBlockStart;
|
|
|
|
|
mBEnd += aBlockStart;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ nscoord
|
|
|
|
|
nsFloatManager::PolygonShapeInfo::XInterceptAtY(const nscoord aY,
|
|
|
|
|
const nsPoint& aP1,
|
|
|
|
|
const nsPoint& aP2)
|
|
|
|
|
{
|
|
|
|
|
// Solve for x in the linear equation: x = x1 + (y-y1) * (x2-x1) / (y2-y1),
|
|
|
|
|
// where aP1 = (x1, y1) and aP2 = (x2, y2).
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(aP1.y <= aY && aY <= aP2.y,
|
|
|
|
|
"This function won't work if the horizontal line at aY and "
|
|
|
|
|
"the line segment (aP1, aP2) do not intersect!");
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(aP1.y != aP2.y,
|
|
|
|
|
"A horizontal line segment results in dividing by zero error!");
|
|
|
|
|
|
|
|
|
|
return aP1.x + (aY - aP1.y) * (aP2.x - aP1.x) / (aP2.y - aP1.y);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-05 03:39:54 +03:00
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// FloatInfo
|
|
|
|
|
|
2015-03-22 12:44:48 +03:00
|
|
|
|
nsFloatManager::FloatInfo::FloatInfo(nsIFrame* aFrame,
|
2016-10-12 09:26:26 +03:00
|
|
|
|
nscoord aLineLeft, nscoord aBlockStart,
|
|
|
|
|
const LogicalRect& aMarginRect,
|
|
|
|
|
WritingMode aWM,
|
|
|
|
|
const nsSize& aContainerSize)
|
2015-03-22 12:44:48 +03:00
|
|
|
|
: mFrame(aFrame)
|
2017-02-16 05:51:48 +03:00
|
|
|
|
, mRect(ShapeInfo::ConvertToFloatLogical(aMarginRect, aWM, aContainerSize) +
|
|
|
|
|
nsPoint(aLineLeft, aBlockStart))
|
2009-01-05 03:39:54 +03:00
|
|
|
|
{
|
|
|
|
|
MOZ_COUNT_CTOR(nsFloatManager::FloatInfo);
|
2016-10-12 11:06:25 +03:00
|
|
|
|
|
2017-02-21 18:26:17 +03:00
|
|
|
|
const StyleShapeSource& shapeOutside = mFrame->StyleDisplay()->mShapeOutside;
|
2016-10-12 11:06:25 +03:00
|
|
|
|
|
2017-01-06 11:36:30 +03:00
|
|
|
|
if (shapeOutside.GetType() == StyleShapeSourceType::None) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-19 08:41:19 +03:00
|
|
|
|
if (shapeOutside.GetType() == StyleShapeSourceType::URL) {
|
|
|
|
|
// Bug 1265343: Implement 'shape-image-threshold'. Early return
|
|
|
|
|
// here because shape-outside with url() value doesn't have a
|
|
|
|
|
// reference box, and GetReferenceBox() asserts that.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 11:36:30 +03:00
|
|
|
|
// Initialize <shape-box>'s reference rect.
|
2017-02-16 05:51:48 +03:00
|
|
|
|
LogicalRect shapeBoxRect =
|
|
|
|
|
ShapeInfo::ComputeShapeBoxRect(shapeOutside, mFrame, aMarginRect, aWM);
|
2017-01-06 11:36:30 +03:00
|
|
|
|
|
|
|
|
|
if (shapeOutside.GetType() == StyleShapeSourceType::Box) {
|
2017-02-16 05:51:48 +03:00
|
|
|
|
mShapeInfo = ShapeInfo::CreateShapeBox(mFrame, shapeBoxRect, aWM,
|
|
|
|
|
aContainerSize);
|
2017-01-06 11:36:43 +03:00
|
|
|
|
} else if (shapeOutside.GetType() == StyleShapeSourceType::Shape) {
|
|
|
|
|
StyleBasicShape* const basicShape = shapeOutside.GetBasicShape();
|
|
|
|
|
|
2017-01-23 12:18:07 +03:00
|
|
|
|
switch (basicShape->GetShapeType()) {
|
|
|
|
|
case StyleBasicShapeType::Polygon:
|
2017-03-13 07:03:40 +03:00
|
|
|
|
mShapeInfo =
|
|
|
|
|
ShapeInfo::CreatePolygon(basicShape, shapeBoxRect, aWM,
|
|
|
|
|
aContainerSize);
|
|
|
|
|
break;
|
2017-01-23 12:18:07 +03:00
|
|
|
|
case StyleBasicShapeType::Circle:
|
|
|
|
|
case StyleBasicShapeType::Ellipse:
|
|
|
|
|
mShapeInfo =
|
2017-02-16 05:51:48 +03:00
|
|
|
|
ShapeInfo::CreateCircleOrEllipse(basicShape, shapeBoxRect, aWM,
|
|
|
|
|
aContainerSize);
|
2017-01-23 12:18:07 +03:00
|
|
|
|
break;
|
|
|
|
|
case StyleBasicShapeType::Inset:
|
2017-02-16 05:51:49 +03:00
|
|
|
|
mShapeInfo =
|
|
|
|
|
ShapeInfo::CreateInset(basicShape, shapeBoxRect, aWM, aContainerSize);
|
|
|
|
|
break;
|
2017-01-06 11:36:43 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unknown StyleShapeSourceType!");
|
2016-10-12 11:06:25 +03:00
|
|
|
|
}
|
2017-01-23 12:17:37 +03:00
|
|
|
|
|
2017-02-02 06:53:06 +03:00
|
|
|
|
MOZ_ASSERT(mShapeInfo,
|
|
|
|
|
"All shape-outside values except none should have mShapeInfo!");
|
|
|
|
|
|
2017-01-23 12:17:37 +03:00
|
|
|
|
// Translate the shape to the same origin as nsFloatManager.
|
|
|
|
|
mShapeInfo->Translate(aLineLeft, aBlockStart);
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2017-01-06 11:36:19 +03:00
|
|
|
|
nsFloatManager::FloatInfo::FloatInfo(FloatInfo&& aOther)
|
|
|
|
|
: mFrame(Move(aOther.mFrame))
|
|
|
|
|
, mLeftBEnd(Move(aOther.mLeftBEnd))
|
|
|
|
|
, mRightBEnd(Move(aOther.mRightBEnd))
|
|
|
|
|
, mRect(Move(aOther.mRect))
|
2017-01-06 11:36:30 +03:00
|
|
|
|
, mShapeInfo(Move(aOther.mShapeInfo))
|
2009-01-05 04:25:58 +03:00
|
|
|
|
{
|
|
|
|
|
MOZ_COUNT_CTOR(nsFloatManager::FloatInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-05 03:39:54 +03:00
|
|
|
|
nsFloatManager::FloatInfo::~FloatInfo()
|
|
|
|
|
{
|
|
|
|
|
MOZ_COUNT_DTOR(nsFloatManager::FloatInfo);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-10-12 11:06:25 +03:00
|
|
|
|
nscoord
|
2017-03-13 07:03:39 +03:00
|
|
|
|
nsFloatManager::FloatInfo::LineLeft(ShapeType aShapeType,
|
2016-10-13 11:28:38 +03:00
|
|
|
|
const nscoord aBStart,
|
|
|
|
|
const nscoord aBEnd) const
|
2016-10-12 11:06:25 +03:00
|
|
|
|
{
|
|
|
|
|
if (aShapeType == ShapeType::Margin) {
|
|
|
|
|
return LineLeft();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(aShapeType == ShapeType::ShapeOutside);
|
2017-01-06 11:36:30 +03:00
|
|
|
|
if (!mShapeInfo) {
|
2016-10-12 11:06:25 +03:00
|
|
|
|
return LineLeft();
|
|
|
|
|
}
|
2017-01-06 11:36:43 +03:00
|
|
|
|
// Clip the flow area to the margin-box because
|
|
|
|
|
// https://drafts.csswg.org/css-shapes-1/#relation-to-box-model-and-float-behavior
|
|
|
|
|
// says "When a shape is used to define a float area, the shape is clipped
|
|
|
|
|
// to the float’s margin box."
|
2017-03-13 07:03:39 +03:00
|
|
|
|
return std::max(LineLeft(), mShapeInfo->LineLeft(aBStart, aBEnd));
|
2016-10-12 11:06:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nscoord
|
2017-03-13 07:03:39 +03:00
|
|
|
|
nsFloatManager::FloatInfo::LineRight(ShapeType aShapeType,
|
2016-10-13 11:28:38 +03:00
|
|
|
|
const nscoord aBStart,
|
|
|
|
|
const nscoord aBEnd) const
|
2016-10-12 11:06:25 +03:00
|
|
|
|
{
|
|
|
|
|
if (aShapeType == ShapeType::Margin) {
|
|
|
|
|
return LineRight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(aShapeType == ShapeType::ShapeOutside);
|
2017-01-06 11:36:30 +03:00
|
|
|
|
if (!mShapeInfo) {
|
2016-10-12 11:06:25 +03:00
|
|
|
|
return LineRight();
|
|
|
|
|
}
|
2017-01-06 11:36:43 +03:00
|
|
|
|
// Clip the flow area to the margin-box. See LineLeft().
|
2017-03-13 07:03:39 +03:00
|
|
|
|
return std::min(LineRight(), mShapeInfo->LineRight(aBStart, aBEnd));
|
2017-01-06 11:36:30 +03:00
|
|
|
|
}
|
2016-10-12 11:06:25 +03:00
|
|
|
|
|
2017-01-06 11:36:30 +03:00
|
|
|
|
nscoord
|
|
|
|
|
nsFloatManager::FloatInfo::BStart(ShapeType aShapeType) const
|
|
|
|
|
{
|
|
|
|
|
if (aShapeType == ShapeType::Margin) {
|
|
|
|
|
return BStart();
|
|
|
|
|
}
|
2017-01-06 11:36:43 +03:00
|
|
|
|
|
2017-01-06 11:36:30 +03:00
|
|
|
|
MOZ_ASSERT(aShapeType == ShapeType::ShapeOutside);
|
|
|
|
|
if (!mShapeInfo) {
|
|
|
|
|
return BStart();
|
2017-01-06 11:36:30 +03:00
|
|
|
|
}
|
2017-01-06 11:36:43 +03:00
|
|
|
|
// Clip the flow area to the margin-box. See LineLeft().
|
|
|
|
|
return std::max(BStart(), mShapeInfo->BStart());
|
2017-01-06 11:36:30 +03:00
|
|
|
|
}
|
2017-01-12 16:19:20 +03:00
|
|
|
|
|
2017-01-06 11:36:30 +03:00
|
|
|
|
nscoord
|
|
|
|
|
nsFloatManager::FloatInfo::BEnd(ShapeType aShapeType) const
|
|
|
|
|
{
|
|
|
|
|
if (aShapeType == ShapeType::Margin) {
|
|
|
|
|
return BEnd();
|
|
|
|
|
}
|
2017-01-12 16:19:20 +03:00
|
|
|
|
|
2017-01-06 11:36:30 +03:00
|
|
|
|
MOZ_ASSERT(aShapeType == ShapeType::ShapeOutside);
|
|
|
|
|
if (!mShapeInfo) {
|
|
|
|
|
return BEnd();
|
|
|
|
|
}
|
2017-01-06 11:36:43 +03:00
|
|
|
|
// Clip the flow area to the margin-box. See LineLeft().
|
|
|
|
|
return std::min(BEnd(), mShapeInfo->BEnd());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
nsFloatManager::FloatInfo::IsEmpty(ShapeType aShapeType) const
|
|
|
|
|
{
|
|
|
|
|
if (aShapeType == ShapeType::Margin) {
|
|
|
|
|
return IsEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOZ_ASSERT(aShapeType == ShapeType::ShapeOutside);
|
|
|
|
|
if (!mShapeInfo) {
|
|
|
|
|
return IsEmpty();
|
|
|
|
|
}
|
|
|
|
|
return mShapeInfo->IsEmpty();
|
2016-10-12 11:06:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 12:18:07 +03:00
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// ShapeInfo
|
|
|
|
|
|
2017-02-16 05:51:48 +03:00
|
|
|
|
/* static */ LogicalRect
|
|
|
|
|
nsFloatManager::ShapeInfo::ComputeShapeBoxRect(
|
2017-02-21 18:26:17 +03:00
|
|
|
|
const StyleShapeSource& aShapeOutside,
|
2017-02-16 05:51:48 +03:00
|
|
|
|
nsIFrame* const aFrame,
|
|
|
|
|
const mozilla::LogicalRect& aMarginRect,
|
|
|
|
|
mozilla::WritingMode aWM)
|
|
|
|
|
{
|
|
|
|
|
LogicalRect rect = aMarginRect;
|
|
|
|
|
|
|
|
|
|
switch (aShapeOutside.GetReferenceBox()) {
|
2017-03-16 10:18:10 +03:00
|
|
|
|
case StyleGeometryBox::ContentBox:
|
2017-02-16 05:51:48 +03:00
|
|
|
|
rect.Deflate(aWM, aFrame->GetLogicalUsedPadding(aWM));
|
|
|
|
|
MOZ_FALLTHROUGH;
|
2017-03-16 10:18:10 +03:00
|
|
|
|
case StyleGeometryBox::PaddingBox:
|
2017-02-16 05:51:48 +03:00
|
|
|
|
rect.Deflate(aWM, aFrame->GetLogicalUsedBorder(aWM));
|
|
|
|
|
MOZ_FALLTHROUGH;
|
2017-03-16 10:18:10 +03:00
|
|
|
|
case StyleGeometryBox::BorderBox:
|
2017-02-16 05:51:48 +03:00
|
|
|
|
rect.Deflate(aWM, aFrame->GetLogicalUsedMargin(aWM));
|
|
|
|
|
break;
|
2017-03-16 10:18:10 +03:00
|
|
|
|
case StyleGeometryBox::MarginBox:
|
2017-02-16 05:51:48 +03:00
|
|
|
|
// Do nothing. rect is already a margin rect.
|
|
|
|
|
break;
|
2017-02-21 18:26:17 +03:00
|
|
|
|
case StyleGeometryBox::NoBox:
|
|
|
|
|
default:
|
2017-02-16 05:51:48 +03:00
|
|
|
|
MOZ_ASSERT(aShapeOutside.GetType() != StyleShapeSourceType::Box,
|
|
|
|
|
"Box source type must have <shape-box> specified!");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-16 05:51:48 +03:00
|
|
|
|
/* static */ UniquePtr<nsFloatManager::ShapeInfo>
|
|
|
|
|
nsFloatManager::ShapeInfo::CreateShapeBox(
|
|
|
|
|
nsIFrame* const aFrame,
|
|
|
|
|
const LogicalRect& aShapeBoxRect,
|
|
|
|
|
WritingMode aWM,
|
|
|
|
|
const nsSize& aContainerSize)
|
|
|
|
|
{
|
|
|
|
|
nsRect logicalShapeBoxRect
|
|
|
|
|
= ConvertToFloatLogical(aShapeBoxRect, aWM, aContainerSize);
|
|
|
|
|
|
|
|
|
|
nscoord physicalRadii[8];
|
|
|
|
|
bool hasRadii = aFrame->GetShapeBoxBorderRadii(physicalRadii);
|
|
|
|
|
if (!hasRadii) {
|
2017-02-16 05:51:48 +03:00
|
|
|
|
return MakeUnique<RoundedBoxShapeInfo>(logicalShapeBoxRect,
|
|
|
|
|
UniquePtr<nscoord[]>());
|
2017-02-16 05:51:48 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-16 05:51:48 +03:00
|
|
|
|
return MakeUnique<RoundedBoxShapeInfo>(logicalShapeBoxRect,
|
|
|
|
|
ConvertToFloatLogical(physicalRadii,
|
|
|
|
|
aWM));
|
2017-02-16 05:51:48 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-16 05:51:49 +03:00
|
|
|
|
/* static */ UniquePtr<nsFloatManager::ShapeInfo>
|
|
|
|
|
nsFloatManager::ShapeInfo::CreateInset(
|
2017-03-13 07:03:40 +03:00
|
|
|
|
const StyleBasicShape* aBasicShape,
|
2017-02-16 05:51:49 +03:00
|
|
|
|
const LogicalRect& aShapeBoxRect,
|
|
|
|
|
WritingMode aWM,
|
|
|
|
|
const nsSize& aContainerSize)
|
|
|
|
|
{
|
|
|
|
|
// Use physical coordinates to compute inset() because the top, right,
|
|
|
|
|
// bottom and left offsets are physical.
|
|
|
|
|
// https://drafts.csswg.org/css-shapes-1/#funcdef-inset
|
|
|
|
|
nsRect physicalShapeBoxRect =
|
|
|
|
|
aShapeBoxRect.GetPhysicalRect(aWM, aContainerSize);
|
|
|
|
|
nsRect insetRect =
|
|
|
|
|
ShapeUtils::ComputeInsetRect(aBasicShape, physicalShapeBoxRect);
|
|
|
|
|
|
|
|
|
|
nsRect logicalInsetRect =
|
|
|
|
|
ConvertToFloatLogical(LogicalRect(aWM, insetRect, aContainerSize),
|
|
|
|
|
aWM, aContainerSize);
|
|
|
|
|
nscoord physicalRadii[8];
|
|
|
|
|
bool hasRadii =
|
|
|
|
|
ShapeUtils::ComputeInsetRadii(aBasicShape, insetRect, physicalShapeBoxRect,
|
|
|
|
|
physicalRadii);
|
|
|
|
|
if (!hasRadii) {
|
|
|
|
|
return MakeUnique<RoundedBoxShapeInfo>(logicalInsetRect,
|
|
|
|
|
UniquePtr<nscoord[]>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MakeUnique<RoundedBoxShapeInfo>(logicalInsetRect,
|
|
|
|
|
ConvertToFloatLogical(physicalRadii,
|
|
|
|
|
aWM));
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-25 11:01:51 +03:00
|
|
|
|
/* static */ UniquePtr<nsFloatManager::ShapeInfo>
|
|
|
|
|
nsFloatManager::ShapeInfo::CreateCircleOrEllipse(
|
2017-03-13 07:03:40 +03:00
|
|
|
|
const StyleBasicShape* aBasicShape,
|
2017-01-25 11:01:51 +03:00
|
|
|
|
const LogicalRect& aShapeBoxRect,
|
|
|
|
|
WritingMode aWM,
|
|
|
|
|
const nsSize& aContainerSize)
|
|
|
|
|
{
|
|
|
|
|
// Use physical coordinates to compute the center of circle() or ellipse()
|
|
|
|
|
// since the <position> keywords such as 'left', 'top', etc. are physical.
|
|
|
|
|
// https://drafts.csswg.org/css-shapes-1/#funcdef-ellipse
|
|
|
|
|
nsRect physicalShapeBoxRect =
|
|
|
|
|
aShapeBoxRect.GetPhysicalRect(aWM, aContainerSize);
|
|
|
|
|
nsPoint physicalCenter =
|
|
|
|
|
ShapeUtils::ComputeCircleOrEllipseCenter(aBasicShape, physicalShapeBoxRect);
|
2017-02-16 05:51:48 +03:00
|
|
|
|
nsPoint logicalCenter =
|
|
|
|
|
ConvertToFloatLogical(physicalCenter, aWM, aContainerSize);
|
2017-01-25 11:01:51 +03:00
|
|
|
|
|
|
|
|
|
// Compute the circle or ellipse radii.
|
|
|
|
|
nsSize radii;
|
|
|
|
|
StyleBasicShapeType type = aBasicShape->GetShapeType();
|
|
|
|
|
if (type == StyleBasicShapeType::Circle) {
|
|
|
|
|
nscoord radius = ShapeUtils::ComputeCircleRadius(aBasicShape, physicalCenter,
|
|
|
|
|
physicalShapeBoxRect);
|
|
|
|
|
radii = nsSize(radius, radius);
|
|
|
|
|
} else {
|
|
|
|
|
MOZ_ASSERT(type == StyleBasicShapeType::Ellipse);
|
|
|
|
|
nsSize physicalRadii =
|
|
|
|
|
ShapeUtils::ComputeEllipseRadii(aBasicShape, physicalCenter,
|
|
|
|
|
physicalShapeBoxRect);
|
|
|
|
|
LogicalSize logicalRadii(aWM, physicalRadii);
|
|
|
|
|
radii = nsSize(logicalRadii.ISize(aWM), logicalRadii.BSize(aWM));
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-16 05:51:48 +03:00
|
|
|
|
return MakeUnique<EllipseShapeInfo>(logicalCenter, radii);
|
2017-01-25 11:01:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-13 07:03:40 +03:00
|
|
|
|
/* static */ UniquePtr<nsFloatManager::ShapeInfo>
|
|
|
|
|
nsFloatManager::ShapeInfo::CreatePolygon(
|
|
|
|
|
const StyleBasicShape* aBasicShape,
|
|
|
|
|
const LogicalRect& aShapeBoxRect,
|
|
|
|
|
WritingMode aWM,
|
|
|
|
|
const nsSize& aContainerSize)
|
|
|
|
|
{
|
|
|
|
|
// Use physical coordinates to compute each (xi, yi) vertex because CSS
|
|
|
|
|
// represents them using physical coordinates.
|
|
|
|
|
// https://drafts.csswg.org/css-shapes-1/#funcdef-polygon
|
|
|
|
|
nsRect physicalShapeBoxRect =
|
|
|
|
|
aShapeBoxRect.GetPhysicalRect(aWM, aContainerSize);
|
|
|
|
|
|
|
|
|
|
// Get physical vertices.
|
|
|
|
|
nsTArray<nsPoint> vertices =
|
|
|
|
|
ShapeUtils::ComputePolygonVertices(aBasicShape, physicalShapeBoxRect);
|
|
|
|
|
|
|
|
|
|
// Convert all the physical vertices to logical.
|
|
|
|
|
for (nsPoint& vertex : vertices) {
|
|
|
|
|
vertex = ConvertToFloatLogical(vertex, aWM, aContainerSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MakeUnique<PolygonShapeInfo>(Move(vertices));
|
|
|
|
|
}
|
2017-01-25 11:01:51 +03:00
|
|
|
|
|
2016-10-13 11:28:38 +03:00
|
|
|
|
/* static */ nscoord
|
2017-01-06 11:36:30 +03:00
|
|
|
|
nsFloatManager::ShapeInfo::ComputeEllipseLineInterceptDiff(
|
2016-11-18 08:54:09 +03:00
|
|
|
|
const nscoord aShapeBoxBStart, const nscoord aShapeBoxBEnd,
|
|
|
|
|
const nscoord aBStartCornerRadiusL, const nscoord aBStartCornerRadiusB,
|
|
|
|
|
const nscoord aBEndCornerRadiusL, const nscoord aBEndCornerRadiusB,
|
|
|
|
|
const nscoord aBandBStart, const nscoord aBandBEnd)
|
2016-10-13 11:28:38 +03:00
|
|
|
|
{
|
2016-11-18 08:54:09 +03:00
|
|
|
|
// An example for the band intersecting with the top right corner of an
|
|
|
|
|
// ellipse with writing-mode horizontal-tb.
|
2016-10-13 11:28:38 +03:00
|
|
|
|
//
|
2016-11-18 08:54:09 +03:00
|
|
|
|
// lineIntercept lineDiff
|
2016-10-13 11:28:38 +03:00
|
|
|
|
// | |
|
2016-11-18 08:54:09 +03:00
|
|
|
|
// +---------------------------------|-------|-+---- aShapeBoxBStart
|
2016-10-13 11:28:38 +03:00
|
|
|
|
// | ##########^ | | |
|
|
|
|
|
// | ##############|#### | | |
|
2016-11-18 08:54:09 +03:00
|
|
|
|
// +---------#################|######|-------|-+---- aBandBStart
|
2016-10-13 11:28:38 +03:00
|
|
|
|
// | ###################|######|## | |
|
2016-11-18 08:54:09 +03:00
|
|
|
|
// | aBStartCornerRadiusB |######|### | |
|
2016-10-13 11:28:38 +03:00
|
|
|
|
// | ######################|######|##### | |
|
2016-11-18 08:54:09 +03:00
|
|
|
|
// +---#######################|<-----------><->^---- aBandBEnd
|
2016-10-13 11:28:38 +03:00
|
|
|
|
// | ########################|############## |
|
2016-11-18 08:54:09 +03:00
|
|
|
|
// | ########################|############## |---- b
|
2016-10-13 11:28:38 +03:00
|
|
|
|
// | #########################|############### |
|
|
|
|
|
// | ######################## v<-------------->v
|
2016-11-18 08:54:09 +03:00
|
|
|
|
// |###################### aBStartCornerRadiusL|
|
2016-10-13 11:28:38 +03:00
|
|
|
|
// |###########################################|
|
|
|
|
|
// |###########################################|
|
|
|
|
|
// |###########################################|
|
|
|
|
|
// |###########################################|
|
|
|
|
|
// | ######################################### |
|
|
|
|
|
// | ######################################### |
|
|
|
|
|
// | ####################################### |
|
|
|
|
|
// | ####################################### |
|
|
|
|
|
// | ##################################### |
|
|
|
|
|
// | ################################### |
|
|
|
|
|
// | ############################### |
|
|
|
|
|
// | ############################# |
|
|
|
|
|
// | ######################### |
|
|
|
|
|
// | ################### |
|
|
|
|
|
// | ########### |
|
2016-11-18 08:54:09 +03:00
|
|
|
|
// +-------------------------------------------+----- aShapeBoxBEnd
|
|
|
|
|
|
|
|
|
|
NS_ASSERTION(aShapeBoxBStart <= aShapeBoxBEnd, "Bad shape box coordinates!");
|
|
|
|
|
NS_ASSERTION(aBandBStart <= aBandBEnd, "Bad band coordinates!");
|
|
|
|
|
|
|
|
|
|
nscoord lineDiff = 0;
|
|
|
|
|
|
|
|
|
|
// If the band intersects both the block-start and block-end corners, we
|
|
|
|
|
// don't need to enter either branch because the correct lineDiff is 0.
|
|
|
|
|
if (aBStartCornerRadiusB > 0 &&
|
|
|
|
|
aBandBEnd >= aShapeBoxBStart &&
|
|
|
|
|
aBandBEnd <= aShapeBoxBStart + aBStartCornerRadiusB) {
|
|
|
|
|
// The band intersects only the block-start corner.
|
|
|
|
|
nscoord b = aBStartCornerRadiusB - (aBandBEnd - aShapeBoxBStart);
|
|
|
|
|
nscoord lineIntercept =
|
|
|
|
|
XInterceptAtY(b, aBStartCornerRadiusL, aBStartCornerRadiusB);
|
|
|
|
|
lineDiff = aBStartCornerRadiusL - lineIntercept;
|
|
|
|
|
} else if (aBEndCornerRadiusB > 0 &&
|
|
|
|
|
aBandBStart >= aShapeBoxBEnd - aBEndCornerRadiusB &&
|
|
|
|
|
aBandBStart <= aShapeBoxBEnd) {
|
|
|
|
|
// The band intersects only the block-end corner.
|
|
|
|
|
nscoord b = aBEndCornerRadiusB - (aShapeBoxBEnd - aBandBStart);
|
|
|
|
|
nscoord lineIntercept =
|
|
|
|
|
XInterceptAtY(b, aBEndCornerRadiusL, aBEndCornerRadiusB);
|
|
|
|
|
lineDiff = aBEndCornerRadiusL - lineIntercept;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lineDiff;
|
2016-10-13 11:28:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ nscoord
|
2017-01-06 11:36:30 +03:00
|
|
|
|
nsFloatManager::ShapeInfo::XInterceptAtY(const nscoord aY,
|
2017-01-09 08:11:25 +03:00
|
|
|
|
const nscoord aRadiusX,
|
|
|
|
|
const nscoord aRadiusY)
|
2016-10-13 11:28:38 +03:00
|
|
|
|
{
|
|
|
|
|
// Solve for x in the ellipse equation (x/radiusX)^2 + (y/radiusY)^2 = 1.
|
|
|
|
|
MOZ_ASSERT(aRadiusY > 0);
|
|
|
|
|
return aRadiusX * std::sqrt(1 - (aY * aY) / double(aRadiusY * aRadiusY));
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 12:18:07 +03:00
|
|
|
|
/* static */ nsPoint
|
2017-02-16 05:51:48 +03:00
|
|
|
|
nsFloatManager::ShapeInfo::ConvertToFloatLogical(
|
2017-01-23 12:18:07 +03:00
|
|
|
|
const nsPoint& aPoint,
|
2017-02-16 05:51:48 +03:00
|
|
|
|
WritingMode aWM,
|
2017-01-23 12:18:07 +03:00
|
|
|
|
const nsSize& aContainerSize)
|
|
|
|
|
{
|
|
|
|
|
LogicalPoint logicalPoint(aWM, aPoint, aContainerSize);
|
|
|
|
|
return nsPoint(logicalPoint.LineRelative(aWM, aContainerSize),
|
|
|
|
|
logicalPoint.B(aWM));
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-16 05:51:48 +03:00
|
|
|
|
/* static */ UniquePtr<nscoord[]>
|
|
|
|
|
nsFloatManager::ShapeInfo::ConvertToFloatLogical(const nscoord aRadii[8],
|
|
|
|
|
WritingMode aWM)
|
|
|
|
|
{
|
|
|
|
|
UniquePtr<nscoord[]> logicalRadii(new nscoord[8]);
|
|
|
|
|
|
|
|
|
|
// Get the physical side for line-left and line-right since border radii
|
|
|
|
|
// are on the physical axis.
|
|
|
|
|
Side lineLeftSide =
|
|
|
|
|
aWM.PhysicalSide(aWM.LogicalSideForLineRelativeDir(eLineRelativeDirLeft));
|
|
|
|
|
logicalRadii[eCornerTopLeftX] =
|
|
|
|
|
aRadii[SideToHalfCorner(lineLeftSide, true, false)];
|
|
|
|
|
logicalRadii[eCornerTopLeftY] =
|
|
|
|
|
aRadii[SideToHalfCorner(lineLeftSide, true, true)];
|
|
|
|
|
logicalRadii[eCornerBottomLeftX] =
|
|
|
|
|
aRadii[SideToHalfCorner(lineLeftSide, false, false)];
|
|
|
|
|
logicalRadii[eCornerBottomLeftY] =
|
|
|
|
|
aRadii[SideToHalfCorner(lineLeftSide, false, true)];
|
|
|
|
|
|
|
|
|
|
Side lineRightSide =
|
|
|
|
|
aWM.PhysicalSide(aWM.LogicalSideForLineRelativeDir(eLineRelativeDirRight));
|
|
|
|
|
logicalRadii[eCornerTopRightX] =
|
|
|
|
|
aRadii[SideToHalfCorner(lineRightSide, false, false)];
|
|
|
|
|
logicalRadii[eCornerTopRightY] =
|
|
|
|
|
aRadii[SideToHalfCorner(lineRightSide, false, true)];
|
|
|
|
|
logicalRadii[eCornerBottomRightX] =
|
|
|
|
|
aRadii[SideToHalfCorner(lineRightSide, true, false)];
|
|
|
|
|
logicalRadii[eCornerBottomRightY] =
|
|
|
|
|
aRadii[SideToHalfCorner(lineRightSide, true, true)];
|
|
|
|
|
|
|
|
|
|
if (aWM.IsLineInverted()) {
|
|
|
|
|
// When IsLineInverted() is true, i.e. aWM is vertical-lr,
|
|
|
|
|
// line-over/line-under are inverted from block-start/block-end. So the
|
|
|
|
|
// relationship reverses between which corner comes first going
|
|
|
|
|
// clockwise, and which corner is block-start versus block-end. We need
|
|
|
|
|
// to swap the values stored in top and bottom corners.
|
|
|
|
|
std::swap(logicalRadii[eCornerTopLeftX], logicalRadii[eCornerBottomLeftX]);
|
|
|
|
|
std::swap(logicalRadii[eCornerTopLeftY], logicalRadii[eCornerBottomLeftY]);
|
|
|
|
|
std::swap(logicalRadii[eCornerTopRightX], logicalRadii[eCornerBottomRightX]);
|
|
|
|
|
std::swap(logicalRadii[eCornerTopRightY], logicalRadii[eCornerBottomRightY]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return logicalRadii;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-05 03:39:54 +03:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
nsAutoFloatManager::~nsAutoFloatManager()
|
|
|
|
|
{
|
2016-09-15 06:29:14 +03:00
|
|
|
|
// Restore the old float manager in the reflow input if necessary.
|
2009-01-05 03:39:54 +03:00
|
|
|
|
if (mNew) {
|
2016-09-15 09:32:12 +03:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
if (nsBlockFrame::gNoisyFloatManager) {
|
|
|
|
|
printf("restoring old float manager %p\n", mOld);
|
|
|
|
|
}
|
2009-01-05 03:39:54 +03:00
|
|
|
|
#endif
|
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
|
mReflowInput.mFloatManager = mOld;
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
2016-09-15 09:32:12 +03:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
if (nsBlockFrame::gNoisyFloatManager) {
|
|
|
|
|
if (mOld) {
|
|
|
|
|
mReflowInput.mFrame->ListTag(stdout);
|
|
|
|
|
printf(": float manager %p after reflow\n", mOld);
|
|
|
|
|
mOld->List(stdout);
|
|
|
|
|
}
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-15 18:29:57 +03:00
|
|
|
|
void
|
2009-01-05 03:39:54 +03:00
|
|
|
|
nsAutoFloatManager::CreateFloatManager(nsPresContext *aPresContext)
|
|
|
|
|
{
|
2017-02-09 12:57:16 +03:00
|
|
|
|
MOZ_ASSERT(!mNew, "Redundant call to CreateFloatManager!");
|
|
|
|
|
|
2009-01-05 03:39:54 +03:00
|
|
|
|
// Create a new float manager and install it in the reflow
|
2016-09-15 06:29:14 +03:00
|
|
|
|
// input. `Remember' the old float manager so we can restore it
|
2009-01-05 03:39:54 +03:00
|
|
|
|
// later.
|
2017-02-09 12:57:16 +03:00
|
|
|
|
mNew = MakeUnique<nsFloatManager>(aPresContext->PresShell(),
|
|
|
|
|
mReflowInput.GetWritingMode());
|
2009-01-05 03:39:54 +03:00
|
|
|
|
|
2016-09-15 09:32:12 +03:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
if (nsBlockFrame::gNoisyFloatManager) {
|
|
|
|
|
printf("constructed new float manager %p (replacing %p)\n",
|
2017-02-09 12:57:16 +03:00
|
|
|
|
mNew.get(), mReflowInput.mFloatManager);
|
2016-09-15 09:32:12 +03:00
|
|
|
|
}
|
2009-01-05 03:39:54 +03:00
|
|
|
|
#endif
|
|
|
|
|
|
2016-09-15 06:29:14 +03:00
|
|
|
|
// Set the float manager in the existing reflow input.
|
2016-07-21 13:36:39 +03:00
|
|
|
|
mOld = mReflowInput.mFloatManager;
|
2017-02-09 12:57:16 +03:00
|
|
|
|
mReflowInput.mFloatManager = mNew.get();
|
2009-01-05 03:39:54 +03:00
|
|
|
|
}
|