| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/desktop_background/desktop_background_resources.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/rand_util.h" | |
| 9 #include "grit/ash_wallpaper_resources.h" | |
| 10 #include "ui/base/resource/resource_bundle.h" | |
| 11 #include "ui/gfx/image/image.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 // Keeps in sync (same order) with WallpaperLayout enum in header file. | |
| 16 const char* kWallpaperLayoutArrays[] = { | |
| 17 "CENTER", | |
| 18 "CENTER_CROPPED", | |
| 19 "STRETCH", | |
| 20 "TILE" | |
| 21 }; | |
| 22 | |
| 23 const ash::WallpaperInfo kDefaultWallpapers[] = { | |
| 24 #if defined(GOOGLE_CHROME_BUILD) | |
| 25 { | |
| 26 { | |
| 27 IDR_AURA_WALLPAPERS_2_LANDSCAPE7_LARGE, | |
| 28 ash::CENTER_CROPPED | |
| 29 }, | |
| 30 { | |
| 31 IDR_AURA_WALLPAPERS_2_LANDSCAPE7_SMALL, | |
| 32 ash::CENTER | |
| 33 } | |
| 34 }, | |
| 35 { | |
| 36 { | |
| 37 IDR_AURA_WALLPAPERS_2_LANDSCAPE8_LARGE, | |
| 38 ash::CENTER_CROPPED | |
| 39 }, | |
| 40 { | |
| 41 IDR_AURA_WALLPAPERS_2_LANDSCAPE8_SMALL, | |
| 42 ash::CENTER | |
| 43 } | |
| 44 }, | |
| 45 #endif | |
| 46 { | |
| 47 { | |
| 48 IDR_AURA_WALLPAPERS_5_GRADIENT5_LARGE, | |
| 49 ash::TILE | |
| 50 }, | |
| 51 { | |
| 52 IDR_AURA_WALLPAPERS_5_GRADIENT5_SMALL, | |
| 53 ash::TILE | |
| 54 } | |
| 55 } | |
| 56 }; | |
| 57 | |
| 58 const int kWallpaperLayoutCount = arraysize(kWallpaperLayoutArrays); | |
| 59 const int kDefaultWallpaperCount = arraysize(kDefaultWallpapers); | |
| 60 const int kInvalidWallpaperIndex = -1; | |
| 61 const int kSolidColorIndex = -2; | |
| 62 | |
| 63 // TODO(saintlou): These hardcoded indexes, although checked against the size | |
| 64 // of the array are really hacky. | |
| 65 #if defined(GOOGLE_CHROME_BUILD) | |
| 66 const int kDefaultWallpaperIndex = 1; // IDR_AURA_WALLPAPERS_2_LANDSCAPE8 | |
| 67 const int kGuestWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_2_LANDSCAPE7 | |
| 68 #else | |
| 69 // Set default wallpaper to the grey background for faster wallpaper loading | |
| 70 // time in browser tests. Otherwise, some of the tests will finish before | |
| 71 // wallpaper loaded and cause crashes. | |
| 72 const int kDefaultWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_5_GRADIENT5 | |
| 73 const int kGuestWallpaperIndex = kDefaultWallpaperIndex; | |
| 74 #endif | |
| 75 | |
| 76 } // namespace | |
| 77 | |
| 78 namespace ash { | |
| 79 | |
| 80 int GetDefaultWallpaperIndex() { | |
| 81 DCHECK(kDefaultWallpaperIndex < kDefaultWallpaperCount); | |
| 82 return std::min(kDefaultWallpaperIndex, kDefaultWallpaperCount - 1); | |
| 83 } | |
| 84 | |
| 85 int GetGuestWallpaperIndex() { | |
| 86 DCHECK(kGuestWallpaperIndex < kDefaultWallpaperCount); | |
| 87 return std::min(kGuestWallpaperIndex, kDefaultWallpaperCount - 1); | |
| 88 } | |
| 89 | |
| 90 int GetInvalidWallpaperIndex() { | |
| 91 return kInvalidWallpaperIndex; | |
| 92 } | |
| 93 | |
| 94 WallpaperLayout GetLayoutEnum(const std::string& layout) { | |
| 95 for (int i = 0; i < kWallpaperLayoutCount; i++) { | |
| 96 if (layout.compare(kWallpaperLayoutArrays[i]) == 0) | |
| 97 return static_cast<WallpaperLayout>(i); | |
| 98 } | |
| 99 // Default to use CENTER layout. | |
| 100 return CENTER; | |
| 101 } | |
| 102 | |
| 103 int GetSolidColorIndex() { | |
| 104 return kSolidColorIndex; | |
| 105 } | |
| 106 | |
| 107 int GetWallpaperCount() { | |
| 108 return kDefaultWallpaperCount; | |
| 109 } | |
| 110 | |
| 111 const WallpaperInfo& GetWallpaperInfo(int index) { | |
| 112 DCHECK(index >= 0 && index < kDefaultWallpaperCount); | |
| 113 return kDefaultWallpapers[index]; | |
| 114 } | |
| 115 | |
| 116 const WallpaperViewInfo& GetWallpaperViewInfo(int index, | |
| 117 WallpaperResolution resolution) { | |
| 118 DCHECK(index >= 0 && index < kDefaultWallpaperCount); | |
| 119 if (resolution == SMALL) | |
| 120 return kDefaultWallpapers[index].small_wallpaper; | |
| 121 else | |
| 122 return kDefaultWallpapers[index].large_wallpaper; | |
| 123 } | |
| 124 | |
| 125 } // namespace ash | |
| OLD | NEW |