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

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

Issue 2473583002: Revert BrowserControlsOffsetManager changes (Closed)
Patch Set: Created 4 years, 1 month 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/browser_controls_offset_manager.h" 5 #include "cc/input/browser_controls_offset_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 BrowserControlsOffsetManager::~BrowserControlsOffsetManager() {} 53 BrowserControlsOffsetManager::~BrowserControlsOffsetManager() {}
54 54
55 float BrowserControlsOffsetManager::ControlsTopOffset() const { 55 float BrowserControlsOffsetManager::ControlsTopOffset() const {
56 return ContentTopOffset() - TopControlsHeight(); 56 return ContentTopOffset() - TopControlsHeight();
57 } 57 }
58 58
59 float BrowserControlsOffsetManager::ContentTopOffset() const { 59 float BrowserControlsOffsetManager::ContentTopOffset() const {
60 return TopControlsShownRatio() * TopControlsHeight(); 60 return TopControlsShownRatio() * TopControlsHeight();
61 } 61 }
62 62
63 float BrowserControlsOffsetManager::ContentOffsetInternal() const {
64 if (!TopControlsHeight())
65 return BottomControlsShownRatio() * BottomControlsHeight();
66 return ContentTopOffset();
67 }
68
69 float BrowserControlsOffsetManager::TopControlsShownRatio() const { 63 float BrowserControlsOffsetManager::TopControlsShownRatio() const {
70 return client_->CurrentBrowserControlsShownRatio(); 64 return client_->CurrentBrowserControlsShownRatio();
71 } 65 }
72 66
73 float BrowserControlsOffsetManager::TopControlsHeight() const { 67 float BrowserControlsOffsetManager::TopControlsHeight() const {
74 return client_->TopControlsHeight(); 68 return client_->TopControlsHeight();
75 } 69 }
76 70
77 float BrowserControlsOffsetManager::BottomControlsHeight() const { 71 float BrowserControlsOffsetManager::BottomControlsHeight() const {
78 return client_->BottomControlsHeight(); 72 return client_->BottomControlsHeight();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void BrowserControlsOffsetManager::ScrollBegin() { 113 void BrowserControlsOffsetManager::ScrollBegin() {
120 if (pinch_gesture_active_) 114 if (pinch_gesture_active_)
121 return; 115 return;
122 116
123 ResetAnimations(); 117 ResetAnimations();
124 ResetBaseline(); 118 ResetBaseline();
125 } 119 }
126 120
127 gfx::Vector2dF BrowserControlsOffsetManager::ScrollBy( 121 gfx::Vector2dF BrowserControlsOffsetManager::ScrollBy(
128 const gfx::Vector2dF& pending_delta) { 122 const gfx::Vector2dF& pending_delta) {
129 // If one or both of the top/bottom controls are showing, the shown ratio 123 if (!TopControlsHeight())
130 // needs to be computed.
131 float controls_height =
132 TopControlsHeight() ? TopControlsHeight() : BottomControlsHeight();
133
134 if (!controls_height)
135 return pending_delta; 124 return pending_delta;
136 125
137 if (pinch_gesture_active_) 126 if (pinch_gesture_active_)
138 return pending_delta; 127 return pending_delta;
139 128
140 if (permitted_state_ == SHOWN && pending_delta.y() > 0) 129 if (permitted_state_ == SHOWN && pending_delta.y() > 0)
141 return pending_delta; 130 return pending_delta;
142 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0) 131 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0)
143 return pending_delta; 132 return pending_delta;
144 133
145 accumulated_scroll_delta_ += pending_delta.y(); 134 accumulated_scroll_delta_ += pending_delta.y();
146 135
147 float old_offset = ContentOffsetInternal(); 136 float old_offset = ContentTopOffset();
148 client_->SetCurrentBrowserControlsShownRatio( 137 client_->SetCurrentBrowserControlsShownRatio(
149 (baseline_content_offset_ - accumulated_scroll_delta_) / controls_height); 138 (baseline_content_offset_ - accumulated_scroll_delta_) /
139 TopControlsHeight());
150 140
151 // If the controls are fully visible, treat the current position as the 141 // If the controls are fully visible, treat the current position as the
152 // new baseline even if the gesture didn't end. 142 // new baseline even if the gesture didn't end.
153 if (TopControlsShownRatio() == 1.f) 143 if (TopControlsShownRatio() == 1.f)
154 ResetBaseline(); 144 ResetBaseline();
155 145
156 ResetAnimations(); 146 ResetAnimations();
157 147
158 gfx::Vector2dF applied_delta(0.f, old_offset - ContentOffsetInternal()); 148 gfx::Vector2dF applied_delta(0.f, old_offset - ContentTopOffset());
159 return pending_delta - applied_delta; 149 return pending_delta - applied_delta;
160 } 150 }
161 151
162 void BrowserControlsOffsetManager::ScrollEnd() { 152 void BrowserControlsOffsetManager::ScrollEnd() {
163 if (pinch_gesture_active_) 153 if (pinch_gesture_active_)
164 return; 154 return;
165 155
166 StartAnimationIfNecessary(); 156 StartAnimationIfNecessary();
167 } 157 }
168 158
(...skipping 13 matching lines...) Expand all
182 172
183 void BrowserControlsOffsetManager::MainThreadHasStoppedFlinging() { 173 void BrowserControlsOffsetManager::MainThreadHasStoppedFlinging() {
184 StartAnimationIfNecessary(); 174 StartAnimationIfNecessary();
185 } 175 }
186 176
187 gfx::Vector2dF BrowserControlsOffsetManager::Animate( 177 gfx::Vector2dF BrowserControlsOffsetManager::Animate(
188 base::TimeTicks monotonic_time) { 178 base::TimeTicks monotonic_time) {
189 if (!has_animation() || !client_->HaveRootScrollLayer()) 179 if (!has_animation() || !client_->HaveRootScrollLayer())
190 return gfx::Vector2dF(); 180 return gfx::Vector2dF();
191 181
192 float old_offset = ContentOffsetInternal(); 182 float old_offset = ContentTopOffset();
193 float new_ratio = gfx::Tween::ClampedFloatValueBetween( 183 float new_ratio = gfx::Tween::ClampedFloatValueBetween(
194 monotonic_time, animation_start_time_, animation_start_value_, 184 monotonic_time, animation_start_time_, animation_start_value_,
195 animation_stop_time_, animation_stop_value_); 185 animation_stop_time_, animation_stop_value_);
196 client_->SetCurrentBrowserControlsShownRatio(new_ratio); 186 client_->SetCurrentBrowserControlsShownRatio(new_ratio);
197 187
198 if (IsAnimationComplete(new_ratio)) 188 if (IsAnimationComplete(new_ratio))
199 ResetAnimations(); 189 ResetAnimations();
200 190
201 gfx::Vector2dF scroll_delta(0.f, ContentOffsetInternal() - old_offset); 191 gfx::Vector2dF scroll_delta(0.f, ContentTopOffset() - old_offset);
202 return scroll_delta; 192 return scroll_delta;
203 } 193 }
204 194
205 void BrowserControlsOffsetManager::ResetAnimations() { 195 void BrowserControlsOffsetManager::ResetAnimations() {
206 animation_start_time_ = base::TimeTicks(); 196 animation_start_time_ = base::TimeTicks();
207 animation_start_value_ = 0.f; 197 animation_start_value_ = 0.f;
208 animation_stop_time_ = base::TimeTicks(); 198 animation_stop_time_ = base::TimeTicks();
209 animation_stop_value_ = 0.f; 199 animation_stop_value_ = 0.f;
210 200
211 animation_direction_ = NO_ANIMATION; 201 animation_direction_ = NO_ANIMATION;
212 } 202 }
213 203
214 void BrowserControlsOffsetManager::SetupAnimation( 204 void BrowserControlsOffsetManager::SetupAnimation(
215 AnimationDirection direction) { 205 AnimationDirection direction) {
216 DCHECK_NE(NO_ANIMATION, direction); 206 DCHECK_NE(NO_ANIMATION, direction);
217 DCHECK(direction != HIDING_CONTROLS || TopControlsShownRatio() > 0.f); 207 DCHECK(direction != HIDING_CONTROLS || TopControlsShownRatio() > 0.f);
218 DCHECK(direction != SHOWING_CONTROLS || TopControlsShownRatio() < 1.f); 208 DCHECK(direction != SHOWING_CONTROLS || TopControlsShownRatio() < 1.f);
219 209
220 if (has_animation() && animation_direction_ == direction) 210 if (has_animation() && animation_direction_ == direction)
221 return; 211 return;
222 212
223 if (!TopControlsHeight() && !BottomControlsHeight()) { 213 if (!TopControlsHeight()) {
224 client_->SetCurrentBrowserControlsShownRatio( 214 client_->SetCurrentBrowserControlsShownRatio(
225 direction == HIDING_CONTROLS ? 0.f : 1.f); 215 direction == HIDING_CONTROLS ? 0.f : 1.f);
226 return; 216 return;
227 } 217 }
228 218
229 animation_start_time_ = base::TimeTicks::Now(); 219 animation_start_time_ = base::TimeTicks::Now();
230 animation_start_value_ = TopControlsShownRatio(); 220 animation_start_value_ = TopControlsShownRatio();
231 221
232 const float max_ending_ratio = (direction == SHOWING_CONTROLS ? 1 : -1); 222 const float max_ending_ratio = (direction == SHOWING_CONTROLS ? 1 : -1);
233 animation_stop_time_ = 223 animation_stop_time_ =
(...skipping 24 matching lines...) Expand all
258 } 248 }
259 } 249 }
260 250
261 bool BrowserControlsOffsetManager::IsAnimationComplete(float new_ratio) { 251 bool BrowserControlsOffsetManager::IsAnimationComplete(float new_ratio) {
262 return (animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) || 252 return (animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) ||
263 (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f); 253 (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f);
264 } 254 }
265 255
266 void BrowserControlsOffsetManager::ResetBaseline() { 256 void BrowserControlsOffsetManager::ResetBaseline() {
267 accumulated_scroll_delta_ = 0.f; 257 accumulated_scroll_delta_ = 0.f;
268 baseline_content_offset_ = ContentOffsetInternal(); 258 baseline_content_offset_ = ContentTopOffset();
269 } 259 }
270 260
271 } // namespace cc 261 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/browser_controls_offset_manager.h ('k') | cc/input/browser_controls_offset_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698