summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/platform/graphics/Color.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/platform/graphics/Color.h')
-rw-r--r--chromium/third_party/WebKit/Source/platform/graphics/Color.h38
1 files changed, 19 insertions, 19 deletions
diff --git a/chromium/third_party/WebKit/Source/platform/graphics/Color.h b/chromium/third_party/WebKit/Source/platform/graphics/Color.h
index 9664906a8f7..ce371ab23f8 100644
--- a/chromium/third_party/WebKit/Source/platform/graphics/Color.h
+++ b/chromium/third_party/WebKit/Source/platform/graphics/Color.h
@@ -62,16 +62,14 @@ const NamedColor* findColor(register const char* str, register unsigned len);
class PLATFORM_EXPORT Color {
WTF_MAKE_FAST_ALLOCATED;
public:
- Color() : m_color(0), m_valid(false) { }
- Color(RGBA32 color, bool valid = true) : m_color(color), m_valid(valid) { ASSERT(!m_color || m_valid); }
- Color(int r, int g, int b) : m_color(makeRGB(r, g, b)), m_valid(true) { }
- Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)), m_valid(true) { }
+ Color() : m_color(Color::transparent) { }
+ Color(RGBA32 color) : m_color(color) { }
+ Color(int r, int g, int b) : m_color(makeRGB(r, g, b)) { }
+ Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)) { }
// Color is currently limited to 32bit RGBA, perhaps some day we'll support better colors
- Color(float r, float g, float b, float a) : m_color(makeRGBA32FromFloats(r, g, b, a)), m_valid(true) { }
+ Color(float r, float g, float b, float a) : m_color(makeRGBA32FromFloats(r, g, b, a)) { }
// Creates a new color from the specific CMYK and alpha values.
- Color(float c, float m, float y, float k, float a) : m_color(makeRGBAFromCMYKA(c, m, y, k, a)), m_valid(true) { }
- explicit Color(const String&);
- explicit Color(const char*);
+ Color(float c, float m, float y, float k, float a) : m_color(makeRGBAFromCMYKA(c, m, y, k, a)) { }
static Color createUnchecked(int r, int g, int b)
{
@@ -88,13 +86,18 @@ public:
// - http://www.whatwg.org/specs/web-apps/current-work/#serialization-of-a-color
String serialized() const;
+ // Returns the color serialized according to CSSOM
+ // - http://dev.w3.org/csswg/cssom/#serialize-a-css-component-value
+ String serializedAsCSSComponentValue() const;
+
// Returns the color serialized as either #RRGGBB or #RRGGBBAA
// The latter format is not a valid CSS color, and should only be seen in DRT dumps.
String nameForRenderTreeAsText() const;
- void setNamedColor(const String&);
-
- bool isValid() const { return m_valid; }
+ // Returns whether parsing succeeded. The resulting Color is arbitrary
+ // if parsing fails.
+ bool setFromString(const String&);
+ bool setNamedColor(const String&);
bool hasAlpha() const { return alpha() < 255; }
@@ -104,8 +107,8 @@ public:
int alpha() const { return alphaChannel(m_color); }
RGBA32 rgb() const { return m_color; } // Preserve the alpha.
- void setRGB(int r, int g, int b) { m_color = makeRGB(r, g, b); m_valid = true; }
- void setRGB(RGBA32 rgb) { m_color = rgb; m_valid = true; }
+ void setRGB(int r, int g, int b) { m_color = makeRGB(r, g, b); }
+ void setRGB(RGBA32 rgb) { m_color = rgb; }
void getRGBA(float& r, float& g, float& b, float& a) const;
void getRGBA(double& r, double& g, double& b, double& a) const;
void getHSL(double& h, double& s, double& l) const;
@@ -113,6 +116,8 @@ public:
Color light() const;
Color dark() const;
+ Color combineWithAlpha(float otherAlpha) const;
+
// This is an implementation of Porter-Duff's "source-over" equation
Color blend(const Color&) const;
Color blendWithWhite() const;
@@ -130,12 +135,11 @@ public:
private:
RGBA32 m_color;
- bool m_valid;
};
inline bool operator==(const Color& a, const Color& b)
{
- return a.rgb() == b.rgb() && a.isValid() == b.isValid();
+ return a.rgb() == b.rgb();
}
inline bool operator!=(const Color& a, const Color& b)
@@ -148,10 +152,6 @@ PLATFORM_EXPORT RGBA32 premultipliedARGBFromColor(const Color&);
inline Color blend(const Color& from, const Color& to, double progress, bool blendPremultiplied = true)
{
- // We need to preserve the state of the valid flag at the end of the animation
- if (progress == 1 && !to.isValid())
- return Color();
-
if (blendPremultiplied) {
// Contrary to the name, RGBA32 actually stores ARGB, so we can initialize Color directly from premultipliedARGBFromColor().
// Also, premultipliedARGBFromColor() bails on zero alpha, so special-case that.