Bug 908364 - Don't show doorhanger popup while in editing mode. r=bnicholson
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Fri, 13 Sep 2013 16:07:17 -0700
changeset 147151 33fbbf1340d92a685fb8a5455743b9f2f70c48a8
parent 147150 b1bfed7bc3125bb94dbc465d5084007c106f323e
child 147152 cdc22fbf554ea6d69ba5e17991d910d968a380bf
child 147176 c33d415d991ecd8b9bf948913926f5491c2641c9
push id25286
push userkwierso@gmail.com
push dateSat, 14 Sep 2013 01:08:17 +0000
treeherdermozilla-central@cdc22fbf554e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs908364
milestone26.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 908364 - Don't show doorhanger popup while in editing mode. r=bnicholson
mobile/android/base/BrowserApp.java
mobile/android/base/BrowserToolbar.java
mobile/android/base/DoorHangerPopup.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -446,16 +446,30 @@ abstract public class BrowserApp extends
         });
 
         mBrowserToolbar.setOnFilterListener(new BrowserToolbar.OnFilterListener() {
             public void onFilter(String searchText, AutocompleteHandler handler) {
                 filterEditingMode(searchText, handler);
             }
         });
 
+        mBrowserToolbar.setOnStartEditingListener(new BrowserToolbar.OnStartEditingListener() {
+            public void onStartEditing() {
+                // Temporarily disable doorhanger notifications.
+                mDoorHangerPopup.disable();
+            }
+        });
+
+        mBrowserToolbar.setOnStopEditingListener(new BrowserToolbar.OnStopEditingListener() {
+            public void onStopEditing() {
+                // Re-enable doorhanger notifications.
+                mDoorHangerPopup.enable();
+            }
+        });
+
         // Intercept key events for gamepad shortcuts
         mBrowserToolbar.setOnKeyListener(this);
 
         if (mTabsPanel != null) {
             mTabsPanel.setTabsLayoutChangeListener(this);
             updateSideBarState();
         }
 
@@ -1387,17 +1401,17 @@ abstract public class BrowserApp extends
         animator.setUseHardwareLayer(false);
 
         mBrowserToolbar.startEditing(url, animator);
         showHomePagerWithAnimator(HomePager.Page.HISTORY, animator);
 
         animator.start();
     }
 
-    void commitEditingMode() {
+    private void commitEditingMode() {
         if (!mBrowserToolbar.isEditing()) {
             return;
         }
 
         final String url = mBrowserToolbar.commitEdit();
         animateHideHomePager();
         hideBrowserSearch();
 
@@ -1462,17 +1476,17 @@ abstract public class BrowserApp extends
             message.put("location", where);
             message.put("identifier", identifier);
             GeckoAppShell.getEventDispatcher().dispatchEvent(message);
         } catch (Exception e) {
             Log.w(LOGTAG, "Error recording search.", e);
         }
     }
 
-    boolean dismissEditingMode() {
+    private boolean dismissEditingMode() {
         if (!mBrowserToolbar.isEditing()) {
             return false;
         }
 
         mBrowserToolbar.cancelEdit();
 
         // Resetting the visibility of HomePager, which might have been hidden
         // by the filterEditingMode().
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -96,16 +96,24 @@ public class BrowserToolbar extends Geck
     public interface OnDismissListener {
         public void onDismiss();
     }
 
     public interface OnFilterListener {
         public void onFilter(String searchText, AutocompleteHandler handler);
     }
 
+    public interface OnStartEditingListener {
+        public void onStartEditing();
+    }
+
+    public interface OnStopEditingListener {
+        public void onStopEditing();
+    }
+
     private LayoutParams mAwesomeBarParams;
     private View mUrlDisplayContainer;
     private View mUrlEditContainer;
     private CustomEditText mUrlEditText;
     private View mUrlBarEntry;
     private ImageView mUrlBarRightEdge;
     private BrowserToolbarBackground mUrlBarBackground;
     private GeckoTextView mTitle;
@@ -123,20 +131,23 @@ public class BrowserToolbar extends Geck
     private Animation mProgressSpinner;
     private TabCounter mTabsCounter;
     private ImageView mShadow;
     private GeckoImageButton mMenu;
     private GeckoImageView mMenuIcon;
     private LinearLayout mActionItemBar;
     private MenuPopup mMenuPopup;
     private List<? extends View> mFocusOrder;
+
     private OnActivateListener mActivateListener;
     private OnCommitListener mCommitListener;
     private OnDismissListener mDismissListener;
     private OnFilterListener mFilterListener;
+    private OnStartEditingListener mStartEditingListener;
+    private OnStopEditingListener mStopEditingListener;
 
     final private BrowserApp mActivity;
     private boolean mHasSoftMenuButton;
 
     private boolean mShowSiteSecurity;
     private boolean mShowReader;
     private boolean mSpinnerVisible;
 
@@ -1176,16 +1187,24 @@ public class BrowserToolbar extends Geck
     public void setOnDismissListener(OnDismissListener listener) {
         mDismissListener = listener;
     }
 
     public void setOnFilterListener(OnFilterListener listener) {
         mFilterListener = listener;
     }
 
+    public void setOnStartEditingListener(OnStartEditingListener listener) {
+        mStartEditingListener = listener;
+    }
+
+    public void setOnStopEditingListener(OnStopEditingListener listener) {
+        mStopEditingListener = listener;
+    }
+
     private void showSoftInput() {
         InputMethodManager imm =
                (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
         imm.showSoftInput(mUrlEditText, InputMethodManager.SHOW_IMPLICIT);
     }
 
     private void showUrlEditContainer() {
         setUrlEditContainerVisibility(true, null);
@@ -1263,16 +1282,20 @@ public class BrowserToolbar extends Geck
     public void startEditing(String url, PropertyAnimator animator) {
         if (isEditing()) {
             return;
         }
 
         mUrlEditText.setText(url != null ? url : "");
         mIsEditing = true;
 
+        if (mStartEditingListener != null) {
+            mStartEditingListener.onStartEditing();
+        }
+
         final int entryTranslation = getUrlBarEntryTranslation();
         final int curveTranslation = getUrlBarCurveTranslation();
 
         // This animation doesn't make much sense in a sidebar UI
         if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
             showUrlEditContainer();
 
             if (!HardwareUtils.isTablet()) {
@@ -1371,16 +1394,20 @@ public class BrowserToolbar extends Geck
 
     private String stopEditing() {
         final String url = mUrlEditText.getText().toString();
         if (!isEditing()) {
             return url;
         }
         mIsEditing = false;
 
+        if (mStopEditingListener != null) {
+            mStopEditingListener.onStopEditing();
+        }
+
         if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
             hideUrlEditContainer();
 
             if (!HardwareUtils.isTablet()) {
                 updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
 
                 if (mUrlBarRightEdge != null) {
                     ViewHelper.setTranslationX(mUrlBarRightEdge, 0);
--- a/mobile/android/base/DoorHangerPopup.java
+++ b/mobile/android/base/DoorHangerPopup.java
@@ -25,32 +25,53 @@ public class DoorHangerPopup extends Arr
                                         Tabs.OnTabsChangedListener,
                                         DoorHanger.OnButtonClickListener {
     private static final String LOGTAG = "GeckoDoorHangerPopup";
 
     // Stores a set of all active DoorHanger notifications. A DoorHanger is
     // uniquely identified by its tabId and value.
     private HashSet<DoorHanger> mDoorHangers;
 
+    // Whether or not the doorhanger popup is disabled.
+    private boolean mDisabled;
+
     DoorHangerPopup(GeckoApp activity, View anchor) {
         super(activity, anchor);
 
         mDoorHangers = new HashSet<DoorHanger>();
 
         registerEventListener("Doorhanger:Add");
         registerEventListener("Doorhanger:Remove");
         Tabs.registerOnTabsChangedListener(this);
     }
 
     void destroy() {
         unregisterEventListener("Doorhanger:Add");
         unregisterEventListener("Doorhanger:Remove");
         Tabs.unregisterOnTabsChangedListener(this);
     }
 
+    /**
+     * Temporarily disables the doorhanger popup. If the popup is disabled,
+     * it will not be shown to the user, but it will continue to process
+     * calls to add/remove doorhanger notifications.
+     */
+    void disable() {
+        mDisabled = true;
+        updatePopup();
+    }
+
+    /**
+     * Re-enables the doorhanger popup.
+     */
+    void enable() {
+        mDisabled = false;
+        updatePopup();
+    }
+
     @Override
     public void handleMessage(String event, JSONObject geckoObject) {
         try {
             if (event.equals("Doorhanger:Add")) {
                 final int tabId = geckoObject.getInt("tabID");
                 final String value = geckoObject.getString("value");
                 final String message = geckoObject.getString("message");
                 final JSONArray buttons = geckoObject.getJSONArray("buttons");
@@ -241,22 +262,23 @@ public class DoorHangerPopup extends Arr
         }
     }
 
     /**
      * Updates the popup state.
      *
      * This method must be called on the UI thread.
      */
-    void updatePopup() {
+    private void updatePopup() {
         // Bail if the selected tab is null, if there are no active doorhangers,
-        // or if we haven't inflated the layout yet (this can happen if updatePopup()
-        // is called before the runnable from addDoorHanger() runs). 
+        // if we haven't inflated the layout yet (this can happen if updatePopup()
+        // is called before the runnable from addDoorHanger() runs), or if the
+        // doorhanger popup is temporarily disabled.
         Tab tab = Tabs.getInstance().getSelectedTab();
-        if (tab == null || mDoorHangers.size() == 0 || !mInflated) {
+        if (tab == null || mDoorHangers.size() == 0 || !mInflated || mDisabled) {
             dismiss();
             return;
         }
 
         // Show doorhangers for the selected tab
         int tabId = tab.getId();
         boolean shouldShowPopup = false;
         for (DoorHanger dh : mDoorHangers) {