diff --git a/dom/webidl/CSSImportRule.webidl b/dom/webidl/CSSImportRule.webidl index 27ad5e804329..f54faf7ce140 100644 --- a/dom/webidl/CSSImportRule.webidl +++ b/dom/webidl/CSSImportRule.webidl @@ -17,5 +17,5 @@ interface CSSImportRule : CSSRule { [SameObject, PutForwards=mediaText] readonly attribute MediaList? media; // Per spec, the .styleSheet is never null, but in our implementation it can // be. See . - [SameObject, BinaryName="styleSheetForBindings"] readonly attribute CSSStyleSheet? styleSheet; + [SameObject] readonly attribute CSSStyleSheet? styleSheet; }; diff --git a/layout/inspector/ServoStyleRuleMap.cpp b/layout/inspector/ServoStyleRuleMap.cpp index 3683cecf11df..8d2ac11a6a16 100644 --- a/layout/inspector/ServoStyleRuleMap.cpp +++ b/layout/inspector/ServoStyleRuleMap.cpp @@ -45,12 +45,6 @@ void ServoStyleRuleMap::SheetAdded(StyleSheet& aStyleSheet) { } } -void ServoStyleRuleMap::SheetCloned(StyleSheet& aStyleSheet) { - // Invalidate all data inside. We could probably track down all the individual - // rules that changed etc, but it doesn't seem worth it. - mTable.Clear(); -} - void ServoStyleRuleMap::SheetRemoved(StyleSheet& aStyleSheet) { // Invalidate all data inside. This isn't strictly necessary since // we should always get update from document before new queries come. diff --git a/layout/inspector/ServoStyleRuleMap.h b/layout/inspector/ServoStyleRuleMap.h index 523f1fa6a152..7e10ef44734c 100644 --- a/layout/inspector/ServoStyleRuleMap.h +++ b/layout/inspector/ServoStyleRuleMap.h @@ -36,7 +36,6 @@ class ServoStyleRuleMap { void SheetAdded(StyleSheet&); void SheetRemoved(StyleSheet&); - void SheetCloned(StyleSheet&); void RuleAdded(StyleSheet& aStyleSheet, css::Rule&); void RuleRemoved(StyleSheet& aStyleSheet, css::Rule&); diff --git a/layout/style/CSSCounterStyleRule.cpp b/layout/style/CSSCounterStyleRule.cpp index 0a44146cd765..531988aa725b 100644 --- a/layout/style/CSSCounterStyleRule.cpp +++ b/layout/style/CSSCounterStyleRule.cpp @@ -31,11 +31,6 @@ uint16_t CSSCounterStyleRule::Type() const { return CSSRule_Binding::COUNTER_STYLE_RULE; } -void CSSCounterStyleRule::SetRawAfterClone( - RefPtr aRaw) { - mRawRule = std::move(aRaw); -} - void CSSCounterStyleRule::GetCssText(nsACString& aCssText) const { Servo_CounterStyleRule_GetCssText(mRawRule, &aCssText); } @@ -47,27 +42,16 @@ void CSSCounterStyleRule::GetName(nsAString& aName) { nsStyleUtil::AppendEscapedCSSIdent(nameStr, aName); } -template -void CSSCounterStyleRule::ModifyRule(Func aCallback) { +void CSSCounterStyleRule::SetName(const nsAString& aName) { if (IsReadOnly()) { return; } - - StyleSheet* sheet = GetStyleSheet(); - if (sheet) { - sheet->WillDirty(); + NS_ConvertUTF16toUTF8 name(aName); + if (Servo_CounterStyleRule_SetName(mRawRule, &name)) { + if (StyleSheet* sheet = GetStyleSheet()) { + sheet->RuleChanged(this, StyleRuleChangeKind::Generic); + } } - - if (aCallback() && sheet) { - sheet->RuleChanged(this, StyleRuleChangeKind::Generic); - } -} - -void CSSCounterStyleRule::SetName(const nsAString& aName) { - ModifyRule([&] { - NS_ConvertUTF16toUTF8 name(aName); - return Servo_CounterStyleRule_SetName(mRawRule, &name); - }); } #define CSS_COUNTER_DESC(name_, method_) \ @@ -77,10 +61,15 @@ void CSSCounterStyleRule::SetName(const nsAString& aName) { mRawRule, eCSSCounterDesc_##method_, &aValue); \ } \ void CSSCounterStyleRule::Set##method_(const nsACString& aValue) { \ - ModifyRule([&] { \ - return Servo_CounterStyleRule_SetDescriptor( \ - mRawRule, eCSSCounterDesc_##method_, &aValue); \ - }); \ + if (IsReadOnly()) { \ + return; \ + } \ + if (Servo_CounterStyleRule_SetDescriptor( \ + mRawRule, eCSSCounterDesc_##method_, &aValue)) { \ + if (StyleSheet* sheet = GetStyleSheet()) { \ + sheet->RuleChanged(this, StyleRuleChangeKind::Generic); \ + } \ + } \ } #include "nsCSSCounterDescList.h" #undef CSS_COUNTER_DESC diff --git a/layout/style/CSSCounterStyleRule.h b/layout/style/CSSCounterStyleRule.h index f546f857a7d3..4020adf5c25a 100644 --- a/layout/style/CSSCounterStyleRule.h +++ b/layout/style/CSSCounterStyleRule.h @@ -27,14 +27,10 @@ class CSSCounterStyleRule final : public css::Rule { CSSCounterStyleRule(const CSSCounterStyleRule& aCopy) = delete; ~CSSCounterStyleRule() = default; - template - void ModifyRule(Func); - public: bool IsCCLeaf() const final; const RawServoCounterStyleRule* Raw() const { return mRawRule.get(); } - void SetRawAfterClone(RefPtr); #ifdef DEBUG void List(FILE* out = stdout, int32_t aIndent = 0) const final; diff --git a/layout/style/CSSFontFaceRule.cpp b/layout/style/CSSFontFaceRule.cpp index 6f6f546d316b..3287e7f54139 100644 --- a/layout/style/CSSFontFaceRule.cpp +++ b/layout/style/CSSFontFaceRule.cpp @@ -34,10 +34,6 @@ NS_INTERFACE_MAP_END NS_IMPL_ADDREF_USING_AGGREGATOR(CSSFontFaceRuleDecl, ContainingRule()) NS_IMPL_RELEASE_USING_AGGREGATOR(CSSFontFaceRuleDecl, ContainingRule()) -void CSSFontFaceRuleDecl::SetRawAfterClone(RefPtr aRaw) { - mRawRule = std::move(aRaw); -} - // helper for string GetPropertyValue and RemovePropertyValue void CSSFontFaceRuleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID, nsACString& aResult) const { @@ -201,10 +197,6 @@ uint16_t CSSFontFaceRule::Type() const { return CSSRule_Binding::FONT_FACE_RULE; } -void CSSFontFaceRule::SetRawAfterClone(RefPtr aRaw) { - mDecl.SetRawAfterClone(std::move(aRaw)); -} - void CSSFontFaceRule::GetCssText(nsACString& aCssText) const { aCssText.Truncate(); Servo_FontFaceRule_GetCssText(Raw(), &aCssText); diff --git a/layout/style/CSSFontFaceRule.h b/layout/style/CSSFontFaceRule.h index 0db74a949a99..d78e6bef090e 100644 --- a/layout/style/CSSFontFaceRule.h +++ b/layout/style/CSSFontFaceRule.h @@ -43,7 +43,6 @@ class CSSFontFaceRuleDecl final : public nsICSSDeclaration { inline const CSSFontFaceRule* ContainingRule() const; RefPtr mRawRule; - void SetRawAfterClone(RefPtr); private: void* operator new(size_t size) noexcept(true) = delete; @@ -65,7 +64,6 @@ class CSSFontFaceRule final : public css::Rule { bool IsCCLeaf() const final; RawServoFontFaceRule* Raw() const { return mDecl.mRawRule; } - void SetRawAfterClone(RefPtr); // WebIDL interface uint16_t Type() const final; diff --git a/layout/style/CSSFontFeatureValuesRule.cpp b/layout/style/CSSFontFeatureValuesRule.cpp index b4526e7924a3..5af4c3d444cd 100644 --- a/layout/style/CSSFontFeatureValuesRule.cpp +++ b/layout/style/CSSFontFeatureValuesRule.cpp @@ -28,11 +28,6 @@ void CSSFontFeatureValuesRule::List(FILE* out, int32_t aIndent) const { } #endif -void CSSFontFeatureValuesRule::SetRawAfterClone( - RefPtr aRaw) { - mRawRule = std::move(aRaw); -} - /* CSSRule implementation */ void CSSFontFeatureValuesRule::GetCssText(nsACString& aCssText) const { diff --git a/layout/style/CSSFontFeatureValuesRule.h b/layout/style/CSSFontFeatureValuesRule.h index dec9e91bfbde..7cfe295466a8 100644 --- a/layout/style/CSSFontFeatureValuesRule.h +++ b/layout/style/CSSFontFeatureValuesRule.h @@ -26,7 +26,6 @@ class CSSFontFeatureValuesRule final : public css::Rule { virtual bool IsCCLeaf() const override; RawServoFontFeatureValuesRule* Raw() const { return mRawRule; } - void SetRawAfterClone(RefPtr aRaw); // WebIDL interfaces uint16_t Type() const final { diff --git a/layout/style/CSSImportRule.cpp b/layout/style/CSSImportRule.cpp index fc13842e65a5..4e7c438942b6 100644 --- a/layout/style/CSSImportRule.cpp +++ b/layout/style/CSSImportRule.cpp @@ -71,28 +71,9 @@ void CSSImportRule::List(FILE* out, int32_t aIndent) const { } #endif -void CSSImportRule::SetRawAfterClone(RefPtr aRaw) { - mRawRule = std::move(aRaw); - mChildSheet = - const_cast(Servo_ImportRule_GetSheet(mRawRule.get())); -} - -StyleSheet* CSSImportRule::GetStyleSheetForBindings() { - // FIXME(emilio): This is needed to make sure we don't expose shared sheets to - // the OM (see wpt /css/cssom/cssimportrule-sheet-identity.html for example). - // - // Perhaps instead we could create a clone of the stylesheet and keep it in - // mChildSheet, without calling EnsureUniqueInner(), or something like that? - if (StyleSheet* parent = GetParentStyleSheet()) { - parent->EnsureUniqueInner(); - } - return mChildSheet; -} - -dom::MediaList* CSSImportRule::GetMedia() { - auto* sheet = GetStyleSheetForBindings(); +dom::MediaList* CSSImportRule::GetMedia() const { // When Bug 1326509 is fixed, we can assert mChildSheet instead. - return sheet ? sheet->Media() : nullptr; + return mChildSheet ? mChildSheet->Media() : nullptr; } void CSSImportRule::DropSheetReference() { diff --git a/layout/style/CSSImportRule.h b/layout/style/CSSImportRule.h index 99b7483fed0d..8732b81af389 100644 --- a/layout/style/CSSImportRule.h +++ b/layout/style/CSSImportRule.h @@ -35,9 +35,8 @@ class CSSImportRule final : public css::Rule { uint16_t Type() const final { return CSSRule_Binding::IMPORT_RULE; } void GetCssText(nsACString& aCssText) const override; void GetHref(nsAString& aHref) const; - dom::MediaList* GetMedia(); + dom::MediaList* GetMedia() const; StyleSheet* GetStyleSheet() const { return mChildSheet; } - StyleSheet* GetStyleSheetForBindings(); // Clear the mSheet pointer on this rule and descendants. void DropSheetReference() final; @@ -46,7 +45,6 @@ class CSSImportRule final : public css::Rule { JS::Handle aGivenProto) override; const RawServoImportRule* Raw() const { return mRawRule.get(); } - void SetRawAfterClone(RefPtr); private: ~CSSImportRule(); diff --git a/layout/style/CSSKeyframeRule.cpp b/layout/style/CSSKeyframeRule.cpp index 34e450c9e649..d1a5c0b6348e 100644 --- a/layout/style/CSSKeyframeRule.cpp +++ b/layout/style/CSSKeyframeRule.cpp @@ -22,7 +22,6 @@ class CSSKeyframeDeclaration : public nsDOMCSSDeclaration { explicit CSSKeyframeDeclaration(CSSKeyframeRule* aRule) : mRule(aRule) { mDecls = new DeclarationBlock(Servo_Keyframe_GetStyle(aRule->Raw()).Consume()); - mDecls->SetOwningRule(aRule); } NS_DECL_CYCLE_COLLECTING_ISUPPORTS @@ -38,11 +37,6 @@ class CSSKeyframeDeclaration : public nsDOMCSSDeclaration { DeclarationBlock* GetOrCreateCSSDeclaration( Operation aOperation, DeclarationBlock** aCreated) final { - if (aOperation != Operation::Read && mRule) { - if (StyleSheet* sheet = mRule->GetStyleSheet()) { - sheet->WillDirty(); - } - } return mDecls; } nsresult SetCSSDeclaration(DeclarationBlock* aDecls, @@ -80,12 +74,6 @@ class CSSKeyframeDeclaration : public nsDOMCSSDeclaration { return n; } - void SetRawAfterClone(RawServoKeyframe* aKeyframe) { - mDecls->SetOwningRule(nullptr); - mDecls = new DeclarationBlock(Servo_Keyframe_GetStyle(aKeyframe).Consume()); - mDecls->SetOwningRule(mRule); - } - private: virtual ~CSSKeyframeDeclaration() { MOZ_ASSERT(!mRule, "Backpointer should have been cleared"); @@ -142,14 +130,6 @@ bool CSSKeyframeRule::IsCCLeaf() const { return Rule::IsCCLeaf() && !mDeclaration; } -void CSSKeyframeRule::SetRawAfterClone(RefPtr aRaw) { - mRaw = std::move(aRaw); - - if (mDeclaration) { - mDeclaration->SetRawAfterClone(mRaw); - } -} - #ifdef DEBUG /* virtual */ void CSSKeyframeRule::List(FILE* out, int32_t aIndent) const { @@ -168,14 +148,9 @@ void CSSKeyframeRule::UpdateRule(Func aCallback) { return; } - StyleSheet* sheet = GetStyleSheet(); - if (sheet) { - sheet->WillDirty(); - } - aCallback(); - if (sheet) { + if (StyleSheet* sheet = GetStyleSheet()) { sheet->RuleChanged(this, StyleRuleChangeKind::Generic); } } diff --git a/layout/style/CSSKeyframeRule.h b/layout/style/CSSKeyframeRule.h index e97594fc6a78..2149576d8d4f 100644 --- a/layout/style/CSSKeyframeRule.h +++ b/layout/style/CSSKeyframeRule.h @@ -32,7 +32,6 @@ class CSSKeyframeRule final : public css::Rule { #endif RawServoKeyframe* Raw() const { return mRaw; } - void SetRawAfterClone(RefPtr); // WebIDL interface uint16_t Type() const final { return CSSRule_Binding::KEYFRAME_RULE; } diff --git a/layout/style/CSSKeyframesRule.cpp b/layout/style/CSSKeyframesRule.cpp index cd6801baf4cd..5a73700d41d7 100644 --- a/layout/style/CSSKeyframesRule.cpp +++ b/layout/style/CSSKeyframesRule.cpp @@ -31,22 +31,6 @@ class CSSKeyframeList : public dom::CSSRuleList { NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CSSKeyframeList, dom::CSSRuleList) - void SetRawAfterClone(RefPtr aRaw) { - mRawRule = std::move(aRaw); - uint32_t index = 0; - for (css::Rule* rule : mRules) { - if (rule) { - uint32_t line = 0, column = 0; - RefPtr keyframe = - Servo_KeyframesRule_GetKeyframeAt(mRawRule, index, &line, &column) - .Consume(); - static_cast(rule)->SetRawAfterClone( - std::move(keyframe)); - } - index++; - } - } - void DropSheetReference() { if (!mStyleSheet) { return; @@ -207,13 +191,6 @@ bool CSSKeyframesRule::IsCCLeaf() const { return Rule::IsCCLeaf() && !mKeyframeList; } -void CSSKeyframesRule::SetRawAfterClone(RefPtr aRaw) { - mRawRule = std::move(aRaw); - if (mKeyframeList) { - mKeyframeList->SetRawAfterClone(mRawRule); - } -} - #ifdef DEBUG /* virtual */ void CSSKeyframesRule::List(FILE* out, int32_t aIndent) const { @@ -247,14 +224,8 @@ nsresult CSSKeyframesRule::UpdateRule(Func aCallback) { return NS_OK; } - StyleSheet* sheet = GetStyleSheet(); - if (sheet) { - sheet->WillDirty(); - } - aCallback(); - - if (sheet) { + if (StyleSheet* sheet = GetStyleSheet()) { sheet->RuleChanged(this, StyleRuleChangeKind::Generic); } diff --git a/layout/style/CSSKeyframesRule.h b/layout/style/CSSKeyframesRule.h index e9b783163465..95829455545d 100644 --- a/layout/style/CSSKeyframesRule.h +++ b/layout/style/CSSKeyframesRule.h @@ -34,7 +34,6 @@ class CSSKeyframesRule final : public css::Rule { // WebIDL interface uint16_t Type() const final { return CSSRule_Binding::KEYFRAMES_RULE; } const RawServoKeyframesRule* Raw() const { return mRawRule.get(); } - void SetRawAfterClone(RefPtr); void GetCssText(nsACString& aCssText) const final; void GetName(nsAString& aName) const; diff --git a/layout/style/CSSMediaRule.cpp b/layout/style/CSSMediaRule.cpp index 953677b9536f..8389663923ea 100644 --- a/layout/style/CSSMediaRule.cpp +++ b/layout/style/CSSMediaRule.cpp @@ -56,15 +56,6 @@ void CSSMediaRule::DropSheetReference() { ConditionRule::DropSheetReference(); } -void CSSMediaRule::SetRawAfterClone(RefPtr aRaw) { - mRawRule = std::move(aRaw); - if (mMediaList) { - mMediaList->SetRawAfterClone(Servo_MediaRule_GetMedia(mRawRule).Consume()); - } - css::ConditionRule::SetRawAfterClone( - Servo_MediaRule_GetRules(mRawRule).Consume()); -} - #ifdef DEBUG /* virtual */ void CSSMediaRule::List(FILE* out, int32_t aIndent) const { diff --git a/layout/style/CSSMediaRule.h b/layout/style/CSSMediaRule.h index 2b097d276bc9..4b21239ac1dd 100644 --- a/layout/style/CSSMediaRule.h +++ b/layout/style/CSSMediaRule.h @@ -28,7 +28,6 @@ class CSSMediaRule final : public css::ConditionRule { #endif RawServoMediaRule* Raw() const { return mRawRule; } - void SetRawAfterClone(RefPtr); // WebIDL interface uint16_t Type() const override { return CSSRule_Binding::MEDIA_RULE; } diff --git a/layout/style/CSSMozDocumentRule.cpp b/layout/style/CSSMozDocumentRule.cpp index e31377fa3f05..145fe706ab70 100644 --- a/layout/style/CSSMozDocumentRule.cpp +++ b/layout/style/CSSMozDocumentRule.cpp @@ -108,13 +108,6 @@ void CSSMozDocumentRule::List(FILE* out, int32_t aIndent) const { } #endif -void CSSMozDocumentRule::SetRawAfterClone( - RefPtr aRaw) { - mRawRule = std::move(aRaw); - css::ConditionRule::SetRawAfterClone( - Servo_MozDocumentRule_GetRules(mRawRule).Consume()); -} - void CSSMozDocumentRule::GetConditionText(nsACString& aConditionText) { Servo_MozDocumentRule_GetConditionText(mRawRule, &aConditionText); } diff --git a/layout/style/CSSMozDocumentRule.h b/layout/style/CSSMozDocumentRule.h index a1a5f84f2186..9ae28567dbd3 100644 --- a/layout/style/CSSMozDocumentRule.h +++ b/layout/style/CSSMozDocumentRule.h @@ -31,7 +31,6 @@ class CSSMozDocumentRule final : public css::ConditionRule { #endif RawServoMozDocumentRule* Raw() const { return mRawRule; } - void SetRawAfterClone(RefPtr); // WebIDL interface uint16_t Type() const final { return CSSRule_Binding::DOCUMENT_RULE; } diff --git a/layout/style/CSSNamespaceRule.cpp b/layout/style/CSSNamespaceRule.cpp index 088db2312227..219ff5b7f51d 100644 --- a/layout/style/CSSNamespaceRule.cpp +++ b/layout/style/CSSNamespaceRule.cpp @@ -38,10 +38,6 @@ void CSSNamespaceRule::GetCssText(nsACString& aCssText) const { Servo_NamespaceRule_GetCssText(mRawRule, &aCssText); } -void CSSNamespaceRule::SetRawAfterClone(RefPtr aRaw) { - mRawRule = std::move(aRaw); -} - size_t CSSNamespaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { return aMallocSizeOf(this); } diff --git a/layout/style/CSSNamespaceRule.h b/layout/style/CSSNamespaceRule.h index 9a29b691145a..ff28de8e7ea1 100644 --- a/layout/style/CSSNamespaceRule.h +++ b/layout/style/CSSNamespaceRule.h @@ -40,7 +40,6 @@ class CSSNamespaceRule final : public css::Rule { uint16_t Type() const final { return CSSRule_Binding::NAMESPACE_RULE; } const RawServoNamespaceRule* Raw() const { return mRawRule.get(); } - void SetRawAfterClone(RefPtr); void GetNamespaceURI(nsString& aNamespaceURI) { GetURLSpec(aNamespaceURI); } diff --git a/layout/style/CSSPageRule.cpp b/layout/style/CSSPageRule.cpp index c84fd19fd24f..2fb4a943f4f2 100644 --- a/layout/style/CSSPageRule.cpp +++ b/layout/style/CSSPageRule.cpp @@ -17,9 +17,7 @@ namespace dom { CSSPageRuleDeclaration::CSSPageRuleDeclaration( already_AddRefed aDecls) - : mDecls(new DeclarationBlock(std::move(aDecls))) { - mDecls->SetOwningRule(Rule()); -} + : mDecls(new DeclarationBlock(std::move(aDecls))) {} CSSPageRuleDeclaration::~CSSPageRuleDeclaration() { mDecls->SetOwningRule(nullptr); @@ -53,26 +51,18 @@ nsISupports* CSSPageRuleDeclaration::GetParentObject() const { DeclarationBlock* CSSPageRuleDeclaration::GetOrCreateCSSDeclaration( Operation aOperation, DeclarationBlock** aCreated) { - if (aOperation != Operation::Read) { - if (StyleSheet* sheet = Rule()->GetStyleSheet()) { - sheet->WillDirty(); - } - } return mDecls; } -void CSSPageRuleDeclaration::SetRawAfterClone( - RefPtr aDeclarationBlock) { - mDecls->SetOwningRule(nullptr); - mDecls = new DeclarationBlock(aDeclarationBlock.forget()); - mDecls->SetOwningRule(Rule()); -} - nsresult CSSPageRuleDeclaration::SetCSSDeclaration( DeclarationBlock* aDecl, MutationClosureData* aClosureData) { MOZ_ASSERT(aDecl, "must be non-null"); CSSPageRule* rule = Rule(); + if (rule->IsReadOnly()) { + return NS_OK; + } + if (aDecl != mDecls) { mDecls->SetOwningRule(nullptr); RefPtr decls = aDecl; @@ -139,11 +129,6 @@ bool CSSPageRule::IsCCLeaf() const { return !mDecls.PreservingWrapper(); } -void CSSPageRule::SetRawAfterClone(RefPtr aRaw) { - mRawRule = std::move(aRaw); - mDecls.SetRawAfterClone(Servo_PageRule_GetStyle(mRawRule.get()).Consume()); -} - size_t CSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { // TODO Implement this! return aMallocSizeOf(this); diff --git a/layout/style/CSSPageRule.h b/layout/style/CSSPageRule.h index fe20d2635ab9..59f1df667796 100644 --- a/layout/style/CSSPageRule.h +++ b/layout/style/CSSPageRule.h @@ -43,8 +43,6 @@ class CSSPageRuleDeclaration final : public nsDOMCSSDeclaration { explicit CSSPageRuleDeclaration( already_AddRefed aDecls); - void SetRawAfterClone(RefPtr); - ~CSSPageRuleDeclaration(); inline CSSPageRule* Rule(); @@ -64,7 +62,6 @@ class CSSPageRule final : public css::Rule { bool IsCCLeaf() const final; RawServoPageRule* Raw() const { return mRawRule; } - void SetRawAfterClone(RefPtr); // WebIDL interfaces uint16_t Type() const final { return CSSRule_Binding::PAGE_RULE; } diff --git a/layout/style/CSSStyleRule.cpp b/layout/style/CSSStyleRule.cpp index d1b01de51c6f..55da0762d64c 100644 --- a/layout/style/CSSStyleRule.cpp +++ b/layout/style/CSSStyleRule.cpp @@ -25,9 +25,7 @@ namespace dom { CSSStyleRuleDeclaration::CSSStyleRuleDeclaration( already_AddRefed aDecls) - : mDecls(new DeclarationBlock(std::move(aDecls))) { - mDecls->SetOwningRule(Rule()); -} + : mDecls(new DeclarationBlock(std::move(aDecls))) {} CSSStyleRuleDeclaration::~CSSStyleRuleDeclaration() { mDecls->SetOwningRule(nullptr); @@ -61,31 +59,18 @@ nsISupports* CSSStyleRuleDeclaration::GetParentObject() const { DeclarationBlock* CSSStyleRuleDeclaration::GetOrCreateCSSDeclaration( Operation aOperation, DeclarationBlock** aCreated) { - if (aOperation != Operation::Read) { - if (StyleSheet* sheet = Rule()->GetStyleSheet()) { - sheet->WillDirty(); - } - } return mDecls; } -void CSSStyleRule::SetRawAfterClone(RefPtr aRaw) { - mRawRule = std::move(aRaw); - mDecls.SetRawAfterClone(Servo_StyleRule_GetStyle(mRawRule).Consume()); -} - -void CSSStyleRuleDeclaration::SetRawAfterClone(RefPtr aRaw) { - RefPtr block = new DeclarationBlock(aRaw.forget()); - mDecls->SetOwningRule(nullptr); - mDecls = std::move(block); - mDecls->SetOwningRule(Rule()); -} - nsresult CSSStyleRuleDeclaration::SetCSSDeclaration( DeclarationBlock* aDecl, MutationClosureData* aClosureData) { CSSStyleRule* rule = Rule(); - if (StyleSheet* sheet = rule->GetStyleSheet()) { + if (rule->IsReadOnly()) { + return NS_OK; + } + + if (RefPtr sheet = rule->GetStyleSheet()) { if (aDecl != mDecls) { mDecls->SetOwningRule(nullptr); RefPtr decls = aDecl; @@ -191,7 +176,10 @@ void CSSStyleRule::SetSelectorText(const nsACString& aSelectorText) { return; } - if (StyleSheet* sheet = GetStyleSheet()) { + if (RefPtr sheet = GetStyleSheet()) { + // StyleRule lives inside of the Inner, it is unsafe to call WillDirty + // if sheet does not already have a unique Inner. + sheet->AssertHasUniqueInner(); sheet->WillDirty(); // TODO(emilio): May actually be more efficient to handle this as rule diff --git a/layout/style/CSSStyleRule.h b/layout/style/CSSStyleRule.h index 8355091d66c1..46add412acaa 100644 --- a/layout/style/CSSStyleRule.h +++ b/layout/style/CSSStyleRule.h @@ -49,8 +49,6 @@ class CSSStyleRuleDeclaration final : public nsDOMCSSDeclaration { inline CSSStyleRule* Rule(); inline const CSSStyleRule* Rule() const; - void SetRawAfterClone(RefPtr); - RefPtr mDecls; }; @@ -83,7 +81,6 @@ class CSSStyleRule final : public BindingStyleRule, public SupportsWeakPtr { nsICSSDeclaration* Style() final; RawServoStyleRule* Raw() const { return mRawRule; } - void SetRawAfterClone(RefPtr); // Methods of mozilla::css::Rule size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final; diff --git a/layout/style/CSSSupportsRule.cpp b/layout/style/CSSSupportsRule.cpp index 35c0cb5d856d..e1266c3957ab 100644 --- a/layout/style/CSSSupportsRule.cpp +++ b/layout/style/CSSSupportsRule.cpp @@ -59,13 +59,6 @@ void CSSSupportsRule::GetCssText(nsACString& aCssText) const { Servo_SupportsRule_GetCssText(mRawRule, &aCssText); } -void CSSSupportsRule::SetRawAfterClone(RefPtr aRaw) { - mRawRule = std::move(aRaw); - - css::ConditionRule::SetRawAfterClone( - Servo_SupportsRule_GetRules(mRawRule).Consume()); -} - /* virtual */ size_t CSSSupportsRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { // TODO Implement this! diff --git a/layout/style/CSSSupportsRule.h b/layout/style/CSSSupportsRule.h index 12ac0e900703..e291f8079ca2 100644 --- a/layout/style/CSSSupportsRule.h +++ b/layout/style/CSSSupportsRule.h @@ -25,7 +25,6 @@ class CSSSupportsRule : public css::ConditionRule { #endif RawServoSupportsRule* Raw() const { return mRawRule; } - void SetRawAfterClone(RefPtr); // WebIDL interface uint16_t Type() const override { return CSSRule_Binding::SUPPORTS_RULE; } diff --git a/layout/style/GroupRule.h b/layout/style/GroupRule.h index cd2e574b850f..73122a79e6b6 100644 --- a/layout/style/GroupRule.h +++ b/layout/style/GroupRule.h @@ -55,10 +55,6 @@ class GroupRule : public Rule { return mRuleList->GetRule(aIndex); } - void SetRawAfterClone(RefPtr aRules) { - mRuleList->SetRawAfterClone(std::move(aRules)); - } - /* * The next method should never be called unless you have first called * WillDirty() on the parent stylesheet. diff --git a/layout/style/MediaList.h b/layout/style/MediaList.h index 674d17485d5d..29ce7cfdc752 100644 --- a/layout/style/MediaList.h +++ b/layout/style/MediaList.h @@ -47,9 +47,6 @@ class MediaList final : public nsISupports, public nsWrapperCache { bool Matches(const Document&) const; void SetStyleSheet(StyleSheet* aSheet); - void SetRawAfterClone(RefPtr aRaw) { - mRawList = std::move(aRaw); - } // WebIDL void GetMediaText(nsACString& aMediaText); diff --git a/layout/style/ServoCSSRuleList.cpp b/layout/style/ServoCSSRuleList.cpp index 57a64093e6f1..131e954bfdac 100644 --- a/layout/style/ServoCSSRuleList.cpp +++ b/layout/style/ServoCSSRuleList.cpp @@ -49,7 +49,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ServoCSSRuleList) NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(dom::CSSRuleList) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoCSSRuleList, dom::CSSRuleList) - tmp->EnumerateInstantiatedRules([&](css::Rule* aRule, uint32_t) { + tmp->EnumerateInstantiatedRules([&](css::Rule* aRule) { if (!aRule->IsCCLeaf()) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRules[i]"); cb.NoteXPCOMChild(aRule); @@ -65,13 +65,12 @@ css::Rule* ServoCSSRuleList::GetRule(uint32_t aIndex) { #define CASE_RULE(const_, name_) \ case CSSRule_Binding::const_##_RULE: { \ uint32_t line = 0, column = 0; \ - RefPtr raw = \ + RefPtr rule = \ Servo_CssRules_Get##name_##RuleAt(mRawRules, aIndex, &line, &column) \ .Consume(); \ - MOZ_ASSERT(raw); \ - ruleObj = new CSS##name_##Rule(raw.forget(), mStyleSheet, mParentRule, \ + MOZ_ASSERT(rule); \ + ruleObj = new CSS##name_##Rule(rule.forget(), mStyleSheet, mParentRule, \ line, column); \ - MOZ_ASSERT(ruleObj->Type() == rule); \ break; \ } CASE_RULE(STYLE, Style) @@ -110,12 +109,10 @@ css::Rule* ServoCSSRuleList::IndexedGetter(uint32_t aIndex, bool& aFound) { template void ServoCSSRuleList::EnumerateInstantiatedRules(Func aCallback) { - uint32_t index = 0; for (uintptr_t rule : mRules) { if (rule > kMaxRuleType) { - aCallback(CastToPtr(rule), index); + aCallback(CastToPtr(rule)); } - index++; } } @@ -149,13 +146,13 @@ void ServoCSSRuleList::DropSheetReference() { } mStyleSheet = nullptr; EnumerateInstantiatedRules( - [](css::Rule* rule, uint32_t) { rule->DropSheetReference(); }); + [](css::Rule* rule) { rule->DropSheetReference(); }); } void ServoCSSRuleList::DropParentRuleReference() { mParentRule = nullptr; EnumerateInstantiatedRules( - [](css::Rule* rule, uint32_t) { rule->DropParentRuleReference(); }); + [](css::Rule* rule) { rule->DropParentRuleReference(); }); } nsresult ServoCSSRuleList::InsertRule(const nsACString& aRule, @@ -168,8 +165,6 @@ nsresult ServoCSSRuleList::InsertRule(const nsACString& aRule, return NS_OK; } - mStyleSheet->WillDirty(); - bool nested = !!mParentRule; css::Loader* loader = nullptr; auto allowImportRules = mStyleSheet->SelfOrAncestorIsConstructed() @@ -219,42 +214,6 @@ uint16_t ServoCSSRuleList::GetDOMCSSRuleType(uint32_t aIndex) const { return CastToPtr(rule)->Type(); } -void ServoCSSRuleList::SetRawAfterClone(RefPtr aNewRules) { - mRawRules = std::move(aNewRules); - EnumerateInstantiatedRules([&](css::Rule* aRule, uint32_t aIndex) { -#define CASE_FOR(constant_, type_) \ - case CSSRule_Binding::constant_##_RULE: { \ - uint32_t line = 0, column = 0; \ - RefPtr raw = \ - Servo_CssRules_Get##type_##RuleAt(mRawRules, aIndex, &line, &column) \ - .Consume(); \ - static_cast(aRule)->SetRawAfterClone( \ - std::move(raw)); \ - break; \ - } - switch (aRule->Type()) { - CASE_FOR(STYLE, Style) - CASE_FOR(KEYFRAMES, Keyframes) - CASE_FOR(MEDIA, Media) - CASE_FOR(NAMESPACE, Namespace) - CASE_FOR(PAGE, Page) - CASE_FOR(SUPPORTS, Supports) - CASE_FOR(DOCUMENT, MozDocument) - CASE_FOR(IMPORT, Import) - CASE_FOR(FONT_FEATURE_VALUES, FontFeatureValues) - CASE_FOR(FONT_FACE, FontFace) - CASE_FOR(COUNTER_STYLE, CounterStyle) - case CSSRule_Binding::KEYFRAME_RULE: - MOZ_ASSERT_UNREACHABLE("keyframe rule cannot be here"); - break; - default: - MOZ_ASSERT_UNREACHABLE("Which rule do we have here?"); - break; - } -#undef CASE_FOR - }); -} - ServoCSSRuleList::~ServoCSSRuleList() { MOZ_ASSERT(!mStyleSheet, "Backpointer should have been cleared"); MOZ_ASSERT(!mParentRule, "Backpointer should have been cleared"); diff --git a/layout/style/ServoCSSRuleList.h b/layout/style/ServoCSSRuleList.h index 4db3939fbd8d..bc27b4c8b9ab 100644 --- a/layout/style/ServoCSSRuleList.h +++ b/layout/style/ServoCSSRuleList.h @@ -50,8 +50,6 @@ class ServoCSSRuleList final : public dom::CSSRuleList { uint16_t GetDOMCSSRuleType(uint32_t aIndex) const; - void SetRawAfterClone(RefPtr); - private: virtual ~ServoCSSRuleList(); diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index 78489f13527b..1dbe456d76d0 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -942,13 +942,6 @@ void ServoStyleSet::RuleChanged(StyleSheet& aSheet, css::Rule* aRule, } } -void ServoStyleSet::SheetCloned(StyleSheet& aSheet) { - mNeedsRestyleAfterEnsureUniqueInner = true; - if (mStyleRuleMap) { - mStyleRuleMap->SheetCloned(aSheet); - } -} - #ifdef DEBUG void ServoStyleSet::AssertTreeIsClean() { DocumentStyleRootIterator iter(mDocument); diff --git a/layout/style/ServoStyleSet.h b/layout/style/ServoStyleSet.h index 8f6b36be60b6..a30cee54b6fa 100644 --- a/layout/style/ServoStyleSet.h +++ b/layout/style/ServoStyleSet.h @@ -119,7 +119,7 @@ class ServoStyleSet { void RuleAdded(StyleSheet&, css::Rule&); void RuleRemoved(StyleSheet&, css::Rule&); void RuleChanged(StyleSheet&, css::Rule*, StyleRuleChangeKind); - void SheetCloned(StyleSheet&); + void SheetCloned(StyleSheet&) { mNeedsRestyleAfterEnsureUniqueInner = true; } void ImportRuleLoaded(dom::CSSImportRule&, StyleSheet&); // Runs style invalidation due to document state changes. diff --git a/layout/style/StyleSheet.cpp b/layout/style/StyleSheet.cpp index 44b2207f0eef..e1c6ec4eb65d 100644 --- a/layout/style/StyleSheet.cpp +++ b/layout/style/StyleSheet.cpp @@ -537,14 +537,13 @@ void StyleSheet::EnsureUniqueInner() { StyleSheetInfo* clone = mInner->CloneFor(this); MOZ_ASSERT(clone); - mInner->RemoveSheet(this); mInner = clone; // Fixup the child lists and parent links in the Servo sheet. This is done // here instead of in StyleSheetInner::CloneFor, because it's just more // convenient to do so instead. - FixUpAfterInnerClone(); + BuildChildListAfterInnerClone(); // let our containing style sets know that if we call // nsPresContext::EnsureSafeToHandOutCSSRules we will need to restyle the @@ -817,8 +816,6 @@ void StyleSheet::RuleRemoved(css::Rule& aRule) { } void StyleSheet::RuleChanged(css::Rule* aRule, StyleRuleChangeKind aKind) { - MOZ_ASSERT(!aRule || HasUniqueInner(), - "Shouldn't have mutated a shared sheet"); SetModifiedRules(); NOTIFY(RuleChanged, (*this, aRule, aKind)); } @@ -1109,7 +1106,7 @@ JSObject* StyleSheet::WrapObject(JSContext* aCx, return dom::CSSStyleSheet_Binding::Wrap(aCx, this, aGivenProto); } -void StyleSheet::FixUpAfterInnerClone() { +void StyleSheet::BuildChildListAfterInnerClone() { MOZ_ASSERT(Inner().mSheets.Length() == 1, "Should've just cloned"); MOZ_ASSERT(Inner().mSheets[0] == this); MOZ_ASSERT(Inner().mChildren.IsEmpty()); @@ -1117,10 +1114,6 @@ void StyleSheet::FixUpAfterInnerClone() { auto* contents = Inner().mContents.get(); RefPtr rules = Servo_StyleSheet_GetRules(contents).Consume(); - if (mRuleList) { - mRuleList->SetRawAfterClone(rules); - } - uint32_t index = 0; while (true) { uint32_t line, column; // Actually unused. @@ -1387,6 +1380,8 @@ already_AddRefed StyleSheet::CloneAdoptedSheet( ServoCSSRuleList* StyleSheet::GetCssRulesInternal() { if (!mRuleList) { + EnsureUniqueInner(); + RefPtr rawRules = Servo_StyleSheet_GetRules(Inner().mContents).Consume(); MOZ_ASSERT(rawRules); diff --git a/layout/style/StyleSheet.h b/layout/style/StyleSheet.h index 068224ecf36e..eec11b1370ac 100644 --- a/layout/style/StyleSheet.h +++ b/layout/style/StyleSheet.h @@ -501,7 +501,7 @@ class StyleSheet final : public nsICSSLoaderObserver, public nsWrapperCache { // Take the recently cloned sheets from the `@import` rules, and reparent them // correctly to `aPrimarySheet`. - void FixUpAfterInnerClone(); + void BuildChildListAfterInnerClone(); void DropRuleList();