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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
16 #include "ui/base/accessibility/accessibility_types.h" | 16 #include "ui/base/accessibility/accessibility_types.h" |
17 #include "ui/gfx/animation/animation_delegate.h" | 17 #include "ui/gfx/animation/animation_delegate.h" |
18 #include "ui/gfx/animation/slide_animation.h" | 18 #include "ui/gfx/animation/slide_animation.h" |
19 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
20 #include "ui/message_center/message_center.h" | 20 #include "ui/message_center/message_center.h" |
21 #include "ui/message_center/message_center_style.h" | 21 #include "ui/message_center/message_center_style.h" |
22 #include "ui/message_center/message_center_tray.h" | 22 #include "ui/message_center/message_center_tray.h" |
23 #include "ui/message_center/message_center_util.h" | 23 #include "ui/message_center/message_center_util.h" |
24 #include "ui/message_center/notification.h" | 24 #include "ui/message_center/notification.h" |
25 #include "ui/message_center/notification_list.h" | 25 #include "ui/message_center/notification_list.h" |
| 26 #include "ui/message_center/views/message_view_context_menu_controller.h" |
26 #include "ui/message_center/views/notification_view.h" | 27 #include "ui/message_center/views/notification_view.h" |
27 #include "ui/message_center/views/toast_contents_view.h" | 28 #include "ui/message_center/views/toast_contents_view.h" |
28 #include "ui/views/background.h" | 29 #include "ui/views/background.h" |
29 #include "ui/views/layout/fill_layout.h" | 30 #include "ui/views/layout/fill_layout.h" |
30 #include "ui/views/view.h" | 31 #include "ui/views/view.h" |
31 #include "ui/views/views_delegate.h" | 32 #include "ui/views/views_delegate.h" |
32 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
33 #include "ui/views/widget/widget_delegate.h" | 34 #include "ui/views/widget/widget_delegate.h" |
34 | 35 |
35 namespace message_center { | 36 namespace message_center { |
(...skipping 25 matching lines...) Expand all Loading... |
61 MessageCenter* message_center, | 62 MessageCenter* message_center, |
62 MessageCenterTray* tray, | 63 MessageCenterTray* tray, |
63 bool first_item_has_no_margin) | 64 bool first_item_has_no_margin) |
64 : parent_(parent), | 65 : parent_(parent), |
65 message_center_(message_center), | 66 message_center_(message_center), |
66 tray_(tray), | 67 tray_(tray), |
67 defer_counter_(0), | 68 defer_counter_(0), |
68 latest_toast_entered_(NULL), | 69 latest_toast_entered_(NULL), |
69 user_is_closing_toasts_by_clicking_(false), | 70 user_is_closing_toasts_by_clicking_(false), |
70 first_item_has_no_margin_(first_item_has_no_margin), | 71 first_item_has_no_margin_(first_item_has_no_margin), |
| 72 context_menu_controller_(new MessageViewContextMenuController(this)), |
71 weak_factory_(this) { | 73 weak_factory_(this) { |
72 DCHECK(message_center_); | 74 DCHECK(message_center_); |
73 defer_timer_.reset(new base::OneShotTimer<MessagePopupCollection>); | 75 defer_timer_.reset(new base::OneShotTimer<MessagePopupCollection>); |
74 message_center_->AddObserver(this); | 76 message_center_->AddObserver(this); |
75 gfx::Screen* screen = NULL; | 77 gfx::Screen* screen = NULL; |
76 gfx::Display display; | 78 gfx::Display display; |
77 if (!parent_) { | 79 if (!parent_) { |
78 // On Win+Aura, we don't have a parent since the popups currently show up | 80 // On Win+Aura, we don't have a parent since the popups currently show up |
79 // on the Windows desktop, not in the Aura/Ash desktop. This code will | 81 // on the Windows desktop, not in the Aura/Ash desktop. This code will |
80 // display the popups on the primary display. | 82 // display the popups on the primary display. |
(...skipping 28 matching lines...) Expand all Loading... |
109 const std::string& notification_id) { | 111 const std::string& notification_id) { |
110 message_center_->ClickOnNotification(notification_id); | 112 message_center_->ClickOnNotification(notification_id); |
111 } | 113 } |
112 | 114 |
113 void MessagePopupCollection::RemoveNotification( | 115 void MessagePopupCollection::RemoveNotification( |
114 const std::string& notification_id, | 116 const std::string& notification_id, |
115 bool by_user) { | 117 bool by_user) { |
116 message_center_->RemoveNotification(notification_id, by_user); | 118 message_center_->RemoveNotification(notification_id, by_user); |
117 } | 119 } |
118 | 120 |
119 void MessagePopupCollection::DisableNotificationsFromThisSource( | 121 scoped_ptr<ui::MenuModel> MessagePopupCollection::CreateMenuModel( |
120 const NotifierId& notifier_id) { | 122 const NotifierId& notifier_id, |
121 message_center_->DisableNotificationsByNotifier(notifier_id); | 123 const base::string16& display_source) { |
122 } | 124 return tray_->CreateNotificationMenuModel(notifier_id, display_source); |
123 | |
124 void MessagePopupCollection::ShowNotifierSettingsBubble() { | |
125 tray_->ShowNotifierSettingsBubble(); | |
126 } | 125 } |
127 | 126 |
128 bool MessagePopupCollection::HasClickedListener( | 127 bool MessagePopupCollection::HasClickedListener( |
129 const std::string& notification_id) { | 128 const std::string& notification_id) { |
130 return message_center_->HasClickedListener(notification_id); | 129 return message_center_->HasClickedListener(notification_id); |
131 } | 130 } |
132 | 131 |
133 void MessagePopupCollection::ClickOnNotificationButton( | 132 void MessagePopupCollection::ClickOnNotificationButton( |
134 const std::string& notification_id, | 133 const std::string& notification_id, |
135 int button_index) { | 134 int button_index) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 continue; | 186 continue; |
188 | 187 |
189 bool expanded = true; | 188 bool expanded = true; |
190 if (IsExperimentalNotificationUIEnabled()) | 189 if (IsExperimentalNotificationUIEnabled()) |
191 expanded = (*iter)->is_expanded(); | 190 expanded = (*iter)->is_expanded(); |
192 NotificationView* view = | 191 NotificationView* view = |
193 NotificationView::Create(NULL, | 192 NotificationView::Create(NULL, |
194 *(*iter), | 193 *(*iter), |
195 expanded, | 194 expanded, |
196 true); // Create top-level notification. | 195 true); // Create top-level notification. |
| 196 view->set_context_menu_controller(context_menu_controller_.get()); |
197 int view_height = ToastContentsView::GetToastSizeForView(view).height(); | 197 int view_height = ToastContentsView::GetToastSizeForView(view).height(); |
198 int height_available = top_down ? work_area_.bottom() - base : base; | 198 int height_available = top_down ? work_area_.bottom() - base : base; |
199 | 199 |
200 if (height_available - view_height - kToastMarginY < 0) { | 200 if (height_available - view_height - kToastMarginY < 0) { |
201 delete view; | 201 delete view; |
202 break; | 202 break; |
203 } | 203 } |
204 | 204 |
205 ToastContentsView* toast = | 205 ToastContentsView* toast = |
206 new ToastContentsView((*iter)->id(), weak_factory_.GetWeakPtr()); | 206 new ToastContentsView((*iter)->id(), weak_factory_.GetWeakPtr()); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 const RichNotificationData& optional_fields = | 506 const RichNotificationData& optional_fields = |
507 (*iter)->rich_notification_data(); | 507 (*iter)->rich_notification_data(); |
508 bool a11y_feedback_for_updates = | 508 bool a11y_feedback_for_updates = |
509 optional_fields.should_make_spoken_feedback_for_popup_updates; | 509 optional_fields.should_make_spoken_feedback_for_popup_updates; |
510 | 510 |
511 NotificationView* view = | 511 NotificationView* view = |
512 NotificationView::Create(*toast_iter, | 512 NotificationView::Create(*toast_iter, |
513 *(*iter), | 513 *(*iter), |
514 expanded, | 514 expanded, |
515 true); // Create top-level notification. | 515 true); // Create top-level notification. |
| 516 view->set_context_menu_controller(context_menu_controller_.get()); |
516 (*toast_iter)->SetContents(view, a11y_feedback_for_updates); | 517 (*toast_iter)->SetContents(view, a11y_feedback_for_updates); |
517 updated = true; | 518 updated = true; |
518 } | 519 } |
519 | 520 |
520 // OnNotificationUpdated() can be called when a notification is excluded from | 521 // OnNotificationUpdated() can be called when a notification is excluded from |
521 // the popup notification list but still remains in the full notification | 522 // the popup notification list but still remains in the full notification |
522 // list. In that case the widget for the notification has to be closed here. | 523 // list. In that case the widget for the notification has to be closed here. |
523 if (!updated) | 524 if (!updated) |
524 RemoveToast(*toast_iter, /*mark_as_shown=*/true); | 525 RemoveToast(*toast_iter, /*mark_as_shown=*/true); |
525 | 526 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 views::Widget* widget = (*iter)->GetWidget(); | 630 views::Widget* widget = (*iter)->GetWidget(); |
630 if (widget) | 631 if (widget) |
631 return widget->GetWindowBoundsInScreen(); | 632 return widget->GetWindowBoundsInScreen(); |
632 break; | 633 break; |
633 } | 634 } |
634 } | 635 } |
635 return gfx::Rect(); | 636 return gfx::Rect(); |
636 } | 637 } |
637 | 638 |
638 } // namespace message_center | 639 } // namespace message_center |
OLD | NEW |