initial import
[vuplus_webkit] / Source / WebCore / 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 #if ENABLE(SVG)
27 #include "SVGColor.h"
28 #include <wtf/text/WTFString.h>
29
30 namespace WebCore {
31
32 class SVGPaint : public SVGColor {
33 public:
34     enum SVGPaintType {
35         SVG_PAINTTYPE_UNKNOWN = 0,
36         SVG_PAINTTYPE_RGBCOLOR = 1,
37         SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR = 2,
38         SVG_PAINTTYPE_NONE = 101,
39         SVG_PAINTTYPE_CURRENTCOLOR = 102,
40         SVG_PAINTTYPE_URI_NONE = 103,
41         SVG_PAINTTYPE_URI_CURRENTCOLOR = 104,
42         SVG_PAINTTYPE_URI_RGBCOLOR = 105,
43         SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR = 106,
44         SVG_PAINTTYPE_URI = 107
45     };
46
47     static PassRefPtr<SVGPaint> createUnknown()
48     {
49         return adoptRef(new SVGPaint(SVG_PAINTTYPE_UNKNOWN));
50     }
51
52     static PassRefPtr<SVGPaint> createNone()
53     {
54         return adoptRef(new SVGPaint(SVG_PAINTTYPE_NONE));
55     }
56
57     static PassRefPtr<SVGPaint> createCurrentColor()
58     {
59         return adoptRef(new SVGPaint(SVG_PAINTTYPE_CURRENTCOLOR));
60     }
61
62     static PassRefPtr<SVGPaint> createColor(const Color& color)
63     {
64         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_RGBCOLOR));
65         paint->setColor(color);
66         return paint.release();
67     }
68
69     static PassRefPtr<SVGPaint> createURI(const String& uri)
70     {
71         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_URI, uri));
72         return paint.release();
73     }
74
75     static PassRefPtr<SVGPaint> createURIAndColor(const String& uri, const Color& color)
76     {
77         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_URI_RGBCOLOR, uri));
78         paint->setColor(color);
79         return paint.release();
80     }
81
82     static PassRefPtr<SVGPaint> createURIAndNone(const String& uri)
83     {
84         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_URI_NONE, uri));
85         return paint.release();
86     }
87
88     const SVGPaintType& paintType() const { return m_paintType; }
89     String uri() const { return m_uri; }
90
91     void setUri(const String&);
92     void setPaint(unsigned short paintType, const String& uri, const String& rgbColor, const String& iccColor, ExceptionCode&);
93
94     bool matchesTargetURI(const String& referenceId);
95
96 private:
97     friend class CSSComputedStyleDeclaration;
98
99     static PassRefPtr<SVGPaint> create(const SVGPaintType& type, const String& uri, const Color& color)
100     {
101         RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(type, uri));
102         paint->setColor(color);
103         return paint.release();
104     }
105
106 private:
107     SVGPaint(const SVGPaintType&, const String& uri = String());
108
109     virtual bool isSVGPaint() const { return true; }
110     virtual String cssText() const;
111
112     SVGPaintType m_paintType;
113     String m_uri;
114 };
115
116 } // namespace WebCore
117
118 #endif // ENABLE(SVG)
119 #endif // SVGPaint_h