1 // Copyright 2012 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 #include "cc/animation/scrollbar_animation_controller_linear_fade.h"
7 #include "base/time/time.h"
8 #include "cc/layers/layer_impl.h"
9 #include "cc/layers/scrollbar_layer_impl_base.h"
13 scoped_ptr
<ScrollbarAnimationControllerLinearFade
>
14 ScrollbarAnimationControllerLinearFade::Create(
15 LayerImpl
* scroll_layer
,
16 ScrollbarAnimationControllerClient
* client
,
17 base::TimeDelta delay_before_starting
,
18 base::TimeDelta resize_delay_before_starting
,
19 base::TimeDelta duration
) {
20 return make_scoped_ptr(
21 new ScrollbarAnimationControllerLinearFade(scroll_layer
,
23 delay_before_starting
,
24 resize_delay_before_starting
,
28 ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade(
29 LayerImpl
* scroll_layer
,
30 ScrollbarAnimationControllerClient
* client
,
31 base::TimeDelta delay_before_starting
,
32 base::TimeDelta resize_delay_before_starting
,
33 base::TimeDelta duration
)
34 : ScrollbarAnimationController(client
,
35 delay_before_starting
,
36 resize_delay_before_starting
,
38 scroll_layer_(scroll_layer
) {
41 ScrollbarAnimationControllerLinearFade::
42 ~ScrollbarAnimationControllerLinearFade() {}
44 void ScrollbarAnimationControllerLinearFade::RunAnimationFrame(float progress
) {
45 ApplyOpacityToScrollbars(1.f
- progress
);
50 void ScrollbarAnimationControllerLinearFade::DidScrollUpdate(bool on_resize
) {
51 ScrollbarAnimationController::DidScrollUpdate(on_resize
);
52 ApplyOpacityToScrollbars(1.f
);
55 void ScrollbarAnimationControllerLinearFade::ApplyOpacityToScrollbars(
57 if (!scroll_layer_
->scrollbars())
60 LayerImpl::ScrollbarSet
* scrollbars
= scroll_layer_
->scrollbars();
61 for (LayerImpl::ScrollbarSet::iterator it
= scrollbars
->begin();
62 it
!= scrollbars
->end();
64 ScrollbarLayerImplBase
* scrollbar
= *it
;
66 if (scrollbar
->is_overlay_scrollbar())
67 scrollbar
->SetOpacity(scrollbar
->CanScrollOrientation() ? opacity
: 0);