Chromium Code Reviews| 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 e9b7321342d885af224bfc8c3d2c30d9debdc3d3..efef70457384b0de2bcfb0fd876f4b8db79a7d05 100644 |
| --- a/ui/views/controls/menu/menu_controller.cc |
| +++ b/ui/views/controls/menu/menu_controller.cc |
| @@ -715,8 +715,18 @@ void MenuController::OnMouseMoved(SubmenuView* source, |
| } |
| MenuHostRootView* root_view = GetRootView(source, event.location()); |
| - if (root_view) |
| + if (root_view) { |
| root_view->ProcessMouseMoved(event); |
| + |
| + 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()); |
| } |
| @@ -800,10 +810,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. |
| + if (details.child == hot_button_) |
| + hot_button_ = nullptr; |
| } |
| } |
| @@ -1033,8 +1048,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); |
| - if (button) |
| - button->SetHotTracked(false); |
| + if (button) { |
| + DCHECK_EQ(hot_button_, button); |
| + SetHotTrackedButton(nullptr); |
| + } |
| } |
| // Notify the old path it isn't selected. |
| @@ -1286,6 +1303,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()), |
| @@ -1322,7 +1340,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; |
| } |
| @@ -2084,8 +2102,14 @@ 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) |
| + if (to_select) { |
| 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) |
| + SetHotTrackedButton(button_hot); |
|
varkha
2016/02/26 22:09:06
This block will not be necessary after https://cod
varkha
2016/02/26 22:34:42
Done.
|
| + } |
| return; |
| } |
| } |
| @@ -2093,12 +2117,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 { |
| @@ -2106,7 +2131,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; |
| } |
| } |
| @@ -2127,7 +2152,7 @@ void MenuController::IncrementSelection( |
| to_select, direction == INCREMENT_SELECTION_DOWN); |
| CustomButton* button_hot = CustomButton::AsCustomButton(to_make_hot); |
| if (button_hot) |
| - button_hot->SetHotTracked(true); |
| + SetHotTrackedButton(button_hot); |
| break; |
| } |
| } |
| @@ -2609,4 +2634,14 @@ void MenuController::HandleMouseLocation(SubmenuView* source, |
| } |
| } |
| +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); |
| +} |
| + |
| } // namespace views |