Bug 1339629 Part 5: Change CSSStyleSet::mStyleSets to use StyleSetHandles. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 15 May 2017 15:01:23 -0700
changeset 584199 b064917b8f46a2c0eeb19234f9ed9b1adafb38aa
parent 584198 11076ea2cd177cbd18ec495809069989a442bbe0
child 584200 99c7e529150a679dfb3a8a35ee677773c8083e0c
push id60647
push userbwerth@mozilla.com
push dateThu, 25 May 2017 00:33:14 +0000
bugs1339629
milestone55.0a1
Bug 1339629 Part 5: Change CSSStyleSet::mStyleSets to use StyleSetHandles. MozReview-Commit-ID: 7KFbhh4fCW9
layout/style/CSSStyleSheet.cpp
layout/style/CSSStyleSheet.h
layout/style/StyleSetHandle.h
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -590,18 +590,18 @@ CSSStyleSheet::EnsureUniqueInner()
   StyleSheet::EnsureUniqueInner();
 
   // otherwise the rule processor has pointers to the old rules
   ClearRuleCascades();
 
   // let our containing style sets know that if we call
   // nsPresContext::EnsureSafeToHandOutCSSRules we will need to restyle the
   // document
-  for (nsStyleSet* styleSet : mStyleSets) {
-    styleSet->SetNeedsRestyleAfterEnsureUniqueInner();
+  for (StyleSetHandle setHandle : mStyleSets) {
+    setHandle->AsGecko()->SetNeedsRestyleAfterEnsureUniqueInner();
   }
 }
 
 void
 CSSStyleSheet::AppendAllChildSheets(nsTArray<CSSStyleSheet*>& aArray)
 {
   for (StyleSheet* child = GetFirstChild(); child;
        child = child->mNext) {
@@ -646,18 +646,18 @@ CSSStyleSheet::List(FILE* out, int32_t a
 void 
 CSSStyleSheet::ClearRuleCascades()
 {
   // We might be in ClearRuleCascades 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 (nsStyleSet* styleSet : mStyleSets) {
-    styleSet->ClearSelectors();
+  for (StyleSetHandle setHandle : mStyleSets) {
+    setHandle->AsGecko()->ClearSelectors();
   }
 
   bool removedSheetFromRuleProcessorCache = false;
   if (mRuleProcessors) {
     nsCSSRuleProcessor **iter = mRuleProcessors->Elements(),
                        **end = iter + mRuleProcessors->Length();
     for(; iter != end; ++iter) {
       if (!removedSheetFromRuleProcessorCache && (*iter)->IsShared()) {
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -7,16 +7,17 @@
 /* representation of a CSS style sheet */
 
 #ifndef mozilla_CSSStyleSheet_h
 #define mozilla_CSSStyleSheet_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/IncrementalClearCOMRuleArray.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/StyleSetHandle.h"
 #include "mozilla/StyleSheet.h"
 #include "mozilla/StyleSheetInfo.h"
 #include "mozilla/css/SheetParsingMode.h"
 
 #include "nscore.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsTArrayForwardDeclare.h"
@@ -219,17 +220,17 @@ protected:
 
   css::ImportRule*      mOwnerRule; // weak ref
 
   RefPtr<CSSRuleListImpl> mRuleCollection;
   bool                  mInRuleProcessorCache;
   RefPtr<dom::Element> mScopeElement;
 
   AutoTArray<nsCSSRuleProcessor*, 8>* mRuleProcessors;
-  nsTArray<nsStyleSet*> mStyleSets;
+  nsTArray<StyleSetHandle> mStyleSets;
 
   friend class mozilla::StyleSheet;
   friend class ::nsCSSRuleProcessor;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(CSSStyleSheet, NS_CSS_STYLE_SHEET_IMPL_CID)
 
 } // namespace mozilla
--- a/layout/style/StyleSetHandle.h
+++ b/layout/style/StyleSetHandle.h
@@ -210,16 +210,21 @@ public:
     MOZ_CRASH("should not have a ServoStyleSet object when MOZ_STYLO is "
               "disabled");
 #endif
   }
 
   // Make StyleSetHandle usable in boolean contexts.
   explicit operator bool() const { return !!mPtr.mValue; }
   bool operator!() const { return !mPtr.mValue; }
+  bool operator==(const StyleSetHandle& aOth) const
+  {
+    return mPtr.mValue == aOth.mPtr.mValue;
+  }
+  bool operator!=(const StyleSetHandle& aOth) const { return !(*this == aOth); }
 
   // Make StyleSetHandle behave like a smart pointer.
   Ptr* operator->() { return &mPtr; }
   const Ptr* operator->() const { return &mPtr; }
 
 private:
   Ptr mPtr;
 };