Chromium Code Reviews| 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.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 | 41 |
| 42 using content::BrowserThread; | 42 using content::BrowserThread; |
| 43 using extensions::Extension; | 43 using extensions::Extension; |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 // Version number of the current theme pack. We just throw out and rebuild | 47 // Version number of the current theme pack. We just throw out and rebuild |
| 48 // theme packs that aren't int-equal to this. Increment this number if you | 48 // theme packs that aren't int-equal to this. Increment this number if you |
| 49 // change default theme assets or if you need themes to recreate their generated | 49 // change default theme assets or if you need themes to recreate their generated |
| 50 // images (which are cached). | 50 // images (which are cached). |
| 51 const int kThemePackVersion = 45; | 51 const int kThemePackVersion = 45; |
|
Elliot Glaysher
2017/01/31 21:35:34
Does this change need the theme pack version bumpe
Tom (Use chromium acct)
2017/02/01 00:21:17
idk, but I did it anyway
| |
| 52 | 52 |
| 53 // IDs that are in the DataPack won't clash with the positive integer | 53 // IDs that are in the DataPack won't clash with the positive integer |
| 54 // uint16_t. kHeaderID should always have the maximum value because we want the | 54 // uint16_t. kHeaderID should always have the maximum value because we want the |
| 55 // "header" to be written last. That way we can detect whether the pack was | 55 // "header" to be written last. That way we can detect whether the pack was |
| 56 // successfully written and ignore and regenerate if it was only partially | 56 // successfully written and ignore and regenerate if it was only partially |
| 57 // written (i.e. chrome crashed on a different thread while writing the pack). | 57 // written (i.e. chrome crashed on a different thread while writing the pack). |
| 58 const int kMaxID = 0x0000FFFF; // Max unsigned 16-bit int. | 58 const int kMaxID = 0x0000FFFF; // Max unsigned 16-bit int. |
| 59 const int kHeaderID = kMaxID - 1; | 59 const int kHeaderID = kMaxID - 1; |
| 60 const int kTintsID = kMaxID - 2; | 60 const int kTintsID = kMaxID - 2; |
| 61 const int kColorsID = kMaxID - 3; | 61 const int kColorsID = kMaxID - 3; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 { "frame_incognito", ThemeProperties::COLOR_FRAME_INCOGNITO }, | 228 { "frame_incognito", ThemeProperties::COLOR_FRAME_INCOGNITO }, |
| 229 { "frame_incognito_inactive", | 229 { "frame_incognito_inactive", |
| 230 ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE }, | 230 ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE }, |
| 231 { "toolbar", ThemeProperties::COLOR_TOOLBAR }, | 231 { "toolbar", ThemeProperties::COLOR_TOOLBAR }, |
| 232 { "tab_text", ThemeProperties::COLOR_TAB_TEXT }, | 232 { "tab_text", ThemeProperties::COLOR_TAB_TEXT }, |
| 233 { "tab_background_text", ThemeProperties::COLOR_BACKGROUND_TAB_TEXT }, | 233 { "tab_background_text", ThemeProperties::COLOR_BACKGROUND_TAB_TEXT }, |
| 234 { "bookmark_text", ThemeProperties::COLOR_BOOKMARK_TEXT }, | 234 { "bookmark_text", ThemeProperties::COLOR_BOOKMARK_TEXT }, |
| 235 { "ntp_background", ThemeProperties::COLOR_NTP_BACKGROUND }, | 235 { "ntp_background", ThemeProperties::COLOR_NTP_BACKGROUND }, |
| 236 { "ntp_text", ThemeProperties::COLOR_NTP_TEXT }, | 236 { "ntp_text", ThemeProperties::COLOR_NTP_TEXT }, |
| 237 { "ntp_link", ThemeProperties::COLOR_NTP_LINK }, | 237 { "ntp_link", ThemeProperties::COLOR_NTP_LINK }, |
| 238 { "ntp_link_underline", ThemeProperties::COLOR_NTP_LINK_UNDERLINE }, | |
| 239 { "ntp_header", ThemeProperties::COLOR_NTP_HEADER }, | 238 { "ntp_header", ThemeProperties::COLOR_NTP_HEADER }, |
| 240 { "ntp_section", ThemeProperties::COLOR_NTP_SECTION }, | 239 { "ntp_section", ThemeProperties::COLOR_NTP_SECTION }, |
| 241 { "ntp_section_text", ThemeProperties::COLOR_NTP_SECTION_TEXT }, | |
| 242 { "ntp_section_link", ThemeProperties::COLOR_NTP_SECTION_LINK }, | |
| 243 { "ntp_section_link_underline", | |
| 244 ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE }, | |
| 245 { "button_background", ThemeProperties::COLOR_BUTTON_BACKGROUND }, | 240 { "button_background", ThemeProperties::COLOR_BUTTON_BACKGROUND }, |
| 246 }; | 241 }; |
| 247 const size_t kColorTableLength = arraysize(kColorTable); | 242 const size_t kColorTableLength = arraysize(kColorTable); |
| 248 | 243 |
| 249 // Strings used by themes to identify display properties keys in JSON. | 244 // Strings used by themes to identify display properties keys in JSON. |
| 250 const StringToIntTable kDisplayProperties[] = { | 245 const StringToIntTable kDisplayProperties[] = { |
| 251 { "ntp_background_alignment", | 246 { "ntp_background_alignment", |
| 252 ThemeProperties::NTP_BACKGROUND_ALIGNMENT }, | 247 ThemeProperties::NTP_BACKGROUND_ALIGNMENT }, |
| 253 { "ntp_background_repeat", ThemeProperties::NTP_BACKGROUND_TILING }, | 248 { "ntp_background_repeat", ThemeProperties::NTP_BACKGROUND_TILING }, |
| 254 { "ntp_logo_alternate", ThemeProperties::NTP_LOGO_ALTERNATE }, | 249 { "ntp_logo_alternate", ThemeProperties::NTP_LOGO_ALTERNATE }, |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 } else { | 959 } else { |
| 965 // Invalid entry for part 4. | 960 // Invalid entry for part 4. |
| 966 continue; | 961 continue; |
| 967 } | 962 } |
| 968 } else { | 963 } else { |
| 969 color = SkColorSetRGB(r, g, b); | 964 color = SkColorSetRGB(r, g, b); |
| 970 } | 965 } |
| 971 | 966 |
| 972 int id = GetIntForString(iter.key(), kColorTable, kColorTableLength); | 967 int id = GetIntForString(iter.key(), kColorTable, kColorTableLength); |
| 973 if (id != -1) { | 968 if (id != -1) { |
| 974 (*temp_colors)[id] = color; | 969 (*temp_colors)[id] = color; |
|
Tom (Use chromium acct)
2017/01/31 21:29:27
We could remove COLOR_NTP_SECTION too if we add a
Evan Stade
2017/01/31 23:51:54
I guess I would be in favor of that. We have to sp
Tom (Use chromium acct)
2017/02/01 00:21:17
Done.
| |
| 975 } | 970 } |
| 976 } | 971 } |
| 977 } | 972 } |
| 978 } | 973 } |
| 979 } | 974 } |
| 980 | 975 |
| 981 void BrowserThemePack::GenerateMissingColors( | 976 void BrowserThemePack::GenerateMissingColors( |
| 982 std::map<int, SkColor>* colors) { | 977 std::map<int, SkColor>* colors) { |
| 983 // Generate link colors, if missing. (See GetColor()). | |
| 984 if (!colors->count(ThemeProperties::COLOR_NTP_HEADER) && | 978 if (!colors->count(ThemeProperties::COLOR_NTP_HEADER) && |
| 985 colors->count(ThemeProperties::COLOR_NTP_SECTION)) { | 979 colors->count(ThemeProperties::COLOR_NTP_SECTION)) { |
| 986 (*colors)[ThemeProperties::COLOR_NTP_HEADER] = | 980 (*colors)[ThemeProperties::COLOR_NTP_HEADER] = |
| 987 (*colors)[ThemeProperties::COLOR_NTP_SECTION]; | 981 (*colors)[ThemeProperties::COLOR_NTP_SECTION]; |
| 988 } | 982 } |
| 989 | 983 |
| 990 if (!colors->count(ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE) && | |
| 991 colors->count(ThemeProperties::COLOR_NTP_SECTION_LINK)) { | |
| 992 SkColor color_section_link = | |
| 993 (*colors)[ThemeProperties::COLOR_NTP_SECTION_LINK]; | |
| 994 (*colors)[ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE] = | |
| 995 SkColorSetA(color_section_link, SkColorGetA(color_section_link) / 3); | |
| 996 } | |
| 997 | |
| 998 if (!colors->count(ThemeProperties::COLOR_NTP_LINK_UNDERLINE) && | |
| 999 colors->count(ThemeProperties::COLOR_NTP_LINK)) { | |
| 1000 SkColor color_link = (*colors)[ThemeProperties::COLOR_NTP_LINK]; | |
| 1001 (*colors)[ThemeProperties::COLOR_NTP_LINK_UNDERLINE] = | |
| 1002 SkColorSetA(color_link, SkColorGetA(color_link) / 3); | |
| 1003 } | |
| 1004 | |
| 1005 // Generate frame colors, if missing. (See GenerateFrameColors()). | 984 // Generate frame colors, if missing. (See GenerateFrameColors()). |
| 1006 SkColor frame; | 985 SkColor frame; |
| 1007 std::map<int, SkColor>::const_iterator it = | 986 std::map<int, SkColor>::const_iterator it = |
| 1008 colors->find(ThemeProperties::COLOR_FRAME); | 987 colors->find(ThemeProperties::COLOR_FRAME); |
| 1009 if (it != colors->end()) { | 988 if (it != colors->end()) { |
| 1010 frame = it->second; | 989 frame = it->second; |
| 1011 } else { | 990 } else { |
| 1012 frame = | 991 frame = |
| 1013 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_FRAME, false); | 992 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_FRAME, false); |
| 1014 } | 993 } |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1452 false, | 1431 false, |
| 1453 &bitmap_data)) { | 1432 &bitmap_data)) { |
| 1454 NOTREACHED() << "Unable to encode theme image for prs_id=" | 1433 NOTREACHED() << "Unable to encode theme image for prs_id=" |
| 1455 << prs_id << " for scale_factor=" << scale_factors_[i]; | 1434 << prs_id << " for scale_factor=" << scale_factors_[i]; |
| 1456 break; | 1435 break; |
| 1457 } | 1436 } |
| 1458 image_memory_[scaled_raw_id] = | 1437 image_memory_[scaled_raw_id] = |
| 1459 base::RefCountedBytes::TakeVector(&bitmap_data); | 1438 base::RefCountedBytes::TakeVector(&bitmap_data); |
| 1460 } | 1439 } |
| 1461 } | 1440 } |
| OLD | NEW |