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