KHTML
Color.h
Go to the documentation of this file.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 #include "PlatformString.h"
00031
00032 #if PLATFORM(CG)
00033 typedef struct CGColor* CGColorRef;
00034 #endif
00035
00036 #if PLATFORM(QT)
00037 #include <qglobal.h>
00038 QT_BEGIN_NAMESPACE
00039 class QColor;
00040 QT_END_NAMESPACE
00041 #endif
00042
00043 #if PLATFORM(GTK)
00044 typedef struct _GdkColor GdkColor;
00045 #endif
00046
00047 #if PLATFORM(WX)
00048 class wxColour;
00049 #endif
00050
00051 namespace WebCore {
00052
00053
00054 class Color;
00055
00056 typedef unsigned RGBA32;
00057
00058 RGBA32 makeRGB(int r, int g, int b);
00059 RGBA32 makeRGBA(int r, int g, int b, int a);
00060 RGBA32 makeRGBAFromHSLA(double h, double s, double l, double a);
00061
00062 int differenceSquared(const Color&, const Color&);
00063
00064 class Color {
00065 public:
00066 Color() : m_color(0), m_valid(false) { }
00067 Color(RGBA32 col) : m_color(col), m_valid(true) { }
00068 Color(int r, int g, int b) : m_color(makeRGB(r, g, b)), m_valid(true) { }
00069 Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)), m_valid(true) { }
00070 explicit Color(const String&);
00071 explicit Color(const char*);
00072
00073 String name() const;
00074 void setNamedColor(const String&);
00075
00076 bool isValid() const { return m_valid; }
00077
00078 bool hasAlpha() const { return alpha() < 255; }
00079
00080 int red() const { return (m_color >> 16) & 0xFF; }
00081 int green() const { return (m_color >> 8) & 0xFF; }
00082 int blue() const { return m_color & 0xFF; }
00083 int alpha() const { return (m_color >> 24) & 0xFF; }
00084
00085 RGBA32 rgb() const { return m_color; }
00086 void setRGB(int r, int g, int b) { m_color = makeRGB(r, g, b); m_valid = true; }
00087 void setRGB(RGBA32 rgb) { m_color = rgb; m_valid = true; }
00088 void getRGBA(float& r, float& g, float& b, float& a) const;
00089 void getRGBA(double& r, double& g, double& b, double& a) const;
00090
00091 Color light() const;
00092 Color dark() const;
00093
00094 Color blend(const Color&) const;
00095 Color blendWithWhite() const;
00096
00097 #if PLATFORM(QT)
00098 Color(const QColor&);
00099 operator QColor() const;
00100 #endif
00101
00102 #if PLATFORM(GTK)
00103 Color(const GdkColor&);
00104
00105 #endif
00106
00107 #if PLATFORM(WX)
00108 Color(const wxColour&);
00109 operator wxColour() const;
00110 #endif
00111
00112 #if PLATFORM(CG)
00113 Color(CGColorRef);
00114 #endif
00115
00116 static bool parseHexColor(const String& name, RGBA32& rgb);
00117
00118 static const RGBA32 black = 0xFF000000;
00119 static const RGBA32 white = 0xFFFFFFFF;
00120 static const RGBA32 darkGray = 0xFF808080;
00121 static const RGBA32 gray = 0xFFA0A0A0;
00122 static const RGBA32 lightGray = 0xFFC0C0C0;
00123 static const RGBA32 transparent = 0x00000000;
00124
00125 private:
00126 RGBA32 m_color;
00127 bool m_valid : 1;
00128 };
00129
00130 inline bool operator==(const Color& a, const Color& b)
00131 {
00132 return a.rgb() == b.rgb() && a.isValid() == b.isValid();
00133 }
00134
00135 inline bool operator!=(const Color& a, const Color& b)
00136 {
00137 return !(a == b);
00138 }
00139
00140 Color focusRingColor();
00141 void setFocusRingColorChangeFunction(void (*)());
00142
00143 #if PLATFORM(CG)
00144 CGColorRef cgColor(const Color&);
00145 #endif
00146
00147 }
00148
00149 #endif // Color_h