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

Side by Side Diff: cc/top_controls_manager.cc

Issue 12025031: Find root scroll layer at tree activation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
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"
(...skipping 28 matching lines...) Expand all
39 previous_root_scroll_offset_(0.f), 39 previous_root_scroll_offset_(0.f),
40 scroll_readjustment_enabled_(false), 40 scroll_readjustment_enabled_(false),
41 is_showing_animation_(false) { 41 is_showing_animation_(false) {
42 CHECK(client_); 42 CHECK(client_);
43 } 43 }
44 44
45 TopControlsManager::~TopControlsManager() { 45 TopControlsManager::~TopControlsManager() {
46 } 46 }
47 47
48 void TopControlsManager::UpdateDrawPositions() { 48 void TopControlsManager::UpdateDrawPositions() {
49 if (!RootScrollLayer()) 49 if (!client_->haveRootScrollLayer())
50 return; 50 return;
51 51
52 // If the scroll position has changed underneath us (i.e. a javascript 52 // If the scroll position has changed underneath us (i.e. a javascript
53 // scroll), then simulate a scroll that covers the delta. 53 // scroll), then simulate a scroll that covers the delta.
54 float scroll_total_y = RootScrollLayerTotalScrollY(); 54 float scroll_total_y = RootScrollLayerTotalScrollY();
55 if (scroll_readjustment_enabled_ 55 if (scroll_readjustment_enabled_
56 && scroll_total_y != previous_root_scroll_offset_) { 56 && scroll_total_y != previous_root_scroll_offset_) {
57 ScrollBy(gfx::Vector2dF(0, scroll_total_y - previous_root_scroll_offset_)); 57 ScrollBy(gfx::Vector2dF(0, scroll_total_y - previous_root_scroll_offset_));
58 StartAnimationIfNecessary(); 58 StartAnimationIfNecessary();
59 previous_root_scroll_offset_ = RootScrollLayerTotalScrollY(); 59 previous_root_scroll_offset_ = RootScrollLayerTotalScrollY();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 return pending_delta - applied_delta; 111 return pending_delta - applied_delta;
112 } 112 }
113 113
114 void TopControlsManager::ScrollEnd() { 114 void TopControlsManager::ScrollEnd() {
115 StartAnimationIfNecessary(); 115 StartAnimationIfNecessary();
116 previous_root_scroll_offset_ = RootScrollLayerTotalScrollY(); 116 previous_root_scroll_offset_ = RootScrollLayerTotalScrollY();
117 scroll_readjustment_enabled_ = true; 117 scroll_readjustment_enabled_ = true;
118 } 118 }
119 119
120 void TopControlsManager::Animate(base::TimeTicks monotonic_time) { 120 void TopControlsManager::Animate(base::TimeTicks monotonic_time) {
121 if (!top_controls_animation_ || !RootScrollLayer()) 121 if (!top_controls_animation_ || !client_->haveRootScrollLayer())
122 return; 122 return;
123 123
124 double time = (monotonic_time - base::TimeTicks()).InMillisecondsF(); 124 double time = (monotonic_time - base::TimeTicks()).InMillisecondsF();
125 float new_offset = top_controls_animation_->getValue(time); 125 float new_offset = top_controls_animation_->getValue(time);
126 gfx::Vector2dF scroll_vector(0.f, -(new_offset - controls_top_offset_)); 126 gfx::Vector2dF scroll_vector(0.f, -(new_offset - controls_top_offset_));
127 ScrollInternal(scroll_vector); 127 ScrollInternal(scroll_vector);
128 client_->setNeedsRedraw(); 128 client_->setNeedsRedraw();
129 129
130 if ((is_showing_animation_ && new_offset >= 0) || 130 if ((is_showing_animation_ && new_offset >= 0) ||
131 (!is_showing_animation_ && new_offset <= -top_controls_height_)) { 131 (!is_showing_animation_ && new_offset <= -top_controls_height_)) {
132 top_controls_animation_.reset(); 132 top_controls_animation_.reset();
133 StartAnimationIfNecessary(); 133 StartAnimationIfNecessary();
134 } 134 }
135 } 135 }
136 136
137 void TopControlsManager::ResetAnimations() { 137 void TopControlsManager::ResetAnimations() {
138 if (top_controls_animation_) 138 if (top_controls_animation_)
139 top_controls_animation_.reset(); 139 top_controls_animation_.reset();
140 } 140 }
141 141
142 LayerImpl* TopControlsManager::RootScrollLayer() {
143 return client_->activeTree()->root_scroll_layer();
144 }
145
146 float TopControlsManager::RootScrollLayerTotalScrollY() { 142 float TopControlsManager::RootScrollLayerTotalScrollY() {
147 LayerImpl* layer = RootScrollLayer(); 143 return client_->rootScrollLayerTotalScrollY();
148 if (!layer)
149 return 0;
150 gfx::Vector2dF scroll_total = layer->scrollOffset() + layer->scrollDelta();
151 return scroll_total.y();
152 } 144 }
153 145
154 void TopControlsManager::SetupAnimation(bool show_controls) { 146 void TopControlsManager::SetupAnimation(bool show_controls) {
155 top_controls_animation_ = KeyframedFloatAnimationCurve::create(); 147 top_controls_animation_ = KeyframedFloatAnimationCurve::create();
156 double start_time = 148 double start_time =
157 (base::TimeTicks::Now() - base::TimeTicks()).InMillisecondsF(); 149 (base::TimeTicks::Now() - base::TimeTicks()).InMillisecondsF();
158 top_controls_animation_->addKeyframe( 150 top_controls_animation_->addKeyframe(
159 FloatKeyframe::create(start_time, controls_top_offset_, 151 FloatKeyframe::create(start_time, controls_top_offset_,
160 scoped_ptr<TimingFunction>())); 152 scoped_ptr<TimingFunction>()));
161 float max_ending_offset = (show_controls ? 1 : -1) * top_controls_height_; 153 float max_ending_offset = (show_controls ? 1 : -1) * top_controls_height_;
162 top_controls_animation_->addKeyframe( 154 top_controls_animation_->addKeyframe(
163 FloatKeyframe::create(start_time + kShowHideMaxDurationMs, 155 FloatKeyframe::create(start_time + kShowHideMaxDurationMs,
164 controls_top_offset_ + max_ending_offset, 156 controls_top_offset_ + max_ending_offset,
165 EaseTimingFunction::create())); 157 EaseTimingFunction::create()));
166 is_showing_animation_ = show_controls; 158 is_showing_animation_ = show_controls;
167 } 159 }
168 160
169 void TopControlsManager::StartAnimationIfNecessary() { 161 void TopControlsManager::StartAnimationIfNecessary() {
170 float scroll_total_y = RootScrollLayerTotalScrollY(); 162 float scroll_total_y = RootScrollLayerTotalScrollY();
171 163
172 if (controls_top_offset_ != 0 164 if (controls_top_offset_ != 0
173 && controls_top_offset_ != -top_controls_height_) { 165 && controls_top_offset_ != -top_controls_height_) {
174 SetupAnimation( 166 SetupAnimation(
175 controls_top_offset_ >= -(top_controls_height_ * kShowHideThreshold)); 167 controls_top_offset_ >= -(top_controls_height_ * kShowHideThreshold));
176 client_->setNeedsRedraw(); 168 client_->setNeedsRedraw();
177 } 169 }
178 } 170 }
179 171
180 } // namespace cc 172 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698