replace OVERRIDE and FINAL with override and final in ash/
[chromium-blink-merge.git] / ash / desktop_background / desktop_background_controller.h
blobe9bf6393ef752b76817762514fc279b7decc1d33
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 "ui/compositor/layer.h"
19 #include "ui/gfx/image/image_skia.h"
21 typedef unsigned int SkColor;
23 namespace aura {
24 class Window;
27 namespace ash {
29 enum WallpaperLayout {
30 // Center the wallpaper on the desktop without scaling it. The wallpaper
31 // may be cropped.
32 WALLPAPER_LAYOUT_CENTER,
33 // Scale the wallpaper (while preserving its aspect ratio) to cover the
34 // desktop; the wallpaper may be cropped.
35 WALLPAPER_LAYOUT_CENTER_CROPPED,
36 // Scale the wallpaper (without preserving its aspect ratio) to match the
37 // desktop's size.
38 WALLPAPER_LAYOUT_STRETCH,
39 // Tile the wallpaper over the background without scaling it.
40 WALLPAPER_LAYOUT_TILE
43 const SkColor kLoginWallpaperColor = 0xFEFEFE;
45 class DesktopBackgroundControllerObserver;
46 class WallpaperResizer;
48 // Updates background layer if necessary.
49 class ASH_EXPORT DesktopBackgroundController
50 : public DisplayController::Observer,
51 public ShellObserver {
52 public:
53 class TestAPI;
55 enum BackgroundMode {
56 BACKGROUND_NONE,
57 BACKGROUND_IMAGE,
60 DesktopBackgroundController();
61 virtual ~DesktopBackgroundController();
63 BackgroundMode desktop_background_mode() const {
64 return desktop_background_mode_;
67 // Add/Remove observers.
68 void AddObserver(DesktopBackgroundControllerObserver* observer);
69 void RemoveObserver(DesktopBackgroundControllerObserver* observer);
71 // Provides current image on the background, or empty gfx::ImageSkia if there
72 // is no image, e.g. background is none.
73 gfx::ImageSkia GetWallpaper() const;
75 WallpaperLayout GetWallpaperLayout() const;
77 // Sets wallpaper. This is mostly called by WallpaperManager to set
78 // the default or user selected custom wallpaper.
79 // Returns true if new image was actually set. And false when duplicate set
80 // request detected.
81 bool SetWallpaperImage(const gfx::ImageSkia& image, WallpaperLayout layout);
83 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready
84 // when running. However, the wallpaper widgets are now created
85 // asynchronously. If loading a real wallpaper, there are cases that these
86 // tests crash because the required widget is not ready. This function
87 // synchronously creates an empty widget for those tests to prevent
88 // crashes. An example test is SystemGestureEventFilterTest.ThreeFingerSwipe.
89 void CreateEmptyWallpaper();
91 // Move all desktop widgets to locked container.
92 // Returns true if the desktop moved.
93 bool MoveDesktopToLockedContainer();
95 // Move all desktop widgets to unlocked container.
96 // Returns true if the desktop moved.
97 bool MoveDesktopToUnlockedContainer();
99 // DisplayController::Observer:
100 virtual void OnDisplayConfigurationChanged() override;
102 // ShellObserver:
103 virtual void OnRootWindowAdded(aura::Window* root_window) override;
105 // Returns the maximum size of all displays combined in native
106 // resolutions. Note that this isn't the bounds of the display who
107 // has maximum resolutions. Instead, this returns the size of the
108 // maximum width of all displays, and the maximum height of all displays.
109 static gfx::Size GetMaxDisplaySizeInNative();
111 // Returns true if the specified wallpaper is already stored
112 // in |current_wallpaper_|.
113 // If |compare_layouts| is false, layout is ignored.
114 bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia& image,
115 bool compare_layouts,
116 WallpaperLayout layout) const;
118 private:
119 friend class DesktopBackgroundControllerTest;
120 // friend class chromeos::WallpaperManagerBrowserTestDefaultWallpaper;
121 FRIEND_TEST_ALL_PREFIXES(DesktopBackgroundControllerTest, GetMaxDisplaySize);
123 // Creates view for all root windows, or notifies them to repaint if they
124 // already exist.
125 void SetDesktopBackgroundImageMode();
127 // Creates and adds component for current mode (either Widget or Layer) to
128 // |root_window|.
129 void InstallDesktopController(aura::Window* root_window);
131 // Creates and adds component for current mode (either Widget or Layer) to
132 // all root windows.
133 void InstallDesktopControllerForAllWindows();
135 // Moves all desktop components from one container to other across all root
136 // windows. Returns true if a desktop moved.
137 bool ReparentBackgroundWidgets(int src_container, int dst_container);
139 // Returns id for background container for unlocked and locked states.
140 int GetBackgroundContainerId(bool locked);
142 // Send notification that background animation finished.
143 void NotifyAnimationFinished();
145 // Reload the wallpaper.
146 void UpdateWallpaper();
148 void set_wallpaper_reload_delay_for_test(bool value) {
149 wallpaper_reload_delay_ = value;
152 // Can change at runtime.
153 bool locked_;
155 BackgroundMode desktop_background_mode_;
157 SkColor background_color_;
159 ObserverList<DesktopBackgroundControllerObserver> observers_;
161 // The current wallpaper.
162 scoped_ptr<WallpaperResizer> current_wallpaper_;
164 gfx::Size current_max_display_size_;
166 base::OneShotTimer<DesktopBackgroundController> timer_;
168 int wallpaper_reload_delay_;
170 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController);
173 } // namespace ash
175 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_