Bug 1180295 - Hook up toolbar show/hide animations to the DynamicToolbarAnimator. r=rbarker
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 18 Aug 2015 14:27:18 -0400
changeset 258264 2ed49a9cb8594640dfd6b18fb7cde9a9e29e62b8
parent 258263 69a90ad6126e513bd9566efb72276a7cc5df9ecf
child 258265 2f960e690b57279cc48b8f5cb3e4b83123a4512f
push id29249
push userryanvm@gmail.com
push dateWed, 19 Aug 2015 11:17:27 +0000
treeherdermozilla-central@706b23a03d1c [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 - Hook up toolbar show/hide animations to the DynamicToolbarAnimator. r=rbarker
mobile/android/base/BrowserApp.java
mobile/android/base/gfx/DynamicToolbarAnimator.java
mobile/android/base/gfx/GeckoLayerClient.java
mobile/android/base/gfx/LayerView.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -1591,24 +1591,28 @@ public class BrowserApp extends GeckoApp
 
     @Override
     public void onPanZoomStopped() {
         if (!mDynamicToolbar.isEnabled() || isHomePagerVisible()) {
             return;
         }
 
         // Make sure the toolbar is fully hidden or fully shown when the user
-        // lifts their finger. If the page is shorter than the viewport or if
-        // the user has reached the end of a long (longer than twice the viewport height) page,
-        // the toolbar is always shown.
+        // lifts their finger, depending on various conditions.
         ImmutableViewportMetrics metrics = mLayerView.getViewportMetrics();
-        final float height = metrics.viewportRectBottom - metrics.viewportRectTop;
-        if (metrics.getPageHeight() < metrics.getHeight()
-              || metrics.marginTop >= mToolbarHeight / 2
-              || (metrics.pageRectBottom == metrics.viewportRectBottom && metrics.pageRectBottom > 2*height)) {
+        float toolbarTranslation = mLayerView.getDynamicToolbarAnimator().getToolbarTranslation();
+
+        boolean shortPage = metrics.getPageHeight() < metrics.getHeight();
+        boolean toolbarMostlyVisible = toolbarTranslation < (mToolbarHeight / 2);
+        boolean atBottomOfLongPage = (metrics.pageRectBottom == metrics.viewportRectBottom)
+            && (metrics.pageRectBottom > 2 * metrics.getHeight());
+        Log.v(LOGTAG, "On pan/zoom stopped, short page: " + shortPage
+            + "; toolbarMostlyVisible: " + toolbarMostlyVisible
+            + "; atBottomOfLongPage: " + atBottomOfLongPage);
+        if (shortPage || toolbarMostlyVisible || atBottomOfLongPage) {
             mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
         } else {
             mDynamicToolbar.setVisible(false, VisibilityTransition.ANIMATE);
         }
     }
 
     public void refreshToolbarHeight() {
         ThreadUtils.assertOnUiThread();
--- a/mobile/android/base/gfx/DynamicToolbarAnimator.java
+++ b/mobile/android/base/gfx/DynamicToolbarAnimator.java
@@ -105,26 +105,36 @@ public class DynamicToolbarAnimator {
     }
 
     private void fireListeners() {
         for (LayerView.DynamicToolbarListener listener : mListeners) {
             listener.onTranslationChanged(mToolbarTranslation, mLayerViewTranslation);
         }
     }
 
+    void onPanZoomStopped() {
+        for (LayerView.DynamicToolbarListener listener : mListeners) {
+            listener.onPanZoomStopped();
+        }
+    }
+
     public void setMaxTranslation(float maxTranslation) {
         ThreadUtils.assertOnUiThread();
         if (maxTranslation < 0) {
             Log.e(LOGTAG, "Got a negative max-translation value: " + maxTranslation + "; clamping to zero");
             mMaxTranslation = 0;
         } else {
             mMaxTranslation = maxTranslation;
         }
     }
 
+    public float getToolbarTranslation() {
+        return mToolbarTranslation;
+    }
+
     public void setPinned(boolean pinned) {
         mPinned = pinned;
     }
 
     public boolean isPinned() {
         return mPinned;
     }
 
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -132,19 +132,19 @@ class GeckoLayerClient implements LayerV
         if (tab != null) {
             mZoomConstraints = tab.getZoomConstraints();
             mViewportMetrics = mViewportMetrics.setIsRTL(tab.getIsRTL());
         }
 
         mFrameMetrics = mViewportMetrics;
 
         mDrawListeners = new ArrayList<DrawListener>();
+        mToolbarAnimator = new DynamicToolbarAnimator(this);
         mPanZoomController = PanZoomController.Factory.create(this, view, eventDispatcher);
         mMarginsAnimator = new LayerMarginsAnimator(this, view);
-        mToolbarAnimator = new DynamicToolbarAnimator(this);
         mView = view;
         mView.setListener(this);
         mContentDocumentIsDisplayed = true;
     }
 
     public void setOverscrollHandler(final Overscroll listener) {
         mPanZoomController.setOverscrollHandler(listener);
     }
@@ -901,19 +901,17 @@ class GeckoLayerClient implements LayerV
         // Set mViewportMetrics manually so the margin changes take.
         mViewportMetrics = mViewportMetrics.offsetViewportBy(dx, dy);
         viewportMetricsChanged(true);
     }
 
     /** Implementation of PanZoomTarget */
     @Override
     public void panZoomStopped() {
-        if (mDynamicToolbarViewportChangeListener != null) {
-            mDynamicToolbarViewportChangeListener.onPanZoomStopped();
-        }
+        mToolbarAnimator.onPanZoomStopped();
         if (mZoomedViewViewportChangeListener != null) {
             mZoomedViewViewportChangeListener.onPanZoomStopped();
         }
     }
 
     /** Implementation of PanZoomTarget */
     @Override
     public void forceRedraw(DisplayPortMetrics displayPort) {
--- a/mobile/android/base/gfx/LayerView.java
+++ b/mobile/android/base/gfx/LayerView.java
@@ -667,16 +667,17 @@ public class LayerView extends FrameLayo
             setIsRTL(tab.getIsRTL());
         }
     }
 
     // Public hooks for dynamic toolbar translation
 
     public interface DynamicToolbarListener {
         public void onTranslationChanged(float aToolbarTranslation, float aLayerViewTranslation);
+        public void onPanZoomStopped();
     }
 
     // Public hooks for listening to metrics changing
 
     public interface OnMetricsChangedListener {
         public void onMetricsChanged(ImmutableViewportMetrics viewport);
         public void onPanZoomStopped();
     }