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

Unified Diff: chrome/browser/chromeos/status/clock_menu_button.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: chrome/browser/chromeos/status/clock_menu_button.cc
diff --git a/chrome/browser/chromeos/status/clock_menu_button.cc b/chrome/browser/chromeos/status/clock_menu_button.cc
index 5e1706610cefc80232d0a6d083e7877cee05b184..3b0384c605ed4dd1fe84136761e31a117737a21b 100644
--- a/chrome/browser/chromeos/status/clock_menu_button.cc
+++ b/chrome/browser/chromeos/status/clock_menu_button.cc
@@ -20,6 +20,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font.h"
+#include "views/controls/menu/menu_runner.h"
#include "views/widget/widget.h"
#include "unicode/datefmt.h"
@@ -155,12 +156,11 @@ void ClockMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
gfx::Point screen_location;
views::View::ConvertPointToScreen(source, &screen_location);
gfx::Rect bounds(screen_location, source->size());
- menu_->RunMenuAt(
- source->GetWidget()->GetTopLevelWidget(),
- this,
- bounds,
- views::MenuItemView::TOPRIGHT,
- true);
+ if (menu_runner_->RunMenuAt(
+ source->GetWidget()->GetTopLevelWidget(), this, bounds,
+ views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) ==
+ views::MenuRunner::MENU_DELETED)
+ return;
}
// ClockMenuButton, views::View implementation:
@@ -170,23 +170,26 @@ void ClockMenuButton::OnLocaleChanged() {
}
void ClockMenuButton::EnsureMenu() {
- if (!menu_.get()) {
- menu_.reset(new views::MenuItemView(this));
-
- // Text for this item will be set by GetLabel().
- menu_->AppendDelegateMenuItem(CLOCK_DISPLAY_ITEM);
-
- // If options dialog is unavailable, don't show a separator and configure
- // menu item.
- if (host_->ShouldOpenButtonOptions(this)) {
- menu_->AppendSeparator();
-
- const string16 clock_open_options_label =
- l10n_util::GetStringUTF16(IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG);
- menu_->AppendMenuItemWithLabel(
- CLOCK_OPEN_OPTIONS_ITEM,
- UTF16ToWide(clock_open_options_label));
- }
+ if (menu_runner_.get())
+ return;
+
+ views::MenuItemView* menu = new views::MenuItemView(this);
+ // menu_runner_ takes ownership of menu.
+ menu_runner_.reset(new views::MenuRunner(menu));
+
+ // Text for this item will be set by GetLabel().
+ menu->AppendDelegateMenuItem(CLOCK_DISPLAY_ITEM);
+
+ // If options dialog is unavailable, don't show a separator and configure
+ // menu item.
+ if (host_->ShouldOpenButtonOptions(this)) {
+ menu->AppendSeparator();
+
+ const string16 clock_open_options_label =
+ l10n_util::GetStringUTF16(IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG);
+ menu->AppendMenuItemWithLabel(
+ CLOCK_OPEN_OPTIONS_ITEM,
+ UTF16ToWide(clock_open_options_label));
}
}

Powered by Google App Engine
This is Rietveld 408576698