Bug 266236 part 7: Simplify calling convention of SetClipRect and SetClipRegion.
authorZack Weinberg <zackw@panix.com>
Thu, 07 Apr 2011 18:04:40 -0700
changeset 68127 5fb27ef09b9b4b4bc416ad36f9226e9f96f3d656
parent 68126 cf8bfa6a407376d42c802f1e966e368ab61c8a63
child 68128 3eba1138ea6dd509f46605d408ce18da8bc72df1
push idunknown
push userunknown
push dateunknown
bugs266236
milestone6.0a1
Bug 266236 part 7: Simplify calling convention of SetClipRect and SetClipRegion.
gfx/src/nsRenderingContext.cpp
gfx/src/nsRenderingContext.h
layout/base/nsDisplayList.cpp
layout/base/nsPresShell.cpp
layout/forms/nsComboboxControlFrame.cpp
layout/forms/nsFieldSetFrame.cpp
layout/generic/nsImageFrame.cpp
layout/generic/nsPageFrame.cpp
layout/mathml/nsMathMLChar.cpp
layout/svg/base/src/nsSVGIntegrationUtils.cpp
layout/svg/base/src/nsSVGOuterSVGFrame.cpp
layout/xul/base/src/nsGroupBoxFrame.cpp
layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
--- a/gfx/src/nsRenderingContext.cpp
+++ b/gfx/src/nsRenderingContext.cpp
@@ -119,48 +119,40 @@ nsRenderingContext::PopState()
     mThebes->Restore();
 }
 
 //
 // clipping
 //
 
 void
-nsRenderingContext::SetClipRect(const nsRect& aRect, nsClipCombine aCombine)
+nsRenderingContext::IntersectClip(const nsRect& aRect)
 {
-    if (aCombine == nsClipCombine_kReplace) {
-        mThebes->ResetClip();
-    } else if (aCombine != nsClipCombine_kIntersect) {
-        NS_WARNING("Unexpected usage of SetClipRect");
-    }
-
     mThebes->NewPath();
     gfxRect clipRect(GFX_RECT_FROM_TWIPS_RECT(aRect));
     if (mThebes->UserToDevicePixelSnapped(clipRect, PR_TRUE)) {
         gfxMatrix mat(mThebes->CurrentMatrix());
         mThebes->IdentityMatrix();
         mThebes->Rectangle(clipRect);
         mThebes->SetMatrix(mat);
     } else {
         mThebes->Rectangle(clipRect);
     }
 
     mThebes->Clip();
 }
 
 void
-nsRenderingContext::SetClipRegion(const nsIntRegion& aRegion,
-                                  nsClipCombine aCombine)
+nsRenderingContext::SetClip(const nsIntRegion& aRegion)
 {
-    // Region is in device coords, no transformation.
-    // This should only be called when there is no transform in place, when we
-    // we just start painting a widget. The region is set by the platform paint
-    // routine.
-    NS_ASSERTION(aCombine == nsClipCombine_kReplace,
-                 "Unexpected usage of SetClipRegion");
+    // Region is in device coords, no transformation.  This should
+    // only be called when there is no transform in place, when we we
+    // just start painting a widget. The region is set by the platform
+    // paint routine.  Therefore, there is no option to intersect with
+    // an existing clip.
 
     gfxMatrix mat = mThebes->CurrentMatrix();
     mThebes->IdentityMatrix();
 
     mThebes->ResetClip();
 
     mThebes->NewPath();
     nsIntRegionRectIterator iter(aRegion);
--- a/gfx/src/nsRenderingContext.h
+++ b/gfx/src/nsRenderingContext.h
@@ -45,23 +45,16 @@
 #include "nsIRegion.h"
 #include "nsPoint.h"
 #include "nsSize.h"
 #include "nsColor.h"
 #include "nsRect.h"
 #include "gfxContext.h"
 
 typedef enum {
-    nsClipCombine_kIntersect = 0,
-    nsClipCombine_kUnion = 1,
-    nsClipCombine_kSubtract = 2,
-    nsClipCombine_kReplace = 3
-} nsClipCombine;
-
-typedef enum {
     nsLineStyle_kNone   = 0,
     nsLineStyle_kSolid  = 1,
     nsLineStyle_kDashed = 2,
     nsLineStyle_kDotted = 3
 } nsLineStyle;
 
 #ifdef MOZ_MATHML
 /* Struct used for accurate measurements of a string in order
@@ -151,18 +144,18 @@ public:
 
     already_AddRefed<nsIDeviceContext> GetDeviceContext();
     gfxContext *ThebesContext() { return mThebes; }
 
     // Graphics state
 
     void PushState(void);
     void PopState(void);
-    void SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
-    void SetClipRegion(const nsIntRegion& aRegion, nsClipCombine aCombine);
+    void IntersectClip(const nsRect& aRect);
+    void SetClip(const nsIntRegion& aRegion);
     void SetLineStyle(nsLineStyle aLineStyle);
     void SetColor(nscolor aColor);
     void Translate(const nsPoint& aPt);
     void Scale(float aSx, float aSy);
 
     class AutoPushTranslation {
         nsRenderingContext* mCtx;
     public:
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -1402,17 +1402,17 @@ nsDisplayBoxShadowOuter::Paint(nsDisplay
   nsPoint offset = ToReferenceFrame();
   nsRect borderRect = nsRect(offset, mFrame->GetSize());
   nsPresContext* presContext = mFrame->PresContext();
   nsAutoTArray<nsRect,10> rects;
   ComputeDisjointRectangles(mVisibleRegion, &rects);
 
   for (PRUint32 i = 0; i < rects.Length(); ++i) {
     aCtx->PushState();
-    aCtx->SetClipRect(rects[i], nsClipCombine_kIntersect);
+    aCtx->IntersectClip(rects[i]);
     nsCSSRendering::PaintBoxShadowOuter(presContext, *aCtx, mFrame,
                                         borderRect, rects[i]);
     aCtx->PopState();
   }
 }
 
 nsRect
 nsDisplayBoxShadowOuter::GetBounds(nsDisplayListBuilder* aBuilder) {
@@ -1455,17 +1455,17 @@ nsDisplayBoxShadowInner::Paint(nsDisplay
   nsPoint offset = ToReferenceFrame();
   nsRect borderRect = nsRect(offset, mFrame->GetSize());
   nsPresContext* presContext = mFrame->PresContext();
   nsAutoTArray<nsRect,10> rects;
   ComputeDisjointRectangles(mVisibleRegion, &rects);
 
   for (PRUint32 i = 0; i < rects.Length(); ++i) {
     aCtx->PushState();
-    aCtx->SetClipRect(rects[i], nsClipCombine_kIntersect);
+    aCtx->IntersectClip(rects[i]);
     nsCSSRendering::PaintBoxShadowInner(presContext, *aCtx, mFrame,
                                         borderRect, rects[i]);
     aCtx->PopState();
   }
 }
 
 PRBool
 nsDisplayBoxShadowInner::ComputeVisibility(nsDisplayListBuilder* aBuilder,
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -5610,17 +5610,17 @@ PresShell::PaintRangePaintInfo(nsTArray<
   deviceContext->CreateRenderingContextInstance(*getter_AddRefs(rc));
   rc->Init(deviceContext, surface);
 
   if (aRegion) {
     // Convert aRegion from CSS pixels to dev pixels
     nsIntRegion region =
       aRegion->ToAppUnits(nsPresContext::AppUnitsPerCSSPixel())
         .ToOutsidePixels(pc->AppUnitsPerDevPixel());
-    rc->SetClipRegion(region, nsClipCombine_kReplace);
+    rc->SetClip(region);
   }
 
   if (resize)
     rc->Scale(scale, scale);
 
   // translate so that points are relative to the surface area
   rc->Translate(-aArea.TopLeft());
 
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -1406,17 +1406,17 @@ void nsComboboxControlFrame::PaintFocus(
 {
   /* Do we need to do anything? */
   nsEventStates eventStates = mContent->IntrinsicState();
   if (eventStates.HasState(NS_EVENT_STATE_DISABLED) || mFocused != this)
     return;
 
   aRenderingContext.PushState();
   nsRect clipRect = mDisplayFrame->GetRect() + aPt;
-  aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
+  aRenderingContext.IntersectClip(clipRect);
 
   // REVIEW: Why does the old code paint mDisplayFrame again? We've
   // already painted it in the children above. So clipping it here won't do
   // us much good.
 
   /////////////////////
   // draw focus
 
--- a/layout/forms/nsFieldSetFrame.cpp
+++ b/layout/forms/nsFieldSetFrame.cpp
@@ -302,44 +302,44 @@ nsFieldSetFrame::PaintBorderBackground(n
     // to achieve the same effect.
 
     // draw left side
     nsRect clipRect(rect);
     clipRect.width = legendRect.x - rect.x;
     clipRect.height = topBorder;
 
     aRenderingContext.PushState();
-    aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
+    aRenderingContext.IntersectClip(clipRect);
     nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
                                 aDirtyRect, rect, mStyleContext, skipSides);
 
     aRenderingContext.PopState();
 
 
     // draw right side
     clipRect = rect;
     clipRect.x = legendRect.XMost();
     clipRect.width = rect.XMost() - legendRect.XMost();
     clipRect.height = topBorder;
 
     aRenderingContext.PushState();
-    aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
+    aRenderingContext.IntersectClip(clipRect);
     nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
                                 aDirtyRect, rect, mStyleContext, skipSides);
 
     aRenderingContext.PopState();
 
     
     // draw bottom
     clipRect = rect;
     clipRect.y += topBorder;
     clipRect.height = mRect.height - (yoff + topBorder);
     
     aRenderingContext.PushState();
-    aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
+    aRenderingContext.IntersectClip(clipRect);
     nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
                                 aDirtyRect, rect, mStyleContext, skipSides);
 
     aRenderingContext.PopState();
   } else {
 
     nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
                                 aDirtyRect,
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -1082,17 +1082,17 @@ nsImageFrame::DisplayAltFeedback(nsRende
   inner.Deflate(nsPresContext::CSSPixelsToAppUnits(ICON_PADDING+ALT_BORDER_WIDTH), 
                 nsPresContext::CSSPixelsToAppUnits(ICON_PADDING+ALT_BORDER_WIDTH));
   if (inner.IsEmpty()) {
     return;
   }
 
   // Clip so we don't render outside the inner rect
   aRenderingContext.PushState();
-  aRenderingContext.SetClipRect(inner, nsClipCombine_kIntersect);
+  aRenderingContext.IntersectClip(inner);
 
   // Check if we should display image placeholders
   if (gIconLoad->mPrefShowPlaceholders) {
     const nsStyleVisibility* vis = GetStyleVisibility();
     nscoord size = nsPresContext::CSSPixelsToAppUnits(ICON_SIZE);
 
     PRBool iconUsed = PR_FALSE;
 
--- a/layout/generic/nsPageFrame.cpp
+++ b/layout/generic/nsPageFrame.cpp
@@ -384,17 +384,17 @@ nsPageFrame::DrawHeaderFooter(nsRenderin
       y = aRect.y + mPD->mExtraMargin.top + mPD->mEdgePaperMargin.top;
     } else {
       y = aRect.YMost() - aHeight - mPD->mExtraMargin.bottom - mPD->mEdgePaperMargin.bottom;
     }
 
     // set up new clip and draw the text
     aRenderingContext.PushState();
     aRenderingContext.SetColor(NS_RGB(0,0,0));
-    aRenderingContext.SetClipRect(aRect, nsClipCombine_kIntersect);
+    aRenderingContext.IntersectClip(aRect);
     nsLayoutUtils::DrawString(this, &aRenderingContext, str.get(), str.Length(), nsPoint(x, y + aAscent));
     aRenderingContext.PopState();
   }
 }
 
 static void PaintPrintPreviewBackground(nsIFrame* aFrame, nsRenderingContext* aCtx,
                                         const nsRect& aDirtyRect, nsPoint aPt)
 {
@@ -575,17 +575,17 @@ nsPageFrame::PaintPageContent(nsRenderin
     // current page's content (in coordinates *relative* to the page content
     // frame), we just negate its y-position and add the top margin.
     clipRect.y = NSToCoordCeil((-pageContentFrame->GetRect().y + 
                                 mPD->mReflowMargin.top) / scale);
     clipRect.height = expectedPageContentHeight;
     NS_ASSERTION(clipRect.y < pageContentFrame->GetSize().height,
                  "Should be clipping to region inside the page content bounds");
   }
-  aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
+  aRenderingContext.IntersectClip(clipRect);
 
   nsRect backgroundRect = nsRect(nsPoint(0, 0), pageContentFrame->GetSize());
   nsCSSRendering::PaintBackground(PresContext(), aRenderingContext, this,
                                   rect, backgroundRect,
                                   nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES);
 
   nsLayoutUtils::PaintFrame(&aRenderingContext, pageContentFrame,
                             nsRegion(rect), NS_RGBA(0,0,0,0),
--- a/layout/mathml/nsMathMLChar.cpp
+++ b/layout/mathml/nsMathMLChar.cpp
@@ -2195,17 +2195,17 @@ nsMathMLChar::PaintForeground(nsPresCont
  */
 
 class AutoPushClipRect {
   nsRenderingContext& mCtx;
 public:
   AutoPushClipRect(nsRenderingContext& aCtx, const nsRect& aRect)
     : mCtx(aCtx) {
     mCtx.PushState();
-    mCtx.SetClipRect(aRect, nsClipCombine_kIntersect);
+    mCtx.IntersectClip(aRect);
   }
   ~AutoPushClipRect() {
     mCtx.PopState();
   }
 };
 
 static nsPoint
 SnapToDevPixels(const gfxContext* aThebesContext, PRInt32 aAppUnitsPerGfxUnit,
--- a/layout/svg/base/src/nsSVGIntegrationUtils.cpp
+++ b/layout/svg/base/src/nsSVGIntegrationUtils.cpp
@@ -291,18 +291,17 @@ nsSVGIntegrationUtils::PaintFramesWithEf
   gfxMatrix matrix = GetInitialMatrix(aEffectsFrame);
 
   PRBool complexEffects = PR_FALSE;
   /* Check if we need to do additional operations on this child's
    * rendering, which necessitates rendering into another surface. */
   if (opacity != 1.0f || maskFrame || (clipPathFrame && !isTrivialClip)) {
     complexEffects = PR_TRUE;
     gfx->Save();
-    aCtx->SetClipRect(aEffectsFrame->GetVisualOverflowRect(),
-                      nsClipCombine_kIntersect);
+    aCtx->IntersectClip(aEffectsFrame->GetVisualOverflowRect());
     gfx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
   }
 
   /* If this frame has only a trivial clipPath, set up cairo's clipping now so
    * we can just do normal painting and get it clipped appropriately.
    */
   if (clipPathFrame && isTrivialClip) {
     gfx->Save();
--- a/layout/svg/base/src/nsSVGOuterSVGFrame.cpp
+++ b/layout/svg/base/src/nsSVGOuterSVGFrame.cpp
@@ -547,17 +547,17 @@ nsSVGOuterSVGFrame::Paint(const nsDispla
   aRenderingContext.PushState();
 
   nsRect viewportRect = GetContentRect();
   nsPoint viewportOffset = aPt + viewportRect.TopLeft() - GetPosition();
   viewportRect.MoveTo(viewportOffset);
 
   nsRect clipRect;
   clipRect.IntersectRect(aDirtyRect, viewportRect);
-  aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
+  aRenderingContext.IntersectClip(clipRect);
   aRenderingContext.Translate(viewportRect.TopLeft());
   nsRect dirtyRect = clipRect - viewportOffset;
 
 #if defined(DEBUG) && defined(SVG_DEBUG_PAINT_TIMING)
   PRTime start = PR_Now();
 #endif
 
   nsIntRect dirtyPxRect = dirtyRect.ToOutsidePixels(PresContext()->AppUnitsPerDevPixel());
--- a/layout/xul/base/src/nsGroupBoxFrame.cpp
+++ b/layout/xul/base/src/nsGroupBoxFrame.cpp
@@ -191,46 +191,46 @@ nsGroupBoxFrame::PaintBorderBackground(n
     // to achieve the same effect.
 
     // draw left side
     nsRect clipRect(rect);
     clipRect.width = groupRect.x - rect.x;
     clipRect.height = border.top;
 
     aRenderingContext.PushState();
-    aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
+    aRenderingContext.IntersectClip(clipRect);
     nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
                                 aDirtyRect, rect, mStyleContext, skipSides);
 
     aRenderingContext.PopState();
 
 
     // draw right side
     clipRect = rect;
     clipRect.x = groupRect.XMost();
     clipRect.width = rect.XMost() - groupRect.XMost();
     clipRect.height = border.top;
 
     aRenderingContext.PushState();
-    aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
+    aRenderingContext.IntersectClip(clipRect);
     nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
                                 aDirtyRect, rect, mStyleContext, skipSides);
 
     aRenderingContext.PopState();
 
     
   
     // draw bottom
 
     clipRect = rect;
     clipRect.y += border.top;
     clipRect.height = mRect.height - (yoff + border.top);
   
     aRenderingContext.PushState();
-    aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
+    aRenderingContext.IntersectClip(clipRect);
     nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
                                 aDirtyRect, rect, mStyleContext, skipSides);
 
     aRenderingContext.PopState();
     
   } else {
     nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
                                 aDirtyRect, nsRect(aPt, GetSize()),
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
@@ -2818,17 +2818,17 @@ nsTreeBodyFrame::BuildDisplayList(nsDisp
 
 void
 nsTreeBodyFrame::PaintTreeBody(nsRenderingContext& aRenderingContext,
                                const nsRect& aDirtyRect, nsPoint aPt)
 {
   // Update our available height and our page count.
   CalcInnerBox();
   aRenderingContext.PushState();
-  aRenderingContext.SetClipRect(mInnerBox + aPt, nsClipCombine_kIntersect);
+  aRenderingContext.IntersectClip(mInnerBox + aPt);
   PRInt32 oldPageCount = mPageLength;
   if (!mHasFixedRowCount)
     mPageLength = mInnerBox.height/mRowHeight;
 
   if (oldPageCount != mPageLength || mHorzWidth != CalcHorzWidth(GetScrollParts())) {
     // Schedule a ResizeReflow that will update our info properly.
     PresContext()->PresShell()->
       FrameNeedsReflow(this, nsIPresShell::eResize, NS_FRAME_IS_DIRTY);