From c36412d39de1c33b3b4a283dc26f82cfa4f14f4e Mon Sep 17 00:00:00 2001 From: "troy%netscape.com" Date: Thu, 24 Jun 1999 02:04:50 +0000 Subject: [PATCH] Fix for bug #7397. Changed space manager to allows negative values for rect regions --- layout/base/public/nsISpaceManager.h | 17 ++++++------- layout/base/src/nsSpaceManager.cpp | 36 ++++++++++------------------ layout/base/src/nsSpaceManager.h | 2 +- layout/generic/nsSpaceManager.cpp | 36 ++++++++++------------------ layout/generic/nsSpaceManager.h | 2 +- 5 files changed, 33 insertions(+), 60 deletions(-) diff --git a/layout/base/public/nsISpaceManager.h b/layout/base/public/nsISpaceManager.h index 46ba8d133fc..63f7227a48f 100644 --- a/layout/base/public/nsISpaceManager.h +++ b/layout/base/public/nsISpaceManager.h @@ -101,7 +101,10 @@ public: NS_IMETHOD GetTranslation(nscoord& aX, nscoord& aY) const = 0; /** - * Returns the y-most of the bottommost band, or 0 if there are no bands. + * Returns the y-most of the bottommost band or 0 if there are no bands. + * + * @return NS_OK if there are bands and NS_COMFALSE if there are + * no bands */ NS_IMETHOD YMost(nscoord& aYMost) const = 0; @@ -133,16 +136,12 @@ public: * Add a rectangular region of unavailable space. The space is relative to * the local coordinate system. * - * The region is tagged with a frame. When translated to world coordinates - * the origin of the rect MUST be within the defined coordinate space, i.e. - * the x-offset and y-offset must be >= 0 + * 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_ERROR_INVALID_ARG if the rect translated to world coordinates - * is not within the defined coordinate space */ NS_IMETHOD AddRectRegion(nsIFrame* aFrame, const nsRect& aUnavailableSpace) = 0; @@ -153,8 +152,7 @@ public: * 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, and NS_ERROR_FAILURE if the new offset when translated - * to world coordinates is outside the defined coordinate space + * tagged with aFrame */ enum AffectedEdge {LeftEdge, RightEdge}; NS_IMETHOD ResizeRectRegion(nsIFrame* aFrame, @@ -166,8 +164,7 @@ public: * 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, and NS_ERROR_FAILURE if the new offset when translated - * to world coordinates is outside the defined coordinate space + * tagged with aFrame */ NS_IMETHOD OffsetRegion(nsIFrame* aFrame, nscoord dx, nscoord dy) = 0; diff --git a/layout/base/src/nsSpaceManager.cpp b/layout/base/src/nsSpaceManager.cpp index b5b6585d87e..28463ae4a48 100644 --- a/layout/base/src/nsSpaceManager.cpp +++ b/layout/base/src/nsSpaceManager.cpp @@ -43,8 +43,10 @@ NS_RemoveFrameInfoEntries(PLHashEntry* he, PRIntn i, void* arg) ///////////////////////////////////////////////////////////////////////////// // BandList +#define NSCOORD_MIN (-2147483647 - 1) /* minimum signed value */ + nsSpaceManager::BandList::BandList() - : nsSpaceManager::BandRect(-1, -1, -1, -1, (nsIFrame*)nsnull) + : nsSpaceManager::BandRect(NSCOORD_MIN, NSCOORD_MIN, NSCOORD_MIN, NSCOORD_MIN, (nsIFrame*)nsnull) { PR_INIT_CLIST(this); numFrames = 0; @@ -122,15 +124,20 @@ nsSpaceManager::GetTranslation(nscoord& aX, nscoord& aY) const NS_IMETHODIMP nsSpaceManager::YMost(nscoord& aYMost) const { + nsresult result; + if (mBandList.IsEmpty()) { aYMost = 0; + result = NS_COMFALSE; + } else { BandRect* lastRect = mBandList.Tail(); aYMost = lastRect->bottom; + result = NS_OK; } - return NS_OK; + return result; } /** @@ -266,8 +273,8 @@ nsSpaceManager::GetBandData(nscoord aYOffset, // If there are no unavailable rects or the offset is below the bottommost // band, then all the space is available nscoord yMost; - YMost(yMost); - if (y >= yMost) { + + if ((NS_COMFALSE == YMost(yMost)) || (y >= yMost)) { // All the requested space is available aBandData.count = 1; aBandData.trapezoids[0] = nsRect(0, aYOffset, aMaxSize.width, aMaxSize.height); @@ -618,8 +625,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; - YMost(yMost); - if (aBandRect->top >= yMost) { + if ((NS_COMFALSE == YMost(yMost)) || (aBandRect->top >= yMost)) { mBandList.Append(aBandRect); return; } @@ -725,12 +731,6 @@ nsSpaceManager::AddRectRegion(nsIFrame* aFrame, const nsRect& aUnavailableSpace) nsRect rect(aUnavailableSpace.x + mX, aUnavailableSpace.y + mY, aUnavailableSpace.width, aUnavailableSpace.height); - // Verify that the offset is within the defined coordinate space - if ((rect.x < 0) || (rect.y < 0)) { - NS_WARNING("invalid offset for rect region"); - return NS_ERROR_INVALID_ARG; - } - // Create a frame info structure frameInfo = CreateFrameInfo(aFrame, rect); if (nsnull == frameInfo) { @@ -775,12 +775,6 @@ nsSpaceManager::ResizeRectRegion(nsIFrame* aFrame, rect.x += aDeltaWidth; } - // Verify that the offset is within the defined coordinate space - if ((rect.x < 0) || (rect.y < 0)) { - NS_WARNING("invalid offset when resizing rect region"); - return NS_ERROR_FAILURE; - } - // For the time being just remove it and add it back in. Because // AddRectRegion() operates relative to the local coordinate space, // translate from world coordinates to the local coordinate space @@ -804,12 +798,6 @@ nsSpaceManager::OffsetRegion(nsIFrame* aFrame, nscoord aDx, nscoord aDy) nsRect rect(frameInfo->rect); rect.MoveBy(aDx, aDy); - // Verify that the offset is within the defined coordinate space - if ((rect.x < 0) || (rect.y < 0)) { - NS_WARNING("invalid offset when offseting rect region"); - return NS_ERROR_FAILURE; - } - // For the time being just remove it and add it back in. Because // AddRectRegion() operates relative to the local coordinate space, // translate from world coordinates to the local coordinate space diff --git a/layout/base/src/nsSpaceManager.h b/layout/base/src/nsSpaceManager.h index e8f7cd98458..307f9340725 100644 --- a/layout/base/src/nsSpaceManager.h +++ b/layout/base/src/nsSpaceManager.h @@ -132,7 +132,7 @@ public: protected: nsIFrame* const mFrame; // frame associated with the space manager nscoord mX, mY; // translation from local to global coordinate space - BandList mBandList; // header for circular linked list of band rects + BandList mBandList; // header/sentinel for circular linked list of band rects PLHashTable* mFrameInfoMap; protected: diff --git a/layout/generic/nsSpaceManager.cpp b/layout/generic/nsSpaceManager.cpp index b5b6585d87e..28463ae4a48 100644 --- a/layout/generic/nsSpaceManager.cpp +++ b/layout/generic/nsSpaceManager.cpp @@ -43,8 +43,10 @@ NS_RemoveFrameInfoEntries(PLHashEntry* he, PRIntn i, void* arg) ///////////////////////////////////////////////////////////////////////////// // BandList +#define NSCOORD_MIN (-2147483647 - 1) /* minimum signed value */ + nsSpaceManager::BandList::BandList() - : nsSpaceManager::BandRect(-1, -1, -1, -1, (nsIFrame*)nsnull) + : nsSpaceManager::BandRect(NSCOORD_MIN, NSCOORD_MIN, NSCOORD_MIN, NSCOORD_MIN, (nsIFrame*)nsnull) { PR_INIT_CLIST(this); numFrames = 0; @@ -122,15 +124,20 @@ nsSpaceManager::GetTranslation(nscoord& aX, nscoord& aY) const NS_IMETHODIMP nsSpaceManager::YMost(nscoord& aYMost) const { + nsresult result; + if (mBandList.IsEmpty()) { aYMost = 0; + result = NS_COMFALSE; + } else { BandRect* lastRect = mBandList.Tail(); aYMost = lastRect->bottom; + result = NS_OK; } - return NS_OK; + return result; } /** @@ -266,8 +273,8 @@ nsSpaceManager::GetBandData(nscoord aYOffset, // If there are no unavailable rects or the offset is below the bottommost // band, then all the space is available nscoord yMost; - YMost(yMost); - if (y >= yMost) { + + if ((NS_COMFALSE == YMost(yMost)) || (y >= yMost)) { // All the requested space is available aBandData.count = 1; aBandData.trapezoids[0] = nsRect(0, aYOffset, aMaxSize.width, aMaxSize.height); @@ -618,8 +625,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; - YMost(yMost); - if (aBandRect->top >= yMost) { + if ((NS_COMFALSE == YMost(yMost)) || (aBandRect->top >= yMost)) { mBandList.Append(aBandRect); return; } @@ -725,12 +731,6 @@ nsSpaceManager::AddRectRegion(nsIFrame* aFrame, const nsRect& aUnavailableSpace) nsRect rect(aUnavailableSpace.x + mX, aUnavailableSpace.y + mY, aUnavailableSpace.width, aUnavailableSpace.height); - // Verify that the offset is within the defined coordinate space - if ((rect.x < 0) || (rect.y < 0)) { - NS_WARNING("invalid offset for rect region"); - return NS_ERROR_INVALID_ARG; - } - // Create a frame info structure frameInfo = CreateFrameInfo(aFrame, rect); if (nsnull == frameInfo) { @@ -775,12 +775,6 @@ nsSpaceManager::ResizeRectRegion(nsIFrame* aFrame, rect.x += aDeltaWidth; } - // Verify that the offset is within the defined coordinate space - if ((rect.x < 0) || (rect.y < 0)) { - NS_WARNING("invalid offset when resizing rect region"); - return NS_ERROR_FAILURE; - } - // For the time being just remove it and add it back in. Because // AddRectRegion() operates relative to the local coordinate space, // translate from world coordinates to the local coordinate space @@ -804,12 +798,6 @@ nsSpaceManager::OffsetRegion(nsIFrame* aFrame, nscoord aDx, nscoord aDy) nsRect rect(frameInfo->rect); rect.MoveBy(aDx, aDy); - // Verify that the offset is within the defined coordinate space - if ((rect.x < 0) || (rect.y < 0)) { - NS_WARNING("invalid offset when offseting rect region"); - return NS_ERROR_FAILURE; - } - // For the time being just remove it and add it back in. Because // AddRectRegion() operates relative to the local coordinate space, // translate from world coordinates to the local coordinate space diff --git a/layout/generic/nsSpaceManager.h b/layout/generic/nsSpaceManager.h index e8f7cd98458..307f9340725 100644 --- a/layout/generic/nsSpaceManager.h +++ b/layout/generic/nsSpaceManager.h @@ -132,7 +132,7 @@ public: protected: nsIFrame* const mFrame; // frame associated with the space manager nscoord mX, mY; // translation from local to global coordinate space - BandList mBandList; // header for circular linked list of band rects + BandList mBandList; // header/sentinel for circular linked list of band rects PLHashTable* mFrameInfoMap; protected: