Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: cc/input/scrollbar_animation_controller_thinning.cc

Issue 2692243005: Merge Compositor's ScrollbarAnimationControllers into single class (Closed)
Patch Set: fix confict constant Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/input/scrollbar_animation_controller_thinning.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/time/time.h"
9 #include "cc/layers/layer_impl.h"
10 #include "cc/layers/scrollbar_layer_impl_base.h"
11 #include "cc/trees/layer_tree_impl.h"
12
13 namespace cc {
14
15 std::unique_ptr<ScrollbarAnimationControllerThinning>
16 ScrollbarAnimationControllerThinning::Create(
17 int scroll_layer_id,
18 ScrollbarAnimationControllerClient* client,
19 base::TimeDelta delay_before_starting,
20 base::TimeDelta resize_delay_before_starting,
21 base::TimeDelta fade_duration,
22 base::TimeDelta thinning_duration) {
23 return base::WrapUnique(new ScrollbarAnimationControllerThinning(
24 scroll_layer_id, client, delay_before_starting,
25 resize_delay_before_starting, fade_duration, thinning_duration));
26 }
27
28 ScrollbarAnimationControllerThinning::ScrollbarAnimationControllerThinning(
29 int scroll_layer_id,
30 ScrollbarAnimationControllerClient* client,
31 base::TimeDelta delay_before_starting,
32 base::TimeDelta resize_delay_before_starting,
33 base::TimeDelta fade_duration,
34 base::TimeDelta thinning_duration)
35 : ScrollbarAnimationController(scroll_layer_id,
36 client,
37 delay_before_starting,
38 resize_delay_before_starting),
39 opacity_(0.0f),
40 fade_duration_(fade_duration) {
41 vertical_controller_ = SingleScrollbarAnimationControllerThinning::Create(
42 scroll_layer_id, ScrollbarOrientation::VERTICAL, client,
43 thinning_duration);
44 horizontal_controller_ = SingleScrollbarAnimationControllerThinning::Create(
45 scroll_layer_id, ScrollbarOrientation::HORIZONTAL, client,
46 thinning_duration);
47 ApplyOpacityToScrollbars(0.0f);
48 }
49
50 ScrollbarAnimationControllerThinning::~ScrollbarAnimationControllerThinning() {}
51
52
53
54 bool ScrollbarAnimationControllerThinning::ScrollbarsHidden() const {
55 return opacity_ == 0.0f;
56 }
57
58 bool ScrollbarAnimationControllerThinning::NeedThinningAnimation() const {
59 return true;
60 }
61
62 void ScrollbarAnimationControllerThinning::RunAnimationFrame(float progress) {
63 ApplyOpacityToScrollbars(1.f - progress);
64 if (progress == 1.f)
65 StopAnimation();
66 }
67
68 const base::TimeDelta& ScrollbarAnimationControllerThinning::Duration() {
69 return fade_duration_;
70 }
71
72 void ScrollbarAnimationControllerThinning::DidScrollUpdate(bool on_resize) {
73 if (Captured())
74 return;
75
76 ScrollbarAnimationController::DidScrollUpdate(on_resize);
77
78 ApplyOpacityToScrollbars(1);
79 vertical_controller_->UpdateThumbThicknessScale();
80 horizontal_controller_->UpdateThumbThicknessScale();
81
82 // we started a fade out timer in
83 // |ScrollbarAnimationController::DidScrollUpdate| but don't want to
84 // fade out if the mouse is nearby.
85 if (mouse_is_near_any_scrollbar())
86 StopAnimation();
87 }
88
89 void ScrollbarAnimationControllerThinning::DidScrollEnd() {
90 ScrollbarAnimationController::DidScrollEnd();
91
92 // Don't fade out the scrollbar when mouse is near.
93 if (mouse_is_near_any_scrollbar())
94 StopAnimation();
95 }
96
97 void ScrollbarAnimationControllerThinning::ApplyOpacityToScrollbars(
98 float opacity) {
99 for (ScrollbarLayerImplBase* scrollbar : Scrollbars()) {
100 if (!scrollbar->is_overlay_scrollbar())
101 continue;
102 float effective_opacity = scrollbar->CanScrollOrientation() ? opacity : 0;
103 PropertyTrees* property_trees =
104 scrollbar->layer_tree_impl()->property_trees();
105 // If this method is called during LayerImpl::PushPropertiesTo, we may not
106 // yet have valid layer_id_to_effect_node_index entries as property trees
107 // are pushed after layers during activation. We can skip updating opacity
108 // in that case as we are only registering a scrollbar and because opacity
109 // will be overwritten anyway when property trees are pushed.
110 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT,
111 scrollbar->id())) {
112 property_trees->effect_tree.OnOpacityAnimated(
113 effective_opacity,
114 property_trees->layer_id_to_effect_node_index[scrollbar->id()],
115 scrollbar->layer_tree_impl());
116 }
117 }
118
119 bool previouslyVisible = opacity_ > 0.0f;
120 bool currentlyVisible = opacity > 0.0f;
121
122 opacity_ = opacity;
123
124 if (previouslyVisible != currentlyVisible)
125 client_->DidChangeScrollbarVisibility();
126 }
127
128 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698