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

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

Issue 2692243005: Merge Compositor's ScrollbarAnimationControllers into single class (Closed)
Patch Set: fix confict constant Created 3 years, 10 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 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/input/single_scrollbar_animation_controller_thinning.h" 5 #include "cc/input/single_scrollbar_animation_controller_thinning.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "cc/input/scrollbar_animation_controller.h" 11 #include "cc/input/scrollbar_animation_controller.h"
12 #include "cc/layers/layer_impl.h" 12 #include "cc/layers/layer_impl.h"
13 #include "cc/layers/scrollbar_layer_impl_base.h" 13 #include "cc/layers/scrollbar_layer_impl_base.h"
14 #include "cc/trees/layer_tree_impl.h" 14 #include "cc/trees/layer_tree_impl.h"
15 15
16 namespace {
17 const float kIdleThicknessScale = 0.4f;
18 const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f;
19 }
20
21 namespace cc { 16 namespace cc {
22 17
23 std::unique_ptr<SingleScrollbarAnimationControllerThinning> 18 std::unique_ptr<SingleScrollbarAnimationControllerThinning>
24 SingleScrollbarAnimationControllerThinning::Create( 19 SingleScrollbarAnimationControllerThinning::Create(
25 int scroll_layer_id, 20 int scroll_layer_id,
26 ScrollbarOrientation orientation, 21 ScrollbarOrientation orientation,
27 ScrollbarAnimationControllerClient* client, 22 ScrollbarAnimationControllerClient* client,
28 base::TimeDelta thinning_duration) { 23 base::TimeDelta thinning_duration) {
29 return base::WrapUnique(new SingleScrollbarAnimationControllerThinning( 24 return base::WrapUnique(new SingleScrollbarAnimationControllerThinning(
30 scroll_layer_id, orientation, client, thinning_duration)); 25 scroll_layer_id, orientation, client, thinning_duration));
31 } 26 }
32 27
33 SingleScrollbarAnimationControllerThinning:: 28 SingleScrollbarAnimationControllerThinning::
34 SingleScrollbarAnimationControllerThinning( 29 SingleScrollbarAnimationControllerThinning(
35 int scroll_layer_id, 30 int scroll_layer_id,
36 ScrollbarOrientation orientation, 31 ScrollbarOrientation orientation,
37 ScrollbarAnimationControllerClient* client, 32 ScrollbarAnimationControllerClient* client,
38 base::TimeDelta thinning_duration) 33 base::TimeDelta thinning_duration)
39 : client_(client), 34 : client_(client),
40 is_animating_(false), 35 is_animating_(false),
41 scroll_layer_id_(scroll_layer_id), 36 scroll_layer_id_(scroll_layer_id),
42 orientation_(orientation), 37 orientation_(orientation),
43 captured_(false), 38 captured_(false),
44 mouse_is_over_scrollbar_(false), 39 mouse_is_over_scrollbar_(false),
45 mouse_is_near_scrollbar_(false), 40 mouse_is_near_scrollbar_(false),
46 thickness_change_(NONE), 41 thickness_change_(NONE),
47 mouse_move_distance_to_trigger_animation_(
48 kDefaultMouseMoveDistanceToTriggerAnimation),
49 thinning_duration_(thinning_duration) { 42 thinning_duration_(thinning_duration) {
50 ApplyThumbThicknessScale(kIdleThicknessScale); 43 ApplyThumbThicknessScale(kIdleThicknessScale);
51 } 44 }
52 45
53 bool SingleScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) { 46 bool SingleScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) {
54 if (!is_animating_) 47 if (!is_animating_)
55 return false; 48 return false;
56 49
57 if (last_awaken_time_.is_null()) 50 if (last_awaken_time_.is_null())
58 last_awaken_time_ = now; 51 last_awaken_time_ = now;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return; 126 return;
134 127
135 thickness_change_ = DECREASE; 128 thickness_change_ = DECREASE;
136 StartAnimation(); 129 StartAnimation();
137 } 130 }
138 131
139 void SingleScrollbarAnimationControllerThinning::DidMouseMoveNear( 132 void SingleScrollbarAnimationControllerThinning::DidMouseMoveNear(
140 float distance) { 133 float distance) {
141 bool mouse_is_over_scrollbar = distance == 0.0f; 134 bool mouse_is_over_scrollbar = distance == 0.0f;
142 bool mouse_is_near_scrollbar = 135 bool mouse_is_near_scrollbar =
143 distance < mouse_move_distance_to_trigger_animation_; 136 distance < kDefaultMouseMoveDistanceToTriggerAnimation;
144 137
145 if (!captured_ && mouse_is_near_scrollbar != mouse_is_near_scrollbar_) { 138 if (!captured_ && mouse_is_near_scrollbar != mouse_is_near_scrollbar_) {
146 thickness_change_ = mouse_is_near_scrollbar ? INCREASE : DECREASE; 139 thickness_change_ = mouse_is_near_scrollbar ? INCREASE : DECREASE;
147 StartAnimation(); 140 StartAnimation();
148 } 141 }
149 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar; 142 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
150 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar; 143 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
151 } 144 }
152 145
153 float SingleScrollbarAnimationControllerThinning::ThumbThicknessScaleAt( 146 float SingleScrollbarAnimationControllerThinning::ThumbThicknessScaleAt(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 188
196 float scale = AdjustScale(thumb_thickness_scale, 189 float scale = AdjustScale(thumb_thickness_scale,
197 scrollbar->thumb_thickness_scale_factor(), 190 scrollbar->thumb_thickness_scale_factor(),
198 thickness_change_, kIdleThicknessScale, 1); 191 thickness_change_, kIdleThicknessScale, 1);
199 192
200 scrollbar->SetThumbThicknessScaleFactor(scale); 193 scrollbar->SetThumbThicknessScaleFactor(scale);
201 } 194 }
202 } 195 }
203 196
204 } // namespace cc 197 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698