Bug 1357583: Remove ServoStyleSheet::ClearRuleCascades. r?heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 25 May 2017 22:33:47 +0200
changeset 586157 c3af80f14eef73c69ac42d6157e991efabee4b37
parent 586156 759183f38bbfc001fd0de9a766e222488dd5b5ef
child 586158 c81929cad4bfaa4d00b47aef0e3070c94107868a
push id61311
push userbmo:emilio+bugs@crisal.io
push dateMon, 29 May 2017 21:02:45 +0000
reviewersheycam
bugs1357583
milestone55.0a1
Bug 1357583: Remove ServoStyleSheet::ClearRuleCascades. r?heycam These invalidations are already handled from the PresShell notifications, no need to handle it somewhere else. MozReview-Commit-ID: G9KDVvSKMJY
layout/style/CSSStyleSheet.cpp
layout/style/CSSStyleSheet.h
layout/style/ServoStyleSheet.cpp
layout/style/ServoStyleSheet.h
layout/style/StyleSheet.cpp
layout/style/StyleSheet.h
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -596,18 +596,18 @@ CSSStyleSheet::List(FILE* out, int32_t a
 {
   StyleSheet::List(out, aIndent);
 
   fprintf_stderr(out, "%s", "Rules in source order:\n");
   ListRules(Inner()->mOrderedRules, out, aIndent);
 }
 #endif
 
-void 
-CSSStyleSheet::ClearRuleCascadesInternal()
+void
+CSSStyleSheet::ClearRuleCascades()
 {
   // We might be in ClearRuleCascadesInternal because we had a modification
   // to the sheet that resulted in an nsCSSSelector being destroyed.
   // Tell the RestyleManager for each document we're used in
   // so that they can drop any nsCSSSelector pointers (used for
   // eRestyle_SomeDescendants) in their mPendingRestyles.
   for (StyleSetHandle setHandle : mStyleSets) {
     setHandle->AsGecko()->ClearSelectors();
@@ -623,16 +623,20 @@ CSSStyleSheet::ClearRuleCascadesInternal
         // RuleProcessorCache entries that contain this sheet, as the
         // list of @-moz-document rules might have changed.
         RuleProcessorCache::RemoveSheet(this);
         removedSheetFromRuleProcessorCache = true;
       }
       (*iter)->ClearRuleCascades();
     }
   }
+
+  if (mParent) {
+    static_cast<CSSStyleSheet*>(mParent)->ClearRuleCascades();
+  }
 }
 
 void
 CSSStyleSheet::DidDirty()
 {
   MOZ_ASSERT(!mInner->mComplete || mDirty,
              "caller must have called WillDirty()");
   ClearRuleCascades();
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -173,17 +173,17 @@ private:
                 nsINode* aOwningNodeToUse);
 
   CSSStyleSheet(const CSSStyleSheet& aCopy) = delete;
   CSSStyleSheet& operator=(const CSSStyleSheet& aCopy) = delete;
 
 protected:
   virtual ~CSSStyleSheet();
 
-  void ClearRuleCascadesInternal() override;
+  void ClearRuleCascades();
 
   // Add the namespace mapping from this @namespace rule to our namespace map
   nsresult RegisterNamespaceRule(css::Rule* aRule);
 
   // Drop our reference to mRuleCollection
   void DropRuleCollection();
 
   CSSStyleSheetInner* Inner() const
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -214,25 +214,16 @@ ServoStyleSheet::Clone(StyleSheet* aClon
   RefPtr<StyleSheet> clone = new ServoStyleSheet(*this,
     static_cast<ServoStyleSheet*>(aCloneParent),
     aCloneOwnerRule,
     aCloneDocument,
     aCloneOwningNode);
   return clone.forget();
 }
 
-void
-ServoStyleSheet::ClearRuleCascadesInternal()
-{
-  for (StyleSetHandle& setHandle : mStyleSets) {
-    setHandle->AsServo()->NoteStyleSheetsChanged();
-    setHandle->AsServo()->UpdateStylistIfNeeded();
-  }
-}
-
 CSSRuleList*
 ServoStyleSheet::GetCssRulesInternal(ErrorResult& aRv)
 {
   if (!mRuleList) {
     EnsureUniqueInner();
 
     RefPtr<ServoCssRules> rawRules =
       Servo_StyleSheet_GetRules(Inner()->mSheet).Consume();
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -118,18 +118,16 @@ public:
 
   // nsICSSLoaderObserver interface
   NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasAlternate,
                               nsresult aStatus) final;
 
 protected:
   virtual ~ServoStyleSheet();
 
-  void ClearRuleCascadesInternal() override;
-
   ServoStyleSheetInner* Inner() const
   {
     return static_cast<ServoStyleSheetInner*>(mInner);
   }
 
   // Internal methods which do not have security check and completeness check.
   dom::CSSRuleList* GetCssRulesInternal(ErrorResult& aRv);
   uint32_t InsertRuleInternal(const nsAString& aRule,
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -122,25 +122,16 @@ StyleSheet::TraverseInner(nsCycleCollect
   StyleSheet* childSheet = GetFirstChild();
   while (childSheet) {
     NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "child sheet");
     cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, childSheet));
     childSheet = childSheet->mNext;
   }
 }
 
-void
-StyleSheet::ClearRuleCascades()
-{
-  ClearRuleCascadesInternal();
-  if (mParent) {
-    mParent->ClearRuleCascades();
-  }
-}
-
 // QueryInterface implementation for StyleSheet
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(StyleSheet)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver)
   NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet)
 NS_INTERFACE_MAP_END
 
@@ -443,17 +434,24 @@ StyleSheet::EnsureUniqueInner()
   }
 
   StyleSheetInfo* clone = mInner->CloneFor(this);
   MOZ_ASSERT(clone);
   mInner->RemoveSheet(this);
   mInner = clone;
 
   // Ensure we're using the new rules.
-  ClearRuleCascades();
+  //
+  // NOTE: In Servo, all kind of changes that change the set of selectors or
+  // rules we match are covered by the PresShell notifications. In Gecko that's
+  // true too, but this is probably needed because selectors are not refcounted
+  // and can become stale.
+  if (CSSStyleSheet* geckoSheet = GetAsGecko()) {
+    geckoSheet->ClearRuleCascades();
+  }
 
   // let our containing style sets know that if we call
   // nsPresContext::EnsureSafeToHandOutCSSRules we will need to restyle the
   // document
   for (StyleSetHandle& setHandle : mStyleSets) {
     setHandle->SetNeedsRestyleAfterEnsureUniqueInner();
   }
 }
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -283,19 +283,16 @@ protected:
   // Called from SetEnabled when the enabled state changed.
   void EnabledStateChanged();
 
   // Unlink our inner, if needed, for cycle collection
   virtual void UnlinkInner();
   // Traverse our inner, if needed, for cycle collection
   virtual void TraverseInner(nsCycleCollectionTraversalCallback &);
 
-  void ClearRuleCascades();
-  virtual void ClearRuleCascadesInternal() {}
-
   StyleSheet*           mParent;    // weak ref
 
   nsString              mTitle;
   nsIDocument*          mDocument; // weak ref; parents maintain this for their children
   nsINode*              mOwningNode; // weak ref
 
   RefPtr<dom::MediaList> mMedia;