2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* class that manages regions of 2-D space, originally designed
|
|
|
|
* generally but actually specific to space occupied by floats
|
|
|
|
*/
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsSpaceManager.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsSize.h"
|
|
|
|
#include <stdlib.h>
|
1998-05-13 20:22:44 +04:00
|
|
|
#include "nsVoidArray.h"
|
1999-09-15 04:24:54 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsString.h"
|
2001-10-25 05:08:40 +04:00
|
|
|
#include "nsIPresShell.h"
|
2001-10-26 09:06:07 +04:00
|
|
|
#include "nsMemory.h"
|
2003-05-23 00:56:35 +04:00
|
|
|
#include "nsHTMLReflowState.h"
|
2004-09-13 17:35:46 +04:00
|
|
|
#include "nsHashSets.h"
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include "nsIFrameDebug.h"
|
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-20 02:55:40 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// BandList
|
|
|
|
|
2001-09-11 04:55:05 +04:00
|
|
|
PRInt32 nsSpaceManager::sCachedSpaceManagerCount = 0;
|
2001-10-26 09:06:07 +04:00
|
|
|
void* nsSpaceManager::sCachedSpaceManagers[NS_SPACE_MANAGER_CACHE_SIZE];
|
2001-09-11 04:55:05 +04:00
|
|
|
|
1999-06-24 06:04:50 +04:00
|
|
|
#define NSCOORD_MIN (-2147483647 - 1) /* minimum signed value */
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
nsSpaceManager::BandList::BandList()
|
1999-06-24 06:04:50 +04:00
|
|
|
: nsSpaceManager::BandRect(NSCOORD_MIN, NSCOORD_MIN, NSCOORD_MIN, NSCOORD_MIN, (nsIFrame*)nsnull)
|
1998-05-20 02:55:40 +04:00
|
|
|
{
|
|
|
|
PR_INIT_CLIST(this);
|
|
|
|
}
|
|
|
|
|
1999-01-04 07:54:33 +03:00
|
|
|
void
|
|
|
|
nsSpaceManager::BandList::Clear()
|
1998-05-20 02:55:40 +04:00
|
|
|
{
|
|
|
|
if (!IsEmpty()) {
|
|
|
|
BandRect* bandRect = Head();
|
|
|
|
|
|
|
|
while (bandRect != this) {
|
1999-09-15 04:24:54 +04:00
|
|
|
BandRect* nxt = bandRect->Next();
|
1998-05-20 02:55:40 +04:00
|
|
|
|
|
|
|
delete bandRect;
|
1999-09-15 04:24:54 +04:00
|
|
|
bandRect = nxt;
|
1998-05-20 02:55:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_INIT_CLIST(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// PresShell Arena allocate callback (for nsIntervalSet use below)
|
2008-10-10 19:04:34 +04:00
|
|
|
static void*
|
2001-10-26 09:06:07 +04:00
|
|
|
PSArenaAllocCB(size_t aSize, void* aClosure)
|
2001-10-25 05:08:40 +04:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsIPresShell*>(aClosure)->AllocateFrame(aSize);
|
2001-10-25 05:08:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// PresShell Arena free callback (for nsIntervalSet use below)
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2001-10-26 09:06:07 +04:00
|
|
|
PSArenaFreeCB(size_t aSize, void* aPtr, void* aClosure)
|
2001-10-25 05:08:40 +04:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsIPresShell*>(aClosure)->FreeFrame(aSize, aPtr);
|
2001-10-25 05:08:40 +04:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsSpaceManager
|
|
|
|
|
2008-10-14 22:59:29 +04:00
|
|
|
nsSpaceManager::nsSpaceManager(nsIPresShell* aPresShell)
|
|
|
|
: mLowestTop(NSCOORD_MIN),
|
2006-08-30 01:56:51 +04:00
|
|
|
mFloatDamage(PSArenaAllocCB, PSArenaFreeCB, aPresShell),
|
|
|
|
mHaveCachedLeftYMost(PR_TRUE),
|
|
|
|
mHaveCachedRightYMost(PR_TRUE),
|
2007-07-21 00:05:02 +04:00
|
|
|
mMaximalLeftYMost(nscoord_MIN),
|
|
|
|
mMaximalRightYMost(nscoord_MIN),
|
2007-01-24 00:42:41 +03:00
|
|
|
mCachedBandPosition(nsnull)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-10-26 09:06:07 +04:00
|
|
|
MOZ_COUNT_CTOR(nsSpaceManager);
|
1998-04-14 00:24:54 +04:00
|
|
|
mX = mY = 0;
|
1998-05-19 07:00:56 +04:00
|
|
|
mFrameInfoMap = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-01-04 07:54:33 +03:00
|
|
|
void
|
|
|
|
nsSpaceManager::ClearFrameInfo()
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
1999-10-06 08:22:51 +04:00
|
|
|
while (mFrameInfoMap) {
|
|
|
|
FrameInfo* next = mFrameInfoMap->mNext;
|
|
|
|
delete mFrameInfoMap;
|
|
|
|
mFrameInfoMap = next;
|
1998-05-19 07:00:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
nsSpaceManager::~nsSpaceManager()
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
2001-10-26 09:06:07 +04:00
|
|
|
MOZ_COUNT_DTOR(nsSpaceManager);
|
1998-05-20 02:55:40 +04:00
|
|
|
mBandList.Clear();
|
1998-05-19 07:00:56 +04:00
|
|
|
ClearFrameInfo();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-09-11 04:55:05 +04:00
|
|
|
// static
|
2002-07-03 00:25:30 +04:00
|
|
|
void* nsSpaceManager::operator new(size_t aSize) CPP_THROW_NEW
|
2001-09-11 04:55:05 +04:00
|
|
|
{
|
|
|
|
if (sCachedSpaceManagerCount > 0) {
|
|
|
|
// We have cached unused instances of this class, return a cached
|
|
|
|
// instance in stead of always creating a new one.
|
2001-10-26 09:06:07 +04:00
|
|
|
return sCachedSpaceManagers[--sCachedSpaceManagerCount];
|
2001-09-11 04:55:05 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
// The cache is empty, this means we haveto create a new instance using
|
|
|
|
// the global |operator new|.
|
|
|
|
return nsMemory::Alloc(aSize);
|
2001-09-11 04:55:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-10-26 09:06:07 +04:00
|
|
|
nsSpaceManager::operator delete(void* aPtr, size_t aSize)
|
2001-09-11 04:55:05 +04:00
|
|
|
{
|
2001-10-26 09:06:07 +04:00
|
|
|
if (!aPtr)
|
|
|
|
return;
|
2001-09-11 04:55:05 +04:00
|
|
|
// This space manager is no longer used, if there's still room in
|
|
|
|
// the cache we'll cache this space manager, unless the layout
|
|
|
|
// module was already shut down.
|
|
|
|
|
|
|
|
if (sCachedSpaceManagerCount < NS_SPACE_MANAGER_CACHE_SIZE &&
|
|
|
|
sCachedSpaceManagerCount >= 0) {
|
|
|
|
// There's still space in the cache for more instances, put this
|
|
|
|
// instance in the cache in stead of deleting it.
|
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
sCachedSpaceManagers[sCachedSpaceManagerCount++] = aPtr;
|
2001-09-11 04:55:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The cache is full, or the layout module has been shut down,
|
|
|
|
// delete this space manager.
|
2001-10-26 09:06:07 +04:00
|
|
|
nsMemory::Free(aPtr);
|
2001-09-11 04:55:05 +04:00
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
/* static */
|
|
|
|
void nsSpaceManager::Shutdown()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-10-26 09:06:07 +04:00
|
|
|
// The layout module is being shut down, clean up the cache and
|
|
|
|
// disable further caching.
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
PRInt32 i;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
for (i = 0; i < sCachedSpaceManagerCount; i++) {
|
|
|
|
void* spaceManager = sCachedSpaceManagers[i];
|
|
|
|
if (spaceManager)
|
|
|
|
nsMemory::Free(spaceManager);
|
|
|
|
}
|
|
|
|
|
2005-11-21 01:05:24 +03:00
|
|
|
// Disable further caching.
|
2001-10-26 09:06:07 +04:00
|
|
|
sCachedSpaceManagerCount = -1;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
PRBool
|
1999-01-04 07:54:33 +03:00
|
|
|
nsSpaceManager::YMost(nscoord& aYMost) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2001-10-26 09:06:07 +04:00
|
|
|
PRBool result;
|
1999-06-24 06:04:50 +04:00
|
|
|
|
1998-05-20 02:55:40 +04:00
|
|
|
if (mBandList.IsEmpty()) {
|
1999-01-04 07:54:33 +03:00
|
|
|
aYMost = 0;
|
2001-10-26 09:06:07 +04:00
|
|
|
result = PR_FALSE;
|
1999-06-24 06:04:50 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
} else {
|
1998-05-20 02:55:40 +04:00
|
|
|
BandRect* lastRect = mBandList.Tail();
|
1998-05-19 07:00:56 +04:00
|
|
|
|
1999-07-03 03:31:01 +04:00
|
|
|
aYMost = lastRect->mBottom;
|
2001-10-26 09:06:07 +04:00
|
|
|
result = PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-05-19 07:00:56 +04:00
|
|
|
|
1999-06-24 06:04:50 +04:00
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1998-04-29 04:58:16 +04:00
|
|
|
* Internal function that returns the list of available and unavailable space
|
|
|
|
* within the band
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2007-11-16 02:56:23 +03:00
|
|
|
* Note: If the clip rectangle has 0 width and is aligned exactly at
|
|
|
|
* aBand->mLeft or aBand->mRight, we count it as intersecting the band, and we
|
|
|
|
* return an unavailable-space trapezoid for the band. (The alternative would
|
|
|
|
* be to return a zero-width available-space trapezoid, which would make no
|
|
|
|
* sense. See bug 403129)
|
|
|
|
*
|
1998-04-14 00:24:54 +04:00
|
|
|
* @param aBand the first rect in the band
|
|
|
|
* @param aY the y-offset in world coordinates
|
|
|
|
* @param aMaxSize the size to use to constrain the band data
|
2007-11-16 02:56:23 +03:00
|
|
|
* @param aBandData the object to populate with available and unavailable space
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
1999-01-04 07:54:33 +03:00
|
|
|
nsresult
|
|
|
|
nsSpaceManager::GetBandAvailableSpace(const BandRect* aBand,
|
|
|
|
nscoord aY,
|
|
|
|
const nsSize& aMaxSize,
|
|
|
|
nsBandData& aBandData) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-07-03 03:31:01 +04:00
|
|
|
nscoord topOfBand = aBand->mTop;
|
1998-04-21 03:53:47 +04:00
|
|
|
nscoord localY = aY - mY;
|
1999-07-03 03:31:01 +04:00
|
|
|
nscoord height = PR_MIN(aBand->mBottom - aY, aMaxSize.height);
|
1999-07-25 23:01:13 +04:00
|
|
|
nsBandTrapezoid* trapezoid = aBandData.mTrapezoids;
|
1998-04-21 03:53:47 +04:00
|
|
|
nscoord rightEdge = mX + aMaxSize.width;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Initialize the band data
|
1999-07-25 23:01:13 +04:00
|
|
|
aBandData.mCount = 0;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Skip any rectangles that are to the left of the local coordinate space
|
1999-07-03 03:31:01 +04:00
|
|
|
while (aBand->mTop == topOfBand) {
|
2007-11-16 02:56:23 +03:00
|
|
|
if (aBand->mRight > mX ||
|
|
|
|
(aMaxSize.width == 0 && aBand->mRight == mX)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the next rect in the band
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand = aBand->Next();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-04-29 04:58:16 +04:00
|
|
|
// This is used to track the current x-location within the band. This is in
|
|
|
|
// world coordinates
|
|
|
|
nscoord left = mX;
|
|
|
|
|
|
|
|
// Process the remaining rectangles that are within the clip width
|
2007-11-16 02:56:23 +03:00
|
|
|
while ((aBand->mTop == topOfBand) &&
|
|
|
|
(aBand->mLeft < rightEdge ||
|
|
|
|
(aMaxSize.width == 0 && aBand->mLeft == mX))) {
|
1998-04-29 04:58:16 +04:00
|
|
|
// Compare the left edge of the occupied space with the current left
|
|
|
|
// coordinate
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBand->mLeft > left) {
|
1998-04-29 04:58:16 +04:00
|
|
|
// The rect is to the right of our current left coordinate, so we've
|
|
|
|
// found some available space
|
1999-07-25 23:01:13 +04:00
|
|
|
if (aBandData.mCount >= aBandData.mSize) {
|
1999-01-04 07:54:33 +03:00
|
|
|
// Not enough space in the array of trapezoids
|
1999-07-25 23:01:13 +04:00
|
|
|
aBandData.mCount += 2 * aBand->Length() + 2; // estimate the number needed
|
1999-01-04 07:54:33 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-08-30 19:29:06 +04:00
|
|
|
trapezoid->mFrames = nsnull;
|
1998-04-29 04:58:16 +04:00
|
|
|
|
|
|
|
// Assign the trapezoid a rectangular shape. The trapezoid must be in the
|
|
|
|
// local coordinate space, so convert the current left coordinate
|
1999-07-03 03:31:01 +04:00
|
|
|
*trapezoid = nsRect(left - mX, localY, aBand->mLeft - left, height);
|
1998-04-29 04:58:16 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Move to the next output rect
|
1998-04-21 03:53:47 +04:00
|
|
|
trapezoid++;
|
1999-07-25 23:01:13 +04:00
|
|
|
aBandData.mCount++;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-04-29 04:58:16 +04:00
|
|
|
// The rect represents unavailable space, so add another trapezoid
|
1999-07-25 23:01:13 +04:00
|
|
|
if (aBandData.mCount >= aBandData.mSize) {
|
1999-01-04 07:54:33 +03:00
|
|
|
// Not enough space in the array of trapezoids
|
1999-07-25 23:01:13 +04:00
|
|
|
aBandData.mCount += 2 * aBand->Length() + 1; // estimate the number needed
|
1999-01-04 07:54:33 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-08-30 19:29:06 +04:00
|
|
|
NS_ASSERTION(aBand->mFrames.Count() > 0, "unexpected frame count");
|
|
|
|
trapezoid->mFrames = &aBand->mFrames;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-03 03:31:01 +04:00
|
|
|
nscoord x = aBand->mLeft;
|
1998-04-29 04:58:16 +04:00
|
|
|
// The first band can straddle the clip rect
|
|
|
|
if (x < mX) {
|
|
|
|
// Clip the left edge
|
|
|
|
x = mX;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assign the trapezoid a rectangular shape. The trapezoid must be in the
|
|
|
|
// local coordinate space, so convert the rects's left coordinate
|
1999-07-03 03:31:01 +04:00
|
|
|
*trapezoid = nsRect(x - mX, localY, aBand->mRight - x, height);
|
1998-04-29 04:58:16 +04:00
|
|
|
|
|
|
|
// Move to the next output rect
|
|
|
|
trapezoid++;
|
1999-07-25 23:01:13 +04:00
|
|
|
aBandData.mCount++;
|
1998-04-29 04:58:16 +04:00
|
|
|
|
|
|
|
// Adjust our current x-location within the band
|
1999-07-03 03:31:01 +04:00
|
|
|
left = aBand->mRight;
|
1998-04-29 04:58:16 +04:00
|
|
|
|
|
|
|
// Move to the next rect within the band
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand = aBand->Next();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-04-21 03:53:47 +04:00
|
|
|
// No more rects left in the band. If we haven't yet reached the right edge,
|
1998-04-14 00:24:54 +04:00
|
|
|
// then all the remaining space is available
|
2007-07-26 01:52:20 +04:00
|
|
|
if (left < rightEdge || aBandData.mCount == 0) {
|
1999-07-25 23:01:13 +04:00
|
|
|
if (aBandData.mCount >= aBandData.mSize) {
|
1999-01-04 07:54:33 +03:00
|
|
|
// Not enough space in the array of trapezoids
|
1999-07-25 23:01:13 +04:00
|
|
|
aBandData.mCount++;
|
1999-01-04 07:54:33 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-08-30 19:29:06 +04:00
|
|
|
trapezoid->mFrames = nsnull;
|
1998-04-21 03:53:47 +04:00
|
|
|
|
1998-04-29 04:58:16 +04:00
|
|
|
// Assign the trapezoid a rectangular shape. The trapezoid must be in the
|
|
|
|
// local coordinate space, so convert the current left coordinate
|
|
|
|
*trapezoid = nsRect(left - mX, localY, rightEdge - left, height);
|
1999-07-25 23:01:13 +04:00
|
|
|
aBandData.mCount++;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-01-04 07:54:33 +03:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
nsresult
|
1999-01-04 07:54:33 +03:00
|
|
|
nsSpaceManager::GetBandData(nscoord aYOffset,
|
|
|
|
const nsSize& aMaxSize,
|
|
|
|
nsBandData& aBandData) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-07-25 23:01:13 +04:00
|
|
|
NS_PRECONDITION(aBandData.mSize >= 1, "bad band data");
|
1999-01-04 07:54:33 +03:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Convert the y-offset to world coordinates
|
1998-05-19 07:00:56 +04:00
|
|
|
nscoord y = mY + aYOffset;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// If there are no unavailable rects or the offset is below the bottommost
|
1998-05-19 07:00:56 +04:00
|
|
|
// band, then all the space is available
|
1999-01-04 07:54:33 +03:00
|
|
|
nscoord yMost;
|
2005-03-23 06:35:08 +03:00
|
|
|
nscoord maxHeight = aMaxSize.height == NS_UNCONSTRAINEDSIZE ? NS_UNCONSTRAINEDSIZE
|
|
|
|
: PR_MAX(0, aMaxSize.height - aYOffset);
|
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
if (!YMost(yMost) || (y >= yMost)) {
|
1998-04-29 04:58:16 +04:00
|
|
|
// All the requested space is available
|
1999-07-25 23:01:13 +04:00
|
|
|
aBandData.mCount = 1;
|
2005-03-23 06:35:08 +03:00
|
|
|
aBandData.mTrapezoids[0] = nsRect(0, aYOffset, aMaxSize.width, maxHeight);
|
2007-08-30 19:29:06 +04:00
|
|
|
aBandData.mTrapezoids[0].mFrames = nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
} else {
|
|
|
|
// Find the first band that contains the y-offset or is below the y-offset
|
2007-01-24 00:42:41 +03:00
|
|
|
BandRect* band = GuessBandWithTopAbove(y);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-25 23:01:13 +04:00
|
|
|
aBandData.mCount = 0;
|
1998-05-19 07:00:56 +04:00
|
|
|
while (nsnull != band) {
|
1999-07-03 03:31:01 +04:00
|
|
|
if (band->mTop > y) {
|
1998-04-29 04:58:16 +04:00
|
|
|
// The band is below the y-offset. The area between the y-offset and
|
|
|
|
// the top of the band is available
|
1999-07-25 23:01:13 +04:00
|
|
|
aBandData.mCount = 1;
|
|
|
|
aBandData.mTrapezoids[0] =
|
2005-03-23 06:35:08 +03:00
|
|
|
nsRect(0, aYOffset, aMaxSize.width, PR_MIN(band->mTop - y, maxHeight));
|
2007-08-30 19:29:06 +04:00
|
|
|
aBandData.mTrapezoids[0].mFrames = nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
1999-07-03 03:31:01 +04:00
|
|
|
} else if (y < band->mBottom) {
|
1998-04-29 04:58:16 +04:00
|
|
|
// The band contains the y-offset. Return a list of available and
|
|
|
|
// unavailable rects within the band
|
2005-03-23 06:35:08 +03:00
|
|
|
return GetBandAvailableSpace(band, y, nsSize(aMaxSize.width, maxHeight), aBandData);
|
1998-04-14 00:24:54 +04:00
|
|
|
} else {
|
|
|
|
// Skip to the next band
|
1998-05-19 07:00:56 +04:00
|
|
|
band = GetNextBand(band);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-25 23:01:13 +04:00
|
|
|
NS_POSTCONDITION(aBandData.mCount > 0, "unexpected band data count");
|
1999-01-04 07:54:33 +03:00
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Skips to the start of the next band.
|
|
|
|
*
|
1998-05-19 07:00:56 +04:00
|
|
|
* @param aBandRect A rect within the band
|
|
|
|
* @returns The start of the next band, or nsnull of this is the last band.
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
1999-01-04 07:54:33 +03:00
|
|
|
nsSpaceManager::BandRect*
|
|
|
|
nsSpaceManager::GetNextBand(const BandRect* aBandRect) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-07-03 03:31:01 +04:00
|
|
|
nscoord topOfBand = aBandRect->mTop;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-20 02:55:40 +04:00
|
|
|
aBandRect = aBandRect->Next();
|
1998-05-19 07:00:56 +04:00
|
|
|
while (aBandRect != &mBandList) {
|
|
|
|
// Check whether this rect is part of the same band
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBandRect->mTop != topOfBand) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// We found the start of the next band
|
1998-05-19 07:00:56 +04:00
|
|
|
return (BandRect*)aBandRect;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-20 02:55:40 +04:00
|
|
|
aBandRect = aBandRect->Next();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// No bands left
|
|
|
|
return nsnull;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2007-01-24 00:42:41 +03:00
|
|
|
/**
|
|
|
|
* Skips to the start of the previous band.
|
|
|
|
*
|
|
|
|
* @param aBandRect The first rect within a band
|
|
|
|
* @returns The start of the previous band, or nsnull of this is the first band.
|
|
|
|
*/
|
|
|
|
nsSpaceManager::BandRect*
|
|
|
|
nsSpaceManager::GetPrevBand(const BandRect* aBandRect) const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aBandRect->Prev() == &mBandList ||
|
|
|
|
aBandRect->Prev()->mBottom <= aBandRect->mTop,
|
|
|
|
"aBandRect should be first rect within its band");
|
|
|
|
|
|
|
|
BandRect* prev = aBandRect->Prev();
|
|
|
|
nscoord topOfBand = prev->mTop;
|
|
|
|
|
|
|
|
while (prev != &mBandList) {
|
|
|
|
// Check whether the prev rect is part of the same band
|
|
|
|
if (prev->mTop != topOfBand) {
|
|
|
|
// We found the beginning of this band
|
|
|
|
return (BandRect*)aBandRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
aBandRect = prev;
|
|
|
|
prev = aBandRect->Prev();
|
|
|
|
}
|
|
|
|
|
|
|
|
// No bands left
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
|
|
|
* Divides the current band into two vertically
|
|
|
|
*
|
1998-05-19 07:00:56 +04:00
|
|
|
* @param aBandRect the first rect in the band
|
|
|
|
* @param aBottom where to split the band. This becomes the bottom of the top
|
|
|
|
* part
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
1999-01-04 07:54:33 +03:00
|
|
|
void
|
|
|
|
nsSpaceManager::DivideBand(BandRect* aBandRect, nscoord aBottom)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-07-03 03:31:01 +04:00
|
|
|
NS_PRECONDITION(aBottom < aBandRect->mBottom, "bad height");
|
|
|
|
nscoord topOfBand = aBandRect->mTop;
|
1998-05-19 07:00:56 +04:00
|
|
|
BandRect* nextBand = GetNextBand(aBandRect);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
if (nsnull == nextBand) {
|
|
|
|
nextBand = (BandRect*)&mBandList;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-03 03:31:01 +04:00
|
|
|
while (topOfBand == aBandRect->mTop) {
|
1998-05-19 07:00:56 +04:00
|
|
|
// Split the band rect into two vertically
|
|
|
|
BandRect* bottomBandRect = aBandRect->SplitVertically(aBottom);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Insert the new bottom part
|
1998-05-20 02:55:40 +04:00
|
|
|
nextBand->InsertBefore(bottomBandRect);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Move to the next rect in the band
|
1998-05-20 02:55:40 +04:00
|
|
|
aBandRect = aBandRect->Next();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-04 07:54:33 +03:00
|
|
|
PRBool
|
|
|
|
nsSpaceManager::CanJoinBands(BandRect* aBand, BandRect* aPrevBand)
|
1998-05-20 02:55:40 +04:00
|
|
|
{
|
|
|
|
PRBool result;
|
1999-07-03 03:31:01 +04:00
|
|
|
nscoord topOfBand = aBand->mTop;
|
|
|
|
nscoord topOfPrevBand = aPrevBand->mTop;
|
1998-05-20 02:55:40 +04:00
|
|
|
|
|
|
|
// The bands can be joined if:
|
|
|
|
// - they're adjacent
|
|
|
|
// - they have the same number of rects
|
|
|
|
// - each rect has the same left and right edge as its corresponding rect, and
|
|
|
|
// the rects are occupied by the same frames
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aPrevBand->mBottom == aBand->mTop) {
|
1998-05-20 02:55:40 +04:00
|
|
|
// Compare each of the rects in the two bands
|
|
|
|
while (PR_TRUE) {
|
1999-07-03 03:31:01 +04:00
|
|
|
if ((aBand->mLeft != aPrevBand->mLeft) || (aBand->mRight != aPrevBand->mRight)) {
|
1998-05-20 02:55:40 +04:00
|
|
|
// The rects have different edges
|
|
|
|
result = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aBand->HasSameFrameList(aPrevBand)) {
|
|
|
|
// The rects are occupied by different frames
|
|
|
|
result = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move to the next rects within the bands
|
|
|
|
aBand = aBand->Next();
|
|
|
|
aPrevBand = aPrevBand->Next();
|
|
|
|
|
|
|
|
// Have we reached the end of either band?
|
1999-07-03 03:31:01 +04:00
|
|
|
PRBool endOfBand = aBand->mTop != topOfBand;
|
|
|
|
PRBool endOfPrevBand = aPrevBand->mTop != topOfPrevBand;
|
1998-05-20 02:55:40 +04:00
|
|
|
|
|
|
|
if (endOfBand || endOfPrevBand) {
|
|
|
|
result = endOfBand & endOfPrevBand;
|
|
|
|
break; // all done
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// The bands aren't adjacent
|
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-05-19 19:30:10 +04:00
|
|
|
/**
|
|
|
|
* Tries to join the two adjacent bands. Returns PR_TRUE if successful and
|
|
|
|
* PR_FALSE otherwise
|
|
|
|
*
|
2005-11-21 01:05:24 +03:00
|
|
|
* If the two bands are joined, the previous band is the band that's deleted
|
1998-05-19 19:30:10 +04:00
|
|
|
*/
|
1999-01-04 07:54:33 +03:00
|
|
|
PRBool
|
|
|
|
nsSpaceManager::JoinBands(BandRect* aBand, BandRect* aPrevBand)
|
1998-05-19 19:30:10 +04:00
|
|
|
{
|
1998-05-20 02:55:40 +04:00
|
|
|
if (CanJoinBands(aBand, aPrevBand)) {
|
1998-05-20 09:14:14 +04:00
|
|
|
BandRect* startOfNextBand = aBand;
|
2007-01-24 00:42:41 +03:00
|
|
|
// We're going to be removing aPrevBand, so if mCachedBandPosition points
|
|
|
|
// to it just advance it to startOfNextBand.
|
|
|
|
if (mCachedBandPosition == aPrevBand) {
|
|
|
|
SetCachedBandPosition(startOfNextBand);
|
|
|
|
}
|
1998-05-20 02:55:40 +04:00
|
|
|
|
1998-05-20 09:14:14 +04:00
|
|
|
while (aPrevBand != startOfNextBand) {
|
1998-05-20 02:55:40 +04:00
|
|
|
// Adjust the top of the band we're keeping, and then move to the next
|
|
|
|
// rect within the band
|
1999-07-03 03:31:01 +04:00
|
|
|
aBand->mTop = aPrevBand->mTop;
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand = aBand->Next();
|
|
|
|
|
|
|
|
// Delete the rect from the previous band
|
|
|
|
BandRect* next = aPrevBand->Next();
|
|
|
|
|
2007-01-24 00:42:41 +03:00
|
|
|
NS_ASSERTION(mCachedBandPosition != aPrevBand,
|
|
|
|
"Removing mCachedBandPosition BandRect?");
|
1998-05-20 02:55:40 +04:00
|
|
|
aPrevBand->Remove();
|
|
|
|
delete aPrevBand;
|
|
|
|
aPrevBand = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-05-19 19:30:10 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
/**
|
|
|
|
* Adds a new rect to a band.
|
|
|
|
*
|
|
|
|
* @param aBand the first rect in the band
|
1998-05-19 07:00:56 +04:00
|
|
|
* @param aBandRect the band rect to add to the band
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
1999-01-04 07:54:33 +03:00
|
|
|
void
|
|
|
|
nsSpaceManager::AddRectToBand(BandRect* aBand, BandRect* aBandRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-07-03 03:31:01 +04:00
|
|
|
NS_PRECONDITION((aBand->mTop == aBandRect->mTop) &&
|
|
|
|
(aBand->mBottom == aBandRect->mBottom), "bad band");
|
2007-08-30 19:29:06 +04:00
|
|
|
NS_PRECONDITION(1 == aBandRect->mFrames.Count(), "shared band rect");
|
1999-07-03 03:31:01 +04:00
|
|
|
nscoord topOfBand = aBand->mTop;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Figure out where in the band horizontally to insert the rect
|
1998-04-14 00:24:54 +04:00
|
|
|
do {
|
|
|
|
// Compare the left edge of the new rect with the left edge of the existing
|
|
|
|
// rect
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBandRect->mLeft < aBand->mLeft) {
|
1998-04-29 04:58:16 +04:00
|
|
|
// The new rect's left edge is to the left of the existing rect's left edge.
|
|
|
|
// Could be any of these cases (N is new rect, E is existing rect):
|
|
|
|
//
|
|
|
|
// Case 1: left-of Case 2: overlaps Case 3: N.contains(E)
|
|
|
|
// --------------- ---------------- ---------------------
|
|
|
|
// +-----+ +-----+ +-----+ +---------+
|
|
|
|
// | N | | E | | N | | N |
|
|
|
|
// +-----+ +-----+ +-----+ +---------+
|
|
|
|
// +-----+ +---+
|
|
|
|
// | E | | E |
|
|
|
|
// +-----+ +---+
|
|
|
|
//
|
|
|
|
// Do the two rectangles overlap?
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBandRect->mRight <= aBand->mLeft) {
|
1998-04-29 04:58:16 +04:00
|
|
|
// No, the new rect is completely to the left of the existing rect
|
|
|
|
// (case #1). Insert a new rect
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand->InsertBefore(aBandRect);
|
2007-01-24 00:42:41 +03:00
|
|
|
if (mCachedBandPosition == aBand) {
|
|
|
|
SetCachedBandPosition(aBandRect);
|
|
|
|
}
|
1998-04-29 04:58:16 +04:00
|
|
|
return;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Yes, they overlap. Compare the right edges.
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBandRect->mRight > aBand->mRight) {
|
1998-05-19 07:00:56 +04:00
|
|
|
// The new rect's right edge is to the right of the existing rect's
|
|
|
|
// right edge (case #3). Split the new rect
|
1999-07-03 03:31:01 +04:00
|
|
|
BandRect* r1 = aBandRect->SplitHorizontally(aBand->mLeft);
|
1998-04-29 04:58:16 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Insert the part of the new rect that's to the left of the existing
|
|
|
|
// rect as a new band rect
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand->InsertBefore(aBandRect);
|
2007-01-29 05:16:23 +03:00
|
|
|
if (mCachedBandPosition == aBand) {
|
|
|
|
SetCachedBandPosition(aBandRect);
|
|
|
|
}
|
1998-05-20 02:55:40 +04:00
|
|
|
|
|
|
|
// Continue below with the part that overlaps the existing rect
|
1998-05-19 07:00:56 +04:00
|
|
|
aBandRect = r1;
|
1998-04-29 04:58:16 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
} else {
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBand->mRight > aBandRect->mRight) {
|
1998-05-19 07:00:56 +04:00
|
|
|
// The existing rect extends past the new rect (case #2). Split the
|
|
|
|
// existing rect
|
1999-07-03 03:31:01 +04:00
|
|
|
BandRect* r1 = aBand->SplitHorizontally(aBandRect->mRight);
|
1998-05-19 07:00:56 +04:00
|
|
|
|
|
|
|
// Insert the new right half of the existing rect
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand->InsertAfter(r1);
|
1998-05-19 07:00:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Insert the part of the new rect that's to the left of the existing
|
|
|
|
// rect
|
1999-07-03 03:31:01 +04:00
|
|
|
aBandRect->mRight = aBand->mLeft;
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand->InsertBefore(aBandRect);
|
1998-05-19 07:00:56 +04:00
|
|
|
|
2007-01-24 00:42:41 +03:00
|
|
|
if (mCachedBandPosition == aBand) {
|
|
|
|
SetCachedBandPosition(aBandRect);
|
|
|
|
}
|
|
|
|
|
1998-05-20 02:55:40 +04:00
|
|
|
// Mark the existing rect as shared
|
2007-08-30 19:29:06 +04:00
|
|
|
aBand->AddFrame(aBandRect->FrameAt(0));
|
1998-05-19 07:00:56 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1998-04-29 04:58:16 +04:00
|
|
|
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBandRect->mLeft > aBand->mLeft) {
|
1998-04-29 04:58:16 +04:00
|
|
|
// The new rect's left edge is to the right of the existing rect's left
|
|
|
|
// edge. Could be any one of these cases:
|
|
|
|
//
|
|
|
|
// Case 4: right-of Case 5: overlaps Case 6: E.Contains(N)
|
|
|
|
// --------------- ---------------- ---------------------
|
|
|
|
// +-----+ +-----+ +-----+ +------------+
|
|
|
|
// | E | | N | | E | | E |
|
|
|
|
// +-----+ +-----+ +-----+ +------------+
|
|
|
|
// +-----+ +-----+
|
|
|
|
// | N | | N |
|
|
|
|
// +-----+ +-----+
|
|
|
|
//
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBandRect->mLeft >= aBand->mRight) {
|
1998-04-29 04:58:16 +04:00
|
|
|
// The new rect is to the right of the existing rect (case #4), so move
|
|
|
|
// to the next rect in the band
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand = aBand->Next();
|
1998-04-29 04:58:16 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The rects overlap, so divide the existing rect into two rects: the
|
|
|
|
// part to the left of the new rect, and the part that overlaps
|
1999-07-03 03:31:01 +04:00
|
|
|
BandRect* r1 = aBand->SplitHorizontally(aBandRect->mLeft);
|
1998-04-29 04:58:16 +04:00
|
|
|
|
|
|
|
// Insert the new right half of the existing rect, and make it the current
|
|
|
|
// rect
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand->InsertAfter(r1);
|
1998-05-19 07:00:56 +04:00
|
|
|
aBand = r1;
|
1998-04-29 04:58:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// At this point the left edge of the new rect is the same as the left edge
|
|
|
|
// of the existing rect
|
1999-07-03 03:31:01 +04:00
|
|
|
NS_ASSERTION(aBandRect->mLeft == aBand->mLeft, "unexpected rect");
|
1998-04-29 04:58:16 +04:00
|
|
|
|
|
|
|
// Compare which rect is wider, the new rect or the existing rect
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBand->mRight > aBandRect->mRight) {
|
1998-05-19 07:00:56 +04:00
|
|
|
// The existing rect is wider (case #6). Divide the existing rect into
|
|
|
|
// two rects: the part that overlaps, and the part to the right of the
|
|
|
|
// new rect
|
1999-07-03 03:31:01 +04:00
|
|
|
BandRect* r1 = aBand->SplitHorizontally(aBandRect->mRight);
|
1998-04-29 04:58:16 +04:00
|
|
|
|
|
|
|
// Insert the new right half of the existing rect
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand->InsertAfter(r1);
|
1998-04-29 04:58:16 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Mark the overlap as being shared
|
2007-08-30 19:29:06 +04:00
|
|
|
aBand->AddFrame(aBandRect->FrameAt(0));
|
2007-12-19 20:44:45 +03:00
|
|
|
|
|
|
|
// We no longer need aBandRect, since the area it covers is covered by
|
|
|
|
// the part of aBand that SplitHorizontally left in place. Just delete
|
|
|
|
// it.
|
|
|
|
delete aBandRect;
|
1998-04-14 00:24:54 +04:00
|
|
|
return;
|
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
} else {
|
|
|
|
// Indicate the frames share the existing rect
|
2007-08-30 19:29:06 +04:00
|
|
|
aBand->AddFrame(aBandRect->FrameAt(0));
|
1998-05-19 07:00:56 +04:00
|
|
|
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBand->mRight == aBandRect->mRight) {
|
1998-05-19 07:00:56 +04:00
|
|
|
// The new and existing rect have the same right edge. We're all done,
|
|
|
|
// and the new band rect is no longer needed
|
|
|
|
delete aBandRect;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// The new rect is wider than the existing rect (cases #5). Set the
|
|
|
|
// new rect to be the overhang, and move to the next rect within the band
|
1999-07-03 03:31:01 +04:00
|
|
|
aBandRect->mLeft = aBand->mRight;
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand = aBand->Next();
|
1998-05-19 07:00:56 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
1999-07-03 03:31:01 +04:00
|
|
|
} while (aBand->mTop == topOfBand);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2007-01-24 00:42:41 +03:00
|
|
|
// Insert a new rect. This is an insertion at the _end_ of the band, so we
|
|
|
|
// absolutely do not want to set mCachedBandPosition to aBandRect here.
|
1998-05-20 02:55:40 +04:00
|
|
|
aBand->InsertBefore(aBandRect);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// When comparing a rect to a band there are seven cases to consider.
|
|
|
|
// 'R' is the rect and 'B' is the band.
|
|
|
|
//
|
|
|
|
// Case 1 Case 2 Case 3 Case 4
|
|
|
|
// ------ ------ ------ ------
|
|
|
|
// +-----+ +-----+ +-----+ +-----+
|
|
|
|
// | R | | R | +-----+ +-----+ | | | |
|
|
|
|
// +-----+ +-----+ | | | R | | B | | B |
|
|
|
|
// +-----+ | B | +-----+ | | +-----+ | |
|
|
|
|
// | | | | +-----+ | R | +-----+
|
|
|
|
// | B | +-----+ +-----+
|
|
|
|
// | |
|
|
|
|
// +-----+
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Case 5 Case 6 Case 7
|
|
|
|
// ------ ------ ------
|
|
|
|
// +-----+ +-----+ +-----+ +-----+
|
|
|
|
// | | | R | | B | | | +-----+
|
|
|
|
// | B | +-----+ +-----+ | R | | B |
|
|
|
|
// | | | | +-----+
|
|
|
|
// +-----+ +-----+
|
|
|
|
// +-----+
|
|
|
|
// | R |
|
|
|
|
// +-----+
|
|
|
|
//
|
1999-01-04 07:54:33 +03:00
|
|
|
void
|
|
|
|
nsSpaceManager::InsertBandRect(BandRect* aBandRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-19 07:00:56 +04:00
|
|
|
// If there are no existing bands or this rect is below the bottommost
|
|
|
|
// band, then add a new band
|
1999-01-04 07:54:33 +03:00
|
|
|
nscoord yMost;
|
2001-10-26 09:06:07 +04:00
|
|
|
if (!YMost(yMost) || (aBandRect->mTop >= yMost)) {
|
1998-05-20 02:55:40 +04:00
|
|
|
mBandList.Append(aBandRect);
|
2007-01-24 00:42:41 +03:00
|
|
|
SetCachedBandPosition(aBandRect);
|
1998-05-19 07:00:56 +04:00
|
|
|
return;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Examine each band looking for a band that intersects this rect
|
2007-01-24 00:42:41 +03:00
|
|
|
// First guess a band whose top is above aBandRect->mTop. We know
|
|
|
|
// aBandRect won't overlap any bands before that one.
|
|
|
|
BandRect* band = GuessBandWithTopAbove(aBandRect->mTop);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
while (nsnull != band) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// Compare the top edge of this rect with the top edge of the band
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBandRect->mTop < band->mTop) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// The top edge of the rect is above the top edge of the band.
|
|
|
|
// Is there any overlap?
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBandRect->mBottom <= band->mTop) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// Case #1. This rect is completely above the band, so insert a
|
1998-05-19 07:00:56 +04:00
|
|
|
// new band before the current band
|
1998-05-20 02:55:40 +04:00
|
|
|
band->InsertBefore(aBandRect);
|
2007-01-24 00:42:41 +03:00
|
|
|
SetCachedBandPosition(aBandRect);
|
1998-04-14 00:24:54 +04:00
|
|
|
break; // we're all done
|
|
|
|
}
|
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Case #2 and case #7. Divide this rect, creating a new rect for
|
|
|
|
// the part that's above the band
|
1999-07-03 03:31:01 +04:00
|
|
|
BandRect* bandRect1 = new BandRect(aBandRect->mLeft, aBandRect->mTop,
|
|
|
|
aBandRect->mRight, band->mTop,
|
2007-08-30 19:29:06 +04:00
|
|
|
aBandRect->mFrames);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Insert bandRect1 as a new band
|
1998-05-20 02:55:40 +04:00
|
|
|
band->InsertBefore(bandRect1);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Modify this rect to exclude the part above the band
|
1999-07-03 03:31:01 +04:00
|
|
|
aBandRect->mTop = band->mTop;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-03 03:31:01 +04:00
|
|
|
} else if (aBandRect->mTop > band->mTop) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// The top edge of the rect is below the top edge of the band. Is there
|
|
|
|
// any overlap?
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBandRect->mTop >= band->mBottom) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// Case #5. This rect is below the current band. Skip to the next band
|
1998-05-19 07:00:56 +04:00
|
|
|
band = GetNextBand(band);
|
1998-04-14 00:24:54 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Case #3 and case #4. Divide the current band into two bands with the
|
|
|
|
// top band being the part that's above the rect
|
1999-07-03 03:31:01 +04:00
|
|
|
DivideBand(band, aBandRect->mTop);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Skip to the bottom band that we just created
|
1998-05-19 07:00:56 +04:00
|
|
|
band = GetNextBand(band);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// At this point the rect and the band should have the same y-offset
|
1999-07-03 03:31:01 +04:00
|
|
|
NS_ASSERTION(aBandRect->mTop == band->mTop, "unexpected band");
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Is the band higher than the rect?
|
1999-07-03 03:31:01 +04:00
|
|
|
if (band->mBottom > aBandRect->mBottom) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// Divide the band into two bands with the top band the same height
|
|
|
|
// as the rect
|
1999-07-03 03:31:01 +04:00
|
|
|
DivideBand(band, aBandRect->mBottom);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-07-03 03:31:01 +04:00
|
|
|
if (aBandRect->mBottom == band->mBottom) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// Add the rect to the band
|
2007-01-24 00:42:41 +03:00
|
|
|
SetCachedBandPosition(band); // Do this before AddRectToBand
|
1998-05-19 07:00:56 +04:00
|
|
|
AddRectToBand(band, aBandRect);
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Case #4 and case #7. The rect contains the band vertically. Divide
|
|
|
|
// the rect, creating a new rect for the part that overlaps the band
|
1999-07-03 03:31:01 +04:00
|
|
|
BandRect* bandRect1 = new BandRect(aBandRect->mLeft, aBandRect->mTop,
|
|
|
|
aBandRect->mRight, band->mBottom,
|
2007-08-30 19:29:06 +04:00
|
|
|
aBandRect->mFrames);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Add bandRect1 to the band
|
|
|
|
AddRectToBand(band, bandRect1);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Modify aBandRect to be the part below the band
|
1999-07-03 03:31:01 +04:00
|
|
|
aBandRect->mTop = band->mBottom;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Continue with the next band
|
1998-05-19 07:00:56 +04:00
|
|
|
band = GetNextBand(band);
|
|
|
|
if (nsnull == band) {
|
1998-04-14 00:24:54 +04:00
|
|
|
// Append a new bottommost band
|
1998-05-20 02:55:40 +04:00
|
|
|
mBandList.Append(aBandRect);
|
2007-01-24 00:42:41 +03:00
|
|
|
SetCachedBandPosition(aBandRect);
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-05-19 07:00:56 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
nsresult
|
1999-01-04 07:54:33 +03:00
|
|
|
nsSpaceManager::AddRectRegion(nsIFrame* aFrame, const nsRect& aUnavailableSpace)
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null frame");
|
2007-10-04 08:33:43 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Convert the frame to world coordinates
|
|
|
|
nsRect rect(aUnavailableSpace.x + mX, aUnavailableSpace.y + mY,
|
|
|
|
aUnavailableSpace.width, aUnavailableSpace.height);
|
|
|
|
|
2003-03-12 02:56:49 +03:00
|
|
|
if (rect.y > mLowestTop)
|
|
|
|
mLowestTop = rect.y;
|
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Create a frame info structure
|
2006-08-30 01:56:51 +04:00
|
|
|
FrameInfo* frameInfo = CreateFrameInfo(aFrame, rect);
|
1999-01-04 07:54:33 +03:00
|
|
|
if (nsnull == frameInfo) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-05-19 07:00:56 +04:00
|
|
|
|
2007-11-08 07:42:26 +03:00
|
|
|
if (aUnavailableSpace.IsEmpty())
|
1999-01-04 07:54:33 +03:00
|
|
|
return NS_OK;
|
1998-05-19 07:00:56 +04:00
|
|
|
|
|
|
|
// Allocate a band rect
|
2007-11-07 14:03:10 +03:00
|
|
|
BandRect* bandRect = new BandRect(rect.x, rect.y,
|
|
|
|
PR_MIN(rect.XMost(), nscoord_MAX),
|
|
|
|
PR_MIN(rect.YMost(), nscoord_MAX),
|
|
|
|
aFrame);
|
1999-01-04 07:54:33 +03:00
|
|
|
if (nsnull == bandRect) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-05-13 03:02:02 +04:00
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
// Insert the band rect
|
|
|
|
InsertBandRect(bandRect);
|
1999-01-04 07:54:33 +03:00
|
|
|
return NS_OK;
|
1998-05-13 03:02:02 +04:00
|
|
|
}
|
|
|
|
|
2004-09-13 17:35:46 +04:00
|
|
|
nsresult
|
|
|
|
nsSpaceManager::RemoveTrailingRegions(nsIFrame* aFrameList) {
|
|
|
|
nsVoidHashSet frameSet;
|
|
|
|
|
|
|
|
frameSet.Init(1);
|
|
|
|
for (nsIFrame* f = aFrameList; f; f = f->GetNextSibling()) {
|
|
|
|
frameSet.Put(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pop frame regions off as long as they're in the set of frames to
|
|
|
|
// remove
|
|
|
|
while (mFrameInfoMap && frameSet.Contains(mFrameInfoMap->mFrame)) {
|
|
|
|
RemoveRegion(mFrameInfoMap->mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
for (FrameInfo* frameInfo = mFrameInfoMap; frameInfo;
|
|
|
|
frameInfo = frameInfo->mNext) {
|
|
|
|
NS_ASSERTION(!frameSet.Contains(frameInfo->mFrame),
|
|
|
|
"Frame region deletion was requested but we couldn't delete it");
|
|
|
|
}
|
|
|
|
#endif
|
2004-09-13 19:24:11 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2004-09-13 17:35:46 +04:00
|
|
|
}
|
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
nsresult
|
1999-01-04 07:54:33 +03:00
|
|
|
nsSpaceManager::RemoveRegion(nsIFrame* aFrame)
|
1998-05-13 03:02:02 +04:00
|
|
|
{
|
1998-05-20 02:55:40 +04:00
|
|
|
// Get the frame info associated with aFrame
|
1998-05-19 19:30:10 +04:00
|
|
|
FrameInfo* frameInfo = GetFrameInfoFor(aFrame);
|
|
|
|
|
|
|
|
if (nsnull == frameInfo) {
|
|
|
|
NS_WARNING("no region associated with aFrame");
|
1999-01-04 07:54:33 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
1998-05-19 19:30:10 +04:00
|
|
|
}
|
1998-05-13 03:02:02 +04:00
|
|
|
|
2007-11-08 07:42:26 +03:00
|
|
|
if (!frameInfo->mRect.IsEmpty()) {
|
1998-05-20 09:14:14 +04:00
|
|
|
NS_ASSERTION(!mBandList.IsEmpty(), "no bands");
|
1998-05-20 02:55:40 +04:00
|
|
|
BandRect* band = mBandList.Head();
|
1998-05-19 19:30:10 +04:00
|
|
|
BandRect* prevBand = nsnull;
|
|
|
|
PRBool prevFoundMatchingRect = PR_FALSE;
|
1998-05-13 20:22:44 +04:00
|
|
|
|
1998-05-19 19:30:10 +04:00
|
|
|
// Iterate each band looking for rects tagged with aFrame
|
|
|
|
while (nsnull != band) {
|
|
|
|
BandRect* rect = band;
|
|
|
|
BandRect* prevRect = nsnull;
|
1999-07-03 03:31:01 +04:00
|
|
|
nscoord topOfBand = band->mTop;
|
1998-05-19 19:30:10 +04:00
|
|
|
PRBool foundMatchingRect = PR_FALSE;
|
|
|
|
PRBool prevIsSharedRect = PR_FALSE;
|
|
|
|
|
|
|
|
// Iterate each rect in the band
|
|
|
|
do {
|
|
|
|
PRBool isSharedRect = PR_FALSE;
|
|
|
|
|
|
|
|
if (rect->IsOccupiedBy(aFrame)) {
|
1998-05-20 09:14:14 +04:00
|
|
|
// Remember that we found a matching rect in this band
|
|
|
|
foundMatchingRect = PR_TRUE;
|
|
|
|
|
2007-08-30 19:29:06 +04:00
|
|
|
if (rect->mFrames.Count() > 1) {
|
1998-05-19 19:30:10 +04:00
|
|
|
// The band rect is occupied by more than one frame
|
2007-08-30 19:29:06 +04:00
|
|
|
rect->mFrames.RemoveElement(aFrame);
|
1998-05-19 19:30:10 +04:00
|
|
|
|
|
|
|
// Remember that this rect was being shared by more than one frame
|
|
|
|
// including aFrame
|
|
|
|
isSharedRect = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// The rect isn't shared so just delete it
|
1998-05-20 09:14:14 +04:00
|
|
|
BandRect* next = rect->Next();
|
1998-05-20 02:55:40 +04:00
|
|
|
rect->Remove();
|
1998-05-20 09:14:14 +04:00
|
|
|
if (rect == band) {
|
|
|
|
// The rect we're deleting is the start of the band
|
1999-07-03 03:31:01 +04:00
|
|
|
if (topOfBand == next->mTop) {
|
1998-05-20 09:14:14 +04:00
|
|
|
band = next;
|
|
|
|
} else {
|
|
|
|
band = nsnull;
|
|
|
|
}
|
2007-01-24 00:42:41 +03:00
|
|
|
if (mCachedBandPosition == rect) {
|
|
|
|
SetCachedBandPosition(band);
|
|
|
|
}
|
1998-05-20 09:14:14 +04:00
|
|
|
}
|
|
|
|
delete rect;
|
|
|
|
rect = next;
|
|
|
|
|
|
|
|
// We don't need to try and coalesce adjacent rects in this case
|
|
|
|
prevRect = nsnull;
|
|
|
|
prevIsSharedRect = PR_FALSE;
|
|
|
|
continue;
|
1998-05-19 19:30:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-20 09:14:14 +04:00
|
|
|
// If we found a shared rect occupied by aFrame, then we need to try
|
|
|
|
// and coalesce adjacent rects
|
1998-05-19 19:30:10 +04:00
|
|
|
if (prevIsSharedRect || (isSharedRect && (nsnull != prevRect))) {
|
|
|
|
NS_ASSERTION(nsnull != prevRect, "no previous rect");
|
1999-07-03 03:31:01 +04:00
|
|
|
if ((prevRect->mRight == rect->mLeft) && (prevRect->HasSameFrameList(rect))) {
|
1998-05-19 19:30:10 +04:00
|
|
|
// Modify the current rect's left edge, and delete the previous rect
|
1999-07-03 03:31:01 +04:00
|
|
|
rect->mLeft = prevRect->mLeft;
|
1998-05-20 02:55:40 +04:00
|
|
|
prevRect->Remove();
|
1998-05-20 09:14:14 +04:00
|
|
|
if (prevRect == band) {
|
|
|
|
// the rect we're deleting is the start of the band
|
|
|
|
band = rect;
|
2007-01-24 00:42:41 +03:00
|
|
|
if (mCachedBandPosition == prevRect) {
|
|
|
|
SetCachedBandPosition(band);
|
|
|
|
}
|
1998-05-20 09:14:14 +04:00
|
|
|
}
|
1998-05-19 19:30:10 +04:00
|
|
|
delete prevRect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the next rect in the band
|
|
|
|
prevRect = rect;
|
|
|
|
prevIsSharedRect = isSharedRect;
|
1998-05-20 02:55:40 +04:00
|
|
|
rect = rect->Next();
|
1999-07-03 03:31:01 +04:00
|
|
|
} while (rect->mTop == topOfBand);
|
1998-05-19 19:30:10 +04:00
|
|
|
|
1998-05-20 09:14:14 +04:00
|
|
|
if (nsnull != band) {
|
|
|
|
// If we found a rect occupied by aFrame in this band or the previous band
|
|
|
|
// then try to join the two bands
|
1998-05-31 03:56:28 +04:00
|
|
|
if ((nsnull != prevBand) && (foundMatchingRect || prevFoundMatchingRect)) {
|
1998-05-20 09:14:14 +04:00
|
|
|
// Try and join this band with the previous band
|
|
|
|
JoinBands(band, prevBand);
|
|
|
|
}
|
1998-05-13 20:22:44 +04:00
|
|
|
}
|
1998-05-19 19:30:10 +04:00
|
|
|
|
|
|
|
// Move to the next band
|
|
|
|
prevFoundMatchingRect = foundMatchingRect;
|
1998-05-20 09:14:14 +04:00
|
|
|
prevBand = band;
|
|
|
|
band = (rect == &mBandList) ? nsnull : rect;
|
2007-01-24 00:42:41 +03:00
|
|
|
if (!mCachedBandPosition) {
|
|
|
|
SetCachedBandPosition(band);
|
|
|
|
}
|
1998-05-13 03:02:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-19 19:30:10 +04:00
|
|
|
DestroyFrameInfo(frameInfo);
|
1999-01-04 07:54:33 +03:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2002-08-19 08:41:57 +04:00
|
|
|
void
|
2006-06-29 05:19:48 +04:00
|
|
|
nsSpaceManager::PushState(SavedState* aState)
|
2002-08-19 08:41:57 +04:00
|
|
|
{
|
2006-06-29 05:19:48 +04:00
|
|
|
NS_PRECONDITION(aState, "Need a place to save state");
|
|
|
|
|
|
|
|
// This is a cheap push implementation, which
|
2002-08-19 08:41:57 +04:00
|
|
|
// 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.
|
|
|
|
//
|
2006-06-29 05:19:48 +04:00
|
|
|
// This push/pop mechanism is used to undo any
|
2003-10-14 01:51:02 +04:00
|
|
|
// floats that were added during the unconstrained reflow
|
2002-08-19 08:41:57 +04:00
|
|
|
// 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.
|
2006-06-29 05:19:48 +04:00
|
|
|
aState->mX = mX;
|
|
|
|
aState->mY = mY;
|
|
|
|
aState->mLowestTop = mLowestTop;
|
2006-08-30 01:56:51 +04:00
|
|
|
aState->mHaveCachedLeftYMost = mHaveCachedLeftYMost;
|
|
|
|
aState->mHaveCachedRightYMost = mHaveCachedRightYMost;
|
|
|
|
aState->mMaximalLeftYMost = mMaximalLeftYMost;
|
|
|
|
aState->mMaximalRightYMost = mMaximalRightYMost;
|
2002-08-19 08:41:57 +04:00
|
|
|
|
|
|
|
if (mFrameInfoMap) {
|
2006-06-29 05:19:48 +04:00
|
|
|
aState->mLastFrame = mFrameInfoMap->mFrame;
|
2004-06-06 22:45:02 +04:00
|
|
|
} else {
|
2006-06-29 05:19:48 +04:00
|
|
|
aState->mLastFrame = nsnull;
|
2002-08-19 08:41:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-29 05:19:48 +04:00
|
|
|
nsSpaceManager::PopState(SavedState* aState)
|
2002-08-19 08:41:57 +04:00
|
|
|
{
|
2006-06-29 05:19:48 +04:00
|
|
|
NS_PRECONDITION(aState, "No state to restore?");
|
|
|
|
|
2002-08-19 08:41:57 +04:00
|
|
|
// This is a quick and dirty pop implementation, to
|
|
|
|
// match the current implementation of PushState(). The
|
|
|
|
// idea here is to remove any frames that have been added
|
|
|
|
// to the mFrameInfoMap since the last call to PushState().
|
|
|
|
|
2006-08-30 01:56:51 +04:00
|
|
|
// Say we don't have cached left- and right-YMost, so that we don't
|
|
|
|
// try to check for it in RemoveRegion. We'll restore these from
|
|
|
|
// the state anyway.
|
|
|
|
mHaveCachedLeftYMost = mHaveCachedRightYMost = PR_FALSE;
|
|
|
|
|
2002-08-19 08:41:57 +04:00
|
|
|
// mFrameInfoMap is LIFO so keep removing what it points
|
|
|
|
// to until we hit mLastFrame.
|
2006-06-29 05:19:48 +04:00
|
|
|
while (mFrameInfoMap && mFrameInfoMap->mFrame != aState->mLastFrame) {
|
2002-08-19 08:41:57 +04:00
|
|
|
RemoveRegion(mFrameInfoMap->mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we trip this assertion it means that someone added
|
|
|
|
// PushState()/PopState() calls around code that actually
|
|
|
|
// removed mLastFrame from mFrameInfoMap, which means our
|
|
|
|
// state is now out of sync with what we thought it should be.
|
|
|
|
|
2006-06-29 05:19:48 +04:00
|
|
|
NS_ASSERTION(((aState->mLastFrame && mFrameInfoMap) ||
|
|
|
|
(!aState->mLastFrame && !mFrameInfoMap)),
|
2002-08-19 08:41:57 +04:00
|
|
|
"Unexpected outcome!");
|
|
|
|
|
2006-06-29 05:19:48 +04:00
|
|
|
mX = aState->mX;
|
|
|
|
mY = aState->mY;
|
|
|
|
mLowestTop = aState->mLowestTop;
|
2006-08-30 01:56:51 +04:00
|
|
|
mHaveCachedLeftYMost = aState->mHaveCachedLeftYMost;
|
|
|
|
mHaveCachedRightYMost = aState->mHaveCachedRightYMost;
|
|
|
|
mMaximalLeftYMost = aState->mMaximalLeftYMost;
|
|
|
|
mMaximalRightYMost = aState->mMaximalRightYMost;
|
2004-11-25 17:51:00 +03:00
|
|
|
}
|
|
|
|
|
2003-03-12 02:56:49 +03:00
|
|
|
nscoord
|
|
|
|
nsSpaceManager::GetLowestRegionTop()
|
|
|
|
{
|
|
|
|
if (mLowestTop == NSCOORD_MIN)
|
|
|
|
return mLowestTop;
|
|
|
|
return mLowestTop - mY;
|
|
|
|
}
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
2002-05-10 22:22:41 +04:00
|
|
|
void
|
|
|
|
DebugListSpaceManager(nsSpaceManager *aSpaceManager)
|
|
|
|
{
|
|
|
|
aSpaceManager->List(stdout);
|
|
|
|
}
|
|
|
|
|
2001-10-26 09:06:07 +04:00
|
|
|
nsresult
|
1999-09-15 04:24:54 +04:00
|
|
|
nsSpaceManager::List(FILE* out)
|
|
|
|
{
|
|
|
|
nsAutoString tmp;
|
|
|
|
|
|
|
|
fprintf(out, "SpaceManager@%p", this);
|
|
|
|
fprintf(out, " xy=%d,%d <\n", mX, mY);
|
|
|
|
if (mBandList.IsEmpty()) {
|
|
|
|
fprintf(out, " no bands\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BandRect* band = mBandList.Head();
|
|
|
|
do {
|
2007-08-30 19:29:06 +04:00
|
|
|
PRInt32 const n = band->mFrames.Count();
|
|
|
|
fprintf(out, " left=%d top=%d right=%d bottom=%d count=%d frames=",
|
|
|
|
band->mLeft, band->mTop, band->mRight, band->mBottom, n);
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < n; i++) {
|
|
|
|
nsIFrame* frame = (nsIFrame*)band->mFrames.FastElementAt(i);
|
|
|
|
if (frame) {
|
|
|
|
nsIFrameDebug* frameDebug;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(frame->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) {
|
|
|
|
frameDebug->GetFrameName(tmp);
|
|
|
|
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
|
|
|
|
fprintf(out, "@%p ", frame);
|
1999-09-15 04:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
band = band->Next();
|
|
|
|
} while (band != mBandList.Head());
|
|
|
|
}
|
|
|
|
fprintf(out, ">\n");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1999-09-15 04:24:54 +04:00
|
|
|
|
1999-01-04 07:54:33 +03:00
|
|
|
nsSpaceManager::FrameInfo*
|
|
|
|
nsSpaceManager::GetFrameInfoFor(nsIFrame* aFrame)
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
|
|
|
FrameInfo* result = nsnull;
|
|
|
|
|
1999-10-06 08:22:51 +04:00
|
|
|
for (result = mFrameInfoMap; result; result = result->mNext) {
|
|
|
|
if (result->mFrame == aFrame) {
|
|
|
|
break;
|
|
|
|
}
|
1998-05-19 07:00:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-01-04 07:54:33 +03:00
|
|
|
nsSpaceManager::FrameInfo*
|
|
|
|
nsSpaceManager::CreateFrameInfo(nsIFrame* aFrame, const nsRect& aRect)
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
|
|
|
FrameInfo* frameInfo = new FrameInfo(aFrame, aRect);
|
1999-10-06 08:22:51 +04:00
|
|
|
|
|
|
|
if (frameInfo) {
|
|
|
|
// Link it into the list
|
|
|
|
frameInfo->mNext = mFrameInfoMap;
|
|
|
|
mFrameInfoMap = frameInfo;
|
2006-08-30 01:56:51 +04:00
|
|
|
|
|
|
|
// Optimize for the common case case when the frame being added is
|
|
|
|
// likely to be near the bottom.
|
|
|
|
nscoord ymost = aRect.YMost();
|
|
|
|
PRUint8 floatType = aFrame->GetStyleDisplay()->mFloats;
|
|
|
|
if (mHaveCachedLeftYMost && ymost > mMaximalLeftYMost &&
|
|
|
|
floatType == NS_STYLE_FLOAT_LEFT) {
|
|
|
|
mMaximalLeftYMost = ymost;
|
|
|
|
}
|
|
|
|
else if (mHaveCachedRightYMost && ymost > mMaximalRightYMost &&
|
|
|
|
floatType == NS_STYLE_FLOAT_RIGHT) {
|
|
|
|
mMaximalRightYMost = ymost;
|
|
|
|
}
|
1999-01-04 07:54:33 +03:00
|
|
|
}
|
1998-05-19 07:00:56 +04:00
|
|
|
return frameInfo;
|
|
|
|
}
|
|
|
|
|
1999-01-04 07:54:33 +03:00
|
|
|
void
|
|
|
|
nsSpaceManager::DestroyFrameInfo(FrameInfo* aFrameInfo)
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
1999-10-06 08:22:51 +04:00
|
|
|
// See if it's at the head of the list
|
|
|
|
if (mFrameInfoMap == aFrameInfo) {
|
|
|
|
mFrameInfoMap = aFrameInfo->mNext;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
FrameInfo* prev;
|
|
|
|
|
|
|
|
// Find the previous node in the list
|
|
|
|
for (prev = mFrameInfoMap; prev && (prev->mNext != aFrameInfo); prev = prev->mNext) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disconnect it from the list
|
|
|
|
NS_ASSERTION(prev, "element not in list");
|
|
|
|
if (prev) {
|
|
|
|
prev->mNext = aFrameInfo->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-30 01:56:51 +04:00
|
|
|
// Optimize for the case when the frame being removed is likely to be near
|
|
|
|
// the bottom, but do nothing if we have neither cached value -- that case is
|
|
|
|
// likely to be hit from PopState().
|
|
|
|
if (mHaveCachedLeftYMost || mHaveCachedRightYMost) {
|
|
|
|
PRUint8 floatType = aFrameInfo->mFrame->GetStyleDisplay()->mFloats;
|
|
|
|
if (floatType == NS_STYLE_FLOAT_LEFT) {
|
|
|
|
mHaveCachedLeftYMost = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(floatType == NS_STYLE_FLOAT_RIGHT, "Unexpected float type");
|
|
|
|
mHaveCachedRightYMost = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
delete aFrameInfo;
|
|
|
|
}
|
|
|
|
|
2006-08-30 01:56:51 +04:00
|
|
|
nscoord
|
|
|
|
nsSpaceManager::ClearFloats(nscoord aY, PRUint8 aBreakType)
|
2004-06-08 23:18:30 +04:00
|
|
|
{
|
2006-08-30 01:56:51 +04:00
|
|
|
nscoord bottom = aY + mY;
|
|
|
|
|
|
|
|
if ((!mHaveCachedLeftYMost && aBreakType != NS_STYLE_CLEAR_RIGHT) ||
|
|
|
|
(!mHaveCachedRightYMost && aBreakType != NS_STYLE_CLEAR_LEFT)) {
|
|
|
|
// Recover our maximal YMost values. Might need both if this is a
|
|
|
|
// NS_STYLE_CLEAR_LEFT_AND_RIGHT
|
2007-07-21 00:05:02 +04:00
|
|
|
nscoord maximalLeftYMost = mHaveCachedLeftYMost ? mMaximalLeftYMost : nscoord_MIN;
|
|
|
|
nscoord maximalRightYMost = mHaveCachedRightYMost ? mMaximalRightYMost : nscoord_MIN;
|
2006-08-30 01:56:51 +04:00
|
|
|
|
|
|
|
// Optimize for most floats not being near the bottom
|
|
|
|
for (FrameInfo *frame = mFrameInfoMap; frame; frame = frame->mNext) {
|
|
|
|
nscoord ymost = frame->mRect.YMost();
|
|
|
|
if (ymost > maximalLeftYMost) {
|
|
|
|
if (frame->mFrame->GetStyleDisplay()->mFloats == NS_STYLE_FLOAT_LEFT) {
|
|
|
|
NS_ASSERTION(!mHaveCachedLeftYMost, "Shouldn't happen");
|
|
|
|
maximalLeftYMost = ymost;
|
|
|
|
// No need to compare to the right ymost
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ymost > maximalRightYMost) {
|
|
|
|
if (frame->mFrame->GetStyleDisplay()->mFloats == NS_STYLE_FLOAT_RIGHT) {
|
|
|
|
NS_ASSERTION(!mHaveCachedRightYMost, "Shouldn't happen");
|
|
|
|
maximalRightYMost = ymost;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mMaximalLeftYMost = maximalLeftYMost;
|
|
|
|
mMaximalRightYMost = maximalRightYMost;
|
|
|
|
mHaveCachedRightYMost = mHaveCachedLeftYMost = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2004-06-08 23:18:30 +04:00
|
|
|
switch (aBreakType) {
|
|
|
|
case NS_STYLE_CLEAR_LEFT_AND_RIGHT:
|
2006-08-30 01:56:51 +04:00
|
|
|
NS_ASSERTION(mHaveCachedLeftYMost && mHaveCachedRightYMost,
|
|
|
|
"Need cached values!");
|
|
|
|
bottom = PR_MAX(bottom, mMaximalLeftYMost);
|
|
|
|
bottom = PR_MAX(bottom, mMaximalRightYMost);
|
2004-06-08 23:18:30 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_CLEAR_LEFT:
|
2006-08-30 01:56:51 +04:00
|
|
|
NS_ASSERTION(mHaveCachedLeftYMost, "Need cached value!");
|
|
|
|
bottom = PR_MAX(bottom, mMaximalLeftYMost);
|
2004-06-08 23:18:30 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_CLEAR_RIGHT:
|
2006-08-30 01:56:51 +04:00
|
|
|
NS_ASSERTION(mHaveCachedRightYMost, "Need cached value!");
|
|
|
|
bottom = PR_MAX(bottom, mMaximalRightYMost);
|
2004-06-08 23:18:30 +04:00
|
|
|
break;
|
|
|
|
default:
|
2006-08-30 01:56:51 +04:00
|
|
|
// Do nothing
|
|
|
|
break;
|
2004-06-08 23:18:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bottom -= mY;
|
|
|
|
|
|
|
|
return bottom;
|
|
|
|
}
|
|
|
|
|
2007-01-24 00:42:41 +03:00
|
|
|
nsSpaceManager::BandRect*
|
|
|
|
nsSpaceManager::GuessBandWithTopAbove(nscoord aYOffset) const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mBandList.IsEmpty(), "no bands");
|
|
|
|
BandRect* band = nsnull;
|
|
|
|
if (mCachedBandPosition) {
|
|
|
|
band = mCachedBandPosition;
|
|
|
|
// Now seek backward so that we're guaranteed to be the topmost
|
|
|
|
// band which might contain the y-offset or be below it.
|
|
|
|
while (band && band->mTop > aYOffset) {
|
|
|
|
band = GetPrevBand(band);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (band) {
|
|
|
|
return band;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mBandList.Head();
|
|
|
|
}
|
|
|
|
|
1998-05-19 07:00:56 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FrameInfo
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
nsSpaceManager::FrameInfo::FrameInfo(nsIFrame* aFrame, const nsRect& aRect)
|
1999-10-06 08:22:51 +04:00
|
|
|
: mFrame(aFrame), mRect(aRect), mNext(0)
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
2000-12-16 21:56:06 +03:00
|
|
|
MOZ_COUNT_CTOR(nsSpaceManager::FrameInfo);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-12-16 21:56:06 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
1999-10-09 00:41:19 +04:00
|
|
|
nsSpaceManager::FrameInfo::~FrameInfo()
|
|
|
|
{
|
2000-12-16 21:56:06 +03:00
|
|
|
MOZ_COUNT_DTOR(nsSpaceManager::FrameInfo);
|
1999-10-09 00:41:19 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-05-13 20:22:44 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// BandRect
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
nsSpaceManager::BandRect::BandRect(nscoord aLeft,
|
|
|
|
nscoord aTop,
|
|
|
|
nscoord aRight,
|
|
|
|
nscoord aBottom,
|
|
|
|
nsIFrame* aFrame)
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(BandRect);
|
1999-07-03 03:31:01 +04:00
|
|
|
mLeft = aLeft;
|
|
|
|
mTop = aTop;
|
|
|
|
mRight = aRight;
|
|
|
|
mBottom = aBottom;
|
2007-08-30 19:29:06 +04:00
|
|
|
AddFrame(aFrame);
|
1998-05-19 07:00:56 +04:00
|
|
|
}
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
nsSpaceManager::BandRect::BandRect(nscoord aLeft,
|
|
|
|
nscoord aTop,
|
|
|
|
nscoord aRight,
|
|
|
|
nscoord aBottom,
|
2007-08-30 19:29:06 +04:00
|
|
|
nsSmallVoidArray& aFrames)
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(BandRect);
|
1999-07-03 03:31:01 +04:00
|
|
|
mLeft = aLeft;
|
|
|
|
mTop = aTop;
|
|
|
|
mRight = aRight;
|
|
|
|
mBottom = aBottom;
|
2007-08-30 19:29:06 +04:00
|
|
|
mFrames = aFrames;
|
1998-05-19 07:00:56 +04:00
|
|
|
}
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
nsSpaceManager::BandRect::~BandRect()
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(BandRect);
|
1998-05-19 07:00:56 +04:00
|
|
|
}
|
|
|
|
|
1999-01-04 07:54:33 +03:00
|
|
|
nsSpaceManager::BandRect*
|
|
|
|
nsSpaceManager::BandRect::SplitVertically(nscoord aBottom)
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
1999-07-03 03:31:01 +04:00
|
|
|
NS_PRECONDITION((aBottom > mTop) && (aBottom < mBottom), "bad argument");
|
1998-05-19 07:00:56 +04:00
|
|
|
|
|
|
|
// Create a new band rect for the bottom part
|
2007-08-30 19:29:06 +04:00
|
|
|
BandRect* bottomBandRect = new BandRect(mLeft, aBottom, mRight, mBottom, mFrames);
|
1998-05-19 07:00:56 +04:00
|
|
|
|
|
|
|
// This band rect becomes the top part, so adjust the bottom edge
|
1999-07-03 03:31:01 +04:00
|
|
|
mBottom = aBottom;
|
1998-05-19 07:00:56 +04:00
|
|
|
return bottomBandRect;
|
|
|
|
}
|
|
|
|
|
1999-01-04 07:54:33 +03:00
|
|
|
nsSpaceManager::BandRect*
|
|
|
|
nsSpaceManager::BandRect::SplitHorizontally(nscoord aRight)
|
1998-05-19 07:00:56 +04:00
|
|
|
{
|
1999-07-03 03:31:01 +04:00
|
|
|
NS_PRECONDITION((aRight > mLeft) && (aRight < mRight), "bad argument");
|
1998-05-19 07:00:56 +04:00
|
|
|
|
|
|
|
// Create a new band rect for the right part
|
2007-08-30 19:29:06 +04:00
|
|
|
BandRect* rightBandRect = new BandRect(aRight, mTop, mRight, mBottom, mFrames);
|
1998-05-19 07:00:56 +04:00
|
|
|
|
|
|
|
// This band rect becomes the left part, so adjust the right edge
|
1999-07-03 03:31:01 +04:00
|
|
|
mRight = aRight;
|
1998-05-19 07:00:56 +04:00
|
|
|
return rightBandRect;
|
|
|
|
}
|
|
|
|
|
1999-01-04 07:54:33 +03:00
|
|
|
PRBool
|
|
|
|
nsSpaceManager::BandRect::HasSameFrameList(const BandRect* aBandRect) const
|
1998-05-19 19:30:10 +04:00
|
|
|
{
|
2007-08-30 19:29:06 +04:00
|
|
|
const PRInt32 count = mFrames.Count();
|
1998-05-20 02:55:40 +04:00
|
|
|
|
1998-05-19 19:30:10 +04:00
|
|
|
// Check whether they're occupied by the same number of frames
|
2007-08-30 19:29:06 +04:00
|
|
|
if (count != aBandRect->mFrames.Count()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
// For each frame occupying this band rect check whether it also occupies
|
|
|
|
// aBandRect
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
if (-1 == aBandRect->mFrames.IndexOf(mFrames.FastElementAt(i))) {
|
|
|
|
return PR_FALSE;
|
1998-05-19 19:30:10 +04:00
|
|
|
}
|
|
|
|
}
|
1998-05-20 02:55:40 +04:00
|
|
|
|
2007-08-30 19:29:06 +04:00
|
|
|
return PR_TRUE;
|
1998-05-19 19:30:10 +04:00
|
|
|
}
|
1999-01-04 07:54:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal helper function that counts the number of rects in this band
|
|
|
|
* including the current band rect
|
|
|
|
*/
|
|
|
|
PRInt32
|
|
|
|
nsSpaceManager::BandRect::Length() const
|
|
|
|
{
|
|
|
|
PRInt32 len = 1;
|
|
|
|
BandRect* bandRect = Next();
|
|
|
|
|
|
|
|
// Because there's a header cell we know we'll either find the next band
|
|
|
|
// (which has a different y-offset) or the header cell which has an invalid
|
|
|
|
// y-offset
|
1999-07-03 03:31:01 +04:00
|
|
|
while (bandRect->mTop == mTop) {
|
1999-01-04 07:54:33 +03:00
|
|
|
len++;
|
|
|
|
bandRect = bandRect->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
2003-05-23 00:56:35 +04:00
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsAutoSpaceManager::~nsAutoSpaceManager()
|
|
|
|
{
|
|
|
|
// Restore the old space manager in the reflow state if necessary.
|
|
|
|
if (mNew) {
|
|
|
|
#ifdef NOISY_SPACEMANAGER
|
|
|
|
printf("restoring old space manager %p\n", mOld);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mReflowState.mSpaceManager = mOld;
|
|
|
|
|
|
|
|
#ifdef NOISY_SPACEMANAGER
|
|
|
|
if (mOld) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsFrame *>(mReflowState.frame)->ListTag(stdout);
|
2003-05-23 00:56:35 +04:00
|
|
|
printf(": space-manager %p after reflow\n", mOld);
|
|
|
|
mOld->List(stdout);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (mOwns)
|
|
|
|
#endif
|
|
|
|
delete mNew;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2008-10-14 22:59:29 +04:00
|
|
|
nsAutoSpaceManager::CreateSpaceManager(nsPresContext *aPresContext)
|
2003-05-23 00:56:35 +04:00
|
|
|
{
|
|
|
|
// Create a new space manager and install it in the reflow
|
|
|
|
// state. `Remember' the old space manager so we can restore it
|
|
|
|
// later.
|
2008-10-14 22:59:29 +04:00
|
|
|
mNew = new nsSpaceManager(aPresContext->PresShell());
|
2003-05-23 00:56:35 +04:00
|
|
|
if (! mNew)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
#ifdef NOISY_SPACEMANAGER
|
|
|
|
printf("constructed new space manager %p (replacing %p)\n",
|
|
|
|
mNew, mReflowState.mSpaceManager);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Set the space manager in the existing reflow state
|
|
|
|
mOld = mReflowState.mSpaceManager;
|
|
|
|
mReflowState.mSpaceManager = mNew;
|
|
|
|
return NS_OK;
|
|
|
|
}
|