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

Implement toggleevents for dialog open/close #23332

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

keithamus
Copy link
Member

@keithamus keithamus commented Jan 26, 2024

Implement toggleevents for dialog open/close
https://bugs.webkit.org/show_bug.cgi?id=268160

Reviewed by NOBODY (OOPS!).

This adds the `beforetoggle` cancelable event to `show()`/`showModal()`
calls. If `beforetoggle` isn't cancelled, it will show the dialog and
dispatch a `toggle` event.

Likewise, the close method adds a NON cancelable `beforetoggle` and
`toggle` event.

These events can help developers when prepping a dialog to be shown or
hidden, such as doing page calculations or kicking off animations.

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/toggle-events.tentative-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/toggle-events.tentative.html: Added.
* Source/WebCore/html/HTMLDialogElement.cpp:
(WebCore::HTMLDialogElement::show):
(WebCore::HTMLDialogElement::showModal):
(WebCore::HTMLDialogElement::close):
(WebCore::HTMLDialogElement::queueDialogToggleEventTask):
* Source/WebCore/html/HTMLDialogElement.h:

706583c

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ›  gtk
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ›  tv ❌ πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-wk2-stress
βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@nt1m
Copy link
Member

nt1m commented Jan 26, 2024

Is this is in the spec somewhere?

@Ahmad-S792 Ahmad-S792 added the DOM For bugs specific to XML/HTML DOM elements (including parsing). label Jan 26, 2024
https://bugs.webkit.org/show_bug.cgi?id=268160

Reviewed by NOBODY (OOPS!).

This adds the `beforetoggle` cancelable event to `show()`/`showModal()`
calls. If `beforetoggle` isn't cancelled, it will show the dialog and
dispatch a `toggle` event.

Likewise, the close method adds a NON cancelable `beforetoggle` and
`toggle` event.

These events can help developers when prepping a dialog to be shown or
hidden, such as doing page calculations or kicking off animations.

* LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/toggle-events.tentative-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/toggle-events.tentative.html: Added.
* Source/WebCore/html/HTMLDialogElement.cpp:
(WebCore::HTMLDialogElement::show):
(WebCore::HTMLDialogElement::showModal):
(WebCore::HTMLDialogElement::close):
(WebCore::HTMLDialogElement::queueDialogToggleEventTask):
* Source/WebCore/html/HTMLDialogElement.h:
@keithamus
Copy link
Member Author

Is this is in the spec somewhere?

Not yet but we discussed it as TPAC and it was deemed a reasonable addition. Tentative spec PR here: whatwg/html#10091

@@ -177,4 +198,21 @@ void HTMLDialogElement::setIsModal(bool newValue)
m_isModal = newValue;
}

void HTMLDialogElement::queueDialogToggleEventTask(DialogState oldState, DialogState newState)
Copy link
Member

Choose a reason for hiding this comment

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

This should be shared somehow with the details / popover code to avoid duplication.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had considered this but I also thought it might be better as a follow up PR. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer refactoring details / popover first and then adopting the new shared code here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines +147 to 149
queueDialogToggleEventTask(DialogState::Open, DialogState::Closed);

queueTaskToDispatchEvent(TaskSource::UserInteraction, Event::create(eventNames().closeEvent, Event::CanBubble::No, Event::IsCancelable::No));
Copy link
Member

Choose a reason for hiding this comment

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

the close event should be emitted before toggle, to get consistent event ordering (otherwise toggle might fire first when no coalescing is happening, but after when it isn't)

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DOM For bugs specific to XML/HTML DOM elements (including parsing). merging-blocked Applied to prevent a change from being merged
Projects
None yet
5 participants