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.
5 #include "chrome/browser/ui/views/message_center/web_notification_tray.h"
7 #include "chrome/browser/browser_process.h"
8 #include "ui/gfx/screen.h"
9 #include "ui/message_center/message_center_tray.h"
10 #include "ui/message_center/message_center_tray_delegate.h"
11 #include "ui/message_center/views/desktop_popup_alignment_delegate.h"
12 #include "ui/message_center/views/message_popup_collection.h"
14 namespace message_center
{
16 MessageCenterTrayDelegate
* CreateMessageCenterTray() {
17 return new WebNotificationTray();
20 WebNotificationTray::WebNotificationTray() {
21 message_center_tray_
.reset(
22 new MessageCenterTray(this, g_browser_process
->message_center()));
23 alignment_delegate_
.reset(new message_center::DesktopPopupAlignmentDelegate
);
24 popup_collection_
.reset(new message_center::MessagePopupCollection(
25 NULL
, message_center(), message_center_tray_
.get(),
26 alignment_delegate_
.get()));
29 WebNotificationTray::~WebNotificationTray() {
30 // Reset this early so that delegated events during destruction don't cause
32 popup_collection_
.reset();
33 message_center_tray_
.reset();
36 message_center::MessageCenter
* WebNotificationTray::message_center() {
37 return message_center_tray_
->message_center();
40 bool WebNotificationTray::ShowPopups() {
41 alignment_delegate_
->StartObserving(gfx::Screen::GetNativeScreen());
42 popup_collection_
->DoUpdateIfPossible();
46 void WebNotificationTray::HidePopups() {
47 DCHECK(popup_collection_
.get());
48 popup_collection_
->MarkAllPopupsShown();
51 bool WebNotificationTray::ShowMessageCenter() {
52 // Message center not available on Windows/Linux.
56 void WebNotificationTray::HideMessageCenter() {
59 bool WebNotificationTray::ShowNotifierSettings() {
60 // Message center settings not available on Windows/Linux.
64 bool WebNotificationTray::IsContextMenuEnabled() const {
65 // It can always return true because the notifications are invisible if
66 // the context menu shouldn't be enabled, such as in the lock screen.
70 void WebNotificationTray::OnMessageCenterTrayChanged() {
73 MessageCenterTray
* WebNotificationTray::GetMessageCenterTray() {
74 return message_center_tray_
.get();
77 } // namespace message_center