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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/menu/menu_item_view.h" 5 #include "ui/views/controls/menu/menu_item_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 has_mnemonics_(false), 105 has_mnemonics_(false),
106 show_mnemonics_(false), 106 show_mnemonics_(false),
107 has_icons_(false), 107 has_icons_(false),
108 icon_view_(NULL), 108 icon_view_(NULL),
109 top_margin_(-1), 109 top_margin_(-1),
110 bottom_margin_(-1), 110 bottom_margin_(-1),
111 left_icon_margin_(0), 111 left_icon_margin_(0),
112 right_icon_margin_(0), 112 right_icon_margin_(0),
113 requested_menu_position_(POSITION_BEST_FIT), 113 requested_menu_position_(POSITION_BEST_FIT),
114 actual_menu_position_(requested_menu_position_), 114 actual_menu_position_(requested_menu_position_),
115 use_right_margin_(true) { 115 use_right_margin_(true),
116 hot_button_(nullptr) {
116 // NOTE: don't check the delegate for NULL, UpdateMenuPartSizes() supplies a 117 // NOTE: don't check the delegate for NULL, UpdateMenuPartSizes() supplies a
117 // NULL delegate. 118 // NULL delegate.
118 Init(NULL, 0, SUBMENU, delegate); 119 Init(NULL, 0, SUBMENU, delegate);
119 } 120 }
120 121
121 void MenuItemView::ChildPreferredSizeChanged(View* child) { 122 void MenuItemView::ChildPreferredSizeChanged(View* child) {
122 invalidate_dimensions(); 123 invalidate_dimensions();
123 PreferredSizeChanged(); 124 PreferredSizeChanged();
124 } 125 }
125 126
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 invalidate_dimensions(); // Triggers preferred size recalculation. 360 invalidate_dimensions(); // Triggers preferred size recalculation.
360 } 361 }
361 362
362 void MenuItemView::SetMinorText(const base::string16& minor_text) { 363 void MenuItemView::SetMinorText(const base::string16& minor_text) {
363 minor_text_ = minor_text; 364 minor_text_ = minor_text;
364 invalidate_dimensions(); // Triggers preferred size recalculation. 365 invalidate_dimensions(); // Triggers preferred size recalculation.
365 } 366 }
366 367
367 void MenuItemView::SetSelected(bool selected) { 368 void MenuItemView::SetSelected(bool selected) {
368 selected_ = selected; 369 selected_ = selected;
370 if (!selected_)
371 SetHotTrackedButton(nullptr);
369 SchedulePaint(); 372 SchedulePaint();
370 } 373 }
371 374
372 void MenuItemView::SetTooltip(const base::string16& tooltip, int item_id) { 375 void MenuItemView::SetTooltip(const base::string16& tooltip, int item_id) {
373 MenuItemView* item = GetMenuItemByID(item_id); 376 MenuItemView* item = GetMenuItemByID(item_id);
374 DCHECK(item); 377 DCHECK(item);
375 item->tooltip_ = tooltip; 378 item->tooltip_ = tooltip;
376 } 379 }
377 380
378 void MenuItemView::SetIcon(const gfx::ImageSkia& icon, int item_id) { 381 void MenuItemView::SetIcon(const gfx::ImageSkia& icon, int item_id) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 (icon_area_width_ - size.width()) / 2; 561 (icon_area_width_ - size.width()) / 2;
559 if (config.icons_in_label || type_ == CHECKBOX || type_ == RADIO) 562 if (config.icons_in_label || type_ == CHECKBOX || type_ == RADIO)
560 x = label_start_; 563 x = label_start_;
561 int y = 564 int y =
562 (height() + GetTopMargin() - GetBottomMargin() - size.height()) / 2; 565 (height() + GetTopMargin() - GetBottomMargin() - size.height()) / 2;
563 icon_view_->SetPosition(gfx::Point(x, y)); 566 icon_view_->SetPosition(gfx::Point(x, y));
564 } 567 }
565 } 568 }
566 } 569 }
567 570
571 void MenuItemView::SetHotTrackedButton(CustomButton* hot_button) {
572 if (hot_button == hot_button_) {
573 // Hot-tracked state may change outside of the MenuController. Correct it.
574 if (hot_button && !hot_button->IsHotTracked())
575 hot_button->SetHotTracked(true);
576 return;
577 }
578 if (hot_button_)
579 hot_button_->SetHotTracked(false);
580 hot_button_ = hot_button;
581 if (hot_button)
582 hot_button->SetHotTracked(true);
583 }
584
568 void MenuItemView::SetMargins(int top_margin, int bottom_margin) { 585 void MenuItemView::SetMargins(int top_margin, int bottom_margin) {
569 top_margin_ = top_margin; 586 top_margin_ = top_margin;
570 bottom_margin_ = bottom_margin; 587 bottom_margin_ = bottom_margin;
571 588
572 invalidate_dimensions(); 589 invalidate_dimensions();
573 } 590 }
574 591
575 MenuItemView::MenuItemView(MenuItemView* parent, 592 MenuItemView::MenuItemView(MenuItemView* parent,
576 int command, 593 int command,
577 MenuItemView::Type type) 594 MenuItemView::Type type)
578 : delegate_(NULL), 595 : delegate_(NULL),
579 controller_(NULL), 596 controller_(NULL),
580 canceled_(false), 597 canceled_(false),
581 parent_menu_item_(parent), 598 parent_menu_item_(parent),
582 type_(type), 599 type_(type),
583 selected_(false), 600 selected_(false),
584 command_(command), 601 command_(command),
585 submenu_(NULL), 602 submenu_(NULL),
586 has_mnemonics_(false), 603 has_mnemonics_(false),
587 show_mnemonics_(false), 604 show_mnemonics_(false),
588 has_icons_(false), 605 has_icons_(false),
589 icon_view_(NULL), 606 icon_view_(NULL),
590 top_margin_(-1), 607 top_margin_(-1),
591 bottom_margin_(-1), 608 bottom_margin_(-1),
592 left_icon_margin_(0), 609 left_icon_margin_(0),
593 right_icon_margin_(0), 610 right_icon_margin_(0),
594 requested_menu_position_(POSITION_BEST_FIT), 611 requested_menu_position_(POSITION_BEST_FIT),
595 actual_menu_position_(requested_menu_position_), 612 actual_menu_position_(requested_menu_position_),
596 use_right_margin_(true) { 613 use_right_margin_(true),
614 hot_button_(nullptr) {
597 Init(parent, command, type, NULL); 615 Init(parent, command, type, NULL);
598 } 616 }
599 617
600 MenuItemView::~MenuItemView() { 618 MenuItemView::~MenuItemView() {
601 delete submenu_; 619 delete submenu_;
602 STLDeleteElements(&removed_items_); 620 STLDeleteElements(&removed_items_);
603 } 621 }
604 622
605 const char* MenuItemView::GetClassName() const { 623 const char* MenuItemView::GetClassName() const {
606 return kViewClassName; 624 return kViewClassName;
607 } 625 }
608 626
627 void MenuItemView::ViewHierarchyChanged(
628 const ViewHierarchyChangedDetails& details) {
629 if (!details.is_add) {
630 // Update |hot_button_| if it gets removed while a menu is up.
631 if (details.child == hot_button_)
632 hot_button_ = nullptr;
633 }
634 }
635
609 // Calculates all sizes that we can from the OS. 636 // Calculates all sizes that we can from the OS.
610 // 637 //
611 // This is invoked prior to Running a menu. 638 // This is invoked prior to Running a menu.
612 void MenuItemView::UpdateMenuPartSizes() { 639 void MenuItemView::UpdateMenuPartSizes() {
613 const MenuConfig& config = MenuConfig::instance(); 640 const MenuConfig& config = MenuConfig::instance();
614 641
615 item_right_margin_ = config.label_to_arrow_padding + config.arrow_width + 642 item_right_margin_ = config.label_to_arrow_padding + config.arrow_width +
616 config.arrow_to_edge_padding; 643 config.arrow_to_edge_padding;
617 icon_area_width_ = config.check_width; 644 icon_area_width_ = config.check_width;
618 if (has_icons_) 645 if (has_icons_)
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 } else { 1108 } else {
1082 const Type& type = menu_item->GetType(); 1109 const Type& type = menu_item->GetType();
1083 if (type == CHECKBOX || type == RADIO) 1110 if (type == CHECKBOX || type == RADIO)
1084 return true; 1111 return true;
1085 } 1112 }
1086 } 1113 }
1087 return false; 1114 return false;
1088 } 1115 }
1089 1116
1090 } // namespace views 1117 } // namespace views
OLDNEW
« 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