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