mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:47:35 +00:00
LibWeb: Make DOM::Event and all its subclasses GC-allocated
This commit is contained in:
parent
a4ddb0ef87
commit
7c3db526b0
76 changed files with 892 additions and 565 deletions
|
@ -1,10 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/CharacterTypes.h>
|
||||
#include <LibWeb/Bindings/KeyboardEventPrototype.h>
|
||||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/UIEvents/KeyboardEvent.h>
|
||||
|
||||
namespace Web::UIEvents {
|
||||
|
@ -65,7 +67,7 @@ static unsigned long determine_key_code(KeyCode platform_key, u32 code_point)
|
|||
return platform_key;
|
||||
}
|
||||
|
||||
NonnullRefPtr<KeyboardEvent> KeyboardEvent::create_from_platform_event(FlyString const& event_name, KeyCode platform_key, unsigned modifiers, u32 code_point)
|
||||
KeyboardEvent* KeyboardEvent::create_from_platform_event(Bindings::WindowObject& window_object, FlyString const& event_name, KeyCode platform_key, unsigned modifiers, u32 code_point)
|
||||
{
|
||||
// FIXME: Figure out what these should actually contain.
|
||||
String event_key = key_code_to_string(platform_key);
|
||||
|
@ -87,7 +89,7 @@ NonnullRefPtr<KeyboardEvent> KeyboardEvent::create_from_platform_event(FlyString
|
|||
event_init.bubbles = true;
|
||||
event_init.cancelable = true;
|
||||
event_init.composed = true;
|
||||
return KeyboardEvent::create(event_name, event_init);
|
||||
return KeyboardEvent::create(window_object, event_name, event_init);
|
||||
}
|
||||
|
||||
bool KeyboardEvent::get_modifier_state(String const& key_arg)
|
||||
|
@ -102,4 +104,34 @@ bool KeyboardEvent::get_modifier_state(String const& key_arg)
|
|||
return m_meta_key;
|
||||
return false;
|
||||
}
|
||||
|
||||
KeyboardEvent* KeyboardEvent::create(Bindings::WindowObject& window_object, FlyString const& event_name, KeyboardEventInit const& event_init)
|
||||
{
|
||||
return window_object.heap().allocate<KeyboardEvent>(window_object.realm(), window_object, event_name, event_init);
|
||||
}
|
||||
|
||||
KeyboardEvent* KeyboardEvent::create_with_global_object(Bindings::WindowObject& window_object, FlyString const& event_name, KeyboardEventInit const& event_init)
|
||||
{
|
||||
return create(window_object, event_name, event_init);
|
||||
}
|
||||
|
||||
KeyboardEvent::KeyboardEvent(Bindings::WindowObject& window_object, FlyString const& event_name, KeyboardEventInit const& event_init)
|
||||
: UIEvent(window_object, event_name, event_init)
|
||||
, m_key(event_init.key)
|
||||
, m_code(event_init.code)
|
||||
, m_location(event_init.location)
|
||||
, m_ctrl_key(event_init.ctrl_key)
|
||||
, m_shift_key(event_init.shift_key)
|
||||
, m_alt_key(event_init.alt_key)
|
||||
, m_meta_key(event_init.meta_key)
|
||||
, m_repeat(event_init.repeat)
|
||||
, m_is_composing(event_init.is_composing)
|
||||
, m_key_code(event_init.key_code)
|
||||
, m_char_code(event_init.char_code)
|
||||
{
|
||||
set_prototype(&window_object.ensure_web_prototype<Bindings::KeyboardEventPrototype>("KeyboardEvent"));
|
||||
}
|
||||
|
||||
KeyboardEvent::~KeyboardEvent() = default;
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue