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
3 // found in the LICENSE file.
5 #ifndef CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_
6 #define CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/animation/scrollbar_animation_controller.h"
10 #include "cc/base/cc_export.h"
15 // Scrollbar animation that partially fades and thins after an idle delay,
16 // and reacts to mouse movements.
17 class CC_EXPORT ScrollbarAnimationControllerThinning
18 : public ScrollbarAnimationController
{
20 static scoped_ptr
<ScrollbarAnimationControllerThinning
> Create(
21 LayerImpl
* scroll_layer
,
22 ScrollbarAnimationControllerClient
* client
,
23 base::TimeDelta delay_before_starting
,
24 base::TimeDelta duration
);
26 virtual ~ScrollbarAnimationControllerThinning();
28 void set_mouse_move_distance_for_test(float distance
) {
29 mouse_move_distance_to_trigger_animation_
= distance
;
31 bool mouse_is_over_scrollbar() const { return mouse_is_over_scrollbar_
; }
32 bool mouse_is_near_scrollbar() const { return mouse_is_near_scrollbar_
; }
34 virtual void DidScrollUpdate() OVERRIDE
;
35 virtual void DidMouseMoveOffScrollbar() OVERRIDE
;
36 virtual void DidMouseMoveNear(float distance
) OVERRIDE
;
39 ScrollbarAnimationControllerThinning(
40 LayerImpl
* scroll_layer
,
41 ScrollbarAnimationControllerClient
* client
,
42 base::TimeDelta delay_before_starting
,
43 base::TimeDelta duration
);
45 virtual void RunAnimationFrame(float progress
) OVERRIDE
;
48 // Describes whether the current animation should INCREASE (darken / thicken)
49 // a bar or DECREASE it (lighten / thin).
50 enum AnimationChange
{
55 float OpacityAtAnimationProgress(float progress
);
56 float ThumbThicknessScaleAtAnimationProgress(float progress
);
57 float AdjustScale(float new_value
,
59 AnimationChange animation_change
);
60 void ApplyOpacityAndThumbThicknessScale(float opacity
,
61 float thumb_thickness_scale
);
63 LayerImpl
* scroll_layer_
;
65 bool mouse_is_over_scrollbar_
;
66 bool mouse_is_near_scrollbar_
;
67 // Are we narrowing or thickening the bars.
68 AnimationChange thickness_change_
;
69 // Are we darkening or lightening the bars.
70 AnimationChange opacity_change_
;
71 // How close should the mouse be to the scrollbar before we thicken it.
72 float mouse_move_distance_to_trigger_animation_
;
74 DISALLOW_COPY_AND_ASSIGN(ScrollbarAnimationControllerThinning
);
79 #endif // CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_