From 21a470ab25137d2e4ea25f1849d5d6b5bb2cc986 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Thu, 2 Oct 2014 12:32:07 +1000 Subject: [PATCH] Bug 1028497 - Part 13: Implement FontFace.load(). r=jdaggett --- layout/style/FontFace.cpp | 13 +++++++++++++ layout/style/FontFaceSet.cpp | 11 +++++++++++ layout/style/FontFaceSet.h | 6 ++++++ 3 files changed, 30 insertions(+) diff --git a/layout/style/FontFace.cpp b/layout/style/FontFace.cpp index 97d1dec7d2a..f6bfe9d05ed 100644 --- a/layout/style/FontFace.cpp +++ b/layout/style/FontFace.cpp @@ -246,11 +246,24 @@ FontFace::Status() Promise* FontFace::Load(ErrorResult& aRv) { + mPresContext->FlushUserFontSet(); + if (!mLoaded) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } + if (mStatus != FontFaceLoadStatus::Unloaded) { + return mLoaded; + } + + SetStatus(FontFaceLoadStatus::Loading); + + gfxUserFontEntry* entry = + mPresContext->Fonts()->FindUserFontEntryForFontFace(this); + if (entry) { + entry->Load(); + } return mLoaded; } diff --git a/layout/style/FontFaceSet.cpp b/layout/style/FontFaceSet.cpp index 94bed87fd92..8ceea6bc901 100644 --- a/layout/style/FontFaceSet.cpp +++ b/layout/style/FontFaceSet.cpp @@ -701,6 +701,17 @@ FontFaceSet::FindUserFontEntryForRule(nsCSSFontFaceRule* aRule) return nullptr; } +gfxUserFontEntry* +FontFaceSet::FindUserFontEntryForFontFace(FontFace* aFontFace) +{ + for (size_t i = 0; i < mRules.Length(); i++) { + if (mRules[i].mContainer.mRule->GetFontFace() == aFontFace) { + return mRules[i].mUserFontEntry; + } + } + return nullptr; +} + nsresult FontFaceSet::LogMessage(gfxUserFontEntry* aUserFontEntry, const char* aMessage, diff --git a/layout/style/FontFaceSet.h b/layout/style/FontFaceSet.h index 9977bb42b0c..39614a29e2b 100644 --- a/layout/style/FontFaceSet.h +++ b/layout/style/FontFaceSet.h @@ -118,6 +118,12 @@ public: */ FontFace* FindFontFaceForEntry(gfxUserFontEntry* aUserFontEntry); + /** + * Looks up the corresponding user font entry for the given FontFace object. + * Returns null if there was none. + */ + gfxUserFontEntry* FindUserFontEntryForFontFace(FontFace* aFontFace); + // -- Web IDL -------------------------------------------------------------- IMPL_EVENT_HANDLER(loading)