summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 04:52:03 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-18 04:52:03 +0000
commit872068906ee8a04b493d667ccfb37e3360fbf591 (patch)
treef8da7e179c7e490c4127d7c147b8010672f52597 /ash
parent52fde7fe645c204496961faa555b730fc56783a2 (diff)
downloadchromium_src-872068906ee8a04b493d667ccfb37e3360fbf591.zip
chromium_src-872068906ee8a04b493d667ccfb37e3360fbf591.tar.gz
chromium_src-872068906ee8a04b493d667ccfb37e3360fbf591.tar.bz2
Add a simple animation when showing/hiding windows.
http://crbug.com/110024 TEST=none Review URL: http://codereview.chromium.org/9167032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118057 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/ash.gyp2
-rw-r--r--ash/wm/stacking_controller.cc5
-rw-r--r--ash/wm/toplevel_layout_manager.cc7
-rw-r--r--ash/wm/window_animations.cc119
-rw-r--r--ash/wm/window_animations.h25
5 files changed, 157 insertions, 1 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index a911108..6cfd90f 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -144,6 +144,8 @@
'wm/toplevel_layout_manager.h',
'wm/toplevel_window_event_filter.cc',
'wm/toplevel_window_event_filter.h',
+ 'wm/window_animations.cc',
+ 'wm/window_animations.h',
'wm/window_cycle_controller.cc',
'wm/window_cycle_controller.h',
'wm/window_frame.cc',
diff --git a/ash/wm/stacking_controller.cc b/ash/wm/stacking_controller.cc
index 08a990b..3516822 100644
--- a/ash/wm/stacking_controller.cc
+++ b/ash/wm/stacking_controller.cc
@@ -48,6 +48,11 @@ aura::Window* StackingController::GetDefaultParent(aura::Window* window) {
switch (window->type()) {
case aura::client::WINDOW_TYPE_NORMAL:
case aura::client::WINDOW_TYPE_POPUP:
+ // TODO(beng): control windows with NULL parents should be parented to a
+ // unique, probably hidden, container. Adding here now for
+ // compatibility, since these windows were WINDOW_TYPE_POPUP
+ // until now.
+ case aura::client::WINDOW_TYPE_CONTROL:
if (IsSystemModal(window))
return GetModalContainer(window);
return always_on_top_controller_->GetContainer(window);
diff --git a/ash/wm/toplevel_layout_manager.cc b/ash/wm/toplevel_layout_manager.cc
index 83a8552..47b3c01 100644
--- a/ash/wm/toplevel_layout_manager.cc
+++ b/ash/wm/toplevel_layout_manager.cc
@@ -6,6 +6,7 @@
#include "ash/wm/property_util.h"
#include "ash/wm/shelf_layout_manager.h"
+#include "ash/wm/window_animations.h"
#include "ash/wm/window_util.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
@@ -77,7 +78,11 @@ void ToplevelLayoutManager::OnWillRemoveWindowFromLayout(
}
void ToplevelLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child,
- bool visibile) {
+ bool visible) {
+ if (child->type() == aura::client::WINDOW_TYPE_NORMAL ||
+ child->type() == aura::client::WINDOW_TYPE_POPUP) {
+ visible ? AnimateShowWindow(child) : AnimateHideWindow(child);
+ }
UpdateShelfVisibility();
UpdateStatusAreaVisibility();
}
diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc
new file mode 100644
index 0000000..228070e
--- /dev/null
+++ b/ash/wm/window_animations.cc
@@ -0,0 +1,119 @@
+// Copyright (c) 2012 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 "ash/wm/window_animations.h"
+
+#include "base/compiler_specific.h"
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_observer.h"
+#include "ui/gfx/compositor/layer_animation_observer.h"
+
+namespace ash {
+namespace internal {
+namespace {
+
+const float kWindowAnimation_HideOpacity = 0.0f;
+const float kWindowAnimation_ShowOpacity = 1.0f;
+const float kWindowAnimation_TranslateFactor = -0.025f;
+const float kWindowAnimation_ScaleFactor = 1.05f;
+
+// Observes a hide animation.
+// A window can be hidden for a variety of reasons. Sometimes, Hide() will be
+// called and life is simple. Sometimes, the window is actually bound to a
+// views::Widget and that Widget is closed, and life is a little more
+// complicated. When a Widget is closed the aura::Window* is actually not
+// destroyed immediately - it is actually just immediately hidden and then
+// destroyed when the stack unwinds. To handle this case, we start the hide
+// animation immediately when the window is hidden, then when the window is
+// subsequently destroyed this object acquires ownership of the window's layer,
+// so that it can continue animating it until the animation completes.
+// Regardless of whether or not the window is destroyed, this object deletes
+// itself when the animation completes.
+class HidingWindowAnimationObserver : public ui::ImplicitAnimationObserver,
+ public aura::WindowObserver {
+ public:
+ explicit HidingWindowAnimationObserver(aura::Window* window)
+ : window_(window) {
+ window_->AddObserver(this);
+ }
+ virtual ~HidingWindowAnimationObserver() {}
+
+ private:
+ // Overridden from ui::ImplicitAnimationObserver:
+ virtual void OnImplicitAnimationsCompleted() OVERRIDE {
+ // Restore the correct visibility value (overridden for the duration of the
+ // animation in AnimateHideWindow()).
+ layer()->SetVisible(false);
+ // Window may have been destroyed by this point.
+ if (window_)
+ window_->RemoveObserver(this);
+ MessageLoop::current()->DeleteSoon(FROM_HERE, this);
+ }
+
+ // Overridden from aura::WindowObserver:
+ virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
+ DCHECK_EQ(window, window_);
+ layer_.reset(window_->AcquireLayer());
+ window_->RemoveObserver(this);
+ window_ = NULL;
+ }
+
+ ui::Layer* layer() { return window_ ? window_->layer() : layer_.get(); }
+
+ aura::Window* window_;
+ scoped_ptr<ui::Layer> layer_;
+
+ DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver);
+};
+
+} // namespace
+
+////////////////////////////////////////////////////////////////////////////////
+// WindowAnimation, public:
+
+void AnimateShowWindow(aura::Window* window) {
+ // Set the start state pre-animation.
+ window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
+ ui::Transform transform;
+ transform.ConcatScale(kWindowAnimation_ScaleFactor,
+ kWindowAnimation_ScaleFactor);
+ transform.ConcatTranslate(
+ kWindowAnimation_TranslateFactor * window->bounds().width(),
+ kWindowAnimation_TranslateFactor * window->bounds().height());
+ window->layer()->SetTransform(transform);
+
+ {
+ // Property sets within this scope will be implicitly animated.
+ ui::LayerAnimator::ScopedSettings settings(window->layer()->GetAnimator());
+ window->layer()->SetTransform(ui::Transform());
+ window->layer()->SetOpacity(kWindowAnimation_ShowOpacity);
+ }
+}
+
+void AnimateHideWindow(aura::Window* window) {
+ // The window's layer was just hidden, but we need it to draw until it's fully
+ // transparent, so we show it again. This is undone once the animation is
+ // complete.
+ window->layer()->SetVisible(true);
+ {
+ // Property sets within this scope will be implicitly animated.
+ ui::LayerAnimator::ScopedSettings settings(window->layer()->GetAnimator());
+ settings.AddImplicitObserver(new HidingWindowAnimationObserver(window));
+
+ window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
+
+ ui::Transform transform;
+ transform.ConcatScale(kWindowAnimation_ScaleFactor,
+ kWindowAnimation_ScaleFactor);
+ transform.ConcatTranslate(
+ kWindowAnimation_TranslateFactor * window->bounds().width(),
+ kWindowAnimation_TranslateFactor * window->bounds().height());
+ window->layer()->SetTransform(transform);
+ }
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/wm/window_animations.h b/ash/wm/window_animations.h
new file mode 100644
index 0000000..146e1d8
--- /dev/null
+++ b/ash/wm/window_animations.h
@@ -0,0 +1,25 @@
+// Copyright (c) 2012 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 ASH_WM_WINDOW_ANIMATIONS_H_
+#define ASH_WM_WINDOW_ANIMATIONS_H_
+#pragma once
+
+namespace aura {
+class Window;
+}
+
+namespace ash {
+namespace internal {
+
+// Implements a variety of canned animations for window transitions.
+
+void AnimateShowWindow(aura::Window* window);
+void AnimateHideWindow(aura::Window* window);
+
+} // namespace internal
+} // namespace ash
+
+
+#endif // ASH_WM_WINDOW_ANIMATIONS_H_