diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 14faf6c1e2a..cbf8aba9652 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -39,7 +39,6 @@ #define PL_ARENA_CONST_ALIGN_MASK 3 #include "nsIPresShell.h" -#include "nsISpaceManager.h" #include "nsIPresContext.h" #include "nsIContent.h" #include "nsIDocument.h" @@ -6513,7 +6512,7 @@ CompareTrees(nsIPresContext* aFirstPresContext, nsIFrame* aFirstFrame, // or they both do and the space managers are equivalent nsCOMPtrfm1; nsCOMPtr ps1; - nsISpaceManager *sm1; // note, no ref counting here + nsSpaceManager *sm1; aFirstPresContext->GetShell(getter_AddRefs(ps1)); NS_ASSERTION(ps1, "no pres shell for primary tree!"); ps1->GetFrameManager(getter_AddRefs(fm1)); @@ -6523,7 +6522,7 @@ CompareTrees(nsIPresContext* aFirstPresContext, nsIFrame* aFirstFrame, // look at the test frame nsCOMPtrfm2; nsCOMPtr ps2; - nsISpaceManager *sm2; // note, no ref counting here + nsSpaceManager *sm2; aSecondPresContext->GetShell(getter_AddRefs(ps2)); NS_ASSERTION(ps2, "no pres shell for test tree!"); ps2->GetFrameManager(getter_AddRefs(fm2)); diff --git a/mozilla/layout/base/public/MANIFEST b/mozilla/layout/base/public/MANIFEST index a65045e1659..7831e25821c 100644 --- a/mozilla/layout/base/public/MANIFEST +++ b/mozilla/layout/base/public/MANIFEST @@ -6,17 +6,21 @@ nsFrameTraversal.h nsHTMLReflowMetrics.h nsHTMLReflowState.h nsIAutoCopy.h +nsICanvasFrame.h nsICaret.h nsIFocusTracker.h nsIFrame.h nsIFrameDebug.h nsIFrameManager.h nsIFrameSelection.h +nsIFrameTraversal.h nsIFrameUtil.h +nsIImageFrame.h nsIIndependentSelection.h nsILayoutDebugger.h nsILayoutHistoryState.h nsIMutableStyleContext.h +nsIObjectFrame.h nsIPageSequenceFrame.h nsIPresContext.h nsIPresShell.h @@ -26,15 +30,10 @@ nsIReflowCallback.h nsIReflowCommand.h nsIScrollableFrame.h nsIScrollableViewProvider.h -nsISpaceManager.h nsIStatefulFrame.h nsIStyleContext.h +nsIStyleFrameConstruction.h nsIStyleSet.h +nsITextFrame.h nsStyleChangeList.h nsStyleConsts.h -nsIStyleFrameConstruction.h -nsIFrameTraversal.h -nsIObjectFrame.h -nsIImageFrame.h -nsITextFrame.h -nsICanvasFrame.h diff --git a/mozilla/layout/base/public/Makefile.in b/mozilla/layout/base/public/Makefile.in index cb53472b595..408fba3d5b2 100644 --- a/mozilla/layout/base/public/Makefile.in +++ b/mozilla/layout/base/public/Makefile.in @@ -30,20 +30,26 @@ MODULE = layout XPIDL_MODULE = layout_base EXPORTS = \ +nsFrameList.h \ +nsFrameTraversal.h \ nsHTMLReflowMetrics.h \ nsHTMLReflowState.h \ nsIAutoCopy.h \ +nsICanvasFrame.h \ nsICaret.h \ nsIFocusTracker.h \ nsIFrame.h \ -nsIImageFrame.h \ -nsIObjectFrame.h \ -nsIFrameTraversal.h \ nsIFrameDebug.h \ nsIFrameManager.h \ +nsIFrameSelection.h \ +nsIFrameTraversal.h \ +nsIFrameUtil.h \ +nsIImageFrame.h \ nsIIndependentSelection.h \ nsILayoutDebugger.h \ -nsIFrameUtil.h \ +nsILayoutHistoryState.h \ +nsIMutableStyleContext.h \ +nsIObjectFrame.h \ nsIPageSequenceFrame.h \ nsIPresContext.h \ nsIPresShell.h \ @@ -51,21 +57,14 @@ nsIPresState.h \ nsIPrintContext.h \ nsIReflowCallback.h \ nsIReflowCommand.h \ -nsIFrameSelection.h \ -nsISpaceManager.h \ -nsIStyleContext.h \ -nsIMutableStyleContext.h \ -nsIStyleFrameConstruction.h \ -nsIStyleSet.h \ -nsFrameList.h \ -nsFrameTraversal.h \ -nsStyleChangeList.h \ -nsStyleConsts.h \ -nsILayoutHistoryState.h \ -nsIStatefulFrame.h \ nsIScrollableFrame.h \ nsIScrollableViewProvider.h \ -nsICanvasFrame.h \ +nsIStatefulFrame.h \ +nsIStyleContext.h \ +nsIStyleFrameConstruction.h \ +nsIStyleSet.h \ +nsStyleChangeList.h \ +nsStyleConsts.h \ $(NULL) ifdef IBMBIDI diff --git a/mozilla/layout/base/public/makefile.win b/mozilla/layout/base/public/makefile.win index a62c18e7a31..ea6990fb8ee 100644 --- a/mozilla/layout/base/public/makefile.win +++ b/mozilla/layout/base/public/makefile.win @@ -25,42 +25,41 @@ XPIDL_MODULE=layout_base include <$(DEPTH)\config\config.mak> EXPORTS = \ + nsFrameList.h \ + nsFrameTraversal.h \ nsHTMLReflowMetrics.h \ nsHTMLReflowState.h \ nsIAutoCopy.h \ + nsICanvasFrame.h \ nsICaret.h \ nsIFocusTracker.h \ nsIFrame.h \ - nsIObjectFrame.h \ - nsIImageFrame.h \ - nsIFrameTraversal.h \ nsIFrameDebug.h \ nsIFrameManager.h \ - nsIIndependentSelection.h \ - nsILayoutDebugger.h \ + nsIFrameSelection.h \ + nsIFrameTraversal.h \ nsIFrameUtil.h \ + nsIImageFrame.h \ + nsIIndependentSelection.h \ + nsILayoutDebugger.h \ + nsILayoutHistoryState.h \ + nsIMutableStyleContext.h \ + nsIObjectFrame.h \ nsIPageSequenceFrame.h \ nsIPresContext.h \ nsIPresShell.h \ - nsIPresState.h \ - nsIReflowCallback.h \ + nsIPresState.h \ + nsIPrintContext.h \ + nsIReflowCallback.h \ nsIReflowCommand.h \ - nsIFrameSelection.h \ - nsISpaceManager.h \ + nsIScrollableFrame.h \ + nsIScrollableViewProvider.h \ + nsIStatefulFrame.h \ nsIStyleContext.h \ - nsIMutableStyleContext.h \ nsIStyleFrameConstruction.h \ nsIStyleSet.h \ - nsFrameList.h \ - nsFrameTraversal.h \ nsStyleChangeList.h \ nsStyleConsts.h \ - nsILayoutHistoryState.h \ - nsIStatefulFrame.h \ - nsIScrollableFrame.h \ - nsIScrollableViewProvider.h \ - nsIPrintContext.h \ - nsICanvasFrame.h \ !ifdef IBMBIDI nsBidiPresUtils.h \ nsITextFrame.h \ diff --git a/mozilla/layout/base/public/nsHTMLReflowState.h b/mozilla/layout/base/public/nsHTMLReflowState.h index e165f897334..ede29e88aa8 100644 --- a/mozilla/layout/base/public/nsHTMLReflowState.h +++ b/mozilla/layout/base/public/nsHTMLReflowState.h @@ -44,7 +44,7 @@ class nsIFrame; class nsIPresContext; class nsIReflowCommand; class nsIRenderingContext; -class nsISpaceManager; +class nsSpaceManager; class nsLineLayout; struct nsStyleDisplay; @@ -161,7 +161,7 @@ struct nsHTMLReflowState { nsCSSFrameType mFrameType; // pointer to the space manager associated with this area - nsISpaceManager* mSpaceManager; + nsSpaceManager* mSpaceManager; // LineLayout object (only for inline reflow; set to NULL otherwise) nsLineLayout* mLineLayout; diff --git a/mozilla/layout/base/public/nsISpaceManager.h b/mozilla/layout/base/public/nsISpaceManager.h deleted file mode 100644 index 3898e3d6dc5..00000000000 --- a/mozilla/layout/base/public/nsISpaceManager.h +++ /dev/null @@ -1,283 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either 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"), - * 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 - * use your version of this file under the terms of the NPL, indicate your - * 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 - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsISpaceManager_h___ -#define nsISpaceManager_h___ - -#include "nsISupports.h" -#include "nsCoord.h" -#include "nsRect.h" - -class nsIFrame; -class nsVoidArray; -class nsISizeOfHandler; -struct nsSize; - -// IID for the nsISpaceManager interface {17C8FB50-BE96-11d1-80B5-00805F8A274D} -#define NS_ISPACEMANAGER_IID \ -{ 0x17c8fb50, 0xbe96, 0x11d1, \ - {0x80, 0xb5, 0x0, 0x80, 0x5f, 0x8a, 0x27, 0x4d}} - -/** - * Information about a particular trapezoid within a band. The space described - * by the trapezoid is in one of three states: - *
    - *
  • available - *
  • occupied by one frame - *
  • occupied by more than one frame - *
- */ -struct nsBandTrapezoid { - enum State {Available, Occupied, OccupiedMultiple}; - - nscoord mTopY, mBottomY; // top and bottom y-coordinates - nscoord mTopLeftX, mBottomLeftX; // left edge x-coordinates - nscoord mTopRightX, mBottomRightX; // right edge x-coordinates - State mState; // state of the space - union { - nsIFrame* mFrame; // single frame occupying the space - const nsVoidArray* mFrames; // list of frames occupying the space - }; - - // Get the height of the trapezoid - nscoord GetHeight() const {return mBottomY - mTopY;} - - // Get the bouding rect of the trapezoid - void GetRect(nsRect& aRect) const; - - // Set the trapezoid from a rectangle - void operator=(const nsRect& aRect); - - /** does a binary compare of this object with aTrap */ - PRBool Equals(const nsBandTrapezoid aTrap) const; - - /** does a semantic compare only of geometric data in this object and aTrap */ - PRBool EqualGeometry(const nsBandTrapezoid aTrap) const; - - nsBandTrapezoid() { - mTopY = mBottomY = mTopLeftX = mBottomLeftX = mTopRightX = mBottomRightX = 0; - mFrame = nsnull; - } -}; - -/** - * Structure used for describing the space within a band. - * @see #GetBandData() - */ -struct nsBandData { - PRInt32 mCount; // [out] actual number of trapezoids in the band data - PRInt32 mSize; // [in] the size of the array (number of trapezoids) - nsBandTrapezoid* mTrapezoids; // [out] array of length 'size' -}; - -/** - * Interface for dealing with bands of available space. The space manager defines a coordinate - * space with an origin at (0, 0) that grows down and to the right. - * - * @see nsIRunaround - */ -class nsISpaceManager : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_ISPACEMANAGER_IID; return iid; } - - /** - * Get the frame that's associated with the space manager. This frame created - * the space manager, and the world coordinate space is relative to this frame. - * - * You can use QueryInterface() on this frame to get any additional interfaces - */ - NS_IMETHOD GetFrame(nsIFrame*& aFrame) const = 0; - - /** - * Translate the current origin by the specified (dx, dy). This creates a new - * local coordinate space relative to the current coordinate space. - */ - NS_IMETHOD Translate(nscoord aDx, nscoord aDy) = 0; - - /** - * Returns the current translation from local coordinate space to world - * coordinate space. This represents the accumulated calls to Translate(). - */ - NS_IMETHOD GetTranslation(nscoord& aX, nscoord& aY) const = 0; - - /** - * Returns the y-most of the bottommost band or 0 if there are no bands. - * - * @return NS_OK if there are bands and NS_ERROR_ABORT if there are - * no bands - */ - NS_IMETHOD YMost(nscoord& aYMost) const = 0; - - /** - * Returns a band starting at the specified y-offset. The band data indicates - * which parts of the band are available, and which parts are unavailable - * - * The band data that is returned is in the coordinate space of the local - * coordinate system. - * - * The local coordinate space origin, the y-offset, and the max size describe - * a rectangle that's used to clip the underlying band of available space, i.e. - * {0, aYOffset, aMaxSize.width, aMaxSize.height} in the local coordinate space - * - * @param aYOffset the y-offset of where the band begins. The coordinate is - * relative to the upper-left corner of the local coordinate space - * @param aMaxSize the size to use to constrain the band data - * @param aBandData [in,out] used to return the list of trapezoids that - * describe the available space and the unavailable space - * @return NS_OK if successful and NS_ERROR_FAILURE if the band data is not - * not large enough. The 'count' member of the band data struct - * indicates how large the array of trapezoids needs to be - */ - NS_IMETHOD GetBandData(nscoord aYOffset, - const nsSize& aMaxSize, - nsBandData& aBandData) const = 0; - - /** - * Add a rectangular region of unavailable space. The space is relative to - * the local coordinate system. - * - * The region is tagged with a frame - * - * @param aFrame the frame used to identify the region. Must not be NULL - * @param aUnavailableSpace the bounding rect of the unavailable space - * @return NS_OK if successful - * NS_ERROR_FAILURE if there is already a region tagged with aFrame - */ - NS_IMETHOD AddRectRegion(nsIFrame* aFrame, - const nsRect& aUnavailableSpace) = 0; - - /** - * Resize the rectangular region associated with aFrame by the specified - * deltas. The height change always applies to the bottom edge or the existing - * rect. You specify whether the width change applies to the left or right edge - * - * Returns NS_OK if successful, NS_ERROR_INVALID_ARG if there is no region - * tagged with aFrame - */ - enum AffectedEdge {LeftEdge, RightEdge}; - NS_IMETHOD ResizeRectRegion(nsIFrame* aFrame, - nscoord aDeltaWidth, - nscoord aDeltaHeight, - AffectedEdge aEdge = RightEdge) = 0; - - /** - * Offset the region associated with aFrame by the specified amount. - * - * Returns NS_OK if successful, NS_ERROR_INVALID_ARG if there is no region - * tagged with aFrame - */ - NS_IMETHOD OffsetRegion(nsIFrame* aFrame, nscoord dx, nscoord dy) = 0; - - /** - * Remove the region associated with aFrane. - * - * Returns NS_OK if successful and NS_ERROR_INVALID_ARG if there is no region - * tagged with aFrame - */ - NS_IMETHOD RemoveRegion(nsIFrame* aFrame) = 0; - - /** - * Clears the list of regions representing the unavailable space. - */ - NS_IMETHOD ClearRegions() = 0; - - /** - * Methods for dealing with the propagation of float damage during - * reflow. - * - * (Yes, this is bad XPCOM style, but I want to remove the interface - * here -- see bug 102453. Once that's done, these (and many others) - * could be inline functions.) - */ - NS_IMETHOD_(PRBool) HasFloatDamage() = 0; - NS_IMETHOD_(void) IncludeInDamage(nscoord aIntervalBegin, - nscoord aIntervalEnd) = 0; - NS_IMETHOD_(PRBool) IntersectsDamage(nscoord aIntervalBegin, - nscoord aIntervalEnd) = 0; - -#ifdef DEBUG - /** - * Dump the state of the spacemanager out to a file - */ - NS_IMETHOD List(FILE* out) = 0; - - virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const = 0; -#endif -}; - -inline void nsBandTrapezoid::GetRect(nsRect& aRect) const -{ - aRect.x = PR_MIN(mTopLeftX, mBottomLeftX); - aRect.y = mTopY; - aRect.width = PR_MAX(mTopRightX, mBottomRightX) - aRect.x; - aRect.height = mBottomY - mTopY; -} - -inline void nsBandTrapezoid::operator=(const nsRect& aRect) -{ - mTopLeftX = mBottomLeftX = aRect.x; - mTopRightX = mBottomRightX = aRect.XMost(); - mTopY = aRect.y; - mBottomY = aRect.YMost(); -} - -inline PRBool nsBandTrapezoid::Equals(const nsBandTrapezoid aTrap) const -{ - return ( - mTopLeftX == aTrap.mTopLeftX && - mBottomLeftX == aTrap.mBottomLeftX && - mTopRightX == aTrap.mTopRightX && - mBottomRightX == aTrap.mBottomRightX && - mTopY == aTrap.mTopY && - mBottomY == aTrap.mBottomY && - mState == aTrap.mState && - mFrame == aTrap.mFrame - ); -} - -inline PRBool nsBandTrapezoid::EqualGeometry(const nsBandTrapezoid aTrap) const -{ - return ( - mTopLeftX == aTrap.mTopLeftX && - mBottomLeftX == aTrap.mBottomLeftX && - mTopRightX == aTrap.mTopRightX && - mBottomRightX == aTrap.mBottomRightX && - mTopY == aTrap.mTopY && - mBottomY == aTrap.mBottomY - ); -} - -#endif /* nsISpaceManager_h___ */ diff --git a/mozilla/layout/base/src/nsSpaceManager.cpp b/mozilla/layout/base/src/nsSpaceManager.cpp index 27d8333b8dd..5cc9d693550 100644 --- a/mozilla/layout/base/src/nsSpaceManager.cpp +++ b/mozilla/layout/base/src/nsSpaceManager.cpp @@ -44,6 +44,7 @@ #include "nsIFrame.h" #include "nsString.h" #include "nsIPresShell.h" +#include "nsMemory.h" #ifdef DEBUG #include "nsIFrameDebug.h" #endif @@ -52,8 +53,7 @@ // BandList PRInt32 nsSpaceManager::sCachedSpaceManagerCount = 0; -nsSpaceManager * - nsSpaceManager::sCachedSpaceManagers[NS_SPACE_MANAGER_CACHE_SIZE]; +void* nsSpaceManager::sCachedSpaceManagers[NS_SPACE_MANAGER_CACHE_SIZE]; #define NSCOORD_MIN (-2147483647 - 1) /* minimum signed value */ @@ -84,7 +84,8 @@ nsSpaceManager::BandList::Clear() ///////////////////////////////////////////////////////////////////////////// // PresShell Arena allocate callback (for nsIntervalSet use below) -static void* PR_CALLBACK PSArenaAllocCB(size_t aSize, void* aClosure) +PR_STATIC_CALLBACK(void*) +PSArenaAllocCB(size_t aSize, void* aClosure) { void *rv; NS_STATIC_CAST(nsIPresShell*, aClosure)->AllocateFrame(aSize, &rv); @@ -92,7 +93,8 @@ static void* PR_CALLBACK PSArenaAllocCB(size_t aSize, void* aClosure) } // PresShell Arena free callback (for nsIntervalSet use below) -static void PR_CALLBACK PSArenaFreeCB(size_t aSize, void* aPtr, void* aClosure) +PR_STATIC_CALLBACK(void) +PSArenaFreeCB(size_t aSize, void* aPtr, void* aClosure) { NS_STATIC_CAST(nsIPresShell*, aClosure)->FreeFrame(aSize, aPtr); } @@ -100,11 +102,13 @@ static void PR_CALLBACK PSArenaFreeCB(size_t aSize, void* aPtr, void* aClosure) ///////////////////////////////////////////////////////////////////////////// // nsSpaceManager +MOZ_DECL_CTOR_COUNTER(nsSpaceManager) + nsSpaceManager::nsSpaceManager(nsIPresShell* aPresShell, nsIFrame* aFrame) : mFrame(aFrame), mFloatDamage(PSArenaAllocCB, PSArenaFreeCB, aPresShell) { - NS_INIT_ISUPPORTS(); + MOZ_COUNT_CTOR(nsSpaceManager); mX = mY = 0; mFrameInfoMap = nsnull; } @@ -121,68 +125,30 @@ nsSpaceManager::ClearFrameInfo() nsSpaceManager::~nsSpaceManager() { + MOZ_COUNT_DTOR(nsSpaceManager); mBandList.Clear(); ClearFrameInfo(); } - -NS_INTERFACE_MAP_BEGIN(nsSpaceManager) - NS_INTERFACE_MAP_ENTRY(nsISpaceManager) - NS_INTERFACE_MAP_ENTRY(nsISupports) -NS_INTERFACE_MAP_END - -NS_IMPL_ADDREF(nsSpaceManager) -NS_IMPL_RELEASE_WITH_DESTROY(nsSpaceManager, LastRelease()) - - // static -nsSpaceManager *nsSpaceManager::Create(nsIPresShell* aPresShell, - nsIFrame* aFrame) +void* nsSpaceManager::operator new(size_t aSize) { if (sCachedSpaceManagerCount > 0) { // We have cached unused instances of this class, return a cached // instance in stead of always creating a new one. - nsSpaceManager *spaceManager = - sCachedSpaceManagers[--sCachedSpaceManagerCount]; - - // Re-initialize the cached space manager by calling its - // constructor (using placement new), the destructor was called - // when the space manager was put in the cache. - return new (spaceManager) nsSpaceManager(aPresShell, aFrame); + return sCachedSpaceManagers[--sCachedSpaceManagerCount]; } - // The cache is empty, this means we haveto create a new instance. - return new nsSpaceManager(aPresShell, aFrame); + // The cache is empty, this means we haveto create a new instance using + // the global |operator new|. + return nsMemory::Alloc(aSize); } - -// static -void nsSpaceManager::Shutdown() -{ - // The layout module is being shut down, clean up the cache and - // disable further caching. - - PRInt32 i; - - for (i = 0; i < sCachedSpaceManagerCount; i++) { - // The destructor for the cached space managers has already been - // called (when the space manager was put in the cache) so we cast - // spaceManager to char * when calling delete to prevent the - // destructor from being called again. - - nsSpaceManager *spaceManager = sCachedSpaceManagers[i]; - - delete (char *)spaceManager; - } - - // Disable futher caching. - sCachedSpaceManagerCount = -1; -} - - void -nsSpaceManager::LastRelease() +nsSpaceManager::operator delete(void* aPtr, size_t aSize) { + if (!aPtr) + return; // 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. @@ -192,58 +158,49 @@ nsSpaceManager::LastRelease() // There's still space in the cache for more instances, put this // instance in the cache in stead of deleting it. - sCachedSpaceManagers[sCachedSpaceManagerCount++] = this; - - // Call the destructor so that the proper cleanup happens - this->~nsSpaceManager(); - + sCachedSpaceManagers[sCachedSpaceManagerCount++] = aPtr; return; } // The cache is full, or the layout module has been shut down, // delete this space manager. - - delete this; + nsMemory::Free(aPtr); } -NS_IMETHODIMP -nsSpaceManager::GetFrame(nsIFrame*& aFrame) const +/* static */ +void nsSpaceManager::Shutdown() { - aFrame = mFrame; - return NS_OK; + // The layout module is being shut down, clean up the cache and + // disable further caching. + + PRInt32 i; + + for (i = 0; i < sCachedSpaceManagerCount; i++) { + void* spaceManager = sCachedSpaceManagers[i]; + if (spaceManager) + nsMemory::Free(spaceManager); + } + + // Disable futher caching. + sCachedSpaceManagerCount = -1; } -NS_IMETHODIMP -nsSpaceManager::Translate(nscoord aDx, nscoord aDy) -{ - mX += aDx; - mY += aDy; - return NS_OK; -} -NS_IMETHODIMP -nsSpaceManager::GetTranslation(nscoord& aX, nscoord& aY) const -{ - aX = mX; - aY = mY; - return NS_OK; -} - -NS_IMETHODIMP +PRBool nsSpaceManager::YMost(nscoord& aYMost) const { - nsresult result; + PRBool result; if (mBandList.IsEmpty()) { aYMost = 0; - result = NS_ERROR_ABORT; + result = PR_FALSE; } else { BandRect* lastRect = mBandList.Tail(); aYMost = lastRect->mBottom; - result = NS_OK; + result = PR_TRUE; } return result; @@ -368,7 +325,7 @@ nsSpaceManager::GetBandAvailableSpace(const BandRect* aBand, return NS_OK; } -NS_IMETHODIMP +nsresult nsSpaceManager::GetBandData(nscoord aYOffset, const nsSize& aMaxSize, nsBandData& aBandData) const @@ -383,7 +340,7 @@ nsSpaceManager::GetBandData(nscoord aYOffset, // band, then all the space is available nscoord yMost; - if ((NS_ERROR_ABORT == YMost(yMost)) || (y >= yMost)) { + if (!YMost(yMost) || (y >= yMost)) { // All the requested space is available aBandData.mCount = 1; aBandData.mTrapezoids[0] = nsRect(0, aYOffset, aMaxSize.width, aMaxSize.height); @@ -734,7 +691,7 @@ nsSpaceManager::InsertBandRect(BandRect* aBandRect) // If there are no existing bands or this rect is below the bottommost // band, then add a new band nscoord yMost; - if ((NS_ERROR_ABORT == YMost(yMost)) || (aBandRect->mTop >= yMost)) { + if (!YMost(yMost) || (aBandRect->mTop >= yMost)) { mBandList.Append(aBandRect); return; } @@ -823,7 +780,7 @@ nsSpaceManager::InsertBandRect(BandRect* aBandRect) } } -NS_IMETHODIMP +nsresult nsSpaceManager::AddRectRegion(nsIFrame* aFrame, const nsRect& aUnavailableSpace) { NS_PRECONDITION(nsnull != aFrame, "null frame"); @@ -863,7 +820,7 @@ nsSpaceManager::AddRectRegion(nsIFrame* aFrame, const nsRect& aUnavailableSpace) return NS_OK; } -NS_IMETHODIMP +nsresult nsSpaceManager::ResizeRectRegion(nsIFrame* aFrame, nscoord aDeltaWidth, nscoord aDeltaHeight, @@ -892,7 +849,7 @@ nsSpaceManager::ResizeRectRegion(nsIFrame* aFrame, return AddRectRegion(aFrame, rect); } -NS_IMETHODIMP +nsresult nsSpaceManager::OffsetRegion(nsIFrame* aFrame, nscoord aDx, nscoord aDy) { // Get the frame info associated with with aFrame @@ -915,7 +872,7 @@ nsSpaceManager::OffsetRegion(nsIFrame* aFrame, nscoord aDx, nscoord aDy) return AddRectRegion(aFrame, rect); } -NS_IMETHODIMP +nsresult nsSpaceManager::RemoveRegion(nsIFrame* aFrame) { // Get the frame info associated with aFrame @@ -1019,33 +976,15 @@ nsSpaceManager::RemoveRegion(nsIFrame* aFrame) return NS_OK; } -NS_IMETHODIMP +void nsSpaceManager::ClearRegions() { ClearFrameInfo(); mBandList.Clear(); - return NS_OK; -} - -NS_IMETHODIMP_(PRBool) nsSpaceManager::HasFloatDamage() -{ - return !mFloatDamage.IsEmpty(); -} - -NS_IMETHODIMP_(void) nsSpaceManager::IncludeInDamage(nscoord aIntervalBegin, - nscoord aIntervalEnd) -{ - mFloatDamage.IncludeInterval(aIntervalBegin + mY, aIntervalEnd + mY); -} - -NS_IMETHODIMP_(PRBool) nsSpaceManager::IntersectsDamage(nscoord aIntervalBegin, - nscoord aIntervalEnd) -{ - return mFloatDamage.Intersects(aIntervalBegin + mY, aIntervalEnd + mY); } #ifdef DEBUG -NS_IMETHODIMP +nsresult nsSpaceManager::List(FILE* out) { nsAutoString tmp; diff --git a/mozilla/layout/base/src/nsSpaceManager.h b/mozilla/layout/base/src/nsSpaceManager.h index 98870ac2719..1505628ad5b 100644 --- a/mozilla/layout/base/src/nsSpaceManager.h +++ b/mozilla/layout/base/src/nsSpaceManager.h @@ -1,4 +1,5 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +// vim:cindent:ts=2:et:sw=2: /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -37,63 +38,271 @@ #ifndef nsSpaceManager_h___ #define nsSpaceManager_h___ -#include "nsISpaceManager.h" #include "prclist.h" #include "nsIntervalSet.h" +#include "nsISupports.h" +#include "nsCoord.h" +#include "nsRect.h" class nsIPresShell; +class nsIFrame; +class nsVoidArray; +class nsISizeOfHandler; +struct nsSize; #define NS_SPACE_MANAGER_CACHE_SIZE 4 /** - * Implementation of nsISpaceManager that maintains a region data structure of - * unavailable space + * Information about a particular trapezoid within a band. The space described + * by the trapezoid is in one of three states: + *
    + *
  • available + *
  • occupied by one frame + *
  • occupied by more than one frame + *
*/ -class nsSpaceManager : public nsISpaceManager { +struct nsBandTrapezoid { + enum State {Available, Occupied, OccupiedMultiple}; + + nscoord mTopY, mBottomY; // top and bottom y-coordinates + nscoord mTopLeftX, mBottomLeftX; // left edge x-coordinates + nscoord mTopRightX, mBottomRightX; // right edge x-coordinates + State mState; // state of the space + union { + nsIFrame* mFrame; // single frame occupying the space + const nsVoidArray* mFrames; // list of frames occupying the space + }; + + // Get the height of the trapezoid + nscoord GetHeight() const {return mBottomY - mTopY;} + + // Get the bounding rect of the trapezoid + inline void GetRect(nsRect& aRect) const; + + // Set the trapezoid from a rectangle + inline void operator=(const nsRect& aRect); + + // Do these trapezoids have the same geometry, frame, and state? + inline PRBool Equals(const nsBandTrapezoid& aTrap) const; + + // Do these trapezoids have the same geometry? + inline PRBool EqualGeometry(const nsBandTrapezoid& aTrap) const; + + nsBandTrapezoid() + : mTopY(0), + mBottomY(0), + mTopLeftX(0), + mBottomLeftX(0), + mTopRightX(0), + mBottomRightX(0), + mFrame(nsnull) + { + } +}; + +inline void nsBandTrapezoid::GetRect(nsRect& aRect) const +{ + aRect.x = PR_MIN(mTopLeftX, mBottomLeftX); + aRect.y = mTopY; + aRect.width = PR_MAX(mTopRightX, mBottomRightX) - aRect.x; + aRect.height = mBottomY - mTopY; +} + +inline void nsBandTrapezoid::operator=(const nsRect& aRect) +{ + mTopLeftX = mBottomLeftX = aRect.x; + mTopRightX = mBottomRightX = aRect.XMost(); + mTopY = aRect.y; + mBottomY = aRect.YMost(); +} + +inline PRBool nsBandTrapezoid::Equals(const nsBandTrapezoid& aTrap) const +{ + return ( + mTopLeftX == aTrap.mTopLeftX && + mBottomLeftX == aTrap.mBottomLeftX && + mTopRightX == aTrap.mTopRightX && + mBottomRightX == aTrap.mBottomRightX && + mTopY == aTrap.mTopY && + mBottomY == aTrap.mBottomY && + mState == aTrap.mState && + mFrame == aTrap.mFrame + ); +} + +inline PRBool nsBandTrapezoid::EqualGeometry(const nsBandTrapezoid& aTrap) const +{ + return ( + mTopLeftX == aTrap.mTopLeftX && + mBottomLeftX == aTrap.mBottomLeftX && + mTopRightX == aTrap.mTopRightX && + mBottomRightX == aTrap.mBottomRightX && + mTopY == aTrap.mTopY && + mBottomY == aTrap.mBottomY + ); +} + +/** + * Structure used for describing the space within a band. + * @see #GetBandData() + */ +struct nsBandData { + PRInt32 mCount; // [out] actual number of trapezoids in the band data + PRInt32 mSize; // [in] the size of the array (number of trapezoids) + nsBandTrapezoid* mTrapezoids; // [out] array of length 'size' +}; + +/** + * Class for dealing with bands of available space. The space manager + * defines a coordinate space with an origin at (0, 0) that grows down + * and to the right. + */ +class nsSpaceManager { public: - static nsSpaceManager *Create(nsIPresShell* aPresShell, - nsIFrame* aFrame); + nsSpaceManager(nsIPresShell* aPresShell, nsIFrame* aFrame); + ~nsSpaceManager(); + + void* operator new(size_t aSize); + void operator delete(void* aPtr, size_t aSize); + static void Shutdown(); - // nsISupports - NS_DECL_ISUPPORTS + /* + * Get the frame that's associated with the space manager. This frame + * created the space manager, and the world coordinate space is + * relative to this frame. + * + * You can use QueryInterface() on this frame to get any additional + * interfaces. + */ + nsIFrame* GetFrame() const { return mFrame; } - // nsISpaceManager - NS_IMETHOD GetFrame(nsIFrame*& aFrame) const; + /** + * Translate the current origin by the specified (dx, dy). This + * creates a new local coordinate space relative to the current + * coordinate space. + */ + void Translate(nscoord aDx, nscoord aDy) { mX += aDx; mY += aDy; } - NS_IMETHOD Translate(nscoord aDx, nscoord aDy); - NS_IMETHOD GetTranslation(nscoord& aX, nscoord& aY) const; - NS_IMETHOD YMost(nscoord& aYMost) const; + /** + * Returns the current translation from local coordinate space to + * world coordinate space. This represents the accumulated calls to + * Translate(). + */ + void GetTranslation(nscoord& aX, nscoord& aY) const { aX = mX; aY = mY; } - NS_IMETHOD GetBandData(nscoord aYOffset, - const nsSize& aMaxSize, - nsBandData& aBandData) const; + /** + * Returns the y-most of the bottommost band or 0 if there are no bands. + * + * @return PR_TRUE if there are bands and PR_FALSE if there are no bands + */ + PRBool YMost(nscoord& aYMost) const; - NS_IMETHOD AddRectRegion(nsIFrame* aFrame, - const nsRect& aUnavailableSpace); - NS_IMETHOD ResizeRectRegion(nsIFrame* aFrame, - nscoord aDeltaWidth, - nscoord aDeltaHeight, - AffectedEdge aEdge); - NS_IMETHOD OffsetRegion(nsIFrame* aFrame, nscoord aDx, nscoord aDy); - NS_IMETHOD RemoveRegion(nsIFrame* aFrame); + /** + * Returns a band starting at the specified y-offset. The band data + * indicates which parts of the band are available, and which parts + * are unavailable + * + * The band data that is returned is in the coordinate space of the + * local coordinate system. + * + * The local coordinate space origin, the y-offset, and the max size + * describe a rectangle that's used to clip the underlying band of + * available space, i.e. + * {0, aYOffset, aMaxSize.width, aMaxSize.height} in the local + * coordinate space + * + * @param aYOffset the y-offset of where the band begins. The coordinate is + * relative to the upper-left corner of the local coordinate space + * @param aMaxSize the size to use to constrain the band data + * @param aBandData [in,out] used to return the list of trapezoids that + * describe the available space and the unavailable space + * @return NS_OK if successful and NS_ERROR_FAILURE if the band data is not + * not large enough. The 'count' member of the band data struct + * indicates how large the array of trapezoids needs to be + */ + nsresult GetBandData(nscoord aYOffset, + const nsSize& aMaxSize, + nsBandData& aBandData) const; - NS_IMETHOD ClearRegions(); + /** + * Add a rectangular region of unavailable space. The space is + * relative to the local coordinate system. + * + * The region is tagged with a frame + * + * @param aFrame the frame used to identify the region. Must not be NULL + * @param aUnavailableSpace the bounding rect of the unavailable space + * @return NS_OK if successful + * NS_ERROR_FAILURE if there is already a region tagged with aFrame + */ + nsresult AddRectRegion(nsIFrame* aFrame, + const nsRect& aUnavailableSpace); - NS_IMETHOD_(PRBool) HasFloatDamage(); - NS_IMETHOD_(void) IncludeInDamage(nscoord aIntervalBegin, - nscoord aIntervalEnd); - NS_IMETHOD_(PRBool) IntersectsDamage(nscoord aIntervalBegin, - nscoord aIntervalEnd); + /** + * Resize the rectangular region associated with aFrame by the specified + * deltas. The height change always applies to the bottom edge or the existing + * rect. You specify whether the width change applies to the left or right edge + * + * Returns NS_OK if successful, NS_ERROR_INVALID_ARG if there is no region + * tagged with aFrame + */ + enum AffectedEdge {LeftEdge, RightEdge}; + nsresult ResizeRectRegion(nsIFrame* aFrame, + nscoord aDeltaWidth, + nscoord aDeltaHeight, + AffectedEdge aEdge = RightEdge); + + /** + * Offset the region associated with aFrame by the specified amount. + * + * Returns NS_OK if successful, NS_ERROR_INVALID_ARG if there is no region + * tagged with aFrame + */ + nsresult OffsetRegion(nsIFrame* aFrame, nscoord dx, nscoord dy); + + /** + * Remove the region associated with aFrane. + * + * Returns NS_OK if successful and NS_ERROR_INVALID_ARG if there is no region + * tagged with aFrame + */ + nsresult RemoveRegion(nsIFrame* aFrame); + + /** + * Clears the list of regions representing the unavailable space. + */ + void ClearRegions(); + + /** + * Methods for dealing with the propagation of float damage during + * reflow. + */ + PRBool HasFloatDamage() + { + return !mFloatDamage.IsEmpty(); + } + + void IncludeInDamage(nscoord aIntervalBegin, nscoord aIntervalEnd) + { + mFloatDamage.IncludeInterval(aIntervalBegin + mY, aIntervalEnd + mY); + } + + PRBool IntersectsDamage(nscoord aIntervalBegin, nscoord aIntervalEnd) + { + return mFloatDamage.Intersects(aIntervalBegin + mY, aIntervalEnd + mY); + } #ifdef DEBUG - NS_IMETHOD List(FILE* out); - void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; + /** + * Dump the state of the spacemanager out to a file + */ + nsresult List(FILE* out); + + void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; #endif protected: - nsSpaceManager(nsIPresShell* aPresShell, nsIFrame* aFrame); - // Structure that maintains information about the region associated // with a particular frame struct FrameInfo { @@ -179,7 +388,6 @@ protected: nsIntervalSet mFloatDamage; protected: - virtual ~nsSpaceManager(); FrameInfo* GetFrameInfoFor(nsIFrame* aFrame); FrameInfo* CreateFrameInfo(nsIFrame* aFrame, const nsRect& aRect); void DestroyFrameInfo(FrameInfo*); @@ -201,9 +409,7 @@ protected: private: static PRInt32 sCachedSpaceManagerCount; - static nsSpaceManager *sCachedSpaceManagers[NS_SPACE_MANAGER_CACHE_SIZE]; - - void LastRelease(); + static void* sCachedSpaceManagers[NS_SPACE_MANAGER_CACHE_SIZE]; nsSpaceManager(const nsSpaceManager&); // no implementation void operator=(const nsSpaceManager&); // no implementation diff --git a/mozilla/layout/base/tests/TestSpaceManager.cpp b/mozilla/layout/base/tests/TestSpaceManager.cpp index 559f745b37e..fb086916428 100644 --- a/mozilla/layout/base/tests/TestSpaceManager.cpp +++ b/mozilla/layout/base/tests/TestSpaceManager.cpp @@ -703,7 +703,7 @@ PRBool MySpaceManager::TestResizeRectRegion() // #1. A simple test of resizing the right edge of the one and only band rect status = AddRectRegion((nsIFrame*)0x01, nsRect(10, 100, 100, 100)); NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status"); - status = ResizeRectRegion((nsIFrame*)0x01, 50, 50, nsISpaceManager::RightEdge); + status = ResizeRectRegion((nsIFrame*)0x01, 50, 50, nsSpaceManager::RightEdge); NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status"); // Verify there is one band with one rect @@ -804,23 +804,21 @@ int main(int argc, char** argv) // Create a space manager MySpaceManager* spaceMgr = new MySpaceManager(nsnull, nsnull); - NS_ADDREF(spaceMgr); - // Test adding rect regions if (!spaceMgr->TestAddBand()) { - NS_RELEASE(spaceMgr); + delete spaceMgr; return -1; } // Test adding rect regions that overlap existing bands if (!spaceMgr->TestAddBandOverlap()) { - NS_RELEASE(spaceMgr); + delete spaceMgr; return -1; } // Test adding rects within an existing band if (!spaceMgr->TestAddRectToBand()) { - NS_RELEASE(spaceMgr); + delete spaceMgr; return -1; } @@ -844,6 +842,6 @@ int main(int argc, char** argv) return -1; } - NS_RELEASE(spaceMgr); + delete spaceMgr; return 0; } diff --git a/mozilla/layout/generic/nsBlockBandData.cpp b/mozilla/layout/generic/nsBlockBandData.cpp index b5a17e27686..5e8f237f639 100644 --- a/mozilla/layout/generic/nsBlockBandData.cpp +++ b/mozilla/layout/generic/nsBlockBandData.cpp @@ -57,24 +57,18 @@ nsBlockBandData::nsBlockBandData() nsBlockBandData::~nsBlockBandData() { - NS_IF_RELEASE(mSpaceManager); if (mTrapezoids != mData) { delete [] mTrapezoids; } } nsresult -nsBlockBandData::Init(nsISpaceManager* aSpaceManager, +nsBlockBandData::Init(nsSpaceManager* aSpaceManager, const nsSize& aSpace) { - NS_PRECONDITION(nsnull != aSpaceManager, "null pointer"); - if (nsnull == aSpaceManager) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aSpaceManager, "null pointer"); - NS_IF_RELEASE(mSpaceManager); mSpaceManager = aSpaceManager; - NS_ADDREF(aSpaceManager); aSpaceManager->GetTranslation(mSpaceManagerX, mSpaceManagerY); mSpace = aSpace; @@ -115,9 +109,6 @@ nsresult nsBlockBandData::GetBandData(nscoord aY) { NS_ASSERTION(mSpaceManager, "bad state, no space manager"); - if (!mSpaceManager) { - return NS_ERROR_FAILURE; - } PRInt32 iterations =0; nsresult rv = mSpaceManager->GetBandData(aY, mSpace, *this); while (NS_FAILED(rv)) { diff --git a/mozilla/layout/generic/nsBlockBandData.h b/mozilla/layout/generic/nsBlockBandData.h index c52a34f737a..b8af0c32055 100644 --- a/mozilla/layout/generic/nsBlockBandData.h +++ b/mozilla/layout/generic/nsBlockBandData.h @@ -37,7 +37,7 @@ #ifndef nsBlockBandData_h___ #define nsBlockBandData_h___ -#include "nsISpaceManager.h" +#include "nsSpaceManager.h" class nsIPresContext; @@ -54,7 +54,7 @@ public: ~nsBlockBandData(); // Initialize. This must be called before any of the other methods. - nsresult Init(nsISpaceManager* aSpaceManager, const nsSize& aSpace); + nsresult Init(nsSpaceManager* aSpaceManager, const nsSize& aSpace); // Get some available space. Note that aY is relative to the current // space manager translation. @@ -119,7 +119,7 @@ protected: nsresult GetBandData(nscoord aY); // The spacemanager we are getting space from - nsISpaceManager* mSpaceManager; + nsSpaceManager* mSpaceManager; nscoord mSpaceManagerX, mSpaceManagerY; // Limit to the available space (set by Init) diff --git a/mozilla/layout/generic/nsBlockFrame.cpp b/mozilla/layout/generic/nsBlockFrame.cpp index f2eb958e39c..e7ef70cc1c3 100644 --- a/mozilla/layout/generic/nsBlockFrame.cpp +++ b/mozilla/layout/generic/nsBlockFrame.cpp @@ -55,7 +55,6 @@ #include "nsIPresContext.h" #include "nsIPresShell.h" #include "nsIReflowCommand.h" -#include "nsISpaceManager.h" #include "nsIStyleContext.h" #include "nsIView.h" #include "nsIFontMetrics.h" @@ -688,28 +687,28 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, } // Should we create a space manager? - nsCOMPtr spaceManager; - nsISpaceManager* oldSpaceManager = aReflowState.mSpaceManager; + nsSpaceManager* spaceManager; + nsSpaceManager* oldSpaceManager; // XXXldb If we start storing the space manager in the frame rather // than keeping it around only during reflow then we should create it // only when there are actually floats to manage. Otherwise things // like tables will gain significant bloat. if (NS_BLOCK_SPACE_MGR & mState) { + oldSpaceManager = aReflowState.mSpaceManager; + nsCOMPtr shell; aPresContext->GetShell(getter_AddRefs(shell)); - nsSpaceManager* rawPtr = nsSpaceManager::Create(shell, this); - if (!rawPtr) { + spaceManager = new nsSpaceManager(shell, this); + if (!spaceManager) return NS_ERROR_OUT_OF_MEMORY; - } - - spaceManager = do_QueryInterface(rawPtr); // Set the space manager in the existing reflow state nsHTMLReflowState& reflowState = NS_CONST_CAST(nsHTMLReflowState&, aReflowState); - reflowState.mSpaceManager = spaceManager.get(); + reflowState.mSpaceManager = spaceManager; #ifdef NOISY_SPACEMANAGER - printf("constructed new space manager %p (replacing %p)\n", reflowState.mSpaceManager, oldSpaceManager); + printf("constructed new space manager %p (replacing %p)\n", + reflowState.mSpaceManager, oldSpaceManager); #endif } @@ -851,6 +850,7 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, // see if verifyReflow is enabled, and if so store off the space manager pointer #ifdef DEBUG PRInt32 verifyReflowFlags = nsIPresShell::GetVerifyReflowFlags(); + PRBool transferredSpaceManager = PR_FALSE; if (VERIFY_REFLOW_INCLUDE_SPACE_MANAGER & verifyReflowFlags) { // this is a leak of the space manager, but it's only in debug if verify reflow is enabled, so not a big deal @@ -861,9 +861,11 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, shell->GetFrameManager(getter_AddRefs(frameManager)); if (frameManager) { nsHTMLReflowState& reflowState = (nsHTMLReflowState&)aReflowState; - NS_ADDREF(reflowState.mSpaceManager); - rv = frameManager->SetFrameProperty(this, nsLayoutAtoms::spaceManagerProperty, - reflowState.mSpaceManager, nsnull /* should be nsSpaceManagerDestroyer*/); + rv = frameManager->SetFrameProperty( + this, nsLayoutAtoms::spaceManagerProperty, + reflowState.mSpaceManager, + nsnull /* should be nsSpaceManagerDestroyer*/); + transferredSpaceManager = PR_TRUE; } } } @@ -877,10 +879,14 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, printf("restoring old space manager %p\n", oldSpaceManager); #endif reflowState.mSpaceManager = oldSpaceManager; +#ifdef DEBUG + // For debugging, we sometimes transfer ownership to the frame manager + // (above). + if (!transferredSpaceManager) +#endif + delete spaceManager; } - NS_ASSERTION(aReflowState.mSpaceManager == oldSpaceManager, "lost a space manager"); - #ifdef NOISY_SPACEMANAGER nsHTMLReflowState& reflowState = NS_CONST_CAST(nsHTMLReflowState&, aReflowState); if (reflowState.mSpaceManager) { @@ -1882,7 +1888,7 @@ nsBlockFrame::RememberFloaterDamage(nsBlockReflowState& aState, nscoord oldYMost = aOldCombinedArea.YMost(); nscoord impactYB = newYMost < oldYMost ? oldYMost : newYMost; nscoord impactYA = lineCombinedArea.y; - nsISpaceManager *spaceManager = aState.mReflowState.mSpaceManager; + nsSpaceManager *spaceManager = aState.mReflowState.mSpaceManager; spaceManager->IncludeInDamage(impactYA, impactYB); } } @@ -1907,7 +1913,7 @@ nsBlockFrame::PropagateFloaterDamage(nsBlockReflowState& aState, NS_PRECONDITION(!aLine->IsDirty(), "should never be called on dirty lines"); // Check the damage region recorded in the float damage. - nsISpaceManager *spaceManager = aState.mReflowState.mSpaceManager; + nsSpaceManager *spaceManager = aState.mReflowState.mSpaceManager; if (spaceManager->HasFloatDamage()) { nscoord lineYA = aLine->mBounds.y + aDeltaY; nscoord lineYB = lineYA + aLine->mBounds.height; @@ -2730,7 +2736,7 @@ nsBlockFrame::SlideLine(nsBlockReflowState& aState, nsresult nsBlockFrame::UpdateSpaceManager(nsIPresContext* aPresContext, - nsISpaceManager* aSpaceManager) + nsSpaceManager* aSpaceManager) { for (line_iterator line = begin_lines(), line_end = end_lines(); line != line_end; @@ -5309,7 +5315,7 @@ nsBlockFrame::Paint(nsIPresContext* aPresContext, #if 0 if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) { // Render the bands in the spacemanager - nsISpaceManager* sm = mSpaceManager; + nsSpaceManager* sm = mSpaceManager; if (nsnull != sm) { nsBlockBandData band; diff --git a/mozilla/layout/generic/nsBlockFrame.h b/mozilla/layout/generic/nsBlockFrame.h index efc8f52558b..8ce3c5e2fe9 100644 --- a/mozilla/layout/generic/nsBlockFrame.h +++ b/mozilla/layout/generic/nsBlockFrame.h @@ -192,7 +192,7 @@ public: * recursively adds floaters in child blocks of this frame. */ nsresult UpdateSpaceManager(nsIPresContext* aPresContext, - nsISpaceManager* aSpaceManager); + nsSpaceManager* aSpaceManager); // returns true on success and false if aFoundLine is set to end_lines() PRBool FindLineFor(nsIFrame* aFrame, diff --git a/mozilla/layout/generic/nsBlockReflowContext.cpp b/mozilla/layout/generic/nsBlockReflowContext.cpp index c03a10c1f2f..f79088f4391 100644 --- a/mozilla/layout/generic/nsBlockReflowContext.cpp +++ b/mozilla/layout/generic/nsBlockReflowContext.cpp @@ -39,7 +39,7 @@ #include "nsBlockReflowContext.h" #include "nsLineLayout.h" #include "nsHTMLIIDs.h" -#include "nsISpaceManager.h" +#include "nsSpaceManager.h" #include "nsIFontMetrics.h" #include "nsIPresContext.h" #include "nsIContent.h" diff --git a/mozilla/layout/generic/nsBlockReflowState.cpp b/mozilla/layout/generic/nsBlockReflowState.cpp index a41e46a14fb..b19b83c35a9 100644 --- a/mozilla/layout/generic/nsBlockReflowState.cpp +++ b/mozilla/layout/generic/nsBlockReflowState.cpp @@ -83,8 +83,9 @@ nsBlockReflowState::nsBlockReflowState(const nsHTMLReflowState& aReflowState, mSpaceManager = aReflowState.mSpaceManager; - NS_ASSERTION( nsnull != mSpaceManager, "SpaceManager should be set in nsBlockReflowState" ); - if( nsnull != mSpaceManager ) { + NS_ASSERTION(mSpaceManager, + "SpaceManager should be set in nsBlockReflowState" ); + if (mSpaceManager) { // Translate into our content area and then save the // coordinate system origin for later. mSpaceManager->Translate(borderPadding.left, borderPadding.top); diff --git a/mozilla/layout/generic/nsBlockReflowState.h b/mozilla/layout/generic/nsBlockReflowState.h index 718867ac895..ef559e496d4 100644 --- a/mozilla/layout/generic/nsBlockReflowState.h +++ b/mozilla/layout/generic/nsBlockReflowState.h @@ -138,7 +138,7 @@ public: const nsHTMLReflowState& mReflowState; - nsISpaceManager* mSpaceManager; + nsSpaceManager* mSpaceManager; // The coordinates within the spacemanager where the block is being // placed after taking into account the blocks border and diff --git a/mozilla/layout/generic/nsContainerFrame.cpp b/mozilla/layout/generic/nsContainerFrame.cpp index 611acd94504..8b39bee6398 100644 --- a/mozilla/layout/generic/nsContainerFrame.cpp +++ b/mozilla/layout/generic/nsContainerFrame.cpp @@ -39,7 +39,6 @@ #include "nsIContent.h" #include "nsIPresContext.h" #include "nsIRenderingContext.h" -#include "nsISpaceManager.h" #include "nsIStyleContext.h" #include "nsRect.h" #include "nsPoint.h" diff --git a/mozilla/layout/generic/nsHTMLReflowState.h b/mozilla/layout/generic/nsHTMLReflowState.h index e165f897334..ede29e88aa8 100644 --- a/mozilla/layout/generic/nsHTMLReflowState.h +++ b/mozilla/layout/generic/nsHTMLReflowState.h @@ -44,7 +44,7 @@ class nsIFrame; class nsIPresContext; class nsIReflowCommand; class nsIRenderingContext; -class nsISpaceManager; +class nsSpaceManager; class nsLineLayout; struct nsStyleDisplay; @@ -161,7 +161,7 @@ struct nsHTMLReflowState { nsCSSFrameType mFrameType; // pointer to the space manager associated with this area - nsISpaceManager* mSpaceManager; + nsSpaceManager* mSpaceManager; // LineLayout object (only for inline reflow; set to NULL otherwise) nsLineLayout* mLineLayout; diff --git a/mozilla/layout/generic/nsLineBox.cpp b/mozilla/layout/generic/nsLineBox.cpp index 091cdbb31a9..84bc458028a 100644 --- a/mozilla/layout/generic/nsLineBox.cpp +++ b/mozilla/layout/generic/nsLineBox.cpp @@ -38,7 +38,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsLineBox.h" -#include "nsISpaceManager.h" +#include "nsSpaceManager.h" #include "nsIStyleContext.h" #include "nsLineLayout.h" #include "prprf.h" @@ -407,7 +407,7 @@ nsLineBox::FreeFloaters(nsFloaterCacheFreeList& aFreeList) } void -nsLineBox::RemoveFloatersFromSpaceManager(nsISpaceManager* aSpaceManager) +nsLineBox::RemoveFloatersFromSpaceManager(nsSpaceManager* aSpaceManager) { if (IsInline()) { if (mInlineData) { diff --git a/mozilla/layout/generic/nsLineBox.h b/mozilla/layout/generic/nsLineBox.h index c1fbe7da82f..be8ef9c17f4 100644 --- a/mozilla/layout/generic/nsLineBox.h +++ b/mozilla/layout/generic/nsLineBox.h @@ -44,7 +44,7 @@ #include "nsILineIterator.h" #include "nsISizeOfHandler.h" -class nsISpaceManager; +class nsSpaceManager; class nsLineBox; class nsFloaterCache; class nsFloaterCacheList; @@ -333,7 +333,7 @@ public: void FreeFloaters(nsFloaterCacheFreeList& aFreeList); void AppendFloaters(nsFloaterCacheFreeList& aFreeList); PRBool RemoveFloater(nsIFrame* aFrame); - void RemoveFloatersFromSpaceManager(nsISpaceManager* aSpaceManager); + void RemoveFloatersFromSpaceManager(nsSpaceManager* aSpaceManager); // Combined area void SetCombinedArea(const nsRect& aCombinedArea); diff --git a/mozilla/layout/generic/nsLineLayout.cpp b/mozilla/layout/generic/nsLineLayout.cpp index 7ffad424fc1..e0957ee4a03 100644 --- a/mozilla/layout/generic/nsLineLayout.cpp +++ b/mozilla/layout/generic/nsLineLayout.cpp @@ -45,7 +45,7 @@ #include "nsStyleConsts.h" #include "nsHTMLContainerFrame.h" #include "nsHTMLIIDs.h" -#include "nsISpaceManager.h" +#include "nsSpaceManager.h" #include "nsIStyleContext.h" #include "nsIPresContext.h" #include "nsIFontMetrics.h" @@ -155,7 +155,7 @@ static PRBool InUnconstrainedTableCell(const nsHTMLReflowState& aBlockReflowStat MOZ_DECL_CTOR_COUNTER(nsLineLayout) nsLineLayout::nsLineLayout(nsIPresContext* aPresContext, - nsISpaceManager* aSpaceManager, + nsSpaceManager* aSpaceManager, const nsHTMLReflowState* aOuterReflowState, PRBool aComputeMaxElementSize) : mPresContext(aPresContext), diff --git a/mozilla/layout/generic/nsLineLayout.h b/mozilla/layout/generic/nsLineLayout.h index bb4d4935099..deb45a08090 100644 --- a/mozilla/layout/generic/nsLineLayout.h +++ b/mozilla/layout/generic/nsLineLayout.h @@ -36,7 +36,7 @@ #include "nsLineBox.h" #include "nsBlockReflowState.h" -class nsISpaceManager; +class nsSpaceManager; class nsPlaceholderFrame; struct nsStyleText; @@ -46,7 +46,7 @@ struct nsStyleText; class nsLineLayout { public: nsLineLayout(nsIPresContext* aPresContext, - nsISpaceManager* aSpaceManager, + nsSpaceManager* aSpaceManager, const nsHTMLReflowState* aOuterReflowState, PRBool aComputeMaxElementSize); nsLineLayout(nsIPresContext* aPresContext); @@ -265,7 +265,7 @@ public: protected: // This state is constant for a given block frame doing line layout - nsISpaceManager* mSpaceManager; + nsSpaceManager* mSpaceManager; const nsStyleText* mStyleText; // for the block const nsHTMLReflowState* mBlockReflowState; nsBlockReflowState* mBlockRS;/* XXX hack! */ diff --git a/mozilla/layout/generic/nsSpaceManager.cpp b/mozilla/layout/generic/nsSpaceManager.cpp index 27d8333b8dd..5cc9d693550 100644 --- a/mozilla/layout/generic/nsSpaceManager.cpp +++ b/mozilla/layout/generic/nsSpaceManager.cpp @@ -44,6 +44,7 @@ #include "nsIFrame.h" #include "nsString.h" #include "nsIPresShell.h" +#include "nsMemory.h" #ifdef DEBUG #include "nsIFrameDebug.h" #endif @@ -52,8 +53,7 @@ // BandList PRInt32 nsSpaceManager::sCachedSpaceManagerCount = 0; -nsSpaceManager * - nsSpaceManager::sCachedSpaceManagers[NS_SPACE_MANAGER_CACHE_SIZE]; +void* nsSpaceManager::sCachedSpaceManagers[NS_SPACE_MANAGER_CACHE_SIZE]; #define NSCOORD_MIN (-2147483647 - 1) /* minimum signed value */ @@ -84,7 +84,8 @@ nsSpaceManager::BandList::Clear() ///////////////////////////////////////////////////////////////////////////// // PresShell Arena allocate callback (for nsIntervalSet use below) -static void* PR_CALLBACK PSArenaAllocCB(size_t aSize, void* aClosure) +PR_STATIC_CALLBACK(void*) +PSArenaAllocCB(size_t aSize, void* aClosure) { void *rv; NS_STATIC_CAST(nsIPresShell*, aClosure)->AllocateFrame(aSize, &rv); @@ -92,7 +93,8 @@ static void* PR_CALLBACK PSArenaAllocCB(size_t aSize, void* aClosure) } // PresShell Arena free callback (for nsIntervalSet use below) -static void PR_CALLBACK PSArenaFreeCB(size_t aSize, void* aPtr, void* aClosure) +PR_STATIC_CALLBACK(void) +PSArenaFreeCB(size_t aSize, void* aPtr, void* aClosure) { NS_STATIC_CAST(nsIPresShell*, aClosure)->FreeFrame(aSize, aPtr); } @@ -100,11 +102,13 @@ static void PR_CALLBACK PSArenaFreeCB(size_t aSize, void* aPtr, void* aClosure) ///////////////////////////////////////////////////////////////////////////// // nsSpaceManager +MOZ_DECL_CTOR_COUNTER(nsSpaceManager) + nsSpaceManager::nsSpaceManager(nsIPresShell* aPresShell, nsIFrame* aFrame) : mFrame(aFrame), mFloatDamage(PSArenaAllocCB, PSArenaFreeCB, aPresShell) { - NS_INIT_ISUPPORTS(); + MOZ_COUNT_CTOR(nsSpaceManager); mX = mY = 0; mFrameInfoMap = nsnull; } @@ -121,68 +125,30 @@ nsSpaceManager::ClearFrameInfo() nsSpaceManager::~nsSpaceManager() { + MOZ_COUNT_DTOR(nsSpaceManager); mBandList.Clear(); ClearFrameInfo(); } - -NS_INTERFACE_MAP_BEGIN(nsSpaceManager) - NS_INTERFACE_MAP_ENTRY(nsISpaceManager) - NS_INTERFACE_MAP_ENTRY(nsISupports) -NS_INTERFACE_MAP_END - -NS_IMPL_ADDREF(nsSpaceManager) -NS_IMPL_RELEASE_WITH_DESTROY(nsSpaceManager, LastRelease()) - - // static -nsSpaceManager *nsSpaceManager::Create(nsIPresShell* aPresShell, - nsIFrame* aFrame) +void* nsSpaceManager::operator new(size_t aSize) { if (sCachedSpaceManagerCount > 0) { // We have cached unused instances of this class, return a cached // instance in stead of always creating a new one. - nsSpaceManager *spaceManager = - sCachedSpaceManagers[--sCachedSpaceManagerCount]; - - // Re-initialize the cached space manager by calling its - // constructor (using placement new), the destructor was called - // when the space manager was put in the cache. - return new (spaceManager) nsSpaceManager(aPresShell, aFrame); + return sCachedSpaceManagers[--sCachedSpaceManagerCount]; } - // The cache is empty, this means we haveto create a new instance. - return new nsSpaceManager(aPresShell, aFrame); + // The cache is empty, this means we haveto create a new instance using + // the global |operator new|. + return nsMemory::Alloc(aSize); } - -// static -void nsSpaceManager::Shutdown() -{ - // The layout module is being shut down, clean up the cache and - // disable further caching. - - PRInt32 i; - - for (i = 0; i < sCachedSpaceManagerCount; i++) { - // The destructor for the cached space managers has already been - // called (when the space manager was put in the cache) so we cast - // spaceManager to char * when calling delete to prevent the - // destructor from being called again. - - nsSpaceManager *spaceManager = sCachedSpaceManagers[i]; - - delete (char *)spaceManager; - } - - // Disable futher caching. - sCachedSpaceManagerCount = -1; -} - - void -nsSpaceManager::LastRelease() +nsSpaceManager::operator delete(void* aPtr, size_t aSize) { + if (!aPtr) + return; // 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. @@ -192,58 +158,49 @@ nsSpaceManager::LastRelease() // There's still space in the cache for more instances, put this // instance in the cache in stead of deleting it. - sCachedSpaceManagers[sCachedSpaceManagerCount++] = this; - - // Call the destructor so that the proper cleanup happens - this->~nsSpaceManager(); - + sCachedSpaceManagers[sCachedSpaceManagerCount++] = aPtr; return; } // The cache is full, or the layout module has been shut down, // delete this space manager. - - delete this; + nsMemory::Free(aPtr); } -NS_IMETHODIMP -nsSpaceManager::GetFrame(nsIFrame*& aFrame) const +/* static */ +void nsSpaceManager::Shutdown() { - aFrame = mFrame; - return NS_OK; + // The layout module is being shut down, clean up the cache and + // disable further caching. + + PRInt32 i; + + for (i = 0; i < sCachedSpaceManagerCount; i++) { + void* spaceManager = sCachedSpaceManagers[i]; + if (spaceManager) + nsMemory::Free(spaceManager); + } + + // Disable futher caching. + sCachedSpaceManagerCount = -1; } -NS_IMETHODIMP -nsSpaceManager::Translate(nscoord aDx, nscoord aDy) -{ - mX += aDx; - mY += aDy; - return NS_OK; -} -NS_IMETHODIMP -nsSpaceManager::GetTranslation(nscoord& aX, nscoord& aY) const -{ - aX = mX; - aY = mY; - return NS_OK; -} - -NS_IMETHODIMP +PRBool nsSpaceManager::YMost(nscoord& aYMost) const { - nsresult result; + PRBool result; if (mBandList.IsEmpty()) { aYMost = 0; - result = NS_ERROR_ABORT; + result = PR_FALSE; } else { BandRect* lastRect = mBandList.Tail(); aYMost = lastRect->mBottom; - result = NS_OK; + result = PR_TRUE; } return result; @@ -368,7 +325,7 @@ nsSpaceManager::GetBandAvailableSpace(const BandRect* aBand, return NS_OK; } -NS_IMETHODIMP +nsresult nsSpaceManager::GetBandData(nscoord aYOffset, const nsSize& aMaxSize, nsBandData& aBandData) const @@ -383,7 +340,7 @@ nsSpaceManager::GetBandData(nscoord aYOffset, // band, then all the space is available nscoord yMost; - if ((NS_ERROR_ABORT == YMost(yMost)) || (y >= yMost)) { + if (!YMost(yMost) || (y >= yMost)) { // All the requested space is available aBandData.mCount = 1; aBandData.mTrapezoids[0] = nsRect(0, aYOffset, aMaxSize.width, aMaxSize.height); @@ -734,7 +691,7 @@ nsSpaceManager::InsertBandRect(BandRect* aBandRect) // If there are no existing bands or this rect is below the bottommost // band, then add a new band nscoord yMost; - if ((NS_ERROR_ABORT == YMost(yMost)) || (aBandRect->mTop >= yMost)) { + if (!YMost(yMost) || (aBandRect->mTop >= yMost)) { mBandList.Append(aBandRect); return; } @@ -823,7 +780,7 @@ nsSpaceManager::InsertBandRect(BandRect* aBandRect) } } -NS_IMETHODIMP +nsresult nsSpaceManager::AddRectRegion(nsIFrame* aFrame, const nsRect& aUnavailableSpace) { NS_PRECONDITION(nsnull != aFrame, "null frame"); @@ -863,7 +820,7 @@ nsSpaceManager::AddRectRegion(nsIFrame* aFrame, const nsRect& aUnavailableSpace) return NS_OK; } -NS_IMETHODIMP +nsresult nsSpaceManager::ResizeRectRegion(nsIFrame* aFrame, nscoord aDeltaWidth, nscoord aDeltaHeight, @@ -892,7 +849,7 @@ nsSpaceManager::ResizeRectRegion(nsIFrame* aFrame, return AddRectRegion(aFrame, rect); } -NS_IMETHODIMP +nsresult nsSpaceManager::OffsetRegion(nsIFrame* aFrame, nscoord aDx, nscoord aDy) { // Get the frame info associated with with aFrame @@ -915,7 +872,7 @@ nsSpaceManager::OffsetRegion(nsIFrame* aFrame, nscoord aDx, nscoord aDy) return AddRectRegion(aFrame, rect); } -NS_IMETHODIMP +nsresult nsSpaceManager::RemoveRegion(nsIFrame* aFrame) { // Get the frame info associated with aFrame @@ -1019,33 +976,15 @@ nsSpaceManager::RemoveRegion(nsIFrame* aFrame) return NS_OK; } -NS_IMETHODIMP +void nsSpaceManager::ClearRegions() { ClearFrameInfo(); mBandList.Clear(); - return NS_OK; -} - -NS_IMETHODIMP_(PRBool) nsSpaceManager::HasFloatDamage() -{ - return !mFloatDamage.IsEmpty(); -} - -NS_IMETHODIMP_(void) nsSpaceManager::IncludeInDamage(nscoord aIntervalBegin, - nscoord aIntervalEnd) -{ - mFloatDamage.IncludeInterval(aIntervalBegin + mY, aIntervalEnd + mY); -} - -NS_IMETHODIMP_(PRBool) nsSpaceManager::IntersectsDamage(nscoord aIntervalBegin, - nscoord aIntervalEnd) -{ - return mFloatDamage.Intersects(aIntervalBegin + mY, aIntervalEnd + mY); } #ifdef DEBUG -NS_IMETHODIMP +nsresult nsSpaceManager::List(FILE* out) { nsAutoString tmp; diff --git a/mozilla/layout/generic/nsSpaceManager.h b/mozilla/layout/generic/nsSpaceManager.h index 98870ac2719..1505628ad5b 100644 --- a/mozilla/layout/generic/nsSpaceManager.h +++ b/mozilla/layout/generic/nsSpaceManager.h @@ -1,4 +1,5 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +// vim:cindent:ts=2:et:sw=2: /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -37,63 +38,271 @@ #ifndef nsSpaceManager_h___ #define nsSpaceManager_h___ -#include "nsISpaceManager.h" #include "prclist.h" #include "nsIntervalSet.h" +#include "nsISupports.h" +#include "nsCoord.h" +#include "nsRect.h" class nsIPresShell; +class nsIFrame; +class nsVoidArray; +class nsISizeOfHandler; +struct nsSize; #define NS_SPACE_MANAGER_CACHE_SIZE 4 /** - * Implementation of nsISpaceManager that maintains a region data structure of - * unavailable space + * Information about a particular trapezoid within a band. The space described + * by the trapezoid is in one of three states: + *
    + *
  • available + *
  • occupied by one frame + *
  • occupied by more than one frame + *
*/ -class nsSpaceManager : public nsISpaceManager { +struct nsBandTrapezoid { + enum State {Available, Occupied, OccupiedMultiple}; + + nscoord mTopY, mBottomY; // top and bottom y-coordinates + nscoord mTopLeftX, mBottomLeftX; // left edge x-coordinates + nscoord mTopRightX, mBottomRightX; // right edge x-coordinates + State mState; // state of the space + union { + nsIFrame* mFrame; // single frame occupying the space + const nsVoidArray* mFrames; // list of frames occupying the space + }; + + // Get the height of the trapezoid + nscoord GetHeight() const {return mBottomY - mTopY;} + + // Get the bounding rect of the trapezoid + inline void GetRect(nsRect& aRect) const; + + // Set the trapezoid from a rectangle + inline void operator=(const nsRect& aRect); + + // Do these trapezoids have the same geometry, frame, and state? + inline PRBool Equals(const nsBandTrapezoid& aTrap) const; + + // Do these trapezoids have the same geometry? + inline PRBool EqualGeometry(const nsBandTrapezoid& aTrap) const; + + nsBandTrapezoid() + : mTopY(0), + mBottomY(0), + mTopLeftX(0), + mBottomLeftX(0), + mTopRightX(0), + mBottomRightX(0), + mFrame(nsnull) + { + } +}; + +inline void nsBandTrapezoid::GetRect(nsRect& aRect) const +{ + aRect.x = PR_MIN(mTopLeftX, mBottomLeftX); + aRect.y = mTopY; + aRect.width = PR_MAX(mTopRightX, mBottomRightX) - aRect.x; + aRect.height = mBottomY - mTopY; +} + +inline void nsBandTrapezoid::operator=(const nsRect& aRect) +{ + mTopLeftX = mBottomLeftX = aRect.x; + mTopRightX = mBottomRightX = aRect.XMost(); + mTopY = aRect.y; + mBottomY = aRect.YMost(); +} + +inline PRBool nsBandTrapezoid::Equals(const nsBandTrapezoid& aTrap) const +{ + return ( + mTopLeftX == aTrap.mTopLeftX && + mBottomLeftX == aTrap.mBottomLeftX && + mTopRightX == aTrap.mTopRightX && + mBottomRightX == aTrap.mBottomRightX && + mTopY == aTrap.mTopY && + mBottomY == aTrap.mBottomY && + mState == aTrap.mState && + mFrame == aTrap.mFrame + ); +} + +inline PRBool nsBandTrapezoid::EqualGeometry(const nsBandTrapezoid& aTrap) const +{ + return ( + mTopLeftX == aTrap.mTopLeftX && + mBottomLeftX == aTrap.mBottomLeftX && + mTopRightX == aTrap.mTopRightX && + mBottomRightX == aTrap.mBottomRightX && + mTopY == aTrap.mTopY && + mBottomY == aTrap.mBottomY + ); +} + +/** + * Structure used for describing the space within a band. + * @see #GetBandData() + */ +struct nsBandData { + PRInt32 mCount; // [out] actual number of trapezoids in the band data + PRInt32 mSize; // [in] the size of the array (number of trapezoids) + nsBandTrapezoid* mTrapezoids; // [out] array of length 'size' +}; + +/** + * Class for dealing with bands of available space. The space manager + * defines a coordinate space with an origin at (0, 0) that grows down + * and to the right. + */ +class nsSpaceManager { public: - static nsSpaceManager *Create(nsIPresShell* aPresShell, - nsIFrame* aFrame); + nsSpaceManager(nsIPresShell* aPresShell, nsIFrame* aFrame); + ~nsSpaceManager(); + + void* operator new(size_t aSize); + void operator delete(void* aPtr, size_t aSize); + static void Shutdown(); - // nsISupports - NS_DECL_ISUPPORTS + /* + * Get the frame that's associated with the space manager. This frame + * created the space manager, and the world coordinate space is + * relative to this frame. + * + * You can use QueryInterface() on this frame to get any additional + * interfaces. + */ + nsIFrame* GetFrame() const { return mFrame; } - // nsISpaceManager - NS_IMETHOD GetFrame(nsIFrame*& aFrame) const; + /** + * Translate the current origin by the specified (dx, dy). This + * creates a new local coordinate space relative to the current + * coordinate space. + */ + void Translate(nscoord aDx, nscoord aDy) { mX += aDx; mY += aDy; } - NS_IMETHOD Translate(nscoord aDx, nscoord aDy); - NS_IMETHOD GetTranslation(nscoord& aX, nscoord& aY) const; - NS_IMETHOD YMost(nscoord& aYMost) const; + /** + * Returns the current translation from local coordinate space to + * world coordinate space. This represents the accumulated calls to + * Translate(). + */ + void GetTranslation(nscoord& aX, nscoord& aY) const { aX = mX; aY = mY; } - NS_IMETHOD GetBandData(nscoord aYOffset, - const nsSize& aMaxSize, - nsBandData& aBandData) const; + /** + * Returns the y-most of the bottommost band or 0 if there are no bands. + * + * @return PR_TRUE if there are bands and PR_FALSE if there are no bands + */ + PRBool YMost(nscoord& aYMost) const; - NS_IMETHOD AddRectRegion(nsIFrame* aFrame, - const nsRect& aUnavailableSpace); - NS_IMETHOD ResizeRectRegion(nsIFrame* aFrame, - nscoord aDeltaWidth, - nscoord aDeltaHeight, - AffectedEdge aEdge); - NS_IMETHOD OffsetRegion(nsIFrame* aFrame, nscoord aDx, nscoord aDy); - NS_IMETHOD RemoveRegion(nsIFrame* aFrame); + /** + * Returns a band starting at the specified y-offset. The band data + * indicates which parts of the band are available, and which parts + * are unavailable + * + * The band data that is returned is in the coordinate space of the + * local coordinate system. + * + * The local coordinate space origin, the y-offset, and the max size + * describe a rectangle that's used to clip the underlying band of + * available space, i.e. + * {0, aYOffset, aMaxSize.width, aMaxSize.height} in the local + * coordinate space + * + * @param aYOffset the y-offset of where the band begins. The coordinate is + * relative to the upper-left corner of the local coordinate space + * @param aMaxSize the size to use to constrain the band data + * @param aBandData [in,out] used to return the list of trapezoids that + * describe the available space and the unavailable space + * @return NS_OK if successful and NS_ERROR_FAILURE if the band data is not + * not large enough. The 'count' member of the band data struct + * indicates how large the array of trapezoids needs to be + */ + nsresult GetBandData(nscoord aYOffset, + const nsSize& aMaxSize, + nsBandData& aBandData) const; - NS_IMETHOD ClearRegions(); + /** + * Add a rectangular region of unavailable space. The space is + * relative to the local coordinate system. + * + * The region is tagged with a frame + * + * @param aFrame the frame used to identify the region. Must not be NULL + * @param aUnavailableSpace the bounding rect of the unavailable space + * @return NS_OK if successful + * NS_ERROR_FAILURE if there is already a region tagged with aFrame + */ + nsresult AddRectRegion(nsIFrame* aFrame, + const nsRect& aUnavailableSpace); - NS_IMETHOD_(PRBool) HasFloatDamage(); - NS_IMETHOD_(void) IncludeInDamage(nscoord aIntervalBegin, - nscoord aIntervalEnd); - NS_IMETHOD_(PRBool) IntersectsDamage(nscoord aIntervalBegin, - nscoord aIntervalEnd); + /** + * Resize the rectangular region associated with aFrame by the specified + * deltas. The height change always applies to the bottom edge or the existing + * rect. You specify whether the width change applies to the left or right edge + * + * Returns NS_OK if successful, NS_ERROR_INVALID_ARG if there is no region + * tagged with aFrame + */ + enum AffectedEdge {LeftEdge, RightEdge}; + nsresult ResizeRectRegion(nsIFrame* aFrame, + nscoord aDeltaWidth, + nscoord aDeltaHeight, + AffectedEdge aEdge = RightEdge); + + /** + * Offset the region associated with aFrame by the specified amount. + * + * Returns NS_OK if successful, NS_ERROR_INVALID_ARG if there is no region + * tagged with aFrame + */ + nsresult OffsetRegion(nsIFrame* aFrame, nscoord dx, nscoord dy); + + /** + * Remove the region associated with aFrane. + * + * Returns NS_OK if successful and NS_ERROR_INVALID_ARG if there is no region + * tagged with aFrame + */ + nsresult RemoveRegion(nsIFrame* aFrame); + + /** + * Clears the list of regions representing the unavailable space. + */ + void ClearRegions(); + + /** + * Methods for dealing with the propagation of float damage during + * reflow. + */ + PRBool HasFloatDamage() + { + return !mFloatDamage.IsEmpty(); + } + + void IncludeInDamage(nscoord aIntervalBegin, nscoord aIntervalEnd) + { + mFloatDamage.IncludeInterval(aIntervalBegin + mY, aIntervalEnd + mY); + } + + PRBool IntersectsDamage(nscoord aIntervalBegin, nscoord aIntervalEnd) + { + return mFloatDamage.Intersects(aIntervalBegin + mY, aIntervalEnd + mY); + } #ifdef DEBUG - NS_IMETHOD List(FILE* out); - void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; + /** + * Dump the state of the spacemanager out to a file + */ + nsresult List(FILE* out); + + void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const; #endif protected: - nsSpaceManager(nsIPresShell* aPresShell, nsIFrame* aFrame); - // Structure that maintains information about the region associated // with a particular frame struct FrameInfo { @@ -179,7 +388,6 @@ protected: nsIntervalSet mFloatDamage; protected: - virtual ~nsSpaceManager(); FrameInfo* GetFrameInfoFor(nsIFrame* aFrame); FrameInfo* CreateFrameInfo(nsIFrame* aFrame, const nsRect& aRect); void DestroyFrameInfo(FrameInfo*); @@ -201,9 +409,7 @@ protected: private: static PRInt32 sCachedSpaceManagerCount; - static nsSpaceManager *sCachedSpaceManagers[NS_SPACE_MANAGER_CACHE_SIZE]; - - void LastRelease(); + static void* sCachedSpaceManagers[NS_SPACE_MANAGER_CACHE_SIZE]; nsSpaceManager(const nsSpaceManager&); // no implementation void operator=(const nsSpaceManager&); // no implementation diff --git a/mozilla/layout/html/base/src/nsBlockBandData.cpp b/mozilla/layout/html/base/src/nsBlockBandData.cpp index b5a17e27686..5e8f237f639 100644 --- a/mozilla/layout/html/base/src/nsBlockBandData.cpp +++ b/mozilla/layout/html/base/src/nsBlockBandData.cpp @@ -57,24 +57,18 @@ nsBlockBandData::nsBlockBandData() nsBlockBandData::~nsBlockBandData() { - NS_IF_RELEASE(mSpaceManager); if (mTrapezoids != mData) { delete [] mTrapezoids; } } nsresult -nsBlockBandData::Init(nsISpaceManager* aSpaceManager, +nsBlockBandData::Init(nsSpaceManager* aSpaceManager, const nsSize& aSpace) { - NS_PRECONDITION(nsnull != aSpaceManager, "null pointer"); - if (nsnull == aSpaceManager) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aSpaceManager, "null pointer"); - NS_IF_RELEASE(mSpaceManager); mSpaceManager = aSpaceManager; - NS_ADDREF(aSpaceManager); aSpaceManager->GetTranslation(mSpaceManagerX, mSpaceManagerY); mSpace = aSpace; @@ -115,9 +109,6 @@ nsresult nsBlockBandData::GetBandData(nscoord aY) { NS_ASSERTION(mSpaceManager, "bad state, no space manager"); - if (!mSpaceManager) { - return NS_ERROR_FAILURE; - } PRInt32 iterations =0; nsresult rv = mSpaceManager->GetBandData(aY, mSpace, *this); while (NS_FAILED(rv)) { diff --git a/mozilla/layout/html/base/src/nsBlockBandData.h b/mozilla/layout/html/base/src/nsBlockBandData.h index c52a34f737a..b8af0c32055 100644 --- a/mozilla/layout/html/base/src/nsBlockBandData.h +++ b/mozilla/layout/html/base/src/nsBlockBandData.h @@ -37,7 +37,7 @@ #ifndef nsBlockBandData_h___ #define nsBlockBandData_h___ -#include "nsISpaceManager.h" +#include "nsSpaceManager.h" class nsIPresContext; @@ -54,7 +54,7 @@ public: ~nsBlockBandData(); // Initialize. This must be called before any of the other methods. - nsresult Init(nsISpaceManager* aSpaceManager, const nsSize& aSpace); + nsresult Init(nsSpaceManager* aSpaceManager, const nsSize& aSpace); // Get some available space. Note that aY is relative to the current // space manager translation. @@ -119,7 +119,7 @@ protected: nsresult GetBandData(nscoord aY); // The spacemanager we are getting space from - nsISpaceManager* mSpaceManager; + nsSpaceManager* mSpaceManager; nscoord mSpaceManagerX, mSpaceManagerY; // Limit to the available space (set by Init) diff --git a/mozilla/layout/html/base/src/nsBlockFrame.cpp b/mozilla/layout/html/base/src/nsBlockFrame.cpp index f2eb958e39c..e7ef70cc1c3 100644 --- a/mozilla/layout/html/base/src/nsBlockFrame.cpp +++ b/mozilla/layout/html/base/src/nsBlockFrame.cpp @@ -55,7 +55,6 @@ #include "nsIPresContext.h" #include "nsIPresShell.h" #include "nsIReflowCommand.h" -#include "nsISpaceManager.h" #include "nsIStyleContext.h" #include "nsIView.h" #include "nsIFontMetrics.h" @@ -688,28 +687,28 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, } // Should we create a space manager? - nsCOMPtr spaceManager; - nsISpaceManager* oldSpaceManager = aReflowState.mSpaceManager; + nsSpaceManager* spaceManager; + nsSpaceManager* oldSpaceManager; // XXXldb If we start storing the space manager in the frame rather // than keeping it around only during reflow then we should create it // only when there are actually floats to manage. Otherwise things // like tables will gain significant bloat. if (NS_BLOCK_SPACE_MGR & mState) { + oldSpaceManager = aReflowState.mSpaceManager; + nsCOMPtr shell; aPresContext->GetShell(getter_AddRefs(shell)); - nsSpaceManager* rawPtr = nsSpaceManager::Create(shell, this); - if (!rawPtr) { + spaceManager = new nsSpaceManager(shell, this); + if (!spaceManager) return NS_ERROR_OUT_OF_MEMORY; - } - - spaceManager = do_QueryInterface(rawPtr); // Set the space manager in the existing reflow state nsHTMLReflowState& reflowState = NS_CONST_CAST(nsHTMLReflowState&, aReflowState); - reflowState.mSpaceManager = spaceManager.get(); + reflowState.mSpaceManager = spaceManager; #ifdef NOISY_SPACEMANAGER - printf("constructed new space manager %p (replacing %p)\n", reflowState.mSpaceManager, oldSpaceManager); + printf("constructed new space manager %p (replacing %p)\n", + reflowState.mSpaceManager, oldSpaceManager); #endif } @@ -851,6 +850,7 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, // see if verifyReflow is enabled, and if so store off the space manager pointer #ifdef DEBUG PRInt32 verifyReflowFlags = nsIPresShell::GetVerifyReflowFlags(); + PRBool transferredSpaceManager = PR_FALSE; if (VERIFY_REFLOW_INCLUDE_SPACE_MANAGER & verifyReflowFlags) { // this is a leak of the space manager, but it's only in debug if verify reflow is enabled, so not a big deal @@ -861,9 +861,11 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, shell->GetFrameManager(getter_AddRefs(frameManager)); if (frameManager) { nsHTMLReflowState& reflowState = (nsHTMLReflowState&)aReflowState; - NS_ADDREF(reflowState.mSpaceManager); - rv = frameManager->SetFrameProperty(this, nsLayoutAtoms::spaceManagerProperty, - reflowState.mSpaceManager, nsnull /* should be nsSpaceManagerDestroyer*/); + rv = frameManager->SetFrameProperty( + this, nsLayoutAtoms::spaceManagerProperty, + reflowState.mSpaceManager, + nsnull /* should be nsSpaceManagerDestroyer*/); + transferredSpaceManager = PR_TRUE; } } } @@ -877,10 +879,14 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, printf("restoring old space manager %p\n", oldSpaceManager); #endif reflowState.mSpaceManager = oldSpaceManager; +#ifdef DEBUG + // For debugging, we sometimes transfer ownership to the frame manager + // (above). + if (!transferredSpaceManager) +#endif + delete spaceManager; } - NS_ASSERTION(aReflowState.mSpaceManager == oldSpaceManager, "lost a space manager"); - #ifdef NOISY_SPACEMANAGER nsHTMLReflowState& reflowState = NS_CONST_CAST(nsHTMLReflowState&, aReflowState); if (reflowState.mSpaceManager) { @@ -1882,7 +1888,7 @@ nsBlockFrame::RememberFloaterDamage(nsBlockReflowState& aState, nscoord oldYMost = aOldCombinedArea.YMost(); nscoord impactYB = newYMost < oldYMost ? oldYMost : newYMost; nscoord impactYA = lineCombinedArea.y; - nsISpaceManager *spaceManager = aState.mReflowState.mSpaceManager; + nsSpaceManager *spaceManager = aState.mReflowState.mSpaceManager; spaceManager->IncludeInDamage(impactYA, impactYB); } } @@ -1907,7 +1913,7 @@ nsBlockFrame::PropagateFloaterDamage(nsBlockReflowState& aState, NS_PRECONDITION(!aLine->IsDirty(), "should never be called on dirty lines"); // Check the damage region recorded in the float damage. - nsISpaceManager *spaceManager = aState.mReflowState.mSpaceManager; + nsSpaceManager *spaceManager = aState.mReflowState.mSpaceManager; if (spaceManager->HasFloatDamage()) { nscoord lineYA = aLine->mBounds.y + aDeltaY; nscoord lineYB = lineYA + aLine->mBounds.height; @@ -2730,7 +2736,7 @@ nsBlockFrame::SlideLine(nsBlockReflowState& aState, nsresult nsBlockFrame::UpdateSpaceManager(nsIPresContext* aPresContext, - nsISpaceManager* aSpaceManager) + nsSpaceManager* aSpaceManager) { for (line_iterator line = begin_lines(), line_end = end_lines(); line != line_end; @@ -5309,7 +5315,7 @@ nsBlockFrame::Paint(nsIPresContext* aPresContext, #if 0 if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) { // Render the bands in the spacemanager - nsISpaceManager* sm = mSpaceManager; + nsSpaceManager* sm = mSpaceManager; if (nsnull != sm) { nsBlockBandData band; diff --git a/mozilla/layout/html/base/src/nsBlockFrame.h b/mozilla/layout/html/base/src/nsBlockFrame.h index efc8f52558b..8ce3c5e2fe9 100644 --- a/mozilla/layout/html/base/src/nsBlockFrame.h +++ b/mozilla/layout/html/base/src/nsBlockFrame.h @@ -192,7 +192,7 @@ public: * recursively adds floaters in child blocks of this frame. */ nsresult UpdateSpaceManager(nsIPresContext* aPresContext, - nsISpaceManager* aSpaceManager); + nsSpaceManager* aSpaceManager); // returns true on success and false if aFoundLine is set to end_lines() PRBool FindLineFor(nsIFrame* aFrame, diff --git a/mozilla/layout/html/base/src/nsBlockReflowContext.cpp b/mozilla/layout/html/base/src/nsBlockReflowContext.cpp index c03a10c1f2f..f79088f4391 100644 --- a/mozilla/layout/html/base/src/nsBlockReflowContext.cpp +++ b/mozilla/layout/html/base/src/nsBlockReflowContext.cpp @@ -39,7 +39,7 @@ #include "nsBlockReflowContext.h" #include "nsLineLayout.h" #include "nsHTMLIIDs.h" -#include "nsISpaceManager.h" +#include "nsSpaceManager.h" #include "nsIFontMetrics.h" #include "nsIPresContext.h" #include "nsIContent.h" diff --git a/mozilla/layout/html/base/src/nsBlockReflowState.cpp b/mozilla/layout/html/base/src/nsBlockReflowState.cpp index a41e46a14fb..b19b83c35a9 100644 --- a/mozilla/layout/html/base/src/nsBlockReflowState.cpp +++ b/mozilla/layout/html/base/src/nsBlockReflowState.cpp @@ -83,8 +83,9 @@ nsBlockReflowState::nsBlockReflowState(const nsHTMLReflowState& aReflowState, mSpaceManager = aReflowState.mSpaceManager; - NS_ASSERTION( nsnull != mSpaceManager, "SpaceManager should be set in nsBlockReflowState" ); - if( nsnull != mSpaceManager ) { + NS_ASSERTION(mSpaceManager, + "SpaceManager should be set in nsBlockReflowState" ); + if (mSpaceManager) { // Translate into our content area and then save the // coordinate system origin for later. mSpaceManager->Translate(borderPadding.left, borderPadding.top); diff --git a/mozilla/layout/html/base/src/nsBlockReflowState.h b/mozilla/layout/html/base/src/nsBlockReflowState.h index 718867ac895..ef559e496d4 100644 --- a/mozilla/layout/html/base/src/nsBlockReflowState.h +++ b/mozilla/layout/html/base/src/nsBlockReflowState.h @@ -138,7 +138,7 @@ public: const nsHTMLReflowState& mReflowState; - nsISpaceManager* mSpaceManager; + nsSpaceManager* mSpaceManager; // The coordinates within the spacemanager where the block is being // placed after taking into account the blocks border and diff --git a/mozilla/layout/html/base/src/nsContainerFrame.cpp b/mozilla/layout/html/base/src/nsContainerFrame.cpp index 611acd94504..8b39bee6398 100644 --- a/mozilla/layout/html/base/src/nsContainerFrame.cpp +++ b/mozilla/layout/html/base/src/nsContainerFrame.cpp @@ -39,7 +39,6 @@ #include "nsIContent.h" #include "nsIPresContext.h" #include "nsIRenderingContext.h" -#include "nsISpaceManager.h" #include "nsIStyleContext.h" #include "nsRect.h" #include "nsPoint.h" diff --git a/mozilla/layout/html/base/src/nsLineBox.cpp b/mozilla/layout/html/base/src/nsLineBox.cpp index 091cdbb31a9..84bc458028a 100644 --- a/mozilla/layout/html/base/src/nsLineBox.cpp +++ b/mozilla/layout/html/base/src/nsLineBox.cpp @@ -38,7 +38,7 @@ * * ***** END LICENSE BLOCK ***** */ #include "nsLineBox.h" -#include "nsISpaceManager.h" +#include "nsSpaceManager.h" #include "nsIStyleContext.h" #include "nsLineLayout.h" #include "prprf.h" @@ -407,7 +407,7 @@ nsLineBox::FreeFloaters(nsFloaterCacheFreeList& aFreeList) } void -nsLineBox::RemoveFloatersFromSpaceManager(nsISpaceManager* aSpaceManager) +nsLineBox::RemoveFloatersFromSpaceManager(nsSpaceManager* aSpaceManager) { if (IsInline()) { if (mInlineData) { diff --git a/mozilla/layout/html/base/src/nsLineBox.h b/mozilla/layout/html/base/src/nsLineBox.h index c1fbe7da82f..be8ef9c17f4 100644 --- a/mozilla/layout/html/base/src/nsLineBox.h +++ b/mozilla/layout/html/base/src/nsLineBox.h @@ -44,7 +44,7 @@ #include "nsILineIterator.h" #include "nsISizeOfHandler.h" -class nsISpaceManager; +class nsSpaceManager; class nsLineBox; class nsFloaterCache; class nsFloaterCacheList; @@ -333,7 +333,7 @@ public: void FreeFloaters(nsFloaterCacheFreeList& aFreeList); void AppendFloaters(nsFloaterCacheFreeList& aFreeList); PRBool RemoveFloater(nsIFrame* aFrame); - void RemoveFloatersFromSpaceManager(nsISpaceManager* aSpaceManager); + void RemoveFloatersFromSpaceManager(nsSpaceManager* aSpaceManager); // Combined area void SetCombinedArea(const nsRect& aCombinedArea); diff --git a/mozilla/layout/html/base/src/nsLineLayout.cpp b/mozilla/layout/html/base/src/nsLineLayout.cpp index 7ffad424fc1..e0957ee4a03 100644 --- a/mozilla/layout/html/base/src/nsLineLayout.cpp +++ b/mozilla/layout/html/base/src/nsLineLayout.cpp @@ -45,7 +45,7 @@ #include "nsStyleConsts.h" #include "nsHTMLContainerFrame.h" #include "nsHTMLIIDs.h" -#include "nsISpaceManager.h" +#include "nsSpaceManager.h" #include "nsIStyleContext.h" #include "nsIPresContext.h" #include "nsIFontMetrics.h" @@ -155,7 +155,7 @@ static PRBool InUnconstrainedTableCell(const nsHTMLReflowState& aBlockReflowStat MOZ_DECL_CTOR_COUNTER(nsLineLayout) nsLineLayout::nsLineLayout(nsIPresContext* aPresContext, - nsISpaceManager* aSpaceManager, + nsSpaceManager* aSpaceManager, const nsHTMLReflowState* aOuterReflowState, PRBool aComputeMaxElementSize) : mPresContext(aPresContext), diff --git a/mozilla/layout/html/base/src/nsLineLayout.h b/mozilla/layout/html/base/src/nsLineLayout.h index bb4d4935099..deb45a08090 100644 --- a/mozilla/layout/html/base/src/nsLineLayout.h +++ b/mozilla/layout/html/base/src/nsLineLayout.h @@ -36,7 +36,7 @@ #include "nsLineBox.h" #include "nsBlockReflowState.h" -class nsISpaceManager; +class nsSpaceManager; class nsPlaceholderFrame; struct nsStyleText; @@ -46,7 +46,7 @@ struct nsStyleText; class nsLineLayout { public: nsLineLayout(nsIPresContext* aPresContext, - nsISpaceManager* aSpaceManager, + nsSpaceManager* aSpaceManager, const nsHTMLReflowState* aOuterReflowState, PRBool aComputeMaxElementSize); nsLineLayout(nsIPresContext* aPresContext); @@ -265,7 +265,7 @@ public: protected: // This state is constant for a given block frame doing line layout - nsISpaceManager* mSpaceManager; + nsSpaceManager* mSpaceManager; const nsStyleText* mStyleText; // for the block const nsHTMLReflowState* mBlockReflowState; nsBlockReflowState* mBlockRS;/* XXX hack! */ diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 14faf6c1e2a..cbf8aba9652 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -39,7 +39,6 @@ #define PL_ARENA_CONST_ALIGN_MASK 3 #include "nsIPresShell.h" -#include "nsISpaceManager.h" #include "nsIPresContext.h" #include "nsIContent.h" #include "nsIDocument.h" @@ -6513,7 +6512,7 @@ CompareTrees(nsIPresContext* aFirstPresContext, nsIFrame* aFirstFrame, // or they both do and the space managers are equivalent nsCOMPtrfm1; nsCOMPtr ps1; - nsISpaceManager *sm1; // note, no ref counting here + nsSpaceManager *sm1; aFirstPresContext->GetShell(getter_AddRefs(ps1)); NS_ASSERTION(ps1, "no pres shell for primary tree!"); ps1->GetFrameManager(getter_AddRefs(fm1)); @@ -6523,7 +6522,7 @@ CompareTrees(nsIPresContext* aFirstPresContext, nsIFrame* aFirstFrame, // look at the test frame nsCOMPtrfm2; nsCOMPtr ps2; - nsISpaceManager *sm2; // note, no ref counting here + nsSpaceManager *sm2; aSecondPresContext->GetShell(getter_AddRefs(ps2)); NS_ASSERTION(ps2, "no pres shell for test tree!"); ps2->GetFrameManager(getter_AddRefs(fm2)); diff --git a/mozilla/layout/mathml/base/src/Makefile.in b/mozilla/layout/mathml/base/src/Makefile.in index 6cc0be243b2..649a03e99a7 100644 --- a/mozilla/layout/mathml/base/src/Makefile.in +++ b/mozilla/layout/mathml/base/src/Makefile.in @@ -46,6 +46,7 @@ REQUIRES = xpcom \ LOCAL_INCLUDES = \ -I$(srcdir)/../../../html/style/src \ -I$(srcdir)/../../../html/base/src \ + -I$(srcdir)/../../../base/src \ -I$(srcdir)/../../../html/table/src \ -I$(srcdir)/../../content/src \ $(NULL) diff --git a/mozilla/layout/mathml/base/src/makefile.win b/mozilla/layout/mathml/base/src/makefile.win index ee9cc701932..e88e6e97326 100644 --- a/mozilla/layout/mathml/base/src/makefile.win +++ b/mozilla/layout/mathml/base/src/makefile.win @@ -100,6 +100,7 @@ EXPORTS = \ LINCS= \ -I..\..\..\html\style\src \ -I..\..\..\html\base\src \ + -I..\..\..\base\src \ -I..\..\..\html\table\src \ -I..\..\content\src \ $(NULL) diff --git a/mozilla/layout/svg/base/src/nsSVGContainerFrame.cpp b/mozilla/layout/svg/base/src/nsSVGContainerFrame.cpp index db32efb0ad7..a0217487dfb 100644 --- a/mozilla/layout/svg/base/src/nsSVGContainerFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGContainerFrame.cpp @@ -46,7 +46,6 @@ #include "nsSVGAtoms.h" #include "nsIReflowCommand.h" #include "nsIContent.h" -#include "nsSpaceManager.h" #include "nsHTMLParts.h" #include "nsIViewManager.h" #include "nsIView.h" diff --git a/mozilla/layout/svg/base/src/nsSVGContainerFrame.h b/mozilla/layout/svg/base/src/nsSVGContainerFrame.h index 67ff3eb6a4a..56f945b61be 100644 --- a/mozilla/layout/svg/base/src/nsSVGContainerFrame.h +++ b/mozilla/layout/svg/base/src/nsSVGContainerFrame.h @@ -40,7 +40,6 @@ #include "nsCOMPtr.h" #include "nsHTMLContainerFrame.h" -#include "nsISpaceManager.h" class nsHTMLReflowCommand; class nsHTMLInfo; diff --git a/mozilla/layout/xul/base/src/nsBoxToBlockAdaptor.cpp b/mozilla/layout/xul/base/src/nsBoxToBlockAdaptor.cpp index 2eb9aa139bd..ca45ab57ee7 100644 --- a/mozilla/layout/xul/base/src/nsBoxToBlockAdaptor.cpp +++ b/mozilla/layout/xul/base/src/nsBoxToBlockAdaptor.cpp @@ -244,8 +244,7 @@ nsBoxToBlockAdaptor::operator delete(void* aPtr, size_t sz) nsBoxToBlockAdaptor::~nsBoxToBlockAdaptor() { - if (mSpaceManager) - NS_RELEASE(mSpaceManager); + delete mSpaceManager; } @@ -624,11 +623,10 @@ nsBoxToBlockAdaptor::Reflow(nsBoxLayoutState& aState, // if (frameState & NS_STATE_CURRENTLY_IN_DEBUG) // printf("In debug\n"); - if (mSpaceManager == nsnull) { + if (!mSpaceManager) { nsCOMPtr shell; aPresContext->GetShell(getter_AddRefs(shell)); - mSpaceManager = nsSpaceManager::Create(shell, mFrame); - NS_ADDREF(mSpaceManager); + mSpaceManager = new nsSpaceManager(shell, mFrame); } // Modify the reflow state and set the space manager