Bug 1408303 - Part 1: Store mIsServo into FontFace. draft
authorBoris Chiou <boris.chiou@gmail.com>
Tue, 21 Nov 2017 15:00:59 +0800
changeset 706111 0378dd637d54bd075dcc4e100857ecc2a127e71b
parent 706025 a21f4e2ce5186e2dc9ee411b07e9348866b4ef30
child 706112 898603e54bed300a6fe257492996c4e4d7aea100
push id91721
push userbmo:boris.chiou@gmail.com
push dateFri, 01 Dec 2017 10:24:42 +0000
bugs1408303
milestone59.0a1
Bug 1408303 - Part 1: Store mIsServo into FontFace. We need this flag to know if we enable stylo in FontFace. MozReview-Commit-ID: 9bi3NNO50Wp
layout/style/FontFace.cpp
layout/style/FontFace.h
layout/style/FontFaceSet.cpp
--- a/layout/style/FontFace.cpp
+++ b/layout/style/FontFace.cpp
@@ -96,26 +96,29 @@ 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, FontFaceSet* aFontFaceSet)
+FontFace::FontFace(nsISupports* aParent,
+                   FontFaceSet* aFontFaceSet,
+                   bool aIsServo)
   : mParent(aParent)
   , mLoadedRejection(NS_OK)
   , mStatus(FontFaceLoadStatus::Unloaded)
   , mSourceType(SourceType(0))
   , mSourceBuffer(nullptr)
   , mSourceBufferLength(0)
   , mFontFaceSet(aFontFaceSet)
   , mUnicodeRangeDirty(true)
   , mInFontFaceSet(false)
+  , mIsServo(aIsServo)
 {
 }
 
 FontFace::~FontFace()
 {
   // Assert that we don't drop any FontFace objects during a Servo traversal,
   // since PostTraversalTask objects can hold raw pointers to FontFaces.
   MOZ_ASSERT(!ServoStyleSet::IsInServoTraversal());
@@ -149,19 +152,20 @@ LoadStateToStatus(gfxUserFontEntry::User
   }
   NS_NOTREACHED("invalid aLoadState value");
   return FontFaceLoadStatus::Error;
 }
 
 already_AddRefed<FontFace>
 FontFace::CreateForRule(nsISupports* aGlobal,
                         FontFaceSet* aFontFaceSet,
-                        nsCSSFontFaceRule* aRule)
+                        nsCSSFontFaceRule* aRule,
+                        bool aIsServo)
 {
-  RefPtr<FontFace> obj = new FontFace(aGlobal, aFontFaceSet);
+  RefPtr<FontFace> obj = new FontFace(aGlobal, aFontFaceSet, aIsServo);
   obj->mRule = aRule;
   obj->mSourceType = eSourceType_FontFaceRule;
   obj->mInFontFaceSet = true;
   return obj.forget();
 }
 
 already_AddRefed<FontFace>
 FontFace::Constructor(const GlobalObject& aGlobal,
@@ -173,17 +177,19 @@ FontFace::Constructor(const GlobalObject
   nsISupports* global = aGlobal.GetAsSupports();
   nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global);
   nsIDocument* doc = window->GetDoc();
   if (!doc) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  RefPtr<FontFace> obj = new FontFace(global, doc->Fonts());
+  RefPtr<FontFace> obj = new FontFace(global,
+                                      doc->Fonts(),
+                                      doc->IsStyledByServo());
   if (!obj->SetDescriptors(aFamily, aDescriptors)) {
     return obj.forget();
   }
 
   obj->InitializeSource(aSource);
   return obj.forget();
 }
 
--- a/layout/style/FontFace.h
+++ b/layout/style/FontFace.h
@@ -72,17 +72,18 @@ 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, FontFaceSet* aFontFaceSet,
-                nsCSSFontFaceRule* aRule);
+                nsCSSFontFaceRule* aRule,
+                bool aIsServo);
 
   nsCSSFontFaceRule* GetRule() { return mRule; }
 
   void GetDesc(nsCSSFontDesc aDescID, nsCSSValue& aResult) const;
 
   gfxUserFontEntry* CreateUserFontEntry();
   gfxUserFontEntry* GetUserFontEntry() const { return mUserFontEntry; }
   void SetUserFontEntry(gfxUserFontEntry* aEntry);
@@ -161,17 +162,17 @@ public:
   void GetDisplay(nsString& aResult);
   void SetDisplay(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, FontFaceSet* aFontFaceSet);
+  FontFace(nsISupports* aParent, FontFaceSet* aFontFaceSet, bool aIsServo);
   ~FontFace();
 
   void InitializeSource(const StringOrArrayBufferOrArrayBufferView& aSource);
 
   // Helper function for Load.
   void DoLoad();
 
   /**
@@ -275,14 +276,17 @@ private:
   nsTArray<RefPtr<FontFaceSet>> mOtherFontFaceSets;
 
   // Whether mUnicodeRange needs to be rebuilt before being returned from
   // GetUnicodeRangeAsCharacterMap.
   bool mUnicodeRangeDirty;
 
   // Whether this FontFace appears in mFontFaceSet.
   bool mInFontFaceSet;
+
+  // Whether this FontFace is styled by Servo backend.
+  bool mIsServo;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // !defined(mozilla_dom_FontFace_h)
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -746,29 +746,31 @@ FontFaceSet::UpdateRules(const nsTArray<
   }
 
   // Sometimes aRules has duplicate @font-face rules in it; we should make
   // that not happen, but in the meantime, don't try to insert the same
   // FontFace object more than once into mRuleFaces.  We track which
   // ones we've handled in this table.
   nsTHashtable<nsPtrHashKey<nsCSSFontFaceRule>> handledRules;
 
+  bool isServo = mDocument->IsStyledByServo();
+
   for (size_t i = 0, i_end = aRules.Length(); i < i_end; ++i) {
     // Insert each FontFace objects for each rule into our list, migrating old
     // font entries if possible rather than creating new ones; set  modified  to
     // true if we detect that rule ordering has changed, or if a new entry is
     // created.
     nsCSSFontFaceRule* rule = aRules[i].mRule;
     if (!handledRules.EnsureInserted(rule)) {
       // rule was already present in the hashtable
       continue;
     }
     RefPtr<FontFace> f = ruleFaceMap.Get(rule);
     if (!f.get()) {
-      f = FontFace::CreateForRule(GetParentObject(), this, rule);
+      f = FontFace::CreateForRule(GetParentObject(), this, rule, isServo);
     }
     InsertRuleFontFace(f, aRules[i].mSheetType, oldRecords, modified);
   }
 
   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);
   }