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.
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.
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.
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.
23 #include "core/svg/SVGPaint.h"
25 #include "bindings/v8/ExceptionMessages.h"
26 #include "bindings/v8/ExceptionState.h"
27 #include "core/css/RGBColor.h"
28 #include "core/css/parser/BisonCSSParser.h"
32 SVGPaint::SVGPaint(const SVGPaintType& paintType, const String& uri)
33 : CSSValue(SVGPaintClass)
34 , m_paintType(paintType)
39 String SVGPaint::customCSSText() const
41 switch (m_paintType) {
42 case SVG_PAINTTYPE_UNKNOWN:
44 case SVG_PAINTTYPE_RGBCOLOR:
45 case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
46 return m_color.serializedAsCSSComponentValue();
47 case SVG_PAINTTYPE_CURRENTCOLOR:
48 return "currentColor";
49 case SVG_PAINTTYPE_NONE:
51 case SVG_PAINTTYPE_URI_NONE:
52 return m_uri + " none";
53 case SVG_PAINTTYPE_URI_CURRENTCOLOR:
54 return "url(" + m_uri + ") currentColor";
55 case SVG_PAINTTYPE_URI_RGBCOLOR:
56 case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: {
57 return "url(" + m_uri + ") " + m_color.serializedAsCSSComponentValue();
59 case SVG_PAINTTYPE_URI:
60 return "url(" + m_uri + ')';
67 SVGPaint::SVGPaint(const SVGPaint& cloneFrom)
68 : CSSValue(SVGPaintClass, /*isCSSOMSafe*/ true)
69 , m_paintType(cloneFrom.m_paintType)
70 , m_color(cloneFrom.m_color)
71 , m_uri(cloneFrom.m_uri)
75 PassRefPtrWillBeRawPtr<SVGPaint> SVGPaint::cloneForCSSOM() const
77 return adoptRefWillBeNoop(new SVGPaint(*this));
80 bool SVGPaint::equals(const SVGPaint& other) const
82 return m_paintType == other.m_paintType && m_uri == other.m_uri && m_color == other.m_color;
85 StyleColor SVGPaint::colorFromRGBColorString(const String& colorString)
87 // FIXME: Rework css parser so it is more SVG aware.
89 if (BisonCSSParser::parseColor(color, colorString.stripWhiteSpace()))
90 return StyleColor(color);
91 // FIXME: This branch catches the string currentColor, but we should error if we have an illegal color value.
92 return StyleColor::currentColor();