| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/android/overscroll_refresh.h" | 5 #include "content/browser/android/overscroll_refresh.h" |
| 6 | 6 |
| 7 #include "cc/layers/ui_resource_layer.h" | 7 #include "cc/layers/ui_resource_layer.h" |
| 8 #include "cc/trees/layer_tree_host.h" | 8 #include "cc/trees/layer_tree_host.h" |
| 9 #include "content/browser/android/animation_utils.h" | 9 #include "content/browser/android/animation_utils.h" |
| 10 #include "ui/base/android/system_ui_resource_manager.h" | 10 #include "ui/base/android/system_ui_resource_manager.h" |
| 11 #include "ui/gfx/screen.h" |
| 11 | 12 |
| 13 using std::abs; |
| 12 using std::max; | 14 using std::max; |
| 13 using std::min; | 15 using std::min; |
| 14 | 16 |
| 15 namespace content { | 17 namespace content { |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 const ui::SystemUIResourceType kIdleResourceType = ui::OVERSCROLL_REFRESH_IDLE; | 20 const ui::SystemUIResourceType kIdleResourceType = ui::OVERSCROLL_REFRESH_IDLE; |
| 19 const ui::SystemUIResourceType kActiveResourceType = | 21 const ui::SystemUIResourceType kActiveResourceType = |
| 20 ui::OVERSCROLL_REFRESH_ACTIVE; | 22 ui::OVERSCROLL_REFRESH_ACTIVE; |
| 21 | 23 |
| 24 // Default offset in dips from the top of the view to where the progress spinner |
| 25 // should stop. |
| 26 const int kDefaultSpinnerTargetDips = 64; |
| 27 |
| 28 // Drag movement multiplier between user input and effect translation. |
| 29 const float kDragRate = .5f; |
| 30 |
| 22 // Animation duration after the effect is released without triggering a refresh. | 31 // Animation duration after the effect is released without triggering a refresh. |
| 23 const int kRecedeTimeMs = 300; | 32 const int kRecedeTimeMs = 300; |
| 24 | 33 |
| 34 // Animation duration immediately after the effect is released and activated. |
| 35 const int kActivationStartTimeMs = 150; |
| 36 |
| 25 // Animation duration after the effect is released and triggers a refresh. | 37 // Animation duration after the effect is released and triggers a refresh. |
| 26 const int kActivationTimeMs = 1000; | 38 const int kActivationTimeMs = 1000; |
| 27 | 39 |
| 28 // Max animation duration after the effect is released and triggers a refresh. | 40 // Max animation duration after the effect is released and triggers a refresh. |
| 29 const int kMaxActivationTimeMs = kActivationTimeMs * 3; | 41 const int kMaxActivationTimeMs = kActivationTimeMs * 3; |
| 30 | 42 |
| 31 // Animation duration after the refresh activated phase has completed. | 43 // Animation duration after the refresh activated phase has completed. |
| 32 const int kActivationRecedeTimeMs = 300; | 44 const int kActivationRecedeTimeMs = 300; |
| 33 | 45 |
| 34 // Input threshold required to activate the refresh. | |
| 35 const float kPullActivationThreshold = .35f; | |
| 36 | |
| 37 // Input threshold required to start glowing. | 46 // Input threshold required to start glowing. |
| 38 const float kGlowActivationThreshold = kPullActivationThreshold * 0.85f; | 47 const float kGlowActivationThreshold = 0.85f; |
| 39 | 48 |
| 40 // Useful for avoiding accidental triggering when a scroll janks (is delayed), | 49 // Useful for avoiding accidental triggering when a scroll janks (is delayed), |
| 41 // capping the impulse per event. | 50 // capping the impulse per event. |
| 42 const float kMaxNormalizedDeltaPerPull = kPullActivationThreshold / 4.f; | 51 const int kMinPullsToActivate = 4; |
| 43 | |
| 44 // Maximum offset of the effect relative to the content size. | |
| 45 const float kMaxRelativeOffset = .3f; | |
| 46 | 52 |
| 47 // Minimum alpha for the effect layer. | 53 // Minimum alpha for the effect layer. |
| 48 const float kMinAlpha = 0.25f; | 54 const float kMinAlpha = 0.3f; |
| 49 | |
| 50 // Controls spin velocity. | |
| 51 const float kPullRotationMultiplier = 180.f * (1.f / kPullActivationThreshold); | |
| 52 | 55 |
| 53 // Experimentally determined constant used to allow activation even if touch | 56 // Experimentally determined constant used to allow activation even if touch |
| 54 // release results in a small upward fling (quite common during a slow scroll). | 57 // release results in a small upward fling (quite common during a slow scroll). |
| 55 const float kMinFlingVelocityForActivation = -500.f; | 58 const float kMinFlingVelocityForActivation = -500.f; |
| 56 | 59 |
| 57 const float kEpsilon = 0.005f; | 60 const float kEpsilon = 0.005f; |
| 58 | 61 |
| 59 void UpdateLayer(cc::UIResourceLayer* layer, | 62 void UpdateLayer(cc::UIResourceLayer* layer, |
| 60 cc::Layer* parent, | 63 cc::Layer* parent, |
| 61 cc::UIResourceId res_id, | 64 cc::UIResourceId res_id, |
| 62 const gfx::SizeF& viewport_size, | 65 const gfx::SizeF& viewport_size, |
| 63 float relative_offset, | 66 float offset, |
| 64 float opacity, | 67 float opacity, |
| 65 float rotation) { | 68 float rotation) { |
| 66 if (layer->parent() != parent) | 69 if (layer->parent() != parent) |
| 67 parent->AddChild(layer); | 70 parent->AddChild(layer); |
| 68 | 71 |
| 69 if (!layer->layer_tree_host()) | 72 if (!layer->layer_tree_host()) |
| 70 return; | 73 return; |
| 71 | 74 |
| 72 // An empty window size, while meaningless, is also relatively harmless, and | 75 // An empty window size, while meaningless, is also relatively harmless, and |
| 73 // will simply prevent any drawing of the layers. | 76 // will simply prevent any drawing of the layers. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 89 | 92 |
| 90 gfx::Size image_size = layer->layer_tree_host()->GetUIResourceSize(res_id); | 93 gfx::Size image_size = layer->layer_tree_host()->GetUIResourceSize(res_id); |
| 91 layer->SetUIResourceId(res_id); | 94 layer->SetUIResourceId(res_id); |
| 92 layer->SetIsDrawable(true); | 95 layer->SetIsDrawable(true); |
| 93 layer->SetTransformOrigin( | 96 layer->SetTransformOrigin( |
| 94 gfx::Point3F(image_size.width() * 0.5f, image_size.height() * 0.5f, 0)); | 97 gfx::Point3F(image_size.width() * 0.5f, image_size.height() * 0.5f, 0)); |
| 95 layer->SetBounds(image_size); | 98 layer->SetBounds(image_size); |
| 96 layer->SetContentsOpaque(false); | 99 layer->SetContentsOpaque(false); |
| 97 layer->SetOpacity(Clamp(opacity, 0.f, 1.f)); | 100 layer->SetOpacity(Clamp(opacity, 0.f, 1.f)); |
| 98 | 101 |
| 99 float min_viewport_size = min(viewport_size.width(), viewport_size.height()); | |
| 100 float offset_x = (viewport_size.width() - image_size.width()) * 0.5f; | 102 float offset_x = (viewport_size.width() - image_size.width()) * 0.5f; |
| 101 float offset_y = | 103 float offset_y = offset - image_size.height(); |
| 102 Damp(relative_offset, 1.2f) * min_viewport_size * kMaxRelativeOffset - | |
| 103 image_size.height(); | |
| 104 gfx::Transform transform; | 104 gfx::Transform transform; |
| 105 transform.Translate(offset_x, offset_y); | 105 transform.Translate(offset_x, offset_y); |
| 106 transform.Rotate(rotation); | 106 transform.Rotate(rotation); |
| 107 layer->SetTransform(transform); | 107 layer->SetTransform(transform); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace | 110 } // namespace |
| 111 | 111 |
| 112 class OverscrollRefresh::Effect { | 112 class OverscrollRefresh::Effect { |
| 113 public: | 113 public: |
| 114 Effect(ui::SystemUIResourceManager* resource_manager) | 114 Effect(ui::SystemUIResourceManager* resource_manager) |
| 115 : resource_manager_(resource_manager), | 115 : resource_manager_(resource_manager), |
| 116 idle_layer_(cc::UIResourceLayer::Create()), | 116 idle_layer_(cc::UIResourceLayer::Create()), |
| 117 active_layer_(cc::UIResourceLayer::Create()), | 117 active_layer_(cc::UIResourceLayer::Create()), |
| 118 target_drag_(kDefaultSpinnerTargetDips * |
| 119 gfx::Screen::GetNativeScreen() |
| 120 ->GetPrimaryDisplay() |
| 121 .device_scale_factor()), |
| 122 drag_(0), |
| 118 idle_alpha_(0), | 123 idle_alpha_(0), |
| 119 active_alpha_(0), | 124 active_alpha_(0), |
| 120 offset_(0), | 125 offset_(0), |
| 121 rotation_(0), | 126 rotation_(0), |
| 122 idle_alpha_start_(0), | 127 idle_alpha_start_(0), |
| 123 idle_alpha_finish_(0), | 128 idle_alpha_finish_(0), |
| 124 active_alpha_start_(0), | 129 active_alpha_start_(0), |
| 125 active_alpha_finish_(0), | 130 active_alpha_finish_(0), |
| 126 offset_start_(0), | 131 offset_start_(0), |
| 127 offset_finish_(0), | 132 offset_finish_(0), |
| 128 rotation_start_(0), | 133 rotation_start_(0), |
| 129 rotation_finish_(0), | 134 rotation_finish_(0), |
| 130 state_(STATE_IDLE) { | 135 state_(STATE_IDLE) { |
| 136 DCHECK(target_drag_); |
| 131 idle_layer_->SetIsDrawable(false); | 137 idle_layer_->SetIsDrawable(false); |
| 132 active_layer_->SetIsDrawable(false); | 138 active_layer_->SetIsDrawable(false); |
| 133 } | 139 } |
| 134 | 140 |
| 135 ~Effect() { Detach(); } | 141 ~Effect() { Detach(); } |
| 136 | 142 |
| 137 void Pull(float normalized_delta) { | 143 void Pull(float delta) { |
| 138 if (state_ != STATE_PULL) | 144 if (state_ != STATE_PULL) |
| 139 offset_ = 0; | 145 drag_ = 0; |
| 140 | 146 |
| 141 state_ = STATE_PULL; | 147 state_ = STATE_PULL; |
| 142 | 148 |
| 143 normalized_delta = Clamp(normalized_delta, -kMaxNormalizedDeltaPerPull, | 149 delta *= kDragRate; |
| 144 kMaxNormalizedDeltaPerPull); | 150 float max_delta = target_drag_ / kMinPullsToActivate; |
| 151 delta = Clamp(delta, -max_delta, max_delta); |
| 145 | 152 |
| 146 offset_ += normalized_delta; | 153 drag_ += delta; |
| 147 offset_ = Clamp(offset_, 0.f, 1.f); | 154 drag_ = Clamp(drag_, 0.f, target_drag_ * 3.f); |
| 155 |
| 156 // The following logic and constants were taken from Android's refresh |
| 157 // effect (see SwipeRefreshLayout.java from v4 of the AppCompat library). |
| 158 float original_drag_percent = drag_ / target_drag_; |
| 159 float drag_percent = min(1.f, abs(original_drag_percent)); |
| 160 float adjusted_percent = max(drag_percent - .4f, 0.f) * 5.f / 3.f; |
| 161 float extra_os = abs(drag_) - target_drag_; |
| 162 float slingshot_dist = target_drag_; |
| 163 float tension_slingshot_percent = |
| 164 max(0.f, min(extra_os, slingshot_dist * 2) / slingshot_dist); |
| 165 float tension_percent = ((tension_slingshot_percent / 4) - |
| 166 std::pow((tension_slingshot_percent / 4), 2.f)) * |
| 167 2.f; |
| 168 float extra_move = slingshot_dist * tension_percent * 2; |
| 169 |
| 170 offset_ = slingshot_dist * drag_percent + extra_move; |
| 171 |
| 172 rotation_ = |
| 173 360.f * ((-0.25f + .4f * adjusted_percent + tension_percent * 2) * .5f); |
| 148 | 174 |
| 149 idle_alpha_ = | 175 idle_alpha_ = |
| 150 kMinAlpha + (1.f - kMinAlpha) * offset_ / kGlowActivationThreshold; | 176 kMinAlpha + (1.f - kMinAlpha) * drag_percent / kGlowActivationThreshold; |
| 151 active_alpha_ = (offset_ - kGlowActivationThreshold) / | 177 active_alpha_ = (drag_percent - kGlowActivationThreshold) / |
| 152 (kPullActivationThreshold - kGlowActivationThreshold); | 178 (1.f - kGlowActivationThreshold); |
| 153 idle_alpha_ = Clamp(idle_alpha_, 0.f, 1.f); | 179 idle_alpha_ = Clamp(idle_alpha_, 0.f, 1.f); |
| 154 active_alpha_ = Clamp(active_alpha_, 0.f, 1.f); | 180 active_alpha_ = Clamp(active_alpha_, 0.f, 1.f); |
| 155 | |
| 156 rotation_ = kPullRotationMultiplier * Damp(offset_, 1.f); | |
| 157 } | 181 } |
| 158 | 182 |
| 159 bool Animate(base::TimeTicks current_time, bool still_refreshing) { | 183 bool Animate(base::TimeTicks current_time, bool still_refreshing) { |
| 160 if (IsFinished()) | 184 if (IsFinished()) |
| 161 return false; | 185 return false; |
| 162 | 186 |
| 163 if (state_ == STATE_PULL) | 187 if (state_ == STATE_PULL) |
| 164 return true; | 188 return true; |
| 165 | 189 |
| 166 const double dt = (current_time - start_time_).InMilliseconds(); | 190 const double dt = (current_time - start_time_).InMilliseconds(); |
| 167 const double t = min(dt / duration_.InMilliseconds(), 1.); | 191 const double t = dt / duration_.InMilliseconds(); |
| 168 const float interp = static_cast<float>(Damp(t, 1.)); | 192 const float interp = static_cast<float>(Damp(min(t, 1.), 1.)); |
| 169 | 193 |
| 170 idle_alpha_ = Lerp(idle_alpha_start_, idle_alpha_finish_, interp); | 194 idle_alpha_ = Lerp(idle_alpha_start_, idle_alpha_finish_, interp); |
| 171 active_alpha_ = Lerp(active_alpha_start_, active_alpha_finish_, interp); | 195 active_alpha_ = Lerp(active_alpha_start_, active_alpha_finish_, interp); |
| 172 offset_ = Lerp(offset_start_, offset_finish_, interp); | 196 offset_ = Lerp(offset_start_, offset_finish_, interp); |
| 173 rotation_ = Lerp(rotation_start_, rotation_finish_, interp); | 197 rotation_ = Lerp(rotation_start_, rotation_finish_, interp); |
| 174 | 198 |
| 175 if (t < 1.f - kEpsilon) | 199 if (t < 1.f - kEpsilon) |
| 176 return true; | 200 return true; |
| 177 | 201 |
| 178 switch (state_) { | 202 switch (state_) { |
| 179 case STATE_IDLE: | 203 case STATE_IDLE: |
| 180 case STATE_PULL: | 204 case STATE_PULL: |
| 181 NOTREACHED() << "Invalidate state for animation."; | 205 NOTREACHED() << "Invalidate state for animation."; |
| 182 break; | 206 break; |
| 207 case STATE_ACTIVATED_START: |
| 208 // Briefly pause the animation after the rapid initial translation. |
| 209 if (t < 1.5f) |
| 210 break; |
| 211 state_ = STATE_ACTIVATED; |
| 212 start_time_ = current_time; |
| 213 duration_ = base::TimeDelta::FromMilliseconds(kActivationTimeMs); |
| 214 activated_start_time_ = current_time; |
| 215 offset_start_ = offset_finish_ = offset_; |
| 216 rotation_start_ = rotation_; |
| 217 rotation_finish_ = rotation_start_ + 360.f; |
| 218 break; |
| 183 case STATE_ACTIVATED: | 219 case STATE_ACTIVATED: |
| 184 start_time_ = current_time; | 220 start_time_ = current_time; |
| 185 if (still_refreshing && | 221 if (still_refreshing && |
| 186 (current_time - activated_start_time_ < | 222 (current_time - activated_start_time_ < |
| 187 base::TimeDelta::FromMilliseconds(kMaxActivationTimeMs))) { | 223 base::TimeDelta::FromMilliseconds(kMaxActivationTimeMs))) { |
| 188 offset_start_ = offset_finish_ = offset_; | 224 offset_start_ = offset_finish_ = offset_; |
| 189 rotation_start_ = rotation_; | 225 rotation_start_ = rotation_; |
| 190 rotation_finish_ = rotation_start_ + 360.f; | 226 rotation_finish_ = rotation_start_ + 360.f; |
| 191 break; | 227 break; |
| 192 } | 228 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 204 break; | 240 break; |
| 205 case STATE_RECEDE: | 241 case STATE_RECEDE: |
| 206 Finish(); | 242 Finish(); |
| 207 break; | 243 break; |
| 208 }; | 244 }; |
| 209 | 245 |
| 210 return !IsFinished(); | 246 return !IsFinished(); |
| 211 } | 247 } |
| 212 | 248 |
| 213 bool Release(base::TimeTicks current_time, bool allow_activation) { | 249 bool Release(base::TimeTicks current_time, bool allow_activation) { |
| 214 if (state_ != STATE_ACTIVATED && state_ != STATE_PULL) | 250 switch (state_) { |
| 215 return false; | 251 case STATE_PULL: |
| 252 break; |
| 216 | 253 |
| 217 if (state_ == STATE_ACTIVATED && allow_activation) | 254 case STATE_ACTIVATED: |
| 218 return false; | 255 case STATE_ACTIVATED_START: |
| 256 // Avoid redundant activations. |
| 257 if (allow_activation) |
| 258 return false; |
| 259 break; |
| 260 |
| 261 case STATE_IDLE: |
| 262 case STATE_ACTIVATED_RECEDE: |
| 263 case STATE_RECEDE: |
| 264 // These states have already been "released" in some fashion. |
| 265 return false; |
| 266 } |
| 219 | 267 |
| 220 start_time_ = current_time; | 268 start_time_ = current_time; |
| 221 idle_alpha_start_ = idle_alpha_; | 269 idle_alpha_start_ = idle_alpha_; |
| 222 active_alpha_start_ = active_alpha_; | 270 active_alpha_start_ = active_alpha_; |
| 223 offset_start_ = offset_; | 271 offset_start_ = offset_; |
| 224 rotation_start_ = rotation_; | 272 rotation_start_ = rotation_; |
| 225 | 273 |
| 226 if (offset_ < kPullActivationThreshold || !allow_activation) { | 274 if (drag_ < target_drag_ || !allow_activation) { |
| 227 state_ = STATE_RECEDE; | 275 state_ = STATE_RECEDE; |
| 228 duration_ = base::TimeDelta::FromMilliseconds(kRecedeTimeMs); | 276 duration_ = base::TimeDelta::FromMilliseconds(kRecedeTimeMs); |
| 229 idle_alpha_finish_ = 0; | 277 idle_alpha_finish_ = 0; |
| 230 active_alpha_finish_ = 0; | 278 active_alpha_finish_ = 0; |
| 231 offset_finish_ = 0; | 279 offset_finish_ = 0; |
| 232 rotation_finish_ = rotation_start_ - 180.f; | 280 rotation_finish_ = rotation_start_ - 180.f; |
| 233 return false; | 281 return false; |
| 234 } | 282 } |
| 235 | 283 |
| 236 state_ = STATE_ACTIVATED; | 284 state_ = STATE_ACTIVATED_START; |
| 237 duration_ = base::TimeDelta::FromMilliseconds(kActivationTimeMs); | 285 duration_ = base::TimeDelta::FromMilliseconds(kActivationStartTimeMs); |
| 238 activated_start_time_ = current_time; | 286 activated_start_time_ = current_time; |
| 239 idle_alpha_finish_ = idle_alpha_start_; | 287 idle_alpha_finish_ = idle_alpha_start_; |
| 240 active_alpha_finish_ = active_alpha_start_; | 288 active_alpha_finish_ = active_alpha_start_; |
| 241 offset_finish_ = kPullActivationThreshold; | 289 offset_finish_ = target_drag_; |
| 242 rotation_finish_ = rotation_start_ + 360.f; | 290 rotation_finish_ = rotation_start_; |
| 243 return true; | 291 return true; |
| 244 } | 292 } |
| 245 | 293 |
| 246 void Finish() { | 294 void Finish() { |
| 247 Detach(); | 295 Detach(); |
| 248 idle_layer_->SetIsDrawable(false); | 296 idle_layer_->SetIsDrawable(false); |
| 249 active_layer_->SetIsDrawable(false); | 297 active_layer_->SetIsDrawable(false); |
| 250 offset_ = 0; | 298 offset_ = 0; |
| 251 idle_alpha_ = 0; | 299 idle_alpha_ = 0; |
| 252 active_alpha_ = 0; | 300 active_alpha_ = 0; |
| 253 rotation_ = 0; | 301 rotation_ = 0; |
| 254 state_ = STATE_IDLE; | 302 state_ = STATE_IDLE; |
| 255 } | 303 } |
| 256 | 304 |
| 257 void ApplyToLayers(const gfx::SizeF& size, cc::Layer* parent) { | 305 void ApplyToLayers(const gfx::SizeF& size, cc::Layer* parent) { |
| 258 if (IsFinished()) | 306 if (IsFinished()) |
| 259 return; | 307 return; |
| 260 | 308 |
| 261 UpdateLayer(idle_layer_.get(), | 309 UpdateLayer(idle_layer_.get(), parent, |
| 262 parent, | 310 resource_manager_->GetUIResourceId(kIdleResourceType), size, |
| 263 resource_manager_->GetUIResourceId(kIdleResourceType), | 311 offset_, idle_alpha_, rotation_); |
| 264 size, | 312 UpdateLayer(active_layer_.get(), parent, |
| 265 offset_, | 313 resource_manager_->GetUIResourceId(kActiveResourceType), size, |
| 266 idle_alpha_, | 314 offset_, active_alpha_, rotation_); |
| 267 rotation_); | |
| 268 UpdateLayer(active_layer_.get(), | |
| 269 parent, | |
| 270 resource_manager_->GetUIResourceId(kActiveResourceType), | |
| 271 size, | |
| 272 offset_, | |
| 273 active_alpha_, | |
| 274 rotation_); | |
| 275 } | 315 } |
| 276 | 316 |
| 277 bool IsFinished() const { return state_ == STATE_IDLE; } | 317 bool IsFinished() const { return state_ == STATE_IDLE; } |
| 278 | 318 |
| 279 private: | 319 private: |
| 280 enum State { | 320 enum State { |
| 281 STATE_IDLE = 0, | 321 STATE_IDLE = 0, |
| 282 STATE_PULL, | 322 STATE_PULL, |
| 323 STATE_ACTIVATED_START, |
| 283 STATE_ACTIVATED, | 324 STATE_ACTIVATED, |
| 284 STATE_ACTIVATED_RECEDE, | 325 STATE_ACTIVATED_RECEDE, |
| 285 STATE_RECEDE | 326 STATE_RECEDE |
| 286 }; | 327 }; |
| 287 | 328 |
| 288 void Detach() { | 329 void Detach() { |
| 289 idle_layer_->RemoveFromParent(); | 330 idle_layer_->RemoveFromParent(); |
| 290 active_layer_->RemoveFromParent(); | 331 active_layer_->RemoveFromParent(); |
| 291 } | 332 } |
| 292 | 333 |
| 293 ui::SystemUIResourceManager* const resource_manager_; | 334 ui::SystemUIResourceManager* const resource_manager_; |
| 294 | 335 |
| 295 scoped_refptr<cc::UIResourceLayer> idle_layer_; | 336 scoped_refptr<cc::UIResourceLayer> idle_layer_; |
| 296 scoped_refptr<cc::UIResourceLayer> active_layer_; | 337 scoped_refptr<cc::UIResourceLayer> active_layer_; |
| 297 | 338 |
| 339 const float target_drag_; |
| 340 float drag_; |
| 298 float idle_alpha_; | 341 float idle_alpha_; |
| 299 float active_alpha_; | 342 float active_alpha_; |
| 300 float offset_; | 343 float offset_; |
| 301 float rotation_; | 344 float rotation_; |
| 302 | 345 |
| 303 float idle_alpha_start_; | 346 float idle_alpha_start_; |
| 304 float idle_alpha_finish_; | 347 float idle_alpha_finish_; |
| 305 float active_alpha_start_; | 348 float active_alpha_start_; |
| 306 float active_alpha_finish_; | 349 float active_alpha_finish_; |
| 307 float offset_start_; | 350 float offset_start_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 case DISABLED: | 405 case DISABLED: |
| 363 return false; | 406 return false; |
| 364 | 407 |
| 365 case AWAITING_SCROLL_UPDATE_ACK: | 408 case AWAITING_SCROLL_UPDATE_ACK: |
| 366 // If the initial scroll motion is downward, never allow activation. | 409 // If the initial scroll motion is downward, never allow activation. |
| 367 if (scroll_delta.y() <= 0) | 410 if (scroll_delta.y() <= 0) |
| 368 scroll_consumption_state_ = DISABLED; | 411 scroll_consumption_state_ = DISABLED; |
| 369 return false; | 412 return false; |
| 370 | 413 |
| 371 case ENABLED: { | 414 case ENABLED: { |
| 372 float normalized_delta = scroll_delta.y() / min(viewport_size_.height(), | 415 effect_->Pull(scroll_delta.y()); |
| 373 viewport_size_.width()); | |
| 374 effect_->Pull(normalized_delta); | |
| 375 return true; | 416 return true; |
| 376 } | 417 } |
| 377 } | 418 } |
| 378 | 419 |
| 379 NOTREACHED() << "Invalid overscroll state: " << scroll_consumption_state_; | 420 NOTREACHED() << "Invalid overscroll state: " << scroll_consumption_state_; |
| 380 return false; | 421 return false; |
| 381 } | 422 } |
| 382 | 423 |
| 383 bool OverscrollRefresh::Animate(base::TimeTicks current_time, | 424 bool OverscrollRefresh::Animate(base::TimeTicks current_time, |
| 384 cc::Layer* parent_layer) { | 425 cc::Layer* parent_layer) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 409 | 450 |
| 410 void OverscrollRefresh::Release(bool allow_activation) { | 451 void OverscrollRefresh::Release(bool allow_activation) { |
| 411 if (scroll_consumption_state_ == ENABLED) { | 452 if (scroll_consumption_state_ == ENABLED) { |
| 412 if (effect_->Release(base::TimeTicks::Now(), allow_activation)) | 453 if (effect_->Release(base::TimeTicks::Now(), allow_activation)) |
| 413 client_->TriggerRefresh(); | 454 client_->TriggerRefresh(); |
| 414 } | 455 } |
| 415 scroll_consumption_state_ = DISABLED; | 456 scroll_consumption_state_ = DISABLED; |
| 416 } | 457 } |
| 417 | 458 |
| 418 } // namespace content | 459 } // namespace content |
| OLD | NEW |