diff --git a/Tests/LibWeb/Text/expected/show-non-modal-dialog.txt b/Tests/LibWeb/Text/expected/show-non-modal-dialog.txt new file mode 100644 index 0000000000..55e2fa1b86 --- /dev/null +++ b/Tests/LibWeb/Text/expected/show-non-modal-dialog.txt @@ -0,0 +1,2 @@ + dialog.open state before show(): false +dialog.open state after show(): true diff --git a/Tests/LibWeb/Text/input/show-non-modal-dialog.html b/Tests/LibWeb/Text/input/show-non-modal-dialog.html new file mode 100644 index 0000000000..19ceb7d600 --- /dev/null +++ b/Tests/LibWeb/Text/input/show-non-modal-dialog.html @@ -0,0 +1,10 @@ + + + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.cpp index b3535fc291..18642c58d5 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.cpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace Web::HTML { @@ -26,9 +27,25 @@ void HTMLDialogElement::initialize(JS::Realm& realm) } // https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-dialog-show -void HTMLDialogElement::show() +WebIDL::ExceptionOr HTMLDialogElement::show() { - dbgln("(STUBBED) HTMLDialogElement::show()"); + // 1. If this has an open attribute and the is modal flag of this is false, then return. + // FIXME: Add modal flag check here when modal dialog support is added + if (has_attribute(AttributeNames::open)) + return {}; + + // FIXME: 2. If this has an open attribute, then throw an "InvalidStateError" DOMException. + + // 3. Add an open attribute to this, whose value is the empty string. + TRY(set_attribute(AttributeNames::open, {})); + + // FIXME 4. Set this's previously focused element to the focused element. + // FIXME 5. Run hide all popovers given this's node document. + + // 6. Run the dialog focusing steps given this. + run_dialog_focusing_steps(); + + return {}; } // https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-dialog-showmodal @@ -92,4 +109,21 @@ void HTMLDialogElement::close_the_dialog(Optional result) // 2. Set subject's close watcher to null. } +// https://html.spec.whatwg.org/multipage/interactive-elements.html#dialog-focusing-steps +void HTMLDialogElement::run_dialog_focusing_steps() +{ + // 1. Let control be null + JS::GCPtr control = nullptr; + + // FIXME 2. If subject has the autofocus attribute, then set control to subject. + // FIXME 3. If control is null, then set control to the focus delegate of subject. + + // 4. If control is null, then set control to subject. + if (!control) + control = this; + + // 5. Run the focusing steps for control. + run_focusing_steps(control); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.h b/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.h index ebc3965e8e..36fec3f922 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLDialogElement.h @@ -21,7 +21,7 @@ public: String return_value() const; void set_return_value(String); - void show(); + WebIDL::ExceptionOr show(); void show_modal(); void close(Optional return_value); @@ -35,6 +35,8 @@ private: void close_the_dialog(Optional result); + void run_dialog_focusing_steps(); + String m_return_value; };