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

Side by Side Diff: cc/animation/scrollbar_animation_controller_thinning.cc

Issue 26880010: gfx: Add FrameTime and DisplayTime classes (Closed) Base URL: http://git.chromium.org/chromium/src.git@checkHighResNow4
Patch Set: WIP Created 7 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/animation/scrollbar_animation_controller_thinning.h" 5 #include "cc/animation/scrollbar_animation_controller_thinning.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 29 matching lines...) Expand all
40 mouse_move_distance_to_trigger_animation_(100.f) {} 40 mouse_move_distance_to_trigger_animation_(100.f) {}
41 41
42 ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() { 42 ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {
43 } 43 }
44 44
45 bool ScrollbarAnimationControllerThinning::IsAnimating() const { 45 bool ScrollbarAnimationControllerThinning::IsAnimating() const {
46 return !last_awaken_time_.is_null(); 46 return !last_awaken_time_.is_null();
47 } 47 }
48 48
49 base::TimeDelta ScrollbarAnimationControllerThinning::DelayBeforeStart( 49 base::TimeDelta ScrollbarAnimationControllerThinning::DelayBeforeStart(
50 base::TimeTicks now) const { 50 gfx::FrameTime now) const {
51 if (now > last_awaken_time_ + animation_delay_) 51 if (now > last_awaken_time_ + animation_delay_)
52 return base::TimeDelta(); 52 return base::TimeDelta();
53 return animation_delay_ - (now - last_awaken_time_); 53 return animation_delay_ - (now - last_awaken_time_);
54 } 54 }
55 55
56 bool ScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) { 56 bool ScrollbarAnimationControllerThinning::Animate(gfx::FrameTime now) {
57 if (mouse_is_over_scrollbar_) { 57 if (mouse_is_over_scrollbar_) {
58 ApplyOpacityAndThumbThicknessScale(1, 1); 58 ApplyOpacityAndThumbThicknessScale(1, 1);
59 return false; 59 return false;
60 } 60 }
61 float progress = AnimationProgressAtTime(now); 61 float progress = AnimationProgressAtTime(now);
62 float opacity = OpacityAtAnimationProgress(progress); 62 float opacity = OpacityAtAnimationProgress(progress);
63 float thumb_thickness_scale = ThumbThicknessScaleAtAnimationProgress( 63 float thumb_thickness_scale = ThumbThicknessScaleAtAnimationProgress(
64 progress); 64 progress);
65 ApplyOpacityAndThumbThicknessScale(opacity, thumb_thickness_scale); 65 ApplyOpacityAndThumbThicknessScale(opacity, thumb_thickness_scale);
66 if (progress == 1.f) 66 if (progress == 1.f)
67 last_awaken_time_ = base::TimeTicks(); 67 last_awaken_time_ = gfx::FrameTime();
68 return IsAnimating() && DelayBeforeStart(now) == base::TimeDelta(); 68 return IsAnimating() && DelayBeforeStart(now) == base::TimeDelta();
69 } 69 }
70 70
71 void ScrollbarAnimationControllerThinning::DidScrollGestureBegin() { 71 void ScrollbarAnimationControllerThinning::DidScrollGestureBegin() {
72 ApplyOpacityAndThumbThicknessScale(1, 1); 72 ApplyOpacityAndThumbThicknessScale(1, 1);
73 last_awaken_time_ = base::TimeTicks(); 73 last_awaken_time_ = gfx::FrameTime();
74 scroll_gesture_in_progress_ = true; 74 scroll_gesture_in_progress_ = true;
75 } 75 }
76 76
77 void ScrollbarAnimationControllerThinning::DidScrollGestureEnd( 77 void ScrollbarAnimationControllerThinning::DidScrollGestureEnd(
78 base::TimeTicks now) { 78 gfx::FrameTime now) {
79 last_awaken_time_ = now; 79 last_awaken_time_ = now;
80 scroll_gesture_in_progress_ = false; 80 scroll_gesture_in_progress_ = false;
81 } 81 }
82 82
83 void ScrollbarAnimationControllerThinning::DidMouseMoveOffScrollbar( 83 void ScrollbarAnimationControllerThinning::DidMouseMoveOffScrollbar(
84 base::TimeTicks now) { 84 gfx::FrameTime now) {
85 mouse_is_over_scrollbar_ = false; 85 mouse_is_over_scrollbar_ = false;
86 DidScrollUpdate(now); 86 DidScrollUpdate(now);
87 } 87 }
88 88
89 bool ScrollbarAnimationControllerThinning::DidScrollUpdate( 89 bool ScrollbarAnimationControllerThinning::DidScrollUpdate(
90 base::TimeTicks now) { 90 gfx::FrameTime now) {
91 ApplyOpacityAndThumbThicknessScale(1, 1); 91 ApplyOpacityAndThumbThicknessScale(1, 1);
92 92
93 last_awaken_time_ = now; 93 last_awaken_time_ = now;
94 return true; 94 return true;
95 } 95 }
96 96
97 bool ScrollbarAnimationControllerThinning::DidMouseMoveNear( 97 bool ScrollbarAnimationControllerThinning::DidMouseMoveNear(
98 base::TimeTicks now, float distance) { 98 gfx::FrameTime now, float distance) {
99 if (distance == 0.0) { 99 if (distance == 0.0) {
100 mouse_is_over_scrollbar_ = true; 100 mouse_is_over_scrollbar_ = true;
101 return false; 101 return false;
102 } 102 }
103 103
104 if (distance < mouse_move_distance_to_trigger_animation_) 104 if (distance < mouse_move_distance_to_trigger_animation_)
105 return DidScrollUpdate(now); 105 return DidScrollUpdate(now);
106 106
107 return false; 107 return false;
108 } 108 }
109 109
110 float ScrollbarAnimationControllerThinning::AnimationProgressAtTime( 110 float ScrollbarAnimationControllerThinning::AnimationProgressAtTime(
111 base::TimeTicks now) { 111 gfx::FrameTime now) {
112 if (scroll_gesture_in_progress_) 112 if (scroll_gesture_in_progress_)
113 return 0; 113 return 0;
114 114
115 if (last_awaken_time_.is_null()) 115 if (last_awaken_time_.is_null())
116 return 1; 116 return 1;
117 117
118 base::TimeDelta delta = now - last_awaken_time_; 118 base::TimeDelta delta = now - last_awaken_time_;
119 float progress = (delta - animation_delay_).InSecondsF() / 119 float progress = (delta - animation_delay_).InSecondsF() /
120 animation_duration_.InSecondsF(); 120 animation_duration_.InSecondsF();
121 return std::max(std::min(progress, 1.f), 0.f); 121 return std::max(std::min(progress, 1.f), 0.f);
(...skipping 26 matching lines...) Expand all
148 148
149 ScrollbarLayerImplBase* vertical_scrollbar = 149 ScrollbarLayerImplBase* vertical_scrollbar =
150 scroll_layer_->vertical_scrollbar_layer(); 150 scroll_layer_->vertical_scrollbar_layer();
151 if (vertical_scrollbar) { 151 if (vertical_scrollbar) {
152 vertical_scrollbar->SetOpacity(opacity); 152 vertical_scrollbar->SetOpacity(opacity);
153 vertical_scrollbar->set_thumb_thickness_scale_factor(thumb_thickness_scale); 153 vertical_scrollbar->set_thumb_thickness_scale_factor(thumb_thickness_scale);
154 } 154 }
155 } 155 }
156 156
157 } // namespace cc 157 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698