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

Side by Side Diff: ash/system/web_notification/web_notification_tray.cc

Issue 10852007: Update appearance of read Ash notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/system/web_notification/web_notification_tray.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/web_notification/web_notification_tray.h" 5 #include "ash/system/web_notification/web_notification_tray.h"
6 6
7 #include "ash/system/status_area_widget.h" 7 #include "ash/system/status_area_widget.h"
8 #include "ash/system/tray/system_tray.h" 8 #include "ash/system/tray/system_tray.h"
9 #include "ash/system/tray/tray_bubble_view.h" 9 #include "ash/system/tray/tray_bubble_view.h"
10 #include "ash/system/tray/tray_constants.h" 10 #include "ash/system/tray/tray_constants.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return base::StringPrintf("%d", notification_count); 73 return base::StringPrintf("%d", notification_count);
74 } 74 }
75 75
76 } // namespace 76 } // namespace
77 77
78 namespace ash { 78 namespace ash {
79 79
80 namespace internal { 80 namespace internal {
81 81
82 struct WebNotification { 82 struct WebNotification {
83 WebNotification(const std::string& i, 83 WebNotification() : is_read(false) {}
84 const string16& t,
85 const string16& m,
86 const string16& s,
87 const std::string& e)
88 : id(i),
89 title(t),
90 message(m),
91 display_source(s),
92 extension_id(e) {
93 }
94
95 std::string id; 84 std::string id;
96 string16 title; 85 string16 title;
97 string16 message; 86 string16 message;
98 string16 display_source; 87 string16 display_source;
99 std::string extension_id; 88 std::string extension_id;
100 gfx::ImageSkia image; 89 gfx::ImageSkia image;
90 bool is_read;
101 }; 91 };
102 92
103 // A helper class to manage the list of notifications. 93 // A helper class to manage the list of notifications.
104 class WebNotificationList { 94 class WebNotificationList {
105 public: 95 public:
106 typedef std::list<WebNotification> Notifications; 96 typedef std::list<WebNotification> Notifications;
107 97
108 WebNotificationList() { 98 WebNotificationList()
99 : is_visible_(false),
100 unread_count_(0) {
101 }
102
103 void SetIsVisible(bool visible) {
104 if (is_visible_ == visible)
105 return;
106 is_visible_ = visible;
107 if (visible) {
108 // Clear the unread count when the list is shown.
109 unread_count_ = 0;
110 } else {
111 // Mark all notifications as read when the list is hidden.
112 for (Notifications::iterator iter = notifications_.begin();
113 iter != notifications_.end(); ++iter) {
114 iter->is_read = true;
115 }
116 }
109 } 117 }
110 118
111 void AddNotification(const std::string& id, 119 void AddNotification(const std::string& id,
112 const string16& title, 120 const string16& title,
113 const string16& message, 121 const string16& message,
114 const string16& display_source, 122 const string16& display_source,
115 const std::string& extension_id) { 123 const std::string& extension_id) {
124 WebNotification notification;
116 Notifications::iterator iter = GetNotification(id); 125 Notifications::iterator iter = GetNotification(id);
117 if (iter != notifications_.end()) { 126 if (iter != notifications_.end()) {
118 // Update existing notification. 127 notification = *iter;
119 iter->title = title; 128 EraseNotification(iter);
120 iter->message = message;
121 iter->display_source = display_source;
122 iter->extension_id = extension_id;
123 } else {
124 notifications_.push_front(
125 WebNotification(id, title, message, display_source, extension_id));
126 } 129 }
130 notification.id = id;
131 notification.title = title;
132 notification.message = message;
133 notification.display_source = display_source;
134 notification.extension_id = extension_id;
135 notification.is_read = false;
136 PushNotification(notification);
127 } 137 }
128 138
129 void UpdateNotificationMessage(const std::string& id, 139 void UpdateNotificationMessage(const std::string& id,
130 const string16& title, 140 const string16& title,
131 const string16& message) { 141 const string16& message) {
132 Notifications::iterator iter = GetNotification(id); 142 Notifications::iterator iter = GetNotification(id);
133 if (iter == notifications_.end()) 143 if (iter == notifications_.end())
134 return; 144 return;
135 iter->title = title; 145 // Copy and update notification, then move it to the front of the list.
136 iter->message = message; 146 WebNotification notification(*iter);
147 notification.title = title;
148 notification.message = message;
149 notification.is_read = false;
150 EraseNotification(iter);
151 PushNotification(notification);
137 } 152 }
138 153
139 bool RemoveNotification(const std::string& id) { 154 bool RemoveNotification(const std::string& id) {
140 Notifications::iterator iter = GetNotification(id); 155 Notifications::iterator iter = GetNotification(id);
141 if (iter == notifications_.end()) 156 if (iter == notifications_.end())
142 return false; 157 return false;
143 notifications_.erase(iter); 158 EraseNotification(iter);
144 return true; 159 return true;
145 } 160 }
146 161
147 void RemoveAllNotifications() { 162 void RemoveAllNotifications() {
148 notifications_.clear(); 163 notifications_.clear();
149 } 164 }
150 165
151 void RemoveNotificationsBySource(const std::string& id) { 166 void RemoveNotificationsBySource(const std::string& id) {
152 Notifications::iterator source_iter = GetNotification(id); 167 Notifications::iterator source_iter = GetNotification(id);
153 if (source_iter == notifications_.end()) 168 if (source_iter == notifications_.end())
154 return; 169 return;
155 string16 display_source = source_iter->display_source; 170 string16 display_source = source_iter->display_source;
156 for (Notifications::iterator loopiter = notifications_.begin(); 171 for (Notifications::iterator loopiter = notifications_.begin();
157 loopiter != notifications_.end(); ) { 172 loopiter != notifications_.end(); ) {
158 Notifications::iterator curiter = loopiter++; 173 Notifications::iterator curiter = loopiter++;
159 if (curiter->display_source == display_source) 174 if (curiter->display_source == display_source)
160 notifications_.erase(curiter); 175 EraseNotification(curiter);
161 } 176 }
162 } 177 }
163 178
164 void RemoveNotificationsByExtension(const std::string& id) { 179 void RemoveNotificationsByExtension(const std::string& id) {
165 Notifications::iterator source_iter = GetNotification(id); 180 Notifications::iterator source_iter = GetNotification(id);
166 if (source_iter == notifications_.end()) 181 if (source_iter == notifications_.end())
167 return; 182 return;
168 std::string extension_id = source_iter->extension_id; 183 std::string extension_id = source_iter->extension_id;
169 for (Notifications::iterator loopiter = notifications_.begin(); 184 for (Notifications::iterator loopiter = notifications_.begin();
170 loopiter != notifications_.end(); ) { 185 loopiter != notifications_.end(); ) {
171 Notifications::iterator curiter = loopiter++; 186 Notifications::iterator curiter = loopiter++;
172 if (curiter->extension_id == extension_id) 187 if (curiter->extension_id == extension_id)
173 notifications_.erase(curiter); 188 EraseNotification(curiter);
174 } 189 }
175 } 190 }
176 191
177 bool SetNotificationImage(const std::string& id, 192 bool SetNotificationImage(const std::string& id,
178 const gfx::ImageSkia& image) { 193 const gfx::ImageSkia& image) {
179 Notifications::iterator iter = GetNotification(id); 194 Notifications::iterator iter = GetNotification(id);
180 if (iter == notifications_.end()) 195 if (iter == notifications_.end())
181 return false; 196 return false;
182 iter->image = image; 197 iter->image = image;
183 return true; 198 return true;
184 } 199 }
185 200
201 std::string GetFirstId() {
202 if (notifications_.empty())
203 return std::string();
204 return notifications_.front().id;
205 }
206
186 const Notifications& notifications() const { return notifications_; } 207 const Notifications& notifications() const { return notifications_; }
208 int unread_count() const { return unread_count_; }
187 209
188 private: 210 private:
189 Notifications::iterator GetNotification(const std::string& id) { 211 Notifications::iterator GetNotification(const std::string& id) {
190 for (Notifications::iterator iter = notifications_.begin(); 212 for (Notifications::iterator iter = notifications_.begin();
191 iter != notifications_.end(); ++iter) { 213 iter != notifications_.end(); ++iter) {
192 if (iter->id == id) 214 if (iter->id == id)
193 return iter; 215 return iter;
194 } 216 }
195 return notifications_.end(); 217 return notifications_.end();
196 } 218 }
197 219
220 void EraseNotification(Notifications::iterator iter) {
221 if (!is_visible_ && !iter->is_read)
222 --unread_count_;
223 notifications_.erase(iter);
224 }
225
226 void PushNotification(const WebNotification& notification) {
227 if (!is_visible_)
228 ++unread_count_;
229 notifications_.push_front(notification);
230 }
231
198 Notifications notifications_; 232 Notifications notifications_;
233 bool is_visible_;
234 int unread_count_;
199 235
200 DISALLOW_COPY_AND_ASSIGN(WebNotificationList); 236 DISALLOW_COPY_AND_ASSIGN(WebNotificationList);
201 }; 237 };
202 238
203 // A dropdown menu for notifications. 239 // A dropdown menu for notifications.
204 class WebNotificationMenuModel : public ui::SimpleMenuModel, 240 class WebNotificationMenuModel : public ui::SimpleMenuModel,
205 public ui::SimpleMenuModel::Delegate { 241 public ui::SimpleMenuModel::Delegate {
206 public: 242 public:
207 explicit WebNotificationMenuModel(WebNotificationTray* tray, 243 explicit WebNotificationMenuModel(WebNotificationTray* tray,
208 const WebNotification& notification) 244 const WebNotification& notification)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 InitView(tray, notification); 335 InitView(tray, notification);
300 } 336 }
301 337
302 virtual ~WebNotificationView() { 338 virtual ~WebNotificationView() {
303 } 339 }
304 340
305 void InitView(WebNotificationTray* tray, 341 void InitView(WebNotificationTray* tray,
306 const WebNotification& notification) { 342 const WebNotification& notification) {
307 set_border(views::Border::CreateSolidSidedBorder( 343 set_border(views::Border::CreateSolidSidedBorder(
308 1, 0, 0, 0, kBorderLightColor)); 344 1, 0, 0, 0, kBorderLightColor));
309 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 345 SkColor bg_color = notification.is_read
346 ? kHeaderBackgroundColorLight : kBackgroundColor;
347 set_background(views::Background::CreateSolidBackground(bg_color));
310 348
311 icon_ = new views::ImageView; 349 icon_ = new views::ImageView;
312 icon_->SetImageSize( 350 icon_->SetImageSize(
313 gfx::Size(kWebNotificationIconSize, kWebNotificationIconSize)); 351 gfx::Size(kWebNotificationIconSize, kWebNotificationIconSize));
314 icon_->SetImage(notification.image); 352 icon_->SetImage(notification.image);
315 353
316 views::Label* title = new views::Label(notification.title); 354 views::Label* title = new views::Label(notification.title);
317 title->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 355 title->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
318 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); 356 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD));
319 views::Label* message = new views::Label(notification.message); 357 views::Label* message = new views::Label(notification.message);
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); 604 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
567 AddChildView(content_); 605 AddChildView(content_);
568 } 606 }
569 607
570 void Update(const WebNotificationList::Notifications& notifications) { 608 void Update(const WebNotificationList::Notifications& notifications) {
571 content_->RemoveAllChildViews(true); 609 content_->RemoveAllChildViews(true);
572 WebNotificationList::Notifications::const_iterator iter = 610 WebNotificationList::Notifications::const_iterator iter =
573 notifications.begin(); 611 notifications.begin();
574 WebNotificationView* view = new WebNotificationView(tray_, *iter); 612 WebNotificationView* view = new WebNotificationView(tray_, *iter);
575 content_->AddChildView(view); 613 content_->AddChildView(view);
614 Layout();
576 GetWidget()->GetRootView()->SchedulePaint(); 615 GetWidget()->GetRootView()->SchedulePaint();
577 } 616 }
578 617
579 private: 618 private:
580 WebNotificationTray* tray_; 619 WebNotificationTray* tray_;
581 views::View* content_; 620 views::View* content_;
582 621
583 DISALLOW_COPY_AND_ASSIGN(WebNotificationContentsView); 622 DISALLOW_COPY_AND_ASSIGN(WebNotificationContentsView);
584 }; 623 };
585 624
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 761
723 DISALLOW_COPY_AND_ASSIGN(Bubble); 762 DISALLOW_COPY_AND_ASSIGN(Bubble);
724 }; 763 };
725 764
726 WebNotificationTray::WebNotificationTray( 765 WebNotificationTray::WebNotificationTray(
727 internal::StatusAreaWidget* status_area_widget) 766 internal::StatusAreaWidget* status_area_widget)
728 : internal::TrayBackgroundView(status_area_widget), 767 : internal::TrayBackgroundView(status_area_widget),
729 notification_list_(new WebNotificationList()), 768 notification_list_(new WebNotificationList()),
730 count_label_(NULL), 769 count_label_(NULL),
731 delegate_(NULL), 770 delegate_(NULL),
732 show_message_center_on_unlock_(false), 771 show_message_center_on_unlock_(false) {
733 unread_count_(0) {
734 count_label_ = new views::Label(UTF8ToUTF16("0")); 772 count_label_ = new views::Label(UTF8ToUTF16("0"));
735 internal::SetupLabelForTray(count_label_); 773 internal::SetupLabelForTray(count_label_);
736 gfx::Font font = count_label_->font(); 774 gfx::Font font = count_label_->font();
737 count_label_->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD)); 775 count_label_->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD));
738 count_label_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); 776 count_label_->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
739 777
740 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); 778 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight));
741 tray_container()->AddChildView(count_label_); 779 tray_container()->AddChildView(count_label_);
742 780
743 UpdateTray(); 781 UpdateTray();
744 } 782 }
745 783
746 WebNotificationTray::~WebNotificationTray() { 784 WebNotificationTray::~WebNotificationTray() {
747 } 785 }
748 786
749 void WebNotificationTray::SetDelegate(Delegate* delegate) { 787 void WebNotificationTray::SetDelegate(Delegate* delegate) {
750 DCHECK(!delegate_); 788 DCHECK(!delegate_);
751 delegate_ = delegate; 789 delegate_ = delegate;
752 } 790 }
753 791
754 void WebNotificationTray::AddNotification(const std::string& id, 792 void WebNotificationTray::AddNotification(const std::string& id,
755 const string16& title, 793 const string16& title,
756 const string16& message, 794 const string16& message,
757 const string16& display_source, 795 const string16& display_source,
758 const std::string& extension_id) { 796 const std::string& extension_id) {
759 notification_list_->AddNotification( 797 notification_list_->AddNotification(
760 id, title, message, display_source, extension_id); 798 id, title, message, display_source, extension_id);
761 if (!message_center_bubble())
762 ++unread_count_;
763 UpdateTrayAndBubble(); 799 UpdateTrayAndBubble();
764 if (!message_center_bubble()) 800 ShowNotificationBubble();
765 ShowNotificationBubble();
766 } 801 }
767 802
768 void WebNotificationTray::UpdateNotification(const std::string& id, 803 void WebNotificationTray::UpdateNotification(const std::string& id,
769 const string16& title, 804 const string16& title,
770 const string16& message) { 805 const string16& message) {
771 notification_list_->UpdateNotificationMessage(id, title, message); 806 notification_list_->UpdateNotificationMessage(id, title, message);
772 UpdateTrayAndBubble(); 807 UpdateTrayAndBubble();
808 ShowNotificationBubble();
773 } 809 }
774 810
775 void WebNotificationTray::RemoveNotification(const std::string& id) { 811 void WebNotificationTray::RemoveNotification(const std::string& id) {
812 if (id == notification_list_->GetFirstId())
813 HideNotificationBubble();
776 if (!notification_list_->RemoveNotification(id)) 814 if (!notification_list_->RemoveNotification(id))
777 return; 815 return;
778 if (delegate_) 816 if (delegate_)
779 delegate_->NotificationRemoved(id); 817 delegate_->NotificationRemoved(id);
780 UpdateTrayAndBubble(); 818 UpdateTrayAndBubble();
781 } 819 }
782 820
783 void WebNotificationTray::RemoveAllNotifications() { 821 void WebNotificationTray::RemoveAllNotifications() {
784 const WebNotificationList::Notifications& notifications = 822 const WebNotificationList::Notifications& notifications =
785 notification_list_->notifications(); 823 notification_list_->notifications();
786 if (delegate_) { 824 if (delegate_) {
787 for (WebNotificationList::Notifications::const_iterator loopiter = 825 for (WebNotificationList::Notifications::const_iterator loopiter =
788 notifications.begin(); 826 notifications.begin();
789 loopiter != notifications.end(); ) { 827 loopiter != notifications.end(); ) {
790 WebNotificationList::Notifications::const_iterator curiter = loopiter++; 828 WebNotificationList::Notifications::const_iterator curiter = loopiter++;
791 std::string notification_id = curiter->id; 829 std::string notification_id = curiter->id;
792 // May call RemoveNotification and erase curiter. 830 // May call RemoveNotification and erase curiter.
793 delegate_->NotificationRemoved(notification_id); 831 delegate_->NotificationRemoved(notification_id);
794 } 832 }
795 } 833 }
796 notification_list_->RemoveAllNotifications(); 834 notification_list_->RemoveAllNotifications();
797 UpdateTrayAndBubble(); 835 UpdateTrayAndBubble();
798 } 836 }
799 837
800 void WebNotificationTray::SetNotificationImage(const std::string& id, 838 void WebNotificationTray::SetNotificationImage(const std::string& id,
801 const gfx::ImageSkia& image) { 839 const gfx::ImageSkia& image) {
802 if (!notification_list_->SetNotificationImage(id, image)) 840 if (!notification_list_->SetNotificationImage(id, image))
803 return; 841 return;
804 UpdateTrayAndBubble(); 842 UpdateTrayAndBubble();
843 if (notification_bubble() && id == notification_list_->GetFirstId())
844 ShowNotificationBubble();
805 } 845 }
806 846
807 void WebNotificationTray::DisableByExtension(const std::string& id) { 847 void WebNotificationTray::DisableByExtension(const std::string& id) {
808 // When we disable notifications, we remove any existing matching 848 // When we disable notifications, we remove any existing matching
809 // notifications to avoid adding complicated UI to re-enable the source. 849 // notifications to avoid adding complicated UI to re-enable the source.
850 if (id == notification_list_->GetFirstId())
851 HideNotificationBubble();
810 notification_list_->RemoveNotificationsByExtension(id); 852 notification_list_->RemoveNotificationsByExtension(id);
811 UpdateTrayAndBubble(); 853 UpdateTrayAndBubble();
812 if (delegate_) 854 if (delegate_)
813 delegate_->DisableExtension(id); 855 delegate_->DisableExtension(id);
814 } 856 }
815 857
816 void WebNotificationTray::DisableByUrl(const std::string& id) { 858 void WebNotificationTray::DisableByUrl(const std::string& id) {
817 // See comment for DisableByExtension. 859 // See comment for DisableByExtension.
860 if (id == notification_list_->GetFirstId())
861 HideNotificationBubble();
818 notification_list_->RemoveNotificationsBySource(id); 862 notification_list_->RemoveNotificationsBySource(id);
819 UpdateTrayAndBubble(); 863 UpdateTrayAndBubble();
820 if (delegate_) 864 if (delegate_)
821 delegate_->DisableNotificationsFromSource(id); 865 delegate_->DisableNotificationsFromSource(id);
822 } 866 }
823 867
824 void WebNotificationTray::ShowMessageCenterBubble() { 868 void WebNotificationTray::ShowMessageCenterBubble() {
825 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) 869 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED)
826 return; 870 return;
827 unread_count_ = 0; 871 if (message_center_bubble() || GetNotificationCount() == 0) {
872 UpdateTray();
873 return;
874 }
875 notification_list_->SetIsVisible(true); // clears notification count
828 UpdateTray(); 876 UpdateTray();
829 if (message_center_bubble()) 877 HideNotificationBubble();
830 return;
831 if (GetNotificationCount() == 0)
832 return;
833 notification_bubble_.reset();
834 message_center_bubble_.reset( 878 message_center_bubble_.reset(
835 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER)); 879 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER));
836 status_area_widget()->SetHideSystemNotifications(true); 880 status_area_widget()->SetHideSystemNotifications(true);
837 } 881 }
838 882
839 void WebNotificationTray::HideMessageCenterBubble() { 883 void WebNotificationTray::HideMessageCenterBubble() {
840 message_center_bubble_.reset(); 884 message_center_bubble_.reset();
841 show_message_center_on_unlock_ = false; 885 show_message_center_on_unlock_ = false;
886 notification_list_->SetIsVisible(false);
842 status_area_widget()->SetHideSystemNotifications(false); 887 status_area_widget()->SetHideSystemNotifications(false);
843 } 888 }
844 889
845 void WebNotificationTray::ShowNotificationBubble() { 890 void WebNotificationTray::ShowNotificationBubble() {
846 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) 891 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED)
847 return; 892 return;
848 if (message_center_bubble()) 893 if (message_center_bubble())
849 return; 894 return;
850 if (!status_area_widget()->ShouldShowNonSystemNotifications()) 895 if (!status_area_widget()->ShouldShowNonSystemNotifications())
851 return; 896 return;
852 UpdateTray(); 897 UpdateTray();
853 notification_bubble_.reset( 898 if (notification_bubble()) {
854 new Bubble(this, Bubble::BUBBLE_TYPE_NOTIFICATION)); 899 notification_bubble()->ScheduleUpdate();
900 } else {
901 notification_bubble_.reset(
902 new Bubble(this, Bubble::BUBBLE_TYPE_NOTIFICATION));
903 }
855 } 904 }
856 905
857 void WebNotificationTray::HideNotificationBubble() { 906 void WebNotificationTray::HideNotificationBubble() {
858 notification_bubble_.reset(); 907 notification_bubble_.reset();
859 } 908 }
860 909
861 void WebNotificationTray::UpdateAfterLoginStatusChange( 910 void WebNotificationTray::UpdateAfterLoginStatusChange(
862 user::LoginStatus login_status) { 911 user::LoginStatus login_status) {
863 if (login_status == user::LOGGED_IN_LOCKED) { 912 if (login_status == user::LOGGED_IN_LOCKED) {
864 if (message_center_bubble()) { 913 if (message_center_bubble()) {
865 message_center_bubble_.reset(); 914 message_center_bubble_.reset();
866 show_message_center_on_unlock_ = true; 915 show_message_center_on_unlock_ = true;
867 } 916 }
868 if (notification_bubble()) 917 HideNotificationBubble();
869 notification_bubble_.reset();
870 } else { 918 } else {
871 if (show_message_center_on_unlock_) 919 if (show_message_center_on_unlock_)
872 ShowMessageCenterBubble(); 920 ShowMessageCenterBubble();
873 show_message_center_on_unlock_ = false; 921 show_message_center_on_unlock_ = false;
874 } 922 }
875 UpdateTray(); 923 UpdateTray();
876 } 924 }
877 925
878 void WebNotificationTray::ShowSettings(const std::string& id) { 926 void WebNotificationTray::ShowSettings(const std::string& id) {
879 if (delegate_) 927 if (delegate_)
880 delegate_->ShowSettings(id); 928 delegate_->ShowSettings(id);
881 } 929 }
882 930
883 void WebNotificationTray::OnClicked(const std::string& id) { 931 void WebNotificationTray::OnClicked(const std::string& id) {
884 if (delegate_) 932 if (delegate_)
885 delegate_->OnClicked(id); 933 delegate_->OnClicked(id);
886 } 934 }
887 935
888 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { 936 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) {
889 if (alignment == shelf_alignment()) 937 if (alignment == shelf_alignment())
890 return; 938 return;
891 internal::TrayBackgroundView::SetShelfAlignment(alignment); 939 internal::TrayBackgroundView::SetShelfAlignment(alignment);
892 if (alignment == SHELF_ALIGNMENT_BOTTOM) 940 if (alignment == SHELF_ALIGNMENT_BOTTOM)
893 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); 941 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight));
894 else 942 else
895 tray_container()->set_size(gfx::Size(kTraySideWidth, kTraySideHeight)); 943 tray_container()->set_size(gfx::Size(kTraySideWidth, kTraySideHeight));
896 // Destroy any existing bubble so that it will be rebuilt correctly. 944 // Destroy any existing bubble so that it will be rebuilt correctly.
897 message_center_bubble_.reset(); 945 HideMessageCenterBubble();
898 notification_bubble_.reset(); 946 HideNotificationBubble();
899 } 947 }
900 948
901 bool WebNotificationTray::PerformAction(const views::Event& event) { 949 bool WebNotificationTray::PerformAction(const views::Event& event) {
902 if (message_center_bubble()) 950 if (message_center_bubble())
903 HideMessageCenterBubble(); 951 HideMessageCenterBubble();
904 else 952 else
905 ShowMessageCenterBubble(); 953 ShowMessageCenterBubble();
906 return true; 954 return true;
907 } 955 }
908 956
909 int WebNotificationTray::GetNotificationCount() const { 957 int WebNotificationTray::GetNotificationCount() const {
910 return notification_list()->notifications().size(); 958 return notification_list()->notifications().size();
911 } 959 }
912 960
913 void WebNotificationTray::UpdateTray() { 961 void WebNotificationTray::UpdateTray() {
914 count_label_->SetText(UTF8ToUTF16(GetNotificationText(unread_count_))); 962 count_label_->SetText(UTF8ToUTF16(
963 GetNotificationText(notification_list()->unread_count())));
915 Layout(); 964 Layout();
916 SchedulePaint(); 965 SchedulePaint();
917 } 966 }
918 967
919 void WebNotificationTray::UpdateTrayAndBubble() { 968 void WebNotificationTray::UpdateTrayAndBubble() {
920 UpdateTray(); 969 UpdateTray();
921 if (GetNotificationCount() == 0) { 970 if (GetNotificationCount() == 0) {
922 HideMessageCenterBubble(); 971 HideMessageCenterBubble();
923 notification_bubble_.reset(); 972 HideNotificationBubble();
924 return; 973 return;
925 } 974 }
926 if (message_center_bubble()) 975 if (message_center_bubble())
927 message_center_bubble()->ScheduleUpdate(); 976 message_center_bubble()->ScheduleUpdate();
928 if (notification_bubble()) 977 if (notification_bubble())
929 notification_bubble()->ScheduleUpdate(); 978 notification_bubble()->ScheduleUpdate();
930 } 979 }
931 980
932 void WebNotificationTray::HideBubble(Bubble* bubble) { 981 void WebNotificationTray::HideBubble(Bubble* bubble) {
933 if (bubble == message_center_bubble()) { 982 if (bubble == message_center_bubble()) {
934 HideMessageCenterBubble(); 983 HideMessageCenterBubble();
935 } else if (bubble == notification_bubble()) { 984 } else if (bubble == notification_bubble()) {
936 notification_bubble_.reset(); 985 HideNotificationBubble();
937 } 986 }
938 } 987 }
939 988
940 } // namespace ash 989 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/web_notification/web_notification_tray.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698