Chromium Code Reviews| 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 { | 26 namespace chromeos { |
| 27 class CommandLine; | 27 class WallpaperManagerBrowserTestDefaultWallpaper; |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace ash { | 30 namespace ash { |
| 31 | 31 |
| 32 enum WallpaperLayout { | 32 enum WallpaperLayout { |
| 33 // Center the wallpaper on the desktop without scaling it. The wallpaper | 33 // Center the wallpaper on the desktop without scaling it. The wallpaper |
| 34 // may be cropped. | 34 // may be cropped. |
| 35 WALLPAPER_LAYOUT_CENTER, | 35 WALLPAPER_LAYOUT_CENTER, |
| 36 // Scale the wallpaper (while preserving its aspect ratio) to cover the | 36 // Scale the wallpaper (while preserving its aspect ratio) to cover the |
| 37 // desktop; the wallpaper may be cropped. | 37 // desktop; the wallpaper may be cropped. |
| 38 WALLPAPER_LAYOUT_CENTER_CROPPED, | 38 WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 39 // Scale the wallpaper (without preserving its aspect ratio) to match the | 39 // Scale the wallpaper (without preserving its aspect ratio) to match the |
| 40 // desktop's size. | 40 // desktop's size. |
| 41 WALLPAPER_LAYOUT_STRETCH, | 41 WALLPAPER_LAYOUT_STRETCH, |
| 42 // Tile the wallpaper over the background without scaling it. | 42 // Tile the wallpaper over the background without scaling it. |
| 43 WALLPAPER_LAYOUT_TILE, | 43 WALLPAPER_LAYOUT_TILE, |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 enum WallpaperResolution { | |
| 47 WALLPAPER_RESOLUTION_LARGE, | |
| 48 WALLPAPER_RESOLUTION_SMALL | |
| 49 }; | |
| 50 | |
| 51 const SkColor kLoginWallpaperColor = 0xFEFEFE; | 46 const SkColor kLoginWallpaperColor = 0xFEFEFE; |
| 52 | 47 |
| 53 // The width and height of small/large resolution wallpaper. When screen size is | |
| 54 // smaller than |kSmallWallpaperMaxWidth| and |kSmallWallpaperMaxHeight|, the | |
| 55 // small resolution wallpaper should be used. Otherwise, uses the large | |
| 56 // resolution wallpaper. | |
| 57 ASH_EXPORT extern const int kSmallWallpaperMaxWidth; | |
| 58 ASH_EXPORT extern const int kSmallWallpaperMaxHeight; | |
| 59 ASH_EXPORT extern const int kLargeWallpaperMaxWidth; | |
| 60 ASH_EXPORT extern const int kLargeWallpaperMaxHeight; | |
| 61 | |
| 62 // The width and heigh of wallpaper thumbnails. | |
| 63 ASH_EXPORT extern const int kWallpaperThumbnailWidth; | |
| 64 ASH_EXPORT extern const int kWallpaperThumbnailHeight; | |
| 65 | |
| 66 class DesktopBackgroundControllerObserver; | 48 class DesktopBackgroundControllerObserver; |
| 67 class WallpaperResizer; | 49 class WallpaperResizer; |
| 68 | 50 |
| 69 // Loads selected desktop wallpaper from file system asynchronously and updates | 51 // Loads selected desktop wallpaper from file system asynchronously and updates |
|
Daniel Erat
2014/04/04 02:45:49
update this comment
Alexander Alekseev
2014/04/08 13:18:49
Done.
| |
| 70 // background layer if loaded successfully. | 52 // background layer if loaded successfully. |
| 71 class ASH_EXPORT DesktopBackgroundController | 53 class ASH_EXPORT DesktopBackgroundController |
| 72 : public DisplayController::Observer { | 54 : public DisplayController::Observer { |
| 73 public: | 55 public: |
| 74 enum BackgroundMode { | 56 enum BackgroundMode { |
| 75 BACKGROUND_NONE, | 57 BACKGROUND_NONE, |
| 76 BACKGROUND_IMAGE, | 58 BACKGROUND_IMAGE, |
| 77 }; | 59 }; |
| 78 | 60 |
| 79 DesktopBackgroundController(); | 61 DesktopBackgroundController(); |
| 80 virtual ~DesktopBackgroundController(); | 62 virtual ~DesktopBackgroundController(); |
| 81 | 63 |
| 82 BackgroundMode desktop_background_mode() const { | 64 BackgroundMode desktop_background_mode() const { |
| 83 return desktop_background_mode_; | 65 return desktop_background_mode_; |
| 84 } | 66 } |
| 85 | 67 |
| 86 void set_command_line_for_testing(base::CommandLine* command_line) { | |
| 87 command_line_for_testing_ = command_line; | |
| 88 } | |
| 89 | |
| 90 // Add/Remove observers. | 68 // Add/Remove observers. |
| 91 void AddObserver(DesktopBackgroundControllerObserver* observer); | 69 void AddObserver(DesktopBackgroundControllerObserver* observer); |
| 92 void RemoveObserver(DesktopBackgroundControllerObserver* observer); | 70 void RemoveObserver(DesktopBackgroundControllerObserver* observer); |
| 93 | 71 |
| 94 // Provides current image on the background, or empty gfx::ImageSkia if there | 72 // Provides current image on the background, or empty gfx::ImageSkia if there |
| 95 // is no image, e.g. background is none. | 73 // is no image, e.g. background is none. |
| 96 gfx::ImageSkia GetWallpaper() const; | 74 gfx::ImageSkia GetWallpaper() const; |
| 97 | 75 |
| 98 WallpaperLayout GetWallpaperLayout() const; | 76 WallpaperLayout GetWallpaperLayout() const; |
| 99 | 77 |
| 100 // Initialize root window's background. | 78 // Initialize root window's background. |
| 101 void OnRootWindowAdded(aura::Window* root_window); | 79 void OnRootWindowAdded(aura::Window* root_window); |
| 102 | 80 |
| 103 // Loads builtin wallpaper asynchronously and sets to current wallpaper | 81 // Sets wallpaper. This is mostly called by WallpaperManager to set |
| 104 // after loaded. Returns true if the controller started loading the | 82 // the default or user selected custom wallpaper. |
| 105 // wallpaper and false otherwise (i.e. the appropriate wallpaper was | 83 // Returns true if new image was actually set. And false when duplicate set |
| 106 // already loading or loaded). | 84 // request detected. |
| 107 bool SetDefaultWallpaper(bool is_guest); | 85 bool SetWallpaper(const gfx::ImageSkia& image, WallpaperLayout layout); |
| 108 | 86 // The same, but image from resources is used. |
| 109 // Sets the user selected custom wallpaper. Called when user selected a file | 87 bool SetWallpaper(int resource_id, WallpaperLayout layout); |
|
Daniel Erat
2014/04/04 02:45:49
i'm not sure that we still need to support resourc
Alexander Alekseev
2014/04/05 03:35:13
Done.
| |
| 110 // from file system or changed the layout of wallpaper. | |
| 111 void SetCustomWallpaper(const gfx::ImageSkia& image, WallpaperLayout layout); | |
| 112 | |
| 113 // Cancels |default_wallpaper_loader_| if non-NULL. | |
| 114 void CancelDefaultWallpaperLoader(); | |
| 115 | 88 |
| 116 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready | 89 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready |
| 117 // when running. However, the wallpaper widgets are now created | 90 // when running. However, the wallpaper widgets are now created |
| 118 // asynchronously. If loading a real wallpaper, there are cases that these | 91 // asynchronously. If loading a real wallpaper, there are cases that these |
| 119 // tests crash because the required widget is not ready. This function | 92 // tests crash because the required widget is not ready. This function |
| 120 // synchronously creates an empty widget for those tests to prevent | 93 // synchronously creates an empty widget for those tests to prevent |
| 121 // crashes. An example test is SystemGestureEventFilterTest.ThreeFingerSwipe. | 94 // crashes. An example test is SystemGestureEventFilterTest.ThreeFingerSwipe. |
| 122 void CreateEmptyWallpaper(); | 95 void CreateEmptyWallpaper(); |
| 123 | 96 |
| 124 // Returns the appropriate wallpaper resolution for all root windows. | |
| 125 WallpaperResolution GetAppropriateResolution(); | |
| 126 | |
| 127 // Move all desktop widgets to locked container. | 97 // Move all desktop widgets to locked container. |
| 128 // Returns true if the desktop moved. | 98 // Returns true if the desktop moved. |
| 129 bool MoveDesktopToLockedContainer(); | 99 bool MoveDesktopToLockedContainer(); |
| 130 | 100 |
| 131 // Move all desktop widgets to unlocked container. | 101 // Move all desktop widgets to unlocked container. |
| 132 // Returns true if the desktop moved. | 102 // Returns true if the desktop moved. |
| 133 bool MoveDesktopToUnlockedContainer(); | 103 bool MoveDesktopToUnlockedContainer(); |
| 134 | 104 |
| 135 // Overrides DisplayController::Observer: | 105 // Overrides DisplayController::Observer: |
| 136 virtual void OnDisplayConfigurationChanged() OVERRIDE; | 106 virtual void OnDisplayConfigurationChanged() OVERRIDE; |
| 137 | 107 |
| 108 // Returns the maximum size of all displays combined in native | |
| 109 // resolutions. Note that this isn't the bounds of the display who | |
| 110 // has maximum resolutions. Instead, this returns the size of the | |
| 111 // maximum width of all displays, and the maximum height of all displays. | |
| 112 static gfx::Size GetMaxDisplaySizeInNative(); | |
| 113 | |
| 138 private: | 114 private: |
| 139 friend class DesktopBackgroundControllerTest; | 115 friend class DesktopBackgroundControllerTest; |
| 116 friend class chromeos::WallpaperManagerBrowserTestDefaultWallpaper; | |
| 140 FRIEND_TEST_ALL_PREFIXES(DesktopBackgroundControllerTest, GetMaxDisplaySize); | 117 FRIEND_TEST_ALL_PREFIXES(DesktopBackgroundControllerTest, GetMaxDisplaySize); |
| 141 | 118 |
| 142 // An operation to asynchronously loads wallpaper. | 119 // Returns true if the specified wallpaper is already stored |
| 143 class WallpaperLoader; | |
| 144 | |
| 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_|. | 120 // in |current_wallpaper_|. |
| 152 bool CustomWallpaperIsAlreadyLoaded(const gfx::ImageSkia& image) const; | 121 // If |image| is NULL, resource_id is compared. |
| 122 bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia* image, | |
| 123 int resource_id, | |
| 124 WallpaperLayout layout) const; | |
| 153 | 125 |
| 154 // Creates view for all root windows, or notifies them to repaint if they | 126 // Creates view for all root windows, or notifies them to repaint if they |
| 155 // already exist. | 127 // already exist. |
| 156 void SetDesktopBackgroundImageMode(); | 128 void SetDesktopBackgroundImageMode(); |
| 157 | 129 |
| 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 | 130 // Creates and adds component for current mode (either Widget or Layer) to |
| 163 // |root_window|. | 131 // |root_window|. |
| 164 void InstallDesktopController(aura::Window* root_window); | 132 void InstallDesktopController(aura::Window* root_window); |
| 165 | 133 |
| 166 // Creates and adds component for current mode (either Widget or Layer) to | 134 // Creates and adds component for current mode (either Widget or Layer) to |
| 167 // all root windows. | 135 // all root windows. |
| 168 void InstallDesktopControllerForAllWindows(); | 136 void InstallDesktopControllerForAllWindows(); |
| 169 | 137 |
| 170 // Moves all desktop components from one container to other across all root | 138 // Moves all desktop components from one container to other across all root |
| 171 // windows. Returns true if a desktop moved. | 139 // windows. Returns true if a desktop moved. |
| 172 bool ReparentBackgroundWidgets(int src_container, int dst_container); | 140 bool ReparentBackgroundWidgets(int src_container, int dst_container); |
| 173 | 141 |
| 174 // Returns id for background container for unlocked and locked states. | 142 // Returns id for background container for unlocked and locked states. |
| 175 int GetBackgroundContainerId(bool locked); | 143 int GetBackgroundContainerId(bool locked); |
| 176 | 144 |
| 177 // Send notification that background animation finished. | 145 // Send notification that background animation finished. |
| 178 void NotifyAnimationFinished(); | 146 void NotifyAnimationFinished(); |
| 179 | 147 |
| 180 // Reload the wallpaper. | 148 // Reload the wallpaper. |
| 181 void UpdateWallpaper(); | 149 void UpdateWallpaper(); |
| 182 | 150 |
| 183 void set_wallpaper_reload_delay_for_test(bool value) { | 151 void set_wallpaper_reload_delay_for_test(bool value) { |
| 184 wallpaper_reload_delay_ = value; | 152 wallpaper_reload_delay_ = value; |
| 185 } | 153 } |
| 186 | 154 |
| 187 // Returns the maximum size of all displays combined in native | |
| 188 // resolutions. Note that this isn't the bounds of the display who | |
| 189 // has maximum resolutions. Instead, this returns the size of the | |
| 190 // maximum width of all displays, and the maximum height of all displays. | |
| 191 static gfx::Size GetMaxDisplaySizeInNative(); | |
| 192 | |
| 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. | 155 // Can change at runtime. |
| 197 bool locked_; | 156 bool locked_; |
| 198 | 157 |
| 199 BackgroundMode desktop_background_mode_; | 158 BackgroundMode desktop_background_mode_; |
| 200 | 159 |
| 201 SkColor background_color_; | 160 SkColor background_color_; |
| 202 | 161 |
| 203 ObserverList<DesktopBackgroundControllerObserver> observers_; | 162 ObserverList<DesktopBackgroundControllerObserver> observers_; |
| 204 | 163 |
| 205 // The current wallpaper. | 164 // The current wallpaper. |
| 206 scoped_ptr<WallpaperResizer> current_wallpaper_; | 165 scoped_ptr<WallpaperResizer> current_wallpaper_; |
| 207 | 166 |
| 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_; | 167 gfx::Size current_max_display_size_; |
| 215 | 168 |
| 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_; | 169 base::OneShotTimer<DesktopBackgroundController> timer_; |
| 222 | 170 |
| 223 int wallpaper_reload_delay_; | 171 int wallpaper_reload_delay_; |
| 224 | 172 |
| 225 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); | 173 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); |
| 226 }; | 174 }; |
| 227 | 175 |
| 228 } // namespace ash | 176 } // namespace ash |
| 229 | 177 |
| 230 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | 178 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ |
| OLD | NEW |