Bug 935473 - Change updateBackButton/updateForwardButton to take a Tab argument (r=wesj)
authorLucas Rocha <lucasr@mozilla.com>
Thu, 05 Dec 2013 16:26:35 +0000
changeset 174651 a2e2a341e543f13c2cf0532ddcad12ee3e151c42
parent 174650 dfe673e83ebc696a452799b8fcbb298bfe171bba
child 174652 1353c0a6159aaa485057604d0aadfd360e4c3836
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs935473
milestone28.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 935473 - Change updateBackButton/updateForwardButton to take a Tab argument (r=wesj)
mobile/android/base/BrowserApp.java
mobile/android/base/toolbar/BrowserToolbar.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -873,19 +873,16 @@ abstract public class BrowserApp extends
 
         super.onDestroy();
     }
 
     @Override
     protected void initializeChrome() {
         super.initializeChrome();
 
-        mBrowserToolbar.updateBackButton(false);
-        mBrowserToolbar.updateForwardButton(false);
-
         mDoorHangerPopup.setAnchor(mBrowserToolbar.getDoorHangerAnchor());
 
         // Listen to margin changes to position the toolbar correctly
         if (isDynamicToolbarEnabled()) {
             refreshToolbarHeight();
             mLayerView.getLayerMarginsAnimator().showMargins(true);
             mLayerView.getLayerClient().setOnMetricsChangedListener(this);
         }
--- a/mobile/android/base/toolbar/BrowserToolbar.java
+++ b/mobile/android/base/toolbar/BrowserToolbar.java
@@ -269,19 +269,21 @@ public class BrowserToolbar extends Geck
             mUrlBarRightEdge.getDrawable().setLevel(6000);
         }
 
         mTitle = (GeckoTextView) findViewById(R.id.url_bar_title);
         mTitlePadding = mTitle.getPaddingRight();
 
         mTabs = (ShapedButton) findViewById(R.id.tabs);
         mTabsCounter = (TabCounter) findViewById(R.id.tabs_counter);
+
         mBack = (ImageButton) findViewById(R.id.back);
+        setButtonEnabled(mBack, false);
         mForward = (ImageButton) findViewById(R.id.forward);
-        mForward.setEnabled(false); // initialize the forward button to not be enabled
+        setButtonEnabled(mForward, false);
 
         mFavicon = (ImageButton) findViewById(R.id.favicon);
         if (Build.VERSION.SDK_INT >= 11) {
             if (Build.VERSION.SDK_INT >= 16) {
                 mFavicon.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
             }
             mFavicon.setLayerType(View.LAYER_TYPE_HARDWARE, null);
         }
@@ -558,28 +560,28 @@ public class BrowserToolbar extends Geck
 
         if (tabs.isSelectedTab(tab)) {
             switch (msg) {
                 case TITLE:
                     updateTitle();
                     break;
 
                 case START:
-                    updateBackButton(canDoBack(tab));
-                    updateForwardButton(canDoForward(tab));
+                    updateBackButton(tab);
+                    updateForwardButton(tab);
                     if (tab.getState() == Tab.STATE_LOADING) {
                         setProgressVisibility(true);
                     }
                     setSecurityMode(tab.getSecurityMode());
                     setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
                     break;
 
                 case STOP:
-                    updateBackButton(canDoBack(tab));
-                    updateForwardButton(canDoForward(tab));
+                    updateBackButton(tab);
+                    updateForwardButton(tab);
                     setProgressVisibility(false);
                     // Reset the title in case we haven't navigated to a new page yet.
                     updateTitle();
                     break;
 
                 case SELECTED:
                 case LOAD_ERROR:
                     updateTitle();
@@ -587,18 +589,18 @@ public class BrowserToolbar extends Geck
                 case LOCATION_CHANGE:
                     // A successful location change will cause Tab to notify
                     // us of a title change, so we don't update the title here.
                     refresh();
                     break;
 
                 case CLOSED:
                 case ADDED:
-                    updateBackButton(canDoBack(tab));
-                    updateForwardButton(canDoForward(tab));
+                    updateBackButton(tab);
+                    updateForwardButton(tab);
                     break;
 
                 case FAVICON:
                     setFavicon(tab.getFavicon());
                     break;
 
                 case SECURITY_CHANGE:
                     setSecurityMode(tab.getSecurityMode());
@@ -1374,18 +1376,18 @@ public class BrowserToolbar extends Geck
             // This alpha value has to be in sync with the one used
             // in updateChildrenForEditing().
             drawable.setAlpha(enabled ? 255 : 61);
         }
 
         button.setEnabled(enabled);
     }
 
-    public void updateBackButton(boolean enabled) {
-        setButtonEnabled(mBack, enabled);
+    public void updateBackButton(Tab tab) {
+        setButtonEnabled(mBack, canDoBack(tab));
     }
 
     private void animateForwardButton(final boolean visible) {
         if (mForward.getVisibility() != View.VISIBLE)
             return;
 
         // if the forward button's margin is non-zero, this means it has already
         // been animated to be visible¬ł and vice-versa.
@@ -1443,17 +1445,18 @@ public class BrowserToolbar extends Geck
                 mForwardAnim = null;
             }
         });
 
         prepareForwardAnimation(mForwardAnim, visible, width);
         mForwardAnim.start();
     }
 
-    public void updateForwardButton(boolean enabled) {
+    public void updateForwardButton(Tab tab) {
+        final boolean enabled = canDoForward(tab);
         if (mForward.isEnabled() == enabled)
             return;
 
         // Save the state on the forward button so that we can skip animations
         // when there's nothing to change
         setButtonEnabled(mForward, enabled);
         animateForwardButton(enabled);
     }
@@ -1522,18 +1525,18 @@ public class BrowserToolbar extends Geck
 
     private void refresh() {
         Tab tab = Tabs.getInstance().getSelectedTab();
         if (tab != null) {
             setFavicon(tab.getFavicon());
             setProgressVisibility(tab.getState() == Tab.STATE_LOADING);
             setSecurityMode(tab.getSecurityMode());
             setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
-            updateBackButton(canDoBack(tab));
-            updateForwardButton(canDoForward(tab));
+            updateBackButton(tab);
+            updateForwardButton(tab);
 
             final boolean isPrivate = tab.isPrivate();
             setPrivateMode(isPrivate);
             mTabs.setPrivateMode(isPrivate);
             mTitle.setPrivateMode(isPrivate);
             mMenu.setPrivateMode(isPrivate);
             mMenuIcon.setPrivateMode(isPrivate);
             mUrlEditLayout.setPrivateMode(isPrivate);