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

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

Issue 1775533002: Fixes incorrect clearing of hot-tracked state when context menu is opened from a menu item (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moves hot_button tracking from MenuController to MenuItemView Created 4 years, 9 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 3bbb0457f661c1ca2b67e4c921fa578b9df7a5d8..b0b5e9601284d6d6e384cf15d46161d7d91bce4c 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -558,8 +558,10 @@ bool MenuController::OnMousePressed(SubmenuView* source,
View* view =
forward_to_root->GetEventHandlerForPoint(event_for_root.location());
CustomButton* button = CustomButton::AsCustomButton(view);
- if (hot_button_ && hot_button_ != button)
- SetHotTrackedButton(nullptr);
+ MenuItemView* item = static_cast<MenuItemView*>(
+ button->GetAncestorWithClassName(MenuItemView::kViewClassName));
sky 2016/03/08 16:45:37 What if button is null?
varkha 2016/03/23 21:16:01 Acknowledged (this is no longer necessary if I don
+ if (item && item->hot_button() != button)
+ item->SetHotTrackedButton(nullptr);
// Empty menu items are always handled by the menu controller.
if (!view || view->id() != MenuItemView::kEmptyMenuItemViewID) {
@@ -718,9 +720,11 @@ void MenuController::OnMouseMoved(SubmenuView* source,
}
MenuHostRootView* root_view = GetRootView(source, event.location());
- if (root_view) {
+ if (root_view)
root_view->ProcessMouseMoved(event);
+ HandleMouseLocation(source, event.location());
+ if (pending_state_.item && root_view) {
// 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.
@@ -729,11 +733,12 @@ void MenuController::OnMouseMoved(SubmenuView* source,
View* view =
root_view->GetEventHandlerForPoint(event_for_root.location());
CustomButton* button = CustomButton::AsCustomButton(view);
- if (button && button->IsHotTracked())
- SetHotTrackedButton(button);
+ if (button && button->IsHotTracked() &&
+ button->GetAncestorWithClassName(MenuItemView::kViewClassName) ==
+ pending_state_.item) {
+ pending_state_.item->SetHotTrackedButton(button);
+ }
}
-
- HandleMouseLocation(source, event.location());
}
void MenuController::OnMouseEntered(SubmenuView* source,
@@ -758,8 +763,10 @@ void MenuController::OnGestureEvent(SubmenuView* source,
View* view =
root_view->GetEventHandlerForPoint(event_for_root.location());
CustomButton* button = CustomButton::AsCustomButton(view);
- if (hot_button_ && hot_button_ != button)
- SetHotTrackedButton(nullptr);
+ MenuItemView* item = static_cast<MenuItemView*>(
+ button->GetAncestorWithClassName(MenuItemView::kViewClassName));
+ if (item && item->hot_button() != button)
+ item->SetHotTrackedButton(nullptr);
}
MenuPart part = GetMenuPart(source, event->location());
@@ -834,9 +841,6 @@ void MenuController::ViewHierarchyChanged(
current_mouse_event_target_ = nullptr;
current_mouse_pressed_state_ = 0;
}
- // Update |hot_button_| if it gets removed while a menu is up.
- if (details.child == hot_button_)
- hot_button_ = nullptr;
}
}
@@ -1064,8 +1068,6 @@ void MenuController::SetSelection(MenuItemView* menu_item,
size_t new_size = new_path.size();
bool pending_item_changed = pending_state_.item != menu_item;
- if (pending_item_changed && pending_state_.item)
- SetHotTrackedButton(nullptr);
// Notify the old path it isn't selected.
MenuDelegate* current_delegate =
@@ -1316,7 +1318,6 @@ 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()),
@@ -1346,14 +1347,14 @@ void MenuController::RunMessageLoop(bool nested_menu) {
}
bool MenuController::SendAcceleratorToHotTrackedView() {
- CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item);
+ MenuItemView* item = pending_state_.item;
+ CustomButton* hot_view = GetFirstHotTrackedView(item);
if (!hot_view)
return false;
-
ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE);
hot_view->AcceleratorPressed(accelerator);
CustomButton* button = static_cast<CustomButton*>(hot_view);
- SetHotTrackedButton(button);
+ item->SetHotTrackedButton(button);
return true;
}
@@ -2123,8 +2124,8 @@ void MenuController::IncrementSelection(
if (item->has_children()) {
CustomButton* button = GetFirstHotTrackedView(item);
if (button) {
- DCHECK_EQ(hot_button_, button);
- SetHotTrackedButton(nullptr);
+ DCHECK_EQ(item->hot_button(), button);
+ item->SetHotTrackedButton(nullptr);
}
bool direction_is_down = direction == INCREMENT_SELECTION_DOWN;
View* to_make_hot = button
@@ -2132,7 +2133,7 @@ void MenuController::IncrementSelection(
: GetInitialFocusableView(item, direction_is_down);
CustomButton* hot_button = CustomButton::AsCustomButton(to_make_hot);
if (hot_button) {
- SetHotTrackedButton(hot_button);
+ item->SetHotTrackedButton(hot_button);
return;
}
}
@@ -2634,21 +2635,7 @@ void MenuController::SetInitialHotTrackedView(
SetSelection(item, SELECTION_DEFAULT);
View* hot_view =
GetInitialFocusableView(item, direction == INCREMENT_SELECTION_DOWN);
- SetHotTrackedButton(CustomButton::AsCustomButton(hot_view));
-}
-
-void MenuController::SetHotTrackedButton(CustomButton* hot_button) {
- if (hot_button == hot_button_) {
- // Hot-tracked state may change outside of the MenuController. Correct it.
- if (hot_button && !hot_button->IsHotTracked())
- hot_button->SetHotTracked(true);
- return;
- }
- if (hot_button_)
- hot_button_->SetHotTracked(false);
- hot_button_ = hot_button;
- if (hot_button)
- hot_button->SetHotTracked(true);
+ item->SetHotTrackedButton(CustomButton::AsCustomButton(hot_view));
}
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698