Bug 1352968 part 5 - Add a param to ctor of ServoCSSRuleList for top level list. r=heycam draft
authorXidorn Quan <me@upsuper.org>
Fri, 28 Apr 2017 18:01:33 +0800
changeset 586230 b9b78672249f390d56d71fa46dfa4b4cd49ef182
parent 586229 6b2b471b993f33f9d06af01e4863cd6c5d34ce3a
child 586231 3f7f683b64f42d22a09138cfe01d8ca42d435aa3
push id61334
push userxquan@mozilla.com
push dateTue, 30 May 2017 01:07:29 +0000
reviewersheycam
bugs1352968
milestone55.0a1
Bug 1352968 part 5 - Add a param to ctor of ServoCSSRuleList for top level list. r=heycam @import rules can only exist in top level rule lists, and we need the stylesheet to construct the import rules. MozReview-Commit-ID: APCyGW8re8f
layout/style/GroupRule.h
layout/style/ServoCSSRuleList.cpp
layout/style/ServoCSSRuleList.h
layout/style/ServoStyleSheet.cpp
--- a/layout/style/GroupRule.h
+++ b/layout/style/GroupRule.h
@@ -74,17 +74,17 @@ struct GeckoGroupRuleRules
 
   IncrementalClearCOMRuleArray mRules;
   RefPtr<GroupRuleRuleList> mRuleCollection; // lazily constructed
 };
 
 struct ServoGroupRuleRules
 {
   explicit ServoGroupRuleRules(already_AddRefed<ServoCssRules> aRawRules)
-    : mRuleList(new ServoCSSRuleList(Move(aRawRules))) {}
+    : mRuleList(new ServoCSSRuleList(Move(aRawRules), nullptr)) {}
   ServoGroupRuleRules(ServoGroupRuleRules&& aOther)
     : mRuleList(Move(aOther.mRuleList)) {}
   ServoGroupRuleRules(const ServoGroupRuleRules& aCopy) {
     // Do we ever clone Servo rules?
     MOZ_ASSERT_UNREACHABLE("stylo: Cloning GroupRule not implemented");
   }
 
   void SetParentRule(GroupRule* aParentRule) {
--- a/layout/style/ServoCSSRuleList.cpp
+++ b/layout/style/ServoCSSRuleList.cpp
@@ -17,18 +17,20 @@
 #include "mozilla/ServoPageRule.h"
 #include "mozilla/ServoStyleRule.h"
 #include "mozilla/ServoSupportsRule.h"
 #include "nsCSSCounterStyleRule.h"
 #include "nsCSSFontFaceRule.h"
 
 namespace mozilla {
 
-ServoCSSRuleList::ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules)
-  : mRawRules(aRawRules)
+ServoCSSRuleList::ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules,
+                                   ServoStyleSheet* aDirectOwnerStyleSheet)
+  : mStyleSheet(aDirectOwnerStyleSheet)
+  , mRawRules(aRawRules)
 {
   Servo_CssRules_ListTypes(mRawRules, &mRules);
   // XXX We may want to eagerly create object for import rule, so that
   //     we don't lose the reference to child stylesheet when our own
   //     stylesheet goes away.
 }
 
 // QueryInterface implementation for ServoCSSRuleList
--- a/layout/style/ServoCSSRuleList.h
+++ b/layout/style/ServoCSSRuleList.h
@@ -20,17 +20,22 @@ class ServoStyleSheet;
 namespace css {
 class GroupRule;
 class Rule;
 } // namespace css
 
 class ServoCSSRuleList final : public dom::CSSRuleList
 {
 public:
-  explicit ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules);
+  // @param aDirectOwnerStyleSheet should be set to the owner stylesheet
+  // if this rule list is owned directly by a stylesheet, which means it
+  // is a top level CSSRuleList. If it's owned by a group rule, nullptr.
+  // If this param is set, the caller doesn't need to call SetStyleSheet.
+  ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules,
+                   ServoStyleSheet* aDirectOwnerStyleSheet);
   css::GroupRule* GetParentRule() const { return mParentRule; }
   void SetParentRule(css::GroupRule* aParentRule);
   void SetStyleSheet(StyleSheet* aSheet);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServoCSSRuleList, dom::CSSRuleList)
 
   ServoStyleSheet* GetParentObject() final { return mStyleSheet; }
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -225,18 +225,17 @@ CSSRuleList*
 ServoStyleSheet::GetCssRulesInternal(ErrorResult& aRv)
 {
   if (!mRuleList) {
     EnsureUniqueInner();
 
     RefPtr<ServoCssRules> rawRules =
       Servo_StyleSheet_GetRules(Inner()->mSheet).Consume();
     MOZ_ASSERT(rawRules);
-    mRuleList = new ServoCSSRuleList(rawRules.forget());
-    mRuleList->SetStyleSheet(this);
+    mRuleList = new ServoCSSRuleList(rawRules.forget(), this);
   }
   return mRuleList;
 }
 
 uint32_t
 ServoStyleSheet::InsertRuleInternal(const nsAString& aRule,
                                     uint32_t aIndex, ErrorResult& aRv)
 {