OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/web_notification/web_notification_tray.h" | 5 #include "ash/system/web_notification/web_notification_tray.h" |
6 | 6 |
| 7 #include "ash/root_window_controller.h" |
7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
9 #include "ash/system/status_area_widget.h" | 10 #include "ash/system/status_area_widget.h" |
| 11 #include "ash/system/tray/tray_background_view.h" |
10 #include "ash/system/tray/tray_bubble_wrapper.h" | 12 #include "ash/system/tray/tray_bubble_wrapper.h" |
11 #include "ash/system/tray/tray_constants.h" | |
12 #include "ash/system/tray/tray_views.h" | |
13 #include "ash/wm/shelf_layout_manager.h" | 13 #include "ash/wm/shelf_layout_manager.h" |
14 #include "base/message_loop.h" | |
15 #include "base/stringprintf.h" | |
16 #include "grit/ash_resources.h" | 14 #include "grit/ash_resources.h" |
17 #include "grit/ash_strings.h" | 15 #include "grit/ash_strings.h" |
18 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
19 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 20 #include "ui/message_center/message_bubble_base.h" |
22 #include "ui/message_center/message_center_bubble.h" | 21 #include "ui/message_center/message_center_bubble.h" |
| 22 #include "ui/message_center/message_center_tray_delegate.h" |
23 #include "ui/message_center/message_popup_bubble.h" | 23 #include "ui/message_center/message_popup_bubble.h" |
24 #include "ui/message_center/quiet_mode_bubble.h" | 24 #include "ui/message_center/quiet_mode_bubble.h" |
25 #include "ui/views/bubble/tray_bubble_view.h" | 25 #include "ui/views/bubble/tray_bubble_view.h" |
26 #include "ui/views/widget/widget_observer.h" | 26 #include "ui/views/widget/widget_observer.h" |
27 | 27 |
28 namespace { | 28 #if defined(OS_CHROMEOS) |
29 | 29 |
30 // Tray constants | 30 namespace message_center { |
31 const int kTrayContainerVerticalPaddingBottomAlignment = 3; | |
32 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; | |
33 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; | |
34 const int kTrayContainerHorizontalPaddingVerticalAlignment = 0; | |
35 const int kPaddingFromLeftEdgeOfSystemTrayBottomAlignment = 8; | |
36 const int kPaddingFromTopEdgeOfSystemTrayVerticalAlignment = 10; | |
37 | 31 |
38 } // namespace | 32 MessageCenterTrayDelegate* CreateMessageCenterTray() { |
| 33 // On Windows+Ash the Tray will not be hosted in ash::Shell. |
| 34 NOTREACHED(); |
| 35 return NULL; |
| 36 } |
| 37 |
| 38 } // namespace message_center |
| 39 |
| 40 #endif // defined(OS_CHROMEOS) |
39 | 41 |
40 namespace ash { | 42 namespace ash { |
41 | 43 |
42 namespace internal { | 44 namespace internal { |
43 | 45 |
44 // Class to initialize and manage the WebNotificationBubble and | 46 // Class to initialize and manage the WebNotificationBubble and |
45 // TrayBubbleWrapper instances for a bubble. | 47 // TrayBubbleWrapper instances for a bubble. |
46 | 48 |
47 class WebNotificationBubbleWrapper { | 49 class WebNotificationBubbleWrapper { |
48 public: | 50 public: |
(...skipping 14 matching lines...) Expand all Loading... |
63 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( | 65 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( |
64 tray->GetBubbleWindowContainer(), anchor, tray, &init_params); | 66 tray->GetBubbleWindowContainer(), anchor, tray, &init_params); |
65 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); | 67 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); |
66 bubble->InitializeContents(bubble_view); | 68 bubble->InitializeContents(bubble_view); |
67 } | 69 } |
68 | 70 |
69 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } | 71 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } |
70 | 72 |
71 // Convenience accessors. | 73 // Convenience accessors. |
72 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } | 74 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } |
| 75 views::Widget* bubble_widget() const { |
| 76 return bubble_wrapper_->bubble_widget(); |
| 77 } |
73 | 78 |
74 private: | 79 private: |
75 scoped_ptr<message_center::MessageBubbleBase> bubble_; | 80 scoped_ptr<message_center::MessageBubbleBase> bubble_; |
76 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; | 81 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; |
77 }; | 82 }; |
78 | 83 |
79 } // namespace internal | 84 } // namespace internal |
80 | 85 |
81 WebNotificationTray::WebNotificationTray( | 86 WebNotificationTray::WebNotificationTray( |
82 internal::StatusAreaWidget* status_area_widget) | 87 internal::StatusAreaWidget* status_area_widget) |
83 : internal::TrayBackgroundView(status_area_widget), | 88 : TrayBackgroundView(status_area_widget), |
84 button_(NULL), | 89 button_(NULL), |
85 show_message_center_on_unlock_(false) { | 90 show_message_center_on_unlock_(false) { |
86 message_center_ = ash::Shell::GetInstance()->message_center(); | |
87 message_center_->AddObserver(this); | |
88 button_ = new views::ImageButton(this); | 91 button_ = new views::ImageButton(this); |
89 button_->set_triggerable_event_flags( | 92 button_->set_triggerable_event_flags( |
90 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); | 93 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); |
91 tray_container()->AddChildView(button_); | 94 tray_container()->AddChildView(button_); |
92 SetVisible(false); | 95 SetVisible(false); |
93 UpdateTray(); | 96 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 97 this, |
| 98 Shell::GetInstance()->message_center())); |
| 99 OnMessageCenterTrayChanged(); |
94 } | 100 } |
95 | 101 |
96 WebNotificationTray::~WebNotificationTray() { | 102 WebNotificationTray::~WebNotificationTray() { |
97 // Ensure the message center doesn't notify an object under destruction. | |
98 message_center_->RemoveObserver(this); | |
99 // Release any child views that might have back pointers before ~View(). | 103 // Release any child views that might have back pointers before ~View(). |
100 message_center_bubble_.reset(); | 104 message_center_bubble_.reset(); |
101 popup_bubble_.reset(); | 105 popup_bubble_.reset(); |
102 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) | 106 if (quiet_mode_bubble() && quiet_mode_bubble()->GetBubbleWidget()) |
103 quiet_mode_bubble_->GetBubbleWidget()->RemoveObserver(this); | 107 quiet_mode_bubble()->GetBubbleWidget()->RemoveObserver(this); |
104 quiet_mode_bubble_.reset(); | 108 quiet_mode_bubble_.reset(); |
105 } | 109 } |
106 | 110 |
107 void WebNotificationTray::ShowMessageCenterBubble() { | 111 // Public methods. |
108 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 112 |
109 return; | 113 bool WebNotificationTray::ShowMessageCenter() { |
110 if (quiet_mode_bubble()) | 114 if (!ShouldShowMessageCenter()) |
111 quiet_mode_bubble_.reset(); | 115 return false; |
112 if (message_center_bubble()) { | 116 |
113 UpdateTray(); | 117 message_center::MessageCenterBubble* message_center_bubble = |
114 return; | 118 new message_center::MessageCenterBubble(message_center()); |
115 } | 119 |
116 // Indicate that the message center is visible. Clears the unread count. | |
117 message_center_->SetMessageCenterVisible(true); | |
118 UpdateTray(); | |
119 HidePopupBubble(); | |
120 message_center::MessageCenterBubble* bubble = | |
121 new message_center::MessageCenterBubble(message_center_); | |
122 // Sets the maximum height of the bubble based on the screen. | |
123 // TODO(mukai): move this to WebNotificationBubbleWrapper if it's safe | 120 // TODO(mukai): move this to WebNotificationBubbleWrapper if it's safe |
124 // to set the height of the popup. | 121 // to set the height of the popup. |
125 int max_height = 0; | 122 int max_height = 0; |
126 if (GetShelfLayoutManager()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 123 if (GetShelfLayoutManager()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
127 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); | 124 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); |
128 max_height = shelf_bounds.y(); | 125 max_height = shelf_bounds.y(); |
129 } else { | 126 } else { |
130 // Assume that the bottom line of the status area widget and the bubble are | 127 // Assume that the bottom line of the status area widget and the bubble are |
131 // aligned. | 128 // aligned. |
132 aura::Window* status_area_window = status_area_widget()->GetNativeWindow(); | 129 aura::Window* status_area_window = status_area_widget()->GetNativeWindow(); |
133 max_height = status_area_window->GetBoundsInRootWindow().bottom(); | 130 max_height = status_area_window->GetBoundsInRootWindow().bottom(); |
134 } | 131 } |
135 bubble->SetMaxHeight(max_height); | 132 message_center_bubble->SetMaxHeight(max_height); |
136 message_center_bubble_.reset( | 133 message_center_bubble_.reset( |
137 new internal::WebNotificationBubbleWrapper(this, bubble)); | 134 new internal::WebNotificationBubbleWrapper(this, message_center_bubble)); |
138 | 135 |
139 status_area_widget()->SetHideSystemNotifications(true); | 136 status_area_widget()->SetHideSystemNotifications(true); |
140 GetShelfLayoutManager()->UpdateAutoHideState(); | 137 GetShelfLayoutManager()->UpdateAutoHideState(); |
| 138 return true; |
141 } | 139 } |
142 | 140 |
143 void WebNotificationTray::HideMessageCenterBubble() { | 141 void WebNotificationTray::UpdateMessageCenter() { |
| 142 if (message_center_bubble()) |
| 143 message_center_bubble()->bubble()->ScheduleUpdate(); |
| 144 } |
| 145 |
| 146 void WebNotificationTray::HideMessageCenter() { |
144 if (!message_center_bubble()) | 147 if (!message_center_bubble()) |
145 return; | 148 return; |
146 message_center_bubble_.reset(); | 149 message_center_bubble_.reset(); |
147 show_message_center_on_unlock_ = false; | 150 show_message_center_on_unlock_ = false; |
148 message_center_->SetMessageCenterVisible(false); | |
149 UpdateTray(); | |
150 status_area_widget()->SetHideSystemNotifications(false); | 151 status_area_widget()->SetHideSystemNotifications(false); |
151 GetShelfLayoutManager()->UpdateAutoHideState(); | 152 GetShelfLayoutManager()->UpdateAutoHideState(); |
152 } | 153 } |
153 | 154 |
154 void WebNotificationTray::SetHidePopupBubble(bool hide) { | 155 void WebNotificationTray::SetHidePopupBubble(bool hide) { |
155 if (hide) | 156 if (hide) |
156 HidePopupBubble(); | 157 message_center_tray_->HidePopupBubble(); |
157 else | 158 else |
158 ShowPopupBubble(); | 159 message_center_tray_->ShowPopupBubble(); |
159 } | 160 } |
160 | 161 |
161 void WebNotificationTray::ShowPopupBubble() { | 162 bool WebNotificationTray::ShowPopups() { |
162 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 163 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED || |
163 return; | 164 message_center_bubble() || |
164 if (message_center_bubble()) | 165 !status_area_widget()->ShouldShowWebNotifications()) { |
165 return; | 166 return false; |
166 if (!status_area_widget()->ShouldShowWebNotifications()) | |
167 return; | |
168 UpdateTray(); | |
169 if (popup_bubble()) { | |
170 popup_bubble()->bubble()->ScheduleUpdate(); | |
171 } else if (message_center_->HasPopupNotifications()) { | |
172 popup_bubble_.reset( | |
173 new internal::WebNotificationBubbleWrapper( | |
174 this, new message_center::MessagePopupBubble(message_center_))); | |
175 } | 167 } |
| 168 message_center::MessagePopupBubble* popup_bubble = |
| 169 new message_center::MessagePopupBubble(message_center()); |
| 170 popup_bubble_.reset(new internal::WebNotificationBubbleWrapper( |
| 171 this, popup_bubble)); |
| 172 return true; |
176 } | 173 } |
177 | 174 |
178 void WebNotificationTray::HidePopupBubble() { | 175 void WebNotificationTray::UpdatePopups() { |
| 176 if (popup_bubble()) |
| 177 popup_bubble()->bubble()->ScheduleUpdate(); |
| 178 }; |
| 179 |
| 180 void WebNotificationTray::HidePopups() { |
179 popup_bubble_.reset(); | 181 popup_bubble_.reset(); |
180 } | 182 } |
181 | 183 |
| 184 // Private methods. |
| 185 |
| 186 bool WebNotificationTray::ShouldShowMessageCenter() { |
| 187 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && |
| 188 status_area_widget()->ShouldShowWebNotifications(); |
| 189 } |
| 190 |
182 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { | 191 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { |
183 // TODO(mukai): Add keyboard event handler. | 192 // TODO(mukai): Add keyboard event handler. |
184 if (!event.IsMouseEvent()) | 193 if (!event.IsMouseEvent()) |
185 return false; | 194 return false; |
186 | 195 |
187 const ui::MouseEvent* mouse_event = | 196 const ui::MouseEvent* mouse_event = |
188 static_cast<const ui::MouseEvent*>(&event); | 197 static_cast<const ui::MouseEvent*>(&event); |
189 | 198 |
190 return mouse_event->IsRightMouseButton(); | 199 return mouse_event->IsRightMouseButton(); |
191 } | 200 } |
192 | 201 |
193 void WebNotificationTray::ShowQuietModeBubble() { | 202 void WebNotificationTray::ShowQuietModeBubble() { |
194 aura::Window* parent = Shell::GetContainer( | 203 aura::Window* parent = Shell::GetContainer( |
195 Shell::GetPrimaryRootWindow(), | 204 Shell::GetPrimaryRootWindow(), |
196 internal::kShellWindowId_SettingBubbleContainer); | 205 internal::kShellWindowId_SettingBubbleContainer); |
197 quiet_mode_bubble_.reset(new message_center::QuietModeBubble( | 206 quiet_mode_bubble_.reset(new message_center::QuietModeBubble( |
198 button_, parent, message_center_->notification_list())); | 207 button_, |
199 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); | 208 parent, |
200 quiet_mode_bubble_->GetBubbleWidget()->AddObserver(this); | 209 message_center_tray_->message_center()->notification_list())); |
| 210 quiet_mode_bubble()->GetBubbleWidget()->StackAtTop(); |
| 211 quiet_mode_bubble()->GetBubbleWidget()->AddObserver(this); |
201 } | 212 } |
202 | 213 |
203 void WebNotificationTray::UpdateAfterLoginStatusChange( | 214 void WebNotificationTray::UpdateAfterLoginStatusChange( |
204 user::LoginStatus login_status) { | 215 user::LoginStatus login_status) { |
205 if (login_status == user::LOGGED_IN_LOCKED) { | |
206 if (message_center_bubble()) { | |
207 message_center_bubble_.reset(); | |
208 show_message_center_on_unlock_ = true; | |
209 } | |
210 HidePopupBubble(); | |
211 } else { | |
212 if (show_message_center_on_unlock_) | |
213 ShowMessageCenterBubble(); | |
214 show_message_center_on_unlock_ = false; | |
215 } | |
216 // The status icon should be always visible except for lock screen / login | 216 // The status icon should be always visible except for lock screen / login |
217 // screen, to allow quiet mode and settings. | 217 // screen, to allow quiet mode and settings. |
218 SetVisible((login_status != user::LOGGED_IN_NONE) && | 218 SetVisible((login_status != user::LOGGED_IN_NONE) && |
219 (login_status != user::LOGGED_IN_LOCKED)); | 219 (login_status != user::LOGGED_IN_LOCKED)); |
220 UpdateTray(); | 220 |
| 221 if (login_status == user::LOGGED_IN_LOCKED) { |
| 222 show_message_center_on_unlock_ = |
| 223 message_center_tray_->HideMessageCenterBubble(); |
| 224 message_center_tray_->HidePopupBubble(); |
| 225 } else { |
| 226 // Only try once to show the message center bubble on login status change, |
| 227 // so always set |show_message_center_on_unlock_| to false. |
| 228 if (show_message_center_on_unlock_) |
| 229 message_center_tray_->ShowMessageCenterBubble(); |
| 230 show_message_center_on_unlock_ = false; |
| 231 } |
221 } | 232 } |
222 | 233 |
223 bool WebNotificationTray::ShouldBlockLauncherAutoHide() const { | 234 bool WebNotificationTray::ShouldBlockLauncherAutoHide() const { |
224 return IsMessageCenterBubbleVisible() || quiet_mode_bubble() != NULL; | 235 return IsMessageCenterBubbleVisible() || quiet_mode_bubble() != NULL; |
225 } | 236 } |
226 | 237 |
227 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { | 238 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { |
228 return (message_center_bubble() && | 239 return (message_center_bubble() && |
229 message_center_bubble_->bubble()->IsVisible()); | 240 message_center_bubble()->bubble()->IsVisible()); |
230 } | 241 } |
231 | 242 |
232 bool WebNotificationTray::IsMouseInNotificationBubble() const { | 243 bool WebNotificationTray::IsMouseInNotificationBubble() const { |
233 if (!popup_bubble()) | 244 if (!popup_bubble()) |
234 return false; | 245 return false; |
235 return popup_bubble_->bubble_view()->GetBoundsInScreen().Contains( | 246 return popup_bubble()->bubble_view()->GetBoundsInScreen().Contains( |
236 Shell::GetScreen()->GetCursorScreenPoint()); | 247 Shell::GetScreen()->GetCursorScreenPoint()); |
237 } | 248 } |
238 | 249 |
239 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { | 250 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { |
240 if (alignment == shelf_alignment()) | 251 if (alignment == shelf_alignment()) |
241 return; | 252 return; |
242 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 253 internal::TrayBackgroundView::SetShelfAlignment(alignment); |
243 // Destroy any existing bubble so that it will be rebuilt correctly. | 254 // Destroy any existing bubble so that it will be rebuilt correctly. |
244 HideMessageCenterBubble(); | 255 message_center_tray_->HideMessageCenterBubble(); |
245 HidePopupBubble(); | 256 message_center_tray_->HidePopupBubble(); |
246 } | 257 } |
247 | 258 |
248 void WebNotificationTray::AnchorUpdated() { | 259 void WebNotificationTray::AnchorUpdated() { |
249 if (popup_bubble_.get()) { | 260 if (popup_bubble()) { |
250 popup_bubble_->bubble_view()->UpdateBubble(); | 261 popup_bubble()->bubble_view()->UpdateBubble(); |
251 // Ensure that the notification buble is above the launcher/status area. | 262 // Ensure that the notification buble is above the launcher/status area. |
252 popup_bubble_->bubble_view()->GetWidget()->StackAtTop(); | 263 popup_bubble()->bubble_view()->GetWidget()->StackAtTop(); |
253 UpdateBubbleViewArrow(popup_bubble_->bubble_view()); | 264 UpdateBubbleViewArrow(popup_bubble()->bubble_view()); |
254 } | 265 } |
255 if (message_center_bubble_.get()) { | 266 if (message_center_bubble()) { |
256 message_center_bubble_->bubble_view()->UpdateBubble(); | 267 message_center_bubble()->bubble_view()->UpdateBubble(); |
257 UpdateBubbleViewArrow(message_center_bubble_->bubble_view()); | 268 UpdateBubbleViewArrow(message_center_bubble()->bubble_view()); |
258 } | 269 } |
259 // Quiet mode settings bubble has to be on top. | 270 // Quiet mode settings bubble has to be on top. |
260 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) | 271 if (quiet_mode_bubble() && quiet_mode_bubble()->GetBubbleWidget()) |
261 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); | 272 quiet_mode_bubble()->GetBubbleWidget()->StackAtTop(); |
262 } | 273 } |
263 | 274 |
264 string16 WebNotificationTray::GetAccessibleNameForTray() { | 275 string16 WebNotificationTray::GetAccessibleNameForTray() { |
265 return l10n_util::GetStringUTF16( | 276 return l10n_util::GetStringUTF16( |
266 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); | 277 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); |
267 } | 278 } |
268 | 279 |
269 void WebNotificationTray::HideBubbleWithView( | 280 void WebNotificationTray::HideBubbleWithView( |
270 const views::TrayBubbleView* bubble_view) { | 281 const views::TrayBubbleView* bubble_view) { |
271 if (message_center_bubble() && | 282 if (message_center_bubble() && |
272 bubble_view == message_center_bubble()->bubble_view()) { | 283 bubble_view == message_center_bubble()->bubble_view()) { |
273 HideMessageCenterBubble(); | 284 message_center_tray_->HideMessageCenterBubble(); |
274 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { | 285 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { |
275 HidePopupBubble(); | 286 message_center_tray_->HidePopupBubble(); |
276 } | 287 } |
277 } | 288 } |
278 | 289 |
279 bool WebNotificationTray::PerformAction(const ui::Event& event) { | 290 bool WebNotificationTray::PerformAction(const ui::Event& event) { |
280 if (!quiet_mode_bubble() && ShouldShowQuietModeBubble(event)) { | 291 if (!quiet_mode_bubble() && ShouldShowQuietModeBubble(event)) { |
281 ShowQuietModeBubble(); | 292 ShowQuietModeBubble(); |
282 return true; | 293 return true; |
283 } | 294 } |
284 quiet_mode_bubble_.reset(); | 295 quiet_mode_bubble_.reset(); |
285 ToggleMessageCenterBubble(); | 296 if (message_center_bubble()) |
| 297 message_center_tray_->HideMessageCenterBubble(); |
| 298 else |
| 299 message_center_tray_->ShowMessageCenterBubble(); |
286 return true; | 300 return true; |
287 } | 301 } |
288 | 302 |
289 void WebNotificationTray::BubbleViewDestroyed() { | 303 void WebNotificationTray::BubbleViewDestroyed() { |
290 if (message_center_bubble()) | 304 if (message_center_bubble()) |
291 message_center_bubble()->bubble()->BubbleViewDestroyed(); | 305 message_center_bubble()->bubble()->BubbleViewDestroyed(); |
292 if (popup_bubble()) | 306 if (popup_bubble()) |
293 popup_bubble()->bubble()->BubbleViewDestroyed(); | 307 popup_bubble()->bubble()->BubbleViewDestroyed(); |
294 } | 308 } |
295 | 309 |
296 void WebNotificationTray::OnMouseEnteredView() { | 310 void WebNotificationTray::OnMouseEnteredView() { |
297 if (popup_bubble()) | 311 if (popup_bubble()) |
298 popup_bubble()->bubble()->OnMouseEnteredView(); | 312 popup_bubble()->bubble()->OnMouseEnteredView(); |
299 } | 313 } |
300 | 314 |
301 void WebNotificationTray::OnMouseExitedView() { | 315 void WebNotificationTray::OnMouseExitedView() { |
302 if (popup_bubble()) | 316 if (popup_bubble()) |
303 popup_bubble()->bubble()->OnMouseExitedView(); | 317 popup_bubble()->bubble()->OnMouseExitedView(); |
304 } | 318 } |
305 | 319 |
306 string16 WebNotificationTray::GetAccessibleNameForBubble() { | 320 string16 WebNotificationTray::GetAccessibleNameForBubble() { |
307 return GetAccessibleNameForTray(); | 321 return GetAccessibleNameForTray(); |
308 } | 322 } |
309 | 323 |
310 gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget, | 324 gfx::Rect WebNotificationTray::GetAnchorRect( |
311 AnchorType anchor_type, | 325 views::Widget* anchor_widget, |
312 AnchorAlignment anchor_alignment) { | 326 views::TrayBubbleView::AnchorType anchor_type, |
| 327 views::TrayBubbleView::AnchorAlignment anchor_alignment) { |
313 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); | 328 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); |
314 } | 329 } |
315 | 330 |
316 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { | 331 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
317 HideBubbleWithView(bubble_view); | 332 HideBubbleWithView(bubble_view); |
318 } | 333 } |
319 | 334 |
320 void WebNotificationTray::OnMessageCenterChanged(bool new_notification) { | |
321 if (message_center_bubble()) { | |
322 if (message_center_->NotificationCount() == 0) | |
323 HideMessageCenterBubble(); | |
324 else | |
325 message_center_bubble()->bubble()->ScheduleUpdate(); | |
326 } | |
327 if (popup_bubble()) { | |
328 if (message_center_->NotificationCount() == 0) | |
329 HidePopupBubble(); | |
330 else | |
331 popup_bubble()->bubble()->ScheduleUpdate(); | |
332 } | |
333 UpdateTray(); | |
334 if (new_notification) | |
335 ShowPopupBubble(); | |
336 } | |
337 | |
338 void WebNotificationTray::ButtonPressed(views::Button* sender, | 335 void WebNotificationTray::ButtonPressed(views::Button* sender, |
339 const ui::Event& event) { | 336 const ui::Event& event) { |
340 DCHECK_EQ(button_, sender); | 337 DCHECK_EQ(button_, sender); |
341 PerformAction(event); | 338 PerformAction(event); |
342 } | 339 } |
343 | 340 |
344 void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { | 341 void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { |
345 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget() == widget) { | 342 if (quiet_mode_bubble() && quiet_mode_bubble()->GetBubbleWidget() == widget) { |
346 widget->RemoveObserver(this); | 343 widget->RemoveObserver(this); |
347 } | 344 } |
348 quiet_mode_bubble_.reset(); | 345 quiet_mode_bubble_.reset(); |
349 } | 346 } |
350 | 347 |
351 // Private methods | 348 void WebNotificationTray::OnMessageCenterTrayChanged() { |
352 | |
353 void WebNotificationTray::ToggleMessageCenterBubble() { | |
354 if (message_center_bubble()) | |
355 HideMessageCenterBubble(); | |
356 else | |
357 ShowMessageCenterBubble(); | |
358 UpdateTray(); | |
359 } | |
360 | |
361 void WebNotificationTray::UpdateTray() { | |
362 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 349 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
363 if (message_center_->UnreadNotificationCount() > 0) { | 350 message_center::MessageCenter* message_center = |
| 351 message_center_tray_->message_center(); |
| 352 if (message_center->UnreadNotificationCount() > 0) { |
364 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( | 353 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( |
365 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); | 354 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); |
366 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( | 355 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( |
367 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER)); | 356 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER)); |
368 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( | 357 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( |
369 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED)); | 358 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED)); |
370 } else { | 359 } else { |
371 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( | 360 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( |
372 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL)); | 361 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL)); |
373 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( | 362 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( |
374 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER)); | 363 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER)); |
375 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( | 364 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( |
376 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); | 365 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); |
377 } | 366 } |
378 if (message_center_bubble()) | 367 if (IsMessageCenterBubbleVisible()) |
379 button_->SetState(views::CustomButton::STATE_PRESSED); | 368 button_->SetState(views::CustomButton::STATE_PRESSED); |
380 else | 369 else |
381 button_->SetState(views::CustomButton::STATE_NORMAL); | 370 button_->SetState(views::CustomButton::STATE_NORMAL); |
382 Layout(); | 371 Layout(); |
383 SchedulePaint(); | 372 SchedulePaint(); |
384 } | 373 } |
385 | 374 |
386 bool WebNotificationTray::ClickedOutsideBubble() { | 375 bool WebNotificationTray::ClickedOutsideBubble() { |
387 // Only hide the message center and quiet mode bubble. | 376 // Only hide the message center and quiet mode bubble. |
388 if (!message_center_bubble() && !quiet_mode_bubble()) | 377 if (!message_center_bubble() && !quiet_mode_bubble()) |
389 return false; | 378 return false; |
390 quiet_mode_bubble_.reset(); | 379 quiet_mode_bubble_.reset(); |
391 HideMessageCenterBubble(); | 380 message_center_tray_->HideMessageCenterBubble(); |
392 return true; | 381 return true; |
393 } | 382 } |
394 | 383 |
| 384 message_center::MessageCenter* WebNotificationTray::message_center() { |
| 385 return message_center_tray_->message_center(); |
| 386 } |
| 387 |
395 // Methods for testing | 388 // Methods for testing |
396 | 389 |
| 390 bool WebNotificationTray::IsPopupVisible() const { |
| 391 return message_center_tray_->popups_visible(); |
| 392 } |
| 393 |
397 message_center::MessageCenterBubble* | 394 message_center::MessageCenterBubble* |
398 WebNotificationTray::GetMessageCenterBubbleForTest() { | 395 WebNotificationTray::GetMessageCenterBubbleForTest() { |
399 if (!message_center_bubble_.get()) | 396 if (!message_center_bubble()) |
400 return NULL; | 397 return NULL; |
401 return static_cast<message_center::MessageCenterBubble*>( | 398 return static_cast<message_center::MessageCenterBubble*>( |
402 message_center_bubble_->bubble()); | 399 message_center_bubble()->bubble()); |
403 } | 400 } |
404 | 401 |
405 message_center::MessagePopupBubble* | 402 message_center::MessagePopupBubble* |
406 WebNotificationTray::GetPopupBubbleForTest() { | 403 WebNotificationTray::GetPopupBubbleForTest() { |
407 if (!popup_bubble_.get()) | 404 if (!popup_bubble()) |
408 return NULL; | 405 return NULL; |
409 return static_cast<message_center::MessagePopupBubble*>( | 406 return static_cast<message_center::MessagePopupBubble*>( |
410 popup_bubble_->bubble()); | 407 popup_bubble()->bubble()); |
411 } | 408 } |
412 | 409 |
413 } // namespace ash | 410 } // namespace ash |
OLD | NEW |