diff options
author | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-02 08:44:12 +0000 |
---|---|---|
committer | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-02 08:44:12 +0000 |
commit | 120a0ddbcda18f148d47c85865bf7e2817ae4f06 (patch) | |
tree | b9aaa67075dbeeba2ea7dbe6f8dc7850e4f192b3 /ash | |
parent | b185b52c32e731060ce4d3343cdf1e002033c2ff (diff) | |
download | chromium_src-120a0ddbcda18f148d47c85865bf7e2817ae4f06.zip chromium_src-120a0ddbcda18f148d47c85865bf7e2817ae4f06.tar.gz chromium_src-120a0ddbcda18f148d47c85865bf7e2817ae4f06.tar.bz2 |
Ports TrayIME notifications to message_center
This CL also introduces ClosureNotificationDelegate which provides
some reusable simple delegate (mostly for ash).
BUG=259134
R=stevenjb@chromium.org, nona@chromium.org, dewittj@chromium.org
TEST=manually
Review URL: https://chromiumcodereview.appspot.com/21058006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215249 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/system/chromeos/tray_display.cc | 29 | ||||
-rw-r--r-- | ash/system/ime/tray_ime.cc | 109 | ||||
-rw-r--r-- | ash/system/ime/tray_ime.h | 10 |
3 files changed, 57 insertions, 91 deletions
diff --git a/ash/system/chromeos/tray_display.cc b/ash/system/chromeos/tray_display.cc index bb00e54..4f4e8c1 100644 --- a/ash/system/chromeos/tray_display.cc +++ b/ash/system/chromeos/tray_display.cc @@ -13,6 +13,7 @@ #include "ash/system/tray/system_tray_delegate.h" #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_notification_view.h" +#include "base/bind.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "grit/ash_resources.h" @@ -180,28 +181,6 @@ void OpenSettings(user::LoginStatus login_status) { } } -class DisplayNotificationDelegate - : public message_center::NotificationDelegate { - public: - DisplayNotificationDelegate(user::LoginStatus login_status) - : login_status_(login_status) {} - - // message_center::NotificationDelegate overrides: - virtual void Display() OVERRIDE {} - virtual void Error() OVERRIDE {} - virtual void Close(bool by_user) OVERRIDE {} - virtual bool HasClickedListener() OVERRIDE { return true; } - virtual void Click() OVERRIDE { OpenSettings(login_status_); } - - protected: - virtual ~DisplayNotificationDelegate() {} - - private: - user::LoginStatus login_status_; - - DISALLOW_COPY_AND_ASSIGN(DisplayNotificationDelegate); -}; - void UpdateDisplayNotification(const base::string16& message) { // Always remove the notification to make sure the notification appears // as a popup in any situation. @@ -221,8 +200,10 @@ void UpdateDisplayNotification(const base::string16& message) { base::string16(), // display_source "", // extension_id message_center::RichNotificationData(), - new DisplayNotificationDelegate( - Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()))); + new message_center::HandleNotificationClickedDelegate( + base::Bind(&OpenSettings, + Shell::GetInstance()->system_tray_delegate()-> + GetUserLoginStatus())))); message_center::MessageCenter::Get()->AddNotification(notification.Pass()); } diff --git a/ash/system/ime/tray_ime.cc b/ash/system/ime/tray_ime.cc index fac23a5..6fac8fd 100644 --- a/ash/system/ime/tray_ime.cc +++ b/ash/system/ime/tray_ime.cc @@ -17,7 +17,6 @@ #include "ash/system/tray/tray_details_view.h" #include "ash/system/tray/tray_item_more.h" #include "ash/system/tray/tray_item_view.h" -#include "ash/system/tray/tray_notification_view.h" #include "ash/system/tray/tray_utils.h" #include "base/logging.h" #include "base/strings/utf_string_conversions.h" @@ -27,13 +26,23 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/font.h" #include "ui/gfx/image/image.h" +#include "ui/message_center/message_center.h" +#include "ui/message_center/notification.h" +#include "ui/message_center/notification_delegate.h" #include "ui/views/controls/label.h" #include "ui/views/layout/box_layout.h" #include "ui/views/widget/widget.h" +using message_center::Notification; + +namespace { + +const char kIMENotificationId[] = "chrome://settings/ime"; + +} // namespace + namespace ash { namespace internal { - namespace tray { class IMEDefaultView : public TrayItemMore { @@ -168,44 +177,6 @@ class IMEDetailedView : public TrayDetailsView, DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); }; -class IMENotificationView : public TrayNotificationView { - public: - explicit IMENotificationView(TrayIME* owner) - : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_IME) { - InitView(GetLabel()); - } - - void UpdateLabel() { - RestartAutoCloseTimer(); - UpdateView(GetLabel()); - } - - // Overridden from TrayNotificationView. - virtual void OnClickAction() OVERRIDE { - owner()->PopupDetailedView(0, true); - } - - private: - views::Label* GetLabel() { - SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); - IMEInfo current; - delegate->GetCurrentIME(¤t); - - // TODO(zork): Use IDS_ASH_STATUS_TRAY_THIRD_PARTY_IME_TURNED_ON_BUBBLE for - // third party IMEs - views::Label* label = new views::Label( - l10n_util::GetStringFUTF16( - IDS_ASH_STATUS_TRAY_IME_TURNED_ON_BUBBLE, - current.medium_name)); - label->SetMultiLine(true); - label->SetHorizontalAlignment(gfx::ALIGN_LEFT); - return label; - } - - DISALLOW_COPY_AND_ASSIGN(IMENotificationView); -}; - - } // namespace tray TrayIME::TrayIME(SystemTray* system_tray) @@ -213,13 +184,14 @@ TrayIME::TrayIME(SystemTray* system_tray) tray_label_(NULL), default_(NULL), detailed_(NULL), - notification_(NULL), message_shown_(false) { Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this); } TrayIME::~TrayIME() { Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this); + message_center::MessageCenter::Get()->RemoveNotification( + kIMENotificationId, false /* by_user */); } void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { @@ -235,6 +207,37 @@ void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { } } +void TrayIME::UpdateOrCreateNotification() { + message_center::MessageCenter* message_center = + message_center::MessageCenter::Get(); + + if (!message_center->HasNotification(kIMENotificationId) && message_shown_) + return; + + SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); + IMEInfo current; + delegate->GetCurrentIME(¤t); + + scoped_ptr<Notification> notification(new Notification( + message_center::NOTIFICATION_TYPE_SIMPLE, + kIMENotificationId, + // TODO(zork): Use IDS_ASH_STATUS_TRAY_THIRD_PARTY_IME_TURNED_ON_BUBBLE + // for third party IMEs + l10n_util::GetStringFUTF16( + IDS_ASH_STATUS_TRAY_IME_TURNED_ON_BUBBLE, + current.medium_name), + base::string16(), // message + gfx::Image(), // icon + base::string16(), // display_source + "", // extension_id + message_center::RichNotificationData(), + new message_center::HandleNotificationClickedDelegate( + base::Bind(&TrayIME::PopupDetailedView, + base::Unretained(this), 0, true)))); + message_center->AddNotification(notification.Pass()); + message_shown_ = true; +} + views::View* TrayIME::CreateTrayView(user::LoginStatus status) { CHECK(tray_label_ == NULL); tray_label_ = new TrayItemView(this); @@ -265,13 +268,6 @@ views::View* TrayIME::CreateDetailedView(user::LoginStatus status) { return detailed_; } -views::View* TrayIME::CreateNotificationView(user::LoginStatus status) { - DCHECK(notification_ == NULL); - notification_ = new tray::IMENotificationView(this); - notification_->StartAutoCloseTimer(kTrayPopupAutoCloseDelayForTextInSeconds); - return notification_; -} - void TrayIME::DestroyTrayView() { tray_label_ = NULL; } @@ -284,10 +280,6 @@ void TrayIME::DestroyDetailedView() { detailed_ = NULL; } -void TrayIME::DestroyNotificationView() { - notification_ = NULL; -} - void TrayIME::UpdateAfterLoginStatusChange(user::LoginStatus status) { } @@ -311,17 +303,8 @@ void TrayIME::OnIMERefresh(bool show_message) { if (detailed_) detailed_->Update(list, property_list); - if (list.size() > 1 && show_message) { - // If the notification is still visible, hide it and clear the flag so it is - // refreshed. - if (notification_) { - notification_->UpdateLabel(); - } else if (!Shell::GetPrimaryRootWindowController()->shelf()->IsVisible() || - !message_shown_) { - ShowNotificationView(); - message_shown_ = true; - } - } + if (list.size() > 1 && show_message) + UpdateOrCreateNotification(); } } // namespace internal diff --git a/ash/system/ime/tray_ime.h b/ash/system/ime/tray_ime.h index 351e1e4..b237ae1 100644 --- a/ash/system/ime/tray_ime.h +++ b/ash/system/ime/tray_ime.h @@ -35,16 +35,19 @@ class TrayIME : public SystemTrayItem, private: void UpdateTrayLabel(const IMEInfo& info, size_t count); + // Update the content of the existing IME notification, or create a new one if + // necessary. IME notification should be created only once in a session, i.e. + // if an IME notification is created and removed already, it doesn't create a + // new one. + void UpdateOrCreateNotification(); + // Overridden from SystemTrayItem. virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; - virtual views::View* CreateNotificationView( - user::LoginStatus status) OVERRIDE; virtual void DestroyTrayView() OVERRIDE; virtual void DestroyDefaultView() OVERRIDE; virtual void DestroyDetailedView() OVERRIDE; - virtual void DestroyNotificationView() OVERRIDE; virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; virtual void UpdateAfterShelfAlignmentChange( ShelfAlignment alignment) OVERRIDE; @@ -55,7 +58,6 @@ class TrayIME : public SystemTrayItem, TrayItemView* tray_label_; tray::IMEDefaultView* default_; tray::IMEDetailedView* detailed_; - tray::IMENotificationView* notification_; bool message_shown_; |