Bug 1436059: Cleanup a bit after ourselves. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 16 Feb 2018 11:49:18 +0100
changeset 756086 d9b901c83f388c079721206152fd5a84db208d9d
parent 756083 9dbb2e25d00a9224aec9955f0c00d5279cd5daeb
push id99370
push userbmo:emilio@crisal.io
push dateFri, 16 Feb 2018 11:06:35 +0000
reviewersxidorn
bugs1436059
milestone60.0a1
Bug 1436059: Cleanup a bit after ourselves. r?xidorn MozReview-Commit-ID: DWWmdtigIkk
layout/base/PresShell.cpp
layout/base/nsDocumentViewer.cpp
layout/style/ServoBindings.toml
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -9712,19 +9712,17 @@ PresShell::CloneStyleSet(nsStyleSet* aSe
   CopySheetsIntoClone(aSet, clone);
   return clone;
 }
 #endif
 
 ServoStyleSet*
 PresShell::CloneStyleSet(ServoStyleSet* aSet)
 {
-  MOZ_ASSERT(aSet->IsMaster());
-
-  ServoStyleSet* clone = new ServoStyleSet(ServoStyleSet::Kind::Master);
+  ServoStyleSet* clone = new ServoStyleSet();
   CopySheetsIntoClone(aSet, clone);
   return clone;
 }
 
 // After an incremental reflow, we verify the correctness by doing a
 // full reflow into a fresh frame tree.
 bool
 PresShell::VerifyIncrementalReflow()
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2329,17 +2329,17 @@ nsDocumentViewer::CreateStyleSet(nsIDocu
   StyleSetHandle styleSet;
   if (backendType == StyleBackendType::Gecko) {
 #ifdef MOZ_OLD_STYLE
     styleSet = new nsStyleSet();
 #else
     MOZ_CRASH("old style system disabled");
 #endif
   } else {
-    styleSet = new ServoStyleSet(ServoStyleSet::Kind::Master);
+    styleSet = new ServoStyleSet();
   }
 
   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/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -218,16 +218,17 @@ whitelist-types = [
     "mozilla::AnonymousCounterStyle",
     "mozilla::AtomArray",
     "mozilla::ComputedTiming",
     "mozilla::ComputedTimingFunction",
     "mozilla::ComputedTimingFunction::BeforeFlag",
     "mozilla::SeenPtrs",
     "mozilla::ServoElementSnapshot.*",
     "mozilla::ServoStyleContext",
+    "mozilla::ServoStyleSheet",
     "mozilla::ServoStyleSheetInner",
     "mozilla::ServoStyleSetSizes",
     "mozilla::CSSPseudoClassType",
     "mozilla::css::ErrorReporter",
     "mozilla::css::LoaderReusableStyleSheets",
     "mozilla::css::SheetParsingMode",
     "mozilla::css::URLMatchingFunction",
     "mozilla::dom::IterationCompositeOperation",
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -93,19 +93,18 @@ public:
 
 private:
   AutoRestyleTimelineMarker mTimelineMarker;
   AutoSetInServoTraversal mSetInServoTraversal;
 };
 
 } // namespace mozilla
 
-ServoStyleSet::ServoStyleSet(Kind aKind)
-  : mKind(aKind)
-  , mDocument(nullptr)
+ServoStyleSet::ServoStyleSet()
+  : mDocument(nullptr)
   , mAuthorStyleDisabled(false)
   , mStylistState(StylistState::NotDirty)
   , mUserFontSetUpdateGeneration(0)
   , mUserFontCacheUpdateGeneration(0)
   , mNeedsRestyleAfterEnsureUniqueInner(false)
 {
 }
 
@@ -113,44 +112,16 @@ ServoStyleSet::~ServoStyleSet()
 {
   for (auto& sheetArray : mSheets) {
     for (auto& sheet : sheetArray) {
       sheet->DropStyleSet(this);
     }
   }
 }
 
-UniquePtr<ServoStyleSet>
-ServoStyleSet::CreateXBLServoStyleSet(
-  nsPresContext* aPresContext,
-  const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets)
-{
-  auto set = MakeUnique<ServoStyleSet>(Kind::ForXBL);
-  set->Init(aPresContext);
-
-  // 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().
-  set->ReplaceSheets(SheetType::Doc, aNewSheets);
-
-  // Update stylist immediately.
-  //
-  // NOTE(emilio): that this _needs_ to be the only call to UpdateStylist for
-  // XBL bindings, otherwise the Servo-side Device may have stale pres context
-  // pointers and such, which are not great.
-  set->UpdateStylist();
-
-  // XBL resources are shared for a given URL, even across documents, so we
-  // can't safely keep this reference.
-  set->mDocument = nullptr;
-
-  return set;
-}
-
 nsPresContext*
 ServoStyleSet::GetPresContext()
 {
   if (!mDocument) {
     return nullptr;
   }
 
   auto* shell = mDocument->GetShell();
@@ -209,17 +180,16 @@ ServoStyleSet::InvalidateStyleForCSSRule
   if (nsPresContext* pc = GetPresContext()) {
     pc->RestyleManager()->AsServo()->PostRestyleEventForCSSRuleChanges();
   }
 }
 
 void
 ServoStyleSet::InvalidateStyleForDocumentStateChanges(EventStates aStatesChanged)
 {
-  MOZ_ASSERT(IsMaster());
   MOZ_ASSERT(mDocument);
   MOZ_ASSERT(!aStatesChanged.IsEmpty());
 
   nsPresContext* pc = GetPresContext();
   if (!pc) {
     return;
   }
 
@@ -1470,26 +1440,25 @@ void
 ServoStyleSet::UpdateStylist()
 {
   MOZ_ASSERT(StylistNeedsUpdate());
 
   if (mStylistState & StylistState::StyleSheetsDirty) {
     // There's no need to compute invalidations and such for an XBL styleset,
     // since they are loaded and unloaded synchronously, and they don't have to
     // deal with dynamic content changes.
-    Element* root = IsMaster() ? mDocument->GetRootElement() : nullptr;
+    Element* root = mDocument->GetRootElement();
     const ServoElementSnapshotTable* snapshots = nullptr;
     if (nsPresContext* pc = GetPresContext()) {
       snapshots = &pc->RestyleManager()->AsServo()->Snapshots();
     }
     Servo_StyleSet_FlushStyleSheets(mRawSet.get(), root, snapshots);
   }
 
   if (MOZ_UNLIKELY(mStylistState & StylistState::XBLStyleSheetsDirty)) {
-    MOZ_ASSERT(IsMaster(), "Only master styleset can mark XBL stylesets dirty!");
     MOZ_ASSERT(GetPresContext(), "How did they get dirty?");
     mDocument->BindingManager()->EnumerateBoundContentBindings(
       [&](nsXBLBinding* aBinding) {
         if (auto* authorStyles = aBinding->PrototypeBinding()->GetServoStyles()) {
           Servo_AuthorStyles_Flush(authorStyles, mRawSet.get());
         }
         return true;
       });
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -95,37 +95,19 @@ public:
   static bool IsCurrentThreadInServoTraversal();
 #endif
 
   static ServoStyleSet* Current()
   {
     return sInServoTraversal;
   }
 
-  // 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();
   ~ServoStyleSet();
 
-  static UniquePtr<ServoStyleSet>
-  CreateXBLServoStyleSet(nsPresContext* aPresContext,
-                         const nsTArray<RefPtr<ServoStyleSheet>>& aNewSheets);
-
   void Init(nsPresContext* aPresContext);
   void BeginShutdown() {}
   void Shutdown();
 
   // Called when a rules in a stylesheet in this set, or a child sheet of that,
   // are mutated from CSSOM.
   void RuleAdded(ServoStyleSheet&, css::Rule&);
   void RuleRemoved(ServoStyleSheet&, css::Rule&);
@@ -487,19 +469,16 @@ public:
    */
   already_AddRefed<ServoStyleContext>
   ReparentStyleContext(ServoStyleContext* aStyleContext,
                        ServoStyleContext* aNewParent,
                        ServoStyleContext* aNewParentIgnoringFirstLine,
                        ServoStyleContext* aNewLayoutParent,
                        Element* aElement);
 
-  bool IsMaster() const { return mKind == Kind::Master; }
-  bool IsForXBL() const { return mKind == Kind::ForXBL; }
-
 private:
   friend class AutoSetInServoTraversal;
   friend class AutoPrepareTraversal;
 
   bool ShouldTraverseInParallel() const;
 
   /**
    * Gets the pending snapshots to handle from the restyle manager.
@@ -577,18 +556,16 @@ private:
 
   void InsertSheetOfType(SheetType aType,
                          ServoStyleSheet* aSheet,
                          ServoStyleSheet* aBeforeSheet);
 
   void RemoveSheetOfType(SheetType aType,
                          ServoStyleSheet* aSheet);
 
-  const Kind mKind;
-
   // The owner document of this style set. Null if this is an XBL style set.
   //
   // TODO(emilio): This should become a DocumentOrShadowRoot, and be owned by it
   // directly instead of the shell, eventually.
   nsIDocument* mDocument;
 
   const nsPresContext* GetPresContext() const {
     return const_cast<ServoStyleSet*>(this)->GetPresContext();