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

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

Issue 960873002: Update from https://crrev.com/318214 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « cc/input/top_controls_manager.h ('k') | cc/layers/draw_properties.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/top_controls_manager.h" 5 #include "cc/input/top_controls_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "cc/animation/keyframed_animation_curve.h" 10 #include "cc/animation/keyframed_animation_curve.h"
(...skipping 21 matching lines...) Expand all
32 top_controls_show_threshold, 32 top_controls_show_threshold,
33 top_controls_hide_threshold)); 33 top_controls_hide_threshold));
34 } 34 }
35 35
36 TopControlsManager::TopControlsManager(TopControlsManagerClient* client, 36 TopControlsManager::TopControlsManager(TopControlsManagerClient* client,
37 float top_controls_show_threshold, 37 float top_controls_show_threshold,
38 float top_controls_hide_threshold) 38 float top_controls_hide_threshold)
39 : client_(client), 39 : client_(client),
40 animation_direction_(NO_ANIMATION), 40 animation_direction_(NO_ANIMATION),
41 permitted_state_(BOTH), 41 permitted_state_(BOTH),
42 current_scroll_delta_(0.f), 42 accumulated_scroll_delta_(0.f),
43 controls_scroll_begin_offset_(0.f), 43 baseline_content_offset_(0.f),
44 top_controls_show_threshold_(top_controls_hide_threshold), 44 top_controls_show_threshold_(top_controls_hide_threshold),
45 top_controls_hide_threshold_(top_controls_show_threshold), 45 top_controls_hide_threshold_(top_controls_show_threshold),
46 pinch_gesture_active_(false) { 46 pinch_gesture_active_(false) {
47 CHECK(client_); 47 CHECK(client_);
48 } 48 }
49 49
50 TopControlsManager::~TopControlsManager() { 50 TopControlsManager::~TopControlsManager() {
51 } 51 }
52 52
53 float TopControlsManager::ControlsTopOffset() const { 53 float TopControlsManager::ControlsTopOffset() const {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 SetupAnimation(final_shown_ratio ? SHOWING_CONTROLS : HIDING_CONTROLS); 89 SetupAnimation(final_shown_ratio ? SHOWING_CONTROLS : HIDING_CONTROLS);
90 } else { 90 } else {
91 ResetAnimations(); 91 ResetAnimations();
92 client_->SetCurrentTopControlsShownRatio(final_shown_ratio); 92 client_->SetCurrentTopControlsShownRatio(final_shown_ratio);
93 } 93 }
94 } 94 }
95 95
96 void TopControlsManager::ScrollBegin() { 96 void TopControlsManager::ScrollBegin() {
97 DCHECK(!pinch_gesture_active_); 97 DCHECK(!pinch_gesture_active_);
98 ResetAnimations(); 98 ResetAnimations();
99 current_scroll_delta_ = 0.f; 99 ResetBaseline();
100 controls_scroll_begin_offset_ = ContentTopOffset();
101 } 100 }
102 101
103 gfx::Vector2dF TopControlsManager::ScrollBy( 102 gfx::Vector2dF TopControlsManager::ScrollBy(
104 const gfx::Vector2dF& pending_delta) { 103 const gfx::Vector2dF& pending_delta) {
105 if (pinch_gesture_active_) 104 if (pinch_gesture_active_)
106 return pending_delta; 105 return pending_delta;
107 106
108 if (permitted_state_ == SHOWN && pending_delta.y() > 0) 107 if (permitted_state_ == SHOWN && pending_delta.y() > 0)
109 return pending_delta; 108 return pending_delta;
110 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0) 109 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0)
111 return pending_delta; 110 return pending_delta;
112 111
113 current_scroll_delta_ += pending_delta.y(); 112 accumulated_scroll_delta_ += pending_delta.y();
114 113
115 float old_offset = ContentTopOffset(); 114 float old_offset = ContentTopOffset();
116 client_->SetCurrentTopControlsShownRatio( 115 client_->SetCurrentTopControlsShownRatio(
117 (controls_scroll_begin_offset_ - current_scroll_delta_) / 116 (baseline_content_offset_ - accumulated_scroll_delta_) /
118 TopControlsHeight()); 117 TopControlsHeight());
119 118
120 // If the controls are fully visible, treat the current position as the 119 // If the controls are fully visible, treat the current position as the
121 // new baseline even if the gesture didn't end. 120 // new baseline even if the gesture didn't end.
122 if (TopControlsShownRatio() == 1.f) { 121 if (TopControlsShownRatio() == 1.f)
123 current_scroll_delta_ = 0.f; 122 ResetBaseline();
124 controls_scroll_begin_offset_ = ContentTopOffset();
125 }
126 123
127 ResetAnimations(); 124 ResetAnimations();
128 125
129 gfx::Vector2dF applied_delta(0.f, old_offset - ContentTopOffset()); 126 gfx::Vector2dF applied_delta(0.f, old_offset - ContentTopOffset());
130 return pending_delta - applied_delta; 127 return pending_delta - applied_delta;
131 } 128 }
132 129
133 void TopControlsManager::ScrollEnd() { 130 void TopControlsManager::ScrollEnd() {
134 DCHECK(!pinch_gesture_active_); 131 DCHECK(!pinch_gesture_active_);
135 StartAnimationIfNecessary(); 132 StartAnimationIfNecessary();
136 } 133 }
137 134
138 void TopControlsManager::PinchBegin() { 135 void TopControlsManager::PinchBegin() {
139 DCHECK(!pinch_gesture_active_); 136 DCHECK(!pinch_gesture_active_);
140 pinch_gesture_active_ = true; 137 pinch_gesture_active_ = true;
141 StartAnimationIfNecessary(); 138 StartAnimationIfNecessary();
142 } 139 }
143 140
144 void TopControlsManager::PinchEnd() { 141 void TopControlsManager::PinchEnd() {
145 DCHECK(pinch_gesture_active_); 142 DCHECK(pinch_gesture_active_);
146 // Pinch{Begin,End} will always occur within the scope of Scroll{Begin,End}, 143 // Pinch{Begin,End} will always occur within the scope of Scroll{Begin,End},
147 // so return to a state expected by the remaining scroll sequence. 144 // so return to a state expected by the remaining scroll sequence.
148 pinch_gesture_active_ = false; 145 pinch_gesture_active_ = false;
149 ScrollBegin(); 146 ScrollBegin();
150 } 147 }
151 148
149 void TopControlsManager::MainThreadHasStoppedFlinging() {
150 StartAnimationIfNecessary();
151 }
152
152 gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) { 153 gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) {
153 if (!top_controls_animation_ || !client_->HaveRootScrollLayer()) 154 if (!top_controls_animation_ || !client_->HaveRootScrollLayer())
154 return gfx::Vector2dF(); 155 return gfx::Vector2dF();
155 156
156 base::TimeDelta time = monotonic_time - base::TimeTicks(); 157 base::TimeDelta time = monotonic_time - base::TimeTicks();
157 158
158 float old_offset = ContentTopOffset(); 159 float old_offset = ContentTopOffset();
159 client_->SetCurrentTopControlsShownRatio( 160 client_->SetCurrentTopControlsShownRatio(
160 top_controls_animation_->GetValue(time)); 161 top_controls_animation_->GetValue(time));
161 162
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 if (TopControlsShownRatio() >= 1.f - top_controls_hide_threshold_) { 200 if (TopControlsShownRatio() >= 1.f - top_controls_hide_threshold_) {
200 // If we're showing so much that the hide threshold won't trigger, show. 201 // If we're showing so much that the hide threshold won't trigger, show.
201 SetupAnimation(SHOWING_CONTROLS); 202 SetupAnimation(SHOWING_CONTROLS);
202 } else if (TopControlsShownRatio() <= top_controls_show_threshold_) { 203 } else if (TopControlsShownRatio() <= top_controls_show_threshold_) {
203 // If we're showing so little that the show threshold won't trigger, hide. 204 // If we're showing so little that the show threshold won't trigger, hide.
204 SetupAnimation(HIDING_CONTROLS); 205 SetupAnimation(HIDING_CONTROLS);
205 } else { 206 } else {
206 // If we could be either showing or hiding, we determine which one to 207 // If we could be either showing or hiding, we determine which one to
207 // do based on whether or not the total scroll delta was moving up or 208 // do based on whether or not the total scroll delta was moving up or
208 // down. 209 // down.
209 SetupAnimation(current_scroll_delta_ <= 0.f ? SHOWING_CONTROLS 210 SetupAnimation(accumulated_scroll_delta_ <= 0.f ? SHOWING_CONTROLS
210 : HIDING_CONTROLS); 211 : HIDING_CONTROLS);
211 } 212 }
212 } 213 }
213 214
214 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { 215 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) {
215 if (!top_controls_animation_) 216 if (!top_controls_animation_)
216 return true; 217 return true;
217 218
218 base::TimeDelta animation_time = time - base::TimeTicks(); 219 base::TimeDelta animation_time = time - base::TimeTicks();
219 float new_ratio = top_controls_animation_->GetValue(animation_time); 220 float new_ratio = top_controls_animation_->GetValue(animation_time);
220 221
221 if ((animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) || 222 if ((animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) ||
222 (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f)) { 223 (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f)) {
223 return true; 224 return true;
224 } 225 }
225 return false; 226 return false;
226 } 227 }
227 228
229 void TopControlsManager::ResetBaseline() {
230 accumulated_scroll_delta_ = 0.f;
231 baseline_content_offset_ = ContentTopOffset();
232 }
233
228 } // namespace cc 234 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/top_controls_manager.h ('k') | cc/layers/draw_properties.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698