web_notification_tray.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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  PositionInfo GetPositionInfo();
89
90  void CreateStatusIcon(const gfx::ImageSkia& image,
91                        const base::string16& tool_tip);
92  void DestroyStatusIcon();
93  void AddQuietModeMenu(StatusIcon* status_icon);
94  MessageCenterWidgetDelegate* GetMessageCenterWidgetDelegateForTest();
95
96  MessageCenterWidgetDelegate* message_center_delegate_;
97  scoped_ptr<message_center::MessagePopupCollection> popup_collection_;
98
99  StatusIcon* status_icon_;
100  StatusIconMenuModel* status_icon_menu_;
101  bool message_center_visible_;
102  scoped_ptr<MessageCenterTray> message_center_tray_;
103  gfx::Point mouse_click_point_;
104
105  bool should_update_tray_content_;
106  bool last_quiet_mode_state_;
107
108  DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
109};
110
111}  // namespace message_center
112
113#endif  // CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_
114