| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/location.h" | 6 #include "base/location.h" |
| 7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "ui/gfx/animation/slide_animation.h" | 9 #include "ui/gfx/animation/slide_animation.h" |
| 10 #include "ui/message_center/message_center_style.h" | 10 #include "ui/message_center/message_center_style.h" |
| 11 #include "ui/message_center/message_center_switches.h" | 11 #include "ui/message_center/message_center_switches.h" |
| 12 #include "ui/message_center/views/message_center_view.h" | 12 #include "ui/message_center/views/message_center_view.h" |
| 13 #include "ui/message_center/views/message_list_view.h" | 13 #include "ui/message_center/views/message_list_view.h" |
| 14 #include "ui/message_center/views/message_view.h" | 14 #include "ui/message_center/views/message_view.h" |
| 15 #include "ui/views/background.h" | 15 #include "ui/views/background.h" |
| 16 #include "ui/views/border.h" | 16 #include "ui/views/border.h" |
| 17 #include "ui/views/layout/box_layout.h" | 17 #include "ui/views/layout/box_layout.h" |
| 18 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 19 | 19 |
| 20 namespace message_center { | 20 namespace message_center { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 const int kAnimateClearingNextNotificationDelayMS = 40; | 23 const int kAnimateClearingNextNotificationDelayMS = 40; |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 MessageListView::MessageListView(MessageCenterView* message_center_view, | 26 MessageListView::MessageListView(bool top_down) |
| 27 bool top_down) | 27 : reposition_top_(-1), |
| 28 : message_center_view_(message_center_view), | |
| 29 reposition_top_(-1), | |
| 30 fixed_height_(0), | 28 fixed_height_(0), |
| 31 has_deferred_task_(false), | 29 has_deferred_task_(false), |
| 32 clear_all_started_(false), | 30 clear_all_started_(false), |
| 33 top_down_(top_down), | 31 top_down_(top_down), |
| 34 animator_(this), | 32 animator_(this), |
| 35 quit_message_loop_after_animation_for_test_(false), | 33 quit_message_loop_after_animation_for_test_(false), |
| 36 weak_ptr_factory_(this) { | 34 weak_ptr_factory_(this) { |
| 37 views::BoxLayout* layout = | 35 views::BoxLayout* layout = |
| 38 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1); | 36 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1); |
| 39 layout->SetDefaultFlex(1); | 37 layout->SetDefaultFlex(1); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 MessageView* child = (MessageView*)child_at(i); | 200 MessageView* child = (MessageView*)child_at(i); |
| 203 if (!child->visible()) | 201 if (!child->visible()) |
| 204 continue; | 202 continue; |
| 205 if (gfx::IntersectRects(child->bounds(), visible_scroll_rect).IsEmpty()) | 203 if (gfx::IntersectRects(child->bounds(), visible_scroll_rect).IsEmpty()) |
| 206 continue; | 204 continue; |
| 207 if (child->IsPinned()) | 205 if (child->IsPinned()) |
| 208 continue; | 206 continue; |
| 209 clearing_all_views_.push_back(child); | 207 clearing_all_views_.push_back(child); |
| 210 } | 208 } |
| 211 if (clearing_all_views_.empty()) { | 209 if (clearing_all_views_.empty()) { |
| 212 message_center_view()->OnAllNotificationsCleared(); | 210 for (auto& observer : observers_) |
| 211 observer.OnAllNotificationsCleared(); |
| 213 } else { | 212 } else { |
| 214 DoUpdateIfPossible(); | 213 DoUpdateIfPossible(); |
| 215 } | 214 } |
| 216 } | 215 } |
| 217 | 216 |
| 217 void MessageListView::AddObserver(MessageListView::Observer* observer) { |
| 218 observers_.AddObserver(observer); |
| 219 } |
| 220 |
| 221 void MessageListView::RemoveObserver(MessageListView::Observer* observer) { |
| 222 observers_.RemoveObserver(observer); |
| 223 } |
| 224 |
| 218 void MessageListView::OnBoundsAnimatorProgressed( | 225 void MessageListView::OnBoundsAnimatorProgressed( |
| 219 views::BoundsAnimator* animator) { | 226 views::BoundsAnimator* animator) { |
| 220 DCHECK_EQ(&animator_, animator); | 227 DCHECK_EQ(&animator_, animator); |
| 221 for (auto view : deleted_when_done_) { | 228 for (auto view : deleted_when_done_) { |
| 222 const gfx::SlideAnimation* animation = animator->GetAnimationForView(view); | 229 const gfx::SlideAnimation* animation = animator->GetAnimationForView(view); |
| 223 if (animation) | 230 if (animation) |
| 224 view->layer()->SetOpacity(animation->CurrentValueBetween(1.0, 0.0)); | 231 view->layer()->SetOpacity(animation->CurrentValueBetween(1.0, 0.0)); |
| 225 } | 232 } |
| 226 } | 233 } |
| 227 | 234 |
| 228 void MessageListView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { | 235 void MessageListView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
| 229 for (auto view : deleted_when_done_) | 236 for (auto view : deleted_when_done_) |
| 230 delete view; | 237 delete view; |
| 231 deleted_when_done_.clear(); | 238 deleted_when_done_.clear(); |
| 232 | 239 |
| 233 if (clear_all_started_) { | 240 if (clear_all_started_) { |
| 234 clear_all_started_ = false; | 241 clear_all_started_ = false; |
| 235 message_center_view()->OnAllNotificationsCleared(); | 242 for (auto& observer : observers_) |
| 243 observer.OnAllNotificationsCleared(); |
| 236 } | 244 } |
| 237 | 245 |
| 238 if (has_deferred_task_) { | 246 if (has_deferred_task_) { |
| 239 has_deferred_task_ = false; | 247 has_deferred_task_ = false; |
| 240 DoUpdateIfPossible(); | 248 DoUpdateIfPossible(); |
| 241 } | 249 } |
| 242 | 250 |
| 243 if (GetWidget()) | 251 if (GetWidget()) |
| 244 GetWidget()->SynthesizeMouseMoveEvent(); | 252 GetWidget()->SynthesizeMouseMoveEvent(); |
| 245 | 253 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 base::TimeDelta::FromMilliseconds( | 473 base::TimeDelta::FromMilliseconds( |
| 466 kAnimateClearingNextNotificationDelayMS)); | 474 kAnimateClearingNextNotificationDelayMS)); |
| 467 } | 475 } |
| 468 } | 476 } |
| 469 | 477 |
| 470 void MessageListView::SetRepositionTargetForTest(const gfx::Rect& target_rect) { | 478 void MessageListView::SetRepositionTargetForTest(const gfx::Rect& target_rect) { |
| 471 SetRepositionTarget(target_rect); | 479 SetRepositionTarget(target_rect); |
| 472 } | 480 } |
| 473 | 481 |
| 474 } // namespace message_center | 482 } // namespace message_center |
| OLD | NEW |