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

Side by Side Diff: extensions/browser/image_util.cc

Issue 782693002: Ensure there are always nice icons for bookmark apps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac compile Created 6 years 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
« no previous file with comments | « extensions/browser/image_util.h ('k') | extensions/browser/image_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "extensions/browser/image_util.h"
6
7 #include <stdint.h>
8 #include <vector>
9
10 #include "base/strings/string_number_conversions.h"
11 #include "third_party/skia/include/core/SkColor.h"
12
13 namespace extensions {
14 namespace image_util {
15
16 bool ParseCSSColorString(const std::string& color_string, SkColor* result) {
17 std::string formatted_color;
18 // Check the string for incorrect formatting.
19 if (color_string.empty() || color_string[0] != '#')
20 return false;
21
22 // Convert the string from #FFF format to #FFFFFF format.
23 if (color_string.length() == 4) {
24 for (size_t i = 1; i < 4; ++i) {
25 formatted_color += color_string[i];
26 formatted_color += color_string[i];
27 }
28 } else if (color_string.length() == 7) {
29 formatted_color = color_string.substr(1, 6);
30 } else {
31 return false;
32 }
33
34 // Convert the string to an integer and make sure it is in the correct value
35 // range.
36 std::vector<uint8_t> color_bytes;
37 if (!base::HexStringToBytes(formatted_color, &color_bytes))
38 return false;
39
40 *result = SkColorSetARGB(255, color_bytes[0], color_bytes[1], color_bytes[2]);
41 return true;
42 }
43
44 } // namespace image_util
45 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/image_util.h ('k') | extensions/browser/image_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698