CSSImageSetValue.h [plain text]
#pragma once
#include "CSSValueList.h"
#include "CachedResourceHandle.h"
#include <wtf/Function.h>
namespace WebCore {
class CachedImage;
class CachedResourceLoader;
class Document;
struct ResourceLoaderOptions;
class CSSImageSetValue final : public CSSValueList {
public:
static Ref<CSSImageSetValue> create()
{
return adoptRef(*new CSSImageSetValue());
}
~CSSImageSetValue();
std::pair<CachedImage*, float> loadBestFitImage(CachedResourceLoader&, const ResourceLoaderOptions&);
CachedImage* cachedImage() const { return m_cachedImage.get(); }
String customCSSText() const;
struct ImageWithScale {
URL imageURL;
float scaleFactor;
};
bool traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const;
void updateDeviceScaleFactor(const Document&);
URL bestImageForScaleFactorURL() { return bestImageForScaleFactor().imageURL; }
protected:
ImageWithScale bestImageForScaleFactor();
private:
CSSImageSetValue();
void fillImageSet();
static inline bool compareByScaleFactor(ImageWithScale first, ImageWithScale second) { return first.scaleFactor < second.scaleFactor; }
CachedResourceHandle<CachedImage> m_cachedImage;
bool m_accessedBestFitImage { false };
float m_bestFitImageScaleFactor { 1 };
float m_deviceScaleFactor { 1 };
Vector<ImageWithScale> m_imagesInSet;
};
}
SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSImageSetValue, isImageSetValue())