OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_ | 5 #ifndef ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_ |
6 #define ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_ | 6 #define ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "ash/system/tray/system_tray_bubble.h" | 9 #include "ash/system/tray/system_tray_bubble.h" |
10 #include "ash/system/tray/tray_background_view.h" | 10 #include "ash/system/tray/tray_background_view.h" |
11 #include "ash/system/user/login_status.h" | 11 #include "ash/system/user/login_status.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "ui/views/bubble/tray_bubble_view.h" | 16 #include "ui/views/bubble/tray_bubble_view.h" |
17 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
18 | 18 |
19 #include <map> | 19 #include <map> |
20 #include <vector> | 20 #include <vector> |
21 | 21 |
22 namespace ash { | 22 namespace ash { |
23 | 23 class SystemBubbleWrapper; |
24 class SystemTrayDelegate; | 24 class SystemTrayDelegate; |
25 class SystemTrayItem; | 25 class SystemTrayItem; |
26 | |
27 namespace internal { | |
28 class SystemBubbleWrapper; | |
29 class TrayAccessibility; | 26 class TrayAccessibility; |
30 class TrayDate; | 27 class TrayDate; |
31 class TrayUser; | 28 class TrayUser; |
32 } | |
33 | 29 |
34 // There are different methods for creating bubble views. | 30 // There are different methods for creating bubble views. |
35 enum BubbleCreationType { | 31 enum BubbleCreationType { |
36 BUBBLE_CREATE_NEW, // Closes any existing bubble and creates a new one. | 32 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. | 33 BUBBLE_USE_EXISTING, // Uses any existing bubble, or creates a new one. |
38 }; | 34 }; |
39 | 35 |
40 class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, | 36 class ASH_EXPORT SystemTray : public TrayBackgroundView, |
41 public views::TrayBubbleView::Delegate { | 37 public views::TrayBubbleView::Delegate { |
42 public: | 38 public: |
43 explicit SystemTray(internal::StatusAreaWidget* status_area_widget); | 39 explicit SystemTray(StatusAreaWidget* status_area_widget); |
44 virtual ~SystemTray(); | 40 virtual ~SystemTray(); |
45 | 41 |
46 // Calls TrayBackgroundView::Initialize(), creates the tray items, and | 42 // Calls TrayBackgroundView::Initialize(), creates the tray items, and |
47 // adds them to SystemTrayNotifier. | 43 // adds them to SystemTrayNotifier. |
48 void InitializeTrayItems(SystemTrayDelegate* delegate); | 44 void InitializeTrayItems(SystemTrayDelegate* delegate); |
49 | 45 |
50 // Adds a new item in the tray. | 46 // Adds a new item in the tray. |
51 void AddTrayItem(SystemTrayItem* item); | 47 void AddTrayItem(SystemTrayItem* item); |
52 | 48 |
53 // Removes an existing tray item. | 49 // Removes an existing tray item. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 bool ShouldShowShelf() const; | 91 bool ShouldShowShelf() const; |
96 | 92 |
97 // Returns true if there is a system bubble (already visible or in the process | 93 // Returns true if there is a system bubble (already visible or in the process |
98 // of being created). | 94 // of being created). |
99 bool HasSystemBubble() const; | 95 bool HasSystemBubble() const; |
100 | 96 |
101 // Returns true if there is a notification bubble. | 97 // Returns true if there is a notification bubble. |
102 bool HasNotificationBubble() const; | 98 bool HasNotificationBubble() const; |
103 | 99 |
104 // Returns true if the system_bubble_ exists and is of type |type|. | 100 // Returns true if the system_bubble_ exists and is of type |type|. |
105 bool HasSystemBubbleType(internal::SystemTrayBubble::BubbleType type); | 101 bool HasSystemBubbleType(SystemTrayBubble::BubbleType type); |
106 | 102 |
107 // Returns a pointer to the system bubble or NULL if none. | 103 // Returns a pointer to the system bubble or NULL if none. |
108 internal::SystemTrayBubble* GetSystemBubble(); | 104 SystemTrayBubble* GetSystemBubble(); |
109 | 105 |
110 // Returns true if any bubble is visible. | 106 // Returns true if any bubble is visible. |
111 bool IsAnyBubbleVisible() const; | 107 bool IsAnyBubbleVisible() const; |
112 | 108 |
113 // Returns true if the mouse is inside the notification bubble. | 109 // Returns true if the mouse is inside the notification bubble. |
114 bool IsMouseInNotificationBubble() const; | 110 bool IsMouseInNotificationBubble() const; |
115 | 111 |
116 // Closes system bubble and returns true if it did exist. | 112 // Closes system bubble and returns true if it did exist. |
117 bool CloseSystemBubble() const; | 113 bool CloseSystemBubble() const; |
118 | 114 |
(...skipping 18 matching lines...) Expand all Loading... |
137 // Overridden from message_center::TrayBubbleView::Delegate. | 133 // Overridden from message_center::TrayBubbleView::Delegate. |
138 virtual void BubbleViewDestroyed() OVERRIDE; | 134 virtual void BubbleViewDestroyed() OVERRIDE; |
139 virtual void OnMouseEnteredView() OVERRIDE; | 135 virtual void OnMouseEnteredView() OVERRIDE; |
140 virtual void OnMouseExitedView() OVERRIDE; | 136 virtual void OnMouseExitedView() OVERRIDE; |
141 virtual base::string16 GetAccessibleNameForBubble() OVERRIDE; | 137 virtual base::string16 GetAccessibleNameForBubble() OVERRIDE; |
142 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget, | 138 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget, |
143 AnchorType anchor_type, | 139 AnchorType anchor_type, |
144 AnchorAlignment anchor_alignment) OVERRIDE; | 140 AnchorAlignment anchor_alignment) OVERRIDE; |
145 virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE; | 141 virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE; |
146 | 142 |
147 internal::TrayAccessibility* GetTrayAccessibilityForTest() { | 143 TrayAccessibility* GetTrayAccessibilityForTest() { |
148 return tray_accessibility_; | 144 return tray_accessibility_; |
149 } | 145 } |
150 | 146 |
151 // Get the tray item view (or NULL) for a given |tray_item| in a unit test. | 147 // Get the tray item view (or NULL) for a given |tray_item| in a unit test. |
152 views::View* GetTrayItemViewForTest(SystemTrayItem* tray_item); | 148 views::View* GetTrayItemViewForTest(SystemTrayItem* tray_item); |
153 | 149 |
154 // Gets tray_date_ for browser tests. | 150 // Gets tray_date_ for browser tests. |
155 internal::TrayDate* GetTrayDateForTesting() const; | 151 TrayDate* GetTrayDateForTesting() const; |
156 | 152 |
157 private: | 153 private: |
158 // Creates the default set of items for the sytem tray. | 154 // Creates the default set of items for the sytem tray. |
159 void CreateItems(SystemTrayDelegate* delegate); | 155 void CreateItems(SystemTrayDelegate* delegate); |
160 | 156 |
161 // Resets |system_bubble_| and clears any related state. | 157 // Resets |system_bubble_| and clears any related state. |
162 void DestroySystemBubble(); | 158 void DestroySystemBubble(); |
163 | 159 |
164 // Resets |notification_bubble_| and clears any related state. | 160 // Resets |notification_bubble_| and clears any related state. |
165 void DestroyNotificationBubble(); | 161 void DestroyNotificationBubble(); |
(...skipping 23 matching lines...) Expand all Loading... |
189 | 185 |
190 // Checks the current status of the system tray and updates the web | 186 // Checks the current status of the system tray and updates the web |
191 // notification tray according to the current status. | 187 // notification tray according to the current status. |
192 void UpdateWebNotifications(); | 188 void UpdateWebNotifications(); |
193 | 189 |
194 // Deactivate the system tray in the shelf if it was active before. | 190 // Deactivate the system tray in the shelf if it was active before. |
195 void CloseSystemBubbleAndDeactivateSystemTray(); | 191 void CloseSystemBubbleAndDeactivateSystemTray(); |
196 | 192 |
197 const ScopedVector<SystemTrayItem>& items() const { return items_; } | 193 const ScopedVector<SystemTrayItem>& items() const { return items_; } |
198 | 194 |
199 // Overridden from internal::ActionableView. | 195 // Overridden from ActionableView. |
200 virtual bool PerformAction(const ui::Event& event) OVERRIDE; | 196 virtual bool PerformAction(const ui::Event& event) OVERRIDE; |
201 | 197 |
202 // Owned items. | 198 // Owned items. |
203 ScopedVector<SystemTrayItem> items_; | 199 ScopedVector<SystemTrayItem> items_; |
204 | 200 |
205 // Pointers to members of |items_|. | 201 // Pointers to members of |items_|. |
206 SystemTrayItem* detailed_item_; | 202 SystemTrayItem* detailed_item_; |
207 std::vector<SystemTrayItem*> notification_items_; | 203 std::vector<SystemTrayItem*> notification_items_; |
208 | 204 |
209 // Mappings of system tray item and it's view in the tray. | 205 // Mappings of system tray item and it's view in the tray. |
210 std::map<SystemTrayItem*, views::View*> tray_item_map_; | 206 std::map<SystemTrayItem*, views::View*> tray_item_map_; |
211 | 207 |
212 // Bubble for default and detailed views. | 208 // Bubble for default and detailed views. |
213 scoped_ptr<internal::SystemBubbleWrapper> system_bubble_; | 209 scoped_ptr<SystemBubbleWrapper> system_bubble_; |
214 | 210 |
215 // Bubble for notifications. | 211 // Bubble for notifications. |
216 scoped_ptr<internal::SystemBubbleWrapper> notification_bubble_; | 212 scoped_ptr<SystemBubbleWrapper> notification_bubble_; |
217 | 213 |
218 // Keep track of the default view height so that when we create detailed | 214 // Keep track of the default view height so that when we create detailed |
219 // views directly (e.g. from a notification) we know what height to use. | 215 // views directly (e.g. from a notification) we know what height to use. |
220 int default_bubble_height_; | 216 int default_bubble_height_; |
221 | 217 |
222 // Set to true when system notifications should be hidden (e.g. web | 218 // Set to true when system notifications should be hidden (e.g. web |
223 // notification bubble is visible). | 219 // notification bubble is visible). |
224 bool hide_notifications_; | 220 bool hide_notifications_; |
225 | 221 |
226 // This is true when the displayed system tray menu is a full tray menu, | 222 // This is true when the displayed system tray menu is a full tray menu, |
227 // otherwise a single line item menu like the volume slider is shown. | 223 // otherwise a single line item menu like the volume slider is shown. |
228 // Note that the value is only valid when |system_bubble_| is true. | 224 // Note that the value is only valid when |system_bubble_| is true. |
229 bool full_system_tray_menu_; | 225 bool full_system_tray_menu_; |
230 | 226 |
231 internal::TrayAccessibility* tray_accessibility_; // not owned | 227 TrayAccessibility* tray_accessibility_; // not owned |
232 internal::TrayDate* tray_date_; | 228 TrayDate* tray_date_; |
233 | 229 |
234 DISALLOW_COPY_AND_ASSIGN(SystemTray); | 230 DISALLOW_COPY_AND_ASSIGN(SystemTray); |
235 }; | 231 }; |
236 | 232 |
237 } // namespace ash | 233 } // namespace ash |
238 | 234 |
239 #endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_ | 235 #endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_ |
OLD | NEW |