Commit ad9eb1c8 authored by chinsenj's avatar chinsenj Committed by Commit Bot

cros: Close wallpaper preview when window cycle (alt-tab) starts

If a user is previewing a wallpaper and begins to cycle windows, the
preview item for the wallpaper picker is empty/transparent.

Now when the window cycle starts up, it closes the wallpaper preview if
it is open so the preview item displays the wallpaper picker properly.

Test: WallpaperControllerTest.ClosePreviewWallpaperOnWindowCycleStart
Bug: 895265
Change-Id: Ie1900f2ce172ec03407e6801c051d34f0a94d975
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2341143Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Jeremy Chinsen <chinsenj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795739}
parent 53370ebc
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ash/wallpaper/wallpaper_view.h" #include "ash/wallpaper/wallpaper_view.h"
#include "ash/wallpaper/wallpaper_widget_controller.h" #include "ash/wallpaper/wallpaper_widget_controller.h"
#include "ash/wm/overview/overview_controller.h" #include "ash/wm/overview/overview_controller.h"
#include "ash/wm/window_cycle_controller.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
...@@ -239,13 +240,15 @@ class TestWallpaperControllerClient : public WallpaperControllerClient { ...@@ -239,13 +240,15 @@ class TestWallpaperControllerClient : public WallpaperControllerClient {
virtual ~TestWallpaperControllerClient() = default; virtual ~TestWallpaperControllerClient() = default;
size_t open_count() const { return open_count_; } size_t open_count() const { return open_count_; }
size_t close_preview_count() const { return close_preview_count_; }
// WallpaperControllerClient: // WallpaperControllerClient:
void OpenWallpaperPicker() override { open_count_++; } void OpenWallpaperPicker() override { open_count_++; }
void MaybeClosePreviewWallpaper() override {} void MaybeClosePreviewWallpaper() override { close_preview_count_++; }
private: private:
size_t open_count_ = 0; size_t open_count_ = 0;
size_t close_preview_count_ = 0;
DISALLOW_COPY_AND_ASSIGN(TestWallpaperControllerClient); DISALLOW_COPY_AND_ASSIGN(TestWallpaperControllerClient);
}; };
...@@ -2090,6 +2093,116 @@ TEST_F(WallpaperControllerTest, ShouldNotShowInitialAnimationAfterSignOut) { ...@@ -2090,6 +2093,116 @@ TEST_F(WallpaperControllerTest, ShouldNotShowInitialAnimationAfterSignOut) {
EXPECT_EQ(1, GetWallpaperCount()); EXPECT_EQ(1, GetWallpaperCount());
} }
TEST_F(WallpaperControllerTest, ClosePreviewWallpaperOnOverviewStart) {
TestWallpaperControllerClient client;
controller_->SetClient(&client);
// Verify the user starts with a default wallpaper and the user wallpaper info
// is initialized with default values.
SimulateUserLogin(kUser1);
ClearWallpaperCount();
controller_->ShowUserWallpaper(account_id_1);
RunAllTasksUntilIdle();
EXPECT_EQ(1, GetWallpaperCount());
WallpaperInfo user_wallpaper_info;
WallpaperInfo default_wallpaper_info(std::string(),
WALLPAPER_LAYOUT_CENTER_CROPPED, DEFAULT,
base::Time::Now().LocalMidnight());
EXPECT_TRUE(
controller_->GetUserWallpaperInfo(account_id_1, &user_wallpaper_info));
EXPECT_EQ(user_wallpaper_info, default_wallpaper_info);
// Simulate opening the wallpaper picker window.
std::unique_ptr<aura::Window> wallpaper_picker_window(
CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
WindowState::Get(wallpaper_picker_window.get())->Activate();
// Set a custom wallpaper for the user and enable preview. Verify that the
// wallpaper is changed to the expected color.
const WallpaperLayout layout = WALLPAPER_LAYOUT_CENTER;
gfx::ImageSkia custom_wallpaper = CreateImage(640, 480, kWallpaperColor);
EXPECT_NE(kWallpaperColor, GetWallpaperColor());
ClearWallpaperCount();
controller_->SetCustomWallpaper(account_id_1, wallpaper_files_id_1,
file_name_1, layout, custom_wallpaper,
true /*preview_mode=*/);
RunAllTasksUntilIdle();
EXPECT_EQ(1, GetWallpaperCount());
EXPECT_EQ(kWallpaperColor, GetWallpaperColor());
// Verify that the user wallpaper info remains unchanged during the preview.
EXPECT_TRUE(
controller_->GetUserWallpaperInfo(account_id_1, &user_wallpaper_info));
EXPECT_EQ(user_wallpaper_info, default_wallpaper_info);
// Now enter overview mode. Verify the wallpaper changes back to the default,
// the user wallpaper info remains unchanged, and enters overview mode
// properly.
ClearWallpaperCount();
Shell::Get()->overview_controller()->StartOverview();
RunAllTasksUntilIdle();
EXPECT_EQ(1, GetWallpaperCount());
EXPECT_NE(kWallpaperColor, GetWallpaperColor());
EXPECT_EQ(controller_->GetWallpaperType(), DEFAULT);
EXPECT_EQ(user_wallpaper_info, default_wallpaper_info);
EXPECT_TRUE(Shell::Get()->overview_controller()->InOverviewSession());
EXPECT_EQ(1u, client.close_preview_count());
}
TEST_F(WallpaperControllerTest, ClosePreviewWallpaperOnWindowCycleStart) {
TestWallpaperControllerClient client;
controller_->SetClient(&client);
// Verify the user starts with a default wallpaper and the user wallpaper info
// is initialized with default values.
SimulateUserLogin(kUser1);
ClearWallpaperCount();
controller_->ShowUserWallpaper(account_id_1);
RunAllTasksUntilIdle();
EXPECT_EQ(1, GetWallpaperCount());
WallpaperInfo user_wallpaper_info;
WallpaperInfo default_wallpaper_info(std::string(),
WALLPAPER_LAYOUT_CENTER_CROPPED, DEFAULT,
base::Time::Now().LocalMidnight());
EXPECT_TRUE(
controller_->GetUserWallpaperInfo(account_id_1, &user_wallpaper_info));
EXPECT_EQ(user_wallpaper_info, default_wallpaper_info);
// Simulate opening the wallpaper picker window.
std::unique_ptr<aura::Window> wallpaper_picker_window(
CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
WindowState::Get(wallpaper_picker_window.get())->Activate();
// Set a custom wallpaper for the user and enable preview. Verify that the
// wallpaper is changed to the expected color.
const WallpaperLayout layout = WALLPAPER_LAYOUT_CENTER;
gfx::ImageSkia custom_wallpaper = CreateImage(640, 480, kWallpaperColor);
EXPECT_NE(kWallpaperColor, GetWallpaperColor());
ClearWallpaperCount();
controller_->SetCustomWallpaper(account_id_1, wallpaper_files_id_1,
file_name_1, layout, custom_wallpaper,
true /*preview_mode=*/);
RunAllTasksUntilIdle();
EXPECT_EQ(1, GetWallpaperCount());
EXPECT_EQ(kWallpaperColor, GetWallpaperColor());
// Verify that the user wallpaper info remains unchanged during the preview.
EXPECT_TRUE(
controller_->GetUserWallpaperInfo(account_id_1, &user_wallpaper_info));
EXPECT_EQ(user_wallpaper_info, default_wallpaper_info);
// Now start window cycle. Verify the wallpaper changes back to the default,
// the user wallpaper info remains unchanged, and enters window cycle.
ClearWallpaperCount();
Shell::Get()->window_cycle_controller()->HandleCycleWindow(
WindowCycleController::FORWARD);
RunAllTasksUntilIdle();
EXPECT_EQ(1, GetWallpaperCount());
EXPECT_NE(kWallpaperColor, GetWallpaperColor());
EXPECT_EQ(controller_->GetWallpaperType(), DEFAULT);
EXPECT_EQ(user_wallpaper_info, default_wallpaper_info);
EXPECT_TRUE(Shell::Get()->window_cycle_controller()->IsCycling());
EXPECT_EQ(1u, client.close_preview_count());
}
TEST_F(WallpaperControllerTest, ConfirmPreviewWallpaper) { TEST_F(WallpaperControllerTest, ConfirmPreviewWallpaper) {
// Verify the user starts with a default wallpaper and the user wallpaper info // Verify the user starts with a default wallpaper and the user wallpaper info
// is initialized with default values. // is initialized with default values.
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/session/session_controller_impl.h" #include "ash/session/session_controller_impl.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wallpaper/wallpaper_controller_impl.h"
#include "ash/wm/desks/desk.h" #include "ash/wm/desks/desk.h"
#include "ash/wm/desks/desks_controller.h" #include "ash/wm/desks/desks_controller.h"
#include "ash/wm/desks/desks_util.h" #include "ash/wm/desks/desks_util.h"
...@@ -89,6 +90,11 @@ void WindowCycleController::HandleCycleWindow(Direction direction) { ...@@ -89,6 +90,11 @@ void WindowCycleController::HandleCycleWindow(Direction direction) {
} }
void WindowCycleController::StartCycling() { void WindowCycleController::StartCycling() {
// Close the wallpaper preview if it is open to prevent visual glitches where
// the window view item for the preview is transparent
// (http://crbug.com/895265).
Shell::Get()->wallpaper_controller()->MaybeClosePreviewWallpaper();
WindowCycleList::WindowList window_list = WindowCycleList::WindowList window_list =
Shell::Get()->mru_window_tracker()->BuildWindowForCycleWithPipList( Shell::Get()->mru_window_tracker()->BuildWindowForCycleWithPipList(
features::IsAltTabLimitedToActiveDesk() ? kActiveDesk : kAllDesks); features::IsAltTabLimitedToActiveDesk() ? kActiveDesk : kAllDesks);
......
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