Bug 1293043 - Do not shrink favicons down to 16x16. r=aklotz
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 23 Feb 2019 13:32:12 +0900
changeset 461376 13b55e07553224d3990469466e9d3ea5163813aa
parent 461375 20be3ebad986451e4b1645a5e5a6106b35c9f1e3
child 461377 62b4b842eda6a8e9eb6d04252c94cee31e4047a2
push id35622
push userncsoregi@mozilla.com
push dateWed, 27 Feb 2019 04:32:15 +0000
treeherdermozilla-central@5b8896aa3f69 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1293043
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1293043 - Do not shrink favicons down to 16x16. r=aklotz By this change, icons will never be shrunk to a smaller size. Windows will do it appropriately. Internet Explorer's icon handler will not paint the white background if the icon is large enough. I'm also replicating the behavior.
widget/windows/WinUtils.cpp
--- a/widget/windows/WinUtils.cpp
+++ b/widget/windows/WinUtils.cpp
@@ -1188,20 +1188,21 @@ AsyncFaviconDataReady::OnComplete(nsIURI
   RefPtr<SourceSurface> surface = container->GetFrame(
       imgIContainer::FRAME_FIRST,
       imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY);
   NS_ENSURE_TRUE(surface, NS_ERROR_FAILURE);
 
   RefPtr<DataSourceSurface> dataSurface;
   IntSize size;
 
-  if (mURLShortcut) {
-    // Create a 48x48 surface and paint the icon into the central 16x16 rect.
-    size.width = 48;
-    size.height = 48;
+  if (mURLShortcut &&
+      (surface->GetSize().width < 48 || surface->GetSize().height < 48)) {
+    // Create a 48x48 surface and paint the icon into the central rect.
+    size.width = std::max(surface->GetSize().width, 48);
+    size.height = std::max(surface->GetSize().height, 48);
     dataSurface =
         Factory::CreateDataSourceSurface(size, SurfaceFormat::B8G8R8A8);
     NS_ENSURE_TRUE(dataSurface, NS_ERROR_FAILURE);
 
     DataSourceSurface::MappedSurface map;
     if (!dataSurface->Map(DataSourceSurface::MapType::WRITE, &map)) {
       return NS_ERROR_FAILURE;
     }
@@ -1211,17 +1212,22 @@ AsyncFaviconDataReady::OnComplete(nsIURI
         dataSurface->GetFormat());
     if (!dt) {
       gfxWarning() << "AsyncFaviconDataReady::OnComplete failed in "
                       "CreateDrawTargetForData";
       return NS_ERROR_OUT_OF_MEMORY;
     }
     dt->FillRect(Rect(0, 0, size.width, size.height),
                  ColorPattern(Color(1.0f, 1.0f, 1.0f, 1.0f)));
-    dt->DrawSurface(surface, Rect(16, 16, 16, 16),
+    IntPoint point;
+    point.x = (size.width - surface->GetSize().width) / 2;
+    point.y = (size.height - surface->GetSize().height) / 2;
+    dt->DrawSurface(surface,
+                    Rect(point.x, point.y, surface->GetSize().width,
+                         surface->GetSize().height),
                     Rect(Point(0, 0), Size(surface->GetSize().width,
                                            surface->GetSize().height)));
 
     dataSurface->Unmap();
   } else {
     // By using the input image surface's size, we may end up encoding
     // to a different size than a 16x16 (or bigger for higher DPI) ICO, but
     // Windows will resize appropriately for us. If we want to encode ourselves