1 // Copyright (c) 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 "ui/message_center/message_center_tray.h"
7 #include "base/observer_list.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "grit/ui_strings.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/message_center/message_center.h"
12 #include "ui/message_center/message_center_tray_delegate.h"
13 #include "ui/message_center/message_center_types.h"
15 namespace message_center
{
17 MessageCenterTray::MessageCenterTray(
18 MessageCenterTrayDelegate
* delegate
,
19 message_center::MessageCenter
* message_center
)
20 : message_center_(message_center
),
21 message_center_visible_(false),
22 popups_visible_(false),
24 message_center_
->AddObserver(this);
27 MessageCenterTray::~MessageCenterTray() {
28 message_center_
->RemoveObserver(this);
31 bool MessageCenterTray::ShowMessageCenterBubble() {
32 if (message_center_visible_
)
35 HidePopupBubbleInternal();
37 message_center_visible_
= delegate_
->ShowMessageCenter();
38 message_center_
->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER
);
39 NotifyMessageCenterTrayChanged();
40 return message_center_visible_
;
43 bool MessageCenterTray::HideMessageCenterBubble() {
44 if (!message_center_visible_
)
46 delegate_
->HideMessageCenter();
47 MarkMessageCenterHidden();
51 void MessageCenterTray::MarkMessageCenterHidden() {
52 if (!message_center_visible_
)
54 message_center_visible_
= false;
56 // Some notifications (like system ones) should appear as popups again
57 // after the message center is closed.
58 if (message_center_
->HasPopupNotifications()) {
63 message_center_
->SetVisibility(message_center::VISIBILITY_TRANSIENT
);
65 NotifyMessageCenterTrayChanged();
68 void MessageCenterTray::ToggleMessageCenterBubble() {
69 if (message_center_visible_
)
70 HideMessageCenterBubble();
72 ShowMessageCenterBubble();
75 void MessageCenterTray::ShowPopupBubble() {
76 if (message_center_visible_
)
79 if (popups_visible_
) {
80 NotifyMessageCenterTrayChanged();
84 if (!message_center_
->HasPopupNotifications())
87 popups_visible_
= delegate_
->ShowPopups();
89 NotifyMessageCenterTrayChanged();
92 bool MessageCenterTray::HidePopupBubble() {
95 HidePopupBubbleInternal();
96 NotifyMessageCenterTrayChanged();
101 void MessageCenterTray::HidePopupBubbleInternal() {
102 if (!popups_visible_
)
105 delegate_
->HidePopups();
106 popups_visible_
= false;
109 void MessageCenterTray::ShowNotifierSettingsBubble() {
111 HidePopupBubbleInternal();
113 message_center_visible_
= delegate_
->ShowNotifierSettings();
114 message_center_
->SetVisibility(message_center::VISIBILITY_SETTINGS
);
116 NotifyMessageCenterTrayChanged();
119 void MessageCenterTray::OnNotificationAdded(
120 const std::string
& notification_id
) {
121 OnMessageCenterChanged();
124 void MessageCenterTray::OnNotificationRemoved(
125 const std::string
& notification_id
,
127 OnMessageCenterChanged();
130 void MessageCenterTray::OnNotificationUpdated(
131 const std::string
& notification_id
) {
132 OnMessageCenterChanged();
135 void MessageCenterTray::OnNotificationClicked(
136 const std::string
& notification_id
) {
138 OnMessageCenterChanged();
141 void MessageCenterTray::OnNotificationButtonClicked(
142 const std::string
& notification_id
,
145 OnMessageCenterChanged();
148 void MessageCenterTray::OnNotificationDisplayed(
149 const std::string
& notification_id
) {
150 NotifyMessageCenterTrayChanged();
153 void MessageCenterTray::OnQuietModeChanged(bool in_quiet_mode
) {
154 NotifyMessageCenterTrayChanged();
157 void MessageCenterTray::OnMessageCenterChanged() {
158 if (message_center_visible_
&& message_center_
->NotificationCount() == 0)
159 HideMessageCenterBubble();
161 if (popups_visible_
&& !message_center_
->HasPopupNotifications())
162 HidePopupBubbleInternal();
163 else if (!popups_visible_
&& message_center_
->HasPopupNotifications())
166 NotifyMessageCenterTrayChanged();
169 void MessageCenterTray::NotifyMessageCenterTrayChanged() {
170 delegate_
->OnMessageCenterTrayChanged();
173 } // namespace message_center