| 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 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 StartAutoCloseTimer(); | 755 StartAutoCloseTimer(); |
| 755 | 756 |
| 756 weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update. | 757 weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update. |
| 757 MessageLoop::current()->PostDelayedTask( | 758 MessageLoop::current()->PostDelayedTask( |
| 758 FROM_HERE, | 759 FROM_HERE, |
| 759 base::Bind(&WebNotificationTray::Bubble::UpdateBubbleView, | 760 base::Bind(&WebNotificationTray::Bubble::UpdateBubbleView, |
| 760 weak_ptr_factory_.GetWeakPtr()), | 761 weak_ptr_factory_.GetWeakPtr()), |
| 761 base::TimeDelta::FromMilliseconds(kUpdateDelayMs)); | 762 base::TimeDelta::FromMilliseconds(kUpdateDelayMs)); |
| 762 } | 763 } |
| 763 | 764 |
| 765 bool IsVisible() const { |
| 766 return bubble_widget_ && bubble_widget_->IsVisible(); |
| 767 } |
| 768 |
| 764 views::Widget* bubble_widget() const { return bubble_widget_; } | 769 views::Widget* bubble_widget() const { return bubble_widget_; } |
| 765 TrayBubbleView* bubble_view() const { return bubble_view_; } | 770 TrayBubbleView* bubble_view() const { return bubble_view_; } |
| 766 | 771 |
| 767 // Overridden from TrayBubbleView::Host. | 772 // Overridden from TrayBubbleView::Host. |
| 768 virtual void BubbleViewDestroyed() OVERRIDE { | 773 virtual void BubbleViewDestroyed() OVERRIDE { |
| 769 bubble_view_ = NULL; | 774 bubble_view_ = NULL; |
| 770 contents_view_ = NULL; | 775 contents_view_ = NULL; |
| 771 } | 776 } |
| 772 | 777 |
| 773 virtual void OnMouseEnteredView() OVERRIDE { | 778 virtual void OnMouseEnteredView() OVERRIDE { |
| 774 StopAutoCloseTimer(); | 779 StopAutoCloseTimer(); |
| 780 tray_->UpdateShouldShowLauncher(); |
| 775 } | 781 } |
| 776 | 782 |
| 777 virtual void OnMouseExitedView() OVERRIDE { | 783 virtual void OnMouseExitedView() OVERRIDE { |
| 778 StartAutoCloseTimer(); | 784 StartAutoCloseTimer(); |
| 785 tray_->UpdateShouldShowLauncher(); |
| 779 } | 786 } |
| 780 | 787 |
| 781 virtual void OnClickedOutsideView() OVERRIDE { | 788 virtual void OnClickedOutsideView() OVERRIDE { |
| 782 // May delete |this|. | 789 // May delete |this|. |
| 783 tray_->HideMessageCenterBubble(); | 790 tray_->HideMessageCenterBubble(); |
| 784 } | 791 } |
| 785 | 792 |
| 786 // Overridden from views::WidgetObserver: | 793 // Overridden from views::WidgetObserver: |
| 787 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { | 794 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { |
| 788 CHECK_EQ(bubble_widget_, widget); | 795 CHECK_EQ(bubble_widget_, widget); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 if (message_center_bubble()) { | 907 if (message_center_bubble()) { |
| 901 UpdateTray(); | 908 UpdateTray(); |
| 902 return; | 909 return; |
| 903 } | 910 } |
| 904 notification_list_->SetIsVisible(true); // clears notification count | 911 notification_list_->SetIsVisible(true); // clears notification count |
| 905 UpdateTray(); | 912 UpdateTray(); |
| 906 HideNotificationBubble(); | 913 HideNotificationBubble(); |
| 907 message_center_bubble_.reset( | 914 message_center_bubble_.reset( |
| 908 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER)); | 915 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER)); |
| 909 status_area_widget()->SetHideSystemNotifications(true); | 916 status_area_widget()->SetHideSystemNotifications(true); |
| 917 UpdateShouldShowLauncher(); |
| 910 } | 918 } |
| 911 | 919 |
| 912 void WebNotificationTray::HideMessageCenterBubble() { | 920 void WebNotificationTray::HideMessageCenterBubble() { |
| 913 if (!message_center_bubble()) | 921 if (!message_center_bubble()) |
| 914 return; | 922 return; |
| 915 message_center_bubble_.reset(); | 923 message_center_bubble_.reset(); |
| 916 show_message_center_on_unlock_ = false; | 924 show_message_center_on_unlock_ = false; |
| 917 notification_list_->SetIsVisible(false); | 925 notification_list_->SetIsVisible(false); |
| 918 status_area_widget()->SetHideSystemNotifications(false); | 926 status_area_widget()->SetHideSystemNotifications(false); |
| 927 UpdateShouldShowLauncher(); |
| 919 } | 928 } |
| 920 | 929 |
| 921 void WebNotificationTray::ShowNotificationBubble() { | 930 void WebNotificationTray::ShowNotificationBubble() { |
| 922 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 931 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) |
| 923 return; | 932 return; |
| 924 if (message_center_bubble()) | 933 if (message_center_bubble()) |
| 925 return; | 934 return; |
| 926 if (!status_area_widget()->ShouldShowNonSystemNotifications()) | 935 if (!status_area_widget()->ShouldShowNonSystemNotifications()) |
| 927 return; | 936 return; |
| 928 UpdateTray(); | 937 UpdateTray(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 947 } | 956 } |
| 948 HideNotificationBubble(); | 957 HideNotificationBubble(); |
| 949 } else { | 958 } else { |
| 950 if (show_message_center_on_unlock_) | 959 if (show_message_center_on_unlock_) |
| 951 ShowMessageCenterBubble(); | 960 ShowMessageCenterBubble(); |
| 952 show_message_center_on_unlock_ = false; | 961 show_message_center_on_unlock_ = false; |
| 953 } | 962 } |
| 954 UpdateTray(); | 963 UpdateTray(); |
| 955 } | 964 } |
| 956 | 965 |
| 966 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { |
| 967 return (message_center_bubble() && message_center_bubble_->IsVisible()); |
| 968 } |
| 969 |
| 970 bool WebNotificationTray::IsMouseInNotificationBubble() const { |
| 971 if (!notification_bubble()) |
| 972 return false; |
| 973 return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains( |
| 974 gfx::Screen::GetCursorScreenPoint()); |
| 975 } |
| 976 |
| 957 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { | 977 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 958 if (alignment == shelf_alignment()) | 978 if (alignment == shelf_alignment()) |
| 959 return; | 979 return; |
| 960 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 980 internal::TrayBackgroundView::SetShelfAlignment(alignment); |
| 961 if (alignment == SHELF_ALIGNMENT_BOTTOM) | 981 if (alignment == SHELF_ALIGNMENT_BOTTOM) |
| 962 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); | 982 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); |
| 963 else | 983 else |
| 964 tray_container()->set_size(gfx::Size(kTraySideWidth, kTraySideHeight)); | 984 tray_container()->set_size(gfx::Size(kTraySideWidth, kTraySideHeight)); |
| 965 // Destroy any existing bubble so that it will be rebuilt correctly. | 985 // Destroy any existing bubble so that it will be rebuilt correctly. |
| 966 HideMessageCenterBubble(); | 986 HideMessageCenterBubble(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 } else if (bubble == notification_bubble()) { | 1100 } else if (bubble == notification_bubble()) { |
| 1081 HideNotificationBubble(); | 1101 HideNotificationBubble(); |
| 1082 } | 1102 } |
| 1083 } | 1103 } |
| 1084 | 1104 |
| 1085 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const { | 1105 bool WebNotificationTray::HasNotificationForTest(const std::string& id) const { |
| 1086 return notification_list_->HasNotification(id); | 1106 return notification_list_->HasNotification(id); |
| 1087 } | 1107 } |
| 1088 | 1108 |
| 1089 } // namespace ash | 1109 } // namespace ash |
| OLD | NEW |