Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / 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 #include "core/svg/SVGPaint.h"
24
25 #include "bindings/v8/ExceptionMessages.h"
26 #include "bindings/v8/ExceptionState.h"
27
28 namespace WebCore {
29
30 static inline SVGColor::SVGColorType colorTypeForPaintType(const SVGPaint::SVGPaintType& paintType)
31 {
32     switch (paintType) {
33     case SVGPaint::SVG_PAINTTYPE_NONE:
34     case SVGPaint::SVG_PAINTTYPE_UNKNOWN:
35     case SVGPaint::SVG_PAINTTYPE_URI:
36     case SVGPaint::SVG_PAINTTYPE_URI_NONE:
37         return SVGColor::SVG_COLORTYPE_UNKNOWN;
38     case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR:
39     case SVGPaint::SVG_PAINTTYPE_RGBCOLOR:
40         return SVGColor::SVG_COLORTYPE_RGBCOLOR;
41     case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
42     case SVGPaint::SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
43         return SVGColor::SVG_COLORTYPE_RGBCOLOR_ICCCOLOR;
44     case SVGPaint::SVG_PAINTTYPE_URI_CURRENTCOLOR:
45     case SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR:
46         return SVGColor::SVG_COLORTYPE_CURRENTCOLOR;
47     }
48
49     ASSERT_NOT_REACHED();
50     return SVGColor::SVG_COLORTYPE_UNKNOWN;
51 }
52
53 SVGPaint::SVGPaint(const SVGPaintType& paintType, const String& uri)
54     : SVGColor(SVGPaintClass, colorTypeForPaintType(paintType))
55     , m_paintType(paintType)
56     , m_uri(uri)
57 {
58 }
59
60 void SVGPaint::setUri(const String&)
61 {
62     // The whole SVGPaint interface is deprecated in SVG 1.1 (2nd edition).
63     // The setters are the most problematic part so we remove the support for those first.
64 }
65
66 void SVGPaint::setPaint(unsigned short, const String&, const String&, const String&, ExceptionState& exceptionState)
67 {
68     exceptionState.throwDOMException(NoModificationAllowedError, ExceptionMessages::readOnly());
69 }
70
71 String SVGPaint::customCSSText() const
72 {
73     switch (m_paintType) {
74     case SVG_PAINTTYPE_UNKNOWN:
75         return String();
76     case SVG_PAINTTYPE_RGBCOLOR:
77     case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
78     case SVG_PAINTTYPE_CURRENTCOLOR:
79         return SVGColor::customCSSText();
80     case SVG_PAINTTYPE_NONE:
81         return "none";
82     case SVG_PAINTTYPE_URI_NONE:
83         return m_uri + " none";
84     case SVG_PAINTTYPE_URI_CURRENTCOLOR:
85     case SVG_PAINTTYPE_URI_RGBCOLOR:
86     case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: {
87         String color = SVGColor::customCSSText();
88         if (color.isEmpty())
89             return m_uri;
90         return "url(" + m_uri + ") " + color;
91     }
92     case SVG_PAINTTYPE_URI:
93         return "url(" + m_uri + ')';
94     };
95
96     ASSERT_NOT_REACHED();
97     return String();
98 }
99
100 SVGPaint::SVGPaint(const SVGPaint& cloneFrom)
101     : SVGColor(SVGPaintClass, cloneFrom)
102     , m_paintType(cloneFrom.m_paintType)
103     , m_uri(cloneFrom.m_uri)
104 {
105 }
106
107 PassRefPtrWillBeRawPtr<SVGPaint> SVGPaint::cloneForCSSOM() const
108 {
109     return adoptRefCountedWillBeRefCountedGarbageCollected(new SVGPaint(*this));
110 }
111
112 bool SVGPaint::equals(const SVGPaint& other) const
113 {
114     return m_paintType == other.m_paintType && m_uri == other.m_uri && SVGColor::equals(other);
115 }
116
117 }