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 "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/files/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
14 #include "ui/aura/window_observer.h" | 15 #include "ui/aura/window_observer.h" |
15 #include "ui/compositor/layer.h" | 16 #include "ui/compositor/layer.h" |
16 #include "ui/gfx/image/image_skia.h" | 17 #include "ui/gfx/image/image_skia.h" |
17 | 18 |
18 typedef unsigned int SkColor; | 19 typedef unsigned int SkColor; |
19 | 20 |
| 21 class CommandLine; |
| 22 |
20 namespace aura { | 23 namespace aura { |
21 class RootWindow; | 24 class RootWindow; |
22 } | 25 } |
23 | 26 |
24 namespace ash { | 27 namespace ash { |
25 namespace internal { | 28 namespace internal { |
26 class DesktopBackgroundControllerTest; | 29 class DesktopBackgroundControllerTest; |
27 } // namespace internal | 30 } // namespace internal |
28 | 31 |
29 enum WallpaperLayout { | 32 enum WallpaperLayout { |
| 33 // Center the wallpaper on the desktop without scaling it. The wallpaper |
| 34 // may be cropped. |
30 WALLPAPER_LAYOUT_CENTER, | 35 WALLPAPER_LAYOUT_CENTER, |
| 36 // Scale the wallpaper (while preserving its aspect ratio) to cover the |
| 37 // desktop; the wallpaper may be cropped. |
31 WALLPAPER_LAYOUT_CENTER_CROPPED, | 38 WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 39 // Scale the wallpaper (without preserving its aspect ratio) to match the |
| 40 // desktop's size. |
32 WALLPAPER_LAYOUT_STRETCH, | 41 WALLPAPER_LAYOUT_STRETCH, |
| 42 // Tile the wallpaper over the background without scaling it. |
33 WALLPAPER_LAYOUT_TILE, | 43 WALLPAPER_LAYOUT_TILE, |
34 }; | 44 }; |
35 | 45 |
36 enum WallpaperResolution { | 46 enum WallpaperResolution { |
37 WALLPAPER_RESOLUTION_LARGE, | 47 WALLPAPER_RESOLUTION_LARGE, |
38 WALLPAPER_RESOLUTION_SMALL | 48 WALLPAPER_RESOLUTION_SMALL |
39 }; | 49 }; |
40 | 50 |
41 const SkColor kLoginWallpaperColor = 0xFEFEFE; | 51 const SkColor kLoginWallpaperColor = 0xFEFEFE; |
42 | 52 |
43 // Encapsulates wallpaper infomation needed by desktop background controller. | |
44 struct ASH_EXPORT WallpaperInfo { | |
45 int idr; | |
46 WallpaperLayout layout; | |
47 }; | |
48 | |
49 ASH_EXPORT extern const WallpaperInfo kDefaultLargeWallpaper; | |
50 ASH_EXPORT extern const WallpaperInfo kDefaultSmallWallpaper; | |
51 ASH_EXPORT extern const WallpaperInfo kGuestLargeWallpaper; | |
52 ASH_EXPORT extern const WallpaperInfo kGuestSmallWallpaper; | |
53 | |
54 // The width and height of small/large resolution wallpaper. When screen size is | 53 // The width and height of small/large resolution wallpaper. When screen size is |
55 // smaller than |kSmallWallpaperMaxWidth| and |kSmallWallpaperMaxHeight|, the | 54 // smaller than |kSmallWallpaperMaxWidth| and |kSmallWallpaperMaxHeight|, the |
56 // small resolution wallpaper should be used. Otherwise, uses the large | 55 // small resolution wallpaper should be used. Otherwise, uses the large |
57 // resolution wallpaper. | 56 // resolution wallpaper. |
58 ASH_EXPORT extern const int kSmallWallpaperMaxWidth; | 57 ASH_EXPORT extern const int kSmallWallpaperMaxWidth; |
59 ASH_EXPORT extern const int kSmallWallpaperMaxHeight; | 58 ASH_EXPORT extern const int kSmallWallpaperMaxHeight; |
60 ASH_EXPORT extern const int kLargeWallpaperMaxWidth; | 59 ASH_EXPORT extern const int kLargeWallpaperMaxWidth; |
61 ASH_EXPORT extern const int kLargeWallpaperMaxHeight; | 60 ASH_EXPORT extern const int kLargeWallpaperMaxHeight; |
62 | 61 |
63 // The width and heigh of wallpaper thumbnails. | 62 // The width and heigh of wallpaper thumbnails. |
64 ASH_EXPORT extern const int kWallpaperThumbnailWidth; | 63 ASH_EXPORT extern const int kWallpaperThumbnailWidth; |
65 ASH_EXPORT extern const int kWallpaperThumbnailHeight; | 64 ASH_EXPORT extern const int kWallpaperThumbnailHeight; |
66 | 65 |
67 class DesktopBackgroundControllerObserver; | 66 class DesktopBackgroundControllerObserver; |
68 class WallpaperResizer; | 67 class WallpaperResizer; |
69 | 68 |
70 // Loads selected desktop wallpaper from file system asynchronously and updates | 69 // Loads selected desktop wallpaper from file system asynchronously and updates |
71 // background layer if loaded successfully. | 70 // background layer if loaded successfully. |
72 class ASH_EXPORT DesktopBackgroundController : public aura::WindowObserver { | 71 class ASH_EXPORT DesktopBackgroundController : public aura::WindowObserver { |
73 public: | 72 public: |
74 enum BackgroundMode { | 73 enum BackgroundMode { |
75 BACKGROUND_NONE, | 74 BACKGROUND_NONE, |
76 BACKGROUND_IMAGE, | 75 BACKGROUND_IMAGE, |
77 BACKGROUND_SOLID_COLOR | 76 BACKGROUND_SOLID_COLOR |
78 }; | 77 }; |
79 | 78 |
80 DesktopBackgroundController(); | 79 DesktopBackgroundController(); |
81 virtual ~DesktopBackgroundController(); | 80 virtual ~DesktopBackgroundController(); |
82 | 81 |
83 // Gets the desktop background mode. | |
84 BackgroundMode desktop_background_mode() const { | 82 BackgroundMode desktop_background_mode() const { |
85 return desktop_background_mode_; | 83 return desktop_background_mode_; |
86 } | 84 } |
87 | 85 |
| 86 void set_command_line_for_testing(CommandLine* command_line) { |
| 87 command_line_for_testing_ = command_line; |
| 88 } |
| 89 |
88 // Add/Remove observers. | 90 // Add/Remove observers. |
89 void AddObserver(DesktopBackgroundControllerObserver* observer); | 91 void AddObserver(DesktopBackgroundControllerObserver* observer); |
90 void RemoveObserver(DesktopBackgroundControllerObserver* observer); | 92 void RemoveObserver(DesktopBackgroundControllerObserver* observer); |
91 | 93 |
| 94 // Provides current image on the background, or empty gfx::ImageSkia if there |
| 95 // is no image, e.g. background is solid color. |
92 gfx::ImageSkia GetWallpaper() const; | 96 gfx::ImageSkia GetWallpaper() const; |
93 | 97 |
94 WallpaperLayout GetWallpaperLayout() const; | 98 WallpaperLayout GetWallpaperLayout() const; |
95 | 99 |
96 // Provides current image on the background, or empty gfx::ImageSkia if there | |
97 // is no image, e.g. background is solid color. | |
98 gfx::ImageSkia GetCurrentWallpaperImage(); | |
99 | |
100 // Gets the IDR of current wallpaper. Returns -1 if current wallpaper is not | |
101 // a builtin wallpaper. | |
102 int GetWallpaperIDR() const; | |
103 | |
104 // Initialize root window's background. | 100 // Initialize root window's background. |
105 void OnRootWindowAdded(aura::RootWindow* root_window); | 101 void OnRootWindowAdded(aura::RootWindow* root_window); |
106 | 102 |
107 // Loads builtin wallpaper asynchronously and sets to current wallpaper after | 103 // Loads builtin wallpaper asynchronously and sets to current wallpaper |
108 // loaded. | 104 // after loaded. Returns true if the controller started loading the |
109 void SetDefaultWallpaper(const WallpaperInfo& info); | 105 // wallpaper and false otherwise (i.e. the appropriate wallpaper was |
| 106 // already loading or loaded). |
| 107 bool SetDefaultWallpaper(bool is_guest); |
110 | 108 |
111 // Sets the user selected custom wallpaper. Called when user selected a file | 109 // Sets the user selected custom wallpaper. Called when user selected a file |
112 // from file system or changed the layout of wallpaper. | 110 // from file system or changed the layout of wallpaper. |
113 void SetCustomWallpaper(const gfx::ImageSkia& wallpaper, | 111 void SetCustomWallpaper(const gfx::ImageSkia& image, WallpaperLayout layout); |
114 WallpaperLayout layout); | |
115 | 112 |
116 // Cancels the current wallpaper loading operation. | 113 // Cancels the current wallpaper loading operation. |
117 void CancelPendingWallpaperOperation(); | 114 void CancelPendingWallpaperOperation(); |
118 | 115 |
119 // Sets the desktop background to solid color mode and creates a solid | 116 // Sets the desktop background to solid color mode and creates a solid |
120 // |color| layout. | 117 // |color| layout. |
121 void SetDesktopBackgroundSolidColorMode(SkColor color); | 118 void SetDesktopBackgroundSolidColorMode(SkColor color); |
122 | 119 |
123 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready | 120 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready |
124 // when running. However, the wallpaper widgets are now created asynchronously | 121 // when running. However, the wallpaper widgets are now created asynchronously |
(...skipping 16 matching lines...) Expand all Loading... |
141 | 138 |
142 // WindowObserver implementation. | 139 // WindowObserver implementation. |
143 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; | 140 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
144 | 141 |
145 private: | 142 private: |
146 friend class internal::DesktopBackgroundControllerTest; | 143 friend class internal::DesktopBackgroundControllerTest; |
147 | 144 |
148 // An operation to asynchronously loads wallpaper. | 145 // An operation to asynchronously loads wallpaper. |
149 class WallpaperLoader; | 146 class WallpaperLoader; |
150 | 147 |
| 148 // Returns true if the specified default wallpaper is already being |
| 149 // loaded by |wallpaper_loader_| or stored in |current_wallpaper_|. |
| 150 bool DefaultWallpaperIsAlreadyLoadingOrLoaded( |
| 151 const base::FilePath& image_file, int image_resource_id) const; |
| 152 |
| 153 // Returns true if the specified custom wallpaper is already stored |
| 154 // in |current_wallpaper_|. |
| 155 bool CustomWallpaperIsAlreadyLoaded(const gfx::ImageSkia& image) const; |
| 156 |
151 // Creates view for all root windows, or notifies them to repaint if they | 157 // Creates view for all root windows, or notifies them to repaint if they |
152 // already exist. | 158 // already exist. |
153 void SetDesktopBackgroundImageMode(); | 159 void SetDesktopBackgroundImageMode(); |
154 | 160 |
155 // Creates a new background widget and sets the background mode to image mode. | 161 // Creates a new background widget and sets the background mode to image mode. |
156 // Called after wallpaper loaded successfully. | 162 // Called after a default wallpaper has been loaded successfully. |
157 void OnWallpaperLoadCompleted(scoped_refptr<WallpaperLoader> wl); | 163 void OnDefaultWallpaperLoadCompleted(scoped_refptr<WallpaperLoader> loader); |
158 | 164 |
159 // Adds layer with solid |color| to container |container_id| in |root_window|. | 165 // Adds layer with solid |color| to container |container_id| in |root_window|. |
160 ui::Layer* SetColorLayerForContainer(SkColor color, | 166 ui::Layer* SetColorLayerForContainer(SkColor color, |
161 aura::RootWindow* root_window, | 167 aura::RootWindow* root_window, |
162 int container_id); | 168 int container_id); |
163 | 169 |
164 // Creates and adds component for current mode (either Widget or Layer) to | 170 // Creates and adds component for current mode (either Widget or Layer) to |
165 // |root_window|. | 171 // |root_window|. |
166 void InstallDesktopController(aura::RootWindow* root_window); | 172 void InstallDesktopController(aura::RootWindow* root_window); |
167 | 173 |
168 // Creates and adds component for current mode (either Widget or Layer) to | 174 // Creates and adds component for current mode (either Widget or Layer) to |
169 // all root windows. | 175 // all root windows. |
170 void InstallDesktopControllerForAllWindows(); | 176 void InstallDesktopControllerForAllWindows(); |
171 | 177 |
172 // Moves all desktop components from one container to other across all root | 178 // Moves all desktop components from one container to other across all root |
173 // windows. Returns true if a desktop moved. | 179 // windows. Returns true if a desktop moved. |
174 bool ReparentBackgroundWidgets(int src_container, int dst_container); | 180 bool ReparentBackgroundWidgets(int src_container, int dst_container); |
175 | 181 |
176 // Returns id for background container for unlocked and locked states. | 182 // Returns id for background container for unlocked and locked states. |
177 int GetBackgroundContainerId(bool locked); | 183 int GetBackgroundContainerId(bool locked); |
178 | 184 |
179 // Send notification that background animation finished. | 185 // Send notification that background animation finished. |
180 void NotifyAnimationFinished(); | 186 void NotifyAnimationFinished(); |
181 | 187 |
| 188 // If non-NULL, used in place of the real command line. |
| 189 CommandLine* command_line_for_testing_; |
| 190 |
182 // Can change at runtime. | 191 // Can change at runtime. |
183 bool locked_; | 192 bool locked_; |
184 | 193 |
185 BackgroundMode desktop_background_mode_; | 194 BackgroundMode desktop_background_mode_; |
186 | 195 |
187 SkColor background_color_; | 196 SkColor background_color_; |
188 | 197 |
189 ObserverList<DesktopBackgroundControllerObserver> observers_; | 198 ObserverList<DesktopBackgroundControllerObserver> observers_; |
190 | 199 |
191 // The current wallpaper. | 200 // The current wallpaper. |
192 scoped_ptr<WallpaperResizer> current_wallpaper_; | 201 scoped_ptr<WallpaperResizer> current_wallpaper_; |
193 | 202 |
| 203 // If a default wallpaper is stored in |current_wallpaper_|, the path and |
| 204 // resource ID that were passed to WallpaperLoader when loading it. |
| 205 // Otherwise, empty and -1, respectively. |
| 206 base::FilePath current_default_wallpaper_path_; |
| 207 int current_default_wallpaper_resource_id_; |
| 208 |
194 scoped_refptr<WallpaperLoader> wallpaper_loader_; | 209 scoped_refptr<WallpaperLoader> wallpaper_loader_; |
195 | 210 |
196 base::WeakPtrFactory<DesktopBackgroundController> weak_ptr_factory_; | 211 base::WeakPtrFactory<DesktopBackgroundController> weak_ptr_factory_; |
197 | 212 |
198 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); | 213 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); |
199 }; | 214 }; |
200 | 215 |
201 } // namespace ash | 216 } // namespace ash |
202 | 217 |
203 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | 218 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ |
OLD | NEW |