Skip to content

Commit

Permalink
Bug 1829385 - Popover: The element calling hidePopover is not always …
Browse files Browse the repository at this point in the history
…on the top of auto popover list, r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D176150
  • Loading branch information
cathiechen committed May 3, 2023
1 parent 1648986 commit a7787a9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
12 changes: 11 additions & 1 deletion dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15047,7 +15047,17 @@ void Document::HidePopover(Element& aPopover, bool aFocusPreviousElement,
// TODO: we can't always guarantee:
// The last item in document's auto popover list is popoverHTMLEl.
// See, https://github.com/whatwg/html/issues/9197
MOZ_ASSERT(GetTopmostAutoPopover() == popoverHTMLEl);
// If popoverHTMLEl is not on top, hide popovers again without firing
// events.
if (NS_WARN_IF(GetTopmostAutoPopover() != popoverHTMLEl)) {
HideAllPopoversUntil(*popoverHTMLEl, aFocusPreviousElement, false);
if (!popoverHTMLEl->CheckPopoverValidity(PopoverVisibilityState::Showing,
nullptr, aRv)) {
return;
}
MOZ_ASSERT(GetTopmostAutoPopover() == popoverHTMLEl,
"popoverHTMLEl should be on top of auto popover list");
}
}

aPopover.SetHasPopoverInvoker(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html class='reftest-wait'>
<meta charset='utf-8' />
<title>Popover hide crash test</title>
<link rel='author' href="mailto:[email protected]">
<link rel=help href="https://github.com/whatwg/html/issues/9197">

<p>This test passes if it does not crash.</p>
<div id='popover1' popover='auto'>
<div id='popover2' popover='auto'></div>
<div id='popover3' popover='auto'></div>
</div>

<script>
var showedPopover2 = false;
popover1.showPopover();
popover3.showPopover();
popover3.addEventListener('beforetoggle', (e) => {
if (e.newState != 'open' && !showedPopover2) {
showedPopover2 = true;
popover2.showPopover();
}
});
popover1.hidePopover();
</script>

0 comments on commit a7787a9

Please sign in to comment.