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
This commit is contained in:
Mirko Brodesser
2023-07-18 08:57:25 +00:00
parent a4dac96a43
commit 9dc774c63c
2 changed files with 18 additions and 7 deletions

View File

@@ -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;