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

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: remove duped logic 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 TopControlsHeight() > 0
62 ? TopControlsShownRatio() * TopControlsHeight() : 0.0f;
61 } 63 }
62 64
63 float BrowserControlsOffsetManager::TopControlsShownRatio() const { 65 float BrowserControlsOffsetManager::TopControlsShownRatio() const {
64 return client_->CurrentBrowserControlsShownRatio(); 66 return client_->CurrentBrowserControlsShownRatio();
65 } 67 }
66 68
67 float BrowserControlsOffsetManager::TopControlsHeight() const { 69 float BrowserControlsOffsetManager::TopControlsHeight() const {
68 return client_->TopControlsHeight(); 70 return client_->TopControlsHeight();
69 } 71 }
70 72
71 float BrowserControlsOffsetManager::BottomControlsHeight() const { 73 float BrowserControlsOffsetManager::BottomControlsHeight() const {
72 return client_->BottomControlsHeight(); 74 return client_->BottomControlsHeight();
73 } 75 }
74 76
75 float BrowserControlsOffsetManager::ContentBottomOffset() const { 77 float BrowserControlsOffsetManager::ContentBottomOffset() const {
76 return BottomControlsShownRatio() * BottomControlsHeight(); 78 return BottomControlsHeight() > 0
79 ? BottomControlsShownRatio() * BottomControlsHeight() : 0.0f;
77 } 80 }
78 81
79 float BrowserControlsOffsetManager::BottomControlsShownRatio() const { 82 float BrowserControlsOffsetManager::BottomControlsShownRatio() const {
80 return TopControlsShownRatio(); 83 return TopControlsShownRatio();
81 } 84 }
82 85
83 void BrowserControlsOffsetManager::UpdateBrowserControlsState( 86 void BrowserControlsOffsetManager::UpdateBrowserControlsState(
84 BrowserControlsState constraints, 87 BrowserControlsState constraints,
85 BrowserControlsState current, 88 BrowserControlsState current,
86 bool animate) { 89 bool animate) {
(...skipping 26 matching lines...) Expand all
113 void BrowserControlsOffsetManager::ScrollBegin() { 116 void BrowserControlsOffsetManager::ScrollBegin() {
114 if (pinch_gesture_active_) 117 if (pinch_gesture_active_)
115 return; 118 return;
116 119
117 ResetAnimations(); 120 ResetAnimations();
118 ResetBaseline(); 121 ResetBaseline();
119 } 122 }
120 123
121 gfx::Vector2dF BrowserControlsOffsetManager::ScrollBy( 124 gfx::Vector2dF BrowserControlsOffsetManager::ScrollBy(
122 const gfx::Vector2dF& pending_delta) { 125 const gfx::Vector2dF& pending_delta) {
123 if (!TopControlsHeight()) 126 // If one or both of the top/bottom controls are showing, the shown ratio
127 // needs to be computed.
128 float controls_height =
129 TopControlsHeight() ? TopControlsHeight() : BottomControlsHeight();
130
131 if (!controls_height)
124 return pending_delta; 132 return pending_delta;
125 133
126 if (pinch_gesture_active_) 134 if (pinch_gesture_active_)
127 return pending_delta; 135 return pending_delta;
128 136
129 if (permitted_state_ == SHOWN && pending_delta.y() > 0) 137 if (permitted_state_ == SHOWN && pending_delta.y() > 0)
130 return pending_delta; 138 return pending_delta;
131 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0) 139 else if (permitted_state_ == HIDDEN && pending_delta.y() < 0)
132 return pending_delta; 140 return pending_delta;
133 141
134 accumulated_scroll_delta_ += pending_delta.y(); 142 accumulated_scroll_delta_ += pending_delta.y();
135 143
136 float old_offset = ContentTopOffset(); 144 float old_top_offset = ContentTopOffset();
145 float baseline_content_offset = TopControlsHeight()
146 ? baseline_top_content_offset_ : baseline_bottom_content_offset_;
137 client_->SetCurrentBrowserControlsShownRatio( 147 client_->SetCurrentBrowserControlsShownRatio(
138 (baseline_content_offset_ - accumulated_scroll_delta_) / 148 (baseline_content_offset - accumulated_scroll_delta_) / controls_height);
139 TopControlsHeight());
140 149
141 // If the controls are fully visible, treat the current position as the 150 // If the controls are fully visible, treat the current position as the
142 // new baseline even if the gesture didn't end. 151 // new baseline even if the gesture didn't end.
143 if (TopControlsShownRatio() == 1.f) 152 if (TopControlsShownRatio() == 1.f)
144 ResetBaseline(); 153 ResetBaseline();
145 154
146 ResetAnimations(); 155 ResetAnimations();
147 156
148 gfx::Vector2dF applied_delta(0.f, old_offset - ContentTopOffset()); 157 // applied_delta will negate any scroll on the content if the top browser
158 // controls are showing in favor of hiding the controls and resizing the
159 // content. If the top controls have no height, the content should scroll
160 // immediately.
161 gfx::Vector2dF applied_delta(0.f, old_top_offset - ContentTopOffset());
149 return pending_delta - applied_delta; 162 return pending_delta - applied_delta;
150 } 163 }
151 164
152 void BrowserControlsOffsetManager::ScrollEnd() { 165 void BrowserControlsOffsetManager::ScrollEnd() {
153 if (pinch_gesture_active_) 166 if (pinch_gesture_active_)
154 return; 167 return;
155 168
156 StartAnimationIfNecessary(); 169 StartAnimationIfNecessary();
157 } 170 }
158 171
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 261 }
249 } 262 }
250 263
251 bool BrowserControlsOffsetManager::IsAnimationComplete(float new_ratio) { 264 bool BrowserControlsOffsetManager::IsAnimationComplete(float new_ratio) {
252 return (animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) || 265 return (animation_direction_ == SHOWING_CONTROLS && new_ratio >= 1.f) ||
253 (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f); 266 (animation_direction_ == HIDING_CONTROLS && new_ratio <= 0.f);
254 } 267 }
255 268
256 void BrowserControlsOffsetManager::ResetBaseline() { 269 void BrowserControlsOffsetManager::ResetBaseline() {
257 accumulated_scroll_delta_ = 0.f; 270 accumulated_scroll_delta_ = 0.f;
258 baseline_content_offset_ = ContentTopOffset(); 271 baseline_top_content_offset_ = ContentTopOffset();
272 baseline_bottom_content_offset_ = ContentBottomOffset();
259 } 273 }
260 274
261 } // namespace cc 275 } // 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