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

This commit is contained in:
Brian Nicholson 2013-07-03 17:42:47 -07:00
parent 2df7ddb555
commit 21b7ba59de
2 changed files with 33 additions and 2 deletions

View File

@ -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;
}
}

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