OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 register unsigned len); | 71 register unsigned len); |
72 | 72 |
73 class PLATFORM_EXPORT Color { | 73 class PLATFORM_EXPORT Color { |
74 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 74 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
75 | 75 |
76 public: | 76 public: |
77 Color() : m_color(Color::transparent) {} | 77 Color() : m_color(Color::transparent) {} |
78 Color(RGBA32 color) : m_color(color) {} | 78 Color(RGBA32 color) : m_color(color) {} |
79 Color(int r, int g, int b) : m_color(makeRGB(r, g, b)) {} | 79 Color(int r, int g, int b) : m_color(makeRGB(r, g, b)) {} |
80 Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)) {} | 80 Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)) {} |
81 // Color is currently limited to 32bit RGBA, perhaps some day we'll support be
tter colors | 81 // Color is currently limited to 32bit RGBA. Perhaps some day we'll support |
| 82 // better colors. |
82 Color(float r, float g, float b, float a) | 83 Color(float r, float g, float b, float a) |
83 : m_color(makeRGBA32FromFloats(r, g, b, a)) {} | 84 : m_color(makeRGBA32FromFloats(r, g, b, a)) {} |
84 // Creates a new color from the specific CMYK and alpha values. | 85 // Creates a new color from the specific CMYK and alpha values. |
85 Color(float c, float m, float y, float k, float a) | 86 Color(float c, float m, float y, float k, float a) |
86 : m_color(makeRGBAFromCMYKA(c, m, y, k, a)) {} | 87 : m_color(makeRGBAFromCMYKA(c, m, y, k, a)) {} |
87 | 88 |
88 static Color createUnchecked(int r, int g, int b) { | 89 static Color createUnchecked(int r, int g, int b) { |
89 RGBA32 color = 0xFF000000 | r << 16 | g << 8 | b; | 90 RGBA32 color = 0xFF000000 | r << 16 | g << 8 | b; |
90 return Color(color); | 91 return Color(color); |
91 } | 92 } |
92 static Color createUnchecked(int r, int g, int b, int a) { | 93 static Color createUnchecked(int r, int g, int b, int a) { |
93 RGBA32 color = a << 24 | r << 16 | g << 8 | b; | 94 RGBA32 color = a << 24 | r << 16 | g << 8 | b; |
94 return Color(color); | 95 return Color(color); |
95 } | 96 } |
96 | 97 |
97 // Returns the color serialized according to HTML5 | 98 // Returns the color serialized according to HTML5: |
98 // - http://www.whatwg.org/specs/web-apps/current-work/#serialization-of-a-col
or | 99 // http://www.whatwg.org/specs/web-apps/current-work/#serialization-of-a-color |
99 String serialized() const; | 100 String serialized() const; |
100 | 101 |
101 // Returns the color serialized according to CSSOM | 102 // Returns the color serialized according to CSSOM: |
102 // - http://dev.w3.org/csswg/cssom/#serialize-a-css-component-value | 103 // http://dev.w3.org/csswg/cssom/#serialize-a-css-component-value |
103 String serializedAsCSSComponentValue() const; | 104 String serializedAsCSSComponentValue() const; |
104 | 105 |
105 // Returns the color serialized as either #RRGGBB or #RRGGBBAA | 106 // Returns the color serialized as either #RRGGBB or #RRGGBBAA. The latter |
106 // The latter format is not a valid CSS color, and should only be seen in DRT
dumps. | 107 // format is not a valid CSS color, and should only be seen in DRT dumps. |
107 String nameForLayoutTreeAsText() const; | 108 String nameForLayoutTreeAsText() const; |
108 | 109 |
109 // Returns whether parsing succeeded. The resulting Color is arbitrary | 110 // Returns whether parsing succeeded. The resulting Color is arbitrary |
110 // if parsing fails. | 111 // if parsing fails. |
111 bool setFromString(const String&); | 112 bool setFromString(const String&); |
112 bool setNamedColor(const String&); | 113 bool setNamedColor(const String&); |
113 | 114 |
114 bool hasAlpha() const { return alpha() < 255; } | 115 bool hasAlpha() const { return alpha() < 255; } |
115 | 116 |
116 int red() const { return redChannel(m_color); } | 117 int red() const { return redChannel(m_color); } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 159 } |
159 | 160 |
160 PLATFORM_EXPORT Color colorFromPremultipliedARGB(RGBA32); | 161 PLATFORM_EXPORT Color colorFromPremultipliedARGB(RGBA32); |
161 PLATFORM_EXPORT RGBA32 premultipliedARGBFromColor(const Color&); | 162 PLATFORM_EXPORT RGBA32 premultipliedARGBFromColor(const Color&); |
162 | 163 |
163 inline Color blend(const Color& from, | 164 inline Color blend(const Color& from, |
164 const Color& to, | 165 const Color& to, |
165 double progress, | 166 double progress, |
166 bool blendPremultiplied = true) { | 167 bool blendPremultiplied = true) { |
167 if (blendPremultiplied) { | 168 if (blendPremultiplied) { |
168 // Contrary to the name, RGBA32 actually stores ARGB, so we can initialize C
olor directly from premultipliedARGBFromColor(). | 169 // Contrary to the name, RGBA32 actually stores ARGB, so we can initialize |
169 // Also, premultipliedARGBFromColor() bails on zero alpha, so special-case t
hat. | 170 // Color directly from premultipliedARGBFromColor(). Also, |
| 171 // premultipliedARGBFromColor() bails on zero alpha, so special-case that. |
170 Color premultFrom = from.alpha() ? premultipliedARGBFromColor(from) : 0; | 172 Color premultFrom = from.alpha() ? premultipliedARGBFromColor(from) : 0; |
171 Color premultTo = to.alpha() ? premultipliedARGBFromColor(to) : 0; | 173 Color premultTo = to.alpha() ? premultipliedARGBFromColor(to) : 0; |
172 | 174 |
173 Color premultBlended( | 175 Color premultBlended( |
174 blend(premultFrom.red(), premultTo.red(), progress), | 176 blend(premultFrom.red(), premultTo.red(), progress), |
175 blend(premultFrom.green(), premultTo.green(), progress), | 177 blend(premultFrom.green(), premultTo.green(), progress), |
176 blend(premultFrom.blue(), premultTo.blue(), progress), | 178 blend(premultFrom.blue(), premultTo.blue(), progress), |
177 blend(premultFrom.alpha(), premultTo.alpha(), progress)); | 179 blend(premultFrom.alpha(), premultTo.alpha(), progress)); |
178 | 180 |
179 return Color(colorFromPremultipliedARGB(premultBlended.rgb())); | 181 return Color(colorFromPremultipliedARGB(premultBlended.rgb())); |
180 } | 182 } |
181 | 183 |
182 return Color(blend(from.red(), to.red(), progress), | 184 return Color(blend(from.red(), to.red(), progress), |
183 blend(from.green(), to.green(), progress), | 185 blend(from.green(), to.green(), progress), |
184 blend(from.blue(), to.blue(), progress), | 186 blend(from.blue(), to.blue(), progress), |
185 blend(from.alpha(), to.alpha(), progress)); | 187 blend(from.alpha(), to.alpha(), progress)); |
186 } | 188 } |
187 } // namespace blink | 189 } // namespace blink |
188 | 190 |
189 #endif // Color_h | 191 #endif // Color_h |
OLD | NEW |