2 * Copyright (C) 2003-6 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 typedef struct CGColor* CGColorRef;
46 typedef unsigned RGBA32; // RGBA quadruplet
48 RGBA32 makeRGB(int r, int g, int b);
49 RGBA32 makeRGBA(int r, int g, int b, int a);
50 RGBA32 makeRGBAFromHSLA(double h, double s, double l, double a);
52 int differenceSquared(const Color&, const Color&);
56 Color() : m_color(0), m_valid(false) { }
57 Color(RGBA32 col) : m_color(col), m_valid(true) { }
58 Color(int r, int g, int b) : m_color(makeRGB(r, g, b)), m_valid(true) { }
59 Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)), m_valid(true) { }
60 explicit Color(const String&);
61 explicit Color(const char*);
64 void setNamedColor(const String&);
66 bool isValid() const { return m_valid; }
68 bool hasAlpha() const { return alpha() < 255; }
70 int red() const { return (m_color >> 16) & 0xFF; }
71 int green() const { return (m_color >> 8) & 0xFF; }
72 int blue() const { return m_color & 0xFF; }
73 int alpha() const { return (m_color >> 24) & 0xFF; }
75 RGBA32 rgb() const { return m_color; } // Preserve the alpha.
76 void setRGB(int r, int g, int b) { m_color = makeRGB(r, g, b); m_valid = true; }
77 void setRGB(RGBA32 rgb) { m_color = rgb; m_valid = true; }
78 void getRGBA(float& r, float& g, float& b, float& a) const;
79 void getRGBA(double& r, double& g, double& b, double& a) const;
84 Color blendWithWhite() const;
86 static const RGBA32 black = 0xFF000000;
87 static const RGBA32 white = 0xFFFFFFFF;
88 static const RGBA32 darkGray = 0xFF808080;
89 static const RGBA32 gray = 0xFFA0A0A0;
90 static const RGBA32 lightGray = 0xFFC0C0C0;
91 static const RGBA32 transparent = 0x00000000;
98 inline bool operator==(const Color& a, const Color& b)
100 return a.rgb() == b.rgb() && a.isValid() == b.isValid();
103 inline bool operator!=(const Color& a, const Color& b)
108 Color focusRingColor();
109 void setFocusRingColorChangeFunction(void (*)());
112 NSColor* nsColor(const Color&);
113 CGColorRef cgColor(const Color&);
116 } // namespace WebCore