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

Side by Side Diff: cc/input/scrollbar_animation_controller.cc

Issue 2611013002: Show Overlay Scrollbar when GestureScrollUpdate (Closed)
Patch Set: bokan comment#70 addressed Created 3 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/input/scrollbar_animation_controller.h" 5 #include "cc/input/scrollbar_animation_controller.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/trees/layer_tree_impl.h" 10 #include "cc/trees/layer_tree_impl.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 : client_(client), 46 : client_(client),
47 fade_out_delay_(fade_out_delay), 47 fade_out_delay_(fade_out_delay),
48 fade_out_resize_delay_(fade_out_resize_delay), 48 fade_out_resize_delay_(fade_out_resize_delay),
49 need_trigger_scrollbar_show_(false), 49 need_trigger_scrollbar_show_(false),
50 is_animating_(false), 50 is_animating_(false),
51 scroll_layer_id_(scroll_layer_id), 51 scroll_layer_id_(scroll_layer_id),
52 currently_scrolling_(false), 52 currently_scrolling_(false),
53 scroll_gesture_has_scrolled_(false), 53 scroll_gesture_has_scrolled_(false),
54 opacity_(0.0f), 54 opacity_(0.0f),
55 fade_out_duration_(fade_out_duration), 55 fade_out_duration_(fade_out_duration),
56 show_scrollbars_on_scroll_gesture_(false),
56 need_thinning_animation_(false), 57 need_thinning_animation_(false),
57 weak_factory_(this) { 58 weak_factory_(this) {
58 ApplyOpacityToScrollbars(0.0f); 59 ApplyOpacityToScrollbars(0.0f);
59 } 60 }
60 61
61 ScrollbarAnimationController::ScrollbarAnimationController( 62 ScrollbarAnimationController::ScrollbarAnimationController(
62 int scroll_layer_id, 63 int scroll_layer_id,
63 ScrollbarAnimationControllerClient* client, 64 ScrollbarAnimationControllerClient* client,
64 base::TimeDelta show_delay, 65 base::TimeDelta show_delay,
65 base::TimeDelta fade_out_delay, 66 base::TimeDelta fade_out_delay,
66 base::TimeDelta fade_out_resize_delay, 67 base::TimeDelta fade_out_resize_delay,
67 base::TimeDelta fade_out_duration, 68 base::TimeDelta fade_out_duration,
68 base::TimeDelta thinning_duration) 69 base::TimeDelta thinning_duration)
69 : client_(client), 70 : client_(client),
70 show_delay_(show_delay), 71 show_delay_(show_delay),
71 fade_out_delay_(fade_out_delay), 72 fade_out_delay_(fade_out_delay),
72 fade_out_resize_delay_(fade_out_resize_delay), 73 fade_out_resize_delay_(fade_out_resize_delay),
73 need_trigger_scrollbar_show_(false), 74 need_trigger_scrollbar_show_(false),
74 is_animating_(false), 75 is_animating_(false),
75 scroll_layer_id_(scroll_layer_id), 76 scroll_layer_id_(scroll_layer_id),
76 currently_scrolling_(false), 77 currently_scrolling_(false),
77 scroll_gesture_has_scrolled_(false), 78 scroll_gesture_has_scrolled_(false),
78 opacity_(0.0f), 79 opacity_(0.0f),
79 fade_out_duration_(fade_out_duration), 80 fade_out_duration_(fade_out_duration),
81 show_scrollbars_on_scroll_gesture_(true),
80 need_thinning_animation_(true), 82 need_thinning_animation_(true),
81 weak_factory_(this) { 83 weak_factory_(this) {
82 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create( 84 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create(
83 scroll_layer_id, ScrollbarOrientation::VERTICAL, client, 85 scroll_layer_id, ScrollbarOrientation::VERTICAL, client,
84 thinning_duration); 86 thinning_duration);
85 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create( 87 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create(
86 scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client, 88 scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client,
87 thinning_duration); 89 thinning_duration);
88 ApplyOpacityToScrollbars(0.0f); 90 ApplyOpacityToScrollbars(0.0f);
89 } 91 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return animated; 161 return animated;
160 } 162 }
161 163
162 float ScrollbarAnimationController::AnimationProgressAtTime( 164 float ScrollbarAnimationController::AnimationProgressAtTime(
163 base::TimeTicks now) { 165 base::TimeTicks now) {
164 base::TimeDelta delta = now - last_awaken_time_; 166 base::TimeDelta delta = now - last_awaken_time_;
165 float progress = delta.InSecondsF() / fade_out_duration_.InSecondsF(); 167 float progress = delta.InSecondsF() / fade_out_duration_.InSecondsF();
166 return std::max(std::min(progress, 1.f), 0.f); 168 return std::max(std::min(progress, 1.f), 0.f);
167 } 169 }
168 170
169 void ScrollbarAnimationController::DidScrollBegin() {
170 currently_scrolling_ = true;
171 }
172
173 void ScrollbarAnimationController::RunAnimationFrame(float progress) { 171 void ScrollbarAnimationController::RunAnimationFrame(float progress) {
174 ApplyOpacityToScrollbars(1.f - progress); 172 ApplyOpacityToScrollbars(1.f - progress);
175 client_->SetNeedsRedrawForScrollbarAnimation(); 173 client_->SetNeedsRedrawForScrollbarAnimation();
176 if (progress == 1.f) 174 if (progress == 1.f)
177 StopAnimation(); 175 StopAnimation();
178 } 176 }
179 177
180 void ScrollbarAnimationController::DidScrollUpdate(bool on_resize) { 178 void ScrollbarAnimationController::DidScrollBegin() {
179 currently_scrolling_ = true;
180 }
181
182 void ScrollbarAnimationController::DidScrollEnd() {
183 bool has_scrolled = scroll_gesture_has_scrolled_;
184 scroll_gesture_has_scrolled_ = false;
185
186 currently_scrolling_ = false;
187
188 // We don't fade out scrollbar if they need thinning animation and mouse is
189 // near.
190 if (need_thinning_animation_ && MouseIsNearAnyScrollbar())
191 return;
192
193 if (has_scrolled)
194 PostDelayedFadeOut(false);
195 }
196
197 void ScrollbarAnimationController::DidScrollUpdate() {
181 if (need_thinning_animation_ && Captured()) 198 if (need_thinning_animation_ && Captured())
182 return; 199 return;
183 200
184 StopAnimation(); 201 StopAnimation();
185 202
186 // As an optimization, we avoid spamming fade delay tasks during active fast 203 // As an optimization, we avoid spamming fade delay tasks during active fast
187 // scrolls. But if we're not within one, we need to post every scroll update. 204 // scrolls. But if we're not within one, we need to post every scroll update.
188 if (!currently_scrolling_) { 205 if (!currently_scrolling_) {
189 // We don't fade out scrollbar if they need thinning animation and mouse is 206 // We don't fade out scrollbar if they need thinning animation and mouse is
190 // near. 207 // near.
191 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar()) 208 if (!need_thinning_animation_ || !MouseIsNearAnyScrollbar())
192 PostDelayedFadeOut(on_resize); 209 PostDelayedFadeOut(false);
193 } else { 210 } else {
194 scroll_gesture_has_scrolled_ = true; 211 scroll_gesture_has_scrolled_ = true;
195 } 212 }
196 213
197 Show(); 214 Show();
198 215
199 if (need_thinning_animation_) { 216 if (need_thinning_animation_) {
200 vertical_controller_->UpdateThumbThicknessScale(); 217 vertical_controller_->UpdateThumbThicknessScale();
201 horizontal_controller_->UpdateThumbThicknessScale(); 218 horizontal_controller_->UpdateThumbThicknessScale();
202 } 219 }
203 } 220 }
204 221
205 void ScrollbarAnimationController::DidScrollEnd() { 222 void ScrollbarAnimationController::WillUpdateScroll() {
206 bool has_scrolled = scroll_gesture_has_scrolled_; 223 if (show_scrollbars_on_scroll_gesture_)
207 scroll_gesture_has_scrolled_ = false; 224 DidScrollUpdate();
225 }
208 226
209 currently_scrolling_ = false; 227 void ScrollbarAnimationController::DidResize() {
210 228 StopAnimation();
211 // We don't fade out scrollbar if they need thinning animation and mouse is 229 Show();
212 // near. 230 // We should use the gesture delay rather than the resize delay if we're in a
213 if (need_thinning_animation_ && MouseIsNearAnyScrollbar()) 231 // gesture scroll, even if it is resizing.
214 return; 232 PostDelayedFadeOut(!currently_scrolling_);
215
216 if (has_scrolled)
217 PostDelayedFadeOut(false);
218 } 233 }
219 234
220 void ScrollbarAnimationController::DidMouseDown() { 235 void ScrollbarAnimationController::DidMouseDown() {
221 if (!need_thinning_animation_ || ScrollbarsHidden()) 236 if (!need_thinning_animation_ || ScrollbarsHidden())
222 return; 237 return;
223 238
224 vertical_controller_->DidMouseDown(); 239 vertical_controller_->DidMouseDown();
225 horizontal_controller_->DidMouseDown(); 240 horizontal_controller_->DidMouseDown();
226 } 241 }
227 242
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 bool previouslyVisible = opacity_ > 0.0f; 377 bool previouslyVisible = opacity_ > 0.0f;
363 bool currentlyVisible = opacity > 0.0f; 378 bool currentlyVisible = opacity > 0.0f;
364 379
365 opacity_ = opacity; 380 opacity_ = opacity;
366 381
367 if (previouslyVisible != currentlyVisible) 382 if (previouslyVisible != currentlyVisible)
368 client_->DidChangeScrollbarVisibility(); 383 client_->DidChangeScrollbarVisibility();
369 } 384 }
370 385
371 } // namespace cc 386 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/scrollbar_animation_controller.h ('k') | cc/input/scrollbar_animation_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698