OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/browser/android/edge_effect.h" | 5 #include "content/browser/android/edge_effect.h" |
6 | 6 |
7 #include "cc/layers/layer.h" | 7 #include "cc/layers/layer.h" |
8 #include "cc/layers/ui_resource_layer.h" | 8 #include "cc/layers/ui_resource_layer.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/android/resources/resource_manager.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Time it will take the effect to fully recede in ms | 16 // Time it will take the effect to fully recede in ms |
17 const int kRecedeTimeMs = 1000; | 17 const int kRecedeTimeMs = 1000; |
18 | 18 |
19 // Time it will take before a pulled glow begins receding in ms | 19 // Time it will take before a pulled glow begins receding in ms |
20 const int kPullTimeMs = 167; | 20 const int kPullTimeMs = 167; |
(...skipping 30 matching lines...) Expand all Loading... |
51 const int kVelocityGlowFactor = 12; | 51 const int kVelocityGlowFactor = 12; |
52 | 52 |
53 const float kEdgeHeightAtMdpi = 12.f; | 53 const float kEdgeHeightAtMdpi = 12.f; |
54 const float kGlowHeightAtMdpi = 128.f; | 54 const float kGlowHeightAtMdpi = 128.f; |
55 | 55 |
56 } // namespace | 56 } // namespace |
57 | 57 |
58 class EdgeEffect::EffectLayer { | 58 class EdgeEffect::EffectLayer { |
59 public: | 59 public: |
60 EffectLayer(ui::SystemUIResourceType resource_type, | 60 EffectLayer(ui::SystemUIResourceType resource_type, |
61 ui::SystemUIResourceManager* resource_manager) | 61 ui::ResourceManager* resource_manager) |
62 : ui_resource_layer_(cc::UIResourceLayer::Create()), | 62 : ui_resource_layer_(cc::UIResourceLayer::Create()), |
63 resource_type_(resource_type), | 63 resource_type_(resource_type), |
64 resource_manager_(resource_manager) {} | 64 resource_manager_(resource_manager) {} |
65 | 65 |
66 ~EffectLayer() { ui_resource_layer_->RemoveFromParent(); } | 66 ~EffectLayer() { ui_resource_layer_->RemoveFromParent(); } |
67 | 67 |
68 void SetParent(cc::Layer* parent) { | 68 void SetParent(cc::Layer* parent) { |
69 if (ui_resource_layer_->parent() != parent) | 69 if (ui_resource_layer_->parent() != parent) |
70 parent->AddChild(ui_resource_layer_); | 70 parent->AddChild(ui_resource_layer_); |
71 } | 71 } |
72 | 72 |
73 void Disable() { ui_resource_layer_->SetIsDrawable(false); } | 73 void Disable() { ui_resource_layer_->SetIsDrawable(false); } |
74 | 74 |
75 void Update(const gfx::Size& size, | 75 void Update(const gfx::Size& size, |
76 const gfx::Transform& transform, | 76 const gfx::Transform& transform, |
77 float opacity) { | 77 float opacity) { |
78 ui_resource_layer_->SetUIResourceId( | 78 ui_resource_layer_->SetUIResourceId(resource_manager_->GetUIResourceId( |
79 resource_manager_->GetUIResourceId(resource_type_)); | 79 ui::ANDROID_RESOURCE_TYPE_SYSTEM, resource_type_)); |
80 ui_resource_layer_->SetIsDrawable(true); | 80 ui_resource_layer_->SetIsDrawable(true); |
81 ui_resource_layer_->SetTransformOrigin( | 81 ui_resource_layer_->SetTransformOrigin( |
82 gfx::Point3F(size.width() * 0.5f, 0, 0)); | 82 gfx::Point3F(size.width() * 0.5f, 0, 0)); |
83 ui_resource_layer_->SetTransform(transform); | 83 ui_resource_layer_->SetTransform(transform); |
84 ui_resource_layer_->SetBounds(size); | 84 ui_resource_layer_->SetBounds(size); |
85 ui_resource_layer_->SetOpacity(Clamp(opacity, 0.f, 1.f)); | 85 ui_resource_layer_->SetOpacity(Clamp(opacity, 0.f, 1.f)); |
86 } | 86 } |
87 | 87 |
88 scoped_refptr<cc::UIResourceLayer> ui_resource_layer_; | 88 scoped_refptr<cc::UIResourceLayer> ui_resource_layer_; |
89 ui::SystemUIResourceType resource_type_; | 89 ui::SystemUIResourceType resource_type_; |
90 ui::SystemUIResourceManager* resource_manager_; | 90 ui::ResourceManager* resource_manager_; |
91 | 91 |
92 DISALLOW_COPY_AND_ASSIGN(EffectLayer); | 92 DISALLOW_COPY_AND_ASSIGN(EffectLayer); |
93 }; | 93 }; |
94 | 94 |
95 EdgeEffect::EdgeEffect(ui::SystemUIResourceManager* resource_manager, | 95 EdgeEffect::EdgeEffect(ui::ResourceManager* resource_manager, |
96 float device_scale_factor) | 96 float device_scale_factor) |
97 : edge_(new EffectLayer(ui::OVERSCROLL_EDGE, resource_manager)), | 97 : edge_(new EffectLayer(ui::OVERSCROLL_EDGE, resource_manager)), |
98 glow_(new EffectLayer(ui::OVERSCROLL_GLOW, resource_manager)), | 98 glow_(new EffectLayer(ui::OVERSCROLL_GLOW, resource_manager)), |
99 base_edge_height_(kEdgeHeightAtMdpi * device_scale_factor), | 99 base_edge_height_(kEdgeHeightAtMdpi * device_scale_factor), |
100 base_glow_height_(kGlowHeightAtMdpi * device_scale_factor), | 100 base_glow_height_(kGlowHeightAtMdpi * device_scale_factor), |
101 edge_alpha_(0), | 101 edge_alpha_(0), |
102 edge_scale_y_(0), | 102 edge_scale_y_(0), |
103 glow_alpha_(0), | 103 glow_alpha_(0), |
104 glow_scale_y_(0), | 104 glow_scale_y_(0), |
105 edge_alpha_start_(0), | 105 edge_alpha_start_(0), |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 const gfx::Size edge_size(size.width(), scaled_edge_height); | 328 const gfx::Size edge_size(size.width(), scaled_edge_height); |
329 edge_->Update(edge_size, transform, edge_alpha_); | 329 edge_->Update(edge_size, transform, edge_alpha_); |
330 } | 330 } |
331 | 331 |
332 void EdgeEffect::SetParent(cc::Layer* parent) { | 332 void EdgeEffect::SetParent(cc::Layer* parent) { |
333 edge_->SetParent(parent); | 333 edge_->SetParent(parent); |
334 glow_->SetParent(parent); | 334 glow_->SetParent(parent); |
335 } | 335 } |
336 | 336 |
337 // static | 337 // static |
338 void EdgeEffect::PreloadResources( | 338 void EdgeEffect::PreloadResources(ui::ResourceManager* resource_manager) { |
339 ui::SystemUIResourceManager* resource_manager) { | |
340 DCHECK(resource_manager); | 339 DCHECK(resource_manager); |
341 resource_manager->PreloadResource(ui::OVERSCROLL_EDGE); | 340 resource_manager->PreloadResource(ui::ANDROID_RESOURCE_TYPE_SYSTEM, |
342 resource_manager->PreloadResource(ui::OVERSCROLL_GLOW); | 341 ui::OVERSCROLL_EDGE); |
| 342 resource_manager->PreloadResource(ui::ANDROID_RESOURCE_TYPE_SYSTEM, |
| 343 ui::OVERSCROLL_GLOW); |
343 } | 344 } |
344 | 345 |
345 } // namespace content | 346 } // namespace content |
OLD | NEW |