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/top_controls_manager.cc

Issue 12210050: Expose FS show/hide thresholds to Command Line (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « cc/top_controls_manager.h ('k') | cc/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/top_controls_manager.h" 5 #include "cc/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 "base/time.h" 10 #include "base/time.h"
11 #include "cc/keyframed_animation_curve.h" 11 #include "cc/keyframed_animation_curve.h"
12 #include "cc/layer_tree_impl.h" 12 #include "cc/layer_tree_impl.h"
13 #include "cc/timing_function.h" 13 #include "cc/timing_function.h"
14 #include "cc/top_controls_manager_client.h" 14 #include "cc/top_controls_manager_client.h"
15 #include "ui/gfx/transform.h" 15 #include "ui/gfx/transform.h"
16 #include "ui/gfx/vector2d_f.h" 16 #include "ui/gfx/vector2d_f.h"
17 17
18 namespace cc { 18 namespace cc {
19 namespace { 19 namespace {
20 // These constants were chosen empirically for their visually pleasant behavior. 20 // These constants were chosen empirically for their visually pleasant behavior.
21 // Contact tedchoc@chromium.org for questions about changing these values. 21 // Contact tedchoc@chromium.org for questions about changing these values.
22 const float kShowHideThreshold = 0.5f;
23 const int64 kShowHideMaxDurationMs = 175; 22 const int64 kShowHideMaxDurationMs = 175;
24 } 23 }
25 24
26 // static 25 // static
27 scoped_ptr<TopControlsManager> TopControlsManager::Create( 26 scoped_ptr<TopControlsManager> TopControlsManager::Create(
28 TopControlsManagerClient* client, float top_controls_height) { 27 TopControlsManagerClient* client,
29 return make_scoped_ptr(new TopControlsManager(client, top_controls_height)); 28 float top_controls_height,
29 float top_controls_show_threshold,
30 float top_controls_hide_threshold) {
31 return make_scoped_ptr(new TopControlsManager(client,
32 top_controls_height,
33 top_controls_show_threshold,
34 top_controls_hide_threshold));
30 } 35 }
31 36
32 TopControlsManager::TopControlsManager(TopControlsManagerClient* client, 37 TopControlsManager::TopControlsManager(TopControlsManagerClient* client,
33 float top_controls_height) 38 float top_controls_height,
39 float top_controls_show_threshold,
40 float top_controls_hide_threshold)
34 : client_(client), 41 : client_(client),
35 animation_direction_(NO_ANIMATION), 42 animation_direction_(NO_ANIMATION),
36 in_scroll_gesture_(false), 43 in_scroll_gesture_(false),
37 top_controls_height_(top_controls_height), 44 top_controls_height_(top_controls_height),
38 controls_top_offset_(0), 45 controls_top_offset_(0),
39 content_top_offset_(top_controls_height), 46 content_top_offset_(top_controls_height),
40 previous_root_scroll_offset_(0.f), 47 previous_root_scroll_offset_(0.f),
41 scroll_start_offset_(0.f) { 48 scroll_start_offset_(0.f),
49 current_scroll_delta_(0.f),
50 top_controls_show_height_(
51 top_controls_height * top_controls_hide_threshold),
52 top_controls_hide_height_(
53 top_controls_height * (1.f - top_controls_show_threshold)) {
42 CHECK(client_); 54 CHECK(client_);
43 } 55 }
44 56
45 TopControlsManager::~TopControlsManager() { 57 TopControlsManager::~TopControlsManager() {
46 } 58 }
47 59
48 void TopControlsManager::ScrollBegin() { 60 void TopControlsManager::ScrollBegin() {
49 ResetAnimations(); 61 ResetAnimations();
50 in_scroll_gesture_ = true; 62 in_scroll_gesture_ = true;
51 scroll_start_offset_ = RootScrollLayerTotalScrollY() + controls_top_offset_; 63 scroll_start_offset_ = RootScrollLayerTotalScrollY() + controls_top_offset_;
64 current_scroll_delta_ = 0.f;
52 } 65 }
53 66
54 gfx::Vector2dF TopControlsManager::ScrollBy( 67 gfx::Vector2dF TopControlsManager::ScrollBy(
55 const gfx::Vector2dF pending_delta) { 68 const gfx::Vector2dF pending_delta) {
56 if (pending_delta.y() == 0) 69 if (pending_delta.y() == 0)
57 return pending_delta; 70 return pending_delta;
58 71
72 current_scroll_delta_ += pending_delta.y();
73
59 float scroll_total_y = RootScrollLayerTotalScrollY(); 74 float scroll_total_y = RootScrollLayerTotalScrollY();
60 75
61 if (in_scroll_gesture_ && pending_delta.y() > 0 && controls_top_offset_ == 0) 76 if (in_scroll_gesture_ && pending_delta.y() > 0 && controls_top_offset_ == 0)
62 scroll_start_offset_ = scroll_total_y; 77 scroll_start_offset_ = scroll_total_y;
63 else if (in_scroll_gesture_ && 78 else if (in_scroll_gesture_ &&
64 ((pending_delta.y() > 0 && scroll_total_y < scroll_start_offset_) || 79 ((pending_delta.y() > 0 && scroll_total_y < scroll_start_offset_) ||
65 (pending_delta.y() < 0 && 80 (pending_delta.y() < 0 &&
66 scroll_total_y > scroll_start_offset_ + top_controls_height_))) { 81 scroll_total_y > scroll_start_offset_ + top_controls_height_))) {
67 return pending_delta; 82 return pending_delta;
68 } 83 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 client_->setActiveTreeNeedsUpdateDrawProperties(); 125 client_->setActiveTreeNeedsUpdateDrawProperties();
111 } 126 }
112 127
113 return pending_delta - applied_delta; 128 return pending_delta - applied_delta;
114 } 129 }
115 130
116 void TopControlsManager::ScrollEnd() { 131 void TopControlsManager::ScrollEnd() {
117 StartAnimationIfNecessary(); 132 StartAnimationIfNecessary();
118 previous_root_scroll_offset_ = RootScrollLayerTotalScrollY(); 133 previous_root_scroll_offset_ = RootScrollLayerTotalScrollY();
119 in_scroll_gesture_ = false; 134 in_scroll_gesture_ = false;
135 current_scroll_delta_ = 0.f;
120 } 136 }
121 137
122 void TopControlsManager::Animate(base::TimeTicks monotonic_time) { 138 void TopControlsManager::Animate(base::TimeTicks monotonic_time) {
123 if (!top_controls_animation_ || !client_->haveRootScrollLayer()) 139 if (!top_controls_animation_ || !client_->haveRootScrollLayer())
124 return; 140 return;
125 141
126 double time = (monotonic_time - base::TimeTicks()).InMillisecondsF(); 142 double time = (monotonic_time - base::TimeTicks()).InMillisecondsF();
127 float new_offset = top_controls_animation_->getValue(time); 143 float new_offset = top_controls_animation_->getValue(time);
128 gfx::Vector2dF scroll_vector(0.f, -(new_offset - controls_top_offset_)); 144 gfx::Vector2dF scroll_vector(0.f, -(new_offset - controls_top_offset_));
129 ScrollInternal(scroll_vector); 145 ScrollInternal(scroll_vector);
(...skipping 24 matching lines...) Expand all
154 float max_ending_offset = 170 float max_ending_offset =
155 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_; 171 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_;
156 top_controls_animation_->addKeyframe( 172 top_controls_animation_->addKeyframe(
157 FloatKeyframe::create(start_time + kShowHideMaxDurationMs, 173 FloatKeyframe::create(start_time + kShowHideMaxDurationMs,
158 controls_top_offset_ + max_ending_offset, 174 controls_top_offset_ + max_ending_offset,
159 EaseTimingFunction::create())); 175 EaseTimingFunction::create()));
160 animation_direction_ = direction; 176 animation_direction_ = direction;
161 } 177 }
162 178
163 void TopControlsManager::StartAnimationIfNecessary() { 179 void TopControlsManager::StartAnimationIfNecessary() {
164 float scroll_total_y = RootScrollLayerTotalScrollY();
165
166 if (controls_top_offset_ != 0 180 if (controls_top_offset_ != 0
167 && controls_top_offset_ != -top_controls_height_) { 181 && controls_top_offset_ != -top_controls_height_) {
168 AnimationDirection show_controls = 182 AnimationDirection show_controls = NO_ANIMATION;
169 controls_top_offset_ >= -(top_controls_height_ * kShowHideThreshold) ? 183
170 SHOWING_CONTROLS : HIDING_CONTROLS; 184 if (controls_top_offset_ >= -top_controls_show_height_) {
171 if (!top_controls_animation_ || animation_direction_ != show_controls) { 185 // If we're showing so much that the hide threshold won't trigger, show.
186 show_controls = SHOWING_CONTROLS;
187 } else if (controls_top_offset_ <= -top_controls_hide_height_) {
188 // If we're showing so little that the show threshold won't trigger, hide.
189 show_controls = HIDING_CONTROLS;
190 } else {
191 // If we could be either showing or hiding, we determine which one to
192 // do based on whether or not the total scroll delta was moving up or
193 // down.
194 show_controls = current_scroll_delta_ <= 0.f ?
195 SHOWING_CONTROLS : HIDING_CONTROLS;
196 }
197
198 if (show_controls != NO_ANIMATION &&
199 (!top_controls_animation_ || animation_direction_ != show_controls)) {
172 SetupAnimation(show_controls); 200 SetupAnimation(show_controls);
173 client_->setNeedsRedraw(); 201 client_->setNeedsRedraw();
174 } 202 }
175 } 203 }
176 } 204 }
177 205
178 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { 206 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) {
179 if (!top_controls_animation_) 207 if (!top_controls_animation_)
180 return true; 208 return true;
181 209
182 double time_ms = (time - base::TimeTicks()).InMillisecondsF(); 210 double time_ms = (time - base::TimeTicks()).InMillisecondsF();
183 float new_offset = top_controls_animation_->getValue(time_ms); 211 float new_offset = top_controls_animation_->getValue(time_ms);
184 212
185 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || 213 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) ||
186 (animation_direction_ == HIDING_CONTROLS 214 (animation_direction_ == HIDING_CONTROLS
187 && new_offset <= -top_controls_height_)) { 215 && new_offset <= -top_controls_height_)) {
188 return true; 216 return true;
189 } 217 }
190 return false; 218 return false;
191 } 219 }
192 220
193 } // namespace cc 221 } // namespace cc
OLDNEW
« no previous file with comments | « cc/top_controls_manager.h ('k') | cc/top_controls_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698