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_TRAY_SYSTEM_TRAY_H_ | |
6 #define ASH_COMMON_SYSTEM_TRAY_SYSTEM_TRAY_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 #include <vector> | |
11 | |
12 #include "ash/ash_export.h" | |
13 #include "ash/common/system/tray/system_tray_bubble.h" | |
14 #include "ash/common/system/tray/tray_background_view.h" | |
15 #include "base/macros.h" | |
16 #include "ui/views/bubble/tray_bubble_view.h" | |
17 #include "ui/views/view.h" | |
18 | |
19 namespace ash { | |
20 | |
21 class KeyEventWatcher; | |
22 enum class LoginStatus; | |
23 class ScreenTrayItem; | |
24 class SystemBubbleWrapper; | |
25 class SystemTrayDelegate; | |
26 class SystemTrayItem; | |
27 class TrayAccessibility; | |
28 class TrayAudio; | |
29 class TrayCast; | |
30 class TrayDate; | |
31 class TrayNetwork; | |
32 class TraySystemInfo; | |
33 class TrayTiles; | |
34 class TrayUpdate; | |
35 class WebNotificationTray; | |
36 | |
37 // There are different methods for creating bubble views. | |
38 enum BubbleCreationType { | |
39 BUBBLE_CREATE_NEW, // Closes any existing bubble and creates a new one. | |
40 BUBBLE_USE_EXISTING, // Uses any existing bubble, or creates a new one. | |
41 }; | |
42 | |
43 class ASH_EXPORT SystemTray : public TrayBackgroundView, | |
44 public views::TrayBubbleView::Delegate { | |
45 public: | |
46 explicit SystemTray(WmShelf* wm_shelf); | |
47 ~SystemTray() override; | |
48 | |
49 TrayUpdate* tray_update() { return tray_update_; } | |
50 | |
51 // Calls TrayBackgroundView::Initialize(), creates the tray items, and | |
52 // adds them to SystemTrayNotifier. | |
53 void InitializeTrayItems(SystemTrayDelegate* delegate, | |
54 WebNotificationTray* web_notification_tray); | |
55 | |
56 // Resets internal pointers. This has to be called before deletion. | |
57 void Shutdown(); | |
58 | |
59 // Adds a new item in the tray. | |
60 void AddTrayItem(std::unique_ptr<SystemTrayItem> item); | |
61 | |
62 // Returns all tray items that has been added to system tray. | |
63 std::vector<SystemTrayItem*> GetTrayItems() const; | |
64 | |
65 // Shows the default view of all items. | |
66 void ShowDefaultView(BubbleCreationType creation_type); | |
67 | |
68 // Shows default view that ingnores outside clicks and activation loss. | |
69 void ShowPersistentDefaultView(); | |
70 | |
71 // Shows details of a particular item. If |close_delay_in_seconds| is | |
72 // non-zero, then the view is automatically closed after the specified time. | |
73 void ShowDetailedView(SystemTrayItem* item, | |
74 int close_delay_in_seconds, | |
75 bool activate, | |
76 BubbleCreationType creation_type); | |
77 | |
78 // Continue showing the existing detailed view, if any, for |close_delay| | |
79 // seconds. | |
80 void SetDetailedViewCloseDelay(int close_delay); | |
81 | |
82 // Hides the detailed view for |item|. If |animate| is false, disable | |
83 // the hiding animation for hiding |item|. | |
84 void HideDetailedView(SystemTrayItem* item, bool animate); | |
85 | |
86 // Updates the items when the login status of the system changes. | |
87 void UpdateAfterLoginStatusChange(LoginStatus login_status); | |
88 | |
89 // Updates the items when the shelf alignment changes. | |
90 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment); | |
91 | |
92 // Returns true if the shelf should be forced visible when auto-hidden. | |
93 bool ShouldShowShelf() const; | |
94 | |
95 // Returns true if there is a system bubble (already visible or in the process | |
96 // of being created). | |
97 bool HasSystemBubble() const; | |
98 | |
99 // Returns true if the system_bubble_ exists and is of type |type|. | |
100 bool HasSystemBubbleType(SystemTrayBubble::BubbleType type); | |
101 | |
102 // Returns a pointer to the system bubble or NULL if none. | |
103 SystemTrayBubble* GetSystemBubble(); | |
104 | |
105 // Returns true if system bubble is visible. | |
106 bool IsSystemBubbleVisible() const; | |
107 | |
108 // Closes system bubble and returns true if it did exist. | |
109 bool CloseSystemBubble() const; | |
110 | |
111 // Returns view for help button if default view is shown. Returns NULL | |
112 // otherwise. | |
113 views::View* GetHelpButtonView() const; | |
114 | |
115 // Returns TrayAudio object if present or null otherwise. | |
116 TrayAudio* GetTrayAudio() const; | |
117 | |
118 // Overridden from TrayBackgroundView. | |
119 void SetShelfAlignment(ShelfAlignment alignment) override; | |
120 void AnchorUpdated() override; | |
121 base::string16 GetAccessibleNameForTray() override; | |
122 void BubbleResized(const views::TrayBubbleView* bubble_view) override; | |
123 void HideBubbleWithView(const views::TrayBubbleView* bubble_view) override; | |
124 void ClickedOutsideBubble() override; | |
125 | |
126 // views::TrayBubbleView::Delegate: | |
127 void BubbleViewDestroyed() override; | |
128 void OnMouseEnteredView() override; | |
129 void OnMouseExitedView() override; | |
130 base::string16 GetAccessibleNameForBubble() override; | |
131 void OnBeforeBubbleWidgetInit( | |
132 views::Widget* anchor_widget, | |
133 views::Widget* bubble_widget, | |
134 views::Widget::InitParams* params) const override; | |
135 void HideBubble(const views::TrayBubbleView* bubble_view) override; | |
136 | |
137 ScreenTrayItem* GetScreenShareItem() { return screen_share_tray_item_; } | |
138 ScreenTrayItem* GetScreenCaptureItem() { return screen_capture_tray_item_; } | |
139 | |
140 TrayAccessibility* GetTrayAccessibilityForTest() { | |
141 return tray_accessibility_; | |
142 } | |
143 | |
144 // Get the tray item view (or NULL) for a given |tray_item| in a unit test. | |
145 views::View* GetTrayItemViewForTest(SystemTrayItem* tray_item); | |
146 | |
147 TrayCast* GetTrayCastForTesting() const; | |
148 TrayDate* GetTrayDateForTesting() const; | |
149 TrayNetwork* GetTrayNetworkForTesting() const; | |
150 TraySystemInfo* GetTraySystemInfoForTesting() const; | |
151 TrayTiles* GetTrayTilesForTesting() const; | |
152 | |
153 // Activates the system tray bubble. | |
154 void ActivateBubble(); | |
155 | |
156 private: | |
157 class ActivationObserver; | |
158 | |
159 // Closes the bubble. Used to bind as a KeyEventWatcher::KeyEventCallback. | |
160 void CloseBubble(const ui::KeyEvent& key_event); | |
161 | |
162 // Activates the bubble and starts key navigation with the |key_event|. | |
163 void ActivateAndStartNavigation(const ui::KeyEvent& key_event); | |
164 | |
165 // Creates the key event watcher. See |ShowItems()| for why key events are | |
166 // observed. | |
167 void CreateKeyEventWatcher(); | |
168 | |
169 // Creates the default set of items for the sytem tray. | |
170 void CreateItems(SystemTrayDelegate* delegate); | |
171 | |
172 // Resets |system_bubble_| and clears any related state. | |
173 void DestroySystemBubble(); | |
174 | |
175 // Returns a string with the current time for accessibility on the status | |
176 // tray bar. | |
177 base::string16 GetAccessibleTimeString(const base::Time& now) const; | |
178 | |
179 // Constructs or re-constructs |system_bubble_| and populates it with |items|. | |
180 // Specify |change_tray_status| to true if want to change the tray background | |
181 // status. The bubble will be opened in inactive state. If |can_activate| is | |
182 // true, the bubble will be activated by one of following means. | |
183 // * When alt/alt-tab acclerator is used to start navigation. | |
184 // * When the bubble is opened by accelerator. | |
185 // * When the tray item is set to be focused. | |
186 void ShowItems(const std::vector<SystemTrayItem*>& items, | |
187 bool details, | |
188 bool can_activate, | |
189 BubbleCreationType creation_type, | |
190 bool persistent); | |
191 | |
192 // Checks the current status of the system tray and updates the web | |
193 // notification tray according to the current status. | |
194 void UpdateWebNotifications(); | |
195 | |
196 // Deactivate the system tray in the shelf if it was active before. | |
197 void CloseSystemBubbleAndDeactivateSystemTray(); | |
198 | |
199 // Records UMA metrics for the number of user-visible rows in the system menu | |
200 // and the percentage of the work area height covered by the system menu. | |
201 void RecordSystemMenuMetrics(); | |
202 | |
203 // Overridden from ActionableView. | |
204 bool PerformAction(const ui::Event& event) override; | |
205 | |
206 // The web notification tray view that appears adjacent to this view. | |
207 WebNotificationTray* web_notification_tray_; | |
208 | |
209 // Items. | |
210 std::vector<std::unique_ptr<SystemTrayItem>> items_; | |
211 | |
212 // Pointers to members of |items_|. | |
213 SystemTrayItem* detailed_item_; | |
214 | |
215 // Mappings of system tray item and it's view in the tray. | |
216 std::map<SystemTrayItem*, views::View*> tray_item_map_; | |
217 | |
218 // Bubble for default and detailed views. | |
219 std::unique_ptr<SystemBubbleWrapper> system_bubble_; | |
220 | |
221 // Keep track of the default view height so that when we create detailed | |
222 // views directly (e.g. from a notification) we know what height to use. | |
223 int default_bubble_height_; | |
224 | |
225 // This is true when the displayed system tray menu is a full tray menu, | |
226 // otherwise a single line item menu like the volume slider is shown. | |
227 // Note that the value is only valid when |system_bubble_| is true. | |
228 bool full_system_tray_menu_; | |
229 | |
230 // These objects are not owned by this class. | |
231 TrayAccessibility* tray_accessibility_; | |
232 TrayAudio* tray_audio_; // May be null. | |
233 TrayCast* tray_cast_; | |
234 TrayDate* tray_date_; // null for material design. | |
235 TrayNetwork* tray_network_; | |
236 TrayTiles* tray_tiles_; // only used in material design. | |
237 TraySystemInfo* tray_system_info_; // only used in material design. | |
238 TrayUpdate* tray_update_; | |
239 | |
240 // A reference to the Screen share and capture item. | |
241 ScreenTrayItem* screen_capture_tray_item_; // not owned | |
242 ScreenTrayItem* screen_share_tray_item_; // not owned | |
243 | |
244 // TODO(oshima): Remove this when crbug.com/651242 is fixed. | |
245 bool activating_ = false; | |
246 | |
247 std::unique_ptr<KeyEventWatcher> key_event_watcher_; | |
248 | |
249 std::unique_ptr<ActivationObserver> activation_observer_; | |
250 | |
251 DISALLOW_COPY_AND_ASSIGN(SystemTray); | |
252 }; | |
253 | |
254 } // namespace ash | |
255 | |
256 #endif // ASH_COMMON_SYSTEM_TRAY_SYSTEM_TRAY_H_ | |
OLD | NEW |