OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/animation/scrollbar_animation_controller_linear_fade.h" | 5 #include "cc/animation/scrollbar_animation_controller_linear_fade.h" |
6 | 6 |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "cc/layers/layer_impl.h" | 8 #include "cc/layers/layer_impl.h" |
9 #include "cc/layers/scrollbar_layer_impl_base.h" | 9 #include "cc/layers/scrollbar_layer_impl_base.h" |
10 | 10 |
11 namespace cc { | 11 namespace cc { |
12 | 12 |
13 scoped_ptr<ScrollbarAnimationControllerLinearFade> | 13 scoped_ptr<ScrollbarAnimationControllerLinearFade> |
14 ScrollbarAnimationControllerLinearFade::Create( | 14 ScrollbarAnimationControllerLinearFade::Create( |
15 LayerImpl* scroll_layer, | 15 LayerImpl* scroll_layer, |
16 ScrollbarAnimationControllerClient* client, | 16 ScrollbarAnimationControllerClient* client, |
17 base::TimeDelta delay_before_starting, | 17 base::TimeDelta delay_before_starting, |
18 base::TimeDelta resize_delay_before_starting, | 18 base::TimeDelta resize_delay_before_starting, |
19 base::TimeDelta duration) { | 19 base::TimeDelta duration) { |
20 return make_scoped_ptr( | 20 return make_scoped_ptr(new ScrollbarAnimationControllerLinearFade( |
21 new ScrollbarAnimationControllerLinearFade(scroll_layer, | 21 scroll_layer, client, delay_before_starting, resize_delay_before_starting, |
22 client, | 22 duration)); |
23 delay_before_starting, | |
24 resize_delay_before_starting, | |
25 duration)); | |
26 } | 23 } |
27 | 24 |
28 ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade( | 25 ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade( |
29 LayerImpl* scroll_layer, | 26 LayerImpl* scroll_layer, |
30 ScrollbarAnimationControllerClient* client, | 27 ScrollbarAnimationControllerClient* client, |
31 base::TimeDelta delay_before_starting, | 28 base::TimeDelta delay_before_starting, |
32 base::TimeDelta resize_delay_before_starting, | 29 base::TimeDelta resize_delay_before_starting, |
33 base::TimeDelta duration) | 30 base::TimeDelta duration) |
34 : ScrollbarAnimationController(client, | 31 : ScrollbarAnimationController(scroll_layer, |
| 32 client, |
35 delay_before_starting, | 33 delay_before_starting, |
36 resize_delay_before_starting, | 34 resize_delay_before_starting, |
37 duration), | 35 duration) { |
38 scroll_layer_(scroll_layer) { | |
39 } | 36 } |
40 | 37 |
41 ScrollbarAnimationControllerLinearFade:: | 38 ScrollbarAnimationControllerLinearFade:: |
42 ~ScrollbarAnimationControllerLinearFade() {} | 39 ~ScrollbarAnimationControllerLinearFade() { |
| 40 } |
43 | 41 |
44 void ScrollbarAnimationControllerLinearFade::RunAnimationFrame(float progress) { | 42 void ScrollbarAnimationControllerLinearFade::RunAnimationFrame(float progress) { |
45 ApplyOpacityToScrollbars(1.f - progress); | 43 ApplyOpacityToScrollbars(1.f - progress); |
| 44 client_->SetNeedsRedrawForScrollbarAnimation(); |
46 if (progress == 1.f) | 45 if (progress == 1.f) |
47 StopAnimation(); | 46 StopAnimation(); |
48 } | 47 } |
49 | 48 |
50 void ScrollbarAnimationControllerLinearFade::DidScrollUpdate(bool on_resize) { | 49 void ScrollbarAnimationControllerLinearFade::DidScrollUpdate(bool on_resize) { |
51 ScrollbarAnimationController::DidScrollUpdate(on_resize); | 50 ScrollbarAnimationController::DidScrollUpdate(on_resize); |
52 ApplyOpacityToScrollbars(1.f); | 51 ApplyOpacityToScrollbars(1.f); |
53 } | 52 } |
54 | 53 |
55 void ScrollbarAnimationControllerLinearFade::ApplyOpacityToScrollbars( | 54 void ScrollbarAnimationControllerLinearFade::ApplyOpacityToScrollbars( |
56 float opacity) { | 55 float opacity) { |
57 if (!scroll_layer_->scrollbars()) | 56 if (!scroll_layer_->scrollbars()) |
58 return; | 57 return; |
59 | 58 |
60 LayerImpl::ScrollbarSet* scrollbars = scroll_layer_->scrollbars(); | 59 LayerImpl::ScrollbarSet* scrollbars = scroll_layer_->scrollbars(); |
61 for (LayerImpl::ScrollbarSet::iterator it = scrollbars->begin(); | 60 for (LayerImpl::ScrollbarSet::iterator it = scrollbars->begin(); |
62 it != scrollbars->end(); | 61 it != scrollbars->end(); ++it) { |
63 ++it) { | |
64 ScrollbarLayerImplBase* scrollbar = *it; | 62 ScrollbarLayerImplBase* scrollbar = *it; |
65 | 63 |
66 if (scrollbar->is_overlay_scrollbar()) | 64 if (scrollbar->is_overlay_scrollbar()) |
67 scrollbar->SetOpacity(scrollbar->CanScrollOrientation() ? opacity : 0); | 65 scrollbar->SetOpacity(scrollbar->CanScrollOrientation() ? opacity : 0); |
68 } | 66 } |
69 } | 67 } |
70 | 68 |
71 } // namespace cc | 69 } // namespace cc |
OLD | NEW |