Bug 1151505 - Doorhanger can appear while browser toolbar is scrolled off screen. r=margaret
authorChenxia Liu <liuche@mozilla.com>
Tue, 21 Apr 2015 16:30:25 -0700
changeset 241294 209f11506ce65319d4cfb26e783ca32ced8b4315
parent 241293 f99efc229209e89f0f3530be2aa118b59d277124
child 241295 f5107e422e34f7e010bec7e676c4f8f8a038ca72
push id12611
push usercliu@mozilla.com
push dateMon, 27 Apr 2015 23:45:00 +0000
treeherderfx-team@f5107e422e34 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1151505
milestone40.0a1
Bug 1151505 - Doorhanger can appear while browser toolbar is scrolled off screen. r=margaret
mobile/android/base/BrowserApp.java
mobile/android/base/widget/AnchoredPopup.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -69,16 +69,17 @@ import org.mozilla.gecko.util.GeckoEvent
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.MenuUtils;
 import org.mozilla.gecko.util.NativeEventListener;
 import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.PrefUtils;
 import org.mozilla.gecko.util.StringUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.util.UIAsyncTask;
+import org.mozilla.gecko.widget.AnchoredPopup;
 import org.mozilla.gecko.widget.ButtonToast;
 import org.mozilla.gecko.widget.ButtonToast.ToastListener;
 import org.mozilla.gecko.widget.GeckoActionProvider;
 
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -145,16 +146,17 @@ public class BrowserApp extends GeckoApp
                         implements TabsPanel.TabsLayoutChangeListener,
                                    PropertyAnimator.PropertyAnimationListener,
                                    View.OnKeyListener,
                                    LayerView.OnMetricsChangedListener,
                                    BrowserSearch.OnSearchListener,
                                    BrowserSearch.OnEditSuggestionListener,
                                    OnUrlOpenListener,
                                    OnUrlOpenInBackgroundListener,
+                                   AnchoredPopup.OnShowListener,
                                    ActionModeCompat.Presenter,
                                    LayoutInflater.Factory {
     private static final String LOGTAG = "GeckoBrowserApp";
 
     private static final boolean ZOOMED_VIEW_ENABLED = AppConstants.NIGHTLY_BUILD;
 
     private static final int TABS_ANIMATION_DURATION = 450;
 
@@ -1342,30 +1344,41 @@ public class BrowserApp extends GeckoApp
         super.onDestroy();
     }
 
     @Override
     protected void initializeChrome() {
         super.initializeChrome();
 
         mDoorHangerPopup.setAnchor(mBrowserToolbar.getDoorHangerAnchor());
+        mDoorHangerPopup.setOnShowListener(this);
 
         mDynamicToolbar.setLayerView(mLayerView);
         setDynamicToolbarEnabled(mDynamicToolbar.isEnabled());
 
         // Intercept key events for gamepad shortcuts
         mLayerView.setOnKeyListener(this);
 
         // Initialize the actionbar menu items on startup for both large and small tablets
         if (HardwareUtils.isTablet()) {
             onCreatePanelMenu(Window.FEATURE_OPTIONS_PANEL, null);
             invalidateOptionsMenu();
         }
     }
 
+    @Override
+    public void onDoorHangerShow() {
+        ThreadUtils.postToUiThread(new Runnable() {
+            @Override
+            public void run() {
+                mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
+            }
+        });
+    }
+
     private void handleClearHistory(final boolean clearSearchHistory) {
         final BrowserDB db = getProfile().getDB();
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
                 db.clearHistory(getContentResolver(), clearSearchHistory);
             }
         });
@@ -1431,20 +1444,16 @@ public class BrowserApp extends GeckoApp
                 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 (mDoorHangerPopup.isShowing()) {
-                    mDoorHangerPopup.updatePopup();
-                }
             }
         });
 
         if (mFormAssistPopup != null)
             mFormAssistPopup.onMetricsChanged(aMetrics);
     }
 
     @Override
--- a/mobile/android/base/widget/AnchoredPopup.java
+++ b/mobile/android/base/widget/AnchoredPopup.java
@@ -18,17 +18,22 @@ import android.view.ViewGroup;
 import android.widget.LinearLayout;
 import android.widget.PopupWindow;
 import org.mozilla.gecko.util.HardwareUtils;
 
 /**
  * AnchoredPopup is the base class for doorhanger notifications, and is anchored to the urlbar.
  */
 public abstract class AnchoredPopup extends PopupWindow {
+    public interface OnShowListener {
+        public void onDoorHangerShow();
+    }
+
     private View mAnchor;
+    private OnShowListener mOnShowListener;
 
     protected LinearLayout mContent;
     protected boolean mInflated;
 
     protected final Context mContext;
 
     public AnchoredPopup(Context context) {
         super(context);
@@ -64,25 +69,33 @@ public abstract class AnchoredPopup exte
      * Sets the anchor for this popup.
      *
      * @param anchor Anchor view for positioning the arrow.
      */
     public void setAnchor(View anchor) {
         mAnchor = anchor;
     }
 
+    public void setOnShowListener(OnShowListener listener) {
+        mOnShowListener = listener;
+    }
+
     /**
      * Shows the popup with the arrow pointing to the center of the anchor view. If the anchor
      * isn't visible, the popup will just be shown at the top of the root view.
      */
     public void show() {
         if (!mInflated) {
             throw new IllegalStateException("ArrowPopup#init() must be called before ArrowPopup#show()");
         }
 
+        if (mOnShowListener != null) {
+            mOnShowListener.onDoorHangerShow();
+        }
+
         final int[] anchorLocation = new int[2];
         if (mAnchor != null) {
             mAnchor.getLocationInWindow(anchorLocation);
         }
 
         // The doorhanger should overlap the bottom of the urlbar.
         int offsetY = mContext.getResources().getDimensionPixelOffset(R.dimen.doorhanger_offsetY);
         final View decorView = ((Activity) mContext).getWindow().getDecorView();