1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_
6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_
8 #include "ash/ash_export.h"
9 #include "ash/display/display_controller.h"
10 #include "ash/shell_observer.h"
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h"
17 #include "base/timer/timer.h"
18 #include "components/wallpaper/wallpaper_layout.h"
19 #include "ui/compositor/layer.h"
20 #include "ui/gfx/image/image_skia.h"
22 typedef unsigned int SkColor
;
29 class WallpaperResizer
;
34 const SkColor kLoginWallpaperColor
= 0xFEFEFE;
36 class DesktopBackgroundControllerObserver
;
38 // Updates background layer if necessary.
39 class ASH_EXPORT DesktopBackgroundController
40 : public DisplayController::Observer
,
41 public ShellObserver
{
50 DesktopBackgroundController();
51 ~DesktopBackgroundController() override
;
53 BackgroundMode
desktop_background_mode() const {
54 return desktop_background_mode_
;
57 // Add/Remove observers.
58 void AddObserver(DesktopBackgroundControllerObserver
* observer
);
59 void RemoveObserver(DesktopBackgroundControllerObserver
* observer
);
61 // Provides current image on the background, or empty gfx::ImageSkia if there
62 // is no image, e.g. background is none.
63 gfx::ImageSkia
GetWallpaper() const;
65 wallpaper::WallpaperLayout
GetWallpaperLayout() const;
67 // Sets wallpaper. This is mostly called by WallpaperManager to set
68 // the default or user selected custom wallpaper.
69 // Returns true if new image was actually set. And false when duplicate set
71 bool SetWallpaperImage(const gfx::ImageSkia
& image
,
72 wallpaper::WallpaperLayout layout
);
74 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready
75 // when running. However, the wallpaper widgets are now created
76 // asynchronously. If loading a real wallpaper, there are cases that these
77 // tests crash because the required widget is not ready. This function
78 // synchronously creates an empty widget for those tests to prevent
79 // crashes. An example test is SystemGestureEventFilterTest.ThreeFingerSwipe.
80 void CreateEmptyWallpaper();
82 // Move all desktop widgets to locked container.
83 // Returns true if the desktop moved.
84 bool MoveDesktopToLockedContainer();
86 // Move all desktop widgets to unlocked container.
87 // Returns true if the desktop moved.
88 bool MoveDesktopToUnlockedContainer();
90 // DisplayController::Observer:
91 void OnDisplayConfigurationChanged() override
;
94 void OnRootWindowAdded(aura::Window
* root_window
) override
;
96 // Returns the maximum size of all displays combined in native
97 // resolutions. Note that this isn't the bounds of the display who
98 // has maximum resolutions. Instead, this returns the size of the
99 // maximum width of all displays, and the maximum height of all displays.
100 static gfx::Size
GetMaxDisplaySizeInNative();
102 // Returns true if the specified wallpaper is already stored
103 // in |current_wallpaper_|.
104 // If |compare_layouts| is false, layout is ignored.
105 bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia
& image
,
106 bool compare_layouts
,
107 wallpaper::WallpaperLayout layout
) const;
110 friend class DesktopBackgroundControllerTest
;
111 // friend class chromeos::WallpaperManagerBrowserTestDefaultWallpaper;
112 FRIEND_TEST_ALL_PREFIXES(DesktopBackgroundControllerTest
, GetMaxDisplaySize
);
114 // Creates view for all root windows, or notifies them to repaint if they
116 void SetDesktopBackgroundImageMode();
118 // Creates and adds component for current mode (either Widget or Layer) to
120 void InstallDesktopController(aura::Window
* root_window
);
122 // Creates and adds component for current mode (either Widget or Layer) to
124 void InstallDesktopControllerForAllWindows();
126 // Moves all desktop components from one container to other across all root
127 // windows. Returns true if a desktop moved.
128 bool ReparentBackgroundWidgets(int src_container
, int dst_container
);
130 // Returns id for background container for unlocked and locked states.
131 int GetBackgroundContainerId(bool locked
);
133 // Send notification that background animation finished.
134 void NotifyAnimationFinished();
136 // Reload the wallpaper.
137 void UpdateWallpaper();
139 void set_wallpaper_reload_delay_for_test(bool value
) {
140 wallpaper_reload_delay_
= value
;
143 // Can change at runtime.
146 BackgroundMode desktop_background_mode_
;
148 SkColor background_color_
;
150 ObserverList
<DesktopBackgroundControllerObserver
> observers_
;
152 // The current wallpaper.
153 scoped_ptr
<wallpaper::WallpaperResizer
> current_wallpaper_
;
155 gfx::Size current_max_display_size_
;
157 base::OneShotTimer
<DesktopBackgroundController
> timer_
;
159 int wallpaper_reload_delay_
;
161 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController
);
166 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_