Commit 2ed50ff3 authored by Richard Chui's avatar Richard Chui Committed by Commit Bot

Overview: Fix wallpaper dimming when toggling tablet mode

The wallpaper dimming effect isn't applied when the user is in overview
mode and switches from tablet to clamshell mode. This is because normal
and tablet mode have different default wallpaper properties
(blur/opacity). After the properties are applied initially when entering
overview, they are not changed when toggling tablet mode.

This CL fixes this by updating the wallpaper with the correct properties
when starting and ending tablet mode.

Test: manual, added tests
Bug: 1103019
Change-Id: I74fd97f888017f283786bc26ab87ebb39217026c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340566Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Commit-Queue: Richard Chui <richui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798899}
parent 67e499b1
......@@ -2093,6 +2093,7 @@ test("ash_unittests") {
"wm/overview/overview_session_unittest.cc",
"wm/overview/overview_test_util.cc",
"wm/overview/overview_test_util.h",
"wm/overview/overview_wallpaper_controller_unittest.cc",
"wm/overview/overview_window_drag_controller_unittest.cc",
"wm/overview/overview_window_drag_histogram_unittests.cc",
"wm/overview/scoped_overview_transform_window_unittest.cc",
......
......@@ -440,7 +440,7 @@ void OverviewController::ToggleOverview(OverviewEnterExitType type) {
// the overview immediately, so delaying blur start until start animations
// finish looks janky.
overview_wallpaper_controller_->Blur(
/*animate_only=*/new_type == OverviewEnterExitType::kFadeInEnter);
/*animate=*/new_type == OverviewEnterExitType::kFadeInEnter);
// For app dragging, there are no start animations so add a delay to delay
// animations observing when the start animation ends, such as the shelf,
......@@ -508,7 +508,7 @@ void OverviewController::OnStartingAnimationComplete(bool canceled) {
// so it doesn't have to be requested again on starting animation end.
if (!canceled && overview_session_->enter_exit_overview_type() !=
OverviewEnterExitType::kFadeInEnter) {
overview_wallpaper_controller_->Blur(/*animate_only=*/true);
overview_wallpaper_controller_->Blur(/*animate=*/true);
}
for (auto& observer : observers_)
......
......@@ -7,6 +7,7 @@
#include "ash/root_window_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/wallpaper/wallpaper_property.h"
#include "ash/wallpaper/wallpaper_widget_controller.h"
#include "ash/wm/overview/overview_constants.h"
#include "ash/wm/overview/overview_controller.h"
......@@ -31,55 +32,87 @@ WallpaperWidgetController* GetWallpaperWidgetController(aura::Window* root) {
return RootWindowController::ForWindow(root)->wallpaper_widget_controller();
}
// Returns the wallpaper property based on the current configuration.
WallpaperProperty GetProperty(bool blur) {
if (!blur)
return wallpaper_constants::kClear;
// Tablet mode wallpaper is already dimmed, so no need to change the
// opacity.
if (Shell::Get()->tablet_mode_controller()->InTabletMode())
return wallpaper_constants::kOverviewInTabletState;
return wallpaper_constants::kOverviewState;
}
} // namespace
OverviewWallpaperController::OverviewWallpaperController() {
Shell::Get()->tablet_mode_controller()->AddObserver(this);
}
OverviewWallpaperController::~OverviewWallpaperController() {
Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
}
// static
void OverviewWallpaperController::SetDoNotChangeWallpaperForTests() {
g_disable_wallpaper_change_for_tests = true;
}
void OverviewWallpaperController::Blur(bool animate_only) {
if (!IsWallpaperChangeAllowed())
return;
OnBlurChange(/*should_blur=*/true, animate_only);
void OverviewWallpaperController::Blur(bool animate) {
UpdateWallpaper(/*should_blur=*/true, animate);
}
void OverviewWallpaperController::Unblur() {
UpdateWallpaper(/*should_blur=*/false, /*animate=*/true);
}
void OverviewWallpaperController::OnTabletModeStarted() {
UpdateWallpaper(wallpaper_blurred_, /*animate=*/base::nullopt);
}
void OverviewWallpaperController::OnTabletModeEnded() {
UpdateWallpaper(wallpaper_blurred_, /*animate=*/base::nullopt);
}
void OverviewWallpaperController::UpdateWallpaper(
bool should_blur,
base::Optional<bool> animate) {
if (!IsWallpaperChangeAllowed())
return;
OnBlurChange(/*should_blur=*/false, /*animate_only=*/true);
}
void OverviewWallpaperController::OnBlurChange(bool should_blur,
bool animate_only) {
// Don't apply wallpaper change while the session is blocked.
if (Shell::Get()->session_controller()->IsUserSessionBlocked())
return;
WallpaperProperty property = GetProperty(should_blur);
for (aura::Window* root : Shell::Get()->GetAllRootWindows()) {
auto* wallpaper_widget_controller = GetWallpaperWidgetController(root);
if (property == wallpaper_widget_controller->GetWallpaperProperty())
continue;
if (!animate.has_value()) {
wallpaper_widget_controller->SetWallpaperProperty(property);
continue;
}
const bool should_animate = ShouldAnimateWallpaper(root);
// On adding blur, we want to blur immediately if there are no animations
// and blur after the rest of the overview animations have completed if
// there is to be wallpaper animations. |OnBlurChange| will get called twice
// when blurring, but only change the wallpaper when |should_animate|
// matches |animate_only|.
if (should_blur && should_animate != animate_only)
// there is to be wallpaper animations. |UpdateWallpaper| will get called
// twice when blurring, but only change the wallpaper when |should_animate|
// matches |animate|.
if (should_blur && should_animate != animate.value())
continue;
auto* wallpaper_widget_controller = GetWallpaperWidgetController(root);
// Tablet mode wallpaper is already dimmed, so no need to change the
// opacity.
WallpaperProperty property =
!should_blur ? wallpaper_constants::kClear
: (Shell::Get()->tablet_mode_controller()->InTabletMode()
? wallpaper_constants::kOverviewInTabletState
: wallpaper_constants::kOverviewState);
// TODO(sammiequon): Move this check to wallpaper code.
if (property == wallpaper_widget_controller->GetWallpaperProperty())
continue;
wallpaper_widget_controller->SetWallpaperProperty(
property, should_animate ? kBlurSlideDuration : base::TimeDelta());
}
wallpaper_blurred_ = should_blur;
}
} // namespace ash
......@@ -8,7 +8,9 @@
#include <vector>
#include "ash/ash_export.h"
#include "ash/public/cpp/tablet_mode_observer.h"
#include "base/macros.h"
#include "base/optional.h"
namespace ash {
......@@ -16,21 +18,31 @@ namespace ash {
// entering and exiting overview mode. Blurs the wallpaper automatically if the
// wallpaper is not visible prior to entering overview mode (covered by a
// window), otherwise animates the blur and dim.
class ASH_EXPORT OverviewWallpaperController {
class ASH_EXPORT OverviewWallpaperController : public TabletModeObserver {
public:
OverviewWallpaperController() = default;
~OverviewWallpaperController() = default;
OverviewWallpaperController();
~OverviewWallpaperController() override;
// There is no need to blur or dim the wallpaper for tests.
static void SetDoNotChangeWallpaperForTests();
void Blur(bool animate_only);
void Blur(bool animate);
void Unblur();
// TabletModeObserver:
void OnTabletModeStarted() override;
void OnTabletModeEnded() override;
private:
// Called when the wallpaper is to be changed. Checks to see which root
// windows should have their wallpaper blurs animated.
void OnBlurChange(bool should_blur, bool animate_only);
// Called when the wallpaper is to be changed and updates all root windows.
// Based on the |animate| paramter, several things can happen:
// - nullopt: Apply the blur immediately.
// - true/false: Animates and applies the blur only if this value matches
// whether animations are allowed based on each root window.
void UpdateWallpaper(bool should_blur, base::Optional<bool> animate);
// Tracks if the wallpaper blur should be applied.
bool wallpaper_blurred_ = false;
DISALLOW_COPY_AND_ASSIGN(OverviewWallpaperController);
};
......
// Copyright 2020 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/overview/overview_wallpaper_controller.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wallpaper/wallpaper_property.h"
#include "ash/wallpaper/wallpaper_widget_controller.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_test_util.h"
#include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
namespace ash {
namespace {
WallpaperProperty GetWallpaperProperty(const aura::Window* window) {
return RootWindowController::ForWindow(window)
->wallpaper_widget_controller()
->GetWallpaperProperty();
}
void CheckWallpaperProperty(WallpaperProperty expected) {
for (aura::Window* root : Shell::Get()->GetAllRootWindows())
EXPECT_EQ(expected, GetWallpaperProperty(root));
}
} // namespace
using OverviewWallpaperControllerTest = AshTestBase;
// Tests that entering overview in clamshell mode and toggling to tablet mode
// updates the wallpaper window property correctly.
TEST_F(OverviewWallpaperControllerTest, OverviewToggleEnterTabletMode) {
CheckWallpaperProperty(wallpaper_constants::kClear);
ToggleOverview();
CheckWallpaperProperty(wallpaper_constants::kOverviewState);
TabletModeControllerTestApi().EnterTabletMode();
CheckWallpaperProperty(wallpaper_constants::kOverviewInTabletState);
ToggleOverview();
CheckWallpaperProperty(wallpaper_constants::kClear);
}
// Tests that entering overview in tablet mode and toggling to clamshell mode
// updates the wallpaper window property correctly.
TEST_F(OverviewWallpaperControllerTest, OverviewToggleLeaveTabletMode) {
TabletModeControllerTestApi().EnterTabletMode();
CheckWallpaperProperty(wallpaper_constants::kClear);
ToggleOverview();
CheckWallpaperProperty(wallpaper_constants::kOverviewInTabletState);
TabletModeControllerTestApi().LeaveTabletMode();
CheckWallpaperProperty(wallpaper_constants::kOverviewState);
ToggleOverview();
CheckWallpaperProperty(wallpaper_constants::kClear);
}
} // namespace ash
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