diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 0de26b984e11..6ca55e60156d 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -451,6 +451,20 @@ abstract public class BrowserApp extends GeckoApp } }); + 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); @@ -1392,7 +1406,7 @@ abstract public class BrowserApp extends GeckoApp animator.start(); } - void commitEditingMode() { + private void commitEditingMode() { if (!mBrowserToolbar.isEditing()) { return; } @@ -1467,7 +1481,7 @@ abstract public class BrowserApp extends GeckoApp } } - boolean dismissEditingMode() { + private boolean dismissEditingMode() { if (!mBrowserToolbar.isEditing()) { return false; } diff --git a/mobile/android/base/BrowserToolbar.java b/mobile/android/base/BrowserToolbar.java index d31ebbe20854..1f55a128c8e9 100644 --- a/mobile/android/base/BrowserToolbar.java +++ b/mobile/android/base/BrowserToolbar.java @@ -101,6 +101,14 @@ public class BrowserToolbar extends GeckoRelativeLayout 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; @@ -128,10 +136,13 @@ public class BrowserToolbar extends GeckoRelativeLayout private LinearLayout mActionItemBar; private MenuPopup mMenuPopup; private List 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; @@ -1181,6 +1192,14 @@ public class BrowserToolbar extends GeckoRelativeLayout 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); @@ -1268,6 +1287,10 @@ public class BrowserToolbar extends GeckoRelativeLayout mUrlEditText.setText(url != null ? url : ""); mIsEditing = true; + if (mStartEditingListener != null) { + mStartEditingListener.onStartEditing(); + } + final int entryTranslation = getUrlBarEntryTranslation(); final int curveTranslation = getUrlBarCurveTranslation(); @@ -1376,6 +1399,10 @@ public class BrowserToolbar extends GeckoRelativeLayout } mIsEditing = false; + if (mStopEditingListener != null) { + mStopEditingListener.onStopEditing(); + } + if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) { hideUrlEditContainer(); diff --git a/mobile/android/base/DoorHangerPopup.java b/mobile/android/base/DoorHangerPopup.java index d5b1ceaef39a..6600260b3084 100644 --- a/mobile/android/base/DoorHangerPopup.java +++ b/mobile/android/base/DoorHangerPopup.java @@ -30,6 +30,9 @@ public class DoorHangerPopup extends ArrowPopup // uniquely identified by its tabId and value. private HashSet mDoorHangers; + // Whether or not the doorhanger popup is disabled. + private boolean mDisabled; + DoorHangerPopup(GeckoApp activity, View anchor) { super(activity, anchor); @@ -46,6 +49,24 @@ public class DoorHangerPopup extends ArrowPopup 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 { @@ -246,12 +267,13 @@ public class DoorHangerPopup extends ArrowPopup * * 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; }