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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 wallpaper_height < root_window_size.height()) && | 144 wallpaper_height < root_window_size.height()) && |
145 current_wallpaper_->wallpaper_index != -1 && | 145 current_wallpaper_->wallpaper_index != -1 && |
146 current_wallpaper_->wallpaper_layout != TILE) | 146 current_wallpaper_->wallpaper_layout != TILE) |
147 SetDefaultWallpaper(current_wallpaper_->wallpaper_index, true); | 147 SetDefaultWallpaper(current_wallpaper_->wallpaper_index, true); |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 InstallComponent(root_window); | 151 InstallComponent(root_window); |
152 } | 152 } |
153 | 153 |
| 154 void DesktopBackgroundController::CacheDefaultWallpaper(int index) { |
| 155 DCHECK(index >= 0); |
| 156 |
| 157 WallpaperResolution resolution = GetAppropriateResolution(); |
| 158 scoped_refptr<WallpaperOperation> wallpaper_op = |
| 159 new WallpaperOperation(index, resolution); |
| 160 base::WorkerPool::PostTask( |
| 161 FROM_HERE, |
| 162 base::Bind(&WallpaperOperation::Run, wallpaper_op), |
| 163 true); |
| 164 } |
| 165 |
154 void DesktopBackgroundController::SetDefaultWallpaper(int index, | 166 void DesktopBackgroundController::SetDefaultWallpaper(int index, |
155 bool force_reload) { | 167 bool force_reload) { |
156 // We should not change background when index is invalid. For instance, at | 168 // We should not change background when index is invalid. For instance, at |
157 // login screen or stub_user login. | 169 // login screen or stub_user login. |
158 if (index == GetInvalidWallpaperIndex()) { | 170 if (index == GetInvalidWallpaperIndex()) { |
159 CreateEmptyWallpaper(); | 171 CreateEmptyWallpaper(); |
160 return; | 172 return; |
161 } else if (index == GetSolidColorIndex()) { | 173 } else if (index == GetSolidColorIndex()) { |
162 SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor); | 174 SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor); |
163 return; | 175 return; |
164 } | 176 } |
165 | 177 |
166 if (!force_reload && current_wallpaper_.get() && | 178 if (!force_reload && current_wallpaper_.get() && |
167 current_wallpaper_->wallpaper_index == index) | 179 current_wallpaper_->wallpaper_index == index) |
168 return; | 180 return; |
169 | 181 |
170 CancelPendingWallpaperOperation(); | 182 CancelPendingWallpaperOperation(); |
171 | 183 |
172 WallpaperResolution resolution = SMALL; | 184 WallpaperResolution resolution = GetAppropriateResolution(); |
173 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
174 for (Shell::RootWindowList::iterator iter = root_windows.begin(); | |
175 iter != root_windows.end(); ++iter) { | |
176 gfx::Size root_window_size = (*iter)->GetHostSize(); | |
177 if (root_window_size.width() > kSmallWallpaperMaximalWidth || | |
178 root_window_size.height() > kSmallWallpaperMaximalHeight) | |
179 resolution = LARGE; | |
180 } | |
181 | 185 |
182 wallpaper_op_ = new WallpaperOperation(index, resolution); | 186 wallpaper_op_ = new WallpaperOperation(index, resolution); |
183 base::WorkerPool::PostTaskAndReply( | 187 base::WorkerPool::PostTaskAndReply( |
184 FROM_HERE, | 188 FROM_HERE, |
185 base::Bind(&WallpaperOperation::Run, wallpaper_op_), | 189 base::Bind(&WallpaperOperation::Run, wallpaper_op_), |
186 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, | 190 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, |
187 weak_ptr_factory_.GetWeakPtr(), | 191 weak_ptr_factory_.GetWeakPtr(), |
188 wallpaper_op_), | 192 wallpaper_op_), |
189 true /* task_is_slow */); | 193 true /* task_is_slow */); |
190 } | 194 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 src_container, | 352 src_container, |
349 dst_container); | 353 dst_container); |
350 } | 354 } |
351 } | 355 } |
352 | 356 |
353 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { | 357 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { |
354 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer : | 358 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer : |
355 internal::kShellWindowId_DesktopBackgroundContainer; | 359 internal::kShellWindowId_DesktopBackgroundContainer; |
356 } | 360 } |
357 | 361 |
| 362 WallpaperResolution DesktopBackgroundController::GetAppropriateResolution() { |
| 363 WallpaperResolution resolution = SMALL; |
| 364 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 365 for (Shell::RootWindowList::iterator iter = root_windows.begin(); |
| 366 iter != root_windows.end(); ++iter) { |
| 367 gfx::Size root_window_size = (*iter)->GetHostSize(); |
| 368 if (root_window_size.width() > kSmallWallpaperMaximalWidth || |
| 369 root_window_size.height() > kSmallWallpaperMaximalHeight) |
| 370 resolution = LARGE; |
| 371 } |
| 372 return resolution; |
| 373 } |
| 374 |
358 } // namespace ash | 375 } // namespace ash |
OLD | NEW |