• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4  * Copyright (C) Research In Motion Limited 2011. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef SVGColor_h
23 #define SVGColor_h
24 
25 #include "core/css/CSSValue.h"
26 #include "platform/graphics/Color.h"
27 #include "wtf/PassRefPtr.h"
28 
29 namespace WebCore {
30 
31 class ExceptionState;
32 class RGBColor;
33 
34 class SVGColor : public CSSValue {
35 public:
36     enum SVGColorType {
37         SVG_COLORTYPE_UNKNOWN = 0,
38         SVG_COLORTYPE_RGBCOLOR = 1,
39         SVG_COLORTYPE_RGBCOLOR_ICCCOLOR = 2,
40         SVG_COLORTYPE_CURRENTCOLOR = 3
41     };
42 
createFromString(const String & rgbColor)43     static PassRefPtr<SVGColor> createFromString(const String& rgbColor)
44     {
45         RefPtr<SVGColor> color = adoptRef(new SVGColor(SVG_COLORTYPE_RGBCOLOR));
46         color->setColor(colorFromRGBColorString(rgbColor));
47         return color.release();
48     }
49 
createFromColor(const Color & rgbColor)50     static PassRefPtr<SVGColor> createFromColor(const Color& rgbColor)
51     {
52         RefPtr<SVGColor> color = adoptRef(new SVGColor(SVG_COLORTYPE_RGBCOLOR));
53         color->setColor(rgbColor);
54         return color.release();
55     }
56 
createCurrentColor()57     static PassRefPtr<SVGColor> createCurrentColor()
58     {
59         return adoptRef(new SVGColor(SVG_COLORTYPE_CURRENTCOLOR));
60     }
61 
color()62     const Color& color() const { return m_color; }
colorType()63     const SVGColorType& colorType() const { return m_colorType; }
64     PassRefPtr<RGBColor> rgbColor() const;
65 
66     static Color colorFromRGBColorString(const String&);
67 
68     void setRGBColor(const String& rgbColor, ExceptionState&);
69     void setRGBColorICCColor(const String& rgbColor, const String& iccColor, ExceptionState&);
70     void setColor(unsigned short colorType, const String& rgbColor, const String& iccColor, ExceptionState&);
71 
72     String customCSSText() const;
73 
~SVGColor()74     ~SVGColor() { }
75 
76     PassRefPtr<SVGColor> cloneForCSSOM() const;
77 
78     bool equals(const SVGColor&) const;
79 
80 protected:
81     friend class CSSComputedStyleDeclaration;
82 
83     SVGColor(ClassType, const SVGColorType&);
84     SVGColor(ClassType, const SVGColor& cloneFrom);
85 
setColor(const Color & color)86     void setColor(const Color& color) { m_color = color; }
setColorType(const SVGColorType & type)87     void setColorType(const SVGColorType& type) { m_colorType = type; }
88 
89 private:
90     SVGColor(const SVGColorType&);
91 
92     Color m_color;
93     SVGColorType m_colorType;
94 };
95 
96 DEFINE_CSS_VALUE_TYPE_CASTS(SVGColor, isSVGColor());
97 
98 } // namespace WebCore
99 
100 #endif // SVGColor_h
101