#pragma once
#include "CSSFontFace.h"
#include "CSSPropertyNames.h"
#include "DOMPromiseProxy.h"
#include <wtf/Variant.h>
#include <wtf/WeakPtr.h>
namespace JSC {
class ArrayBuffer;
class ArrayBufferView;
}
namespace WebCore {
class FontFace final : public RefCounted<FontFace>, private CSSFontFace::Client {
public:
struct Descriptors {
String style;
String weight;
String stretch;
String unicodeRange;
String variant;
String featureSettings;
String display;
};
using Source = Variant<String, RefPtr<JSC::ArrayBuffer>, RefPtr<JSC::ArrayBufferView>>;
static ExceptionOr<Ref<FontFace>> create(Document&, const String& family, Source&&, const Descriptors&);
static Ref<FontFace> create(CSSFontFace&);
virtual ~FontFace();
ExceptionOr<void> setFamily(const String&);
ExceptionOr<void> setStyle(const String&);
ExceptionOr<void> setWeight(const String&);
ExceptionOr<void> setStretch(const String&);
ExceptionOr<void> setUnicodeRange(const String&);
ExceptionOr<void> setVariant(const String&);
ExceptionOr<void> setFeatureSettings(const String&);
ExceptionOr<void> setDisplay(const String&);
String family() const;
String style() const;
String weight() const;
String stretch() const;
String unicodeRange() const;
String variant() const;
String featureSettings() const;
String display() const;
enum class LoadStatus { Unloaded, Loading, Loaded, Error };
LoadStatus status() const;
using LoadedPromise = DOMPromiseProxyWithResolveCallback<IDLInterface<FontFace>>;
LoadedPromise& loaded() { return m_loadedPromise; }
LoadedPromise& load();
void adopt(CSSFontFace&);
CSSFontFace& backing() { return m_backing; }
static RefPtr<CSSValue> parseString(const String&, CSSPropertyID);
void fontStateChanged(CSSFontFace&, CSSFontFace::Status oldState, CSSFontFace::Status newState) final;
WeakPtr<FontFace> createWeakPtr();
void ref() final { RefCounted::ref(); }
void deref() final { RefCounted::deref(); }
private:
explicit FontFace(CSSFontSelector&);
explicit FontFace(CSSFontFace&);
FontFace& loadedPromiseResolve();
WeakPtrFactory<FontFace> m_weakPtrFactory;
Ref<CSSFontFace> m_backing;
LoadedPromise m_loadedPromise;
};
}