summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/ui/touch/frame/touch_browser_frame_view.cc68
-rw-r--r--chrome/browser/ui/touch/frame/touch_browser_frame_view.h10
-rw-r--r--chrome/chrome_browser.gypi4
-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/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
-rw-r--r--ui/gfx/compositor/test_layer_animation_delegate.h (renamed from ui/gfx/compositor/dummy_layer_animation_delegate.h)22
-rw-r--r--views/desktop/desktop_window_view.cc15
-rw-r--r--views/layer_property_setter.cc59
-rw-r--r--views/layer_property_setter.h51
-rw-r--r--views/view.cc36
-rw-r--r--views/view.h11
-rw-r--r--views/view_unittest.cc55
-rw-r--r--views/views.gyp5
-rw-r--r--views/widget/native_widget_views.cc8
42 files changed, 850 insertions, 708 deletions
diff --git a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
index e6bd798..ed4aea7 100644
--- a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
+++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
@@ -4,9 +4,45 @@
#include "chrome/browser/ui/touch/frame/touch_browser_frame_view.h"
+#include "chrome/browser/ui/touch/animation/screen_rotation_setter.h"
#include "views/controls/button/image_button.h"
#include "views/desktop/desktop_window_view.h"
-#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/transform.h"
+
+namespace {
+
+ui::Transform SideToTransform(sensors::ScreenOrientation::Side side,
+ const ui::Transform& old_transform,
+ const gfx::Size& size) {
+ gfx::Point origin;
+ gfx::Point bottom_right(size.width(), size.height());
+ old_transform.TransformPoint(origin);
+ old_transform.TransformPoint(bottom_right);
+ int original_width = abs(origin.x() - bottom_right.x());
+ int original_height = abs(origin.y() - bottom_right.y());
+ ui::Transform to_return;
+ switch (side) {
+ case sensors::ScreenOrientation::TOP: break;
+ case sensors::ScreenOrientation::RIGHT:
+ to_return.ConcatRotate(90);
+ to_return.ConcatTranslate(original_width, 0);
+ break;
+ case sensors::ScreenOrientation::LEFT:
+ to_return.ConcatRotate(-90);
+ to_return.ConcatTranslate(0, original_height);
+ break;
+ case sensors::ScreenOrientation::BOTTOM:
+ to_return.ConcatRotate(180);
+ to_return.ConcatTranslate(original_width, original_height);
+ break;
+ default:
+ to_return = old_transform;
+ break;
+ }
+ return to_return;
+}
+
+} // namespace
// static
const char TouchBrowserFrameView::kViewClassName[] =
@@ -19,9 +55,11 @@ TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
BrowserView* browser_view)
: OpaqueBrowserFrameView(frame, browser_view),
initialized_screen_rotation_(false) {
+ sensors::Provider::GetInstance()->AddListener(this);
}
TouchBrowserFrameView::~TouchBrowserFrameView() {
+ sensors::Provider::GetInstance()->RemoveListener(this);
}
std::string TouchBrowserFrameView::GetClassName() const {
@@ -47,3 +85,31 @@ bool TouchBrowserFrameView::HitTest(const gfx::Point& point) const {
return false;
}
+
+void TouchBrowserFrameView::OnScreenOrientationChanged(
+ const sensors::ScreenOrientation& change) {
+ // In views desktop mode, then the desktop_window_view will not be NULL and
+ // is the view to be rotated.
+ views::View* to_rotate =
+ views::desktop::DesktopWindowView::desktop_window_view;
+
+ if (!to_rotate) {
+ // Otherwise, rotate the widget's view.
+ views::Widget* widget = GetWidget();
+ to_rotate = widget->GetRootView();
+ }
+
+ if (!initialized_screen_rotation_) {
+ to_rotate->SetPaintToLayer(true);
+ to_rotate->SetLayerPropertySetter(
+ ScreenRotationSetterFactory::Create(to_rotate));
+ initialized_screen_rotation_ = true;
+ }
+
+ const ui::Transform& old_xform = to_rotate->GetTransform();
+ const ui::Transform& new_xform = SideToTransform(change.upward,
+ old_xform,
+ to_rotate->size());
+ if (old_xform != new_xform)
+ to_rotate->SetTransform(new_xform);
+}
diff --git a/chrome/browser/ui/touch/frame/touch_browser_frame_view.h b/chrome/browser/ui/touch/frame/touch_browser_frame_view.h
index eee15e2..5e4eefb 100644
--- a/chrome/browser/ui/touch/frame/touch_browser_frame_view.h
+++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.h
@@ -8,11 +8,15 @@
#include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
+#include "content/browser/sensors/sensors_provider.h"
+#include "content/common/sensors.h"
+
class BrowserFrame;
class BrowserView;
class TouchBrowserFrameView
- : public OpaqueBrowserFrameView {
+ : public OpaqueBrowserFrameView,
+ public sensors::Listener {
public:
// Internal class name.
static const char kViewClassName[];
@@ -21,6 +25,10 @@ class TouchBrowserFrameView
TouchBrowserFrameView(BrowserFrame* frame, BrowserView* browser_view);
virtual ~TouchBrowserFrameView();
+ // sensors::Listener implementation
+ virtual void OnScreenOrientationChanged(
+ const sensors::ScreenOrientation& change) OVERRIDE;
+
private:
// Overridden from views::View
virtual std::string GetClassName() const OVERRIDE;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 73c3540..a3f81a2 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -3227,6 +3227,10 @@
'browser/ui/toolbar/wrench_menu_model.cc',
'browser/ui/toolbar/wrench_menu_model.h',
'browser/ui/toolbar/wrench_menu_model_chromeos.cc',
+ 'browser/ui/touch/animation/screen_rotation.cc',
+ 'browser/ui/touch/animation/screen_rotation.h',
+ 'browser/ui/touch/animation/screen_rotation_setter.cc',
+ 'browser/ui/touch/animation/screen_rotation_setter.h',
'browser/ui/touch/frame/browser_non_client_frame_view_factory_touch.cc',
'browser/ui/touch/frame/touch_browser_frame_view.cc',
'browser/ui/touch/frame/touch_browser_frame_view.h',
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 34ca7efe..b042f21 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -45,8 +45,6 @@
'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 2c747d2..ae14d46 100644
--- a/ui/aura/desktop.cc
+++ b/ui/aura/desktop.cc
@@ -21,15 +21,11 @@
#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;
@@ -44,22 +40,6 @@ 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) {}
@@ -279,37 +259,31 @@ 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_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;
- }
+ (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;
}
+ layer()->SetAnimation(CreateDefaultAnimation());
+ SetTransform(transform);
+ count = (count + 1) % 4;
+ return true;
}
#endif
@@ -468,7 +442,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()->GetAnimator()->is_animating())
+ if (!layer()->has_animation())
OnHostResized(host_->GetSize());
}
@@ -557,8 +531,7 @@ Desktop* Desktop::GetDesktop() {
return this;
}
-void Desktop::OnLayerAnimationEnded(
- const ui::LayerAnimationSequence* animation) {
+void Desktop::OnLayerAnimationEnded(const ui::Animation* animation) {
OnHostResized(host_->GetSize());
}
diff --git a/ui/aura/desktop.h b/ui/aura/desktop.h
index 9ee5c1d..ec3521d 100644
--- a/ui/aura/desktop.h
+++ b/ui/aura/desktop.h
@@ -25,7 +25,6 @@ class Size;
}
namespace ui {
-class LayerAnimationSequence;
class Transform;
}
@@ -147,8 +146,7 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate,
virtual Desktop* GetDesktop() OVERRIDE;
// Overridden from ui::LayerDelegate:
- virtual void OnLayerAnimationEnded(
- const ui::LayerAnimationSequence* animation) OVERRIDE;
+ virtual void OnLayerAnimationEnded(const ui::Animation* 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
deleted file mode 100644
index d9e1fc8..0000000
--- a/ui/aura/screen_rotation.cc
+++ /dev/null
@@ -1,122 +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/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
deleted file mode 100644
index e947b83..0000000
--- a/ui/aura/screen_rotation.h
+++ /dev/null
@@ -1,54 +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_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 854eaf4..4a0fb35 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -20,6 +20,7 @@
#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 {
@@ -436,6 +437,15 @@ 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;
}
@@ -531,8 +541,7 @@ void Window::OnPaintLayer(gfx::Canvas* canvas) {
delegate_->OnPaint(canvas);
}
-void Window::OnLayerAnimationEnded(
- const ui::LayerAnimationSequence* animation) {
+void Window::OnLayerAnimationEnded(const ui::Animation* animation) {
}
} // namespace aura
diff --git a/ui/aura/window.h b/ui/aura/window.h
index b9ccf56..a809f5d 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -17,7 +17,6 @@
#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"
@@ -28,7 +27,6 @@ namespace ui {
class Animation;
class Compositor;
class Layer;
-class LayerAnimationSequence;
class Transform;
class ViewProp;
}
@@ -269,6 +267,10 @@ 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();
@@ -306,8 +308,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// Overridden from ui::LayerDelegate:
virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
- virtual void OnLayerAnimationEnded(
- const ui::LayerAnimationSequence* animation) OVERRIDE;
+ virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE;
int type_;
diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc
index fdb992f..cac3fe8 100644
--- a/ui/aura_shell/shell.cc
+++ b/ui/aura_shell/shell.cc
@@ -20,7 +20,6 @@
#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 f661e92..a9574da 100644
--- a/ui/aura_shell/workspace/workspace.cc
+++ b/ui/aura_shell/workspace/workspace.cc
@@ -9,7 +9,6 @@
#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.
@@ -212,13 +211,9 @@ void Workspace::MoveWindowTo(
else {
gfx::Rect bounds = window->GetTargetBounds();
bounds.set_origin(origin);
- if (animate) {
- ui::LayerAnimator::ScopedSettings settings(
- window->layer()->GetAnimator());
- window->SetBounds(bounds);
- } else {
- window->SetBounds(bounds);
- }
+ if (animate)
+ window->layer()->SetAnimation(aura::Window::CreateDefaultAnimation());
+ window->SetBounds(bounds);
}
}
diff --git a/ui/aura_shell/workspace/workspace_manager.cc b/ui/aura_shell/workspace/workspace_manager.cc
index c8904ea..4a6ecaa 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());
}
- ui::LayerAnimator::ScopedSettings settings(viewport_->layer()->GetAnimator());
+ viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation());
viewport_->layer()->SetTransform(transform);
}
@@ -247,8 +247,7 @@ void WorkspaceManager::UpdateViewport() {
if (active_workspace_) {
ui::Transform transform;
transform.SetTranslateX(-active_workspace_->bounds().x());
- ui::LayerAnimator::ScopedSettings settings(
- viewport_->layer()->GetAnimator());
+ viewport_->layer()->SetAnimation(aura::Window::CreateDefaultAnimation());
viewport_->SetTransform(transform);
}
}
diff --git a/ui/gfx/compositor/compositor.gyp b/ui/gfx/compositor/compositor.gyp
index 682ca6f..df3f7ac 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,6 +146,8 @@
'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
deleted file mode 100644
index ea026dc..0000000
--- a/ui/gfx/compositor/dummy_layer_animation_delegate.cc
+++ /dev/null
@@ -1,55 +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/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/layer.cc b/ui/gfx/compositor/layer.cc
index e9a9ed5..a075137 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_animator.h"
+#include "ui/gfx/compositor/layer_animation_manager.h"
#include "ui/gfx/interpolated_transform.h"
#include "ui/gfx/point3.h"
@@ -135,46 +135,49 @@ bool Layer::Contains(const Layer* other) const {
return false;
}
-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::SetAnimation(Animation* animation) {
+ if (animation) {
+ if (!animator_.get())
+ animator_.reset(new LayerAnimationManager(this));
+ animation->Start();
+ animator_->SetAnimation(animation);
+ } else {
+ animator_.reset();
+ }
}
void Layer::SetTransform(const ui::Transform& transform) {
- GetAnimator()->SetTransform(transform);
-}
-
-Transform Layer::GetTargetTransform() const {
- if (animator_.get() && animator_->is_animating())
- return animator_->GetTargetTransform();
- return transform_;
+ StopAnimatingIfNecessary(LayerAnimationManager::TRANSFORM);
+ if (animator_.get() && animator_->IsRunning()) {
+ animator_->AnimateTransform(transform);
+ return;
+ }
+ SetTransformImmediately(transform);
}
void Layer::SetBounds(const gfx::Rect& bounds) {
- GetAnimator()->SetBounds(bounds);
+ StopAnimatingIfNecessary(LayerAnimationManager::LOCATION);
+ if (animator_.get() && animator_->IsRunning() &&
+ bounds.size() == bounds_.size()) {
+ animator_->AnimateToPoint(bounds.origin());
+ return;
+ }
+ SetBoundsImmediately(bounds);
}
gfx::Rect Layer::GetTargetBounds() const {
- if (animator_.get() && animator_->is_animating())
- return animator_->GetTargetBounds();
+ if (animator_.get() && animator_->IsRunning())
+ return gfx::Rect(animator_->GetTargetPoint(), bounds_.size());
return bounds_;
}
void Layer::SetOpacity(float opacity) {
- GetAnimator()->SetOpacity(opacity);
-}
-
-float Layer::GetTargetOpacity() const {
- if (animator_.get() && animator_->is_animating())
- return animator_->GetTargetOpacity();
- return opacity_;
+ StopAnimatingIfNecessary(LayerAnimationManager::OPACITY);
+ if (animator_.get() && animator_->IsRunning()) {
+ animator_->AnimateOpacity(opacity);
+ return;
+ }
+ SetOpacityImmediately(opacity);
}
void Layer::SetVisible(bool visible) {
@@ -593,6 +596,29 @@ 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;
@@ -622,39 +648,18 @@ void Layer::SetOpacityImmediately(float opacity) {
#endif
}
-void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) {
+void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) {
SetBoundsImmediately(bounds);
}
-void Layer::SetTransformFromAnimation(const Transform& transform) {
+void Layer::SetTransformFromAnimator(const Transform& transform) {
SetTransformImmediately(transform);
}
-void Layer::SetOpacityFromAnimation(float opacity) {
+void Layer::SetOpacityFromAnimator(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 1bb51e9..792c194 100644
--- a/ui/gfx/compositor/layer.h
+++ b/ui/gfx/compositor/layer.h
@@ -18,6 +18,7 @@
#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"
@@ -25,9 +26,8 @@ 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,22 +84,21 @@ class COMPOSITOR_EXPORT Layer :
// Returns true if this Layer contains |other| somewhere in its children.
bool Contains(const Layer* other) const;
- // 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();
+ // 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 transform, relative to the parent.
- 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;
+ void SetTransform(const ui::Transform& transform);
+ const ui::Transform& transform() const { return transform_; }
// The bounds, relative to the parent.
void SetBounds(const gfx::Rect& bounds);
@@ -114,10 +113,6 @@ 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);
@@ -267,21 +262,22 @@ 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);
- // 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;
+ // LayerAnimatorDelegate overrides:
+ virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE;
+ virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE;
+ virtual void SetOpacityFromAnimator(float opacity) OVERRIDE;
#if defined(USE_WEBKIT_COMPOSITOR)
void CreateWebLayer();
@@ -321,7 +317,7 @@ class COMPOSITOR_EXPORT Layer :
LayerDelegate* delegate_;
- scoped_ptr<LayerAnimator> animator_;
+ scoped_ptr<LayerAnimationManager> 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 0f9ea4b..c6f4fa0 100644
--- a/ui/gfx/compositor/layer_animation_delegate.h
+++ b/ui/gfx/compositor/layer_animation_delegate.h
@@ -12,7 +12,7 @@
namespace ui {
-// Layer animations interact with the layers using this interface.
+// LayerAnimation interacts with the Layer 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 abff5f6..fb52bbb 100644
--- a/ui/gfx/compositor/layer_animation_element.cc
+++ b/ui/gfx/compositor/layer_animation_element.cc
@@ -7,6 +7,8 @@
#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 {
@@ -24,7 +26,6 @@ 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);
@@ -50,10 +51,6 @@ class TransformTransition : public LayerAnimationElement {
Tween::ValueBetween(t, start_, target_));
}
- virtual void OnGetTarget(TargetValue* target) const OVERRIDE {
- target->transform = target_;
- }
-
virtual void OnAbort() OVERRIDE {}
private:
@@ -89,10 +86,6 @@ 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:
@@ -126,10 +119,6 @@ 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:
@@ -148,11 +137,6 @@ class OpacityTransition : public LayerAnimationElement {
} // namespace
-// LayerAnimationElement::TargetValue ------------------------------------------
-
-LayerAnimationElement::TargetValue::TargetValue() : opacity(0.0f) {
-}
-
// LayerAnimationElement -------------------------------------------------------
LayerAnimationElement::LayerAnimationElement(
@@ -171,14 +155,9 @@ 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 d38bc42..12697b0 100644
--- a/ui/gfx/compositor/layer_animation_element.h
+++ b/ui/gfx/compositor/layer_animation_element.h
@@ -10,8 +10,10 @@
#include "base/time.h"
#include "ui/gfx/compositor/compositor_export.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/transform.h"
+
+namespace gfx {
+class Rect;
+} // gfx
namespace ui {
@@ -29,14 +31,6 @@ 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,
@@ -77,9 +71,6 @@ 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_; }
@@ -91,7 +82,6 @@ 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 483817c..efbc1ca 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) {
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate delegate;
Transform start_transform, target_transform, middle_transform;
start_transform.SetRotate(-90);
target_transform.SetRotate(90);
@@ -44,17 +44,13 @@ 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) {
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate delegate;
gfx::Rect start, target, middle;
start = target = middle = gfx::Rect(0, 0, 50, 50);
start.set_x(-90);
@@ -74,17 +70,13 @@ 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) {
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate delegate;
float start = 0.0;
float middle = 0.5;
float target = 1.0;
@@ -102,10 +94,6 @@ 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());
}
@@ -121,8 +109,8 @@ TEST(LayerAnimationElementTest, PauseElement) {
scoped_ptr<LayerAnimationElement> element(
LayerAnimationElement::CreatePauseElement(properties, delta));
- DummyLayerAnimationDelegate delegate;
- DummyLayerAnimationDelegate copy = delegate;
+ TestLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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
new file mode 100644
index 0000000..b900cd0
--- /dev/null
+++ b/ui/gfx/compositor/layer_animation_manager.cc
@@ -0,0 +1,189 @@
+// 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
new file mode 100644
index 0000000..b5b6540
--- /dev/null
+++ b/ui/gfx/compositor/layer_animation_manager.h
@@ -0,0 +1,129 @@
+// 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 8f34969..f0deca6 100644
--- a/ui/gfx/compositor/layer_animation_sequence.cc
+++ b/ui/gfx/compositor/layer_animation_sequence.cc
@@ -29,6 +29,7 @@ LayerAnimationSequence::~LayerAnimationSequence() {
void LayerAnimationSequence::Progress(base::TimeDelta elapsed,
LayerAnimationDelegate* delegate) {
+ TRACE_EVENT0("LayerAnimationSequence", "Progress");
if (elements_.size() == 0 || duration_ == base::TimeDelta())
return;
@@ -68,15 +69,6 @@ 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 4670587..87673d7 100644
--- a/ui/gfx/compositor/layer_animation_sequence.h
+++ b/ui/gfx/compositor/layer_animation_sequence.h
@@ -37,10 +37,6 @@ 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 a80a5f1..3b283a3f 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;
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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;
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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());
- DummyLayerAnimationDelegate copy = delegate;
+ TestLayerAnimationDelegate 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;
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate delegate;
float start_opacity = 0.0;
float target_opacity = 1.0;
base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
@@ -153,28 +153,6 @@ 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 8004c5c..e737377 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_animator_delegate.h"
+#include "ui/gfx/compositor/layer_animation_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(200);
+ base::TimeDelta::FromMilliseconds(250);
static const base::TimeDelta kTimerInterval =
base::TimeDelta::FromMilliseconds(10);
@@ -55,45 +55,30 @@ void LayerAnimator::SetTransform(const Transform& transform) {
if (transition_duration_ == base::TimeDelta())
delegate_->SetTransformFromAnimation(transform);
else
- StartAnimationElement(LayerAnimationElement::CreateTransformElement(
- transform, transition_duration_));
-}
-
-Transform LayerAnimator::GetTargetTransform() const {
- LayerAnimationElement::TargetValue target;
- GetTargetValue(&target);
- return target.transform;
+ StartAnimation(new LayerAnimationSequence(
+ LayerAnimationElement::CreateTransformElement(transform,
+ transition_duration_)));
}
void LayerAnimator::SetBounds(const gfx::Rect& bounds) {
if (transition_duration_ == base::TimeDelta())
delegate_->SetBoundsFromAnimation(bounds);
else
- StartAnimationElement(LayerAnimationElement::CreateBoundsElement(
- bounds, transition_duration_));
-}
-
-gfx::Rect LayerAnimator::GetTargetBounds() const {
- LayerAnimationElement::TargetValue target;
- GetTargetValue(&target);
- return target.bounds;
+ StartAnimation(new LayerAnimationSequence(
+ LayerAnimationElement::CreateBoundsElement(bounds,
+ transition_duration_)));
}
void LayerAnimator::SetOpacity(float opacity) {
if (transition_duration_ == base::TimeDelta())
delegate_->SetOpacityFromAnimation(opacity);
else
- StartAnimationElement(LayerAnimationElement::CreateOpacityElement(
- opacity, transition_duration_));
+ StartAnimation(new LayerAnimationSequence(
+ LayerAnimationElement::CreateOpacityElement(opacity,
+ transition_duration_)));
}
-float LayerAnimator::GetTargetOpacity() const {
- LayerAnimationElement::TargetValue target;
- GetTargetValue(&target);
- return target.opacity;
-}
-
-void LayerAnimator::SetDelegate(LayerAnimatorDelegate* delegate) {
+void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) {
DCHECK(delegate);
delegate_ = delegate;
}
@@ -122,7 +107,6 @@ void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) {
}
}
FinishAnyAnimationWithZeroDuration();
- UpdateAnimationState();
}
void LayerAnimator::ScheduleAnimation(LayerAnimationSequence* animation) {
@@ -132,7 +116,6 @@ void LayerAnimator::ScheduleAnimation(LayerAnimationSequence* animation) {
} else {
StartSequenceImmediately(animation);
}
- UpdateAnimationState();
}
void LayerAnimator::ScheduleTogether(
@@ -158,24 +141,6 @@ 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(
@@ -193,24 +158,10 @@ 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();
@@ -277,7 +228,6 @@ void LayerAnimator::RemoveAnimation(LayerAnimationSequence* sequence) {
void LayerAnimator::FinishAnimation(LayerAnimationSequence* sequence) {
sequence->Progress(sequence->duration(), delegate());
- delegate()->OnLayerAnimationEnded(sequence);
RemoveAnimation(sequence);
ProcessQueue();
UpdateAnimationState();
@@ -293,7 +243,6 @@ 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;
@@ -351,13 +300,11 @@ 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;
@@ -384,7 +331,6 @@ void LayerAnimator::ImmediatelySetNewTarget(LayerAnimationSequence* sequence) {
const bool abort = false;
RemoveAllAnimationsWithACommonProperty(sequence, abort);
sequence->Progress(sequence->duration(), delegate());
- delegate()->OnLayerAnimationEnded(sequence);
RemoveAnimation(sequence);
}
@@ -431,8 +377,10 @@ 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(),
@@ -492,12 +440,4 @@ 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 e6751ff..a51079c 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,19 +50,16 @@ 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(LayerAnimatorDelegate* delegate);
+ void SetDelegate(LayerAnimationDelegate* delegate);
// Sets the animation preemption strategy. This determines the behaviour if
// a property is set during an animation. The default is
@@ -85,14 +82,6 @@ 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(); }
@@ -112,30 +101,10 @@ 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:
- LayerAnimatorDelegate* delegate() { return delegate_; }
+ LayerAnimationDelegate* 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,
@@ -207,15 +176,11 @@ 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.
- LayerAnimatorDelegate* delegate_;
+ LayerAnimationDelegate* 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 173584f..85cbc79 100644
--- a/ui/gfx/compositor/layer_animator_delegate.h
+++ b/ui/gfx/compositor/layer_animator_delegate.h
@@ -6,23 +6,22 @@
#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"
-#include "ui/gfx/compositor/layer_animation_delegate.h"
+
+namespace gfx {
+class Rect;
+}
namespace ui {
-class LayerAnimationSequence;
+class Transform;
-// Layer animators interact with the layers using this interface.
-class COMPOSITOR_EXPORT LayerAnimatorDelegate : public LayerAnimationDelegate {
+// LayerAnimator modifies the Layer using this interface.
+class COMPOSITOR_EXPORT LayerAnimatorDelegate {
public:
- // 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.
+ virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) = 0;
+ virtual void SetTransformFromAnimator(const Transform& transform) = 0;
+ virtual void SetOpacityFromAnimator(float opacity) = 0;
protected:
virtual ~LayerAnimatorDelegate() {}
@@ -30,4 +29,4 @@ class COMPOSITOR_EXPORT LayerAnimatorDelegate : public LayerAnimationDelegate {
} // namespace ui
-#endif // UI_GFX_COMPOSITOR_LAYER_ANIMATOR_DELEGATE_H_
+#endif // UI_GFX_COMPOSITOR_LAYER_H_
diff --git a/ui/gfx/compositor/layer_animator_unittest.cc b/ui/gfx/compositor/layer_animator_unittest.cc
index e92d7c5..6eccb52 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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);
- DummyLayerAnimationDelegate delegate;
+ TestLayerAnimationDelegate 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 474689e..973d12f 100644
--- a/ui/gfx/compositor/layer_delegate.h
+++ b/ui/gfx/compositor/layer_delegate.h
@@ -14,7 +14,7 @@ class Canvas;
namespace ui {
-class LayerAnimationSequence;
+class Animation;
// 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 |seq| ends.
- virtual void OnLayerAnimationEnded(const LayerAnimationSequence* seq) = 0;
+ // Called when |animation| ends.
+ virtual void OnLayerAnimationEnded(const ui::Animation* animation) = 0;
protected:
virtual ~LayerDelegate() {}
diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc
index eb66d63..a5e64feb 100644
--- a/ui/gfx/compositor/layer_unittest.cc
+++ b/ui/gfx/compositor/layer_unittest.cc
@@ -9,7 +9,6 @@
#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"
@@ -42,8 +41,7 @@ class ColoredLayer : public Layer, public LayerDelegate {
canvas->GetSkCanvas()->drawColor(color_);
}
- virtual void OnLayerAnimationEnded(
- const LayerAnimationSequence* animation) OVERRIDE {
+ virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE {
}
private:
@@ -134,8 +132,7 @@ class TestLayerDelegate : public LayerDelegate {
contents.height());
color_index_ = (color_index_ + 1) % static_cast<int>(colors_.size());
}
- virtual void OnLayerAnimationEnded(
- const LayerAnimationSequence* animation) OVERRIDE {
+ virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE {
}
private:
@@ -163,8 +160,7 @@ class DrawTreeLayerDelegate : public LayerDelegate {
virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
painted_ = true;
}
- virtual void OnLayerAnimationEnded(
- const LayerAnimationSequence* animation) OVERRIDE {
+ virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE {
}
bool painted_;
@@ -182,8 +178,7 @@ class NullLayerDelegate : public LayerDelegate {
// Overridden from LayerDelegate:
virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
}
- virtual void OnLayerAnimationEnded(
- const LayerAnimationSequence* animation) OVERRIDE {
+ virtual void OnLayerAnimationEnded(const ui::Animation* 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
new file mode 100644
index 0000000..5d87ae0
--- /dev/null
+++ b/ui/gfx/compositor/test_layer_animation_delegate.cc
@@ -0,0 +1,44 @@
+// 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
diff --git a/ui/gfx/compositor/dummy_layer_animation_delegate.h b/ui/gfx/compositor/test_layer_animation_delegate.h
index 69b6435..046e25c 100644
--- a/ui/gfx/compositor/dummy_layer_animation_delegate.h
+++ b/ui/gfx/compositor/test_layer_animation_delegate.h
@@ -2,26 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef UI_GFX_COMPOSITOR_DUMMY_LAYER_ANIMATION_DELEGATE_H_
-#define UI_GFX_COMPOSITOR_DUMMY_LAYER_ANIMATION_DELEGATE_H_
+#ifndef UI_GFX_COMPOSITOR_TEST_LAYER_ANIMATION_DELEGATE_H_
+#define UI_GFX_COMPOSITOR_TEST_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/compositor_export.h"
-#include "ui/gfx/compositor/layer_animator_delegate.h"
+#include "ui/gfx/compositor/layer_animation_delegate.h"
namespace ui {
-class LayerAnimationSequence;
-
-class COMPOSITOR_EXPORT DummyLayerAnimationDelegate
- : public LayerAnimatorDelegate {
+class TestLayerAnimationDelegate : public LayerAnimationDelegate {
public:
- DummyLayerAnimationDelegate();
- DummyLayerAnimationDelegate(const LayerAnimationDelegate& other);
- virtual ~DummyLayerAnimationDelegate();
+ TestLayerAnimationDelegate();
+ virtual ~TestLayerAnimationDelegate();
// Implementation of LayerAnimationDelegate
virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE;
@@ -32,9 +27,6 @@ class COMPOSITOR_EXPORT DummyLayerAnimationDelegate
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_;
@@ -45,4 +37,4 @@ class COMPOSITOR_EXPORT DummyLayerAnimationDelegate
} // namespace ui
-#endif // UI_GFX_COMPOSITOR_DUMMY_LAYER_ANIMATION_DELEGATE_H_
+#endif // UI_GFX_COMPOSITOR_TEST_LAYER_ANIMATION_DELEGATE_H_
diff --git a/views/desktop/desktop_window_view.cc b/views/desktop/desktop_window_view.cc
index 65d4801..24f0249 100644
--- a/views/desktop/desktop_window_view.cc
+++ b/views/desktop/desktop_window_view.cc
@@ -7,10 +7,9 @@
#include "base/utf_string_conversions.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/transform.h"
-#include "ui/gfx/compositor/layer.h"
-#include "ui/gfx/compositor/layer_animator.h"
#include "views/desktop/desktop_background.h"
#include "views/desktop/desktop_window_manager.h"
+#include "views/layer_property_setter.h"
#include "views/widget/native_widget_view.h"
#include "views/widget/native_widget_views.h"
#include "views/widget/widget.h"
@@ -161,20 +160,12 @@ void DesktopWindowView::CreateTestWindow(const string16& title,
initial_bounds);
window->Show();
- NativeWidgetViews* native_widget_views =
- static_cast<NativeWidgetViews*>(window->native_widget());
-
if (rotate) {
ui::Transform transform;
transform.SetRotate(90.0f);
transform.SetTranslateX(window->GetWindowScreenBounds().width());
- native_widget_views->GetView()->SetTransform(transform);
- }
-
- native_widget_views->GetView()->SetPaintToLayer(true);
- if (native_widget_views->GetView()->layer()) {
- native_widget_views->GetView()->layer()->SetAnimator(
- ui::LayerAnimator::CreateImplicitAnimator());
+ static_cast<NativeWidgetViews*>(window->native_widget())->GetView()->
+ SetTransform(transform);
}
}
diff --git a/views/layer_property_setter.cc b/views/layer_property_setter.cc
new file mode 100644
index 0000000..26f203f
--- /dev/null
+++ b/views/layer_property_setter.cc
@@ -0,0 +1,59 @@
+// 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 "views/layer_property_setter.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "ui/gfx/compositor/compositor.h"
+#include "ui/gfx/compositor/layer.h"
+
+namespace views {
+
+namespace {
+
+// DefaultSetter ---------------------------------------------------------------
+
+class DefaultSetter : public LayerPropertySetter {
+ public:
+ DefaultSetter();
+
+ // LayerPropertySetter:
+ virtual void Installed(ui::Layer* layer) OVERRIDE;
+ virtual void Uninstalled(ui::Layer* layer) OVERRIDE;
+ virtual void SetTransform(ui::Layer* layer,
+ const ui::Transform& transform) OVERRIDE;
+ virtual void SetBounds(ui::Layer* layer, const gfx::Rect& bounds) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DefaultSetter);
+};
+
+DefaultSetter::DefaultSetter() {
+}
+
+void DefaultSetter::Installed(ui::Layer* layer) {
+}
+
+void DefaultSetter::Uninstalled(ui::Layer* layer) {
+}
+
+void DefaultSetter::SetTransform(ui::Layer* layer,
+ const ui::Transform& transform) {
+ layer->SetTransform(transform);
+}
+
+void DefaultSetter::SetBounds(ui::Layer* layer, const gfx::Rect& bounds) {
+ layer->SetBounds(bounds);
+}
+
+} // namespace
+
+// LayerPropertySetter ---------------------------------------------------------
+
+// static
+LayerPropertySetter* LayerPropertySetter::CreateDefaultSetter() {
+ return new DefaultSetter;
+}
+
+} // namespace views
diff --git a/views/layer_property_setter.h b/views/layer_property_setter.h
new file mode 100644
index 0000000..9db167d
--- /dev/null
+++ b/views/layer_property_setter.h
@@ -0,0 +1,51 @@
+// 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_PROPERTY_SETTER_H_
+#define UI_GFX_COMPOSITOR_LAYER_PROPERTY_SETTER_H_
+#pragma once
+
+#include "views/views_export.h"
+
+namespace gfx {
+class Rect;
+}
+
+namespace ui {
+class Layer;
+class Transform;
+}
+
+namespace views {
+
+// When a property of layer needs to be changed it is set by way of
+// LayerPropertySetter. This enables LayerPropertySetter to animate property
+// changes.
+class VIEWS_EXPORT LayerPropertySetter {
+ public:
+ // Creates a LayerPropertySetter that immediately sets the values on the
+ // layer. Ownership returns to caller.
+ static LayerPropertySetter* CreateDefaultSetter();
+
+ virtual ~LayerPropertySetter() {}
+
+ // Invoked when the LayerPropertySetter is to be used for a particular Layer.
+ // This is invoked whenever a new Layer is created. A LayerPropertySetter is
+ // only associated with one Layer at a time.
+ virtual void Installed(ui::Layer* layer) = 0;
+
+ // Invoked when the Layer is destroyed.
+ virtual void Uninstalled(ui::Layer* layer) = 0;
+
+ // Sets the transform on the Layer.
+ virtual void SetTransform(ui::Layer* layer,
+ const ui::Transform& transform) = 0;
+
+ // Sets the bounds of the layer.
+ virtual void SetBounds(ui::Layer* layer, const gfx::Rect& bounds) = 0;
+};
+
+} // namespace views
+
+#endif // UI_GFX_COMPOSITOR_LAYER_PROPERTY_SETTER_H_
diff --git a/views/view.cc b/views/view.cc
index d9b744a8..060eb15 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -18,7 +18,6 @@
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
-#include "ui/gfx/compositor/layer_animator.h"
#include "ui/gfx/interpolated_transform.h"
#include "ui/gfx/path.h"
#include "ui/gfx/point3.h"
@@ -26,6 +25,7 @@
#include "views/background.h"
#include "views/context_menu_controller.h"
#include "views/drag_controller.h"
+#include "views/layer_property_setter.h"
#include "views/layout/layout_manager.h"
#include "views/views_delegate.h"
#include "views/widget/native_widget_private.h"
@@ -424,7 +424,7 @@ const ui::Transform& View::GetTransform() const {
void View::SetTransform(const ui::Transform& transform) {
if (!transform.HasChange()) {
if (layer()) {
- layer()->SetTransform(transform);
+ layer_property_setter_->SetTransform(layer(), transform);
if (!paint_to_layer_)
DestroyLayer();
} else {
@@ -433,7 +433,7 @@ void View::SetTransform(const ui::Transform& transform) {
} else {
if (!layer())
CreateLayer();
- layer()->SetTransform(transform);
+ layer_property_setter_->SetTransform(layer(), transform);
layer()->ScheduleDraw();
}
}
@@ -447,6 +447,20 @@ void View::SetPaintToLayer(bool paint_to_layer) {
}
}
+void View::SetLayerPropertySetter(LayerPropertySetter* setter) {
+ DCHECK(layer());
+ LayerPropertySetter* old_setter = layer_property_setter_.get();
+ if (!layer() || (old_setter && old_setter == setter))
+ return;
+ if (!setter)
+ setter = LayerPropertySetter::CreateDefaultSetter();
+
+ if (old_setter)
+ old_setter->Uninstalled(layer());
+ layer_property_setter_.reset(setter);
+ layer_property_setter_->Installed(layer());
+}
+
// RTL positioning -------------------------------------------------------------
gfx::Rect View::GetMirroredBounds() const {
@@ -1143,7 +1157,8 @@ void View::UpdateChildLayerVisibility(bool ancestor_visible) {
void View::UpdateChildLayerBounds(const gfx::Point& offset) {
if (layer()) {
- layer()->SetBounds(gfx::Rect(offset.x(), offset.y(), width(), height()));
+ layer_property_setter_->SetBounds(layer(), gfx::Rect(offset.x(), offset.y(),
+ width(), height()));
} else {
for (int i = 0, count = child_count(); i < count; ++i) {
gfx::Point new_offset(offset.x() + child_at(i)->x(),
@@ -1159,7 +1174,7 @@ void View::OnPaintLayer(gfx::Canvas* canvas) {
PaintCommon(canvas);
}
-void View::OnLayerAnimationEnded(const ui::LayerAnimationSequence* animation) {
+void View::OnLayerAnimationEnded(const ui::Animation* animation) {
}
void View::ReorderLayers() {
@@ -1584,9 +1599,9 @@ void View::BoundsChanged(const gfx::Rect& previous_bounds) {
gfx::Point offset;
parent_->CalculateOffsetToAncestorWithLayer(&offset, NULL);
offset.Offset(x(), y());
- layer()->SetBounds(gfx::Rect(offset, size()));
+ layer_property_setter_->SetBounds(layer(), gfx::Rect(offset, size()));
} else {
- layer()->SetBounds(bounds_);
+ layer_property_setter_->SetBounds(layer(), bounds_);
}
// TODO(beng): this seems redundant with the SchedulePaint at the top of
// this function. explore collapsing.
@@ -1770,6 +1785,10 @@ void View::CreateLayer() {
layer_.reset(new ui::Layer(NULL));
layer_->set_delegate(this);
+ if (layer_property_setter_.get())
+ layer_property_setter_->Installed(layer());
+ else
+ SetLayerPropertySetter(NULL);
UpdateParentLayers();
UpdateLayerVisibility();
@@ -1840,6 +1859,9 @@ void View::DestroyLayer() {
new_parent->Add(children[i]);
}
+ if (layer_property_setter_.get())
+ layer_property_setter_->Uninstalled(layer());
+
layer_.reset();
if (new_parent)
diff --git a/views/view.h b/views/view.h
index 945e381..d86c805 100644
--- a/views/view.h
+++ b/views/view.h
@@ -36,7 +36,6 @@ namespace ui {
struct AccessibleViewState;
class Compositor;
class Layer;
-class LayerAnimationSequence;
class Texture;
class ThemeProvider;
class Transform;
@@ -56,6 +55,7 @@ class DragController;
class FocusManager;
class FocusTraversable;
class InputMethod;
+class LayerPropertySetter;
class LayoutManager;
class ScrollView;
class TextInputClient;
@@ -286,6 +286,11 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// Compositor.
void SetPaintToLayer(bool paint_to_layer);
+ // Sets the LayerPropertySetter for this view. A value of NULL resets the
+ // LayerPropertySetter to the default (immediate). Can only be called on a
+ // View that has a layer().
+ void SetLayerPropertySetter(LayerPropertySetter* setter);
+
const ui::Layer* layer() const { return layer_.get(); }
ui::Layer* layer() { return layer_.get(); }
@@ -985,8 +990,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// Overridden from ui::LayerDelegate:
virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
- virtual void OnLayerAnimationEnded(
- const ui::LayerAnimationSequence* animation) OVERRIDE;
+ virtual void OnLayerAnimationEnded(const ui::Animation* animation) OVERRIDE;
// Finds the layer that this view paints to (it may belong to an ancestor
// view), then reorders the immediate children of that layer to match the
@@ -1396,6 +1400,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
bool paint_to_layer_;
scoped_ptr<ui::Layer> layer_;
+ scoped_ptr<LayerPropertySetter> layer_property_setter_;
// Accelerators --------------------------------------------------------------
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index a9f7859..55a20f0 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -15,7 +15,6 @@
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
-#include "ui/gfx/compositor/layer_animator.h"
#include "ui/gfx/compositor/test_compositor.h"
#include "ui/gfx/compositor/test_texture.h"
#include "ui/gfx/path.h"
@@ -29,6 +28,7 @@
#include "views/events/event.h"
#include "views/focus/accelerator_handler.h"
#include "views/focus/view_storage.h"
+#include "views/layer_property_setter.h"
#include "views/test/views_test_base.h"
#include "views/touchui/gesture_manager.h"
#include "views/view.h"
@@ -2444,27 +2444,44 @@ TEST_F(ViewTest, GetViewByID) {
namespace {
-// Test implementation of LayerAnimator.
-class TestLayerAnimator : public ui::LayerAnimator {
+// Test implementation of LayerPropertySetter;
+class TestLayerPropertySetter : public LayerPropertySetter {
public:
- TestLayerAnimator();
+ TestLayerPropertySetter();
+ bool installed() const { return installed_; }
const gfx::Rect& last_bounds() const { return last_bounds_; }
- // LayerAnimator.
- virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
+ // LayerPropertySetter:
+ virtual void Installed(ui::Layer* layer) OVERRIDE;
+ virtual void Uninstalled(ui::Layer* layer) OVERRIDE;
+ virtual void SetTransform(ui::Layer* layer,
+ const ui::Transform& transform) OVERRIDE;
+ virtual void SetBounds(ui::Layer* layer, const gfx::Rect& bounds) OVERRIDE;
private:
+ bool installed_;
gfx::Rect last_bounds_;
- DISALLOW_COPY_AND_ASSIGN(TestLayerAnimator);
+ DISALLOW_COPY_AND_ASSIGN(TestLayerPropertySetter);
};
-TestLayerAnimator::TestLayerAnimator()
- : ui::LayerAnimator(base::TimeDelta::FromMilliseconds(0)) {
+TestLayerPropertySetter::TestLayerPropertySetter() : installed_(false) {}
+
+void TestLayerPropertySetter::Installed(ui::Layer* layer) {
+ installed_ = true;
+}
+
+void TestLayerPropertySetter::Uninstalled(ui::Layer* layer) {
+ installed_ = false;
+}
+
+void TestLayerPropertySetter::SetTransform(ui::Layer* layer,
+ const ui::Transform& transform) {
}
-void TestLayerAnimator::SetBounds(const gfx::Rect& bounds) {
+void TestLayerPropertySetter::SetBounds(ui::Layer* layer,
+ const gfx::Rect& bounds) {
last_bounds_ = bounds;
}
@@ -2659,22 +2676,28 @@ TEST_F(ViewLayerTest, NestedLayerToggling) {
EXPECT_EQ(v1->layer(), v3->layer()->parent());
}
-TEST_F(ViewLayerTest, LayerAnimator) {
+TEST_F(ViewLayerTest, LayerPropertySetter) {
View* content_view = new View;
widget()->SetContentsView(content_view);
View* v1 = new View;
content_view->AddChildView(v1);
v1->SetPaintToLayer(true);
- EXPECT_TRUE(v1->layer() != NULL);
+ TestLayerPropertySetter* setter = new TestLayerPropertySetter;
+ v1->SetLayerPropertySetter(setter);
+ EXPECT_TRUE(setter->installed());
+
+ // Turn off the layer, which should trigger uninstall.
+ v1->SetPaintToLayer(false);
+ EXPECT_FALSE(setter->installed());
- TestLayerAnimator* animator = new TestLayerAnimator();
- v1->layer()->SetAnimator(animator);
+ v1->SetPaintToLayer(true);
+ EXPECT_TRUE(setter->installed());
gfx::Rect bounds(1, 2, 3, 4);
v1->SetBoundsRect(bounds);
- EXPECT_EQ(bounds, animator->last_bounds());
- // TestLayerAnimator doesn't update the layer.
+ EXPECT_EQ(bounds, setter->last_bounds());
+ // TestLayerPropertySetter doesn't update the layer.
EXPECT_NE(bounds, v1->layer()->bounds());
}
diff --git a/views/views.gyp b/views/views.gyp
index 650b83e..57e9c0b 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -301,6 +301,8 @@
'ime/text_input_client.h',
'ime/text_input_type_tracker.h',
'ime/text_input_type_tracker.cc',
+ 'layer_property_setter.cc',
+ 'layer_property_setter.h',
'layout/box_layout.cc',
'layout/box_layout.h',
'layout/fill_layout.cc',
@@ -659,7 +661,7 @@
'sources/': [
['exclude', '../ui/aura/test/test_desktop_delegate.cc'],
['exclude', '../ui/aura/test/test_desktop_delegate.h'],
- ],
+ ],
}],
['OS!="mac"', {
'dependencies': [
@@ -852,7 +854,6 @@
'../ui/ui.gyp:ui',
'../ui/ui.gyp:ui_resources',
'../ui/ui.gyp:ui_resources_standard',
- '../ui/gfx/compositor/compositor.gyp:compositor',
'views',
'views_desktop_lib',
],
diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc
index 7d2632d..4ed77ca 100644
--- a/views/widget/native_widget_views.cc
+++ b/views/widget/native_widget_views.cc
@@ -6,8 +6,6 @@
#include "base/bind.h"
#include "ui/gfx/compositor/compositor.h"
-#include "ui/gfx/compositor/layer.h"
-#include "ui/gfx/compositor/layer_animator.h"
#include "views/view.h"
#include "views/views_delegate.h"
#include "views/widget/native_widget_view.h"
@@ -464,9 +462,6 @@ void NativeWidgetViews::Maximize() {
}
void NativeWidgetViews::Minimize() {
- if (view_->layer() && view_->layer()->GetAnimator()->is_animating())
- return;
-
gfx::Rect view_bounds = view_->bounds();
gfx::Rect parent_bounds = view_->parent()->bounds();
@@ -508,9 +503,6 @@ bool NativeWidgetViews::IsMinimized() const {
}
void NativeWidgetViews::Restore() {
- if (view_->layer() && view_->layer()->GetAnimator()->is_animating())
- return;
-
window_state_ = ui::SHOW_STATE_NORMAL;
view_->SetBoundsRect(restored_bounds_);
view_->SetTransform(restored_transform_);