| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 <algorithm> | 5 #include "ui/message_center/views/message_list_view.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/stl_util.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "ui/gfx/animation/slide_animation.h" | 13 #include "ui/gfx/animation/slide_animation.h" |
| 13 #include "ui/message_center/message_center_style.h" | 14 #include "ui/message_center/message_center_style.h" |
| 14 #include "ui/message_center/message_center_switches.h" | 15 #include "ui/message_center/message_center_switches.h" |
| 15 #include "ui/message_center/views/message_center_view.h" | 16 #include "ui/message_center/views/message_center_view.h" |
| 16 #include "ui/message_center/views/message_list_view.h" | |
| 17 #include "ui/message_center/views/message_view.h" | 17 #include "ui/message_center/views/message_view.h" |
| 18 #include "ui/views/background.h" | 18 #include "ui/views/background.h" |
| 19 #include "ui/views/border.h" | 19 #include "ui/views/border.h" |
| 20 #include "ui/views/layout/box_layout.h" | 20 #include "ui/views/layout/box_layout.h" |
| 21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 22 | 22 |
| 23 namespace message_center { | 23 namespace message_center { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 const int kAnimateClearingNextNotificationDelayMS = 40; | 26 const int kAnimateClearingNextNotificationDelayMS = 40; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 adding_views_.insert(view); | 98 adding_views_.insert(view); |
| 99 DoUpdateIfPossible(); | 99 DoUpdateIfPossible(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void MessageListView::RemoveNotification(MessageView* view) { | 102 void MessageListView::RemoveNotification(MessageView* view) { |
| 103 DCHECK_EQ(view->parent(), this); | 103 DCHECK_EQ(view->parent(), this); |
| 104 | 104 |
| 105 // TODO(yhananda): We should consider consolidating clearing_all_views_, | 105 // TODO(yhananda): We should consider consolidating clearing_all_views_, |
| 106 // deleting_views_ and deleted_when_done_. | 106 // deleting_views_ and deleted_when_done_. |
| 107 if (std::find(clearing_all_views_.begin(), clearing_all_views_.end(), view) != | 107 if (base::ContainsValue(clearing_all_views_, view) || |
| 108 clearing_all_views_.end() || | |
| 109 deleting_views_.find(view) != deleting_views_.end() || | 108 deleting_views_.find(view) != deleting_views_.end() || |
| 110 deleted_when_done_.find(view) != deleted_when_done_.end()) { | 109 deleted_when_done_.find(view) != deleted_when_done_.end()) { |
| 111 // Let's skip deleting the view if it's already scheduled for deleting. | 110 // Let's skip deleting the view if it's already scheduled for deleting. |
| 112 // Even if we check clearing_all_views_ here, we actualy have no idea | 111 // Even if we check clearing_all_views_ here, we actualy have no idea |
| 113 // whether the view is due to be removed or not because it could be in its | 112 // whether the view is due to be removed or not because it could be in its |
| 114 // animation before removal. | 113 // animation before removal. |
| 115 // In short, we could delete the view twice even if we check these three | 114 // In short, we could delete the view twice even if we check these three |
| 116 // lists. | 115 // lists. |
| 117 return; | 116 return; |
| 118 } | 117 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 130 } else { | 129 } else { |
| 131 delete view; | 130 delete view; |
| 132 } | 131 } |
| 133 DoUpdateIfPossible(); | 132 DoUpdateIfPossible(); |
| 134 } | 133 } |
| 135 } | 134 } |
| 136 | 135 |
| 137 void MessageListView::UpdateNotification(MessageView* view, | 136 void MessageListView::UpdateNotification(MessageView* view, |
| 138 const Notification& notification) { | 137 const Notification& notification) { |
| 139 // Skip updating the notification being cleared | 138 // Skip updating the notification being cleared |
| 140 if (std::find(clearing_all_views_.begin(), clearing_all_views_.end(), view) != | 139 if (base::ContainsValue(clearing_all_views_, view)) |
| 141 clearing_all_views_.end()) | |
| 142 return; | 140 return; |
| 143 | 141 |
| 144 int index = GetIndexOf(view); | 142 int index = GetIndexOf(view); |
| 145 DCHECK_LE(0, index); // GetIndexOf is negative if not a child. | 143 DCHECK_LE(0, index); // GetIndexOf is negative if not a child. |
| 146 | 144 |
| 147 animator_.StopAnimatingView(view); | 145 animator_.StopAnimatingView(view); |
| 148 if (deleting_views_.find(view) != deleting_views_.end()) | 146 if (deleting_views_.find(view) != deleting_views_.end()) |
| 149 deleting_views_.erase(view); | 147 deleting_views_.erase(view); |
| 150 if (deleted_when_done_.find(view) != deleted_when_done_.end()) | 148 if (deleted_when_done_.find(view) != deleted_when_done_.end()) |
| 151 deleted_when_done_.erase(view); | 149 deleted_when_done_.erase(view); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 if (quit_message_loop_after_animation_for_test_) | 335 if (quit_message_loop_after_animation_for_test_) |
| 338 base::MessageLoop::current()->QuitWhenIdle(); | 336 base::MessageLoop::current()->QuitWhenIdle(); |
| 339 } | 337 } |
| 340 | 338 |
| 341 bool MessageListView::IsValidChild(const views::View* child) const { | 339 bool MessageListView::IsValidChild(const views::View* child) const { |
| 342 return child->visible() && | 340 return child->visible() && |
| 343 deleting_views_.find(const_cast<views::View*>(child)) == | 341 deleting_views_.find(const_cast<views::View*>(child)) == |
| 344 deleting_views_.end() && | 342 deleting_views_.end() && |
| 345 deleted_when_done_.find(const_cast<views::View*>(child)) == | 343 deleted_when_done_.find(const_cast<views::View*>(child)) == |
| 346 deleted_when_done_.end() && | 344 deleted_when_done_.end() && |
| 347 std::find(clearing_all_views_.begin(), clearing_all_views_.end(), | 345 !base::ContainsValue(clearing_all_views_, child); |
| 348 child) == clearing_all_views_.end(); | |
| 349 } | 346 } |
| 350 | 347 |
| 351 void MessageListView::DoUpdateIfPossible() { | 348 void MessageListView::DoUpdateIfPossible() { |
| 352 gfx::Rect child_area = GetContentsBounds(); | 349 gfx::Rect child_area = GetContentsBounds(); |
| 353 if (child_area.IsEmpty()) | 350 if (child_area.IsEmpty()) |
| 354 return; | 351 return; |
| 355 | 352 |
| 356 if (animator_.IsAnimating()) { | 353 if (animator_.IsAnimating()) { |
| 357 has_deferred_task_ = true; | 354 has_deferred_task_ = true; |
| 358 return; | 355 return; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 base::TimeDelta::FromMilliseconds( | 583 base::TimeDelta::FromMilliseconds( |
| 587 kAnimateClearingNextNotificationDelayMS)); | 584 kAnimateClearingNextNotificationDelayMS)); |
| 588 } | 585 } |
| 589 } | 586 } |
| 590 | 587 |
| 591 void MessageListView::SetRepositionTargetForTest(const gfx::Rect& target_rect) { | 588 void MessageListView::SetRepositionTargetForTest(const gfx::Rect& target_rect) { |
| 592 SetRepositionTarget(target_rect); | 589 SetRepositionTarget(target_rect); |
| 593 } | 590 } |
| 594 | 591 |
| 595 } // namespace message_center | 592 } // namespace message_center |
| OLD | NEW |