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_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
6 #define ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
8 #include "ash/ash_export.h"
9 #include "ash/system/tray/tray_background_view.h"
10 #include "ash/system/user/login_status.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "ui/base/models/simple_menu_model.h"
15 #include "ui/message_center/message_center_tray.h"
16 #include "ui/message_center/message_center_tray_delegate.h"
17 #include "ui/views/bubble/tray_bubble_view.h"
18 #include "ui/views/controls/button/button.h"
20 // Status area tray for showing browser and app notifications. This hosts
21 // a MessageCenter class which manages the notification list. This class
22 // contains the Ash specific tray implementation.
24 // Note: These are not related to system notifications (i.e NotificationView
25 // generated by SystemTrayItem). Visibility of one notification type or other
26 // is controlled by StatusAreaWidget.
33 namespace message_center {
34 class MessageBubbleBase;
36 class MessageCenterBubble;
37 class MessagePopupCollection;
42 class StatusAreaWidget;
43 class WebNotificationBubbleWrapper;
44 class WebNotificationButton;
45 class WorkAreaObserver;
48 class ASH_EXPORT WebNotificationTray
49 : public internal::TrayBackgroundView,
50 public views::TrayBubbleView::Delegate,
51 public message_center::MessageCenterTrayDelegate,
52 public views::ButtonListener,
53 public base::SupportsWeakPtr<WebNotificationTray>,
54 public ui::SimpleMenuModel::Delegate {
56 explicit WebNotificationTray(
57 internal::StatusAreaWidget* status_area_widget);
58 virtual ~WebNotificationTray();
60 // Sets the height of the system tray from the edge of the work area so that
61 // the notification popups don't overlap with the tray. Passes 0 if no UI is
62 // shown in the system tray side.
63 void SetSystemTrayHeight(int height);
65 // Returns true if it should block the auto hide behavior of the launcher.
66 bool ShouldBlockLauncherAutoHide() const;
68 // Returns true if the message center bubble is visible.
69 bool IsMessageCenterBubbleVisible() const;
71 // Returns true if the mouse is inside the notification bubble.
72 bool IsMouseInNotificationBubble() const;
74 // Shows the message center bubble.
75 void ShowMessageCenterBubble();
77 // Overridden from TrayBackgroundView.
78 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
79 virtual void AnchorUpdated() OVERRIDE;
80 virtual base::string16 GetAccessibleNameForTray() OVERRIDE;
81 virtual void HideBubbleWithView(
82 const views::TrayBubbleView* bubble_view) OVERRIDE;
83 virtual bool ClickedOutsideBubble() OVERRIDE;
85 // Overridden from internal::ActionableView.
86 virtual bool PerformAction(const ui::Event& event) OVERRIDE;
88 // Overridden from views::TrayBubbleView::Delegate.
89 virtual void BubbleViewDestroyed() OVERRIDE;
90 virtual void OnMouseEnteredView() OVERRIDE;
91 virtual void OnMouseExitedView() OVERRIDE;
92 virtual base::string16 GetAccessibleNameForBubble() OVERRIDE;
93 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget,
94 AnchorType anchor_type,
95 AnchorAlignment anchor_alignment) OVERRIDE;
96 virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE;
98 // Overridden from ButtonListener.
99 virtual void ButtonPressed(views::Button* sender,
100 const ui::Event& event) OVERRIDE;
102 // Overridden from MessageCenterTrayDelegate.
103 virtual void OnMessageCenterTrayChanged() OVERRIDE;
104 virtual bool ShowMessageCenter() OVERRIDE;
105 virtual void HideMessageCenter() OVERRIDE;
106 virtual bool ShowPopups() OVERRIDE;
107 virtual void HidePopups() OVERRIDE;
108 virtual bool ShowNotifierSettings() OVERRIDE;
109 virtual message_center::MessageCenterTray* GetMessageCenterTray() OVERRIDE;
111 // Overridden from SimpleMenuModel::Delegate.
112 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
113 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
114 virtual bool GetAcceleratorForCommandId(
116 ui::Accelerator* accelerator) OVERRIDE;
117 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
119 message_center::MessageCenter* message_center() const;
122 friend class WebNotificationTrayTest;
124 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
125 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble);
126 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest,
127 ManyMessageCenterNotifications);
128 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications);
129 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupShownOnBothDisplays);
130 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndSystemTray);
131 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndAutoHideShelf);
133 void UpdateTrayContent();
135 // The actual process to show the message center. Set |show_settings| to true
136 // if the message center should be initialized with the settings visible.
137 // Returns true if the center is successfully created.
138 bool ShowMessageCenterInternal(bool show_settings);
140 // Queries login status and the status area widget to determine visibility of
141 // the message center.
142 bool ShouldShowMessageCenter();
144 // Returns true if it should show the quiet mode menu.
145 bool ShouldShowQuietModeMenu(const ui::Event& event);
147 // Shows the quiet mode menu.
148 void ShowQuietModeMenu(const ui::Event& event);
150 // Creates the menu model for quiet mode and returns it.
151 ui::MenuModel* CreateQuietModeMenu();
153 internal::WebNotificationBubbleWrapper* message_center_bubble() const {
154 return message_center_bubble_.get();
157 // Testing accessors.
158 bool IsPopupVisible() const;
159 message_center::MessageCenterBubble* GetMessageCenterBubbleForTest();
161 scoped_ptr<message_center::MessageCenterTray> message_center_tray_;
162 scoped_ptr<internal::WebNotificationBubbleWrapper> message_center_bubble_;
163 scoped_ptr<message_center::MessagePopupCollection> popup_collection_;
164 internal::WebNotificationButton* button_;
166 bool show_message_center_on_unlock_;
168 bool should_update_tray_content_;
170 // True when the shelf auto hide behavior has to be blocked. Previously
171 // this was done by checking |message_center_bubble_| but actually
172 // the check can be called when creating this object, so it would cause
173 // flickers of the shelf from hidden to shown. See: crbug.com/181213
174 bool should_block_shelf_auto_hide_;
176 // Observes the work area for |popup_collection_| and notifies to it.
177 scoped_ptr<internal::WorkAreaObserver> work_area_observer_;
179 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
184 #endif // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_