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

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

Issue 1741093002: Fixes alternating keyboard and mouse hot-tracking in menus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes alternating keyboard and mouse hot-tracking in menus (rebased) 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
« 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 b271d959e78cb62b8d419e4999d4260f16395afb..0ca7547043cb3b71b8f9319d8ff264a986be41fc 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -715,11 +715,21 @@ void MenuController::OnMouseMoved(SubmenuView* source,
}
MenuHostRootView* root_view = GetRootView(source, event.location());
- if (root_view)
+ if (root_view) {
root_view->ProcessMouseMoved(event);
- // TODO(varkha): It is possible that another child CustomButton has become
- // hot-tracked as a result of this event. We need to track it for accurate
- // hot-tracking when both mouse and keyboard are used to navigate the menu.
+
+ // Update hot-tracked button when a button state is changed with a mouse
+ // event. It is necessary to track it for accurate hot-tracking when both
+ // mouse and keyboard are used to navigate the menu.
+ ui::MouseEvent event_for_root(event);
+ ConvertLocatedEventForRootView(source, root_view, &event_for_root);
+ View* view =
+ root_view->GetEventHandlerForPoint(event_for_root.location());
+ CustomButton* button = CustomButton::AsCustomButton(view);
+ if (button && button->IsHotTracked())
+ SetHotTrackedButton(button);
+ }
+
HandleMouseLocation(source, event.location());
}
@@ -803,10 +813,15 @@ View* MenuController::GetTooltipHandlerForPoint(SubmenuView* source,
void MenuController::ViewHierarchyChanged(
SubmenuView* source,
const View::ViewHierarchyChangedDetails& details) {
- // If the current mouse handler is removed, remove it as the handler.
- if (!details.is_add && details.child == current_mouse_event_target_) {
- current_mouse_event_target_ = nullptr;
- current_mouse_pressed_state_ = 0;
+ if (!details.is_add) {
+ // If the current mouse handler is removed, remove it as the handler.
+ if (details.child == current_mouse_event_target_) {
+ current_mouse_event_target_ = nullptr;
+ current_mouse_pressed_state_ = 0;
+ }
+ // Update |hot_button_| if it gets deleted while a menu is up.
sky 2016/02/29 16:33:32 deleted->removed
varkha 2016/02/29 19:09:44 Done.
+ if (details.child == hot_button_)
+ hot_button_ = nullptr;
}
}
@@ -1036,8 +1051,10 @@ void MenuController::SetSelection(MenuItemView* menu_item,
bool pending_item_changed = pending_state_.item != menu_item;
if (pending_item_changed && pending_state_.item) {
CustomButton* button = GetFirstHotTrackedView(pending_state_.item);
sky 2016/02/29 16:33:32 It doesn't seem necessary to call this anymore. Ca
varkha 2016/02/29 19:09:44 Here, yes. Done.
- if (button)
- button->SetHotTracked(false);
+ if (button) {
+ DCHECK_EQ(hot_button_, button);
+ SetHotTrackedButton(nullptr);
+ }
}
// Notify the old path it isn't selected.
@@ -1289,6 +1306,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()),
@@ -1325,7 +1343,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(button);
return true;
}
@@ -2095,12 +2113,13 @@ void MenuController::IncrementSelection(
if (item->has_children()) {
CustomButton* button = GetFirstHotTrackedView(item);
if (button) {
- button->SetHotTracked(false);
+ DCHECK_EQ(hot_button_, button);
+ SetHotTrackedButton(nullptr);
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);
return;
}
} else {
@@ -2108,7 +2127,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);
return;
}
}
@@ -2612,7 +2631,15 @@ void MenuController::SetInitialHotTrackedView(
SetSelection(item, SELECTION_DEFAULT);
View* hot_view =
GetInitialFocusableView(item, direction == INCREMENT_SELECTION_DOWN);
- CustomButton* hot_button = CustomButton::AsCustomButton(hot_view);
+ SetHotTrackedButton(CustomButton::AsCustomButton(hot_view));
+}
+
+void MenuController::SetHotTrackedButton(CustomButton* hot_button) {
+ if (hot_button == hot_button_)
+ return;
+ if (hot_button_)
+ hot_button_->SetHotTracked(false);
+ hot_button_ = hot_button;
if (hot_button)
hot_button->SetHotTracked(true);
}
« 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