#ifndef ShapeValue_h
#define ShapeValue_h
#include "core/fetch/ImageResource.h"
#include "core/rendering/style/BasicShapes.h"
#include "core/rendering/style/RenderStyleConstants.h"
#include "core/rendering/style/StyleImage.h"
#include "wtf/PassRefPtr.h"
namespace WebCore {
class ShapeValue : public RefCounted<ShapeValue> {
public:
enum ShapeValueType {
Shape,
Box,
Outside,
Image
};
static PassRefPtr<ShapeValue> createShapeValue(PassRefPtr<BasicShape> shape, CSSBoxType cssBox)
{
return adoptRef(new ShapeValue(shape, cssBox));
}
static PassRefPtr<ShapeValue> createOutsideValue()
{
return adoptRef(new ShapeValue(Outside));
}
static PassRefPtr<ShapeValue> createBoxShapeValue(CSSBoxType cssBox)
{
return adoptRef(new ShapeValue(cssBox));
}
static PassRefPtr<ShapeValue> createImageValue(PassRefPtr<StyleImage> image)
{
return adoptRef(new ShapeValue(image));
}
ShapeValueType type() const { return m_type; }
BasicShape* shape() const { return m_shape.get(); }
StyleImage* image() const { return m_image.get(); }
bool isImageValid() const { return image() && image()->cachedImage() && image()->cachedImage()->hasImage(); }
void setImage(PassRefPtr<StyleImage> image)
{
ASSERT(type() == Image);
if (m_image != image)
m_image = image;
}
CSSBoxType cssBox() const { return m_cssBox; }
bool operator==(const ShapeValue& other) const;
private:
ShapeValue(PassRefPtr<BasicShape> shape, CSSBoxType cssBox)
: m_type(Shape)
, m_shape(shape)
, m_cssBox(cssBox)
{
}
ShapeValue(ShapeValueType type)
: m_type(type)
, m_cssBox(BoxMissing)
{
}
ShapeValue(PassRefPtr<StyleImage> image)
: m_type(Image)
, m_image(image)
, m_cssBox(ContentBox)
{
}
ShapeValue(CSSBoxType cssBox)
: m_type(Box)
, m_cssBox(cssBox)
{
}
ShapeValueType m_type;
RefPtr<BasicShape> m_shape;
RefPtr<StyleImage> m_image;
CSSBoxType m_cssBox;
};
inline bool ShapeValue::operator==(const ShapeValue& other) const
{
if (type() != other.type())
return false;
switch (type()) {
case Shape:
return shape() == other.shape() && cssBox() == other.cssBox();
case Box:
return cssBox() == other.cssBox();
case Outside:
return true;
case Image:
return image() == other.image();
}
ASSERT_NOT_REACHED();
return false;
}
}
#endif