diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 21:14:38 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 21:14:38 +0000 |
commit | 4a26b3967ba6ae7feed5f9889bed7cad51b885a0 (patch) | |
tree | 9a8ad09b94aa46e79c1af18d2e897432dd0507b0 | |
parent | fbdafd7422d158458b48308f0552f4f548712adc (diff) | |
download | chromium_src-4a26b3967ba6ae7feed5f9889bed7cad51b885a0.zip chromium_src-4a26b3967ba6ae7feed5f9889bed7cad51b885a0.tar.gz chromium_src-4a26b3967ba6ae7feed5f9889bed7cad51b885a0.tar.bz2 |
Adds a basic animation for window minimization.
Bonus points to sadrul if he can get this to rotate down into the launcher item.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9701051
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126994 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/wm/window_animations.cc | 52 | ||||
-rw-r--r-- | ash/wm/window_animations.h | 2 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_layout_manager.cc | 15 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_manager.cc | 1 |
4 files changed, 66 insertions, 4 deletions
diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc index 77e31ad..f2269eb 100644 --- a/ash/wm/window_animations.cc +++ b/ash/wm/window_animations.cc @@ -5,6 +5,8 @@ #include "ash/wm/window_animations.h" #include "ash/ash_switches.h" +#include "ash/launcher/launcher.h" +#include "ash/shell.h" #include "base/command_line.h" #include "base/compiler_specific.h" #include "base/logging.h" @@ -18,6 +20,7 @@ #include "ui/gfx/compositor/layer_animation_observer.h" #include "ui/gfx/compositor/layer_animator.h" #include "ui/gfx/compositor/scoped_layer_animation_settings.h" +#include "ui/gfx/screen.h" DECLARE_WINDOW_PROPERTY_TYPE(int) DECLARE_WINDOW_PROPERTY_TYPE(ash::WindowVisibilityAnimationType) @@ -69,6 +72,7 @@ const float kWindowAnimation_HideOpacity = 0.f; const float kWindowAnimation_ShowOpacity = 1.f; const float kWindowAnimation_TranslateFactor = -0.025f; const float kWindowAnimation_ScaleFactor = 1.05f; +const float kWindowAnimation_MinimizeRotate = -90.f; const float kWindowAnimation_Vertical_TranslateY = 15.f; @@ -328,6 +332,48 @@ void AnimateHideWindow_Workspace(aura::Window* window) { ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); } +gfx::Rect GetMinimizeRectForWindow(aura::Window* window) { + gfx::Rect target_bounds = Shell::GetInstance()->launcher()-> + GetScreenBoundsOfItemIconForWindow(window); + if (target_bounds.IsEmpty()) { + // Assume the launcher is overflowed, zoom off to the bottom right of the + // work area. + gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow(window); + target_bounds.SetRect(work_area.right(), work_area.bottom(), 0, 0); + } + return target_bounds; +} + +void AnimateShowWindow_Minimize(aura::Window* window) { + // Recalculate the transform at restore time since the launcher item may have + // moved while the window was minimized. + gfx::Rect target_bounds = GetMinimizeRectForWindow(window); + ui::Transform transform; + transform.ConcatScale( + static_cast<float>(target_bounds.height()) / window->bounds().width(), + static_cast<float>(target_bounds.width()) / window->bounds().height()); + transform.ConcatTranslate(target_bounds.x() - window->bounds().x(), + target_bounds.y() - window->bounds().y()); + + AnimateShowWindowCommon(window, transform, ui::Transform()); + + // Now that the window has been restored, we need to clear its animation style + // to default so that normal animation applies. + SetWindowVisibilityAnimationType( + window, WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT); +} + +void AnimateHideWindow_Minimize(aura::Window* window) { + gfx::Rect target_bounds = GetMinimizeRectForWindow(window); + ui::Transform transform; + transform.ConcatScale( + static_cast<float>(target_bounds.height()) / window->bounds().width(), + static_cast<float>(target_bounds.width()) / window->bounds().height()); + transform.ConcatTranslate(target_bounds.x() - window->bounds().x(), + target_bounds.y() - window->bounds().y()); + AnimateHideWindowCommon(window, transform); +} + bool AnimateShowWindow(aura::Window* window) { if (!HasWindowVisibilityAnimationTransition(window, ANIMATE_SHOW)) return false; @@ -345,6 +391,9 @@ bool AnimateShowWindow(aura::Window* window) { case WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_SHOW: AnimateShowWindow_Workspace(window); return true; + case WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: + AnimateShowWindow_Minimize(window); + return true; default: NOTREACHED(); return false; @@ -368,6 +417,9 @@ bool AnimateHideWindow(aura::Window* window) { case WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE: AnimateHideWindow_Workspace(window); return true; + case WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: + AnimateHideWindow_Minimize(window); + return true; default: NOTREACHED(); return false; diff --git a/ash/wm/window_animations.h b/ash/wm/window_animations.h index 70ea4ff..8668d1f 100644 --- a/ash/wm/window_animations.h +++ b/ash/wm/window_animations.h @@ -26,6 +26,8 @@ enum WindowVisibilityAnimationType { WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_SHOW, // Windows are scaled and // fade in. WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE, // Inverse of SHOW. + WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE, // Window scale/rotates down + // to its launcher icon. }; // Type of visibility change transition that a window should animate. diff --git a/ash/wm/workspace/workspace_layout_manager.cc b/ash/wm/workspace/workspace_layout_manager.cc index 3c9caab..6773d52 100644 --- a/ash/wm/workspace/workspace_layout_manager.cc +++ b/ash/wm/workspace/workspace_layout_manager.cc @@ -6,6 +6,7 @@ #include "ash/screen_ash.h" #include "ash/wm/property_util.h" +#include "ash/wm/window_animations.h" #include "ash/wm/window_util.h" #include "ash/wm/workspace/workspace.h" #include "ash/wm/workspace/workspace_manager.h" @@ -111,19 +112,25 @@ void WorkspaceLayoutManager::OnWindowPropertyChanged(aura::Window* window, BaseLayoutManager::OnWindowPropertyChanged(window, key, old); if (key == aura::client::kShowStateKey && workspace_manager_->IsManagedWindow(window)) { + ui::WindowShowState last_show_state = static_cast<ui::WindowShowState>(old); if (wm::IsWindowMinimized(window)) { // Save the previous show state so that we can correctly restore it. - window->SetProperty(kRestoreShowStateKey, - static_cast<ui::WindowShowState>(old)); + window->SetProperty(kRestoreShowStateKey, last_show_state); workspace_manager_->RemoveWindow(window); + SetWindowVisibilityAnimationType( + window, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); + // Effectively hide the window. - window->layer()->SetVisible(false); + window->Hide(); // Activate another window. if (wm::IsActiveWindow(window)) wm::DeactivateWindow(window); return; } - if (window->TargetVisibility() && + // We can end up here if the window was minimized and we are transitioning + // to another state. In that case the window is hidden. + if ((window->TargetVisibility() || + (last_show_state == ui::SHOW_STATE_MINIMIZED)) && !workspace_manager_->IsManagingWindow(window)) { workspace_manager_->AddWindow(window); if (!window->layer()->visible()) { diff --git a/ash/wm/workspace/workspace_manager.cc b/ash/wm/workspace/workspace_manager.cc index bb74fe1..53fc2d6 100644 --- a/ash/wm/workspace/workspace_manager.cc +++ b/ash/wm/workspace/workspace_manager.cc @@ -260,6 +260,7 @@ void WorkspaceManager::SetWindowLayerVisibility( // Reset the animation type so it isn't used in a future hide/show. ash::SetWindowVisibilityAnimationType( windows[i], ash::WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT); + windows[i]->ClearProperty(aura::client::kAnimationsDisabledKey); } } } |