summaryrefslogtreecommitdiffstats
path: root/cc/input/scrollbar_animation_controller_thinning.cc
diff options
context:
space:
mode:
authorloyso <loyso@chromium.org>2016-02-23 18:59:42 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-24 03:02:04 +0000
commit455b4f607405393fb2f2231cf34b87efee527356 (patch)
treebeca22167affa99ad9bfe6117b40ee5f7a739f39 /cc/input/scrollbar_animation_controller_thinning.cc
parentb50b8e5961af7d8cd3c3b48de4e91689206fc377 (diff)
downloadchromium_src-455b4f607405393fb2f2231cf34b87efee527356.zip
chromium_src-455b4f607405393fb2f2231cf34b87efee527356.tar.gz
chromium_src-455b4f607405393fb2f2231cf34b87efee527356.tar.bz2
CC Animation: Move scrollbar* files to cc/input
BUG=575053 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1730853002 Cr-Commit-Position: refs/heads/master@{#377200}
Diffstat (limited to 'cc/input/scrollbar_animation_controller_thinning.cc')
-rw-r--r--cc/input/scrollbar_animation_controller_thinning.cc152
1 files changed, 152 insertions, 0 deletions
diff --git a/cc/input/scrollbar_animation_controller_thinning.cc b/cc/input/scrollbar_animation_controller_thinning.cc
new file mode 100644
index 0000000..8b801ab
--- /dev/null
+++ b/cc/input/scrollbar_animation_controller_thinning.cc
@@ -0,0 +1,152 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/input/scrollbar_animation_controller_thinning.h"
+
+#include "base/time/time.h"
+#include "cc/layers/layer_impl.h"
+#include "cc/layers/scrollbar_layer_impl_base.h"
+#include "cc/trees/layer_tree_impl.h"
+
+namespace {
+const float kIdleThicknessScale = 0.4f;
+const float kIdleOpacity = 0.7f;
+const float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f;
+}
+
+namespace cc {
+
+scoped_ptr<ScrollbarAnimationControllerThinning>
+ScrollbarAnimationControllerThinning::Create(
+ int scroll_layer_id,
+ ScrollbarAnimationControllerClient* client,
+ base::TimeDelta delay_before_starting,
+ base::TimeDelta resize_delay_before_starting,
+ base::TimeDelta duration) {
+ return make_scoped_ptr(new ScrollbarAnimationControllerThinning(
+ scroll_layer_id, client, delay_before_starting,
+ resize_delay_before_starting, duration));
+}
+
+ScrollbarAnimationControllerThinning::ScrollbarAnimationControllerThinning(
+ int scroll_layer_id,
+ ScrollbarAnimationControllerClient* client,
+ base::TimeDelta delay_before_starting,
+ base::TimeDelta resize_delay_before_starting,
+ base::TimeDelta duration)
+ : ScrollbarAnimationController(scroll_layer_id,
+ client,
+ delay_before_starting,
+ resize_delay_before_starting,
+ duration),
+ mouse_is_over_scrollbar_(false),
+ mouse_is_near_scrollbar_(false),
+ thickness_change_(NONE),
+ opacity_change_(NONE),
+ mouse_move_distance_to_trigger_animation_(
+ kDefaultMouseMoveDistanceToTriggerAnimation) {
+ ApplyOpacityAndThumbThicknessScale(kIdleOpacity, kIdleThicknessScale);
+}
+
+ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {}
+
+void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) {
+ float opacity = OpacityAtAnimationProgress(progress);
+ float thumb_thickness_scale =
+ ThumbThicknessScaleAtAnimationProgress(progress);
+ ApplyOpacityAndThumbThicknessScale(opacity, thumb_thickness_scale);
+ client_->SetNeedsRedrawForScrollbarAnimation();
+ if (progress == 1.f) {
+ opacity_change_ = NONE;
+ thickness_change_ = NONE;
+ StopAnimation();
+ }
+}
+
+void ScrollbarAnimationControllerThinning::DidMouseMoveOffScrollbar() {
+ mouse_is_over_scrollbar_ = false;
+ mouse_is_near_scrollbar_ = false;
+ opacity_change_ = DECREASE;
+ thickness_change_ = DECREASE;
+ StartAnimation();
+}
+
+void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) {
+ ScrollbarAnimationController::DidScrollUpdate(on_resize);
+ ApplyOpacityAndThumbThicknessScale(
+ 1, mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale);
+
+ if (!mouse_is_over_scrollbar_)
+ opacity_change_ = DECREASE;
+}
+
+void ScrollbarAnimationControllerThinning::DidMouseMoveNear(float distance) {
+ bool mouse_is_over_scrollbar = distance == 0.0;
+ bool mouse_is_near_scrollbar =
+ distance < mouse_move_distance_to_trigger_animation_;
+
+ if (mouse_is_over_scrollbar == mouse_is_over_scrollbar_ &&
+ mouse_is_near_scrollbar == mouse_is_near_scrollbar_)
+ return;
+
+ if (mouse_is_over_scrollbar_ != mouse_is_over_scrollbar) {
+ mouse_is_over_scrollbar_ = mouse_is_over_scrollbar;
+ opacity_change_ = mouse_is_over_scrollbar_ ? INCREASE : DECREASE;
+ }
+
+ if (mouse_is_near_scrollbar_ != mouse_is_near_scrollbar) {
+ mouse_is_near_scrollbar_ = mouse_is_near_scrollbar;
+ thickness_change_ = mouse_is_near_scrollbar_ ? INCREASE : DECREASE;
+ }
+
+ StartAnimation();
+}
+
+float ScrollbarAnimationControllerThinning::OpacityAtAnimationProgress(
+ float progress) {
+ if (opacity_change_ == NONE)
+ return mouse_is_over_scrollbar_ ? 1.f : kIdleOpacity;
+ float factor = opacity_change_ == INCREASE ? progress : (1.f - progress);
+ float ret = ((1.f - kIdleOpacity) * factor) + kIdleOpacity;
+ return ret;
+}
+
+float ScrollbarAnimationControllerThinning::
+ ThumbThicknessScaleAtAnimationProgress(float progress) {
+ if (thickness_change_ == NONE)
+ return mouse_is_near_scrollbar_ ? 1.f : kIdleThicknessScale;
+ float factor = thickness_change_ == INCREASE ? progress : (1.f - progress);
+ return ((1.f - kIdleThicknessScale) * factor) + kIdleThicknessScale;
+}
+
+float ScrollbarAnimationControllerThinning::AdjustScale(
+ float new_value,
+ float current_value,
+ AnimationChange animation_change) {
+ if (animation_change == INCREASE && current_value > new_value)
+ return current_value;
+ if (animation_change == DECREASE && current_value < new_value)
+ return current_value;
+ return new_value;
+}
+
+void ScrollbarAnimationControllerThinning::ApplyOpacityAndThumbThicknessScale(
+ float opacity,
+ float thumb_thickness_scale) {
+ for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
+ if (!scrollbar->is_overlay_scrollbar())
+ continue;
+ float effective_opacity =
+ scrollbar->CanScrollOrientation()
+ ? AdjustScale(opacity, scrollbar->opacity(), opacity_change_)
+ : 0;
+
+ scrollbar->OnOpacityAnimated(effective_opacity);
+ scrollbar->SetThumbThicknessScaleFactor(AdjustScale(
+ thumb_thickness_scale, scrollbar->thumb_thickness_scale_factor(),
+ thickness_change_));
+ }
+}
+
+} // namespace cc