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 #include "config.h"
23 #include "core/svg/SVGColor.h"
24
25 #include "bindings/v8/ExceptionState.h"
26 #include "core/css/CSSParser.h"
27 #include "core/css/RGBColor.h"
28
29 namespace WebCore {
30
SVGColor(const SVGColorType & colorType)31 SVGColor::SVGColor(const SVGColorType& colorType)
32 : CSSValue(SVGColorClass)
33 , m_colorType(colorType)
34 {
35 }
36
SVGColor(ClassType classType,const SVGColorType & colorType)37 SVGColor::SVGColor(ClassType classType, const SVGColorType& colorType)
38 : CSSValue(classType)
39 , m_colorType(colorType)
40 {
41 }
42
rgbColor() const43 PassRefPtr<RGBColor> SVGColor::rgbColor() const
44 {
45 return RGBColor::create(m_color.rgb());
46 }
47
colorFromRGBColorString(const String & colorString)48 Color SVGColor::colorFromRGBColorString(const String& colorString)
49 {
50 // FIXME: Rework css parser so it is more SVG aware.
51 RGBA32 color;
52 if (CSSParser::parseColor(color, colorString.stripWhiteSpace()))
53 return color;
54 return Color();
55 }
56
setRGBColor(const String &,ExceptionState & exceptionState)57 void SVGColor::setRGBColor(const String&, ExceptionState& exceptionState)
58 {
59 // The whole SVGColor interface is deprecated in SVG 1.1 (2nd edition).
60 // The setters are the most problematic part so we remove the support for those first.
61 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAllowedError);
62 }
63
setRGBColorICCColor(const String &,const String &,ExceptionState & exceptionState)64 void SVGColor::setRGBColorICCColor(const String&, const String&, ExceptionState& exceptionState)
65 {
66 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAllowedError);
67 }
68
setColor(unsigned short,const String &,const String &,ExceptionState & exceptionState)69 void SVGColor::setColor(unsigned short, const String&, const String&, ExceptionState& exceptionState)
70 {
71 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAllowedError);
72 }
73
customCSSText() const74 String SVGColor::customCSSText() const
75 {
76 switch (m_colorType) {
77 case SVG_COLORTYPE_UNKNOWN:
78 return String();
79 case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
80 case SVG_COLORTYPE_RGBCOLOR:
81 // FIXME: No ICC color support.
82 return m_color.serialized();
83 case SVG_COLORTYPE_CURRENTCOLOR:
84 if (m_color.isValid())
85 return m_color.serialized();
86 return "currentColor";
87 }
88
89 ASSERT_NOT_REACHED();
90 return String();
91 }
92
SVGColor(ClassType classType,const SVGColor & cloneFrom)93 SVGColor::SVGColor(ClassType classType, const SVGColor& cloneFrom)
94 : CSSValue(classType, /*isCSSOMSafe*/ true)
95 , m_color(cloneFrom.m_color)
96 , m_colorType(cloneFrom.m_colorType)
97 {
98 }
99
cloneForCSSOM() const100 PassRefPtr<SVGColor> SVGColor::cloneForCSSOM() const
101 {
102 return adoptRef(new SVGColor(SVGColorClass, *this));
103 }
104
equals(const SVGColor & other) const105 bool SVGColor::equals(const SVGColor& other) const
106 {
107 return m_colorType == other.m_colorType && m_color == other.m_color;
108 }
109
110 }
111