#include "config.h"
#include "SVGPaint.h"
#include "SVGException.h"
#include "SVGURIReference.h"
#include <wtf/text/WTFString.h>
namespace WebCore {
static inline SVGColor::SVGColorType colorTypeForPaintType(const SVGPaint::SVGPaintType& paintType)
{
switch (paintType) {
case SVGPaint::SVG_PAINTTYPE_NONE:
case SVGPaint::SVG_PAINTTYPE_UNKNOWN:
case SVGPaint::SVG_PAINTTYPE_URI:
case SVGPaint::SVG_PAINTTYPE_URI_NONE:
return SVGColor::SVG_COLORTYPE_UNKNOWN;
case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR:
case SVGPaint::SVG_PAINTTYPE_RGBCOLOR:
return SVGColor::SVG_COLORTYPE_RGBCOLOR;
case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
case SVGPaint::SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
return SVGColor::SVG_COLORTYPE_RGBCOLOR_ICCCOLOR;
case SVGPaint::SVG_PAINTTYPE_URI_CURRENTCOLOR:
case SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR:
return SVGColor::SVG_COLORTYPE_CURRENTCOLOR;
}
ASSERT_NOT_REACHED();
return SVGColor::SVG_COLORTYPE_UNKNOWN;
}
SVGPaint::SVGPaint(const SVGPaintType& paintType, const String& uri)
: SVGColor(SVGPaintClass, colorTypeForPaintType(paintType))
, m_paintType(paintType)
, m_uri(uri)
{
}
void SVGPaint::setUri(const String&)
{
}
void SVGPaint::setPaint(unsigned short, const String&, const String&, const String&, ExceptionCode& ec)
{
ec = NO_MODIFICATION_ALLOWED_ERR;
}
String SVGPaint::customCSSText() const
{
switch (m_paintType) {
case SVG_PAINTTYPE_UNKNOWN:
case SVG_PAINTTYPE_RGBCOLOR:
case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
case SVG_PAINTTYPE_CURRENTCOLOR:
return SVGColor::customCSSText();
case SVG_PAINTTYPE_NONE:
return "none";
case SVG_PAINTTYPE_URI_NONE:
return m_uri + " none";
case SVG_PAINTTYPE_URI_CURRENTCOLOR:
case SVG_PAINTTYPE_URI_RGBCOLOR:
case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: {
String color = SVGColor::customCSSText();
if (color.isEmpty())
return m_uri;
return "url(" + m_uri + ") " + color;
}
case SVG_PAINTTYPE_URI:
return "url(" + m_uri + ')';
};
ASSERT_NOT_REACHED();
return String();
}
SVGPaint::SVGPaint(const SVGPaint& cloneFrom)
: SVGColor(SVGPaintClass, cloneFrom)
, m_paintType(cloneFrom.m_paintType)
, m_uri(cloneFrom.m_uri)
{
}
PassRefPtr<SVGPaint> SVGPaint::cloneForCSSOM() const
{
return adoptRef(new SVGPaint(*this));
}
bool SVGPaint::equals(const SVGPaint& other) const
{
return m_paintType == other.m_paintType && m_uri == other.m_uri && SVGColor::equals(other);
}
}