Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(614)

Side by Side Diff: chrome/browser/themes/browser_theme_pack.cc

Issue 6901084: Use new APIs in base/values.h: Value::GetAsNumber and DictionaryValue::GetNumber. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, 2010->2011 Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/printing/print_dialog_cloud.cc ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
291 char* data = reinterpret_cast<char*>(&(raw_data.front())); 291 char* data = reinterpret_cast<char*>(&(raw_data.front()));
292 if (file.ReadUntilComplete(data, size) == avail) 292 if (file.ReadUntilComplete(data, size) == avail)
293 return RefCountedBytes::TakeVector(&raw_data); 293 return RefCountedBytes::TakeVector(&raw_data);
294 } 294 }
295 } 295 }
296 } 296 }
297 297
298 return NULL; 298 return NULL;
299 } 299 }
300 300
301 // Does error checking for invalid incoming data while trying to read an
302 // floating point value.
303 bool ValidDoubleValue(ListValue* tint_list, int index, double* out) {
304 if (tint_list->GetDouble(index, out))
305 return true;
306
307 int value = 0;
308 if (tint_list->GetInteger(index, &value)) {
309 *out = value;
310 return true;
311 }
312
313 return false;
314 }
315
316 // Shifts a bitmap's HSL values. The caller is responsible for deleting 301 // Shifts a bitmap's HSL values. The caller is responsible for deleting
317 // the returned image. 302 // the returned image.
318 gfx::Image* CreateHSLShiftedImage(const gfx::Image& image, 303 gfx::Image* CreateHSLShiftedImage(const gfx::Image& image,
319 const color_utils::HSL& hsl_shift) { 304 const color_utils::HSL& hsl_shift) {
320 std::vector<const SkBitmap*> bitmaps; 305 std::vector<const SkBitmap*> bitmaps;
321 for (size_t i = 0; i < image.GetNumberOfSkBitmaps(); ++i) { 306 for (size_t i = 0; i < image.GetNumberOfSkBitmaps(); ++i) {
322 const SkBitmap* bitmap = image.GetSkBitmapAtIndex(i); 307 const SkBitmap* bitmap = image.GetSkBitmapAtIndex(i);
323 bitmaps.push_back(new SkBitmap(SkBitmapOperations::CreateHSLShiftedBitmap( 308 bitmaps.push_back(new SkBitmap(SkBitmapOperations::CreateHSLShiftedBitmap(
324 *bitmap, hsl_shift))); 309 *bitmap, hsl_shift)));
325 } 310 }
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 624
640 // Parse the incoming data from |tints_value| into an intermediary structure. 625 // Parse the incoming data from |tints_value| into an intermediary structure.
641 std::map<int, color_utils::HSL> temp_tints; 626 std::map<int, color_utils::HSL> temp_tints;
642 for (DictionaryValue::key_iterator iter(tints_value->begin_keys()); 627 for (DictionaryValue::key_iterator iter(tints_value->begin_keys());
643 iter != tints_value->end_keys(); ++iter) { 628 iter != tints_value->end_keys(); ++iter) {
644 ListValue* tint_list; 629 ListValue* tint_list;
645 if (tints_value->GetList(*iter, &tint_list) && 630 if (tints_value->GetList(*iter, &tint_list) &&
646 (tint_list->GetSize() == 3)) { 631 (tint_list->GetSize() == 3)) {
647 color_utils::HSL hsl = { -1, -1, -1 }; 632 color_utils::HSL hsl = { -1, -1, -1 };
648 633
649 if (ValidDoubleValue(tint_list, 0, &hsl.h) && 634 if (tint_list->GetDouble(0, &hsl.h) &&
650 ValidDoubleValue(tint_list, 1, &hsl.s) && 635 tint_list->GetDouble(1, &hsl.s) &&
651 ValidDoubleValue(tint_list, 2, &hsl.l)) { 636 tint_list->GetDouble(2, &hsl.l)) {
652 int id = GetIntForString(*iter, kTintTable); 637 int id = GetIntForString(*iter, kTintTable);
653 if (id != -1) { 638 if (id != -1) {
654 temp_tints[id] = hsl; 639 temp_tints[id] = hsl;
655 } 640 }
656 } 641 }
657 } 642 }
658 } 643 }
659 644
660 // Copy data from the intermediary data structure to the array. 645 // Copy data from the intermediary data structure to the array.
661 int count = 0; 646 int count = 0;
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 hsl.h = tints_[i].h; 1057 hsl.h = tints_[i].h;
1073 hsl.s = tints_[i].s; 1058 hsl.s = tints_[i].s;
1074 hsl.l = tints_[i].l; 1059 hsl.l = tints_[i].l;
1075 return hsl; 1060 return hsl;
1076 } 1061 }
1077 } 1062 }
1078 } 1063 }
1079 1064
1080 return ThemeService::GetDefaultTint(id); 1065 return ThemeService::GetDefaultTint(id);
1081 } 1066 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_dialog_cloud.cc ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698