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

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

Issue 2442573002: Implement fade-out animation for Aura overlay scrollbars (CC only). (Closed)
Patch Set: Few more fixes Created 4 years, 2 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"
11 #include "cc/trees/layer_tree_impl.h" 11 #include "cc/trees/layer_tree_impl.h"
12 12
13 namespace { 13 namespace {
14 const float kIdleThicknessScale = 0.4f; 14 const float kIdleThicknessScale = 0.4f;
15 const float kIdleOpacity = 0.7f;
16 const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f; 15 const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f;
17 } 16 }
18 17
19 namespace cc { 18 namespace cc {
20 19
21 std::unique_ptr<ScrollbarAnimationControllerThinning> 20 std::unique_ptr<ScrollbarAnimationControllerThinning>
22 ScrollbarAnimationControllerThinning::Create( 21 ScrollbarAnimationControllerThinning::Create(
23 int scroll_layer_id, 22 int scroll_layer_id,
24 ScrollbarAnimationControllerClient* client, 23 ScrollbarAnimationControllerClient* client,
25 base::TimeDelta delay_before_starting, 24 base::TimeDelta delay_before_starting,
26 base::TimeDelta resize_delay_before_starting, 25 base::TimeDelta resize_delay_before_starting,
27 base::TimeDelta duration) { 26 base::TimeDelta fade_duration,
27 base::TimeDelta thinning_duration) {
28 return base::WrapUnique(new ScrollbarAnimationControllerThinning( 28 return base::WrapUnique(new ScrollbarAnimationControllerThinning(
29 scroll_layer_id, client, delay_before_starting, 29 scroll_layer_id, client, delay_before_starting,
30 resize_delay_before_starting, duration)); 30 resize_delay_before_starting, fade_duration, thinning_duration));
31 } 31 }
32 32
33 ScrollbarAnimationControllerThinning::ScrollbarAnimationControllerThinning( 33 ScrollbarAnimationControllerThinning::ScrollbarAnimationControllerThinning(
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 fade_duration,
39 base::TimeDelta thinning_duration)
39 : ScrollbarAnimationController(scroll_layer_id, 40 : ScrollbarAnimationController(scroll_layer_id,
40 client, 41 client,
41 delay_before_starting, 42 delay_before_starting,
42 resize_delay_before_starting, 43 resize_delay_before_starting,
43 duration), 44 fade_duration),
45 is_visible_(false),
44 captured_(false), 46 captured_(false),
45 mouse_is_over_scrollbar_(false), 47 mouse_is_over_scrollbar_(false),
46 mouse_is_near_scrollbar_(false), 48 mouse_is_near_scrollbar_(false),
47 thickness_change_(NONE), 49 thickness_change_(NONE),
48 opacity_change_(NONE),
49 mouse_move_distance_to_trigger_animation_( 50 mouse_move_distance_to_trigger_animation_(
50 kDefaultMouseMoveDistanceToTriggerAnimation) { 51 kDefaultMouseMoveDistanceToTriggerAnimation),
51 ApplyOpacityAndThumbThicknessScale(kIdleOpacity, kIdleThicknessScale); 52 fade_duration_(fade_duration),
53 thinning_duration_(thinning_duration),
54 current_animating_property_(OPACITY) {
55 ApplyOpacity(0.f);
56 ApplyThumbThicknessScale(kIdleThicknessScale);
52 } 57 }
53 58
54 ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {} 59 ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {}
55 60
56 void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) { 61 void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) {
57 float opacity = OpacityAtAnimationProgress(progress); 62 if (captured_)
58 float thumb_thickness_scale = 63 return;
59 ThumbThicknessScaleAtAnimationProgress(progress); 64
60 ApplyOpacityAndThumbThicknessScale(opacity, thumb_thickness_scale); 65 if (current_animating_property_ == OPACITY)
66 ApplyOpacity(1.f - progress);
67 else
68 ApplyThumbThicknessScale(ThumbThicknessScaleAt(progress));
69
61 client_->SetNeedsRedrawForScrollbarAnimation(); 70 client_->SetNeedsRedrawForScrollbarAnimation();
62 if (progress == 1.f) { 71 if (progress == 1.f) {
63 opacity_change_ = NONE;
64 thickness_change_ = NONE;
65 StopAnimation(); 72 StopAnimation();
73 if (current_animating_property_ == THICKNESS) {
74 thickness_change_ = NONE;
75 SetCurrentAnimatingProperty(OPACITY);
76 PostDelayedAnimationTask(false);
77 }
66 } 78 }
67 } 79 }
68 80
69 void ScrollbarAnimationControllerThinning::DidCaptureScrollbarBegin() { 81 void ScrollbarAnimationControllerThinning::DidCaptureScrollbarBegin() {
82 if (!is_visible_)
83 return;
84 StopAnimation();
70 captured_ = true; 85 captured_ = true;
71 ApplyOpacityAndThumbThicknessScale(1, 1.f); 86 ApplyOpacity(1.f);
87 ApplyThumbThicknessScale(1.f);
72 } 88 }
73 89
74 void ScrollbarAnimationControllerThinning::DidCaptureScrollbarEnd() { 90 void ScrollbarAnimationControllerThinning::DidCaptureScrollbarEnd() {
91 if (!is_visible_)
92 return;
75 captured_ = false; 93 captured_ = false;
94 StopAnimation();
76 95
77 if (!mouse_is_over_scrollbar_) 96 if (!mouse_is_near_scrollbar_) {
78 opacity_change_ = DECREASE; 97 SetCurrentAnimatingProperty(THICKNESS);
79 if (!mouse_is_near_scrollbar_)
80 thickness_change_ = DECREASE; 98 thickness_change_ = DECREASE;
81 StartAnimation(); 99 StartAnimation();
100 } else {
101 SetCurrentAnimatingProperty(OPACITY);
102 PostDelayedAnimationTask(false);
103 }
82 } 104 }
83 105
84 void ScrollbarAnimationControllerThinning::DidMouseMoveOffScrollbar() { 106 void ScrollbarAnimationControllerThinning::DidMouseMoveOffScrollbar() {
85 if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_) 107 if (!mouse_is_over_scrollbar_ && !mouse_is_near_scrollbar_)
86 return; 108 return;
87 109
88 mouse_is_over_scrollbar_ = false; 110 mouse_is_over_scrollbar_ = false;
89 mouse_is_near_scrollbar_ = false; 111 mouse_is_near_scrollbar_ = false;
90 112
91 if (captured_) 113 if (captured_ || !is_visible_)
92 return; 114 return;
93 115
94 opacity_change_ = DECREASE;
95 thickness_change_ = DECREASE; 116 thickness_change_ = DECREASE;
117 SetCurrentAnimatingProperty(THICKNESS);
96 StartAnimation(); 118 StartAnimation();
97 } 119 }
98 120
99 void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) { 121 void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) {
100 if (captured_) { 122 if (captured_)
101 return; 123 return;
102 }
103 124
104 ScrollbarAnimationController::DidScrollUpdate(on_resize); 125 ScrollbarAnimationController::DidScrollUpdate(on_resize);
105 ApplyOpacityAndThumbThicknessScale( 126 ApplyOpacity(1.f);
106 1, mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale); 127 ApplyThumbThicknessScale(mouse_is_near_scrollbar_ ? 1.f
107 128 : kIdleThicknessScale);
108 if (!mouse_is_over_scrollbar_) 129 SetCurrentAnimatingProperty(OPACITY);
109 opacity_change_ = DECREASE;
110 } 130 }
111 131
112 void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) { 132 void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) {
113 bool mouse_is_over_scrollbar = distance == 0.0; 133 bool mouse_is_over_scrollbar = distance == 0.0;
114 bool mouse_is_near_scrollbar = 134 bool mouse_is_near_scrollbar =
115 distance < mouse_move_distance_to_trigger_animation_; 135 distance < mouse_move_distance_to_trigger_animation_;
116 136
117 if (captured_) { 137 if (captured_ || !is_visible_) {
118 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar; 138 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
119 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar; 139 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
120 return; 140 return;
121 } else { 141 }
122 if (mouse_is_over_scrollbar == mouse_is_over_scrollbar_ &&
123 mouse_is_near_scrollbar == mouse_is_near_scrollbar_)
124 return;
125 142
126 if (mouse_is_over_scrollbar_ != mouse_is_over_scrollbar) { 143 if (mouse_is_over_scrollbar == mouse_is_over_scrollbar_ &&
127 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar; 144 mouse_is_near_scrollbar == mouse_is_near_scrollbar_)
128 opacity_change_ = mouse_is_over_scrollbar_ ? INCREASE : DECREASE; 145 return;
129 }
130 146
131 if (mouse_is_near_scrollbar_ != mouse_is_near_scrollbar) { 147 if (mouse_is_over_scrollbar_ != mouse_is_over_scrollbar)
132 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar; 148 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
133 thickness_change_ = mouse_is_near_scrollbar_ ? INCREASE : DECREASE;
134 }
135 149
136 StartAnimation(); 150 if (mouse_is_near_scrollbar_ != mouse_is_near_scrollbar) {
151 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
152 thickness_change_ = mouse_is_near_scrollbar_ ? INCREASE : DECREASE;
137 } 153 }
154
155 SetCurrentAnimatingProperty(THICKNESS);
156 StartAnimation();
138 } 157 }
139 158
140 float ScrollbarAnimationControllerThinning::OpacityAtAnimationProgress( 159 float ScrollbarAnimationControllerThinning::ThumbThicknessScaleAt(
141 float progress) { 160 float progress) {
142 if (opacity_change_ == NONE)
143 return mouse_is_over_scrollbar_ ? 1.f : kIdleOpacity;
144 float factor = opacity_change_ == INCREASE ? progress : (1.f - progress);
145 float ret = ((1.f - kIdleOpacity) * factor) + kIdleOpacity;
146 return ret;
147 }
148
149 float ScrollbarAnimationControllerThinning::
150 ThumbThicknessScaleAtAnimationProgress(float progress) {
151 if (thickness_change_ == NONE) 161 if (thickness_change_ == NONE)
152 return mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale; 162 return mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale;
153 float factor = thickness_change_ == INCREASE ? progress : (1.f - progress); 163 float factor = thickness_change_ == INCREASE ? progress : (1.f - progress);
154 return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale; 164 return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale;
155 } 165 }
156 166
157 float ScrollbarAnimationControllerThinning::AdjustScale( 167 float ScrollbarAnimationControllerThinning::AdjustScale(
158 float new_value, 168 float new_value,
159 float current_value, 169 float current_value,
160 AnimationChange animation_change, 170 AnimationChange animation_change,
161 float min_value, 171 float min_value,
162 float max_value) { 172 float max_value) {
163 float result; 173 float result;
164 if (animation_change == INCREASE && current_value > new_value) 174 if (animation_change == INCREASE && current_value > new_value)
165 result = current_value; 175 result = current_value;
166 else if (animation_change == DECREASE && current_value < new_value) 176 else if (animation_change == DECREASE && current_value < new_value)
167 result = current_value; 177 result = current_value;
168 else 178 else
169 result = new_value; 179 result = new_value;
170 if (result > max_value) 180 if (result > max_value)
171 return max_value; 181 return max_value;
172 if (result < min_value) 182 if (result < min_value)
173 return min_value; 183 return min_value;
174 return result; 184 return result;
175 } 185 }
176 186
177 void ScrollbarAnimationControllerThinning::ApplyOpacityAndThumbThicknessScale( 187 void ScrollbarAnimationControllerThinning::ApplyOpacity(float opacity) {
178 float opacity,
179 float thumb_thickness_scale) {
180 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) { 188 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
181 if (!scrollbar->is_overlay_scrollbar()) 189 if (!scrollbar->is_overlay_scrollbar())
182 continue; 190 continue;
183 float effective_opacity = 191 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0;
184 scrollbar->CanScrollOrientation()
185 ? AdjustScale(opacity, scrollbar->Opacity(), opacity_change_,
186 kIdleOpacity, 1)
187 : 0;
188 PropertyTrees* property_trees = 192 PropertyTrees* property_trees =
189 scrollbar->layer_tree_impl()->property_trees(); 193 scrollbar->layer_tree_impl()->property_trees();
190 // If this method is called during LayerImpl::PushPropertiesTo, we may not 194 // If this method is called during LayerImpl::PushPropertiesTo, we may not
191 // yet have valid effect_id_to_index_map entries as property trees are 195 // yet have valid effect_id_to_index_map entries as property trees are
192 // pushed after layers during activation. We can skip updating opacity in 196 // pushed after layers during activation. We can skip updating opacity in
193 // that case as we are only registering a scrollbar and because opacity will 197 // that case as we are only registering a scrollbar and because opacity will
194 // be overwritten anyway when property trees are pushed. 198 // be overwritten anyway when property trees are pushed.
195 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, 199 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT,
196 scrollbar->id())) { 200 scrollbar->id())) {
197 property_trees->effect_tree.OnOpacityAnimated( 201 property_trees->effect_tree.OnOpacityAnimated(
198 effective_opacity, 202 effective_opacity,
199 property_trees->effect_id_to_index_map[scrollbar->id()], 203 property_trees->effect_id_to_index_map[scrollbar->id()],
200 scrollbar->layer_tree_impl()); 204 scrollbar->layer_tree_impl());
201 } 205 }
206 }
207
208 is_visible_ = opacity;
209 }
210
211 void ScrollbarAnimationControllerThinning::ApplyThumbThicknessScale(
212 float thumb_thickness_scale) {
213 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
214 if (!scrollbar->is_overlay_scrollbar())
215 continue;
216
202 scrollbar->SetThumbThicknessScaleFactor(AdjustScale( 217 scrollbar->SetThumbThicknessScaleFactor(AdjustScale(
203 thumb_thickness_scale, scrollbar->thumb_thickness_scale_factor(), 218 thumb_thickness_scale, scrollbar->thumb_thickness_scale_factor(),
204 thickness_change_, kIdleThicknessScale, 1)); 219 thickness_change_, kIdleThicknessScale, 1));
205 } 220 }
206 } 221 }
207 222
223 void ScrollbarAnimationControllerThinning::SetCurrentAnimatingProperty(
224 AnimatingProperty property) {
225 if (current_animating_property_ == property)
226 return;
227
228 StopAnimation();
229 current_animating_property_ = property;
230 if (current_animating_property_ == OPACITY) {
231 duration_ = fade_duration_;
232 } else {
233 ApplyOpacity(1.f);
234 duration_ = thinning_duration_;
235 }
236 }
237
208 } // namespace cc 238 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698