From edd4c4f1e883eaa3b0af54d09f2a97b006e5833a Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Tue, 18 Jul 2023 08:57:25 +0000 Subject: [PATCH] Bug 1843035: part 1) Align unbinding a popover node from the tree closer to the spec. r=emilio Differential Revision: https://phabricator.services.mozilla.com/D183381 --- dom/html/nsGenericHTMLElement.cpp | 24 +++++++++++++++++------- dom/html/nsGenericHTMLElement.h | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 39e05ee29496..38c78bc1c02c 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -489,10 +489,8 @@ nsresult nsGenericHTMLElement::BindToTree(BindContext& aContext, void nsGenericHTMLElement::UnbindFromTree(bool aNullParent) { if (IsInComposedDoc()) { // https://html.spec.whatwg.org/#dom-trees:hide-popover-algorithm - // If removedNode's popover attribute is not in the no popover state, then - // run the hide popover algorithm given removedNode, false, false, and - // false. - if (GetPopoverData()) { + AssertPopoverAttributeStateCorrespondsToAttributePresence(); + if (GetPopoverAttributeState() != PopoverAttributeState::None) { HidePopoverWithoutRunningScript(); } RegUnRegAccessKey(false); @@ -3211,16 +3209,14 @@ bool nsGenericHTMLElement::PopoverOpen() const { bool nsGenericHTMLElement::CheckPopoverValidity( PopoverVisibilityState aExpectedState, Document* aExpectedDocument, ErrorResult& aRv) { + AssertPopoverAttributeStateCorrespondsToAttributePresence(); const PopoverData* data = GetPopoverData(); if (!data || data->GetPopoverAttributeState() == PopoverAttributeState::None) { - MOZ_ASSERT(!HasAttr(nsGkAtoms::popover)); aRv.ThrowNotSupportedError("Element is in the no popover state"); return false; } - MOZ_ASSERT(HasAttr(nsGkAtoms::popover)); - if (data->GetPopoverVisibilityState() != aExpectedState) { return false; } @@ -3250,6 +3246,20 @@ bool nsGenericHTMLElement::CheckPopoverValidity( return true; } +void nsGenericHTMLElement:: + AssertPopoverAttributeStateCorrespondsToAttributePresence() const { +#ifdef DEBUG + if (GetPopoverAttributeState() == PopoverAttributeState::None) { + MOZ_ASSERT(!HasAttr(nsGkAtoms::popover)); + } else { + MOZ_ASSERT(HasAttr(nsGkAtoms::popover)); + } +#else + { + } +#endif // DEBUG +} + PopoverAttributeState nsGenericHTMLElement::GetPopoverAttributeState() const { return GetPopoverData() ? GetPopoverData()->GetPopoverAttributeState() : PopoverAttributeState::None; diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index 64c582860726..b323ff980c1c 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -151,6 +151,7 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase { return false; } + void AssertPopoverAttributeStateCorrespondsToAttributePresence() const; mozilla::dom::PopoverAttributeState GetPopoverAttributeState() const; void PopoverPseudoStateUpdate(bool aOpen, bool aNotify); bool PopoverOpen() const; -- 2.11.4.GIT