| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | |
| 6 #define ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "ash/ash_export.h" | |
| 11 #include "ash/common/login_status.h" | |
| 12 #include "ash/common/system/tray/tray_background_view.h" | |
| 13 #include "base/gtest_prod_util.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "ui/base/models/simple_menu_model.h" | |
| 17 #include "ui/message_center/message_center_tray.h" | |
| 18 #include "ui/message_center/message_center_tray_delegate.h" | |
| 19 #include "ui/views/bubble/tray_bubble_view.h" | |
| 20 #include "ui/views/controls/button/button.h" | |
| 21 | |
| 22 // Status area tray for showing browser and app notifications. This hosts | |
| 23 // a MessageCenter class which manages the notification list. This class | |
| 24 // contains the Ash specific tray implementation. | |
| 25 // | |
| 26 // Note: These are not related to system notifications (i.e NotificationView | |
| 27 // generated by SystemTrayItem). Visibility of one notification type or other | |
| 28 // is controlled by StatusAreaWidget. | |
| 29 | |
| 30 namespace views { | |
| 31 class ImageButton; | |
| 32 class MenuRunner; | |
| 33 } | |
| 34 | |
| 35 namespace message_center { | |
| 36 class MessageBubbleBase; | |
| 37 class MessageCenter; | |
| 38 class MessageCenterBubble; | |
| 39 class MessagePopupCollection; | |
| 40 } | |
| 41 | |
| 42 namespace ash { | |
| 43 class StatusAreaWidget; | |
| 44 class WebNotificationBubbleWrapper; | |
| 45 class WebNotificationButton; | |
| 46 class AshPopupAlignmentDelegate; | |
| 47 | |
| 48 class ASH_EXPORT WebNotificationTray | |
| 49 : public 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 { | |
| 55 public: | |
| 56 explicit WebNotificationTray(StatusAreaWidget* status_area_widget); | |
| 57 ~WebNotificationTray() override; | |
| 58 | |
| 59 // Sets the height of the system tray from the edge of the work area so that | |
| 60 // the notification popups don't overlap with the tray. Passes 0 if no UI is | |
| 61 // shown in the system tray side. | |
| 62 void SetSystemTrayHeight(int height); | |
| 63 | |
| 64 // Returns the current system tray height. | |
| 65 int system_tray_height_for_test() const; | |
| 66 | |
| 67 // Returns true if it should block the auto hide behavior of the shelf. | |
| 68 bool ShouldBlockShelfAutoHide() const; | |
| 69 | |
| 70 // Returns true if the message center bubble is visible. | |
| 71 bool IsMessageCenterBubbleVisible() const; | |
| 72 | |
| 73 // Returns true if the mouse is inside the notification bubble. | |
| 74 bool IsMouseInNotificationBubble() const; | |
| 75 | |
| 76 // Shows the message center bubble. | |
| 77 void ShowMessageCenterBubble(); | |
| 78 | |
| 79 // Called when the login status is changed. | |
| 80 void UpdateAfterLoginStatusChange(LoginStatus login_status); | |
| 81 | |
| 82 // Overridden from TrayBackgroundView. | |
| 83 void SetShelfAlignment(ShelfAlignment alignment) override; | |
| 84 void AnchorUpdated() override; | |
| 85 base::string16 GetAccessibleNameForTray() override; | |
| 86 void HideBubbleWithView(const views::TrayBubbleView* bubble_view) override; | |
| 87 void ClickedOutsideBubble() override; | |
| 88 | |
| 89 // Overridden from ActionableView. | |
| 90 bool PerformAction(const ui::Event& event) override; | |
| 91 | |
| 92 // Overridden from views::TrayBubbleView::Delegate. | |
| 93 void BubbleViewDestroyed() override; | |
| 94 void OnMouseEnteredView() override; | |
| 95 void OnMouseExitedView() override; | |
| 96 base::string16 GetAccessibleNameForBubble() override; | |
| 97 gfx::Rect GetAnchorRect(views::Widget* anchor_widget, | |
| 98 AnchorType anchor_type, | |
| 99 AnchorAlignment anchor_alignment) const override; | |
| 100 void OnBeforeBubbleWidgetInit( | |
| 101 views::Widget* anchor_widget, | |
| 102 views::Widget* bubble_widget, | |
| 103 views::Widget::InitParams* params) const override; | |
| 104 void HideBubble(const views::TrayBubbleView* bubble_view) override; | |
| 105 | |
| 106 // Overridden from ButtonListener. | |
| 107 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 108 | |
| 109 // Overridden from MessageCenterTrayDelegate. | |
| 110 void OnMessageCenterTrayChanged() override; | |
| 111 bool ShowMessageCenter() override; | |
| 112 void HideMessageCenter() override; | |
| 113 bool ShowPopups() override; | |
| 114 void HidePopups() override; | |
| 115 bool ShowNotifierSettings() override; | |
| 116 bool IsContextMenuEnabled() const override; | |
| 117 message_center::MessageCenterTray* GetMessageCenterTray() override; | |
| 118 | |
| 119 // Overridden from SimpleMenuModel::Delegate. | |
| 120 bool IsCommandIdChecked(int command_id) const override; | |
| 121 bool IsCommandIdEnabled(int command_id) const override; | |
| 122 bool GetAcceleratorForCommandId(int command_id, | |
| 123 ui::Accelerator* accelerator) override; | |
| 124 void ExecuteCommand(int command_id, int event_flags) override; | |
| 125 | |
| 126 message_center::MessageCenter* message_center() const; | |
| 127 | |
| 128 private: | |
| 129 friend class WebNotificationTrayTest; | |
| 130 | |
| 131 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); | |
| 132 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble); | |
| 133 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, | |
| 134 ManyMessageCenterNotifications); | |
| 135 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications); | |
| 136 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupShownOnBothDisplays); | |
| 137 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndSystemTray); | |
| 138 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndAutoHideShelf); | |
| 139 | |
| 140 void UpdateTrayContent(); | |
| 141 | |
| 142 // The actual process to show the message center. Set |show_settings| to true | |
| 143 // if the message center should be initialized with the settings visible. | |
| 144 // Returns true if the center is successfully created. | |
| 145 bool ShowMessageCenterInternal(bool show_settings); | |
| 146 | |
| 147 // Queries login status and the status area widget to determine visibility of | |
| 148 // the message center. | |
| 149 bool ShouldShowMessageCenter(); | |
| 150 | |
| 151 // Returns true if it should show the quiet mode menu. | |
| 152 bool ShouldShowQuietModeMenu(const ui::Event& event); | |
| 153 | |
| 154 // Shows the quiet mode menu. | |
| 155 void ShowQuietModeMenu(const ui::Event& event); | |
| 156 | |
| 157 // Creates the menu model for quiet mode and returns it. | |
| 158 ui::MenuModel* CreateQuietModeMenu(); | |
| 159 | |
| 160 WebNotificationBubbleWrapper* message_center_bubble() const { | |
| 161 return message_center_bubble_.get(); | |
| 162 } | |
| 163 | |
| 164 // Returns true if any user is logged in and the system is not at the screen | |
| 165 // for adding a secondary user. | |
| 166 bool IsLoggedIn() const; | |
| 167 | |
| 168 // Testing accessors. | |
| 169 bool IsPopupVisible() const; | |
| 170 message_center::MessageCenterBubble* GetMessageCenterBubbleForTest(); | |
| 171 | |
| 172 StatusAreaWidget* status_area_widget_; | |
| 173 std::unique_ptr<message_center::MessageCenterTray> message_center_tray_; | |
| 174 std::unique_ptr<WebNotificationBubbleWrapper> message_center_bubble_; | |
| 175 std::unique_ptr<message_center::MessagePopupCollection> popup_collection_; | |
| 176 WebNotificationButton* button_; | |
| 177 | |
| 178 bool show_message_center_on_unlock_; | |
| 179 | |
| 180 bool should_update_tray_content_; | |
| 181 | |
| 182 // True when the shelf auto hide behavior has to be blocked. Previously | |
| 183 // this was done by checking |message_center_bubble_| but actually | |
| 184 // the check can be called when creating this object, so it would cause | |
| 185 // flickers of the shelf from hidden to shown. See: crbug.com/181213 | |
| 186 bool should_block_shelf_auto_hide_; | |
| 187 | |
| 188 std::unique_ptr<AshPopupAlignmentDelegate> popup_alignment_delegate_; | |
| 189 | |
| 190 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); | |
| 191 }; | |
| 192 | |
| 193 } // namespace ash | |
| 194 | |
| 195 #endif // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | |
| OLD | NEW |