web_notification_tray.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 "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" 19 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. 23// 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. 27 28namespace views { 29class ImageButton; 30class MenuRunner; 31} 32 33namespace message_center { 34class MessageBubbleBase; 35class MessageCenter; 36class MessageCenterBubble; 37class MessagePopupCollection; 38} 39 40namespace ash { 41namespace internal { 42class StatusAreaWidget; 43class WebNotificationBubbleWrapper; 44class WebNotificationButton; 45class WorkAreaObserver; 46} 47 48class 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 { 55 public: 56 explicit WebNotificationTray( 57 internal::StatusAreaWidget* status_area_widget); 58 virtual ~WebNotificationTray(); 59 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); 64 65 // Returns true if it should block the auto hide behavior of the shelf. 66 bool ShouldBlockShelfAutoHide() const; 67 68 // Returns true if the message center bubble is visible. 69 bool IsMessageCenterBubbleVisible() const; 70 71 // Returns true if the mouse is inside the notification bubble. 72 bool IsMouseInNotificationBubble() const; 73 74 // Shows the message center bubble. 75 void ShowMessageCenterBubble(); 76 77 // Called when the login status is changed. 78 void UpdateAfterLoginStatusChange(user::LoginStatus login_status); 79 80 // Overridden from TrayBackgroundView. 81 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; 82 virtual void AnchorUpdated() OVERRIDE; 83 virtual base::string16 GetAccessibleNameForTray() OVERRIDE; 84 virtual void HideBubbleWithView( 85 const views::TrayBubbleView* bubble_view) OVERRIDE; 86 virtual bool ClickedOutsideBubble() OVERRIDE; 87 88 // Overridden from internal::ActionableView. 89 virtual bool PerformAction(const ui::Event& event) OVERRIDE; 90 91 // Overridden from views::TrayBubbleView::Delegate. 92 virtual void BubbleViewDestroyed() OVERRIDE; 93 virtual void OnMouseEnteredView() OVERRIDE; 94 virtual void OnMouseExitedView() OVERRIDE; 95 virtual base::string16 GetAccessibleNameForBubble() OVERRIDE; 96 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget, 97 AnchorType anchor_type, 98 AnchorAlignment anchor_alignment) OVERRIDE; 99 virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE; 100 101 // Overridden from ButtonListener. 102 virtual void ButtonPressed(views::Button* sender, 103 const ui::Event& event) OVERRIDE; 104 105 // Overridden from MessageCenterTrayDelegate. 106 virtual void OnMessageCenterTrayChanged() OVERRIDE; 107 virtual bool ShowMessageCenter() OVERRIDE; 108 virtual void HideMessageCenter() OVERRIDE; 109 virtual bool ShowPopups() OVERRIDE; 110 virtual void HidePopups() OVERRIDE; 111 virtual bool ShowNotifierSettings() OVERRIDE; 112 virtual bool IsContextMenuEnabled() const OVERRIDE; 113 virtual message_center::MessageCenterTray* GetMessageCenterTray() OVERRIDE; 114 115 // Overridden from SimpleMenuModel::Delegate. 116 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 117 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 118 virtual bool GetAcceleratorForCommandId( 119 int command_id, 120 ui::Accelerator* accelerator) OVERRIDE; 121 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 122 123 message_center::MessageCenter* message_center() const; 124 125 private: 126 friend class WebNotificationTrayTest; 127 128 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); 129 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble); 130 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, 131 ManyMessageCenterNotifications); 132 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications); 133 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupShownOnBothDisplays); 134 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndSystemTray); 135 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, PopupAndAutoHideShelf); 136 137 void UpdateTrayContent(); 138 139 // The actual process to show the message center. Set |show_settings| to true 140 // if the message center should be initialized with the settings visible. 141 // Returns true if the center is successfully created. 142 bool ShowMessageCenterInternal(bool show_settings); 143 144 // Queries login status and the status area widget to determine visibility of 145 // the message center. 146 bool ShouldShowMessageCenter(); 147 148 // Returns true if it should show the quiet mode menu. 149 bool ShouldShowQuietModeMenu(const ui::Event& event); 150 151 // Shows the quiet mode menu. 152 void ShowQuietModeMenu(const ui::Event& event); 153 154 // Creates the menu model for quiet mode and returns it. 155 ui::MenuModel* CreateQuietModeMenu(); 156 157 internal::WebNotificationBubbleWrapper* message_center_bubble() const { 158 return message_center_bubble_.get(); 159 } 160 161 // Testing accessors. 162 bool IsPopupVisible() const; 163 message_center::MessageCenterBubble* GetMessageCenterBubbleForTest(); 164 165 scoped_ptr<message_center::MessageCenterTray> message_center_tray_; 166 scoped_ptr<internal::WebNotificationBubbleWrapper> message_center_bubble_; 167 scoped_ptr<message_center::MessagePopupCollection> popup_collection_; 168 internal::WebNotificationButton* button_; 169 170 bool show_message_center_on_unlock_; 171 172 bool should_update_tray_content_; 173 174 // True when the shelf auto hide behavior has to be blocked. Previously 175 // this was done by checking |message_center_bubble_| but actually 176 // the check can be called when creating this object, so it would cause 177 // flickers of the shelf from hidden to shown. See: crbug.com/181213 178 bool should_block_shelf_auto_hide_; 179 180 // Observes the work area for |popup_collection_| and notifies to it. 181 scoped_ptr<internal::WorkAreaObserver> work_area_observer_; 182 183 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); 184}; 185 186} // namespace ash 187 188#endif // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ 189