Chromium Code Reviews| 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/input/scrollbar_animation_controller_thinning.h" | 5 #include "cc/input/scrollbar_animation_controller_thinning.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "cc/layers/layer_impl.h" | 9 #include "cc/layers/layer_impl.h" |
| 10 #include "cc/layers/scrollbar_layer_impl_base.h" | 10 #include "cc/layers/scrollbar_layer_impl_base.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 int scroll_layer_id, | 34 int scroll_layer_id, |
| 35 ScrollbarAnimationControllerClient* client, | 35 ScrollbarAnimationControllerClient* client, |
| 36 base::TimeDelta delay_before_starting, | 36 base::TimeDelta delay_before_starting, |
| 37 base::TimeDelta resize_delay_before_starting, | 37 base::TimeDelta resize_delay_before_starting, |
| 38 base::TimeDelta duration) | 38 base::TimeDelta duration) |
| 39 : ScrollbarAnimationController(scroll_layer_id, | 39 : ScrollbarAnimationController(scroll_layer_id, |
| 40 client, | 40 client, |
| 41 delay_before_starting, | 41 delay_before_starting, |
| 42 resize_delay_before_starting, | 42 resize_delay_before_starting, |
| 43 duration), | 43 duration), |
| 44 captured_(false), | |
| 44 mouse_is_over_scrollbar_(false), | 45 mouse_is_over_scrollbar_(false), |
| 45 mouse_is_near_scrollbar_(false), | 46 mouse_is_near_scrollbar_(false), |
| 46 thickness_change_(NONE), | 47 thickness_change_(NONE), |
| 47 opacity_change_(NONE), | 48 opacity_change_(NONE), |
| 48 mouse_move_distance_to_trigger_animation_( | 49 mouse_move_distance_to_trigger_animation_( |
| 49 kDefaultMouseMoveDistanceToTriggerAnimation) { | 50 kDefaultMouseMoveDistanceToTriggerAnimation) { |
| 50 ApplyOpacityAndThumbThicknessScale(kIdleOpacity, kIdleThicknessScale); | 51 ApplyOpacityAndThumbThicknessScale(kIdleOpacity, kIdleThicknessScale); |
| 51 } | 52 } |
| 52 | 53 |
| 53 ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {} | 54 ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {} |
| 54 | 55 |
| 55 void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) { | 56 void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) { |
| 56 float opacity = OpacityAtAnimationProgress(progress); | 57 float opacity = OpacityAtAnimationProgress(progress); |
| 57 float thumb_thickness_scale = | 58 float thumb_thickness_scale = |
| 58 ThumbThicknessScaleAtAnimationProgress(progress); | 59 ThumbThicknessScaleAtAnimationProgress(progress); |
| 59 ApplyOpacityAndThumbThicknessScale(opacity, thumb_thickness_scale); | 60 ApplyOpacityAndThumbThicknessScale(opacity, thumb_thickness_scale); |
| 60 client_->SetNeedsRedrawForScrollbarAnimation(); | 61 client_->SetNeedsRedrawForScrollbarAnimation(); |
| 61 if (progress == 1.f) { | 62 if (progress == 1.f) { |
| 62 opacity_change_ = NONE; | 63 opacity_change_ = NONE; |
| 63 thickness_change_ = NONE; | 64 thickness_change_ = NONE; |
| 64 StopAnimation(); | 65 StopAnimation(); |
| 65 } | 66 } |
| 66 } | 67 } |
| 67 | 68 |
| 69 void ScrollbarAnimationControllerThinning::DidCaptureScrollbarBegin() { | |
| 70 captured_ = true; | |
| 71 ApplyOpacityAndThumbThicknessScale(1, 1.f); | |
| 72 } | |
| 73 | |
| 74 void ScrollbarAnimationControllerThinning::DidCaptureScrollbarEnd() { | |
| 75 captured_ = false; | |
| 76 | |
| 77 if (!mouse_is_over_scrollbar_) | |
| 78 opacity_change_ = DECREASE; | |
| 79 if (!mouse_is_near_scrollbar_) | |
| 80 thickness_change_ = DECREASE; | |
| 81 StartAnimation(); | |
| 82 } | |
| 83 | |
| 68 void ScrollbarAnimationControllerThinning::DidMouseMoveOffScrollbar() { | 84 void ScrollbarAnimationControllerThinning::DidMouseMoveOffScrollbar() { |
| 69 mouse_is_over_scrollbar_ = false; | 85 mouse_is_over_scrollbar_ = false; |
| 70 mouse_is_near_scrollbar_ = false; | 86 mouse_is_near_scrollbar_ = false; |
| 87 | |
| 88 if (captured_) { | |
|
dtapuska
2016/09/22 20:34:23
Seems you mixed up brackets for single lines style
| |
| 89 return; | |
| 90 } | |
| 91 | |
| 71 opacity_change_ = DECREASE; | 92 opacity_change_ = DECREASE; |
| 72 thickness_change_ = DECREASE; | 93 thickness_change_ = DECREASE; |
| 73 StartAnimation(); | 94 StartAnimation(); |
| 74 } | 95 } |
| 75 | 96 |
| 76 void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) { | 97 void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) { |
| 98 if (captured_) { | |
| 99 return; | |
| 100 } | |
| 101 | |
| 77 ScrollbarAnimationController::DidScrollUpdate(on_resize); | 102 ScrollbarAnimationController::DidScrollUpdate(on_resize); |
| 78 ApplyOpacityAndThumbThicknessScale( | 103 ApplyOpacityAndThumbThicknessScale( |
| 79 1, mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale); | 104 1, mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale); |
| 80 | 105 |
| 81 if (!mouse_is_over_scrollbar_) | 106 if (!mouse_is_over_scrollbar_) |
| 82 opacity_change_ = DECREASE; | 107 opacity_change_ = DECREASE; |
| 83 } | 108 } |
| 84 | 109 |
| 85 void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) { | 110 void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) { |
| 86 bool mouse_is_over_scrollbar = distance == 0.0; | 111 bool mouse_is_over_scrollbar = distance == 0.0; |
| 87 bool mouse_is_near_scrollbar = | 112 bool mouse_is_near_scrollbar = |
| 88 distance < mouse_move_distance_to_trigger_animation_; | 113 distance < mouse_move_distance_to_trigger_animation_; |
| 89 | 114 |
| 90 if (mouse_is_over_scrollbar == mouse_is_over_scrollbar_ && | 115 if (captured_) { |
| 91 mouse_is_near_scrollbar == mouse_is_near_scrollbar_) | 116 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar; |
| 117 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar; | |
| 92 return; | 118 return; |
| 119 } else { | |
| 120 if (mouse_is_over_scrollbar == mouse_is_over_scrollbar_ && | |
| 121 mouse_is_near_scrollbar == mouse_is_near_scrollbar_) | |
| 122 return; | |
| 93 | 123 |
| 94 if (mouse_is_over_scrollbar_ != mouse_is_over_scrollbar) { | 124 if (mouse_is_over_scrollbar_ != mouse_is_over_scrollbar) { |
| 95 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar; | 125 mouse_is_over_scrollbar_ = mouse_is_over_scrollbar; |
| 96 opacity_change_ = mouse_is_over_scrollbar_ ? INCREASE : DECREASE; | 126 opacity_change_ = mouse_is_over_scrollbar_ ? INCREASE : DECREASE; |
| 127 } | |
| 128 | |
| 129 if (mouse_is_near_scrollbar_ != mouse_is_near_scrollbar) { | |
| 130 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar; | |
| 131 thickness_change_ = mouse_is_near_scrollbar_ ? INCREASE : DECREASE; | |
| 132 } | |
| 133 | |
| 134 StartAnimation(); | |
| 97 } | 135 } |
| 98 | |
| 99 if (mouse_is_near_scrollbar_ != mouse_is_near_scrollbar) { | |
| 100 mouse_is_near_scrollbar_ = mouse_is_near_scrollbar; | |
| 101 thickness_change_ = mouse_is_near_scrollbar_ ? INCREASE : DECREASE; | |
| 102 } | |
| 103 | |
| 104 StartAnimation(); | |
| 105 } | 136 } |
| 106 | 137 |
| 107 float ScrollbarAnimationControllerThinning::OpacityAtAnimationProgress( | 138 float ScrollbarAnimationControllerThinning::OpacityAtAnimationProgress( |
| 108 float progress) { | 139 float progress) { |
| 109 if (opacity_change_ == NONE) | 140 if (opacity_change_ == NONE) |
| 110 return mouse_is_over_scrollbar_ ? 1.f : kIdleOpacity; | 141 return mouse_is_over_scrollbar_ ? 1.f : kIdleOpacity; |
| 111 float factor = opacity_change_ == INCREASE ? progress : (1.f - progress); | 142 float factor = opacity_change_ == INCREASE ? progress : (1.f - progress); |
| 112 float ret = ((1.f - kIdleOpacity) * factor) + kIdleOpacity; | 143 float ret = ((1.f - kIdleOpacity) * factor) + kIdleOpacity; |
| 113 return ret; | 144 return ret; |
| 114 } | 145 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 property_trees->effect_id_to_index_map[scrollbar->id()], | 188 property_trees->effect_id_to_index_map[scrollbar->id()], |
| 158 scrollbar->layer_tree_impl()); | 189 scrollbar->layer_tree_impl()); |
| 159 } | 190 } |
| 160 scrollbar->SetThumbThicknessScaleFactor(AdjustScale( | 191 scrollbar->SetThumbThicknessScaleFactor(AdjustScale( |
| 161 thumb_thickness_scale, scrollbar->thumb_thickness_scale_factor(), | 192 thumb_thickness_scale, scrollbar->thumb_thickness_scale_factor(), |
| 162 thickness_change_)); | 193 thickness_change_)); |
| 163 } | 194 } |
| 164 } | 195 } |
| 165 | 196 |
| 166 } // namespace cc | 197 } // namespace cc |
| OLD | NEW |