OLD | NEW |
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 "chrome/browser/themes/browser_theme_pack.h" | 5 #include "chrome/browser/themes/browser_theme_pack.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/themes/theme_service.h" | 15 #include "chrome/browser/themes/theme_service.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
18 #include "grit/theme_resources_standard.h" | 18 #include "grit/theme_resources_standard.h" |
19 #include "grit/ui_resources.h" | 19 #include "grit/ui_resources.h" |
20 #include "net/base/file_stream.h" | 20 #include "net/base/file_stream.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "third_party/skia/include/core/SkCanvas.h" | 22 #include "third_party/skia/include/core/SkCanvas.h" |
23 #include "ui/base/resource/data_pack.h" | 23 #include "ui/base/resource/data_pack.h" |
24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/gfx/codec/png_codec.h" | 25 #include "ui/gfx/codec/png_codec.h" |
26 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
| 27 #include "ui/gfx/image/image_skia.h" |
27 #include "ui/gfx/skbitmap_operations.h" | 28 #include "ui/gfx/skbitmap_operations.h" |
28 | 29 |
29 using content::BrowserThread; | 30 using content::BrowserThread; |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 // Version number of the current theme pack. We just throw out and rebuild | 34 // Version number of the current theme pack. We just throw out and rebuild |
34 // theme packs that aren't int-equal to this. Increment this number if you | 35 // theme packs that aren't int-equal to this. Increment this number if you |
35 // change default theme assets. | 36 // change default theme assets. |
36 const int kThemePackVersion = 20; | 37 const int kThemePackVersion = 20; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 } | 303 } |
303 } | 304 } |
304 | 305 |
305 return NULL; | 306 return NULL; |
306 } | 307 } |
307 | 308 |
308 // Shifts a bitmap's HSL values. The caller is responsible for deleting | 309 // Shifts a bitmap's HSL values. The caller is responsible for deleting |
309 // the returned image. | 310 // the returned image. |
310 gfx::Image* CreateHSLShiftedImage(const gfx::Image& image, | 311 gfx::Image* CreateHSLShiftedImage(const gfx::Image& image, |
311 const color_utils::HSL& hsl_shift) { | 312 const color_utils::HSL& hsl_shift) { |
312 std::vector<const SkBitmap*> bitmaps; | 313 const std::vector<const SkBitmap*>& src_bitmaps = |
313 for (size_t i = 0; i < image.GetNumberOfSkBitmaps(); ++i) { | 314 image.ToImageSkia()->bitmaps(); |
314 const SkBitmap* bitmap = image.GetSkBitmapAtIndex(i); | 315 std::vector<const SkBitmap*> dst_bitmaps; |
315 bitmaps.push_back(new SkBitmap(SkBitmapOperations::CreateHSLShiftedBitmap( | 316 for (size_t i = 0; i < src_bitmaps.size(); ++i) { |
316 *bitmap, hsl_shift))); | 317 const SkBitmap* bitmap = src_bitmaps[i]; |
| 318 dst_bitmaps.push_back(new SkBitmap( |
| 319 SkBitmapOperations::CreateHSLShiftedBitmap(*bitmap, hsl_shift))); |
317 } | 320 } |
318 return new gfx::Image(bitmaps); | 321 return new gfx::Image(dst_bitmaps); |
319 } | 322 } |
320 | 323 |
321 } // namespace | 324 } // namespace |
322 | 325 |
323 BrowserThemePack::~BrowserThemePack() { | 326 BrowserThemePack::~BrowserThemePack() { |
324 if (!data_pack_.get()) { | 327 if (!data_pack_.get()) { |
325 delete header_; | 328 delete header_; |
326 delete [] tints_; | 329 delete [] tints_; |
327 delete [] colors_; | 330 delete [] colors_; |
328 delete [] display_properties_; | 331 delete [] display_properties_; |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 ImageCache temp_output; | 984 ImageCache temp_output; |
982 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) { | 985 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) { |
983 int prs_id = kTabBackgroundMap[i].key; | 986 int prs_id = kTabBackgroundMap[i].key; |
984 int prs_base_id = kTabBackgroundMap[i].value; | 987 int prs_base_id = kTabBackgroundMap[i].value; |
985 | 988 |
986 // We only need to generate the background tab images if we were provided | 989 // We only need to generate the background tab images if we were provided |
987 // with a PRS_THEME_FRAME. | 990 // with a PRS_THEME_FRAME. |
988 ImageCache::const_iterator it = bitmaps->find(prs_base_id); | 991 ImageCache::const_iterator it = bitmaps->find(prs_base_id); |
989 if (it != bitmaps->end()) { | 992 if (it != bitmaps->end()) { |
990 const gfx::Image& image_to_tint = *(it->second); | 993 const gfx::Image& image_to_tint = *(it->second); |
| 994 const std::vector<const SkBitmap*>& bitmaps_to_tint = |
| 995 image_to_tint.ToImageSkia()->bitmaps(); |
991 std::vector<const SkBitmap*> tinted_bitmaps; | 996 std::vector<const SkBitmap*> tinted_bitmaps; |
992 for (size_t j = 0; j < image_to_tint.GetNumberOfSkBitmaps(); ++j) { | 997 for (size_t j = 0; j < bitmaps_to_tint.size(); ++j) { |
993 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap( | 998 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap( |
994 *image_to_tint.GetSkBitmapAtIndex(j), GetTintInternal( | 999 *bitmaps_to_tint[j], GetTintInternal( |
995 ThemeService::TINT_BACKGROUND_TAB)); | 1000 ThemeService::TINT_BACKGROUND_TAB)); |
996 int vertical_offset = bitmaps->count(prs_id) | 1001 int vertical_offset = bitmaps->count(prs_id) |
997 ? kRestoredTabVerticalOffset : 0; | 1002 ? kRestoredTabVerticalOffset : 0; |
998 SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap( | 1003 SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap( |
999 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height())); | 1004 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height())); |
1000 | 1005 |
1001 // If they've provided a custom image, overlay it. | 1006 // If they've provided a custom image, overlay it. |
1002 ImageCache::const_iterator overlay_it = bitmaps->find(prs_id); | 1007 ImageCache::const_iterator overlay_it = bitmaps->find(prs_id); |
1003 if (overlay_it != bitmaps->end()) { | 1008 if (overlay_it != bitmaps->end()) { |
1004 const SkBitmap* overlay = overlay_it->second->ToSkBitmap(); | 1009 const SkBitmap* overlay = overlay_it->second->ToSkBitmap(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 hsl.h = tints_[i].h; | 1069 hsl.h = tints_[i].h; |
1065 hsl.s = tints_[i].s; | 1070 hsl.s = tints_[i].s; |
1066 hsl.l = tints_[i].l; | 1071 hsl.l = tints_[i].l; |
1067 return hsl; | 1072 return hsl; |
1068 } | 1073 } |
1069 } | 1074 } |
1070 } | 1075 } |
1071 | 1076 |
1072 return ThemeService::GetDefaultTint(id); | 1077 return ThemeService::GetDefaultTint(id); |
1073 } | 1078 } |
OLD | NEW |