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

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

Issue 2841943002: Overlay scrollbars expand only when mouse is near thumb (Closed)
Patch Set: add tests Created 3 years, 7 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"
(...skipping 18 matching lines...) Expand all
29 SingleScrollbarAnimationControllerThinning( 29 SingleScrollbarAnimationControllerThinning(
30 ElementId scroll_element_id, 30 ElementId scroll_element_id,
31 ScrollbarOrientation orientation, 31 ScrollbarOrientation orientation,
32 ScrollbarAnimationControllerClient* client, 32 ScrollbarAnimationControllerClient* client,
33 base::TimeDelta thinning_duration) 33 base::TimeDelta thinning_duration)
34 : client_(client), 34 : client_(client),
35 is_animating_(false), 35 is_animating_(false),
36 scroll_element_id_(scroll_element_id), 36 scroll_element_id_(scroll_element_id),
37 orientation_(orientation), 37 orientation_(orientation),
38 captured_(false), 38 captured_(false),
39 mouse_is_over_scrollbar_(false), 39 mouse_is_over_scrollbar_thumb_(false),
40 mouse_is_near_scrollbar_(false), 40 mouse_is_near_scrollbar_thumb_(false),
41 thickness_change_(NONE), 41 thickness_change_(NONE),
42 thinning_duration_(thinning_duration) { 42 thinning_duration_(thinning_duration) {
43 ApplyThumbThicknessScale(kIdleThicknessScale); 43 ApplyThumbThicknessScale(kIdleThicknessScale);
44 } 44 }
45 45
46 bool SingleScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) { 46 bool SingleScrollbarAnimationControllerThinning::Animate(base::TimeTicks now) {
47 if (!is_animating_) 47 if (!is_animating_)
48 return false; 48 return false;
49 49
50 if (last_awaken_time_.is_null()) 50 if (last_awaken_time_.is_null())
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 is_animating_ = true; 85 is_animating_ = true;
86 last_awaken_time_ = base::TimeTicks(); 86 last_awaken_time_ = base::TimeTicks();
87 client_->SetNeedsAnimateForScrollbarAnimation(); 87 client_->SetNeedsAnimateForScrollbarAnimation();
88 } 88 }
89 89
90 void SingleScrollbarAnimationControllerThinning::StopAnimation() { 90 void SingleScrollbarAnimationControllerThinning::StopAnimation() {
91 is_animating_ = false; 91 is_animating_ = false;
92 } 92 }
93 93
94 void SingleScrollbarAnimationControllerThinning::DidMouseDown() { 94 void SingleScrollbarAnimationControllerThinning::DidMouseDown() {
95 if (!mouse_is_over_scrollbar_) 95 if (!mouse_is_over_scrollbar_thumb_)
96 return; 96 return;
97 97
98 StopAnimation(); 98 StopAnimation();
99 captured_ = true; 99 captured_ = true;
100 ApplyThumbThicknessScale(1.f); 100 ApplyThumbThicknessScale(1.f);
101 } 101 }
102 102
103 void SingleScrollbarAnimationControllerThinning::DidMouseUp() { 103 void SingleScrollbarAnimationControllerThinning::DidMouseUp() {
104 if (!captured_) 104 if (!captured_)
105 return; 105 return;
106 106
107 captured_ = false; 107 captured_ = false;
108 StopAnimation(); 108 StopAnimation();
109 109
110 if (!mouse_is_near_scrollbar_) { 110 if (!mouse_is_near_scrollbar_thumb_) {
111 thickness_change_ = DECREASE; 111 thickness_change_ = DECREASE;
112 StartAnimation(); 112 StartAnimation();
113 } else { 113 } else {
114 thickness_change_ = NONE; 114 thickness_change_ = NONE;
115 } 115 }
116 } 116 }
117 117
118 void SingleScrollbarAnimationControllerThinning::DidMouseLeave() { 118 void SingleScrollbarAnimationControllerThinning::DidMouseLeave() {
119 if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_) 119 if (!mouse_is_over_scrollbar_thumb_ && !mouse_is_near_scrollbar_thumb_)
120 return; 120 return;
121 121
122 mouse_is_over_scrollbar_ = false; 122 mouse_is_over_scrollbar_thumb_ = false;
123 mouse_is_near_scrollbar_ = false; 123 mouse_is_near_scrollbar_thumb_ = false;
124 124
125 if (captured_) 125 if (captured_)
126 return; 126 return;
127 127
128 thickness_change_ = DECREASE; 128 thickness_change_ = DECREASE;
129 StartAnimation(); 129 StartAnimation();
130 } 130 }
131 131
132 void SingleScrollbarAnimationControllerThinning::DidMouseMoveNear( 132 void SingleScrollbarAnimationControllerThinning::DidMouseMove(
133 float distance) { 133 float distance_to_thumb) {
134 bool mouse_is_over_scrollbar = distance == 0.0f; 134 bool mouse_is_over_scrollbar_thumb = distance_to_thumb == 0.0f;
135 bool mouse_is_near_scrollbar = 135 bool mouse_is_near_scrollbar_thumb =
136 distance < kDefaultMouseMoveDistanceToTriggerAnimation; 136 distance_to_thumb < kMouseMoveDistanceToTriggerExpand;
137 137
138 if (!captured_ && mouse_is_near_scrollbar != mouse_is_near_scrollbar_) { 138 if (!captured_ &&
139 thickness_change_ = mouse_is_near_scrollbar ? INCREASE : DECREASE; 139 mouse_is_near_scrollbar_thumb != mouse_is_near_scrollbar_thumb_) {
140 thickness_change_ = mouse_is_near_scrollbar_thumb ? INCREASE : DECREASE;
140 StartAnimation(); 141 StartAnimation();
141 } 142 }
142 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar; 143 mouse_is_near_scrollbar_thumb_ = mouse_is_near_scrollbar_thumb;
143 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar; 144 mouse_is_over_scrollbar_thumb_ = mouse_is_over_scrollbar_thumb;
144 } 145 }
145 146
146 float SingleScrollbarAnimationControllerThinning::ThumbThicknessScaleAt( 147 float SingleScrollbarAnimationControllerThinning::ThumbThicknessScaleAt(
147 float progress) { 148 float progress) {
148 if (thickness_change_ == NONE) 149 if (thickness_change_ == NONE)
149 return mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale; 150 return mouse_is_near_scrollbar_thumb_ ? 1.f : kIdleThicknessScale;
150 float factor = thickness_change_ == INCREASE ? progress : (1.f - progress); 151 float factor = thickness_change_ == INCREASE ? progress : (1.f - progress);
151 return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale; 152 return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale;
152 } 153 }
153 154
154 float SingleScrollbarAnimationControllerThinning::AdjustScale( 155 float SingleScrollbarAnimationControllerThinning::AdjustScale(
155 float new_value, 156 float new_value,
156 float current_value, 157 float current_value,
157 AnimationChange animation_change, 158 AnimationChange animation_change,
158 float min_value, 159 float min_value,
159 float max_value) { 160 float max_value) {
160 float result; 161 float result;
161 if (animation_change == INCREASE && current_value > new_value) 162 if (animation_change == INCREASE && current_value > new_value)
162 result = current_value; 163 result = current_value;
163 else if (animation_change == DECREASE && current_value < new_value) 164 else if (animation_change == DECREASE && current_value < new_value)
164 result = current_value; 165 result = current_value;
165 else 166 else
166 result = new_value; 167 result = new_value;
167 if (result > max_value) 168 if (result > max_value)
168 return max_value; 169 return max_value;
169 if (result < min_value) 170 if (result < min_value)
170 return min_value; 171 return min_value;
171 return result; 172 return result;
172 } 173 }
173 174
174 void SingleScrollbarAnimationControllerThinning::UpdateThumbThicknessScale() { 175 void SingleScrollbarAnimationControllerThinning::UpdateThumbThicknessScale() {
175 StopAnimation(); 176 StopAnimation();
176 ApplyThumbThicknessScale(mouse_is_near_scrollbar_ ? 1.f 177 ApplyThumbThicknessScale(
177 : kIdleThicknessScale); 178 mouse_is_near_scrollbar_thumb_ ? 1.f : kIdleThicknessScale);
178 } 179 }
179 180
180 void SingleScrollbarAnimationControllerThinning::ApplyThumbThicknessScale( 181 void SingleScrollbarAnimationControllerThinning::ApplyThumbThicknessScale(
181 float thumb_thickness_scale) { 182 float thumb_thickness_scale) {
182 for (auto* scrollbar : client_->ScrollbarsFor(scroll_element_id_)) { 183 for (auto* scrollbar : client_->ScrollbarsFor(scroll_element_id_)) {
183 if (scrollbar->orientation() != orientation_) 184 if (scrollbar->orientation() != orientation_)
184 continue; 185 continue;
185 if (!scrollbar->is_overlay_scrollbar()) 186 if (!scrollbar->is_overlay_scrollbar())
186 continue; 187 continue;
187 188
188 float scale = AdjustScale(thumb_thickness_scale, 189 float scale = AdjustScale(thumb_thickness_scale,
189 scrollbar->thumb_thickness_scale_factor(), 190 scrollbar->thumb_thickness_scale_factor(),
190 thickness_change_, kIdleThicknessScale, 1); 191 thickness_change_, kIdleThicknessScale, 1);
191 192
192 scrollbar->SetThumbThicknessScaleFactor(scale); 193 scrollbar->SetThumbThicknessScaleFactor(scale);
193 } 194 }
194 } 195 }
195 196
196 } // namespace cc 197 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698