1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_
#define CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_
#include "base/memory/weak_ptr.h"
#include "base/prefs/pref_member.h"
#include "chrome/browser/status_icons/status_icon_menu_model.h"
#include "chrome/browser/status_icons/status_icon_observer.h"
#include "chrome/browser/ui/views/message_center/message_center_widget_delegate.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/message_center/message_center_tray.h"
#include "ui/message_center/message_center_tray_delegate.h"
#include "ui/views/widget/widget_observer.h"
#if defined(OS_WIN)
#include "base/threading/thread.h"
#endif
class PrefService;
class StatusIcon;
namespace message_center {
class MessageCenter;
class MessagePopupCollection;
}
namespace views {
class Widget;
}
namespace message_center {
struct PositionInfo;
class DesktopPopupAlignmentDelegate;
class MessageCenterWidgetDelegate;
// A MessageCenterTrayDelegate implementation that exposes the MessageCenterTray
// via a system tray icon. The notification popups will be displayed in the
// corner of the screen and the message center will be displayed by the system
// tray icon on click.
class WebNotificationTray : public message_center::MessageCenterTrayDelegate,
public StatusIconObserver,
public base::SupportsWeakPtr<WebNotificationTray>,
public StatusIconMenuModel::Delegate {
public:
explicit WebNotificationTray(PrefService* local_state);
~WebNotificationTray() override;
message_center::MessageCenter* message_center();
// MessageCenterTrayDelegate implementation.
bool ShowPopups() override;
void HidePopups() override;
bool ShowMessageCenter() override;
void HideMessageCenter() override;
void OnMessageCenterTrayChanged() override;
bool ShowNotifierSettings() override;
bool IsContextMenuEnabled() const override;
// StatusIconObserver implementation.
void OnStatusIconClicked() override;
#if defined(OS_WIN)
virtual void OnBalloonClicked() override;
// This shows a platform-specific balloon informing the user of the existence
// of the message center in the status tray area.
void DisplayFirstRunBalloon();
void EnforceStatusIconVisible();
#endif
// StatusIconMenuModel::Delegate implementation.
void ExecuteCommand(int command_id, int event_flags) override;
// Changes the icon and hovertext based on number of unread notifications.
void UpdateStatusIcon();
void SendHideMessageCenter();
void MarkMessageCenterHidden();
// Gets the point where the status icon was clicked.
gfx::Point mouse_click_point() { return mouse_click_point_; }
MessageCenterTray* GetMessageCenterTray() override;
private:
FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble);
FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest,
ManyMessageCenterNotifications);
FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications);
FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManuallyCloseMessageCenter);
FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, StatusIconBehavior);
PositionInfo GetPositionInfo();
void CreateStatusIcon(const gfx::ImageSkia& image,
const base::string16& tool_tip);
void DestroyStatusIcon();
void AddQuietModeMenu(StatusIcon* status_icon);
MessageCenterWidgetDelegate* GetMessageCenterWidgetDelegateForTest();
#if defined(OS_WIN)
// This member variable keeps track of whether EnforceStatusIconVisible has
// been invoked on this machine, so the user still has control after we try
// promoting it the first time.
scoped_ptr<BooleanPrefMember> did_force_tray_visible_;
#endif
MessageCenterWidgetDelegate* message_center_delegate_;
scoped_ptr<message_center::MessagePopupCollection> popup_collection_;
scoped_ptr<message_center::DesktopPopupAlignmentDelegate> alignment_delegate_;
StatusIcon* status_icon_;
StatusIconMenuModel* status_icon_menu_;
scoped_ptr<MessageCenterTray> message_center_tray_;
gfx::Point mouse_click_point_;
bool should_update_tray_content_;
bool last_quiet_mode_state_;
base::string16 title_;
DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
};
} // namespace message_center
#endif // CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_
|