Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / ash / system / tray / system_tray.h
blobb37a643205a5bf3e8b241a11e10f12b6d405da3b
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"
19 #include <map>
20 #include <vector>
22 namespace ash {
24 class AccessibilityObserver;
25 class AudioObserver;
26 class BluetoothObserver;
27 class BrightnessObserver;
28 class CapsLockObserver;
29 class ClockObserver;
30 class DriveObserver;
31 class IMEObserver;
32 class LocaleObserver;
33 class LogoutButtonObserver;
34 class SystemTrayDelegate;
35 class UpdateObserver;
36 class UserObserver;
37 #if defined(OS_CHROMEOS)
38 class NetworkObserver;
39 #endif
41 class SystemTrayItem;
43 namespace internal {
44 class SystemBubbleWrapper;
45 class SystemTrayContainer;
46 class TrayAccessibility;
47 class TrayGestureHandler;
50 // There are different methods for creating bubble views.
51 enum BubbleCreationType {
52 BUBBLE_CREATE_NEW, // Closes any existing bubble and creates a new one.
53 BUBBLE_USE_EXISTING, // Uses any existing bubble, or creates a new one.
56 class ASH_EXPORT SystemTray : public internal::TrayBackgroundView,
57 public views::TrayBubbleView::Delegate {
58 public:
59 explicit SystemTray(internal::StatusAreaWidget* status_area_widget);
60 virtual ~SystemTray();
62 // Calls TrayBackgroundView::Initialize(), creates the tray items, and
63 // adds them to SystemTrayNotifier.
64 void InitializeTrayItems(SystemTrayDelegate* delegate);
66 // Adds a new item in the tray.
67 void AddTrayItem(SystemTrayItem* item);
69 // Removes an existing tray item.
70 void RemoveTrayItem(SystemTrayItem* item);
72 // Returns all tray items that has been added to system tray.
73 const std::vector<SystemTrayItem*>& GetTrayItems() const;
75 // Shows the default view of all items.
76 void ShowDefaultView(BubbleCreationType creation_type);
78 // Shows details of a particular item. If |close_delay_in_seconds| is
79 // non-zero, then the view is automatically closed after the specified time.
80 void ShowDetailedView(SystemTrayItem* item,
81 int close_delay_in_seconds,
82 bool activate,
83 BubbleCreationType creation_type);
85 // Continue showing the existing detailed view, if any, for |close_delay|
86 // seconds.
87 void SetDetailedViewCloseDelay(int close_delay);
89 // Hides the detailed view for |item|.
90 void HideDetailedView(SystemTrayItem* item);
92 // Shows the notification view for |item|.
93 void ShowNotificationView(SystemTrayItem* item);
95 // Hides the notification view for |item|.
96 void HideNotificationView(SystemTrayItem* item);
98 // Updates the items when the login status of the system changes.
99 void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
101 // Updates the items when the shelf alignment changes.
102 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment);
104 // Temporarily hides/unhides the notification bubble.
105 void SetHideNotifications(bool hidden);
107 // Returns true if the launcher should be forced visible when auto-hidden.
108 bool ShouldShowLauncher() const;
110 // Returns true if there is a system bubble (already visible or in the process
111 // of being created).
112 bool HasSystemBubble() const;
114 // Returns true if there is a notification bubble.
115 bool HasNotificationBubble() const;
117 // Returns true if the system_bubble_ exists and is of type |type|.
118 bool HasSystemBubbleType(internal::SystemTrayBubble::BubbleType type);
120 // Returns a pointer to the system bubble or NULL if none.
121 internal::SystemTrayBubble* GetSystemBubble();
123 // Returns true if any bubble is visible.
124 bool IsAnyBubbleVisible() const;
126 // Returns true if the mouse is inside the notification bubble.
127 bool IsMouseInNotificationBubble() const;
129 // Closes system bubble and returns true if it did exist.
130 bool CloseSystemBubble() const;
132 // Accessors for testing.
134 // Returns true if the bubble exists.
135 bool CloseNotificationBubbleForTest() const;
137 // Overridden from TrayBackgroundView.
138 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
139 virtual void AnchorUpdated() OVERRIDE;
140 virtual base::string16 GetAccessibleNameForTray() OVERRIDE;
141 virtual void HideBubbleWithView(
142 const views::TrayBubbleView* bubble_view) OVERRIDE;
143 virtual bool ClickedOutsideBubble() OVERRIDE;
145 // Overridden from message_center::TrayBubbleView::Delegate.
146 virtual void BubbleViewDestroyed() OVERRIDE;
147 virtual void OnMouseEnteredView() OVERRIDE;
148 virtual void OnMouseExitedView() OVERRIDE;
149 virtual base::string16 GetAccessibleNameForBubble() OVERRIDE;
150 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget,
151 AnchorType anchor_type,
152 AnchorAlignment anchor_alignment) OVERRIDE;
153 virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE;
155 internal::TrayAccessibility* GetTrayAccessibilityForTest() {
156 return tray_accessibility_;
159 // Overridden from TrayBackgroundView.
160 virtual bool IsPressed() OVERRIDE;
162 private:
163 // Creates the default set of items for the sytem tray.
164 void CreateItems(SystemTrayDelegate* delegate);
166 // Resets |system_bubble_| and clears any related state.
167 void DestroySystemBubble();
169 // Resets |notification_bubble_| and clears any related state.
170 void DestroyNotificationBubble();
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,
178 int x_offset);
180 // Constructs or re-constructs |system_bubble_| and populates it with |items|.
181 // Specify |change_tray_status| to true if want to change the tray background
182 // status.
183 void ShowItems(const std::vector<SystemTrayItem*>& items,
184 bool details,
185 bool activate,
186 BubbleCreationType creation_type,
187 int x_offset);
189 // Constructs or re-constructs |notification_bubble_| and populates it with
190 // |notification_items_|, or destroys it if there are no notification items.
191 void UpdateNotificationBubble();
193 // Checks the current status of the system tray and updates the web
194 // notification tray according to the current status.
195 void UpdateWebNotifications();
197 const ScopedVector<SystemTrayItem>& items() const { return items_; }
199 // Overridden from internal::ActionableView.
200 virtual bool PerformAction(const ui::Event& event) OVERRIDE;
202 // Owned items.
203 ScopedVector<SystemTrayItem> items_;
205 // Pointers to members of |items_|.
206 SystemTrayItem* detailed_item_;
207 std::vector<SystemTrayItem*> notification_items_;
209 // Mappings of system tray item and it's view in the tray.
210 std::map<SystemTrayItem*, views::View*> tray_item_map_;
212 // Bubble for default and detailed views.
213 scoped_ptr<internal::SystemBubbleWrapper> system_bubble_;
215 // Bubble for notifications.
216 scoped_ptr<internal::SystemBubbleWrapper> notification_bubble_;
218 // 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.
220 int default_bubble_height_;
222 // Set to true when system notifications should be hidden (e.g. web
223 // notification bubble is visible).
224 bool hide_notifications_;
226 // 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.
228 // Note that the value is only valid when |system_bubble_| is true.
229 bool full_system_tray_menu_;
231 internal::TrayAccessibility* tray_accessibility_; // not owned
233 DISALLOW_COPY_AND_ASSIGN(SystemTray);
236 } // namespace ash
238 #endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_