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

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

Issue 17502005: Revert r207560 and r207566 to reland r207511. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add more SupportsMultipleDisplays checks Created 7 years, 6 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/desktop_background/desktop_background_controller_observer.h" 8 #include "ash/desktop_background/desktop_background_controller_observer.h"
8 #include "ash/desktop_background/desktop_background_view.h" 9 #include "ash/desktop_background/desktop_background_view.h"
9 #include "ash/desktop_background/desktop_background_widget_controller.h" 10 #include "ash/desktop_background/desktop_background_widget_controller.h"
10 #include "ash/desktop_background/user_wallpaper_delegate.h" 11 #include "ash/desktop_background/user_wallpaper_delegate.h"
11 #include "ash/desktop_background/wallpaper_resizer.h" 12 #include "ash/desktop_background/wallpaper_resizer.h"
12 #include "ash/root_window_controller.h" 13 #include "ash/root_window_controller.h"
13 #include "ash/shell.h" 14 #include "ash/shell.h"
14 #include "ash/shell_factory.h" 15 #include "ash/shell_factory.h"
15 #include "ash/shell_window_ids.h" 16 #include "ash/shell_window_ids.h"
16 #include "ash/wm/root_window_layout_manager.h" 17 #include "ash/wm/root_window_layout_manager.h"
17 #include "base/bind.h" 18 #include "base/bind.h"
19 #include "base/command_line.h"
20 #include "base/file_util.h"
18 #include "base/logging.h" 21 #include "base/logging.h"
19 #include "base/synchronization/cancellation_flag.h" 22 #include "base/synchronization/cancellation_flag.h"
20 #include "base/threading/worker_pool.h" 23 #include "base/threading/worker_pool.h"
21 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
22 #include "grit/ash_wallpaper_resources.h" 25 #include "grit/ash_wallpaper_resources.h"
23 #include "ui/aura/root_window.h" 26 #include "ui/aura/root_window.h"
24 #include "ui/aura/window.h" 27 #include "ui/aura/window.h"
25 #include "ui/compositor/layer.h" 28 #include "ui/compositor/layer.h"
29 #include "ui/gfx/codec/jpeg_codec.h"
30 #include "ui/gfx/image/image_skia.h"
26 #include "ui/gfx/rect.h" 31 #include "ui/gfx/rect.h"
27 #include "ui/gfx/image/image.h"
28 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
29 33
30 using ash::internal::DesktopBackgroundWidgetController; 34 using ash::internal::DesktopBackgroundWidgetController;
31 using ash::internal::kAnimatingDesktopController; 35 using ash::internal::kAnimatingDesktopController;
32 using ash::internal::kDesktopController; 36 using ash::internal::kDesktopController;
33 using content::BrowserThread; 37 using content::BrowserThread;
34 38
35 namespace ash { 39 namespace ash {
36 namespace { 40 namespace {
37 41
(...skipping 16 matching lines...) Expand all
54 if (root_window_size.width() > width) 58 if (root_window_size.width() > width)
55 width = root_window_size.width(); 59 width = root_window_size.width();
56 if (root_window_size.height() > height) 60 if (root_window_size.height() > height)
57 height = root_window_size.height(); 61 height = root_window_size.height();
58 } 62 }
59 return gfx::Size(width, height); 63 return gfx::Size(width, height);
60 } 64 }
61 65
62 } // namespace 66 } // namespace
63 67
64 #if defined(GOOGLE_CHROME_BUILD)
65 const WallpaperInfo kDefaultLargeWallpaper =
66 { IDR_AURA_WALLPAPERS_2_LANDSCAPE8_LARGE, WALLPAPER_LAYOUT_CENTER_CROPPED };
67 const WallpaperInfo kDefaultSmallWallpaper =
68 { IDR_AURA_WALLPAPERS_2_LANDSCAPE8_SMALL, WALLPAPER_LAYOUT_CENTER };
69 const WallpaperInfo kGuestLargeWallpaper =
70 { IDR_AURA_WALLPAPERS_2_LANDSCAPE7_LARGE, WALLPAPER_LAYOUT_CENTER_CROPPED };
71 const WallpaperInfo kGuestSmallWallpaper =
72 { IDR_AURA_WALLPAPERS_2_LANDSCAPE7_SMALL, WALLPAPER_LAYOUT_CENTER };
73 #else
74 const WallpaperInfo kDefaultLargeWallpaper =
75 { IDR_AURA_WALLPAPERS_5_GRADIENT5_LARGE, WALLPAPER_LAYOUT_TILE };
76 const WallpaperInfo kDefaultSmallWallpaper =
77 { IDR_AURA_WALLPAPERS_5_GRADIENT5_SMALL, WALLPAPER_LAYOUT_TILE };
78 const WallpaperInfo kGuestLargeWallpaper = kDefaultLargeWallpaper;
79 const WallpaperInfo kGuestSmallWallpaper = kDefaultSmallWallpaper;
80 #endif
81
82 const int kSmallWallpaperMaxWidth = 1366; 68 const int kSmallWallpaperMaxWidth = 1366;
83 const int kSmallWallpaperMaxHeight = 800; 69 const int kSmallWallpaperMaxHeight = 800;
84 const int kLargeWallpaperMaxWidth = 2560; 70 const int kLargeWallpaperMaxWidth = 2560;
85 const int kLargeWallpaperMaxHeight = 1700; 71 const int kLargeWallpaperMaxHeight = 1700;
86 const int kWallpaperThumbnailWidth = 108; 72 const int kWallpaperThumbnailWidth = 108;
87 const int kWallpaperThumbnailHeight = 68; 73 const int kWallpaperThumbnailHeight = 68;
88 74
89 // DesktopBackgroundController::WallpaperLoader wraps background wallpaper 75 // DesktopBackgroundController::WallpaperLoader wraps background wallpaper
90 // loading. 76 // loading.
91 class DesktopBackgroundController::WallpaperLoader 77 class DesktopBackgroundController::WallpaperLoader
92 : public base::RefCountedThreadSafe< 78 : public base::RefCountedThreadSafe<
93 DesktopBackgroundController::WallpaperLoader> { 79 DesktopBackgroundController::WallpaperLoader> {
94 public: 80 public:
95 explicit WallpaperLoader(const WallpaperInfo& info) 81 // If set, |file_path| must be a trusted (i.e. read-only,
96 : info_(info) { 82 // non-user-controlled) file containing a JPEG image.
83 WallpaperLoader(const base::FilePath& file_path,
84 WallpaperLayout file_layout,
85 int resource_id,
86 WallpaperLayout resource_layout)
87 : file_path_(file_path),
88 file_layout_(file_layout),
89 resource_id_(resource_id),
90 resource_layout_(resource_layout) {
97 } 91 }
98 92
99 static void LoadOnWorkerPoolThread(scoped_refptr<WallpaperLoader> wl) { 93 static void LoadOnWorkerPoolThread(scoped_refptr<WallpaperLoader> loader) {
100 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 94 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
101 wl->LoadingWallpaper(); 95 loader->LoadWallpaper();
102 } 96 }
103 97
98 const base::FilePath& file_path() const { return file_path_; }
99 int resource_id() const { return resource_id_; }
100
104 void Cancel() { 101 void Cancel() {
105 cancel_flag_.Set(); 102 cancel_flag_.Set();
106 } 103 }
107 104
108 int idr() const {
109 return info_.idr;
110 }
111
112 WallpaperResizer* ReleaseWallpaperResizer() { 105 WallpaperResizer* ReleaseWallpaperResizer() {
113 return wallpaper_resizer_.release(); 106 return wallpaper_resizer_.release();
114 } 107 }
115 108
116 private: 109 private:
117 friend class base::RefCountedThreadSafe< 110 friend class base::RefCountedThreadSafe<
118 DesktopBackgroundController::WallpaperLoader>; 111 DesktopBackgroundController::WallpaperLoader>;
119 112
120 void LoadingWallpaper() { 113 // Loads a JPEG image from |path|, a trusted file -- note that the image
114 // is not loaded in a sandboxed process. Returns an empty pointer on
115 // error.
116 static scoped_ptr<SkBitmap> LoadSkBitmapFromJPEGFile(
117 const base::FilePath& path) {
118 std::string data;
119 if (!file_util::ReadFileToString(path, &data)) {
120 LOG(ERROR) << "Unable to read data from " << path.value();
121 return scoped_ptr<SkBitmap>();
122 }
123
124 scoped_ptr<SkBitmap> bitmap(gfx::JPEGCodec::Decode(
125 reinterpret_cast<const unsigned char*>(data.data()), data.size()));
126 if (!bitmap)
127 LOG(ERROR) << "Unable to decode JPEG data from " << path.value();
128 return bitmap.Pass();
129 }
130
131 void LoadWallpaper() {
121 if (cancel_flag_.IsSet()) 132 if (cancel_flag_.IsSet())
122 return; 133 return;
123 wallpaper_resizer_.reset(new WallpaperResizer(info_, GetRootWindowsSize())); 134
135 if (!file_path_.empty())
136 file_bitmap_ = LoadSkBitmapFromJPEGFile(file_path_);
137
138 if (cancel_flag_.IsSet())
139 return;
140
141 if (file_bitmap_) {
142 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(*file_bitmap_);
143 wallpaper_resizer_.reset(new WallpaperResizer(
144 image, GetRootWindowsSize(), file_layout_));
145 } else {
146 wallpaper_resizer_.reset(new WallpaperResizer(
147 resource_id_, GetRootWindowsSize(), resource_layout_));
148 }
124 } 149 }
125 150
126 ~WallpaperLoader() {} 151 ~WallpaperLoader() {}
127 152
128 base::CancellationFlag cancel_flag_; 153 base::CancellationFlag cancel_flag_;
129 154
155 // Bitmap loaded from |file_path_|.
156 scoped_ptr<SkBitmap> file_bitmap_;
157
130 scoped_ptr<WallpaperResizer> wallpaper_resizer_; 158 scoped_ptr<WallpaperResizer> wallpaper_resizer_;
131 159
132 const WallpaperInfo info_; 160 // Path to a trusted JPEG file.
161 base::FilePath file_path_;
162
163 // Layout to be used when displaying the image from |file_path_|.
164 WallpaperLayout file_layout_;
165
166 // ID of an image resource to use if |file_path_| is empty or unloadable.
167 int resource_id_;
168
169 // Layout to be used when displaying |resource_id_|.
170 WallpaperLayout resource_layout_;
133 171
134 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader); 172 DISALLOW_COPY_AND_ASSIGN(WallpaperLoader);
135 }; 173 };
136 174
137 DesktopBackgroundController::DesktopBackgroundController() 175 DesktopBackgroundController::DesktopBackgroundController()
138 : locked_(false), 176 : command_line_for_testing_(NULL),
177 locked_(false),
139 desktop_background_mode_(BACKGROUND_NONE), 178 desktop_background_mode_(BACKGROUND_NONE),
140 background_color_(kTransparentColor), 179 background_color_(kTransparentColor),
180 current_default_wallpaper_resource_id_(-1),
141 weak_ptr_factory_(this) { 181 weak_ptr_factory_(this) {
142 } 182 }
143 183
144 DesktopBackgroundController::~DesktopBackgroundController() { 184 DesktopBackgroundController::~DesktopBackgroundController() {
145 CancelPendingWallpaperOperation(); 185 CancelPendingWallpaperOperation();
146 } 186 }
147 187
148 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const { 188 gfx::ImageSkia DesktopBackgroundController::GetWallpaper() const {
149 if (current_wallpaper_) 189 if (current_wallpaper_)
150 return current_wallpaper_->wallpaper_image(); 190 return current_wallpaper_->wallpaper_image();
151 return gfx::ImageSkia(); 191 return gfx::ImageSkia();
152 } 192 }
153 193
154 void DesktopBackgroundController::AddObserver( 194 void DesktopBackgroundController::AddObserver(
155 DesktopBackgroundControllerObserver* observer) { 195 DesktopBackgroundControllerObserver* observer) {
156 observers_.AddObserver(observer); 196 observers_.AddObserver(observer);
157 } 197 }
158 198
159 void DesktopBackgroundController::RemoveObserver( 199 void DesktopBackgroundController::RemoveObserver(
160 DesktopBackgroundControllerObserver* observer) { 200 DesktopBackgroundControllerObserver* observer) {
161 observers_.RemoveObserver(observer); 201 observers_.RemoveObserver(observer);
162 } 202 }
163 203
164 WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const { 204 WallpaperLayout DesktopBackgroundController::GetWallpaperLayout() const {
165 if (current_wallpaper_) 205 if (current_wallpaper_)
166 return current_wallpaper_->wallpaper_info().layout; 206 return current_wallpaper_->layout();
167 return WALLPAPER_LAYOUT_CENTER_CROPPED; 207 return WALLPAPER_LAYOUT_CENTER_CROPPED;
168 } 208 }
169 209
170 gfx::ImageSkia DesktopBackgroundController::GetCurrentWallpaperImage() {
171 if (desktop_background_mode_ != BACKGROUND_IMAGE)
172 return gfx::ImageSkia();
173 return GetWallpaper();
174 }
175
176 int DesktopBackgroundController::GetWallpaperIDR() const {
177 if (wallpaper_loader_.get())
178 return wallpaper_loader_->idr();
179 else if (current_wallpaper_)
180 return current_wallpaper_->wallpaper_info().idr;
181 else
182 return -1;
183 }
184
185 void DesktopBackgroundController::OnRootWindowAdded( 210 void DesktopBackgroundController::OnRootWindowAdded(
186 aura::RootWindow* root_window) { 211 aura::RootWindow* root_window) {
187 // The background hasn't been set yet. 212 // The background hasn't been set yet.
188 if (desktop_background_mode_ == BACKGROUND_NONE) 213 if (desktop_background_mode_ == BACKGROUND_NONE)
189 return; 214 return;
190 215
191 // Handle resolution change for "built-in" images. 216 // Handle resolution change for "built-in" images.
192 if (BACKGROUND_IMAGE == desktop_background_mode_ && 217 if (BACKGROUND_IMAGE == desktop_background_mode_ &&
193 current_wallpaper_.get()) { 218 current_wallpaper_.get()) {
194 gfx::Size root_window_size = root_window->GetHostSize(); 219 gfx::Size root_window_size = root_window->GetHostSize();
195 int width = current_wallpaper_->wallpaper_image().width(); 220 int width = current_wallpaper_->wallpaper_image().width();
196 int height = current_wallpaper_->wallpaper_image().height(); 221 int height = current_wallpaper_->wallpaper_image().height();
197 // Reloads wallpaper if current wallpaper is smaller than the new added root 222 // Reloads wallpaper if current wallpaper is smaller than the new added root
198 // window. 223 // window.
199 if (width < root_window_size.width() || 224 if (width < root_window_size.width() ||
200 height < root_window_size.height()) { 225 height < root_window_size.height()) {
201 current_wallpaper_.reset(NULL); 226 current_wallpaper_.reset(NULL);
227 current_default_wallpaper_path_ = base::FilePath();
228 current_default_wallpaper_resource_id_ = -1;
202 ash::Shell::GetInstance()->user_wallpaper_delegate()-> 229 ash::Shell::GetInstance()->user_wallpaper_delegate()->
203 UpdateWallpaper(); 230 UpdateWallpaper();
204 } 231 }
205 } 232 }
206 233
207 InstallDesktopController(root_window); 234 InstallDesktopController(root_window);
208 } 235 }
209 236
210 void DesktopBackgroundController::SetDefaultWallpaper( 237 bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) {
211 const WallpaperInfo& info) { 238 const bool use_large =
212 DCHECK_NE(GetWallpaperIDR(), info.idr); 239 GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE;
240
241 base::FilePath file_path;
242 WallpaperLayout file_layout = use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED :
243 WALLPAPER_LAYOUT_CENTER;
244 int resource_id = -1;
245 WallpaperLayout resource_layout = WALLPAPER_LAYOUT_TILE;
246
247 #if defined(GOOGLE_CHROME_BUILD)
248 if (use_large) {
249 resource_id = is_guest ? IDR_AURA_WALLPAPERS_2_LANDSCAPE7_LARGE :
250 IDR_AURA_WALLPAPERS_2_LANDSCAPE8_LARGE;
251 resource_layout = WALLPAPER_LAYOUT_CENTER_CROPPED;
252 } else {
253 resource_id = is_guest ? IDR_AURA_WALLPAPERS_2_LANDSCAPE7_SMALL :
254 IDR_AURA_WALLPAPERS_2_LANDSCAPE8_SMALL;
255 resource_layout = WALLPAPER_LAYOUT_CENTER;
256 }
257 #else
258 resource_id = use_large ? IDR_AURA_WALLPAPERS_5_GRADIENT5_LARGE :
259 IDR_AURA_WALLPAPERS_5_GRADIENT5_SMALL;
260 resource_layout = WALLPAPER_LAYOUT_TILE;
261 #endif
262
263 const char* switch_name = is_guest ?
264 (use_large ? switches::kAshDefaultGuestWallpaperLarge :
265 switches::kAshDefaultGuestWallpaperSmall) :
266 (use_large ? switches::kAshDefaultWallpaperLarge :
267 switches::kAshDefaultWallpaperSmall);
268 CommandLine* command_line = command_line_for_testing_ ?
269 command_line_for_testing_ : CommandLine::ForCurrentProcess();
270 file_path = command_line->GetSwitchValuePath(switch_name);
271
272 if (DefaultWallpaperIsAlreadyLoadingOrLoaded(file_path, resource_id))
273 return false;
213 274
214 CancelPendingWallpaperOperation(); 275 CancelPendingWallpaperOperation();
215 wallpaper_loader_ = new WallpaperLoader(info); 276 wallpaper_loader_ = new WallpaperLoader(
277 file_path, file_layout, resource_id, resource_layout);
216 base::WorkerPool::PostTaskAndReply( 278 base::WorkerPool::PostTaskAndReply(
217 FROM_HERE, 279 FROM_HERE,
218 base::Bind(&WallpaperLoader::LoadOnWorkerPoolThread, wallpaper_loader_), 280 base::Bind(&WallpaperLoader::LoadOnWorkerPoolThread, wallpaper_loader_),
219 base::Bind(&DesktopBackgroundController::OnWallpaperLoadCompleted, 281 base::Bind(&DesktopBackgroundController::OnDefaultWallpaperLoadCompleted,
220 weak_ptr_factory_.GetWeakPtr(), 282 weak_ptr_factory_.GetWeakPtr(),
221 wallpaper_loader_), 283 wallpaper_loader_),
222 true /* task_is_slow */); 284 true /* task_is_slow */);
285 return true;
223 } 286 }
224 287
225 void DesktopBackgroundController::SetCustomWallpaper( 288 void DesktopBackgroundController::SetCustomWallpaper(
226 const gfx::ImageSkia& wallpaper, 289 const gfx::ImageSkia& image,
227 WallpaperLayout layout) { 290 WallpaperLayout layout) {
228 CancelPendingWallpaperOperation(); 291 CancelPendingWallpaperOperation();
229 if (current_wallpaper_.get() && 292 if (CustomWallpaperIsAlreadyLoaded(image))
230 current_wallpaper_->wallpaper_image().BackedBySameObjectAs(wallpaper)) {
231 return; 293 return;
232 }
233 294
234 WallpaperInfo info = { -1, layout }; 295 current_wallpaper_.reset(new WallpaperResizer(
235 current_wallpaper_.reset(new WallpaperResizer(info, GetRootWindowsSize(), 296 image, GetRootWindowsSize(), layout));
236 wallpaper));
237 current_wallpaper_->StartResize(); 297 current_wallpaper_->StartResize();
298
299 current_default_wallpaper_path_ = base::FilePath();
300 current_default_wallpaper_resource_id_ = -1;
301
238 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_, 302 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_,
239 OnWallpaperDataChanged()); 303 OnWallpaperDataChanged());
240 SetDesktopBackgroundImageMode(); 304 SetDesktopBackgroundImageMode();
241 } 305 }
242 306
243 void DesktopBackgroundController::CancelPendingWallpaperOperation() { 307 void DesktopBackgroundController::CancelPendingWallpaperOperation() {
244 // Set canceled flag of previous request to skip unneeded loading. 308 // Set canceled flag of previous request to skip unneeded loading.
245 if (wallpaper_loader_.get()) 309 if (wallpaper_loader_.get())
246 wallpaper_loader_->Cancel(); 310 wallpaper_loader_->Cancel();
247 311
248 // Cancel reply callback for previous request. 312 // Cancel reply callback for previous request.
249 weak_ptr_factory_.InvalidateWeakPtrs(); 313 weak_ptr_factory_.InvalidateWeakPtrs();
250 } 314 }
251 315
252 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode( 316 void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode(
253 SkColor color) { 317 SkColor color) {
254 background_color_ = color; 318 background_color_ = color;
255 desktop_background_mode_ = BACKGROUND_SOLID_COLOR; 319 desktop_background_mode_ = BACKGROUND_SOLID_COLOR;
256 320
257 InstallDesktopControllerForAllWindows(); 321 InstallDesktopControllerForAllWindows();
258 } 322 }
259 323
260 void DesktopBackgroundController::CreateEmptyWallpaper() { 324 void DesktopBackgroundController::CreateEmptyWallpaper() {
261 current_wallpaper_.reset(NULL); 325 current_wallpaper_.reset(NULL);
262 SetDesktopBackgroundImageMode(); 326 SetDesktopBackgroundImageMode();
263 } 327 }
264 328
265 WallpaperResolution DesktopBackgroundController::GetAppropriateResolution() { 329 WallpaperResolution DesktopBackgroundController::GetAppropriateResolution() {
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
267 WallpaperResolution resolution = WALLPAPER_RESOLUTION_SMALL;
268 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 331 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
269 for (Shell::RootWindowList::iterator iter = root_windows.begin(); 332 for (Shell::RootWindowList::iterator iter = root_windows.begin();
270 iter != root_windows.end(); ++iter) { 333 iter != root_windows.end(); ++iter) {
271 // Compare to host size as constants are defined in terms of 334 // Compare to host size as constants are defined in terms of
272 // physical pixel size. 335 // physical pixel size.
273 // TODO(oshima): This may not be ideal for fractional scaling 336 // TODO(oshima): This may not be ideal for fractional scaling
274 // scenario. Revisit and fix if necessary. 337 // scenario. Revisit and fix if necessary.
275 gfx::Size host_window_size = (*iter)->GetHostSize(); 338 gfx::Size host_window_size = (*iter)->GetHostSize();
276 if (host_window_size.width() > kSmallWallpaperMaxWidth || 339 if (host_window_size.width() > kSmallWallpaperMaxWidth ||
277 host_window_size.height() > kSmallWallpaperMaxHeight) { 340 host_window_size.height() > kSmallWallpaperMaxHeight)
278 resolution = WALLPAPER_RESOLUTION_LARGE; 341 return WALLPAPER_RESOLUTION_LARGE;
279 }
280 } 342 }
281 return resolution; 343 return WALLPAPER_RESOLUTION_SMALL;
282 } 344 }
283 345
284 bool DesktopBackgroundController::MoveDesktopToLockedContainer() { 346 bool DesktopBackgroundController::MoveDesktopToLockedContainer() {
285 if (locked_) 347 if (locked_)
286 return false; 348 return false;
287 locked_ = true; 349 locked_ = true;
288 return ReparentBackgroundWidgets(GetBackgroundContainerId(false), 350 return ReparentBackgroundWidgets(GetBackgroundContainerId(false),
289 GetBackgroundContainerId(true)); 351 GetBackgroundContainerId(true));
290 } 352 }
291 353
292 bool DesktopBackgroundController::MoveDesktopToUnlockedContainer() { 354 bool DesktopBackgroundController::MoveDesktopToUnlockedContainer() {
293 if (!locked_) 355 if (!locked_)
294 return false; 356 return false;
295 locked_ = false; 357 locked_ = false;
296 return ReparentBackgroundWidgets(GetBackgroundContainerId(true), 358 return ReparentBackgroundWidgets(GetBackgroundContainerId(true),
297 GetBackgroundContainerId(false)); 359 GetBackgroundContainerId(false));
298 } 360 }
299 361
300 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) { 362 void DesktopBackgroundController::OnWindowDestroying(aura::Window* window) {
301 window->SetProperty(kDesktopController, 363 window->SetProperty(kDesktopController,
302 static_cast<internal::DesktopBackgroundWidgetController*>(NULL)); 364 static_cast<internal::DesktopBackgroundWidgetController*>(NULL));
303 window->SetProperty(kAnimatingDesktopController, 365 window->SetProperty(kAnimatingDesktopController,
304 static_cast<internal::AnimatingDesktopController*>(NULL)); 366 static_cast<internal::AnimatingDesktopController*>(NULL));
305 } 367 }
306 368
369 bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded(
370 const base::FilePath& image_file, int image_resource_id) const {
371 return (wallpaper_loader_ &&
372 wallpaper_loader_->file_path() == image_file &&
373 wallpaper_loader_->resource_id() == image_resource_id) ||
374 (current_wallpaper_.get() &&
375 current_default_wallpaper_path_ == image_file &&
376 current_default_wallpaper_resource_id_ == image_resource_id);
377 }
378
379 bool DesktopBackgroundController::CustomWallpaperIsAlreadyLoaded(
380 const gfx::ImageSkia& image) const {
381 return current_wallpaper_.get() &&
382 current_wallpaper_->wallpaper_image().BackedBySameObjectAs(image);
383 }
384
307 void DesktopBackgroundController::SetDesktopBackgroundImageMode() { 385 void DesktopBackgroundController::SetDesktopBackgroundImageMode() {
308 desktop_background_mode_ = BACKGROUND_IMAGE; 386 desktop_background_mode_ = BACKGROUND_IMAGE;
309 InstallDesktopControllerForAllWindows(); 387 InstallDesktopControllerForAllWindows();
310 } 388 }
311 389
312 void DesktopBackgroundController::OnWallpaperLoadCompleted( 390 void DesktopBackgroundController::OnDefaultWallpaperLoadCompleted(
313 scoped_refptr<WallpaperLoader> wl) { 391 scoped_refptr<WallpaperLoader> loader) {
314 current_wallpaper_.reset(wl->ReleaseWallpaperResizer()); 392 current_wallpaper_.reset(loader->ReleaseWallpaperResizer());
393 current_wallpaper_->StartResize();
394 current_default_wallpaper_path_ = loader->file_path();
395 current_default_wallpaper_resource_id_ = loader->resource_id();
315 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_, 396 FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_,
316 OnWallpaperDataChanged()); 397 OnWallpaperDataChanged());
317 398
318 SetDesktopBackgroundImageMode(); 399 SetDesktopBackgroundImageMode();
319 400
320 DCHECK(wl.get() == wallpaper_loader_.get()); 401 DCHECK(loader.get() == wallpaper_loader_.get());
321 wallpaper_loader_ = NULL; 402 wallpaper_loader_ = NULL;
322 } 403 }
323 404
324 void DesktopBackgroundController::NotifyAnimationFinished() { 405 void DesktopBackgroundController::NotifyAnimationFinished() {
325 Shell* shell = Shell::GetInstance(); 406 Shell* shell = Shell::GetInstance();
326 shell->GetPrimaryRootWindowController()->HandleDesktopBackgroundVisible(); 407 shell->GetPrimaryRootWindowController()->HandleDesktopBackgroundVisible();
327 shell->user_wallpaper_delegate()->OnWallpaperAnimationFinished(); 408 shell->user_wallpaper_delegate()->OnWallpaperAnimationFinished();
328 } 409 }
329 410
330 ui::Layer* DesktopBackgroundController::SetColorLayerForContainer( 411 ui::Layer* DesktopBackgroundController::SetColorLayerForContainer(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 } 504 }
424 return moved; 505 return moved;
425 } 506 }
426 507
427 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) { 508 int DesktopBackgroundController::GetBackgroundContainerId(bool locked) {
428 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer : 509 return locked ? internal::kShellWindowId_LockScreenBackgroundContainer :
429 internal::kShellWindowId_DesktopBackgroundContainer; 510 internal::kShellWindowId_DesktopBackgroundContainer;
430 } 511 }
431 512
432 } // namespace ash 513 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698