summaryrefslogtreecommitdiffstats
path: root/cc/animation/element_animations.h
blob: 17dfbd0670ecbcd103a497b5c06d9a0e84cb4e1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_ANIMATION_ELEMENT_ANIMATIONS_H_
#define CC_ANIMATION_ELEMENT_ANIMATIONS_H_

#include "base/containers/linked_list.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "cc/animation/animation_curve.h"
#include "cc/animation/animation_delegate.h"
#include "cc/animation/layer_animation_controller.h"
#include "cc/animation/layer_animation_value_provider.h"
#include "cc/base/cc_export.h"

namespace gfx {
class ScrollOffset;
class Transform;
}

namespace cc {

class AnimationHost;
class AnimationPlayer;
class FilterOperations;
class LayerAnimationController;
enum class LayerTreeType;

// An ElementAnimations owns a list of all AnimationPlayers, attached to
// the layer. Also, it owns LayerAnimationController instance (1:1
// relationship)
// ElementAnimations object redirects all events from LAC to the list
// of animation layers.
// This is a CC counterpart for blink::ElementAnimations (in 1:1 relationship).
// No pointer to/from respective blink::ElementAnimations object for now.
class CC_EXPORT ElementAnimations : public AnimationDelegate,
                                    public LayerAnimationValueProvider {
 public:
  static scoped_ptr<ElementAnimations> Create(AnimationHost* host);
  ~ElementAnimations() override;

  int layer_id() const {
    return layer_animation_controller_ ? layer_animation_controller_->id() : 0;
  }

  // Parent AnimationHost.
  AnimationHost* animation_host() { return animation_host_; }
  const AnimationHost* animation_host() const { return animation_host_; }

  LayerAnimationController* layer_animation_controller() const {
    return layer_animation_controller_.get();
  }

  void CreateLayerAnimationController(int layer_id);
  void DestroyLayerAnimationController();

  void LayerRegistered(int layer_id, LayerTreeType tree_type);
  void LayerUnregistered(int layer_id, LayerTreeType tree_type);

  bool has_active_value_observer_for_testing() const {
    return !!active_value_observer_;
  }
  bool has_pending_value_observer_for_testing() const {
    return !!pending_value_observer_;
  }

  void AddPlayer(AnimationPlayer* player);
  void RemovePlayer(AnimationPlayer* player);
  bool IsEmpty() const;

  typedef base::LinkedList<AnimationPlayer> PlayersList;
  typedef base::LinkNode<AnimationPlayer> PlayersListNode;
  const PlayersList& players_list() const { return *players_list_.get(); }

  void PushPropertiesTo(ElementAnimations* element_animations_impl);

 private:
  explicit ElementAnimations(AnimationHost* host);

  void SetFilterMutated(LayerTreeType tree_type,
                        const FilterOperations& filters);
  void SetOpacityMutated(LayerTreeType tree_type, float opacity);
  void SetTransformMutated(LayerTreeType tree_type,
                           const gfx::Transform& transform);
  void SetScrollOffsetMutated(LayerTreeType tree_type,
                              const gfx::ScrollOffset& scroll_offset);
  void SetTransformIsPotentiallyAnimatingChanged(LayerTreeType tree_type,
                                                 bool is_animating);

  void CreateActiveValueObserver();
  void DestroyActiveValueObserver();

  void CreatePendingValueObserver();
  void DestroyPendingValueObserver();

  // AnimationDelegate implementation
  void NotifyAnimationStarted(base::TimeTicks monotonic_time,
                              TargetProperty::Type target_property,
                              int group) override;
  void NotifyAnimationFinished(base::TimeTicks monotonic_time,
                               TargetProperty::Type target_property,
                               int group) override;
  void NotifyAnimationAborted(base::TimeTicks monotonic_time,
                              TargetProperty::Type target_property,
                              int group) override;
  void NotifyAnimationTakeover(base::TimeTicks monotonic_time,
                               TargetProperty::Type target_property,
                               double animation_start_time,
                               scoped_ptr<AnimationCurve> curve) override;

  // LayerAnimationValueProvider implementation.
  gfx::ScrollOffset ScrollOffsetForAnimation() const override;

  scoped_ptr<PlayersList> players_list_;

  class ValueObserver;
  scoped_ptr<ValueObserver> active_value_observer_;
  scoped_ptr<ValueObserver> pending_value_observer_;

  // LAC is owned by ElementAnimations (1:1 relationship).
  scoped_refptr<LayerAnimationController> layer_animation_controller_;
  AnimationHost* animation_host_;

  DISALLOW_COPY_AND_ASSIGN(ElementAnimations);
};

}  // namespace cc

#endif  // CC_ANIMATION_ELEMENT_ANIMATIONS_H_