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

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

Issue 2358323003: Keep expanded if mouse moves off of scrollbar while dragging (Closed)
Patch Set: fix style and check left button 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 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/scrollbar_animation_controller_thinning.h" 5 #include "cc/input/scrollbar_animation_controller_thinning.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "cc/layers/layer_impl.h" 9 #include "cc/layers/layer_impl.h"
10 #include "cc/layers/scrollbar_layer_impl_base.h" 10 #include "cc/layers/scrollbar_layer_impl_base.h"
(...skipping 23 matching lines...) Expand all
34 int scroll_layer_id, 34 int scroll_layer_id,
35 ScrollbarAnimationControllerClient* client, 35 ScrollbarAnimationControllerClient* client,
36 base::TimeDelta delay_before_starting, 36 base::TimeDelta delay_before_starting,
37 base::TimeDelta resize_delay_before_starting, 37 base::TimeDelta resize_delay_before_starting,
38 base::TimeDelta duration) 38 base::TimeDelta duration)
39 : ScrollbarAnimationController(scroll_layer_id, 39 : ScrollbarAnimationController(scroll_layer_id,
40 client, 40 client,
41 delay_before_starting, 41 delay_before_starting,
42 resize_delay_before_starting, 42 resize_delay_before_starting,
43 duration), 43 duration),
44 captured_(false),
44 mouse_is_over_scrollbar_(false), 45 mouse_is_over_scrollbar_(false),
45 mouse_is_near_scrollbar_(false), 46 mouse_is_near_scrollbar_(false),
46 thickness_change_(NONE), 47 thickness_change_(NONE),
47 opacity_change_(NONE), 48 opacity_change_(NONE),
48 mouse_move_distance_to_trigger_animation_( 49 mouse_move_distance_to_trigger_animation_(
49 kDefaultMouseMoveDistanceToTriggerAnimation) { 50 kDefaultMouseMoveDistanceToTriggerAnimation) {
50 ApplyOpacityAndThumbThicknessScale(kIdleOpacity, kIdleThicknessScale); 51 ApplyOpacityAndThumbThicknessScale(kIdleOpacity, kIdleThicknessScale);
51 } 52 }
52 53
53 ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {} 54 ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {}
54 55
55 void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) { 56 void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) {
56 float opacity = OpacityAtAnimationProgress(progress); 57 float opacity = OpacityAtAnimationProgress(progress);
57 float thumb_thickness_scale = 58 float thumb_thickness_scale =
58 ThumbThicknessScaleAtAnimationProgress(progress); 59 ThumbThicknessScaleAtAnimationProgress(progress);
59 ApplyOpacityAndThumbThicknessScale(opacity, thumb_thickness_scale); 60 ApplyOpacityAndThumbThicknessScale(opacity, thumb_thickness_scale);
60 client_->SetNeedsRedrawForScrollbarAnimation(); 61 client_->SetNeedsRedrawForScrollbarAnimation();
61 if (progress == 1.f) { 62 if (progress == 1.f) {
62 opacity_change_ = NONE; 63 opacity_change_ = NONE;
63 thickness_change_ = NONE; 64 thickness_change_ = NONE;
64 StopAnimation(); 65 StopAnimation();
65 } 66 }
66 } 67 }
67 68
69 void ScrollbarAnimationControllerThinning::DidCaptureScrollbarBegin() {
70 captured_ = true;
71 ApplyOpacityAndThumbThicknessScale(1, 1.f);
bokan 2016/09/23 00:39:12 I see that 1.f is the maximum opacity in OpacityAt
chaopeng 2016/09/23 02:38:26 I log the opacity in OpacityAtAnimationProgress an
72 }
73
74 void ScrollbarAnimationControllerThinning::DidCaptureScrollbarEnd() {
75 captured_ = false;
76
77 if (!mouse_is_over_scrollbar_)
78 opacity_change_ = DECREASE;
79 if (!mouse_is_near_scrollbar_)
80 thickness_change_ = DECREASE;
81 StartAnimation();
82 }
83
68 void ScrollbarAnimationControllerThinning::DidMouseMoveOffScrollbar() { 84 void ScrollbarAnimationControllerThinning::DidMouseMoveOffScrollbar() {
69 mouse_is_over_scrollbar_ = false; 85 mouse_is_over_scrollbar_ = false;
70 mouse_is_near_scrollbar_ = false; 86 mouse_is_near_scrollbar_ = false;
87
88 if (captured_)
89 return;
90
71 opacity_change_ = DECREASE; 91 opacity_change_ = DECREASE;
72 thickness_change_ = DECREASE; 92 thickness_change_ = DECREASE;
73 StartAnimation(); 93 StartAnimation();
74 } 94 }
75 95
76 void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) { 96 void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) {
97 if (captured_) {
98 return;
99 }
100
77 ScrollbarAnimationController::DidScrollUpdate(on_resize); 101 ScrollbarAnimationController::DidScrollUpdate(on_resize);
78 ApplyOpacityAndThumbThicknessScale( 102 ApplyOpacityAndThumbThicknessScale(
79 1, mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale); 103 1, mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale);
80 104
81 if (!mouse_is_over_scrollbar_) 105 if (!mouse_is_over_scrollbar_)
82 opacity_change_ = DECREASE; 106 opacity_change_ = DECREASE;
83 } 107 }
84 108
85 void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) { 109 void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) {
86 bool mouse_is_over_scrollbar = distance == 0.0; 110 bool mouse_is_over_scrollbar = distance == 0.0;
87 bool mouse_is_near_scrollbar = 111 bool mouse_is_near_scrollbar =
88 distance < mouse_move_distance_to_trigger_animation_; 112 distance < mouse_move_distance_to_trigger_animation_;
89 113
90 if (mouse_is_over_scrollbar == mouse_is_over_scrollbar_ && 114 if (captured_) {
91 mouse_is_near_scrollbar == mouse_is_near_scrollbar_) 115 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
116 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
92 return; 117 return;
118 } else {
119 if (mouse_is_over_scrollbar == mouse_is_over_scrollbar_ &&
120 mouse_is_near_scrollbar == mouse_is_near_scrollbar_)
121 return;
93 122
94 if (mouse_is_over_scrollbar_ != mouse_is_over_scrollbar) { 123 if (mouse_is_over_scrollbar_ != mouse_is_over_scrollbar) {
95 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar; 124 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
96 opacity_change_ = mouse_is_over_scrollbar_ ? INCREASE : DECREASE; 125 opacity_change_ = mouse_is_over_scrollbar_ ? INCREASE : DECREASE;
126 }
127
128 if (mouse_is_near_scrollbar_ != mouse_is_near_scrollbar) {
129 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
130 thickness_change_ = mouse_is_near_scrollbar_ ? INCREASE : DECREASE;
131 }
132
133 StartAnimation();
97 } 134 }
98
99 if (mouse_is_near_scrollbar_ != mouse_is_near_scrollbar) {
100 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
101 thickness_change_ = mouse_is_near_scrollbar_ ? INCREASE : DECREASE;
102 }
103
104 StartAnimation();
105 } 135 }
106 136
107 float ScrollbarAnimationControllerThinning::OpacityAtAnimationProgress( 137 float ScrollbarAnimationControllerThinning::OpacityAtAnimationProgress(
108 float progress) { 138 float progress) {
109 if (opacity_change_ == NONE) 139 if (opacity_change_ == NONE)
110 return mouse_is_over_scrollbar_ ? 1.f : kIdleOpacity; 140 return mouse_is_over_scrollbar_ ? 1.f : kIdleOpacity;
111 float factor = opacity_change_ == INCREASE ? progress : (1.f - progress); 141 float factor = opacity_change_ == INCREASE ? progress : (1.f - progress);
112 float ret = ((1.f - kIdleOpacity) * factor) + kIdleOpacity; 142 float ret = ((1.f - kIdleOpacity) * factor) + kIdleOpacity;
113 return ret; 143 return ret;
114 } 144 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 property_trees->effect_id_to_index_map[scrollbar->id()], 187 property_trees->effect_id_to_index_map[scrollbar->id()],
158 scrollbar->layer_tree_impl()); 188 scrollbar->layer_tree_impl());
159 } 189 }
160 scrollbar->SetThumbThicknessScaleFactor(AdjustScale( 190 scrollbar->SetThumbThicknessScaleFactor(AdjustScale(
161 thumb_thickness_scale, scrollbar->thumb_thickness_scale_factor(), 191 thumb_thickness_scale, scrollbar->thumb_thickness_scale_factor(),
162 thickness_change_)); 192 thickness_change_));
163 } 193 }
164 } 194 }
165 195
166 } // namespace cc 196 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698