#pragma once
#include "CSSFontFace.h"
#include "CSSPropertyNames.h"
#include "JSDOMPromise.h"
#include <wtf/WeakPtr.h>
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;
};
static ExceptionOr<Ref<FontFace>> create(JSC::ExecState&, Document&, const String& family, JSC::JSValue 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&);
String family() const;
String style() const;
String weight() const;
String stretch() const;
String unicodeRange() const;
String variant() const;
String featureSettings() const;
enum class LoadStatus { Unloaded, Loading, Loaded, Error };
LoadStatus status() const;
using Promise = DOMPromise<IDLInterface<FontFace>>;
std::optional<Promise>& promise() { return m_promise; }
void registerLoaded(Promise&&);
void adopt(CSSFontFace&);
void load();
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() const;
void ref() final { RefCounted::ref(); }
void deref() final { RefCounted::deref(); }
private:
explicit FontFace(CSSFontSelector&);
explicit FontFace(CSSFontFace&);
WeakPtrFactory<FontFace> m_weakPtrFactory;
Ref<CSSFontFace> m_backing;
std::optional<Promise> m_promise;
};
}