Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGPaint.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) 2006 Samuel Weinig <sam.weinig@gmial.com>
5  * Copyright (C) Research In Motion Limited 2011. All rights reserved.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef SVGPaint_h
24 #define SVGPaint_h
25
26 #include "core/svg/SVGColor.h"
27 #include "wtf/text/WTFString.h"
28
29 namespace WebCore {
30
31 class ExceptionState;
32
33 class SVGPaint : public SVGColor {
34 public:
35     enum SVGPaintType {
36         SVG_PAINTTYPE_UNKNOWN = 0,
37         SVG_PAINTTYPE_RGBCOLOR = 1,
38         SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR = 2,
39         SVG_PAINTTYPE_NONE = 101,
40         SVG_PAINTTYPE_CURRENTCOLOR = 102,
41         SVG_PAINTTYPE_URI_NONE = 103,
42         SVG_PAINTTYPE_URI_CURRENTCOLOR = 104,
43         SVG_PAINTTYPE_URI_RGBCOLOR = 105,
44         SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR = 106,
45         SVG_PAINTTYPE_URI = 107
46     };
47
48     static PassRefPtr<SVGPaint> createUnknown()
49     {
50         return adoptRef(new SVGPaint(SVG_PAINTTYPE_UNKNOWN));
51     }
52
53     static PassRefPtr<SVGPaint> createNone()
54     {
55         return adoptRef(new SVGPaint(SVG_PAINTTYPE_NONE));
56     }
57
58     static PassRefPtr<SVGPaint> createCurrentColor()
59     {
60         return adoptRef(new SVGPaint(SVG_PAINTTYPE_CURRENTCOLOR));
61     }
62
63     static PassRefPtr<SVGPaint> createColor(const Color& color)
64     {
65         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_RGBCOLOR));
66         paint->setColor(color);
67         return paint.release();
68     }
69
70     static PassRefPtr<SVGPaint> createURI(const String& uri)
71     {
72         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_URI, uri));
73         return paint.release();
74     }
75
76     static PassRefPtr<SVGPaint> createURIAndColor(const String& uri, const Color& color)
77     {
78         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_URI_RGBCOLOR, uri));
79         paint->setColor(color);
80         return paint.release();
81     }
82
83     static PassRefPtr<SVGPaint> createURIAndNone(const String& uri)
84     {
85         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_URI_NONE, uri));
86         return paint.release();
87     }
88
89     static PassRefPtr<SVGPaint> createURIAndCurrentColor(const String& uri)
90     {
91         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_URI_CURRENTCOLOR, uri));
92         return paint.release();
93     }
94
95     const SVGPaintType& paintType() const { return m_paintType; }
96     String uri() const { return m_uri; }
97
98     void setUri(const String&);
99     void setPaint(unsigned short paintType, const String& uri, const String& rgbColor, const String& iccColor, ExceptionState&);
100
101     String customCSSText() const;
102
103     PassRefPtr<SVGPaint> cloneForCSSOM() const;
104
105     bool equals(const SVGPaint&) const;
106
107 private:
108     friend class CSSComputedStyleDeclaration;
109
110     static PassRefPtr<SVGPaint> create(const SVGPaintType& type, const String& uri, const Color& color)
111     {
112         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(type, uri));
113         paint->setColor(color);
114         return paint.release();
115     }
116
117 private:
118     SVGPaint(const SVGPaintType&, const String& uri = String());
119     SVGPaint(const SVGPaint& cloneFrom);
120
121     SVGPaintType m_paintType;
122     String m_uri;
123 };
124
125 DEFINE_CSS_VALUE_TYPE_CASTS(SVGPaint, isSVGPaint());
126
127 } // namespace WebCore
128
129 #endif // SVGPaint_h