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

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

Issue 714003002: Allow changing top controls height (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 6 years 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/input/top_controls_manager_unittest.cc » ('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"
11 #include "cc/animation/timing_function.h" 11 #include "cc/animation/timing_function.h"
12 #include "cc/input/top_controls_manager_client.h" 12 #include "cc/input/top_controls_manager_client.h"
13 #include "cc/output/begin_frame_args.h" 13 #include "cc/output/begin_frame_args.h"
14 #include "cc/trees/layer_tree_impl.h" 14 #include "cc/trees/layer_tree_impl.h"
15 #include "ui/gfx/frame_time.h" 15 #include "ui/gfx/frame_time.h"
16 #include "ui/gfx/geometry/vector2d_f.h" 16 #include "ui/gfx/geometry/vector2d_f.h"
17 #include "ui/gfx/transform.h" 17 #include "ui/gfx/transform.h"
18 18
19 namespace cc { 19 namespace cc {
20 namespace { 20 namespace {
21 // These constants were chosen empirically for their visually pleasant behavior. 21 // These constants were chosen empirically for their visually pleasant behavior.
22 // Contact tedchoc@chromium.org for questions about changing these values. 22 // Contact tedchoc@chromium.org for questions about changing these values.
23 const int64 kShowHideMaxDurationMs = 200; 23 const int64 kShowHideMaxDurationMs = 200;
24 } 24 }
25 25
26 // static 26 // static
27 scoped_ptr<TopControlsManager> TopControlsManager::Create( 27 scoped_ptr<TopControlsManager> TopControlsManager::Create(
28 TopControlsManagerClient* client, 28 TopControlsManagerClient* client,
29 float top_controls_height,
30 float top_controls_show_threshold, 29 float top_controls_show_threshold,
31 float top_controls_hide_threshold) { 30 float top_controls_hide_threshold) {
32 return make_scoped_ptr(new TopControlsManager(client, 31 return make_scoped_ptr(new TopControlsManager(client,
33 top_controls_height,
34 top_controls_show_threshold, 32 top_controls_show_threshold,
35 top_controls_hide_threshold)); 33 top_controls_hide_threshold));
36 } 34 }
37 35
38 TopControlsManager::TopControlsManager(TopControlsManagerClient* client, 36 TopControlsManager::TopControlsManager(TopControlsManagerClient* client,
39 float top_controls_height,
40 float top_controls_show_threshold, 37 float top_controls_show_threshold,
41 float top_controls_hide_threshold) 38 float top_controls_hide_threshold)
42 : client_(client), 39 : client_(client),
43 animation_direction_(NO_ANIMATION), 40 animation_direction_(NO_ANIMATION),
44 permitted_state_(BOTH), 41 permitted_state_(BOTH),
45 top_controls_height_(top_controls_height), 42 top_controls_height_(0.f),
46 current_scroll_delta_(0.f), 43 current_scroll_delta_(0.f),
47 controls_scroll_begin_offset_(0.f), 44 controls_scroll_begin_offset_(0.f),
48 top_controls_show_height_( 45 top_controls_show_threshold_(top_controls_hide_threshold),
49 top_controls_height * top_controls_hide_threshold), 46 top_controls_hide_threshold_(top_controls_show_threshold),
50 top_controls_hide_height_(
51 top_controls_height * (1.f - top_controls_show_threshold)),
52 pinch_gesture_active_(false) { 47 pinch_gesture_active_(false) {
53 CHECK(client_); 48 CHECK(client_);
54 } 49 }
55 50
56 TopControlsManager::~TopControlsManager() { 51 TopControlsManager::~TopControlsManager() {
57 } 52 }
58 53
59 float TopControlsManager::ControlsTopOffset() { 54 float TopControlsManager::ControlsTopOffset() {
60 return client_->ControlsTopOffset(); 55 return client_->ControlsTopOffset();
61 } 56 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 controls_top_offset = std::min(controls_top_offset, 0.f); 151 controls_top_offset = std::min(controls_top_offset, 0.f);
157 152
158 if (client_->ControlsTopOffset() == controls_top_offset) 153 if (client_->ControlsTopOffset() == controls_top_offset)
159 return; 154 return;
160 155
161 client_->SetControlsTopOffset(controls_top_offset); 156 client_->SetControlsTopOffset(controls_top_offset);
162 157
163 client_->DidChangeTopControlsPosition(); 158 client_->DidChangeTopControlsPosition();
164 } 159 }
165 160
161 void TopControlsManager::SetTopControlsHeight(float top_controls_height) {
162 DCHECK_GE(top_controls_height, 0);
163
164 if (top_controls_height == top_controls_height_)
165 return;
166
167 ResetAnimations();
168 float top_controls_offset = client_->ControlsTopOffset();
169 top_controls_height_ = top_controls_height;
170 SetControlsTopOffset(top_controls_offset);
171 StartAnimationIfNecessary();
172 }
173
166 gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) { 174 gfx::Vector2dF TopControlsManager::Animate(base::TimeTicks monotonic_time) {
167 if (!top_controls_animation_ || !client_->HaveRootScrollLayer()) 175 if (!top_controls_animation_ || !client_->HaveRootScrollLayer())
168 return gfx::Vector2dF(); 176 return gfx::Vector2dF();
169 177
170 base::TimeDelta time = monotonic_time - base::TimeTicks(); 178 base::TimeDelta time = monotonic_time - base::TimeTicks();
171 179
172 float old_offset = client_->ControlsTopOffset(); 180 float old_offset = client_->ControlsTopOffset();
173 SetControlsTopOffset(top_controls_animation_->GetValue(time)); 181 SetControlsTopOffset(top_controls_animation_->GetValue(time));
174 182
175 if (IsAnimationCompleteAtTime(monotonic_time)) 183 if (IsAnimationCompleteAtTime(monotonic_time))
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 EaseTimingFunction::Create())); 218 EaseTimingFunction::Create()));
211 animation_direction_ = direction; 219 animation_direction_ = direction;
212 client_->DidChangeTopControlsPosition(); 220 client_->DidChangeTopControlsPosition();
213 } 221 }
214 222
215 void TopControlsManager::StartAnimationIfNecessary() { 223 void TopControlsManager::StartAnimationIfNecessary() {
216 if (client_->ControlsTopOffset() != 0 224 if (client_->ControlsTopOffset() != 0
217 && client_->ControlsTopOffset() != -top_controls_height_) { 225 && client_->ControlsTopOffset() != -top_controls_height_) {
218 AnimationDirection show_controls = NO_ANIMATION; 226 AnimationDirection show_controls = NO_ANIMATION;
219 227
220 if (client_->ControlsTopOffset() >= -top_controls_show_height_) { 228 float top_controls_show_height =
229 top_controls_height_ * top_controls_hide_threshold_;
230 float top_controls_hide_height =
231 top_controls_height_ * (1.f - top_controls_show_threshold_);
232 if (client_->ControlsTopOffset() >= -top_controls_show_height) {
221 // If we're showing so much that the hide threshold won't trigger, show. 233 // If we're showing so much that the hide threshold won't trigger, show.
222 show_controls = SHOWING_CONTROLS; 234 show_controls = SHOWING_CONTROLS;
223 } else if (client_->ControlsTopOffset() <= -top_controls_hide_height_) { 235 } else if (client_->ControlsTopOffset() <= -top_controls_hide_height) {
224 // If we're showing so little that the show threshold won't trigger, hide. 236 // If we're showing so little that the show threshold won't trigger, hide.
225 show_controls = HIDING_CONTROLS; 237 show_controls = HIDING_CONTROLS;
226 } else { 238 } else {
227 // If we could be either showing or hiding, we determine which one to 239 // If we could be either showing or hiding, we determine which one to
228 // do based on whether or not the total scroll delta was moving up or 240 // do based on whether or not the total scroll delta was moving up or
229 // down. 241 // down.
230 show_controls = current_scroll_delta_ <= 0.f ? 242 show_controls = current_scroll_delta_ <= 0.f ?
231 SHOWING_CONTROLS : HIDING_CONTROLS; 243 SHOWING_CONTROLS : HIDING_CONTROLS;
232 } 244 }
233 245
(...skipping 11 matching lines...) Expand all
245 257
246 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || 258 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) ||
247 (animation_direction_ == HIDING_CONTROLS 259 (animation_direction_ == HIDING_CONTROLS
248 && new_offset <= -top_controls_height_)) { 260 && new_offset <= -top_controls_height_)) {
249 return true; 261 return true;
250 } 262 }
251 return false; 263 return false;
252 } 264 }
253 265
254 } // namespace cc 266 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/top_controls_manager.h ('k') | cc/input/top_controls_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698