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

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: Changed refcount guard to use OS_CHROMEOS. 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 12eb535b86a1fa6368c85a5b87cea947d0dd21d0..11ffee3c8509d6f24d85c14ed35746f5079766b5 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,9 +15,19 @@
#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"
+
+using views::MenuItemView;
namespace chromeos {
+// 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.
const int kTimerSlopSeconds = 1;
@@ -82,33 +92,26 @@ 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;
+// ClockMenuButton, views::MenuDelegate implementation:
+std::wstring ClockMenuButton::GetLabel(int id) const
+{
+ DCHECK(id == CLOCK_DISPLAY_ITEM);
oshima 2011/04/14 17:27:31 DCHECK_EQ note: expected value first
rhashimoto 2011/04/14 18:27:04 Done.
+ const string16 label = base::TimeFormatFriendlyDate(base::Time::Now());
+ return UTF16ToWide(label);
}
-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);
-}
-
-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);
+ if (id == CLOCK_DISPLAY_ITEM)
oshima 2011/04/14 17:27:31 return id == CLOCK_OPEN_OPTIONS_ITEM
rhashimoto 2011/04/14 18:27:04 Done.
+ return false;
+ else
+ return true;
}
-void ClockMenuButton::ActivatedAt(int index) {
+void ClockMenuButton::ExecuteCommand(int id)
+{
+ DCHECK(id == CLOCK_OPEN_OPTIONS_ITEM);
oshima 2011/04/14 17:27:31 DCHECK_EQ
rhashimoto 2011/04/14 18:27:04 Done.
host_->OpenButtonOptions(this);
}
@@ -130,12 +133,56 @@ 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(source == this);
oshima 2011/04/14 17:27:31 DCHECK_EQ
rhashimoto 2011/04/14 18:27:04 Done.
+
+ 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));
+ }
+ }
oshima 2011/04/14 17:27:31 It's probably better to separate above code. I'm f
rhashimoto 2011/04/14 18:27:04 Done.
+
+ // 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().
oshima 2011/04/14 17:27:31 won't this work? source->GetWidget()->GetToplevel
rhashimoto 2011/04/14 18:27:04 That gets the NativeView, but we have to pass a Na
oshima 2011/04/15 17:40:12 NativeView is gtk_windonw instance in gtk_widget t
rhashimoto 2011/04/15 21:20:27 I think this is fundamentally what I've done, i.e.
+ 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
oshima 2011/04/15 17:40:12 no need for ifdefs as ths is only for chromeos
rhashimoto 2011/04/15 21:20:27 Done. I was thinking that the #ifdefs signalled t
+ }
+
+ 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);
}
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698