mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 20:27:46 +00:00
LibWeb: Port KeyboardEvent to new String
This commit is contained in:
parent
e14be3927a
commit
03d6cb88ff
5 changed files with 26 additions and 23 deletions
|
@ -66,11 +66,13 @@ static unsigned long determine_key_code(KeyCode platform_key, u32 code_point)
|
|||
return platform_key;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> KeyboardEvent::create_from_platform_event(JS::Realm& realm, DeprecatedFlyString const& event_name, KeyCode platform_key, unsigned modifiers, u32 code_point)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> KeyboardEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, KeyCode platform_key, unsigned modifiers, u32 code_point)
|
||||
{
|
||||
auto& vm = realm.vm();
|
||||
|
||||
// FIXME: Figure out what these should actually contain.
|
||||
DeprecatedString event_key = key_code_to_string(platform_key);
|
||||
DeprecatedString event_code = "FIXME";
|
||||
auto event_key = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(key_code_to_string(platform_key)));
|
||||
auto event_code = TRY_OR_THROW_OOM(vm, "FIXME"_string);
|
||||
|
||||
auto key_code = determine_key_code(platform_key, code_point);
|
||||
KeyboardEventInit event_init {};
|
||||
|
@ -91,7 +93,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> KeyboardEvent::create_from_
|
|||
return KeyboardEvent::create(realm, event_name, event_init);
|
||||
}
|
||||
|
||||
bool KeyboardEvent::get_modifier_state(DeprecatedString const& key_arg)
|
||||
bool KeyboardEvent::get_modifier_state(String const& key_arg)
|
||||
{
|
||||
if (key_arg == "Alt")
|
||||
return m_alt_key;
|
||||
|
@ -104,18 +106,18 @@ bool KeyboardEvent::get_modifier_state(DeprecatedString const& key_arg)
|
|||
return false;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> KeyboardEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> KeyboardEvent::create(JS::Realm& realm, FlyString const& event_name, KeyboardEventInit const& event_init)
|
||||
{
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<KeyboardEvent>(realm, realm, event_name, event_init));
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> KeyboardEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> KeyboardEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, KeyboardEventInit const& event_init)
|
||||
{
|
||||
return create(realm, event_name, event_init);
|
||||
}
|
||||
|
||||
KeyboardEvent::KeyboardEvent(JS::Realm& realm, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init)
|
||||
: UIEvent(realm, event_name, event_init)
|
||||
KeyboardEvent::KeyboardEvent(JS::Realm& realm, FlyString const& event_name, KeyboardEventInit const& event_init)
|
||||
: UIEvent(realm, event_name.to_deprecated_fly_string(), event_init)
|
||||
, m_key(event_init.key)
|
||||
, m_code(event_init.code)
|
||||
, m_location(event_init.location)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/TypeCasts.h>
|
||||
#include <Kernel/API/KeyCode.h>
|
||||
#include <LibWeb/UIEvents/EventModifier.h>
|
||||
|
@ -14,8 +15,8 @@
|
|||
namespace Web::UIEvents {
|
||||
|
||||
struct KeyboardEventInit : public EventModifierInit {
|
||||
DeprecatedString key { "" };
|
||||
DeprecatedString code { "" };
|
||||
String key;
|
||||
String code;
|
||||
u32 location { 0 };
|
||||
bool repeat { false };
|
||||
bool is_composing { false };
|
||||
|
@ -28,17 +29,17 @@ class KeyboardEvent final : public UIEvent {
|
|||
WEB_PLATFORM_OBJECT(KeyboardEvent, UIEvent);
|
||||
|
||||
public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> create(JS::Realm&, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init = {});
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> create_from_platform_event(JS::Realm&, DeprecatedFlyString const& event_name, KeyCode, unsigned modifiers, u32 code_point);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> create(JS::Realm&, FlyString const& event_name, KeyboardEventInit const& event_init = {});
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> construct_impl(JS::Realm&, FlyString const& event_name, KeyboardEventInit const& event_init);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> create_from_platform_event(JS::Realm&, FlyString const& event_name, KeyCode, unsigned modifiers, u32 code_point);
|
||||
|
||||
virtual ~KeyboardEvent() override;
|
||||
|
||||
u32 key_code() const { return m_key_code; }
|
||||
u32 char_code() const { return m_char_code; }
|
||||
|
||||
DeprecatedString key() const { return m_key; }
|
||||
DeprecatedString code() const { return m_code; }
|
||||
String key() const { return m_key; }
|
||||
String code() const { return m_code; }
|
||||
u32 location() const { return m_location; }
|
||||
|
||||
bool ctrl_key() const { return m_ctrl_key; }
|
||||
|
@ -49,17 +50,17 @@ public:
|
|||
bool repeat() const { return m_repeat; }
|
||||
bool is_composing() const { return m_is_composing; }
|
||||
|
||||
bool get_modifier_state(DeprecatedString const& key_arg);
|
||||
bool get_modifier_state(String const& key_arg);
|
||||
|
||||
virtual u32 which() const override { return m_key_code; }
|
||||
|
||||
private:
|
||||
KeyboardEvent(JS::Realm&, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init);
|
||||
KeyboardEvent(JS::Realm&, FlyString const& event_name, KeyboardEventInit const& event_init);
|
||||
|
||||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||
|
||||
DeprecatedString m_key;
|
||||
DeprecatedString m_code;
|
||||
String m_key;
|
||||
String m_code;
|
||||
u32 m_location { 0 };
|
||||
bool m_ctrl_key { false };
|
||||
bool m_shift_key { false };
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#import <UIEvents/EventModifier.idl>
|
||||
|
||||
[Exposed=Window]
|
||||
[Exposed=Window, UseNewAKString]
|
||||
interface KeyboardEvent : UIEvent {
|
||||
|
||||
constructor(DOMString type, optional KeyboardEventInit eventInitDict = {});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue