summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-31 20:45:16 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-31 20:45:16 +0000
commitbc3d2110f80449765e8eebeffa4777f58a0b543a (patch)
treeba7edf740c459421cfdce88e16160dfb9f4c1a27 /ash
parente137610304f8c72c439d2d1a7fd2f1a81efc2ef7 (diff)
downloadchromium_src-bc3d2110f80449765e8eebeffa4777f58a0b543a.zip
chromium_src-bc3d2110f80449765e8eebeffa4777f58a0b543a.tar.gz
chromium_src-bc3d2110f80449765e8eebeffa4777f58a0b543a.tar.bz2
Acquire all layers when hiding window gets destroyed.
Add duration to show/hide animation (lock screen has longer animation) Window can now specify in which visibility change phrase it wants to animate (login screen and lock screen should animate only when hiding) BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/9233044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119949 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/shell.cc1
-rw-r--r--ash/wm/visibility_controller.cc3
-rw-r--r--ash/wm/window_animations.cc99
-rw-r--r--ash/wm/window_animations.h22
4 files changed, 103 insertions, 22 deletions
diff --git a/ash/shell.cc b/ash/shell.cc
index c839d58..4ff7364 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -116,6 +116,7 @@ void CreateSpecialContainers(aura::Window::Windows* containers) {
lock_container->SetLayoutManager(new internal::BaseLayoutManager);
lock_container->set_stops_event_propagation(true);
lock_container->set_id(internal::kShellWindowId_LockScreenContainer);
+ SetChildWindowVisibilityChangesAnimated(lock_container);
containers->push_back(lock_container);
aura::Window* lock_modal_container = new aura::Window(NULL);
diff --git a/ash/wm/visibility_controller.cc b/ash/wm/visibility_controller.cc
index 8006ff3..2fe55b8 100644
--- a/ash/wm/visibility_controller.cc
+++ b/ash/wm/visibility_controller.cc
@@ -35,8 +35,7 @@ void VisibilityController::UpdateLayerVisibility(aura::Window* window,
bool animated = GetChildWindowVisibilityChangesAnimated(window->parent()) &&
window->type() != aura::client::WINDOW_TYPE_CONTROL &&
window->type() != aura::client::WINDOW_TYPE_UNKNOWN;
- if (animated)
- AnimateOnChildWindowVisibilityChanged(window, visible);
+ animated = animated && AnimateOnChildWindowVisibilityChanged(window, visible);
// When a window is made visible, we always make its layer visible
// immediately. When a window is hidden, the layer must be left visible and
diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc
index d644f2e..8b8c0b1 100644
--- a/ash/wm/window_animations.cc
+++ b/ash/wm/window_animations.cc
@@ -7,6 +7,8 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/stl_util.h"
+#include "base/time.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
@@ -17,6 +19,12 @@ namespace ash {
namespace internal {
const char kWindowVisibilityAnimationTypeKey[] =
"WindowVisibilityAnimationType";
+
+const char kWindowVisibilityAnimationDurationKey[] =
+ "WindowVisibilityAnimationDuration";
+
+const char kWindowVisibilityAnimationTransitionKey[] =
+ "WindowVisibilityAnimationTransition";
} // namespace internal
void SetWindowVisibilityAnimationType(aura::Window* window,
@@ -24,6 +32,27 @@ void SetWindowVisibilityAnimationType(aura::Window* window,
window->SetIntProperty(internal::kWindowVisibilityAnimationTypeKey, type);
}
+void SetWindowVisibilityAnimationTransition(
+ aura::Window* window,
+ WindowVisibilityAnimationTransition transition) {
+ window->SetIntProperty(internal::kWindowVisibilityAnimationTransitionKey,
+ transition);
+}
+
+void SetWindowVisibilityAnimationDuration(aura::Window* window,
+ const base::TimeDelta& duration) {
+ window->SetIntProperty(internal::kWindowVisibilityAnimationDurationKey,
+ static_cast<int>(duration.ToInternalValue()));
+}
+
+bool HasWindowVisibilityAnimationTransition(
+ aura::Window* window,
+ WindowVisibilityAnimationTransition transition) {
+ int prop = window->GetIntProperty(
+ internal::kWindowVisibilityAnimationTransitionKey);
+ return !prop || (prop & transition) != 0;
+}
+
namespace internal {
namespace {
@@ -67,7 +96,9 @@ class HidingWindowAnimationObserver : public ui::ImplicitAnimationObserver,
: window_(window) {
window_->AddObserver(this);
}
- virtual ~HidingWindowAnimationObserver() {}
+ virtual ~HidingWindowAnimationObserver() {
+ STLDeleteElements(&layers_);
+ }
private:
// Overridden from ui::ImplicitAnimationObserver:
@@ -84,15 +115,26 @@ class HidingWindowAnimationObserver : public ui::ImplicitAnimationObserver,
// Overridden from aura::WindowObserver:
virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
DCHECK_EQ(window, window_);
- layer_.reset(window_->AcquireLayer());
+ DCHECK(layers_.empty());
+ AcquireAllLayers(window_);
window_->RemoveObserver(this);
window_ = NULL;
}
- ui::Layer* layer() { return window_ ? window_->layer() : layer_.get(); }
+ void AcquireAllLayers(aura::Window* window) {
+ ui::Layer* layer = window->AcquireLayer();
+ DCHECK(layer);
+ layers_.push_back(layer);
+ for (aura::Window::Windows::const_iterator it = window->children().begin();
+ it != window->children().end();
+ ++it)
+ AcquireAllLayers(*it);
+ }
+
+ ui::Layer* layer() { return window_ ? window_->layer() : layers_[0]; }
aura::Window* window_;
- scoped_ptr<ui::Layer> layer_;
+ std::vector<ui::Layer*> layers_;
DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver);
};
@@ -109,6 +151,13 @@ void AnimateShowWindowCommon(aura::Window* window,
{
// Property sets within this scope will be implicitly animated.
ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
+ int duration =
+ window->GetIntProperty(internal::kWindowVisibilityAnimationDurationKey);
+ if (duration > 0) {
+ settings.SetTransitionDuration(
+ base::TimeDelta::FromInternalValue(duration));
+ }
+
window->layer()->SetTransform(end_transform);
window->layer()->SetOpacity(kWindowAnimation_ShowOpacity);
}
@@ -123,6 +172,12 @@ void AnimateHideWindowCommon(aura::Window* window,
// Property sets within this scope will be implicitly animated.
ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
settings.AddImplicitObserver(new HidingWindowAnimationObserver(window));
+ int duration =
+ window->GetIntProperty(internal::kWindowVisibilityAnimationDurationKey);
+ if (duration > 0) {
+ settings.SetTransitionDuration(
+ base::TimeDelta::FromInternalValue(duration));
+ }
window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
window->layer()->SetTransform(end_transform);
@@ -171,37 +226,43 @@ void AnimateHideWindow_Fade(aura::Window* window) {
AnimateHideWindowCommon(window, ui::Transform());
}
-void AnimateShowWindow(aura::Window* window) {
+bool AnimateShowWindow(aura::Window* window) {
+ if (!HasWindowVisibilityAnimationTransition(window, ANIMATE_SHOW))
+ return false;
+
switch (GetWindowVisibilityAnimationType(window)) {
case WINDOW_VISIBILITY_ANIMATION_TYPE_DROP:
AnimateShowWindow_Drop(window);
- break;
+ return true;
case WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL:
AnimateShowWindow_Vertical(window);
- break;
+ return true;
case WINDOW_VISIBILITY_ANIMATION_TYPE_FADE:
AnimateShowWindow_Fade(window);
- break;
+ return true;
default:
NOTREACHED();
- break;
+ return false;
}
}
-void AnimateHideWindow(aura::Window* window) {
+bool AnimateHideWindow(aura::Window* window) {
+ if (!HasWindowVisibilityAnimationTransition(window, ANIMATE_HIDE))
+ return false;
+
switch (GetWindowVisibilityAnimationType(window)) {
case WINDOW_VISIBILITY_ANIMATION_TYPE_DROP:
AnimateHideWindow_Drop(window);
- break;
+ return true;
case WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL:
AnimateHideWindow_Vertical(window);
- break;
+ return true;
case WINDOW_VISIBILITY_ANIMATION_TYPE_FADE:
AnimateHideWindow_Fade(window);
- break;
+ return true;
default:
NOTREACHED();
- break;
+ return false;
}
}
@@ -210,15 +271,15 @@ void AnimateHideWindow(aura::Window* window) {
////////////////////////////////////////////////////////////////////////////////
// WindowAnimation, public:
-void AnimateOnChildWindowVisibilityChanged(aura::Window* window, bool visible) {
+bool AnimateOnChildWindowVisibilityChanged(aura::Window* window, bool visible) {
if (window->GetIntProperty(aura::client::kAnimationsDisabledKey) == 1)
- return;
+ return false;
if (visible) {
- AnimateShowWindow(window);
+ return AnimateShowWindow(window);
} else {
// Don't start hiding the window again if it's already being hidden.
- if (window->layer()->GetTargetOpacity() != 0.0f)
- AnimateHideWindow(window);
+ return window->layer()->GetTargetOpacity() != 0.0f &&
+ AnimateHideWindow(window);
}
}
diff --git a/ash/wm/window_animations.h b/ash/wm/window_animations.h
index d6d4512..f15e484 100644
--- a/ash/wm/window_animations.h
+++ b/ash/wm/window_animations.h
@@ -7,6 +7,7 @@
#pragma once
#include "ash/ash_export.h"
+#include "base/time.h"
namespace aura {
class Window;
@@ -23,13 +24,32 @@ enum WindowVisibilityAnimationType {
WINDOW_VISIBILITY_ANIMATION_TYPE_FADE // Fades in/out.
};
+// Type of visibility change transition that a window should animate.
+// Default behavior is to animate both show and hide.
+enum WindowVisibilityAnimationTransition {
+ // 0 is used as default.
+ ANIMATE_SHOW = 0x1,
+ ANIMATE_HIDE = 0x2,
+ ANIMATE_BOTH = ANIMATE_SHOW | ANIMATE_HIDE,
+ ANIMATE_NONE = 0x4,
+};
+
void ASH_EXPORT SetWindowVisibilityAnimationType(
aura::Window* window,
WindowVisibilityAnimationType type);
+void ASH_EXPORT SetWindowVisibilityAnimationTransition(
+ aura::Window* window,
+ WindowVisibilityAnimationTransition transition);
+
+void ASH_EXPORT SetWindowVisibilityAnimationDuration(
+ aura::Window* window,
+ const base::TimeDelta& duration);
+
namespace internal {
-void AnimateOnChildWindowVisibilityChanged(aura::Window* window, bool visible);
+// Returns false if the |window| didn't animate.
+bool AnimateOnChildWindowVisibilityChanged(aura::Window* window, bool visible);
} // namespace internal
} // namespace ash