From e4a73a5b36974b850424868581748abbe5aba377 Mon Sep 17 00:00:00 2001 From: Parth Mudgal Date: Sat, 21 Jul 2012 16:07:30 -0400 Subject: [PATCH] Bug 753021 - Favicon shortcuts should be centered with a white background. r=bbondy --- widget/windows/WinUtils.cpp | 40 +++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/widget/windows/WinUtils.cpp b/widget/windows/WinUtils.cpp index c10a09f03687..5e2cec832807 100644 --- a/widget/windows/WinUtils.cpp +++ b/widget/windows/WinUtils.cpp @@ -24,6 +24,7 @@ #include "nsINetUtil.h" #include "nsIChannel.h" #include "nsIObserver.h" +#include "imgIEncoder.h" namespace mozilla { namespace widget { @@ -458,13 +459,14 @@ AsyncFaviconDataReady::OnComplete(nsIURI *aFaviconURI, if (mURLShortcut) { OnFaviconDataNotAvailable(); } + return NS_OK; } nsCOMPtr icoFile; nsresult rv = FaviconHelper::GetOutputIconPath(mNewURI, icoFile, mURLShortcut); - NS_ENSURE_SUCCESS(rv, rv); + nsAutoString path; rv = icoFile->GetPath(path); NS_ENSURE_SUCCESS(rv, rv); @@ -544,12 +546,38 @@ NS_IMETHODIMP AsyncWriteIconToDisk::Run() EmptyString(), getter_AddRefs(iconStream)); } else { - mMimeTypeOfInputData.AssignLiteral("image/vnd.microsoft.icon"); - rv = imgtool->EncodeImage(container, - mMimeTypeOfInputData, - NS_LITERAL_STRING("format=bmp;bpp=32"), - getter_AddRefs(iconStream)); + nsRefPtr s; + rv = container->GetFrame(imgIContainer::FRAME_FIRST, 0, getter_AddRefs(s)); + NS_ENSURE_SUCCESS(rv, rv); + + gfxImageSurface* surface = + new gfxImageSurface(gfxIntSize(48, 48), + gfxImageSurface::ImageFormatARGB32); + gfxContext context(surface); + context.SetOperator(gfxContext::OPERATOR_SOURCE); + context.SetColor(gfxRGBA(1, 1, 1, 1)); + context.Rectangle(gfxRect(0, 0, 48, 48)); + context.Fill(); + + context.Translate(gfxPoint(16, 16)); + context.SetOperator(gfxContext::OPERATOR_OVER); + context.DrawSurface(s, gfxSize(16, 16)); + gfxIntSize size = surface->GetSize(); + + nsRefPtr encoder = + do_CreateInstance("@mozilla.org/image/encoder;2?" + "type=image/vnd.microsoft.icon"); + NS_ENSURE_TRUE(encoder, NS_ERROR_FAILURE); + rv = encoder->InitFromData(surface->Data(), surface->Stride() * size.height, + size.width, size.height, surface->Stride(), + imgIEncoder::INPUT_FORMAT_HOSTARGB, EmptyString()); + NS_ENSURE_SUCCESS(rv, rv); + CallQueryInterface(encoder.get(), getter_AddRefs(iconStream)); + if (!iconStream) { + return NS_ERROR_FAILURE; + } } + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr icoFile = do_CreateInstance("@mozilla.org/file/local;1");