15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/ash_export.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget_observer.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
16eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass RootWindowController;
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)// This class implements a widget-based wallpaper.
19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// DesktopBackgroundWidgetController is owned by RootWindowController.
20eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// When the animation completes the old DesktopBackgroundWidgetController is
21eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// destroyed. Exported for tests.
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ASH_EXPORT DesktopBackgroundWidgetController
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : public views::WidgetObserver {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit DesktopBackgroundWidgetController(views::Widget* widget);
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~DesktopBackgroundWidgetController();
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from views::WidgetObserver.
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set bounds of component that draws background.
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetBounds(gfx::Rect bounds);
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Move component from |src_container| in |root_window| to |dest_container|.
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // It is required for lock screen, when we need to move background so that
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // it hides user's windows. Returns true if there was something to reparent.
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  bool Reparent(aura::Window* root_window,
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                int src_container,
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                int dest_container);
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Starts wallpaper fade in animation. |root_window_controller| is
44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // the root window where the animation will happen. (This is
45eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // necessary this as |layer_| doesn't have access to the root window).
46eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void StartAnimating(RootWindowController* root_window_controller);
47eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::Widget* widget() { return widget_; }
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::Widget* widget_;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundWidgetController);
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// This class wraps a DesktopBackgroundWidgetController pointer. It is owned
57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// by RootWindowController. The instance of DesktopBackgroundWidgetController is
58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// moved to this RootWindowController when the animation completes.
59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Exported for tests.
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ASH_EXPORT AnimatingDesktopController {
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit AnimatingDesktopController(
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      DesktopBackgroundWidgetController* component);
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~AnimatingDesktopController();
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stops animation and makes sure OnImplicitAnimationsCompleted() is called if
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // current animation is not finished yet.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note we have to make sure this function is called before we set
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // kAnimatingDesktopController to a new controller. If it is not called, the
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // animating widget/layer is closed immediately and the new one is animating
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // from the widget/layer before animation. For instance, if a user quickly
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // switches between red, green and blue wallpapers. The green wallpaper will
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // first fade in from red wallpaper. And in the middle of the animation, blue
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // wallpaper also wants to fade in. If the green wallpaper animation does not
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // finish immediately, the green wallpaper widget will be removed and the red
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // widget will show again. As a result, the blue wallpaper fades in from red
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // wallpaper. This is a bad user experience. See bug http://crbug.com/156542
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for more details.
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StopAnimating();
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets the wrapped DesktopBackgroundWidgetController pointer. Caller should
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // take ownership of the pointer if |pass_ownership| is true.
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DesktopBackgroundWidgetController* GetController(bool pass_ownership);
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<DesktopBackgroundWidgetController> controller_;
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AnimatingDesktopController);
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_WIDGET_CONTROLLER_H_
94