Bug 1307621 - Use the original size if the downloaded favicon is not big enough. r=sebastian draft
authorNevin Chen <cnevinchen@gmail.com>
Wed, 02 Nov 2016 16:27:14 +0800
changeset 432509 e8646f98fd91ae2954a137b380ee11c62e8d0bbe
parent 430701 944cb0fd05526894fcd90fbe7d1e625ee53cd73d
child 433140 ed6bd1c96770b52c6336e0aa38fedbf0ba2a7070
push id34341
push userbmo:cnevinchen@gmail.com
push dateWed, 02 Nov 2016 08:28:26 +0000
reviewerssebastian
bugs1307621
milestone52.0a1
Bug 1307621 - Use the original size if the downloaded favicon is not big enough. r=sebastian MozReview-Commit-ID: 53U8bjNDMOI
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -1948,30 +1948,55 @@ public abstract class GeckoApp
         // draw the overlay
         Bitmap overlay = BitmapUtils.decodeResource(this, R.drawable.home_bg);
         canvas.drawBitmap(overlay, null, new Rect(0, 0, size, size), null);
 
         // draw the favicon
         if (aSource == null)
             aSource = BitmapUtils.decodeResource(this, R.drawable.home_star);
 
-        // by default, we scale the icon to this size
+
+        //  use the original size if the downloaded favicon is not big enough. (bug 1307621)
+        if (aSource.getWidth() < insetSize || aSource.getHeight() < insetSize) {
+            drawCenter(aSource, size, canvas);
+
+        } else {
+
+            // by default, we scale the icon to this size
+            drawScaleToFill(aSource, size, insetSize, canvas);
+        }
+        return bitmap;
+    }
+
+    private void drawScaleToFill(Bitmap aSource, int size, int insetSize, Canvas canvas) {
+
         int sWidth = insetSize / 2;
         int sHeight = sWidth;
-
         int halfSize = size / 2;
+
         canvas.drawBitmap(aSource,
                 null,
                 new Rect(halfSize - sWidth,
                         halfSize - sHeight,
                         halfSize + sWidth,
                         halfSize + sHeight),
                 null);
-
-        return bitmap;
+    }
+
+    private void drawCenter(Bitmap aSource, int size, Canvas canvas) {
+
+        int left = size / 2 - aSource.getWidth() / 2;
+        int top = size / 2 - aSource.getHeight() / 2;
+        int right = left + aSource.getWidth();
+        int bottom = top + aSource.getHeight();
+
+        canvas.drawBitmap(aSource,
+                null,
+                new Rect(left, top, right, bottom),
+                null);
     }
 
     @Override
     protected void onNewIntent(Intent externalIntent) {
         final SafeIntent intent = new SafeIntent(externalIntent);
 
         final boolean isFirstTab = !mWasFirstTabShownAfterActivityUnhidden;
         mWasFirstTabShownAfterActivityUnhidden = true; // Reset since we'll be loading a tab.