Home | History | Annotate | Download | only in animation
      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 duration) {
     19   return make_scoped_ptr(new ScrollbarAnimationControllerLinearFade(
     20       scroll_layer, client, delay_before_starting, duration));
     21 }
     22 
     23 ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade(
     24     LayerImpl* scroll_layer,
     25     ScrollbarAnimationControllerClient* client,
     26     base::TimeDelta delay_before_starting,
     27     base::TimeDelta duration)
     28     : ScrollbarAnimationController(client, delay_before_starting, duration),
     29       scroll_layer_(scroll_layer) {
     30 }
     31 
     32 ScrollbarAnimationControllerLinearFade::
     33     ~ScrollbarAnimationControllerLinearFade() {}
     34 
     35 void ScrollbarAnimationControllerLinearFade::RunAnimationFrame(float progress) {
     36   ApplyOpacityToScrollbars(1.f - progress);
     37   if (progress == 1.f)
     38     StopAnimation();
     39 }
     40 
     41 void ScrollbarAnimationControllerLinearFade::DidScrollUpdate() {
     42   ScrollbarAnimationController::DidScrollUpdate();
     43   ApplyOpacityToScrollbars(1.f);
     44 }
     45 
     46 void ScrollbarAnimationControllerLinearFade::ApplyOpacityToScrollbars(
     47     float opacity) {
     48   if (!scroll_layer_->scrollbars())
     49     return;
     50 
     51   LayerImpl::ScrollbarSet* scrollbars = scroll_layer_->scrollbars();
     52   for (LayerImpl::ScrollbarSet::iterator it = scrollbars->begin();
     53        it != scrollbars->end();
     54        ++it) {
     55     ScrollbarLayerImplBase* scrollbar = *it;
     56     if (scrollbar->is_overlay_scrollbar())
     57       scrollbar->SetOpacity(opacity);
     58   }
     59 }
     60 
     61 }  // namespace cc
     62