| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } | 131 } |
| 132 | 132 |
| 133 void MessagePopupCollection::MarkAllPopupsShown() { | 133 void MessagePopupCollection::MarkAllPopupsShown() { |
| 134 std::set<std::string> closed_ids = CloseAllWidgets(); | 134 std::set<std::string> closed_ids = CloseAllWidgets(); |
| 135 for (std::set<std::string>::iterator iter = closed_ids.begin(); | 135 for (std::set<std::string>::iterator iter = closed_ids.begin(); |
| 136 iter != closed_ids.end(); iter++) { | 136 iter != closed_ids.end(); iter++) { |
| 137 message_center_->MarkSinglePopupAsShown(*iter, false); | 137 message_center_->MarkSinglePopupAsShown(*iter, false); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 void MessagePopupCollection::PausePopupTimers() { |
| 142 DCHECK(timer_pause_counter_ >= 0); |
| 143 if (timer_pause_counter_ <= 0) { |
| 144 message_center_->PausePopupTimers(); |
| 145 timer_pause_counter_ = 1; |
| 146 } else { |
| 147 timer_pause_counter_++; |
| 148 } |
| 149 } |
| 150 |
| 151 void MessagePopupCollection::RestartPopupTimers() { |
| 152 DCHECK(timer_pause_counter_ >= 1); |
| 153 if (timer_pause_counter_ <= 1) { |
| 154 message_center_->RestartPopupTimers(); |
| 155 timer_pause_counter_ = 0; |
| 156 } else { |
| 157 timer_pause_counter_--; |
| 158 } |
| 159 } |
| 160 |
| 141 void MessagePopupCollection::UpdateWidgets() { | 161 void MessagePopupCollection::UpdateWidgets() { |
| 142 if (message_center_->IsMessageCenterVisible()) { | 162 if (message_center_->IsMessageCenterVisible()) { |
| 143 DCHECK_EQ(0u, message_center_->GetPopupNotifications().size()); | 163 DCHECK_EQ(0u, message_center_->GetPopupNotifications().size()); |
| 144 return; | 164 return; |
| 145 } | 165 } |
| 146 | 166 |
| 147 NotificationList::PopupNotifications popups = | 167 NotificationList::PopupNotifications popups = |
| 148 message_center_->GetPopupNotifications(); | 168 message_center_->GetPopupNotifications(); |
| 149 if (popups.empty()) { | 169 if (popups.empty()) { |
| 150 CloseAllWidgets(); | 170 CloseAllWidgets(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 message_center_->DisplayedNotification( | 242 message_center_->DisplayedNotification( |
| 223 (*iter)->id(), message_center::DISPLAY_SOURCE_POPUP); | 243 (*iter)->id(), message_center::DISPLAY_SOURCE_POPUP); |
| 224 } | 244 } |
| 225 } | 245 } |
| 226 | 246 |
| 227 void MessagePopupCollection::OnMouseEntered(ToastContentsView* toast_entered) { | 247 void MessagePopupCollection::OnMouseEntered(ToastContentsView* toast_entered) { |
| 228 // Sometimes we can get two MouseEntered/MouseExited in a row when animating | 248 // Sometimes we can get two MouseEntered/MouseExited in a row when animating |
| 229 // toasts. So we need to keep track of which one is the currently active one. | 249 // toasts. So we need to keep track of which one is the currently active one. |
| 230 latest_toast_entered_ = toast_entered; | 250 latest_toast_entered_ = toast_entered; |
| 231 | 251 |
| 232 message_center_->PausePopupTimers(); | 252 PausePopupTimers(); |
| 233 | 253 |
| 234 if (user_is_closing_toasts_by_clicking_) | 254 if (user_is_closing_toasts_by_clicking_) |
| 235 defer_timer_->Stop(); | 255 defer_timer_->Stop(); |
| 236 } | 256 } |
| 237 | 257 |
| 238 void MessagePopupCollection::OnMouseExited(ToastContentsView* toast_exited) { | 258 void MessagePopupCollection::OnMouseExited(ToastContentsView* toast_exited) { |
| 239 // If we're exiting a toast after entering a different toast, then ignore | 259 // If we're exiting a toast after entering a different toast, then ignore |
| 240 // this mouse event. | 260 // this mouse event. |
| 241 if (toast_exited != latest_toast_entered_) | 261 if (toast_exited != latest_toast_entered_) |
| 242 return; | 262 return; |
| 243 latest_toast_entered_ = NULL; | 263 latest_toast_entered_ = NULL; |
| 244 | 264 |
| 245 if (user_is_closing_toasts_by_clicking_) { | 265 if (user_is_closing_toasts_by_clicking_) { |
| 246 defer_timer_->Start( | 266 defer_timer_->Start( |
| 247 FROM_HERE, | 267 FROM_HERE, |
| 248 base::TimeDelta::FromMilliseconds(kMouseExitedDeferTimeoutMs), | 268 base::TimeDelta::FromMilliseconds(kMouseExitedDeferTimeoutMs), |
| 249 this, | 269 this, |
| 250 &MessagePopupCollection::OnDeferTimerExpired); | 270 &MessagePopupCollection::OnDeferTimerExpired); |
| 251 } else { | 271 } else { |
| 252 message_center_->RestartPopupTimers(); | 272 RestartPopupTimers(); |
| 253 } | 273 } |
| 254 } | 274 } |
| 255 | 275 |
| 256 std::set<std::string> MessagePopupCollection::CloseAllWidgets() { | 276 std::set<std::string> MessagePopupCollection::CloseAllWidgets() { |
| 257 std::set<std::string> closed_toast_ids; | 277 std::set<std::string> closed_toast_ids; |
| 258 | 278 |
| 259 while (!toasts_.empty()) { | 279 while (!toasts_.empty()) { |
| 260 ToastContentsView* toast = toasts_.front(); | 280 ToastContentsView* toast = toasts_.front(); |
| 261 toasts_.pop_front(); | 281 toasts_.pop_front(); |
| 262 closed_toast_ids.insert(toast->id()); | 282 closed_toast_ids.insert(toast->id()); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 RemoveToast(*iter, /*mark_as_shown=*/true); | 425 RemoveToast(*iter, /*mark_as_shown=*/true); |
| 406 | 426 |
| 407 if (by_user) | 427 if (by_user) |
| 408 RepositionWidgetsWithTarget(); | 428 RepositionWidgetsWithTarget(); |
| 409 } | 429 } |
| 410 | 430 |
| 411 void MessagePopupCollection::OnDeferTimerExpired() { | 431 void MessagePopupCollection::OnDeferTimerExpired() { |
| 412 user_is_closing_toasts_by_clicking_ = false; | 432 user_is_closing_toasts_by_clicking_ = false; |
| 413 DecrementDeferCounter(); | 433 DecrementDeferCounter(); |
| 414 | 434 |
| 415 message_center_->RestartPopupTimers(); | 435 RestartPopupTimers(); |
| 416 } | 436 } |
| 417 | 437 |
| 418 void MessagePopupCollection::OnNotificationUpdated( | 438 void MessagePopupCollection::OnNotificationUpdated( |
| 419 const std::string& notification_id) { | 439 const std::string& notification_id) { |
| 420 // Find a toast. | 440 // Find a toast. |
| 421 Toasts::const_iterator toast_iter = toasts_.begin(); | 441 Toasts::const_iterator toast_iter = toasts_.begin(); |
| 422 for (; toast_iter != toasts_.end(); ++toast_iter) { | 442 for (; toast_iter != toasts_.end(); ++toast_iter) { |
| 423 if ((*toast_iter)->id() == notification_id) | 443 if ((*toast_iter)->id() == notification_id) |
| 424 break; | 444 break; |
| 425 } | 445 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 views::Widget* widget = (*iter)->GetWidget(); | 564 views::Widget* widget = (*iter)->GetWidget(); |
| 545 if (widget) | 565 if (widget) |
| 546 return widget->GetWindowBoundsInScreen(); | 566 return widget->GetWindowBoundsInScreen(); |
| 547 break; | 567 break; |
| 548 } | 568 } |
| 549 } | 569 } |
| 550 return gfx::Rect(); | 570 return gfx::Rect(); |
| 551 } | 571 } |
| 552 | 572 |
| 553 } // namespace message_center | 573 } // namespace message_center |
| OLD | NEW |