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..d7328398eba7dbff54cc5d6bd5c2905643c4852b 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,20 @@ 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: |
oshima
2011/04/15 22:26:51
please use new format
// ClockMenuButton, ...... :
rhashimoto
2011/04/15 23:44:32
Done.
|
+std::wstring ClockMenuButton::GetLabel(int id) const { |
+ DCHECK_EQ(CLOCK_DISPLAY_ITEM, id); |
+ 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 +164,33 @@ 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)); |
+ // 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()) |
+ window = source->GetWindow()->GetNativeWindow(); |
else |
- clock_menu_->Rebuild(); |
- clock_menu_->UpdateStates(); |
- clock_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); |
+ window = GTK_WINDOW(source->GetWidget()->GetNativeView()); |
oshima
2011/04/15 22:26:51
i now understand. all you need is this.
window =
rhashimoto
2011/04/15 23:44:32
I'd like to keep the other line present:
window
oshima
2011/04/15 23:52:19
It will not survive when you move to MenuButton. W
rhashimoto
2011/04/21 19:31:17
Done.
|
+ |
+ 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); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -180,4 +200,25 @@ 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 |