Chromium Code Reviews| Index: ash/desktop_background/desktop_background_controller.cc |
| diff --git a/ash/desktop_background/desktop_background_controller.cc b/ash/desktop_background/desktop_background_controller.cc |
| index 4f9780673190f892db7adcd9256a335775fe5c66..3cdac2f91dd6fa180d892ad8539f75458818e568 100644 |
| --- a/ash/desktop_background/desktop_background_controller.cc |
| +++ b/ash/desktop_background/desktop_background_controller.cc |
| @@ -5,47 +5,27 @@ |
| #include "ash/desktop_background/desktop_background_controller.h" |
| #include "ash/aura/wm_window_aura.h" |
| -#include "ash/common/ash_switches.h" |
| #include "ash/common/display/display_info.h" |
| #include "ash/common/shell_window_ids.h" |
| -#include "ash/common/wm/root_window_layout_manager.h" |
| #include "ash/common/wm_shell.h" |
| #include "ash/desktop_background/desktop_background_controller_observer.h" |
| #include "ash/desktop_background/desktop_background_view.h" |
| #include "ash/desktop_background/desktop_background_widget_controller.h" |
| #include "ash/desktop_background/user_wallpaper_delegate.h" |
| -#include "ash/display/display_manager.h" |
| #include "ash/root_window_controller.h" |
| #include "ash/shell.h" |
| -#include "ash/shell_factory.h" |
| #include "base/bind.h" |
| -#include "base/command_line.h" |
| -#include "base/files/file_util.h" |
| #include "base/logging.h" |
| -#include "base/synchronization/cancellation_flag.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| #include "components/wallpaper/wallpaper_resizer.h" |
| #include "ui/aura/window.h" |
| -#include "ui/aura/window_event_dispatcher.h" |
| -#include "ui/compositor/layer.h" |
| #include "ui/display/screen.h" |
| -#include "ui/gfx/codec/jpeg_codec.h" |
| -#include "ui/gfx/geometry/rect.h" |
| -#include "ui/gfx/image/image_skia.h" |
| #include "ui/views/widget/widget.h" |
| -using wallpaper::WallpaperResizer; |
|
James Cook
2016/08/02 16:51:50
totally optional: using declarations don't bother
msw
2016/08/02 18:28:57
I only like them when they cleanup a large part of
|
| -using wallpaper::WallpaperLayout; |
| -using wallpaper::WALLPAPER_LAYOUT_CENTER; |
| -using wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; |
| -using wallpaper::WALLPAPER_LAYOUT_STRETCH; |
| -using wallpaper::WALLPAPER_LAYOUT_TILE; |
| - |
| namespace ash { |
| namespace { |
| -// How long to wait reloading the wallpaper after the max display has |
| -// changed? |
| +// How long to wait reloading the wallpaper after the max display has changed. |
|
James Cook
2016/08/02 16:51:50
nit: What the heck does "after the max display has
msw
2016/08/02 18:28:57
Done. Simplified the comment.
|
| const int kWallpaperReloadDelayMs = 100; |
| } // namespace |
| @@ -56,12 +36,12 @@ DesktopBackgroundController::DesktopBackgroundController( |
| desktop_background_mode_(BACKGROUND_NONE), |
| wallpaper_reload_delay_(kWallpaperReloadDelayMs), |
| blocking_pool_(blocking_pool) { |
| - Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); |
| + WmShell::Get()->AddDisplayObserver(this); |
| WmShell::Get()->AddShellObserver(this); |
| } |
| DesktopBackgroundController::~DesktopBackgroundController() { |
| - Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); |
| + WmShell::Get()->RemoveDisplayObserver(this); |
| WmShell::Get()->RemoveShellObserver(this); |
| } |
| @@ -81,15 +61,18 @@ void DesktopBackgroundController::RemoveObserver( |
| observers_.RemoveObserver(observer); |
| } |
| -WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const { |
| +wallpaper::WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() |
| + const { |
| if (current_wallpaper_) |
| return current_wallpaper_->layout(); |
| - return WALLPAPER_LAYOUT_CENTER_CROPPED; |
| + return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; |
| } |
| -bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image, |
| - WallpaperLayout layout) { |
| - VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image) |
| +bool DesktopBackgroundController::SetWallpaperImage( |
| + const gfx::ImageSkia& image, |
| + wallpaper::WallpaperLayout layout) { |
| + VLOG(1) << "SetWallpaper: image_id=" |
| + << wallpaper::WallpaperResizer::GetImageId(image) |
| << " layout=" << layout; |
| if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) { |
| @@ -97,19 +80,21 @@ bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image, |
| return false; |
| } |
| - current_wallpaper_.reset(new WallpaperResizer( |
| + current_wallpaper_.reset(new wallpaper::WallpaperResizer( |
| image, GetMaxDisplaySizeInNative(), layout, blocking_pool_)); |
| current_wallpaper_->StartResize(); |
| FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_, |
| OnWallpaperDataChanged()); |
| - SetDesktopBackgroundImageMode(); |
| + desktop_background_mode_ = BACKGROUND_IMAGE; |
| + InstallDesktopControllerForAllWindows(); |
| return true; |
| } |
| void DesktopBackgroundController::CreateEmptyWallpaper() { |
| - current_wallpaper_.reset(NULL); |
| - SetDesktopBackgroundImageMode(); |
| + current_wallpaper_.reset(nullptr); |
|
James Cook
2016/08/02 16:51:50
optional nit: or just reset()
msw
2016/08/02 18:28:56
Done.
|
| + desktop_background_mode_ = BACKGROUND_IMAGE; |
| + InstallDesktopControllerForAllWindows(); |
| } |
| bool DesktopBackgroundController::MoveDesktopToLockedContainer() { |
| @@ -132,8 +117,7 @@ void DesktopBackgroundController::OnDisplayConfigurationChanged() { |
| gfx::Size max_display_size = GetMaxDisplaySizeInNative(); |
| if (current_max_display_size_ != max_display_size) { |
| current_max_display_size_ = max_display_size; |
| - if (desktop_background_mode_ == BACKGROUND_IMAGE && |
| - current_wallpaper_.get()) { |
| + if (desktop_background_mode_ == BACKGROUND_IMAGE && current_wallpaper_) { |
| timer_.Stop(); |
| timer_.Start(FROM_HERE, |
| base::TimeDelta::FromMilliseconds(wallpaper_reload_delay_), |
| @@ -152,12 +136,11 @@ void DesktopBackgroundController::OnRootWindowAdded(WmWindow* root_window) { |
| gfx::Size max_display_size = GetMaxDisplaySizeInNative(); |
| if (current_max_display_size_ != max_display_size) { |
| current_max_display_size_ = max_display_size; |
| - if (desktop_background_mode_ == BACKGROUND_IMAGE && |
| - current_wallpaper_.get()) |
| + if (desktop_background_mode_ == BACKGROUND_IMAGE && current_wallpaper_) |
| UpdateWallpaper(true /* clear cache */); |
| } |
| - InstallDesktopController(WmWindowAura::GetAuraWindow(root_window)); |
| + InstallDesktopController(root_window); |
| } |
| // static |
| @@ -166,89 +149,71 @@ gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() { |
| if (!display::Screen::GetScreen()) |
| return gfx::Size(); |
| - int width = 0; |
| - int height = 0; |
| - DisplayManager* display_manager = |
| - Shell::HasInstance() ? Shell::GetInstance()->display_manager() : nullptr; |
| + gfx::Size max; |
| for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) { |
| - // Don't use size_in_pixel because we want to use the native pixel size. |
| - // TODO(msw): Fix this for Mash/Mus; see http://crbug.com/613657. |
| - gfx::Size size_in_pixel = |
| - display_manager |
| - ? display_manager->GetDisplayInfo(display.id()) |
| - .bounds_in_native() |
| - .size() |
| - : display.size(); |
| + // Use the native size, not DisplayInfo::size_in_pixel or Display::size. |
| + gfx::Size size = |
| + WmShell::Get()->GetDisplayInfo(display.id()).bounds_in_native().size(); |
| + // TODO(msw): Avoid using Display::size here; see http://crbug.com/613657. |
| + size.SetToMax(display.size()); |
| if (display.rotation() == display::Display::ROTATE_90 || |
| display.rotation() == display::Display::ROTATE_270) { |
| - size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width()); |
| + size = gfx::Size(size.height(), size.width()); |
| } |
| - width = std::max(size_in_pixel.width(), width); |
| - height = std::max(size_in_pixel.height(), height); |
| + max.SetToMax(size); |
| } |
| - return gfx::Size(width, height); |
| + |
| + return max; |
| } |
| bool DesktopBackgroundController::WallpaperIsAlreadyLoaded( |
| const gfx::ImageSkia& image, |
| bool compare_layouts, |
| - WallpaperLayout layout) const { |
| - if (!current_wallpaper_.get()) |
| + wallpaper::WallpaperLayout layout) const { |
| + if (!current_wallpaper_) |
| return false; |
| // Compare layouts only if necessary. |
| if (compare_layouts && layout != current_wallpaper_->layout()) |
| return false; |
| - return WallpaperResizer::GetImageId(image) == |
| + return wallpaper::WallpaperResizer::GetImageId(image) == |
| current_wallpaper_->original_image_id(); |
| } |
| -void DesktopBackgroundController::SetDesktopBackgroundImageMode() { |
| - desktop_background_mode_ = BACKGROUND_IMAGE; |
| - InstallDesktopControllerForAllWindows(); |
| -} |
| - |
| void DesktopBackgroundController::InstallDesktopController( |
| - aura::Window* root_window) { |
| - DesktopBackgroundWidgetController* component = NULL; |
| + WmWindow* root_window) { |
| + DesktopBackgroundWidgetController* component = nullptr; |
| int container_id = GetBackgroundContainerId(locked_); |
| switch (desktop_background_mode_) { |
| case BACKGROUND_IMAGE: { |
| - views::Widget* widget = |
| - CreateDesktopBackground(root_window, container_id); |
| - component = new DesktopBackgroundWidgetController(widget); |
| + component = new DesktopBackgroundWidgetController( |
| + CreateDesktopBackground(root_window, container_id)); |
| break; |
| } |
| case BACKGROUND_NONE: |
| NOTREACHED(); |
| return; |
| } |
| - GetRootWindowController(root_window) |
| - ->SetAnimatingWallpaperController( |
| - new AnimatingDesktopController(component)); |
| - component->StartAnimating(GetRootWindowController(root_window)); |
| + aura::Window* aura_root_window = WmWindowAura::GetAuraWindow(root_window); |
| + RootWindowController* controller = GetRootWindowController(aura_root_window); |
| + controller->SetAnimatingWallpaperController( |
| + new AnimatingDesktopController(component)); |
| + component->StartAnimating(controller); |
| } |
| void DesktopBackgroundController::InstallDesktopControllerForAllWindows() { |
| - aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| - for (aura::Window::Windows::iterator iter = root_windows.begin(); |
| - iter != root_windows.end(); ++iter) { |
| - InstallDesktopController(*iter); |
| - } |
| + for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) |
| + InstallDesktopController(root); |
| current_max_display_size_ = GetMaxDisplaySizeInNative(); |
| } |
| bool DesktopBackgroundController::ReparentBackgroundWidgets(int src_container, |
| int dst_container) { |
| bool moved = false; |
| - Shell::RootWindowControllerList controllers = |
| - Shell::GetAllRootWindowControllers(); |
| - for (Shell::RootWindowControllerList::iterator iter = controllers.begin(); |
| - iter != controllers.end(); ++iter) { |
| - RootWindowController* root_window_controller = *iter; |
| + for (auto root_window_controller : Shell::GetAllRootWindowControllers()) { |
|
James Cook
2016/08/02 16:51:50
nit: auto* or spell out the type
msw
2016/08/02 18:28:56
Done.
|
| // In the steady state (no animation playing) the background widget |
| // controller exists in the RootWindowController. |
| DesktopBackgroundWidgetController* desktop_controller = |
| @@ -267,7 +232,7 @@ bool DesktopBackgroundController::ReparentBackgroundWidgets(int src_container, |
| root_window_controller->animating_wallpaper_controller() |
| ? root_window_controller->animating_wallpaper_controller() |
| ->GetController(false) |
| - : NULL; |
| + : nullptr; |
| if (animating_controller) { |
| moved |= animating_controller->Reparent( |
| root_window_controller->GetRootWindow(), src_container, |
| @@ -283,9 +248,8 @@ int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { |
| } |
| void DesktopBackgroundController::UpdateWallpaper(bool clear_cache) { |
| - current_wallpaper_.reset(NULL); |
| - ash::Shell::GetInstance()->user_wallpaper_delegate()->UpdateWallpaper( |
| - clear_cache); |
| + current_wallpaper_.reset(nullptr); |
|
James Cook
2016/08/02 16:51:50
optional nit: reset()
msw
2016/08/02 18:28:57
Done.
|
| + Shell::GetInstance()->user_wallpaper_delegate()->UpdateWallpaper(clear_cache); |
| } |
| } // namespace ash |