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

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: Fixes for merge with trunk. 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
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 54ae8d732acf4cb9791a51d54e992709ad85439b..ba83e3b6e9ad2926f6b0dcba2640492a9537744e 100644
--- a/chrome/browser/chromeos/status/clock_menu_button.cc
+++ b/chrome/browser/chromeos/status/clock_menu_button.cc
@@ -20,8 +20,18 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font.h"
+#include "views/widget/widget.h"
+#include "views/window/window.h"
-namespace chromeos {
+using views::MenuItemView;
+
+namespace {
+
+// MenuItemView item ids
+enum {
+ CLOCK_DISPLAY_ITEM,
+ CLOCK_OPEN_OPTIONS_ITEM,
+};
// Amount of slop to add into the timer to make sure we're into the next minute
// when the timer goes off.
@@ -33,6 +43,10 @@ const int kFontSizeDelta = 0;
const int kFontSizeDelta = 1;
#endif
+} // namespace
+
+namespace chromeos {
+
ClockMenuButton::ClockMenuButton(StatusAreaHost* host)
: StatusAreaButton(this),
host_(host) {
@@ -115,35 +129,23 @@ void ClockMenuButton::Observe(NotificationType type,
}
}
-
-////////////////////////////////////////////////////////////////////////////////
-// 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
+{
oshima 2011/04/15 17:40:12 move { to pervious line. (and other places)
rhashimoto 2011/04/15 21:20:27 Done.
+ DCHECK_EQ(CLOCK_DISPLAY_ITEM,id);
oshima 2011/04/15 17:40:12 space after ,
rhashimoto 2011/04/15 21:20:27 Done.
+ const string16 label = base::TimeFormatFriendlyDate(base::Time::Now());
+ 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
+{
+ DCHECK(id == CLOCK_DISPLAY_ITEM || id == CLOCK_OPEN_OPTIONS_ITEM);
+ return id == CLOCK_OPEN_OPTIONS_ITEM;
}
-void ClockMenuButton::ActivatedAt(int index) {
+void ClockMenuButton::ExecuteCommand(int id)
+{
+ DCHECK_EQ(CLOCK_OPEN_OPTIONS_ITEM,id);
host_->OpenButtonOptions(this);
}
@@ -165,12 +167,39 @@ 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);
+ // View passed in must be a views::MenuButton, i.e. the ClockMenuButton.
+ DCHECK_EQ(source,this);
+
+ EnsureMenu();
+
+ // TODO(rhashimoto): Remove this workaround when WebUI provides a
+ // top-level widget on the ChromeOS login screen that is a window.
+ // The current BackgroundView class for the ChromeOS login screen
+ // creates a owning Widget that has a native GtkWindow but is not a
+ // Window. This makes it impossible to get the NativeWindow via
+ // the views API. This workaround casts the top-level NativeWidget
+ // to a NativeWindow that we can pass to MenuItemView::RunMenuAt().
+ gfx::NativeWindow window;
+ if (source->GetWindow()) {
+ // This is the normal case with a browser.
+ window = source->GetWindow()->GetNativeWindow();
+ } else {
+#if defined(OS_WIN)
+ NOTREACHED();
+#elif defined(USE_X11)
+ window = GTK_WINDOW(source->GetWidget()->GetNativeView());
+#endif
+ }
+
+ gfx::Point screen_loc;
+ views::View::ConvertPointToScreen(source, &screen_loc);
+ gfx::Rect bounds(screen_loc, source->size());
+ menu_->RunMenuAt(
+ window,
+ this,
+ bounds,
+ base::i18n::IsRTL() ? MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT,
+ true);
}
oshima 2011/04/15 17:40:12 Looks like we can move this to StatusAreaButton (a
rhashimoto 2011/04/15 21:20:27 If we were going to consolidate it, I think I'd pu
oshima 2011/04/15 22:35:18 sgtm
////////////////////////////////////////////////////////////////////////////////
@@ -180,4 +209,26 @@ void ClockMenuButton::OnLocaleChanged() {
UpdateText();
}
+void ClockMenuButton::EnsureMenu()
+{
+ 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));
+ }
+ }
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698