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/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 "content/browser/android/animation_utils.h" |
9 #include "ui/base/android/system_ui_resource_manager.h" | 9 #include "ui/android/resources/resource_manager.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Time it will take the effect to fully recede in ms | 15 // Time it will take the effect to fully recede in ms |
16 const int kRecedeTimeMs = 600; | 16 const int kRecedeTimeMs = 600; |
17 | 17 |
18 // 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 |
19 const int kPullTimeMs = 167; | 19 const int kPullTimeMs = 167; |
(...skipping 14 matching lines...) Expand all Loading... |
34 | 34 |
35 const float kSin = 0.5f; // sin(PI / 6) | 35 const float kSin = 0.5f; // sin(PI / 6) |
36 const float kCos = 0.866f; // cos(PI / 6); | 36 const float kCos = 0.866f; // cos(PI / 6); |
37 | 37 |
38 // How much dragging should effect the height of the glow image. | 38 // How much dragging should effect the height of the glow image. |
39 // Number determined by user testing. | 39 // Number determined by user testing. |
40 const float kPullDistanceAlphaGlowFactor = 0.8f; | 40 const float kPullDistanceAlphaGlowFactor = 0.8f; |
41 | 41 |
42 const int kVelocityGlowFactor = 6; | 42 const int kVelocityGlowFactor = 6; |
43 | 43 |
44 const ui::SystemUIResourceType kResourceType = ui::OVERSCROLL_GLOW_L; | 44 const ui::SystemUIResourceType kResourceId = ui::OVERSCROLL_GLOW_L; |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 EdgeEffectL::EdgeEffectL(ui::SystemUIResourceManager* resource_manager) | 48 EdgeEffectL::EdgeEffectL(ui::ResourceManager* resource_manager) |
49 : resource_manager_(resource_manager), | 49 : resource_manager_(resource_manager), |
50 glow_(cc::UIResourceLayer::Create()), | 50 glow_(cc::UIResourceLayer::Create()), |
51 glow_alpha_(0), | 51 glow_alpha_(0), |
52 glow_scale_y_(0), | 52 glow_scale_y_(0), |
53 glow_alpha_start_(0), | 53 glow_alpha_start_(0), |
54 glow_alpha_finish_(0), | 54 glow_alpha_finish_(0), |
55 glow_scale_y_start_(0), | 55 glow_scale_y_start_(0), |
56 glow_scale_y_finish_(0), | 56 glow_scale_y_finish_(0), |
57 displacement_(0.5f), | 57 displacement_(0.5f), |
58 target_displacement_(0.5f), | 58 target_displacement_(0.5f), |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 const float h = r - y; | 227 const float h = r - y; |
228 const float o_r = size.height() * 0.75f / kSin; | 228 const float o_r = size.height() * 0.75f / kSin; |
229 const float o_y = kCos * o_r; | 229 const float o_y = kCos * o_r; |
230 const float o_h = o_r - o_y; | 230 const float o_h = o_r - o_y; |
231 const float base_glow_scale = h > 0.f ? std::min(o_h / h, 1.f) : 1.f; | 231 const float base_glow_scale = h > 0.f ? std::min(o_h / h, 1.f) : 1.f; |
232 bounds_ = gfx::Size(size.width(), (int)std::min(size.height(), h)); | 232 bounds_ = gfx::Size(size.width(), (int)std::min(size.height(), h)); |
233 gfx::Size image_bounds( | 233 gfx::Size image_bounds( |
234 r, std::min(1.f, glow_scale_y_) * base_glow_scale * bounds_.height()); | 234 r, std::min(1.f, glow_scale_y_) * base_glow_scale * bounds_.height()); |
235 | 235 |
236 glow_->SetIsDrawable(true); | 236 glow_->SetIsDrawable(true); |
237 glow_->SetUIResourceId(resource_manager_->GetUIResourceId(kResourceType)); | 237 glow_->SetUIResourceId(resource_manager_->GetUIResourceId( |
| 238 ui::ANDROID_RESOURCE_TYPE_SYSTEM, kResourceId)); |
238 glow_->SetTransformOrigin(gfx::Point3F(bounds_.width() * 0.5f, 0, 0)); | 239 glow_->SetTransformOrigin(gfx::Point3F(bounds_.width() * 0.5f, 0, 0)); |
239 glow_->SetBounds(image_bounds); | 240 glow_->SetBounds(image_bounds); |
240 glow_->SetContentsOpaque(false); | 241 glow_->SetContentsOpaque(false); |
241 glow_->SetOpacity(Clamp(glow_alpha_, 0.f, 1.f)); | 242 glow_->SetOpacity(Clamp(glow_alpha_, 0.f, 1.f)); |
242 | 243 |
243 const float displacement = Clamp(displacement_, 0.f, 1.f) - 0.5f; | 244 const float displacement = Clamp(displacement_, 0.f, 1.f) - 0.5f; |
244 const float displacement_offset_x = bounds_.width() * displacement * 0.5f; | 245 const float displacement_offset_x = bounds_.width() * displacement * 0.5f; |
245 const float image_offset_x = (bounds_.width() - image_bounds.width()) * 0.5f; | 246 const float image_offset_x = (bounds_.width() - image_bounds.width()) * 0.5f; |
246 gfx::Transform offset_transform; | 247 gfx::Transform offset_transform; |
247 offset_transform.Translate(image_offset_x - displacement_offset_x, 0); | 248 offset_transform.Translate(image_offset_x - displacement_offset_x, 0); |
248 offset_transform.ConcatTransform(transform); | 249 offset_transform.ConcatTransform(transform); |
249 glow_->SetTransform(offset_transform); | 250 glow_->SetTransform(offset_transform); |
250 } | 251 } |
251 | 252 |
252 void EdgeEffectL::SetParent(cc::Layer* parent) { | 253 void EdgeEffectL::SetParent(cc::Layer* parent) { |
253 if (glow_->parent() != parent) | 254 if (glow_->parent() != parent) |
254 parent->AddChild(glow_); | 255 parent->AddChild(glow_); |
255 } | 256 } |
256 | 257 |
257 // static | 258 // static |
258 void EdgeEffectL::PreloadResources( | 259 void EdgeEffectL::PreloadResources(ui::ResourceManager* resource_manager) { |
259 ui::SystemUIResourceManager* resource_manager) { | |
260 DCHECK(resource_manager); | 260 DCHECK(resource_manager); |
261 resource_manager->PreloadResource(kResourceType); | 261 resource_manager->PreloadResource(ui::ANDROID_RESOURCE_TYPE_SYSTEM, |
| 262 kResourceId); |
262 } | 263 } |
263 | 264 |
264 } // namespace content | 265 } // namespace content |
OLD | NEW |