diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index 7a8148d3969d..0497c0405a19 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -842,13 +842,16 @@ void nsCSSRendering::PaintBackground(nsIPresContext& aPresContext, nsSize imageSize; nsIImage* image = nsnull; nsIFrameImageLoader* loader = nsnull; - nsresult rv = aPresContext.LoadImage(aColor.mBackgroundImage, + PRBool transparentBG = NS_STYLE_BG_COLOR_TRANSPARENT == + (aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT); + nsresult rv = aPresContext.LoadImage(aColor.mBackgroundImage, transparentBG ? + nsnull : &aColor.mBackgroundColor, aForFrame, PR_FALSE, loader); if ((NS_OK != rv) || (nsnull == loader) || (loader->GetImage(image), (nsnull == image))) { NS_IF_RELEASE(loader); // Redraw will happen later - if (0 == (aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT)) { + if (!transparentBG) { aRenderingContext.SetColor(aColor.mBackgroundColor); aRenderingContext.FillRect(0, 0, aBounds.width, aBounds.height); } diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 15b4add6b323..6322a13226e3 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -259,6 +259,7 @@ nsPresContext::GetImageGroup(nsIImageGroup*& aGroupResult) NS_METHOD nsPresContext::LoadImage(const nsString& aURL, + const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, PRBool aNeedSizeUpdate, nsIFrameImageLoader*& aLoaderResult) @@ -315,7 +316,8 @@ nsPresContext::LoadImage(const nsString& aURL, // Return new loader NS_ADDREF(loader); - rv = loader->Init(this, mImageGroup, aURL, aTargetFrame, aNeedSizeUpdate); + rv = loader->Init(this, mImageGroup, aURL, aBackgroundColor, aTargetFrame, + aNeedSizeUpdate); if (NS_OK != rv) { return rv; } diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index a99f1f71b389..e99efdfa2bb4 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -21,6 +21,7 @@ #include "nslayout.h" #include "nsISupports.h" #include "nsRect.h" +#include "nsColor.h" struct nsFont; @@ -102,15 +103,21 @@ public: /** * Load an image for the target frame. This call can be made - * repeated with only a single image every being loaded. If - * aNeedSizeUpdate is PR_TRUE then when the image's size is + * repeated with only a single image ever being loaded. If + * aNeedSizeUpdate is PR_TRUE, then when the image's size is * determined the target frame will be reflowed (via a * ContentChanged notification on the presentation shell). When the - * image's data is ready for rendering the target frames Paint - * method will be invoked (via the ViewManager so that the - * appropriate damage repair is done). + * image's data is ready for rendering the target frame's Paint() + * method will be invoked (via the ViewManager) so that the + * appropriate damage repair is done. + * + * @param aBackgroundColor - If the background color is NULL, a mask + * will be generated for transparent images. If the background + * color is non-NULL, it indicates the RGB value to be folded + * into the transparent areas of the image and no mask is created. */ NS_IMETHOD LoadImage(const nsString& aURL, + const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, PRBool aNeedSizeUpdate, nsIFrameImageLoader*& aLoader) = 0; diff --git a/layout/base/public/nsIFrameImageLoader.h b/layout/base/public/nsIFrameImageLoader.h index e09fc889bf0f..4ba424e7912c 100644 --- a/layout/base/public/nsIFrameImageLoader.h +++ b/layout/base/public/nsIFrameImageLoader.h @@ -20,6 +20,7 @@ #include "nslayout.h" #include "nsIImageObserver.h" +#include "nscolor.h" class nsIFrame; class nsIImage; class nsIImageGroup; @@ -43,6 +44,7 @@ public: NS_IMETHOD Init(nsIPresContext* aPresContext, nsIImageGroup* aGroup, const nsString& aURL, + const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, PRBool aNeedSizeUpdate) = 0; diff --git a/layout/base/public/nsIPresContext.h b/layout/base/public/nsIPresContext.h index a99f1f71b389..e99efdfa2bb4 100644 --- a/layout/base/public/nsIPresContext.h +++ b/layout/base/public/nsIPresContext.h @@ -21,6 +21,7 @@ #include "nslayout.h" #include "nsISupports.h" #include "nsRect.h" +#include "nsColor.h" struct nsFont; @@ -102,15 +103,21 @@ public: /** * Load an image for the target frame. This call can be made - * repeated with only a single image every being loaded. If - * aNeedSizeUpdate is PR_TRUE then when the image's size is + * repeated with only a single image ever being loaded. If + * aNeedSizeUpdate is PR_TRUE, then when the image's size is * determined the target frame will be reflowed (via a * ContentChanged notification on the presentation shell). When the - * image's data is ready for rendering the target frames Paint - * method will be invoked (via the ViewManager so that the - * appropriate damage repair is done). + * image's data is ready for rendering the target frame's Paint() + * method will be invoked (via the ViewManager) so that the + * appropriate damage repair is done. + * + * @param aBackgroundColor - If the background color is NULL, a mask + * will be generated for transparent images. If the background + * color is non-NULL, it indicates the RGB value to be folded + * into the transparent areas of the image and no mask is created. */ NS_IMETHOD LoadImage(const nsString& aURL, + const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, PRBool aNeedSizeUpdate, nsIFrameImageLoader*& aLoader) = 0; diff --git a/layout/base/public/nsPresContext.h b/layout/base/public/nsPresContext.h index a99f1f71b389..e99efdfa2bb4 100644 --- a/layout/base/public/nsPresContext.h +++ b/layout/base/public/nsPresContext.h @@ -21,6 +21,7 @@ #include "nslayout.h" #include "nsISupports.h" #include "nsRect.h" +#include "nsColor.h" struct nsFont; @@ -102,15 +103,21 @@ public: /** * Load an image for the target frame. This call can be made - * repeated with only a single image every being loaded. If - * aNeedSizeUpdate is PR_TRUE then when the image's size is + * repeated with only a single image ever being loaded. If + * aNeedSizeUpdate is PR_TRUE, then when the image's size is * determined the target frame will be reflowed (via a * ContentChanged notification on the presentation shell). When the - * image's data is ready for rendering the target frames Paint - * method will be invoked (via the ViewManager so that the - * appropriate damage repair is done). + * image's data is ready for rendering the target frame's Paint() + * method will be invoked (via the ViewManager) so that the + * appropriate damage repair is done. + * + * @param aBackgroundColor - If the background color is NULL, a mask + * will be generated for transparent images. If the background + * color is non-NULL, it indicates the RGB value to be folded + * into the transparent areas of the image and no mask is created. */ NS_IMETHOD LoadImage(const nsString& aURL, + const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, PRBool aNeedSizeUpdate, nsIFrameImageLoader*& aLoader) = 0; diff --git a/layout/base/src/nsFrameImageLoader.cpp b/layout/base/src/nsFrameImageLoader.cpp index 35ba0906bb8d..956ac634a250 100644 --- a/layout/base/src/nsFrameImageLoader.cpp +++ b/layout/base/src/nsFrameImageLoader.cpp @@ -103,6 +103,7 @@ nsresult nsFrameImageLoader::Init(nsIPresContext* aPresContext, nsIImageGroup* aGroup, const nsString& aURL, + const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, PRBool aNeedSizeUpdate) { @@ -131,6 +132,7 @@ nsFrameImageLoader::Init(nsIPresContext* aPresContext, cp ? cp : "(null)", mTargetFrame, mImageLoadStatus)); // Start image load request + // XXX Use aBackgroundColor nscolor bgcolor = NS_RGB(255,255,255); mImageRequest = aGroup->GetImage(cp, this, &bgcolor, 0, 0, 0); delete cp; diff --git a/layout/base/src/nsFrameImageLoader.h b/layout/base/src/nsFrameImageLoader.h index 088767a595db..bf7a8a1b59c8 100644 --- a/layout/base/src/nsFrameImageLoader.h +++ b/layout/base/src/nsFrameImageLoader.h @@ -21,6 +21,7 @@ #include "nsIFrameImageLoader.h" #include "nsSize.h" #include "nsString.h" +#include "nscolor.h" /** * An image loader for frame's. @@ -44,6 +45,7 @@ public: NS_IMETHOD Init(nsIPresContext* aPresContext, nsIImageGroup* aGroup, const nsString& aURL, + const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, PRBool aNeedSizeUpdate); NS_IMETHOD StopImageLoad(); diff --git a/layout/base/src/nsPresContext.cpp b/layout/base/src/nsPresContext.cpp index 15b4add6b323..6322a13226e3 100644 --- a/layout/base/src/nsPresContext.cpp +++ b/layout/base/src/nsPresContext.cpp @@ -259,6 +259,7 @@ nsPresContext::GetImageGroup(nsIImageGroup*& aGroupResult) NS_METHOD nsPresContext::LoadImage(const nsString& aURL, + const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, PRBool aNeedSizeUpdate, nsIFrameImageLoader*& aLoaderResult) @@ -315,7 +316,8 @@ nsPresContext::LoadImage(const nsString& aURL, // Return new loader NS_ADDREF(loader); - rv = loader->Init(this, mImageGroup, aURL, aTargetFrame, aNeedSizeUpdate); + rv = loader->Init(this, mImageGroup, aURL, aBackgroundColor, aTargetFrame, + aNeedSizeUpdate); if (NS_OK != rv) { return rv; } diff --git a/layout/base/src/nsPresContext.h b/layout/base/src/nsPresContext.h index bfd30c27c03d..0fc1ac65978f 100644 --- a/layout/base/src/nsPresContext.h +++ b/layout/base/src/nsPresContext.h @@ -47,6 +47,7 @@ public: virtual const nsFont& GetDefaultFont(void); NS_IMETHOD GetImageGroup(nsIImageGroup*& aGroupResult); NS_IMETHOD LoadImage(const nsString& aURL, + const nscolor* aBackgroundColor, nsIFrame* aTargetFrame, PRBool aNeedSizeUpdate, nsIFrameImageLoader*& aLoader); diff --git a/layout/html/base/src/nsHTMLImage.cpp b/layout/html/base/src/nsHTMLImage.cpp index 71642ec497ef..1070d82fc9bf 100644 --- a/layout/html/base/src/nsHTMLImage.cpp +++ b/layout/html/base/src/nsHTMLImage.cpp @@ -209,8 +209,9 @@ nsHTMLImageLoader::LoadImage(nsIPresContext* aPresContext, } if (nsnull == mImageLoader) { - // Start image loading - rv = aPresContext->LoadImage(src, aForFrame, aNeedSizeUpdate, + // Start image loading. Note that we don't specify a background color + // so transparent images are always rendered using a transparency mask + rv = aPresContext->LoadImage(src, nsnull, aForFrame, aNeedSizeUpdate, mImageLoader); if (NS_OK != rv) { return rv; diff --git a/layout/html/style/src/nsCSSRendering.cpp b/layout/html/style/src/nsCSSRendering.cpp index 7a8148d3969d..0497c0405a19 100644 --- a/layout/html/style/src/nsCSSRendering.cpp +++ b/layout/html/style/src/nsCSSRendering.cpp @@ -842,13 +842,16 @@ void nsCSSRendering::PaintBackground(nsIPresContext& aPresContext, nsSize imageSize; nsIImage* image = nsnull; nsIFrameImageLoader* loader = nsnull; - nsresult rv = aPresContext.LoadImage(aColor.mBackgroundImage, + PRBool transparentBG = NS_STYLE_BG_COLOR_TRANSPARENT == + (aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT); + nsresult rv = aPresContext.LoadImage(aColor.mBackgroundImage, transparentBG ? + nsnull : &aColor.mBackgroundColor, aForFrame, PR_FALSE, loader); if ((NS_OK != rv) || (nsnull == loader) || (loader->GetImage(image), (nsnull == image))) { NS_IF_RELEASE(loader); // Redraw will happen later - if (0 == (aColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT)) { + if (!transparentBG) { aRenderingContext.SetColor(aColor.mBackgroundColor); aRenderingContext.FillRect(0, 0, aBounds.width, aBounds.height); }