mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 20:29:18 +00:00
LibWeb: Add a testing helper to send a single named key to an element
Unlike internals.sendText(), this allows sending keys like the escape key.
This commit is contained in:
parent
f14e7c7261
commit
53f775afb9
Notes:
github-actions[bot]
2024-08-20 07:30:44 +00:00
Author: https://github.com/trflynn89
Commit: 53f775afb9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1129
3 changed files with 10 additions and 0 deletions
|
@ -72,6 +72,14 @@ void Internals::send_text(HTML::HTMLElement& target, String const& text)
|
||||||
page.handle_keydown(UIEvents::code_point_to_key_code(code_point), 0, code_point);
|
page.handle_keydown(UIEvents::code_point_to_key_code(code_point), 0, code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Internals::send_key(HTML::HTMLElement& target, String const& key_name)
|
||||||
|
{
|
||||||
|
auto key_code = UIEvents::key_code_from_string(key_name);
|
||||||
|
target.focus();
|
||||||
|
|
||||||
|
global_object().browsing_context()->page().handle_keydown(key_code, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void Internals::commit_text()
|
void Internals::commit_text()
|
||||||
{
|
{
|
||||||
global_object().browsing_context()->page().handle_keydown(UIEvents::Key_Return, 0, 0);
|
global_object().browsing_context()->page().handle_keydown(UIEvents::Key_Return, 0, 0);
|
||||||
|
|
|
@ -25,6 +25,7 @@ public:
|
||||||
JS::Object* hit_test(double x, double y);
|
JS::Object* hit_test(double x, double y);
|
||||||
|
|
||||||
void send_text(HTML::HTMLElement&, String const&);
|
void send_text(HTML::HTMLElement&, String const&);
|
||||||
|
void send_key(HTML::HTMLElement&, String const&);
|
||||||
void commit_text();
|
void commit_text();
|
||||||
|
|
||||||
void click(double x, double y);
|
void click(double x, double y);
|
||||||
|
|
|
@ -10,6 +10,7 @@ interface Internals {
|
||||||
object hitTest(double x, double y);
|
object hitTest(double x, double y);
|
||||||
|
|
||||||
undefined sendText(HTMLElement target, DOMString text);
|
undefined sendText(HTMLElement target, DOMString text);
|
||||||
|
undefined sendKey(HTMLElement target, DOMString keyName);
|
||||||
undefined commitText();
|
undefined commitText();
|
||||||
|
|
||||||
undefined click(double x, double y);
|
undefined click(double x, double y);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue