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

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

Issue 1781563003: chrome.browserAction.setBadgeBackgroundColor accepts color keyword (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "extensions/common/image_util.h" 5 #include "extensions/common/image_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "third_party/re2/src/re2/re2.h" 14 #include "third_party/re2/src/re2/re2.h"
15 #include "third_party/skia/include/core/SkColor.h" 15 #include "third_party/skia/include/core/SkColor.h"
16 #include "third_party/skia/include/utils/SkParse.h"
16 #include "ui/gfx/color_utils.h" 17 #include "ui/gfx/color_utils.h"
17 18
18 namespace extensions { 19 namespace extensions {
19 namespace image_util { 20 namespace image_util {
20 21
21 bool ParseCssColorString(const std::string& color_string, SkColor* result) { 22 bool ParseCssColorString(const std::string& color_string, SkColor* result) {
22 if (color_string.empty()) 23 if (color_string.empty())
23 return false; 24 return false;
24 if (color_string[0] == '#') 25 if (color_string[0] == '#')
25 return ParseHexColorString(color_string, result); 26 return ParseHexColorString(color_string, result);
26 if (base::StartsWith(color_string, "hsl", base::CompareCase::SENSITIVE)) 27 if (base::StartsWith(color_string, "hsl", base::CompareCase::SENSITIVE))
27 return ParseHslColorString(color_string, result); 28 return ParseHslColorString(color_string, result);
28 if (base::StartsWith(color_string, "rgb", base::CompareCase::SENSITIVE)) { 29 if (base::StartsWith(color_string, "rgb", base::CompareCase::SENSITIVE)) {
29 NOTIMPLEMENTED(); 30 NOTIMPLEMENTED();
30 return false; 31 return false;
31 } 32 }
33 if (SkParse::FindNamedColor(color_string.c_str(), color_string.size(),
Devlin 2016/03/09 17:52:20 nifty!
34 result) != nullptr) {
35 return true;
36 }
37
32 return false; 38 return false;
33 } 39 }
34 40
35 bool ParseHexColorString(const std::string& color_string, SkColor* result) { 41 bool ParseHexColorString(const std::string& color_string, SkColor* result) {
36 std::string formatted_color; 42 std::string formatted_color;
37 // Check the string for incorrect formatting. 43 // Check the string for incorrect formatting.
38 if (color_string.empty() || color_string[0] != '#') 44 if (color_string.empty() || color_string[0] != '#')
39 return false; 45 return false;
40 46
41 // Convert the string from #FFF format to #FFFFFF format. 47 // Convert the string from #FFF format to #FFFFFF format.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 hsl.l = std::max(0.0, std::min(100.0, lightness)) / 100.0; 100 hsl.l = std::max(0.0, std::min(100.0, lightness)) / 100.0;
95 101
96 SkAlpha sk_alpha = std::max(0.0, std::min(1.0, alpha)) * 255; 102 SkAlpha sk_alpha = std::max(0.0, std::min(1.0, alpha)) * 255;
97 103
98 *result = color_utils::HSLToSkColor(hsl, sk_alpha); 104 *result = color_utils::HSLToSkColor(hsl, sk_alpha);
99 return true; 105 return true;
100 } 106 }
101 107
102 } // namespace image_util 108 } // namespace image_util
103 } // namespace extensions 109 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/browser_action/color/update4.js ('k') | extensions/common/image_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698