web_notification_tray.h revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
1// Copyright 2013 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 CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_ 6#define CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_ 7 8#include "base/memory/weak_ptr.h" 9#include "chrome/browser/status_icons/status_icon_menu_model.h" 10#include "chrome/browser/status_icons/status_icon_observer.h" 11#include "chrome/browser/ui/views/message_center/message_center_widget_delegate.h" 12#include "content/public/browser/notification_observer.h" 13#include "content/public/browser/notification_registrar.h" 14#include "ui/base/models/simple_menu_model.h" 15#include "ui/gfx/rect.h" 16#include "ui/message_center/message_center_tray.h" 17#include "ui/message_center/message_center_tray_delegate.h" 18#include "ui/views/widget/widget_observer.h" 19 20class StatusIcon; 21 22namespace message_center { 23class MessageCenter; 24class MessagePopupCollection; 25} 26 27namespace views { 28class Widget; 29} 30 31namespace message_center { 32 33struct PositionInfo; 34 35class MessageCenterWidgetDelegate; 36 37// A MessageCenterTrayDelegate implementation that exposes the MessageCenterTray 38// via a system tray icon. The notification popups will be displayed in the 39// corner of the screen and the message center will be displayed by the system 40// tray icon on click. 41class WebNotificationTray : public message_center::MessageCenterTrayDelegate, 42 public StatusIconObserver, 43 public base::SupportsWeakPtr<WebNotificationTray>, 44 public StatusIconMenuModel::Delegate { 45 public: 46 WebNotificationTray(); 47 virtual ~WebNotificationTray(); 48 49 message_center::MessageCenter* message_center(); 50 51 // MessageCenterTrayDelegate implementation. 52 virtual bool ShowPopups() OVERRIDE; 53 virtual void HidePopups() OVERRIDE; 54 virtual bool ShowMessageCenter() OVERRIDE; 55 virtual void HideMessageCenter() OVERRIDE; 56 virtual void OnMessageCenterTrayChanged() OVERRIDE; 57 virtual bool ShowNotifierSettings() OVERRIDE; 58 59 // StatusIconObserver implementation. 60 virtual void OnStatusIconClicked() OVERRIDE; 61#if defined(OS_WIN) 62 virtual void OnBalloonClicked() OVERRIDE; 63 64 // This shows a platform-specific balloon informing the user of the existence 65 // of the message center in the status tray area. 66 void DisplayFirstRunBalloon(); 67#endif 68 69 // StatusIconMenuModel::Delegate implementation. 70 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 71 72 // Changes the icon and hovertext based on number of unread notifications. 73 void UpdateStatusIcon(); 74 void SendHideMessageCenter(); 75 void MarkMessageCenterHidden(); 76 77 // Gets the point where the status icon was clicked. 78 gfx::Point mouse_click_point() { return mouse_click_point_; } 79 virtual MessageCenterTray* GetMessageCenterTray() OVERRIDE; 80 81 private: 82 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); 83 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble); 84 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, 85 ManyMessageCenterNotifications); 86 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications); 87 88 // The actual process to show the message center. Set |show_settings| to true 89 // if the message center should be initialized with the settings visible. 90 // Returns true if the center is successfully created. 91 bool ShowMessageCenterInternal(bool show_settings); 92 93 PositionInfo GetPositionInfo(); 94 95 void CreateStatusIcon(const gfx::ImageSkia& image, const string16& tool_tip); 96 void DestroyStatusIcon(); 97 void AddQuietModeMenu(StatusIcon* status_icon); 98 MessageCenterWidgetDelegate* GetMessageCenterWidgetDelegateForTest(); 99 100 MessageCenterWidgetDelegate* message_center_delegate_; 101 scoped_ptr<message_center::MessagePopupCollection> popup_collection_; 102 103 StatusIcon* status_icon_; 104 StatusIconMenuModel* status_icon_menu_; 105 bool message_center_visible_; 106 scoped_ptr<MessageCenterTray> message_center_tray_; 107 gfx::Point mouse_click_point_; 108 109 bool should_update_tray_content_; 110 bool last_quiet_mode_state_; 111 112 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); 113}; 114 115} // namespace message_center 116 117#endif // CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_ 118