From ddb66e070e2cd3b96354fd5220137d497636ecb3 Mon Sep 17 00:00:00 2001 From: Brad Werth Date: Fri, 7 Apr 2017 08:07:37 -0700 Subject: [PATCH] Bug 1346256 Part 2: Define methods in ServoCSSRuleList to fill a hash of RawServoStyleRule to ServoStyleRule. r=heycam,xidorn MozReview-Commit-ID: 4Swb9KwV0uO --HG-- extra : rebase_source : 496b33bfdeaa4c4715796df6a8baa3fe1b4a9531 --- layout/style/ServoCSSRuleList.cpp | 20 ++++++++++++++++++++ layout/style/ServoCSSRuleList.h | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/layout/style/ServoCSSRuleList.cpp b/layout/style/ServoCSSRuleList.cpp index 590880dda150..dc9c0e050d98 100644 --- a/layout/style/ServoCSSRuleList.cpp +++ b/layout/style/ServoCSSRuleList.cpp @@ -202,6 +202,26 @@ ServoCSSRuleList::GetRuleType(uint32_t aIndex) const 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(GetRule(i)); + RawServoStyleRule* rawRule = castedRule->Raw(); + aTable.Put(rawRule, castedRule); + } else if (type == nsIDOMCSSRule::MEDIA_RULE) { + ServoMediaRule* castedRule = static_cast(GetRule(i)); + + // Call this method recursively on the ServoCSSRuleList in the rule. + ServoCSSRuleList* castedRuleList = static_cast( + castedRule->CssRules()); + castedRuleList->FillStyleRuleHashtable(aTable); + } + } +} + ServoCSSRuleList::~ServoCSSRuleList() { DropAllRules(); diff --git a/layout/style/ServoCSSRuleList.h b/layout/style/ServoCSSRuleList.h index dcc003e68410..9ded5d31ed7d 100644 --- a/layout/style/ServoCSSRuleList.h +++ b/layout/style/ServoCSSRuleList.h @@ -11,9 +11,11 @@ #include "mozilla/ServoBindingTypes.h" #include "mozilla/dom/CSSRuleList.h" +#include "nsDataHashtable.h" namespace mozilla { +class ServoStyleRule; class ServoStyleSheet; namespace css { class GroupRule; @@ -44,6 +46,10 @@ public: uint16_t GetRuleType(uint32_t aIndex) const; + typedef nsDataHashtable, + ServoStyleRule*> StyleRuleHashtable; + void FillStyleRuleHashtable(StyleRuleHashtable& aTable); + private: virtual ~ServoCSSRuleList();