File: linear_animation.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (89 lines) | stat: -rw-r--r-- 2,967 bytes parent folder | download | duplicates (9)
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
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_ANIMATION_LINEAR_ANIMATION_H_
#define UI_GFX_ANIMATION_LINEAR_ANIMATION_H_

#include "base/time/time.h"
#include "ui/gfx/animation/animation.h"

namespace gfx {

class AnimationDelegate;

// Linear time bounded animation. As the animation progresses AnimateToState is
// invoked.
class ANIMATION_EXPORT LinearAnimation : public Animation {
 public:
  // Default frame rate (hz).
  static const int kDefaultFrameRate;

  // Initializes everything except the duration.
  //
  // Caller must make sure to call SetDuration() if they use this
  // constructor; it is preferable to use the full one, but sometimes
  // duration can change between calls to Start() and we need to
  // expose this interface.
  explicit LinearAnimation(AnimationDelegate* delegate,
                           int frame_rate = kDefaultFrameRate);

  // Initializes all fields.
  LinearAnimation(base::TimeDelta duration,
                  int frame_rate,
                  AnimationDelegate* delegate);

  LinearAnimation(const LinearAnimation&) = delete;
  LinearAnimation& operator=(const LinearAnimation&) = delete;

  // Gets the value for the current state, according to the animation curve in
  // use. This class provides only for a linear relationship, however subclasses
  // can override this to provide others.
  double GetCurrentValue() const override;

  // Change the current state of the animation to |new_value|.
  void SetCurrentValue(double new_value);

  // Skip to the end of the current animation.
  void End();

  // Changes the length of the animation. This resets the current
  // state of the animation to the beginning. This value will be multiplied by
  // the currently set scale factor.
  void SetDuration(base::TimeDelta duration);

 protected:
  // Called when the animation progresses. Subclasses override this to
  // efficiently update their state.
  virtual void AnimateToState(double state) {}

  // Invoked by the AnimationContainer when the animation is running to advance
  // the animation. Use |time_now| rather than Time::Now to avoid multiple
  // animations running at the same time diverging.
  void Step(base::TimeTicks time_now) override;

  // Overriden to initialize state.
  void AnimationStarted() override;

  // Overriden to advance to the end (if End was invoked).
  void AnimationStopped() override;

  // Overriden to return true if state is not 1.
  bool ShouldSendCanceledFromStop() override;

  base::TimeDelta duration() const { return duration_; }

 private:
  base::TimeDelta duration_;

  // Current state, on a scale from 0.0 to 1.0.
  double state_;

  // If true, we're in end. This is used to determine if the animation should
  // be advanced to the end from AnimationStopped.
  bool in_end_;
};

}  // namespace gfx

#endif  // UI_GFX_ANIMATION_LINEAR_ANIMATION_H_