summaryrefslogtreecommitdiff
path: root/chromium/ash/accelerators/debug_commands.cc
blob: 4ca1720e3a00d581eebe5e70d3199d69d2488094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/accelerators/accelerator_commands.h"

#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/desktop_background/user_wallpaper_delegate.h"
#include "ash/shell.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h"

namespace ash {
namespace debug {
namespace {

gfx::ImageSkia CreateWallpaperImage(SkColor fill, SkColor rect) {
  // TODO(oshima): Consider adding a command line option to control
  // wallpaper images for testing.
  // The size is randomly picked.
  gfx::Size image_size(1366, 768);
  gfx::Canvas canvas(image_size, 1.0f, true);
  canvas.DrawColor(fill);
  SkPaint paint;
  paint.setColor(rect);
  paint.setStrokeWidth(10);
  paint.setStyle(SkPaint::kStroke_Style);
  paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
  canvas.DrawRoundRect(gfx::Rect(image_size), 100, paint);
  return gfx::ImageSkia(canvas.ExtractImageRep());
}

}  // namespace

bool CycleDesktopBackgroundMode() {
  static int index = 0;
  DesktopBackgroundController* desktop_background_controller =
      Shell::GetInstance()->desktop_background_controller();
  switch (++index % 4) {
    case 0:
      ash::Shell::GetInstance()->user_wallpaper_delegate()->
          InitializeWallpaper();
      break;
    case 1:
      desktop_background_controller->SetCustomWallpaper(
          CreateWallpaperImage(SK_ColorRED, SK_ColorBLUE),
          WALLPAPER_LAYOUT_STRETCH);
      break;
    case 2:
      desktop_background_controller->SetCustomWallpaper(
          CreateWallpaperImage(SK_ColorBLUE, SK_ColorGREEN),
          WALLPAPER_LAYOUT_CENTER);
      break;
    case 3:
      desktop_background_controller->SetCustomWallpaper(
          CreateWallpaperImage(SK_ColorGREEN, SK_ColorRED),
          WALLPAPER_LAYOUT_CENTER_CROPPED);
      break;
  }
  return true;
}

}  // namespace debug
}  // namespace ash