Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1042)

Unified Diff: ui/views/controls/menu/menu_controller.cc

Issue 1129203003: Skips disabled menu items when selection is changed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Skips disabled menu items when selection is changed (test) Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/menu/menu_controller.cc
diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc
index 7cc495535baafdaf99caadd1ca7e1728b240dfc4..e97ff860127699f37294bf33332a30e56285cdef 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -1885,9 +1885,11 @@ void MenuController::IncrementSelection(int delta) {
if (pending_state_.submenu_open && item->HasSubmenu() &&
item->GetSubmenu()->IsShowing()) {
// A menu is selected and open, but none of its children are selected,
- // select the first menu item.
+ // select the first menu item that is visible and enabled.
if (item->GetSubmenu()->GetMenuItemCount()) {
- SetSelection(item->GetSubmenu()->GetMenuItemAt(0), SELECTION_DEFAULT);
+ MenuItemView* to_select = FindFirstSelectableMenuItem(item);
+ if (to_select)
+ SetSelection(to_select, SELECTION_DEFAULT);
return;
}
}
@@ -1934,19 +1936,27 @@ void MenuController::IncrementSelection(int delta) {
}
}
+MenuItemView* MenuController::FindFirstSelectableMenuItem(
+ MenuItemView* parent) {
+ MenuItemView* child = parent->GetSubmenu()->GetMenuItemAt(0);
+ if (!child->visible() || !child->enabled())
+ child = FindNextSelectableMenuItem(parent, 0, 1);
+ return child;
+}
+
MenuItemView* MenuController::FindNextSelectableMenuItem(MenuItemView* parent,
int index,
int delta) {
int start_index = index;
int parent_count = parent->GetSubmenu()->GetMenuItemCount();
// Loop through the menu items skipping any invisible menus. The loop stops
- // when we wrap or find a visible child.
+ // when we wrap or find a visible and enabled child.
do {
index = (index + delta + parent_count) % parent_count;
if (index == start_index)
return NULL;
MenuItemView* child = parent->GetSubmenu()->GetMenuItemAt(index);
- if (child->visible())
+ if (child->visible() && child->enabled())
return child;
} while (index != start_index);
return NULL;
@@ -1954,15 +1964,17 @@ MenuItemView* MenuController::FindNextSelectableMenuItem(MenuItemView* parent,
void MenuController::OpenSubmenuChangeSelectionIfCan() {
MenuItemView* item = pending_state_.item;
- if (item->HasSubmenu() && item->enabled()) {
- if (item->GetSubmenu()->GetMenuItemCount() > 0) {
- SetSelection(item->GetSubmenu()->GetMenuItemAt(0),
- SELECTION_UPDATE_IMMEDIATELY);
- } else {
- // No menu items, just show the sub-menu.
- SetSelection(item, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY);
- }
+ if (!item->HasSubmenu() || !item->enabled())
+ return;
+ MenuItemView* to_select = NULL;
+ if (item->GetSubmenu()->GetMenuItemCount() > 0)
+ to_select = FindFirstSelectableMenuItem(item);
+ if (to_select) {
+ SetSelection(to_select, SELECTION_UPDATE_IMMEDIATELY);
+ return;
}
+ // No menu items, just show the sub-menu.
+ SetSelection(item, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY);
}
void MenuController::CloseSubmenu() {
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698