cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ash / system / web_notification / web_notification_tray.h
blobaf79b5368b4bc31810d69af9866bb7dafcecdbd5
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.
28 namespace views {
29 class ImageButton;
30 class MenuRunner;
33 namespace message_center {
34 class MessageBubbleBase;
35 class MessageCenter;
36 class MessageCenterBubble;
37 class MessagePopupCollection;
40 namespace ash {
41 class StatusAreaWidget;
42 class WebNotificationBubbleWrapper;
43 class WebNotificationButton;
44 class AshPopupAlignmentDelegate;
46 class ASH_EXPORT WebNotificationTray
47 : public TrayBackgroundView,
48 public views::TrayBubbleView::Delegate,
49 public message_center::MessageCenterTrayDelegate,
50 public views::ButtonListener,
51 public base::SupportsWeakPtr<WebNotificationTray>,
52 public ui::SimpleMenuModel::Delegate {
53 public:
54 explicit WebNotificationTray(StatusAreaWidget* status_area_widget);
55 ~WebNotificationTray() override;
57 // Sets the height of the system tray from the edge of the work area so that
58 // the notification popups don't overlap with the tray. Passes 0 if no UI is
59 // shown in the system tray side.
60 void SetSystemTrayHeight(int height);
62 // Returns true if it should block the auto hide behavior of the shelf.
63 bool ShouldBlockShelfAutoHide() const;
65 // Returns true if the message center bubble is visible.
66 bool IsMessageCenterBubbleVisible() const;
68 // Returns true if the mouse is inside the notification bubble.
69 bool IsMouseInNotificationBubble() const;
71 // Shows the message center bubble.
72 void ShowMessageCenterBubble();
74 // Called when the login status is changed.
75 void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
77 // Overridden from TrayBackgroundView.
78 void SetShelfAlignment(ShelfAlignment alignment) override;
79 void AnchorUpdated() override;
80 base::string16 GetAccessibleNameForTray() override;
81 void HideBubbleWithView(const views::TrayBubbleView* bubble_view) override;
82 bool ClickedOutsideBubble() override;
84 // Overridden from ActionableView.
85 bool PerformAction(const ui::Event& event) override;
87 // Overridden from views::TrayBubbleView::Delegate.
88 void BubbleViewDestroyed() override;
89 void OnMouseEnteredView() override;
90 void OnMouseExitedView() override;
91 base::string16 GetAccessibleNameForBubble() override;
92 gfx::Rect GetAnchorRect(views::Widget* anchor_widget,
93 AnchorType anchor_type,
94 AnchorAlignment anchor_alignment) const override;
95 void HideBubble(const views::TrayBubbleView* bubble_view) override;
97 // Overridden from ButtonListener.
98 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
100 // Overridden from MessageCenterTrayDelegate.
101 void OnMessageCenterTrayChanged() override;
102 bool ShowMessageCenter() override;
103 void HideMessageCenter() override;
104 bool ShowPopups() override;
105 void HidePopups() override;
106 bool ShowNotifierSettings() override;
107 bool IsContextMenuEnabled() const override;
108 message_center::MessageCenterTray* GetMessageCenterTray() override;
110 // Overridden from SimpleMenuModel::Delegate.
111 bool IsCommandIdChecked(int command_id) const override;
112 bool IsCommandIdEnabled(int command_id) const override;
113 bool GetAcceleratorForCommandId(int command_id,
114 ui::Accelerator* accelerator) override;
115 void ExecuteCommand(int command_id, int event_flags) override;
117 message_center::MessageCenter* message_center() const;
119 private:
120 friend class WebNotificationTrayTest;
122 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
123 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble);
124 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest,
125 ManyMessageCenterNotifications);
126 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications);
127 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupShownOnBothDisplays);
128 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndSystemTray);
129 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndAutoHideShelf);
131 void UpdateTrayContent();
133 // The actual process to show the message center. Set |show_settings| to true
134 // if the message center should be initialized with the settings visible.
135 // Returns true if the center is successfully created.
136 bool ShowMessageCenterInternal(bool show_settings);
138 // Queries login status and the status area widget to determine visibility of
139 // the message center.
140 bool ShouldShowMessageCenter();
142 // Returns true if it should show the quiet mode menu.
143 bool ShouldShowQuietModeMenu(const ui::Event& event);
145 // Shows the quiet mode menu.
146 void ShowQuietModeMenu(const ui::Event& event);
148 // Creates the menu model for quiet mode and returns it.
149 ui::MenuModel* CreateQuietModeMenu();
151 WebNotificationBubbleWrapper* message_center_bubble() const {
152 return message_center_bubble_.get();
155 // Testing accessors.
156 bool IsPopupVisible() const;
157 message_center::MessageCenterBubble* GetMessageCenterBubbleForTest();
159 scoped_ptr<message_center::MessageCenterTray> message_center_tray_;
160 scoped_ptr<WebNotificationBubbleWrapper> message_center_bubble_;
161 scoped_ptr<message_center::MessagePopupCollection> popup_collection_;
162 WebNotificationButton* button_;
164 bool show_message_center_on_unlock_;
166 bool should_update_tray_content_;
168 // True when the shelf auto hide behavior has to be blocked. Previously
169 // this was done by checking |message_center_bubble_| but actually
170 // the check can be called when creating this object, so it would cause
171 // flickers of the shelf from hidden to shown. See: crbug.com/181213
172 bool should_block_shelf_auto_hide_;
174 scoped_ptr<AshPopupAlignmentDelegate> popup_alignment_delegate_;
176 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
179 } // namespace ash
181 #endif // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_