OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/animation/slide_animation.h" | 5 #include "ui/gfx/animation/slide_animation.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/auto_reset.h" | |
10 #include "ui/gfx/animation/animation_delegate.h" | |
11 | |
9 namespace gfx { | 12 namespace gfx { |
10 | 13 |
11 // How long animations should take by default. | 14 // How long animations should take by default. |
12 static const int kDefaultDurationMs = 120; | 15 static const int kDefaultDurationMs = 120; |
13 | 16 |
14 SlideAnimation::SlideAnimation(AnimationDelegate* target) | 17 SlideAnimation::SlideAnimation(AnimationDelegate* target) |
15 : LinearAnimation(target), | 18 : LinearAnimation(target), |
16 target_(target), | 19 target_(target), |
17 tween_type_(Tween::EASE_OUT), | 20 tween_type_(Tween::EASE_OUT), |
18 showing_(false), | 21 showing_(false), |
(...skipping 20 matching lines...) Expand all Loading... | |
39 if (showing_) | 42 if (showing_) |
40 return; | 43 return; |
41 | 44 |
42 showing_ = true; | 45 showing_ = true; |
43 value_start_ = value_current_; | 46 value_start_ = value_current_; |
44 value_end_ = 1.0; | 47 value_end_ = 1.0; |
45 | 48 |
46 // Make sure we actually have something to do. | 49 // Make sure we actually have something to do. |
47 if (slide_duration_ == 0) { | 50 if (slide_duration_ == 0) { |
48 AnimateToState(1.0); // Skip to the end of the animation. | 51 AnimateToState(1.0); // Skip to the end of the animation. |
52 if (delegate()) | |
53 delegate()->AnimationProgressed(this); | |
James Cook
2017/02/08 00:31:28
Do you know offhand if any of Chrome's other users
bruthig
2017/02/10 18:49:10
I did a quick audit and it appears there might be
| |
49 return; | 54 return; |
50 } else if (value_current_ == value_end_) { | 55 } else if (value_current_ == value_end_) { |
51 return; | 56 return; |
52 } | 57 } |
53 | 58 |
54 // This will also reset the currently-occurring animation. | 59 // This will also reset the currently-occurring animation. |
55 SetDuration(static_cast<int>(slide_duration_ * (1 - value_current_))); | 60 SetDuration(static_cast<int>(slide_duration_ * (1 - value_current_))); |
56 Start(); | 61 Start(); |
57 } | 62 } |
58 | 63 |
64 void SlideAnimation::ShowImmediately() { | |
65 base::AutoReset<int> auto_reset_duration(&slide_duration_, 0); | |
66 Show(); | |
67 } | |
68 | |
59 void SlideAnimation::Hide() { | 69 void SlideAnimation::Hide() { |
60 // If we're already hiding (or hidden), we have nothing to do. | 70 // If we're already hiding (or hidden), we have nothing to do. |
61 if (!showing_) | 71 if (!showing_) |
62 return; | 72 return; |
63 | 73 |
64 showing_ = false; | 74 showing_ = false; |
65 value_start_ = value_current_; | 75 value_start_ = value_current_; |
66 value_end_ = 0.0; | 76 value_end_ = 0.0; |
67 | 77 |
68 // Make sure we actually have something to do. | 78 // Make sure we actually have something to do. |
69 if (slide_duration_ == 0) { | 79 if (slide_duration_ == 0) { |
70 AnimateToState(0.0); // Skip to the end of the animation. | 80 AnimateToState(1.0); // Skip to the end of the animation. |
81 if (delegate()) | |
82 delegate()->AnimationProgressed(this); | |
71 return; | 83 return; |
72 } else if (value_current_ == value_end_) { | 84 } else if (value_current_ == value_end_) { |
73 return; | 85 return; |
74 } | 86 } |
75 | 87 |
76 // This will also reset the currently-occurring animation. | 88 // This will also reset the currently-occurring animation. |
77 SetDuration(static_cast<int>(slide_duration_ * value_current_)); | 89 SetDuration(static_cast<int>(slide_duration_ * value_current_)); |
78 Start(); | 90 Start(); |
79 } | 91 } |
80 | 92 |
93 void SlideAnimation::HideImmediately() { | |
94 base::AutoReset<int> auto_reset_duration(&slide_duration_, 0); | |
95 Hide(); | |
96 } | |
97 | |
81 void SlideAnimation::SetSlideDuration(int duration) { | 98 void SlideAnimation::SetSlideDuration(int duration) { |
82 slide_duration_ = duration; | 99 slide_duration_ = duration; |
83 } | 100 } |
84 | 101 |
85 double SlideAnimation::GetCurrentValue() const { | 102 double SlideAnimation::GetCurrentValue() const { |
86 return value_current_; | 103 return value_current_; |
87 } | 104 } |
88 | 105 |
89 void SlideAnimation::AnimateToState(double state) { | 106 void SlideAnimation::AnimateToState(double state) { |
90 if (state > 1.0) | 107 if (state > 1.0) |
(...skipping 10 matching lines...) Expand all Loading... | |
101 | 118 |
102 // Correct for any overshoot (while state may be capped at 1.0, let's not | 119 // Correct for any overshoot (while state may be capped at 1.0, let's not |
103 // take any rounding error chances. | 120 // take any rounding error chances. |
104 if ((value_end_ >= value_start_ && value_current_ > value_end_) || | 121 if ((value_end_ >= value_start_ && value_current_ > value_end_) || |
105 (value_end_ < value_start_ && value_current_ < value_end_)) { | 122 (value_end_ < value_start_ && value_current_ < value_end_)) { |
106 value_current_ = value_end_; | 123 value_current_ = value_end_; |
107 } | 124 } |
108 } | 125 } |
109 | 126 |
110 } // namespace gfx | 127 } // namespace gfx |
OLD | NEW |