Bug 477708 - expose nsIRegion::getrects() to scripts r=stuart
--- a/gfx/idl/nsIScriptableRegion.idl
+++ b/gfx/idl/nsIScriptableRegion.idl
@@ -41,17 +41,17 @@
%{C++
class nsIRegion;
%}
[ptr] native nsIRegion(nsIRegion);
-[scriptable, uuid(82d8f400-5bde-11d3-b033-b27a62766bbc)]
+[scriptable, uuid(dbd0e356-09f5-40b1-99a7-5629c1a45f06)]
interface nsIScriptableRegion : nsISupports
{
void init ( ) ;
/**
* copy operator equivalent that takes another region
*
* @param region to copy
@@ -191,16 +191,34 @@ interface nsIScriptableRegion : nsISuppo
* does the region intersect the rectangle?
*
* @param rect to check for containment
* @return true if the region intersects the rect
*
**/
boolean containsRect ( in long aX, in long aY, in long aWidth, in long aHeight ) ;
+
+ /**
+ * returns a rectangle within the region
+ *
+ * @param aIndex index of the rect to retrieve
+ * @param aX out parameter for xoffset of bounding rect for region
+ * @param aY out parameter for yoffset of bounding rect for region
+ * @param aWidth out parameter for width of bounding rect for region
+ * @param aHeight out parameter for height of bounding rect for region
+ * @return void
+ *
+ **/
+ void getRect ( in unsigned long aIndex, out long aX, out long aY, out long aWidth, out long aHeight ) ;
+
+ /**
+ * The number of rectangles that can be retrieved via getRect
+ */
+ readonly attribute unsigned long numRects;
[noscript] readonly attribute nsIRegion region;
};
%{ C++
--- a/gfx/src/nsScriptableRegion.cpp
+++ b/gfx/src/nsScriptableRegion.cpp
@@ -33,28 +33,30 @@
* 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsScriptableRegion.h"
-#include "nsIRegion.h"
#include "nsCOMPtr.h"
-nsScriptableRegion::nsScriptableRegion(nsIRegion* region) : mRegion(nsnull)
+nsScriptableRegion::nsScriptableRegion(nsIRegion* region) : mRegion(nsnull), mRectSet(nsnull)
{
mRegion = region;
NS_IF_ADDREF(mRegion);
}
nsScriptableRegion::~nsScriptableRegion()
{
- NS_IF_RELEASE(mRegion);
+ if (mRegion) {
+ mRegion->FreeRects(mRectSet);
+ NS_RELEASE(mRegion);
+ }
}
NS_IMPL_ISUPPORTS1(nsScriptableRegion, nsIScriptableRegion)
NS_IMETHODIMP nsScriptableRegion::Init()
{
return mRegion->Init();
}
@@ -144,8 +146,25 @@ NS_IMETHODIMP nsScriptableRegion::Contai
NS_IMETHODIMP nsScriptableRegion::GetRegion(nsIRegion** outRgn)
{
*outRgn = mRegion;
NS_IF_ADDREF(*outRgn);
return NS_OK;
}
+
+NS_IMETHODIMP nsScriptableRegion::GetRect(PRUint32 aIndex, PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight) {
+ // nsIRegion reuses the GetRects parameter between calls
+ nsresult rv = mRegion->GetRects(&mRectSet);
+ NS_ENSURE_SUCCESS(rv, rv);
+ NS_ENSURE_TRUE(aIndex < mRectSet->mNumRects, NS_ERROR_INVALID_ARG);
+ nsRegionRect &rect = mRectSet->mRects[aIndex];
+ *aX = rect.x;
+ *aY = rect.y;
+ *aWidth = rect.width;
+ *aHeight = rect.height;
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsScriptableRegion::GetNumRects(PRUint32 *aLength) {
+ return mRegion->GetNumRects(aLength);
+}
--- a/gfx/src/nsScriptableRegion.h
+++ b/gfx/src/nsScriptableRegion.h
@@ -34,26 +34,28 @@
* 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIScriptableRegion.h"
#include "gfxCore.h"
+#include "nsIRegion.h"
class nsIRegion;
/**
* An adapter class for the unscriptable nsIRegion interface.
*/
class NS_GFX nsScriptableRegion : public nsIScriptableRegion {
public:
nsScriptableRegion(nsIRegion* region);
virtual ~nsScriptableRegion();
NS_DECL_ISUPPORTS
NS_DECL_NSISCRIPTABLEREGION
private:
- nsIRegion* mRegion;
+ nsIRegion* mRegion;
+ nsRegionRectSet *mRectSet;
};