OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser_theme_pack.h" | 5 #include "chrome/browser/browser_theme_pack.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <climits> | 8 #include <climits> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "net/base/file_stream.h" | 27 #include "net/base/file_stream.h" |
28 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
29 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
30 #include "third_party/skia/include/core/SkCanvas.h" | 30 #include "third_party/skia/include/core/SkCanvas.h" |
31 #include "third_party/skia/include/core/SkUnPreMultiply.h" | 31 #include "third_party/skia/include/core/SkUnPreMultiply.h" |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 // Version number of the current theme pack. We just throw out and rebuild | 35 // Version number of the current theme pack. We just throw out and rebuild |
36 // theme packs that aren't int-equal to this. | 36 // theme packs that aren't int-equal to this. |
37 const int kThemePackVersion = 4; | 37 const int kThemePackVersion = 5; |
38 | 38 |
39 // IDs that are in the DataPack won't clash with the positive integer | 39 // IDs that are in the DataPack won't clash with the positive integer |
40 // int32_t. kHeaderID should always have the maximum value because we want the | 40 // int32_t. kHeaderID should always have the maximum value because we want the |
41 // "header" to be written last. That way we can detect whether the pack was | 41 // "header" to be written last. That way we can detect whether the pack was |
42 // successfully written and ignore and regenerate if it was only partially | 42 // successfully written and ignore and regenerate if it was only partially |
43 // written (i.e. chrome crashed on a different thread while writing the pack). | 43 // written (i.e. chrome crashed on a different thread while writing the pack). |
44 const int kHeaderID = UINT_MAX - 1; | 44 const int kHeaderID = UINT_MAX - 1; |
45 const int kTintsID = UINT_MAX - 2; | 45 const int kTintsID = UINT_MAX - 2; |
46 const int kColorsID = UINT_MAX - 3; | 46 const int kColorsID = UINT_MAX - 3; |
47 const int kDisplayPropertiesID = UINT_MAX - 4; | 47 const int kDisplayPropertiesID = UINT_MAX - 4; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 { 49, IDR_STOP_P, NULL }, | 159 { 49, IDR_STOP_P, NULL }, |
160 { 50, IDR_MENU_BOOKMARK, NULL }, | 160 { 50, IDR_MENU_BOOKMARK, NULL }, |
161 { 51, IDR_MENU_PAGE, NULL }, | 161 { 51, IDR_MENU_PAGE, NULL }, |
162 { 52, IDR_MENU_PAGE_RTL, NULL }, | 162 { 52, IDR_MENU_PAGE_RTL, NULL }, |
163 { 53, IDR_MENU_CHROME, NULL }, | 163 { 53, IDR_MENU_CHROME, NULL }, |
164 { 54, IDR_MENU_CHROME_RTL, NULL }, | 164 { 54, IDR_MENU_CHROME_RTL, NULL }, |
165 { 55, IDR_MENU_DROPARROW, NULL }, | 165 { 55, IDR_MENU_DROPARROW, NULL }, |
166 { 56, IDR_THROBBER, NULL }, | 166 { 56, IDR_THROBBER, NULL }, |
167 { 57, IDR_THROBBER_WAITING, NULL }, | 167 { 57, IDR_THROBBER_WAITING, NULL }, |
168 { 58, IDR_THROBBER_LIGHT, NULL }, | 168 { 58, IDR_THROBBER_LIGHT, NULL }, |
169 { 59, IDR_LOCATIONBG, NULL } | 169 { 59, IDR_LOCATIONBG, NULL }, |
| 170 |
| 171 { 60, IDR_RELOAD_NOBORDER, NULL }, |
| 172 { 61, IDR_RELOAD_NOBORDER_CENTER, NULL }, |
| 173 { 62, IDR_RELOAD_ENDCAP, NULL }, |
| 174 { 63, IDR_RELOAD_ENDCAP_H, NULL }, |
| 175 { 64, IDR_RELOAD_ENDCAP_P, NULL } |
170 }; | 176 }; |
171 | 177 |
172 int GetPersistentIDByName(const std::string& key) { | 178 int GetPersistentIDByName(const std::string& key) { |
173 for (size_t i = 0; i < arraysize(kPersistingImages); ++i) { | 179 for (size_t i = 0; i < arraysize(kPersistingImages); ++i) { |
174 if (kPersistingImages[i].key != NULL && | 180 if (kPersistingImages[i].key != NULL && |
175 base::strcasecmp(key.c_str(), kPersistingImages[i].key) == 0) { | 181 base::strcasecmp(key.c_str(), kPersistingImages[i].key) == 0) { |
176 return kPersistingImages[i].persistent_id; | 182 return kPersistingImages[i].persistent_id; |
177 } | 183 } |
178 } | 184 } |
179 | 185 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 return true; | 514 return true; |
509 } | 515 } |
510 } | 516 } |
511 } | 517 } |
512 | 518 |
513 return false; | 519 return false; |
514 } | 520 } |
515 | 521 |
516 SkBitmap* BrowserThemePack::GetBitmapNamed(int idr_id) const { | 522 SkBitmap* BrowserThemePack::GetBitmapNamed(int idr_id) const { |
517 int prs_id = GetPersistentIDByIDR(idr_id); | 523 int prs_id = GetPersistentIDByIDR(idr_id); |
| 524 if (prs_id == -1) |
| 525 return NULL; |
518 | 526 |
519 // Check our cache of prepared images, first. | 527 // Check our cache of prepared images, first. |
520 ImageCache::const_iterator image_iter = prepared_images_.find(prs_id); | 528 ImageCache::const_iterator image_iter = prepared_images_.find(prs_id); |
521 if (image_iter != prepared_images_.end()) | 529 if (image_iter != prepared_images_.end()) |
522 return image_iter->second; | 530 return image_iter->second; |
523 | 531 |
524 // Check if we've already loaded this image. | 532 // Check if we've already loaded this image. |
525 image_iter = loaded_images_.find(prs_id); | 533 image_iter = loaded_images_.find(prs_id); |
526 if (image_iter != loaded_images_.end()) | 534 if (image_iter != loaded_images_.end()) |
527 return image_iter->second; | 535 return image_iter->second; |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 void BrowserThemePack::GenerateTintedButtons( | 965 void BrowserThemePack::GenerateTintedButtons( |
958 color_utils::HSL button_tint, | 966 color_utils::HSL button_tint, |
959 ImageCache* processed_bitmaps) const { | 967 ImageCache* processed_bitmaps) const { |
960 if (button_tint.h != -1 || button_tint.s != -1 || button_tint.l != -1) { | 968 if (button_tint.h != -1 || button_tint.s != -1 || button_tint.l != -1) { |
961 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 969 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
962 const std::set<int>& idr_ids = | 970 const std::set<int>& idr_ids = |
963 BrowserThemeProvider::GetTintableToolbarButtons(); | 971 BrowserThemeProvider::GetTintableToolbarButtons(); |
964 for (std::set<int>::const_iterator it = idr_ids.begin(); | 972 for (std::set<int>::const_iterator it = idr_ids.begin(); |
965 it != idr_ids.end(); ++it) { | 973 it != idr_ids.end(); ++it) { |
966 int prs_id = GetPersistentIDByIDR(*it); | 974 int prs_id = GetPersistentIDByIDR(*it); |
967 if (prs_id < 0) | 975 DCHECK(prs_id > 0); |
968 continue; | |
969 | 976 |
970 // Fetch the image by IDR... | 977 // Fetch the image by IDR... |
971 scoped_ptr<SkBitmap> button(new SkBitmap(*rb.GetBitmapNamed(*it))); | 978 scoped_ptr<SkBitmap> button(new SkBitmap(*rb.GetBitmapNamed(*it))); |
972 | 979 |
973 // but save a version with the persistent ID. | 980 // but save a version with the persistent ID. |
974 (*processed_bitmaps)[prs_id] = new SkBitmap( | 981 (*processed_bitmaps)[prs_id] = new SkBitmap( |
975 SkBitmapOperations::CreateHSLShiftedBitmap(*button, button_tint)); | 982 SkBitmapOperations::CreateHSLShiftedBitmap(*button, button_tint)); |
976 } | 983 } |
977 } | 984 } |
978 } | 985 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 hsl.h = tints_[i].h; | 1064 hsl.h = tints_[i].h; |
1058 hsl.s = tints_[i].s; | 1065 hsl.s = tints_[i].s; |
1059 hsl.l = tints_[i].l; | 1066 hsl.l = tints_[i].l; |
1060 return hsl; | 1067 return hsl; |
1061 } | 1068 } |
1062 } | 1069 } |
1063 } | 1070 } |
1064 | 1071 |
1065 return BrowserThemeProvider::GetDefaultTint(id); | 1072 return BrowserThemeProvider::GetDefaultTint(id); |
1066 } | 1073 } |
OLD | NEW |