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" |
| 14 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
14 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
15 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
16 #include "components/wallpaper/wallpaper_layout.h" | 18 #include "components/wallpaper/wallpaper_layout.h" |
| 19 #include "mojo/public/cpp/bindings/binding_set.h" |
17 #include "ui/gfx/image/image_skia.h" | 20 #include "ui/gfx/image/image_skia.h" |
18 | 21 |
19 namespace base { | 22 namespace base { |
20 class TaskRunner; | 23 class TaskRunner; |
21 } | 24 } |
22 | 25 |
23 namespace wallpaper { | 26 namespace wallpaper { |
24 class WallpaperResizer; | 27 class WallpaperResizer; |
25 } | 28 } |
26 | 29 |
27 namespace ash { | 30 namespace ash { |
28 | 31 |
29 class WallpaperControllerObserver; | 32 class WallpaperControllerObserver; |
30 | 33 |
31 // Controls the desktop background wallpaper. | 34 // Controls the desktop background wallpaper. |
32 class ASH_EXPORT WallpaperController : public WmDisplayObserver, | 35 class ASH_EXPORT WallpaperController |
33 public ShellObserver { | 36 : public NON_EXPORTED_BASE(mojom::WallpaperController), |
| 37 public WmDisplayObserver, |
| 38 public ShellObserver { |
34 public: | 39 public: |
35 enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE }; | 40 enum WallpaperMode { WALLPAPER_NONE, WALLPAPER_IMAGE }; |
36 | 41 |
37 explicit WallpaperController( | 42 explicit WallpaperController( |
38 const scoped_refptr<base::TaskRunner>& task_runner); | 43 const scoped_refptr<base::TaskRunner>& task_runner); |
39 ~WallpaperController() override; | 44 ~WallpaperController() override; |
40 | 45 |
| 46 // Binds the mojom::WallpaperController interface request to this object. |
| 47 void BindRequest(mojom::WallpaperControllerRequest request); |
| 48 |
41 // Add/Remove observers. | 49 // Add/Remove observers. |
42 void AddObserver(WallpaperControllerObserver* observer); | 50 void AddObserver(WallpaperControllerObserver* observer); |
43 void RemoveObserver(WallpaperControllerObserver* observer); | 51 void RemoveObserver(WallpaperControllerObserver* observer); |
44 | 52 |
45 // Provides current image on the wallpaper, or empty gfx::ImageSkia if there | 53 // Provides current image on the wallpaper, or empty gfx::ImageSkia if there |
46 // is no image, e.g. wallpaper is none. | 54 // is no image, e.g. wallpaper is none. |
47 gfx::ImageSkia GetWallpaper() const; | 55 gfx::ImageSkia GetWallpaper() const; |
48 | 56 |
49 wallpaper::WallpaperLayout GetWallpaperLayout() const; | 57 wallpaper::WallpaperLayout GetWallpaperLayout() const; |
50 | 58 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // in |current_wallpaper_|. | 95 // in |current_wallpaper_|. |
88 // If |compare_layouts| is false, layout is ignored. | 96 // If |compare_layouts| is false, layout is ignored. |
89 bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia& image, | 97 bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia& image, |
90 bool compare_layouts, | 98 bool compare_layouts, |
91 wallpaper::WallpaperLayout layout) const; | 99 wallpaper::WallpaperLayout layout) const; |
92 | 100 |
93 void set_wallpaper_reload_delay_for_test(int value) { | 101 void set_wallpaper_reload_delay_for_test(int value) { |
94 wallpaper_reload_delay_ = value; | 102 wallpaper_reload_delay_ = value; |
95 } | 103 } |
96 | 104 |
| 105 // Opens the set wallpaper page in the browser. |
| 106 void OpenSetWallpaperPage(); |
| 107 |
| 108 // mojom::WallpaperController overrides: |
| 109 void SetWallpaper(const SkBitmap& wallpaper, |
| 110 wallpaper::WallpaperLayout layout) override; |
| 111 void GetWallpaper(const GetWallpaperCallback& callback) override; |
| 112 |
97 private: | 113 private: |
98 // Creates a WallpaperWidgetController for |root_window|. | 114 // Creates a WallpaperWidgetController for |root_window|. |
99 void InstallDesktopController(WmWindow* root_window); | 115 void InstallDesktopController(WmWindow* root_window); |
100 | 116 |
101 // Creates a WallpaperWidgetController for all root windows. | 117 // Creates a WallpaperWidgetController for all root windows. |
102 void InstallDesktopControllerForAllWindows(); | 118 void InstallDesktopControllerForAllWindows(); |
103 | 119 |
104 // Moves the wallpaper to the specified container across all root windows. | 120 // Moves the wallpaper to the specified container across all root windows. |
105 // Returns true if a wallpaper moved. | 121 // Returns true if a wallpaper moved. |
106 bool ReparentWallpaper(int container); | 122 bool ReparentWallpaper(int container); |
107 | 123 |
108 // Returns the wallpaper container id for unlocked and locked states. | 124 // Returns the wallpaper container id for unlocked and locked states. |
109 int GetWallpaperContainerId(bool locked); | 125 int GetWallpaperContainerId(bool locked); |
110 | 126 |
111 // Reload the wallpaper. |clear_cache| specifies whether to clear the | 127 // Reload the wallpaper. |clear_cache| specifies whether to clear the |
112 // wallpaper cahce or not. | 128 // wallpaper cahce or not. |
113 void UpdateWallpaper(bool clear_cache); | 129 void UpdateWallpaper(bool clear_cache); |
114 | 130 |
115 bool locked_; | 131 bool locked_; |
116 | 132 |
117 WallpaperMode wallpaper_mode_; | 133 WallpaperMode wallpaper_mode_; |
118 | 134 |
| 135 // Bindings for the WallpaperController interface. |
| 136 mojo::BindingSet<mojom::WallpaperController> bindings_; |
| 137 |
119 base::ObserverList<WallpaperControllerObserver> observers_; | 138 base::ObserverList<WallpaperControllerObserver> observers_; |
120 | 139 |
121 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; | 140 std::unique_ptr<wallpaper::WallpaperResizer> current_wallpaper_; |
122 | 141 |
123 gfx::Size current_max_display_size_; | 142 gfx::Size current_max_display_size_; |
124 | 143 |
125 base::OneShotTimer timer_; | 144 base::OneShotTimer timer_; |
126 | 145 |
127 int wallpaper_reload_delay_; | 146 int wallpaper_reload_delay_; |
128 | 147 |
129 scoped_refptr<base::TaskRunner> task_runner_; | 148 scoped_refptr<base::TaskRunner> task_runner_; |
130 | 149 |
131 DISALLOW_COPY_AND_ASSIGN(WallpaperController); | 150 DISALLOW_COPY_AND_ASSIGN(WallpaperController); |
132 }; | 151 }; |
133 | 152 |
134 } // namespace ash | 153 } // namespace ash |
135 | 154 |
136 #endif // ASH_COMMON_WALLPAPER_WALLPAPER_CONTROLLER_H_ | 155 #endif // ASH_COMMON_WALLPAPER_WALLPAPER_CONTROLLER_H_ |
OLD | NEW |