Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve popover event handling in nested showing and hiding #9198

Merged
merged 9 commits into from
Jun 8, 2023

Conversation

josepharhar
Copy link
Contributor

@josepharhar josepharhar commented Apr 21, 2023

Fixes whatwg#9197
Fixes whatwg#9196

But there was a case where the `beforetoggle`
event could open a new popover while an old one was closing. This
led to odd situations where asserts and infinite loops ensued.
This PR breaks that loop, or rather converts it to an explicit one,
by repeating the "hide all popovers until" algorithm until all
popovers are closed. That admits an explicit loop, which is the
popover equivalent of `while(true) {}`: when the `beforetoggle`
handler for a popover re-shows the popover.
@annevk annevk added the topic: popover The popover attribute and friends label Apr 24, 2023
@annevk
Copy link
Member

annevk commented Apr 24, 2023

#9197 (comment) needs to be addressed first.

@josepharhar
Copy link
Contributor Author

There are some additional changes to this PR i need to make based on some more changes mason has made in chromium to address #9196 and #9197
I will reopen this when it this has been incorporated and is ready for review

@josepharhar josepharhar changed the title Fix a corner case where beforetoggle opens a new popover Improve popover event handling in nested showing and hiding May 11, 2023
@josepharhar
Copy link
Contributor Author

Ok, this PR is ready for review again and should fix both #9196 and #9197

@josepharhar josepharhar reopened this May 11, 2023
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
@nt1m nt1m requested a review from emilio May 15, 2023 14:17
@nt1m
Copy link
Member

nt1m commented May 15, 2023

@emilio or @cathiechen, can you please review this? Mainly interested in two things:

  • if this addresses your concerns (presumably yes)
  • if you can find any simplifications to be made

@emilio
Copy link
Contributor

emilio commented May 22, 2023

@emilio or @cathiechen, can you please review this? Mainly interested in two things:

* if this addresses your concerns (presumably yes)

Yes

* if you can find any simplifications to be made

Instead of the if is nested, then set the flag to false, it might be easier to reason about as always set the flag to the previous (is nested) value? But that's editorial, I don't think it's observable.

@cathiechen
Copy link

The fix in Gecko, We have only made modifications to the loop in the hidePopover function.
So I'm thinking could we remove the changes in showPopover. Upon further examination, making changes in both functions seems reasonable for me, as I discovered the potential for nested calls to showPopover. So with changes in showPopover, we can reduce the length of the call stack.

Yet, I found another corner issue about nested popover, and I filed an issue in #9319

webkit-commit-queue pushed a commit to rwlbuis/WebKit that referenced this pull request May 27, 2023
https://bugs.webkit.org/show_bug.cgi?id=256379

Reviewed by Tim Nguyen.

Fix hideAllPopoversUntil for the case where hiding an auto popover changes the auto popover
list (through beforetoggle) so the same auto popover is on top, causing a loop. To fix this, when
this is detected, continue the loop without firing events.

See:
whatwg/html#9198

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-light-dismiss-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-light-dismiss.html:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/semantics/popovers/popover-light-dismiss-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/html/semantics/popovers/popover-light-dismiss-expected.txt:
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::topmostAutoPopover const):
(WebCore::Document::hideAllPopoversUntil):
* Source/WebCore/dom/PopoverData.h:
(WebCore::PopoverData::ScopedStartShowingOrHiding::ScopedStartShowingOrHiding):
(WebCore::PopoverData::ScopedStartShowingOrHiding::~ScopedStartShowingOrHiding):
(WebCore::PopoverData::ScopedStartShowingOrHiding::wasShowingOrHiding const):
* Source/WebCore/html/HTMLElement.cpp:
(WebCore::HTMLElement::showPopover):
(WebCore::HTMLElement::hidePopoverInternal):

Canonical link: https://commits.webkit.org/264623@main
source Outdated Show resolved Hide resolved
source Outdated Show resolved Hide resolved
source Show resolved Hide resolved
@nt1m
Copy link
Member

nt1m commented Jun 6, 2023

Can you add "Fixes #9319" to the commit message?

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found some nits that would be nice to see fixed in a follow-up. As they already existed I'm not gonna hold this up over them as this PR is quite old now.

<li><p>If <var>foundEndpoint</var> is false, then run <var>closeAllOpenPopovers</var> and
return.</p></li>
<li>
<p>For each <var>popover</var> in <var>document</var>'s <span>auto popover list</span>:</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should link for each here.

<li>
<p>While <var>lastToHide</var> is not null and <var>lastToHide</var>'s <span>popover
visibility state</span> is <span data-x="popover-showing-state">showing</span> and
<var>document</var>'s <span>auto popover list</span> is not empty:</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should make is not empty an xref.

@annevk
Copy link
Member

annevk commented Jun 8, 2023

@cathiechen does this look good to you now as well? And Gecko bug we should link from OP?

@cathiechen
Copy link

@cathiechen does this look good to you now as well? And Gecko bug we should link from OP?

Yes, it looks good to me. And filed the Gecko bug https://bugzilla.mozilla.org/show_bug.cgi?id=1837360

@annevk annevk merged commit baab26f into whatwg:main Jun 8, 2023
1 check passed
mnutt pushed a commit to movableink/webkit that referenced this pull request Jun 28, 2023
https://bugs.webkit.org/show_bug.cgi?id=256379

Reviewed by Tim Nguyen.

Fix hideAllPopoversUntil for the case where hiding an auto popover changes the auto popover
list (through beforetoggle) so the same auto popover is on top, causing a loop. To fix this, when
this is detected, continue the loop without firing events.

See:
whatwg/html#9198

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-light-dismiss-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/popovers/popover-light-dismiss.html:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/semantics/popovers/popover-light-dismiss-expected.txt:
* LayoutTests/platform/ios/imported/w3c/web-platform-tests/html/semantics/popovers/popover-light-dismiss-expected.txt:
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::topmostAutoPopover const):
(WebCore::Document::hideAllPopoversUntil):
* Source/WebCore/dom/PopoverData.h:
(WebCore::PopoverData::ScopedStartShowingOrHiding::ScopedStartShowingOrHiding):
(WebCore::PopoverData::ScopedStartShowingOrHiding::~ScopedStartShowingOrHiding):
(WebCore::PopoverData::ScopedStartShowingOrHiding::wasShowingOrHiding const):
* Source/WebCore/html/HTMLElement.cpp:
(WebCore::HTMLElement::showPopover):
(WebCore::HTMLElement::hidePopoverInternal):

Canonical link: https://commits.webkit.org/264623@main
josepharhar added a commit to josepharhar/html that referenced this pull request Jul 17, 2023
Fixes whatwg#9468

I mistakenly added and modified this check while speccing a chromium
patch in this PR: whatwg#9198
annevk pushed a commit that referenced this pull request Jul 25, 2023
I mistakenly added and modified this check in #9198.

Fixes #9468.
rubberyuzu pushed a commit to rubberyuzu/html that referenced this pull request Aug 25, 2023
I mistakenly added and modified this check in whatwg#9198.

Fixes whatwg#9468.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: popover The popover attribute and friends
5 participants