mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-12 11:09:18 +00:00
LibWeb: Support non-required numpad code names
These aren't required to comply with the UIEvents spec, but they are required by WebDriver.
This commit is contained in:
parent
a11e5055c7
commit
5b2633d90f
Notes:
github-actions[bot]
2024-10-10 08:42:15 +00:00
Author: https://github.com/trflynn89
Commit: 5b2633d90f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1706
6 changed files with 85 additions and 9 deletions
20
Tests/LibWeb/Text/expected/UIEvents/KeyEvent-numpad-keys.txt
Normal file
20
Tests/LibWeb/Text/expected/UIEvents/KeyEvent-numpad-keys.txt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
key="0" code=Numpad0
|
||||||
|
key="1" code=Numpad1
|
||||||
|
key="2" code=Numpad2
|
||||||
|
key="3" code=Numpad3
|
||||||
|
key="4" code=Numpad4
|
||||||
|
key="5" code=Numpad5
|
||||||
|
key="6" code=Numpad6
|
||||||
|
key="7" code=Numpad7
|
||||||
|
key="8" code=Numpad8
|
||||||
|
key="9" code=Numpad9
|
||||||
|
key="+" code=NumpadAdd
|
||||||
|
key="," code=NumpadComma
|
||||||
|
key="." code=NumpadDecimal
|
||||||
|
key="/" code=NumpadDivide
|
||||||
|
key="*" code=NumpadMultiply
|
||||||
|
key="-" code=NumpadSubtract
|
||||||
|
key="=" code=NumpadEqual
|
||||||
|
key="#" code=NumpadHash
|
||||||
|
key="(" code=NumpadParenLeft
|
||||||
|
key=")" code=NumpadParenRight
|
38
Tests/LibWeb/Text/input/UIEvents/KeyEvent-numpad-keys.html
Normal file
38
Tests/LibWeb/Text/input/UIEvents/KeyEvent-numpad-keys.html
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
<input id="input" />
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
const NUMPAD_KEYS = [
|
||||||
|
"0",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
"5",
|
||||||
|
"6",
|
||||||
|
"7",
|
||||||
|
"8",
|
||||||
|
"9",
|
||||||
|
"+",
|
||||||
|
",",
|
||||||
|
".",
|
||||||
|
"/",
|
||||||
|
"*",
|
||||||
|
"-",
|
||||||
|
"=",
|
||||||
|
"#",
|
||||||
|
"(",
|
||||||
|
")",
|
||||||
|
];
|
||||||
|
|
||||||
|
test(() => {
|
||||||
|
let input = document.getElementById("input");
|
||||||
|
|
||||||
|
input.addEventListener("keydown", e => {
|
||||||
|
println(`key="${e.key}" code=${e.code}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
NUMPAD_KEYS.forEach(key => {
|
||||||
|
internals.sendText(input, key, internals.MOD_KEYPAD);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -74,21 +74,21 @@ JS::Object* Internals::hit_test(double x, double y)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internals::send_text(HTML::HTMLElement& target, String const& text)
|
void Internals::send_text(HTML::HTMLElement& target, String const& text, WebIDL::UnsignedShort modifiers)
|
||||||
{
|
{
|
||||||
auto& page = internals_page();
|
auto& page = internals_page();
|
||||||
target.focus();
|
target.focus();
|
||||||
|
|
||||||
for (auto code_point : text.code_points())
|
for (auto code_point : text.code_points())
|
||||||
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), modifiers, code_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internals::send_key(HTML::HTMLElement& target, String const& key_name)
|
void Internals::send_key(HTML::HTMLElement& target, String const& key_name, WebIDL::UnsignedShort modifiers)
|
||||||
{
|
{
|
||||||
auto key_code = UIEvents::key_code_from_string(key_name);
|
auto key_code = UIEvents::key_code_from_string(key_name);
|
||||||
target.focus();
|
target.focus();
|
||||||
|
|
||||||
internals_page().handle_keydown(key_code, 0, 0);
|
internals_page().handle_keydown(key_code, modifiers, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internals::commit_text()
|
void Internals::commit_text()
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <LibWeb/Bindings/PlatformObject.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
#include <LibWeb/Internals/InternalAnimationTimeline.h>
|
#include <LibWeb/Internals/InternalAnimationTimeline.h>
|
||||||
#include <LibWeb/UIEvents/MouseButton.h>
|
#include <LibWeb/UIEvents/MouseButton.h>
|
||||||
|
#include <LibWeb/WebIDL/Types.h>
|
||||||
|
|
||||||
namespace Web::Internals {
|
namespace Web::Internals {
|
||||||
|
|
||||||
|
@ -24,8 +25,8 @@ public:
|
||||||
void gc();
|
void gc();
|
||||||
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&, WebIDL::UnsignedShort modifiers);
|
||||||
void send_key(HTML::HTMLElement&, String const&);
|
void send_key(HTML::HTMLElement&, String const&, WebIDL::UnsignedShort modifiers);
|
||||||
void commit_text();
|
void commit_text();
|
||||||
|
|
||||||
void click(double x, double y);
|
void click(double x, double y);
|
||||||
|
|
|
@ -9,8 +9,15 @@ interface Internals {
|
||||||
undefined gc();
|
undefined gc();
|
||||||
object hitTest(double x, double y);
|
object hitTest(double x, double y);
|
||||||
|
|
||||||
undefined sendText(HTMLElement target, DOMString text);
|
const unsigned short MOD_NONE = 0;
|
||||||
undefined sendKey(HTMLElement target, DOMString keyName);
|
const unsigned short MOD_ALT = 1;
|
||||||
|
const unsigned short MOD_CTRL = 2;
|
||||||
|
const unsigned short MOD_SHIFT = 4;
|
||||||
|
const unsigned short MOD_SUPER = 8;
|
||||||
|
const unsigned short MOD_KEYPAD = 16;
|
||||||
|
|
||||||
|
undefined sendText(HTMLElement target, DOMString text, optional unsigned short modifiers = 0);
|
||||||
|
undefined sendKey(HTMLElement target, DOMString keyName, optional unsigned short modifiers = 0);
|
||||||
undefined commitText();
|
undefined commitText();
|
||||||
|
|
||||||
undefined click(double x, double y);
|
undefined click(double x, double y);
|
||||||
|
|
|
@ -326,6 +326,8 @@ static ErrorOr<String> get_event_code(KeyCode platform_key, unsigned modifiers)
|
||||||
return "Numpad9"_string;
|
return "Numpad9"_string;
|
||||||
case KeyCode::Key_Plus:
|
case KeyCode::Key_Plus:
|
||||||
return "NumpadAdd"_string;
|
return "NumpadAdd"_string;
|
||||||
|
case KeyCode::Key_Comma:
|
||||||
|
return "NumpadComma"_string;
|
||||||
case KeyCode::Key_Period:
|
case KeyCode::Key_Period:
|
||||||
case KeyCode::Key_Delete:
|
case KeyCode::Key_Delete:
|
||||||
return "NumpadDecimal"_string;
|
return "NumpadDecimal"_string;
|
||||||
|
@ -334,9 +336,17 @@ static ErrorOr<String> get_event_code(KeyCode platform_key, unsigned modifiers)
|
||||||
case KeyCode::Key_Return:
|
case KeyCode::Key_Return:
|
||||||
return "NumpadEnter"_string;
|
return "NumpadEnter"_string;
|
||||||
case KeyCode::Key_Asterisk:
|
case KeyCode::Key_Asterisk:
|
||||||
return "NumpadAsterisk"_string;
|
return "NumpadMultiply"_string;
|
||||||
case KeyCode::Key_Minus:
|
case KeyCode::Key_Minus:
|
||||||
return "NumpadSubtract"_string;
|
return "NumpadSubtract"_string;
|
||||||
|
case KeyCode::Key_Equal:
|
||||||
|
return "NumpadEqual"_string;
|
||||||
|
case KeyCode::Key_Hashtag:
|
||||||
|
return "NumpadHash"_string;
|
||||||
|
case KeyCode::Key_LeftParen:
|
||||||
|
return "NumpadParenLeft"_string;
|
||||||
|
case KeyCode::Key_RightParen:
|
||||||
|
return "NumpadParenRight"_string;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue