2024-07-18 19:35:14 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/Bindings/InputEventPrototype.h>
|
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
|
|
|
#include <LibWeb/UIEvents/InputEvent.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::UIEvents {
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(InputEvent);
|
2024-07-18 19:35:14 +01:00
|
|
|
|
2025-07-18 13:03:46 +01:00
|
|
|
GC::Ref<InputEvent> InputEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, InputEventInit const& event_init, Vector<GC::Ref<DOM::StaticRange>> const& target_ranges)
|
2024-02-24 06:08:26 +01:00
|
|
|
{
|
2025-07-18 13:03:46 +01:00
|
|
|
auto event = realm.create<InputEvent>(realm, event_name, event_init, target_ranges);
|
2024-10-20 21:54:32 +02:00
|
|
|
event->set_bubbles(true);
|
|
|
|
|
if (event_name == "beforeinput"_fly_string) {
|
|
|
|
|
event->set_cancelable(true);
|
|
|
|
|
}
|
|
|
|
|
return event;
|
2024-02-24 06:08:26 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<InputEvent>> InputEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, InputEventInit const& event_init)
|
2024-07-18 19:35:14 +01:00
|
|
|
{
|
2024-11-14 05:50:17 +13:00
|
|
|
return realm.create<InputEvent>(realm, event_name, event_init);
|
2024-07-18 19:35:14 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-18 13:03:46 +01:00
|
|
|
InputEvent::InputEvent(JS::Realm& realm, FlyString const& event_name, InputEventInit const& event_init, Vector<GC::Ref<DOM::StaticRange>> const& target_ranges)
|
2024-07-18 19:35:14 +01:00
|
|
|
: UIEvent(realm, event_name, event_init)
|
|
|
|
|
, m_data(event_init.data)
|
|
|
|
|
, m_is_composing(event_init.is_composing)
|
|
|
|
|
, m_input_type(event_init.input_type)
|
2025-07-18 13:03:46 +01:00
|
|
|
, m_target_ranges(target_ranges)
|
2024-07-18 19:35:14 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InputEvent::~InputEvent() = default;
|
|
|
|
|
|
|
|
|
|
void InputEvent::initialize(JS::Realm& realm)
|
|
|
|
|
{
|
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(InputEvent);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2024-07-18 19:35:14 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-18 13:03:46 +01:00
|
|
|
void InputEvent::visit_edges(Visitor& visitor)
|
2024-10-20 21:54:55 +02:00
|
|
|
{
|
2025-07-18 13:03:46 +01:00
|
|
|
Base::visit_edges(visitor);
|
|
|
|
|
visitor.visit(m_target_ranges);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://w3c.github.io/input-events/#dom-inputevent-gettargetranges
|
|
|
|
|
ReadonlySpan<GC::Ref<DOM::StaticRange>> InputEvent::get_target_ranges() const
|
|
|
|
|
{
|
|
|
|
|
// getTargetRanges() returns an array of StaticRanges representing the content that the event will modify if it is
|
|
|
|
|
// not canceled. The returned StaticRanges MUST cover only the code points that the browser would normally replace,
|
|
|
|
|
// even if they are only part of a grapheme cluster.
|
|
|
|
|
return m_target_ranges;
|
2024-10-20 21:54:55 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-18 19:35:14 +01:00
|
|
|
}
|