Bug 1018994 - Remove favicon from the url bar. r?mcomella draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Thu, 11 Feb 2016 15:39:03 +0100
changeset 330339 eeffe2c565ea0fe9bd59360c52f0f416558bb6db
parent 330126 7f9f6cc8991de19a0bc932cdb9d717a7df444f27
child 330340 5ce795b1bf953f7cb97587ac8c9f00602990775c
push id10737
push users.kaspari@gmail.com
push dateThu, 11 Feb 2016 15:04:24 +0000
reviewersmcomella
bugs1018994
milestone47.0a1
Bug 1018994 - Remove favicon from the url bar. r?mcomella MozReview-Commit-ID: AuTLg1ViI8r
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
mobile/android/base/resources/drawable-large-v11/site_security_level.xml
mobile/android/base/resources/drawable-large-v11/site_security_unknown.xml
mobile/android/base/resources/drawable/site_security_level.xml
mobile/android/base/resources/drawable/site_security_unknown.xml
mobile/android/base/resources/layout/browser_toolbar.xml
mobile/android/base/resources/layout/toolbar_display_layout.xml
mobile/android/base/resources/values/dimens.xml
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
@@ -5,38 +5,34 @@
 
 package org.mozilla.gecko.toolbar;
 
 import java.util.Arrays;
 import java.util.EnumSet;
 import java.util.List;
 
 import org.mozilla.gecko.AboutPages;
-import org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.BrowserApp;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.ReaderModeUtils;
 import org.mozilla.gecko.SiteIdentity;
 import org.mozilla.gecko.SiteIdentity.MixedMode;
 import org.mozilla.gecko.SiteIdentity.SecurityMode;
 import org.mozilla.gecko.SiteIdentity.TrackingMode;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.ViewHelper;
-import org.mozilla.gecko.favicons.Favicons;
 import org.mozilla.gecko.toolbar.BrowserToolbarTabletBase.ForwardButtonAnimation;
 import org.mozilla.gecko.util.ColorUtils;
-import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.StringUtils;
 import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
 import org.mozilla.gecko.widget.themed.ThemedTextView;
 
 import android.content.Context;
 import android.content.res.Resources;
-import android.graphics.Bitmap;
 import android.os.SystemClock;
 import android.text.Spannable;
 import android.text.SpannableStringBuilder;
 import android.text.TextUtils;
 import android.text.style.ForegroundColorSpan;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.LayoutInflater;
@@ -103,22 +99,16 @@ public class ToolbarDisplayLayout extend
     private boolean mIsAttached;
 
     private final ThemedTextView mTitle;
     private final int mTitlePadding;
     private ToolbarPrefs mPrefs;
     private OnTitleChangeListener mTitleChangeListener;
 
     private final ImageButton mSiteSecurity;
-    private boolean mSiteSecurityVisible;
-
-    // To de-bounce sets.
-    private Bitmap mLastFavicon;
-    private final ImageButton mFavicon;
-    private int mFaviconSize;
 
     private final ImageButton mStop;
     private OnStopListener mStopListener;
 
     private final PageActionLayout mPageActionLayout;
 
     private AlphaAnimation mLockFadeIn;
     private TranslateAnimation mTitleSlideLeft;
@@ -158,65 +148,46 @@ public class ToolbarDisplayLayout extend
 
         final Resources res = getResources();
 
         mUrlColor = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_urltext));
         mBlockedColor = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_blockedtext));
         mDomainColor = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_domaintext));
         mPrivateDomainColor = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_domaintext_private));
 
-        mFavicon = (ImageButton) findViewById(R.id.favicon);
         mSiteSecurity = (ImageButton) findViewById(R.id.site_security);
 
-        if (HardwareUtils.isTablet()) {
-            mSiteSecurity.setVisibility(View.VISIBLE);
-
-            // We don't show favicons in the toolbar on new tablet. Note that while we could
-            // null the favicon reference, we don't do so to avoid excessive null-checking.
-            removeView(mFavicon);
-        } else {
-            if (Versions.feature16Plus) {
-                mFavicon.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
-            }
-            mFaviconSize = Math.round(Favicons.browserToolbarFaviconSize);
-        }
-
-        mSiteSecurityVisible = (mSiteSecurity.getVisibility() == View.VISIBLE);
-
         mSiteIdentityPopup = new SiteIdentityPopup(mActivity);
         mSiteIdentityPopup.setAnchor(this);
         mSiteIdentityPopup.setOnVisibilityChangeListener(mActivity);
 
         mStop = (ImageButton) findViewById(R.id.stop);
         mPageActionLayout = (PageActionLayout) findViewById(R.id.page_action_layout);
     }
 
     @Override
     public void onAttachedToWindow() {
         mIsAttached = true;
 
-        Button.OnClickListener faviconListener = new Button.OnClickListener() {
+        mSiteSecurity.setOnClickListener(new Button.OnClickListener() {
             @Override
             public void onClick(View view) {
                 mSiteIdentityPopup.show();
             }
-        };
-
-        mFavicon.setOnClickListener(faviconListener);
-        mSiteSecurity.setOnClickListener(faviconListener);
+        });
 
         mStop.setOnClickListener(new Button.OnClickListener() {
             @Override
             public void onClick(View v) {
                 if (mStopListener != null) {
                     // Force toolbar to switch to Display mode
                     // immediately based on the stopped tab.
                     final Tab tab = mStopListener.onStop();
                     if (tab != null) {
-                        updateUiMode(UIMode.DISPLAY, EnumSet.noneOf(UpdateFlags.class));
+                        updateUiMode(UIMode.DISPLAY);
                     }
                 }
             }
         });
 
         float slideWidth = getResources().getDimension(R.dimen.browser_toolbar_site_security_width);
 
         LayoutParams siteSecParams = (LayoutParams) mSiteSecurity.getLayoutParams();
@@ -242,18 +213,17 @@ public class ToolbarDisplayLayout extend
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
         mIsAttached = false;
     }
 
     @Override
     public void onAnimationStart(Animation animation) {
         if (animation.equals(mLockFadeIn)) {
-            if (mSiteSecurityVisible)
-                mSiteSecurity.setVisibility(View.VISIBLE);
+            mSiteSecurity.setVisibility(View.VISIBLE);
         } else if (animation.equals(mTitleSlideLeft)) {
             // These two animations may be scheduled to start while the forward
             // animation is occurring. If we're showing the site security icon, make
             // sure it doesn't take any space during the forward transition.
             mSiteSecurity.setVisibility(View.GONE);
         } else if (animation.equals(mTitleSlideRight)) {
             // If we're hiding the icon, make sure that we keep its padding
             // in place during the forward transition
@@ -269,17 +239,16 @@ public class ToolbarDisplayLayout extend
     public void onAnimationEnd(Animation animation) {
         if (animation.equals(mTitleSlideRight)) {
             mSiteSecurity.startAnimation(mLockFadeIn);
         }
     }
 
     @Override
     public void setNextFocusDownId(int nextId) {
-        mFavicon.setNextFocusDownId(nextId);
         mStop.setNextFocusDownId(nextId);
         mSiteSecurity.setNextFocusDownId(nextId);
         mPageActionLayout.setNextFocusDownId(nextId);
     }
 
     void setToolbarPrefs(final ToolbarPrefs prefs) {
         mPrefs = prefs;
     }
@@ -290,26 +259,22 @@ public class ToolbarDisplayLayout extend
         if (!mIsAttached) {
             return;
         }
 
         if (flags.contains(UpdateFlags.TITLE)) {
             updateTitle(tab);
         }
 
-        if (flags.contains(UpdateFlags.FAVICON)) {
-            updateFavicon(tab);
-        }
-
         if (flags.contains(UpdateFlags.SITE_IDENTITY)) {
-            updateSiteIdentity(tab, flags);
+            updateSiteIdentity(tab);
         }
 
         if (flags.contains(UpdateFlags.PROGRESS)) {
-            updateProgress(tab, flags);
+            updateProgress(tab);
         }
 
         if (flags.contains(UpdateFlags.PRIVATE_MODE)) {
             mTitle.setPrivateMode(tab != null && tab.isPrivate());
         }
     }
 
     void setTitle(CharSequence title) {
@@ -375,48 +340,17 @@ public class ToolbarDisplayLayout extend
     private String stripAboutReaderURL(final String url) {
         if (!AboutPages.isAboutReader(url)) {
             return url;
         }
 
         return ReaderModeUtils.getUrlFromAboutReader(url);
     }
 
-    private void updateFavicon(Tab tab) {
-        if (HardwareUtils.isTablet()) {
-            // We don't display favicons in the toolbar on tablet.
-            return;
-        }
-
-        if (tab == null) {
-            mFavicon.setImageDrawable(null);
-            return;
-        }
-
-        Bitmap image = tab.getFavicon();
-
-        if (image != null && image == mLastFavicon) {
-            Log.d(LOGTAG, "Ignoring favicon: new image is identical to previous one.");
-            return;
-        }
-
-        // Cache the original so we can debounce without scaling
-        mLastFavicon = image;
-
-        Log.d(LOGTAG, "updateFavicon(" + image + ")");
-
-        if (image != null) {
-            image = Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, false);
-            mFavicon.setImageBitmap(image);
-        } else {
-            mFavicon.setImageResource(R.drawable.favicon_globe);
-        }
-    }
-
-    private void updateSiteIdentity(Tab tab, EnumSet<UpdateFlags> flags) {
+    private void updateSiteIdentity(Tab tab) {
         final SiteIdentity siteIdentity;
         if (tab == null) {
             siteIdentity = null;
         } else {
             siteIdentity = tab.getSiteIdentity();
         }
 
         mSiteIdentityPopup.setSiteIdentity(siteIdentity);
@@ -463,102 +397,64 @@ public class ToolbarDisplayLayout extend
             imageLevel = LEVEL_LOCK_DISABLED;
         } else if (displayMixedMode == MixedMode.MIXED_CONTENT_LOADED) {
             imageLevel = LEVEL_WARNING_MINOR;
         }
 
         if (mSecurityImageLevel != imageLevel) {
             mSecurityImageLevel = imageLevel;
             mSiteSecurity.setImageLevel(mSecurityImageLevel);
-            updatePageActions(flags);
+            updatePageActions();
         }
 
         mTrackingProtectionEnabled = trackingMode == TrackingMode.TRACKING_CONTENT_BLOCKED;
     }
 
-    private void updateProgress(Tab tab, EnumSet<UpdateFlags> flags) {
+    private void updateProgress(Tab tab) {
         final boolean shouldShowThrobber = (tab != null &&
                                             tab.getState() == Tab.STATE_LOADING);
 
-        updateUiMode(shouldShowThrobber ? UIMode.PROGRESS : UIMode.DISPLAY, flags);
+        updateUiMode(shouldShowThrobber ? UIMode.PROGRESS : UIMode.DISPLAY);
 
         if (Tab.STATE_SUCCESS == tab.getState() && mTrackingProtectionEnabled) {
             mActivity.showTrackingProtectionPromptIfApplicable();
         }
     }
 
-    private void updateUiMode(UIMode uiMode, EnumSet<UpdateFlags> flags) {
+    private void updateUiMode(UIMode uiMode) {
         if (mUiMode == uiMode) {
             return;
         }
 
         mUiMode = uiMode;
 
         // The "Throbber start" and "Throbber stop" log messages in this method
         // are needed by S1/S2 tests (http://mrcote.info/phonedash/#).
         // See discussion in Bug 804457. Bug 805124 tracks paring these down.
         if (mUiMode == UIMode.PROGRESS) {
             Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - Throbber start");
         } else {
             Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - Throbber stop");
         }
 
-        updatePageActions(flags);
+        updatePageActions();
     }
 
-    private void updatePageActions(EnumSet<UpdateFlags> flags) {
+    private void updatePageActions() {
         final boolean isShowingProgress = (mUiMode == UIMode.PROGRESS);
 
         mStop.setVisibility(isShowingProgress ? View.VISIBLE : View.GONE);
         mPageActionLayout.setVisibility(!isShowingProgress ? View.VISIBLE : View.GONE);
 
-        boolean shouldShowSiteSecurity = (!isShowingProgress && mSecurityImageLevel > 0);
-
-        setSiteSecurityVisibility(shouldShowSiteSecurity, flags);
-
         // We want title to fill the whole space available for it when there are icons
         // being shown on the right side of the toolbar as the icons already have some
         // padding in them. This is just to avoid wasting space when icons are shown.
         mTitle.setPadding(0, 0, (!isShowingProgress ? mTitlePadding : 0), 0);
     }
 
-    private void setSiteSecurityVisibility(boolean visible, EnumSet<UpdateFlags> flags) {
-        // We don't hide site security on tablet.
-        if (visible == mSiteSecurityVisible || HardwareUtils.isTablet()) {
-            return;
-        }
-
-        mSiteSecurityVisible = visible;
-
-        mTitle.clearAnimation();
-        mSiteSecurity.clearAnimation();
-
-        if (flags.contains(UpdateFlags.DISABLE_ANIMATIONS)) {
-            mSiteSecurity.setVisibility(visible ? View.VISIBLE : View.GONE);
-            return;
-        }
-
-        // If any of these animations were cancelled as a result of the
-        // clearAnimation() calls above, we need to reset them.
-        mLockFadeIn.reset();
-        mTitleSlideLeft.reset();
-        mTitleSlideRight.reset();
-
-        if (mForwardAnim != null) {
-            long delay = mForwardAnim.getRemainingTime();
-            mTitleSlideRight.setStartOffset(delay);
-            mTitleSlideLeft.setStartOffset(delay);
-        } else {
-            mTitleSlideRight.setStartOffset(0);
-            mTitleSlideLeft.setStartOffset(0);
-        }
-
-        mTitle.startAnimation(visible ? mTitleSlideRight : mTitleSlideLeft);
-    }
-
     List<View> getFocusOrder() {
         return Arrays.asList(mSiteSecurity, mPageActionLayout, mStop);
     }
 
     void setOnStopListener(OnStopListener listener) {
         mStopListener = listener;
     }
 
@@ -581,45 +477,37 @@ public class ToolbarDisplayLayout extend
         mForwardAnim = anim;
 
         if (animation == ForwardButtonAnimation.HIDE) {
             // We animate these items individually, rather than this entire view,
             // so that we don't animate certain views, e.g. the stop button.
             anim.attach(mTitle,
                         PropertyAnimator.Property.TRANSLATION_X,
                         0);
-            anim.attach(mFavicon,
-                        PropertyAnimator.Property.TRANSLATION_X,
-                        0);
             anim.attach(mSiteSecurity,
                         PropertyAnimator.Property.TRANSLATION_X,
                         0);
 
             // We're hiding the forward button. We're going to reset the margin before
             // the animation starts, so we shift these items to the right so that they don't
             // appear to move initially.
             ViewHelper.setTranslationX(mTitle, width);
-            ViewHelper.setTranslationX(mFavicon, width);
             ViewHelper.setTranslationX(mSiteSecurity, width);
         } else {
             anim.attach(mTitle,
                         PropertyAnimator.Property.TRANSLATION_X,
                         width);
-            anim.attach(mFavicon,
-                        PropertyAnimator.Property.TRANSLATION_X,
-                        width);
             anim.attach(mSiteSecurity,
                         PropertyAnimator.Property.TRANSLATION_X,
                         width);
         }
     }
 
     void finishForwardAnimation() {
         ViewHelper.setTranslationX(mTitle, 0);
-        ViewHelper.setTranslationX(mFavicon, 0);
         ViewHelper.setTranslationX(mSiteSecurity, 0);
 
         mForwardAnim = null;
     }
 
     void prepareStartEditingAnimation() {
         // Hide page actions/stop buttons immediately
         ViewHelper.setAlpha(mPageActionLayout, 0);
deleted file mode 100644
--- a/mobile/android/base/resources/drawable-large-v11/site_security_level.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- This Source Code Form is subject to the terms of the Mozilla Public
-   - License, v. 2.0. If a copy of the MPL was not distributed with this
-   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
-
-<level-list xmlns:android="http://schemas.android.com/apk/res/android">
-
-    <item android:maxLevel="0" android:drawable="@drawable/site_security_unknown"/>
-    <item android:maxLevel="1" android:drawable="@drawable/lock_secure"/>
-    <item android:maxLevel="2" android:drawable="@drawable/lock_secure"/>
-    <item android:maxLevel="3" android:drawable="@drawable/warning_minor"/>
-    <item android:maxLevel="4" android:drawable="@drawable/lock_disabled"/>
-    <item android:maxLevel="5" android:drawable="@drawable/shield_enabled"/>
-    <item android:maxLevel="6" android:drawable="@drawable/shield_disabled"/>
-
-</level-list>
--- a/mobile/android/base/resources/drawable/site_security_level.xml
+++ b/mobile/android/base/resources/drawable/site_security_level.xml
@@ -1,16 +1,16 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <level-list xmlns:android="http://schemas.android.com/apk/res/android">
 
-    <item android:maxLevel="0" android:drawable="@android:color/transparent"/>
+    <item android:maxLevel="0" android:drawable="@drawable/site_security_unknown"/>
     <item android:maxLevel="1" android:drawable="@drawable/lock_secure"/>
     <item android:maxLevel="2" android:drawable="@drawable/lock_secure"/>
     <item android:maxLevel="3" android:drawable="@drawable/warning_minor"/>
     <item android:maxLevel="4" android:drawable="@drawable/lock_disabled"/>
     <item android:maxLevel="5" android:drawable="@drawable/shield_enabled"/>
     <item android:maxLevel="6" android:drawable="@drawable/shield_disabled"/>
 
 </level-list>
rename from mobile/android/base/resources/drawable-large-v11/site_security_unknown.xml
rename to mobile/android/base/resources/drawable/site_security_unknown.xml
--- a/mobile/android/base/resources/layout/browser_toolbar.xml
+++ b/mobile/android/base/resources/layout/browser_toolbar.xml
@@ -101,12 +101,12 @@
                   android:visibility="invisible"
                   android:paddingLeft="8dp"
                   android:paddingRight="8dp"/>
 
     <org.mozilla.gecko.toolbar.ToolbarDisplayLayout android:id="@+id/display_layout"
                   style="@style/UrlBar.Button"
                   android:layout_alignLeft="@id/url_bar_entry"
                   android:layout_alignRight="@id/url_bar_entry"
-                  android:paddingLeft="8dip"
+                  android:paddingLeft="1dip"
                   android:paddingRight="4dip"/>
 
 </merge>
--- a/mobile/android/base/resources/layout/toolbar_display_layout.xml
+++ b/mobile/android/base/resources/layout/toolbar_display_layout.xml
@@ -1,23 +1,16 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <merge xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:gecko="http://schemas.android.com/apk/res-auto">
 
-    <ImageButton android:id="@+id/favicon"
-                 style="@style/UrlBar.ImageButton"
-                 android:layout_width="@dimen/browser_toolbar_favicon_size"
-                 android:scaleType="fitCenter"
-                 android:paddingRight="4dip"
-                 android:layout_gravity="center_vertical"/>
-
     <!-- The site security icon is misaligned with the page title so
          we add a bottom margin to align their bottoms.
          Site security icon must have exact position and size as search icon in
          edit layout -->
     <ImageButton android:id="@+id/site_security"
                  style="@style/UrlBar.ImageButton"
                  android:layout_width="@dimen/browser_toolbar_site_security_width"
                  android:layout_height="@dimen/browser_toolbar_site_security_height"
@@ -25,17 +18,17 @@
                  android:layout_marginRight="@dimen/browser_toolbar_site_security_margin_right"
                  android:layout_marginBottom="@dimen/browser_toolbar_site_security_margin_bottom"
                  android:paddingLeft="@dimen/browser_toolbar_site_security_padding_horizontal"
                  android:paddingRight="@dimen/browser_toolbar_site_security_padding_horizontal"
                  android:paddingTop="@dimen/browser_toolbar_site_security_padding_vertical"
                  android:paddingBottom="@dimen/browser_toolbar_site_security_padding_vertical"
                  android:src="@drawable/site_security_level"
                  android:contentDescription="@string/site_security"
-                 android:visibility="gone"/>
+                 android:layout_gravity="center_vertical" />
 
     <org.mozilla.gecko.widget.FadedMultiColorTextView
             android:id="@+id/url_bar_title"
             style="@style/UrlBar.Title"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_weight="1.0"
             gecko:fadeWidth="40dip"
--- a/mobile/android/base/resources/values/dimens.xml
+++ b/mobile/android/base/resources/values/dimens.xml
@@ -63,21 +63,21 @@
     <dimen name="firstrun_brand_size">48dp</dimen>
     <dimen name="firstrun_background_height">180dp</dimen>
 
     <dimen name="overlay_prompt_content_width">260dp</dimen>
     <dimen name="overlay_prompt_button_width">148dp</dimen>
     <dimen name="overlay_prompt_container_width">@dimen/match_parent</dimen>
 
     <!-- Site security icon -->
-    <dimen name="browser_toolbar_site_security_height">@dimen/match_parent</dimen>
-    <dimen name="browser_toolbar_site_security_width">12dp</dimen>
-    <dimen name="browser_toolbar_site_security_margin_right">4dp</dimen>
-    <dimen name="browser_toolbar_site_security_padding_vertical">0dp</dimen>
-    <dimen name="browser_toolbar_site_security_padding_horizontal">0dp</dimen>
+    <dimen name="browser_toolbar_site_security_height">32dp</dimen>
+    <dimen name="browser_toolbar_site_security_width">32dp</dimen>
+    <dimen name="browser_toolbar_site_security_margin_right">0dp</dimen>
+    <dimen name="browser_toolbar_site_security_padding_vertical">7dp</dimen>
+    <dimen name="browser_toolbar_site_security_padding_horizontal">7dp</dimen>
 
     <!-- If one of these values changes, they all should. -->
     <dimen name="browser_toolbar_site_security_margin_bottom">.5dp</dimen>
     <dimen name="site_security_unknown_inset_top">1dp</dimen>
     <dimen name="site_security_unknown_inset_bottom">-1dp</dimen>
 
     <!-- Regular page row on about:home -->
     <dimen name="page_row_height">64dp</dimen>