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

Side by Side Diff: content/browser/android/edge_effect_l.cc

Issue 679493002: [Android] Add a native pull-to-refresh overscroll effect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix findbugs... Created 6 years, 1 month 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 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/edge_effect_l.h" 5 #include "content/browser/android/edge_effect_l.h"
6 6
7 #include "cc/layers/ui_resource_layer.h" 7 #include "cc/layers/ui_resource_layer.h"
8 #include "content/browser/android/animation_utils.h"
8 #include "ui/base/android/system_ui_resource_manager.h" 9 #include "ui/base/android/system_ui_resource_manager.h"
9 10
10 namespace content { 11 namespace content {
11 12
12 namespace { 13 namespace {
13 14
14 // Time it will take the effect to fully recede in ms 15 // Time it will take the effect to fully recede in ms
15 const int kRecedeTimeMs = 600; 16 const int kRecedeTimeMs = 600;
16 17
17 // Time it will take before a pulled glow begins receding in ms 18 // Time it will take before a pulled glow begins receding in ms
(...skipping 15 matching lines...) Expand all
33 34
34 const float kSin = 0.5f; // sin(PI / 6) 35 const float kSin = 0.5f; // sin(PI / 6)
35 const float kCos = 0.866f; // cos(PI / 6); 36 const float kCos = 0.866f; // cos(PI / 6);
36 37
37 // How much dragging should effect the height of the glow image. 38 // How much dragging should effect the height of the glow image.
38 // Number determined by user testing. 39 // Number determined by user testing.
39 const float kPullDistanceAlphaGlowFactor = 0.8f; 40 const float kPullDistanceAlphaGlowFactor = 0.8f;
40 41
41 const int kVelocityGlowFactor = 6; 42 const int kVelocityGlowFactor = 6;
42 43
43 const ui::SystemUIResourceManager::ResourceType kResourceType = 44 const ui::SystemUIResourceType kResourceType = ui::OVERSCROLL_GLOW_L;
44 ui::SystemUIResourceManager::OVERSCROLL_GLOW_L;
45
46 template <typename T>
47 T Lerp(T a, T b, T t) {
48 return a + (b - a) * t;
49 }
50
51 template <typename T>
52 T Clamp(T value, T low, T high) {
53 return value < low ? low : (value > high ? high : value);
54 }
55
56 template <typename T>
57 T Damp(T input, T factor) {
58 T result;
59 if (factor == 1) {
60 result = 1 - (1 - input) * (1 - input);
61 } else {
62 result = 1 - std::pow(1 - input, 2 * factor);
63 }
64 return result;
65 }
66 45
67 } // namespace 46 } // namespace
68 47
69 EdgeEffectL::EdgeEffectL(ui::SystemUIResourceManager* resource_manager) 48 EdgeEffectL::EdgeEffectL(ui::SystemUIResourceManager* resource_manager)
70 : resource_manager_(resource_manager), 49 : resource_manager_(resource_manager),
71 glow_(cc::UIResourceLayer::Create()), 50 glow_(cc::UIResourceLayer::Create()),
72 glow_alpha_(0), 51 glow_alpha_(0),
73 glow_scale_y_(0), 52 glow_scale_y_(0),
74 glow_alpha_start_(0), 53 glow_alpha_start_(0),
75 glow_alpha_finish_(0), 54 glow_alpha_finish_(0),
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 256 }
278 257
279 // static 258 // static
280 void EdgeEffectL::PreloadResources( 259 void EdgeEffectL::PreloadResources(
281 ui::SystemUIResourceManager* resource_manager) { 260 ui::SystemUIResourceManager* resource_manager) {
282 DCHECK(resource_manager); 261 DCHECK(resource_manager);
283 resource_manager->PreloadResource(kResourceType); 262 resource_manager->PreloadResource(kResourceType);
284 } 263 }
285 264
286 } // namespace content 265 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/edge_effect.cc ('k') | content/browser/android/overscroll_controller_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698