| 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 "chrome/browser/chromeos/ui/accessibility_focus_ring_controller.h" | 5 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 base::TimeDelta fade_out_time = animation_info->fade_out_time; | 430 base::TimeDelta fade_out_time = animation_info->fade_out_time; |
| 431 | 431 |
| 432 if (change_delta > fade_in_time + fade_out_time) { | 432 if (change_delta > fade_in_time + fade_out_time) { |
| 433 animation_info->opacity = 0.0; | 433 animation_info->opacity = 0.0; |
| 434 return; | 434 return; |
| 435 } | 435 } |
| 436 | 436 |
| 437 float opacity; | 437 float opacity; |
| 438 if (start_delta < fade_in_time) { | 438 if (start_delta < fade_in_time) { |
| 439 opacity = start_delta.InSecondsF() / fade_in_time.InSecondsF(); | 439 opacity = start_delta.InSecondsF() / fade_in_time.InSecondsF(); |
| 440 if (opacity > 1.0) | |
| 441 opacity = 1.0; | |
| 442 } else { | 440 } else { |
| 443 opacity = 1.0 - (change_delta.InSecondsF() / | 441 opacity = 1.0 - (change_delta.InSecondsF() / |
| 444 (fade_in_time + fade_out_time).InSecondsF()); | 442 (fade_in_time + fade_out_time).InSecondsF()); |
| 445 if (opacity < 0.0) | |
| 446 opacity = 0.0; | |
| 447 } | 443 } |
| 448 | 444 |
| 445 // Layer::SetOpacity will throw an error if we're not within 0...1. |
| 446 opacity = std::min(std::max(opacity, 0.0f), 1.0f); |
| 447 |
| 449 animation_info->opacity = opacity; | 448 animation_info->opacity = opacity; |
| 450 } | 449 } |
| 451 | 450 |
| 452 void AccessibilityFocusRingController::AnimateCursorRing( | 451 void AccessibilityFocusRingController::AnimateCursorRing( |
| 453 base::TimeTicks timestamp) { | 452 base::TimeTicks timestamp) { |
| 454 CHECK(cursor_layer_); | 453 CHECK(cursor_layer_); |
| 455 | 454 |
| 456 ComputeOpacity(&cursor_animation_info_, timestamp); | 455 ComputeOpacity(&cursor_animation_info_, timestamp); |
| 457 if (cursor_animation_info_.opacity == 0.0) { | 456 if (cursor_animation_info_.opacity == 0.0) { |
| 458 cursor_layer_.reset(); | 457 cursor_layer_.reset(); |
| 459 return; | 458 return; |
| 460 } | 459 } |
| 461 cursor_layer_->SetOpacity(cursor_animation_info_.opacity); | 460 cursor_layer_->SetOpacity(cursor_animation_info_.opacity); |
| 462 } | 461 } |
| 463 | 462 |
| 464 void AccessibilityFocusRingController::AnimateCaretRing( | 463 void AccessibilityFocusRingController::AnimateCaretRing( |
| 465 base::TimeTicks timestamp) { | 464 base::TimeTicks timestamp) { |
| 466 CHECK(caret_layer_); | 465 CHECK(caret_layer_); |
| 467 | 466 |
| 468 ComputeOpacity(&caret_animation_info_, timestamp); | 467 ComputeOpacity(&caret_animation_info_, timestamp); |
| 469 if (caret_animation_info_.opacity == 0.0) { | 468 if (caret_animation_info_.opacity == 0.0) { |
| 470 caret_layer_.reset(); | 469 caret_layer_.reset(); |
| 471 return; | 470 return; |
| 472 } | 471 } |
| 473 caret_layer_->SetOpacity(caret_animation_info_.opacity); | 472 caret_layer_->SetOpacity(caret_animation_info_.opacity); |
| 474 } | 473 } |
| 475 | 474 |
| 476 } // namespace chromeos | 475 } // namespace chromeos |
| OLD | NEW |