Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: ash/wallpaper/wallpaper_controller.cc

Issue 2290473004: Rename ash desktop_background to wallpaper. (Closed)
Patch Set: Cleanup Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "ash/desktop_background/desktop_background_controller.h" 5 #include "ash/wallpaper/wallpaper_controller.h"
6 6
7 #include "ash/aura/wm_window_aura.h" 7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/display/display_info.h" 8 #include "ash/common/display/display_info.h"
9 #include "ash/common/shell_window_ids.h" 9 #include "ash/common/shell_window_ids.h"
10 #include "ash/common/wallpaper/wallpaper_delegate.h" 10 #include "ash/common/wallpaper/wallpaper_delegate.h"
11 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
12 #include "ash/desktop_background/desktop_background_controller_observer.h"
13 #include "ash/desktop_background/desktop_background_view.h"
14 #include "ash/desktop_background/desktop_background_widget_controller.h"
15 #include "ash/root_window_controller.h" 12 #include "ash/root_window_controller.h"
16 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "ash/wallpaper/wallpaper_controller_observer.h"
15 #include "ash/wallpaper/wallpaper_view.h"
16 #include "ash/wallpaper/wallpaper_widget_controller.h"
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/threading/sequenced_worker_pool.h" 19 #include "base/threading/sequenced_worker_pool.h"
20 #include "components/wallpaper/wallpaper_resizer.h" 20 #include "components/wallpaper/wallpaper_resizer.h"
21 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
22 #include "ui/display/screen.h" 22 #include "ui/display/screen.h"
23 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
24 24
25 namespace ash { 25 namespace ash {
26 namespace { 26 namespace {
27 27
28 // How long to wait reloading the wallpaper after the display size has changed. 28 // How long to wait reloading the wallpaper after the display size has changed.
29 const int kWallpaperReloadDelayMs = 100; 29 const int kWallpaperReloadDelayMs = 100;
30 30
31 } // namespace 31 } // namespace
32 32
33 DesktopBackgroundController::DesktopBackgroundController( 33 WallpaperController::WallpaperController(
34 base::SequencedWorkerPool* blocking_pool) 34 base::SequencedWorkerPool* blocking_pool)
35 : locked_(false), 35 : locked_(false),
36 desktop_background_mode_(BACKGROUND_NONE), 36 wallpaper_mode_(WALLPAPER_NONE),
37 wallpaper_reload_delay_(kWallpaperReloadDelayMs), 37 wallpaper_reload_delay_(kWallpaperReloadDelayMs),
38 blocking_pool_(blocking_pool) { 38 blocking_pool_(blocking_pool) {
39 WmShell::Get()->AddDisplayObserver(this); 39 WmShell::Get()->AddDisplayObserver(this);
40 WmShell::Get()->AddShellObserver(this); 40 WmShell::Get()->AddShellObserver(this);
41 } 41 }
42 42
43 DesktopBackgroundController::~DesktopBackgroundController() { 43 WallpaperController::~WallpaperController() {
44 WmShell::Get()->RemoveDisplayObserver(this); 44 WmShell::Get()->RemoveDisplayObserver(this);
45 WmShell::Get()->RemoveShellObserver(this); 45 WmShell::Get()->RemoveShellObserver(this);
46 } 46 }
47 47
48 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { 48 gfx::ImageSkia WallpaperController::GetWallpaper() const {
49 if (current_wallpaper_) 49 if (current_wallpaper_)
50 return current_wallpaper_->image(); 50 return current_wallpaper_->image();
51 return gfx::ImageSkia(); 51 return gfx::ImageSkia();
52 } 52 }
53 53
54 void DesktopBackgroundController::AddObserver( 54 void WallpaperController::AddObserver(WallpaperControllerObserver* observer) {
55 DesktopBackgroundControllerObserver* observer) {
56 observers_.AddObserver(observer); 55 observers_.AddObserver(observer);
57 } 56 }
58 57
59 void DesktopBackgroundController::RemoveObserver( 58 void WallpaperController::RemoveObserver(
60 DesktopBackgroundControllerObserver* observer) { 59 WallpaperControllerObserver* observer) {
61 observers_.RemoveObserver(observer); 60 observers_.RemoveObserver(observer);
62 } 61 }
63 62
64 wallpaper::WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() 63 wallpaper::WallpaperLayout WallpaperController::GetWallpaperLayout() const {
65 const {
66 if (current_wallpaper_) 64 if (current_wallpaper_)
67 return current_wallpaper_->layout(); 65 return current_wallpaper_->layout();
68 return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; 66 return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED;
69 } 67 }
70 68
71 bool DesktopBackgroundController::SetWallpaperImage( 69 bool WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image,
72 const gfx::ImageSkia& image, 70 wallpaper::WallpaperLayout layout) {
73 wallpaper::WallpaperLayout layout) {
74 VLOG(1) << "SetWallpaper: image_id=" 71 VLOG(1) << "SetWallpaper: image_id="
75 << wallpaper::WallpaperResizer::GetImageId(image) 72 << wallpaper::WallpaperResizer::GetImageId(image)
76 << " layout=" << layout; 73 << " layout=" << layout;
77 74
78 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) { 75 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) {
79 VLOG(1) << "Wallpaper is already loaded"; 76 VLOG(1) << "Wallpaper is already loaded";
80 return false; 77 return false;
81 } 78 }
82 79
83 current_wallpaper_.reset(new wallpaper::WallpaperResizer( 80 current_wallpaper_.reset(new wallpaper::WallpaperResizer(
84 image, GetMaxDisplaySizeInNative(), layout, blocking_pool_)); 81 image, GetMaxDisplaySizeInNative(), layout, blocking_pool_));
85 current_wallpaper_->StartResize(); 82 current_wallpaper_->StartResize();
86 83
87 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_, 84 FOR_EACH_OBSERVER(WallpaperControllerObserver, observers_,
88 OnWallpaperDataChanged()); 85 OnWallpaperDataChanged());
89 desktop_background_mode_ = BACKGROUND_IMAGE; 86 wallpaper_mode_ = WALLPAPER_IMAGE;
90 InstallDesktopControllerForAllWindows(); 87 InstallDesktopControllerForAllWindows();
91 return true; 88 return true;
92 } 89 }
93 90
94 void DesktopBackgroundController::CreateEmptyWallpaper() { 91 void WallpaperController::CreateEmptyWallpaper() {
95 current_wallpaper_.reset(); 92 current_wallpaper_.reset();
96 desktop_background_mode_ = BACKGROUND_IMAGE; 93 wallpaper_mode_ = WALLPAPER_IMAGE;
97 InstallDesktopControllerForAllWindows(); 94 InstallDesktopControllerForAllWindows();
98 } 95 }
99 96
100 bool DesktopBackgroundController::MoveDesktopToLockedContainer() { 97 bool WallpaperController::MoveToLockedContainer() {
101 if (locked_) 98 if (locked_)
102 return false; 99 return false;
103 locked_ = true; 100 locked_ = true;
104 return ReparentBackgroundWidgets(GetBackgroundContainerId(false), 101 return ReparentWallpaper(GetWallpaperContainerId(true));
105 GetBackgroundContainerId(true));
106 } 102 }
107 103
108 bool DesktopBackgroundController::MoveDesktopToUnlockedContainer() { 104 bool WallpaperController::MoveToUnlockedContainer() {
109 if (!locked_) 105 if (!locked_)
110 return false; 106 return false;
111 locked_ = false; 107 locked_ = false;
112 return ReparentBackgroundWidgets(GetBackgroundContainerId(true), 108 return ReparentWallpaper(GetWallpaperContainerId(false));
113 GetBackgroundContainerId(false));
114 } 109 }
115 110
116 void DesktopBackgroundController::OnDisplayConfigurationChanged() { 111 void WallpaperController::OnDisplayConfigurationChanged() {
117 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); 112 gfx::Size max_display_size = GetMaxDisplaySizeInNative();
118 if (current_max_display_size_ != max_display_size) { 113 if (current_max_display_size_ != max_display_size) {
119 current_max_display_size_ = max_display_size; 114 current_max_display_size_ = max_display_size;
120 if (desktop_background_mode_ == BACKGROUND_IMAGE && current_wallpaper_) { 115 if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_) {
121 timer_.Stop(); 116 timer_.Stop();
122 timer_.Start(FROM_HERE, 117 timer_.Start(FROM_HERE,
123 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), 118 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_),
124 base::Bind(&DesktopBackgroundController::UpdateWallpaper, 119 base::Bind(&WallpaperController::UpdateWallpaper,
125 base::Unretained(this), false /* clear cache */)); 120 base::Unretained(this), false /* clear cache */));
126 } 121 }
127 } 122 }
128 } 123 }
129 124
130 void DesktopBackgroundController::OnRootWindowAdded(WmWindow* root_window) { 125 void WallpaperController::OnRootWindowAdded(WmWindow* root_window) {
131 // The background hasn't been set yet. 126 // The wallpaper hasn't been set yet.
132 if (desktop_background_mode_ == BACKGROUND_NONE) 127 if (wallpaper_mode_ == WALLPAPER_NONE)
133 return; 128 return;
134 129
135 // Handle resolution change for "built-in" images. 130 // Handle resolution change for "built-in" images.
136 gfx::Size max_display_size = GetMaxDisplaySizeInNative(); 131 gfx::Size max_display_size = GetMaxDisplaySizeInNative();
137 if (current_max_display_size_ != max_display_size) { 132 if (current_max_display_size_ != max_display_size) {
138 current_max_display_size_ = max_display_size; 133 current_max_display_size_ = max_display_size;
139 if (desktop_background_mode_ == BACKGROUND_IMAGE && current_wallpaper_) 134 if (wallpaper_mode_ == WALLPAPER_IMAGE && current_wallpaper_)
140 UpdateWallpaper(true /* clear cache */); 135 UpdateWallpaper(true /* clear cache */);
141 } 136 }
142 137
143 InstallDesktopController(root_window); 138 InstallDesktopController(root_window);
144 } 139 }
145 140
146 // static 141 // static
147 gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() { 142 gfx::Size WallpaperController::GetMaxDisplaySizeInNative() {
148 // Return an empty size for test environments where the screen is null. 143 // Return an empty size for test environments where the screen is null.
149 if (!display::Screen::GetScreen()) 144 if (!display::Screen::GetScreen())
150 return gfx::Size(); 145 return gfx::Size();
151 146
152 // Note that |shell| is null when this is called from Chrome running in Mash. 147 // Note that |shell| is null when this is called from Chrome running in Mash.
153 WmShell* shell = WmShell::Get(); 148 WmShell* shell = WmShell::Get();
154 149
155 gfx::Size max; 150 gfx::Size max;
156 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) { 151 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) {
157 // Use the native size, not DisplayInfo::size_in_pixel or Display::size. 152 // Use the native size, not DisplayInfo::size_in_pixel or Display::size.
158 // TODO(msw): Avoid using Display::size here; see http://crbug.com/613657. 153 // TODO(msw): Avoid using Display::size here; see http://crbug.com/613657.
159 gfx::Size size = display.size(); 154 gfx::Size size = display.size();
160 if (shell) 155 if (shell)
161 size = shell->GetDisplayInfo(display.id()).bounds_in_native().size(); 156 size = shell->GetDisplayInfo(display.id()).bounds_in_native().size();
162 if (display.rotation() == display::Display::ROTATE_90 || 157 if (display.rotation() == display::Display::ROTATE_90 ||
163 display.rotation() == display::Display::ROTATE_270) { 158 display.rotation() == display::Display::ROTATE_270) {
164 size = gfx::Size(size.height(), size.width()); 159 size = gfx::Size(size.height(), size.width());
165 } 160 }
166 max.SetToMax(size); 161 max.SetToMax(size);
167 } 162 }
168 163
169 return max; 164 return max;
170 } 165 }
171 166
172 bool DesktopBackgroundController::WallpaperIsAlreadyLoaded( 167 bool WallpaperController::WallpaperIsAlreadyLoaded(
173 const gfx::ImageSkia& image, 168 const gfx::ImageSkia& image,
174 bool compare_layouts, 169 bool compare_layouts,
175 wallpaper::WallpaperLayout layout) const { 170 wallpaper::WallpaperLayout layout) const {
176 if (!current_wallpaper_) 171 if (!current_wallpaper_)
177 return false; 172 return false;
178 173
179 // Compare layouts only if necessary. 174 // Compare layouts only if necessary.
180 if (compare_layouts && layout != current_wallpaper_->layout()) 175 if (compare_layouts && layout != current_wallpaper_->layout())
181 return false; 176 return false;
182 177
183 return wallpaper::WallpaperResizer::GetImageId(image) == 178 return wallpaper::WallpaperResizer::GetImageId(image) ==
184 current_wallpaper_->original_image_id(); 179 current_wallpaper_->original_image_id();
185 } 180 }
186 181
187 void DesktopBackgroundController::InstallDesktopController( 182 void WallpaperController::InstallDesktopController(WmWindow* root_window) {
188 WmWindow* root_window) { 183 WallpaperWidgetController* component = nullptr;
189 DesktopBackgroundWidgetController* component = nullptr; 184 int container_id = GetWallpaperContainerId(locked_);
190 int container_id = GetBackgroundContainerId(locked_);
191 185
192 switch (desktop_background_mode_) { 186 switch (wallpaper_mode_) {
193 case BACKGROUND_IMAGE: { 187 case WALLPAPER_IMAGE: {
194 component = new DesktopBackgroundWidgetController( 188 component = new WallpaperWidgetController(
195 CreateDesktopBackground(root_window, container_id)); 189 CreateWallpaper(root_window, container_id));
196 break; 190 break;
197 } 191 }
198 case BACKGROUND_NONE: 192 case WALLPAPER_NONE:
199 NOTREACHED(); 193 NOTREACHED();
200 return; 194 return;
201 } 195 }
202 196
203 aura::Window* aura_root_window = WmWindowAura::GetAuraWindow(root_window); 197 aura::Window* aura_root_window = WmWindowAura::GetAuraWindow(root_window);
204 RootWindowController* controller = GetRootWindowController(aura_root_window); 198 RootWindowController* controller = GetRootWindowController(aura_root_window);
205 controller->SetAnimatingWallpaperController( 199 controller->SetAnimatingWallpaperController(
206 new AnimatingDesktopController(component)); 200 new AnimatingDesktopController(component));
207 component->StartAnimating(controller); 201 component->StartAnimating(controller);
208 } 202 }
209 203
210 void DesktopBackgroundController::InstallDesktopControllerForAllWindows() { 204 void WallpaperController::InstallDesktopControllerForAllWindows() {
211 for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) 205 for (WmWindow* root : WmShell::Get()->GetAllRootWindows())
212 InstallDesktopController(root); 206 InstallDesktopController(root);
213 current_max_display_size_ = GetMaxDisplaySizeInNative(); 207 current_max_display_size_ = GetMaxDisplaySizeInNative();
214 } 208 }
215 209
216 bool DesktopBackgroundController::ReparentBackgroundWidgets(int src_container, 210 bool WallpaperController::ReparentWallpaper(int container) {
217 int dst_container) {
218 bool moved = false; 211 bool moved = false;
219 for (auto* root_window_controller : Shell::GetAllRootWindowControllers()) { 212 for (auto* root_window_controller : Shell::GetAllRootWindowControllers()) {
220 // In the steady state (no animation playing) the background widget 213 // In the steady state (no animation playing) the wallpaper widget
221 // controller exists in the RootWindowController. 214 // controller exists in the RootWindowController.
222 DesktopBackgroundWidgetController* desktop_controller = 215 WallpaperWidgetController* wallpaper_controller =
223 root_window_controller->wallpaper_controller(); 216 root_window_controller->wallpaper_controller();
224 if (desktop_controller) { 217 if (wallpaper_controller) {
225 moved |= 218 moved |= wallpaper_controller->Reparent(
226 desktop_controller->Reparent(root_window_controller->GetRootWindow(), 219 root_window_controller->GetRootWindow(), container);
227 src_container, dst_container);
228 } 220 }
229 // During desktop show animations the controller lives in 221 // During wallpaper show animations the controller lives in
230 // AnimatingDesktopController owned by RootWindowController. 222 // AnimatingDesktopController owned by RootWindowController.
231 // NOTE: If a wallpaper load happens during a desktop show animation there 223 // NOTE: If an image load happens during a wallpaper show animation there
232 // can temporarily be two desktop background widgets. We must reparent 224 // can temporarily be two wallpaper wallpaper widgets. We must reparent both
James Cook 2016/08/30 05:18:19 nit: wallpaper wallpaper -> wallpaper
msw 2016/08/30 16:07:59 Done.
233 // both of them - one above and one here. 225 // of them - one above and one here.
234 DesktopBackgroundWidgetController* animating_controller = 226 WallpaperWidgetController* animating_controller =
235 root_window_controller->animating_wallpaper_controller() 227 root_window_controller->animating_wallpaper_controller()
236 ? root_window_controller->animating_wallpaper_controller() 228 ? root_window_controller->animating_wallpaper_controller()
237 ->GetController(false) 229 ->GetController(false)
238 : nullptr; 230 : nullptr;
239 if (animating_controller) { 231 if (animating_controller) {
240 moved |= animating_controller->Reparent( 232 moved |= animating_controller->Reparent(
241 root_window_controller->GetRootWindow(), src_container, 233 root_window_controller->GetRootWindow(), container);
242 dst_container);
243 } 234 }
244 } 235 }
245 return moved; 236 return moved;
246 } 237 }
James Cook 2016/08/30 05:18:19 Aside: I once spent ~2 weeks tracking down a bug t
msw 2016/08/30 16:07:59 Yikes!
247 238
248 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { 239 int WallpaperController::GetWallpaperContainerId(bool locked) {
249 return locked ? kShellWindowId_LockScreenBackgroundContainer 240 return locked ? kShellWindowId_LockScreenWallpaperContainer
250 : kShellWindowId_DesktopBackgroundContainer; 241 : kShellWindowId_WallpaperContainer;
251 } 242 }
252 243
253 void DesktopBackgroundController::UpdateWallpaper(bool clear_cache) { 244 void WallpaperController::UpdateWallpaper(bool clear_cache) {
254 current_wallpaper_.reset(); 245 current_wallpaper_.reset();
255 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); 246 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache);
256 } 247 }
257 248
258 } // namespace ash 249 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698