#ifndef StyleImage_h
#define StyleImage_h
#include "core/css/CSSValue.h"
#include "platform/geometry/IntSize.h"
#include "platform/geometry/LayoutSize.h"
#include "platform/graphics/Image.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
namespace WebCore {
class ImageResource;
class CSSValue;
class RenderObject;
typedef void* WrappedImagePtr;
class StyleImage : public RefCounted<StyleImage> {
public:
virtual ~StyleImage() { }
bool operator==(const StyleImage& other) const
{
return data() == other.data();
}
virtual PassRefPtrWillBeRawPtr<CSSValue> cssValue() const = 0;
virtual bool canRender(const RenderObject*, float ) const { return true; }
virtual bool isLoaded() const { return true; }
virtual bool errorOccurred() const { return false; }
virtual LayoutSize imageSize(const RenderObject*, float multiplier) const = 0;
virtual void computeIntrinsicDimensions(const RenderObject*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio) = 0;
virtual bool imageHasRelativeWidth() const = 0;
virtual bool imageHasRelativeHeight() const = 0;
virtual bool usesImageContainerSize() const = 0;
virtual void setContainerSizeForRenderer(const RenderObject*, const IntSize&, float) = 0;
virtual void addClient(RenderObject*) = 0;
virtual void removeClient(RenderObject*) = 0;
virtual PassRefPtr<Image> image(RenderObject*, const IntSize&) const = 0;
virtual WrappedImagePtr data() const = 0;
virtual float imageScaleFactor() const { return 1; }
virtual bool knownToBeOpaque(const RenderObject*) const = 0;
virtual ImageResource* cachedImage() const { return 0; }
ALWAYS_INLINE bool isImageResource() const { return m_isImageResource; }
ALWAYS_INLINE bool isPendingImage() const { return m_isPendingImage; }
ALWAYS_INLINE bool isGeneratedImage() const { return m_isGeneratedImage; }
ALWAYS_INLINE bool isImageResourceSet() const { return m_isImageResourceSet; }
static bool imagesEquivalent(const StyleImage* image1, const StyleImage* image2)
{
if (image1 != image2) {
if (!image1 || !image2)
return false;
return *image1 == *image2;
}
return true;
}
protected:
StyleImage()
: m_isImageResource(false)
, m_isPendingImage(false)
, m_isGeneratedImage(false)
, m_isImageResourceSet(false)
{
}
bool m_isImageResource:1;
bool m_isPendingImage:1;
bool m_isGeneratedImage:1;
bool m_isImageResourceSet:1;
};
#define DEFINE_STYLE_IMAGE_TYPE_CASTS(thisType, function) \
DEFINE_TYPE_CASTS(thisType, StyleImage, styleImage, styleImage->function, styleImage.function); \
inline thisType* to##thisType(const RefPtr<StyleImage>& styleImage) { return to##thisType(styleImage.get()); } \
typedef int NeedsSemiColonAfterDefineStyleImageTypeCasts
}
#endif