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

Side by Side Diff: ash/desktop_background/desktop_background_controller.cc

Issue 24499002: Reload wallpaper when display configuration changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
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/desktop_background/desktop_background_controller.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/desktop_background/desktop_background_controller_observer.h" 8 #include "ash/desktop_background/desktop_background_controller_observer.h"
9 #include "ash/desktop_background/desktop_background_view.h" 9 #include "ash/desktop_background/desktop_background_view.h"
10 #include "ash/desktop_background/desktop_background_widget_controller.h" 10 #include "ash/desktop_background/desktop_background_widget_controller.h"
(...skipping 21 matching lines...) Expand all
32 #include "ui/gfx/image/image_skia.h" 32 #include "ui/gfx/image/image_skia.h"
33 #include "ui/gfx/rect.h" 33 #include "ui/gfx/rect.h"
34 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
35 35
36 using ash::internal::DesktopBackgroundWidgetController; 36 using ash::internal::DesktopBackgroundWidgetController;
37 using content::BrowserThread; 37 using content::BrowserThread;
38 38
39 namespace ash { 39 namespace ash {
40 namespace { 40 namespace {
41 41
42 // How long to wait reloading the wallpaper after the max display has
43 // changed?
44 const int kWallpaperReloadDelayMs = 2000;
45
42 const SkColor kTransparentColor = SkColorSetARGB(0x00, 0x00, 0x00, 0x00); 46 const SkColor kTransparentColor = SkColorSetARGB(0x00, 0x00, 0x00, 0x00);
43 47
44 internal::RootWindowLayoutManager* GetRootWindowLayoutManager( 48 internal::RootWindowLayoutManager* GetRootWindowLayoutManager(
45 aura::RootWindow* root_window) { 49 aura::RootWindow* root_window) {
46 return static_cast<internal::RootWindowLayoutManager*>( 50 return static_cast<internal::RootWindowLayoutManager*>(
47 root_window->layout_manager()); 51 root_window->layout_manager());
48 } 52 }
49 53
50 } // namespace 54 } // namespace
51 55
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 WallpaperLayout resource_layout_; 158 WallpaperLayout resource_layout_;
155 159
156 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); 160 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader);
157 }; 161 };
158 162
159 DesktopBackgroundController::DesktopBackgroundController() 163 DesktopBackgroundController::DesktopBackgroundController()
160 : command_line_for_testing_(NULL), 164 : command_line_for_testing_(NULL),
161 locked_(false), 165 locked_(false),
162 desktop_background_mode_(BACKGROUND_NONE), 166 desktop_background_mode_(BACKGROUND_NONE),
163 current_default_wallpaper_resource_id_(-1), 167 current_default_wallpaper_resource_id_(-1),
164 weak_ptr_factory_(this) { 168 weak_ptr_factory_(this),
169 wallpaper_reload_delay_(kWallpaperReloadDelayMs) {
170 Shell::GetInstance()->display_controller()->AddObserver(this);
165 } 171 }
166 172
167 DesktopBackgroundController::~DesktopBackgroundController() { 173 DesktopBackgroundController::~DesktopBackgroundController() {
168 CancelPendingWallpaperOperation(); 174 CancelPendingWallpaperOperation();
175 Shell::GetInstance()->display_controller()->RemoveObserver(this);
169 } 176 }
170 177
171 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { 178 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const {
172 if (current_wallpaper_) 179 if (current_wallpaper_)
173 return current_wallpaper_->wallpaper_image(); 180 return current_wallpaper_->wallpaper_image();
174 return gfx::ImageSkia(); 181 return gfx::ImageSkia();
175 } 182 }
176 183
177 void DesktopBackgroundController::AddObserver( 184 void DesktopBackgroundController::AddObserver(
178 DesktopBackgroundControllerObserver* observer) { 185 DesktopBackgroundControllerObserver* observer) {
179 observers_.AddObserver(observer); 186 observers_.AddObserver(observer);
180 } 187 }
181 188
182 void DesktopBackgroundController::RemoveObserver( 189 void DesktopBackgroundController::RemoveObserver(
183 DesktopBackgroundControllerObserver* observer) { 190 DesktopBackgroundControllerObserver* observer) {
184 observers_.RemoveObserver(observer); 191 observers_.RemoveObserver(observer);
185 } 192 }
186 193
187 WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const { 194 WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const {
188 if (current_wallpaper_) 195 if (current_wallpaper_)
189 return current_wallpaper_->layout(); 196 return current_wallpaper_->layout();
190 return WALLPAPER_LAYOUT_CENTER_CROPPED; 197 return WALLPAPER_LAYOUT_CENTER_CROPPED;
191 } 198 }
192 199
193 void DesktopBackgroundController::OnRootWindowAdded( 200 void DesktopBackgroundController::OnRootWindowAdded(
194 aura::RootWindow* root_window) { 201 aura::RootWindow* root_window) {
195 // The background hasn't been set yet. 202 // The background hasn't been set yet.
196 if (desktop_background_mode_ == BACKGROUND_NONE) 203 if (desktop_background_mode_ == BACKGROUND_NONE)
197 return; 204 return;
198 205 gfx::Size max_display_size = GetMaxDisplaySizeInNative();
199 // Handle resolution change for "built-in" images. 206 // Handle resolution change for "built-in" images.
200 if (BACKGROUND_IMAGE == desktop_background_mode_ && 207 if (BACKGROUND_IMAGE == desktop_background_mode_ &&
201 current_wallpaper_.get()) { 208 current_wallpaper_.get() &&
202 gfx::Size root_window_size = root_window->GetHostSize(); 209 current_max_display_size_ != max_display_size) {
203 int width = current_wallpaper_->wallpaper_image().width(); 210 current_max_display_size_ = max_display_size;
204 int height = current_wallpaper_->wallpaper_image().height(); 211 UpdateWallpaper();
205 // Reloads wallpaper if current wallpaper is smaller than the new added root
206 // window.
207 if (width < root_window_size.width() ||
208 height < root_window_size.height()) {
209 current_wallpaper_.reset(NULL);
210 current_default_wallpaper_path_ = base::FilePath();
211 current_default_wallpaper_resource_id_ = -1;
212 ash::Shell::GetInstance()->user_wallpaper_delegate()->
213 UpdateWallpaper();
214 }
215 } 212 }
216 213
217 InstallDesktopController(root_window); 214 InstallDesktopController(root_window);
218 } 215 }
219 216
220 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) { 217 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) {
221 const bool use_large = 218 const bool use_large =
222 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE; 219 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE;
223 220
224 base::FilePath file_path; 221 base::FilePath file_path;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 300 }
304 301
305 bool DesktopBackgroundController::MoveDesktopToUnlockedContainer() { 302 bool DesktopBackgroundController::MoveDesktopToUnlockedContainer() {
306 if (!locked_) 303 if (!locked_)
307 return false; 304 return false;
308 locked_ = false; 305 locked_ = false;
309 return ReparentBackgroundWidgets(GetBackgroundContainerId(true), 306 return ReparentBackgroundWidgets(GetBackgroundContainerId(true),
310 GetBackgroundContainerId(false)); 307 GetBackgroundContainerId(false));
311 } 308 }
312 309
310 void DesktopBackgroundController::OnDisplayConfigurationChanged() {
311 gfx::Size max_display_size = GetMaxDisplaySizeInNative();
312 if (current_max_display_size_ != max_display_size) {
313 current_max_display_size_ = max_display_size;
314 timer_.Stop();
315 timer_.Start(FROM_HERE,
316 base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_),
317 this,
318 &DesktopBackgroundController::UpdateWallpaper);
319 }
320 }
321
313 bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded( 322 bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded(
314 const base::FilePath& image_file, int image_resource_id) const { 323 const base::FilePath& image_file, int image_resource_id) const {
315 return (wallpaper_loader_.get() && 324 return (wallpaper_loader_.get() &&
316 wallpaper_loader_->file_path() == image_file && 325 wallpaper_loader_->file_path() == image_file &&
317 wallpaper_loader_->resource_id() == image_resource_id) || 326 wallpaper_loader_->resource_id() == image_resource_id) ||
318 (current_wallpaper_.get() && 327 (current_wallpaper_.get() &&
319 current_default_wallpaper_path_ == image_file && 328 current_default_wallpaper_path_ == image_file &&
320 current_default_wallpaper_resource_id_ == image_resource_id); 329 current_default_wallpaper_resource_id_ == image_resource_id);
321 } 330 }
322 331
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 377
369 component->StartAnimating(internal::GetRootWindowController(root_window)); 378 component->StartAnimating(internal::GetRootWindowController(root_window));
370 } 379 }
371 380
372 void DesktopBackgroundController::InstallDesktopControllerForAllWindows() { 381 void DesktopBackgroundController::InstallDesktopControllerForAllWindows() {
373 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 382 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
374 for (Shell::RootWindowList::iterator iter = root_windows.begin(); 383 for (Shell::RootWindowList::iterator iter = root_windows.begin();
375 iter != root_windows.end(); ++iter) { 384 iter != root_windows.end(); ++iter) {
376 InstallDesktopController(*iter); 385 InstallDesktopController(*iter);
377 } 386 }
387 current_max_display_size_ = GetMaxDisplaySizeInNative();
378 } 388 }
379 389
380 bool DesktopBackgroundController::ReparentBackgroundWidgets(int src_container, 390 bool DesktopBackgroundController::ReparentBackgroundWidgets(int src_container,
381 int dst_container) { 391 int dst_container) {
382 bool moved = false; 392 bool moved = false;
383 Shell::RootWindowControllerList controllers = 393 Shell::RootWindowControllerList controllers =
384 Shell::GetAllRootWindowControllers(); 394 Shell::GetAllRootWindowControllers();
385 for (Shell::RootWindowControllerList::iterator iter = controllers.begin(); 395 for (Shell::RootWindowControllerList::iterator iter = controllers.begin();
386 iter != controllers.end(); ++iter) { 396 iter != controllers.end(); ++iter) {
387 internal::RootWindowController* root_window_controller = *iter; 397 internal::RootWindowController* root_window_controller = *iter;
(...skipping 25 matching lines...) Expand all
413 } 423 }
414 } 424 }
415 return moved; 425 return moved;
416 } 426 }
417 427
418 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { 428 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) {
419 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer : 429 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer :
420 internal::kShellWindowId_DesktopBackgroundContainer; 430 internal::kShellWindowId_DesktopBackgroundContainer;
421 } 431 }
422 432
433 void DesktopBackgroundController::UpdateWallpaper() {
434 current_wallpaper_.reset(NULL);
435 current_default_wallpaper_path_ = base::FilePath();
436 current_default_wallpaper_resource_id_ = -1;
437 ash::Shell::GetInstance()->user_wallpaper_delegate()->
438 UpdateWallpaper();
439 }
440
423 // static 441 // static
424 gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() { 442 gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() {
425 int width = 0; 443 int width = 0;
426 int height = 0; 444 int height = 0;
427 std::vector<gfx::Display> displays = Shell::GetScreen()->GetAllDisplays(); 445 std::vector<gfx::Display> displays = Shell::GetScreen()->GetAllDisplays();
428 internal::DisplayManager* display_manager = 446 internal::DisplayManager* display_manager =
429 Shell::GetInstance()->display_manager(); 447 Shell::GetInstance()->display_manager();
430 448
431 for (std::vector<gfx::Display>::iterator iter = displays.begin(); 449 for (std::vector<gfx::Display>::iterator iter = displays.begin();
432 iter != displays.end(); ++iter) { 450 iter != displays.end(); ++iter) {
433 // Don't use size_in_pixel because we want to use the native pixel size. 451 // Don't use size_in_pixel because we want to use the native pixel size.
434 gfx::Size size_in_pixel = 452 gfx::Size size_in_pixel =
435 display_manager->GetDisplayInfo(iter->id()).bounds_in_native().size(); 453 display_manager->GetDisplayInfo(iter->id()).bounds_in_native().size();
436 if (iter->rotation() == gfx::Display::ROTATE_90 || 454 if (iter->rotation() == gfx::Display::ROTATE_90 ||
437 iter->rotation() == gfx::Display::ROTATE_270) { 455 iter->rotation() == gfx::Display::ROTATE_270) {
438 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); 456 size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width());
439 } 457 }
440 width = std::max(size_in_pixel.width(), width); 458 width = std::max(size_in_pixel.width(), width);
441 height = std::max(size_in_pixel.height(), height); 459 height = std::max(size_in_pixel.height(), height);
442 } 460 }
443 return gfx::Size(width, height); 461 return gfx::Size(width, height);
444 } 462 }
445 463
446 } // namespace ash 464 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698