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