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.
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.
25 #include "core/css/CSSValue.h"
26 #include "core/css/StyleColor.h"
27 #include "platform/graphics/Color.h"
28 #include "wtf/PassRefPtr.h"
35 class SVGColor : public CSSValue {
38 SVG_COLORTYPE_UNKNOWN = 0,
39 SVG_COLORTYPE_RGBCOLOR = 1,
40 SVG_COLORTYPE_RGBCOLOR_ICCCOLOR = 2,
41 SVG_COLORTYPE_CURRENTCOLOR = 3
44 static PassRefPtrWillBeRawPtr<SVGColor> createFromString(const String& rgbColor)
46 RefPtrWillBeRawPtr<SVGColor> color = adoptRefCountedWillBeRefCountedGarbageCollected(new SVGColor(SVG_COLORTYPE_RGBCOLOR));
47 StyleColor styleColor = colorFromRGBColorString(rgbColor);
48 ASSERT(!styleColor.isCurrentColor());
49 color->setColor(styleColor.color());
50 return color.release();
53 static PassRefPtrWillBeRawPtr<SVGColor> createFromColor(const Color& rgbColor)
55 RefPtrWillBeRawPtr<SVGColor> color = adoptRefCountedWillBeRefCountedGarbageCollected(new SVGColor(SVG_COLORTYPE_RGBCOLOR));
56 color->setColor(rgbColor);
57 return color.release();
60 static PassRefPtrWillBeRawPtr<SVGColor> createCurrentColor()
62 return adoptRefCountedWillBeRefCountedGarbageCollected(new SVGColor(SVG_COLORTYPE_CURRENTCOLOR));
65 const Color& color() const { return m_color; }
66 const SVGColorType& colorType() const { return m_colorType; }
67 PassRefPtr<RGBColor> rgbColor() const;
69 static StyleColor colorFromRGBColorString(const String&);
71 void setRGBColor(const String& rgbColor, ExceptionState&);
72 void setRGBColorICCColor(const String& rgbColor, const String& iccColor, ExceptionState&);
73 void setColor(unsigned short colorType, const String& rgbColor, const String& iccColor, ExceptionState&);
75 String customCSSText() const;
79 PassRefPtrWillBeRawPtr<SVGColor> cloneForCSSOM() const;
81 bool equals(const SVGColor&) const;
83 void traceAfterDispatch(Visitor* visitor) { CSSValue::traceAfterDispatch(visitor); }
86 friend class CSSComputedStyleDeclaration;
88 SVGColor(ClassType, const SVGColorType&);
89 SVGColor(ClassType, const SVGColor& cloneFrom);
91 void setColor(const Color& color)
94 setColorType(SVG_COLORTYPE_RGBCOLOR);
96 void setColorType(const SVGColorType& type) { m_colorType = type; }
99 SVGColor(const SVGColorType&);
102 SVGColorType m_colorType;
105 DEFINE_CSS_VALUE_TYPE_CASTS(SVGColor, isSVGColor());
107 } // namespace WebCore