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