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

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

Issue 2442473002: Controls offsets computed if either top or bottom are showing (Closed)
Patch Set: rebase 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 25 matching lines...) Expand all
36 BrowserControlsOffsetManager::BrowserControlsOffsetManager( 36 BrowserControlsOffsetManager::BrowserControlsOffsetManager(
37 BrowserControlsOffsetManagerClient* client, 37 BrowserControlsOffsetManagerClient* client,
38 float controls_show_threshold, 38 float controls_show_threshold,
39 float controls_hide_threshold) 39 float controls_hide_threshold)
40 : client_(client), 40 : client_(client),
41 animation_start_value_(0.f), 41 animation_start_value_(0.f),
42 animation_stop_value_(0.f), 42 animation_stop_value_(0.f),
43 animation_direction_(NO_ANIMATION), 43 animation_direction_(NO_ANIMATION),
44 permitted_state_(BOTH), 44 permitted_state_(BOTH),
45 accumulated_scroll_delta_(0.f), 45 accumulated_scroll_delta_(0.f),
46 baseline_content_offset_(0.f), 46 baseline_top_content_offset_(0.f),
47 baseline_bottom_content_offset_(0.f),
47 controls_show_threshold_(controls_hide_threshold), 48 controls_show_threshold_(controls_hide_threshold),
48 controls_hide_threshold_(controls_show_threshold), 49 controls_hide_threshold_(controls_show_threshold),
49 pinch_gesture_active_(false) { 50 pinch_gesture_active_(false) {
50 CHECK(client_); 51 CHECK(client_);
51 } 52 }
52 53
53 BrowserControlsOffsetManager::~BrowserControlsOffsetManager() {} 54 BrowserControlsOffsetManager::~BrowserControlsOffsetManager() {}
54 55
55 float BrowserControlsOffsetManager::ControlsTopOffset() const { 56 float BrowserControlsOffsetManager::ControlsTopOffset() const {
56 return ContentTopOffset() - TopControlsHeight(); 57 return ContentTopOffset() - TopControlsHeight();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 void BrowserControlsOffsetManager::ScrollBegin() { 114 void BrowserControlsOffsetManager::ScrollBegin() {
114 if (pinch_gesture_active_) 115 if (pinch_gesture_active_)
115 return; 116 return;
116 117
117 ResetAnimations(); 118 ResetAnimations();
118 ResetBaseline(); 119 ResetBaseline();
119 } 120 }
120 121
121 gfx::Vector2dF BrowserControlsOffsetManager::ScrollBy( 122 gfx::Vector2dF BrowserControlsOffsetManager::ScrollBy(
122 const gfx::Vector2dF& pending_delta) { 123 const gfx::Vector2dF& pending_delta) {
123 if (!TopControlsHeight()) 124 // If one or both of the top/bottom controls are showing, the shown ratio
125 // needs to be computed.
126 float controls_height =
127 TopControlsHeight() ? TopControlsHeight() : BottomControlsHeight();
128
129 if (!controls_height)
124 return pending_delta; 130 return pending_delta;
125 131
126 if (pinch_gesture_active_) 132 if (pinch_gesture_active_)
127 return pending_delta; 133 return pending_delta;
128 134
129 if (permitted_state_ == SHOWN && pending_delta.y() > 0) 135 if (permitted_state_ == SHOWN && pending_delta.y() > 0)
130 return pending_delta; 136 return pending_delta;
131 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0) 137 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0)
132 return pending_delta; 138 return pending_delta;
133 139
134 accumulated_scroll_delta_ += pending_delta.y(); 140 accumulated_scroll_delta_ += pending_delta.y();
135 141
136 float old_offset = ContentTopOffset(); 142 float old_top_offset = ContentTopOffset();
143 float baseline_content_offset = TopControlsHeight()
144 ? baseline_top_content_offset_ : baseline_bottom_content_offset_;
137 client_->SetCurrentBrowserControlsShownRatio( 145 client_->SetCurrentBrowserControlsShownRatio(
138 (baseline_content_offset_ - accumulated_scroll_delta_) / 146 (baseline_content_offset - accumulated_scroll_delta_) / controls_height);
139 TopControlsHeight());
140 147
141 // If the controls are fully visible, treat the current position as the 148 // If the controls are fully visible, treat the current position as the
142 // new baseline even if the gesture didn't end. 149 // new baseline even if the gesture didn't end.
143 if (TopControlsShownRatio() == 1.f) 150 if (TopControlsShownRatio() == 1.f)
144 ResetBaseline(); 151 ResetBaseline();
145 152
146 ResetAnimations(); 153 ResetAnimations();
147 154
148 gfx::Vector2dF applied_delta(0.f, old_offset - ContentTopOffset()); 155 // applied_delta will negate any scroll on the content if the top browser
156 // controls are showing in favor of hiding the controls and resizing the
157 // content. If the top controls have no height, the content should scroll
158 // immediately.
159 gfx::Vector2dF applied_delta(0.f,
160 TopControlsHeight() ? old_top_offset - ContentTopOffset() : 0.0f);
149 return pending_delta - applied_delta; 161 return pending_delta - applied_delta;
150 } 162 }
151 163
152 void BrowserControlsOffsetManager::ScrollEnd() { 164 void BrowserControlsOffsetManager::ScrollEnd() {
153 if (pinch_gesture_active_) 165 if (pinch_gesture_active_)
154 return; 166 return;
155 167
156 StartAnimationIfNecessary(); 168 StartAnimationIfNecessary();
157 } 169 }
158 170
(...skipping 22 matching lines...) Expand all
181 193
182 float old_offset = ContentTopOffset(); 194 float old_offset = ContentTopOffset();
183 float new_ratio = gfx::Tween::ClampedFloatValueBetween( 195 float new_ratio = gfx::Tween::ClampedFloatValueBetween(
184 monotonic_time, animation_start_time_, animation_start_value_, 196 monotonic_time, animation_start_time_, animation_start_value_,
185 animation_stop_time_, animation_stop_value_); 197 animation_stop_time_, animation_stop_value_);
186 client_->SetCurrentBrowserControlsShownRatio(new_ratio); 198 client_->SetCurrentBrowserControlsShownRatio(new_ratio);
187 199
188 if (IsAnimationComplete(new_ratio)) 200 if (IsAnimationComplete(new_ratio))
189 ResetAnimations(); 201 ResetAnimations();
190 202
191 gfx::Vector2dF scroll_delta(0.f, ContentTopOffset() - old_offset); 203 // Don't move the content if the top controls aren't used.
204 gfx::Vector2dF scroll_delta(0.f,
205 TopControlsHeight() ? (ContentTopOffset() - old_offset) : 0.0f);
aelias_OOO_until_Jul13 2016/11/04 04:24:50 ContentTopOffset() method name is now a lie (it do
mdjones 2016/11/05 00:17:26 I'm not sure I understand what you mean. In the ca
aelias_OOO_until_Jul13 2016/11/05 00:47:15 OK, right. Well, the source of my confusion is th
mdjones 2016/11/07 17:14:45 Done, added logic to ContentTopOffset and ContentB
192 return scroll_delta; 206 return scroll_delta;
193 } 207 }
194 208
195 void BrowserControlsOffsetManager::ResetAnimations() { 209 void BrowserControlsOffsetManager::ResetAnimations() {
196 animation_start_time_ = base::TimeTicks(); 210 animation_start_time_ = base::TimeTicks();
197 animation_start_value_ = 0.f; 211 animation_start_value_ = 0.f;
198 animation_stop_time_ = base::TimeTicks(); 212 animation_stop_time_ = base::TimeTicks();
199 animation_stop_value_ = 0.f; 213 animation_stop_value_ = 0.f;
200 214
201 animation_direction_ = NO_ANIMATION; 215 animation_direction_ = NO_ANIMATION;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 262 }
249 } 263 }
250 264
251 bool BrowserControlsOffsetManager::IsAnimationComplete(float new_ratio) { 265 bool BrowserControlsOffsetManager::IsAnimationComplete(float new_ratio) {
252 return (animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) || 266 return (animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) ||
253 (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f); 267 (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f);
254 } 268 }
255 269
256 void BrowserControlsOffsetManager::ResetBaseline() { 270 void BrowserControlsOffsetManager::ResetBaseline() {
257 accumulated_scroll_delta_ = 0.f; 271 accumulated_scroll_delta_ = 0.f;
258 baseline_content_offset_ = ContentTopOffset(); 272 baseline_top_content_offset_ = ContentTopOffset();
273 baseline_bottom_content_offset_ = ContentBottomOffset();
259 } 274 }
260 275
261 } // namespace cc 276 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698