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/timer.h" | 10 #include "base/timer.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 int seconds = kAutocloseDefaultDelaySeconds; | 40 int seconds = kAutocloseDefaultDelaySeconds; |
41 if (notification->priority() > DEFAULT_PRIORITY) | 41 if (notification->priority() > DEFAULT_PRIORITY) |
42 seconds = kAutocloseHighPriorityDelaySeconds; | 42 seconds = kAutocloseHighPriorityDelaySeconds; |
43 delay_ = base::TimeDelta::FromSeconds(seconds); | 43 delay_ = base::TimeDelta::FromSeconds(seconds); |
44 } | 44 } |
45 | 45 |
46 views::Widget* CreateWidget(gfx::NativeView context) { | 46 views::Widget* CreateWidget(gfx::NativeView context) { |
47 views::Widget::InitParams params( | 47 views::Widget::InitParams params( |
48 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 48 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
49 params.keep_on_top = true; | 49 params.keep_on_top = true; |
50 if (context) | 50 params.context = context; |
51 params.context = context; | |
52 else | |
53 params.top_level = true; | |
54 params.transparent = true; | 51 params.transparent = true; |
55 // The origin of the initial bounds are set to (0, 0). It'll then moved by | 52 // The origin of the initial bounds are set to (0, 0). It'll then moved by |
56 // MessagePopupCollection. | 53 // MessagePopupCollection. |
57 params.bounds = gfx::Rect( | 54 params.bounds = gfx::Rect( |
58 gfx::Size(kWebNotificationWidth, | 55 gfx::Size(kWebNotificationWidth, |
59 GetHeightForWidth(kWebNotificationWidth))); | 56 GetHeightForWidth(kWebNotificationWidth))); |
60 params.delegate = this; | 57 params.delegate = this; |
61 views::Widget* widget = new views::Widget(); | 58 views::Widget* widget = new views::Widget(); |
62 widget->Init(params); | 59 widget->Init(params); |
63 return widget; | 60 return widget; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 139 |
143 void MessagePopupCollection::UpdatePopups() { | 140 void MessagePopupCollection::UpdatePopups() { |
144 NotificationList::PopupNotifications popups = | 141 NotificationList::PopupNotifications popups = |
145 message_center_->notification_list()->GetPopupNotifications(); | 142 message_center_->notification_list()->GetPopupNotifications(); |
146 | 143 |
147 if (popups.empty()) { | 144 if (popups.empty()) { |
148 CloseAllWidgets(); | 145 CloseAllWidgets(); |
149 return; | 146 return; |
150 } | 147 } |
151 | 148 |
152 gfx::Rect work_area; | 149 gfx::Screen* screen = gfx::Screen::GetScreenFor(context_); |
153 if (!context_) { | 150 gfx::Rect work_area = screen->GetDisplayNearestWindow(context_).work_area(); |
154 // On Win+Aura, we don't have a context since the popups currently show up | |
155 // on the Windows desktop, not in the Aura/Ash desktop. This code will | |
156 // display the popups on the primary display. | |
157 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | |
158 work_area = screen->GetPrimaryDisplay().work_area(); | |
159 } else { | |
160 gfx::Screen* screen = gfx::Screen::GetScreenFor(context_); | |
161 work_area = screen->GetDisplayNearestWindow(context_).work_area(); | |
162 } | |
163 | 151 |
164 std::set<std::string> old_toast_ids; | 152 std::set<std::string> old_toast_ids; |
165 for (ToastContainer::iterator iter = toasts_.begin(); iter != toasts_.end(); | 153 for (ToastContainer::iterator iter = toasts_.begin(); iter != toasts_.end(); |
166 ++iter) { | 154 ++iter) { |
167 old_toast_ids.insert(iter->first); | 155 old_toast_ids.insert(iter->first); |
168 } | 156 } |
169 | 157 |
170 int bottom = work_area.bottom() - kMarginBetweenItems; | 158 int bottom = work_area.bottom() - kMarginBetweenItems; |
171 int left = work_area.right() - kWebNotificationWidth - kMarginBetweenItems; | 159 int left = work_area.right() - kWebNotificationWidth - kMarginBetweenItems; |
172 // Iterate in the reverse order to keep the oldest toasts on screen. Newer | 160 // Iterate in the reverse order to keep the oldest toasts on screen. Newer |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 message_center_->notification_list()->MarkSinglePopupAsShown( | 246 message_center_->notification_list()->MarkSinglePopupAsShown( |
259 iter->first, false); | 247 iter->first, false); |
260 toasts_.erase(iter); | 248 toasts_.erase(iter); |
261 break; | 249 break; |
262 } | 250 } |
263 } | 251 } |
264 UpdatePopups(); | 252 UpdatePopups(); |
265 } | 253 } |
266 | 254 |
267 } // namespace message_center | 255 } // namespace message_center |
OLD | NEW |