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

Unified Diff: views/controls/combobox/native_combobox_views.cc

Issue 7720012: Moves ownership of MenuItemView to MenuRunner as well as responbility (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 9 years, 4 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: views/controls/combobox/native_combobox_views.cc
diff --git a/views/controls/combobox/native_combobox_views.cc b/views/controls/combobox/native_combobox_views.cc
index 6a7b318b874fe5707434a42eb8ccbc82e7972c28..469661585849c437607959454f79c8ab54815062 100644
--- a/views/controls/combobox/native_combobox_views.cc
+++ b/views/controls/combobox/native_combobox_views.cc
@@ -18,6 +18,7 @@
#include "views/border.h"
#include "views/controls/combobox/combobox.h"
#include "views/controls/focusable_border.h"
+#include "views/controls/menu/menu_runner.h"
#include "views/controls/menu/submenu_view.h"
#include "views/widget/root_view.h"
#include "views/widget/widget.h"
@@ -163,7 +164,9 @@ void NativeComboboxViews::UpdateFromModel() {
int max_width = 0;
const gfx::Font &font = GetFont();
- dropdown_list_menu_.reset(new MenuItemView(this));
+ MenuItemView* menu = new MenuItemView(this);
+ // MenuRunner owns |menu|.
+ dropdown_list_menu_runner_.reset(new MenuRunner(menu));
int num_items = combobox_->model()->GetItemCount();
for (int i = 0; i < num_items; ++i) {
@@ -173,10 +176,10 @@ void NativeComboboxViews::UpdateFromModel() {
// text is displayed correctly in right-to-left UIs.
base::i18n::AdjustStringForLocaleDirection(&text);
- dropdown_list_menu_->AppendMenuItem(i + kFirstMenuItemId, UTF16ToWide(text),
- MenuItemView::NORMAL);
- max_width = std::max(max_width, font.GetStringWidth(text));
- }
+ menu->AppendMenuItem(i + kFirstMenuItemId, UTF16ToWide(text),
+ MenuItemView::NORMAL);
+ max_width = std::max(max_width, font.GetStringWidth(text));
+ }
content_width_ = max_width;
content_height_ = font.GetFontSize();
@@ -342,11 +345,11 @@ void NativeComboboxViews::PaintText(gfx::Canvas* canvas) {
void NativeComboboxViews::ShowDropDownMenu() {
- if (!dropdown_list_menu_.get())
+ if (!dropdown_list_menu_runner_.get())
UpdateFromModel();
// Extend the menu to the width of the combobox.
- SubmenuView* submenu = dropdown_list_menu_->CreateSubmenu();
+ SubmenuView* submenu = dropdown_list_menu_runner_->GetMenu()->CreateSubmenu();
submenu->set_minimum_preferred_width(size().width());
gfx::Rect lb = GetLocalBounds();
@@ -358,8 +361,10 @@ void NativeComboboxViews::ShowDropDownMenu() {
gfx::Rect bounds(menu_position, lb.size());
dropdown_open_ = true;
- dropdown_list_menu_->RunMenuAt(NULL, NULL, bounds, MenuItemView::TOPLEFT,
- true);
+ if (dropdown_list_menu_runner_->RunMenuAt(
+ NULL, NULL, bounds, MenuItemView::TOPLEFT,
+ MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED)
+ return;
dropdown_open_ = false;
// Need to explicitly clear mouse handler so that events get sent

Powered by Google App Engine
This is Rietveld 408576698