Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ash / system / tray / system_tray.h
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 "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"
18
19 #include <map>
20 #include <vector>
21
22 namespace ash {
23 class ScreenTrayItem;
24 class SystemBubbleWrapper;
25 class SystemTrayDelegate;
26 class SystemTrayItem;
27 class TrayAccessibility;
28 class TrayDate;
29 class TrayUser;
30
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.
35 };
36
37 class ASH_EXPORT SystemTray : public TrayBackgroundView,
38                               public views::TrayBubbleView::Delegate {
39  public:
40   explicit SystemTray(StatusAreaWidget* status_area_widget);
41   virtual ~SystemTray();
42
43   // Calls TrayBackgroundView::Initialize(), creates the tray items, and
44   // adds them to SystemTrayNotifier.
45   void InitializeTrayItems(SystemTrayDelegate* delegate);
46
47   // Adds a new item in the tray.
48   void AddTrayItem(SystemTrayItem* item);
49
50   // Removes an existing tray item.
51   void RemoveTrayItem(SystemTrayItem* item);
52
53   // Returns all tray items that has been added to system tray.
54   const std::vector<SystemTrayItem*>& GetTrayItems() const;
55
56   // Shows the default view of all items.
57   void ShowDefaultView(BubbleCreationType creation_type);
58
59   // Shows default view that ingnores outside clicks and activation loss.
60   void ShowPersistentDefaultView();
61
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,
66                         bool activate,
67                         BubbleCreationType creation_type);
68
69   // Continue showing the existing detailed view, if any, for |close_delay|
70   // seconds.
71   void SetDetailedViewCloseDelay(int close_delay);
72
73   // Hides the detailed view for |item|.
74   void HideDetailedView(SystemTrayItem* item);
75
76   // Shows the notification view for |item|.
77   void ShowNotificationView(SystemTrayItem* item);
78
79   // Hides the notification view for |item|.
80   void HideNotificationView(SystemTrayItem* item);
81
82   // Updates the items when the login status of the system changes.
83   void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
84
85   // Updates the items when the shelf alignment changes.
86   void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment);
87
88   // Temporarily hides/unhides the notification bubble.
89   void SetHideNotifications(bool hidden);
90
91   // Returns true if the shelf should be forced visible when auto-hidden.
92   bool ShouldShowShelf() const;
93
94   // Returns true if there is a system bubble (already visible or in the process
95   // of being created).
96   bool HasSystemBubble() const;
97
98   // Returns true if there is a notification bubble.
99   bool HasNotificationBubble() const;
100
101   // Returns true if the system_bubble_ exists and is of type |type|.
102   bool HasSystemBubbleType(SystemTrayBubble::BubbleType type);
103
104   // Returns a pointer to the system bubble or NULL if none.
105   SystemTrayBubble* GetSystemBubble();
106
107   // Returns true if any bubble is visible.
108   bool IsAnyBubbleVisible() const;
109
110   // Returns true if the mouse is inside the notification bubble.
111   bool IsMouseInNotificationBubble() const;
112
113   // Closes system bubble and returns true if it did exist.
114   bool CloseSystemBubble() const;
115
116   // Returns view for help button if default view is shown. Returns NULL
117   // otherwise.
118   views::View* GetHelpButtonView() const;
119
120   // Accessors for testing.
121
122   // Returns true if the bubble exists.
123   bool CloseNotificationBubbleForTest() const;
124
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;
133
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;
144
145   ScreenTrayItem* GetScreenShareItem() { return screen_share_tray_item_; }
146   ScreenTrayItem* GetScreenCaptureItem() { return screen_capture_tray_item_; }
147
148   TrayAccessibility* GetTrayAccessibilityForTest() {
149     return tray_accessibility_;
150   }
151
152   // Get the tray item view (or NULL) for a given |tray_item| in a unit test.
153   views::View* GetTrayItemViewForTest(SystemTrayItem* tray_item);
154
155   // Gets tray_date_ for browser tests.
156   TrayDate* GetTrayDateForTesting() const;
157
158  private:
159   // Creates the default set of items for the sytem tray.
160   void CreateItems(SystemTrayDelegate* delegate);
161
162   // Resets |system_bubble_| and clears any related state.
163   void DestroySystemBubble();
164
165   // Resets |notification_bubble_| and clears any related state.
166   void DestroyNotificationBubble();
167
168   // Returns a string with the current time for accessibility on the status
169   // tray bar.
170   base::string16 GetAccessibleTimeString(const base::Time& now) const;
171
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;
175
176   // Shows the default view and its arrow position is shifted by |x_offset|.
177   void ShowDefaultViewWithOffset(BubbleCreationType creation_type,
178                                  int x_offset,
179                                  bool persistent);
180
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
183   // status.
184   void ShowItems(const std::vector<SystemTrayItem*>& items,
185                  bool details,
186                  bool activate,
187                  BubbleCreationType creation_type,
188                  int x_offset,
189                  bool persistent);
190
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();
194
195   // Checks the current status of the system tray and updates the web
196   // notification tray according to the current status.
197   void UpdateWebNotifications();
198
199   // Deactivate the system tray in the shelf if it was active before.
200   void CloseSystemBubbleAndDeactivateSystemTray();
201
202   const ScopedVector<SystemTrayItem>& items() const { return items_; }
203
204   // Overridden from ActionableView.
205   virtual bool PerformAction(const ui::Event& event) OVERRIDE;
206
207   // Owned items.
208   ScopedVector<SystemTrayItem> items_;
209
210   // Pointers to members of |items_|.
211   SystemTrayItem* detailed_item_;
212   std::vector<SystemTrayItem*> notification_items_;
213
214   // Mappings of system tray item and it's view in the tray.
215   std::map<SystemTrayItem*, views::View*> tray_item_map_;
216
217   // Bubble for default and detailed views.
218   scoped_ptr<SystemBubbleWrapper> system_bubble_;
219
220   // Bubble for notifications.
221   scoped_ptr<SystemBubbleWrapper> notification_bubble_;
222
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_;
226
227   // Set to true when system notifications should be hidden (e.g. web
228   // notification bubble is visible).
229   bool hide_notifications_;
230
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_;
235
236   TrayAccessibility* tray_accessibility_;  // not owned
237   TrayDate* tray_date_;
238
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
242
243   DISALLOW_COPY_AND_ASSIGN(SystemTray);
244 };
245
246 }  // namespace ash
247
248 #endif  // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_