Bug 1315601 part 11 - Add Servo support to GroupRule. r=heycam draft
authorXidorn Quan <me@upsuper.org>
Thu, 09 Mar 2017 20:52:26 +1100
changeset 497347 a1ecece1115d08e3c377d8eb1bcd8f7e34957dc2
parent 497346 a51c88fd19cf85376a52b4c61b3bd84df6356dab
child 497348 39815c7f1c4ab65b32fa5b41c4231c3e76661628
push id48869
push userxquan@mozilla.com
push dateMon, 13 Mar 2017 06:50:23 +0000
reviewersheycam
bugs1315601
milestone55.0a1
Bug 1315601 part 11 - Add Servo support to GroupRule. r=heycam MozReview-Commit-ID: HLYRz0hsFWc
layout/style/GroupRule.cpp
layout/style/GroupRule.h
--- a/layout/style/GroupRule.cpp
+++ b/layout/style/GroupRule.cpp
@@ -13,21 +13,20 @@
 
 #include "mozilla/dom/CSSRuleList.h"
 
 using namespace mozilla::dom;
 
 namespace mozilla {
 namespace css {
 
-// TODO The other branch should be changed to Servo rule.
 #define CALL_INNER(inner_, call_)               \
   ((inner_).is<GeckoGroupRuleRules>()           \
     ? (inner_).as<GeckoGroupRuleRules>().call_  \
-    : (inner_).as<GeckoGroupRuleRules>().call_)
+    : (inner_).as<ServoGroupRuleRules>().call_)
 
 // -------------------------------
 // Style Rule List for group rules
 //
 
 class GroupRuleRuleList final : public dom::CSSRuleList
 {
 public:
@@ -191,16 +190,35 @@ GeckoGroupRuleRules::SizeOfExcludingThis
 
   // Measurement of the following members may be added later if DMD finds it is
   // worthwhile:
   // - mRuleCollection
   return n;
 }
 
 // -------------------------------
+// ServoGroupRuleRules
+//
+
+#ifdef DEBUG
+void
+ServoGroupRuleRules::List(FILE* out, int32_t aIndent) const
+{
+  // TODO list something reasonable?
+}
+#endif
+
+size_t
+ServoGroupRuleRules::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  // TODO how to implement?
+  return 0;
+}
+
+// -------------------------------
 // GroupRule
 //
 
 GroupRule::GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber)
   : Rule(aLineNumber, aColumnNumber)
   , mInner(GeckoGroupRuleRules())
 {
 }
--- a/layout/style/GroupRule.h
+++ b/layout/style/GroupRule.h
@@ -10,16 +10,17 @@
 
 #ifndef mozilla_css_GroupRule_h__
 #define mozilla_css_GroupRule_h__
 
 #include "mozilla/Attributes.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/IncrementalClearCOMRuleArray.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/ServoCSSRuleList.h"
 #include "mozilla/Variant.h"
 #include "mozilla/css/Rule.h"
 #include "nsCycleCollectionParticipant.h"
 
 class nsPresContext;
 class nsMediaQueryResultCacheKey;
 
 namespace mozilla {
@@ -70,18 +71,72 @@ struct GeckoGroupRuleRules
   dom::CSSRuleList* CssRules(GroupRule* aParentRule);
 
   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
 
   IncrementalClearCOMRuleArray mRules;
   RefPtr<GroupRuleRuleList> mRuleCollection; // lazily constructed
 };
 
-#define REDIRECT_TO_INNER(call_) \
-  return mInner.as<GeckoGroupRuleRules>().call_;
+struct ServoGroupRuleRules
+{
+  explicit ServoGroupRuleRules(already_AddRefed<ServoCssRules> aRawRules)
+    : mRuleList(new ServoCSSRuleList(Move(aRawRules))) {}
+  ServoGroupRuleRules(const ServoGroupRuleRules& aCopy) {
+    // Do we ever clone Servo rules?
+    MOZ_ASSERT_UNREACHABLE("stylo: Cloning GroupRule not implemented");
+  }
+
+  void SetParentRule(GroupRule* aParentRule) {
+    if (mRuleList) {
+      mRuleList->SetParentRule(aParentRule);
+    }
+  }
+  void SetStyleSheet(StyleSheet* aSheet) {
+    if (mRuleList) {
+      mRuleList->SetStyleSheet(aSheet);
+    }
+  }
+
+  void Clear() {
+    mRuleList->DropReference();
+    mRuleList = nullptr;
+  }
+  void Traverse(nsCycleCollectionTraversalCallback& cb) {
+    ImplCycleCollectionTraverse(cb, mRuleList, "mRuleList");
+  }
+
+#ifdef DEBUG
+  void List(FILE* out, int32_t aIndent) const;
+#endif
+
+  int32_t StyleRuleCount() const { return mRuleList->Length(); }
+  Rule* GetStyleRuleAt(int32_t aIndex) const {
+    return mRuleList->GetRule(aIndex);
+  }
+
+  nsresult DeleteStyleRuleAt(uint32_t aIndex) {
+    return mRuleList->DeleteRule(aIndex);
+  }
+
+  dom::CSSRuleList* CssRules(GroupRule* aParentRule) {
+    return mRuleList;
+  }
+
+  size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
+
+  RefPtr<ServoCSSRuleList> mRuleList;
+};
+
+#define REDIRECT_TO_INNER(call_)                   \
+  if (mInner.is<GeckoGroupRuleRules>()) {          \
+    return mInner.as<GeckoGroupRuleRules>().call_; \
+  } else {                                         \
+    return mInner.as<ServoGroupRuleRules>().call_; \
+  }                                                \
 
 // inherits from Rule so it can be shared between
 // MediaRule and DocumentRule
 class GroupRule : public Rule
 {
 protected:
   GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber);
   GroupRule(const GroupRule& aCopy);
@@ -152,17 +207,17 @@ protected:
   IncrementalClearCOMRuleArray& GeckoRules() {
     return mInner.as<GeckoGroupRuleRules>().mRules;
   }
   const IncrementalClearCOMRuleArray& GeckoRules() const {
     return mInner.as<GeckoGroupRuleRules>().mRules;
   }
 
 private:
-  Variant<GeckoGroupRuleRules> mInner;
+  Variant<GeckoGroupRuleRules, ServoGroupRuleRules> mInner;
 };
 
 #undef REDIRECT_TO_INNER
 
 // Implementation of WebIDL CSSConditionRule.
 class ConditionRule : public GroupRule
 {
 protected: