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 if (desktop_background_mode_ != BACKGROUND_SOLID_COLOR) |
217 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; | 216 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; |
218 InstallComponentForAllWindows(); | |
219 return; | |
220 } | |
221 | 217 |
222 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 218 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 } | 219 } |
233 | 220 |
234 void DesktopBackgroundController::CreateEmptyWallpaper() { | 221 void DesktopBackgroundController::CreateEmptyWallpaper() { |
235 current_wallpaper_.reset(NULL); | 222 current_wallpaper_.reset(NULL); |
236 SetDesktopBackgroundImageMode(); | 223 SetDesktopBackgroundImageMode(); |
237 } | 224 } |
238 | 225 |
239 void DesktopBackgroundController::MoveDesktopToLockedContainer() { | 226 void DesktopBackgroundController::MoveDesktopToLockedContainer() { |
240 if (locked_) | 227 if (locked_) |
241 return; | 228 return; |
(...skipping 11 matching lines...) Expand all Loading... |
253 } | 240 } |
254 | 241 |
255 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { | 242 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { |
256 window->SetProperty(internal::kWindowDesktopComponent, | 243 window->SetProperty(internal::kWindowDesktopComponent, |
257 static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); | 244 static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); |
258 } | 245 } |
259 | 246 |
260 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { | 247 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { |
261 if (desktop_background_mode_ != BACKGROUND_IMAGE) { | 248 if (desktop_background_mode_ != BACKGROUND_IMAGE) { |
262 desktop_background_mode_ = BACKGROUND_IMAGE; | 249 desktop_background_mode_ = BACKGROUND_IMAGE; |
263 InstallComponentForAllWindows(); | |
264 return; | |
265 } | 250 } |
266 | 251 InstallComponentForAllWindows(); |
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 } | 252 } |
281 | 253 |
282 void DesktopBackgroundController::OnWallpaperLoadCompleted( | 254 void DesktopBackgroundController::OnWallpaperLoadCompleted( |
283 scoped_refptr<WallpaperOperation> wo) { | 255 scoped_refptr<WallpaperOperation> wo) { |
284 current_wallpaper_.reset(wo->ReleaseWallpaperData()); | 256 current_wallpaper_.reset(wo->ReleaseWallpaperData()); |
285 | 257 |
286 SetDesktopBackgroundImageMode(); | 258 SetDesktopBackgroundImageMode(); |
287 | 259 |
288 DCHECK(wo.get() == wallpaper_op_.get()); | 260 DCHECK(wo.get() == wallpaper_op_.get()); |
289 wallpaper_op_ = NULL; | 261 wallpaper_op_ = NULL; |
(...skipping 14 matching lines...) Expand all Loading... |
304 void DesktopBackgroundController::InstallComponent( | 276 void DesktopBackgroundController::InstallComponent( |
305 aura::RootWindow* root_window) { | 277 aura::RootWindow* root_window) { |
306 internal::DesktopBackgroundWidgetController* component = NULL; | 278 internal::DesktopBackgroundWidgetController* component = NULL; |
307 int container_id = GetBackgroundContainerId(locked_); | 279 int container_id = GetBackgroundContainerId(locked_); |
308 | 280 |
309 switch (desktop_background_mode_) { | 281 switch (desktop_background_mode_) { |
310 case BACKGROUND_IMAGE: { | 282 case BACKGROUND_IMAGE: { |
311 views::Widget* widget = internal::CreateDesktopBackground(root_window, | 283 views::Widget* widget = internal::CreateDesktopBackground(root_window, |
312 container_id); | 284 container_id); |
313 component = new internal::DesktopBackgroundWidgetController(widget); | 285 component = new internal::DesktopBackgroundWidgetController(widget); |
| 286 root_window_component_map_[root_window] = component; |
314 break; | 287 break; |
315 } | 288 } |
316 case BACKGROUND_SOLID_COLOR: { | 289 case BACKGROUND_SOLID_COLOR: { |
317 ui::Layer* layer = SetColorLayerForContainer(background_color_, | 290 ui::Layer* layer = SetColorLayerForContainer(background_color_, |
318 root_window, | 291 root_window, |
319 container_id); | 292 container_id); |
320 component = new internal::DesktopBackgroundWidgetController(layer); | 293 component = new internal::DesktopBackgroundWidgetController(layer); |
321 break; | 294 break; |
322 } | 295 } |
323 default: { | 296 default: { |
324 NOTREACHED(); | 297 NOTREACHED(); |
325 } | 298 } |
326 } | 299 } |
327 if (NULL == root_window->GetProperty(internal::kWindowDesktopComponent)) { | 300 if (NULL == root_window->GetProperty(internal::kWindowDesktopComponent)) { |
328 // First time for this root window | 301 // First time for this root window |
329 root_window->AddObserver(this); | 302 root_window->AddObserver(this); |
330 } | 303 } |
| 304 } |
| 305 |
| 306 void DesktopBackgroundController::SetComponentForRootWindow( |
| 307 aura::RootWindow* root_window) { |
| 308 internal::DesktopBackgroundWidgetController* component = |
| 309 root_window_component_map_[root_window]; |
331 root_window->SetProperty(internal::kWindowDesktopComponent, component); | 310 root_window->SetProperty(internal::kWindowDesktopComponent, component); |
332 } | 311 } |
333 | 312 |
334 void DesktopBackgroundController::InstallComponentForAllWindows() { | 313 void DesktopBackgroundController::InstallComponentForAllWindows() { |
335 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 314 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
336 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | 315 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
337 iter != root_windows.end(); ++iter) { | 316 iter != root_windows.end(); ++iter) { |
338 InstallComponent(*iter); | 317 InstallComponent(*iter); |
339 } | 318 } |
340 } | 319 } |
(...skipping 25 matching lines...) Expand all Loading... |
366 iter != root_windows.end(); ++iter) { | 345 iter != root_windows.end(); ++iter) { |
367 gfx::Size root_window_size = (*iter)->GetHostSize(); | 346 gfx::Size root_window_size = (*iter)->GetHostSize(); |
368 if (root_window_size.width() > kSmallWallpaperMaximalWidth || | 347 if (root_window_size.width() > kSmallWallpaperMaximalWidth || |
369 root_window_size.height() > kSmallWallpaperMaximalHeight) | 348 root_window_size.height() > kSmallWallpaperMaximalHeight) |
370 resolution = LARGE; | 349 resolution = LARGE; |
371 } | 350 } |
372 return resolution; | 351 return resolution; |
373 } | 352 } |
374 | 353 |
375 } // namespace ash | 354 } // namespace ash |
OLD | NEW |