OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/compositor/layer_animator.h" | 5 #include "ui/compositor/layer_animator.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "ui/base/animation/animation_container.h" | 10 #include "ui/base/animation/animation_container.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 // Returns the AnimationContainer we're added to. | 38 // Returns the AnimationContainer we're added to. |
39 ui::AnimationContainer* GetAnimationContainer() { | 39 ui::AnimationContainer* GetAnimationContainer() { |
40 static ui::AnimationContainer* container = NULL; | 40 static ui::AnimationContainer* container = NULL; |
41 if (!container) { | 41 if (!container) { |
42 container = new AnimationContainer(); | 42 container = new AnimationContainer(); |
43 container->AddRef(); | 43 container->AddRef(); |
44 } | 44 } |
45 return container; | 45 return container; |
46 } | 46 } |
47 | 47 |
48 class SuccessCallbackAnimationObserver : public LayerAnimationObserver { | |
49 public: | |
50 SuccessCallbackAnimationObserver(base::Closure callback) | |
51 : callback_(callback), | |
52 num_attached_sequences_(0) { | |
53 } | |
54 | |
55 virtual void OnLayerAnimationEnded(LayerAnimationSequence* sequence) { | |
Daniel Erat
2012/11/27 19:03:27
nit: add OVERRIDE to all overridden methods, along
Denis Kuznetsov (DE-MUC)
2012/11/28 15:41:46
Done.
| |
56 callback_.Run(); | |
57 callback_.Reset(); | |
58 } | |
59 | |
60 virtual void OnLayerAnimationAborted( | |
61 LayerAnimationSequence* sequence) {} | |
62 | |
63 virtual void OnLayerAnimationScheduled( | |
64 LayerAnimationSequence* sequence) {} | |
65 | |
66 private: | |
67 virtual void OnAttachedToSequence(LayerAnimationSequence* sequence) { | |
68 num_attached_sequences_++; | |
69 } | |
70 | |
71 virtual void OnDetachedFromSequence(LayerAnimationSequence* sequence) { | |
72 num_attached_sequences_--; | |
73 if (num_attached_sequences_ == 0) | |
74 delete this; | |
75 } | |
76 | |
77 base::Closure callback_; | |
78 int num_attached_sequences_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(SuccessCallbackAnimationObserver); | |
81 }; | |
82 | |
48 } // namespace | 83 } // namespace |
49 | 84 |
50 // static | 85 // static |
51 bool LayerAnimator::disable_animations_for_test_ = false; | 86 bool LayerAnimator::disable_animations_for_test_ = false; |
52 // static | 87 // static |
53 bool LayerAnimator::slow_animation_mode_ = false; | 88 bool LayerAnimator::slow_animation_mode_ = false; |
54 // static | 89 // static |
55 int LayerAnimator::slow_animation_scale_factor_ = 4; | 90 int LayerAnimator::slow_animation_scale_factor_ = 4; |
56 | 91 |
57 // LayerAnimator public -------------------------------------------------------- | 92 // LayerAnimator public -------------------------------------------------------- |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 for (int p = static_cast<int>(property); p != -1; p = va_arg(marker, int)) { | 286 for (int p = static_cast<int>(property); p != -1; p = va_arg(marker, int)) { |
252 properties_to_pause.insert( | 287 properties_to_pause.insert( |
253 static_cast<LayerAnimationElement::AnimatableProperty>(p)); | 288 static_cast<LayerAnimationElement::AnimatableProperty>(p)); |
254 } | 289 } |
255 va_end(marker); | 290 va_end(marker); |
256 ScheduleAnimation(new ui::LayerAnimationSequence( | 291 ScheduleAnimation(new ui::LayerAnimationSequence( |
257 ui::LayerAnimationElement::CreatePauseElement( | 292 ui::LayerAnimationElement::CreatePauseElement( |
258 properties_to_pause, duration))); | 293 properties_to_pause, duration))); |
259 } | 294 } |
260 | 295 |
296 void LayerAnimator::SetCompletionCallbackForProperties( | |
297 base::Closure& callback, | |
298 LayerAnimationElement::AnimatableProperty property, | |
299 ...) { | |
300 ui::LayerAnimationElement::AnimatableProperties properties_to_pause; | |
301 va_list marker; | |
302 va_start(marker, property); | |
303 for (int p = static_cast<int>(property); p != -1; p = va_arg(marker, int)) { | |
304 properties_to_pause.insert( | |
305 static_cast<LayerAnimationElement::AnimatableProperty>(p)); | |
306 } | |
307 va_end(marker); | |
308 | |
309 ui::LayerAnimationSequence* sequence = new ui::LayerAnimationSequence( | |
310 ui::LayerAnimationElement::CreatePauseElement( | |
311 properties_to_pause, base::TimeDelta())); | |
312 | |
313 sequence->AddObserver(new SuccessCallbackAnimationObserver(callback)); | |
314 | |
315 ScheduleAnimation(sequence); | |
316 } | |
317 | |
261 bool LayerAnimator::IsAnimatingProperty( | 318 bool LayerAnimator::IsAnimatingProperty( |
262 LayerAnimationElement::AnimatableProperty property) const { | 319 LayerAnimationElement::AnimatableProperty property) const { |
263 for (AnimationQueue::const_iterator queue_iter = animation_queue_.begin(); | 320 for (AnimationQueue::const_iterator queue_iter = animation_queue_.begin(); |
264 queue_iter != animation_queue_.end(); ++queue_iter) { | 321 queue_iter != animation_queue_.end(); ++queue_iter) { |
265 if ((*queue_iter)->properties().find(property) != | 322 if ((*queue_iter)->properties().find(property) != |
266 (*queue_iter)->properties().end()) { | 323 (*queue_iter)->properties().end()) { |
267 return true; | 324 return true; |
268 } | 325 } |
269 } | 326 } |
270 return false; | 327 return false; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 const bool abort = false; | 590 const bool abort = false; |
534 RemoveAllAnimationsWithACommonProperty(sequence, abort); | 591 RemoveAllAnimationsWithACommonProperty(sequence, abort); |
535 if (!weak_sequence_ptr) | 592 if (!weak_sequence_ptr) |
536 return; | 593 return; |
537 | 594 |
538 LayerAnimationSequence* removed = RemoveAnimation(sequence); | 595 LayerAnimationSequence* removed = RemoveAnimation(sequence); |
539 DCHECK(removed == NULL || removed == sequence); | 596 DCHECK(removed == NULL || removed == sequence); |
540 if (!weak_sequence_ptr) | 597 if (!weak_sequence_ptr) |
541 return; | 598 return; |
542 | 599 |
543 ProgressAnimation(sequence, sequence->duration()); | 600 ProgressAnimationToEnd(sequence); |
544 if (!weak_sequence_ptr) | 601 if (!weak_sequence_ptr) |
545 return; | 602 return; |
546 | 603 |
547 delete sequence; | 604 delete sequence; |
548 } | 605 } |
549 | 606 |
550 void LayerAnimator::ImmediatelyAnimateToNewTarget( | 607 void LayerAnimator::ImmediatelyAnimateToNewTarget( |
551 LayerAnimationSequence* sequence) { | 608 LayerAnimationSequence* sequence) { |
552 // Need to detect if our sequence gets destroyed. | 609 // Need to detect if our sequence gets destroyed. |
553 base::WeakPtr<LayerAnimationSequence> weak_sequence_ptr = | 610 base::WeakPtr<LayerAnimationSequence> weak_sequence_ptr = |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 LayerAnimator::RunningAnimation::RunningAnimation( | 806 LayerAnimator::RunningAnimation::RunningAnimation( |
750 const base::WeakPtr<LayerAnimationSequence>& sequence, | 807 const base::WeakPtr<LayerAnimationSequence>& sequence, |
751 base::TimeTicks start_time) | 808 base::TimeTicks start_time) |
752 : sequence_(sequence), | 809 : sequence_(sequence), |
753 start_time_(start_time) { | 810 start_time_(start_time) { |
754 } | 811 } |
755 | 812 |
756 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 813 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
757 | 814 |
758 } // namespace ui | 815 } // namespace ui |
OLD | NEW |