| Index: ui/gfx/compositor/layer.cc
|
| diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
|
| index b9b1cd373afcf86a586e1d9b4309764fbc424fd6..644ff51e7869ce5d3c31ed5dfe83df5c29e46610 100644
|
| --- a/ui/gfx/compositor/layer.cc
|
| +++ b/ui/gfx/compositor/layer.cc
|
| @@ -8,7 +8,6 @@
|
|
|
| #include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| -#include "ui/base/animation/animation.h"
|
| #include "ui/gfx/compositor/layer_animator.h"
|
| #include "ui/gfx/canvas_skia.h"
|
| #include "ui/gfx/interpolated_transform.h"
|
| @@ -106,43 +105,37 @@ bool Layer::Contains(const Layer* other) const {
|
| return false;
|
| }
|
|
|
| -void Layer::SetAnimation(Animation* animation) {
|
| - if (animation) {
|
| - if (!animator_.get())
|
| - animator_.reset(new LayerAnimator(this));
|
| - animation->Start();
|
| - animator_->SetAnimation(animation);
|
| - } else {
|
| - animator_.reset();
|
| +void Layer::SetAnimator(LayerAnimator* animator) {
|
| + animator->SetLayer(this);
|
| + animator_.reset(animator);
|
| +}
|
| +
|
| +LayerAnimator& Layer::GetAnimator() {
|
| + if (!animator_.get()) {
|
| + SetAnimator(LayerAnimator::CreateDefaultAnimator());
|
| }
|
| + return *animator_;
|
| }
|
|
|
| void Layer::SetTransform(const ui::Transform& transform) {
|
| - StopAnimatingIfNecessary(LayerAnimator::TRANSFORM);
|
| - if (animator_.get() && animator_->IsRunning()) {
|
| - animator_->AnimateTransform(transform);
|
| - return;
|
| - }
|
| - SetTransformImmediately(transform);
|
| + if (animator_.get())
|
| + animator_->SetTransform(transform);
|
| + else
|
| + SetTransformImmediately(transform);
|
| }
|
|
|
| void Layer::SetBounds(const gfx::Rect& bounds) {
|
| - StopAnimatingIfNecessary(LayerAnimator::LOCATION);
|
| - if (animator_.get() && animator_->IsRunning() &&
|
| - bounds.size() == bounds_.size()) {
|
| - animator_->AnimateToPoint(bounds.origin());
|
| - return;
|
| - }
|
| - SetBoundsImmediately(bounds);
|
| + if (animator_.get())
|
| + animator_->SetBounds(bounds);
|
| + else
|
| + SetBoundsImmediately(bounds);
|
| }
|
|
|
| void Layer::SetOpacity(float opacity) {
|
| - StopAnimatingIfNecessary(LayerAnimator::OPACITY);
|
| - if (animator_.get() && animator_->IsRunning()) {
|
| - animator_->AnimateOpacity(opacity);
|
| - return;
|
| - }
|
| - SetOpacityImmediately(opacity);
|
| + if (animator_.get())
|
| + animator_->SetOpacity(opacity);
|
| + else
|
| + SetOpacityImmediately(opacity);
|
| }
|
|
|
| void Layer::SetVisible(bool visible) {
|
| @@ -328,8 +321,15 @@ void Layer::RecomputeHole() {
|
| !IsApproximateMultilpleOf(degrees, 90.0f))
|
| continue;
|
|
|
| - gfx::Rect candidate_hole = children_[i]->bounds();
|
| - children_[i]->transform().TransformRect(&candidate_hole);
|
| + // The reason why we don't just take the bounds and apply the transform is
|
| + // that the bounds encodes a position, too, so the effective transformation
|
| + // matrix is actually different that the one reported. As well, the bounds
|
| + // will not necessarily be at the origin.
|
| + gfx::Rect candidate_hole(children_[i]->bounds_.size());
|
| + ui::Transform transform = children_[i]->transform();
|
| + transform.ConcatTranslate(static_cast<float>(children_[i]->bounds_.x()),
|
| + static_cast<float>(children_[i]->bounds_.y()));
|
| + transform.TransformRect(&candidate_hole);
|
|
|
| // This layer might not contain the child (e.g., a portion of the child may
|
| // be offscreen). Only the portion of the child that overlaps this layer is
|
| @@ -343,7 +343,7 @@ void Layer::RecomputeHole() {
|
|
|
| // Free up texture memory if the hole fills bounds of layer.
|
| if (!ShouldDraw() && !layer_updated_externally_)
|
| - texture_ = NULL;
|
| + DropTextures();
|
| }
|
|
|
| bool Layer::IsCompletelyOpaque() const {
|
| @@ -425,29 +425,6 @@ bool Layer::GetTransformRelativeTo(const Layer* ancestor,
|
| return p == ancestor;
|
| }
|
|
|
| -void Layer::StopAnimatingIfNecessary(
|
| - LayerAnimator::AnimationProperty property) {
|
| - if (!animator_.get() || !animator_->IsRunning() ||
|
| - !animator_->got_initial_tick()) {
|
| - return;
|
| - }
|
| -
|
| - if (property != LayerAnimator::LOCATION &&
|
| - animator_->IsAnimating(LayerAnimator::LOCATION)) {
|
| - SetBoundsImmediately(
|
| - gfx::Rect(animator_->GetTargetPoint(), bounds_.size()));
|
| - }
|
| - if (property != LayerAnimator::OPACITY &&
|
| - animator_->IsAnimating(LayerAnimator::OPACITY)) {
|
| - SetOpacityImmediately(animator_->GetTargetOpacity());
|
| - }
|
| - if (property != LayerAnimator::TRANSFORM &&
|
| - animator_->IsAnimating(LayerAnimator::TRANSFORM)) {
|
| - SetTransformImmediately(animator_->GetTargetTransform());
|
| - }
|
| - animator_.reset();
|
| -}
|
| -
|
| void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
|
| bounds_ = bounds;
|
|
|
| @@ -484,16 +461,32 @@ void Layer::SetOpacityImmediately(float opacity) {
|
| }
|
| }
|
|
|
| -void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) {
|
| +void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) {
|
| SetBoundsImmediately(bounds);
|
| }
|
|
|
| -void Layer::SetTransformFromAnimator(const Transform& transform) {
|
| +void Layer::SetTransformFromAnimation(const Transform& transform) {
|
| SetTransformImmediately(transform);
|
| }
|
|
|
| -void Layer::SetOpacityFromAnimator(float opacity) {
|
| +void Layer::SetOpacityFromAnimation(float opacity) {
|
| SetOpacityImmediately(opacity);
|
| }
|
|
|
| +void Layer::ScheduleDrawForAnimation() {
|
| + ScheduleDraw();
|
| +}
|
| +
|
| +const gfx::Rect& Layer::GetBoundsForAnimation() const {
|
| + return bounds();
|
| +}
|
| +
|
| +const Transform& Layer::GetTransformForAnimation() const {
|
| + return transform();
|
| +}
|
| +
|
| +const float Layer::GetOpacityForAnimation() const {
|
| + return opacity();
|
| +}
|
| +
|
| } // namespace ui
|
|
|