Bug 1161413 - Part 2: Create FontFace objects with a FontFaceSet rather than a pres context. r=jdaggett
authorCameron McCormack <cam@mcc.id.au>
Sat, 27 Jun 2015 11:39:54 +1000
changeset 268561 68f448e76abb471585e814d153879684301f10a5
parent 268560 57086b92200dcd1528036071fc53a39ed531de1c
child 268562 a8b95bf6004f1a5d87e673d0e364a0edf59d8017
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-esr52@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett
bugs1161413
milestone41.0a1
Bug 1161413 - Part 2: Create FontFace objects with a FontFaceSet rather than a pres context. r=jdaggett
layout/style/FontFace.cpp
layout/style/FontFace.h
layout/style/FontFaceSet.cpp
--- a/layout/style/FontFace.cpp
+++ b/layout/style/FontFace.cpp
@@ -94,24 +94,23 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FontFace)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(FontFace)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(FontFace)
 
-FontFace::FontFace(nsISupports* aParent, nsPresContext* aPresContext)
+FontFace::FontFace(nsISupports* aParent, FontFaceSet* aFontFaceSet)
   : mParent(aParent)
-  , mPresContext(aPresContext)
   , mStatus(FontFaceLoadStatus::Unloaded)
   , mSourceType(SourceType(0))
   , mSourceBuffer(nullptr)
   , mSourceBufferLength(0)
-  , mFontFaceSet(aPresContext->Fonts())
+  , mFontFaceSet(aFontFaceSet)
   , mInFontFaceSet(false)
 {
   MOZ_COUNT_CTOR(FontFace);
 
   nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aParent);
 
   // If the pref is not set, don't create the Promise (which the page wouldn't
   // be able to get to anyway) as it causes the window.FontFace constructor
@@ -157,22 +156,22 @@ LoadStateToStatus(gfxUserFontEntry::User
       return FontFaceLoadStatus::Error;
   }
   NS_NOTREACHED("invalid aLoadState value");
   return FontFaceLoadStatus::Error;
 }
 
 already_AddRefed<FontFace>
 FontFace::CreateForRule(nsISupports* aGlobal,
-                        nsPresContext* aPresContext,
+                        FontFaceSet* aFontFaceSet,
                         nsCSSFontFaceRule* aRule)
 {
   nsCOMPtr<nsIGlobalObject> globalObject = do_QueryInterface(aGlobal);
 
-  nsRefPtr<FontFace> obj = new FontFace(aGlobal, aPresContext);
+  nsRefPtr<FontFace> obj = new FontFace(aGlobal, aFontFaceSet);
   obj->mRule = aRule;
   obj->mSourceType = eSourceType_FontFaceRule;
   obj->mInFontFaceSet = true;
   return obj.forget();
 }
 
 already_AddRefed<FontFace>
 FontFace::Constructor(const GlobalObject& aGlobal,
@@ -184,29 +183,22 @@ FontFace::Constructor(const GlobalObject
   nsISupports* global = aGlobal.GetAsSupports();
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global);
   nsIDocument* doc = window->GetDoc();
   if (!doc) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsIPresShell* shell = doc->GetShell();
-  if (!shell) {
-    aRv.Throw(NS_ERROR_FAILURE);
+  FontFaceSet* set = doc->GetFonts(aRv);
+  if (aRv.Failed()) {
     return nullptr;
   }
 
-  nsPresContext* presContext = shell->GetPresContext();
-  if (!presContext) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  nsRefPtr<FontFace> obj = new FontFace(global, presContext);
+  nsRefPtr<FontFace> obj = new FontFace(global, set);
   obj->mFontFaceSet->AddUnavailableFontFace(obj);
   if (!obj->SetDescriptors(aFamily, aDescriptors)) {
     return obj.forget();
   }
 
   obj->InitializeSource(aSource);
   return obj.forget();
 }
@@ -247,17 +239,17 @@ FontFace::InitializeSource(const StringO
 
   SetStatus(FontFaceLoadStatus::Loading);
   DoLoad();
 }
 
 void
 FontFace::GetFamily(nsString& aResult)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
 
   // Serialize the same way as in nsCSSFontFaceStyleDecl::GetPropertyValue.
   nsCSSValue value;
   GetDesc(eCSSFontDesc_Family, value);
 
   aResult.Truncate();
 
   if (value.GetUnit() == eCSSUnit_Null) {
@@ -270,124 +262,124 @@ FontFace::GetFamily(nsString& aResult)
     // family name or an invalid descriptor to the JS FontFace constructor.
     nsStyleUtil::AppendEscapedCSSString(family, aResult);
   }
 }
 
 void
 FontFace::SetFamily(const nsAString& aValue, ErrorResult& aRv)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
   SetDescriptor(eCSSFontDesc_Family, aValue, aRv);
 }
 
 void
 FontFace::GetStyle(nsString& aResult)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
   GetDesc(eCSSFontDesc_Style, eCSSProperty_font_style, aResult);
 }
 
 void
 FontFace::SetStyle(const nsAString& aValue, ErrorResult& aRv)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
   SetDescriptor(eCSSFontDesc_Style, aValue, aRv);
 }
 
 void
 FontFace::GetWeight(nsString& aResult)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
   GetDesc(eCSSFontDesc_Weight, eCSSProperty_font_weight, aResult);
 }
 
 void
 FontFace::SetWeight(const nsAString& aValue, ErrorResult& aRv)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
   SetDescriptor(eCSSFontDesc_Weight, aValue, aRv);
 }
 
 void
 FontFace::GetStretch(nsString& aResult)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
   GetDesc(eCSSFontDesc_Stretch, eCSSProperty_font_stretch, aResult);
 }
 
 void
 FontFace::SetStretch(const nsAString& aValue, ErrorResult& aRv)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
   SetDescriptor(eCSSFontDesc_Stretch, aValue, aRv);
 }
 
 void
 FontFace::GetUnicodeRange(nsString& aResult)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
 
   // There is no eCSSProperty_unicode_range for us to pass in to GetDesc
   // to get a serialized (possibly defaulted) value, but that function
   // doesn't use the property ID for this descriptor anyway.
   GetDesc(eCSSFontDesc_UnicodeRange, eCSSProperty_UNKNOWN, aResult);
 }
 
 void
 FontFace::SetUnicodeRange(const nsAString& aValue, ErrorResult& aRv)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
   SetDescriptor(eCSSFontDesc_UnicodeRange, aValue, aRv);
 }
 
 void
 FontFace::GetVariant(nsString& aResult)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
 
   // XXX Just expose the font-variant descriptor as "normal" until we
   // support it properly (bug 1055385).
   aResult.AssignLiteral("normal");
 }
 
 void
 FontFace::SetVariant(const nsAString& aValue, ErrorResult& aRv)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
 
   // XXX Ignore assignments to variant until we support font-variant
   // descriptors (bug 1055385).
 }
 
 void
 FontFace::GetFeatureSettings(nsString& aResult)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
   GetDesc(eCSSFontDesc_FontFeatureSettings, eCSSProperty_font_feature_settings,
           aResult);
 }
 
 void
 FontFace::SetFeatureSettings(const nsAString& aValue, ErrorResult& aRv)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
   SetDescriptor(eCSSFontDesc_FontFeatureSettings, aValue, aRv);
 }
 
 FontFaceLoadStatus
 FontFace::Status()
 {
   return mStatus;
 }
 
 Promise*
 FontFace::Load(ErrorResult& aRv)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
 
   if (!mLoaded) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   // Calling Load on a FontFace constructed with an ArrayBuffer data source,
   // or on one that is already loading (or has finished loading), has no
@@ -425,17 +417,17 @@ FontFace::DoLoad()
   }
 
   mUserFontEntry->Load();
 }
 
 Promise*
 FontFace::GetLoaded(ErrorResult& aRv)
 {
-  mPresContext->FlushUserFontSet();
+  mFontFaceSet->FlushUserFontSet();
 
   if (!mLoaded) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   return mLoaded;
 }
--- a/layout/style/FontFace.h
+++ b/layout/style/FontFace.h
@@ -9,17 +9,16 @@
 #include "mozilla/dom/FontFaceBinding.h"
 #include "gfxUserFontSet.h"
 #include "nsCSSProperty.h"
 #include "nsCSSValue.h"
 #include "nsWrapperCache.h"
 
 class gfxFontFaceBufferSource;
 class nsCSSFontFaceRule;
-class nsPresContext;
 
 namespace mozilla {
 struct CSSFontFaceDescriptors;
 namespace dom {
 class FontFaceBufferSource;
 struct FontFaceDescriptors;
 class FontFaceSet;
 class Promise;
@@ -65,17 +64,17 @@ public:
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FontFace)
 
   nsISupports* GetParentObject() const { return mParent; }
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   static already_AddRefed<FontFace>
-  CreateForRule(nsISupports* aGlobal, nsPresContext* aPresContext,
+  CreateForRule(nsISupports* aGlobal, FontFaceSet* aFontFaceSet,
                 nsCSSFontFaceRule* aRule);
 
   nsCSSFontFaceRule* GetRule() { return mRule; }
 
   void GetDesc(nsCSSFontDesc aDescID, nsCSSValue& aResult) const;
 
   gfxUserFontEntry* GetUserFontEntry() const { return mUserFontEntry; }
   void SetUserFontEntry(gfxUserFontEntry* aEntry);
@@ -156,17 +155,17 @@ public:
   void GetFeatureSettings(nsString& aResult);
   void SetFeatureSettings(const nsAString& aValue, mozilla::ErrorResult& aRv);
 
   mozilla::dom::FontFaceLoadStatus Status();
   mozilla::dom::Promise* Load(mozilla::ErrorResult& aRv);
   mozilla::dom::Promise* GetLoaded(mozilla::ErrorResult& aRv);
 
 private:
-  FontFace(nsISupports* aParent, nsPresContext* aPresContext);
+  FontFace(nsISupports* aParent, FontFaceSet* aFontFaceSet);
   ~FontFace();
 
   void InitializeSource(const StringOrArrayBufferOrArrayBufferView& aSource);
 
   // Helper function for Load.
   void DoLoad();
 
   /**
@@ -198,17 +197,16 @@ private:
                nsString& aResult) const;
 
   /**
    * Returns and takes ownership of the buffer storing the font data.
    */
   void TakeBuffer(uint8_t*& aBuffer, uint32_t& aLength);
 
   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
   // rule backed FontFace.
   nsRefPtr<nsCSSFontFaceRule> mRule;
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -587,17 +587,17 @@ FontFaceSet::UpdateRules(const nsTArray<
     // true if we detect that rule ordering has changed, or if a new entry is
     // created.
     if (handledRules.Contains(aRules[i].mRule)) {
       continue;
     }
     nsCSSFontFaceRule* rule = aRules[i].mRule;
     nsRefPtr<FontFace> f = ruleFaceMap.Get(rule);
     if (!f.get()) {
-      f = FontFace::CreateForRule(GetParentObject(), mPresContext, rule);
+      f = FontFace::CreateForRule(GetParentObject(), this, rule);
     }
     InsertRuleFontFace(f, aRules[i].mSheetType, oldRecords, modified);
     handledRules.PutEntry(aRules[i].mRule);
   }
 
   for (size_t i = 0, i_end = mNonRuleFaces.Length(); i < i_end; ++i) {
     // Do the same for the non rule backed FontFace objects.
     InsertNonRuleFontFace(mNonRuleFaces[i].mFontFace, modified);