summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorvollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-28 15:22:54 +0000
committervollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-28 15:22:54 +0000
commitfe7074c6120fdfc9d1d33f93b18d85dc9f496dfa (patch)
tree9a79a4c98976bd979a6f13c7cb10cc96e3d43f92 /ui
parent5e207050d52060974ab6b9ce6686574af706d440 (diff)
downloadchromium_src-fe7074c6120fdfc9d1d33f93b18d85dc9f496dfa.zip
chromium_src-fe7074c6120fdfc9d1d33f93b18d85dc9f496dfa.tar.gz
chromium_src-fe7074c6120fdfc9d1d33f93b18d85dc9f496dfa.tar.bz2
Reland r107720 - Enable the new layer animation framework.
Depends on http://codereview.chromium.org/8247009/ BUG=None TEST=None Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=107715 Review URL: http://codereview.chromium.org/8362006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107736 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/aura.gyp2
-rw-r--r--ui/aura/desktop.cc77
-rw-r--r--ui/aura/desktop.h4
-rw-r--r--ui/aura/screen_rotation.cc122
-rw-r--r--ui/aura/screen_rotation.h54
-rw-r--r--ui/aura/window.cc13
-rw-r--r--ui/aura/window.h9
-rw-r--r--ui/aura_shell/shell.cc1
-rw-r--r--ui/aura_shell/workspace/workspace.cc11
-rw-r--r--ui/aura_shell/workspace/workspace_manager.cc5
-rw-r--r--ui/gfx/compositor/compositor.gyp6
-rw-r--r--ui/gfx/compositor/dummy_layer_animation_delegate.cc55
-rw-r--r--ui/gfx/compositor/dummy_layer_animation_delegate.h (renamed from ui/gfx/compositor/test_layer_animation_delegate.h)22
-rw-r--r--ui/gfx/compositor/layer.cc109
-rw-r--r--ui/gfx/compositor/layer.h56
-rw-r--r--ui/gfx/compositor/layer_animation_delegate.h2
-rw-r--r--ui/gfx/compositor/layer_animation_element.cc25
-rw-r--r--ui/gfx/compositor/layer_animation_element.h18
-rw-r--r--ui/gfx/compositor/layer_animation_element_unittest.cc24
-rw-r--r--ui/gfx/compositor/layer_animation_manager.cc189
-rw-r--r--ui/gfx/compositor/layer_animation_manager.h129
-rw-r--r--ui/gfx/compositor/layer_animation_sequence.cc10
-rw-r--r--ui/gfx/compositor/layer_animation_sequence.h4
-rw-r--r--ui/gfx/compositor/layer_animation_sequence_unittest.cc32
-rw-r--r--ui/gfx/compositor/layer_animator.cc94
-rw-r--r--ui/gfx/compositor/layer_animator.h45
-rw-r--r--ui/gfx/compositor/layer_animator_delegate.h23
-rw-r--r--ui/gfx/compositor/layer_animator_unittest.cc32
-rw-r--r--ui/gfx/compositor/layer_delegate.h6
-rw-r--r--ui/gfx/compositor/layer_unittest.cc13
-rw-r--r--ui/gfx/compositor/test_layer_animation_delegate.cc44
31 files changed, 658 insertions, 578 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index b042f21..34ca7efe 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -45,6 +45,8 @@
'layout_manager.h',
'screen_aura.cc',
'screen_aura.h',
+ 'screen_rotation.cc',
+ 'screen_rotation.h',
'toplevel_window_container.cc',
'toplevel_window_container.h',
'toplevel_window_event_filter.cc',
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc
index ae14d46..2c747d2 100644
--- a/ui/aura/desktop.cc
+++ b/ui/aura/desktop.cc
@@ -21,11 +21,15 @@
#include "ui/aura/event_filter.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/screen_aura.h"
+#include "ui/aura/screen_rotation.h"
#include "ui/aura/toplevel_window_container.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/compositor/layer_animation_sequence.h"
+#include "ui/gfx/compositor/layer_animator.h"
+#include "ui/gfx/interpolated_transform.h"
using std::string;
using std::vector;
@@ -40,6 +44,22 @@ static const int kDefaultHostWindowY = 200;
static const int kDefaultHostWindowWidth = 1280;
static const int kDefaultHostWindowHeight = 1024;
+#if !defined(NDEBUG)
+// Converts degrees to an angle in the range [-180, 180).
+int NormalizeAngle(int degrees) {
+ while (degrees <= -180) degrees += 360;
+ while (degrees > 180) degrees -= 360;
+ return degrees;
+}
+
+static int SymmetricRound(float x) {
+ return static_cast<int>(
+ x > 0
+ ? std::floor(x + 0.5f)
+ : std::ceil(x - 0.5f));
+}
+#endif
+
class DefaultDesktopDelegate : public DesktopDelegate {
public:
explicit DefaultDesktopDelegate(Desktop* desktop) : desktop_(desktop) {}
@@ -259,31 +279,37 @@ bool Desktop::DispatchMouseEvent(MouseEvent* event) {
bool Desktop::DispatchKeyEvent(KeyEvent* event) {
#if !defined(NDEBUG)
- // Press Home key to rotate the screen. Primarily used for testing.
if (event->type() == ui::ET_KEY_PRESSED &&
- (event->flags() & ui::EF_CONTROL_DOWN) &&
- event->key_code() == ui::VKEY_HOME) {
- ui::Transform transform;
- static int count = 0;
- gfx::Size size = host_->GetSize();
- switch (count) {
- case 0:
- transform.ConcatRotate(-90.0f);
- transform.ConcatTranslate(0, size.height());
- break;
- case 1:
- transform.ConcatRotate(180.0f);
- transform.ConcatTranslate(size.width(), size.height());
- break;
- case 2:
- transform.ConcatRotate(90.0f);
- transform.ConcatTranslate(size.width(), 0);
- break;
+ (event->flags() & ui::EF_SHIFT_DOWN) &&
+ (event->flags() & ui::EF_ALT_DOWN) &&
+ event->is_char()) {
+
+ bool should_rotate = true;
+ int new_degrees = 0;
+ switch (event->key_code()) {
+ case ui::VKEY_UP: new_degrees = 0; break;
+ case ui::VKEY_DOWN: new_degrees = 180; break;
+ case ui::VKEY_RIGHT: new_degrees = 90; break;
+ case ui::VKEY_LEFT: new_degrees = -90; break;
+ default: should_rotate = false; break;
+ }
+
+ if (should_rotate) {
+ float rotation = 0.0f;
+ int degrees = 0;
+ const ui::Transform& transform = layer()->GetTargetTransform();
+ if (ui::InterpolatedTransform::FactorTRS(transform,
+ NULL, &rotation, NULL))
+ degrees = NormalizeAngle(new_degrees - SymmetricRound(rotation));
+
+ if (degrees != 0) {
+ layer()->GetAnimator()->set_preemption_strategy(
+ ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
+ layer()->GetAnimator()->ScheduleAnimationElement(
+ new ScreenRotation(degrees));
+ return true;
+ }
}
- layer()->SetAnimation(CreateDefaultAnimation());
- SetTransform(transform);
- count = (count + 1) % 4;
- return true;
}
#endif
@@ -442,7 +468,7 @@ void Desktop::SetTransform(const ui::Transform& transform) {
// If the layer is not animating, then we need to update the host size
// immediately.
- if (!layer()->has_animation())
+ if (!layer()->GetAnimator()->is_animating())
OnHostResized(host_->GetSize());
}
@@ -531,7 +557,8 @@ Desktop* Desktop::GetDesktop() {
return this;
}
-void Desktop::OnLayerAnimationEnded(const ui::Animation* animation) {
+void Desktop::OnLayerAnimationEnded(
+ const ui::LayerAnimationSequence* animation) {
OnHostResized(host_->GetSize());
}
diff --git a/ui/aura/desktop.h b/ui/aura/desktop.h
index ec3521d..9ee5c1d 100644
--- a/ui/aura/desktop.h
+++ b/ui/aura/desktop.h
@@ -25,6 +25,7 @@ class Size;
}
namespace ui {
+class LayerAnimationSequence;
class Transform;
}
@@ -146,7 +147,8 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate,
virtual Desktop* GetDesktop() OVERRIDE;
// Overridden from ui::LayerDelegate:
- virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE;
+ virtual void OnLayerAnimationEnded(
+ const ui::LayerAnimationSequence* animation) OVERRIDE;
// Overridden from FocusManager:
virtual void SetFocusedWindow(Window* window) OVERRIDE;
diff --git a/ui/aura/screen_rotation.cc b/ui/aura/screen_rotation.cc
new file mode 100644
index 0000000..d9e1fc8
--- /dev/null
+++ b/ui/aura/screen_rotation.cc
@@ -0,0 +1,122 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/aura/screen_rotation.h"
+
+#include "base/debug/trace_event.h"
+#include "base/time.h"
+#include "ui/gfx/compositor/layer_animation_delegate.h"
+#include "ui/gfx/interpolated_transform.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/transform.h"
+
+namespace {
+
+const int k90DegreeTransitionDurationMs = 350;
+const int k180DegreeTransitionDurationMs = 550;
+
+base::TimeDelta GetTransitionDuration(int degrees) {
+ if (degrees == 180)
+ return base::TimeDelta::FromMilliseconds(k180DegreeTransitionDurationMs);
+ else if (degrees == 0)
+ return base::TimeDelta::FromMilliseconds(0);
+ return base::TimeDelta::FromMilliseconds(k90DegreeTransitionDurationMs);
+}
+
+} // namespace
+
+ScreenRotation::ScreenRotation(int degrees)
+ : ui::LayerAnimationElement(GetProperties(),
+ GetTransitionDuration(degrees)),
+ degrees_(degrees) {
+}
+
+ScreenRotation::~ScreenRotation() {
+}
+
+void ScreenRotation::OnStart(ui::LayerAnimationDelegate* delegate) {
+ //TRACE_EVENT0("ScreenRotation", "init");
+
+ // No rotation required.
+ if (degrees_ == 0)
+ return;
+
+ const ui::Transform& current_transform = delegate->GetTransformForAnimation();
+ const gfx::Rect& bounds = delegate->GetBoundsForAnimation();
+
+ gfx::Point old_pivot;
+ gfx::Point new_pivot;
+
+ int width = bounds.width();
+ int height = bounds.height();
+
+ switch (degrees_) {
+ case 90:
+ new_origin_ = new_pivot = gfx::Point(width, 0);
+ break;
+ case -90:
+ new_origin_ = new_pivot = gfx::Point(0, height);
+ break;
+ case 180:
+ new_pivot = old_pivot = gfx::Point(width / 2, height / 2);
+ new_origin_.SetPoint(width, height);
+ break;
+ }
+
+ // Convert points to world space.
+ current_transform.TransformPoint(old_pivot);
+ current_transform.TransformPoint(new_pivot);
+ current_transform.TransformPoint(new_origin_);
+
+ scoped_ptr<ui::InterpolatedTransform> rotation(
+ new ui::InterpolatedTransformAboutPivot(
+ old_pivot,
+ new ui::InterpolatedRotation(0, degrees_)));
+
+ scoped_ptr<ui::InterpolatedTransform> translation(
+ new ui::InterpolatedTranslation(
+ gfx::Point(0, 0),
+ gfx::Point(new_pivot.x() - old_pivot.x(),
+ new_pivot.y() - old_pivot.y())));
+
+ float scale_factor = 0.9f;
+ scoped_ptr<ui::InterpolatedTransform> scale_down(
+ new ui::InterpolatedScale(1.0f, scale_factor, 0.0f, 0.5f));
+
+ scoped_ptr<ui::InterpolatedTransform> scale_up(
+ new ui::InterpolatedScale(1.0f, 1.0f / scale_factor, 0.5f, 1.0f));
+
+ interpolated_transform_.reset(
+ new ui::InterpolatedConstantTransform(current_transform));
+
+ scale_up->SetChild(scale_down.release());
+ translation->SetChild(scale_up.release());
+ rotation->SetChild(translation.release());
+ interpolated_transform_->SetChild(rotation.release());
+}
+
+void ScreenRotation::OnProgress(double t,
+ ui::LayerAnimationDelegate* delegate) {
+ //TRACE_EVENT0("ScreenRotation", "Progress");
+ delegate->SetTransformFromAnimation(interpolated_transform_->Interpolate(t));
+ delegate->ScheduleDrawForAnimation();
+}
+
+void ScreenRotation::OnGetTarget(TargetValue* target) const {
+ target->transform = interpolated_transform_->Interpolate(1.0);
+}
+
+void ScreenRotation::OnAbort() {
+}
+
+// static
+const ui::LayerAnimationElement::AnimatableProperties&
+ScreenRotation::GetProperties() {
+ static LayerAnimationElement::AnimatableProperties properties;
+ if (properties.size() == 0) {
+ properties.insert(LayerAnimationElement::TRANSFORM);
+ properties.insert(LayerAnimationElement::BOUNDS);
+ }
+ return properties;
+}
diff --git a/ui/aura/screen_rotation.h b/ui/aura/screen_rotation.h
new file mode 100644
index 0000000..e947b83
--- /dev/null
+++ b/ui/aura/screen_rotation.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_AURA_SCREEN_ROTATION_H_
+#define UI_AURA_SCREEN_ROTATION_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/base/animation/animation_delegate.h"
+#include "ui/gfx/compositor/layer_animation_element.h"
+#include "ui/gfx/point.h"
+
+namespace ui {
+class InterpolatedTransform;
+class LayerAnimationDelegate;
+}
+
+// A screen rotation represents a single transition from one screen orientation
+// to another. The intended usage is that a new instance of the class is
+// created for every transition. It is possible to update the target orientation
+// in the middle of a transition.
+class ScreenRotation : public ui::LayerAnimationElement {
+ public:
+ // The screen rotation does not own the view or the listener, and these
+ // objects are required to outlive the Screen rotation object.
+ ScreenRotation(int degrees);
+ virtual ~ScreenRotation();
+
+ private:
+ // Implementation of ui::LayerAnimationDelegate
+ virtual void OnStart(ui::LayerAnimationDelegate* delegate) OVERRIDE;
+ virtual void OnProgress(double t,
+ ui::LayerAnimationDelegate* delegate) OVERRIDE;
+ virtual void OnGetTarget(TargetValue* target) const OVERRIDE;
+ virtual void OnAbort() OVERRIDE;
+
+ static const ui::LayerAnimationElement::AnimatableProperties& GetProperties();
+
+ // Generates the intermediate transformation matrices used during the
+ // animation.
+ scoped_ptr<ui::InterpolatedTransform> interpolated_transform_;
+
+ // The number of degrees to rotate.
+ int degrees_;
+
+ // The target origin for |view_|
+ gfx::Point new_origin_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScreenRotation);
+};
+
+#endif // UI_AURA_SCREEN_ROTATION_H_
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index 4a0fb35..854eaf4 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -20,7 +20,6 @@
#include "ui/base/view_prop.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/compositor.h"
-#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/screen.h"
namespace aura {
@@ -437,15 +436,6 @@ void* Window::GetProperty(const char* name) const {
return ui::ViewProp::GetValue(const_cast<gfx::NativeView>(this), name);
}
-// static
-ui::Animation* Window::CreateDefaultAnimation() {
- std::vector<ui::MultiAnimation::Part> parts;
- parts.push_back(ui::MultiAnimation::Part(200, ui::Tween::LINEAR));
- ui::MultiAnimation* multi_animation = new ui::MultiAnimation(parts);
- multi_animation->set_continuous(false);
- return multi_animation;
-}
-
Desktop* Window::GetDesktop() {
return parent_ ? parent_->GetDesktop() : NULL;
}
@@ -541,7 +531,8 @@ void Window::OnPaintLayer(gfx::Canvas* canvas) {
delegate_->OnPaint(canvas);
}
-void Window::OnLayerAnimationEnded(const ui::Animation* animation) {
+void Window::OnLayerAnimationEnded(
+ const ui::LayerAnimationSequence* animation) {
}
} // namespace aura
diff --git a/ui/aura/window.h b/ui/aura/window.h
index daa8f06..2554716 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -17,6 +17,7 @@
#include "ui/base/ui_base_types.h"
#include "ui/aura/aura_export.h"
#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/compositor/layer_animator.h"
#include "ui/gfx/compositor/layer_delegate.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/rect.h"
@@ -27,6 +28,7 @@ namespace ui {
class Animation;
class Compositor;
class Layer;
+class LayerAnimationSequence;
class Transform;
class ViewProp;
}
@@ -268,10 +270,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// the property does not exist.
void* GetProperty(const char* name) const;
- // Returns an animation configured with the default duration. All animations
- // should use this. Caller owns returned value.
- static ui::Animation* CreateDefaultAnimation();
-
protected:
// Returns the desktop or NULL if we aren't yet attached to a desktop.
virtual Desktop* GetDesktop();
@@ -309,7 +307,8 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// Overridden from ui::LayerDelegate:
virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
- virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE;
+ virtual void OnLayerAnimationEnded(
+ const ui::LayerAnimationSequence* animation) OVERRIDE;
int type_;
diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc
index cac3fe8..fdb992f 100644
--- a/ui/aura_shell/shell.cc
+++ b/ui/aura_shell/shell.cc
@@ -20,6 +20,7 @@
#include "ui/aura_shell/workspace/workspace_manager.h"
#include "ui/base/view_prop.h"
#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/compositor/layer_animator.h"
#include "views/widget/native_widget_aura.h"
#include "views/widget/widget.h"
diff --git a/ui/aura_shell/workspace/workspace.cc b/ui/aura_shell/workspace/workspace.cc
index a9574da..f661e92 100644
--- a/ui/aura_shell/workspace/workspace.cc
+++ b/ui/aura_shell/workspace/workspace.cc
@@ -9,6 +9,7 @@
#include "ui/aura/window.h"
#include "ui/aura_shell/workspace/workspace_manager.h"
#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/compositor/layer_animator.h"
namespace {
// Horizontal margin between windows.
@@ -211,9 +212,13 @@ void Workspace::MoveWindowTo(
else {
gfx::Rect bounds = window->GetTargetBounds();
bounds.set_origin(origin);
- if (animate)
- window->layer()->SetAnimation(aura::Window::CreateDefaultAnimation());
- window->SetBounds(bounds);
+ if (animate) {
+ ui::LayerAnimator::ScopedSettings settings(
+ window->layer()->GetAnimator());
+ window->SetBounds(bounds);
+ } else {
+ window->SetBounds(bounds);
+ }
}
}
diff --git a/ui/aura_shell/workspace/workspace_manager.cc b/ui/aura_shell/workspace/workspace_manager.cc
index 4a6ecaa..c8904ea 100644
--- a/ui/aura_shell/workspace/workspace_manager.cc
+++ b/ui/aura_shell/workspace/workspace_manager.cc
@@ -131,7 +131,7 @@ void WorkspaceManager::SetOverview(bool overview) {
transform.SetTranslateX(-active_workspace_->bounds().x());
}
- viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation());
+ ui::LayerAnimator::ScopedSettings settings(viewport_->layer()->GetAnimator());
viewport_->layer()->SetTransform(transform);
}
@@ -247,7 +247,8 @@ void WorkspaceManager::UpdateViewport() {
if (active_workspace_) {
ui::Transform transform;
transform.SetTranslateX(-active_workspace_->bounds().x());
- viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation());
+ ui::LayerAnimator::ScopedSettings settings(
+ viewport_->layer()->GetAnimator());
viewport_->SetTransform(transform);
}
}
diff --git a/ui/gfx/compositor/compositor.gyp b/ui/gfx/compositor/compositor.gyp
index df3f7ac..682ca6f 100644
--- a/ui/gfx/compositor/compositor.gyp
+++ b/ui/gfx/compositor/compositor.gyp
@@ -45,13 +45,13 @@
'compositor_observer.h',
'compositor_stub.cc',
'compositor_win.cc',
+ 'dummy_layer_animation_delegate.cc',
+ 'dummy_layer_animation_delegate.h',
'layer.cc',
'layer.h',
'layer_animation_delegate.h',
'layer_animation_element.cc',
'layer_animation_element.h',
- 'layer_animation_manager.cc',
- 'layer_animation_manager.h',
'layer_animation_sequence.cc',
'layer_animation_sequence.h',
'layer_animator.cc',
@@ -146,8 +146,6 @@
'test_compositor_host.h',
'test_compositor_host_linux.cc',
'test_compositor_host_win.cc',
- 'test_layer_animation_delegate.cc',
- 'test_layer_animation_delegate.h',
'test_suite.cc',
'test_suite.h',
'test_utils.cc',
diff --git a/ui/gfx/compositor/dummy_layer_animation_delegate.cc b/ui/gfx/compositor/dummy_layer_animation_delegate.cc
new file mode 100644
index 0000000..ea026dc
--- /dev/null
+++ b/ui/gfx/compositor/dummy_layer_animation_delegate.cc
@@ -0,0 +1,55 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/compositor/dummy_layer_animation_delegate.h"
+
+namespace ui {
+
+DummyLayerAnimationDelegate::DummyLayerAnimationDelegate() : opacity_(1.0f) {
+}
+
+DummyLayerAnimationDelegate::DummyLayerAnimationDelegate(
+ const LayerAnimationDelegate& other)
+ : bounds_(other.GetBoundsForAnimation()),
+ transform_(other.GetTransformForAnimation()),
+ opacity_(other.GetOpacityForAnimation()) {
+}
+
+DummyLayerAnimationDelegate::~DummyLayerAnimationDelegate() {
+}
+
+void DummyLayerAnimationDelegate::SetBoundsFromAnimation(
+ const gfx::Rect& bounds) {
+ bounds_ = bounds;
+}
+
+void DummyLayerAnimationDelegate::SetTransformFromAnimation(
+ const Transform& transform) {
+ transform_ = transform;
+}
+
+void DummyLayerAnimationDelegate::SetOpacityFromAnimation(float opacity) {
+ opacity_ = opacity;
+}
+
+void DummyLayerAnimationDelegate::ScheduleDrawForAnimation() {
+}
+
+const gfx::Rect& DummyLayerAnimationDelegate::GetBoundsForAnimation() const {
+ return bounds_;
+}
+
+const Transform& DummyLayerAnimationDelegate::GetTransformForAnimation() const {
+ return transform_;
+}
+
+float DummyLayerAnimationDelegate::GetOpacityForAnimation() const {
+ return opacity_;
+}
+
+void DummyLayerAnimationDelegate::OnLayerAnimationEnded(
+ LayerAnimationSequence* sequence) {
+}
+
+} // namespace ui
diff --git a/ui/gfx/compositor/test_layer_animation_delegate.h b/ui/gfx/compositor/dummy_layer_animation_delegate.h
index 046e25c..69b6435 100644
--- a/ui/gfx/compositor/test_layer_animation_delegate.h
+++ b/ui/gfx/compositor/dummy_layer_animation_delegate.h
@@ -2,21 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef UI_GFX_COMPOSITOR_TEST_LAYER_ANIMATION_DELEGATE_H_
-#define UI_GFX_COMPOSITOR_TEST_LAYER_ANIMATION_DELEGATE_H_
+#ifndef UI_GFX_COMPOSITOR_DUMMY_LAYER_ANIMATION_DELEGATE_H_
+#define UI_GFX_COMPOSITOR_DUMMY_LAYER_ANIMATION_DELEGATE_H_
#pragma once
#include "base/compiler_specific.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/transform.h"
-#include "ui/gfx/compositor/layer_animation_delegate.h"
+#include "ui/gfx/compositor/compositor_export.h"
+#include "ui/gfx/compositor/layer_animator_delegate.h"
namespace ui {
-class TestLayerAnimationDelegate : public LayerAnimationDelegate {
+class LayerAnimationSequence;
+
+class COMPOSITOR_EXPORT DummyLayerAnimationDelegate
+ : public LayerAnimatorDelegate {
public:
- TestLayerAnimationDelegate();
- virtual ~TestLayerAnimationDelegate();
+ DummyLayerAnimationDelegate();
+ DummyLayerAnimationDelegate(const LayerAnimationDelegate& other);
+ virtual ~DummyLayerAnimationDelegate();
// Implementation of LayerAnimationDelegate
virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE;
@@ -27,6 +32,9 @@ class TestLayerAnimationDelegate : public LayerAnimationDelegate {
virtual const Transform& GetTransformForAnimation() const OVERRIDE;
virtual float GetOpacityForAnimation() const OVERRIDE;
+ // Implementation of LayerAnimatorDelegate
+ virtual void OnLayerAnimationEnded(LayerAnimationSequence* sequence) OVERRIDE;
+
private:
gfx::Rect bounds_;
Transform transform_;
@@ -37,4 +45,4 @@ class TestLayerAnimationDelegate : public LayerAnimationDelegate {
} // namespace ui
-#endif // UI_GFX_COMPOSITOR_TEST_LAYER_ANIMATION_DELEGATE_H_
+#endif // UI_GFX_COMPOSITOR_DUMMY_LAYER_ANIMATION_DELEGATE_H_
diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
index a075137..e9a9ed5 100644
--- a/ui/gfx/compositor/layer.cc
+++ b/ui/gfx/compositor/layer.cc
@@ -18,7 +18,7 @@
#include "ui/gfx/compositor/compositor_cc.h"
#endif
#include "ui/gfx/canvas_skia.h"
-#include "ui/gfx/compositor/layer_animation_manager.h"
+#include "ui/gfx/compositor/layer_animator.h"
#include "ui/gfx/interpolated_transform.h"
#include "ui/gfx/point3.h"
@@ -135,49 +135,46 @@ bool Layer::Contains(const Layer* other) const {
return false;
}
-void Layer::SetAnimation(Animation* animation) {
- if (animation) {
- if (!animator_.get())
- animator_.reset(new LayerAnimationManager(this));
- animation->Start();
- animator_->SetAnimation(animation);
- } else {
- animator_.reset();
- }
+void Layer::SetAnimator(LayerAnimator* animator) {
+ if (animator)
+ animator->SetDelegate(this);
+ animator_.reset(animator);
+}
+
+LayerAnimator* Layer::GetAnimator() {
+ if (!animator_.get())
+ SetAnimator(LayerAnimator::CreateDefaultAnimator());
+ return animator_.get();
}
void Layer::SetTransform(const ui::Transform& transform) {
- StopAnimatingIfNecessary(LayerAnimationManager::TRANSFORM);
- if (animator_.get() && animator_->IsRunning()) {
- animator_->AnimateTransform(transform);
- return;
- }
- SetTransformImmediately(transform);
+ GetAnimator()->SetTransform(transform);
+}
+
+Transform Layer::GetTargetTransform() const {
+ if (animator_.get() && animator_->is_animating())
+ return animator_->GetTargetTransform();
+ return transform_;
}
void Layer::SetBounds(const gfx::Rect& bounds) {
- StopAnimatingIfNecessary(LayerAnimationManager::LOCATION);
- if (animator_.get() && animator_->IsRunning() &&
- bounds.size() == bounds_.size()) {
- animator_->AnimateToPoint(bounds.origin());
- return;
- }
- SetBoundsImmediately(bounds);
+ GetAnimator()->SetBounds(bounds);
}
gfx::Rect Layer::GetTargetBounds() const {
- if (animator_.get() && animator_->IsRunning())
- return gfx::Rect(animator_->GetTargetPoint(), bounds_.size());
+ if (animator_.get() && animator_->is_animating())
+ return animator_->GetTargetBounds();
return bounds_;
}
void Layer::SetOpacity(float opacity) {
- StopAnimatingIfNecessary(LayerAnimationManager::OPACITY);
- if (animator_.get() && animator_->IsRunning()) {
- animator_->AnimateOpacity(opacity);
- return;
- }
- SetOpacityImmediately(opacity);
+ GetAnimator()->SetOpacity(opacity);
+}
+
+float Layer::GetTargetOpacity() const {
+ if (animator_.get() && animator_->is_animating())
+ return animator_->GetTargetOpacity();
+ return opacity_;
}
void Layer::SetVisible(bool visible) {
@@ -596,29 +593,6 @@ bool Layer::GetTransformRelativeTo(const Layer* ancestor,
return p == ancestor;
}
-void Layer::StopAnimatingIfNecessary(
- LayerAnimationManager::AnimationProperty property) {
- if (!animator_.get() || !animator_->IsRunning() ||
- !animator_->got_initial_tick()) {
- return;
- }
-
- if (property != LayerAnimationManager::LOCATION &&
- animator_->IsAnimating(LayerAnimationManager::LOCATION)) {
- SetBoundsImmediately(
- gfx::Rect(animator_->GetTargetPoint(), bounds_.size()));
- }
- if (property != LayerAnimationManager::OPACITY &&
- animator_->IsAnimating(LayerAnimationManager::OPACITY)) {
- SetOpacityImmediately(animator_->GetTargetOpacity());
- }
- if (property != LayerAnimationManager::TRANSFORM &&
- animator_->IsAnimating(LayerAnimationManager::TRANSFORM)) {
- SetTransformImmediately(animator_->GetTargetTransform());
- }
- animator_.reset();
-}
-
void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
bounds_ = bounds;
@@ -648,18 +622,39 @@ void Layer::SetOpacityImmediately(float opacity) {
#endif
}
-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();
+}
+
+float Layer::GetOpacityForAnimation() const {
+ return opacity();
+}
+
+void Layer::OnLayerAnimationEnded(LayerAnimationSequence* sequence) {
+ if (delegate_)
+ delegate_->OnLayerAnimationEnded(sequence);
+}
+
#if defined(USE_WEBKIT_COMPOSITOR)
void Layer::CreateWebLayer() {
web_layer_ = WebKit::WebContentLayer::create(this, this);
diff --git a/ui/gfx/compositor/layer.h b/ui/gfx/compositor/layer.h
index 792c194..1bb51e9 100644
--- a/ui/gfx/compositor/layer.h
+++ b/ui/gfx/compositor/layer.h
@@ -18,7 +18,6 @@
#include "ui/gfx/rect.h"
#include "ui/gfx/transform.h"
#include "ui/gfx/compositor/compositor.h"
-#include "ui/gfx/compositor/layer_animation_manager.h"
#include "ui/gfx/compositor/layer_animator_delegate.h"
#include "ui/gfx/compositor/layer_delegate.h"
@@ -26,8 +25,9 @@ class SkCanvas;
namespace ui {
-class Animation;
class Compositor;
+class LayerAnimator;
+class LayerAnimationSequence;
class Texture;
// Layer manages a texture, transform and a set of child Layers. Any View that
@@ -84,21 +84,22 @@ class COMPOSITOR_EXPORT Layer :
// Returns true if this Layer contains |other| somewhere in its children.
bool Contains(const Layer* other) const;
- // Sets the animation to use for changes to opacity, position or transform.
- // That is, if you invoke this with non-NULL |animation| is started and any
- // changes to opacity, position or transform are animated between the current
- // value and target value. If the current animation is NULL or completed,
- // changes are immediate. If the opacity, transform or bounds are changed
- // and the animation is part way through, the animation is canceled and
- // the bounds, opacity and transfrom and set to the target value.
- // Layer takes ownership of |animation| and installs it's own delegate on the
- // animation.
- void SetAnimation(Animation* animation);
- bool has_animation() const { return animator_.get() != NULL; }
+ // The layer's animator is responsible for causing automatic animations when
+ // properties are set. It also manages a queue of pending animations and
+ // handles blending of animations. The layer takes ownership of the animator.
+ void SetAnimator(LayerAnimator* animator);
+
+ // Returns the layer's animator. Creates a default animator of one has not
+ // been set. Will not return NULL.
+ LayerAnimator* GetAnimator();
// The transform, relative to the parent.
- void SetTransform(const ui::Transform& transform);
- const ui::Transform& transform() const { return transform_; }
+ void SetTransform(const Transform& transform);
+ const Transform& transform() const { return transform_; }
+
+ // Return the target transform if animator is running, or the current
+ // transform otherwise.
+ Transform GetTargetTransform() const;
// The bounds, relative to the parent.
void SetBounds(const gfx::Rect& bounds);
@@ -113,6 +114,10 @@ class COMPOSITOR_EXPORT Layer :
float opacity() const { return opacity_; }
void SetOpacity(float opacity);
+ // Return the target opacity if animator is running, or the current bounds
+ // otherwise.
+ float GetTargetOpacity() const;
+
// Sets the visibility of the Layer. A Layer may be visible but not
// drawn. This happens if any ancestor of a Layer is not visible.
void SetVisible(bool visible);
@@ -262,22 +267,21 @@ class COMPOSITOR_EXPORT Layer :
// should have valid alpha.
bool has_valid_alpha_channel() const { return !layer_updated_externally_; }
- // If the animation is running and has progressed, it is stopped and all
- // properties that are animated (except |property|) are immediately set to
- // their target value.
- void StopAnimatingIfNecessary(
- LayerAnimationManager::AnimationProperty property);
-
// Following are invoked from the animation or if no animation exists to
// update the values immediately.
void SetBoundsImmediately(const gfx::Rect& bounds);
void SetTransformImmediately(const ui::Transform& transform);
void SetOpacityImmediately(float opacity);
- // LayerAnimatorDelegate overrides:
- virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE;
- virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE;
- virtual void SetOpacityFromAnimator(float opacity) OVERRIDE;
+ // Implementation of LayerAnimatorDelegate
+ virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE;
+ virtual void SetTransformFromAnimation(const Transform& transform) OVERRIDE;
+ virtual void SetOpacityFromAnimation(float opacity) OVERRIDE;
+ virtual void ScheduleDrawForAnimation() OVERRIDE;
+ virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE;
+ virtual const Transform& GetTransformForAnimation() const OVERRIDE;
+ virtual float GetOpacityForAnimation() const OVERRIDE;
+ virtual void OnLayerAnimationEnded(LayerAnimationSequence* sequence) OVERRIDE;
#if defined(USE_WEBKIT_COMPOSITOR)
void CreateWebLayer();
@@ -317,7 +321,7 @@ class COMPOSITOR_EXPORT Layer :
LayerDelegate* delegate_;
- scoped_ptr<LayerAnimationManager> animator_;
+ scoped_ptr<LayerAnimator> animator_;
#if defined(USE_WEBKIT_COMPOSITOR)
WebKit::WebLayer web_layer_;
diff --git a/ui/gfx/compositor/layer_animation_delegate.h b/ui/gfx/compositor/layer_animation_delegate.h
index c6f4fa0..0f9ea4b 100644
--- a/ui/gfx/compositor/layer_animation_delegate.h
+++ b/ui/gfx/compositor/layer_animation_delegate.h
@@ -12,7 +12,7 @@
namespace ui {
-// LayerAnimation interacts with the Layer using this interface.
+// Layer animations interact with the layers using this interface.
class COMPOSITOR_EXPORT LayerAnimationDelegate {
public:
virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) = 0;
diff --git a/ui/gfx/compositor/layer_animation_element.cc b/ui/gfx/compositor/layer_animation_element.cc
index fb52bbb..abff5f6 100644
--- a/ui/gfx/compositor/layer_animation_element.cc
+++ b/ui/gfx/compositor/layer_animation_element.cc
@@ -7,8 +7,6 @@
#include "base/compiler_specific.h"
#include "ui/base/animation/tween.h"
#include "ui/gfx/compositor/layer_animation_delegate.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/transform.h"
namespace ui {
@@ -26,6 +24,7 @@ class Pause : public LayerAnimationElement {
virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE {}
virtual void OnProgress(double t,
LayerAnimationDelegate* delegate) OVERRIDE {}
+ virtual void OnGetTarget(TargetValue* target) const OVERRIDE {}
virtual void OnAbort() OVERRIDE {}
DISALLOW_COPY_AND_ASSIGN(Pause);
@@ -51,6 +50,10 @@ class TransformTransition : public LayerAnimationElement {
Tween::ValueBetween(t, start_, target_));
}
+ virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
+ target->transform = target_;
+ }
+
virtual void OnAbort() OVERRIDE {}
private:
@@ -86,6 +89,10 @@ class BoundsTransition : public LayerAnimationElement {
delegate->SetBoundsFromAnimation(Tween::ValueBetween(t, start_, target_));
}
+ virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
+ target->bounds = target_;
+ }
+
virtual void OnAbort() OVERRIDE {}
private:
@@ -119,6 +126,10 @@ class OpacityTransition : public LayerAnimationElement {
delegate->SetOpacityFromAnimation(Tween::ValueBetween(t, start_, target_));
}
+ virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
+ target->opacity = target_;
+ }
+
virtual void OnAbort() OVERRIDE {}
private:
@@ -137,6 +148,11 @@ class OpacityTransition : public LayerAnimationElement {
} // namespace
+// LayerAnimationElement::TargetValue ------------------------------------------
+
+LayerAnimationElement::TargetValue::TargetValue() : opacity(0.0f) {
+}
+
// LayerAnimationElement -------------------------------------------------------
LayerAnimationElement::LayerAnimationElement(
@@ -155,9 +171,14 @@ void LayerAnimationElement::Progress(double t,
if (first_frame_)
OnStart(delegate);
OnProgress(t, delegate);
+ delegate->ScheduleDrawForAnimation();
first_frame_ = t == 1.0;
}
+void LayerAnimationElement::GetTargetValue(TargetValue* target) const {
+ OnGetTarget(target);
+}
+
void LayerAnimationElement::Abort() {
first_frame_ = true;
OnAbort();
diff --git a/ui/gfx/compositor/layer_animation_element.h b/ui/gfx/compositor/layer_animation_element.h
index 12697b0..d38bc42 100644
--- a/ui/gfx/compositor/layer_animation_element.h
+++ b/ui/gfx/compositor/layer_animation_element.h
@@ -10,10 +10,8 @@
#include "base/time.h"
#include "ui/gfx/compositor/compositor_export.h"
-
-namespace gfx {
-class Rect;
-} // gfx
+#include "ui/gfx/rect.h"
+#include "ui/gfx/transform.h"
namespace ui {
@@ -31,6 +29,14 @@ class COMPOSITOR_EXPORT LayerAnimationElement {
OPACITY
};
+ struct TargetValue {
+ public:
+ TargetValue();
+ gfx::Rect bounds;
+ Transform transform;
+ float opacity;
+ };
+
typedef std::set<AnimatableProperty> AnimatableProperties;
LayerAnimationElement(const AnimatableProperties& properties,
@@ -71,6 +77,9 @@ class COMPOSITOR_EXPORT LayerAnimationElement {
// before OnStarted or Progress.
void Abort();
+ // Assigns the target value to |target|.
+ void GetTargetValue(TargetValue* target) const;
+
// The properties that the element modifies.
const AnimatableProperties& properties() const { return properties_; }
@@ -82,6 +91,7 @@ class COMPOSITOR_EXPORT LayerAnimationElement {
// OnProgress.
virtual void OnStart(LayerAnimationDelegate* delegate) = 0;
virtual void OnProgress(double t, LayerAnimationDelegate* delegate) = 0;
+ virtual void OnGetTarget(TargetValue* target) const = 0;
virtual void OnAbort() = 0;
private:
diff --git a/ui/gfx/compositor/layer_animation_element_unittest.cc b/ui/gfx/compositor/layer_animation_element_unittest.cc
index efbc1ca..483817c 100644
--- a/ui/gfx/compositor/layer_animation_element_unittest.cc
+++ b/ui/gfx/compositor/layer_animation_element_unittest.cc
@@ -11,9 +11,9 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/transform.h"
+#include "ui/gfx/compositor/dummy_layer_animation_delegate.h"
#include "ui/gfx/compositor/layer_animation_delegate.h"
#include "ui/gfx/compositor/test_utils.h"
-#include "ui/gfx/compositor/test_layer_animation_delegate.h"
namespace ui {
@@ -22,7 +22,7 @@ namespace {
// Check that the transformation element progresses the delegate as expected and
// that the element can be reused after it completes.
TEST(LayerAnimationElementTest, TransformElement) {
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
Transform start_transform, target_transform, middle_transform;
start_transform.SetRotate(-90);
target_transform.SetRotate(90);
@@ -44,13 +44,17 @@ TEST(LayerAnimationElementTest, TransformElement) {
delegate.GetTransformForAnimation());
}
+ LayerAnimationElement::TargetValue target_value;
+ element->GetTargetValue(&target_value);
+ CheckApproximatelyEqual(target_transform, target_value.transform);
+
EXPECT_EQ(delta, element->duration());
}
// Check that the bounds element progresses the delegate as expected and
// that the element can be reused after it completes.
TEST(LayerAnimationElementTest, BoundsElement) {
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
gfx::Rect start, target, middle;
start = target = middle = gfx::Rect(0, 0, 50, 50);
start.set_x(-90);
@@ -70,13 +74,17 @@ TEST(LayerAnimationElementTest, BoundsElement) {
CheckApproximatelyEqual(target, delegate.GetBoundsForAnimation());
}
+ LayerAnimationElement::TargetValue target_value;
+ element->GetTargetValue(&target_value);
+ CheckApproximatelyEqual(target, target_value.bounds);
+
EXPECT_EQ(delta, element->duration());
}
// Check that the opacity element progresses the delegate as expected and
// that the element can be reused after it completes.
TEST(LayerAnimationElementTest, OpacityElement) {
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
float start = 0.0;
float middle = 0.5;
float target = 1.0;
@@ -94,6 +102,10 @@ TEST(LayerAnimationElementTest, OpacityElement) {
EXPECT_FLOAT_EQ(target, delegate.GetOpacityForAnimation());
}
+ LayerAnimationElement::TargetValue target_value;
+ element->GetTargetValue(&target_value);
+ EXPECT_FLOAT_EQ(target, target_value.opacity);
+
EXPECT_EQ(delta, element->duration());
}
@@ -109,8 +121,8 @@ TEST(LayerAnimationElementTest, PauseElement) {
scoped_ptr<LayerAnimationElement> element(
LayerAnimationElement::CreatePauseElement(properties, delta));
- TestLayerAnimationDelegate delegate;
- TestLayerAnimationDelegate copy = delegate;
+ DummyLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate copy = delegate;
element->Progress(1.0, &delegate);
diff --git a/ui/gfx/compositor/layer_animation_manager.cc b/ui/gfx/compositor/layer_animation_manager.cc
deleted file mode 100644
index b900cd0..0000000
--- a/ui/gfx/compositor/layer_animation_manager.cc
+++ /dev/null
@@ -1,189 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/gfx/compositor/layer_animation_manager.h"
-
-#include "base/logging.h"
-#include "base/stl_util.h"
-#include "ui/base/animation/animation_container.h"
-#include "ui/base/animation/animation.h"
-#include "ui/base/animation/tween.h"
-#include "ui/gfx/compositor/compositor.h"
-#include "ui/gfx/compositor/layer.h"
-#include "ui/gfx/compositor/layer_animator_delegate.h"
-#include "ui/gfx/transform.h"
-#include "ui/gfx/rect.h"
-
-namespace {
-
-void SetMatrixElement(SkMatrix44& matrix, int index, SkMScalar value) {
- int row = index / 4;
- int col = index % 4;
- matrix.set(row, col, value);
-}
-
-SkMScalar GetMatrixElement(const SkMatrix44& matrix, int index) {
- int row = index / 4;
- int col = index % 4;
- return matrix.get(row, col);
-}
-
-} // anonymous namespace
-
-namespace ui {
-
-LayerAnimationManager::LayerAnimationManager(Layer* layer)
- : layer_(layer),
- got_initial_tick_(false) {
-}
-
-LayerAnimationManager::~LayerAnimationManager() {
-}
-
-void LayerAnimationManager::SetAnimation(Animation* animation) {
- animation_.reset(animation);
- if (animation_.get()) {
- static ui::AnimationContainer* container = NULL;
- if (!container) {
- container = new AnimationContainer;
- container->AddRef();
- }
- animation_->set_delegate(this);
- animation_->SetContainer(container);
- got_initial_tick_ = false;
- }
-}
-
-void LayerAnimationManager::AnimateToPoint(const gfx::Point& target) {
- StopAnimating(LOCATION);
- const gfx::Rect& layer_bounds = layer_->bounds();
- if (target == layer_bounds.origin())
- return; // Already there.
-
- Params& element = elements_[LOCATION];
- element.location.target_x = target.x();
- element.location.target_y = target.y();
- element.location.start_x = layer_bounds.origin().x();
- element.location.start_y = layer_bounds.origin().y();
-}
-
-void LayerAnimationManager::AnimateTransform(const Transform& transform) {
- StopAnimating(TRANSFORM);
- const Transform& layer_transform = layer_->transform();
- if (transform == layer_transform)
- return; // Already there.
-
- Params& element = elements_[TRANSFORM];
- for (int i = 0; i < 16; ++i) {
- element.transform.start[i] =
- GetMatrixElement(layer_transform.matrix(), i);
- element.transform.target[i] =
- GetMatrixElement(transform.matrix(), i);
- }
-}
-
-void LayerAnimationManager::AnimateOpacity(float target_opacity) {
- StopAnimating(OPACITY);
- if (layer_->opacity() == target_opacity)
- return;
-
- Params& element = elements_[OPACITY];
- element.opacity.start = layer_->opacity();
- element.opacity.target = target_opacity;
-}
-
-gfx::Point LayerAnimationManager::GetTargetPoint() {
- return IsAnimating(LOCATION) ?
- gfx::Point(elements_[LOCATION].location.target_x,
- elements_[LOCATION].location.target_y) :
- layer_->bounds().origin();
-}
-
-float LayerAnimationManager::GetTargetOpacity() {
- return IsAnimating(OPACITY) ?
- elements_[OPACITY].opacity.target : layer_->opacity();
-}
-
-ui::Transform LayerAnimationManager::GetTargetTransform() {
- if (IsAnimating(TRANSFORM)) {
- Transform transform;
- for (int i = 0; i < 16; ++i) {
- SetMatrixElement(transform.matrix(), i,
- elements_[TRANSFORM].transform.target[i]);
- }
- return transform;
- }
- return layer_->transform();
-}
-
-bool LayerAnimationManager::IsAnimating(AnimationProperty property) const {
- return elements_.count(property) > 0;
-}
-
-bool LayerAnimationManager::IsRunning() const {
- return animation_.get() && animation_->is_animating();
-}
-
-void LayerAnimationManager::AnimationProgressed(
- const ui::Animation* animation) {
- got_initial_tick_ = true;
- for (Elements::const_iterator i = elements_.begin(); i != elements_.end();
- ++i) {
- switch (i->first) {
- case LOCATION: {
- const gfx::Rect& current_bounds(layer_->bounds());
- gfx::Rect new_bounds = animation_->CurrentValueBetween(
- gfx::Rect(gfx::Point(i->second.location.start_x,
- i->second.location.start_y),
- current_bounds.size()),
- gfx::Rect(gfx::Point(i->second.location.target_x,
- i->second.location.target_y),
- current_bounds.size()));
- delegate()->SetBoundsFromAnimator(new_bounds);
- break;
- }
-
- case TRANSFORM: {
- Transform transform;
- for (int j = 0; j < 16; ++j) {
- SkMScalar value = animation_->CurrentValueBetween(
- i->second.transform.start[j],
- i->second.transform.target[j]);
- SetMatrixElement(transform.matrix(), j, value);
- }
- delegate()->SetTransformFromAnimator(transform);
- break;
- }
-
- case OPACITY: {
- delegate()->SetOpacityFromAnimator(animation_->CurrentValueBetween(
- i->second.opacity.start, i->second.opacity.target));
- break;
- }
-
- default:
- NOTREACHED();
- }
- }
- layer_->ScheduleDraw();
-}
-
-void LayerAnimationManager::AnimationEnded(const ui::Animation* animation) {
- AnimationProgressed(animation);
- if (layer_->delegate())
- layer_->delegate()->OnLayerAnimationEnded(animation);
-}
-
-void LayerAnimationManager::StopAnimating(AnimationProperty property) {
- if (!IsAnimating(property))
- return;
-
- elements_.erase(property);
-}
-
-LayerAnimatorDelegate* LayerAnimationManager::delegate() {
- return static_cast<LayerAnimatorDelegate*>(layer_);
-}
-
-} // namespace ui
diff --git a/ui/gfx/compositor/layer_animation_manager.h b/ui/gfx/compositor/layer_animation_manager.h
deleted file mode 100644
index b5b6540..0000000
--- a/ui/gfx/compositor/layer_animation_manager.h
+++ /dev/null
@@ -1,129 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef UI_GFX_COMPOSITOR_LAYER_ANIMATION_MANAGER_H_
-#define UI_GFX_COMPOSITOR_LAYER_ANIMATION_MANAGER_H_
-#pragma once
-
-#include <map>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/memory/scoped_ptr.h"
-#include "third_party/skia/include/core/SkScalar.h"
-#include "third_party/skia/include/utils/SkMatrix44.h"
-#include "ui/base/animation/animation_delegate.h"
-#include "ui/gfx/compositor/compositor_export.h"
-
-namespace gfx {
-class Point;
-}
-
-namespace ui {
-
-class Animation;
-class Layer;
-class LayerAnimatorDelegate;
-class Transform;
-
-// LayerAnimationManager manages animating various properties of a Layer.
-class COMPOSITOR_EXPORT LayerAnimationManager : public ui::AnimationDelegate {
- public:
- // Types of properties that can be animated.
- enum AnimationProperty {
- LOCATION,
- OPACITY,
- TRANSFORM,
- };
-
- explicit LayerAnimationManager(Layer* layer);
- virtual ~LayerAnimationManager();
-
- // Sets the animation to use. LayerAnimationManager takes ownership of the
- // animation.
- void SetAnimation(Animation* animation);
-
- ui::Layer* layer() { return layer_; }
-
- // Animates the layer to the specified point. The point is relative to the
- // parent layer.
- void AnimateToPoint(const gfx::Point& target);
-
- // Animates the transform from the current transform to |transform|.
- void AnimateTransform(const Transform& transform);
-
- // Animates the opacity from the current opacity to |target_opacity|.
- void AnimateOpacity(float target_opacity);
-
- // Returns the target value for the specified type. If the specified property
- // is not animating, the current value is returned.
- gfx::Point GetTargetPoint();
- float GetTargetOpacity();
- ui::Transform GetTargetTransform();
-
- // Returns true if animating |property|.
- bool IsAnimating(AnimationProperty property) const;
-
- // Returns true if the animation is running.
- bool IsRunning() const;
-
- // Returns true if the animation has progressed at least once since
- // SetAnimation() was invoked.
- bool got_initial_tick() const { return got_initial_tick_; }
-
- // AnimationDelegate:
- virtual void AnimationProgressed(const Animation* animation) OVERRIDE;
- virtual void AnimationEnded(const Animation* animation) OVERRIDE;
-
- private:
- // Parameters used when animating the location.
- struct LocationParams {
- int start_x;
- int start_y;
- int target_x;
- int target_y;
- };
-
- // Parameters used when animating the transform.
- struct TransformParams {
- SkMScalar start[16];
- SkMScalar target[16];
- };
-
- // Parameters used when animating the opacity.
- struct OpacityParams {
- float start;
- float target;
- };
-
- union Params {
- LocationParams location;
- OpacityParams opacity;
- TransformParams transform;
- };
-
- typedef std::map<AnimationProperty, Params> Elements;
-
- // Stops animating the specified property. This does not set the property
- // being animated to its final value.
- void StopAnimating(AnimationProperty property);
-
- LayerAnimatorDelegate* delegate();
-
- // The layer.
- Layer* layer_;
-
- // Properties being animated.
- Elements elements_;
-
- scoped_ptr<ui::Animation> animation_;
-
- bool got_initial_tick_;
-
- DISALLOW_COPY_AND_ASSIGN(LayerAnimationManager);
-};
-
-} // namespace ui
-
-#endif // UI_GFX_COMPOSITOR_LAYER_ANIMATION_MANAGER_H_
diff --git a/ui/gfx/compositor/layer_animation_sequence.cc b/ui/gfx/compositor/layer_animation_sequence.cc
index f0deca6..8f34969 100644
--- a/ui/gfx/compositor/layer_animation_sequence.cc
+++ b/ui/gfx/compositor/layer_animation_sequence.cc
@@ -29,7 +29,6 @@ LayerAnimationSequence::~LayerAnimationSequence() {
void LayerAnimationSequence::Progress(base::TimeDelta elapsed,
LayerAnimationDelegate* delegate) {
- TRACE_EVENT0("LayerAnimationSequence", "Progress");
if (elements_.size() == 0 || duration_ == base::TimeDelta())
return;
@@ -69,6 +68,15 @@ void LayerAnimationSequence::Progress(base::TimeDelta elapsed,
}
}
+void LayerAnimationSequence::GetTargetValue(
+ LayerAnimationElement::TargetValue* target) const {
+ if (is_cyclic_)
+ return;
+
+ for (size_t i = last_element_; i < elements_.size(); ++i)
+ elements_[i]->GetTargetValue(target);
+}
+
void LayerAnimationSequence::Abort() {
size_t current_index = last_element_ % elements_.size();
while (current_index < elements_.size()) {
diff --git a/ui/gfx/compositor/layer_animation_sequence.h b/ui/gfx/compositor/layer_animation_sequence.h
index 87673d7..4670587 100644
--- a/ui/gfx/compositor/layer_animation_sequence.h
+++ b/ui/gfx/compositor/layer_animation_sequence.h
@@ -37,6 +37,10 @@ class COMPOSITOR_EXPORT LayerAnimationSequence {
// guaranteed that Animate will be called with elapsed = Duration().
void Progress(base::TimeDelta elapsed, LayerAnimationDelegate* delegate);
+ // Sets the target value to the value that would have been set had
+ // the sequence completed. Does nothing if the sequence is cyclic.
+ void GetTargetValue(LayerAnimationElement::TargetValue* target) const;
+
// Aborts the given animation.
void Abort();
diff --git a/ui/gfx/compositor/layer_animation_sequence_unittest.cc b/ui/gfx/compositor/layer_animation_sequence_unittest.cc
index 3b283a3f..a80a5f1 100644
--- a/ui/gfx/compositor/layer_animation_sequence_unittest.cc
+++ b/ui/gfx/compositor/layer_animation_sequence_unittest.cc
@@ -11,10 +11,10 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/transform.h"
+#include "ui/gfx/compositor/dummy_layer_animation_delegate.h"
#include "ui/gfx/compositor/layer_animation_delegate.h"
#include "ui/gfx/compositor/layer_animation_element.h"
#include "ui/gfx/compositor/test_utils.h"
-#include "ui/gfx/compositor/test_layer_animation_delegate.h"
namespace ui {
@@ -33,7 +33,7 @@ TEST(LayerAnimationSequenceTest, NoElement) {
// a single element.
TEST(LayerAnimationSequenceTest, SingleElement) {
LayerAnimationSequence sequence;
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
float start = 0.0;
float middle = 0.5;
float target = 1.0;
@@ -61,7 +61,7 @@ TEST(LayerAnimationSequenceTest, SingleElement) {
// multiple elements. Note, see the layer animator tests for cyclic sequences.
TEST(LayerAnimationSequenceTest, MultipleElement) {
LayerAnimationSequence sequence;
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
float start_opacity = 0.0;
float middle_opacity = 0.5;
float target_opacity = 1.0;
@@ -93,7 +93,7 @@ TEST(LayerAnimationSequenceTest, MultipleElement) {
EXPECT_FLOAT_EQ(middle_opacity, delegate.GetOpacityForAnimation());
sequence.Progress(base::TimeDelta::FromMilliseconds(1000), &delegate);
EXPECT_FLOAT_EQ(target_opacity, delegate.GetOpacityForAnimation());
- TestLayerAnimationDelegate copy = delegate;
+ DummyLayerAnimationDelegate copy = delegate;
// In the middle of the pause -- nothing should have changed.
sequence.Progress(base::TimeDelta::FromMilliseconds(1500), &delegate);
@@ -129,7 +129,7 @@ TEST(LayerAnimationSequenceTest, MultipleElement) {
// Check that a sequence can still be aborted if it has cycled many times.
TEST(LayerAnimationSequenceTest, AbortingCyclicSequence) {
LayerAnimationSequence sequence;
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
float start_opacity = 0.0;
float target_opacity = 1.0;
base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
@@ -153,6 +153,28 @@ TEST(LayerAnimationSequenceTest, AbortingCyclicSequence) {
EXPECT_FLOAT_EQ(start_opacity, delegate.GetOpacityForAnimation());
}
+// Check that a sequence can be 'fast-forwarded' to the end and the target set.
+// Also check that this has no effect if the sequence is cyclic.
+TEST(LayerAnimationSequenceTest, SetTarget) {
+ LayerAnimationSequence sequence;
+ DummyLayerAnimationDelegate delegate;
+ float start_opacity = 0.0;
+ float target_opacity = 1.0;
+ base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
+ sequence.AddElement(
+ LayerAnimationElement::CreateOpacityElement(target_opacity, delta));
+
+ LayerAnimationElement::TargetValue target_value;
+ target_value.opacity = start_opacity;
+ sequence.GetTargetValue(&target_value);
+ EXPECT_FLOAT_EQ(target_opacity, target_value.opacity);
+
+ sequence.set_is_cyclic(true);
+ target_value.opacity = start_opacity;
+ sequence.GetTargetValue(&target_value);
+ EXPECT_FLOAT_EQ(start_opacity, target_value.opacity);
+}
+
} // namespace
} // namespace ui
diff --git a/ui/gfx/compositor/layer_animator.cc b/ui/gfx/compositor/layer_animator.cc
index e737377..8004c5c 100644
--- a/ui/gfx/compositor/layer_animator.cc
+++ b/ui/gfx/compositor/layer_animator.cc
@@ -10,7 +10,7 @@
#include "ui/base/animation/animation_container.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
-#include "ui/gfx/compositor/layer_animation_delegate.h"
+#include "ui/gfx/compositor/layer_animator_delegate.h"
#include "ui/gfx/compositor/layer_animation_sequence.h"
namespace ui {
@@ -20,7 +20,7 @@ class LayerAnimator;
namespace {
static const base::TimeDelta kDefaultTransitionDuration =
- base::TimeDelta::FromMilliseconds(250);
+ base::TimeDelta::FromMilliseconds(200);
static const base::TimeDelta kTimerInterval =
base::TimeDelta::FromMilliseconds(10);
@@ -55,30 +55,45 @@ void LayerAnimator::SetTransform(const Transform& transform) {
if (transition_duration_ == base::TimeDelta())
delegate_->SetTransformFromAnimation(transform);
else
- StartAnimation(new LayerAnimationSequence(
- LayerAnimationElement::CreateTransformElement(transform,
- transition_duration_)));
+ StartAnimationElement(LayerAnimationElement::CreateTransformElement(
+ transform, transition_duration_));
+}
+
+Transform LayerAnimator::GetTargetTransform() const {
+ LayerAnimationElement::TargetValue target;
+ GetTargetValue(&target);
+ return target.transform;
}
void LayerAnimator::SetBounds(const gfx::Rect& bounds) {
if (transition_duration_ == base::TimeDelta())
delegate_->SetBoundsFromAnimation(bounds);
else
- StartAnimation(new LayerAnimationSequence(
- LayerAnimationElement::CreateBoundsElement(bounds,
- transition_duration_)));
+ StartAnimationElement(LayerAnimationElement::CreateBoundsElement(
+ bounds, transition_duration_));
+}
+
+gfx::Rect LayerAnimator::GetTargetBounds() const {
+ LayerAnimationElement::TargetValue target;
+ GetTargetValue(&target);
+ return target.bounds;
}
void LayerAnimator::SetOpacity(float opacity) {
if (transition_duration_ == base::TimeDelta())
delegate_->SetOpacityFromAnimation(opacity);
else
- StartAnimation(new LayerAnimationSequence(
- LayerAnimationElement::CreateOpacityElement(opacity,
- transition_duration_)));
+ StartAnimationElement(LayerAnimationElement::CreateOpacityElement(
+ opacity, transition_duration_));
}
-void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) {
+float LayerAnimator::GetTargetOpacity() const {
+ LayerAnimationElement::TargetValue target;
+ GetTargetValue(&target);
+ return target.opacity;
+}
+
+void LayerAnimator::SetDelegate(LayerAnimatorDelegate* delegate) {
DCHECK(delegate);
delegate_ = delegate;
}
@@ -107,6 +122,7 @@ void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) {
}
}
FinishAnyAnimationWithZeroDuration();
+ UpdateAnimationState();
}
void LayerAnimator::ScheduleAnimation(LayerAnimationSequence* animation) {
@@ -116,6 +132,7 @@ void LayerAnimator::ScheduleAnimation(LayerAnimationSequence* animation) {
} else {
StartSequenceImmediately(animation);
}
+ UpdateAnimationState();
}
void LayerAnimator::ScheduleTogether(
@@ -141,6 +158,24 @@ void LayerAnimator::ScheduleTogether(
for (iter = animations.begin(); iter != animations.end(); ++iter) {
ScheduleAnimation(*iter);
}
+
+ UpdateAnimationState();
+}
+
+void LayerAnimator::StartAnimationElement(LayerAnimationElement* animation) {
+ StartAnimation(new LayerAnimationSequence(animation));
+}
+
+void LayerAnimator::ScheduleAnimationElement(LayerAnimationElement* animation) {
+ ScheduleAnimation(new LayerAnimationSequence(animation));
+}
+
+void LayerAnimator::ScheduleElementsTogether(
+ const std::vector<LayerAnimationElement*>& animations) {
+ std::vector<LayerAnimationSequence*> sequences;
+ for (size_t i = 0; i < animations.size(); ++i)
+ sequences.push_back(new LayerAnimationSequence(animations[i]));
+ ScheduleTogether(sequences);
}
void LayerAnimator::StopAnimatingProperty(
@@ -158,10 +193,24 @@ void LayerAnimator::StopAnimating() {
FinishAnimation(running_animations_[0].sequence);
}
+LayerAnimator::ScopedSettings::ScopedSettings(LayerAnimator* animator)
+ : animator_(animator),
+ old_transition_duration_(animator->transition_duration_) {
+ SetTransitionDuration(kDefaultTransitionDuration);
+}
+
+LayerAnimator::ScopedSettings::~ScopedSettings() {
+ animator_->transition_duration_ = old_transition_duration_;
+}
+
+void LayerAnimator::ScopedSettings::SetTransitionDuration(
+ base::TimeDelta duration) {
+ animator_->transition_duration_ = duration;
+}
+
// LayerAnimator private -------------------------------------------------------
void LayerAnimator::Step(base::TimeTicks now) {
- TRACE_EVENT0("LayerAnimator", "Step");
last_step_time_ = now;
std::vector<LayerAnimationSequence*> to_finish;
for (RunningAnimations::iterator iter = running_animations_.begin();
@@ -228,6 +277,7 @@ void LayerAnimator::RemoveAnimation(LayerAnimationSequence* sequence) {
void LayerAnimator::FinishAnimation(LayerAnimationSequence* sequence) {
sequence->Progress(sequence->duration(), delegate());
+ delegate()->OnLayerAnimationEnded(sequence);
RemoveAnimation(sequence);
ProcessQueue();
UpdateAnimationState();
@@ -243,6 +293,7 @@ void LayerAnimator::FinishAnyAnimationWithZeroDuration() {
if (running_animations_[i].sequence->duration() == base::TimeDelta()) {
running_animations_[i].sequence->Progress(
running_animations_[i].sequence->duration(), delegate());
+ delegate()->OnLayerAnimationEnded(running_animations_[i].sequence);
RemoveAnimation(running_animations_[i].sequence);
} else {
++i;
@@ -300,11 +351,13 @@ void LayerAnimator::RemoveAllAnimationsWithACommonProperty(
if (running_animations_[i].sequence->HasCommonProperty(
sequence->properties())) {
// Finish the animation.
- if (abort)
+ if (abort){
running_animations_[i].sequence->Abort();
- else
+ } else {
running_animations_[i].sequence->Progress(
running_animations_[i].sequence->duration(), delegate());
+ delegate()->OnLayerAnimationEnded(running_animations_[i].sequence);
+ }
RemoveAnimation(running_animations_[i].sequence);
} else {
++i;
@@ -331,6 +384,7 @@ void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) {
const bool abort = false;
RemoveAllAnimationsWithACommonProperty(sequence, abort);
sequence->Progress(sequence->duration(), delegate());
+ delegate()->OnLayerAnimationEnded(sequence);
RemoveAnimation(sequence);
}
@@ -377,10 +431,8 @@ void LayerAnimator::ProcessQueue() {
bool started_sequence = false;
do {
started_sequence = false;
-
// Build a list of all currently animated properties.
LayerAnimationElement::AnimatableProperties animated;
-
for (RunningAnimations::const_iterator iter = running_animations_.begin();
iter != running_animations_.end(); ++iter) {
animated.insert((*iter).sequence->properties().begin(),
@@ -440,4 +492,12 @@ bool LayerAnimator::StartSequenceImmediately(LayerAnimationSequence* sequence) {
return true;
}
+void LayerAnimator::GetTargetValue(
+ LayerAnimationElement::TargetValue* target) const {
+ for (RunningAnimations::const_iterator iter = running_animations_.begin();
+ iter != running_animations_.end(); ++iter) {
+ (*iter).sequence->GetTargetValue(target);
+ }
+}
+
} // namespace ui
diff --git a/ui/gfx/compositor/layer_animator.h b/ui/gfx/compositor/layer_animator.h
index a51079c..e6751ff 100644
--- a/ui/gfx/compositor/layer_animator.h
+++ b/ui/gfx/compositor/layer_animator.h
@@ -24,11 +24,11 @@ namespace ui {
class Animation;
class Layer;
class LayerAnimationSequence;
+class LayerAnimatorDelegate;
class Transform;
// When a property of layer needs to be changed it is set by way of
-// LayerAnimator. This enables LayerAnimator to animate property
-// changes.
+// LayerAnimator. This enables LayerAnimator to animate property changes.
class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement {
public:
enum PreemptionStrategy {
@@ -50,16 +50,19 @@ class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement {
// Sets the transform on the delegate. May cause an implicit animation.
virtual void SetTransform(const Transform& transform);
+ Transform GetTargetTransform() const;
// Sets the bounds on the delegate. May cause an implicit animation.
virtual void SetBounds(const gfx::Rect& bounds);
+ gfx::Rect GetTargetBounds() const;
// Sets the opacity on the delegate. May cause an implicit animation.
virtual void SetOpacity(float opacity);
+ float GetTargetOpacity() const;
// Sets the layer animation delegate the animator is associated with. The
// animator does not own the delegate.
- void SetDelegate(LayerAnimationDelegate* delegate);
+ void SetDelegate(LayerAnimatorDelegate* delegate);
// Sets the animation preemption strategy. This determines the behaviour if
// a property is set during an animation. The default is
@@ -82,6 +85,14 @@ class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement {
// animation sequences.
void ScheduleTogether(const std::vector<LayerAnimationSequence*>& animations);
+ // These are cover functions that create sequences for you to wrap the given
+ // elements. These sequences are then passed to the corresponding function
+ // above.
+ void StartAnimationElement(LayerAnimationElement* element);
+ void ScheduleAnimationElement(LayerAnimationElement* element);
+ void ScheduleElementsTogether(
+ const std::vector<LayerAnimationElement*>& element);
+
// Returns true if there is an animation in the queue (animations remain in
// the queue until they complete).
bool is_animating() const { return !animation_queue_.empty(); }
@@ -101,10 +112,30 @@ class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement {
}
base::TimeTicks get_last_step_time_for_test() { return last_step_time_; }
+ // Scoped settings allow you to temporarily change the animator's settings and
+ // these changes are reverted when the object is destroyed. NOTE: when the
+ // settings object is created, it applies the default transition duration
+ // (200ms).
+ class ScopedSettings {
+ public:
+ explicit ScopedSettings(LayerAnimator* animator);
+ virtual ~ScopedSettings();
+
+ void SetTransitionDuration(base::TimeDelta duration);
+
+ private:
+ LayerAnimator* animator_;
+ base::TimeDelta old_transition_duration_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedSettings);
+ };
+
protected:
- LayerAnimationDelegate* delegate() { return delegate_; }
+ LayerAnimatorDelegate* delegate() { return delegate_; }
private:
+ friend class TransientSettings;
+
// We need to keep track of the start time of every running animation.
struct RunningAnimation {
RunningAnimation(LayerAnimationSequence* sequence,
@@ -176,11 +207,15 @@ class COMPOSITOR_EXPORT LayerAnimator : public AnimationContainerElement {
// properties affected by |sequence|.
bool StartSequenceImmediately(LayerAnimationSequence* sequence);
+ // Sets the value of target as if all the running and queued animations were
+ // allowed to finish.
+ void GetTargetValue(LayerAnimationElement::TargetValue* target) const;
+
// This is the queue of animations to run.
AnimationQueue animation_queue_;
// The target of all layer animations.
- LayerAnimationDelegate* delegate_;
+ LayerAnimatorDelegate* delegate_;
// The currently running animations.
RunningAnimations running_animations_;
diff --git a/ui/gfx/compositor/layer_animator_delegate.h b/ui/gfx/compositor/layer_animator_delegate.h
index 85cbc79..173584f 100644
--- a/ui/gfx/compositor/layer_animator_delegate.h
+++ b/ui/gfx/compositor/layer_animator_delegate.h
@@ -6,22 +6,23 @@
#define UI_GFX_COMPOSITOR_LAYER_ANIMATOR_DELEGATE_H_
#pragma once
+#include "ui/gfx/rect.h"
+#include "ui/gfx/transform.h"
#include "ui/gfx/compositor/compositor_export.h"
-
-namespace gfx {
-class Rect;
-}
+#include "ui/gfx/compositor/layer_animation_delegate.h"
namespace ui {
-class Transform;
+class LayerAnimationSequence;
-// LayerAnimator modifies the Layer using this interface.
-class COMPOSITOR_EXPORT LayerAnimatorDelegate {
+// Layer animators interact with the layers using this interface.
+class COMPOSITOR_EXPORT LayerAnimatorDelegate : public LayerAnimationDelegate {
public:
- virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) = 0;
- virtual void SetTransformFromAnimator(const Transform& transform) = 0;
- virtual void SetOpacityFromAnimator(float opacity) = 0;
+ // Called when the |sequence| ends. Not called if |sequence| is aborted.
+ virtual void OnLayerAnimationEnded(LayerAnimationSequence* sequence) = 0;
+
+ // if this becomes necessary, this would be the appropriate place to add
+ // notifications about elements starting or ending, or sequences starting.
protected:
virtual ~LayerAnimatorDelegate() {}
@@ -29,4 +30,4 @@ class COMPOSITOR_EXPORT LayerAnimatorDelegate {
} // namespace ui
-#endif // UI_GFX_COMPOSITOR_LAYER_H_
+#endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_DELEGATE_H_
diff --git a/ui/gfx/compositor/layer_animator_unittest.cc b/ui/gfx/compositor/layer_animator_unittest.cc
index 6eccb52..e92d7c5 100644
--- a/ui/gfx/compositor/layer_animator_unittest.cc
+++ b/ui/gfx/compositor/layer_animator_unittest.cc
@@ -11,11 +11,11 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/transform.h"
+#include "ui/gfx/compositor/dummy_layer_animation_delegate.h"
#include "ui/gfx/compositor/layer_animation_delegate.h"
#include "ui/gfx/compositor/layer_animation_element.h"
#include "ui/gfx/compositor/layer_animation_sequence.h"
#include "ui/gfx/compositor/test_utils.h"
-#include "ui/gfx/compositor/test_layer_animation_delegate.h"
namespace ui {
@@ -27,7 +27,7 @@ TEST(LayerAnimatorTest, ImplicitAnimation) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator());
AnimationContainerElement* element = animator.get();
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
base::TimeTicks now = base::TimeTicks::Now();
animator->SetOpacity(0.5);
@@ -41,7 +41,7 @@ TEST(LayerAnimatorTest, ImplicitAnimation) {
TEST(LayerAnimatorTest, NoImplicitAnimation) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
base::TimeTicks now = base::TimeTicks::Now();
animator->SetOpacity(0.5);
@@ -54,7 +54,7 @@ TEST(LayerAnimatorTest, NoImplicitAnimation) {
TEST(LayerAnimatorTest, StopAnimatingProperty) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator());
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
base::TimeTicks now = base::TimeTicks::Now();
double target_opacity(0.5);
@@ -74,7 +74,7 @@ TEST(LayerAnimatorTest, StopAnimatingProperty) {
TEST(LayerAnimatorTest, StopAnimating) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateImplicitAnimator());
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
base::TimeTicks now = base::TimeTicks::Now();
double target_opacity(0.5);
@@ -94,7 +94,7 @@ TEST(LayerAnimatorTest, ScheduleAnimationThatCanRunImmediately) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
AnimationContainerElement* element = animator.get();
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
double start_opacity(0.0);
@@ -131,7 +131,7 @@ TEST(LayerAnimatorTest, ScheduleTwoAnimationsThatCanRunImmediately) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
AnimationContainerElement* element = animator.get();
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
double start_opacity(0.0);
@@ -181,7 +181,7 @@ TEST(LayerAnimatorTest, ScheduleTwoAnimationsOnSameProperty) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
AnimationContainerElement* element = animator.get();
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
double start_opacity(0.0);
@@ -233,7 +233,7 @@ TEST(LayerAnimatorTest, ScheduleBlockedAnimation) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
AnimationContainerElement* element = animator.get();
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
double start_opacity(0.0);
@@ -311,7 +311,7 @@ TEST(LayerAnimatorTest, ScheduleTogether) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
AnimationContainerElement* element = animator.get();
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
double start_opacity(0.0);
@@ -364,7 +364,7 @@ TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
AnimationContainerElement* element = animator.get();
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
double start_opacity(0.0);
@@ -399,7 +399,7 @@ TEST(LayerAnimatorTest, StartAnimationThatCanRunImmediately) {
TEST(LayerAnimatorTest, PreemptBySettingNewTarget) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
double start_opacity(0.0);
@@ -428,7 +428,7 @@ TEST(LayerAnimatorTest, PreemptByImmediatelyAnimatingToNewTarget) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
AnimationContainerElement* element = animator.get();
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
double start_opacity(0.0);
@@ -480,7 +480,7 @@ TEST(LayerAnimatorTest, PreemptEnqueueNewAnimation) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
AnimationContainerElement* element = animator.get();
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
double start_opacity(0.0);
@@ -533,7 +533,7 @@ TEST(LayerAnimatorTest, PreemptyByReplacingQueuedAnimations) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
AnimationContainerElement* element = animator.get();
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
double start_opacity(0.0);
@@ -588,7 +588,7 @@ TEST(LayerAnimatorTest, CyclicSequences) {
scoped_ptr<LayerAnimator> animator(LayerAnimator::CreateDefaultAnimator());
AnimationContainerElement* element = animator.get();
animator->set_disable_timer_for_test(true);
- TestLayerAnimationDelegate delegate;
+ DummyLayerAnimationDelegate delegate;
animator->SetDelegate(&delegate);
double start_opacity(0.0);
diff --git a/ui/gfx/compositor/layer_delegate.h b/ui/gfx/compositor/layer_delegate.h
index 973d12f..474689e 100644
--- a/ui/gfx/compositor/layer_delegate.h
+++ b/ui/gfx/compositor/layer_delegate.h
@@ -14,7 +14,7 @@ class Canvas;
namespace ui {
-class Animation;
+class LayerAnimationSequence;
// A delegate interface implemented by an object that renders to a Layer.
class COMPOSITOR_EXPORT LayerDelegate {
@@ -23,8 +23,8 @@ class COMPOSITOR_EXPORT LayerDelegate {
// clipped to the Layer's invalid rect.
virtual void OnPaintLayer(gfx::Canvas* canvas) = 0;
- // Called when |animation| ends.
- virtual void OnLayerAnimationEnded(const ui::Animation* animation) = 0;
+ // Called when |seq| ends.
+ virtual void OnLayerAnimationEnded(const LayerAnimationSequence* seq) = 0;
protected:
virtual ~LayerDelegate() {}
diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc
index a5e64feb..eb66d63 100644
--- a/ui/gfx/compositor/layer_unittest.cc
+++ b/ui/gfx/compositor/layer_unittest.cc
@@ -9,6 +9,7 @@
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/compositor_observer.h"
#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/compositor/layer_animation_sequence.h"
#include "ui/gfx/compositor/test_compositor.h"
#include "ui/gfx/compositor/test_compositor_host.h"
@@ -41,7 +42,8 @@ class ColoredLayer : public Layer, public LayerDelegate {
canvas->GetSkCanvas()->drawColor(color_);
}
- virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE {
+ virtual void OnLayerAnimationEnded(
+ const LayerAnimationSequence* animation) OVERRIDE {
}
private:
@@ -132,7 +134,8 @@ class TestLayerDelegate : public LayerDelegate {
contents.height());
color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size());
}
- virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE {
+ virtual void OnLayerAnimationEnded(
+ const LayerAnimationSequence* animation) OVERRIDE {
}
private:
@@ -160,7 +163,8 @@ class DrawTreeLayerDelegate : public LayerDelegate {
virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
painted_ = true;
}
- virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE {
+ virtual void OnLayerAnimationEnded(
+ const LayerAnimationSequence* animation) OVERRIDE {
}
bool painted_;
@@ -178,7 +182,8 @@ class NullLayerDelegate : public LayerDelegate {
// Overridden from LayerDelegate:
virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
}
- virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE {
+ virtual void OnLayerAnimationEnded(
+ const LayerAnimationSequence* animation) OVERRIDE {
}
DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate);
diff --git a/ui/gfx/compositor/test_layer_animation_delegate.cc b/ui/gfx/compositor/test_layer_animation_delegate.cc
deleted file mode 100644
index 5d87ae0..0000000
--- a/ui/gfx/compositor/test_layer_animation_delegate.cc
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/gfx/compositor/test_layer_animation_delegate.h"
-
-namespace ui {
-
-TestLayerAnimationDelegate::TestLayerAnimationDelegate() : opacity_(1.0f) {
-}
-
-TestLayerAnimationDelegate::~TestLayerAnimationDelegate() {
-}
-
-void TestLayerAnimationDelegate::SetBoundsFromAnimation(
- const gfx::Rect& bounds) {
- bounds_ = bounds;
-}
-
-void TestLayerAnimationDelegate::SetTransformFromAnimation(
- const Transform& transform) {
- transform_ = transform;
-}
-
-void TestLayerAnimationDelegate::SetOpacityFromAnimation(float opacity) {
- opacity_ = opacity;
-}
-
-void TestLayerAnimationDelegate::ScheduleDrawForAnimation() {
-}
-
-const gfx::Rect& TestLayerAnimationDelegate::GetBoundsForAnimation() const {
- return bounds_;
-}
-
-const Transform& TestLayerAnimationDelegate::GetTransformForAnimation() const {
- return transform_;
-}
-
-float TestLayerAnimationDelegate::GetOpacityForAnimation() const {
- return opacity_;
-}
-
-} // namespace ui