| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_thinning.h" | 5 #include "cc/animation/scrollbar_animation_controller_thinning.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 #include "cc/trees/layer_tree_impl.h" |
| 10 | 11 |
| 11 namespace { | 12 namespace { |
| 12 const float kIdleThicknessScale = 0.4f; | 13 const float kIdleThicknessScale = 0.4f; |
| 13 const float kIdleOpacity = 0.7f; | 14 const float kIdleOpacity = 0.7f; |
| 14 const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f; | 15 const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f; |
| 15 } | 16 } |
| 16 | 17 |
| 17 namespace cc { | 18 namespace cc { |
| 18 | 19 |
| 19 scoped_ptr<ScrollbarAnimationControllerThinning> | 20 scoped_ptr<ScrollbarAnimationControllerThinning> |
| 20 ScrollbarAnimationControllerThinning::Create( | 21 ScrollbarAnimationControllerThinning::Create( |
| 21 LayerImpl* scroll_layer, | 22 LayerImpl* scroll_layer, |
| 22 ScrollbarAnimationControllerClient* client, | 23 ScrollbarAnimationControllerClient* client, |
| 23 base::TimeDelta delay_before_starting, | 24 base::TimeDelta delay_before_starting, |
| 24 base::TimeDelta resize_delay_before_starting, | 25 base::TimeDelta resize_delay_before_starting, |
| 25 base::TimeDelta duration) { | 26 base::TimeDelta duration) { |
| 26 return make_scoped_ptr( | 27 return make_scoped_ptr(new ScrollbarAnimationControllerThinning( |
| 27 new ScrollbarAnimationControllerThinning(scroll_layer, | 28 scroll_layer, client, delay_before_starting, resize_delay_before_starting, |
| 28 client, | 29 duration)); |
| 29 delay_before_starting, | |
| 30 resize_delay_before_starting, | |
| 31 duration)); | |
| 32 } | 30 } |
| 33 | 31 |
| 34 ScrollbarAnimationControllerThinning::ScrollbarAnimationControllerThinning( | 32 ScrollbarAnimationControllerThinning::ScrollbarAnimationControllerThinning( |
| 35 LayerImpl* scroll_layer, | 33 LayerImpl* scroll_layer, |
| 36 ScrollbarAnimationControllerClient* client, | 34 ScrollbarAnimationControllerClient* client, |
| 37 base::TimeDelta delay_before_starting, | 35 base::TimeDelta delay_before_starting, |
| 38 base::TimeDelta resize_delay_before_starting, | 36 base::TimeDelta resize_delay_before_starting, |
| 39 base::TimeDelta duration) | 37 base::TimeDelta duration) |
| 40 : ScrollbarAnimationController(client, | 38 : ScrollbarAnimationController(scroll_layer, |
| 39 client, |
| 41 delay_before_starting, | 40 delay_before_starting, |
| 42 resize_delay_before_starting, | 41 resize_delay_before_starting, |
| 43 duration), | 42 duration), |
| 44 scroll_layer_(scroll_layer), | |
| 45 mouse_is_over_scrollbar_(false), | 43 mouse_is_over_scrollbar_(false), |
| 46 mouse_is_near_scrollbar_(false), | 44 mouse_is_near_scrollbar_(false), |
| 47 thickness_change_(NONE), | 45 thickness_change_(NONE), |
| 48 opacity_change_(NONE), | 46 opacity_change_(NONE), |
| 49 mouse_move_distance_to_trigger_animation_( | 47 mouse_move_distance_to_trigger_animation_( |
| 50 kDefaultMouseMoveDistanceToTriggerAnimation) { | 48 kDefaultMouseMoveDistanceToTriggerAnimation) { |
| 51 ApplyOpacityAndThumbThicknessScale(kIdleOpacity, kIdleThicknessScale); | 49 ApplyOpacityAndThumbThicknessScale(kIdleOpacity, kIdleThicknessScale); |
| 52 } | 50 } |
| 53 | 51 |
| 54 ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() { | 52 ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() { |
| 55 } | 53 } |
| 56 | 54 |
| 57 void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) { | 55 void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) { |
| 58 float opacity = OpacityAtAnimationProgress(progress); | 56 float opacity = OpacityAtAnimationProgress(progress); |
| 59 float thumb_thickness_scale = ThumbThicknessScaleAtAnimationProgress( | 57 float thumb_thickness_scale = |
| 60 progress); | 58 ThumbThicknessScaleAtAnimationProgress(progress); |
| 61 ApplyOpacityAndThumbThicknessScale(opacity, thumb_thickness_scale); | 59 ApplyOpacityAndThumbThicknessScale(opacity, thumb_thickness_scale); |
| 60 client_->SetNeedsRedrawForScrollbarAnimation(); |
| 62 if (progress == 1.f) { | 61 if (progress == 1.f) { |
| 63 opacity_change_ = NONE; | 62 opacity_change_ = NONE; |
| 64 thickness_change_ = NONE; | 63 thickness_change_ = NONE; |
| 65 StopAnimation(); | 64 StopAnimation(); |
| 66 } | 65 } |
| 67 } | 66 } |
| 68 | 67 |
| 69 void ScrollbarAnimationControllerThinning::DidMouseMoveOffScrollbar() { | 68 void ScrollbarAnimationControllerThinning::DidMouseMoveOffScrollbar() { |
| 70 mouse_is_over_scrollbar_ = false; | 69 mouse_is_over_scrollbar_ = false; |
| 71 mouse_is_near_scrollbar_ = false; | 70 mouse_is_near_scrollbar_ = false; |
| 72 opacity_change_ = DECREASE; | 71 opacity_change_ = DECREASE; |
| 73 thickness_change_ = DECREASE; | 72 thickness_change_ = DECREASE; |
| 74 StartAnimation(); | 73 StartAnimation(); |
| 75 } | 74 } |
| 76 | 75 |
| 77 void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) { | 76 void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) { |
| 78 ScrollbarAnimationController::DidScrollUpdate(on_resize); | 77 ScrollbarAnimationController::DidScrollUpdate(on_resize); |
| 79 ApplyOpacityAndThumbThicknessScale( | 78 ApplyOpacityAndThumbThicknessScale( |
| 80 1, mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale); | 79 1, mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale); |
| 81 | 80 |
| 82 if (!mouse_is_over_scrollbar_) | 81 if (!mouse_is_over_scrollbar_) |
| 83 opacity_change_ = DECREASE; | 82 opacity_change_ = DECREASE; |
| 84 } | 83 } |
| 85 | 84 |
| 86 void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) { | 85 void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) { |
| 87 bool mouse_is_over_scrollbar = distance == 0.0; | 86 bool mouse_is_over_scrollbar = distance == 0.0; |
| 88 bool mouse_is_near_scrollbar = | 87 bool mouse_is_near_scrollbar = |
| 89 distance < mouse_move_distance_to_trigger_animation_; | 88 distance < mouse_move_distance_to_trigger_animation_; |
| 90 | 89 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 107 | 106 |
| 108 float ScrollbarAnimationControllerThinning::OpacityAtAnimationProgress( | 107 float ScrollbarAnimationControllerThinning::OpacityAtAnimationProgress( |
| 109 float progress) { | 108 float progress) { |
| 110 if (opacity_change_ == NONE) | 109 if (opacity_change_ == NONE) |
| 111 return mouse_is_over_scrollbar_ ? 1.f : kIdleOpacity; | 110 return mouse_is_over_scrollbar_ ? 1.f : kIdleOpacity; |
| 112 float factor = opacity_change_ == INCREASE ? progress : (1.f - progress); | 111 float factor = opacity_change_ == INCREASE ? progress : (1.f - progress); |
| 113 float ret = ((1.f - kIdleOpacity) * factor) + kIdleOpacity; | 112 float ret = ((1.f - kIdleOpacity) * factor) + kIdleOpacity; |
| 114 return ret; | 113 return ret; |
| 115 } | 114 } |
| 116 | 115 |
| 117 float | 116 float ScrollbarAnimationControllerThinning:: |
| 118 ScrollbarAnimationControllerThinning::ThumbThicknessScaleAtAnimationProgress( | 117 ThumbThicknessScaleAtAnimationProgress(float progress) { |
| 119 float progress) { | |
| 120 if (thickness_change_ == NONE) | 118 if (thickness_change_ == NONE) |
| 121 return mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale; | 119 return mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale; |
| 122 float factor = thickness_change_ == INCREASE ? progress : (1.f - progress); | 120 float factor = thickness_change_ == INCREASE ? progress : (1.f - progress); |
| 123 return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale; | 121 return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale; |
| 124 } | 122 } |
| 125 | 123 |
| 126 float ScrollbarAnimationControllerThinning::AdjustScale( | 124 float ScrollbarAnimationControllerThinning::AdjustScale( |
| 127 float new_value, | 125 float new_value, |
| 128 float current_value, | 126 float current_value, |
| 129 AnimationChange animation_change) { | 127 AnimationChange animation_change) { |
| 130 if (animation_change == INCREASE && current_value > new_value) | 128 if (animation_change == INCREASE && current_value > new_value) |
| 131 return current_value; | 129 return current_value; |
| 132 if (animation_change == DECREASE && current_value < new_value) | 130 if (animation_change == DECREASE && current_value < new_value) |
| 133 return current_value; | 131 return current_value; |
| 134 return new_value; | 132 return new_value; |
| 135 } | 133 } |
| 136 | 134 |
| 137 void ScrollbarAnimationControllerThinning::ApplyOpacityAndThumbThicknessScale( | 135 void ScrollbarAnimationControllerThinning::ApplyOpacityAndThumbThicknessScale( |
| 138 float opacity, float thumb_thickness_scale) { | 136 float opacity, |
| 137 float thumb_thickness_scale) { |
| 139 if (!scroll_layer_->scrollbars()) | 138 if (!scroll_layer_->scrollbars()) |
| 140 return; | 139 return; |
| 141 | 140 |
| 142 LayerImpl::ScrollbarSet* scrollbars = scroll_layer_->scrollbars(); | 141 LayerImpl::ScrollbarSet* scrollbars = scroll_layer_->scrollbars(); |
| 143 for (LayerImpl::ScrollbarSet::iterator it = scrollbars->begin(); | 142 for (LayerImpl::ScrollbarSet::iterator it = scrollbars->begin(); |
| 144 it != scrollbars->end(); | 143 it != scrollbars->end(); ++it) { |
| 145 ++it) { | |
| 146 ScrollbarLayerImplBase* scrollbar = *it; | 144 ScrollbarLayerImplBase* scrollbar = *it; |
| 147 if (scrollbar->is_overlay_scrollbar()) { | 145 if (scrollbar->is_overlay_scrollbar()) { |
| 148 float effectiveOpacity = | 146 float effectiveOpacity = |
| 149 scrollbar->CanScrollOrientation() | 147 scrollbar->CanScrollOrientation() |
| 150 ? AdjustScale(opacity, scrollbar->opacity(), opacity_change_) | 148 ? AdjustScale(opacity, scrollbar->opacity(), opacity_change_) |
| 151 : 0; | 149 : 0; |
| 152 | 150 |
| 153 scrollbar->SetOpacity(effectiveOpacity); | 151 scrollbar->SetOpacity(effectiveOpacity); |
| 154 scrollbar->SetThumbThicknessScaleFactor( | 152 scrollbar->SetThumbThicknessScaleFactor(AdjustScale( |
| 155 AdjustScale(thumb_thickness_scale, | 153 thumb_thickness_scale, scrollbar->thumb_thickness_scale_factor(), |
| 156 scrollbar->thumb_thickness_scale_factor(), | 154 thickness_change_)); |
| 157 thickness_change_)); | |
| 158 } | 155 } |
| 159 } | 156 } |
| 160 } | 157 } |
| 161 | 158 |
| 162 } // namespace cc | 159 } // namespace cc |
| OLD | NEW |