#ifndef CSSCanvasValue_h
#define CSSCanvasValue_h
#include "core/css/CSSImageGeneratorValue.h"
#include "core/html/HTMLCanvasElement.h"
namespace WebCore {
class Document;
class CSSCanvasValue : public CSSImageGeneratorValue {
public:
static PassRefPtrWillBeRawPtr<CSSCanvasValue> create(const String& name)
{
return adoptRefWillBeRefCountedGarbageCollected(new CSSCanvasValue(name));
}
~CSSCanvasValue();
String customCSSText() const;
PassRefPtr<Image> image(RenderObject*, const IntSize&);
bool isFixedSize() const { return true; }
IntSize fixedSize(const RenderObject*);
bool isPending() const { return false; }
void loadSubimages(ResourceFetcher*) { }
bool equals(const CSSCanvasValue&) const;
void traceAfterDispatch(Visitor* visitor) { CSSImageGeneratorValue::traceAfterDispatch(visitor); }
private:
explicit CSSCanvasValue(const String& name)
: CSSImageGeneratorValue(CanvasClass)
, m_canvasObserver(this)
, m_name(name)
, m_element(0)
{
}
class CanvasObserverProxy FINAL : public CanvasObserver {
public:
CanvasObserverProxy(CSSCanvasValue* ownerValue) : m_ownerValue(ownerValue) { }
virtual ~CanvasObserverProxy() { }
virtual void canvasChanged(HTMLCanvasElement* canvas, const FloatRect& changedRect) OVERRIDE
{
m_ownerValue->canvasChanged(canvas, changedRect);
}
virtual void canvasResized(HTMLCanvasElement* canvas) OVERRIDE
{
m_ownerValue->canvasResized(canvas);
}
virtual void canvasDestroyed(HTMLCanvasElement* canvas) OVERRIDE
{
m_ownerValue->canvasDestroyed(canvas);
}
private:
CSSCanvasValue* m_ownerValue;
};
void canvasChanged(HTMLCanvasElement*, const FloatRect& changedRect);
void canvasResized(HTMLCanvasElement*);
void canvasDestroyed(HTMLCanvasElement*);
HTMLCanvasElement* element(Document*);
CanvasObserverProxy m_canvasObserver;
String m_name;
HTMLCanvasElement* m_element;
};
DEFINE_CSS_VALUE_TYPE_CASTS(CSSCanvasValue, isCanvasValue());
}
#endif