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/animation/timing_function.h" | 7 #include "cc/animation/timing_function.h" |
8 #include "cc/layers/ui_resource_layer.h" | 8 #include "cc/layers/ui_resource_layer.h" |
9 #include "cc/trees/layer_tree_host.h" | 9 #include "cc/trees/layer_tree_host.h" |
10 #include "content/browser/android/animation_utils.h" | 10 #include "content/browser/android/animation_utils.h" |
11 #include "ui/base/android/system_ui_resource_manager.h" | 11 #include "ui/android/resources/resource_manager.h" |
12 #include "ui/gfx/geometry/size_conversions.h" | 12 #include "ui/gfx/geometry/size_conversions.h" |
13 | 13 |
14 using std::abs; | 14 using std::abs; |
15 using std::max; | 15 using std::max; |
16 using std::min; | 16 using std::min; |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 namespace { | 19 namespace { |
20 | 20 |
21 const ui::SystemUIResourceType kIdleResourceType = ui::OVERSCROLL_REFRESH_IDLE; | 21 const ui::SystemUIResourceType kIdleResourceId = ui::OVERSCROLL_REFRESH_IDLE; |
22 const ui::SystemUIResourceType kActiveResourceType = | 22 const ui::SystemUIResourceType kActiveResourceId = |
23 ui::OVERSCROLL_REFRESH_ACTIVE; | 23 ui::OVERSCROLL_REFRESH_ACTIVE; |
24 | 24 |
25 // Drag movement multiplier between user input and effect translation. | 25 // Drag movement multiplier between user input and effect translation. |
26 const float kDragRate = .5f; | 26 const float kDragRate = .5f; |
27 | 27 |
28 // Animation duration after the effect is released without triggering a refresh. | 28 // Animation duration after the effect is released without triggering a refresh. |
29 const int kRecedeTimeMs = 300; | 29 const int kRecedeTimeMs = 300; |
30 | 30 |
31 // Animation duration immediately after the effect is released and activated. | 31 // Animation duration immediately after the effect is released and activated. |
32 const int kActivationStartTimeMs = 150; | 32 const int kActivationStartTimeMs = 150; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 gfx::Transform transform; | 98 gfx::Transform transform; |
99 transform.Translate(offset_x, offset_y); | 99 transform.Translate(offset_x, offset_y); |
100 transform.Rotate(rotation); | 100 transform.Rotate(rotation); |
101 layer->SetTransform(transform); | 101 layer->SetTransform(transform); |
102 } | 102 } |
103 | 103 |
104 } // namespace | 104 } // namespace |
105 | 105 |
106 class OverscrollRefresh::Effect { | 106 class OverscrollRefresh::Effect { |
107 public: | 107 public: |
108 Effect(ui::SystemUIResourceManager* resource_manager, float target_drag) | 108 Effect(ui::ResourceManager* resource_manager, float target_drag) |
109 : resource_manager_(resource_manager), | 109 : resource_manager_(resource_manager), |
110 idle_layer_(cc::UIResourceLayer::Create()), | 110 idle_layer_(cc::UIResourceLayer::Create()), |
111 active_layer_(cc::UIResourceLayer::Create()), | 111 active_layer_(cc::UIResourceLayer::Create()), |
112 target_drag_(target_drag), | 112 target_drag_(target_drag), |
113 drag_(0), | 113 drag_(0), |
114 idle_alpha_(0), | 114 idle_alpha_(0), |
115 active_alpha_(0), | 115 active_alpha_(0), |
116 offset_(0), | 116 offset_(0), |
117 rotation_(0), | 117 rotation_(0), |
118 size_scale_(1), | 118 size_scale_(1), |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 return; | 318 return; |
319 | 319 |
320 // An empty window size, while meaningless, is also relatively harmless, and | 320 // An empty window size, while meaningless, is also relatively harmless, and |
321 // will simply prevent any drawing of the layers. | 321 // will simply prevent any drawing of the layers. |
322 if (viewport_size.IsEmpty()) { | 322 if (viewport_size.IsEmpty()) { |
323 idle_layer_->SetIsDrawable(false); | 323 idle_layer_->SetIsDrawable(false); |
324 active_layer_->SetIsDrawable(false); | 324 active_layer_->SetIsDrawable(false); |
325 return; | 325 return; |
326 } | 326 } |
327 | 327 |
328 cc::UIResourceId idle_resource = | 328 cc::UIResourceId idle_resource = resource_manager_->GetUIResourceId( |
329 resource_manager_->GetUIResourceId(kIdleResourceType); | 329 ui::ANDROID_RESOURCE_TYPE_SYSTEM, kIdleResourceId); |
330 cc::UIResourceId active_resource = | 330 cc::UIResourceId active_resource = resource_manager_->GetUIResourceId( |
331 resource_manager_->GetUIResourceId(kActiveResourceType); | 331 ui::ANDROID_RESOURCE_TYPE_SYSTEM, kActiveResourceId); |
332 | 332 |
333 gfx::Size idle_size = | 333 gfx::Size idle_size = |
334 parent->layer_tree_host()->GetUIResourceSize(idle_resource); | 334 parent->layer_tree_host()->GetUIResourceSize(idle_resource); |
335 gfx::Size active_size = | 335 gfx::Size active_size = |
336 parent->layer_tree_host()->GetUIResourceSize(active_resource); | 336 parent->layer_tree_host()->GetUIResourceSize(active_resource); |
337 gfx::Size scaled_idle_size = | 337 gfx::Size scaled_idle_size = |
338 gfx::ToRoundedSize(gfx::ScaleSize(idle_size, size_scale_)); | 338 gfx::ToRoundedSize(gfx::ScaleSize(idle_size, size_scale_)); |
339 gfx::Size scaled_active_size = | 339 gfx::Size scaled_active_size = |
340 gfx::ToRoundedSize(gfx::ScaleSize(active_size, size_scale_)); | 340 gfx::ToRoundedSize(gfx::ScaleSize(active_size, size_scale_)); |
341 | 341 |
(...skipping 18 matching lines...) Expand all Loading... |
360 STATE_ACTIVATED, | 360 STATE_ACTIVATED, |
361 STATE_ACTIVATED_RECEDE, | 361 STATE_ACTIVATED_RECEDE, |
362 STATE_RECEDE | 362 STATE_RECEDE |
363 }; | 363 }; |
364 | 364 |
365 void Detach() { | 365 void Detach() { |
366 idle_layer_->RemoveFromParent(); | 366 idle_layer_->RemoveFromParent(); |
367 active_layer_->RemoveFromParent(); | 367 active_layer_->RemoveFromParent(); |
368 } | 368 } |
369 | 369 |
370 ui::SystemUIResourceManager* const resource_manager_; | 370 ui::ResourceManager* const resource_manager_; |
371 | 371 |
372 scoped_refptr<cc::UIResourceLayer> idle_layer_; | 372 scoped_refptr<cc::UIResourceLayer> idle_layer_; |
373 scoped_refptr<cc::UIResourceLayer> active_layer_; | 373 scoped_refptr<cc::UIResourceLayer> active_layer_; |
374 | 374 |
375 const float target_drag_; | 375 const float target_drag_; |
376 float drag_; | 376 float drag_; |
377 float idle_alpha_; | 377 float idle_alpha_; |
378 float active_alpha_; | 378 float active_alpha_; |
379 float offset_; | 379 float offset_; |
380 float rotation_; | 380 float rotation_; |
(...skipping 15 matching lines...) Expand all Loading... |
396 base::TimeDelta duration_; | 396 base::TimeDelta duration_; |
397 | 397 |
398 State state_; | 398 State state_; |
399 | 399 |
400 scoped_ptr<cc::TimingFunction> ease_out_; | 400 scoped_ptr<cc::TimingFunction> ease_out_; |
401 scoped_ptr<cc::TimingFunction> ease_in_out_; | 401 scoped_ptr<cc::TimingFunction> ease_in_out_; |
402 | 402 |
403 DISALLOW_COPY_AND_ASSIGN(Effect); | 403 DISALLOW_COPY_AND_ASSIGN(Effect); |
404 }; | 404 }; |
405 | 405 |
406 OverscrollRefresh::OverscrollRefresh( | 406 OverscrollRefresh::OverscrollRefresh(ui::ResourceManager* resource_manager, |
407 ui::SystemUIResourceManager* resource_manager, | 407 OverscrollRefreshClient* client, |
408 OverscrollRefreshClient* client, | 408 float target_drag_offset_pixels) |
409 float target_drag_offset_pixels) | |
410 : client_(client), | 409 : client_(client), |
411 scrolled_to_top_(true), | 410 scrolled_to_top_(true), |
412 scroll_consumption_state_(DISABLED), | 411 scroll_consumption_state_(DISABLED), |
413 effect_(new Effect(resource_manager, target_drag_offset_pixels)) { | 412 effect_(new Effect(resource_manager, target_drag_offset_pixels)) { |
414 DCHECK(client); | 413 DCHECK(client); |
415 } | 414 } |
416 | 415 |
417 OverscrollRefresh::~OverscrollRefresh() { | 416 OverscrollRefresh::~OverscrollRefresh() { |
418 } | 417 } |
419 | 418 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 | 498 |
500 void OverscrollRefresh::Release(bool allow_activation) { | 499 void OverscrollRefresh::Release(bool allow_activation) { |
501 if (scroll_consumption_state_ == ENABLED) { | 500 if (scroll_consumption_state_ == ENABLED) { |
502 if (effect_->Release(base::TimeTicks::Now(), allow_activation)) | 501 if (effect_->Release(base::TimeTicks::Now(), allow_activation)) |
503 client_->TriggerRefresh(); | 502 client_->TriggerRefresh(); |
504 } | 503 } |
505 scroll_consumption_state_ = DISABLED; | 504 scroll_consumption_state_ = DISABLED; |
506 } | 505 } |
507 | 506 |
508 } // namespace content | 507 } // namespace content |
OLD | NEW |