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

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

Issue 14139013: Hide location bar on Javascript-initiated scroll. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Upload again after sync. Created 7 years, 8 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
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 "base/time.h" 10 #include "base/time.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if (animate) { 75 if (animate) {
76 SetupAnimation(visibility_restriction_ == ALWAYS_SHOWN ? 76 SetupAnimation(visibility_restriction_ == ALWAYS_SHOWN ?
77 SHOWING_CONTROLS : HIDING_CONTROLS); 77 SHOWING_CONTROLS : HIDING_CONTROLS);
78 } else { 78 } else {
79 controls_top_offset_ = final_controls_position; 79 controls_top_offset_ = final_controls_position;
80 } 80 }
81 client_->DidChangeTopControlsPosition(); 81 client_->DidChangeTopControlsPosition();
82 } 82 }
83 } 83 }
84 84
85 void TopControlsManager::ShowTopControls(bool show) {
86 if (show) {
87 DCHECK(visibility_restriction_ != ALWAYS_HIDDEN);
88 SetupAnimation(SHOWING_CONTROLS);
89 } else {
90 DCHECK(visibility_restriction_ != ALWAYS_SHOWN);
91 SetupAnimation(HIDING_CONTROLS);
92 }
93 }
94
85 void TopControlsManager::ScrollBegin() { 95 void TopControlsManager::ScrollBegin() {
86 ResetAnimations(); 96 ResetAnimations();
87 current_scroll_delta_ = 0.f; 97 current_scroll_delta_ = 0.f;
88 controls_scroll_begin_offset_ = controls_top_offset_; 98 controls_scroll_begin_offset_ = controls_top_offset_;
89 } 99 }
90 100
91 gfx::Vector2dF TopControlsManager::ScrollBy( 101 gfx::Vector2dF TopControlsManager::ScrollBy(
92 const gfx::Vector2dF pending_delta) { 102 const gfx::Vector2dF pending_delta) {
93 if (visibility_restriction_ == ALWAYS_SHOWN && pending_delta.y() > 0) 103 if (visibility_restriction_ == ALWAYS_SHOWN && pending_delta.y() > 0)
94 return pending_delta; 104 return pending_delta;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 156 }
147 157
148 void TopControlsManager::ResetAnimations() { 158 void TopControlsManager::ResetAnimations() {
149 if (top_controls_animation_) 159 if (top_controls_animation_)
150 top_controls_animation_.reset(); 160 top_controls_animation_.reset();
151 161
152 animation_direction_ = NO_ANIMATION; 162 animation_direction_ = NO_ANIMATION;
153 } 163 }
154 164
155 void TopControlsManager::SetupAnimation(AnimationDirection direction) { 165 void TopControlsManager::SetupAnimation(AnimationDirection direction) {
166 DCHECK(direction != NO_ANIMATION);
167
168 if (direction == SHOWING_CONTROLS && controls_top_offset_ == 0)
169 return;
170
171 if (direction == HIDING_CONTROLS &&
172 controls_top_offset_ == -top_controls_height_) {
173 return;
174 }
175
176 if (top_controls_animation_ && animation_direction_ == direction)
177 return;
178
156 top_controls_animation_ = KeyframedFloatAnimationCurve::Create(); 179 top_controls_animation_ = KeyframedFloatAnimationCurve::Create();
157 double start_time = 180 double start_time =
158 (base::TimeTicks::Now() - base::TimeTicks()).InMillisecondsF(); 181 (base::TimeTicks::Now() - base::TimeTicks()).InMillisecondsF();
159 top_controls_animation_->AddKeyframe( 182 top_controls_animation_->AddKeyframe(
160 FloatKeyframe::Create(start_time, controls_top_offset_, 183 FloatKeyframe::Create(start_time, controls_top_offset_,
161 scoped_ptr<TimingFunction>())); 184 scoped_ptr<TimingFunction>()));
162 float max_ending_offset = 185 float max_ending_offset =
163 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_; 186 (direction == SHOWING_CONTROLS ? 1 : -1) * top_controls_height_;
164 top_controls_animation_->AddKeyframe( 187 top_controls_animation_->AddKeyframe(
165 FloatKeyframe::Create(start_time + kShowHideMaxDurationMs, 188 FloatKeyframe::Create(start_time + kShowHideMaxDurationMs,
166 controls_top_offset_ + max_ending_offset, 189 controls_top_offset_ + max_ending_offset,
167 EaseTimingFunction::Create())); 190 EaseTimingFunction::Create()));
168 animation_direction_ = direction; 191 animation_direction_ = direction;
192 client_->DidChangeTopControlsPosition();
169 } 193 }
170 194
171 void TopControlsManager::StartAnimationIfNecessary() { 195 void TopControlsManager::StartAnimationIfNecessary() {
172 if (controls_top_offset_ != 0 196 if (controls_top_offset_ != 0
173 && controls_top_offset_ != -top_controls_height_) { 197 && controls_top_offset_ != -top_controls_height_) {
174 AnimationDirection show_controls = NO_ANIMATION; 198 AnimationDirection show_controls = NO_ANIMATION;
175 199
176 if (controls_top_offset_ >= -top_controls_show_height_) { 200 if (controls_top_offset_ >= -top_controls_show_height_) {
177 // If we're showing so much that the hide threshold won't trigger, show. 201 // If we're showing so much that the hide threshold won't trigger, show.
178 show_controls = SHOWING_CONTROLS; 202 show_controls = SHOWING_CONTROLS;
179 } else if (controls_top_offset_ <= -top_controls_hide_height_) { 203 } else if (controls_top_offset_ <= -top_controls_hide_height_) {
180 // If we're showing so little that the show threshold won't trigger, hide. 204 // If we're showing so little that the show threshold won't trigger, hide.
181 show_controls = HIDING_CONTROLS; 205 show_controls = HIDING_CONTROLS;
182 } else { 206 } else {
183 // If we could be either showing or hiding, we determine which one to 207 // If we could be either showing or hiding, we determine which one to
184 // do based on whether or not the total scroll delta was moving up or 208 // do based on whether or not the total scroll delta was moving up or
185 // down. 209 // down.
186 show_controls = current_scroll_delta_ <= 0.f ? 210 show_controls = current_scroll_delta_ <= 0.f ?
187 SHOWING_CONTROLS : HIDING_CONTROLS; 211 SHOWING_CONTROLS : HIDING_CONTROLS;
188 } 212 }
189 213
190 if (show_controls != NO_ANIMATION && 214 if (show_controls != NO_ANIMATION)
191 (!top_controls_animation_ || animation_direction_ != show_controls)) {
192 SetupAnimation(show_controls); 215 SetupAnimation(show_controls);
193 client_->DidChangeTopControlsPosition();
194 }
195 } 216 }
196 } 217 }
197 218
198 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) { 219 bool TopControlsManager::IsAnimationCompleteAtTime(base::TimeTicks time) {
199 if (!top_controls_animation_) 220 if (!top_controls_animation_)
200 return true; 221 return true;
201 222
202 double time_ms = (time - base::TimeTicks()).InMillisecondsF(); 223 double time_ms = (time - base::TimeTicks()).InMillisecondsF();
203 float new_offset = top_controls_animation_->GetValue(time_ms); 224 float new_offset = top_controls_animation_->GetValue(time_ms);
204 225
205 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) || 226 if ((animation_direction_ == SHOWING_CONTROLS && new_offset >= 0) ||
206 (animation_direction_ == HIDING_CONTROLS 227 (animation_direction_ == HIDING_CONTROLS
207 && new_offset <= -top_controls_height_)) { 228 && new_offset <= -top_controls_height_)) {
208 return true; 229 return true;
209 } 230 }
210 return false; 231 return false;
211 } 232 }
212 233
213 } // namespace cc 234 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698