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

Unified Diff: chrome/browser/chromeos/status/clock_menu_button.cc

Issue 6811025: Change status button menu implementation from Menu2 to MenuItemView. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Use MenuItemView convenience function. Created 9 years, 8 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
« no previous file with comments | « chrome/browser/chromeos/status/clock_menu_button.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 12eb535b86a1fa6368c85a5b87cea947d0dd21d0..134f1f4a4e345145d1f5adc951b635a9f03bbb1a 100644
--- a/chrome/browser/chromeos/status/clock_menu_button.cc
+++ b/chrome/browser/chromeos/status/clock_menu_button.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -15,6 +15,19 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font.h"
+#include "views/window/window.h"
+
+using views::MenuItemView;
oshima 2011/04/08 17:21:17 move this nito chromeos namespace.
rhashimoto 2011/04/14 00:58:54 The using declaration or the anonymous namespace c
+
+namespace {
+
+// MenuItemView item ids
+enum {
+ CLOCK_DISPLAY_ITEM,
+ CLOCK_OPEN_OPTIONS_ITEM,
+};
+
+} // anonymous namespace
oshima 2011/04/08 17:21:17 two space before // just "namespace"
rhashimoto 2011/04/14 00:58:54 Done.
namespace chromeos {
@@ -82,34 +95,37 @@ void ClockMenuButton::UpdateText() {
}
////////////////////////////////////////////////////////////////////////////////
-// ClockMenuButton, ui::MenuModel implementation:
-
-int ClockMenuButton::GetItemCount() const {
- // If options dialog is unavailable, don't count a separator and configure
- // menu item.
- return host_->ShouldOpenButtonOptions(this) ? 3 : 1;
-}
-
-ui::MenuModel::ItemType ClockMenuButton::GetTypeAt(int index) const {
- // There's a separator between the current date and the menu item to open
- // the options menu.
- return index == 1 ? ui::MenuModel::TYPE_SEPARATOR:
- ui::MenuModel::TYPE_COMMAND;
-}
-
-string16 ClockMenuButton::GetLabelAt(int index) const {
- if (index == 0)
- return base::TimeFormatFriendlyDate(base::Time::Now());
- return l10n_util::GetStringUTF16(IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG);
+// ClockMenuButton, views::MenuDelegate implementation:
+std::wstring ClockMenuButton::GetLabel(int id) const
+{
+ string16 label;
+ switch (id) {
+ case CLOCK_DISPLAY_ITEM:
+ label = base::TimeFormatFriendlyDate(base::Time::Now());
+ break;
oshima 2011/04/08 17:21:17 just use if I assume else case shouldn't happen? I
rhashimoto 2011/04/14 00:58:54 Done.
+ }
+
+ return UTF16ToWide(label);
}
-bool ClockMenuButton::IsEnabledAt(int index) const {
- // The 1st item is the current date, which is disabled.
- return index != 0;
+bool ClockMenuButton::IsCommandEnabled(int id) const
+{
+ switch (id) {
+ case CLOCK_DISPLAY_ITEM:
+ return false;
oshima 2011/04/08 17:21:17 same here.
rhashimoto 2011/04/14 00:58:54 This one is disabled only for CLOCK_DISPLAY_ITEM.
+ default:
+ return true;
+ }
}
-void ClockMenuButton::ActivatedAt(int index) {
- host_->OpenButtonOptions(this);
+void ClockMenuButton::ExecuteCommand(int id)
+{
+ switch (id)
+ {
+ case CLOCK_OPEN_OPTIONS_ITEM:
+ host_->OpenButtonOptions(this);
oshima 2011/04/08 17:21:17 same here
rhashimoto 2011/04/14 00:58:54 Done.
+ break;
+ }
}
///////////////////////////////////////////////////////////////////////////////
@@ -130,12 +146,34 @@ void ClockMenuButton::TimezoneChanged(const icu::TimeZone& timezone) {
// ClockMenuButton, views::ViewMenuDelegate implementation:
void ClockMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
- if (!clock_menu_.get())
- clock_menu_.reset(new views::Menu2(this));
- else
- clock_menu_->Rebuild();
- clock_menu_->UpdateStates();
- clock_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
+ if (!menu_.get()) {
+ menu_.reset(new MenuItemView(this));
+
+ // Text for this item will be set by GetLabel().
+ menu_->AppendDelegateMenuItem(CLOCK_DISPLAY_ITEM);
+
+ // If options dialog is unavailable, don't count 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));
+ }
+ }
+
+ gfx::Point screen_loc;
+ views::View::ConvertPointToScreen(source, &screen_loc);
+ gfx::Rect bounds(screen_loc, source->size());
oshima 2011/04/08 17:21:17 will RTL work with this?
rhashimoto 2011/04/14 00:58:54 I don't know, but this is how the WrenchMenu is im
+ menu_->RunMenuAt(
+ source->GetWindow()->GetNativeWindow(),
+ this,
+ bounds,
+ base::i18n::IsRTL() ? MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT,
+ true);
}
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/status/clock_menu_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698