diff --git a/mobile/android/base/ActionModeCompatView.java b/mobile/android/base/ActionModeCompatView.java index 954626897c2..cae887142e4 100644 --- a/mobile/android/base/ActionModeCompatView.java +++ b/mobile/android/base/ActionModeCompatView.java @@ -119,9 +119,12 @@ class ActionModeCompatView extends LinearLayout implements GeckoMenu.ActionItemB maxWidth = mActionButtonBar.getMeasuredWidth(); } - // Since we don't know how many items will be added, we always reserve space for the overflow menu - mMenuButton.measure(SPEC, SPEC); - maxWidth -= mMenuButton.getMeasuredWidth(); + // If the menu button is already visible, no need to account for it + if (mMenuButton.getVisibility() == View.GONE) { + // Since we don't know how many items will be added, we always reserve space for the overflow menu + mMenuButton.measure(SPEC, SPEC); + maxWidth -= mMenuButton.getMeasuredWidth(); + } if (mActionButtonsWidth <= 0) { mActionButtonsWidth = 0; @@ -142,12 +145,14 @@ class ActionModeCompatView extends LinearLayout implements GeckoMenu.ActionItemB mActionButtonBar.addView(actionItem); return true; } + return false; } /* GeckoMenu.ActionItemBarPresenter */ @Override public void removeActionItem(View actionItem) { + actionItem.measure(SPEC, SPEC); mActionButtonsWidth -= actionItem.getMeasuredWidth(); mActionButtonBar.removeView(actionItem); } diff --git a/mobile/android/base/menu/GeckoMenu.java b/mobile/android/base/menu/GeckoMenu.java index 552870f727b..a50f95eaa04 100644 --- a/mobile/android/base/menu/GeckoMenu.java +++ b/mobile/android/base/menu/GeckoMenu.java @@ -171,11 +171,12 @@ public class GeckoMenu extends ListView } }); - mActionItems.put(menuItem, actionView); - mActionItemBarPresenter.addActionItem(actionView); - mItems.add(menuItem); - - return true; + if (mActionItemBarPresenter.addActionItem(actionView)) { + mActionItems.put(menuItem, actionView); + mItems.add(menuItem); + return true; + } + return false; } @Override