Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: ash/system/tray/system_tray.h

Issue 2148593004: mash: Move StatusTray and StatusAreaWidget to //ash/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@traydisplay
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/system/tray/DEPS ('k') | ash/system/tray/system_tray.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_SYSTEM_TRAY_SYSTEM_TRAY_H_
6 #define ASH_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 "base/memory/scoped_vector.h"
17 #include "ui/views/bubble/tray_bubble_view.h"
18 #include "ui/views/view.h"
19
20 namespace ash {
21
22 enum class LoginStatus;
23 class ScreenTrayItem;
24 class SystemBubbleWrapper;
25 class SystemTrayDelegate;
26 class SystemTrayItem;
27 class TrayAccessibility;
28 class TrayCast;
29 class TrayDate;
30 class TrayUpdate;
31 class TrayUser;
32 class WebNotificationTray;
33
34 // There are different methods for creating bubble views.
35 enum BubbleCreationType {
36 BUBBLE_CREATE_NEW, // Closes any existing bubble and creates a new one.
37 BUBBLE_USE_EXISTING, // Uses any existing bubble, or creates a new one.
38 };
39
40 class ASH_EXPORT SystemTray : public TrayBackgroundView,
41 public views::TrayBubbleView::Delegate {
42 public:
43 explicit SystemTray(WmShelf* wm_shelf);
44 ~SystemTray() override;
45
46 // Calls TrayBackgroundView::Initialize(), creates the tray items, and
47 // adds them to SystemTrayNotifier.
48 void InitializeTrayItems(SystemTrayDelegate* delegate,
49 WebNotificationTray* web_notification_tray);
50
51 // Resets internal pointers.
52 void Shutdown();
53
54 // Adds a new item in the tray. Takes ownership.
55 void AddTrayItem(SystemTrayItem* item);
56
57 // Returns all tray items that has been added to system tray.
58 const std::vector<SystemTrayItem*>& GetTrayItems() const;
59
60 // Shows the default view of all items.
61 void ShowDefaultView(BubbleCreationType creation_type);
62
63 // Shows default view that ingnores outside clicks and activation loss.
64 void ShowPersistentDefaultView();
65
66 // Shows details of a particular item. If |close_delay_in_seconds| is
67 // non-zero, then the view is automatically closed after the specified time.
68 void ShowDetailedView(SystemTrayItem* item,
69 int close_delay_in_seconds,
70 bool activate,
71 BubbleCreationType creation_type);
72
73 // Continue showing the existing detailed view, if any, for |close_delay|
74 // seconds.
75 void SetDetailedViewCloseDelay(int close_delay);
76
77 // Hides the detailed view for |item|.
78 void HideDetailedView(SystemTrayItem* item);
79
80 // Shows the notification view for |item|.
81 void ShowNotificationView(SystemTrayItem* item);
82
83 // Hides the notification view for |item|.
84 void HideNotificationView(SystemTrayItem* item);
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 // Temporarily hides/unhides the notification bubble.
93 void SetHideNotifications(bool hidden);
94
95 // Returns true if the shelf should be forced visible when auto-hidden.
96 bool ShouldShowShelf() const;
97
98 // Returns true if there is a system bubble (already visible or in the process
99 // of being created).
100 bool HasSystemBubble() const;
101
102 // Returns true if there is a notification bubble.
103 bool HasNotificationBubble() const;
104
105 // Returns true if the system_bubble_ exists and is of type |type|.
106 bool HasSystemBubbleType(SystemTrayBubble::BubbleType type);
107
108 // Returns a pointer to the system bubble or NULL if none.
109 SystemTrayBubble* GetSystemBubble();
110
111 // Returns true if any bubble is visible.
112 bool IsAnyBubbleVisible() const;
113
114 // Returns true if the mouse is inside the notification bubble.
115 bool IsMouseInNotificationBubble() const;
116
117 // Closes system bubble and returns true if it did exist.
118 bool CloseSystemBubble() const;
119
120 // Returns view for help button if default view is shown. Returns NULL
121 // otherwise.
122 views::View* GetHelpButtonView() const;
123
124 // Accessors for testing.
125
126 // Returns true if the bubble exists.
127 bool CloseNotificationBubbleForTest() const;
128
129 // Overridden from TrayBackgroundView.
130 void SetShelfAlignment(ShelfAlignment alignment) override;
131 void AnchorUpdated() override;
132 base::string16 GetAccessibleNameForTray() override;
133 void BubbleResized(const views::TrayBubbleView* bubble_view) override;
134 void HideBubbleWithView(const views::TrayBubbleView* bubble_view) override;
135 void ClickedOutsideBubble() override;
136
137 // views::TrayBubbleView::Delegate:
138 void BubbleViewDestroyed() override;
139 void OnMouseEnteredView() override;
140 void OnMouseExitedView() override;
141 base::string16 GetAccessibleNameForBubble() override;
142 gfx::Rect GetAnchorRect(views::Widget* anchor_widget,
143 AnchorType anchor_type,
144 AnchorAlignment anchor_alignment) const override;
145 void OnBeforeBubbleWidgetInit(
146 views::Widget* anchor_widget,
147 views::Widget* bubble_widget,
148 views::Widget::InitParams* params) const override;
149 void HideBubble(const views::TrayBubbleView* bubble_view) override;
150
151 ScreenTrayItem* GetScreenShareItem() { return screen_share_tray_item_; }
152 ScreenTrayItem* GetScreenCaptureItem() { return screen_capture_tray_item_; }
153
154 TrayAccessibility* GetTrayAccessibilityForTest() {
155 return tray_accessibility_;
156 }
157
158 // Get the tray item view (or NULL) for a given |tray_item| in a unit test.
159 views::View* GetTrayItemViewForTest(SystemTrayItem* tray_item);
160
161 TrayCast* GetTrayCastForTesting() const;
162 TrayDate* GetTrayDateForTesting() const;
163 TrayUpdate* GetTrayUpdateForTesting() const;
164
165 private:
166 // Creates the default set of items for the sytem tray.
167 void CreateItems(SystemTrayDelegate* delegate);
168
169 // Resets |system_bubble_| and clears any related state.
170 void DestroySystemBubble();
171
172 // Resets |notification_bubble_| and clears any related state.
173 void DestroyNotificationBubble();
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 // Calculates the x-offset for the item in the tray. Returns -1 if its tray
180 // item view is not visible.
181 int GetTrayXOffset(SystemTrayItem* item) const;
182
183 // Shows the default view and its arrow position is shifted by |x_offset|.
184 void ShowDefaultViewWithOffset(BubbleCreationType creation_type,
185 int x_offset,
186 bool persistent);
187
188 // Constructs or re-constructs |system_bubble_| and populates it with |items|.
189 // Specify |change_tray_status| to true if want to change the tray background
190 // status.
191 void ShowItems(const std::vector<SystemTrayItem*>& items,
192 bool details,
193 bool activate,
194 BubbleCreationType creation_type,
195 int x_offset,
196 bool persistent);
197
198 // Constructs or re-constructs |notification_bubble_| and populates it with
199 // |notification_items_|, or destroys it if there are no notification items.
200 void UpdateNotificationBubble();
201
202 // Checks the current status of the system tray and updates the web
203 // notification tray according to the current status.
204 void UpdateWebNotifications();
205
206 // Deactivate the system tray in the shelf if it was active before.
207 void CloseSystemBubbleAndDeactivateSystemTray();
208
209 // Records UMA metrics for the number of user-visible rows in the system menu
210 // and the percentage of the work area height covered by the system menu.
211 void RecordSystemMenuMetrics();
212
213 const ScopedVector<SystemTrayItem>& items() const { return items_; }
214
215 // Overridden from ActionableView.
216 bool PerformAction(const ui::Event& event) override;
217
218 // The web notification tray view that appears adjacent to this view.
219 WebNotificationTray* web_notification_tray_;
220
221 // Owned items.
222 ScopedVector<SystemTrayItem> items_;
223
224 // Pointers to members of |items_|.
225 SystemTrayItem* detailed_item_;
226 std::vector<SystemTrayItem*> notification_items_;
227
228 // Mappings of system tray item and it's view in the tray.
229 std::map<SystemTrayItem*, views::View*> tray_item_map_;
230
231 // Bubble for default and detailed views.
232 std::unique_ptr<SystemBubbleWrapper> system_bubble_;
233
234 // Bubble for notifications.
235 std::unique_ptr<SystemBubbleWrapper> notification_bubble_;
236
237 // Keep track of the default view height so that when we create detailed
238 // views directly (e.g. from a notification) we know what height to use.
239 int default_bubble_height_;
240
241 // Set to true when system notifications should be hidden (e.g. web
242 // notification bubble is visible).
243 bool hide_notifications_;
244
245 // This is true when the displayed system tray menu is a full tray menu,
246 // otherwise a single line item menu like the volume slider is shown.
247 // Note that the value is only valid when |system_bubble_| is true.
248 bool full_system_tray_menu_;
249
250 TrayAccessibility* tray_accessibility_; // not owned
251 TrayCast* tray_cast_;
252 TrayDate* tray_date_;
253 TrayUpdate* tray_update_;
254
255 // A reference to the Screen share and capture item.
256 ScreenTrayItem* screen_capture_tray_item_; // not owned
257 ScreenTrayItem* screen_share_tray_item_; // not owned
258
259 DISALLOW_COPY_AND_ASSIGN(SystemTray);
260 };
261
262 } // namespace ash
263
264 #endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_
OLDNEW
« no previous file with comments | « ash/system/tray/DEPS ('k') | ash/system/tray/system_tray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698