blob: 7226c1bd5df542b156ef015c69495d9e0ff9c47a [file] [log] [blame]
// Copyright (c) 2012 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 <list>
#include <memory>
#include "ash/ash_export.h"
#include "base/callback.h"
#include "base/macros.h"
namespace aura {
class Window;
namespace views {
class Widget;
namespace ash {
// This class manages widget-based wallpapers.
// WallpaperWidgetController is owned by RootWindowController.
// Exported for tests.
class ASH_EXPORT WallpaperWidgetController {
explicit WallpaperWidgetController(base::OnceClosure wallpaper_set_callback);
views::Widget* GetWidget();
views::Widget* GetAnimatingWidget();
// Whether a wallpaper change is in progress - it will be set if
// |animating_widget_| exists.
bool IsAnimating() const;
// If an animating wallpaper change is in progress, it ends the animation and
// changes the wallpaper immediately.
// No-op if IsAnimation() returns false.
void EndPendingAnimation();
// If an animating wallpaper change is in progress, it adds a callback that
// will be run when the pending animation ends.
// The callback will not be run if a wallpaper animation is not in progress -
// in that case the method will return false.
void AddPendingAnimationEndCallback(base::OnceClosure callback);
// Sets a new wallpaper widget - this will not change the primary widget
// immediately. The primary widget will be switched when |widget|'s showing
// animation finishes (during which |widget| will be kept by
// |animating_widget_|).
// |blur_sigma| - if non-zero, the blur that should be applied to the
// wallpaper widget layer.
void SetWallpaperWidget(views::Widget* widget, float blur_sigma);
// Move the wallpaper for |root_window| to the specified |container|.
// The lock screen moves the wallpaper container to hides the user's windows.
// Returns true if there was something to reparent.
bool Reparent(aura::Window* root_window, int container);
// Blur pixels of the wallpaper layer by 3 * the given amount.
void SetWallpaperBlur(float blur_sigma);
// Reset, and closes both |active_widget_| and |animating_widget_|. Can be
// used in tests to reset the wallpaper widget controller state.
void ResetWidgetsForTesting();
// Wrapper around wallpaper widgets that manages the widget state.
class WidgetHandler;
// Called when a WidgetHandler for a wallpaper widget is reset - this happens
// when the wallpaper widget is being destroyed.
void WidgetHandlerReset(WidgetHandler* widget);
// Called when WidgetHandler |widget| detects its associated widget is done
// animating to shown state.
void WidgetFinishedAnimating(WidgetHandler* widget);
// Moves |animated_widget_| to |active_widget_|.
void SetAnimatingWidgetAsActive();
// Runs callbacks in |pending_animation_end_callbacks_|.
void RunPendingAnimationEndCallbacks();
// Callback that will be run when |active_widget_| is first set.
base::OnceClosure wallpaper_set_callback_;
// The current wallpaper widget.
std::unique_ptr<WidgetHandler> active_widget_;
// The pending wallpaper widget, which is currently in process of being
// shown.
std::unique_ptr<WidgetHandler> animating_widget_;
// Callbacks to be run when the |animating_widget_| stops animating and gets
// set as the active widget.
std::list<base::OnceClosure> pending_animation_end_callbacks_;
} // namespace ash