Bug 1028497 - Part 6: Have a FontFace::Entry class extending gfxUserFontEntry that can inform the FontFaceSet about loading. r=jdaggett

We can't make FontFace inherit from gfxUserFontEntry, since the former
is cycle collected.  So instead, we have a small class that inherits
from it that will override its virtual methods and forward things on to
the FontFace object.

We make gfxUserFontSet::CreateFontFace virtual so we can override it to
produce instances of our gfxUserFontEntry subclass.
This commit is contained in:
Cameron McCormack 2014-10-02 12:32:06 +10:00
parent 0da9bd2766
commit 550275b747
5 changed files with 46 additions and 5 deletions

View File

@ -126,6 +126,8 @@ gfxUserFontEntry::gfxUserFontEntry(gfxUserFontSet* aFontSet,
mLoader(nullptr),
mFontSet(aFontSet)
{
MOZ_ASSERT(aWeight != 0,
"aWeight must not be 0; use NS_FONT_WEIGHT_NORMAL instead");
mIsUserFontContainer = true;
mSrcList = aFontFaceSrcList;
mSrcIndex = 0;
@ -727,8 +729,6 @@ gfxUserFontSet::CreateFontFace(const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
uint32_t aLanguageOverride,
gfxSparseBitSet* aUnicodeRanges)
{
MOZ_ASSERT(aWeight != 0,
"aWeight must not be 0; use NS_FONT_WEIGHT_NORMAL instead");
nsRefPtr<gfxUserFontEntry> userFontEntry =
new gfxUserFontEntry(this, aFontFaceSrcList, aWeight,

View File

@ -154,14 +154,14 @@ public:
// italic style = constants in gfxFontConstants.h, e.g. NS_FONT_STYLE_NORMAL
// language override = result of calling gfxFontStyle::ParseFontLanguageOverride
// TODO: support for unicode ranges not yet implemented
already_AddRefed<gfxUserFontEntry> CreateFontFace(
virtual already_AddRefed<gfxUserFontEntry> CreateFontFace(
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
uint32_t aWeight,
int32_t aStretch,
uint32_t aItalicStyle,
const nsTArray<gfxFontFeature>& aFeatureSettings,
uint32_t aLanguageOverride,
gfxSparseBitSet* aUnicodeRanges);
gfxSparseBitSet* aUnicodeRanges) = 0;
// creates a font face for the specified family, or returns an existing
// matching entry on the family if there is one

View File

@ -6,8 +6,9 @@
#ifndef mozilla_dom_FontFace_h
#define mozilla_dom_FontFace_h
#include "nsWrapperCache.h"
#include "mozilla/dom/FontFaceBinding.h"
#include "gfxUserFontSet.h"
#include "nsWrapperCache.h"
namespace mozilla {
namespace dom {
@ -24,6 +25,21 @@ class FontFace MOZ_FINAL : public nsISupports,
public nsWrapperCache
{
public:
class Entry MOZ_FINAL : public gfxUserFontEntry {
public:
Entry(gfxUserFontSet* aFontSet,
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
uint32_t aWeight,
int32_t aStretch,
uint32_t aItalicStyle,
const nsTArray<gfxFontFeature>& aFeatureSettings,
uint32_t aLanguageOverride,
gfxSparseBitSet* aUnicodeRanges)
: gfxUserFontEntry(aFontSet, aFontFaceSrcList, aWeight, aStretch,
aItalicStyle, aFeatureSettings, aLanguageOverride,
aUnicodeRanges) {}
};
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FontFace)

View File

@ -11,6 +11,7 @@
#endif /* MOZ_LOGGING */
#include "prlog.h"
#include "mozilla/dom/FontFace.h"
#include "mozilla/dom/FontFaceSetBinding.h"
#include "mozilla/dom/Promise.h"
#include "nsCrossSiteListenerProxy.h"
@ -987,3 +988,19 @@ FontFaceSet::UserFontSet::DoRebuildUserFontSet()
}
mFontFaceSet->DoRebuildUserFontSet();
}
/* virtual */ already_AddRefed<gfxUserFontEntry>
FontFaceSet::UserFontSet::CreateFontFace(
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
uint32_t aWeight,
int32_t aStretch,
uint32_t aItalicStyle,
const nsTArray<gfxFontFeature>& aFeatureSettings,
uint32_t aLanguageOverride,
gfxSparseBitSet* aUnicodeRanges)
{
nsRefPtr<gfxUserFontEntry> entry =
new FontFace::Entry(this, aFontFaceSrcList, aWeight, aStretch, aItalicStyle,
aFeatureSettings, aLanguageOverride, aUnicodeRanges);
return entry.forget();
}

View File

@ -72,6 +72,14 @@ public:
uint32_t aFlags = nsIScriptError::errorFlag,
nsresult aStatus = NS_OK) MOZ_OVERRIDE;
virtual void DoRebuildUserFontSet() MOZ_OVERRIDE;
virtual already_AddRefed<gfxUserFontEntry> CreateFontFace(
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
uint32_t aWeight,
int32_t aStretch,
uint32_t aItalicStyle,
const nsTArray<gfxFontFeature>& aFeatureSettings,
uint32_t aLanguageOverride,
gfxSparseBitSet* aUnicodeRanges) MOZ_OVERRIDE;
private:
nsRefPtr<FontFaceSet> mFontFaceSet;