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 "ui/gfx/screen.h" | 8 #include "ui/gfx/screen.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 , edge_scale_y_start_(0) | 132 , edge_scale_y_start_(0) |
133 , edge_scale_y_finish_(0) | 133 , edge_scale_y_finish_(0) |
134 , glow_alpha_start_(0) | 134 , glow_alpha_start_(0) |
135 , glow_alpha_finish_(0) | 135 , glow_alpha_finish_(0) |
136 , glow_scale_y_start_(0) | 136 , glow_scale_y_start_(0) |
137 , glow_scale_y_finish_(0) | 137 , glow_scale_y_finish_(0) |
138 , state_(STATE_IDLE) | 138 , state_(STATE_IDLE) |
139 , pull_distance_(0) | 139 , pull_distance_(0) |
140 , dpi_scale_(1) { | 140 , dpi_scale_(1) { |
141 // Prevent the provided layers from drawing until the effect is activated. | 141 // Prevent the provided layers from drawing until the effect is activated. |
142 DisableLayer(edge_); | 142 DisableLayer(edge_.get()); |
143 DisableLayer(glow_); | 143 DisableLayer(glow_.get()); |
144 | 144 |
145 dpi_scale_ = | 145 dpi_scale_ = |
146 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor(); | 146 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor(); |
147 } | 147 } |
148 | 148 |
149 EdgeEffect::~EdgeEffect() { } | 149 EdgeEffect::~EdgeEffect() { } |
150 | 150 |
151 bool EdgeEffect::IsFinished() const { | 151 bool EdgeEffect::IsFinished() const { |
152 return state_ == STATE_IDLE; | 152 return state_ == STATE_IDLE; |
153 } | 153 } |
154 | 154 |
155 void EdgeEffect::Finish() { | 155 void EdgeEffect::Finish() { |
156 DisableLayer(edge_); | 156 DisableLayer(edge_.get()); |
157 DisableLayer(glow_); | 157 DisableLayer(glow_.get()); |
158 pull_distance_ = 0; | 158 pull_distance_ = 0; |
159 state_ = STATE_IDLE; | 159 state_ = STATE_IDLE; |
160 } | 160 } |
161 | 161 |
162 void EdgeEffect::Pull(base::TimeTicks current_time, float delta_distance) { | 162 void EdgeEffect::Pull(base::TimeTicks current_time, float delta_distance) { |
163 if (state_ == STATE_PULL_DECAY && current_time - start_time_ < duration_) { | 163 if (state_ == STATE_PULL_DECAY && current_time - start_time_ < duration_) { |
164 return; | 164 return; |
165 } | 165 } |
166 if (state_ != STATE_PULL) { | 166 if (state_ != STATE_PULL) { |
167 glow_scale_y_ = kPullGlowBegin; | 167 glow_scale_y_ = kPullGlowBegin; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 return !IsFinished(); | 331 return !IsFinished(); |
332 } | 332 } |
333 | 333 |
334 void EdgeEffect::ApplyToLayers(gfx::SizeF size, Edge edge) { | 334 void EdgeEffect::ApplyToLayers(gfx::SizeF size, Edge edge) { |
335 if (IsFinished()) | 335 if (IsFinished()) |
336 return; | 336 return; |
337 | 337 |
338 // An empty effect size, while meaningless, is also relatively harmless, and | 338 // An empty effect size, while meaningless, is also relatively harmless, and |
339 // will simply prevent any drawing of the layers. | 339 // will simply prevent any drawing of the layers. |
340 if (size.IsEmpty()) { | 340 if (size.IsEmpty()) { |
341 DisableLayer(edge_); | 341 DisableLayer(edge_.get()); |
342 DisableLayer(glow_); | 342 DisableLayer(glow_.get()); |
343 return; | 343 return; |
344 } | 344 } |
345 | 345 |
346 float dummy_scale_x, dummy_scale_y; | 346 float dummy_scale_x, dummy_scale_y; |
347 | 347 |
348 // Glow | 348 // Glow |
349 gfx::Size glow_image_bounds; | 349 gfx::Size glow_image_bounds; |
350 glow_->CalculateContentsScale(1.f, 1.f, 1.f, false, | 350 glow_->CalculateContentsScale(1.f, 1.f, 1.f, false, |
351 &dummy_scale_x, &dummy_scale_y, | 351 &dummy_scale_x, &dummy_scale_y, |
352 &glow_image_bounds); | 352 &glow_image_bounds); |
353 const int glow_height = glow_image_bounds.height(); | 353 const int glow_height = glow_image_bounds.height(); |
354 const int glow_bottom = static_cast<int>(std::min( | 354 const int glow_bottom = static_cast<int>(std::min( |
355 glow_height * glow_scale_y_ * kGlowImageAspectRatioInverse * 0.6f, | 355 glow_height * glow_scale_y_ * kGlowImageAspectRatioInverse * 0.6f, |
356 glow_height * kMaxGlowHeight) * dpi_scale_ + 0.5f); | 356 glow_height * kMaxGlowHeight) * dpi_scale_ + 0.5f); |
357 UpdateLayer(glow_, edge, size, glow_bottom, glow_alpha_); | 357 UpdateLayer(glow_.get(), edge, size, glow_bottom, glow_alpha_); |
358 | 358 |
359 // Edge | 359 // Edge |
360 gfx::Size edge_image_bounds; | 360 gfx::Size edge_image_bounds; |
361 edge_->CalculateContentsScale(1.f, 1.f, 1.f, false, | 361 edge_->CalculateContentsScale(1.f, 1.f, 1.f, false, |
362 &dummy_scale_x, &dummy_scale_y, | 362 &dummy_scale_x, &dummy_scale_y, |
363 &edge_image_bounds); | 363 &edge_image_bounds); |
364 const int edge_height = edge_image_bounds.height(); | 364 const int edge_height = edge_image_bounds.height(); |
365 const int edge_bottom = static_cast<int>( | 365 const int edge_bottom = static_cast<int>( |
366 edge_height * edge_scale_y_ * dpi_scale_); | 366 edge_height * edge_scale_y_ * dpi_scale_); |
367 UpdateLayer(edge_, edge, size, edge_bottom, edge_alpha_); | 367 UpdateLayer(edge_.get(), edge, size, edge_bottom, edge_alpha_); |
368 } | 368 } |
369 | 369 |
370 } // namespace content | 370 } // namespace content |
OLD | NEW |