#pragma once
#include "CSSImageGeneratorValue.h"
#include "HTMLCanvasElement.h"
namespace WebCore {
class Document;
class HTMLCanvasElement;
class CSSCanvasValue : public CSSImageGeneratorValue {
public:
static Ref<CSSCanvasValue> create(const String& name) { return adoptRef(*new CSSCanvasValue(name)); }
~CSSCanvasValue();
String customCSSText() const;
RefPtr<Image> image(RenderElement*, const FloatSize&);
bool isFixedSize() const { return true; }
FloatSize fixedSize(const RenderElement*);
bool isPending() const { return false; }
void loadSubimages(CachedResourceLoader&, const ResourceLoaderOptions&) { }
bool equals(const CSSCanvasValue&) const;
private:
explicit CSSCanvasValue(const String& name)
: CSSImageGeneratorValue(CanvasClass)
, m_canvasObserver(*this)
, m_name(name)
{
}
class CanvasObserverProxy final : public CanvasObserver {
public:
explicit CanvasObserverProxy(CSSCanvasValue& ownerValue)
: m_ownerValue(ownerValue)
{
}
virtual ~CanvasObserverProxy()
{
}
private:
void canvasChanged(HTMLCanvasElement& canvas, const FloatRect& changedRect) override
{
m_ownerValue.canvasChanged(canvas, changedRect);
}
void canvasResized(HTMLCanvasElement& canvas) override
{
m_ownerValue.canvasResized(canvas);
}
void canvasDestroyed(HTMLCanvasElement& canvas) override
{
m_ownerValue.canvasDestroyed(canvas);
}
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 { nullptr };
};
}
SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSCanvasValue, isCanvasValue())