Bug 1346256 Part 2: Define methods in ServoCSSRuleList to fill a hash of RawServoStyleRule to ServoStyleRule.
MozReview-Commit-ID: 4Swb9KwV0uO
--- 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) {