OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "ui/message_center/views/message_popup_collection.h" | 5 #include "ui/message_center/views/message_popup_collection.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 if (by_user && widgets_went_empty) | 380 if (by_user && widgets_went_empty) |
381 RepositionWidgetsWithTarget(removed_bounds); | 381 RepositionWidgetsWithTarget(removed_bounds); |
382 } | 382 } |
383 | 383 |
384 void MessagePopupCollection::OnNotificationUpdated( | 384 void MessagePopupCollection::OnNotificationUpdated( |
385 const std::string& notification_id) { | 385 const std::string& notification_id) { |
386 ToastContainer::iterator toast_iter = toasts_.find(notification_id); | 386 ToastContainer::iterator toast_iter = toasts_.find(notification_id); |
387 if (toast_iter == toasts_.end()) | 387 if (toast_iter == toasts_.end()) |
388 return; | 388 return; |
389 | 389 |
390 NotificationList::Notifications notifications = | 390 NotificationList::PopupNotifications notifications = |
391 message_center_->GetNotifications(); | 391 message_center_->GetPopupNotifications(); |
392 bool updated = false; | 392 bool updated = false; |
393 for (NotificationList::Notifications::iterator iter = | 393 for (NotificationList::PopupNotifications::iterator iter = |
394 notifications.begin(); iter != notifications.end(); ++iter) { | 394 notifications.begin(); iter != notifications.end(); ++iter) { |
395 if ((*iter)->id() != notification_id) | 395 if ((*iter)->id() != notification_id) |
396 continue; | 396 continue; |
397 | 397 |
398 MessageView* view = NotificationView::Create( | 398 MessageView* view = NotificationView::Create( |
399 *(*iter), message_center_, true); | 399 *(*iter), message_center_, true); |
400 toast_iter->second->SetContents(view); | 400 toast_iter->second->SetContents(view); |
401 toast_iter->second->ResetTimeout((*iter)->priority()); | 401 toast_iter->second->ResetTimeout((*iter)->priority()); |
402 toast_iter->second->RestartTimer(); | 402 toast_iter->second->RestartTimer(); |
403 updated = true; | 403 updated = true; |
404 } | 404 } |
405 | 405 |
406 if (updated) { | 406 // OnNotificationUpdated() can be called when a notification is excluded from |
407 RepositionWidgets(); | 407 // the popup notification list but still remains in the full notification |
408 // Reposition could create extra space which allows additional widgets. | 408 // list. In that case the widget for the notification has to be closed here. |
409 UpdateWidgets(); | 409 if (!updated) { |
| 410 views::Widget* widget = toast_iter->second->GetWidget(); |
| 411 widget->RemoveObserver(this); |
| 412 widgets_.erase(std::find(widgets_.begin(), widgets_.end(), widget)); |
| 413 widget->Close(); |
| 414 toasts_.erase(toast_iter); |
410 } | 415 } |
| 416 |
| 417 RepositionWidgets(); |
| 418 // Reposition could create extra space which allows additional widgets. |
| 419 UpdateWidgets(); |
411 } | 420 } |
412 | 421 |
413 void MessagePopupCollection::SetWorkAreaForTest(const gfx::Rect& work_area) { | 422 void MessagePopupCollection::SetWorkAreaForTest(const gfx::Rect& work_area) { |
414 work_area_ = work_area; | 423 work_area_ = work_area; |
415 } | 424 } |
416 | 425 |
| 426 views::Widget* MessagePopupCollection::GetWidgetForId(const std::string& id) { |
| 427 ToastContainer::const_iterator iter = toasts_.find(id); |
| 428 return (iter == toasts_.end()) ? NULL : iter->second->GetWidget(); |
| 429 } |
| 430 |
417 } // namespace message_center | 431 } // namespace message_center |
OLD | NEW |