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" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 BACKGROUND_IMAGE, | 76 BACKGROUND_IMAGE, |
77 }; | 77 }; |
78 | 78 |
79 DesktopBackgroundController(); | 79 DesktopBackgroundController(); |
80 virtual ~DesktopBackgroundController(); | 80 virtual ~DesktopBackgroundController(); |
81 | 81 |
82 BackgroundMode desktop_background_mode() const { | 82 BackgroundMode desktop_background_mode() const { |
83 return desktop_background_mode_; | 83 return desktop_background_mode_; |
84 } | 84 } |
85 | 85 |
86 void set_command_line_for_testing(base::CommandLine* command_line) { | |
87 command_line_for_testing_ = command_line; | |
88 } | |
89 | |
90 // Add/Remove observers. | 86 // Add/Remove observers. |
91 void AddObserver(DesktopBackgroundControllerObserver* observer); | 87 void AddObserver(DesktopBackgroundControllerObserver* observer); |
92 void RemoveObserver(DesktopBackgroundControllerObserver* observer); | 88 void RemoveObserver(DesktopBackgroundControllerObserver* observer); |
93 | 89 |
94 // Provides current image on the background, or empty gfx::ImageSkia if there | 90 // Provides current image on the background, or empty gfx::ImageSkia if there |
95 // is no image, e.g. background is none. | 91 // is no image, e.g. background is none. |
96 gfx::ImageSkia GetWallpaper() const; | 92 gfx::ImageSkia GetWallpaper() const; |
97 | 93 |
98 WallpaperLayout GetWallpaperLayout() const; | 94 WallpaperLayout GetWallpaperLayout() const; |
99 | 95 |
100 // Initialize root window's background. | 96 // Initialize root window's background. |
101 void OnRootWindowAdded(aura::Window* root_window); | 97 void OnRootWindowAdded(aura::Window* root_window); |
102 | 98 |
| 99 // Initializes |small_default_wallpaper_path_|, |
| 100 // |large_default_wallpaper_path_|, |small_guest_wallpaper_path_|, and |
| 101 // |large_guest_wallpaper_path_| based on the flags in |cl|. |
| 102 // Called from the c'tor with the current process's command line, but also |
| 103 // made public so that tests can call it with a custom command line. |
| 104 void InitWallpaperPathsFromCommandLine(base::CommandLine* cl); |
| 105 |
| 106 // Overrides command-line arguments specifying the default wallpaper. |
| 107 // If the previous default wallpaper is currently being shown, the new default |
| 108 // wallpaper is loaded instead. |
| 109 void SetDefaultWallpaperPaths(const base::FilePath& small_path, |
| 110 const base::FilePath& large_path, |
| 111 bool is_guest); |
| 112 |
103 // Loads builtin wallpaper asynchronously and sets to current wallpaper | 113 // Loads builtin wallpaper asynchronously and sets to current wallpaper |
104 // after loaded. Returns true if the controller started loading the | 114 // after loaded. Returns true if the controller started loading the |
105 // wallpaper and false otherwise (i.e. the appropriate wallpaper was | 115 // wallpaper and false otherwise (i.e. the appropriate wallpaper was |
106 // already loading or loaded). | 116 // already loading or loaded). |
107 bool SetDefaultWallpaper(bool is_guest); | 117 bool SetDefaultWallpaper(bool is_guest); |
108 | 118 |
109 // Sets the user selected custom wallpaper. Called when user selected a file | 119 // Sets the user selected custom wallpaper. Called when user selected a file |
110 // from file system or changed the layout of wallpaper. | 120 // from file system or changed the layout of wallpaper. |
111 void SetCustomWallpaper(const gfx::ImageSkia& image, WallpaperLayout layout); | 121 void SetCustomWallpaper(const gfx::ImageSkia& image, WallpaperLayout layout); |
112 | 122 |
(...skipping 22 matching lines...) Expand all Loading... |
135 // Overrides DisplayController::Observer: | 145 // Overrides DisplayController::Observer: |
136 virtual void OnDisplayConfigurationChanged() OVERRIDE; | 146 virtual void OnDisplayConfigurationChanged() OVERRIDE; |
137 | 147 |
138 private: | 148 private: |
139 friend class DesktopBackgroundControllerTest; | 149 friend class DesktopBackgroundControllerTest; |
140 FRIEND_TEST_ALL_PREFIXES(DesktopBackgroundControllerTest, GetMaxDisplaySize); | 150 FRIEND_TEST_ALL_PREFIXES(DesktopBackgroundControllerTest, GetMaxDisplaySize); |
141 | 151 |
142 // An operation to asynchronously loads wallpaper. | 152 // An operation to asynchronously loads wallpaper. |
143 class WallpaperLoader; | 153 class WallpaperLoader; |
144 | 154 |
| 155 // Determines information about the default wallpaper that should currently be |
| 156 // used. Out-param pointers may be NULL, in which case they will be ignored. |
| 157 void GetDefaultWallpaperInfo(bool is_guest, |
| 158 base::FilePath* file_path, |
| 159 WallpaperLayout* file_layout, |
| 160 int* resource_id, |
| 161 WallpaperLayout* resource_layout); |
| 162 |
145 // Returns true if the specified default wallpaper is already being | 163 // Returns true if the specified default wallpaper is already being |
146 // loaded by |wallpaper_loader_| or stored in |current_wallpaper_|. | 164 // loaded by |wallpaper_loader_| or stored in |current_wallpaper_|. |
147 bool DefaultWallpaperIsAlreadyLoadingOrLoaded( | 165 bool DefaultWallpaperIsAlreadyLoadingOrLoaded( |
148 const base::FilePath& image_file, int image_resource_id) const; | 166 const base::FilePath& image_file, |
| 167 int image_resource_id) const; |
149 | 168 |
150 // Returns true if the specified custom wallpaper is already stored | 169 // Returns true if the specified custom wallpaper is already stored |
151 // in |current_wallpaper_|. | 170 // in |current_wallpaper_|. |
152 bool CustomWallpaperIsAlreadyLoaded(const gfx::ImageSkia& image) const; | 171 bool CustomWallpaperIsAlreadyLoaded(const gfx::ImageSkia& image) const; |
153 | 172 |
154 // Creates view for all root windows, or notifies them to repaint if they | 173 // Creates view for all root windows, or notifies them to repaint if they |
155 // already exist. | 174 // already exist. |
156 void SetDesktopBackgroundImageMode(); | 175 void SetDesktopBackgroundImageMode(); |
157 | 176 |
158 // Creates a new background widget and sets the background mode to image mode. | 177 // Creates a new background widget and sets the background mode to image mode. |
(...skipping 14 matching lines...) Expand all Loading... |
173 | 192 |
174 // Returns id for background container for unlocked and locked states. | 193 // Returns id for background container for unlocked and locked states. |
175 int GetBackgroundContainerId(bool locked); | 194 int GetBackgroundContainerId(bool locked); |
176 | 195 |
177 // Send notification that background animation finished. | 196 // Send notification that background animation finished. |
178 void NotifyAnimationFinished(); | 197 void NotifyAnimationFinished(); |
179 | 198 |
180 // Reload the wallpaper. | 199 // Reload the wallpaper. |
181 void UpdateWallpaper(); | 200 void UpdateWallpaper(); |
182 | 201 |
183 void set_wallpaper_reload_delay_for_test(bool value) { | 202 void set_wallpaper_reload_delay_for_test(base::TimeDelta delay) { |
184 wallpaper_reload_delay_ = value; | 203 wallpaper_reload_delay_ = delay; |
185 } | 204 } |
186 | 205 |
187 // Returns the maximum size of all displays combined in native | 206 // Returns the maximum size of all displays combined in native |
188 // resolutions. Note that this isn't the bounds of the display who | 207 // resolutions. Note that this isn't the bounds of the display who |
189 // has maximum resolutions. Instead, this returns the size of the | 208 // has maximum resolutions. Instead, this returns the size of the |
190 // maximum width of all displays, and the maximum height of all displays. | 209 // maximum width of all displays, and the maximum height of all displays. |
191 static gfx::Size GetMaxDisplaySizeInNative(); | 210 static gfx::Size GetMaxDisplaySizeInNative(); |
192 | 211 |
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. | 212 // Can change at runtime. |
197 bool locked_; | 213 bool locked_; |
198 | 214 |
| 215 // Wallpaper images loaded by SetDefaultWallpaper(). |
| 216 base::FilePath small_default_wallpaper_path_; |
| 217 base::FilePath large_default_wallpaper_path_; |
| 218 base::FilePath small_guest_wallpaper_path_; |
| 219 base::FilePath large_guest_wallpaper_path_; |
| 220 |
199 BackgroundMode desktop_background_mode_; | 221 BackgroundMode desktop_background_mode_; |
200 | 222 |
201 SkColor background_color_; | 223 SkColor background_color_; |
202 | 224 |
203 ObserverList<DesktopBackgroundControllerObserver> observers_; | 225 ObserverList<DesktopBackgroundControllerObserver> observers_; |
204 | 226 |
205 // The current wallpaper. | 227 // The current wallpaper. |
206 scoped_ptr<WallpaperResizer> current_wallpaper_; | 228 scoped_ptr<WallpaperResizer> current_wallpaper_; |
207 | 229 |
208 // If a default wallpaper is stored in |current_wallpaper_|, the path and | 230 // If a default wallpaper is stored in |current_wallpaper_|, the path and |
209 // resource ID that were passed to WallpaperLoader when loading it. | 231 // resource ID that were passed to WallpaperLoader when loading it. |
210 // Otherwise, empty and -1, respectively. | 232 // Otherwise, empty and -1, respectively. |
211 base::FilePath current_default_wallpaper_path_; | 233 base::FilePath current_default_wallpaper_path_; |
212 int current_default_wallpaper_resource_id_; | 234 int current_default_wallpaper_resource_id_; |
213 | 235 |
214 gfx::Size current_max_display_size_; | 236 gfx::Size current_max_display_size_; |
215 | 237 |
216 // Loads default wallpaper from disk. | 238 // Loads default wallpaper from disk. |
217 scoped_refptr<WallpaperLoader> default_wallpaper_loader_; | 239 scoped_refptr<WallpaperLoader> default_wallpaper_loader_; |
218 | 240 |
219 base::WeakPtrFactory<DesktopBackgroundController> weak_ptr_factory_; | 241 base::WeakPtrFactory<DesktopBackgroundController> weak_ptr_factory_; |
220 | 242 |
221 base::OneShotTimer<DesktopBackgroundController> timer_; | 243 base::OneShotTimer<DesktopBackgroundController> timer_; |
222 | 244 |
223 int wallpaper_reload_delay_; | 245 // Delay before updating the wallpaper when the display configuration changes. |
| 246 base::TimeDelta wallpaper_reload_delay_; |
224 | 247 |
225 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); | 248 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); |
226 }; | 249 }; |
227 | 250 |
228 } // namespace ash | 251 } // namespace ash |
229 | 252 |
230 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | 253 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ |
OLD | NEW |