Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: ui/gfx/animation/linear_animation.cc

Issue 2329633003: Implement progress bar spec (determinate and indeterminate). (Closed)
Patch Set: sky review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/linear_animation.h" 5 #include "ui/gfx/animation/linear_animation.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "ui/gfx/animation/animation_container.h" 12 #include "ui/gfx/animation/animation_container.h"
13 #include "ui/gfx/animation/animation_delegate.h" 13 #include "ui/gfx/animation/animation_delegate.h"
14 14
15 using base::Time; 15 using base::Time;
16 using base::TimeDelta; 16 using base::TimeDelta;
17 17
18 namespace gfx { 18 namespace gfx {
19 19
20 static TimeDelta CalculateInterval(int frame_rate) { 20 static TimeDelta CalculateInterval(int frame_rate) {
21 int timer_interval = 1000000 / frame_rate; 21 int timer_interval = 1000000 / frame_rate;
22 if (timer_interval < 10000) 22 if (timer_interval < 10000)
23 timer_interval = 10000; 23 timer_interval = 10000;
24 return TimeDelta::FromMicroseconds(timer_interval); 24 return TimeDelta::FromMicroseconds(timer_interval);
25 } 25 }
26 26
27 LinearAnimation::LinearAnimation(int frame_rate, 27 LinearAnimation::LinearAnimation(AnimationDelegate* delegate, int frame_rate)
28 : LinearAnimation(0, frame_rate, delegate) {}
29
30 LinearAnimation::LinearAnimation(int duration,
31 int frame_rate,
28 AnimationDelegate* delegate) 32 AnimationDelegate* delegate)
29 : Animation(CalculateInterval(frame_rate)), 33 : Animation(CalculateInterval(frame_rate)),
30 state_(0.0), 34 state_(0.0),
31 in_end_(false) { 35 in_end_(false) {
32 set_delegate(delegate); 36 set_delegate(delegate);
33 }
34
35 LinearAnimation::LinearAnimation(int duration,
36 int frame_rate,
37 AnimationDelegate* delegate)
38 : Animation(CalculateInterval(frame_rate)),
39 duration_(TimeDelta::FromMilliseconds(duration)),
40 state_(0.0),
41 in_end_(false) {
42 set_delegate(delegate);
43 SetDuration(duration); 37 SetDuration(duration);
44 } 38 }
45 39
46 double LinearAnimation::GetCurrentValue() const { 40 double LinearAnimation::GetCurrentValue() const {
47 // Default is linear relationship, subclass to adapt. 41 // Default is linear relationship, subclass to adapt.
48 return state_; 42 return state_;
49 } 43 }
50 44
51 void LinearAnimation::SetCurrentValue(double new_value) { 45 void LinearAnimation::SetCurrentValue(double new_value) {
52 new_value = std::max(0.0, std::min(1.0, new_value)); 46 new_value = std::max(0.0, std::min(1.0, new_value));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // Set state_ to ensure we send ended to delegate and not canceled. 96 // Set state_ to ensure we send ended to delegate and not canceled.
103 state_ = 1; 97 state_ = 1;
104 AnimateToState(1.0); 98 AnimateToState(1.0);
105 } 99 }
106 100
107 bool LinearAnimation::ShouldSendCanceledFromStop() { 101 bool LinearAnimation::ShouldSendCanceledFromStop() {
108 return state_ != 1; 102 return state_ != 1;
109 } 103 }
110 104
111 } // namespace gfx 105 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698