| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/gfx/compositor/layer.h" | 5 #include "ui/gfx/compositor/layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "ui/base/animation/animation.h" | 11 #include "ui/base/animation/animation.h" |
| 12 #include "ui/gfx/compositor/layer_animator.h" | 12 #include "ui/gfx/compositor/layer_animation_manager.h" |
| 13 #include "ui/gfx/canvas_skia.h" | 13 #include "ui/gfx/canvas_skia.h" |
| 14 #include "ui/gfx/interpolated_transform.h" | 14 #include "ui/gfx/interpolated_transform.h" |
| 15 #include "ui/gfx/point3.h" | 15 #include "ui/gfx/point3.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const float EPSILON = 1e-3f; | 19 const float EPSILON = 1e-3f; |
| 20 | 20 |
| 21 bool IsApproximateMultilpleOf(float value, float base) { | 21 bool IsApproximateMultilpleOf(float value, float base) { |
| 22 float remainder = fmod(fabs(value), base); | 22 float remainder = fmod(fabs(value), base); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 for (const Layer* parent = other; parent; parent = parent->parent()) { | 102 for (const Layer* parent = other; parent; parent = parent->parent()) { |
| 103 if (parent == this) | 103 if (parent == this) |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 return false; | 106 return false; |
| 107 } | 107 } |
| 108 | 108 |
| 109 void Layer::SetAnimation(Animation* animation) { | 109 void Layer::SetAnimation(Animation* animation) { |
| 110 if (animation) { | 110 if (animation) { |
| 111 if (!animator_.get()) | 111 if (!animator_.get()) |
| 112 animator_.reset(new LayerAnimator(this)); | 112 animator_.reset(new LayerAnimationManager(this)); |
| 113 animation->Start(); | 113 animation->Start(); |
| 114 animator_->SetAnimation(animation); | 114 animator_->SetAnimation(animation); |
| 115 } else { | 115 } else { |
| 116 animator_.reset(); | 116 animator_.reset(); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 void Layer::SetTransform(const ui::Transform& transform) { | 120 void Layer::SetTransform(const ui::Transform& transform) { |
| 121 StopAnimatingIfNecessary(LayerAnimator::TRANSFORM); | 121 StopAnimatingIfNecessary(LayerAnimationManager::TRANSFORM); |
| 122 if (animator_.get() && animator_->IsRunning()) { | 122 if (animator_.get() && animator_->IsRunning()) { |
| 123 animator_->AnimateTransform(transform); | 123 animator_->AnimateTransform(transform); |
| 124 return; | 124 return; |
| 125 } | 125 } |
| 126 SetTransformImmediately(transform); | 126 SetTransformImmediately(transform); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void Layer::SetBounds(const gfx::Rect& bounds) { | 129 void Layer::SetBounds(const gfx::Rect& bounds) { |
| 130 StopAnimatingIfNecessary(LayerAnimator::LOCATION); | 130 StopAnimatingIfNecessary(LayerAnimationManager::LOCATION); |
| 131 if (animator_.get() && animator_->IsRunning() && | 131 if (animator_.get() && animator_->IsRunning() && |
| 132 bounds.size() == bounds_.size()) { | 132 bounds.size() == bounds_.size()) { |
| 133 animator_->AnimateToPoint(bounds.origin()); | 133 animator_->AnimateToPoint(bounds.origin()); |
| 134 return; | 134 return; |
| 135 } | 135 } |
| 136 SetBoundsImmediately(bounds); | 136 SetBoundsImmediately(bounds); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void Layer::SetOpacity(float opacity) { | 139 void Layer::SetOpacity(float opacity) { |
| 140 StopAnimatingIfNecessary(LayerAnimator::OPACITY); | 140 StopAnimatingIfNecessary(LayerAnimationManager::OPACITY); |
| 141 if (animator_.get() && animator_->IsRunning()) { | 141 if (animator_.get() && animator_->IsRunning()) { |
| 142 animator_->AnimateOpacity(opacity); | 142 animator_->AnimateOpacity(opacity); |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 SetOpacityImmediately(opacity); | 145 SetOpacityImmediately(opacity); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void Layer::SetVisible(bool visible) { | 148 void Layer::SetVisible(bool visible) { |
| 149 if (visible_ == visible) | 149 if (visible_ == visible) |
| 150 return; | 150 return; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 for (; p && p != ancestor; p = p->parent()) { | 426 for (; p && p != ancestor; p = p->parent()) { |
| 427 if (p->transform().HasChange()) | 427 if (p->transform().HasChange()) |
| 428 transform->ConcatTransform(p->transform()); | 428 transform->ConcatTransform(p->transform()); |
| 429 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), | 429 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), |
| 430 static_cast<float>(p->bounds().y())); | 430 static_cast<float>(p->bounds().y())); |
| 431 } | 431 } |
| 432 return p == ancestor; | 432 return p == ancestor; |
| 433 } | 433 } |
| 434 | 434 |
| 435 void Layer::StopAnimatingIfNecessary( | 435 void Layer::StopAnimatingIfNecessary( |
| 436 LayerAnimator::AnimationProperty property) { | 436 LayerAnimationManager::AnimationProperty property) { |
| 437 if (!animator_.get() || !animator_->IsRunning() || | 437 if (!animator_.get() || !animator_->IsRunning() || |
| 438 !animator_->got_initial_tick()) { | 438 !animator_->got_initial_tick()) { |
| 439 return; | 439 return; |
| 440 } | 440 } |
| 441 | 441 |
| 442 if (property != LayerAnimator::LOCATION && | 442 if (property != LayerAnimationManager::LOCATION && |
| 443 animator_->IsAnimating(LayerAnimator::LOCATION)) { | 443 animator_->IsAnimating(LayerAnimationManager::LOCATION)) { |
| 444 SetBoundsImmediately( | 444 SetBoundsImmediately( |
| 445 gfx::Rect(animator_->GetTargetPoint(), bounds_.size())); | 445 gfx::Rect(animator_->GetTargetPoint(), bounds_.size())); |
| 446 } | 446 } |
| 447 if (property != LayerAnimator::OPACITY && | 447 if (property != LayerAnimationManager::OPACITY && |
| 448 animator_->IsAnimating(LayerAnimator::OPACITY)) { | 448 animator_->IsAnimating(LayerAnimationManager::OPACITY)) { |
| 449 SetOpacityImmediately(animator_->GetTargetOpacity()); | 449 SetOpacityImmediately(animator_->GetTargetOpacity()); |
| 450 } | 450 } |
| 451 if (property != LayerAnimator::TRANSFORM && | 451 if (property != LayerAnimationManager::TRANSFORM && |
| 452 animator_->IsAnimating(LayerAnimator::TRANSFORM)) { | 452 animator_->IsAnimating(LayerAnimationManager::TRANSFORM)) { |
| 453 SetTransformImmediately(animator_->GetTargetTransform()); | 453 SetTransformImmediately(animator_->GetTargetTransform()); |
| 454 } | 454 } |
| 455 animator_.reset(); | 455 animator_.reset(); |
| 456 } | 456 } |
| 457 | 457 |
| 458 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { | 458 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { |
| 459 bounds_ = bounds; | 459 bounds_ = bounds; |
| 460 | 460 |
| 461 if (parent()) | 461 if (parent()) |
| 462 parent()->RecomputeHole(); | 462 parent()->RecomputeHole(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 497 |
| 498 void Layer::SetTransformFromAnimator(const Transform& transform) { | 498 void Layer::SetTransformFromAnimator(const Transform& transform) { |
| 499 SetTransformImmediately(transform); | 499 SetTransformImmediately(transform); |
| 500 } | 500 } |
| 501 | 501 |
| 502 void Layer::SetOpacityFromAnimator(float opacity) { | 502 void Layer::SetOpacityFromAnimator(float opacity) { |
| 503 SetOpacityImmediately(opacity); | 503 SetOpacityImmediately(opacity); |
| 504 } | 504 } |
| 505 | 505 |
| 506 } // namespace ui | 506 } // namespace ui |
| OLD | NEW |