tizen beta release
[framework/web/webkit-efl.git] / Source / WebCore / svg / SVGPaint.cpp
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 2010-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 #include "config.h"
23
24 #if ENABLE(SVG)
25 #include "SVGPaint.h"
26
27 #include "SVGException.h"
28 #include "SVGURIReference.h"
29 #include <wtf/text/WTFString.h>
30
31 namespace WebCore {
32
33 static inline SVGColor::SVGColorType colorTypeForPaintType(const SVGPaint::SVGPaintType& paintType)
34 {
35     switch (paintType) {
36     case SVGPaint::SVG_PAINTTYPE_NONE:
37     case SVGPaint::SVG_PAINTTYPE_UNKNOWN:
38     case SVGPaint::SVG_PAINTTYPE_URI:
39     case SVGPaint::SVG_PAINTTYPE_URI_NONE:
40         return SVGColor::SVG_COLORTYPE_UNKNOWN;
41     case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR:
42     case SVGPaint::SVG_PAINTTYPE_RGBCOLOR:
43         return SVGColor::SVG_COLORTYPE_RGBCOLOR;
44     case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
45     case SVGPaint::SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
46         return SVGColor::SVG_COLORTYPE_RGBCOLOR_ICCCOLOR;
47     case SVGPaint::SVG_PAINTTYPE_URI_CURRENTCOLOR:
48     case SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR:
49         return SVGColor::SVG_COLORTYPE_CURRENTCOLOR;
50     }
51
52     ASSERT_NOT_REACHED();
53     return SVGColor::SVG_COLORTYPE_UNKNOWN;
54 }
55
56 SVGPaint::SVGPaint(const SVGPaintType& paintType, const String& uri)
57     : SVGColor(SVGPaintClass, colorTypeForPaintType(paintType))
58     , m_paintType(paintType)
59     , m_uri(uri)
60 {
61 }
62
63 void SVGPaint::setUri(const String&)
64 {
65     // The whole SVGPaint interface is deprecated in SVG 1.1 (2nd edition).
66     // The setters are the most problematic part so we remove the support for those first.
67 }
68
69 void SVGPaint::setPaint(unsigned short, const String&, const String&, const String&, ExceptionCode& ec)
70 {
71     ec = NO_MODIFICATION_ALLOWED_ERR;
72 }
73
74 String SVGPaint::customCssText() const
75 {
76     switch (m_paintType) {
77     case SVG_PAINTTYPE_UNKNOWN:
78     case SVG_PAINTTYPE_RGBCOLOR:
79     case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
80     case SVG_PAINTTYPE_CURRENTCOLOR:
81         return SVGColor::customCssText();
82     case SVG_PAINTTYPE_NONE:
83         return "none";
84     case SVG_PAINTTYPE_URI_NONE:
85         return m_uri + " none";
86     case SVG_PAINTTYPE_URI_CURRENTCOLOR:
87     case SVG_PAINTTYPE_URI_RGBCOLOR:
88     case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: {
89         String color = SVGColor::customCssText();
90         if (color.isEmpty())
91             return m_uri;
92         return m_uri + ' ' + color;
93     }
94     case SVG_PAINTTYPE_URI:
95         return m_uri;
96     };
97
98     ASSERT_NOT_REACHED();
99     return String();
100 }
101
102 }
103
104 #endif // ENABLE(SVG)