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/tray/system_tray_bubble.h"
10 #include "ash/system/tray/tray_background_view.h"
11 #include "ash/system/user/login_status.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "ui/views/bubble/tray_bubble_view.h"
17 #include "ui/views/view.h"
24 class SystemBubbleWrapper
;
25 class SystemTrayDelegate
;
27 class TrayAccessibility
;
31 // There are different methods for creating bubble views.
32 enum BubbleCreationType
{
33 BUBBLE_CREATE_NEW
, // Closes any existing bubble and creates a new one.
34 BUBBLE_USE_EXISTING
, // Uses any existing bubble, or creates a new one.
37 class ASH_EXPORT SystemTray
: public TrayBackgroundView
,
38 public views::TrayBubbleView::Delegate
{
40 explicit SystemTray(StatusAreaWidget
* status_area_widget
);
41 virtual ~SystemTray();
43 // Calls TrayBackgroundView::Initialize(), creates the tray items, and
44 // adds them to SystemTrayNotifier.
45 void InitializeTrayItems(SystemTrayDelegate
* delegate
);
47 // Adds a new item in the tray.
48 void AddTrayItem(SystemTrayItem
* item
);
50 // Removes an existing tray item.
51 void RemoveTrayItem(SystemTrayItem
* item
);
53 // Returns all tray items that has been added to system tray.
54 const std::vector
<SystemTrayItem
*>& GetTrayItems() const;
56 // Shows the default view of all items.
57 void ShowDefaultView(BubbleCreationType creation_type
);
59 // Shows default view that ingnores outside clicks and activation loss.
60 void ShowPersistentDefaultView();
62 // Shows details of a particular item. If |close_delay_in_seconds| is
63 // non-zero, then the view is automatically closed after the specified time.
64 void ShowDetailedView(SystemTrayItem
* item
,
65 int close_delay_in_seconds
,
67 BubbleCreationType creation_type
);
69 // Continue showing the existing detailed view, if any, for |close_delay|
71 void SetDetailedViewCloseDelay(int close_delay
);
73 // Hides the detailed view for |item|.
74 void HideDetailedView(SystemTrayItem
* item
);
76 // Shows the notification view for |item|.
77 void ShowNotificationView(SystemTrayItem
* item
);
79 // Hides the notification view for |item|.
80 void HideNotificationView(SystemTrayItem
* item
);
82 // Updates the items when the login status of the system changes.
83 void UpdateAfterLoginStatusChange(user::LoginStatus login_status
);
85 // Updates the items when the shelf alignment changes.
86 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment
);
88 // Temporarily hides/unhides the notification bubble.
89 void SetHideNotifications(bool hidden
);
91 // Returns true if the shelf should be forced visible when auto-hidden.
92 bool ShouldShowShelf() const;
94 // Returns true if there is a system bubble (already visible or in the process
96 bool HasSystemBubble() const;
98 // Returns true if there is a notification bubble.
99 bool HasNotificationBubble() const;
101 // Returns true if the system_bubble_ exists and is of type |type|.
102 bool HasSystemBubbleType(SystemTrayBubble::BubbleType type
);
104 // Returns a pointer to the system bubble or NULL if none.
105 SystemTrayBubble
* GetSystemBubble();
107 // Returns true if any bubble is visible.
108 bool IsAnyBubbleVisible() const;
110 // Returns true if the mouse is inside the notification bubble.
111 bool IsMouseInNotificationBubble() const;
113 // Closes system bubble and returns true if it did exist.
114 bool CloseSystemBubble() const;
116 // Returns view for help button if default view is shown. Returns NULL
118 views::View
* GetHelpButtonView() const;
120 // Accessors for testing.
122 // Returns true if the bubble exists.
123 bool CloseNotificationBubbleForTest() const;
125 // Overridden from TrayBackgroundView.
126 virtual void SetShelfAlignment(ShelfAlignment alignment
) OVERRIDE
;
127 virtual void AnchorUpdated() OVERRIDE
;
128 virtual base::string16
GetAccessibleNameForTray() OVERRIDE
;
129 virtual void BubbleResized(const views::TrayBubbleView
* bubble_view
) OVERRIDE
;
130 virtual void HideBubbleWithView(
131 const views::TrayBubbleView
* bubble_view
) OVERRIDE
;
132 virtual bool ClickedOutsideBubble() OVERRIDE
;
134 // Overridden from message_center::TrayBubbleView::Delegate.
135 virtual void BubbleViewDestroyed() OVERRIDE
;
136 virtual void OnMouseEnteredView() OVERRIDE
;
137 virtual void OnMouseExitedView() OVERRIDE
;
138 virtual base::string16
GetAccessibleNameForBubble() OVERRIDE
;
139 virtual gfx::Rect
GetAnchorRect(
140 views::Widget
* anchor_widget
,
141 AnchorType anchor_type
,
142 AnchorAlignment anchor_alignment
) const OVERRIDE
;
143 virtual void HideBubble(const views::TrayBubbleView
* bubble_view
) OVERRIDE
;
145 ScreenTrayItem
* GetScreenShareItem() { return screen_share_tray_item_
; }
146 ScreenTrayItem
* GetScreenCaptureItem() { return screen_capture_tray_item_
; }
148 TrayAccessibility
* GetTrayAccessibilityForTest() {
149 return tray_accessibility_
;
152 // Get the tray item view (or NULL) for a given |tray_item| in a unit test.
153 views::View
* GetTrayItemViewForTest(SystemTrayItem
* tray_item
);
155 // Gets tray_date_ for browser tests.
156 TrayDate
* GetTrayDateForTesting() const;
159 // Creates the default set of items for the sytem tray.
160 void CreateItems(SystemTrayDelegate
* delegate
);
162 // Resets |system_bubble_| and clears any related state.
163 void DestroySystemBubble();
165 // Resets |notification_bubble_| and clears any related state.
166 void DestroyNotificationBubble();
168 // Returns a string with the current time for accessibility on the status
170 base::string16
GetAccessibleTimeString(const base::Time
& now
) const;
172 // Calculates the x-offset for the item in the tray. Returns -1 if its tray
173 // item view is not visible.
174 int GetTrayXOffset(SystemTrayItem
* item
) const;
176 // Shows the default view and its arrow position is shifted by |x_offset|.
177 void ShowDefaultViewWithOffset(BubbleCreationType creation_type
,
181 // Constructs or re-constructs |system_bubble_| and populates it with |items|.
182 // Specify |change_tray_status| to true if want to change the tray background
184 void ShowItems(const std::vector
<SystemTrayItem
*>& items
,
187 BubbleCreationType creation_type
,
191 // Constructs or re-constructs |notification_bubble_| and populates it with
192 // |notification_items_|, or destroys it if there are no notification items.
193 void UpdateNotificationBubble();
195 // Checks the current status of the system tray and updates the web
196 // notification tray according to the current status.
197 void UpdateWebNotifications();
199 // Deactivate the system tray in the shelf if it was active before.
200 void CloseSystemBubbleAndDeactivateSystemTray();
202 const ScopedVector
<SystemTrayItem
>& items() const { return items_
; }
204 // Overridden from ActionableView.
205 virtual bool PerformAction(const ui::Event
& event
) OVERRIDE
;
208 ScopedVector
<SystemTrayItem
> items_
;
210 // Pointers to members of |items_|.
211 SystemTrayItem
* detailed_item_
;
212 std::vector
<SystemTrayItem
*> notification_items_
;
214 // Mappings of system tray item and it's view in the tray.
215 std::map
<SystemTrayItem
*, views::View
*> tray_item_map_
;
217 // Bubble for default and detailed views.
218 scoped_ptr
<SystemBubbleWrapper
> system_bubble_
;
220 // Bubble for notifications.
221 scoped_ptr
<SystemBubbleWrapper
> notification_bubble_
;
223 // Keep track of the default view height so that when we create detailed
224 // views directly (e.g. from a notification) we know what height to use.
225 int default_bubble_height_
;
227 // Set to true when system notifications should be hidden (e.g. web
228 // notification bubble is visible).
229 bool hide_notifications_
;
231 // This is true when the displayed system tray menu is a full tray menu,
232 // otherwise a single line item menu like the volume slider is shown.
233 // Note that the value is only valid when |system_bubble_| is true.
234 bool full_system_tray_menu_
;
236 TrayAccessibility
* tray_accessibility_
; // not owned
237 TrayDate
* tray_date_
;
239 // A reference to the Screen share and capture item.
240 ScreenTrayItem
* screen_capture_tray_item_
; // not owned
241 ScreenTrayItem
* screen_share_tray_item_
; // not owned
243 DISALLOW_COPY_AND_ASSIGN(SystemTray
);
248 #endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_