From 226c729d9a7bd68d166a8b21328db674ced8d498 Mon Sep 17 00:00:00 2001 From: "sadrul@chromium.org" Date: Fri, 15 Aug 2014 02:52:05 +0000 Subject: compositor: Add a ClosureAnimationObserver to run a Closure at the end of the animation. ClosureAnimationObserver maintains its own lifetime, destroying itself after running the callback at the end of the animation. BUG=none R=ajuma@chromium.org, oshima@chromium.org, vollick@chromium.org Review URL: https://codereview.chromium.org/470693002 Cr-Commit-Position: refs/heads/master@{#289749} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289749 0039d316-1c4b-4281-b951-d872f2087c98 --- athena/athena.gyp | 2 -- athena/common/closure_animation_observer.cc | 22 ------------------ athena/common/closure_animation_observer.h | 32 -------------------------- athena/wm/overview_toolbar.cc | 4 ++-- athena/wm/split_view_controller.cc | 28 ++--------------------- athena/wm/title_drag_controller.cc | 4 ++-- athena/wm/window_overview_mode.cc | 4 ++-- ui/compositor/BUILD.gn | 2 ++ ui/compositor/closure_animation_observer.cc | 22 ++++++++++++++++++ ui/compositor/closure_animation_observer.h | 35 +++++++++++++++++++++++++++++ ui/compositor/compositor.gyp | 2 ++ 11 files changed, 69 insertions(+), 88 deletions(-) delete mode 100644 athena/common/closure_animation_observer.cc delete mode 100644 athena/common/closure_animation_observer.h create mode 100644 ui/compositor/closure_animation_observer.cc create mode 100644 ui/compositor/closure_animation_observer.h diff --git a/athena/athena.gyp b/athena/athena.gyp index eab29f9..e56502f 100644 --- a/athena/athena.gyp +++ b/athena/athena.gyp @@ -39,8 +39,6 @@ 'activity/public/activity_view_manager.h', 'activity/public/activity_view_model.h', 'athena_export.h', - 'common/closure_animation_observer.cc', - 'common/closure_animation_observer.h', 'common/container_priorities.h', 'common/fill_layout_manager.cc', 'common/fill_layout_manager.h', diff --git a/athena/common/closure_animation_observer.cc b/athena/common/closure_animation_observer.cc deleted file mode 100644 index 083aec0..0000000 --- a/athena/common/closure_animation_observer.cc +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2014 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 "athena/common/closure_animation_observer.h" - -namespace athena { - -ClosureAnimationObserver::ClosureAnimationObserver(const base::Closure& closure) - : closure_(closure) { - DCHECK(!closure_.is_null()); -} - -ClosureAnimationObserver::~ClosureAnimationObserver() { -} - -void ClosureAnimationObserver::OnImplicitAnimationsCompleted() { - closure_.Run(); - delete this; -} - -} // namespace athena diff --git a/athena/common/closure_animation_observer.h b/athena/common/closure_animation_observer.h deleted file mode 100644 index 50e0ec8..0000000 --- a/athena/common/closure_animation_observer.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2014 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 ATHENA_COMMON_CLOSURE_ANIMATION_OBSERVER_H_ -#define ATHENA_COMMON_CLOSURE_ANIMATION_OBSERVER_H_ - -#include "base/callback.h" -#include "base/macros.h" -#include "ui/compositor/layer_animation_observer.h" - -namespace athena { - -// Runs a callback at the end of the animation. This observe also destroys -// itself afterwards. -class ClosureAnimationObserver : public ui::ImplicitAnimationObserver { - public: - explicit ClosureAnimationObserver(const base::Closure& closure); - - private: - virtual ~ClosureAnimationObserver(); - - // ui::ImplicitAnimationObserver: - virtual void OnImplicitAnimationsCompleted() OVERRIDE; - - const base::Closure closure_; - - DISALLOW_COPY_AND_ASSIGN(ClosureAnimationObserver); -}; -} - -#endif // ATHENA_COMMON_CLOSURE_ANIMATION_OBSERVER_H_ diff --git a/athena/wm/overview_toolbar.cc b/athena/wm/overview_toolbar.cc index 5c7de40..4537a04 100644 --- a/athena/wm/overview_toolbar.cc +++ b/athena/wm/overview_toolbar.cc @@ -4,13 +4,13 @@ #include "athena/wm/overview_toolbar.h" -#include "athena/common/closure_animation_observer.h" #include "athena/resources/grit/athena_resources.h" #include "base/bind.h" #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" #include "ui/aura/window.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/compositor/closure_animation_observer.h" #include "ui/compositor/layer.h" #include "ui/compositor/layer_delegate.h" #include "ui/compositor/scoped_layer_animation_settings.h" @@ -43,7 +43,7 @@ class ActionButton : public ui::LayerDelegate { static void DestroyAfterFadeout(scoped_ptr button) { ui::Layer* layer = button->layer(); ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); - settings.AddObserver(new ClosureAnimationObserver( + settings.AddObserver(new ui::ClosureAnimationObserver( base::Bind(&ActionButton::DestroyImmediately, base::Passed(&button)))); layer->SetOpacity(0); } diff --git a/athena/wm/split_view_controller.cc b/athena/wm/split_view_controller.cc index cde4657..9e8984a 100644 --- a/athena/wm/split_view_controller.cc +++ b/athena/wm/split_view_controller.cc @@ -10,6 +10,7 @@ #include "athena/wm/public/window_manager.h" #include "base/bind.h" #include "ui/aura/window.h" +#include "ui/compositor/closure_animation_observer.h" #include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/events/event_handler.h" @@ -17,31 +18,6 @@ #include "ui/gfx/screen.h" namespace athena { -namespace { - -// An animation observer that runs a callback at the end of the animation, and -// destroys itself. -class CallbackAnimationObserver : public ui::ImplicitAnimationObserver { - public: - explicit CallbackAnimationObserver(const base::Closure& closure) - : closure_(closure) {} - - virtual ~CallbackAnimationObserver() {} - - private: - // Overridden from ui::ImplicitAnimationObserver: - virtual void OnImplicitAnimationsCompleted() OVERRIDE { - if (!closure_.is_null()) - closure_.Run(); - delete this; - } - - const base::Closure closure_; - - DISALLOW_COPY_AND_ASSIGN(CallbackAnimationObserver); -}; - -} // namespace SplitViewController::SplitViewController( aura::Window* container, @@ -143,7 +119,7 @@ void SplitViewController::SetWindowTransform(aura::Window* window, ui::ScopedLayerAnimationSettings settings(animator); settings.SetPreemptionStrategy( ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); - settings.AddObserver(new CallbackAnimationObserver( + settings.AddObserver(new ui::ClosureAnimationObserver( base::Bind(&SplitViewController::OnAnimationCompleted, weak_factory_.GetWeakPtr(), window))); diff --git a/athena/wm/title_drag_controller.cc b/athena/wm/title_drag_controller.cc index 597f50a..36bf8238 100644 --- a/athena/wm/title_drag_controller.cc +++ b/athena/wm/title_drag_controller.cc @@ -4,11 +4,11 @@ #include "athena/wm/title_drag_controller.h" -#include "athena/common/closure_animation_observer.h" #include "base/bind.h" #include "ui/aura/window.h" #include "ui/aura/window_delegate.h" #include "ui/base/hit_test.h" +#include "ui/compositor/closure_animation_observer.h" #include "ui/compositor/layer.h" #include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/wm/core/shadow.h" @@ -46,7 +46,7 @@ void TitleDragController::EndTransition(aura::Window* window, bool complete) { ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); settings.SetPreemptionStrategy( ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); - settings.AddObserver(new ClosureAnimationObserver( + settings.AddObserver(new ui::ClosureAnimationObserver( base::Bind(&TitleDragController::OnTransitionEnd, weak_ptr_.GetWeakPtr(), window, diff --git a/athena/wm/window_overview_mode.cc b/athena/wm/window_overview_mode.cc index b36ec11..d8e0597 100644 --- a/athena/wm/window_overview_mode.cc +++ b/athena/wm/window_overview_mode.cc @@ -8,7 +8,6 @@ #include #include -#include "athena/common/closure_animation_observer.h" #include "athena/wm/overview_toolbar.h" #include "athena/wm/public/window_list_provider.h" #include "base/bind.h" @@ -19,6 +18,7 @@ #include "ui/aura/window_property.h" #include "ui/aura/window_targeter.h" #include "ui/aura/window_tree_host.h" +#include "ui/compositor/closure_animation_observer.h" #include "ui/compositor/compositor.h" #include "ui/compositor/compositor_animation_observer.h" #include "ui/compositor/scoped_layer_animation_settings.h" @@ -367,7 +367,7 @@ class WindowOverviewModeImpl : public WindowOverviewMode, dragged_window_->layer()->GetAnimator()); settings.SetPreemptionStrategy( ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); - settings.AddObserver(new ClosureAnimationObserver( + settings.AddObserver(new ui::ClosureAnimationObserver( base::Bind(&base::DeletePointer, dragged_window_))); WindowOverviewState* dragged_state = diff --git a/ui/compositor/BUILD.gn b/ui/compositor/BUILD.gn index d3a2dff..59d5005 100644 --- a/ui/compositor/BUILD.gn +++ b/ui/compositor/BUILD.gn @@ -6,6 +6,8 @@ import("//build/config/ui.gni") component("compositor") { sources = [ + "closure_animation_observer.cc", + "closure_animation_observer.h", "compositor.cc", "compositor.h", "compositor_animation_observer.h", diff --git a/ui/compositor/closure_animation_observer.cc b/ui/compositor/closure_animation_observer.cc new file mode 100644 index 0000000..2ac7f91 --- /dev/null +++ b/ui/compositor/closure_animation_observer.cc @@ -0,0 +1,22 @@ +// Copyright 2014 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/compositor/closure_animation_observer.h" + +namespace ui { + +ClosureAnimationObserver::ClosureAnimationObserver(const base::Closure& closure) + : closure_(closure) { + DCHECK(!closure_.is_null()); +} + +ClosureAnimationObserver::~ClosureAnimationObserver() { +} + +void ClosureAnimationObserver::OnImplicitAnimationsCompleted() { + closure_.Run(); + delete this; +} + +} // namespace ui diff --git a/ui/compositor/closure_animation_observer.h b/ui/compositor/closure_animation_observer.h new file mode 100644 index 0000000..320ea2b1 --- /dev/null +++ b/ui/compositor/closure_animation_observer.h @@ -0,0 +1,35 @@ +// Copyright 2014 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_COMPOSITOR_CLOSURE_ANIMATION_OBSERVER_H_ +#define UI_COMPOSITOR_CLOSURE_ANIMATION_OBSERVER_H_ + +#include "base/callback.h" +#include "base/macros.h" +#include "ui/compositor/compositor_export.h" +#include "ui/compositor/layer_animation_observer.h" + +namespace ui { + +// Runs a callback at the end of the animation. This observe also destroys +// itself afterwards. +class COMPOSITOR_EXPORT ClosureAnimationObserver + : public ImplicitAnimationObserver { + public: + explicit ClosureAnimationObserver(const base::Closure& closure); + + private: + virtual ~ClosureAnimationObserver(); + + // ImplicitAnimationObserver: + virtual void OnImplicitAnimationsCompleted() OVERRIDE; + + const base::Closure closure_; + + DISALLOW_COPY_AND_ASSIGN(ClosureAnimationObserver); +}; + +} // namespace ui + +#endif // UI_COMPOSITOR_CLOSURE_ANIMATION_OBSERVER_H_ diff --git a/ui/compositor/compositor.gyp b/ui/compositor/compositor.gyp index b29b87b..0471140 100644 --- a/ui/compositor/compositor.gyp +++ b/ui/compositor/compositor.gyp @@ -24,6 +24,8 @@ 'COMPOSITOR_IMPLEMENTATION', ], 'sources': [ + 'closure_animation_observer.cc', + 'closure_animation_observer.h', 'compositor.cc', 'compositor.h', 'compositor_animation_observer.h', -- cgit v1.1