190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file.
490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
5cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/ui/ash/solid_color_user_wallpaper_delegate.h"
690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/desktop_background/desktop_background_controller.h"
8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/desktop_background/user_wallpaper_delegate.h"
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/shell.h"
1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/wm/window_animations.h"
1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/basictypes.h"
1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/gfx/image/image_skia.h"
1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace {
1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const char kBackgroundRed   = 70;
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const char kBackgroundGreen = 70;
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const char kBackgroundBlue  = 78;
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class UserWallpaperDelegate : public ash::UserWallpaperDelegate {
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public:
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  UserWallpaperDelegate() {
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual ~UserWallpaperDelegate() {
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual int GetAnimationType() OVERRIDE {
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return ShouldShowInitialAnimation() ?
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        ash::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE :
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        static_cast<int>(wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual bool ShouldShowInitialAnimation() OVERRIDE {
3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return true;
3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual int GetAnimationDurationOverride() OVERRIDE {
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Return 0 to select the default.
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return 0;
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void SetAnimationDurationOverride(
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      int animation_duration_in_ms) OVERRIDE {
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    NOTIMPLEMENTED();
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void UpdateWallpaper(bool clear_cache) OVERRIDE {
4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    SkBitmap bitmap;
50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    bitmap.allocN32Pixels(16, 16);
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    bitmap.eraseARGB(255, kBackgroundRed, kBackgroundGreen, kBackgroundBlue);
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if !defined(NDEBUG)
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // In debug builds we generate a simple pattern that allows visually
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // notice if transparency is broken.
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    {
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      SkAutoLockPixels alp(bitmap);
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      *bitmap.getAddr32(0,0) = SkColorSetRGB(0, 0, 0);
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
60a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    gfx::ImageSkia wallpaper = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
61c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    ash::Shell::GetInstance()
62c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch        ->desktop_background_controller()
63c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch        ->SetWallpaperImage(wallpaper, ash::WALLPAPER_LAYOUT_TILE);
6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void InitializeWallpaper() OVERRIDE {
67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    UpdateWallpaper(false);
68a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
69a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void OpenSetWallpaperPage() OVERRIDE {
7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual bool CanOpenSetWallpaperPage() OVERRIDE {
7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return false;
7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void OnWallpaperAnimationFinished() OVERRIDE {
7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual void OnWallpaperBootAnimationFinished() OVERRIDE {
8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private:
8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(UserWallpaperDelegate);
8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace
8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
89cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)ash::UserWallpaperDelegate* CreateSolidColorUserWallpaperDelegate() {
9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return new UserWallpaperDelegate();
9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
92