15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <set>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/memory/weak_ptr.h"
11eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/animation/animation.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/animation/animation_events.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/compositor_export.h"
16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/animation/tween.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/transform.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InterpolatedTransform;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LayerAnimationDelegate;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LayerAnimationElements represent one segment of an animation between two
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// keyframes. They know how to update a LayerAnimationDelegate given a value
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// between 0 and 1 (0 for initial, and 1 for final).
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class COMPOSITOR_EXPORT LayerAnimationElement {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum AnimatableProperty {
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    UNKNOWN = 0,
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    TRANSFORM = (1 << 0),
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    BOUNDS = (1 << 1),
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    OPACITY = (1 << 2),
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    VISIBILITY = (1 << 3),
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    BRIGHTNESS = (1 << 4),
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    GRAYSCALE = (1 << 5),
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    COLOR = (1 << 6),
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Used when iterating over properties.
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    FIRST_PROPERTY = TRANSFORM,
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    SENTINEL = (1 << 7)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static AnimatableProperty ToAnimatableProperty(
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cc::Animation::TargetProperty property);
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct COMPOSITOR_EXPORT TargetValue {
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TargetValue();
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Initializes the target value to match the delegate. NULL may be supplied.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    explicit TargetValue(const LayerAnimationDelegate* delegate);
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::Rect bounds;
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::Transform transform;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    float opacity;
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool visibility;
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    float brightness;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    float grayscale;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SkColor color;
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  typedef uint32 AnimatableProperties;
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LayerAnimationElement(AnimatableProperties properties,
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        base::TimeDelta duration);
6658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~LayerAnimationElement();
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given transform. The caller owns
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the return value.
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateTransformElement(
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const gfx::Transform& transform,
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Creates an element that counters a transition to the given transform.
7658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // This element maintains the invariant uninverted_transition->at(t) *
7758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // this->at(t) == base_transform * this->at(t_start) for any t. The caller
7858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // owns the return value.
7958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static LayerAnimationElement* CreateInverseTransformElement(
8058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const gfx::Transform& base_transform,
8158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const LayerAnimationElement* uninverted_transition);
8258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
83d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
84d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Duplicates elements as created by CreateInverseTransformElement.
85d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  static LayerAnimationElement* CloneInverseTransformElement(
86d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      const LayerAnimationElement* other);
87d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to another in a way determined by an
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // interpolated transform. The element accepts ownership of the interpolated
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // transform. NB: at every step, the interpolated transform clobbers the
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // existing transform. That is, it does not interpolate between the existing
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // transform and the last value the interpolated transform will assume. It is
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // therefore important that the value of the interpolated at time 0 matches
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the current transform.
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateInterpolatedTransformElement(
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      InterpolatedTransform* interpolated_transform,
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given bounds. The caller owns
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the return value.
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateBoundsElement(
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const gfx::Rect& bounds,
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given opacity. The caller owns
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the return value.
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateOpacityElement(
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      float opacity,
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that sets visibily following a delay. The caller owns
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the return value.
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateVisibilityElement(
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      bool visibility,
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given brightness.
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The caller owns the return value.
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateBrightnessElement(
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      float brightness,
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given grayscale value.
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The caller owns the return value.
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateGrayscaleElement(
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      float grayscale,
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that pauses the given properties. The caller owns the
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // return value.
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreatePauseElement(
1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      AnimatableProperties properties,
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given color. The caller owns the
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // return value.
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateColorElement(
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      SkColor color,
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets the start time for the animation. This must be called before the first
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // call to {Start, IsFinished}. Once the animation is finished, this must
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // be called again in order to restart the animation.
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_requested_start_time(base::TimeTicks start_time) {
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    requested_start_time_ = start_time;
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeTicks requested_start_time() const { return requested_start_time_; }
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets the actual start time for the animation, taking into account any
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // queueing delays.
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_effective_start_time(base::TimeTicks start_time) {
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    effective_start_time_ = start_time;
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeTicks effective_start_time() const { return effective_start_time_; }
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This must be called before the first call to Progress. If starting the
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // animation involves dispatching to another thread, then this will proceed
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // with that dispatch, ultimately resulting in the animation getting an
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // effective start time (the time the animation starts on the other thread).
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void Start(LayerAnimationDelegate* delegate, int animation_group_id);
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if the animation has started but hasn't finished.
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool Started() { return !first_frame_; }
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Updates the delegate to the appropriate value for |now|. Returns true
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // if a redraw is required.
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool Progress(base::TimeTicks now, LayerAnimationDelegate* delegate);
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If calling Progress now, with the given time, will finish the animation,
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // returns true and sets |end_duration| to the actual duration for this
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // animation, incuding any queueing delays.
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool IsFinished(base::TimeTicks time, base::TimeDelta* total_duration);
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Updates the delegate to the end of the animation. Returns true if a
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // redraw is required.
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool ProgressToEnd(LayerAnimationDelegate* delegate);
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called if the animation is not allowed to complete. This may be called
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // before OnStarted or Progress.
1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void Abort(LayerAnimationDelegate* delegate);
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Assigns the target value to |target|.
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetTargetValue(TargetValue* target) const;
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The properties that the element modifies.
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AnimatableProperties properties() const { return properties_; }
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Whether this element animates on the compositor thread.
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool IsThreaded() const;
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
191d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  gfx::Tween::Type tween_type() const { return tween_type_; }
192d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  void set_tween_type(gfx::Tween::Type tween_type) { tween_type_ = tween_type; }
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Each LayerAnimationElement has a unique animation_id. Elements belonging
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // to sequences that are supposed to start together have the same
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // animation_group_id.
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int animation_id() const { return animation_id_; }
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int animation_group_id() const { return animation_group_id_; }
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_animation_group_id(int id) { animation_group_id_ = id; }
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
20158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  base::TimeDelta duration() const { return duration_; }
20258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The fraction of the animation that has been completed after the last
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // call made to {Progress, ProgressToEnd}.
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  double last_progressed_fraction() const { return last_progressed_fraction_; }
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called once each time the animation element is run before any call to
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // OnProgress.
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) = 0;
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) = 0;
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const = 0;
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) = 0;
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Actually start the animation, dispatching to another thread if needed.
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RequestEffectiveStart(LayerAnimationDelegate* delegate);
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
21858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  LayerAnimationElement(const LayerAnimationElement& element);
21958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For debugging purposes, we sometimes alter the duration we actually use.
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For example, during tests we often set duration = 0, and it is sometimes
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // useful to slow animations down to see them more clearly.
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeDelta GetEffectiveDuration(const base::TimeDelta& delta);
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool first_frame_;
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const AnimatableProperties properties_;
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeTicks requested_start_time_;
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // When the animation actually started, taking into account queueing delays.
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeTicks effective_start_time_;
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::TimeDelta duration_;
233d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  gfx::Tween::Type tween_type_;
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const int animation_id_;
2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int animation_group_id_;
2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  double last_progressed_fraction_;
2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::WeakPtrFactory<LayerAnimationElement> weak_ptr_factory_;
2414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
24258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  DISALLOW_ASSIGN(LayerAnimationElement);
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ui
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_
248