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

Unified Diff: cc/top_controls_manager.cc

Issue 11953040: Add a scroll threshold/marker to control hiding/showing top controls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/top_controls_manager.h ('k') | cc/top_controls_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/top_controls_manager.cc
diff --git a/cc/top_controls_manager.cc b/cc/top_controls_manager.cc
index 7c0f03cf3b5bcc25be9ad55829f611f1bb7136ea..ca47e59a17a3a7f01bc6d908c3fb12bfa55c585c 100644
--- a/cc/top_controls_manager.cc
+++ b/cc/top_controls_manager.cc
@@ -34,11 +34,12 @@ TopControlsManager::TopControlsManager(TopControlsManagerClient* client,
: client_(client),
animation_direction_(NO_ANIMATION),
is_overlay_mode_(false),
- scroll_readjustment_enabled_(false),
+ in_scroll_gesture_(false),
top_controls_height_(top_controls_height),
controls_top_offset_(0),
content_top_offset_(top_controls_height),
- previous_root_scroll_offset_(0.f) {
+ previous_root_scroll_offset_(0.f),
+ scroll_start_offset_(0.f) {
CHECK(client_);
}
@@ -52,7 +53,7 @@ void TopControlsManager::UpdateDrawPositions() {
// If the scroll position has changed underneath us (i.e. a javascript
// scroll), then simulate a scroll that covers the delta.
float scroll_total_y = RootScrollLayerTotalScrollY();
- if (scroll_readjustment_enabled_
+ if (!in_scroll_gesture_
&& scroll_total_y != previous_root_scroll_offset_) {
ScrollBy(gfx::Vector2dF(0, scroll_total_y - previous_root_scroll_offset_));
StartAnimationIfNecessary();
@@ -62,11 +63,23 @@ void TopControlsManager::UpdateDrawPositions() {
void TopControlsManager::ScrollBegin() {
ResetAnimations();
- scroll_readjustment_enabled_ = false;
+ in_scroll_gesture_ = true;
+ scroll_start_offset_ = RootScrollLayerTotalScrollY() + controls_top_offset_;
}
gfx::Vector2dF TopControlsManager::ScrollBy(
const gfx::Vector2dF pending_delta) {
+ if (pending_delta.y() == 0)
+ return pending_delta;
+
+ float scroll_total_y = RootScrollLayerTotalScrollY();
+ if (in_scroll_gesture_ &&
+ ((pending_delta.y() > 0 && scroll_total_y < scroll_start_offset_) ||
+ (pending_delta.y() < 0 &&
+ scroll_total_y > scroll_start_offset_ + top_controls_height_))) {
+ return pending_delta;
+ }
+
ResetAnimations();
return ScrollInternal(pending_delta);
}
@@ -87,7 +100,15 @@ gfx::Vector2dF TopControlsManager::ScrollInternal(
if (scroll_total_y > 0 || (scroll_total_y == 0
&& content_top_offset_ < scroll_delta_y)) {
is_overlay_mode_ = true;
- content_top_offset_ = 0;
+
+ // The first case is where the page applies a scroll (javascript) and is
+ // being re-adjusted in a call to UpdateDrawPositions. Instead of slamming
+ // the controls to the top, we adjust by the scroll delta until we reach
+ // zero as we expect.
+ if (scroll_total_y > 0 && content_top_offset_ != 0)
+ content_top_offset_ -= scroll_delta_y;
+ else
+ content_top_offset_ = 0;
} else if (scroll_total_y <= 0 && (scroll_delta_y < 0
|| (scroll_delta_y > 0 && content_top_offset_ > 0))) {
is_overlay_mode_ = false;
@@ -114,7 +135,7 @@ gfx::Vector2dF TopControlsManager::ScrollInternal(
void TopControlsManager::ScrollEnd() {
StartAnimationIfNecessary();
previous_root_scroll_offset_ = RootScrollLayerTotalScrollY();
- scroll_readjustment_enabled_ = true;
+ in_scroll_gesture_ = false;
}
void TopControlsManager::Animate(base::TimeTicks monotonic_time) {
« 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