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 #include "ash/desktop_background/desktop_background_controller.h" | 5 #include "ash/desktop_background/desktop_background_controller.h" |
6 | 6 |
7 #include "ash/desktop_background/desktop_background_view.h" | 7 #include "ash/desktop_background/desktop_background_view.h" |
8 #include "ash/desktop_background/desktop_background_widget_controller.h" | 8 #include "ash/desktop_background/desktop_background_widget_controller.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_factory.h" | 10 #include "ash/shell_factory.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 const WallpaperResolution resolution_; | 99 const WallpaperResolution resolution_; |
100 | 100 |
101 DISALLOW_COPY_AND_ASSIGN(WallpaperOperation); | 101 DISALLOW_COPY_AND_ASSIGN(WallpaperOperation); |
102 }; | 102 }; |
103 | 103 |
104 DesktopBackgroundController::DesktopBackgroundController() | 104 DesktopBackgroundController::DesktopBackgroundController() |
105 : locked_(false), | 105 : locked_(false), |
106 desktop_background_mode_(BACKGROUND_SOLID_COLOR), | 106 desktop_background_mode_(BACKGROUND_SOLID_COLOR), |
107 background_color_(kTransparentColor), | 107 background_color_(kTransparentColor), |
108 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 108 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
109 InstallComponentForAllWindows(); | |
110 } | 109 } |
111 | 110 |
112 DesktopBackgroundController::~DesktopBackgroundController() { | 111 DesktopBackgroundController::~DesktopBackgroundController() { |
113 CancelPendingWallpaperOperation(); | 112 CancelPendingWallpaperOperation(); |
114 } | 113 } |
115 | 114 |
116 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { | 115 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { |
117 if (current_wallpaper_.get()) | 116 if (current_wallpaper_.get()) |
118 return current_wallpaper_->wallpaper_image; | 117 return current_wallpaper_->wallpaper_image; |
119 return gfx::ImageSkia(); | 118 return gfx::ImageSkia(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 if (wallpaper_op_.get()) | 205 if (wallpaper_op_.get()) |
207 wallpaper_op_->Cancel(); | 206 wallpaper_op_->Cancel(); |
208 | 207 |
209 // Cancel reply callback for previous request. | 208 // Cancel reply callback for previous request. |
210 weak_ptr_factory_.InvalidateWeakPtrs(); | 209 weak_ptr_factory_.InvalidateWeakPtrs(); |
211 } | 210 } |
212 | 211 |
213 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode( | 212 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode( |
214 SkColor color) { | 213 SkColor color) { |
215 background_color_ = color; | 214 background_color_ = color; |
216 if (desktop_background_mode_ != BACKGROUND_SOLID_COLOR) { | 215 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; |
217 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; | |
218 InstallComponentForAllWindows(); | |
219 return; | |
220 } | |
221 | 216 |
222 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 217 InstallComponentForAllWindows(); |
223 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | |
224 iter != root_windows.end(); ++iter) { | |
225 aura::RootWindow* root_window = *iter; | |
226 internal::DesktopBackgroundWidgetController* component = root_window-> | |
227 GetProperty(internal::kWindowDesktopComponent); | |
228 DCHECK(component); | |
229 DCHECK(component->layer()); | |
230 component->layer()->SetColor(background_color_ ); | |
231 } | |
232 } | 218 } |
233 | 219 |
234 void DesktopBackgroundController::CreateEmptyWallpaper() { | 220 void DesktopBackgroundController::CreateEmptyWallpaper() { |
235 current_wallpaper_.reset(NULL); | 221 current_wallpaper_.reset(NULL); |
236 SetDesktopBackgroundImageMode(); | 222 SetDesktopBackgroundImageMode(); |
237 } | 223 } |
238 | 224 |
239 void DesktopBackgroundController::MoveDesktopToLockedContainer() { | 225 void DesktopBackgroundController::MoveDesktopToLockedContainer() { |
240 if (locked_) | 226 if (locked_) |
241 return; | 227 return; |
242 locked_ = true; | 228 locked_ = true; |
243 ReparentBackgroundWidgets(GetBackgroundContainerId(false), | 229 ReparentBackgroundWidgets(GetBackgroundContainerId(false), |
244 GetBackgroundContainerId(true)); | 230 GetBackgroundContainerId(true)); |
245 } | 231 } |
246 | 232 |
247 void DesktopBackgroundController::MoveDesktopToUnlockedContainer() { | 233 void DesktopBackgroundController::MoveDesktopToUnlockedContainer() { |
248 if (!locked_) | 234 if (!locked_) |
249 return; | 235 return; |
250 locked_ = false; | 236 locked_ = false; |
251 ReparentBackgroundWidgets(GetBackgroundContainerId(true), | 237 ReparentBackgroundWidgets(GetBackgroundContainerId(true), |
252 GetBackgroundContainerId(false)); | 238 GetBackgroundContainerId(false)); |
253 } | 239 } |
254 | 240 |
255 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { | 241 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { |
256 window->SetProperty(internal::kWindowDesktopComponent, | 242 window->SetProperty(internal::kWindowDesktopComponent, |
257 static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); | 243 static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); |
| 244 window->SetProperty(internal::kComponentWrapper, |
| 245 static_cast<internal::ComponentWrapper*>(NULL)); |
258 } | 246 } |
259 | 247 |
260 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { | 248 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { |
261 if (desktop_background_mode_ != BACKGROUND_IMAGE) { | 249 desktop_background_mode_ = BACKGROUND_IMAGE; |
262 desktop_background_mode_ = BACKGROUND_IMAGE; | 250 InstallComponentForAllWindows(); |
263 InstallComponentForAllWindows(); | |
264 return; | |
265 } | |
266 | |
267 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
268 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | |
269 iter != root_windows.end(); ++iter) { | |
270 aura::RootWindow* root_window = *iter; | |
271 internal::DesktopBackgroundWidgetController* component = root_window-> | |
272 GetProperty(internal::kWindowDesktopComponent); | |
273 DCHECK(component); | |
274 DCHECK(component->widget()); | |
275 aura::Window* window = component->widget()->GetNativeView(); | |
276 gfx::Rect bounds = window->bounds(); | |
277 window->SchedulePaintInRect(gfx::Rect(0, 0, | |
278 bounds.width(), bounds.height())); | |
279 } | |
280 } | 251 } |
281 | 252 |
282 void DesktopBackgroundController::OnWallpaperLoadCompleted( | 253 void DesktopBackgroundController::OnWallpaperLoadCompleted( |
283 scoped_refptr<WallpaperOperation> wo) { | 254 scoped_refptr<WallpaperOperation> wo) { |
284 current_wallpaper_.reset(wo->ReleaseWallpaperData()); | 255 current_wallpaper_.reset(wo->ReleaseWallpaperData()); |
285 | 256 |
286 SetDesktopBackgroundImageMode(); | 257 SetDesktopBackgroundImageMode(); |
287 | 258 |
288 DCHECK(wo.get() == wallpaper_op_.get()); | 259 DCHECK(wo.get() == wallpaper_op_.get()); |
289 wallpaper_op_ = NULL; | 260 wallpaper_op_ = NULL; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 break; | 292 break; |
322 } | 293 } |
323 default: { | 294 default: { |
324 NOTREACHED(); | 295 NOTREACHED(); |
325 } | 296 } |
326 } | 297 } |
327 if (NULL == root_window->GetProperty(internal::kWindowDesktopComponent)) { | 298 if (NULL == root_window->GetProperty(internal::kWindowDesktopComponent)) { |
328 // First time for this root window | 299 // First time for this root window |
329 root_window->AddObserver(this); | 300 root_window->AddObserver(this); |
330 } | 301 } |
331 root_window->SetProperty(internal::kWindowDesktopComponent, component); | 302 root_window->SetProperty(internal::kComponentWrapper, |
| 303 new internal::ComponentWrapper(component)); |
332 } | 304 } |
333 | 305 |
334 void DesktopBackgroundController::InstallComponentForAllWindows() { | 306 void DesktopBackgroundController::InstallComponentForAllWindows() { |
335 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 307 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
336 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | 308 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
337 iter != root_windows.end(); ++iter) { | 309 iter != root_windows.end(); ++iter) { |
338 InstallComponent(*iter); | 310 InstallComponent(*iter); |
339 } | 311 } |
340 } | 312 } |
341 | 313 |
(...skipping 24 matching lines...) Expand all Loading... |
366 iter != root_windows.end(); ++iter) { | 338 iter != root_windows.end(); ++iter) { |
367 gfx::Size root_window_size = (*iter)->GetHostSize(); | 339 gfx::Size root_window_size = (*iter)->GetHostSize(); |
368 if (root_window_size.width() > kSmallWallpaperMaximalWidth || | 340 if (root_window_size.width() > kSmallWallpaperMaximalWidth || |
369 root_window_size.height() > kSmallWallpaperMaximalHeight) | 341 root_window_size.height() > kSmallWallpaperMaximalHeight) |
370 resolution = LARGE; | 342 resolution = LARGE; |
371 } | 343 } |
372 return resolution; | 344 return resolution; |
373 } | 345 } |
374 | 346 |
375 } // namespace ash | 347 } // namespace ash |
OLD | NEW |