From 21b7ba59def0fc19321422c1b7188569ba367dd2 Mon Sep 17 00:00:00 2001 From: Brian Nicholson Date: Wed, 3 Jul 2013 17:42:47 -0700 Subject: [PATCH] Bug 888497 - Fix focus order of browser toolbar. r=sriram --- mobile/android/base/BrowserToolbar.java | 34 +++++++++++++++++-- .../android/base/menu/MenuItemActionBar.java | 1 + 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/mobile/android/base/BrowserToolbar.java b/mobile/android/base/BrowserToolbar.java index 1079bbe91ff..15f5a5e3bac 100644 --- a/mobile/android/base/BrowserToolbar.java +++ b/mobile/android/base/BrowserToolbar.java @@ -420,7 +420,15 @@ public class BrowserToolbar extends GeckoRelativeLayout }); } - mFocusOrder = Arrays.asList(mBack, mForward, mReader, mSiteSecurity, mStop, mTabs); + // We use different layouts on phones and tablets, so adjust the focus + // order appropriately. + if (HardwareUtils.isTablet()) { + mFocusOrder = Arrays.asList(mTabs, mBack, mForward, this, + mSiteSecurity, mReader, mStop, mActionItemBar, mMenu); + } else { + mFocusOrder = Arrays.asList(this, mSiteSecurity, mReader, mStop, + mTabs, mMenu); + } } @Override @@ -873,15 +881,37 @@ public class BrowserToolbar extends GeckoRelativeLayout private void updateFocusOrder() { View prevView = null; + // If the element that has focus becomes disabled or invisible, focus + // is given to the URL bar. + boolean needsNewFocus = false; + for (View view : mFocusOrder) { - if (view.getVisibility() != View.VISIBLE) + if (view.getVisibility() != View.VISIBLE || !view.isEnabled()) { + if (view.hasFocus()) { + needsNewFocus = true; + } continue; + } if (prevView != null) { + if (view == mActionItemBar) { + final int childCount = mActionItemBar.getChildCount(); + if (childCount > 1) { + View firstChild = mActionItemBar.getChildAt(0); + firstChild.setNextFocusLeftId(prevView.getId()); + prevView.setNextFocusRightId(firstChild.getId()); + } + view = mActionItemBar.getChildAt(childCount - 1); + } + view.setNextFocusLeftId(prevView.getId()); prevView.setNextFocusRightId(view.getId()); } + if (needsNewFocus) { + requestFocus(); + } + prevView = view; } } diff --git a/mobile/android/base/menu/MenuItemActionBar.java b/mobile/android/base/menu/MenuItemActionBar.java index 584354b8970..5f02500efae 100644 --- a/mobile/android/base/menu/MenuItemActionBar.java +++ b/mobile/android/base/menu/MenuItemActionBar.java @@ -39,6 +39,7 @@ public class MenuItemActionBar extends ImageButton setIcon(item.getIcon()); setTitle(item.getTitle()); setEnabled(item.isEnabled()); + setId(item.getItemId()); } private void setIcon(Drawable icon) {