| 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_WALLPAPER_WALLPAPER_CONTROLLER_H_ | |
| 6 #define ASH_WALLPAPER_WALLPAPER_CONTROLLER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "ash/ash_export.h" | |
| 11 #include "ash/public/interfaces/wallpaper.mojom.h" | |
| 12 #include "ash/shell_observer.h" | |
| 13 #include "ash/wm_display_observer.h" | |
| 14 #include "base/compiler_specific.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "base/observer_list.h" | |
| 17 #include "base/timer/timer.h" | |
| 18 #include "components/wallpaper/wallpaper_color_calculator_observer.h" | |
| 19 #include "components/wallpaper/wallpaper_layout.h" | |
| 20 #include "components/wallpaper/wallpaper_resizer_observer.h" | |
| 21 #include "mojo/public/cpp/bindings/binding_set.h" | |
| 22 #include "ui/gfx/color_analysis.h" | |
| 23 #include "ui/gfx/image/image_skia.h" | |
| 24 | |
| 25 namespace base { | |
| 26 class TaskRunner; | |
| 27 } | |
| 28 | |
| 29 namespace wallpaper { | |
| 30 class WallpaperColorCalculator; | |
| 31 class WallpaperResizer; | |
| 32 } | |
| 33 | |
| 34 namespace ash { | |
| 35 | |
| 36 class WallpaperControllerObserver; | |
| 37 | |
| 38 // Controls the desktop background wallpaper. | |
| 39 class ASH_EXPORT WallpaperController | |
| 40 : public NON_EXPORTED_BASE(mojom::WallpaperController), | |
| 41 public WmDisplayObserver, | |
| 42 public ShellObserver, | |
| 43 public wallpaper::WallpaperResizerObserver, | |
| 44 public wallpaper::WallpaperColorCalculatorObserver { | |
| 45 public: | |
| 46 enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE }; | |
| 47 | |
| 48 explicit WallpaperController( | |
| 49 const scoped_refptr<base::TaskRunner>& task_runner); | |
| 50 ~WallpaperController() override; | |
| 51 | |
| 52 // Binds the mojom::WallpaperController interface request to this object. | |
| 53 void BindRequest(mojom::WallpaperControllerRequest request); | |
| 54 | |
| 55 // Add/Remove observers. | |
| 56 void AddObserver(WallpaperControllerObserver* observer); | |
| 57 void RemoveObserver(WallpaperControllerObserver* observer); | |
| 58 | |
| 59 SkColor prominent_color() const { return prominent_color_; } | |
| 60 | |
| 61 // Provides current image on the wallpaper, or empty gfx::ImageSkia if there | |
| 62 // is no image, e.g. wallpaper is none. | |
| 63 gfx::ImageSkia GetWallpaper() const; | |
| 64 | |
| 65 wallpaper::WallpaperLayout GetWallpaperLayout() const; | |
| 66 | |
| 67 // Sets the wallpaper and alerts observers of changes. | |
| 68 void SetWallpaperImage(const gfx::ImageSkia& image, | |
| 69 wallpaper::WallpaperLayout layout); | |
| 70 | |
| 71 // Creates an empty wallpaper. Some tests require a wallpaper widget is ready | |
| 72 // when running. However, the wallpaper widgets are now created | |
| 73 // asynchronously. If loading a real wallpaper, there are cases that these | |
| 74 // tests crash because the required widget is not ready. This function | |
| 75 // synchronously creates an empty widget for those tests to prevent | |
| 76 // crashes. An example test is SystemGestureEventFilterTest.ThreeFingerSwipe. | |
| 77 void CreateEmptyWallpaper(); | |
| 78 | |
| 79 // Move all wallpaper widgets to the locked container. | |
| 80 // Returns true if the wallpaper moved. | |
| 81 bool MoveToLockedContainer(); | |
| 82 | |
| 83 // Move all wallpaper widgets to unlocked container. | |
| 84 // Returns true if the wallpaper moved. | |
| 85 bool MoveToUnlockedContainer(); | |
| 86 | |
| 87 // WmDisplayObserver: | |
| 88 void OnDisplayConfigurationChanged() override; | |
| 89 | |
| 90 // ShellObserver: | |
| 91 void OnRootWindowAdded(WmWindow* root_window) override; | |
| 92 | |
| 93 // Returns the maximum size of all displays combined in native | |
| 94 // resolutions. Note that this isn't the bounds of the display who | |
| 95 // has maximum resolutions. Instead, this returns the size of the | |
| 96 // maximum width of all displays, and the maximum height of all displays. | |
| 97 static gfx::Size GetMaxDisplaySizeInNative(); | |
| 98 | |
| 99 // Returns true if the specified wallpaper is already stored | |
| 100 // in |current_wallpaper_|. | |
| 101 // If |compare_layouts| is false, layout is ignored. | |
| 102 bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia& image, | |
| 103 bool compare_layouts, | |
| 104 wallpaper::WallpaperLayout layout) const; | |
| 105 | |
| 106 void set_wallpaper_reload_delay_for_test(int value) { | |
| 107 wallpaper_reload_delay_ = value; | |
| 108 } | |
| 109 | |
| 110 // Opens the set wallpaper page in the browser. | |
| 111 void OpenSetWallpaperPage(); | |
| 112 | |
| 113 // mojom::WallpaperController overrides: | |
| 114 void SetWallpaperPicker(mojom::WallpaperPickerPtr picker) override; | |
| 115 void SetWallpaper(const SkBitmap& wallpaper, | |
| 116 wallpaper::WallpaperLayout layout) override; | |
| 117 | |
| 118 // WallpaperResizerObserver: | |
| 119 void OnWallpaperResized() override; | |
| 120 | |
| 121 // WallpaperColorCalculatorObserver: | |
| 122 void OnColorCalculationComplete() override; | |
| 123 | |
| 124 private: | |
| 125 // Returns true if the shelf should be colored based on the wallpaper's | |
| 126 // prominent color. |luma| and |saturation| are output parameters. | |
| 127 static bool GetProminentColorProfile( | |
| 128 color_utils::LumaRange* luma, | |
| 129 color_utils::SaturationRange* saturation); | |
| 130 | |
| 131 // Creates a WallpaperWidgetController for |root_window|. | |
| 132 void InstallDesktopController(WmWindow* root_window); | |
| 133 | |
| 134 // Creates a WallpaperWidgetController for all root windows. | |
| 135 void InstallDesktopControllerForAllWindows(); | |
| 136 | |
| 137 // Moves the wallpaper to the specified container across all root windows. | |
| 138 // Returns true if a wallpaper moved. | |
| 139 bool ReparentWallpaper(int container); | |
| 140 | |
| 141 // Returns the wallpaper container id for unlocked and locked states. | |
| 142 int GetWallpaperContainerId(bool locked); | |
| 143 | |
| 144 // Reload the wallpaper. |clear_cache| specifies whether to clear the | |
| 145 // wallpaper cahce or not. | |
| 146 void UpdateWallpaper(bool clear_cache); | |
| 147 | |
| 148 // Sets |prominent_color_| and notifies the observers if there is a change. | |
| 149 void SetProminentColor(SkColor color); | |
| 150 | |
| 151 // If enabled, will initiates an asynchronous task to extract colors from the | |
| 152 // wallpaper. If an existing calculation is in progress it is destroyed. | |
| 153 void CalculateWallpaperColors(); | |
| 154 | |
| 155 bool locked_; | |
| 156 | |
| 157 WallpaperMode wallpaper_mode_; | |
| 158 | |
| 159 // Wallpaper picker interface in chrome browser, used to open the picker. | |
| 160 mojom::WallpaperPickerPtr wallpaper_picker_; | |
| 161 | |
| 162 // Bindings for the WallpaperController interface. | |
| 163 mojo::BindingSet<mojom::WallpaperController> bindings_; | |
| 164 | |
| 165 base::ObserverList<WallpaperControllerObserver> observers_; | |
| 166 | |
| 167 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; | |
| 168 | |
| 169 // Asynchronous task to extract colors from the wallpaper. | |
| 170 std::unique_ptr<wallpaper::WallpaperColorCalculator> color_calculator_; | |
| 171 | |
| 172 // The prominent color extracted from the current wallpaper. | |
| 173 // SK_ColorTRANSPARENT is used by default or if extracting colors fails. | |
| 174 SkColor prominent_color_; | |
| 175 | |
| 176 gfx::Size current_max_display_size_; | |
| 177 | |
| 178 base::OneShotTimer timer_; | |
| 179 | |
| 180 int wallpaper_reload_delay_; | |
| 181 | |
| 182 scoped_refptr<base::TaskRunner> task_runner_; | |
| 183 | |
| 184 DISALLOW_COPY_AND_ASSIGN(WallpaperController); | |
| 185 }; | |
| 186 | |
| 187 } // namespace ash | |
| 188 | |
| 189 #endif // ASH_WALLPAPER_WALLPAPER_CONTROLLER_H_ | |
| OLD | NEW |