| 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/themes/browser_theme_pack.h" | 5 #include "chrome/browser/themes/browser_theme_pack.h" |
| 6 | 6 |
| 7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 return RefCountedBytes::TakeVector(&raw_data); | 291 return RefCountedBytes::TakeVector(&raw_data); |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 return NULL; | 296 return NULL; |
| 297 } | 297 } |
| 298 | 298 |
| 299 // Does error checking for invalid incoming data while trying to read an | 299 // Does error checking for invalid incoming data while trying to read an |
| 300 // floating point value. | 300 // floating point value. |
| 301 bool ValidRealValue(ListValue* tint_list, int index, double* out) { | 301 bool ValidDoubleValue(ListValue* tint_list, int index, double* out) { |
| 302 if (tint_list->GetReal(index, out)) | 302 if (tint_list->GetDouble(index, out)) |
| 303 return true; | 303 return true; |
| 304 | 304 |
| 305 int value = 0; | 305 int value = 0; |
| 306 if (tint_list->GetInteger(index, &value)) { | 306 if (tint_list->GetInteger(index, &value)) { |
| 307 *out = value; | 307 *out = value; |
| 308 return true; | 308 return true; |
| 309 } | 309 } |
| 310 | 310 |
| 311 return false; | 311 return false; |
| 312 } | 312 } |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 | 612 |
| 613 // Parse the incoming data from |tints_value| into an intermediary structure. | 613 // Parse the incoming data from |tints_value| into an intermediary structure. |
| 614 std::map<int, color_utils::HSL> temp_tints; | 614 std::map<int, color_utils::HSL> temp_tints; |
| 615 for (DictionaryValue::key_iterator iter(tints_value->begin_keys()); | 615 for (DictionaryValue::key_iterator iter(tints_value->begin_keys()); |
| 616 iter != tints_value->end_keys(); ++iter) { | 616 iter != tints_value->end_keys(); ++iter) { |
| 617 ListValue* tint_list; | 617 ListValue* tint_list; |
| 618 if (tints_value->GetList(*iter, &tint_list) && | 618 if (tints_value->GetList(*iter, &tint_list) && |
| 619 (tint_list->GetSize() == 3)) { | 619 (tint_list->GetSize() == 3)) { |
| 620 color_utils::HSL hsl = { -1, -1, -1 }; | 620 color_utils::HSL hsl = { -1, -1, -1 }; |
| 621 | 621 |
| 622 if (ValidRealValue(tint_list, 0, &hsl.h) && | 622 if (ValidDoubleValue(tint_list, 0, &hsl.h) && |
| 623 ValidRealValue(tint_list, 1, &hsl.s) && | 623 ValidDoubleValue(tint_list, 1, &hsl.s) && |
| 624 ValidRealValue(tint_list, 2, &hsl.l)) { | 624 ValidDoubleValue(tint_list, 2, &hsl.l)) { |
| 625 int id = GetIntForString(*iter, kTintTable); | 625 int id = GetIntForString(*iter, kTintTable); |
| 626 if (id != -1) { | 626 if (id != -1) { |
| 627 temp_tints[id] = hsl; | 627 temp_tints[id] = hsl; |
| 628 } | 628 } |
| 629 } | 629 } |
| 630 } | 630 } |
| 631 } | 631 } |
| 632 | 632 |
| 633 // Copy data from the intermediary data structure to the array. | 633 // Copy data from the intermediary data structure to the array. |
| 634 int count = 0; | 634 int count = 0; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 if (colors_value->GetList(*iter, &color_list) && | 673 if (colors_value->GetList(*iter, &color_list) && |
| 674 ((color_list->GetSize() == 3) || (color_list->GetSize() == 4))) { | 674 ((color_list->GetSize() == 3) || (color_list->GetSize() == 4))) { |
| 675 SkColor color = SK_ColorWHITE; | 675 SkColor color = SK_ColorWHITE; |
| 676 int r, g, b; | 676 int r, g, b; |
| 677 if (color_list->GetInteger(0, &r) && | 677 if (color_list->GetInteger(0, &r) && |
| 678 color_list->GetInteger(1, &g) && | 678 color_list->GetInteger(1, &g) && |
| 679 color_list->GetInteger(2, &b)) { | 679 color_list->GetInteger(2, &b)) { |
| 680 if (color_list->GetSize() == 4) { | 680 if (color_list->GetSize() == 4) { |
| 681 double alpha; | 681 double alpha; |
| 682 int alpha_int; | 682 int alpha_int; |
| 683 if (color_list->GetReal(3, &alpha)) { | 683 if (color_list->GetDouble(3, &alpha)) { |
| 684 color = SkColorSetARGB(static_cast<int>(alpha * 255), r, g, b); | 684 color = SkColorSetARGB(static_cast<int>(alpha * 255), r, g, b); |
| 685 } else if (color_list->GetInteger(3, &alpha_int) && | 685 } else if (color_list->GetInteger(3, &alpha_int) && |
| 686 (alpha_int == 0 || alpha_int == 1)) { | 686 (alpha_int == 0 || alpha_int == 1)) { |
| 687 color = SkColorSetARGB(alpha_int ? 255 : 0, r, g, b); | 687 color = SkColorSetARGB(alpha_int ? 255 : 0, r, g, b); |
| 688 } else { | 688 } else { |
| 689 // Invalid entry for part 4. | 689 // Invalid entry for part 4. |
| 690 continue; | 690 continue; |
| 691 } | 691 } |
| 692 } else { | 692 } else { |
| 693 color = SkColorSetRGB(r, g, b); | 693 color = SkColorSetRGB(r, g, b); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 hsl.h = tints_[i].h; | 1041 hsl.h = tints_[i].h; |
| 1042 hsl.s = tints_[i].s; | 1042 hsl.s = tints_[i].s; |
| 1043 hsl.l = tints_[i].l; | 1043 hsl.l = tints_[i].l; |
| 1044 return hsl; | 1044 return hsl; |
| 1045 } | 1045 } |
| 1046 } | 1046 } |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 return BrowserThemeProvider::GetDefaultTint(id); | 1049 return BrowserThemeProvider::GetDefaultTint(id); |
| 1050 } | 1050 } |
| OLD | NEW |