diff options
author | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-19 23:22:08 +0000 |
---|---|---|
committer | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-19 23:22:08 +0000 |
commit | d07a0e72bcbfe63c859855bf72912af65123b4d7 (patch) | |
tree | 69cade1a130bec45f6f620ab664623aac8b6e442 /ash/system/web_notification | |
parent | 2871722de956b92049a2febce1c490960c56ef02 (diff) | |
download | chromium_src-d07a0e72bcbfe63c859855bf72912af65123b4d7.zip chromium_src-d07a0e72bcbfe63c859855bf72912af65123b4d7.tar.gz chromium_src-d07a0e72bcbfe63c859855bf72912af65123b4d7.tar.bz2 |
Places the unread count in the middle of web notification tray button.
In the new design, we places the unread count of the notifications to the button.
If there are no unread notifications, we still use the existing dim icon.
Othewise, the count is put in the middle. "9+" is used if more than 9 unread
notifications.
BUG=189129
Review URL: https://codereview.chromium.org/14366014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195333 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/system/web_notification')
-rw-r--r-- | ash/system/web_notification/web_notification_tray.cc | 94 | ||||
-rw-r--r-- | ash/system/web_notification/web_notification_tray.h | 3 |
2 files changed, 78 insertions, 19 deletions
diff --git a/ash/system/web_notification/web_notification_tray.cc b/ash/system/web_notification/web_notification_tray.cc index 9c2aa04..7931a03 100644 --- a/ash/system/web_notification/web_notification_tray.cc +++ b/ash/system/web_notification/web_notification_tray.cc @@ -12,6 +12,9 @@ #include "ash/system/tray/tray_background_view.h" #include "ash/system/tray/tray_bubble_wrapper.h" #include "ash/system/tray/tray_constants.h" +#include "ash/system/tray/tray_views.h" +#include "base/strings/string_number_conversions.h" +#include "base/utf_string_conversions.h" #include "grit/ash_resources.h" #include "grit/ui_strings.h" #include "ui/aura/root_window.h" @@ -27,6 +30,7 @@ #include "ui/message_center/views/message_popup_collection.h" #include "ui/views/bubble/tray_bubble_view.h" #include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/menu/menu_runner.h" #if defined(OS_CHROMEOS) @@ -44,8 +48,14 @@ MessageCenterTrayDelegate* CreateMessageCenterTray() { #endif // defined(OS_CHROMEOS) namespace ash { - namespace internal { +namespace { + +// The text cannot be placed in the middle of the button vertically. This +// constant is used to modify the vertical position of the text. +const int kUnreadLabelBottomOffset = 6; + +} // Class to initialize and manage the WebNotificationBubble and // TrayBubbleWrapper instances for a bubble. @@ -80,6 +90,69 @@ class WebNotificationBubbleWrapper { private: scoped_ptr<message_center::MessageBubbleBase> bubble_; scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; + + DISALLOW_COPY_AND_ASSIGN(WebNotificationBubbleWrapper); +}; + +class WebNotificationButton : public views::ImageButton { + public: + WebNotificationButton(views::ButtonListener* listener) + : views::ImageButton(listener), + unread_label_(NULL) { + } + + void SetUnreadCount(int unread_count) { + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + if (unread_count == 0) { + SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( + IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL)); + SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( + IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER)); + SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( + IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); + + if (unread_label_) { + delete unread_label_; + unread_label_ = NULL; + } + } else { + SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( + IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); + SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( + IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER)); + SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( + IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED)); + + string16 text((unread_count > 9) ? + UTF8ToUTF16("9+") : base::IntToString16(unread_count)); + if (unread_label_) { + unread_label_->SetText(text); + } else { + unread_label_ = new views::Label(text); + SetupLabelForTray(unread_label_); + AddChildView(unread_label_); + } + } + InvalidateLayout(); + SchedulePaint(); + } + + protected: + // Overridden from views::ImageButton: + virtual void Layout() OVERRIDE { + views::ImageButton::Layout(); + if (unread_label_) { + gfx::Rect parent_bounds(bounds()); + parent_bounds.set_height( + parent_bounds.height() - kUnreadLabelBottomOffset); + unread_label_->SetBoundsRect(parent_bounds); + } + } + + private: + views::Label* unread_label_; + + DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); }; } // namespace internal @@ -89,7 +162,7 @@ WebNotificationTray::WebNotificationTray( : TrayBackgroundView(status_area_widget), button_(NULL), show_message_center_on_unlock_(false) { - button_ = new views::ImageButton(this); + button_ = new internal::WebNotificationButton(this); button_->set_triggerable_event_flags( ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); tray_container()->AddChildView(button_); @@ -377,24 +450,9 @@ void WebNotificationTray::ButtonPressed(views::Button* sender, } void WebNotificationTray::OnMessageCenterTrayChanged() { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); message_center::MessageCenter* message_center = message_center_tray_->message_center(); - if (message_center->UnreadNotificationCount() > 0) { - button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); - button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER)); - button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED)); - } else { - button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL)); - button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER)); - button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( - IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); - } + button_->SetUnreadCount(message_center->UnreadNotificationCount()); if (IsMessageCenterBubbleVisible()) button_->SetState(views::CustomButton::STATE_PRESSED); else diff --git a/ash/system/web_notification/web_notification_tray.h b/ash/system/web_notification/web_notification_tray.h index 7c4f01f..13be8c6 100644 --- a/ash/system/web_notification/web_notification_tray.h +++ b/ash/system/web_notification/web_notification_tray.h @@ -41,6 +41,7 @@ namespace ash { namespace internal { class StatusAreaWidget; class WebNotificationBubbleWrapper; +class WebNotificationButton; } class ASH_EXPORT WebNotificationTray @@ -142,7 +143,7 @@ class ASH_EXPORT WebNotificationTray scoped_ptr<internal::WebNotificationBubbleWrapper> popup_bubble_; scoped_ptr<message_center::MessagePopupCollection> popup_collection_; scoped_ptr<views::MenuRunner> quiet_mode_menu_runner_; - views::ImageButton* button_; + internal::WebNotificationButton* button_; bool show_message_center_on_unlock_; |