зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1028497 - Part 22: Make FontFace.load() work for unconnected FontFace objects. r=jdaggett
The same DoLoad() call works with both CSS-connected and unconnected FontFaces.
This commit is contained in:
Родитель
41fa46909a
Коммит
ef23ddf3cf
|
@ -478,11 +478,7 @@ FontFace::Load(ErrorResult& aRv)
|
|||
SetStatus(FontFaceLoadStatus::Loading);
|
||||
|
||||
if (mInitialized) {
|
||||
// XXX For FontFace objects not in the FontFaceSet, we will need a
|
||||
// way to create a user font entry.
|
||||
if (mUserFontEntry) {
|
||||
mUserFontEntry->Load();
|
||||
}
|
||||
DoLoad();
|
||||
} else {
|
||||
// We can only load an initialized font; this will cause the font to be
|
||||
// loaded once it has been initialized.
|
||||
|
@ -492,6 +488,28 @@ FontFace::Load(ErrorResult& aRv)
|
|||
return mLoaded;
|
||||
}
|
||||
|
||||
void
|
||||
FontFace::DoLoad()
|
||||
{
|
||||
MOZ_ASSERT(mInitialized);
|
||||
|
||||
if (!mUserFontEntry) {
|
||||
MOZ_ASSERT(!IsConnected(),
|
||||
"CSS-connected FontFace objects should already have a user font "
|
||||
"entry by the time Load() can be called on them");
|
||||
|
||||
nsRefPtr<gfxUserFontEntry> newEntry =
|
||||
mFontFaceSet->FindOrCreateUserFontEntryFromFontFace(this);
|
||||
if (!newEntry) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetUserFontEntry(newEntry);
|
||||
}
|
||||
|
||||
mUserFontEntry->Load();
|
||||
}
|
||||
|
||||
Promise*
|
||||
FontFace::GetLoaded(ErrorResult& aRv)
|
||||
{
|
||||
|
@ -637,6 +655,13 @@ FontFace::OnInitialized()
|
|||
|
||||
mInitialized = true;
|
||||
|
||||
// For a FontFace that was created and immediately had Load() called on
|
||||
// it, before it had a chance to be initialized, we kick off its load now.
|
||||
if (mLoadWhenInitialized) {
|
||||
mLoadWhenInitialized = false;
|
||||
DoLoad();
|
||||
}
|
||||
|
||||
if (mInFontFaceSet) {
|
||||
mFontFaceSet->OnFontFaceInitialized(this);
|
||||
}
|
||||
|
@ -696,8 +721,8 @@ FontFace::SetUserFontEntry(gfxUserFontEntry* aEntry)
|
|||
// new FontFace("ABC", "url(x)").load();
|
||||
//
|
||||
// where the SetUserFontEntry call (from the after-initialization
|
||||
// FontFaceSet::LoadFontFace call) comes after the author's call to
|
||||
// load(), which set mStatus to Loading.
|
||||
// DoLoad call) comes after the author's call to load(), which set mStatus
|
||||
// to Loading.
|
||||
FontFaceLoadStatus newStatus =
|
||||
LoadStateToStatus(mUserFontEntry->LoadState());
|
||||
if (newStatus > mStatus) {
|
||||
|
|
|
@ -155,6 +155,9 @@ private:
|
|||
*/
|
||||
void Initialize(FontFaceInitializer* aInitializer);
|
||||
|
||||
// Helper function for Load.
|
||||
void DoLoad();
|
||||
|
||||
/**
|
||||
* Parses a @font-face descriptor value, storing the result in aResult.
|
||||
* Returns whether the parsing was successful.
|
||||
|
|
|
@ -620,6 +620,20 @@ FontFaceSet::InsertConnectedFontFace(
|
|||
mUserFontSet->AddUserFontEntry(fontfamily, entry);
|
||||
}
|
||||
|
||||
already_AddRefed<gfxUserFontEntry>
|
||||
FontFaceSet::FindOrCreateUserFontEntryFromFontFace(FontFace* aFontFace)
|
||||
{
|
||||
nsAutoString fontfamily;
|
||||
if (!aFontFace->GetFamilyName(fontfamily)) {
|
||||
// If there is no family name, this rule cannot contribute a
|
||||
// usable font, so there is no point in processing it further.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return FindOrCreateUserFontEntryFromFontFace(fontfamily, aFontFace,
|
||||
nsStyleSet::eDocSheet);
|
||||
}
|
||||
|
||||
already_AddRefed<gfxUserFontEntry>
|
||||
FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsAString& aFamilyName,
|
||||
FontFace* aFontFace,
|
||||
|
|
|
@ -124,6 +124,13 @@ public:
|
|||
*/
|
||||
void RemoveUnavailableFontFace(FontFace* aFontFace);
|
||||
|
||||
/**
|
||||
* Finds an existing entry in the user font cache or creates a new user
|
||||
* font entry for the given FontFace object.
|
||||
*/
|
||||
already_AddRefed<gfxUserFontEntry>
|
||||
FindOrCreateUserFontEntryFromFontFace(FontFace* aFontFace);
|
||||
|
||||
/**
|
||||
* Notification method called by a FontFace once it has been initialized.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче