Revert 224458 "Enabling MediaStreamInfoBarTest.DenyingCameraDoes..."
[chromium-blink-merge.git] / ash / desktop_background / desktop_background_controller.h
blob24399c9159f44b8afdacdfbaad7d40a1cff17ed9
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 "base/basictypes.h"
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "ui/aura/window.h"
15 #include "ui/compositor/layer.h"
16 #include "ui/gfx/image/image_skia.h"
18 typedef unsigned int SkColor;
20 class CommandLine;
22 namespace aura {
23 class RootWindow;
26 namespace ash {
27 namespace internal {
28 class DesktopBackgroundControllerTest;
29 } // namespace internal
31 enum WallpaperLayout {
32 // Center the wallpaper on the desktop without scaling it. The wallpaper
33 // may be cropped.
34 WALLPAPER_LAYOUT_CENTER,
35 // Scale the wallpaper (while preserving its aspect ratio) to cover the
36 // desktop; the wallpaper may be cropped.
37 WALLPAPER_LAYOUT_CENTER_CROPPED,
38 // Scale the wallpaper (without preserving its aspect ratio) to match the
39 // desktop's size.
40 WALLPAPER_LAYOUT_STRETCH,
41 // Tile the wallpaper over the background without scaling it.
42 WALLPAPER_LAYOUT_TILE,
45 enum WallpaperResolution {
46 WALLPAPER_RESOLUTION_LARGE,
47 WALLPAPER_RESOLUTION_SMALL
50 const SkColor kLoginWallpaperColor = 0xFEFEFE;
52 // The width and height of small/large resolution wallpaper. When screen size is
53 // smaller than |kSmallWallpaperMaxWidth| and |kSmallWallpaperMaxHeight|, the
54 // small resolution wallpaper should be used. Otherwise, uses the large
55 // resolution wallpaper.
56 ASH_EXPORT extern const int kSmallWallpaperMaxWidth;
57 ASH_EXPORT extern const int kSmallWallpaperMaxHeight;
58 ASH_EXPORT extern const int kLargeWallpaperMaxWidth;
59 ASH_EXPORT extern const int kLargeWallpaperMaxHeight;
61 // The width and heigh of wallpaper thumbnails.
62 ASH_EXPORT extern const int kWallpaperThumbnailWidth;
63 ASH_EXPORT extern const int kWallpaperThumbnailHeight;
65 class DesktopBackgroundControllerObserver;
66 class WallpaperResizer;
68 // Loads selected desktop wallpaper from file system asynchronously and updates
69 // background layer if loaded successfully.
70 class ASH_EXPORT DesktopBackgroundController {
71 public:
72 enum BackgroundMode {
73 BACKGROUND_NONE,
74 BACKGROUND_IMAGE,
77 DesktopBackgroundController();
78 virtual ~DesktopBackgroundController();
80 BackgroundMode desktop_background_mode() const {
81 return desktop_background_mode_;
84 void set_command_line_for_testing(CommandLine* command_line) {
85 command_line_for_testing_ = command_line;
88 // Add/Remove observers.
89 void AddObserver(DesktopBackgroundControllerObserver* observer);
90 void RemoveObserver(DesktopBackgroundControllerObserver* observer);
92 // Provides current image on the background, or empty gfx::ImageSkia if there
93 // is no image, e.g. background is none.
94 gfx::ImageSkia GetWallpaper() const;
96 WallpaperLayout GetWallpaperLayout() const;
98 // Initialize root window's background.
99 void OnRootWindowAdded(aura::RootWindow* root_window);
101 // Loads builtin wallpaper asynchronously and sets to current wallpaper
102 // after loaded. Returns true if the controller started loading the
103 // wallpaper and false otherwise (i.e. the appropriate wallpaper was
104 // already loading or loaded).
105 bool SetDefaultWallpaper(bool is_guest);
107 // Sets the user selected custom wallpaper. Called when user selected a file
108 // from file system or changed the layout of wallpaper.
109 void SetCustomWallpaper(const gfx::ImageSkia& image, WallpaperLayout layout);
111 // Cancels the current wallpaper loading operation.
112 void CancelPendingWallpaperOperation();
114 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready
115 // when running. However, the wallpaper widgets are now created asynchronously
116 // . If loading a real wallpaper, there are cases that these tests crash
117 // because the required widget is not ready. This function synchronously
118 // creates an empty widget for those tests to prevent crashes. An example test
119 // is SystemGestureEventFilterTest.ThreeFingerSwipe.
120 void CreateEmptyWallpaper();
122 // Returns the appropriate wallpaper resolution for all root windows.
123 WallpaperResolution GetAppropriateResolution();
125 // Move all desktop widgets to locked container.
126 // Returns true if the desktop moved.
127 bool MoveDesktopToLockedContainer();
129 // Move all desktop widgets to unlocked container.
130 // Returns true if the desktop moved.
131 bool MoveDesktopToUnlockedContainer();
133 private:
134 friend class internal::DesktopBackgroundControllerTest;
136 // An operation to asynchronously loads wallpaper.
137 class WallpaperLoader;
139 // Returns true if the specified default wallpaper is already being
140 // loaded by |wallpaper_loader_| or stored in |current_wallpaper_|.
141 bool DefaultWallpaperIsAlreadyLoadingOrLoaded(
142 const base::FilePath& image_file, int image_resource_id) const;
144 // Returns true if the specified custom wallpaper is already stored
145 // in |current_wallpaper_|.
146 bool CustomWallpaperIsAlreadyLoaded(const gfx::ImageSkia& image) const;
148 // Creates view for all root windows, or notifies them to repaint if they
149 // already exist.
150 void SetDesktopBackgroundImageMode();
152 // Creates a new background widget and sets the background mode to image mode.
153 // Called after a default wallpaper has been loaded successfully.
154 void OnDefaultWallpaperLoadCompleted(scoped_refptr<WallpaperLoader> loader);
156 // Creates and adds component for current mode (either Widget or Layer) to
157 // |root_window|.
158 void InstallDesktopController(aura::RootWindow* root_window);
160 // Creates and adds component for current mode (either Widget or Layer) to
161 // all root windows.
162 void InstallDesktopControllerForAllWindows();
164 // Moves all desktop components from one container to other across all root
165 // windows. Returns true if a desktop moved.
166 bool ReparentBackgroundWidgets(int src_container, int dst_container);
168 // Returns id for background container for unlocked and locked states.
169 int GetBackgroundContainerId(bool locked);
171 // Send notification that background animation finished.
172 void NotifyAnimationFinished();
174 // If non-NULL, used in place of the real command line.
175 CommandLine* command_line_for_testing_;
177 // Can change at runtime.
178 bool locked_;
180 BackgroundMode desktop_background_mode_;
182 SkColor background_color_;
184 ObserverList<DesktopBackgroundControllerObserver> observers_;
186 // The current wallpaper.
187 scoped_ptr<WallpaperResizer> current_wallpaper_;
189 // If a default wallpaper is stored in |current_wallpaper_|, the path and
190 // resource ID that were passed to WallpaperLoader when loading it.
191 // Otherwise, empty and -1, respectively.
192 base::FilePath current_default_wallpaper_path_;
193 int current_default_wallpaper_resource_id_;
195 scoped_refptr<WallpaperLoader> wallpaper_loader_;
197 base::WeakPtrFactory<DesktopBackgroundController> weak_ptr_factory_;
199 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController);
202 } // namespace ash
204 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_