layer_animation_element.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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 {
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TRANSFORM = 0,
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    BOUNDS,
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    OPACITY,
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    VISIBILITY,
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    BRIGHTNESS,
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GRAYSCALE,
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    COLOR,
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static AnimatableProperty ToAnimatableProperty(
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      cc::Animation::TargetProperty property);
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct COMPOSITOR_EXPORT TargetValue {
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TargetValue();
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Initializes the target value to match the delegate. NULL may be supplied.
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    explicit TargetValue(const LayerAnimationDelegate* delegate);
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::Rect bounds;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::Transform transform;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    float opacity;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool visibility;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    float brightness;
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    float grayscale;
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SkColor color;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef std::set<AnimatableProperty> AnimatableProperties;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LayerAnimationElement(const AnimatableProperties& properties,
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        base::TimeDelta duration);
6158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~LayerAnimationElement();
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given transform. The caller owns
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the return value.
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateTransformElement(
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const gfx::Transform& transform,
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Creates an element that counters a transition to the given transform.
7158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // This element maintains the invariant uninverted_transition->at(t) *
7258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // this->at(t) == base_transform * this->at(t_start) for any t. The caller
7358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // owns the return value.
7458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  static LayerAnimationElement* CreateInverseTransformElement(
7558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const gfx::Transform& base_transform,
7658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      const LayerAnimationElement* uninverted_transition);
7758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
79d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Duplicates elements as created by CreateInverseTransformElement.
80d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  static LayerAnimationElement* CloneInverseTransformElement(
81d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      const LayerAnimationElement* other);
82d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to another in a way determined by an
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // interpolated transform. The element accepts ownership of the interpolated
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // transform. NB: at every step, the interpolated transform clobbers the
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // existing transform. That is, it does not interpolate between the existing
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // transform and the last value the interpolated transform will assume. It is
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // therefore important that the value of the interpolated at time 0 matches
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the current transform.
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateInterpolatedTransformElement(
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      InterpolatedTransform* interpolated_transform,
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given bounds. The caller owns
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the return value.
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateBoundsElement(
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const gfx::Rect& bounds,
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given opacity. The caller owns
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the return value.
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateOpacityElement(
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      float opacity,
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that sets visibily following a delay. The caller owns
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the return value.
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateVisibilityElement(
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      bool visibility,
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given brightness.
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The caller owns the return value.
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateBrightnessElement(
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      float brightness,
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given grayscale value.
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The caller owns the return value.
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateGrayscaleElement(
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      float grayscale,
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that pauses the given properties. The caller owns the
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // return value.
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreatePauseElement(
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const AnimatableProperties& properties,
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates an element that transitions to the given color. The caller owns the
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // return value.
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static LayerAnimationElement* CreateColorElement(
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      SkColor color,
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::TimeDelta duration);
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets the start time for the animation. This must be called before the first
1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // call to {Start, IsFinished}. Once the animation is finished, this must
1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // be called again in order to restart the animation.
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_requested_start_time(base::TimeTicks start_time) {
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    requested_start_time_ = start_time;
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeTicks requested_start_time() const { return requested_start_time_; }
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets the actual start time for the animation, taking into account any
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // queueing delays.
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_effective_start_time(base::TimeTicks start_time) {
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    effective_start_time_ = start_time;
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeTicks effective_start_time() const { return effective_start_time_; }
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This must be called before the first call to Progress. If starting the
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // animation involves dispatching to another thread, then this will proceed
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // with that dispatch, ultimately resulting in the animation getting an
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // effective start time (the time the animation starts on the other thread).
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void Start(LayerAnimationDelegate* delegate, int animation_group_id);
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns true if the animation has started but hasn't finished.
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool Started() { return !first_frame_; }
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Updates the delegate to the appropriate value for |now|. Returns true
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // if a redraw is required.
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool Progress(base::TimeTicks now, LayerAnimationDelegate* delegate);
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If calling Progress now, with the given time, will finish the animation,
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // returns true and sets |end_duration| to the actual duration for this
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // animation, incuding any queueing delays.
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool IsFinished(base::TimeTicks time, base::TimeDelta* total_duration);
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Updates the delegate to the end of the animation. Returns true if a
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // redraw is required.
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool ProgressToEnd(LayerAnimationDelegate* delegate);
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called if the animation is not allowed to complete. This may be called
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // before OnStarted or Progress.
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void Abort(LayerAnimationDelegate* delegate);
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Assigns the target value to |target|.
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetTargetValue(TargetValue* target) const;
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The properties that the element modifies.
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const AnimatableProperties& properties() const { return properties_; }
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Whether this element animates on the compositor thread.
1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool IsThreaded() const;
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
186d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  gfx::Tween::Type tween_type() const { return tween_type_; }
187d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  void set_tween_type(gfx::Tween::Type tween_type) { tween_type_ = tween_type; }
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Each LayerAnimationElement has a unique animation_id. Elements belonging
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // to sequences that are supposed to start together have the same
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // animation_group_id.
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int animation_id() const { return animation_id_; }
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int animation_group_id() const { return animation_group_id_; }
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void set_animation_group_id(int id) { animation_group_id_ = id; }
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
19658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  base::TimeDelta duration() const { return duration_; }
19758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The fraction of the animation that has been completed after the last
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // call made to {Progress, ProgressToEnd}.
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  double last_progressed_fraction() const { return last_progressed_fraction_; }
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called once each time the animation element is run before any call to
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // OnProgress.
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnStart(LayerAnimationDelegate* delegate) = 0;
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) = 0;
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnGetTarget(TargetValue* target) const = 0;
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnAbort(LayerAnimationDelegate* delegate) = 0;
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Actually start the animation, dispatching to another thread if needed.
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RequestEffectiveStart(LayerAnimationDelegate* delegate);
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
21358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  LayerAnimationElement(const LayerAnimationElement& element);
21458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For debugging purposes, we sometimes alter the duration we actually use.
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For example, during tests we often set duration = 0, and it is sometimes
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // useful to slow animations down to see them more clearly.
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeDelta GetEffectiveDuration(const base::TimeDelta& delta);
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool first_frame_;
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const AnimatableProperties properties_;
2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeTicks requested_start_time_;
2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // When the animation actually started, taking into account queueing delays.
2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeTicks effective_start_time_;
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::TimeDelta duration_;
228d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  gfx::Tween::Type tween_type_;
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const int animation_id_;
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int animation_group_id_;
2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  double last_progressed_fraction_;
2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  base::WeakPtrFactory<LayerAnimationElement> weak_ptr_factory_;
2364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
23758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  DISALLOW_ASSIGN(LayerAnimationElement);
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ui
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // UI_COMPOSITOR_LAYER_ANIMATION_ELEMENT_H_
243