Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ash / system / tray / system_tray.h
blob140921657cd32736b07e910c77fd992861ab1374
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.
5 #ifndef ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_
6 #define ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_
8 #include "ash/ash_export.h"
9 #include "ash/system/cast/tray_cast.h"
10 #include "ash/system/tray/system_tray_bubble.h"
11 #include "ash/system/tray/tray_background_view.h"
12 #include "ash/system/user/login_status.h"
13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.h"
17 #include "ui/views/bubble/tray_bubble_view.h"
18 #include "ui/views/view.h"
20 #include <map>
21 #include <vector>
23 namespace ash {
24 class ScreenTrayItem;
25 class SystemBubbleWrapper;
26 class SystemTrayDelegate;
27 class SystemTrayItem;
28 class TrayAccessibility;
29 class TrayDate;
30 class TrayUser;
32 // There are different methods for creating bubble views.
33 enum BubbleCreationType {
34 BUBBLE_CREATE_NEW, // Closes any existing bubble and creates a new one.
35 BUBBLE_USE_EXISTING, // Uses any existing bubble, or creates a new one.
38 class ASH_EXPORT SystemTray : public TrayBackgroundView,
39 public views::TrayBubbleView::Delegate {
40 public:
41 explicit SystemTray(StatusAreaWidget* status_area_widget);
42 ~SystemTray() override;
44 // Calls TrayBackgroundView::Initialize(), creates the tray items, and
45 // adds them to SystemTrayNotifier.
46 void InitializeTrayItems(SystemTrayDelegate* delegate);
48 // Adds a new item in the tray.
49 void AddTrayItem(SystemTrayItem* item);
51 // Removes an existing tray item.
52 void RemoveTrayItem(SystemTrayItem* item);
54 // Returns all tray items that has been added to system tray.
55 const std::vector<SystemTrayItem*>& GetTrayItems() const;
57 // Shows the default view of all items.
58 void ShowDefaultView(BubbleCreationType creation_type);
60 // Shows default view that ingnores outside clicks and activation loss.
61 void ShowPersistentDefaultView();
63 // Shows details of a particular item. If |close_delay_in_seconds| is
64 // non-zero, then the view is automatically closed after the specified time.
65 void ShowDetailedView(SystemTrayItem* item,
66 int close_delay_in_seconds,
67 bool activate,
68 BubbleCreationType creation_type);
70 // Continue showing the existing detailed view, if any, for |close_delay|
71 // seconds.
72 void SetDetailedViewCloseDelay(int close_delay);
74 // Hides the detailed view for |item|.
75 void HideDetailedView(SystemTrayItem* item);
77 // Shows the notification view for |item|.
78 void ShowNotificationView(SystemTrayItem* item);
80 // Hides the notification view for |item|.
81 void HideNotificationView(SystemTrayItem* item);
83 // Updates the items when the login status of the system changes.
84 void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
86 // Updates the items when the shelf alignment changes.
87 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment);
89 // Temporarily hides/unhides the notification bubble.
90 void SetHideNotifications(bool hidden);
92 // Returns true if the shelf should be forced visible when auto-hidden.
93 bool ShouldShowShelf() const;
95 // Returns true if there is a system bubble (already visible or in the process
96 // of being created).
97 bool HasSystemBubble() const;
99 // Returns true if there is a notification bubble.
100 bool HasNotificationBubble() const;
102 // Returns true if the system_bubble_ exists and is of type |type|.
103 bool HasSystemBubbleType(SystemTrayBubble::BubbleType type);
105 // Returns a pointer to the system bubble or NULL if none.
106 SystemTrayBubble* GetSystemBubble();
108 // Returns true if any bubble is visible.
109 bool IsAnyBubbleVisible() const;
111 // Returns true if the mouse is inside the notification bubble.
112 bool IsMouseInNotificationBubble() const;
114 // Closes system bubble and returns true if it did exist.
115 bool CloseSystemBubble() const;
117 // Returns view for help button if default view is shown. Returns NULL
118 // otherwise.
119 views::View* GetHelpButtonView() const;
121 // Accessors for testing.
123 // Returns true if the bubble exists.
124 bool CloseNotificationBubbleForTest() const;
126 // Overridden from TrayBackgroundView.
127 void SetShelfAlignment(ShelfAlignment alignment) override;
128 void AnchorUpdated() override;
129 base::string16 GetAccessibleNameForTray() override;
130 void BubbleResized(const views::TrayBubbleView* bubble_view) override;
131 void HideBubbleWithView(const views::TrayBubbleView* bubble_view) override;
132 bool ClickedOutsideBubble() override;
134 // Overridden from message_center::TrayBubbleView::Delegate.
135 void BubbleViewDestroyed() override;
136 void OnMouseEnteredView() override;
137 void OnMouseExitedView() override;
138 base::string16 GetAccessibleNameForBubble() override;
139 gfx::Rect GetAnchorRect(views::Widget* anchor_widget,
140 AnchorType anchor_type,
141 AnchorAlignment anchor_alignment) const override;
142 void HideBubble(const views::TrayBubbleView* bubble_view) override;
144 ScreenTrayItem* GetScreenShareItem() { return screen_share_tray_item_; }
145 ScreenTrayItem* GetScreenCaptureItem() { return screen_capture_tray_item_; }
147 TrayAccessibility* GetTrayAccessibilityForTest() {
148 return tray_accessibility_;
151 // Get the tray item view (or NULL) for a given |tray_item| in a unit test.
152 views::View* GetTrayItemViewForTest(SystemTrayItem* tray_item);
154 // Gets tray_cast_ for browser tests.
155 TrayCast* GetTrayCastForTesting() const;
157 // Gets tray_date_ for browser tests.
158 TrayDate* GetTrayDateForTesting() const;
160 private:
161 // Creates the default set of items for the sytem tray.
162 void CreateItems(SystemTrayDelegate* delegate);
164 // Resets |system_bubble_| and clears any related state.
165 void DestroySystemBubble();
167 // Resets |notification_bubble_| and clears any related state.
168 void DestroyNotificationBubble();
170 // Returns a string with the current time for accessibility on the status
171 // tray bar.
172 base::string16 GetAccessibleTimeString(const base::Time& now) const;
174 // Calculates the x-offset for the item in the tray. Returns -1 if its tray
175 // item view is not visible.
176 int GetTrayXOffset(SystemTrayItem* item) const;
178 // Shows the default view and its arrow position is shifted by |x_offset|.
179 void ShowDefaultViewWithOffset(BubbleCreationType creation_type,
180 int x_offset,
181 bool persistent);
183 // Constructs or re-constructs |system_bubble_| and populates it with |items|.
184 // Specify |change_tray_status| to true if want to change the tray background
185 // status.
186 void ShowItems(const std::vector<SystemTrayItem*>& items,
187 bool details,
188 bool activate,
189 BubbleCreationType creation_type,
190 int x_offset,
191 bool persistent);
193 // Constructs or re-constructs |notification_bubble_| and populates it with
194 // |notification_items_|, or destroys it if there are no notification items.
195 void UpdateNotificationBubble();
197 // Checks the current status of the system tray and updates the web
198 // notification tray according to the current status.
199 void UpdateWebNotifications();
201 // Deactivate the system tray in the shelf if it was active before.
202 void CloseSystemBubbleAndDeactivateSystemTray();
204 const ScopedVector<SystemTrayItem>& items() const { return items_; }
206 // Overridden from ActionableView.
207 bool PerformAction(const ui::Event& event) override;
209 // Owned items.
210 ScopedVector<SystemTrayItem> items_;
212 // Pointers to members of |items_|.
213 SystemTrayItem* detailed_item_;
214 std::vector<SystemTrayItem*> notification_items_;
216 // Mappings of system tray item and it's view in the tray.
217 std::map<SystemTrayItem*, views::View*> tray_item_map_;
219 // Bubble for default and detailed views.
220 scoped_ptr<SystemBubbleWrapper> system_bubble_;
222 // Bubble for notifications.
223 scoped_ptr<SystemBubbleWrapper> notification_bubble_;
225 // Keep track of the default view height so that when we create detailed
226 // views directly (e.g. from a notification) we know what height to use.
227 int default_bubble_height_;
229 // Set to true when system notifications should be hidden (e.g. web
230 // notification bubble is visible).
231 bool hide_notifications_;
233 // This is true when the displayed system tray menu is a full tray menu,
234 // otherwise a single line item menu like the volume slider is shown.
235 // Note that the value is only valid when |system_bubble_| is true.
236 bool full_system_tray_menu_;
238 TrayAccessibility* tray_accessibility_; // not owned
239 TrayCast* tray_cast_;
240 TrayDate* tray_date_;
242 // A reference to the Screen share and capture item.
243 ScreenTrayItem* screen_capture_tray_item_; // not owned
244 ScreenTrayItem* screen_share_tray_item_; // not owned
246 DISALLOW_COPY_AND_ASSIGN(SystemTray);
249 } // namespace ash
251 #endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_