mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:08:12 +00:00
LibWeb: Implement HTMLDialogElement::show()
This commit is contained in:
parent
8042558805
commit
151cd11b5b
4 changed files with 51 additions and 3 deletions
2
Tests/LibWeb/Text/expected/show-non-modal-dialog.txt
Normal file
2
Tests/LibWeb/Text/expected/show-non-modal-dialog.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
dialog.open state before show(): false
|
||||||
|
dialog.open state after show(): true
|
10
Tests/LibWeb/Text/input/show-non-modal-dialog.html
Normal file
10
Tests/LibWeb/Text/input/show-non-modal-dialog.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<script src="./include.js"></script>
|
||||||
|
<dialog id="test-dialog"></dialog>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const dialog = document.getElementById("test-dialog");
|
||||||
|
println(`dialog.open state before show(): ${dialog.open}`)
|
||||||
|
dialog.show();
|
||||||
|
println(`dialog.open state after show(): ${dialog.open}`);
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
#include <LibWeb/DOM/Event.h>
|
#include <LibWeb/DOM/Event.h>
|
||||||
|
#include <LibWeb/HTML/Focus.h>
|
||||||
#include <LibWeb/HTML/HTMLDialogElement.h>
|
#include <LibWeb/HTML/HTMLDialogElement.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
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
|
// https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-dialog-show
|
||||||
void HTMLDialogElement::show()
|
WebIDL::ExceptionOr<void> 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
|
// https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-dialog-showmodal
|
||||||
|
@ -92,4 +109,21 @@ void HTMLDialogElement::close_the_dialog(Optional<String> result)
|
||||||
// 2. Set subject's close watcher to null.
|
// 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<Element> 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public:
|
||||||
String return_value() const;
|
String return_value() const;
|
||||||
void set_return_value(String);
|
void set_return_value(String);
|
||||||
|
|
||||||
void show();
|
WebIDL::ExceptionOr<void> show();
|
||||||
void show_modal();
|
void show_modal();
|
||||||
void close(Optional<String> return_value);
|
void close(Optional<String> return_value);
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@ private:
|
||||||
|
|
||||||
void close_the_dialog(Optional<String> result);
|
void close_the_dialog(Optional<String> result);
|
||||||
|
|
||||||
|
void run_dialog_focusing_steps();
|
||||||
|
|
||||||
String m_return_value;
|
String m_return_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue