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

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

Issue 1661673004: Enables hot-tracking for overflow extension buttons in the app menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restores hot-tracking of extension buttons in app menu with MD Created 4 years, 10 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
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 1cd057e8dcfc1e33813236383bba75570df59295..5f7389a6bf07b4a1efa36d004e51ae57bc824f8a 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -114,6 +114,21 @@ static CustomButton* GetFirstHotTrackedView(View* view) {
return NULL;
}
+CustomButton* OtherHotTrackedButton(View* view, CustomButton* button_hot) {
+ if (!view)
+ return nullptr;
+ CustomButton* button = CustomButton::AsCustomButton(view);
+ if (button && button != button_hot && button->IsHotTracked())
+ return button;
+
+ for (int i = 0; i < view->child_count(); ++i) {
+ button = OtherHotTrackedButton(view->child_at(i), button_hot);
+ if (button)
+ return button;
+ }
+ return nullptr;
+}
+
// Recurses through the child views of |view| returning the first view starting
// at |start| that is focusable. A value of -1 for |start| indicates to start at
// the first view (if |forward| is false, iterating starts at the last view). If
@@ -939,7 +954,13 @@ void MenuController::SetSelection(MenuItemView* menu_item,
if (pending_item_changed && pending_state_.item) {
CustomButton* button = GetFirstHotTrackedView(pending_state_.item);
if (button)
- button->SetHotTracked(false);
+ SetHotTrackedButton(button, false);
+ }
+ CustomButton* new_hot_button = OtherHotTrackedButton(menu_item, hot_button_);
+ if (new_hot_button) {
+ if (hot_button_)
+ SetHotTrackedButton(hot_button_, false);
+ SetHotTrackedButton(new_hot_button, true);
}
// Notify the old path it isn't selected.
@@ -1191,6 +1212,7 @@ MenuController::MenuController(bool blocking,
last_drop_operation_(MenuDelegate::DROP_UNKNOWN),
showing_submenu_(false),
active_mouse_view_id_(ViewStorage::GetInstance()->CreateStorageID()),
+ hot_button_(nullptr),
delegate_(delegate),
message_loop_depth_(0),
closing_event_time_(base::TimeDelta()),
@@ -1226,8 +1248,7 @@ bool MenuController::SendAcceleratorToHotTrackedView() {
ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE);
hot_view->AcceleratorPressed(accelerator);
- CustomButton* button = static_cast<CustomButton*>(hot_view);
- button->SetHotTracked(true);
+ SetHotTrackedButton(hot_view, true);
return true;
}
@@ -1989,8 +2010,7 @@ void MenuController::IncrementSelection(
// select the first menu item that is visible and enabled.
if (item->GetSubmenu()->GetMenuItemCount()) {
MenuItemView* to_select = FindInitialSelectableMenuItem(item, direction);
- if (to_select)
- SetSelection(to_select, SELECTION_DEFAULT);
+ SetInitialHotTrackedView(to_select, direction);
return;
}
}
@@ -1998,12 +2018,12 @@ void MenuController::IncrementSelection(
if (item->has_children()) {
CustomButton* button = GetFirstHotTrackedView(item);
if (button) {
- button->SetHotTracked(false);
+ SetHotTrackedButton(button, false);
View* to_make_hot = GetNextFocusableView(
item, button, direction == INCREMENT_SELECTION_DOWN);
CustomButton* button_hot = CustomButton::AsCustomButton(to_make_hot);
if (button_hot) {
- button_hot->SetHotTracked(true);
+ SetHotTrackedButton(button_hot, true);
return;
}
} else {
@@ -2011,7 +2031,7 @@ void MenuController::IncrementSelection(
GetInitialFocusableView(item, direction == INCREMENT_SELECTION_DOWN);
CustomButton* button_hot = CustomButton::AsCustomButton(to_make_hot);
if (button_hot) {
- button_hot->SetHotTracked(true);
+ SetHotTrackedButton(button_hot, true);
return;
}
}
@@ -2025,14 +2045,7 @@ void MenuController::IncrementSelection(
if (parent->GetSubmenu()->GetMenuItemAt(i) == item) {
MenuItemView* to_select =
FindNextSelectableMenuItem(parent, i, direction);
- if (!to_select)
- break;
- SetSelection(to_select, SELECTION_DEFAULT);
- View* to_make_hot = GetInitialFocusableView(
- to_select, direction == INCREMENT_SELECTION_DOWN);
- CustomButton* button_hot = CustomButton::AsCustomButton(to_make_hot);
- if (button_hot)
- button_hot->SetHotTracked(true);
+ SetInitialHotTrackedView(to_select, direction);
break;
}
}
@@ -2597,4 +2610,30 @@ void MenuController::HandleMouseLocation(SubmenuView* source,
}
}
+void MenuController::SetHotTrackedButton(CustomButton* hot_button,
+ bool is_hot_tracked) {
+ DCHECK(hot_button);
+ hot_button->SetHotTracked(is_hot_tracked);
+ if (is_hot_tracked)
+ hot_button_ = hot_button;
+ else if (hot_button_ == hot_button)
+ hot_button_ = nullptr;
+ else
+ NOTREACHED();
Peter Kasting 2016/02/06 02:51:12 Nit: Simpler: DCHECK(is_hot_tracked || (hot_but
varkha 2016/02/16 19:59:44 Done.
+}
+
+void MenuController::SetInitialHotTrackedView(
+ MenuItemView* item,
+ SelectionIncrementDirectionType direction) {
+ if (!item)
+ return;
+ SetSelection(item, SELECTION_DEFAULT);
+ View* to_make_hot =
Peter Kasting 2016/02/06 02:51:13 Nit: |hot_view| is shorter and, to me, less awkwar
varkha 2016/02/16 19:59:44 Done.
+ GetInitialFocusableView(item, direction == INCREMENT_SELECTION_DOWN);
+ CustomButton* button_hot = CustomButton::AsCustomButton(to_make_hot);
Peter Kasting 2016/02/06 02:51:12 Nit: Use |hot_button| for consistency with previou
varkha 2016/02/16 19:59:44 Done.
+ if (button_hot)
+ SetHotTrackedButton(button_hot, true);
+ return;
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698