Bug 620658: Add nsRegion::Contains(nsRegion). sr=roc
authorChris Jones <jones.chris.g@gmail.com>
Wed, 26 Jan 2011 00:26:37 -0600
changeset 61315 23cfa8965c9e749afda622091c4ee40cee0047ce
parent 61314 bfd44071cce9c3a35c059915959c876ad61d2365
child 61316 0f592a9724829c19e1b8fecf218c11e3b802ca78
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs620658
milestone2.0b11pre
Bug 620658: Add nsRegion::Contains(nsRegion). sr=roc
gfx/src/nsRegion.cpp
gfx/src/nsRegion.h
--- a/gfx/src/nsRegion.cpp
+++ b/gfx/src/nsRegion.cpp
@@ -1008,16 +1008,28 @@ PRBool nsRegion::Contains (const nsRect&
   if (!IsComplex())
     return mBoundRect.Contains (aRect);
 
   nsRegion tmpRgn;
   tmpRgn.Sub(aRect, *this);
   return tmpRgn.IsEmpty();
 }
 
+PRBool nsRegion::Contains (const nsRegion& aRgn) const
+{
+  // XXX this could be made faster
+  nsRegionRectIterator iter(aRgn);
+  while (const nsRect* r = iter.Next()) {
+    if (!Contains (*r)) {
+      return PR_FALSE;
+    }
+  }
+  return PR_TRUE;
+}
+
 PRBool nsRegion::Intersects (const nsRect& aRect) const
 {
   if (aRect.IsEmpty() || IsEmpty())
     return PR_FALSE;
 
   const RgnRect* r = mRectListHead.next;
   while (r != &mRectListHead)
   {
--- a/gfx/src/nsRegion.h
+++ b/gfx/src/nsRegion.h
@@ -155,16 +155,17 @@ public:
   }
   nsRegion& Sub  (const nsRect& aRect1, const nsRect& aRect2)
   {
     Copy (aRect1);
     return Sub (*this, aRect2);
   }
 
   PRBool Contains (const nsRect& aRect) const;
+  PRBool Contains (const nsRegion& aRgn) const;
   PRBool Intersects (const nsRect& aRect) const;
 
   void MoveBy (PRInt32 aXOffset, PRInt32 aYOffset)
   {
     MoveBy (nsPoint (aXOffset, aYOffset));
   }
   void MoveBy (nsPoint aPt);
   void SetEmpty ()
@@ -395,16 +396,20 @@ public:
     mImpl = ToRect (aRect1);
     return Sub (*this, aRect2);
   }
 
   PRBool Contains (const nsIntRect& aRect) const
   {
     return mImpl.Contains (ToRect (aRect));
   }
+  PRBool Contains (const nsIntRegion& aRgn) const
+  {
+    return mImpl.Contains (aRgn.mImpl);
+  }
   PRBool Intersects (const nsIntRect& aRect) const
   {
     return mImpl.Intersects (ToRect (aRect));
   }
 
   void MoveBy (PRInt32 aXOffset, PRInt32 aYOffset)
   {
     MoveBy (nsIntPoint (aXOffset, aYOffset));