commit 2d9326f07add96d7fad597dce857ec77690a58b6 parent b736fd9f0f75b9e4718f80536a13e8eea439d4a3 Author: Sandor Molnar <smolnar@mozilla.com> Date: Mon, 15 Dec 2025 22:39:06 +0200 Revert "Bug 2004140 - Implement initial StylePropertyMap support for CSSStyleRule. r=emilio,firefox-style-system-reviewers,janv" for causing build bustages @ StylePropertyMapReadOnly.cpp This reverts commit 96a8bffa4ef26c4208c6546981bcc1ee2cdec116. Diffstat:
13 files changed, 75 insertions(+), 104 deletions(-)
diff --git a/layout/style/CSSStyleRule.cpp b/layout/style/CSSStyleRule.cpp @@ -203,10 +203,6 @@ const StyleLockedDeclarationBlock* CSSStyleRule::RawStyle() const { return mDecls.mDecls->Raw(); } -DeclarationBlock& CSSStyleRule::GetDeclarationBlock() const { - return *mDecls.mDecls; -} - void CSSStyleRule::GetSelectorText(nsACString& aSelectorText) { Servo_StyleRule_GetSelectorText(mRawRule, &aSelectorText); } @@ -409,7 +405,7 @@ already_AddRefed<nsINodeList> CSSStyleRule::QuerySelectorAll(nsINode& aRoot) { StylePropertyMap* CSSStyleRule::StyleMap() { if (!mStyleMap) { - mStyleMap = MakeRefPtr<StylePropertyMap>(this); + mStyleMap = MakeRefPtr<StylePropertyMap>(this, /* aComputed */ false); } return mStyleMap; diff --git a/layout/style/CSSStyleRule.h b/layout/style/CSSStyleRule.h @@ -73,7 +73,7 @@ class CSSStyleRule final : public css::GroupRule { bool aRelevantLinkVisited); Element* GetScopeRootFor(uint32_t aSelectorIndex, dom::Element&, const nsAString& aPseudo, bool aRelevantLinkVisited); - DeclarationBlock& GetDeclarationBlock() const; + NotNull<DeclarationBlock*> GetDeclarationBlock() const; void GetSelectorWarnings(nsTArray<SelectorWarning>& aResult) const; already_AddRefed<nsINodeList> QuerySelectorAll(nsINode& aRoot); diff --git a/layout/style/typedom/StylePropertyMap.cpp b/layout/style/typedom/StylePropertyMap.cpp @@ -24,14 +24,12 @@ namespace mozilla::dom { -StylePropertyMap::StylePropertyMap(Element* aElement, bool aComputed) - : StylePropertyMapReadOnly(aElement, aComputed) { +StylePropertyMap::StylePropertyMap(nsCOMPtr<nsISupports> aParent, + bool aComputed) + : StylePropertyMapReadOnly(std::move(aParent), aComputed) { MOZ_DIAGNOSTIC_ASSERT(!aComputed); } -StylePropertyMap::StylePropertyMap(CSSStyleRule* aRule) - : StylePropertyMapReadOnly(aRule) {} - JSObject* StylePropertyMap::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { return StylePropertyMap_Binding::Wrap(aCx, this, aGivenProto); @@ -72,7 +70,7 @@ void StylePropertyMap::Set( // Step 4 - const auto* valuePropertyId = styleValue.GetPropertyId(); + const auto valuePropertyId = styleValue.GetPropertyId(); if (valuePropertyId && *valuePropertyId != propertyId) { aRv.ThrowTypeError("Invalid type for property"_ns); diff --git a/layout/style/typedom/StylePropertyMap.h b/layout/style/typedom/StylePropertyMap.h @@ -28,8 +28,7 @@ class Sequence; class StylePropertyMap final : public StylePropertyMapReadOnly { public: - StylePropertyMap(Element* aElement, bool aComputed); - explicit StylePropertyMap(CSSStyleRule* aRule); + StylePropertyMap(nsCOMPtr<nsISupports> aParent, bool aComputed); JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override; diff --git a/layout/style/typedom/StylePropertyMapReadOnly.cpp b/layout/style/typedom/StylePropertyMapReadOnly.cpp @@ -16,7 +16,6 @@ #include "mozilla/dom/CSSKeywordValue.h" #include "mozilla/dom/CSSMathSum.h" #include "mozilla/dom/CSSNumericArray.h" -#include "mozilla/dom/CSSStyleRule.h" #include "mozilla/dom/CSSStyleValue.h" #include "mozilla/dom/CSSUnitValue.h" #include "mozilla/dom/Element.h" @@ -24,6 +23,7 @@ #include "nsCSSProps.h" #include "nsComputedDOMStyle.h" #include "nsCycleCollectionParticipant.h" +#include "nsQueryObject.h" #include "nsReadableUtils.h" namespace mozilla::dom { @@ -84,36 +84,13 @@ struct DeclarationTraits<ComputedStyleDeclarations> { } }; -// Specialization for style rule -struct StyleRuleDeclarations {}; -template <> -struct DeclarationTraits<StyleRuleDeclarations> { - static StylePropertyTypedValueResult Get(const CSSStyleRule* aRule, - const nsACString& aProperty, - ErrorResult& aRv) { - MOZ_ASSERT(aRule); - - auto result = StylePropertyTypedValueResult::None(); - - if (!aRule->GetDeclarationBlock().GetPropertyTypedValue(aProperty, - result)) { - return result; - } - - return result; - } -}; +// XXX StyleRuleDeclarations go here } // namespace -StylePropertyMapReadOnly::StylePropertyMapReadOnly(Element* aElement, - bool aComputed) - : mParent(aElement), mDeclarations(aElement, aComputed) { - MOZ_ASSERT(mParent); -} - -StylePropertyMapReadOnly::StylePropertyMapReadOnly(CSSStyleRule* aRule) - : mParent(aRule), mDeclarations(aRule) { +StylePropertyMapReadOnly::StylePropertyMapReadOnly( + nsCOMPtr<nsISupports> aParent, bool aComputed) + : mParent(std::move(aParent)), mDeclarations(aComputed) { MOZ_ASSERT(mParent); } @@ -124,17 +101,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(StylePropertyMapReadOnly) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(StylePropertyMapReadOnly) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(StylePropertyMapReadOnly) - // Clear out our weak pointers. - tmp->mDeclarations.Unlink(); - - NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent) - NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER -NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(StylePropertyMapReadOnly) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(StylePropertyMapReadOnly, mParent) nsISupports* StylePropertyMapReadOnly::GetParentObject() const { return mParent; @@ -153,10 +120,13 @@ JSObject* StylePropertyMapReadOnly::WrapObject( void StylePropertyMapReadOnly::Get(const nsACString& aProperty, OwningUndefinedOrCSSStyleValue& aRetVal, ErrorResult& aRv) const { - if (!mParent) { - aRv.Throw(NS_ERROR_UNEXPECTED); + // XXX This QO wouldn't be needed if we had RefPtr<Element> mElement + RefPtr<Element> element = do_QueryObject(mParent); + if (!element) { + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); return; } + // Step 2. NonCustomCSSPropertyId id = nsCSSProps::LookupProperty(aProperty); @@ -171,7 +141,7 @@ void StylePropertyMapReadOnly::Get(const nsACString& aProperty, // Step 4. - auto result = declarations.Get(aProperty, aRv); + auto result = declarations.Get(element, aProperty, aRv); if (aRv.Failed()) { return; } @@ -306,33 +276,14 @@ size_t StylePropertyMapReadOnly::SizeOfIncludingThis( } StylePropertyTypedValueResult StylePropertyMapReadOnly::Declarations::Get( - const nsACString& aProperty, ErrorResult& aRv) const { - switch (mKind) { - case Kind::Inline: - return DeclarationTraits<InlineStyleDeclarations>::Get(mElement, + Element* aElement, const nsACString& aProperty, ErrorResult& aRv) const { + if (mComputed) { + return DeclarationTraits<ComputedStyleDeclarations>::Get(aElement, aProperty, aRv); - - case Kind::Computed: - return DeclarationTraits<ComputedStyleDeclarations>::Get(mElement, - aProperty, aRv); - - case Kind::Rule: - return DeclarationTraits<StyleRuleDeclarations>::Get(mRule, aProperty, - aRv); } -} - -void StylePropertyMapReadOnly::Declarations::Unlink() { - switch (mKind) { - case Kind::Inline: - case Kind::Computed: - mElement = nullptr; - break; - case Kind::Rule: - mRule = nullptr; - break; - } + return DeclarationTraits<InlineStyleDeclarations>::Get(aElement, aProperty, + aRv); } } // namespace mozilla::dom diff --git a/layout/style/typedom/StylePropertyMapReadOnly.h b/layout/style/typedom/StylePropertyMapReadOnly.h @@ -29,14 +29,12 @@ struct StylePropertyTypedValueResult; namespace dom { -class CSSStyleRule; class Element; class OwningUndefinedOrCSSStyleValue; class StylePropertyMapReadOnly : public nsISupports, public nsWrapperCache { public: - StylePropertyMapReadOnly(Element* aElement, bool aComputed); - explicit StylePropertyMapReadOnly(CSSStyleRule* aRule); + StylePropertyMapReadOnly(nsCOMPtr<nsISupports> aParent, bool aComputed); NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(StylePropertyMapReadOnly) @@ -76,33 +74,21 @@ class StylePropertyMapReadOnly : public nsISupports, public nsWrapperCache { class Declarations { public: - enum class Kind : uint8_t { - Inline, - Computed, - Rule, - }; - Declarations(Element* aElement, bool aComputed) - : mElement(aElement), - mKind(aComputed ? Kind::Computed : Kind::Inline) {} - - explicit Declarations(CSSStyleRule* aRule) - : mRule(aRule), mKind(Kind::Rule) {} - - StylePropertyTypedValueResult Get(const nsACString& aProperty, - ErrorResult& aRv) const; + explicit Declarations(bool aComputed) : mComputed(aComputed) {} - void Unlink(); + // XXX This will have to be changed a bit when support for CSSStyleRule + // is added (There won't be Element in that case) + StylePropertyTypedValueResult Get(Element* aElement, + const nsACString& aProperty, + ErrorResult& aRv) const; private: - union { - Element* mElement; - CSSStyleRule* mRule; - }; - const Kind mKind; + const bool mComputed; }; + // XXX Make this RefPtr<Element> nsCOMPtr<nsISupports> mParent; - Declarations mDeclarations; + const Declarations mDeclarations; }; } // namespace dom diff --git a/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/declared.tentative.html.ini b/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/declared.tentative.html.ini @@ -5,11 +5,18 @@ [Declared StylePropertyMap contains properties with their last valid value] expected: FAIL + [Declared StylePropertyMap does not contain properties with invalid values] + expected: FAIL + [Declared StylePropertyMap only contains properties in the style rule] expected: FAIL [Declared StylePropertyMap is live] expected: FAIL + [Declared StylePropertyMap does not contain inline styles] + expected: FAIL + [Declared StylePropertyMap contains CSS property declarations in style rules] expected: FAIL + diff --git a/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/get-invalid.html.ini b/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/get-invalid.html.ini @@ -0,0 +1,3 @@ +[get-invalid.html] + [Calling StylePropertyMap.get with an unsupported property throws a TypeError] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/get-shorthand.html.ini b/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/get-shorthand.html.ini @@ -0,0 +1,6 @@ +[get-shorthand.html] + [Getting a shorthand property set explicitly in css rule returns a base CSSStyleValue] + expected: FAIL + + [Getting a shorthand property that is partially set in css rule returns undefined] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/get.html.ini b/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/get.html.ini @@ -13,3 +13,9 @@ [Declared StylePropertyMap.get reflects changes in the CSS rule] expected: FAIL + + [Getting a custom property not in the CSS rule returns undefined] + expected: FAIL + + [Getting a valid property not in the CSS rule returns undefined] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/getAll-shorthand.html.ini b/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/getAll-shorthand.html.ini @@ -0,0 +1,7 @@ +[getAll-shorthand.html] + [StylePropertyMap.getAll() with a shorthand property set explicitly in css rule returns a base CSSStyleValue] + expected: FAIL + + [StylePropertyMap.getAll() with a shorthand property that is partially in css rule returns empty list] + expected: FAIL + diff --git a/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/getAll.tentative.html.ini b/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/getAll.tentative.html.ini @@ -1,4 +1,10 @@ [getAll.tentative.html] + [Calling StylePropertyMap.getAll with a property not in the property model returns an empty list] + expected: FAIL + + [Calling StylePropertyMap.getAll with a custom property not in the property model returns an empty list] + expected: FAIL + [Calling StylePropertyMap.getAll with a valid property returns a single element list with the correct entry] expected: FAIL @@ -10,3 +16,6 @@ [Calling StylePropertyMap.getAll with a list-valued property returns all the values] expected: FAIL + + [Calling StylePropertyMap.getAll with an unsupported property throws a TypeError] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/set.tentative.html.ini b/testing/web-platform/meta/css/css-typed-om/the-stylepropertymap/declared/set.tentative.html.ini @@ -31,3 +31,6 @@ [StylePropertyMap.set is case-insensitive] expected: FAIL + + [Setting a property with a CSSStyleValue whose associated property does not match throws TypeError] + expected: FAIL