Bug 1352968 part 5 - Add a param to ctor of ServoCSSRuleList for top level list. r=heycam
@import rules can only exist in top level rule lists, and we need the
stylesheet to construct the import rules.
MozReview-Commit-ID: APCyGW8re8f
--- a/layout/style/GroupRule.h
+++ b/layout/style/GroupRule.h
@@ -74,17 +74,17 @@ struct GeckoGroupRuleRules
IncrementalClearCOMRuleArray mRules;
RefPtr<GroupRuleRuleList> mRuleCollection; // lazily constructed
};
struct ServoGroupRuleRules
{
explicit ServoGroupRuleRules(already_AddRefed<ServoCssRules> aRawRules)
- : mRuleList(new ServoCSSRuleList(Move(aRawRules))) {}
+ : mRuleList(new ServoCSSRuleList(Move(aRawRules), nullptr)) {}
ServoGroupRuleRules(ServoGroupRuleRules&& aOther)
: mRuleList(Move(aOther.mRuleList)) {}
ServoGroupRuleRules(const ServoGroupRuleRules& aCopy) {
// Do we ever clone Servo rules?
MOZ_ASSERT_UNREACHABLE("stylo: Cloning GroupRule not implemented");
}
void SetParentRule(GroupRule* aParentRule) {
--- a/layout/style/ServoCSSRuleList.cpp
+++ b/layout/style/ServoCSSRuleList.cpp
@@ -17,18 +17,20 @@
#include "mozilla/ServoPageRule.h"
#include "mozilla/ServoStyleRule.h"
#include "mozilla/ServoSupportsRule.h"
#include "nsCSSCounterStyleRule.h"
#include "nsCSSFontFaceRule.h"
namespace mozilla {
-ServoCSSRuleList::ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules)
- : mRawRules(aRawRules)
+ServoCSSRuleList::ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules,
+ ServoStyleSheet* aDirectOwnerStyleSheet)
+ : mStyleSheet(aDirectOwnerStyleSheet)
+ , mRawRules(aRawRules)
{
Servo_CssRules_ListTypes(mRawRules, &mRules);
// XXX We may want to eagerly create object for import rule, so that
// we don't lose the reference to child stylesheet when our own
// stylesheet goes away.
}
// QueryInterface implementation for ServoCSSRuleList
--- a/layout/style/ServoCSSRuleList.h
+++ b/layout/style/ServoCSSRuleList.h
@@ -20,17 +20,22 @@ class ServoStyleSheet;
namespace css {
class GroupRule;
class Rule;
} // namespace css
class ServoCSSRuleList final : public dom::CSSRuleList
{
public:
- explicit ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules);
+ // @param aDirectOwnerStyleSheet should be set to the owner stylesheet
+ // if this rule list is owned directly by a stylesheet, which means it
+ // is a top level CSSRuleList. If it's owned by a group rule, nullptr.
+ // If this param is set, the caller doesn't need to call SetStyleSheet.
+ ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules,
+ ServoStyleSheet* aDirectOwnerStyleSheet);
css::GroupRule* GetParentRule() const { return mParentRule; }
void SetParentRule(css::GroupRule* aParentRule);
void SetStyleSheet(StyleSheet* aSheet);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServoCSSRuleList, dom::CSSRuleList)
ServoStyleSheet* GetParentObject() final { return mStyleSheet; }
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -225,18 +225,17 @@ CSSRuleList*
ServoStyleSheet::GetCssRulesInternal(ErrorResult& aRv)
{
if (!mRuleList) {
EnsureUniqueInner();
RefPtr<ServoCssRules> rawRules =
Servo_StyleSheet_GetRules(Inner()->mSheet).Consume();
MOZ_ASSERT(rawRules);
- mRuleList = new ServoCSSRuleList(rawRules.forget());
- mRuleList->SetStyleSheet(this);
+ mRuleList = new ServoCSSRuleList(rawRules.forget(), this);
}
return mRuleList;
}
uint32_t
ServoStyleSheet::InsertRuleInternal(const nsAString& aRule,
uint32_t aIndex, ErrorResult& aRv)
{