Bug 1346256 Part 2: Define methods in ServoCSSRuleList to fill a hash of RawServoStyleRule to ServoStyleRule. draft
authorBrad Werth <bwerth@mozilla.com>
Fri, 07 Apr 2017 08:07:37 -0700
changeset 559517 1e1145bb4ee21a6d4564ace4930eb97bba86a291
parent 559516 26a0885cb6133ccebabfcffa1321fb9d9eb9d228
child 559518 b54ea57f2786c953bbcf1cab41aa823ef6f44adf
push id53118
push userbwerth@mozilla.com
push dateMon, 10 Apr 2017 08:18:55 +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,34 @@ ServoCSSRuleList::GetRuleType(uint32_t a
 {
   uintptr_t rule = mRules[aIndex];
   if (rule <= kMaxRuleType) {
     return rule;
   }
   return CastToPtr(rule)->Type();
 }
 
+void
+ServoCSSRuleList::FillStyleRuleHashtable(StyleRuleHashtable& aTable)
+{
+  for (uint32_t i = 0; i < mRules.Length(); i++) {
+    uint16_t type = GetRuleType(i);
+    if (type == nsIDOMCSSRule::STYLE_RULE) {
+      ServoStyleRule* castedRule = static_cast<ServoStyleRule*>(GetRule(i));
+      RawServoStyleRule* rawRule = castedRule->Raw();
+      aTable.Put(rawRule, castedRule);
+    } else if (type == nsIDOMCSSRule::MEDIA_RULE) {
+      ServoMediaRule* castedRule = static_cast<ServoMediaRule*>(GetRule(i));
+
+      // Call this method recursively on the ServoCSSRuleList in the rule.
+      ServoCSSRuleList* castedRuleList = static_cast<ServoCSSRuleList*>(
+        castedRule->CssRules());
+      castedRuleList->FillStyleRuleHashtable(aTable);
+    }
+  }
+}
+
 ServoCSSRuleList::~ServoCSSRuleList()
 {
   DropAllRules();
 }
 
 } // namespace mozilla
--- a/layout/style/ServoCSSRuleList.h
+++ b/layout/style/ServoCSSRuleList.h
@@ -6,19 +6,21 @@
 
 /* representation of CSSRuleList for stylo */
 
 #ifndef mozilla_ServoCSSRuleList_h
 #define mozilla_ServoCSSRuleList_h
 
 #include "mozilla/ServoBindingTypes.h"
 #include "mozilla/dom/CSSRuleList.h"
+#include "nsDataHashtable.h"
 
 namespace mozilla {
 
+class ServoStyleRule;
 class ServoStyleSheet;
 namespace css {
 class GroupRule;
 class Rule;
 } // namespace css
 
 class ServoCSSRuleList final : public dom::CSSRuleList
 {
@@ -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 nsDataHashtable<nsPtrHashKey<const RawServoStyleRule>,
+                          ServoStyleRule*> StyleRuleHashtable;
+  void FillStyleRuleHashtable(StyleRuleHashtable& aTable);
+
 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) {