Commit fc2d77d5 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

overivew: Animate blur when there are no maximized windows.

See bug(s) for spec. This CL adds an animated blur on wallpaper when entering/existing
overview when no maximized/fullscreen windows.

Bug: 823533, 812004
Change-Id: Icf8bdababedaaefe869f62768aacf7abcb3643d2
Reviewed-on: https://chromium-review.googlesource.com/979167Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549780}
parent 0cb48b93
...@@ -83,10 +83,6 @@ constexpr float kOldShieldOpacity = 0.7f; ...@@ -83,10 +83,6 @@ constexpr float kOldShieldOpacity = 0.7f;
// form the shield widgets color. // form the shield widgets color.
constexpr SkColor kShieldBaseColor = SkColorSetARGB(179, 0, 0, 0); constexpr SkColor kShieldBaseColor = SkColorSetARGB(179, 0, 0, 0);
// Amount of blur to apply on the wallpaper when we enter or exit overview mode.
constexpr float kWallpaperBlurSigma = 10.f;
constexpr float kWallpaperClearBlurSigma = 0.f;
// In the conceptual overview table, the window margin is the space reserved // In the conceptual overview table, the window margin is the space reserved
// around the window within the cell. This margin does not overlap so the // around the window within the cell. This margin does not overlap so the
// closest distance between adjacent windows will be twice this amount. // closest distance between adjacent windows will be twice this amount.
...@@ -241,13 +237,6 @@ WindowGrid::WindowGrid(aura::Window* root_window, ...@@ -241,13 +237,6 @@ WindowGrid::WindowGrid(aura::Window* root_window,
window_list_.push_back( window_list_.push_back(
std::make_unique<WindowSelectorItem>(window, window_selector_, this)); std::make_unique<WindowSelectorItem>(window, window_selector_, this));
} }
if (IsNewOverviewUi() &&
Shell::Get()->wallpaper_controller()->IsBlurEnabled()) {
RootWindowController::ForWindow(root_window_)
->wallpaper_widget_controller()
->SetWallpaperBlur(kWallpaperBlurSigma);
}
} }
WindowGrid::~WindowGrid() = default; WindowGrid::~WindowGrid() = default;
...@@ -280,13 +269,6 @@ void WindowGrid::Shutdown() { ...@@ -280,13 +269,6 @@ void WindowGrid::Shutdown() {
std::move(observer)); std::move(observer));
shield_widget->SetOpacity(0.f); shield_widget->SetOpacity(0.f);
} }
if (IsNewOverviewUi() &&
Shell::Get()->wallpaper_controller()->IsBlurEnabled()) {
RootWindowController::ForWindow(root_window_)
->wallpaper_widget_controller()
->SetWallpaperBlur(kWallpaperClearBlurSigma);
}
} }
void WindowGrid::PrepareForOverview() { void WindowGrid::PrepareForOverview() {
......
...@@ -651,6 +651,35 @@ bool WindowSelector::IsShuttingDown() const { ...@@ -651,6 +651,35 @@ bool WindowSelector::IsShuttingDown() const {
return Shell::Get()->window_selector_controller()->is_shutting_down(); return Shell::Get()->window_selector_controller()->is_shutting_down();
} }
bool WindowSelector::ShouldAnimateWallpaper(aura::Window* root_window) {
// Find the grid associated with |root_window|.
WindowGrid* grid = nullptr;
for (const auto& window_grid : grid_list_) {
if (window_grid->root_window() == root_window) {
grid = window_grid.get();
break;
}
}
if (!grid)
return false;
// It is possible we leave overview mode to enter split view mode with both
// windows snapped. Do not animate the wallpaper in this case.
if (Shell::Get()->split_view_controller()->state() ==
SplitViewController::BOTH_SNAPPED) {
return false;
}
// If one of the windows covers the workspace, we do not need to animate.
for (const auto& selector_item : grid->window_list()) {
if (CanCoverAvailableWorkspace(selector_item->GetWindow()))
return false;
}
return true;
}
bool WindowSelector::HandleKeyEvent(views::Textfield* sender, bool WindowSelector::HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) { const ui::KeyEvent& key_event) {
// Do not do anything with the events if none of the window grids have windows // Do not do anything with the events if none of the window grids have windows
......
...@@ -129,6 +129,11 @@ class ASH_EXPORT WindowSelector : public display::DisplayObserver, ...@@ -129,6 +129,11 @@ class ASH_EXPORT WindowSelector : public display::DisplayObserver,
// If we are in middle of ending overview mode. // If we are in middle of ending overview mode.
bool IsShuttingDown() const; bool IsShuttingDown() const;
// Checks if the grid associated with a given |root_window| needs to have the
// wallpaper animated. Returns false if one of the grids windows covers the
// the entire workspace, true otherwise.
bool ShouldAnimateWallpaper(aura::Window* root_window);
WindowSelectorDelegate* delegate() { return delegate_; } WindowSelectorDelegate* delegate() { return delegate_; }
bool restoring_minimized_windows() const { bool restoring_minimized_windows() const {
......
...@@ -7,8 +7,11 @@ ...@@ -7,8 +7,11 @@
#include <vector> #include <vector>
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller.h" #include "ash/session/session_controller.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wallpaper/wallpaper_controller.h"
#include "ash/wallpaper/wallpaper_widget_controller.h"
#include "ash/wm/mru_window_tracker.h" #include "ash/wm/mru_window_tracker.h"
#include "ash/wm/overview/overview_utils.h" #include "ash/wm/overview/overview_utils.h"
#include "ash/wm/overview/window_grid.h" #include "ash/wm/overview/window_grid.h"
...@@ -21,12 +24,19 @@ ...@@ -21,12 +24,19 @@
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/wm/core/window_util.h" #include "ui/wm/core/window_util.h"
namespace ash { namespace ash {
namespace { namespace {
// Amount of blur to apply on the wallpaper when we enter or exit overview mode.
constexpr double kWallpaperBlurSigma = 10.f;
constexpr double kWallpaperClearBlurSigma = 0.f;
constexpr int kBlurSlideDurationMs = 250;
// Returns true if |window| should be hidden when entering overview. // Returns true if |window| should be hidden when entering overview.
bool ShouldHideWindowInOverview(const aura::Window* window) { bool ShouldHideWindowInOverview(const aura::Window* window) {
return !window->GetProperty(ash::kShowInOverviewKey); return !window->GetProperty(ash::kShowInOverviewKey);
...@@ -55,11 +65,136 @@ bool ShouldExcludeWindowFromOverview(const aura::Window* window) { ...@@ -55,11 +65,136 @@ bool ShouldExcludeWindowFromOverview(const aura::Window* window) {
return false; return false;
} }
bool IsBlurEnabled() {
return IsNewOverviewUi() &&
Shell::Get()->wallpaper_controller()->IsBlurEnabled();
}
} // namespace } // namespace
WindowSelectorController::WindowSelectorController() = default; // Class that handles of blurring wallpaper upon 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.
class WindowSelectorController::OverviewBlurController
: public gfx::AnimationDelegate,
public aura::WindowObserver {
public:
OverviewBlurController() : animation_(this) {
animation_.SetSlideDuration(kBlurSlideDurationMs);
}
~OverviewBlurController() override {
animation_.Stop();
for (aura::Window* root : roots_to_animate_)
root->RemoveObserver(this);
}
void Blur() {
state_ = WallpaperAnimationState::kAddingBlur;
OnBlurChange();
}
void Unblur() {
state_ = WallpaperAnimationState::kRemovingBlur;
OnBlurChange();
}
private:
enum class WallpaperAnimationState {
kAddingBlur,
kRemovingBlur,
kNormal,
};
// gfx::AnimationDelegate:
void AnimationEnded(const gfx::Animation* animation) override {
DCHECK(state_ == WallpaperAnimationState::kAddingBlur ||
state_ == WallpaperAnimationState::kRemovingBlur);
double value = state_ == WallpaperAnimationState::kAddingBlur
? kWallpaperBlurSigma
: kWallpaperClearBlurSigma;
for (aura::Window* root : roots_to_animate_)
ApplyBlur(root, value);
state_ = WallpaperAnimationState::kNormal;
}
void AnimationProgressed(const gfx::Animation* animation) override {
double value = animation_.CurrentValueBetween(kWallpaperClearBlurSigma,
kWallpaperBlurSigma);
for (aura::Window* root : roots_to_animate_)
ApplyBlur(root, value);
}
void AnimationCanceled(const gfx::Animation* animation) override {
for (aura::Window* root : roots_to_animate_)
ApplyBlur(root, kWallpaperClearBlurSigma);
state_ = WallpaperAnimationState::kNormal;
}
// aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override {
window->RemoveObserver(this);
auto it =
std::find(roots_to_animate_.begin(), roots_to_animate_.end(), window);
if (it != roots_to_animate_.end())
roots_to_animate_.erase(it);
}
void ApplyBlur(aura::Window* root, float blur_sigma) {
RootWindowController::ForWindow(root)
->wallpaper_widget_controller()
->SetWallpaperBlur(static_cast<float>(blur_sigma));
}
// Called when the wallpaper is to be changed. Checks to see which root
// windows should have their wallpaper blurs animated and fills
// |roots_to_animate_| accordingly. Applys blur or unblur immediately if
// the wallpaper does not need blur animation.
void OnBlurChange() {
bool should_blur = state_ == WallpaperAnimationState::kAddingBlur;
double value = should_blur ? kWallpaperBlurSigma : kWallpaperClearBlurSigma;
for (aura::Window* root : roots_to_animate_)
root->RemoveObserver(this);
roots_to_animate_.clear();
WindowSelector* window_selector =
Shell::Get()->window_selector_controller()->window_selector();
DCHECK(window_selector);
for (aura::Window* root : Shell::Get()->GetAllRootWindows()) {
if (!window_selector->ShouldAnimateWallpaper(root)) {
ApplyBlur(root, value);
} else {
root->AddObserver(this);
roots_to_animate_.push_back(root);
}
}
// Run the animation if one of the roots needs to be aniamted.
if (roots_to_animate_.empty()) {
state_ = WallpaperAnimationState::kNormal;
} else if (should_blur) {
animation_.Show();
} else {
animation_.Hide();
}
}
WallpaperAnimationState state_ = WallpaperAnimationState::kNormal;
gfx::SlideAnimation animation_;
// Vector which contains the root windows, if any, whose wallpaper should have
// blur animated after Blur or Unblur is called.
std::vector<aura::Window*> roots_to_animate_;
DISALLOW_COPY_AND_ASSIGN(OverviewBlurController);
};
WindowSelectorController::WindowSelectorController()
: overview_blur_controller_(std::make_unique<OverviewBlurController>()) {}
WindowSelectorController::~WindowSelectorController() { WindowSelectorController::~WindowSelectorController() {
overview_blur_controller_.reset();
// Destroy widgets that may be still animating if shell shuts down soon after // Destroy widgets that may be still animating if shell shuts down soon after
// exiting overview mode. // exiting overview mode.
for (std::unique_ptr<DelayedAnimationObserver>& animation_observer : for (std::unique_ptr<DelayedAnimationObserver>& animation_observer :
...@@ -117,6 +252,8 @@ bool WindowSelectorController::ToggleOverview() { ...@@ -117,6 +252,8 @@ bool WindowSelectorController::ToggleOverview() {
Shell::Get()->NotifyOverviewModeStarting(); Shell::Get()->NotifyOverviewModeStarting();
window_selector_.reset(new WindowSelector(this)); window_selector_.reset(new WindowSelector(this));
window_selector_->Init(windows, hide_windows); window_selector_->Init(windows, hide_windows);
if (IsBlurEnabled())
overview_blur_controller_->Blur();
OnSelectionStarted(); OnSelectionStarted();
} }
return true; return true;
...@@ -269,6 +406,9 @@ WindowSelectorController::GetWindowsListInOverviewGridsForTesting() { ...@@ -269,6 +406,9 @@ WindowSelectorController::GetWindowsListInOverviewGridsForTesting() {
void WindowSelectorController::OnSelectionEnded() { void WindowSelectorController::OnSelectionEnded() {
if (is_shutting_down_) if (is_shutting_down_)
return; return;
if (IsBlurEnabled())
overview_blur_controller_->Unblur();
is_shutting_down_ = true; is_shutting_down_ = true;
Shell::Get()->NotifyOverviewModeEnding(); Shell::Get()->NotifyOverviewModeEnding();
window_selector_->Shutdown(); window_selector_->Shutdown();
......
...@@ -70,6 +70,7 @@ class ASH_EXPORT WindowSelectorController : public WindowSelectorDelegate { ...@@ -70,6 +70,7 @@ class ASH_EXPORT WindowSelectorController : public WindowSelectorDelegate {
WindowSelector* window_selector() { return window_selector_.get(); } WindowSelector* window_selector() { return window_selector_.get(); }
private: private:
class OverviewBlurController;
friend class WindowSelectorTest; friend class WindowSelectorTest;
// Dispatched when window selection begins. // Dispatched when window selection begins.
...@@ -86,6 +87,10 @@ class ASH_EXPORT WindowSelectorController : public WindowSelectorDelegate { ...@@ -86,6 +87,10 @@ class ASH_EXPORT WindowSelectorController : public WindowSelectorDelegate {
// If we are in middle of ending overview mode. // If we are in middle of ending overview mode.
bool is_shutting_down_ = false; bool is_shutting_down_ = false;
// Handles blurring of the wallpaper when entering or exiting overview mode.
// Animates the blurring if necessary.
std::unique_ptr<OverviewBlurController> overview_blur_controller_;
DISALLOW_COPY_AND_ASSIGN(WindowSelectorController); DISALLOW_COPY_AND_ASSIGN(WindowSelectorController);
}; };
......
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