MD Downloads: prevent search text from overlapping with the cancel search (X)
[chromium-blink-merge.git] / ui / compositor / layer_animator_collection.cc
blobce4d70874d805d5d8353b029fe00cf589c359e4b
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/compositor/layer_animator_collection.h"
7 #include <set>
9 #include "base/time/time.h"
10 #include "ui/compositor/compositor.h"
11 #include "ui/compositor/layer_animator.h"
13 namespace ui {
15 LayerAnimatorCollection::LayerAnimatorCollection(Compositor* compositor)
16 : compositor_(compositor), last_tick_time_(base::TimeTicks::Now()) {
19 LayerAnimatorCollection::~LayerAnimatorCollection() {
20 if (compositor_)
21 compositor_->RemoveAnimationObserver(this);
24 void LayerAnimatorCollection::StartAnimator(
25 scoped_refptr<LayerAnimator> animator) {
26 DCHECK_EQ(0U, animators_.count(animator));
27 if (!animators_.size())
28 last_tick_time_ = base::TimeTicks::Now();
29 animators_.insert(animator);
30 if (animators_.size() == 1U && compositor_)
31 compositor_->AddAnimationObserver(this);
34 void LayerAnimatorCollection::StopAnimator(
35 scoped_refptr<LayerAnimator> animator) {
36 DCHECK_GT(animators_.count(animator), 0U);
37 animators_.erase(animator);
38 if (animators_.empty() && compositor_)
39 compositor_->RemoveAnimationObserver(this);
42 bool LayerAnimatorCollection::HasActiveAnimators() const {
43 return !animators_.empty();
46 void LayerAnimatorCollection::OnAnimationStep(base::TimeTicks now) {
47 last_tick_time_ = now;
48 std::set<scoped_refptr<LayerAnimator> > list = animators_;
49 for (std::set<scoped_refptr<LayerAnimator> >::iterator iter = list.begin();
50 iter != list.end();
51 ++iter) {
52 // Make sure the animator is still valid.
53 if (animators_.count(*iter) > 0)
54 (*iter)->Step(now);
56 if (!HasActiveAnimators() && compositor_)
57 compositor_->RemoveAnimationObserver(this);
60 void LayerAnimatorCollection::OnCompositingShuttingDown(
61 Compositor* compositor) {
62 DCHECK_EQ(compositor_, compositor);
63 compositor_->RemoveAnimationObserver(this);
64 compositor_ = nullptr;
67 } // namespace ui