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/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 76 } |
77 | 77 |
78 void MessagePopupCollection::ClickOnNotification( | 78 void MessagePopupCollection::ClickOnNotification( |
79 const std::string& notification_id) { | 79 const std::string& notification_id) { |
80 message_center_->ClickOnNotification(notification_id); | 80 message_center_->ClickOnNotification(notification_id); |
81 } | 81 } |
82 | 82 |
83 void MessagePopupCollection::RemoveNotification( | 83 void MessagePopupCollection::RemoveNotification( |
84 const std::string& notification_id, | 84 const std::string& notification_id, |
85 bool by_user) { | 85 bool by_user) { |
86 message_center_->RemoveNotification(notification_id, by_user); | 86 NotificationList::PopupNotifications notifications = |
| 87 message_center_->GetPopupNotifications(); |
| 88 for (NotificationList::PopupNotifications::iterator iter = |
| 89 notifications.begin(); |
| 90 iter != notifications.end(); ++iter) { |
| 91 Notification* notification = *iter; |
| 92 DCHECK(notification); |
| 93 |
| 94 if (notification->id() != notification_id) |
| 95 continue; |
| 96 |
| 97 // Don't remove the notification only when it's not pinned. |
| 98 if (!notification->pinned()) |
| 99 message_center_->RemoveNotification(notification_id, by_user); |
| 100 else |
| 101 message_center_->MarkSinglePopupAsShown(notification_id, true /* read */); |
| 102 |
| 103 break; |
| 104 } |
87 } | 105 } |
88 | 106 |
89 scoped_ptr<ui::MenuModel> MessagePopupCollection::CreateMenuModel( | 107 scoped_ptr<ui::MenuModel> MessagePopupCollection::CreateMenuModel( |
90 const NotifierId& notifier_id, | 108 const NotifierId& notifier_id, |
91 const base::string16& display_source) { | 109 const base::string16& display_source) { |
92 return tray_->CreateNotificationMenuModel(notifier_id, display_source); | 110 return tray_->CreateNotificationMenuModel(notifier_id, display_source); |
93 } | 111 } |
94 | 112 |
95 bool MessagePopupCollection::HasClickedListener( | 113 bool MessagePopupCollection::HasClickedListener( |
96 const std::string& notification_id) { | 114 const std::string& notification_id) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 bool top_down = alignment_delegate_->IsTopDown(); | 150 bool top_down = alignment_delegate_->IsTopDown(); |
133 int base = GetBaseLine(toasts_.empty() ? NULL : toasts_.back()); | 151 int base = GetBaseLine(toasts_.empty() ? NULL : toasts_.back()); |
134 | 152 |
135 // Iterate in the reverse order to keep the oldest toasts on screen. Newer | 153 // Iterate in the reverse order to keep the oldest toasts on screen. Newer |
136 // items may be ignored if there are no room to place them. | 154 // items may be ignored if there are no room to place them. |
137 for (NotificationList::PopupNotifications::const_reverse_iterator iter = | 155 for (NotificationList::PopupNotifications::const_reverse_iterator iter = |
138 popups.rbegin(); iter != popups.rend(); ++iter) { | 156 popups.rbegin(); iter != popups.rend(); ++iter) { |
139 if (FindToast((*iter)->id())) | 157 if (FindToast((*iter)->id())) |
140 continue; | 158 continue; |
141 | 159 |
142 NotificationView* view = | 160 NotificationView* view; |
143 NotificationView::Create(NULL, | 161 // Create top-level notification. |
144 *(*iter), | 162 #if defined(OS_CHROMEOS) |
145 true); // Create top-level notification. | 163 if ((*iter)->pinned()) { |
| 164 Notification notification = *(*iter); |
| 165 // Override pinned status, since toasts should be closable even when it's |
| 166 // pinned. |
| 167 notification.set_pinned(false); |
| 168 view = NotificationView::Create(NULL, notification, true); |
| 169 } else |
| 170 #endif // defined(OS_CHROMEOS) |
| 171 { |
| 172 view = NotificationView::Create(NULL, *(*iter), true); |
| 173 } |
| 174 |
146 view->set_context_menu_controller(context_menu_controller_.get()); | 175 view->set_context_menu_controller(context_menu_controller_.get()); |
147 int view_height = ToastContentsView::GetToastSizeForView(view).height(); | 176 int view_height = ToastContentsView::GetToastSizeForView(view).height(); |
148 int height_available = | 177 int height_available = |
149 top_down ? alignment_delegate_->GetWorkAreaBottom() - base : base; | 178 top_down ? alignment_delegate_->GetWorkAreaBottom() - base : base; |
150 | 179 |
151 if (height_available - view_height - kToastMarginY < 0) { | 180 if (height_available - view_height - kToastMarginY < 0) { |
152 delete view; | 181 delete view; |
153 break; | 182 break; |
154 } | 183 } |
155 | 184 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 views::Widget* widget = (*iter)->GetWidget(); | 538 views::Widget* widget = (*iter)->GetWidget(); |
510 if (widget) | 539 if (widget) |
511 return widget->GetWindowBoundsInScreen(); | 540 return widget->GetWindowBoundsInScreen(); |
512 break; | 541 break; |
513 } | 542 } |
514 } | 543 } |
515 return gfx::Rect(); | 544 return gfx::Rect(); |
516 } | 545 } |
517 | 546 |
518 } // namespace message_center | 547 } // namespace message_center |
OLD | NEW |