Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / cc / animation / scrollbar_animation_controller_linear_fade.cc
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.
4
5 #include "cc/animation/scrollbar_animation_controller_linear_fade.h"
6
7 #include "base/time/time.h"
8 #include "cc/layers/layer_impl.h"
9 #include "cc/layers/scrollbar_layer_impl_base.h"
10
11 namespace cc {
12
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,
22                                                  client,
23                                                  delay_before_starting,
24                                                  resize_delay_before_starting,
25                                                  duration));
26 }
27
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,
37                                    duration),
38       scroll_layer_(scroll_layer) {
39 }
40
41 ScrollbarAnimationControllerLinearFade::
42     ~ScrollbarAnimationControllerLinearFade() {}
43
44 void ScrollbarAnimationControllerLinearFade::RunAnimationFrame(float progress) {
45   ApplyOpacityToScrollbars(1.f - progress);
46   if (progress == 1.f)
47     StopAnimation();
48 }
49
50 void ScrollbarAnimationControllerLinearFade::DidScrollUpdate(bool on_resize) {
51   ScrollbarAnimationController::DidScrollUpdate(on_resize);
52   ApplyOpacityToScrollbars(1.f);
53 }
54
55 void ScrollbarAnimationControllerLinearFade::ApplyOpacityToScrollbars(
56     float opacity) {
57   if (!scroll_layer_->scrollbars())
58     return;
59
60   LayerImpl::ScrollbarSet* scrollbars = scroll_layer_->scrollbars();
61   for (LayerImpl::ScrollbarSet::iterator it = scrollbars->begin();
62        it != scrollbars->end();
63        ++it) {
64     ScrollbarLayerImplBase* scrollbar = *it;
65
66     if (scrollbar->is_overlay_scrollbar())
67       scrollbar->SetOpacity(scrollbar->CanScrollOrientation() ? opacity : 0);
68   }
69 }
70
71 }  // namespace cc