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(new ScrollbarAnimationControllerLinearFade(
21 scroll_layer
, client
, delay_before_starting
, resize_delay_before_starting
,
25 ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade(
26 LayerImpl
* scroll_layer
,
27 ScrollbarAnimationControllerClient
* client
,
28 base::TimeDelta delay_before_starting
,
29 base::TimeDelta resize_delay_before_starting
,
30 base::TimeDelta duration
)
31 : ScrollbarAnimationController(scroll_layer
,
33 delay_before_starting
,
34 resize_delay_before_starting
,
38 ScrollbarAnimationControllerLinearFade::
39 ~ScrollbarAnimationControllerLinearFade() {
42 void ScrollbarAnimationControllerLinearFade::RunAnimationFrame(float progress
) {
43 ApplyOpacityToScrollbars(1.f
- progress
);
44 client_
->SetNeedsRedrawForScrollbarAnimation();
49 void ScrollbarAnimationControllerLinearFade::DidScrollUpdate(bool on_resize
) {
50 ScrollbarAnimationController::DidScrollUpdate(on_resize
);
51 ApplyOpacityToScrollbars(1.f
);
54 void ScrollbarAnimationControllerLinearFade::ApplyOpacityToScrollbars(
56 if (!scroll_layer_
->scrollbars())
59 LayerImpl::ScrollbarSet
* scrollbars
= scroll_layer_
->scrollbars();
60 for (LayerImpl::ScrollbarSet::iterator it
= scrollbars
->begin();
61 it
!= scrollbars
->end(); ++it
) {
62 ScrollbarLayerImplBase
* scrollbar
= *it
;
64 if (scrollbar
->is_overlay_scrollbar())
65 scrollbar
->SetOpacity(scrollbar
->CanScrollOrientation() ? opacity
: 0);