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

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

Issue 10855151: Gradient overlay for constrained window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/animation/linear_animation.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/base/animation/linear_animation.h" 5 #include "ui/base/animation/linear_animation.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "ui/base/animation/animation_container.h" 9 #include "ui/base/animation/animation_container.h"
10 #include "ui/base/animation/animation_delegate.h" 10 #include "ui/base/animation/animation_delegate.h"
(...skipping 27 matching lines...) Expand all
38 in_end_(false) { 38 in_end_(false) {
39 set_delegate(delegate); 39 set_delegate(delegate);
40 SetDuration(duration); 40 SetDuration(duration);
41 } 41 }
42 42
43 double LinearAnimation::GetCurrentValue() const { 43 double LinearAnimation::GetCurrentValue() const {
44 // Default is linear relationship, subclass to adapt. 44 // Default is linear relationship, subclass to adapt.
45 return state_; 45 return state_;
46 } 46 }
47 47
48 void LinearAnimation::SetCurrentValue(double new_value) {
49 new_value = std::max(0.0, std::min(1.0, new_value));
50 base::TimeDelta time_delta = base::TimeDelta::FromMicroseconds(
51 duration_.InMicroseconds() * (new_value - state_));
52 SetStartTime(start_time() - time_delta);
53 state_ = new_value;
54 }
55
48 void LinearAnimation::End() { 56 void LinearAnimation::End() {
49 if (!is_animating()) 57 if (!is_animating())
50 return; 58 return;
51 59
52 // NOTE: We don't use AutoReset here as Stop may end up deleting us (by way 60 // NOTE: We don't use AutoReset here as Stop may end up deleting us (by way
53 // of the delegate). 61 // of the delegate).
54 in_end_ = true; 62 in_end_ = true;
55 Stop(); 63 Stop();
56 } 64 }
57 65
(...skipping 14 matching lines...) Expand all
72 80
73 AnimateToState(state_); 81 AnimateToState(state_);
74 82
75 if (delegate()) 83 if (delegate())
76 delegate()->AnimationProgressed(this); 84 delegate()->AnimationProgressed(this);
77 85
78 if (state_ == 1.0) 86 if (state_ == 1.0)
79 Stop(); 87 Stop();
80 } 88 }
81 89
90 void LinearAnimation::AnimationStarted() {
91 state_ = 0.0;
92 }
93
82 void LinearAnimation::AnimationStopped() { 94 void LinearAnimation::AnimationStopped() {
83 if (!in_end_) 95 if (!in_end_)
84 return; 96 return;
85 97
86 in_end_ = false; 98 in_end_ = false;
87 // Set state_ to ensure we send ended to delegate and not canceled. 99 // Set state_ to ensure we send ended to delegate and not canceled.
88 state_ = 1; 100 state_ = 1;
89 AnimateToState(1.0); 101 AnimateToState(1.0);
90 } 102 }
91 103
92 bool LinearAnimation::ShouldSendCanceledFromStop() { 104 bool LinearAnimation::ShouldSendCanceledFromStop() {
93 return state_ != 1; 105 return state_ != 1;
94 } 106 }
95 107
96 } // namespace ui 108 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/animation/linear_animation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698