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