| 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 gfx::Rect Layer::GetTargetBounds() const { | 139 gfx::Rect Layer::GetTargetBounds() const { |
| 140 if (animator_.get() && animator_->IsRunning()) | 140 if (animator_.get() && animator_->IsRunning()) |
| 141 return gfx::Rect(animator_->GetTargetPoint(), bounds_.size()); | 141 return gfx::Rect(animator_->GetTargetPoint(), bounds_.size()); |
| 142 return bounds_; | 142 return bounds_; |
| 143 } | 143 } |
| 144 | 144 |
| 145 void Layer::SetOpacity(float opacity) { | 145 void Layer::SetOpacity(float opacity) { |
| 146 StopAnimatingIfNecessary(LayerAnimator::OPACITY); | 146 StopAnimatingIfNecessary(LayerAnimationManager::OPACITY); |
| 147 if (animator_.get() && animator_->IsRunning()) { | 147 if (animator_.get() && animator_->IsRunning()) { |
| 148 animator_->AnimateOpacity(opacity); | 148 animator_->AnimateOpacity(opacity); |
| 149 return; | 149 return; |
| 150 } | 150 } |
| 151 SetOpacityImmediately(opacity); | 151 SetOpacityImmediately(opacity); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void Layer::SetVisible(bool visible) { | 154 void Layer::SetVisible(bool visible) { |
| 155 if (visible_ == visible) | 155 if (visible_ == visible) |
| 156 return; | 156 return; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 for (; p && p != ancestor; p = p->parent()) { | 432 for (; p && p != ancestor; p = p->parent()) { |
| 433 if (p->transform().HasChange()) | 433 if (p->transform().HasChange()) |
| 434 transform->ConcatTransform(p->transform()); | 434 transform->ConcatTransform(p->transform()); |
| 435 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), | 435 transform->ConcatTranslate(static_cast<float>(p->bounds().x()), |
| 436 static_cast<float>(p->bounds().y())); | 436 static_cast<float>(p->bounds().y())); |
| 437 } | 437 } |
| 438 return p == ancestor; | 438 return p == ancestor; |
| 439 } | 439 } |
| 440 | 440 |
| 441 void Layer::StopAnimatingIfNecessary( | 441 void Layer::StopAnimatingIfNecessary( |
| 442 LayerAnimator::AnimationProperty property) { | 442 LayerAnimationManager::AnimationProperty property) { |
| 443 if (!animator_.get() || !animator_->IsRunning() || | 443 if (!animator_.get() || !animator_->IsRunning() || |
| 444 !animator_->got_initial_tick()) { | 444 !animator_->got_initial_tick()) { |
| 445 return; | 445 return; |
| 446 } | 446 } |
| 447 | 447 |
| 448 if (property != LayerAnimator::LOCATION && | 448 if (property != LayerAnimationManager::LOCATION && |
| 449 animator_->IsAnimating(LayerAnimator::LOCATION)) { | 449 animator_->IsAnimating(LayerAnimationManager::LOCATION)) { |
| 450 SetBoundsImmediately( | 450 SetBoundsImmediately( |
| 451 gfx::Rect(animator_->GetTargetPoint(), bounds_.size())); | 451 gfx::Rect(animator_->GetTargetPoint(), bounds_.size())); |
| 452 } | 452 } |
| 453 if (property != LayerAnimator::OPACITY && | 453 if (property != LayerAnimationManager::OPACITY && |
| 454 animator_->IsAnimating(LayerAnimator::OPACITY)) { | 454 animator_->IsAnimating(LayerAnimationManager::OPACITY)) { |
| 455 SetOpacityImmediately(animator_->GetTargetOpacity()); | 455 SetOpacityImmediately(animator_->GetTargetOpacity()); |
| 456 } | 456 } |
| 457 if (property != LayerAnimator::TRANSFORM && | 457 if (property != LayerAnimationManager::TRANSFORM && |
| 458 animator_->IsAnimating(LayerAnimator::TRANSFORM)) { | 458 animator_->IsAnimating(LayerAnimationManager::TRANSFORM)) { |
| 459 SetTransformImmediately(animator_->GetTargetTransform()); | 459 SetTransformImmediately(animator_->GetTargetTransform()); |
| 460 } | 460 } |
| 461 animator_.reset(); | 461 animator_.reset(); |
| 462 } | 462 } |
| 463 | 463 |
| 464 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { | 464 void Layer::SetBoundsImmediately(const gfx::Rect& bounds) { |
| 465 bounds_ = bounds; | 465 bounds_ = bounds; |
| 466 | 466 |
| 467 if (parent()) | 467 if (parent()) |
| 468 parent()->RecomputeHole(); | 468 parent()->RecomputeHole(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 503 |
| 504 void Layer::SetTransformFromAnimator(const Transform& transform) { | 504 void Layer::SetTransformFromAnimator(const Transform& transform) { |
| 505 SetTransformImmediately(transform); | 505 SetTransformImmediately(transform); |
| 506 } | 506 } |
| 507 | 507 |
| 508 void Layer::SetOpacityFromAnimator(float opacity) { | 508 void Layer::SetOpacityFromAnimator(float opacity) { |
| 509 SetOpacityImmediately(opacity); | 509 SetOpacityImmediately(opacity); |
| 510 } | 510 } |
| 511 | 511 |
| 512 } // namespace ui | 512 } // namespace ui |
| OLD | NEW |