| 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_COMMON_WALLPAPER_WALLPAPER_CONTROLLER_H_ | 5 #ifndef ASH_COMMON_WALLPAPER_WALLPAPER_CONTROLLER_H_ |
| 6 #define ASH_COMMON_WALLPAPER_WALLPAPER_CONTROLLER_H_ | 6 #define ASH_COMMON_WALLPAPER_WALLPAPER_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 11 #include "ash/common/shell_observer.h" | 11 #include "ash/common/shell_observer.h" |
| 12 #include "ash/common/wm_display_observer.h" | 12 #include "ash/common/wm_display_observer.h" |
| 13 #include "ash/public/interfaces/wallpaper.mojom.h" | 13 #include "ash/public/interfaces/wallpaper.mojom.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
| 18 #include "components/wallpaper/wallpaper_color_calculator_observer.h" |
| 18 #include "components/wallpaper/wallpaper_layout.h" | 19 #include "components/wallpaper/wallpaper_layout.h" |
| 20 #include "components/wallpaper/wallpaper_resizer_observer.h" |
| 19 #include "mojo/public/cpp/bindings/binding_set.h" | 21 #include "mojo/public/cpp/bindings/binding_set.h" |
| 22 #include "ui/gfx/color_analysis.h" |
| 20 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
| 21 | 24 |
| 22 namespace base { | 25 namespace base { |
| 23 class TaskRunner; | 26 class TaskRunner; |
| 24 } | 27 } |
| 25 | 28 |
| 26 namespace wallpaper { | 29 namespace wallpaper { |
| 30 class WallpaperColorCalculator; |
| 27 class WallpaperResizer; | 31 class WallpaperResizer; |
| 28 } | 32 } |
| 29 | 33 |
| 30 namespace ash { | 34 namespace ash { |
| 31 | 35 |
| 32 class WallpaperControllerObserver; | 36 class WallpaperControllerObserver; |
| 33 | 37 |
| 34 // Controls the desktop background wallpaper. | 38 // Controls the desktop background wallpaper. |
| 35 class ASH_EXPORT WallpaperController | 39 class ASH_EXPORT WallpaperController |
| 36 : public NON_EXPORTED_BASE(mojom::WallpaperController), | 40 : public NON_EXPORTED_BASE(mojom::WallpaperController), |
| 37 public WmDisplayObserver, | 41 public WmDisplayObserver, |
| 38 public ShellObserver { | 42 public ShellObserver, |
| 43 public wallpaper::WallpaperResizerObserver, |
| 44 public wallpaper::WallpaperColorCalculatorObserver { |
| 39 public: | 45 public: |
| 40 enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE }; | 46 enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE }; |
| 41 | 47 |
| 42 explicit WallpaperController( | 48 explicit WallpaperController( |
| 43 const scoped_refptr<base::TaskRunner>& task_runner); | 49 const scoped_refptr<base::TaskRunner>& task_runner); |
| 44 ~WallpaperController() override; | 50 ~WallpaperController() override; |
| 45 | 51 |
| 46 // Binds the mojom::WallpaperController interface request to this object. | 52 // Binds the mojom::WallpaperController interface request to this object. |
| 47 void BindRequest(mojom::WallpaperControllerRequest request); | 53 void BindRequest(mojom::WallpaperControllerRequest request); |
| 48 | 54 |
| 49 // Add/Remove observers. | 55 // Add/Remove observers. |
| 50 void AddObserver(WallpaperControllerObserver* observer); | 56 void AddObserver(WallpaperControllerObserver* observer); |
| 51 void RemoveObserver(WallpaperControllerObserver* observer); | 57 void RemoveObserver(WallpaperControllerObserver* observer); |
| 52 | 58 |
| 59 SkColor prominent_color() const { return prominent_color_; } |
| 60 |
| 53 // Provides current image on the wallpaper, or empty gfx::ImageSkia if there | 61 // Provides current image on the wallpaper, or empty gfx::ImageSkia if there |
| 54 // is no image, e.g. wallpaper is none. | 62 // is no image, e.g. wallpaper is none. |
| 55 gfx::ImageSkia GetWallpaper() const; | 63 gfx::ImageSkia GetWallpaper() const; |
| 56 | 64 |
| 57 wallpaper::WallpaperLayout GetWallpaperLayout() const; | 65 wallpaper::WallpaperLayout GetWallpaperLayout() const; |
| 58 | 66 |
| 59 // Sets the wallpaper and alerts observers of changes. | 67 // Sets the wallpaper and alerts observers of changes. |
| 60 void SetWallpaperImage(const gfx::ImageSkia& image, | 68 void SetWallpaperImage(const gfx::ImageSkia& image, |
| 61 wallpaper::WallpaperLayout layout); | 69 wallpaper::WallpaperLayout layout); |
| 62 | 70 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 108 } |
| 101 | 109 |
| 102 // Opens the set wallpaper page in the browser. | 110 // Opens the set wallpaper page in the browser. |
| 103 void OpenSetWallpaperPage(); | 111 void OpenSetWallpaperPage(); |
| 104 | 112 |
| 105 // mojom::WallpaperController overrides: | 113 // mojom::WallpaperController overrides: |
| 106 void SetWallpaperPicker(mojom::WallpaperPickerPtr picker) override; | 114 void SetWallpaperPicker(mojom::WallpaperPickerPtr picker) override; |
| 107 void SetWallpaper(const SkBitmap& wallpaper, | 115 void SetWallpaper(const SkBitmap& wallpaper, |
| 108 wallpaper::WallpaperLayout layout) override; | 116 wallpaper::WallpaperLayout layout) override; |
| 109 | 117 |
| 118 // WallpaperResizerObserver: |
| 119 void OnWallpaperResized() override; |
| 120 |
| 121 // WallpaperColorCalculatorObserver: |
| 122 void OnColorCalculationComplete() override; |
| 123 |
| 110 private: | 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 |
| 111 // Creates a WallpaperWidgetController for |root_window|. | 131 // Creates a WallpaperWidgetController for |root_window|. |
| 112 void InstallDesktopController(WmWindow* root_window); | 132 void InstallDesktopController(WmWindow* root_window); |
| 113 | 133 |
| 114 // Creates a WallpaperWidgetController for all root windows. | 134 // Creates a WallpaperWidgetController for all root windows. |
| 115 void InstallDesktopControllerForAllWindows(); | 135 void InstallDesktopControllerForAllWindows(); |
| 116 | 136 |
| 117 // Moves the wallpaper to the specified container across all root windows. | 137 // Moves the wallpaper to the specified container across all root windows. |
| 118 // Returns true if a wallpaper moved. | 138 // Returns true if a wallpaper moved. |
| 119 bool ReparentWallpaper(int container); | 139 bool ReparentWallpaper(int container); |
| 120 | 140 |
| 121 // Returns the wallpaper container id for unlocked and locked states. | 141 // Returns the wallpaper container id for unlocked and locked states. |
| 122 int GetWallpaperContainerId(bool locked); | 142 int GetWallpaperContainerId(bool locked); |
| 123 | 143 |
| 124 // Reload the wallpaper. |clear_cache| specifies whether to clear the | 144 // Reload the wallpaper. |clear_cache| specifies whether to clear the |
| 125 // wallpaper cahce or not. | 145 // wallpaper cahce or not. |
| 126 void UpdateWallpaper(bool clear_cache); | 146 void UpdateWallpaper(bool clear_cache); |
| 127 | 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 |
| 128 bool locked_; | 155 bool locked_; |
| 129 | 156 |
| 130 WallpaperMode wallpaper_mode_; | 157 WallpaperMode wallpaper_mode_; |
| 131 | 158 |
| 132 // Wallpaper picker interface in chrome browser, used to open the picker. | 159 // Wallpaper picker interface in chrome browser, used to open the picker. |
| 133 mojom::WallpaperPickerPtr wallpaper_picker_; | 160 mojom::WallpaperPickerPtr wallpaper_picker_; |
| 134 | 161 |
| 135 // Bindings for the WallpaperController interface. | 162 // Bindings for the WallpaperController interface. |
| 136 mojo::BindingSet<mojom::WallpaperController> bindings_; | 163 mojo::BindingSet<mojom::WallpaperController> bindings_; |
| 137 | 164 |
| 138 base::ObserverList<WallpaperControllerObserver> observers_; | 165 base::ObserverList<WallpaperControllerObserver> observers_; |
| 139 | 166 |
| 140 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; | 167 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; |
| 141 | 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 |
| 142 gfx::Size current_max_display_size_; | 176 gfx::Size current_max_display_size_; |
| 143 | 177 |
| 144 base::OneShotTimer timer_; | 178 base::OneShotTimer timer_; |
| 145 | 179 |
| 146 int wallpaper_reload_delay_; | 180 int wallpaper_reload_delay_; |
| 147 | 181 |
| 148 scoped_refptr<base::TaskRunner> task_runner_; | 182 scoped_refptr<base::TaskRunner> task_runner_; |
| 149 | 183 |
| 150 DISALLOW_COPY_AND_ASSIGN(WallpaperController); | 184 DISALLOW_COPY_AND_ASSIGN(WallpaperController); |
| 151 }; | 185 }; |
| 152 | 186 |
| 153 } // namespace ash | 187 } // namespace ash |
| 154 | 188 |
| 155 #endif // ASH_COMMON_WALLPAPER_WALLPAPER_CONTROLLER_H_ | 189 #endif // ASH_COMMON_WALLPAPER_WALLPAPER_CONTROLLER_H_ |
| OLD | NEW |