Roll Libjingle 8093:8097
[chromium-blink-merge.git] / cc / animation / scrollbar_animation_controller_thinning.h
blob2cf30f5b82109b48f811257d996ec671ccbedb9d
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"
12 namespace cc {
13 class LayerImpl;
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 {
19 public:
20 static scoped_ptr<ScrollbarAnimationControllerThinning> Create(
21 LayerImpl* scroll_layer,
22 ScrollbarAnimationControllerClient* client,
23 base::TimeDelta delay_before_starting,
24 base::TimeDelta resize_delay_before_starting,
25 base::TimeDelta duration);
27 ~ScrollbarAnimationControllerThinning() override;
29 void set_mouse_move_distance_for_test(float distance) {
30 mouse_move_distance_to_trigger_animation_ = distance;
32 bool mouse_is_over_scrollbar() const { return mouse_is_over_scrollbar_; }
33 bool mouse_is_near_scrollbar() const { return mouse_is_near_scrollbar_; }
35 void DidScrollUpdate(bool on_resize) override;
36 void DidMouseMoveOffScrollbar() override;
37 void DidMouseMoveNear(float distance) override;
39 protected:
40 ScrollbarAnimationControllerThinning(
41 LayerImpl* scroll_layer,
42 ScrollbarAnimationControllerClient* client,
43 base::TimeDelta delay_before_starting,
44 base::TimeDelta resize_delay_before_starting,
45 base::TimeDelta duration);
47 void RunAnimationFrame(float progress) override;
49 private:
50 // Describes whether the current animation should INCREASE (darken / thicken)
51 // a bar or DECREASE it (lighten / thin).
52 enum AnimationChange {
53 NONE,
54 INCREASE,
55 DECREASE
57 float OpacityAtAnimationProgress(float progress);
58 float ThumbThicknessScaleAtAnimationProgress(float progress);
59 float AdjustScale(float new_value,
60 float current_value,
61 AnimationChange animation_change);
62 void ApplyOpacityAndThumbThicknessScale(float opacity,
63 float thumb_thickness_scale);
65 LayerImpl* scroll_layer_;
67 bool mouse_is_over_scrollbar_;
68 bool mouse_is_near_scrollbar_;
69 // Are we narrowing or thickening the bars.
70 AnimationChange thickness_change_;
71 // Are we darkening or lightening the bars.
72 AnimationChange opacity_change_;
73 // How close should the mouse be to the scrollbar before we thicken it.
74 float mouse_move_distance_to_trigger_animation_;
76 DISALLOW_COPY_AND_ASSIGN(ScrollbarAnimationControllerThinning);
79 } // namespace cc
81 #endif // CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_