mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +00:00
LibWeb: Implement HTMLDialogElement::close()
for non-modal dialogs
This commit is contained in:
parent
cfbd14b958
commit
8042558805
4 changed files with 59 additions and 2 deletions
3
Tests/LibWeb/Text/expected/close-non-modal-dialog.txt
Normal file
3
Tests/LibWeb/Text/expected/close-non-modal-dialog.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
dialog.open state before close(): true
|
||||||
|
dialog.open state after close(): false
|
||||||
|
dialog.returnValue state after close(): after-close
|
14
Tests/LibWeb/Text/input/close-non-modal-dialog.html
Normal file
14
Tests/LibWeb/Text/input/close-non-modal-dialog.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<script src="./include.js"></script>
|
||||||
|
<dialog id="test-dialog" open></dialog>
|
||||||
|
<script>
|
||||||
|
asyncTest((done) => {
|
||||||
|
const dialog = document.getElementById("test-dialog");
|
||||||
|
println(`dialog.open state before close(): ${dialog.open}`);
|
||||||
|
dialog.addEventListener("close", (event) => {
|
||||||
|
println(`dialog.open state after close(): ${dialog.open}`);
|
||||||
|
println(`dialog.returnValue state after close(): ${dialog.returnValue}`);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
dialog.close("after-close");
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
#include <LibWeb/DOM/Event.h>
|
||||||
#include <LibWeb/HTML/HTMLDialogElement.h>
|
#include <LibWeb/HTML/HTMLDialogElement.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -37,9 +38,11 @@ void HTMLDialogElement::show_modal()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-dialog-close
|
// https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-dialog-close
|
||||||
void HTMLDialogElement::close(Optional<String>)
|
void HTMLDialogElement::close(Optional<String> return_value)
|
||||||
{
|
{
|
||||||
dbgln("(STUBBED) HTMLDialogElement::close()");
|
// 1. If returnValue is not given, then set it to null.
|
||||||
|
// 2. Close the dialog this with returnValue.
|
||||||
|
close_the_dialog(move(return_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-dialog-returnvalue
|
// https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-dialog-returnvalue
|
||||||
|
@ -54,4 +57,39 @@ void HTMLDialogElement::set_return_value(String return_value)
|
||||||
m_return_value = move(return_value);
|
m_return_value = move(return_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/interactive-elements.html#close-the-dialog
|
||||||
|
void HTMLDialogElement::close_the_dialog(Optional<String> result)
|
||||||
|
{
|
||||||
|
// 1. If subject does not have an open attribute, then return.
|
||||||
|
if (!has_attribute(AttributeNames::open))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 2. Remove subject's open attribute.
|
||||||
|
remove_attribute(AttributeNames::open);
|
||||||
|
|
||||||
|
// FIXME: 3. If the is modal flag of subject is true, then request an element to be removed from the top layer given subject.
|
||||||
|
// FIXME: 4. Let wasModal be the value of subject's is modal flag.
|
||||||
|
// FIXME: 5. Set the is modal flag of subject to false.
|
||||||
|
|
||||||
|
// 6. If result is not null, then set the returnValue attribute to result.
|
||||||
|
if (result.has_value())
|
||||||
|
set_return_value(result.release_value());
|
||||||
|
|
||||||
|
// FIXME: 7. If subject's previously focused element is not null, then:
|
||||||
|
// 1. Let element be subject's previously focused element.
|
||||||
|
// 2. Set subject's previously focused element to null.
|
||||||
|
// 3. If subject's node document's focused area of the document's DOM anchor is a shadow-including inclusive descendant of element,
|
||||||
|
// or wasModal is true, then run the focusing steps for element; the viewport should not be scrolled by doing this step.
|
||||||
|
|
||||||
|
// 8. Queue an element task on the user interaction task source given the subject element to fire an event named close at subject.
|
||||||
|
queue_an_element_task(HTML::Task::Source::UserInteraction, [this] {
|
||||||
|
auto close_event = DOM::Event::create(realm(), HTML::EventNames::close);
|
||||||
|
dispatch_event(close_event);
|
||||||
|
});
|
||||||
|
|
||||||
|
// FIXME: 9. If subject's close watcher is not null, then:
|
||||||
|
// 1. Destroy subject's close watcher.
|
||||||
|
// 2. Set subject's close watcher to null.
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ private:
|
||||||
|
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
|
||||||
|
void close_the_dialog(Optional<String> result);
|
||||||
|
|
||||||
String m_return_value;
|
String m_return_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue