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 #ifndef UI_GFX_COLOR_UTILS_H_ | 5 #ifndef UI_GFX_COLOR_UTILS_H_ |
6 #define UI_GFX_COLOR_UTILS_H_ | 6 #define UI_GFX_COLOR_UTILS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
10 #include "ui/gfx/gfx_export.h" | 10 #include "ui/gfx/gfx_export.h" |
11 | 11 |
12 class SkBitmap; | 12 class SkBitmap; |
13 | 13 |
14 namespace color_utils { | 14 namespace color_utils { |
15 | 15 |
16 // Represents an HSL color. | 16 // Represents an HSL color. |
17 struct HSL { | 17 struct HSL { |
18 double h; | 18 double h; |
19 double s; | 19 double s; |
20 double l; | 20 double l; |
21 }; | 21 }; |
22 | 22 |
| 23 // The minimum contrast between text and background that is still readable. |
| 24 // This value is taken from w3c accessibility guidelines. |
| 25 const double kMinimumReadableContrastRatio = 4.5f; |
| 26 |
| 27 // Determines the contrast ratio of two colors. |
| 28 GFX_EXPORT double GetContrastRatio(SkColor color_a, SkColor color_b); |
| 29 |
23 GFX_EXPORT unsigned char GetLuminanceForColor(SkColor color); | 30 GFX_EXPORT unsigned char GetLuminanceForColor(SkColor color); |
24 | 31 |
25 // Calculated according to http://www.w3.org/TR/WCAG20/#relativeluminancedef | 32 // Calculated according to http://www.w3.org/TR/WCAG20/#relativeluminancedef |
26 GFX_EXPORT double RelativeLuminance(SkColor color); | 33 GFX_EXPORT double RelativeLuminance(SkColor color); |
27 | 34 |
28 // Note: these transformations assume sRGB as the source color space | 35 // Note: these transformations assume sRGB as the source color space |
29 GFX_EXPORT void SkColorToHSL(SkColor c, HSL* hsl); | 36 GFX_EXPORT void SkColorToHSL(SkColor c, HSL* hsl); |
30 GFX_EXPORT SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha); | 37 GFX_EXPORT SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha); |
31 | 38 |
32 // Determines whether the given |hsl| falls within the given range for each | 39 // Determines whether the given |hsl| falls within the given range for each |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // light-on-dark color scheme. | 115 // light-on-dark color scheme. |
109 GFX_EXPORT bool IsInvertedColorScheme(); | 116 GFX_EXPORT bool IsInvertedColorScheme(); |
110 | 117 |
111 // Derives a color for icons on a UI surface based on the text color on the same | 118 // Derives a color for icons on a UI surface based on the text color on the same |
112 // surface. | 119 // surface. |
113 GFX_EXPORT SkColor DeriveDefaultIconColor(SkColor text_color); | 120 GFX_EXPORT SkColor DeriveDefaultIconColor(SkColor text_color); |
114 | 121 |
115 } // namespace color_utils | 122 } // namespace color_utils |
116 | 123 |
117 #endif // UI_GFX_COLOR_UTILS_H_ | 124 #endif // UI_GFX_COLOR_UTILS_H_ |
OLD | NEW |