Bug 1384232: Let ServoStyleset know what its purpose is. r=TYLin
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 31 Aug 2017 22:50:24 +0200
changeset 657403 ffd346281fb9985832a174413c94f6c90ebb1d1b
parent 657402 2a9f62a68924fcbdd669978ca690863be016ea55
child 657404 492969ffe3c8991a486252342636d48a5844dce7
push id77508
push userbmo:emilio@crisal.io
push dateFri, 01 Sep 2017 11:17:48 +0000
reviewersTYLin
bugs1384232
milestone57.0a1
Bug 1384232: Let ServoStyleset know what its purpose is. r=TYLin MozReview-Commit-ID: IwC6FcxhYMT
dom/xbl/nsXBLPrototypeResources.cpp
layout/base/nsDocumentViewer.cpp
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
--- a/dom/xbl/nsXBLPrototypeResources.cpp
+++ b/dom/xbl/nsXBLPrototypeResources.cpp
@@ -162,17 +162,17 @@ nsXBLPrototypeResources::GatherRuleProce
                                           SheetType::Doc,
                                           nullptr,
                                           mRuleProcessor);
 }
 
 void
 nsXBLPrototypeResources::ComputeServoStyleSet(nsPresContext* aPresContext)
 {
-  mServoStyleSet.reset(new ServoStyleSet());
+  mServoStyleSet.reset(new ServoStyleSet(ServoStyleSet::Kind::ForXBL));
   mServoStyleSet->Init(aPresContext, nullptr);
   for (StyleSheet* sheet : mStyleSheetList) {
     MOZ_ASSERT(sheet->IsServo(),
                "This should only be called with Servo-flavored style backend!");
     // The XBL style sheets aren't document level sheets, but we need to
     // decide a particular SheetType to add them to style set. This type
     // doesn't affect the place where we pull those rules from
     // stylist::push_applicable_declarations_as_xbl_only_stylist().
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2314,17 +2314,17 @@ nsDocumentViewer::CreateStyleSet(nsIDocu
   // different sets for different media
 
   StyleBackendType backendType = aDocument->GetStyleBackendType();
 
   StyleSetHandle styleSet;
   if (backendType == StyleBackendType::Gecko) {
     styleSet = new nsStyleSet();
   } else {
-    styleSet = new ServoStyleSet();
+    styleSet = new ServoStyleSet(ServoStyleSet::Kind::Master);
   }
 
   styleSet->BeginUpdate();
 
   // The document will fill in the document sheets when we create the presshell
 
   if (aDocument->IsBeingUsedAsImage()) {
     MOZ_ASSERT(aDocument->IsSVGDocument(),
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -80,18 +80,19 @@ public:
 
 private:
   AutoRestyleTimelineMarker mTimelineMarker;
   AutoSetInServoTraversal mSetInServoTraversal;
 };
 
 } // namespace mozilla
 
-ServoStyleSet::ServoStyleSet()
-  : mPresContext(nullptr)
+ServoStyleSet::ServoStyleSet(Kind aKind)
+  : mKind(aKind)
+  , mPresContext(nullptr)
   , mAuthorStyleDisabled(false)
   , mStylistState(StylistState::NotDirty)
   , mUserFontSetUpdateGeneration(0)
   , mUserFontCacheUpdateGeneration(0)
   , mNeedsRestyleAfterEnsureUniqueInner(false)
 {
 }
 
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -92,17 +92,31 @@ public:
     return sInServoTraversal;
   }
 
   static ServoStyleSet* Current()
   {
     return sInServoTraversal;
   }
 
-  ServoStyleSet();
+  // The kind of styleset we have.
+  //
+  // We use ServoStyleSet also from XBL bindings, and some stuff needs to be
+  // different between them.
+  enum class Kind : uint8_t {
+    // A "master" StyleSet.
+    //
+    // This one is owned by a pres shell for a given document.
+    Master,
+
+    // A StyleSet for XBL, which is owned by a given XBL binding.
+    ForXBL,
+  };
+
+  explicit ServoStyleSet(Kind aKind);
   ~ServoStyleSet();
 
   void Init(nsPresContext* aPresContext, nsBindingManager* aBindingManager);
   void BeginShutdown();
   void Shutdown();
 
   void RecordStyleSheetChange(mozilla::ServoStyleSheet*, StyleSheet::ChangeType);
 
@@ -470,16 +484,19 @@ private:
   friend class AutoSetInServoTraversal;
   friend class AutoPrepareTraversal;
 
   /**
    * Gets the pending snapshots to handle from the restyle manager.
    */
   const SnapshotTable& Snapshots();
 
+  bool IsMaster() const { return mKind == Kind::Master; }
+  bool IsForXBL() const { return mKind == Kind::ForXBL; }
+
   /**
    * Resolve all ServoDeclarationBlocks attached to mapped
    * presentation attributes cached on the document.
    *
    * Call this before jumping into Servo's style system.
    */
   void ResolveMappedAttrDeclarationBlocks();
 
@@ -550,16 +567,17 @@ private:
 
   void InsertSheetOfType(SheetType aType,
                          ServoStyleSheet* aSheet,
                          ServoStyleSheet* aBeforeSheet);
 
   void RemoveSheetOfType(SheetType aType,
                          ServoStyleSheet* aSheet);
 
+  const Kind mKind;
   nsPresContext* mPresContext;
   UniquePtr<RawServoStyleSet> mRawSet;
   EnumeratedArray<SheetType, SheetType::Count,
                   nsTArray<RefPtr<ServoStyleSheet>>> mSheets;
   bool mAuthorStyleDisabled;
   StylistState mStylistState;
   uint64_t mUserFontSetUpdateGeneration;
   uint32_t mUserFontCacheUpdateGeneration;