Bug 1028497 - Part 12: Implement FontFace.loaded. r=jdaggett,bzbarsky

This commit is contained in:
Cameron McCormack 2014-10-02 12:32:07 +10:00
Родитель dda44dce90
Коммит 45d38e257f
3 изменённых файлов: 47 добавлений и 7 удалений

Просмотреть файл

@ -40,7 +40,9 @@ interface FontFace {
readonly attribute FontFaceLoadStatus status;
[Throws]
Promise<FontFace> load();
[Throws]
readonly attribute Promise<FontFace> loaded;
};

Просмотреть файл

@ -35,6 +35,13 @@ FontFace::FontFace(nsISupports* aParent, nsPresContext* aPresContext)
MOZ_ASSERT(mPresContext);
SetIsDOMBinding();
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aParent);
if (global) {
ErrorResult rv;
mLoaded = Promise::Create(global, rv);
}
}
FontFace::~FontFace()
@ -71,9 +78,11 @@ FontFace::CreateForRule(nsISupports* aGlobal,
nsCSSFontFaceRule* aRule,
gfxUserFontEntry* aUserFontEntry)
{
nsCOMPtr<nsIGlobalObject> globalObject = do_QueryInterface(aGlobal);
nsRefPtr<FontFace> obj = new FontFace(aGlobal, aPresContext);
obj->mRule = aRule;
obj->mStatus = LoadStateToStatus(aUserFontEntry->LoadState());
obj->SetStatus(LoadStateToStatus(aUserFontEntry->LoadState()));
return obj.forget();
}
@ -235,21 +244,48 @@ FontFace::Status()
}
Promise*
FontFace::Load()
FontFace::Load(ErrorResult& aRv)
{
return Loaded();
if (!mLoaded) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
return mLoaded;
}
Promise*
FontFace::Loaded()
FontFace::GetLoaded(ErrorResult& aRv)
{
return nullptr;
mPresContext->FlushUserFontSet();
if (!mLoaded) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
return mLoaded;
}
void
FontFace::SetStatus(FontFaceLoadStatus aStatus)
{
if (mStatus == aStatus) {
return;
}
mStatus = aStatus;
if (!mLoaded) {
return;
}
if (mStatus == FontFaceLoadStatus::Loaded) {
mLoaded->MaybeResolve(this);
} else if (mStatus == FontFaceLoadStatus::Error) {
// XXX Use NS_ERROR_DOM_SYNTAX_ERR for array buffer backed FontFaces.
mLoaded->MaybeReject(NS_ERROR_DOM_NETWORK_ERR);
}
}
bool

Просмотреть файл

@ -91,8 +91,8 @@ public:
void SetFeatureSettings(const nsAString& aValue, mozilla::ErrorResult& aRv);
mozilla::dom::FontFaceLoadStatus Status();
mozilla::dom::Promise* Load();
mozilla::dom::Promise* Loaded();
mozilla::dom::Promise* Load(mozilla::ErrorResult& aRv);
mozilla::dom::Promise* GetLoaded(mozilla::ErrorResult& aRv);
private:
FontFace(nsISupports* aParent, nsPresContext* aPresContext);
@ -123,6 +123,8 @@ private:
nsCOMPtr<nsISupports> mParent;
nsPresContext* mPresContext;
// A Promise that is fulfilled once the font represented by this FontFace
// is loaded, and is rejected if the load fails.
nsRefPtr<mozilla::dom::Promise> mLoaded;
// The @font-face rule this FontFace object is reflecting, if it is a