Bug 888497 - Fix focus order of browser toolbar. r=sriram

This commit is contained in:
Brian Nicholson 2013-07-03 15:38:19 -07:00
parent 078034b365
commit 5bc654da8b
2 changed files with 34 additions and 2 deletions

View File

@ -420,7 +420,16 @@ 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, mLayout,
mSiteSecurity, mReader, mStop, mActionItemBar, mMenu);
} else {
mFocusOrder = Arrays.asList(mLayout, mSiteSecurity, mReader, mStop,
mTabs, mMenu);
}
}
}
@Override
@ -873,15 +882,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) {
mLayout.requestFocus();
}
prevView = view;
}
}

View File

@ -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) {