Bug 1344517 - Keep dynamic toolbar visible while page is loading. r=kats, a=ritu
authorRandall Barker <rbarker@mozilla.com>
Mon, 06 Mar 2017 11:55:52 -0800
changeset 378981 1a099492211cbf64425ab3aead4fa33583b9cb0a
parent 378980 725b9ae87b49c35f61063a856547d88b897a663d
child 378982 e1ad07de5780569f07ce128acc5561451ce8c1fb
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats, ritu
bugs1344517
milestone53.0
Bug 1344517 - Keep dynamic toolbar visible while page is loading. r=kats, a=ritu
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarProgressView.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/DynamicToolbarAnimator.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -644,16 +644,17 @@ public class BrowserApp extends GeckoApp
 
             @Override
             public boolean onTouch(View v, MotionEvent event) {
                 return false;
             }
         });
 
         mProgressView = (ToolbarProgressView) findViewById(R.id.progress);
+        mProgressView.setDynamicToolbar(mDynamicToolbar);
         mBrowserToolbar.setProgressBar(mProgressView);
 
         // Initialize Tab History Controller.
         tabHistoryController = new TabHistoryController(new OnShowTabHistory() {
             @Override
             public void onShowHistory(final List<TabHistoryPage> historyPageList, final int toIndex) {
                 runOnUiThread(new Runnable() {
                     @Override
@@ -1454,16 +1455,20 @@ public class BrowserApp extends GeckoApp
 
     @Override
     public void onDestroy() {
         if (mIsAbortingAppLaunch) {
             super.onDestroy();
             return;
         }
 
+        if (mProgressView != null) {
+            mProgressView.setDynamicToolbar(null);
+        }
+
         mDynamicToolbar.destroy();
 
         if (mBrowserToolbar != null)
             mBrowserToolbar.onDestroy();
 
         if (mFindInPageBar != null) {
             mFindInPageBar.onDestroy();
             mFindInPageBar = null;
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
@@ -515,18 +515,20 @@ public abstract class BrowserToolbar ext
         }
     }
 
     private void updateProgressVisibility(Tab selectedTab, int progress) {
         if (!isEditing() && selectedTab.getState() == Tab.STATE_LOADING) {
             progressBar.setProgress(progress);
             progressBar.setPrivateMode(selectedTab.isPrivate());
             progressBar.setVisibility(View.VISIBLE);
+            progressBar.pinDynamicToolbar();
         } else {
             progressBar.setVisibility(View.GONE);
+            progressBar.unpinDynamicToolbar();
         }
     }
 
     protected boolean isVisible() {
         return ViewHelper.getTranslationY(this) == 0;
     }
 
     @Override
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarProgressView.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarProgressView.java
@@ -16,16 +16,19 @@
 
 package org.mozilla.gecko.toolbar;
 
 import android.support.v4.content.ContextCompat;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.widget.themed.ThemedImageView;
 import org.mozilla.gecko.util.WeakReferenceHandler;
+import org.mozilla.gecko.DynamicToolbar;
+import org.mozilla.gecko.DynamicToolbar.VisibilityTransition;
+import org.mozilla.gecko.gfx.DynamicToolbarAnimator.PinReason;
 
 import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffColorFilter;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.os.Handler;
@@ -48,40 +51,58 @@ public class ToolbarProgressView extends
     private static final int STEPS = 10;
     private static final int DELAY = 40;
 
     private int mTargetProgress;
     private int mIncrement;
     private ProgressBounds mBounds;
     private Handler mHandler;
     private int mCurrentProgress;
+    private DynamicToolbar mDynamicToolbar;
 
     private PorterDuffColorFilter mPrivateBrowsingColorFilter;
 
     public ToolbarProgressView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         init(context);
     }
 
     public ToolbarProgressView(Context context, AttributeSet attrs) {
         super(context, attrs);
         init(context);
     }
 
+    public void setDynamicToolbar(DynamicToolbar toolbar) {
+        mDynamicToolbar = toolbar;
+    }
+
     private void init(Context ctx) {
         mBounds = new ProgressBounds();
 
         mTargetProgress = 0;
 
         mPrivateBrowsingColorFilter = new PorterDuffColorFilter(
                 ContextCompat.getColor(ctx, R.color.private_browsing_purple), PorterDuff.Mode.SRC_IN);
 
         mHandler = new ToolbarProgressHandler(this);
     }
 
+    void pinDynamicToolbar() {
+        if ((mDynamicToolbar != null) && mDynamicToolbar.isEnabled()) {
+            mDynamicToolbar.setPinned(true, PinReason.PAGE_LOADING);
+            mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
+        }
+    }
+
+    void unpinDynamicToolbar() {
+        if ((mDynamicToolbar != null) && mDynamicToolbar.isEnabled()) {
+            mDynamicToolbar.setPinned(false, PinReason.PAGE_LOADING);
+        }
+    }
+
     @Override
     public void onLayout(boolean f, int l, int t, int r, int b) {
         mBounds.setLayoutRtl(ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL);
         mBounds.onLayout(f, l, t, r, b);
     }
 
     @Override
     public void onDraw(Canvas canvas) {
@@ -182,16 +203,17 @@ public class ToolbarProgressView extends
                         sendMessageDelayed(that.mHandler.obtainMessage(msg.what), delay);
                     } else if (that.mCurrentProgress == MAX_PROGRESS) {
                         sendMessageDelayed(that.mHandler.obtainMessage(MSG_HIDE), DELAY);
                     }
                     break;
 
                 case MSG_HIDE:
                     that.setVisibility(View.GONE);
+                    that.unpinDynamicToolbar();
                     break;
             }
         }
     };
 
     private final class ProgressBounds {
 
         final Rect bounds;
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/DynamicToolbarAnimator.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/DynamicToolbarAnimator.java
@@ -24,17 +24,18 @@ import java.util.Set;
 public class DynamicToolbarAnimator {
     private static final String LOGTAG = "GeckoDynamicToolbarAnimator";
     private static final String PREF_SCROLL_TOOLBAR_THRESHOLD = "browser.ui.scroll-toolbar-threshold";
 
     public static enum PinReason {
         RELAYOUT,
         ACTION_MODE,
         FULL_SCREEN,
-        CARET_DRAG
+        CARET_DRAG,
+        PAGE_LOADING
     }
 
     private final Set<PinReason> pinFlags = Collections.synchronizedSet(EnumSet.noneOf(PinReason.class));
 
     // The duration of the animation in ns
     private static final long ANIMATION_DURATION = 150000000;
 
     private final GeckoLayerClient mTarget;