OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | 5 #ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ |
6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | 6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "ash/display/display_controller.h" | 9 #include "ash/display/display_controller.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
17 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
18 #include "ui/gfx/image/image_skia.h" | 18 #include "ui/gfx/image/image_skia.h" |
19 | 19 |
20 typedef unsigned int SkColor; | 20 typedef unsigned int SkColor; |
21 | 21 |
22 namespace aura { | 22 namespace aura { |
23 class Window; | 23 class Window; |
24 } | 24 } |
25 | 25 |
26 namespace base { | |
27 class CommandLine; | |
28 } | |
29 | |
30 namespace ash { | 26 namespace ash { |
31 | 27 |
32 enum WallpaperLayout { | 28 enum WallpaperLayout { |
33 // Center the wallpaper on the desktop without scaling it. The wallpaper | 29 // Center the wallpaper on the desktop without scaling it. The wallpaper |
34 // may be cropped. | 30 // may be cropped. |
35 WALLPAPER_LAYOUT_CENTER, | 31 WALLPAPER_LAYOUT_CENTER, |
36 // Scale the wallpaper (while preserving its aspect ratio) to cover the | 32 // Scale the wallpaper (while preserving its aspect ratio) to cover the |
37 // desktop; the wallpaper may be cropped. | 33 // desktop; the wallpaper may be cropped. |
38 WALLPAPER_LAYOUT_CENTER_CROPPED, | 34 WALLPAPER_LAYOUT_CENTER_CROPPED, |
39 // Scale the wallpaper (without preserving its aspect ratio) to match the | 35 // Scale the wallpaper (without preserving its aspect ratio) to match the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 BACKGROUND_IMAGE, | 72 BACKGROUND_IMAGE, |
77 }; | 73 }; |
78 | 74 |
79 DesktopBackgroundController(); | 75 DesktopBackgroundController(); |
80 virtual ~DesktopBackgroundController(); | 76 virtual ~DesktopBackgroundController(); |
81 | 77 |
82 BackgroundMode desktop_background_mode() const { | 78 BackgroundMode desktop_background_mode() const { |
83 return desktop_background_mode_; | 79 return desktop_background_mode_; |
84 } | 80 } |
85 | 81 |
86 void set_command_line_for_testing(base::CommandLine* command_line) { | |
87 command_line_for_testing_ = command_line; | |
88 } | |
89 | |
90 // Add/Remove observers. | 82 // Add/Remove observers. |
91 void AddObserver(DesktopBackgroundControllerObserver* observer); | 83 void AddObserver(DesktopBackgroundControllerObserver* observer); |
92 void RemoveObserver(DesktopBackgroundControllerObserver* observer); | 84 void RemoveObserver(DesktopBackgroundControllerObserver* observer); |
93 | 85 |
94 // Provides current image on the background, or empty gfx::ImageSkia if there | 86 // Provides current image on the background, or empty gfx::ImageSkia if there |
95 // is no image, e.g. background is none. | 87 // is no image, e.g. background is none. |
96 gfx::ImageSkia GetWallpaper() const; | 88 gfx::ImageSkia GetWallpaper() const; |
97 | 89 |
98 WallpaperLayout GetWallpaperLayout() const; | 90 WallpaperLayout GetWallpaperLayout() const; |
99 | 91 |
100 // Initialize root window's background. | 92 // Initialize root window's background. |
101 void OnRootWindowAdded(aura::Window* root_window); | 93 void OnRootWindowAdded(aura::Window* root_window); |
102 | 94 |
103 // Loads builtin wallpaper asynchronously and sets to current wallpaper | |
104 // after loaded. Returns true if the controller started loading the | |
105 // wallpaper and false otherwise (i.e. the appropriate wallpaper was | |
106 // already loading or loaded). | |
107 bool SetDefaultWallpaper(bool is_guest); | |
108 | |
109 // Sets the user selected custom wallpaper. Called when user selected a file | 95 // Sets the user selected custom wallpaper. Called when user selected a file |
Daniel Erat
2014/03/27 01:45:50
update this comment if it's no longer only used fo
Alexander Alekseev
2014/03/31 14:15:40
Done.
| |
110 // from file system or changed the layout of wallpaper. | 96 // from file system or changed the layout of wallpaper. |
111 void SetCustomWallpaper(const gfx::ImageSkia& image, WallpaperLayout layout); | 97 void SetCustomWallpaper(const gfx::ImageSkia& image, WallpaperLayout layout); |
Daniel Erat
2014/03/27 01:45:50
rename this to SetWallpaper()
Alexander Alekseev
2014/03/31 14:15:40
Done.
| |
112 | 98 |
113 // Cancels |default_wallpaper_loader_| if non-NULL. | |
114 void CancelDefaultWallpaperLoader(); | |
115 | |
116 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready | 99 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready |
117 // when running. However, the wallpaper widgets are now created | 100 // when running. However, the wallpaper widgets are now created |
118 // asynchronously. If loading a real wallpaper, there are cases that these | 101 // asynchronously. If loading a real wallpaper, there are cases that these |
119 // tests crash because the required widget is not ready. This function | 102 // tests crash because the required widget is not ready. This function |
120 // synchronously creates an empty widget for those tests to prevent | 103 // synchronously creates an empty widget for those tests to prevent |
121 // crashes. An example test is SystemGestureEventFilterTest.ThreeFingerSwipe. | 104 // crashes. An example test is SystemGestureEventFilterTest.ThreeFingerSwipe. |
122 void CreateEmptyWallpaper(); | 105 void CreateEmptyWallpaper(); |
123 | 106 |
124 // Returns the appropriate wallpaper resolution for all root windows. | 107 // Returns the appropriate wallpaper resolution for all root windows. |
125 WallpaperResolution GetAppropriateResolution(); | 108 WallpaperResolution GetAppropriateResolution(); |
126 | 109 |
127 // Move all desktop widgets to locked container. | 110 // Move all desktop widgets to locked container. |
128 // Returns true if the desktop moved. | 111 // Returns true if the desktop moved. |
129 bool MoveDesktopToLockedContainer(); | 112 bool MoveDesktopToLockedContainer(); |
130 | 113 |
131 // Move all desktop widgets to unlocked container. | 114 // Move all desktop widgets to unlocked container. |
132 // Returns true if the desktop moved. | 115 // Returns true if the desktop moved. |
133 bool MoveDesktopToUnlockedContainer(); | 116 bool MoveDesktopToUnlockedContainer(); |
134 | 117 |
135 // Overrides DisplayController::Observer: | 118 // Overrides DisplayController::Observer: |
136 virtual void OnDisplayConfigurationChanged() OVERRIDE; | 119 virtual void OnDisplayConfigurationChanged() OVERRIDE; |
137 | 120 |
121 // Returns true if the specified custom wallpaper is already stored | |
122 // in |current_wallpaper_|. | |
123 bool CustomWallpaperIsAlreadyLoaded(const gfx::ImageSkia& image) const; | |
124 | |
138 private: | 125 private: |
139 friend class DesktopBackgroundControllerTest; | 126 friend class DesktopBackgroundControllerTest; |
140 FRIEND_TEST_ALL_PREFIXES(DesktopBackgroundControllerTest, GetMaxDisplaySize); | 127 FRIEND_TEST_ALL_PREFIXES(DesktopBackgroundControllerTest, GetMaxDisplaySize); |
141 | 128 |
142 // An operation to asynchronously loads wallpaper. | 129 // An operation to asynchronously loads wallpaper. |
143 class WallpaperLoader; | 130 class WallpaperLoader; |
144 | 131 |
145 // Returns true if the specified default wallpaper is already being | |
146 // loaded by |wallpaper_loader_| or stored in |current_wallpaper_|. | |
147 bool DefaultWallpaperIsAlreadyLoadingOrLoaded( | |
148 const base::FilePath& image_file, int image_resource_id) const; | |
149 | |
150 // Returns true if the specified custom wallpaper is already stored | |
151 // in |current_wallpaper_|. | |
152 bool CustomWallpaperIsAlreadyLoaded(const gfx::ImageSkia& image) const; | |
153 | |
154 // Creates view for all root windows, or notifies them to repaint if they | 132 // Creates view for all root windows, or notifies them to repaint if they |
155 // already exist. | 133 // already exist. |
156 void SetDesktopBackgroundImageMode(); | 134 void SetDesktopBackgroundImageMode(); |
157 | 135 |
158 // Creates a new background widget and sets the background mode to image mode. | |
159 // Called after a default wallpaper has been loaded successfully. | |
160 void OnDefaultWallpaperLoadCompleted(scoped_refptr<WallpaperLoader> loader); | |
161 | |
162 // Creates and adds component for current mode (either Widget or Layer) to | 136 // Creates and adds component for current mode (either Widget or Layer) to |
163 // |root_window|. | 137 // |root_window|. |
164 void InstallDesktopController(aura::Window* root_window); | 138 void InstallDesktopController(aura::Window* root_window); |
165 | 139 |
166 // Creates and adds component for current mode (either Widget or Layer) to | 140 // Creates and adds component for current mode (either Widget or Layer) to |
167 // all root windows. | 141 // all root windows. |
168 void InstallDesktopControllerForAllWindows(); | 142 void InstallDesktopControllerForAllWindows(); |
169 | 143 |
170 // Moves all desktop components from one container to other across all root | 144 // Moves all desktop components from one container to other across all root |
171 // windows. Returns true if a desktop moved. | 145 // windows. Returns true if a desktop moved. |
(...skipping 11 matching lines...) Expand all Loading... | |
183 void set_wallpaper_reload_delay_for_test(bool value) { | 157 void set_wallpaper_reload_delay_for_test(bool value) { |
184 wallpaper_reload_delay_ = value; | 158 wallpaper_reload_delay_ = value; |
185 } | 159 } |
186 | 160 |
187 // Returns the maximum size of all displays combined in native | 161 // Returns the maximum size of all displays combined in native |
188 // resolutions. Note that this isn't the bounds of the display who | 162 // resolutions. Note that this isn't the bounds of the display who |
189 // has maximum resolutions. Instead, this returns the size of the | 163 // has maximum resolutions. Instead, this returns the size of the |
190 // maximum width of all displays, and the maximum height of all displays. | 164 // maximum width of all displays, and the maximum height of all displays. |
191 static gfx::Size GetMaxDisplaySizeInNative(); | 165 static gfx::Size GetMaxDisplaySizeInNative(); |
192 | 166 |
193 // If non-NULL, used in place of the real command line. | |
194 base::CommandLine* command_line_for_testing_; | |
195 | |
196 // Can change at runtime. | 167 // Can change at runtime. |
197 bool locked_; | 168 bool locked_; |
198 | 169 |
199 BackgroundMode desktop_background_mode_; | 170 BackgroundMode desktop_background_mode_; |
200 | 171 |
201 SkColor background_color_; | 172 SkColor background_color_; |
202 | 173 |
203 ObserverList<DesktopBackgroundControllerObserver> observers_; | 174 ObserverList<DesktopBackgroundControllerObserver> observers_; |
204 | 175 |
205 // The current wallpaper. | 176 // The current wallpaper. |
206 scoped_ptr<WallpaperResizer> current_wallpaper_; | 177 scoped_ptr<WallpaperResizer> current_wallpaper_; |
207 | 178 |
208 // If a default wallpaper is stored in |current_wallpaper_|, the path and | |
209 // resource ID that were passed to WallpaperLoader when loading it. | |
210 // Otherwise, empty and -1, respectively. | |
211 base::FilePath current_default_wallpaper_path_; | |
212 int current_default_wallpaper_resource_id_; | |
213 | |
214 gfx::Size current_max_display_size_; | 179 gfx::Size current_max_display_size_; |
215 | 180 |
216 // Loads default wallpaper from disk. | |
217 scoped_refptr<WallpaperLoader> default_wallpaper_loader_; | |
218 | |
219 base::WeakPtrFactory<DesktopBackgroundController> weak_ptr_factory_; | |
220 | |
221 base::OneShotTimer<DesktopBackgroundController> timer_; | 181 base::OneShotTimer<DesktopBackgroundController> timer_; |
222 | 182 |
223 int wallpaper_reload_delay_; | 183 int wallpaper_reload_delay_; |
224 | 184 |
225 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); | 185 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); |
226 }; | 186 }; |
227 | 187 |
228 } // namespace ash | 188 } // namespace ash |
229 | 189 |
230 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | 190 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ |
OLD | NEW |