From f56ca133405b01a6b775dba20f20edccc3d449ad Mon Sep 17 00:00:00 2001 From: Ziran Sun Date: Fri, 16 Feb 2024 21:51:24 +0000 Subject: [PATCH] Bug 1879001 - Remove the popovertarget attribute or set it to an invalid value should clear the explicitly set attr-element. r=emilio Differential Revision: https://phabricator.services.mozilla.com/D201711 --- dom/base/Element.cpp | 14 +++++--- dom/base/Element.h | 2 ++ dom/html/nsGenericHTMLElement.cpp | 2 ++ .../popovertarget-reflection.html.ini | 3 -- .../popovers/popovertarget-reflection.html | 34 ++++++++++++++++++- 5 files changed, 46 insertions(+), 9 deletions(-) delete mode 100644 testing/web-platform/meta/html/semantics/popovers/popovertarget-reflection.html.ini diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 186628e8076a..f653363f48fb 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1767,19 +1767,23 @@ Element* Element::GetAttrAssociatedElement(nsAtom* aAttr) const { return nullptr; } +void Element::ClearExplicitlySetAttrElement(nsAtom* aAttr) { + if (auto* slots = GetExistingExtendedDOMSlots()) { + slots->mExplicitlySetAttrElements.Remove(aAttr); + } +} + void Element::ExplicitlySetAttrElement(nsAtom* aAttr, Element* aElement) { if (aElement) { + SetAttr(aAttr, EmptyString(), IgnoreErrors()); nsExtendedDOMSlots* slots = ExtendedDOMSlots(); slots->mExplicitlySetAttrElements.InsertOrUpdate( aAttr, do_GetWeakReference(aElement)); - SetAttr(aAttr, EmptyString(), IgnoreErrors()); return; } - if (auto* slots = GetExistingExtendedDOMSlots()) { - slots->mExplicitlySetAttrElements.Remove(aAttr); - UnsetAttr(aAttr, IgnoreErrors()); - } + ClearExplicitlySetAttrElement(aAttr); + UnsetAttr(aAttr, IgnoreErrors()); } void Element::GetElementsWithGrid(nsTArray>& aElements) { diff --git a/dom/base/Element.h b/dom/base/Element.h index dd34dfbf162b..6c717bfc88c7 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -1243,6 +1243,8 @@ class Element : public FragmentOrElement { */ void ExplicitlySetAttrElement(nsAtom* aAttr, Element* aElement); + void ClearExplicitlySetAttrElement(nsAtom*); + PseudoStyleType GetPseudoElementType() const { nsresult rv = NS_OK; auto raw = GetProperty(nsGkAtoms::pseudoProperty, &rv); diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index d96ddc5fbce8..de29276fdccd 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -762,6 +762,8 @@ void nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName, nsContentUtils::AddScriptRunner( NewRunnableMethod("nsGenericHTMLElement::AfterSetPopoverAttr", this, &nsGenericHTMLElement::AfterSetPopoverAttr)); + } else if (aName == nsGkAtoms::popovertarget) { + ClearExplicitlySetAttrElement(nsGkAtoms::popovertarget); } else if (aName == nsGkAtoms::dir) { auto dir = Directionality::Ltr; // A boolean tracking whether we need to recompute our directionality. diff --git a/testing/web-platform/meta/html/semantics/popovers/popovertarget-reflection.html.ini b/testing/web-platform/meta/html/semantics/popovers/popovertarget-reflection.html.ini deleted file mode 100644 index b181bd6a9c8f..000000000000 --- a/testing/web-platform/meta/html/semantics/popovers/popovertarget-reflection.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[popovertarget-reflection.html] - [Element attribute reflection of popoverTargetElement/popovertarget should be kept in sync.] - expected: FAIL diff --git a/testing/web-platform/tests/html/semantics/popovers/popovertarget-reflection.html b/testing/web-platform/tests/html/semantics/popovers/popovertarget-reflection.html index 7f265ae4eb51..d0750fdd4c09 100644 --- a/testing/web-platform/tests/html/semantics/popovers/popovertarget-reflection.html +++ b/testing/web-platform/tests/html/semantics/popovers/popovertarget-reflection.html @@ -1,15 +1,25 @@ + - +
popover