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