Bug 1180295 - Start plumbing the outputs of DynamicToolbarAnimator into BrowserApp. r=rbarker
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 18 Aug 2015 14:27:18 -0400
changeset 258250 b675e378dadfe18c73577d03b7651e4aa0e11f5b
parent 258249 f8faf8d59274d3bcdf3837b819feee662a787ad4
child 258251 0700729ed00747937218685cd95a660a3bfc1910
push id63859
push userkgupta@mozilla.com
push dateTue, 18 Aug 2015 18:37:50 +0000
treeherdermozilla-inbound@2b213c98f8a8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker
bugs1180295
milestone43.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 1180295 - Start plumbing the outputs of DynamicToolbarAnimator into BrowserApp. r=rbarker
mobile/android/base/BrowserApp.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -157,16 +157,17 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Vector;
 
 public class BrowserApp extends GeckoApp
                         implements TabsPanel.TabsLayoutChangeListener,
                                    PropertyAnimator.PropertyAnimationListener,
                                    View.OnKeyListener,
                                    LayerView.OnMetricsChangedListener,
+                                   LayerView.DynamicToolbarListener,
                                    BrowserSearch.OnSearchListener,
                                    BrowserSearch.OnEditSuggestionListener,
                                    OnUrlOpenListener,
                                    OnUrlOpenInBackgroundListener,
                                    ReadingListHelper.OnReadingListEventListener,
                                    AnchoredPopup.OnVisibilityChangeListener,
                                    ActionModeCompat.Presenter,
                                    LayoutInflater.Factory {
@@ -1215,30 +1216,33 @@ public class BrowserApp extends GeckoApp
         ps.show("", "", items, ListView.CHOICE_MODE_NONE);
     }
 
     private void setDynamicToolbarEnabled(boolean enabled) {
         ThreadUtils.assertOnUiThread();
 
         if (enabled) {
             if (mLayerView != null) {
-                mLayerView.setOnMetricsChangedDynamicToolbarViewportListener(this);
+                mLayerView.getDynamicToolbarAnimator().addTranslationListener(this);
             }
             setToolbarMargin(0);
             mHomePagerContainer.setPadding(0, mBrowserChrome.getHeight(), 0, 0);
         } else {
             // Immediately show the toolbar when disabling the dynamic
             // toolbar.
             if (mLayerView != null) {
-               mLayerView.setOnMetricsChangedDynamicToolbarViewportListener(null);
+                mLayerView.getDynamicToolbarAnimator().removeTranslationListener(this);
             }
             mHomePagerContainer.setPadding(0, 0, 0, 0);
             if (mBrowserChrome != null) {
                 ViewHelper.setTranslationY(mBrowserChrome, 0);
             }
+            if (mLayerView != null) {
+                ViewHelper.setTranslationY(mLayerView, mBrowserChrome.getHeight());
+            }
         }
 
         refreshToolbarHeight();
     }
 
     private static boolean isAboutHome(final Tab tab) {
         return AboutPages.isAboutHome(tab.getURL());
     }
@@ -1533,16 +1537,36 @@ public class BrowserApp extends GeckoApp
     }
 
     private void setToolbarMargin(int margin) {
         ((RelativeLayout.LayoutParams) mGeckoLayout.getLayoutParams()).topMargin = margin;
         mGeckoLayout.requestLayout();
     }
 
     @Override
+    public void onTranslationChanged(float aToolbarTranslation, float aLayerViewTranslation) {
+        if (isHomePagerVisible() || mBrowserChrome == null) {
+            return;
+        }
+
+        final View browserChrome = mBrowserChrome;
+        final View layerView = mLayerView;
+        final ToolbarProgressView progressView = mProgressView;
+
+        ViewHelper.setTranslationY(browserChrome, -aToolbarTranslation);
+        ViewHelper.setTranslationY(layerView, mToolbarHeight - aLayerViewTranslation);
+
+        // Stop the progressView from moving all the way up so that we can still see a good chunk of it
+        // when the chrome is offscreen.
+        final float offset = getResources().getDimensionPixelOffset(R.dimen.progress_bar_scroll_offset);
+        final float progressTranslationY = Math.min(aToolbarTranslation, mToolbarHeight - offset);
+        ViewHelper.setTranslationY(progressView, -progressTranslationY);
+    }
+
+    @Override
     public void onMetricsChanged(ImmutableViewportMetrics aMetrics) {
         if (isHomePagerVisible() || mBrowserChrome == null) {
             return;
         }
 
         // If the page has shrunk so that the toolbar no longer scrolls, make
         // sure the toolbar is visible.
         if (aMetrics.getPageHeight() <= aMetrics.getHeight()) {
@@ -1556,33 +1580,16 @@ public class BrowserApp extends GeckoApp
                         }
                     });
                 }
             }
         } else {
             mDynamicToolbarCanScroll = true;
         }
 
-        final View browserChrome = mBrowserChrome;
-        final ToolbarProgressView progressView = mProgressView;
-        final int marginTop = Math.round(aMetrics.marginTop);
-        ThreadUtils.postToUiThread(new Runnable() {
-            @Override
-            public void run() {
-                final float translationY = marginTop - browserChrome.getHeight();
-                ViewHelper.setTranslationY(browserChrome, translationY);
-
-                // Stop the progressView from moving all the way up so that we can still see a good chunk of it
-                // when the chrome is offscreen.
-                final float offset = getResources().getDimensionPixelOffset(R.dimen.progress_bar_scroll_offset);
-                final float progressTranslationY = Math.max(marginTop - browserChrome.getHeight(), offset - browserChrome.getHeight());
-                ViewHelper.setTranslationY(progressView, progressTranslationY);
-            }
-        });
-
         if (mFormAssistPopup != null)
             mFormAssistPopup.onMetricsChanged(aMetrics);
     }
 
     @Override
     public void onPanZoomStopped() {
         if (!mDynamicToolbar.isEnabled() || isHomePagerVisible()) {
             return;