| OLD | NEW |
| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 void AddNotification(const std::string& id, | 121 void AddNotification(const std::string& id, |
| 122 const string16& title, | 122 const string16& title, |
| 123 const string16& message, | 123 const string16& message, |
| 124 const string16& display_source, | 124 const string16& display_source, |
| 125 const std::string& extension_id) { | 125 const std::string& extension_id) { |
| 126 WebNotification notification; | 126 WebNotification notification; |
| 127 Notifications::iterator iter = GetNotification(id); | |
| 128 if (iter != notifications_.end()) { | |
| 129 notification = *iter; | |
| 130 EraseNotification(iter); | |
| 131 } | |
| 132 notification.id = id; | 127 notification.id = id; |
| 133 notification.title = title; | 128 notification.title = title; |
| 134 notification.message = message; | 129 notification.message = message; |
| 135 notification.display_source = display_source; | 130 notification.display_source = display_source; |
| 136 notification.extension_id = extension_id; | 131 notification.extension_id = extension_id; |
| 137 notification.is_read = false; | 132 notification.is_read = false; |
| 138 PushNotification(notification); | 133 PushNotification(notification); |
| 139 } | 134 } |
| 140 | 135 |
| 141 void UpdateNotificationMessage(const std::string& id, | 136 void UpdateNotificationMessage(const std::string& old_id, |
| 137 const std::string& new_id, |
| 142 const string16& title, | 138 const string16& title, |
| 143 const string16& message) { | 139 const string16& message) { |
| 144 Notifications::iterator iter = GetNotification(id); | 140 Notifications::iterator iter = GetNotification(old_id); |
| 145 if (iter == notifications_.end()) | 141 if (iter == notifications_.end()) |
| 146 return; | 142 return; |
| 147 // Copy and update notification, then move it to the front of the list. | 143 // Copy and update notification, then move it to the front of the list. |
| 148 WebNotification notification(*iter); | 144 WebNotification notification(*iter); |
| 145 notification.id = new_id; |
| 149 notification.title = title; | 146 notification.title = title; |
| 150 notification.message = message; | 147 notification.message = message; |
| 151 notification.is_read = false; | 148 notification.is_read = false; |
| 152 EraseNotification(iter); | 149 EraseNotification(iter); |
| 153 PushNotification(notification); | 150 PushNotification(notification); |
| 154 } | 151 } |
| 155 | 152 |
| 156 bool RemoveNotification(const std::string& id) { | 153 bool RemoveNotification(const std::string& id) { |
| 157 Notifications::iterator iter = GetNotification(id); | 154 Notifications::iterator iter = GetNotification(id); |
| 158 if (iter == notifications_.end()) | 155 if (iter == notifications_.end()) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 iter->image = image; | 196 iter->image = image; |
| 200 return true; | 197 return true; |
| 201 } | 198 } |
| 202 | 199 |
| 203 std::string GetFirstId() { | 200 std::string GetFirstId() { |
| 204 if (notifications_.empty()) | 201 if (notifications_.empty()) |
| 205 return std::string(); | 202 return std::string(); |
| 206 return notifications_.front().id; | 203 return notifications_.front().id; |
| 207 } | 204 } |
| 208 | 205 |
| 206 bool HasNotification(const std::string& id) { |
| 207 return GetNotification(id) != notifications_.end(); |
| 208 } |
| 209 |
| 209 const Notifications& notifications() const { return notifications_; } | 210 const Notifications& notifications() const { return notifications_; } |
| 210 int unread_count() const { return unread_count_; } | 211 int unread_count() const { return unread_count_; } |
| 211 | 212 |
| 212 private: | 213 private: |
| 213 Notifications::iterator GetNotification(const std::string& id) { | 214 Notifications::iterator GetNotification(const std::string& id) { |
| 214 for (Notifications::iterator iter = notifications_.begin(); | 215 for (Notifications::iterator iter = notifications_.begin(); |
| 215 iter != notifications_.end(); ++iter) { | 216 iter != notifications_.end(); ++iter) { |
| 216 if (iter->id == id) | 217 if (iter->id == id) |
| 217 return iter; | 218 return iter; |
| 218 } | 219 } |
| 219 return notifications_.end(); | 220 return notifications_.end(); |
| 220 } | 221 } |
| 221 | 222 |
| 222 void EraseNotification(Notifications::iterator iter) { | 223 void EraseNotification(Notifications::iterator iter) { |
| 223 if (!is_visible_ && !iter->is_read) | 224 if (!is_visible_ && !iter->is_read) |
| 224 --unread_count_; | 225 --unread_count_; |
| 225 notifications_.erase(iter); | 226 notifications_.erase(iter); |
| 226 } | 227 } |
| 227 | 228 |
| 228 void PushNotification(const WebNotification& notification) { | 229 void PushNotification(const WebNotification& notification) { |
| 230 // Ensure that notification.id is unique by erasing any existing |
| 231 // notification with the same id (shouldn't normally happen). |
| 232 Notifications::iterator iter = GetNotification(notification.id); |
| 233 if (iter != notifications_.end()) |
| 234 EraseNotification(iter); |
| 235 // Add the notification to the front (top) of the list. |
| 229 if (!is_visible_) | 236 if (!is_visible_) |
| 230 ++unread_count_; | 237 ++unread_count_; |
| 231 notifications_.push_front(notification); | 238 notifications_.push_front(notification); |
| 232 } | 239 } |
| 233 | 240 |
| 234 Notifications notifications_; | 241 Notifications notifications_; |
| 235 bool is_visible_; | 242 bool is_visible_; |
| 236 int unread_count_; | 243 int unread_count_; |
| 237 | 244 |
| 238 DISALLOW_COPY_AND_ASSIGN(WebNotificationList); | 245 DISALLOW_COPY_AND_ASSIGN(WebNotificationList); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 const views::GestureEvent& event) OVERRIDE { | 439 const views::GestureEvent& event) OVERRIDE { |
| 433 if (event.type() != ui::ET_GESTURE_TAP) | 440 if (event.type() != ui::ET_GESTURE_TAP) |
| 434 return ui::GESTURE_STATUS_UNKNOWN; | 441 return ui::GESTURE_STATUS_UNKNOWN; |
| 435 tray_->OnClicked(notification_.id); | 442 tray_->OnClicked(notification_.id); |
| 436 return ui::GESTURE_STATUS_CONSUMED; | 443 return ui::GESTURE_STATUS_CONSUMED; |
| 437 } | 444 } |
| 438 | 445 |
| 439 // Overridden from ButtonListener. | 446 // Overridden from ButtonListener. |
| 440 virtual void ButtonPressed(views::Button* sender, | 447 virtual void ButtonPressed(views::Button* sender, |
| 441 const views::Event& event) OVERRIDE { | 448 const views::Event& event) OVERRIDE { |
| 442 if (sender == close_button_) { | 449 if (sender == close_button_) |
| 443 tray_->RemoveNotification(notification_.id); | 450 tray_->SendRemoveNotification(notification_.id); |
| 444 tray_->HideMessageCenterBubbleIfEmpty(); | |
| 445 } | |
| 446 } | 451 } |
| 447 | 452 |
| 448 // Overridden from MenuButtonListener. | 453 // Overridden from MenuButtonListener. |
| 449 virtual void OnMenuButtonClicked( | 454 virtual void OnMenuButtonClicked( |
| 450 View* source, const gfx::Point& point) OVERRIDE { | 455 View* source, const gfx::Point& point) OVERRIDE { |
| 451 if (source != menu_button_) | 456 if (source != menu_button_) |
| 452 return; | 457 return; |
| 453 WebNotificationMenuModel menu_model(tray_, notification_); | 458 WebNotificationMenuModel menu_model(tray_, notification_); |
| 454 views::MenuModelAdapter menu_model_adapter(&menu_model); | 459 views::MenuModelAdapter menu_model_adapter(&menu_model); |
| 455 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu()); | 460 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 virtual ~WebNotificationButtonView() { | 513 virtual ~WebNotificationButtonView() { |
| 509 } | 514 } |
| 510 | 515 |
| 511 void SetCloseAllVisible(bool visible) { | 516 void SetCloseAllVisible(bool visible) { |
| 512 close_all_button_->SetVisible(visible); | 517 close_all_button_->SetVisible(visible); |
| 513 } | 518 } |
| 514 | 519 |
| 515 // Overridden from ButtonListener. | 520 // Overridden from ButtonListener. |
| 516 virtual void ButtonPressed(views::Button* sender, | 521 virtual void ButtonPressed(views::Button* sender, |
| 517 const views::Event& event) OVERRIDE { | 522 const views::Event& event) OVERRIDE { |
| 518 if (sender == close_all_button_) { | 523 if (sender == close_all_button_) |
| 519 tray_->RemoveAllNotifications(); | 524 tray_->SendRemoveAllNotifications(); |
| 520 tray_->HideMessageCenterBubbleIfEmpty(); | |
| 521 } | |
| 522 } | 525 } |
| 523 | 526 |
| 524 private: | 527 private: |
| 525 WebNotificationTray* tray_; | 528 WebNotificationTray* tray_; |
| 526 TrayPopupTextButton* close_all_button_; | 529 TrayPopupTextButton* close_all_button_; |
| 527 | 530 |
| 528 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); | 531 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); |
| 529 }; | 532 }; |
| 530 | 533 |
| 531 class WebContentsView : public views::View { | 534 class WebContentsView : public views::View { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | 588 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
| 586 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 589 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 587 | 590 |
| 588 scroll_content_ = new ScrollContentView; | 591 scroll_content_ = new ScrollContentView; |
| 589 scroller_ = new internal::FixedSizedScrollView; | 592 scroller_ = new internal::FixedSizedScrollView; |
| 590 scroller_->SetContentsView(scroll_content_); | 593 scroller_->SetContentsView(scroll_content_); |
| 591 AddChildView(scroller_); | 594 AddChildView(scroller_); |
| 592 | 595 |
| 593 button_view_ = new internal::WebNotificationButtonView(tray); | 596 button_view_ = new internal::WebNotificationButtonView(tray); |
| 594 AddChildView(button_view_); | 597 AddChildView(button_view_); |
| 598 |
| 599 // Build initial view with no notifications. |
| 600 Update(WebNotificationList::Notifications()); |
| 595 } | 601 } |
| 596 | 602 |
| 597 void Update(const WebNotificationList::Notifications& notifications) { | 603 void Update(const WebNotificationList::Notifications& notifications) { |
| 598 scroll_content_->RemoveAllChildViews(true); | 604 scroll_content_->RemoveAllChildViews(true); |
| 605 scroll_content_->set_preferred_size(gfx::Size()); |
| 599 int num_children = 0; | 606 int num_children = 0; |
| 600 for (WebNotificationList::Notifications::const_iterator iter = | 607 for (WebNotificationList::Notifications::const_iterator iter = |
| 601 notifications.begin(); iter != notifications.end(); ++iter) { | 608 notifications.begin(); iter != notifications.end(); ++iter) { |
| 602 WebNotificationView* view = new WebNotificationView(tray_, *iter); | 609 WebNotificationView* view = new WebNotificationView(tray_, *iter); |
| 603 scroll_content_->AddChildView(view); | 610 scroll_content_->AddChildView(view); |
| 604 if (++num_children >= kMaxVisibleNotifications) | 611 if (++num_children >= kMaxVisibleNotifications) |
| 605 break; | 612 break; |
| 606 } | 613 } |
| 607 if (num_children == 0) { | 614 if (num_children == 0) { |
| 608 views::Label* label = new views::Label(l10n_util::GetStringUTF16( | 615 views::Label* label = new views::Label(l10n_util::GetStringUTF16( |
| 609 IDS_ASH_WEB_NOTFICATION_TRAY_NO_MESSAGES)); | 616 IDS_ASH_WEB_NOTFICATION_TRAY_NO_MESSAGES)); |
| 610 label->SetFont(label->font().DeriveFont(2)); | 617 label->SetFont(label->font().DeriveFont(2)); |
| 611 label->SetHorizontalAlignment(views::Label::ALIGN_CENTER); | 618 label->SetHorizontalAlignment(views::Label::ALIGN_CENTER); |
| 612 scroll_content_->AddChildView(label); | 619 scroll_content_->AddChildView(label); |
| 613 button_view_->SetCloseAllVisible(false); | 620 button_view_->SetCloseAllVisible(false); |
| 614 } else { | 621 } else { |
| 615 button_view_->SetCloseAllVisible(true); | 622 button_view_->SetCloseAllVisible(true); |
| 616 } | 623 } |
| 617 SizeScrollContent(); | 624 SizeScrollContent(); |
| 618 Layout(); | 625 Layout(); |
| 619 GetWidget()->GetRootView()->SchedulePaint(); | 626 if (GetWidget()) |
| 627 GetWidget()->GetRootView()->SchedulePaint(); |
| 620 } | 628 } |
| 621 | 629 |
| 622 private: | 630 private: |
| 623 void SizeScrollContent() { | 631 void SizeScrollContent() { |
| 624 gfx::Size scroll_size = scroll_content_->GetPreferredSize(); | 632 gfx::Size scroll_size = scroll_content_->GetPreferredSize(); |
| 625 const int button_height = button_view_->GetPreferredSize().height(); | 633 const int button_height = button_view_->GetPreferredSize().height(); |
| 626 const int min_height = kWebNotificationBubbleMinHeight - button_height; | 634 const int min_height = kWebNotificationBubbleMinHeight - button_height; |
| 627 const int max_height = kWebNotificationBubbleMaxHeight - button_height; | 635 const int max_height = kWebNotificationBubbleMaxHeight - button_height; |
| 628 int scroll_height = std::min(std::max( | 636 int scroll_height = std::min(std::max( |
| 629 scroll_size.height(), min_height), max_height); | 637 scroll_size.height(), min_height), max_height); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 648 explicit WebNotificationContentsView(WebNotificationTray* tray) | 656 explicit WebNotificationContentsView(WebNotificationTray* tray) |
| 649 : WebContentsView(tray) { | 657 : WebContentsView(tray) { |
| 650 SetLayoutManager( | 658 SetLayoutManager( |
| 651 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | 659 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
| 652 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 660 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 653 | 661 |
| 654 content_ = new views::View; | 662 content_ = new views::View; |
| 655 content_->SetLayoutManager( | 663 content_->SetLayoutManager( |
| 656 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | 664 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
| 657 AddChildView(content_); | 665 AddChildView(content_); |
| 666 |
| 667 // Build initial view with no notification. |
| 668 Update(WebNotificationList::Notifications()); |
| 658 } | 669 } |
| 659 | 670 |
| 660 void Update(const WebNotificationList::Notifications& notifications) { | 671 void Update(const WebNotificationList::Notifications& notifications) { |
| 661 content_->RemoveAllChildViews(true); | 672 content_->RemoveAllChildViews(true); |
| 662 WebNotificationList::Notifications::const_iterator iter = | 673 const WebNotification& notification = (notifications.size() > 0) ? |
| 663 notifications.begin(); | 674 notifications.front() : WebNotification(); |
| 664 WebNotificationView* view = new WebNotificationView(tray_, *iter); | 675 WebNotificationView* view = new WebNotificationView(tray_, notification); |
| 665 content_->AddChildView(view); | 676 content_->AddChildView(view); |
| 677 content_->SizeToPreferredSize(); |
| 666 Layout(); | 678 Layout(); |
| 667 GetWidget()->GetRootView()->SchedulePaint(); | 679 if (GetWidget()) |
| 680 GetWidget()->GetRootView()->SchedulePaint(); |
| 668 } | 681 } |
| 669 | 682 |
| 670 private: | 683 private: |
| 671 views::View* content_; | 684 views::View* content_; |
| 672 | 685 |
| 673 DISALLOW_COPY_AND_ASSIGN(WebNotificationContentsView); | 686 DISALLOW_COPY_AND_ASSIGN(WebNotificationContentsView); |
| 674 }; | 687 }; |
| 675 | 688 |
| 676 } // namespace internal | 689 } // namespace internal |
| 677 | 690 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 } | 843 } |
| 831 | 844 |
| 832 WebNotificationTray::~WebNotificationTray() { | 845 WebNotificationTray::~WebNotificationTray() { |
| 833 } | 846 } |
| 834 | 847 |
| 835 void WebNotificationTray::SetDelegate(Delegate* delegate) { | 848 void WebNotificationTray::SetDelegate(Delegate* delegate) { |
| 836 DCHECK(!delegate_); | 849 DCHECK(!delegate_); |
| 837 delegate_ = delegate; | 850 delegate_ = delegate; |
| 838 } | 851 } |
| 839 | 852 |
| 853 // Add/Update/RemoveNotification are called by the client code, i.e the |
| 854 // Delegate implementation or its proxy. |
| 855 |
| 840 void WebNotificationTray::AddNotification(const std::string& id, | 856 void WebNotificationTray::AddNotification(const std::string& id, |
| 841 const string16& title, | 857 const string16& title, |
| 842 const string16& message, | 858 const string16& message, |
| 843 const string16& display_source, | 859 const string16& display_source, |
| 844 const std::string& extension_id) { | 860 const std::string& extension_id) { |
| 845 notification_list_->AddNotification( | 861 notification_list_->AddNotification( |
| 846 id, title, message, display_source, extension_id); | 862 id, title, message, display_source, extension_id); |
| 847 UpdateTrayAndBubble(); | 863 UpdateTrayAndBubble(); |
| 848 ShowNotificationBubble(); | 864 ShowNotificationBubble(); |
| 849 } | 865 } |
| 850 | 866 |
| 851 void WebNotificationTray::UpdateNotification(const std::string& id, | 867 void WebNotificationTray::UpdateNotification(const std::string& old_id, |
| 868 const std::string& new_id, |
| 852 const string16& title, | 869 const string16& title, |
| 853 const string16& message) { | 870 const string16& message) { |
| 854 notification_list_->UpdateNotificationMessage(id, title, message); | 871 notification_list_->UpdateNotificationMessage(old_id, new_id, title, message); |
| 855 UpdateTrayAndBubble(); | 872 UpdateTrayAndBubble(); |
| 856 ShowNotificationBubble(); | 873 ShowNotificationBubble(); |
| 857 } | 874 } |
| 858 | 875 |
| 859 void WebNotificationTray::RemoveNotification(const std::string& id) { | 876 void WebNotificationTray::RemoveNotification(const std::string& id) { |
| 860 if (id == notification_list_->GetFirstId()) | 877 if (id == notification_list_->GetFirstId()) |
| 861 HideNotificationBubble(); | 878 HideNotificationBubble(); |
| 862 if (!notification_list_->RemoveNotification(id)) | 879 if (!notification_list_->RemoveNotification(id)) |
| 863 return; | 880 return; |
| 864 if (delegate_) | |
| 865 delegate_->NotificationRemoved(id); | |
| 866 UpdateTrayAndBubble(); | 881 UpdateTrayAndBubble(); |
| 867 } | 882 } |
| 868 | 883 |
| 869 void WebNotificationTray::RemoveAllNotifications() { | |
| 870 const WebNotificationList::Notifications& notifications = | |
| 871 notification_list_->notifications(); | |
| 872 if (delegate_) { | |
| 873 for (WebNotificationList::Notifications::const_iterator loopiter = | |
| 874 notifications.begin(); | |
| 875 loopiter != notifications.end(); ) { | |
| 876 WebNotificationList::Notifications::const_iterator curiter = loopiter++; | |
| 877 std::string notification_id = curiter->id; | |
| 878 // May call RemoveNotification and erase curiter. | |
| 879 delegate_->NotificationRemoved(notification_id); | |
| 880 } | |
| 881 } | |
| 882 notification_list_->RemoveAllNotifications(); | |
| 883 HideMessageCenterBubble(); | |
| 884 UpdateTrayAndBubble(); | |
| 885 } | |
| 886 | |
| 887 void WebNotificationTray::SetNotificationImage(const std::string& id, | 884 void WebNotificationTray::SetNotificationImage(const std::string& id, |
| 888 const gfx::ImageSkia& image) { | 885 const gfx::ImageSkia& image) { |
| 889 if (!notification_list_->SetNotificationImage(id, image)) | 886 if (!notification_list_->SetNotificationImage(id, image)) |
| 890 return; | 887 return; |
| 891 UpdateTrayAndBubble(); | 888 UpdateTrayAndBubble(); |
| 892 if (notification_bubble() && id == notification_list_->GetFirstId()) | 889 if (notification_bubble() && id == notification_list_->GetFirstId()) |
| 893 ShowNotificationBubble(); | 890 ShowNotificationBubble(); |
| 894 } | 891 } |
| 895 | 892 |
| 896 void WebNotificationTray::DisableByExtension(const std::string& id) { | |
| 897 // When we disable notifications, we remove any existing matching | |
| 898 // notifications to avoid adding complicated UI to re-enable the source. | |
| 899 if (id == notification_list_->GetFirstId()) | |
| 900 HideNotificationBubble(); | |
| 901 notification_list_->RemoveNotificationsByExtension(id); | |
| 902 UpdateTrayAndBubble(); | |
| 903 if (delegate_) | |
| 904 delegate_->DisableExtension(id); | |
| 905 } | |
| 906 | |
| 907 void WebNotificationTray::DisableByUrl(const std::string& id) { | |
| 908 // See comment for DisableByExtension. | |
| 909 if (id == notification_list_->GetFirstId()) | |
| 910 HideNotificationBubble(); | |
| 911 notification_list_->RemoveNotificationsBySource(id); | |
| 912 UpdateTrayAndBubble(); | |
| 913 if (delegate_) | |
| 914 delegate_->DisableNotificationsFromSource(id); | |
| 915 } | |
| 916 | |
| 917 void WebNotificationTray::ShowMessageCenterBubble() { | 893 void WebNotificationTray::ShowMessageCenterBubble() { |
| 918 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 894 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) |
| 919 return; | 895 return; |
| 920 if (message_center_bubble()) { | 896 if (message_center_bubble()) { |
| 921 UpdateTray(); | 897 UpdateTray(); |
| 922 return; | 898 return; |
| 923 } | 899 } |
| 924 notification_list_->SetIsVisible(true); // clears notification count | 900 notification_list_->SetIsVisible(true); // clears notification count |
| 925 UpdateTray(); | 901 UpdateTray(); |
| 926 HideNotificationBubble(); | 902 HideNotificationBubble(); |
| 927 message_center_bubble_.reset( | 903 message_center_bubble_.reset( |
| 928 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER)); | 904 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER)); |
| 929 status_area_widget()->SetHideSystemNotifications(true); | 905 status_area_widget()->SetHideSystemNotifications(true); |
| 930 } | 906 } |
| 931 | 907 |
| 932 void WebNotificationTray::HideMessageCenterBubble() { | 908 void WebNotificationTray::HideMessageCenterBubble() { |
| 933 if (!message_center_bubble()) | 909 if (!message_center_bubble()) |
| 934 return; | 910 return; |
| 935 message_center_bubble_.reset(); | 911 message_center_bubble_.reset(); |
| 936 show_message_center_on_unlock_ = false; | 912 show_message_center_on_unlock_ = false; |
| 937 notification_list_->SetIsVisible(false); | 913 notification_list_->SetIsVisible(false); |
| 938 status_area_widget()->SetHideSystemNotifications(false); | 914 status_area_widget()->SetHideSystemNotifications(false); |
| 939 } | 915 } |
| 940 | 916 |
| 941 void WebNotificationTray::HideMessageCenterBubbleIfEmpty() { | |
| 942 if (GetNotificationCount() == 0) | |
| 943 HideMessageCenterBubble(); | |
| 944 } | |
| 945 | |
| 946 void WebNotificationTray::ShowNotificationBubble() { | 917 void WebNotificationTray::ShowNotificationBubble() { |
| 947 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 918 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) |
| 948 return; | 919 return; |
| 949 if (message_center_bubble()) | 920 if (message_center_bubble()) |
| 950 return; | 921 return; |
| 951 if (!status_area_widget()->ShouldShowNonSystemNotifications()) | 922 if (!status_area_widget()->ShouldShowNonSystemNotifications()) |
| 952 return; | 923 return; |
| 953 UpdateTray(); | 924 UpdateTray(); |
| 954 if (notification_bubble()) { | 925 if (notification_bubble()) { |
| 955 notification_bubble()->ScheduleUpdate(); | 926 notification_bubble()->ScheduleUpdate(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 972 } | 943 } |
| 973 HideNotificationBubble(); | 944 HideNotificationBubble(); |
| 974 } else { | 945 } else { |
| 975 if (show_message_center_on_unlock_) | 946 if (show_message_center_on_unlock_) |
| 976 ShowMessageCenterBubble(); | 947 ShowMessageCenterBubble(); |
| 977 show_message_center_on_unlock_ = false; | 948 show_message_center_on_unlock_ = false; |
| 978 } | 949 } |
| 979 UpdateTray(); | 950 UpdateTray(); |
| 980 } | 951 } |
| 981 | 952 |
| 982 void WebNotificationTray::ShowSettings(const std::string& id) { | |
| 983 if (delegate_) | |
| 984 delegate_->ShowSettings(id); | |
| 985 } | |
| 986 | |
| 987 void WebNotificationTray::OnClicked(const std::string& id) { | |
| 988 if (delegate_) | |
| 989 delegate_->OnClicked(id); | |
| 990 } | |
| 991 | |
| 992 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { | 953 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 993 if (alignment == shelf_alignment()) | 954 if (alignment == shelf_alignment()) |
| 994 return; | 955 return; |
| 995 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 956 internal::TrayBackgroundView::SetShelfAlignment(alignment); |
| 996 if (alignment == SHELF_ALIGNMENT_BOTTOM) | 957 if (alignment == SHELF_ALIGNMENT_BOTTOM) |
| 997 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); | 958 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); |
| 998 else | 959 else |
| 999 tray_container()->set_size(gfx::Size(kTraySideWidth, kTraySideHeight)); | 960 tray_container()->set_size(gfx::Size(kTraySideWidth, kTraySideHeight)); |
| 1000 // Destroy any existing bubble so that it will be rebuilt correctly. | 961 // Destroy any existing bubble so that it will be rebuilt correctly. |
| 1001 HideMessageCenterBubble(); | 962 HideMessageCenterBubble(); |
| 1002 HideNotificationBubble(); | 963 HideNotificationBubble(); |
| 1003 } | 964 } |
| 1004 | 965 |
| 966 // Protected methods (invoked only from Bubble and its child classes) |
| 967 |
| 968 void WebNotificationTray::SendRemoveNotification(const std::string& id) { |
| 969 // If this is the only notification in the list, close the bubble. |
| 970 if (notification_list_->notifications().size() == 1 && |
| 971 id == notification_list_->GetFirstId()) { |
| 972 HideMessageCenterBubble(); |
| 973 } |
| 974 if (delegate_) |
| 975 delegate_->NotificationRemoved(id); |
| 976 } |
| 977 |
| 978 void WebNotificationTray::SendRemoveAllNotifications() { |
| 979 HideMessageCenterBubble(); |
| 980 if (delegate_) { |
| 981 const WebNotificationList::Notifications& notifications = |
| 982 notification_list_->notifications(); |
| 983 for (WebNotificationList::Notifications::const_iterator loopiter = |
| 984 notifications.begin(); |
| 985 loopiter != notifications.end(); ) { |
| 986 WebNotificationList::Notifications::const_iterator curiter = loopiter++; |
| 987 std::string notification_id = curiter->id; |
| 988 // May call RemoveNotification and erase curiter. |
| 989 delegate_->NotificationRemoved(notification_id); |
| 990 } |
| 991 } |
| 992 } |
| 993 |
| 994 // When we disable notifications, we remove any existing matching |
| 995 // notifications to avoid adding complicated UI to re-enable the source. |
| 996 void WebNotificationTray::DisableByExtension(const std::string& id) { |
| 997 // Will call SendRemoveNotification for each matching notification. |
| 998 notification_list_->RemoveNotificationsByExtension(id); |
| 999 if (delegate_) |
| 1000 delegate_->DisableExtension(id); |
| 1001 } |
| 1002 |
| 1003 void WebNotificationTray::DisableByUrl(const std::string& id) { |
| 1004 // Will call SendRemoveNotification for each matching notification. |
| 1005 notification_list_->RemoveNotificationsBySource(id); |
| 1006 if (delegate_) |
| 1007 delegate_->DisableNotificationsFromSource(id); |
| 1008 } |
| 1009 |
| 1005 bool WebNotificationTray::PerformAction(const views::Event& event) { | 1010 bool WebNotificationTray::PerformAction(const views::Event& event) { |
| 1006 if (message_center_bubble()) | 1011 if (message_center_bubble()) |
| 1007 HideMessageCenterBubble(); | 1012 HideMessageCenterBubble(); |
| 1008 else | 1013 else |
| 1009 ShowMessageCenterBubble(); | 1014 ShowMessageCenterBubble(); |
| 1010 return true; | 1015 return true; |
| 1011 } | 1016 } |
| 1012 | 1017 |
| 1013 int WebNotificationTray::GetNotificationCount() const { | 1018 int WebNotificationTray::GetNotificationCount() const { |
| 1014 return notification_list()->notifications().size(); | 1019 return notification_list()->notifications().size(); |
| 1015 } | 1020 } |
| 1016 | 1021 |
| 1022 void WebNotificationTray::ShowSettings(const std::string& id) { |
| 1023 if (delegate_) |
| 1024 delegate_->ShowSettings(id); |
| 1025 } |
| 1026 |
| 1027 void WebNotificationTray::OnClicked(const std::string& id) { |
| 1028 if (delegate_) |
| 1029 delegate_->OnClicked(id); |
| 1030 } |
| 1031 |
| 1032 // Private methods |
| 1033 |
| 1017 void WebNotificationTray::UpdateTray() { | 1034 void WebNotificationTray::UpdateTray() { |
| 1018 count_label_->SetText(UTF8ToUTF16( | 1035 count_label_->SetText(UTF8ToUTF16( |
| 1019 GetNotificationText(notification_list()->unread_count()))); | 1036 GetNotificationText(notification_list()->unread_count()))); |
| 1020 // Dim the message count text only if the message center is empty. | 1037 // Dim the message count text only if the message center is empty. |
| 1021 count_label_->SetEnabledColor( | 1038 count_label_->SetEnabledColor( |
| 1022 (notification_list()->notifications().size() == 0) ? | 1039 (notification_list()->notifications().size() == 0) ? |
| 1023 kMessageCountDimmedColor : kMessageCountColor); | 1040 kMessageCountDimmedColor : kMessageCountColor); |
| 1024 SetVisible((status_area_widget()->login_status() != user::LOGGED_IN_NONE)); | 1041 SetVisible((status_area_widget()->login_status() != user::LOGGED_IN_NONE)); |
| 1025 Layout(); | 1042 Layout(); |
| 1026 SchedulePaint(); | 1043 SchedulePaint(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1041 } | 1058 } |
| 1042 | 1059 |
| 1043 void WebNotificationTray::HideBubble(Bubble* bubble) { | 1060 void WebNotificationTray::HideBubble(Bubble* bubble) { |
| 1044 if (bubble == message_center_bubble()) { | 1061 if (bubble == message_center_bubble()) { |
| 1045 HideMessageCenterBubble(); | 1062 HideMessageCenterBubble(); |
| 1046 } else if (bubble == notification_bubble()) { | 1063 } else if (bubble == notification_bubble()) { |
| 1047 HideNotificationBubble(); | 1064 HideNotificationBubble(); |
| 1048 } | 1065 } |
| 1049 } | 1066 } |
| 1050 | 1067 |
| 1068 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const { |
| 1069 return notification_list_->HasNotification(id); |
| 1070 } |
| 1071 |
| 1051 } // namespace ash | 1072 } // namespace ash |
| OLD | NEW |