Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGColor.h
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 "core/css/StyleColor.h"
27 #include "platform/graphics/Color.h"
28 #include "wtf/PassRefPtr.h"
29
30 namespace WebCore {
31
32 class ExceptionState;
33 class RGBColor;
34
35 class SVGColor : public CSSValue {
36 public:
37     enum SVGColorType {
38         SVG_COLORTYPE_UNKNOWN = 0,
39         SVG_COLORTYPE_RGBCOLOR = 1,
40         SVG_COLORTYPE_RGBCOLOR_ICCCOLOR = 2,
41         SVG_COLORTYPE_CURRENTCOLOR = 3
42     };
43
44     static PassRefPtrWillBeRawPtr<SVGColor> createFromString(const String& rgbColor)
45     {
46         RefPtrWillBeRawPtr<SVGColor> color = adoptRefCountedWillBeRefCountedGarbageCollected(new SVGColor(SVG_COLORTYPE_RGBCOLOR));
47         StyleColor styleColor = colorFromRGBColorString(rgbColor);
48         ASSERT(!styleColor.isCurrentColor());
49         color->setColor(styleColor.color());
50         return color.release();
51     }
52
53     static PassRefPtrWillBeRawPtr<SVGColor> createFromColor(const Color& rgbColor)
54     {
55         RefPtrWillBeRawPtr<SVGColor> color = adoptRefCountedWillBeRefCountedGarbageCollected(new SVGColor(SVG_COLORTYPE_RGBCOLOR));
56         color->setColor(rgbColor);
57         return color.release();
58     }
59
60     static PassRefPtrWillBeRawPtr<SVGColor> createCurrentColor()
61     {
62         return adoptRefCountedWillBeRefCountedGarbageCollected(new SVGColor(SVG_COLORTYPE_CURRENTCOLOR));
63     }
64
65     const Color& color() const { return m_color; }
66     const SVGColorType& colorType() const { return m_colorType; }
67     PassRefPtr<RGBColor> rgbColor() const;
68
69     static StyleColor colorFromRGBColorString(const String&);
70
71     void setRGBColor(const String& rgbColor, ExceptionState&);
72     void setRGBColorICCColor(const String& rgbColor, const String& iccColor, ExceptionState&);
73     void setColor(unsigned short colorType, const String& rgbColor, const String& iccColor, ExceptionState&);
74
75     String customCSSText() const;
76
77     ~SVGColor() { }
78
79     PassRefPtrWillBeRawPtr<SVGColor> cloneForCSSOM() const;
80
81     bool equals(const SVGColor&) const;
82
83     void traceAfterDispatch(Visitor* visitor) { CSSValue::traceAfterDispatch(visitor); }
84
85 protected:
86     friend class CSSComputedStyleDeclaration;
87
88     SVGColor(ClassType, const SVGColorType&);
89     SVGColor(ClassType, const SVGColor& cloneFrom);
90
91     void setColor(const Color& color)
92     {
93         m_color = color;
94         setColorType(SVG_COLORTYPE_RGBCOLOR);
95     }
96     void setColorType(const SVGColorType& type) { m_colorType = type; }
97
98 private:
99     SVGColor(const SVGColorType&);
100
101     Color m_color;
102     SVGColorType m_colorType;
103 };
104
105 DEFINE_CSS_VALUE_TYPE_CASTS(SVGColor, isSVGColor());
106
107 } // namespace WebCore
108
109 #endif // SVGColor_h