Disable accessible touch exploration by default.
[chromium-blink-merge.git] / ash / system / tray / system_tray.h
blob2df725daac7d7a614633c59cb7d3afc805a0c9e8
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 {
23 class SystemBubbleWrapper;
24 class SystemTrayDelegate;
25 class SystemTrayItem;
26 class TrayAccessibility;
27 class TrayDate;
28 class TrayUser;
30 // There are different methods for creating bubble views.
31 enum BubbleCreationType {
32 BUBBLE_CREATE_NEW, // Closes any existing bubble and creates a new one.
33 BUBBLE_USE_EXISTING, // Uses any existing bubble, or creates a new one.
36 class ASH_EXPORT SystemTray : public TrayBackgroundView,
37 public views::TrayBubbleView::Delegate {
38 public:
39 explicit SystemTray(StatusAreaWidget* status_area_widget);
40 virtual ~SystemTray();
42 // Calls TrayBackgroundView::Initialize(), creates the tray items, and
43 // adds them to SystemTrayNotifier.
44 void InitializeTrayItems(SystemTrayDelegate* delegate);
46 // Adds a new item in the tray.
47 void AddTrayItem(SystemTrayItem* item);
49 // Removes an existing tray item.
50 void RemoveTrayItem(SystemTrayItem* item);
52 // Returns all tray items that has been added to system tray.
53 const std::vector<SystemTrayItem*>& GetTrayItems() const;
55 // Shows the default view of all items.
56 void ShowDefaultView(BubbleCreationType creation_type);
58 // Shows default view that ingnores outside clicks and activation loss.
59 void ShowPersistentDefaultView();
61 // Shows details of a particular item. If |close_delay_in_seconds| is
62 // non-zero, then the view is automatically closed after the specified time.
63 void ShowDetailedView(SystemTrayItem* item,
64 int close_delay_in_seconds,
65 bool activate,
66 BubbleCreationType creation_type);
68 // Continue showing the existing detailed view, if any, for |close_delay|
69 // seconds.
70 void SetDetailedViewCloseDelay(int close_delay);
72 // Hides the detailed view for |item|.
73 void HideDetailedView(SystemTrayItem* item);
75 // Shows the notification view for |item|.
76 void ShowNotificationView(SystemTrayItem* item);
78 // Hides the notification view for |item|.
79 void HideNotificationView(SystemTrayItem* item);
81 // Updates the items when the login status of the system changes.
82 void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
84 // Updates the items when the shelf alignment changes.
85 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment);
87 // Temporarily hides/unhides the notification bubble.
88 void SetHideNotifications(bool hidden);
90 // Returns true if the shelf should be forced visible when auto-hidden.
91 bool ShouldShowShelf() const;
93 // Returns true if there is a system bubble (already visible or in the process
94 // of being created).
95 bool HasSystemBubble() const;
97 // Returns true if there is a notification bubble.
98 bool HasNotificationBubble() const;
100 // Returns true if the system_bubble_ exists and is of type |type|.
101 bool HasSystemBubbleType(SystemTrayBubble::BubbleType type);
103 // Returns a pointer to the system bubble or NULL if none.
104 SystemTrayBubble* GetSystemBubble();
106 // Returns true if any bubble is visible.
107 bool IsAnyBubbleVisible() const;
109 // Returns true if the mouse is inside the notification bubble.
110 bool IsMouseInNotificationBubble() const;
112 // Closes system bubble and returns true if it did exist.
113 bool CloseSystemBubble() const;
115 // Returns view for help button if default view is shown. Returns NULL
116 // otherwise.
117 views::View* GetHelpButtonView() const;
119 // Accessors for testing.
121 // Returns true if the bubble exists.
122 bool CloseNotificationBubbleForTest() const;
124 // Overridden from TrayBackgroundView.
125 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
126 virtual void AnchorUpdated() OVERRIDE;
127 virtual base::string16 GetAccessibleNameForTray() OVERRIDE;
128 virtual void BubbleResized(const views::TrayBubbleView* bubble_view) OVERRIDE;
129 virtual void HideBubbleWithView(
130 const views::TrayBubbleView* bubble_view) OVERRIDE;
131 virtual bool ClickedOutsideBubble() OVERRIDE;
133 // Overridden from message_center::TrayBubbleView::Delegate.
134 virtual void BubbleViewDestroyed() OVERRIDE;
135 virtual void OnMouseEnteredView() OVERRIDE;
136 virtual void OnMouseExitedView() OVERRIDE;
137 virtual base::string16 GetAccessibleNameForBubble() OVERRIDE;
138 virtual gfx::Rect GetAnchorRect(
139 views::Widget* anchor_widget,
140 AnchorType anchor_type,
141 AnchorAlignment anchor_alignment) const OVERRIDE;
142 virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE;
144 TrayAccessibility* GetTrayAccessibilityForTest() {
145 return tray_accessibility_;
148 // Get the tray item view (or NULL) for a given |tray_item| in a unit test.
149 views::View* GetTrayItemViewForTest(SystemTrayItem* tray_item);
151 // Gets tray_date_ for browser tests.
152 TrayDate* GetTrayDateForTesting() const;
154 private:
155 // Creates the default set of items for the sytem tray.
156 void CreateItems(SystemTrayDelegate* delegate);
158 // Resets |system_bubble_| and clears any related state.
159 void DestroySystemBubble();
161 // Resets |notification_bubble_| and clears any related state.
162 void DestroyNotificationBubble();
164 // Returns a string with the current time for accessibility on the status
165 // tray bar.
166 base::string16 GetAccessibleTimeString(const base::Time& now) const;
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,
175 bool persistent);
177 // Constructs or re-constructs |system_bubble_| and populates it with |items|.
178 // Specify |change_tray_status| to true if want to change the tray background
179 // status.
180 void ShowItems(const std::vector<SystemTrayItem*>& items,
181 bool details,
182 bool activate,
183 BubbleCreationType creation_type,
184 int x_offset,
185 bool persistent);
187 // Constructs or re-constructs |notification_bubble_| and populates it with
188 // |notification_items_|, or destroys it if there are no notification items.
189 void UpdateNotificationBubble();
191 // Checks the current status of the system tray and updates the web
192 // notification tray according to the current status.
193 void UpdateWebNotifications();
195 // Deactivate the system tray in the shelf if it was active before.
196 void CloseSystemBubbleAndDeactivateSystemTray();
198 const ScopedVector<SystemTrayItem>& items() const { return items_; }
200 // Overridden from ActionableView.
201 virtual bool PerformAction(const ui::Event& event) OVERRIDE;
203 // Owned items.
204 ScopedVector<SystemTrayItem> items_;
206 // Pointers to members of |items_|.
207 SystemTrayItem* detailed_item_;
208 std::vector<SystemTrayItem*> notification_items_;
210 // Mappings of system tray item and it's view in the tray.
211 std::map<SystemTrayItem*, views::View*> tray_item_map_;
213 // Bubble for default and detailed views.
214 scoped_ptr<SystemBubbleWrapper> system_bubble_;
216 // Bubble for notifications.
217 scoped_ptr<SystemBubbleWrapper> notification_bubble_;
219 // Keep track of the default view height so that when we create detailed
220 // views directly (e.g. from a notification) we know what height to use.
221 int default_bubble_height_;
223 // Set to true when system notifications should be hidden (e.g. web
224 // notification bubble is visible).
225 bool hide_notifications_;
227 // This is true when the displayed system tray menu is a full tray menu,
228 // otherwise a single line item menu like the volume slider is shown.
229 // Note that the value is only valid when |system_bubble_| is true.
230 bool full_system_tray_menu_;
232 TrayAccessibility* tray_accessibility_; // not owned
233 TrayDate* tray_date_;
235 DISALLOW_COPY_AND_ASSIGN(SystemTray);
238 } // namespace ash
240 #endif // ASH_SYSTEM_TRAY_SYSTEM_TRAY_H_