mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:37:34 +00:00
LibWeb: Support committing changes to <input> elements
We currently fire the change event on <input> elements when they lose focus. The spec allows for us to also fire the event when changes are "committed", so long as such an action makes sense for the input type. This patch detects when the return key is entered in an <input> element and uses that as the commit action for text-related types. If no change has occurred since the last commit, no change event is fired.
This commit is contained in:
parent
97665fa92f
commit
7edfeb7056
8 changed files with 88 additions and 11 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Internals/Internals.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
|
@ -62,6 +63,27 @@ JS::Object* Internals::hit_test(double x, double y)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void Internals::send_text(HTML::HTMLElement& target, String const& text)
|
||||
{
|
||||
auto* page = global_object().browsing_context()->page();
|
||||
if (!page)
|
||||
return;
|
||||
|
||||
target.focus();
|
||||
|
||||
for (auto code_point : text.code_points())
|
||||
page->handle_keydown(code_point_to_key_code(code_point), 0, code_point);
|
||||
}
|
||||
|
||||
void Internals::commit_text()
|
||||
{
|
||||
auto* page = global_object().browsing_context()->page();
|
||||
if (!page)
|
||||
return;
|
||||
|
||||
page->handle_keydown(Key_Return, 0, 0);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<bool> Internals::dispatch_user_activated_event(DOM::EventTarget& target, DOM::Event& event)
|
||||
{
|
||||
event.set_is_trusted(true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue