Bug 1346256 Part 2: Define methods in ServoCSSRuleList to fill a hash of RawServoStyleRule to ServoStyleRule. draft
authorBrad Werth <bwerth@mozilla.com>
Wed, 05 Apr 2017 15:44:14 -0700
changeset 556476 0f8b7b1a6534ea66ce85de57dfa1c7e29c752d7b
parent 556475 51d843ba5b12ce574ddfda84b88dd1541d5ebeda
child 556477 f780f05dc4489db79d7dfb2062163136f8748fb9
push id52559
push userbwerth@mozilla.com
push dateWed, 05 Apr 2017 22:55:45 +0000
bugs1346256
milestone55.0a1
Bug 1346256 Part 2: Define methods in ServoCSSRuleList to fill a hash of RawServoStyleRule to ServoStyleRule. MozReview-Commit-ID: 4Swb9KwV0uO
layout/style/ServoCSSRuleList.cpp
layout/style/ServoCSSRuleList.h
--- a/layout/style/ServoCSSRuleList.cpp
+++ b/layout/style/ServoCSSRuleList.cpp
@@ -197,14 +197,36 @@ ServoCSSRuleList::GetRuleType(uint32_t a
 {
   uintptr_t rule = mRules[aIndex];
   if (rule <= kMaxRuleType) {
     return rule;
   }
   return CastToPtr(rule)->Type();
 }
 
+void
+ServoCSSRuleList::FillStyleRuleHashtable(StyleRuleHashtable &table)
+{
+  for (uint32_t i = 0; i < mRules.Length(); i++) {
+    uint16_t type = GetRuleType(i);
+    if (type == nsIDOMCSSRule::STYLE_RULE) {
+      ServoStyleRule* castedRule = (ServoStyleRule*)(GetRule(i));
+      RawServoStyleRule* rawRule = castedRule->Raw();
+      table.Put(rawRule, castedRule);
+    } else if (type == nsIDOMCSSRule::MEDIA_RULE) {
+      ServoMediaRule* castedRule = (ServoMediaRule*)(GetRule(i));
+
+      // Call this method recursively on the ServoCSSRuleList in the rule.
+      nsCOMPtr<nsIDOMCSSRuleList> ruleList;
+      castedRule->GetCssRules(getter_AddRefs(ruleList));
+
+      ServoCSSRuleList* castedRuleList = (ServoCSSRuleList*)(ruleList.get());
+      castedRuleList->FillStyleRuleHashtable(table);
+    }
+  }
+}
+
 ServoCSSRuleList::~ServoCSSRuleList()
 {
   DropAllRules();
 }
 
 } // namespace mozilla
--- a/layout/style/ServoCSSRuleList.h
+++ b/layout/style/ServoCSSRuleList.h
@@ -6,20 +6,22 @@
 
 /* representation of CSSRuleList for stylo */
 
 #ifndef mozilla_ServoCSSRuleList_h
 #define mozilla_ServoCSSRuleList_h
 
 #include "mozilla/ServoBindingTypes.h"
 #include "mozilla/dom/CSSRuleList.h"
+#include "nsRefPtrHashtable.h"
 
 namespace mozilla {
 
 class ServoStyleSheet;
+class ServoStyleRule;
 namespace css {
 class GroupRule;
 class Rule;
 } // namespace css
 
 class ServoCSSRuleList final : public dom::CSSRuleList
 {
 public:
@@ -39,16 +41,20 @@ public:
   void DropReference();
 
   css::Rule* GetRule(uint32_t aIndex);
   nsresult InsertRule(const nsAString& aRule, uint32_t aIndex);
   nsresult DeleteRule(uint32_t aIndex);
 
   uint16_t GetRuleType(uint32_t aIndex) const;
 
+  typedef nsRefPtrHashtable<nsPtrHashKey<const RawServoStyleRule>,
+    ServoStyleRule> StyleRuleHashtable;
+  void FillStyleRuleHashtable(StyleRuleHashtable &table);
+
 private:
   virtual ~ServoCSSRuleList();
 
   // XXX Is it possible to have an address lower than or equal to 255?
   //     Is it possible to have more than 255 CSS rule types?
   static const uintptr_t kMaxRuleType = UINT8_MAX;
 
   static uintptr_t CastToUint(css::Rule* aPtr) {