8
8
9
9
#include < AK/TypeCasts.h>
10
10
#include < Kernel/API/KeyCode.h>
11
+ #include < LibWeb/UIEvents/EventModifier.h>
11
12
#include < LibWeb/UIEvents/UIEvent.h>
12
13
13
14
namespace Web ::UIEvents {
14
15
16
+ struct KeyboardEventInit : public EventModifierInit {
17
+ String key { " " };
18
+ String code { " " };
19
+ u32 location { 0 };
20
+ bool repeat { false };
21
+ bool is_composing { false };
22
+ u32 key_code { 0 };
23
+ u32 char_code { 0 };
24
+ };
25
+
15
26
// https://www.w3.org/TR/uievents/#interface-keyboardevent
16
27
class KeyboardEvent final : public UIEvent {
17
28
public:
18
29
using WrapperType = Bindings::KeyboardEventWrapper;
19
30
20
- static NonnullRefPtr<KeyboardEvent> create (FlyString event_name, String key, String code, unsigned long location, bool ctrl_key, bool shift_key, bool alt_key, bool meta_key, bool repeat, bool is_composing, unsigned long key_code, unsigned long char_code)
31
+ static NonnullRefPtr<KeyboardEvent> create (FlyString const & event_name, KeyboardEventInit const & event_init = {})
32
+ {
33
+ return adopt_ref (*new KeyboardEvent (event_name, event_init));
34
+ }
35
+ static NonnullRefPtr<KeyboardEvent> create_with_global_object (Bindings::WindowObject&, FlyString const & event_name, KeyboardEventInit const & event_init)
21
36
{
22
- return adopt_ref (* new KeyboardEvent ( move ( event_name), move (key), move (code), location, ctrl_key, shift_key, alt_key, meta_key, repeat, is_composing, key_code, char_code) );
37
+ return KeyboardEvent::create ( event_name, event_init );
23
38
}
24
39
25
- static NonnullRefPtr<KeyboardEvent> create_from_platform_event (FlyString event_name, KeyCode, unsigned modifiers, u32 code_point);
40
+ static NonnullRefPtr<KeyboardEvent> create_from_platform_event (FlyString const & event_name, KeyCode, unsigned modifiers, u32 code_point);
26
41
27
- virtual ~KeyboardEvent () override ;
42
+ virtual ~KeyboardEvent () override = default ;
28
43
29
- unsigned long key_code () const { return m_key_code; }
30
- unsigned long char_code () const { return m_char_code; }
44
+ u32 key_code () const { return m_key_code; }
45
+ u32 char_code () const { return m_char_code; }
31
46
32
47
String key () const { return m_key; }
33
48
String code () const { return m_code; }
34
- unsigned long location () const { return m_location; }
49
+ u32 location () const { return m_location; }
35
50
36
51
bool ctrl_key () const { return m_ctrl_key; }
37
52
bool shift_key () const { return m_shift_key; }
@@ -44,19 +59,31 @@ class KeyboardEvent final : public UIEvent {
44
59
bool get_modifier_state (String const & key_arg);
45
60
46
61
private:
47
- KeyboardEvent (FlyString event_name, String key, String code, unsigned long location, bool ctrl_key, bool shift_key, bool alt_key, bool meta_key, bool repeat, bool is_composing, unsigned long key_code, unsigned long char_code);
62
+ KeyboardEvent (FlyString const & event_name, KeyboardEventInit const & event_init)
63
+ : UIEvent(event_name, event_init)
64
+ , m_key(event_init.key)
65
+ , m_code(event_init.code)
66
+ , m_location(event_init.location)
67
+ , m_ctrl_key(event_init.ctrl_key)
68
+ , m_shift_key(event_init.shift_key)
69
+ , m_alt_key(event_init.alt_key)
70
+ , m_meta_key(event_init.meta_key)
71
+ , m_repeat(event_init.repeat)
72
+ , m_is_composing(event_init.is_composing)
73
+ , m_key_code(event_init.key_code)
74
+ , m_char_code(event_init.char_code) {};
48
75
49
76
String m_key;
50
77
String m_code;
51
- unsigned long m_location { 0 };
78
+ u32 m_location { 0 };
52
79
bool m_ctrl_key { false };
53
80
bool m_shift_key { false };
54
81
bool m_alt_key { false };
55
82
bool m_meta_key { false };
56
83
bool m_repeat { false };
57
84
bool m_is_composing { false };
58
- unsigned long m_key_code { 0 };
59
- unsigned long m_char_code { 0 };
85
+ u32 m_key_code { 0 };
86
+ u32 m_char_code { 0 };
60
87
};
61
88
62
89
}
0 commit comments