CSSImageGeneratorValue.h [plain text]
#ifndef CSSImageGeneratorValue_h
#define CSSImageGeneratorValue_h
#include "CSSValue.h"
#include "FloatSize.h"
#include "FloatSizeHash.h"
#include "Timer.h"
#include <wtf/HashCountedSet.h>
namespace WebCore {
class CachedImage;
class CachedResourceLoader;
class GeneratedImage;
class Image;
class RenderElement;
class StyleResolver;
struct ResourceLoaderOptions;
class CSSImageGeneratorValue : public CSSValue {
public:
~CSSImageGeneratorValue();
void addClient(RenderElement*);
void removeClient(RenderElement*);
PassRefPtr<Image> image(RenderElement*, const FloatSize&);
bool isFixedSize() const;
FloatSize fixedSize(const RenderElement*);
bool isPending() const;
bool knownToBeOpaque(const RenderElement*) const;
void loadSubimages(CachedResourceLoader*, const ResourceLoaderOptions&);
protected:
CSSImageGeneratorValue(ClassType);
GeneratedImage* cachedImageForSize(FloatSize);
void saveCachedImageForSize(FloatSize, PassRefPtr<GeneratedImage>);
const HashCountedSet<RenderElement*>& clients() const { return m_clients; }
static CachedImage* cachedImageForCSSValue(CSSValue*, CachedResourceLoader*, const ResourceLoaderOptions&);
static bool subimageIsPending(CSSValue*);
private:
class CachedGeneratedImage {
public:
CachedGeneratedImage(CSSImageGeneratorValue&, FloatSize, PassRefPtr<GeneratedImage>);
GeneratedImage* image() { return m_image.get(); }
void puntEvictionTimer() { m_evictionTimer.restart(); }
private:
void evictionTimerFired();
CSSImageGeneratorValue& m_owner;
FloatSize m_size;
RefPtr<GeneratedImage> m_image;
DeferrableOneShotTimer m_evictionTimer;
};
friend class CachedGeneratedImage;
void evictCachedGeneratedImage(FloatSize);
HashCountedSet<RenderElement*> m_clients;
HashMap<FloatSize, std::unique_ptr<CachedGeneratedImage>> m_images;
};
CSS_VALUE_TYPE_CASTS(CSSImageGeneratorValue, isImageGeneratorValue())
}
#endif // CSSImageGeneratorValue_h