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> | |
6 | |
5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
6 #include "base/location.h" | 8 #include "base/location.h" |
7 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
9 #include "ui/gfx/animation/slide_animation.h" | 11 #include "ui/gfx/animation/slide_animation.h" |
10 #include "ui/message_center/message_center_style.h" | 12 #include "ui/message_center/message_center_style.h" |
11 #include "ui/message_center/message_center_switches.h" | 13 #include "ui/message_center/message_center_switches.h" |
12 #include "ui/message_center/views/message_center_view.h" | 14 #include "ui/message_center/views/message_center_view.h" |
13 #include "ui/message_center/views/message_list_view.h" | 15 #include "ui/message_center/views/message_list_view.h" |
14 #include "ui/message_center/views/message_view.h" | 16 #include "ui/message_center/views/message_view.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 if (GetContentsBounds().IsEmpty()) | 95 if (GetContentsBounds().IsEmpty()) |
94 return; | 96 return; |
95 | 97 |
96 adding_views_.insert(view); | 98 adding_views_.insert(view); |
97 DoUpdateIfPossible(); | 99 DoUpdateIfPossible(); |
98 } | 100 } |
99 | 101 |
100 void MessageListView::RemoveNotification(MessageView* view) { | 102 void MessageListView::RemoveNotification(MessageView* view) { |
101 DCHECK_EQ(view->parent(), this); | 103 DCHECK_EQ(view->parent(), this); |
102 | 104 |
105 // TODO(yhananda): We should consider consolidating clearing_all_views_, | |
106 // deleting_views_ and deleted_when_done_. | |
107 if (std::find(clearing_all_views_.begin(), clearing_all_views_.end(), view) != | |
108 clearing_all_views_.end() || | |
109 deleting_views_.find(view) != deleting_views_.end() || | |
110 deleted_when_done_.find(view) != deleted_when_done_.end()) { | |
111 // 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 | |
113 // whether the view is due to be removed or not because it could be in its | |
114 // animation before removal. | |
115 // In short, we could delete the view twice even if we check these three | |
116 // lists. | |
117 return; | |
118 } | |
103 | 119 |
104 if (GetContentsBounds().IsEmpty()) { | 120 if (GetContentsBounds().IsEmpty()) { |
105 delete view; | 121 delete view; |
106 } else { | 122 } else { |
107 if (adding_views_.find(view) != adding_views_.end()) | 123 if (adding_views_.find(view) != adding_views_.end()) |
108 adding_views_.erase(view); | 124 adding_views_.erase(view); |
109 if (animator_.IsAnimating(view)) | 125 if (animator_.IsAnimating(view)) |
110 animator_.StopAnimatingView(view); | 126 animator_.StopAnimatingView(view); |
111 | 127 |
112 if (view->layer()) { | 128 if (view->layer()) { |
113 deleting_views_.insert(view); | 129 deleting_views_.insert(view); |
114 } else { | 130 } else { |
115 delete view; | 131 delete view; |
116 } | 132 } |
117 DoUpdateIfPossible(); | 133 DoUpdateIfPossible(); |
118 } | 134 } |
119 } | 135 } |
120 | 136 |
121 void MessageListView::UpdateNotification(MessageView* view, | 137 void MessageListView::UpdateNotification(MessageView* view, |
122 const Notification& notification) { | 138 const Notification& notification) { |
123 int index = GetIndexOf(view); | 139 int index = GetIndexOf(view); |
124 DCHECK_LE(0, index); // GetIndexOf is negative if not a child. | 140 DCHECK_LE(0, index); // GetIndexOf is negative if not a child. |
125 | 141 |
yoshiki
2017/04/25 03:59:11
Should we skip updating if the view is in clearing
yhanada
2017/04/25 05:38:04
Done.
| |
126 animator_.StopAnimatingView(view); | 142 animator_.StopAnimatingView(view); |
127 if (deleting_views_.find(view) != deleting_views_.end()) | 143 if (deleting_views_.find(view) != deleting_views_.end()) |
128 deleting_views_.erase(view); | 144 deleting_views_.erase(view); |
129 if (deleted_when_done_.find(view) != deleted_when_done_.end()) | 145 if (deleted_when_done_.find(view) != deleted_when_done_.end()) |
130 deleted_when_done_.erase(view); | 146 deleted_when_done_.erase(view); |
131 view->UpdateWithNotification(notification); | 147 view->UpdateWithNotification(notification); |
132 DoUpdateIfPossible(); | 148 DoUpdateIfPossible(); |
133 } | 149 } |
134 | 150 |
135 gfx::Size MessageListView::GetPreferredSize() const { | 151 gfx::Size MessageListView::GetPreferredSize() const { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 const gfx::Rect& visible_scroll_rect) { | 251 const gfx::Rect& visible_scroll_rect) { |
236 for (int i = 0; i < child_count(); ++i) { | 252 for (int i = 0; i < child_count(); ++i) { |
237 // Safe cast since all views in MessageListView are MessageViews. | 253 // Safe cast since all views in MessageListView are MessageViews. |
238 MessageView* child = (MessageView*)child_at(i); | 254 MessageView* child = (MessageView*)child_at(i); |
239 if (!child->visible()) | 255 if (!child->visible()) |
240 continue; | 256 continue; |
241 if (gfx::IntersectRects(child->bounds(), visible_scroll_rect).IsEmpty()) | 257 if (gfx::IntersectRects(child->bounds(), visible_scroll_rect).IsEmpty()) |
242 continue; | 258 continue; |
243 if (child->IsPinned()) | 259 if (child->IsPinned()) |
244 continue; | 260 continue; |
261 if (deleting_views_.find(child) != deleting_views_.end() || | |
262 deleted_when_done_.find(child) != deleted_when_done_.end()) { | |
263 // We don't check clearing_all_views_ here, so this can lead to a | |
264 // notification being deleted twice. Even if we do check it, there is a | |
265 // problem similar to the problem in RemoveNotification(), it could be | |
266 // currently in its animation before removal, and we could similarly | |
267 // delete it twice. This is a bug. | |
268 continue; | |
269 } | |
245 clearing_all_views_.push_back(child); | 270 clearing_all_views_.push_back(child); |
246 } | 271 } |
247 if (clearing_all_views_.empty()) { | 272 if (clearing_all_views_.empty()) { |
248 for (auto& observer : observers_) | 273 for (auto& observer : observers_) |
249 observer.OnAllNotificationsCleared(); | 274 observer.OnAllNotificationsCleared(); |
yoshiki
2017/04/25 03:59:11
Could you rename is_clearing_ in MessageCenterView
Eliot Courtney
2017/04/25 04:08:47
My understanding of this was that without the call
yhanada
2017/04/25 05:38:04
Renamed to is_clearing_all_notifications_.
| |
250 } else { | 275 } else { |
251 DoUpdateIfPossible(); | 276 DoUpdateIfPossible(); |
252 } | 277 } |
253 } | 278 } |
254 | 279 |
255 void MessageListView::AddObserver(MessageListView::Observer* observer) { | 280 void MessageListView::AddObserver(MessageListView::Observer* observer) { |
256 observers_.AddObserver(observer); | 281 observers_.AddObserver(observer); |
257 } | 282 } |
258 | 283 |
259 void MessageListView::RemoveObserver(MessageListView::Observer* observer) { | 284 void MessageListView::RemoveObserver(MessageListView::Observer* observer) { |
(...skipping 29 matching lines...) Expand all Loading... | |
289 if (GetWidget()) | 314 if (GetWidget()) |
290 GetWidget()->SynthesizeMouseMoveEvent(); | 315 GetWidget()->SynthesizeMouseMoveEvent(); |
291 | 316 |
292 if (quit_message_loop_after_animation_for_test_) | 317 if (quit_message_loop_after_animation_for_test_) |
293 base::MessageLoop::current()->QuitWhenIdle(); | 318 base::MessageLoop::current()->QuitWhenIdle(); |
294 } | 319 } |
295 | 320 |
296 bool MessageListView::IsValidChild(const views::View* child) const { | 321 bool MessageListView::IsValidChild(const views::View* child) const { |
297 return child->visible() && | 322 return child->visible() && |
298 deleting_views_.find(const_cast<views::View*>(child)) == | 323 deleting_views_.find(const_cast<views::View*>(child)) == |
299 deleting_views_.end() && | 324 deleting_views_.end() && |
yoshiki
2017/04/25 03:59:11
Should we check clearing_all_views_ here as well?
yhanada
2017/04/25 05:38:04
Done.
| |
300 deleted_when_done_.find(const_cast<views::View*>(child)) == | 325 deleted_when_done_.find(const_cast<views::View*>(child)) == |
301 deleted_when_done_.end(); | 326 deleted_when_done_.end(); |
302 } | 327 } |
303 | 328 |
304 void MessageListView::DoUpdateIfPossible() { | 329 void MessageListView::DoUpdateIfPossible() { |
305 gfx::Rect child_area = GetContentsBounds(); | 330 gfx::Rect child_area = GetContentsBounds(); |
306 if (child_area.IsEmpty()) | 331 if (child_area.IsEmpty()) |
307 return; | 332 return; |
308 | 333 |
309 if (animator_.IsAnimating()) { | 334 if (animator_.IsAnimating()) { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 base::TimeDelta::FromMilliseconds( | 559 base::TimeDelta::FromMilliseconds( |
535 kAnimateClearingNextNotificationDelayMS)); | 560 kAnimateClearingNextNotificationDelayMS)); |
536 } | 561 } |
537 } | 562 } |
538 | 563 |
539 void MessageListView::SetRepositionTargetForTest(const gfx::Rect& target_rect) { | 564 void MessageListView::SetRepositionTargetForTest(const gfx::Rect& target_rect) { |
540 SetRepositionTarget(target_rect); | 565 SetRepositionTarget(target_rect); |
541 } | 566 } |
542 | 567 |
543 } // namespace message_center | 568 } // namespace message_center |
OLD | NEW |