Chromium Code Reviews| 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/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_factory.h" | 9 #include "ash/shell_factory.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 | 78 |
| 79 base::CancellationFlag cancel_flag_; | 79 base::CancellationFlag cancel_flag_; |
| 80 | 80 |
| 81 const gfx::ImageSkia* wallpaper_; | 81 const gfx::ImageSkia* wallpaper_; |
| 82 WallpaperLayout layout_; | 82 WallpaperLayout layout_; |
| 83 int index_; | 83 int index_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(WallpaperOperation); | 85 DISALLOW_COPY_AND_ASSIGN(WallpaperOperation); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 DesktopBackgroundController::DesktopBackgroundController( | 88 DesktopBackgroundController::DesktopBackgroundController() |
| 89 aura::RootWindow* root_window) | 89 : desktop_background_mode_(BACKGROUND_IMAGE), |
| 90 : root_window_(root_window), | |
| 91 desktop_background_mode_(BACKGROUND_IMAGE), | |
| 92 previous_index_(-1), | 90 previous_index_(-1), |
| 93 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 91 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 94 DCHECK(root_window_); | |
| 95 } | 92 } |
| 96 | 93 |
| 97 DesktopBackgroundController::~DesktopBackgroundController() { | 94 DesktopBackgroundController::~DesktopBackgroundController() { |
| 98 CancelPendingWallpaperOperation(); | 95 CancelPendingWallpaperOperation(); |
| 99 } | 96 } |
| 100 | 97 |
| 101 void DesktopBackgroundController::SetDefaultWallpaper(int index) { | 98 void DesktopBackgroundController::SetDefaultWallpaper(int index) { |
| 102 // We should not change background when index is invalid. For instance, at | 99 // We should not change background when index is invalid. For instance, at |
| 103 // login screen or stub_user login. | 100 // login screen or stub_user login. |
| 104 if (index == ash::GetInvalidWallpaperIndex()) { | 101 if (index == ash::GetInvalidWallpaperIndex()) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 120 base::Bind(&WallpaperOperation::Run, wallpaper_op_), | 117 base::Bind(&WallpaperOperation::Run, wallpaper_op_), |
| 121 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, | 118 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, |
| 122 weak_ptr_factory_.GetWeakPtr(), | 119 weak_ptr_factory_.GetWeakPtr(), |
| 123 wallpaper_op_), | 120 wallpaper_op_), |
| 124 true /* task_is_slow */); | 121 true /* task_is_slow */); |
| 125 } | 122 } |
| 126 | 123 |
| 127 void DesktopBackgroundController::SetCustomWallpaper( | 124 void DesktopBackgroundController::SetCustomWallpaper( |
| 128 const gfx::ImageSkia& wallpaper, | 125 const gfx::ImageSkia& wallpaper, |
| 129 WallpaperLayout layout) { | 126 WallpaperLayout layout) { |
| 130 GetRootWindowLayoutManager(root_window_)->SetBackgroundLayer(NULL); | 127 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| 131 internal::CreateDesktopBackground(wallpaper, layout, root_window_); | 128 GetRootWindowLayoutManager(root_window)->SetBackgroundLayer(NULL); |
| 129 internal::CreateDesktopBackground(wallpaper, layout, root_window); | |
| 132 desktop_background_mode_ = BACKGROUND_IMAGE; | 130 desktop_background_mode_ = BACKGROUND_IMAGE; |
| 133 } | 131 } |
| 134 | 132 |
| 135 void DesktopBackgroundController::CancelPendingWallpaperOperation() { | 133 void DesktopBackgroundController::CancelPendingWallpaperOperation() { |
| 136 // Set canceled flag of previous request to skip unneeded loading. | 134 // Set canceled flag of previous request to skip unneeded loading. |
| 137 if (wallpaper_op_.get()) | 135 if (wallpaper_op_.get()) |
| 138 wallpaper_op_->Cancel(); | 136 wallpaper_op_->Cancel(); |
| 139 | 137 |
| 140 // Cancel reply callback for previous request. | 138 // Cancel reply callback for previous request. |
| 141 weak_ptr_factory_.InvalidateWeakPtrs(); | 139 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 142 } | 140 } |
| 143 | 141 |
| 144 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode( | 142 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode( |
| 145 SkColor color) { | 143 SkColor color) { |
| 146 // Set a solid black background. | 144 // Set a solid black background. |
| 147 // TODO(derat): Remove this in favor of having the compositor only clear the | 145 // TODO(derat): Remove this in favor of having the compositor only clear the |
| 148 // viewport when there are regions not covered by a layer: | 146 // viewport when there are regions not covered by a layer: |
| 149 // http://crbug.com/113445 | 147 // http://crbug.com/113445 |
| 150 ui::Layer* background_layer = new ui::Layer(ui::LAYER_SOLID_COLOR); | 148 ui::Layer* background_layer = new ui::Layer(ui::LAYER_SOLID_COLOR); |
| 151 background_layer->SetColor(color); | 149 background_layer->SetColor(color); |
| 152 root_window_->GetChildById( | 150 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| 151 Shell::GetContainer( | |
| 152 root_window, | |
| 153 internal::kShellWindowId_DesktopBackgroundContainer)-> | 153 internal::kShellWindowId_DesktopBackgroundContainer)-> |
| 154 layer()->Add(background_layer); | 154 layer()->Add(background_layer); |
| 155 GetRootWindowLayoutManager(root_window_)->SetBackgroundLayer( | 155 GetRootWindowLayoutManager(root_window)->SetBackgroundLayer( |
| 156 background_layer); | 156 background_layer); |
| 157 GetRootWindowLayoutManager(root_window_)->SetBackgroundWidget(NULL); | 157 GetRootWindowLayoutManager(root_window)->SetBackgroundWidget(NULL); |
| 158 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; | 158 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; |
| 159 } | 159 } |
| 160 | 160 |
| 161 void DesktopBackgroundController::SetDesktopBackgroundImageMode( | 161 void DesktopBackgroundController::SetDesktopBackgroundImageMode( |
| 162 scoped_refptr<WallpaperOperation> wo) { | 162 scoped_refptr<WallpaperOperation> wo) { |
| 163 GetRootWindowLayoutManager(root_window_)->SetBackgroundLayer(NULL); | 163 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| 164 GetRootWindowLayoutManager(root_window)->SetBackgroundLayer(NULL); | |
| 164 if(wo->wallpaper()) { | 165 if(wo->wallpaper()) { |
|
Daniel Erat
2012/06/12 21:42:22
nit: add missing space after 'if'
oshima
2012/06/12 21:51:55
Done.
| |
| 165 internal::CreateDesktopBackground( | 166 internal::CreateDesktopBackground( |
| 166 *wo->wallpaper(), wo->wallpaper_layout(), root_window_); | 167 *wo->wallpaper(), wo->wallpaper_layout(), root_window); |
| 167 desktop_background_mode_ = BACKGROUND_IMAGE; | 168 desktop_background_mode_ = BACKGROUND_IMAGE; |
| 168 } | 169 } |
| 169 } | 170 } |
| 170 | 171 |
| 171 void DesktopBackgroundController::OnWallpaperLoadCompleted( | 172 void DesktopBackgroundController::OnWallpaperLoadCompleted( |
| 172 scoped_refptr<WallpaperOperation> wo) { | 173 scoped_refptr<WallpaperOperation> wo) { |
| 173 SetDesktopBackgroundImageMode(wo); | 174 SetDesktopBackgroundImageMode(wo); |
| 174 previous_index_ = wo->index(); | 175 previous_index_ = wo->index(); |
| 175 | 176 |
| 176 DCHECK(wo.get() == wallpaper_op_.get()); | 177 DCHECK(wo.get() == wallpaper_op_.get()); |
| 177 wallpaper_op_ = NULL; | 178 wallpaper_op_ = NULL; |
| 178 } | 179 } |
| 179 | 180 |
| 180 void DesktopBackgroundController::CreateEmptyWallpaper() { | 181 void DesktopBackgroundController::CreateEmptyWallpaper() { |
| 181 gfx::ImageSkia dummy; | 182 gfx::ImageSkia dummy; |
| 182 internal::CreateDesktopBackground(dummy, CENTER, root_window_); | 183 internal::CreateDesktopBackground( |
| 184 dummy, CENTER, Shell::GetPrimaryRootWindow()); | |
| 183 desktop_background_mode_ = BACKGROUND_IMAGE; | 185 desktop_background_mode_ = BACKGROUND_IMAGE; |
| 184 } | 186 } |
| 185 | 187 |
| 186 } // namespace ash | 188 } // namespace ash |
| OLD | NEW |