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