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