| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | |
| 6 #define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "ash/ash_export.h" | |
| 11 #include "ash/common/shell_observer.h" | |
| 12 #include "ash/common/wm_display_observer.h" | |
| 13 #include "base/observer_list.h" | |
| 14 #include "base/timer/timer.h" | |
| 15 #include "components/wallpaper/wallpaper_layout.h" | |
| 16 #include "ui/gfx/image/image_skia.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class SequencedWorkerPool; | |
| 20 } | |
| 21 | |
| 22 namespace wallpaper { | |
| 23 class WallpaperResizer; | |
| 24 } | |
| 25 | |
| 26 namespace ash { | |
| 27 | |
| 28 class DesktopBackgroundControllerObserver; | |
| 29 | |
| 30 // Updates the desktop background wallpaper. | |
| 31 class ASH_EXPORT DesktopBackgroundController : public WmDisplayObserver, | |
| 32 public ShellObserver { | |
| 33 public: | |
| 34 enum BackgroundMode { BACKGROUND_NONE, BACKGROUND_IMAGE }; | |
| 35 | |
| 36 explicit DesktopBackgroundController( | |
| 37 base::SequencedWorkerPool* blocking_pool); | |
| 38 ~DesktopBackgroundController() override; | |
| 39 | |
| 40 // Add/Remove observers. | |
| 41 void AddObserver(DesktopBackgroundControllerObserver* observer); | |
| 42 void RemoveObserver(DesktopBackgroundControllerObserver* observer); | |
| 43 | |
| 44 // Provides current image on the background, or empty gfx::ImageSkia if there | |
| 45 // is no image, e.g. background is none. | |
| 46 gfx::ImageSkia GetWallpaper() const; | |
| 47 | |
| 48 wallpaper::WallpaperLayout GetWallpaperLayout() const; | |
| 49 | |
| 50 // Sets wallpaper. This is mostly called by WallpaperManager to set | |
| 51 // the default or user selected custom wallpaper. | |
| 52 // Returns true if new image was actually set. And false when duplicate set | |
| 53 // request detected. | |
| 54 bool SetWallpaperImage(const gfx::ImageSkia& image, | |
| 55 wallpaper::WallpaperLayout layout); | |
| 56 | |
| 57 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready | |
| 58 // when running. However, the wallpaper widgets are now created | |
| 59 // asynchronously. If loading a real wallpaper, there are cases that these | |
| 60 // tests crash because the required widget is not ready. This function | |
| 61 // synchronously creates an empty widget for those tests to prevent | |
| 62 // crashes. An example test is SystemGestureEventFilterTest.ThreeFingerSwipe. | |
| 63 void CreateEmptyWallpaper(); | |
| 64 | |
| 65 // Move all desktop widgets to locked container. | |
| 66 // Returns true if the desktop moved. | |
| 67 bool MoveDesktopToLockedContainer(); | |
| 68 | |
| 69 // Move all desktop widgets to unlocked container. | |
| 70 // Returns true if the desktop moved. | |
| 71 bool MoveDesktopToUnlockedContainer(); | |
| 72 | |
| 73 // WmDisplayObserver: | |
| 74 void OnDisplayConfigurationChanged() override; | |
| 75 | |
| 76 // ShellObserver: | |
| 77 void OnRootWindowAdded(WmWindow* root_window) override; | |
| 78 | |
| 79 // Returns the maximum size of all displays combined in native | |
| 80 // resolutions. Note that this isn't the bounds of the display who | |
| 81 // has maximum resolutions. Instead, this returns the size of the | |
| 82 // maximum width of all displays, and the maximum height of all displays. | |
| 83 static gfx::Size GetMaxDisplaySizeInNative(); | |
| 84 | |
| 85 // Returns true if the specified wallpaper is already stored | |
| 86 // in |current_wallpaper_|. | |
| 87 // If |compare_layouts| is false, layout is ignored. | |
| 88 bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia& image, | |
| 89 bool compare_layouts, | |
| 90 wallpaper::WallpaperLayout layout) const; | |
| 91 | |
| 92 void set_wallpaper_reload_delay_for_test(int value) { | |
| 93 wallpaper_reload_delay_ = value; | |
| 94 } | |
| 95 | |
| 96 private: | |
| 97 // Creates a DesktopBackgroundWidgetController for |root_window|. | |
| 98 void InstallDesktopController(WmWindow* root_window); | |
| 99 | |
| 100 // Creates a DesktopBackgroundWidgetController for all root windows. | |
| 101 void InstallDesktopControllerForAllWindows(); | |
| 102 | |
| 103 // Moves all desktop components from one container to other across all root | |
| 104 // windows. Returns true if a desktop moved. | |
| 105 bool ReparentBackgroundWidgets(int src_container, int dst_container); | |
| 106 | |
| 107 // Returns id for background container for unlocked and locked states. | |
| 108 int GetBackgroundContainerId(bool locked); | |
| 109 | |
| 110 // Reload the wallpaper. |clear_cache| specifies whether to clear the | |
| 111 // wallpaper cahce or not. | |
| 112 void UpdateWallpaper(bool clear_cache); | |
| 113 | |
| 114 bool locked_; | |
| 115 | |
| 116 BackgroundMode desktop_background_mode_; | |
| 117 | |
| 118 base::ObserverList<DesktopBackgroundControllerObserver> observers_; | |
| 119 | |
| 120 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; | |
| 121 | |
| 122 gfx::Size current_max_display_size_; | |
| 123 | |
| 124 base::OneShotTimer timer_; | |
| 125 | |
| 126 int wallpaper_reload_delay_; | |
| 127 | |
| 128 base::SequencedWorkerPool* blocking_pool_; | |
| 129 | |
| 130 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundController); | |
| 131 }; | |
| 132 | |
| 133 } // namespace ash | |
| 134 | |
| 135 #endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_H_ | |
| OLD | NEW |