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

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: fix results of bad 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();
57 } 58 }
58 59
59 float BrowserControlsOffsetManager::ContentTopOffset() const { 60 float BrowserControlsOffsetManager::ContentTopOffset() const {
60 return TopControlsShownRatio() * TopControlsHeight(); 61 return TopControlsShownRatio() * TopControlsHeight();
61 } 62 }
62 63
63 float BrowserControlsOffsetManager::ContentOffsetInternal() const {
64 if (!TopControlsHeight())
65 return BottomControlsShownRatio() * BottomControlsHeight();
66 return ContentTopOffset();
67 }
68
69 float BrowserControlsOffsetManager::TopControlsShownRatio() const { 64 float BrowserControlsOffsetManager::TopControlsShownRatio() const {
70 return client_->CurrentBrowserControlsShownRatio(); 65 return client_->CurrentBrowserControlsShownRatio();
71 } 66 }
72 67
73 float BrowserControlsOffsetManager::TopControlsHeight() const { 68 float BrowserControlsOffsetManager::TopControlsHeight() const {
74 return client_->TopControlsHeight(); 69 return client_->TopControlsHeight();
75 } 70 }
76 71
77 float BrowserControlsOffsetManager::BottomControlsHeight() const { 72 float BrowserControlsOffsetManager::BottomControlsHeight() const {
78 return client_->BottomControlsHeight(); 73 return client_->BottomControlsHeight();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if (pinch_gesture_active_) 132 if (pinch_gesture_active_)
138 return pending_delta; 133 return pending_delta;
139 134
140 if (permitted_state_ == SHOWN && pending_delta.y() > 0) 135 if (permitted_state_ == SHOWN && pending_delta.y() > 0)
141 return pending_delta; 136 return pending_delta;
142 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0) 137 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0)
143 return pending_delta; 138 return pending_delta;
144 139
145 accumulated_scroll_delta_ += pending_delta.y(); 140 accumulated_scroll_delta_ += pending_delta.y();
146 141
147 float old_offset = ContentOffsetInternal(); 142 float old_top_offset = ContentTopOffset();
143 float baseline_content_offset = TopControlsHeight()
aelias_OOO_until_Jul13 2016/11/01 21:15:46 I think this should be structured more symmetrical
144 ? baseline_top_content_offset_ : baseline_bottom_content_offset_;
148 client_->SetCurrentBrowserControlsShownRatio( 145 client_->SetCurrentBrowserControlsShownRatio(
149 (baseline_content_offset_ - accumulated_scroll_delta_) / controls_height); 146 (baseline_content_offset - accumulated_scroll_delta_) / controls_height);
150 147
151 // 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
152 // new baseline even if the gesture didn't end. 149 // new baseline even if the gesture didn't end.
153 if (TopControlsShownRatio() == 1.f) 150 if (TopControlsShownRatio() == 1.f)
154 ResetBaseline(); 151 ResetBaseline();
155 152
156 ResetAnimations(); 153 ResetAnimations();
157 154
158 gfx::Vector2dF applied_delta(0.f, old_offset - ContentOffsetInternal()); 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);
159 return pending_delta - applied_delta; 161 return pending_delta - applied_delta;
160 } 162 }
161 163
162 void BrowserControlsOffsetManager::ScrollEnd() { 164 void BrowserControlsOffsetManager::ScrollEnd() {
163 if (pinch_gesture_active_) 165 if (pinch_gesture_active_)
164 return; 166 return;
165 167
166 StartAnimationIfNecessary(); 168 StartAnimationIfNecessary();
167 } 169 }
168 170
(...skipping 13 matching lines...) Expand all
182 184
183 void BrowserControlsOffsetManager::MainThreadHasStoppedFlinging() { 185 void BrowserControlsOffsetManager::MainThreadHasStoppedFlinging() {
184 StartAnimationIfNecessary(); 186 StartAnimationIfNecessary();
185 } 187 }
186 188
187 gfx::Vector2dF BrowserControlsOffsetManager::Animate( 189 gfx::Vector2dF BrowserControlsOffsetManager::Animate(
188 base::TimeTicks monotonic_time) { 190 base::TimeTicks monotonic_time) {
189 if (!has_animation() || !client_->HaveRootScrollLayer()) 191 if (!has_animation() || !client_->HaveRootScrollLayer())
190 return gfx::Vector2dF(); 192 return gfx::Vector2dF();
191 193
192 float old_offset = ContentOffsetInternal(); 194 float old_offset = ContentTopOffset();
193 float new_ratio = gfx::Tween::ClampedFloatValueBetween( 195 float new_ratio = gfx::Tween::ClampedFloatValueBetween(
194 monotonic_time, animation_start_time_, animation_start_value_, 196 monotonic_time, animation_start_time_, animation_start_value_,
195 animation_stop_time_, animation_stop_value_); 197 animation_stop_time_, animation_stop_value_);
196 client_->SetCurrentBrowserControlsShownRatio(new_ratio); 198 client_->SetCurrentBrowserControlsShownRatio(new_ratio);
197 199
198 if (IsAnimationComplete(new_ratio)) 200 if (IsAnimationComplete(new_ratio))
199 ResetAnimations(); 201 ResetAnimations();
200 202
201 gfx::Vector2dF scroll_delta(0.f, ContentOffsetInternal() - 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);
202 return scroll_delta; 206 return scroll_delta;
203 } 207 }
204 208
205 void BrowserControlsOffsetManager::ResetAnimations() { 209 void BrowserControlsOffsetManager::ResetAnimations() {
206 animation_start_time_ = base::TimeTicks(); 210 animation_start_time_ = base::TimeTicks();
207 animation_start_value_ = 0.f; 211 animation_start_value_ = 0.f;
208 animation_stop_time_ = base::TimeTicks(); 212 animation_stop_time_ = base::TimeTicks();
209 animation_stop_value_ = 0.f; 213 animation_stop_value_ = 0.f;
210 214
211 animation_direction_ = NO_ANIMATION; 215 animation_direction_ = NO_ANIMATION;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 262 }
259 } 263 }
260 264
261 bool BrowserControlsOffsetManager::IsAnimationComplete(float new_ratio) { 265 bool BrowserControlsOffsetManager::IsAnimationComplete(float new_ratio) {
262 return (animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) || 266 return (animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) ||
263 (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f); 267 (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f);
264 } 268 }
265 269
266 void BrowserControlsOffsetManager::ResetBaseline() { 270 void BrowserControlsOffsetManager::ResetBaseline() {
267 accumulated_scroll_delta_ = 0.f; 271 accumulated_scroll_delta_ = 0.f;
268 baseline_content_offset_ = ContentOffsetInternal(); 272 baseline_top_content_offset_ = ContentTopOffset();
273 baseline_bottom_content_offset_ = ContentBottomOffset();
269 } 274 }
270 275
271 } // namespace cc 276 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698