Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: ui/message_center/views/message_popup_collection.cc

Issue 1645843003: Implement Non-Closable Notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed the comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 closable.
dewittj 2016/02/10 00:03:15 nit: when it's pinned.
yoshiki 2016/02/12 23:11:36 Done.
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
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
160 Notification notification = *(*iter);
dewittj 2016/02/10 00:03:15 I don't love copying the notification in order to
yoshiki 2016/02/12 23:11:36 Done.
161 // Override pinned status, since toasts should be closable even when it's
162 // pinned.
163 notification.set_pinned(false);
142 NotificationView* view = 164 NotificationView* view =
143 NotificationView::Create(NULL, 165 NotificationView::Create(NULL, notification,
144 *(*iter), 166 true); // Create top-level notification.
145 true); // Create top-level notification.
146 view->set_context_menu_controller(context_menu_controller_.get()); 167 view->set_context_menu_controller(context_menu_controller_.get());
147 int view_height = ToastContentsView::GetToastSizeForView(view).height(); 168 int view_height = ToastContentsView::GetToastSizeForView(view).height();
148 int height_available = 169 int height_available =
149 top_down ? alignment_delegate_->GetWorkAreaBottom() - base : base; 170 top_down ? alignment_delegate_->GetWorkAreaBottom() - base : base;
150 171
151 if (height_available - view_height - kToastMarginY < 0) { 172 if (height_available - view_height - kToastMarginY < 0) {
152 delete view; 173 delete view;
153 break; 174 break;
154 } 175 }
155 176
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 views::Widget* widget = (*iter)->GetWidget(); 530 views::Widget* widget = (*iter)->GetWidget();
510 if (widget) 531 if (widget)
511 return widget->GetWindowBoundsInScreen(); 532 return widget->GetWindowBoundsInScreen();
512 break; 533 break;
513 } 534 }
514 } 535 }
515 return gfx::Rect(); 536 return gfx::Rect();
516 } 537 }
517 538
518 } // namespace message_center 539 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698