Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ash / system / tray / system_tray.h
blob09885242c481df9e85a5df4259b1375400fe33da
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/power/power_supply_status.h"
10 #include "ash/system/tray/system_tray_bubble.h"
11 #include "ash/system/tray/tray_background_view.h"
12 #include "ash/system/tray/tray_views.h"
13 #include "ash/system/user/login_status.h"
14 #include "base/basictypes.h"
15 #include "base/compiler_specific.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/scoped_vector.h"
18 #include "ui/views/bubble/tray_bubble_view.h"
19 #include "ui/views/view.h"
21 #include <map>
22 #include <vector>
24 namespace ash {
26 class AccessibilityObserver;
27 class AudioObserver;
28 class BluetoothObserver;
29 class BrightnessObserver;
30 class CapsLockObserver;
31 class ClockObserver;
32 class DriveObserver;
33 class IMEObserver;
34 class LocaleObserver;
35 class LogoutButtonObserver;
36 class PowerStatusObserver;
37 class SystemTrayDelegate;
38 class UpdateObserver;
39 class UserObserver;
40 #if defined(OS_CHROMEOS)
41 class NetworkObserver;
42 class SmsObserver;
43 #endif
45 class SystemTrayItem;
47 namespace internal {
48 class SystemBubbleWrapper;
49 class SystemTrayContainer;
50 class TrayAccessibility;
51 class TrayGestureHandler;
54 // There are different methods for creating bubble views.
55 enum BubbleCreationType {
56 BUBBLE_CREATE_NEW, // Closes any existing bubble and creates a new one.
57 BUBBLE_USE_EXISTING, // Uses any existing bubble, or creates a new one.
60 class ASH_EXPORT SystemTray : public internal::TrayBackgroundView,
61 public views::TrayBubbleView::Delegate {
62 public:
63 explicit SystemTray(internal::StatusAreaWidget* status_area_widget);
64 virtual ~SystemTray();
66 // Calls TrayBackgroundView::Initialize(), creates the tray items, and
67 // adds them to SystemTrayNotifier.
68 void InitializeTrayItems(SystemTrayDelegate* delegate);
70 // Adds a new item in the tray.
71 void AddTrayItem(SystemTrayItem* item);
73 // Removes an existing tray item.
74 void RemoveTrayItem(SystemTrayItem* item);
76 // Shows the default view of all items.
77 void ShowDefaultView(BubbleCreationType creation_type);
79 // Shows details of a particular item. If |close_delay_in_seconds| is
80 // non-zero, then the view is automatically closed after the specified time.
81 void ShowDetailedView(SystemTrayItem* item,
82 int close_delay_in_seconds,
83 bool activate,
84 BubbleCreationType creation_type);
86 // Continue showing the existing detailed view, if any, for |close_delay|
87 // seconds.
88 void SetDetailedViewCloseDelay(int close_delay);
90 // Hides the detailed view for |item|.
91 void HideDetailedView(SystemTrayItem* item);
93 // Shows the notification view for |item|.
94 void ShowNotificationView(SystemTrayItem* item);
96 // Hides the notification view for |item|.
97 void HideNotificationView(SystemTrayItem* item);
99 // Updates the items when the login status of the system changes.
100 void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
102 // Updates the items when the shelf alignment changes.
103 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment);
105 // Temporarily hides/unhides the notification bubble.
106 void SetHideNotifications(bool hidden);
108 // Returns true if the launcher should be forced visible when auto-hidden.
109 bool ShouldShowLauncher() const;
111 // Returns true if there is a system bubble (already visible or in the process
112 // of being created).
113 bool HasSystemBubble() const;
115 // Returns true if there is a notification bubble.
116 bool HasNotificationBubble() const;
118 // Returns true if the system_bubble_ exists and is of type |type|.
119 bool HasSystemBubbleType(internal::SystemTrayBubble::BubbleType type);
121 // Returns a pointer to the system bubble or NULL if none.
122 internal::SystemTrayBubble* GetSystemBubble();
124 // Returns true if any bubble is visible.
125 bool IsAnyBubbleVisible() const;
127 // Returns true if the mouse is inside the notification bubble.
128 bool IsMouseInNotificationBubble() const;
130 // Accessors for testing.
132 // Returns true if the bubble exists.
133 bool CloseSystemBubbleForTest() const;
134 bool CloseNotificationBubbleForTest() const;
136 // Overridden from TrayBackgroundView.
137 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
138 virtual void AnchorUpdated() OVERRIDE;
139 virtual string16 GetAccessibleNameForTray() OVERRIDE;
140 virtual void HideBubbleWithView(
141 const views::TrayBubbleView* bubble_view) OVERRIDE;
142 virtual bool ClickedOutsideBubble() OVERRIDE;
144 // Overridden from message_center::TrayBubbleView::Delegate.
145 virtual void BubbleViewDestroyed() OVERRIDE;
146 virtual void OnMouseEnteredView() OVERRIDE;
147 virtual void OnMouseExitedView() OVERRIDE;
148 virtual string16 GetAccessibleNameForBubble() OVERRIDE;
149 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget,
150 AnchorType anchor_type,
151 AnchorAlignment anchor_alignment) OVERRIDE;
152 virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE;
154 internal::TrayAccessibility* GetTrayAccessibilityForTest() {
155 return tray_accessibility_;
158 private:
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 // Calculates the x-offset for the item in the tray. Returns -1 if its tray
169 // item view is not visible.
170 int GetTrayXOffset(SystemTrayItem* item) const;
172 // Shows the default view and its arrow position is shifted by |x_offset|.
173 void ShowDefaultViewWithOffset(BubbleCreationType creation_type,
174 int x_offset);
176 // Constructs or re-constructs |system_bubble_| and populates it with |items|.
177 void ShowItems(const std::vector<SystemTrayItem*>& items,
178 bool details,
179 bool activate,
180 BubbleCreationType creation_type,
181 int x_offset);
183 // Constructs or re-constructs |notification_bubble_| and populates it with
184 // |notification_items_|, or destroys it if there are no notification items.
185 void UpdateNotificationBubble();
187 const ScopedVector<SystemTrayItem>& items() const { return items_; }
189 // Overridden from internal::ActionableView.
190 virtual bool PerformAction(const ui::Event& event) OVERRIDE;
192 // Owned items.
193 ScopedVector<SystemTrayItem> items_;
195 // Pointers to members of |items_|.
196 SystemTrayItem* detailed_item_;
197 std::vector<SystemTrayItem*> notification_items_;
199 // Mappings of system tray item and it's view in the tray.
200 std::map<SystemTrayItem*, views::View*> tray_item_map_;
202 // Bubble for default and detailed views.
203 scoped_ptr<internal::SystemBubbleWrapper> system_bubble_;
205 // Bubble for notifications.
206 scoped_ptr<internal::SystemBubbleWrapper> notification_bubble_;
208 // Keep track of the default view height so that when we create detailed
209 // views directly (e.g. from a notification) we know what height to use.
210 int default_bubble_height_;
212 // Set to true when system notifications should be hidden (e.g. web
213 // notification bubble is visible).
214 bool hide_notifications_;
216 internal::TrayAccessibility* tray_accessibility_; // not owned
218 DISALLOW_COPY_AND_ASSIGN(SystemTray);
221 } // namespace ash
223 #endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_