00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef Color_h
00027 #define Color_h
00028
00029 #include <wtf/Platform.h>
00030
00031 #if PLATFORM(CG)
00032 typedef struct CGColor* CGColorRef;
00033 #endif
00034
00035 #if PLATFORM(QT)
00036 class QColor;
00037 #endif
00038
00039 namespace WebCore {
00040
00041 class String;
00042 class Color;
00043
00044 typedef unsigned RGBA32;
00045
00046 RGBA32 makeRGB(int r, int g, int b);
00047 RGBA32 makeRGBA(int r, int g, int b, int a);
00048 RGBA32 makeRGBAFromHSLA(double h, double s, double l, double a);
00049
00050 int differenceSquared(const Color&, const Color&);
00051
00052 class Color {
00053 public:
00054 Color() : m_color(0), m_valid(false) { }
00055 Color(RGBA32 col) : m_color(col), m_valid(true) { }
00056 Color(int r, int g, int b) : m_color(makeRGB(r, g, b)), m_valid(true) { }
00057 Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)), m_valid(true) { }
00058 explicit Color(const String&);
00059 explicit Color(const char*);
00060
00061 String name() const;
00062 void setNamedColor(const String&);
00063
00064 bool isValid() const { return m_valid; }
00065
00066 bool hasAlpha() const { return alpha() < 255; }
00067
00068 int red() const { return (m_color >> 16) & 0xFF; }
00069 int green() const { return (m_color >> 8) & 0xFF; }
00070 int blue() const { return m_color & 0xFF; }
00071 int alpha() const { return (m_color >> 24) & 0xFF; }
00072
00073 RGBA32 rgb() const { return m_color; }
00074 void setRGB(int r, int g, int b) { m_color = makeRGB(r, g, b); m_valid = true; }
00075 void setRGB(RGBA32 rgb) { m_color = rgb; m_valid = true; }
00076 void getRGBA(float& r, float& g, float& b, float& a) const;
00077 void getRGBA(double& r, double& g, double& b, double& a) const;
00078
00079 Color light() const;
00080 Color dark() const;
00081
00082 Color blend(const Color&) const;
00083 Color blendWithWhite() const;
00084
00085 #if PLATFORM(QT)
00086 Color(const QColor&);
00087 operator QColor() const;
00088 #endif
00089
00090 static bool parseHexColor(const String& name, RGBA32& rgb);
00091
00092 static const RGBA32 black = 0xFF000000;
00093 static const RGBA32 white = 0xFFFFFFFF;
00094 static const RGBA32 darkGray = 0xFF808080;
00095 static const RGBA32 gray = 0xFFA0A0A0;
00096 static const RGBA32 lightGray = 0xFFC0C0C0;
00097 static const RGBA32 transparent = 0x00000000;
00098
00099 private:
00100 RGBA32 m_color;
00101 bool m_valid : 1;
00102 };
00103
00104 inline bool operator==(const Color& a, const Color& b)
00105 {
00106 return a.rgb() == b.rgb() && a.isValid() == b.isValid();
00107 }
00108
00109 inline bool operator!=(const Color& a, const Color& b)
00110 {
00111 return !(a == b);
00112 }
00113
00114 Color focusRingColor();
00115 void setFocusRingColorChangeFunction(void (*)());
00116
00117 #if PLATFORM(CG)
00118 CGColorRef cgColor(const Color&);
00119 #endif
00120
00121 }
00122
00123 #endif // Color_h