Commit 54d566e6 authored by Eliot Courtney's avatar Eliot Courtney Committed by Commit Bot

Apply slide out animation type to PIP window on show.

    applied both times.

Bug: 908337
Test: Open and close a Chrome PIP window twice. Slide out animation is
Change-Id: I617e008070f733184d635486ea3c14b260838c8b
Reviewed-on: https://chromium-review.googlesource.com/c/1350026
Commit-Queue: Eliot Courtney <edcourtney@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611995}
parent 3ed559be
......@@ -21,9 +21,9 @@ enum WindowVisibilityAnimationType {
// Window slides down from above screen to show and, meanwhile, home launcher
// slides down off screen.
WINDOW_VISIBILITY_ANIMATION_TYPE_SLIDE_DOWN,
// Animate a window out of the closest side of the screen.
// This is for hiding only, and does not do anything for showing.
WINDOW_VISIBILITY_ANIMATION_TYPE_SLIDE_OUT,
// Animate a window out of the closest side of the screen. Fade in if it
// re-appears.
WINDOW_VISIBILITY_ANIMATION_TYPE_FADE_IN_SLIDE_OUT,
};
} // namespace wm
......
......@@ -157,7 +157,7 @@ void BaseState::UpdateMinimizedState(
// app, but minimized.
::wm::SetWindowVisibilityAnimationType(
window, previous_state_type == mojom::WindowStateType::PIP
? WINDOW_VISIBILITY_ANIMATION_TYPE_SLIDE_OUT
? WINDOW_VISIBILITY_ANIMATION_TYPE_FADE_IN_SLIDE_OUT
: WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
window->Hide();
......
......@@ -54,6 +54,9 @@ const float kCrossFadeDurationMaxMs = 400.f;
// Durations for the brightness/grayscale fade animation, in milliseconds.
const int kBrightnessGrayscaleFadeDurationMs = 1000;
// Duration for fade in animation, in milliseconds.
const int kFadeInAnimationMs = 200;
// Brightness/grayscale values for hide/show window animations.
const float kWindowAnimation_HideBrightnessGrayscale = 1.f;
const float kWindowAnimation_ShowBrightnessGrayscale = 0.f;
......@@ -228,6 +231,16 @@ void AnimateShowWindow_BrightnessGrayscale(aura::Window* window) {
AnimateShowHideWindowCommon_BrightnessGrayscale(window, true);
}
// TODO(edcourtney): Consolidate with AnimateShowWindow_Fade in ui/wm/core.
void AnimateShowWindow_FadeIn(aura::Window* window) {
window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(kFadeInAnimationMs));
window->layer()->SetVisible(true);
window->layer()->SetOpacity(kWindowAnimation_ShowOpacity);
}
void AnimateHideWindow_BrightnessGrayscale(aura::Window* window) {
AnimateShowHideWindowCommon_BrightnessGrayscale(window, false);
}
......@@ -281,12 +294,6 @@ void AnimateHideWindow_SlideOut(aura::Window* window) {
gfx::Rect dismissed_bounds =
PipPositioner::GetDismissedPosition(display, bounds);
window->layer()->SetBounds(dismissed_bounds);
// For Android PIP windows, they become minimized app windows after
// dismissal, so make sure to reset their animation type back to
// default.
::wm::SetWindowVisibilityAnimationType(
window, ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT);
}
bool AnimateShowWindow(aura::Window* window) {
......@@ -305,9 +312,9 @@ bool AnimateShowWindow(aura::Window* window) {
case wm::WINDOW_VISIBILITY_ANIMATION_TYPE_SLIDE_DOWN:
return AnimateShowWindow_SlideDown(window);
return true;
case wm::WINDOW_VISIBILITY_ANIMATION_TYPE_SLIDE_OUT:
// Slide out is exclusively a hide animation.
return false;
case wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE_IN_SLIDE_OUT:
AnimateShowWindow_FadeIn(window);
return true;
default:
NOTREACHED();
return false;
......@@ -329,7 +336,7 @@ bool AnimateHideWindow(aura::Window* window) {
return true;
case wm::WINDOW_VISIBILITY_ANIMATION_TYPE_SLIDE_DOWN:
return AnimateHideWindow_SlideDown(window);
case wm::WINDOW_VISIBILITY_ANIMATION_TYPE_SLIDE_OUT:
case wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE_IN_SLIDE_OUT:
AnimateHideWindow_SlideOut(window);
return true;
default:
......
......@@ -9,6 +9,7 @@
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_state.h"
#include "ash/wm/wm_event.h"
#include "ash/wm/workspace_controller.h"
#include "base/command_line.h"
#include "base/time/time.h"
......@@ -291,9 +292,62 @@ TEST_F(WindowAnimationsTest, SlideOutAnimation) {
EXPECT_TRUE(window->layer()->visible());
::wm::SetWindowVisibilityAnimationType(
window.get(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_SLIDE_OUT);
window.get(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE_IN_SLIDE_OUT);
AnimateOnChildWindowVisibilityChanged(window.get(), false);
EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity());
EXPECT_FALSE(window->layer()->GetTargetVisibility());
EXPECT_FALSE(window->layer()->visible());
EXPECT_EQ(gfx::Rect(-150, 0, 100, 100), window->layer()->GetTargetBounds());
}
// Test that a fade in slide out animation fades in.
TEST_F(WindowAnimationsTest, FadeInAnimation) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
window->SetBounds(gfx::Rect(0, 0, 100, 100));
window->Hide();
EXPECT_FALSE(window->layer()->visible());
::wm::SetWindowVisibilityAnimationType(
window.get(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE_IN_SLIDE_OUT);
AnimateOnChildWindowVisibilityChanged(window.get(), true);
EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
EXPECT_TRUE(window->layer()->GetTargetVisibility());
EXPECT_TRUE(window->layer()->visible());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), window->layer()->GetTargetBounds());
}
TEST_F(WindowAnimationsTest, SlideOutAnimationPlaysTwiceForPipWindow) {
ui::ScopedAnimationDurationScaleMode test_duration_mode(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
window->SetBounds(gfx::Rect(0, 0, 100, 100));
wm::WindowState* window_state = wm::GetWindowState(window.get());
const wm::WMEvent enter_pip(wm::WM_EVENT_PIP);
window_state->OnWMEvent(&enter_pip);
EXPECT_TRUE(window_state->IsPip());
window->Show();
EXPECT_TRUE(window->layer()->visible());
window->Hide();
EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity());
EXPECT_FALSE(window->layer()->GetTargetVisibility());
EXPECT_FALSE(window->layer()->visible());
EXPECT_EQ("-150,0 100x100", window->layer()->GetTargetBounds().ToString());
// Reset the position and try again.
window->Show();
window->SetBounds(gfx::Rect(0, 0, 100, 100));
EXPECT_TRUE(window->layer()->visible());
window->Hide();
EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity());
EXPECT_FALSE(window->layer()->GetTargetVisibility());
EXPECT_FALSE(window->layer()->visible());
......
......@@ -669,7 +669,7 @@ void WindowState::SetBoundsDirectCrossFade(const gfx::Rect& new_bounds,
void WindowState::UpdatePipState(bool was_pip) {
if (IsPip()) {
::wm::SetWindowVisibilityAnimationType(
window(), WINDOW_VISIBILITY_ANIMATION_TYPE_SLIDE_OUT);
window(), WINDOW_VISIBILITY_ANIMATION_TYPE_FADE_IN_SLIDE_OUT);
} else if (was_pip) {
::wm::SetWindowVisibilityAnimationType(
window(), ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment