| 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" |
| 11 #include "ash/system/tray/tray_views.h" | 11 #include "ash/system/tray/tray_views.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/timer.h" | 15 #include "base/timer.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
| 18 #include "grit/ui_resources.h" | 18 #include "grit/ui_resources.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/models/simple_menu_model.h" | 21 #include "ui/base/models/simple_menu_model.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/gfx/image/image_skia_operations.h" | 23 #include "ui/gfx/image/image_skia_operations.h" |
| 24 #include "ui/gfx/screen.h" |
| 24 #include "ui/views/controls/button/button.h" | 25 #include "ui/views/controls/button/button.h" |
| 25 #include "ui/views/controls/button/menu_button.h" | 26 #include "ui/views/controls/button/menu_button.h" |
| 26 #include "ui/views/controls/button/menu_button_listener.h" | 27 #include "ui/views/controls/button/menu_button_listener.h" |
| 27 #include "ui/views/controls/label.h" | 28 #include "ui/views/controls/label.h" |
| 28 #include "ui/views/controls/menu/menu_model_adapter.h" | 29 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 29 #include "ui/views/controls/menu/menu_runner.h" | 30 #include "ui/views/controls/menu/menu_runner.h" |
| 30 #include "ui/views/layout/box_layout.h" | 31 #include "ui/views/layout/box_layout.h" |
| 31 #include "ui/views/layout/fill_layout.h" | 32 #include "ui/views/layout/fill_layout.h" |
| 32 #include "ui/views/layout/grid_layout.h" | 33 #include "ui/views/layout/grid_layout.h" |
| 33 #include "ui/views/painter.h" | 34 #include "ui/views/painter.h" |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 bubble_view_(NULL), | 710 bubble_view_(NULL), |
| 710 bubble_widget_(NULL), | 711 bubble_widget_(NULL), |
| 711 contents_view_(NULL), | 712 contents_view_(NULL), |
| 712 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 713 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 713 views::View* anchor = tray->tray_container(); | 714 views::View* anchor = tray->tray_container(); |
| 714 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, | 715 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, |
| 715 tray->shelf_alignment()); | 716 tray->shelf_alignment()); |
| 716 init_params.bubble_width = kWebNotificationWidth; | 717 init_params.bubble_width = kWebNotificationWidth; |
| 717 if (bubble_type == BUBBLE_TYPE_MESAGE_CENTER) { | 718 if (bubble_type == BUBBLE_TYPE_MESAGE_CENTER) { |
| 718 init_params.max_height = kWebNotificationBubbleMaxHeight; | 719 init_params.max_height = kWebNotificationBubbleMaxHeight; |
| 720 init_params.can_activate = true; |
| 719 } else { | 721 } else { |
| 720 init_params.arrow_color = kBackgroundColor; | 722 init_params.arrow_color = kBackgroundColor; |
| 721 init_params.close_on_deactivate = false; | 723 init_params.close_on_deactivate = false; |
| 722 } | 724 } |
| 723 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | 725 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
| 724 gfx::Point bounds(anchor->width() / 2, 0); | 726 gfx::Point bounds(anchor->width() / 2, 0); |
| 725 ConvertPointToWidget(anchor, &bounds); | 727 ConvertPointToWidget(anchor, &bounds); |
| 726 init_params.arrow_offset = bounds.x(); | 728 init_params.arrow_offset = bounds.x(); |
| 727 } | 729 } |
| 728 bubble_view_ = TrayBubbleView::Create(anchor, this, init_params); | 730 bubble_view_ = TrayBubbleView::Create(anchor, this, init_params); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 754 StartAutoCloseTimer(); | 756 StartAutoCloseTimer(); |
| 755 | 757 |
| 756 weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update. | 758 weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update. |
| 757 MessageLoop::current()->PostDelayedTask( | 759 MessageLoop::current()->PostDelayedTask( |
| 758 FROM_HERE, | 760 FROM_HERE, |
| 759 base::Bind(&WebNotificationTray::Bubble::UpdateBubbleView, | 761 base::Bind(&WebNotificationTray::Bubble::UpdateBubbleView, |
| 760 weak_ptr_factory_.GetWeakPtr()), | 762 weak_ptr_factory_.GetWeakPtr()), |
| 761 base::TimeDelta::FromMilliseconds(kUpdateDelayMs)); | 763 base::TimeDelta::FromMilliseconds(kUpdateDelayMs)); |
| 762 } | 764 } |
| 763 | 765 |
| 766 bool IsVisible() const { |
| 767 return bubble_widget_ && bubble_widget_->IsVisible(); |
| 768 } |
| 769 |
| 764 views::Widget* bubble_widget() const { return bubble_widget_; } | 770 views::Widget* bubble_widget() const { return bubble_widget_; } |
| 771 TrayBubbleView* bubble_view() const { return bubble_view_; } |
| 765 | 772 |
| 766 // Overridden from TrayBubbleView::Host. | 773 // Overridden from TrayBubbleView::Host. |
| 767 virtual void BubbleViewDestroyed() OVERRIDE { | 774 virtual void BubbleViewDestroyed() OVERRIDE { |
| 768 bubble_view_ = NULL; | 775 bubble_view_ = NULL; |
| 769 contents_view_ = NULL; | 776 contents_view_ = NULL; |
| 770 } | 777 } |
| 771 | 778 |
| 772 virtual void OnMouseEnteredView() OVERRIDE { | 779 virtual void OnMouseEnteredView() OVERRIDE { |
| 773 StopAutoCloseTimer(); | 780 StopAutoCloseTimer(); |
| 781 tray_->UpdateShouldShowLauncher(); |
| 774 } | 782 } |
| 775 | 783 |
| 776 virtual void OnMouseExitedView() OVERRIDE { | 784 virtual void OnMouseExitedView() OVERRIDE { |
| 777 StartAutoCloseTimer(); | 785 StartAutoCloseTimer(); |
| 786 tray_->UpdateShouldShowLauncher(); |
| 778 } | 787 } |
| 779 | 788 |
| 780 virtual void OnClickedOutsideView() OVERRIDE { | 789 virtual void OnClickedOutsideView() OVERRIDE { |
| 781 // May delete |this|. | 790 // May delete |this|. |
| 782 tray_->HideMessageCenterBubble(); | 791 tray_->HideMessageCenterBubble(); |
| 783 } | 792 } |
| 784 | 793 |
| 794 virtual string16 GetAccessibleName() OVERRIDE { |
| 795 return tray_->GetAccessibleName(); |
| 796 } |
| 797 |
| 785 // Overridden from views::WidgetObserver: | 798 // Overridden from views::WidgetObserver: |
| 786 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { | 799 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { |
| 787 CHECK_EQ(bubble_widget_, widget); | 800 CHECK_EQ(bubble_widget_, widget); |
| 788 bubble_widget_ = NULL; | 801 bubble_widget_ = NULL; |
| 789 tray_->HideBubble(this); // Will destroy |this|. | 802 tray_->HideBubble(this); // Will destroy |this|. |
| 790 } | 803 } |
| 791 | 804 |
| 792 private: | 805 private: |
| 793 void UpdateBubbleView() { | 806 void UpdateBubbleView() { |
| 794 const WebNotificationList::Notifications& notifications = | 807 const WebNotificationList::Notifications& notifications = |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 if (message_center_bubble()) { | 912 if (message_center_bubble()) { |
| 900 UpdateTray(); | 913 UpdateTray(); |
| 901 return; | 914 return; |
| 902 } | 915 } |
| 903 notification_list_->SetIsVisible(true); // clears notification count | 916 notification_list_->SetIsVisible(true); // clears notification count |
| 904 UpdateTray(); | 917 UpdateTray(); |
| 905 HideNotificationBubble(); | 918 HideNotificationBubble(); |
| 906 message_center_bubble_.reset( | 919 message_center_bubble_.reset( |
| 907 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER)); | 920 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER)); |
| 908 status_area_widget()->SetHideSystemNotifications(true); | 921 status_area_widget()->SetHideSystemNotifications(true); |
| 922 UpdateShouldShowLauncher(); |
| 909 } | 923 } |
| 910 | 924 |
| 911 void WebNotificationTray::HideMessageCenterBubble() { | 925 void WebNotificationTray::HideMessageCenterBubble() { |
| 912 if (!message_center_bubble()) | 926 if (!message_center_bubble()) |
| 913 return; | 927 return; |
| 914 message_center_bubble_.reset(); | 928 message_center_bubble_.reset(); |
| 915 show_message_center_on_unlock_ = false; | 929 show_message_center_on_unlock_ = false; |
| 916 notification_list_->SetIsVisible(false); | 930 notification_list_->SetIsVisible(false); |
| 917 status_area_widget()->SetHideSystemNotifications(false); | 931 status_area_widget()->SetHideSystemNotifications(false); |
| 932 UpdateShouldShowLauncher(); |
| 918 } | 933 } |
| 919 | 934 |
| 920 void WebNotificationTray::ShowNotificationBubble() { | 935 void WebNotificationTray::ShowNotificationBubble() { |
| 921 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 936 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) |
| 922 return; | 937 return; |
| 923 if (message_center_bubble()) | 938 if (message_center_bubble()) |
| 924 return; | 939 return; |
| 925 if (!status_area_widget()->ShouldShowNonSystemNotifications()) | 940 if (!status_area_widget()->ShouldShowNonSystemNotifications()) |
| 926 return; | 941 return; |
| 927 UpdateTray(); | 942 UpdateTray(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 946 } | 961 } |
| 947 HideNotificationBubble(); | 962 HideNotificationBubble(); |
| 948 } else { | 963 } else { |
| 949 if (show_message_center_on_unlock_) | 964 if (show_message_center_on_unlock_) |
| 950 ShowMessageCenterBubble(); | 965 ShowMessageCenterBubble(); |
| 951 show_message_center_on_unlock_ = false; | 966 show_message_center_on_unlock_ = false; |
| 952 } | 967 } |
| 953 UpdateTray(); | 968 UpdateTray(); |
| 954 } | 969 } |
| 955 | 970 |
| 971 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { |
| 972 return (message_center_bubble() && message_center_bubble_->IsVisible()); |
| 973 } |
| 974 |
| 975 bool WebNotificationTray::IsMouseInNotificationBubble() const { |
| 976 if (!notification_bubble()) |
| 977 return false; |
| 978 return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains( |
| 979 gfx::Screen::GetCursorScreenPoint()); |
| 980 } |
| 981 |
| 956 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { | 982 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 957 if (alignment == shelf_alignment()) | 983 if (alignment == shelf_alignment()) |
| 958 return; | 984 return; |
| 959 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 985 internal::TrayBackgroundView::SetShelfAlignment(alignment); |
| 960 if (alignment == SHELF_ALIGNMENT_BOTTOM) | 986 if (alignment == SHELF_ALIGNMENT_BOTTOM) |
| 961 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); | 987 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); |
| 962 else | 988 else |
| 963 tray_container()->set_size(gfx::Size(kTraySideWidth, kTraySideHeight)); | 989 tray_container()->set_size(gfx::Size(kTraySideWidth, kTraySideHeight)); |
| 964 // Destroy any existing bubble so that it will be rebuilt correctly. | 990 // Destroy any existing bubble so that it will be rebuilt correctly. |
| 965 HideMessageCenterBubble(); | 991 HideMessageCenterBubble(); |
| 966 HideNotificationBubble(); | 992 HideNotificationBubble(); |
| 967 } | 993 } |
| 968 | 994 |
| 995 void WebNotificationTray::AnchorUpdated() { |
| 996 if (notification_bubble_.get()) { |
| 997 notification_bubble_->bubble_view()->UpdateBubble(); |
| 998 // Ensure that the notification buble is above the launcher/status area. |
| 999 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
| 1000 } |
| 1001 if (message_center_bubble_.get()) |
| 1002 message_center_bubble_->bubble_view()->UpdateBubble(); |
| 1003 } |
| 1004 |
| 1005 string16 WebNotificationTray::GetAccessibleName() { |
| 1006 return l10n_util::GetStringUTF16( |
| 1007 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); |
| 1008 } |
| 1009 |
| 969 // Protected methods (invoked only from Bubble and its child classes) | 1010 // Protected methods (invoked only from Bubble and its child classes) |
| 970 | 1011 |
| 971 void WebNotificationTray::SendRemoveNotification(const std::string& id) { | 1012 void WebNotificationTray::SendRemoveNotification(const std::string& id) { |
| 972 // If this is the only notification in the list, close the bubble. | 1013 // If this is the only notification in the list, close the bubble. |
| 973 if (notification_list_->notifications().size() == 1 && | 1014 if (notification_list_->notifications().size() == 1 && |
| 974 id == notification_list_->GetFirstId()) { | 1015 id == notification_list_->GetFirstId()) { |
| 975 HideMessageCenterBubble(); | 1016 HideMessageCenterBubble(); |
| 976 } | 1017 } |
| 977 if (delegate_) | 1018 if (delegate_) |
| 978 delegate_->NotificationRemoved(id); | 1019 delegate_->NotificationRemoved(id); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 | 1075 |
| 1035 // Private methods | 1076 // Private methods |
| 1036 | 1077 |
| 1037 void WebNotificationTray::UpdateTray() { | 1078 void WebNotificationTray::UpdateTray() { |
| 1038 count_label_->SetText(UTF8ToUTF16( | 1079 count_label_->SetText(UTF8ToUTF16( |
| 1039 GetNotificationText(notification_list()->unread_count()))); | 1080 GetNotificationText(notification_list()->unread_count()))); |
| 1040 // Dim the message count text only if the message center is empty. | 1081 // Dim the message count text only if the message center is empty. |
| 1041 count_label_->SetEnabledColor( | 1082 count_label_->SetEnabledColor( |
| 1042 (notification_list()->notifications().size() == 0) ? | 1083 (notification_list()->notifications().size() == 0) ? |
| 1043 kMessageCountDimmedColor : kMessageCountColor); | 1084 kMessageCountDimmedColor : kMessageCountColor); |
| 1044 SetVisible((status_area_widget()->login_status() != user::LOGGED_IN_NONE)); | 1085 bool is_visible = |
| 1086 (status_area_widget()->login_status() != user::LOGGED_IN_NONE) && |
| 1087 (status_area_widget()->login_status() != user::LOGGED_IN_LOCKED); |
| 1088 SetVisible(is_visible); |
| 1045 Layout(); | 1089 Layout(); |
| 1046 SchedulePaint(); | 1090 SchedulePaint(); |
| 1047 } | 1091 } |
| 1048 | 1092 |
| 1049 void WebNotificationTray::UpdateTrayAndBubble() { | 1093 void WebNotificationTray::UpdateTrayAndBubble() { |
| 1050 UpdateTray(); | 1094 UpdateTray(); |
| 1051 | 1095 |
| 1052 if (message_center_bubble()) | 1096 if (message_center_bubble()) |
| 1053 message_center_bubble()->ScheduleUpdate(); | 1097 message_center_bubble()->ScheduleUpdate(); |
| 1054 | 1098 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1066 } else if (bubble == notification_bubble()) { | 1110 } else if (bubble == notification_bubble()) { |
| 1067 HideNotificationBubble(); | 1111 HideNotificationBubble(); |
| 1068 } | 1112 } |
| 1069 } | 1113 } |
| 1070 | 1114 |
| 1071 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const { | 1115 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const { |
| 1072 return notification_list_->HasNotification(id); | 1116 return notification_list_->HasNotification(id); |
| 1073 } | 1117 } |
| 1074 | 1118 |
| 1075 } // namespace ash | 1119 } // namespace ash |
| OLD | NEW |