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 | |
166 void DesktopBackgroundController::SetDefaultWallpaper(int index, | 154 void DesktopBackgroundController::SetDefaultWallpaper(int index, |
167 bool force_reload) { | 155 bool force_reload) { |
168 // We should not change background when index is invalid. For instance, at | 156 // We should not change background when index is invalid. For instance, at |
169 // login screen or stub_user login. | 157 // login screen or stub_user login. |
170 if (index == GetInvalidWallpaperIndex()) { | 158 if (index == GetInvalidWallpaperIndex()) { |
171 CreateEmptyWallpaper(); | 159 CreateEmptyWallpaper(); |
172 return; | 160 return; |
173 } else if (index == GetSolidColorIndex()) { | 161 } else if (index == GetSolidColorIndex()) { |
174 SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor); | 162 SetDesktopBackgroundSolidColorMode(kLoginWallpaperColor); |
175 return; | 163 return; |
176 } | 164 } |
177 | 165 |
178 if (!force_reload && current_wallpaper_.get() && | 166 if (!force_reload && current_wallpaper_.get() && |
179 current_wallpaper_->wallpaper_index == index) | 167 current_wallpaper_->wallpaper_index == index) |
180 return; | 168 return; |
181 | 169 |
182 CancelPendingWallpaperOperation(); | 170 CancelPendingWallpaperOperation(); |
183 | 171 |
184 WallpaperResolution resolution = GetAppropriateResolution(); | 172 WallpaperResolution resolution = SMALL; |
| 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 } |
185 | 181 |
186 wallpaper_op_ = new WallpaperOperation(index, resolution); | 182 wallpaper_op_ = new WallpaperOperation(index, resolution); |
187 base::WorkerPool::PostTaskAndReply( | 183 base::WorkerPool::PostTaskAndReply( |
188 FROM_HERE, | 184 FROM_HERE, |
189 base::Bind(&WallpaperOperation::Run, wallpaper_op_), | 185 base::Bind(&WallpaperOperation::Run, wallpaper_op_), |
190 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, | 186 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, |
191 weak_ptr_factory_.GetWeakPtr(), | 187 weak_ptr_factory_.GetWeakPtr(), |
192 wallpaper_op_), | 188 wallpaper_op_), |
193 true /* task_is_slow */); | 189 true /* task_is_slow */); |
194 } | 190 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 src_container, | 348 src_container, |
353 dst_container); | 349 dst_container); |
354 } | 350 } |
355 } | 351 } |
356 | 352 |
357 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { | 353 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { |
358 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer : | 354 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer : |
359 internal::kShellWindowId_DesktopBackgroundContainer; | 355 internal::kShellWindowId_DesktopBackgroundContainer; |
360 } | 356 } |
361 | 357 |
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 | |
375 } // namespace ash | 358 } // namespace ash |
OLD | NEW |