OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ASH_COMMON_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | |
6 #define ASH_COMMON_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "ash/common/login_status.h" | |
12 #include "ash/common/system/tray/tray_background_view.h" | |
13 #include "base/gtest_prod_util.h" | |
14 #include "base/macros.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 #include "ui/base/models/simple_menu_model.h" | |
17 #include "ui/gfx/animation/animation_container.h" | |
18 #include "ui/message_center/message_center_tray.h" | |
19 #include "ui/message_center/message_center_tray_delegate.h" | |
20 #include "ui/views/bubble/tray_bubble_view.h" | |
21 | |
22 // Status area tray for showing browser and app notifications. This hosts | |
23 // a MessageCenter class which manages the notification list. This class | |
24 // contains the Ash specific tray implementation. | |
25 // | |
26 // Note: These are not related to system notifications (i.e NotificationView | |
27 // generated by SystemTrayItem). Visibility of one notification type or other | |
28 // is controlled by StatusAreaWidget. | |
29 | |
30 namespace message_center { | |
31 class MessageCenter; | |
32 class MessageCenterBubble; | |
33 class MessagePopupCollection; | |
34 } | |
35 | |
36 namespace ash { | |
37 class AshPopupAlignmentDelegate; | |
38 class SystemTray; | |
39 class WebNotificationBubbleWrapper; | |
40 class WebNotificationImage; | |
41 class WebNotificationLabel; | |
42 class WmWindow; | |
43 | |
44 class ASH_EXPORT WebNotificationTray | |
45 : public TrayBackgroundView, | |
46 public views::TrayBubbleView::Delegate, | |
47 public message_center::MessageCenterTrayDelegate, | |
48 public base::SupportsWeakPtr<WebNotificationTray>, | |
49 public ui::SimpleMenuModel::Delegate { | |
50 public: | |
51 WebNotificationTray(WmShelf* shelf, | |
52 WmWindow* status_area_window, | |
53 SystemTray* system_tray); | |
54 ~WebNotificationTray() override; | |
55 | |
56 static void DisableAnimationsForTest(bool disable); | |
57 | |
58 // Sets the height of the system tray bubble (or legacy notification bubble) | |
59 // from the edge of the work area so that the web notification popups don't | |
60 // overlap with the tray. Pass 0 if no bubble is shown. | |
61 void SetTrayBubbleHeight(int height); | |
62 | |
63 // Returns the current tray bubble height or 0 if there is no bubble. | |
64 int tray_bubble_height_for_test() const; | |
65 | |
66 // Returns true if it should block the auto hide behavior of the shelf. | |
67 bool ShouldBlockShelfAutoHide() const; | |
68 | |
69 // Returns true if the message center bubble is visible. | |
70 bool IsMessageCenterBubbleVisible() const; | |
71 | |
72 // Shows the message center bubble. | |
73 void ShowMessageCenterBubble(); | |
74 | |
75 // Called when the login status is changed. | |
76 void UpdateAfterLoginStatusChange(LoginStatus login_status); | |
77 | |
78 // Overridden from TrayBackgroundView. | |
79 void SetShelfAlignment(ShelfAlignment alignment) override; | |
80 void AnchorUpdated() override; | |
81 base::string16 GetAccessibleNameForTray() override; | |
82 void HideBubbleWithView(const views::TrayBubbleView* bubble_view) override; | |
83 void ClickedOutsideBubble() override; | |
84 | |
85 // Overridden from ActionableView. | |
86 bool PerformAction(const ui::Event& event) override; | |
87 | |
88 // Overridden from views::TrayBubbleView::Delegate. | |
89 void BubbleViewDestroyed() override; | |
90 void OnMouseEnteredView() override; | |
91 void OnMouseExitedView() override; | |
92 base::string16 GetAccessibleNameForBubble() override; | |
93 void OnBeforeBubbleWidgetInit( | |
94 views::Widget* anchor_widget, | |
95 views::Widget* bubble_widget, | |
96 views::Widget::InitParams* params) const override; | |
97 void HideBubble(const views::TrayBubbleView* bubble_view) override; | |
98 | |
99 // Overridden from MessageCenterTrayDelegate. | |
100 void OnMessageCenterTrayChanged() override; | |
101 bool ShowMessageCenter() override; | |
102 void HideMessageCenter() override; | |
103 bool ShowPopups() override; | |
104 void HidePopups() override; | |
105 bool ShowNotifierSettings() override; | |
106 bool IsContextMenuEnabled() const override; | |
107 message_center::MessageCenterTray* GetMessageCenterTray() override; | |
108 | |
109 // Overridden from ui::SimpleMenuModel::Delegate. | |
110 bool IsCommandIdChecked(int command_id) const override; | |
111 bool IsCommandIdEnabled(int command_id) const override; | |
112 void ExecuteCommand(int command_id, int event_flags) override; | |
113 | |
114 message_center::MessageCenter* message_center() const; | |
115 | |
116 private: | |
117 friend class WebNotificationTrayTest; | |
118 | |
119 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); | |
120 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble); | |
121 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, | |
122 ManyMessageCenterNotifications); | |
123 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications); | |
124 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupShownOnBothDisplays); | |
125 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndSystemTray); | |
126 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndAutoHideShelf); | |
127 | |
128 void UpdateTrayContent(); | |
129 | |
130 // The actual process to show the message center. Set |show_settings| to true | |
131 // if the message center should be initialized with the settings visible. | |
132 // Returns true if the center is successfully created. | |
133 bool ShowMessageCenterInternal(bool show_settings); | |
134 | |
135 // Queries login status and the status area widget to determine visibility of | |
136 // the message center. | |
137 bool ShouldShowMessageCenter(); | |
138 | |
139 // Returns true if it should show the quiet mode menu. | |
140 bool ShouldShowQuietModeMenu(const ui::Event& event); | |
141 | |
142 // Shows the quiet mode menu. | |
143 void ShowQuietModeMenu(const ui::Event& event); | |
144 | |
145 // Creates the menu model for quiet mode and returns it. | |
146 ui::MenuModel* CreateQuietModeMenu(); | |
147 | |
148 WebNotificationBubbleWrapper* message_center_bubble() const { | |
149 return message_center_bubble_.get(); | |
150 } | |
151 | |
152 // Returns true if any user is logged in and the system is not at the screen | |
153 // for adding a secondary user. | |
154 bool IsLoggedIn() const; | |
155 | |
156 // Testing accessors. | |
157 bool IsPopupVisible() const; | |
158 message_center::MessageCenterBubble* GetMessageCenterBubbleForTest(); | |
159 | |
160 WmWindow* status_area_window_; | |
161 SystemTray* system_tray_; | |
162 std::unique_ptr<message_center::MessageCenterTray> message_center_tray_; | |
163 std::unique_ptr<WebNotificationBubbleWrapper> message_center_bubble_; | |
164 std::unique_ptr<message_center::MessagePopupCollection> popup_collection_; | |
165 std::unique_ptr<WebNotificationImage> bell_icon_; | |
166 std::unique_ptr<WebNotificationLabel> counter_; | |
167 | |
168 scoped_refptr<gfx::AnimationContainer> animation_container_ = | |
169 new gfx::AnimationContainer(); | |
170 | |
171 std::unordered_map<std::string, WebNotificationImage*> visible_small_icons_; | |
172 | |
173 bool show_message_center_on_unlock_; | |
174 | |
175 bool should_update_tray_content_; | |
176 | |
177 // True when the shelf auto hide behavior has to be blocked. Previously | |
178 // this was done by checking |message_center_bubble_| but actually | |
179 // the check can be called when creating this object, so it would cause | |
180 // flickers of the shelf from hidden to shown. See: crbug.com/181213 | |
181 bool should_block_shelf_auto_hide_; | |
182 | |
183 std::unique_ptr<AshPopupAlignmentDelegate> popup_alignment_delegate_; | |
184 | |
185 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); | |
186 }; | |
187 | |
188 } // namespace ash | |
189 | |
190 #endif // ASH_COMMON_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | |
OLD | NEW |