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

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

Issue 748433002: [Android] Isolate OverscrollRefresh from device density (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/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"
12 11
13 using std::abs; 12 using std::abs;
14 using std::max; 13 using std::max;
15 using std::min; 14 using std::min;
16 15
17 namespace content { 16 namespace content {
18 namespace { 17 namespace {
19 18
20 const ui::SystemUIResourceType kIdleResourceType = ui::OVERSCROLL_REFRESH_IDLE; 19 const ui::SystemUIResourceType kIdleResourceType = ui::OVERSCROLL_REFRESH_IDLE;
21 const ui::SystemUIResourceType kActiveResourceType = 20 const ui::SystemUIResourceType kActiveResourceType =
22 ui::OVERSCROLL_REFRESH_ACTIVE; 21 ui::OVERSCROLL_REFRESH_ACTIVE;
23 22
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. 23 // Drag movement multiplier between user input and effect translation.
29 const float kDragRate = .5f; 24 const float kDragRate = .5f;
30 25
31 // Animation duration after the effect is released without triggering a refresh. 26 // Animation duration after the effect is released without triggering a refresh.
32 const int kRecedeTimeMs = 300; 27 const int kRecedeTimeMs = 300;
33 28
34 // Animation duration immediately after the effect is released and activated. 29 // Animation duration immediately after the effect is released and activated.
35 const int kActivationStartTimeMs = 150; 30 const int kActivationStartTimeMs = 150;
36 31
37 // Animation duration after the effect is released and triggers a refresh. 32 // Animation duration after the effect is released and triggers a refresh.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 gfx::Transform transform; 99 gfx::Transform transform;
105 transform.Translate(offset_x, offset_y); 100 transform.Translate(offset_x, offset_y);
106 transform.Rotate(rotation); 101 transform.Rotate(rotation);
107 layer->SetTransform(transform); 102 layer->SetTransform(transform);
108 } 103 }
109 104
110 } // namespace 105 } // namespace
111 106
112 class OverscrollRefresh::Effect { 107 class OverscrollRefresh::Effect {
113 public: 108 public:
114 Effect(ui::SystemUIResourceManager* resource_manager) 109 Effect(ui::SystemUIResourceManager* resource_manager, float target_drag)
115 : resource_manager_(resource_manager), 110 : resource_manager_(resource_manager),
116 idle_layer_(cc::UIResourceLayer::Create()), 111 idle_layer_(cc::UIResourceLayer::Create()),
117 active_layer_(cc::UIResourceLayer::Create()), 112 active_layer_(cc::UIResourceLayer::Create()),
118 target_drag_(kDefaultSpinnerTargetDips * 113 target_drag_(target_drag),
119 gfx::Screen::GetNativeScreen()
120 ->GetPrimaryDisplay()
121 .device_scale_factor()),
122 drag_(0), 114 drag_(0),
123 idle_alpha_(0), 115 idle_alpha_(0),
124 active_alpha_(0), 116 active_alpha_(0),
125 offset_(0), 117 offset_(0),
126 rotation_(0), 118 rotation_(0),
127 idle_alpha_start_(0), 119 idle_alpha_start_(0),
128 idle_alpha_finish_(0), 120 idle_alpha_finish_(0),
129 active_alpha_start_(0), 121 active_alpha_start_(0),
130 active_alpha_finish_(0), 122 active_alpha_finish_(0),
131 offset_start_(0), 123 offset_start_(0),
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 346
355 base::TimeTicks start_time_; 347 base::TimeTicks start_time_;
356 base::TimeTicks activated_start_time_; 348 base::TimeTicks activated_start_time_;
357 base::TimeDelta duration_; 349 base::TimeDelta duration_;
358 350
359 State state_; 351 State state_;
360 }; 352 };
361 353
362 OverscrollRefresh::OverscrollRefresh( 354 OverscrollRefresh::OverscrollRefresh(
363 ui::SystemUIResourceManager* resource_manager, 355 ui::SystemUIResourceManager* resource_manager,
364 OverscrollRefreshClient* client) 356 OverscrollRefreshClient* client,
357 float target_drag_offset_pixels)
365 : client_(client), 358 : client_(client),
366 scrolled_to_top_(true), 359 scrolled_to_top_(true),
367 scroll_consumption_state_(DISABLED), 360 scroll_consumption_state_(DISABLED),
368 effect_(new Effect(resource_manager)) { 361 effect_(new Effect(resource_manager, target_drag_offset_pixels)) {
369 DCHECK(client); 362 DCHECK(client);
370 } 363 }
371 364
372 OverscrollRefresh::~OverscrollRefresh() { 365 OverscrollRefresh::~OverscrollRefresh() {
373 } 366 }
374 367
375 void OverscrollRefresh::Reset() { 368 void OverscrollRefresh::Reset() {
376 scroll_consumption_state_ = DISABLED; 369 scroll_consumption_state_ = DISABLED;
377 effect_->Finish(); 370 effect_->Finish();
378 } 371 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 443
451 void OverscrollRefresh::Release(bool allow_activation) { 444 void OverscrollRefresh::Release(bool allow_activation) {
452 if (scroll_consumption_state_ == ENABLED) { 445 if (scroll_consumption_state_ == ENABLED) {
453 if (effect_->Release(base::TimeTicks::Now(), allow_activation)) 446 if (effect_->Release(base::TimeTicks::Now(), allow_activation))
454 client_->TriggerRefresh(); 447 client_->TriggerRefresh();
455 } 448 }
456 scroll_consumption_state_ = DISABLED; 449 scroll_consumption_state_ = DISABLED;
457 } 450 }
458 451
459 } // namespace content 452 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/overscroll_refresh.h ('k') | content/browser/android/overscroll_refresh_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698