Bug 664127 - Allow to set opacity on ::-moz-tree-image.
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 23 Jun 2011 14:35:07 +0200
changeset 71879 ed60c3abdb71e54383257e8ff16bd1a69c295377
parent 71861 e00de9b8df15e5e2a5ea4a92c4e09ad044e15815
child 71880 26bda006334c3603faec1876f392f940f2bd787d
push idunknown
push userunknown
push dateunknown
bugs664127
milestone7.0a1
Bug 664127 - Allow to set opacity on ::-moz-tree-image. r=roc
layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
@@ -3388,16 +3388,19 @@ nsTreeBodyFrame::PaintImage(PRInt32     
 {
   NS_PRECONDITION(aColumn && aColumn->GetFrame(), "invalid column passed");
 
   PRBool isRTL = GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL;
   nscoord rightEdge = aCurrX + aRemainingWidth;
   // Resolve style for the image.
   nsStyleContext* imageContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreeimage);
 
+  // Obtain opacity value for the image.
+  float opacity = imageContext->GetStyleDisplay()->mOpacity;
+
   // Obtain the margins for the image and then deflate our rect by that
   // amount.  The image is assumed to be contained within the deflated rect.
   nsRect imageRect(aImageRect);
   nsMargin imageMargin;
   imageContext->GetStyleMargin()->GetMargin(imageMargin);
   imageRect.Deflate(imageMargin);
 
   // Get the image.
@@ -3494,20 +3497,30 @@ nsTreeBodyFrame::PaintImage(PRInt32     
     // width and height.
     nsIntSize rawImageSize;
     image->GetWidth(&rawImageSize.width);
     image->GetHeight(&rawImageSize.height);
     nsRect wholeImageDest =
       nsLayoutUtils::GetWholeImageDestination(rawImageSize, sourceRect,
           nsRect(destRect.TopLeft(), imageDestSize));
 
+    gfxContext* ctx = aRenderingContext.ThebesContext();
+    if (opacity != 1.0f) {
+      ctx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
+    }
+
     nsLayoutUtils::DrawImage(&aRenderingContext, image,
         nsLayoutUtils::GetGraphicsFilterForFrame(this),
         wholeImageDest, destRect, destRect.TopLeft(), aDirtyRect,
         imgIContainer::FLAG_NONE);
+
+    if (opacity != 1.0f) {
+      ctx->PopGroupToSource();
+      ctx->Paint(opacity);
+    }
   }
 
   // Update the aRemainingWidth and aCurrX values.
   imageRect.Inflate(imageMargin);
   aRemainingWidth -= imageRect.width;
   if (!isRTL)
     aCurrX += imageRect.width;
 }