1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/ash/solid_color_user_wallpaper_delegate.h" 6 7 #include "ash/desktop_background/desktop_background_controller.h" 8 #include "ash/desktop_background/user_wallpaper_delegate.h" 9 #include "ash/shell.h" 10 #include "ash/wm/window_animations.h" 11 #include "base/basictypes.h" 12 #include "ui/gfx/image/image_skia.h" 13 14 namespace { 15 16 const char kBackgroundRed = 70; 17 const char kBackgroundGreen = 70; 18 const char kBackgroundBlue = 78; 19 20 class UserWallpaperDelegate : public ash::UserWallpaperDelegate { 21 public: 22 UserWallpaperDelegate() { 23 } 24 25 virtual ~UserWallpaperDelegate() { 26 } 27 28 virtual int GetAnimationType() OVERRIDE { 29 return ShouldShowInitialAnimation() ? 30 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE : 31 static_cast<int>(wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 32 } 33 34 virtual bool ShouldShowInitialAnimation() OVERRIDE { 35 return true; 36 } 37 38 virtual int GetAnimationDurationOverride() OVERRIDE { 39 // Return 0 to select the default. 40 return 0; 41 } 42 43 virtual void SetAnimationDurationOverride( 44 int animation_duration_in_ms) OVERRIDE { 45 NOTIMPLEMENTED(); 46 } 47 48 virtual void UpdateWallpaper(bool clear_cache) OVERRIDE { 49 SkBitmap bitmap; 50 bitmap.allocN32Pixels(16, 16); 51 bitmap.eraseARGB(255, kBackgroundRed, kBackgroundGreen, kBackgroundBlue); 52 #if !defined(NDEBUG) 53 // In debug builds we generate a simple pattern that allows visually 54 // notice if transparency is broken. 55 { 56 SkAutoLockPixels alp(bitmap); 57 *bitmap.getAddr32(0,0) = SkColorSetRGB(0, 0, 0); 58 } 59 #endif 60 gfx::ImageSkia wallpaper = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 61 ash::Shell::GetInstance() 62 ->desktop_background_controller() 63 ->SetWallpaperImage(wallpaper, ash::WALLPAPER_LAYOUT_TILE); 64 } 65 66 virtual void InitializeWallpaper() OVERRIDE { 67 UpdateWallpaper(false); 68 } 69 70 virtual void OpenSetWallpaperPage() OVERRIDE { 71 } 72 73 virtual bool CanOpenSetWallpaperPage() OVERRIDE { 74 return false; 75 } 76 77 virtual void OnWallpaperAnimationFinished() OVERRIDE { 78 } 79 80 virtual void OnWallpaperBootAnimationFinished() OVERRIDE { 81 } 82 83 private: 84 DISALLOW_COPY_AND_ASSIGN(UserWallpaperDelegate); 85 }; 86 87 } // namespace 88 89 ash::UserWallpaperDelegate* CreateSolidColorUserWallpaperDelegate() { 90 return new UserWallpaperDelegate(); 91 } 92