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

Unified Diff: ui/views/controls/menu/menu_item_view.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_item_view.cc
diff --git a/ui/views/controls/menu/menu_item_view.cc b/ui/views/controls/menu/menu_item_view.cc
index 8e3013b119756ffaab50866279c442f003116da6..930ca1efe1b01cba67577197a5d9c01af15901c5 100644
--- a/ui/views/controls/menu/menu_item_view.cc
+++ b/ui/views/controls/menu/menu_item_view.cc
@@ -112,7 +112,8 @@ MenuItemView::MenuItemView(MenuDelegate* delegate)
right_icon_margin_(0),
requested_menu_position_(POSITION_BEST_FIT),
actual_menu_position_(requested_menu_position_),
- use_right_margin_(true) {
+ use_right_margin_(true),
+ hot_button_(nullptr) {
// NOTE: don't check the delegate for NULL, UpdateMenuPartSizes() supplies a
// NULL delegate.
Init(NULL, 0, SUBMENU, delegate);
@@ -366,6 +367,8 @@ void MenuItemView::SetMinorText(const base::string16& minor_text) {
void MenuItemView::SetSelected(bool selected) {
selected_ = selected;
+ if (!selected_)
+ SetHotTrackedButton(nullptr);
SchedulePaint();
}
@@ -565,6 +568,20 @@ void MenuItemView::Layout() {
}
}
+void MenuItemView::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);
+}
+
void MenuItemView::SetMargins(int top_margin, int bottom_margin) {
top_margin_ = top_margin;
bottom_margin_ = bottom_margin;
@@ -593,7 +610,8 @@ MenuItemView::MenuItemView(MenuItemView* parent,
right_icon_margin_(0),
requested_menu_position_(POSITION_BEST_FIT),
actual_menu_position_(requested_menu_position_),
- use_right_margin_(true) {
+ use_right_margin_(true),
+ hot_button_(nullptr) {
Init(parent, command, type, NULL);
}
@@ -606,6 +624,15 @@ const char* MenuItemView::GetClassName() const {
return kViewClassName;
}
+void MenuItemView::ViewHierarchyChanged(
+ const ViewHierarchyChangedDetails& details) {
+ if (!details.is_add) {
+ // Update |hot_button_| if it gets removed while a menu is up.
+ if (details.child == hot_button_)
+ hot_button_ = nullptr;
+ }
+}
+
// Calculates all sizes that we can from the OS.
//
// This is invoked prior to Running a menu.
« ui/views/controls/menu/menu_controller.cc ('K') | « ui/views/controls/menu/menu_item_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698