1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 17:17:45 +00:00

LibWeb: Port {Mouse,UI,Wheel,}Event to new String

This ports MouseEvent, UIEvent, WheelEvent, and Event to new String.
They all had a dependency to T::create() in
WebDriverConnection::fire_an_event() and therefore had to be ported in
the same commit.
This commit is contained in:
Kenneth Myhra 2023-04-06 16:12:33 +02:00 committed by Linus Groh
parent e0002aa993
commit ad5cbdc51b
48 changed files with 160 additions and 160 deletions

View file

@ -62,7 +62,7 @@ void AbortSignal::signal_abort(JS::Value reason)
m_abort_algorithms.clear();
// 5. Fire an event named abort at signal.
dispatch_event(Event::create(realm(), HTML::EventNames::abort.to_deprecated_fly_string()).release_value_but_fixme_should_propagate_errors());
dispatch_event(Event::create(realm(), HTML::EventNames::abort).release_value_but_fixme_should_propagate_errors());
}
void AbortSignal::set_onabort(WebIDL::CallbackType* event_handler)

View file

@ -22,7 +22,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CustomEvent>> CustomEvent::construct_impl(J
}
CustomEvent::CustomEvent(JS::Realm& realm, FlyString const& event_name, CustomEventInit const& event_init)
: Event(realm, event_name.to_deprecated_fly_string(), event_init)
: Event(realm, event_name, event_init)
, m_detail(event_init.detail)
{
}
@ -51,7 +51,7 @@ void CustomEvent::init_custom_event(String const& type, bool bubbles, bool cance
return;
// 2. Initialize this with type, bubbles, and cancelable.
initialize_event(type.to_deprecated_string(), bubbles, cancelable);
initialize_event(type, bubbles, cancelable);
// 3. Set thiss detail attribute to detail.
m_detail = detail;

View file

@ -1010,7 +1010,7 @@ void Document::set_hovered_node(Node* node)
// FIXME: Check if we need to dispatch these events in a specific order.
for (auto target = old_hovered_node; target && target.ptr() != common_ancestor; target = target->parent()) {
// FIXME: Populate the event with mouse coordinates, etc.
target->dispatch_event(UIEvents::MouseEvent::create(realm(), UIEvents::EventNames::mouseleave.to_deprecated_fly_string()).release_value_but_fixme_should_propagate_errors());
target->dispatch_event(UIEvents::MouseEvent::create(realm(), UIEvents::EventNames::mouseleave).release_value_but_fixme_should_propagate_errors());
}
}
@ -1019,7 +1019,7 @@ void Document::set_hovered_node(Node* node)
// FIXME: Check if we need to dispatch these events in a specific order.
for (auto target = m_hovered_node; target && target.ptr() != common_ancestor; target = target->parent()) {
// FIXME: Populate the event with mouse coordinates, etc.
target->dispatch_event(UIEvents::MouseEvent::create(realm(), UIEvents::EventNames::mouseenter.to_deprecated_fly_string()).release_value_but_fixme_should_propagate_errors());
target->dispatch_event(UIEvents::MouseEvent::create(realm(), UIEvents::EventNames::mouseenter).release_value_but_fixme_should_propagate_errors());
}
}
}
@ -1292,44 +1292,44 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(DeprecatedSt
// 2. If interface is an ASCII case-insensitive match for any of the strings in the first column in the following table,
// then set constructor to the interface in the second column on the same row as the matching string:
if (Infra::is_ascii_case_insensitive_match(interface, "beforeunloadevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create BeforeUnloadEvent
event = TRY(Event::create(realm, FlyString {})); // FIXME: Create BeforeUnloadEvent
} else if (Infra::is_ascii_case_insensitive_match(interface, "compositionevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create CompositionEvent
event = TRY(Event::create(realm, FlyString {})); // FIXME: Create CompositionEvent
} else if (Infra::is_ascii_case_insensitive_match(interface, "customevent"sv)) {
event = TRY(CustomEvent::create(realm, FlyString {}));
} else if (Infra::is_ascii_case_insensitive_match(interface, "devicemotionevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create DeviceMotionEvent
event = TRY(Event::create(realm, FlyString {})); // FIXME: Create DeviceMotionEvent
} else if (Infra::is_ascii_case_insensitive_match(interface, "deviceorientationevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create DeviceOrientationEvent
event = TRY(Event::create(realm, FlyString {})); // FIXME: Create DeviceOrientationEvent
} else if (Infra::is_ascii_case_insensitive_match(interface, "dragevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create DragEvent
event = TRY(Event::create(realm, FlyString {})); // FIXME: Create DragEvent
} else if (Infra::is_ascii_case_insensitive_match(interface, "event"sv)
|| Infra::is_ascii_case_insensitive_match(interface, "events"sv)) {
event = TRY(Event::create(realm, ""));
event = TRY(Event::create(realm, FlyString {}));
} else if (Infra::is_ascii_case_insensitive_match(interface, "focusevent"sv)) {
event = TRY(UIEvents::FocusEvent::create(realm, ""));
event = TRY(UIEvents::FocusEvent::create(realm, FlyString {}));
} else if (Infra::is_ascii_case_insensitive_match(interface, "hashchangeevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create HashChangeEvent
event = TRY(Event::create(realm, FlyString {})); // FIXME: Create HashChangeEvent
} else if (Infra::is_ascii_case_insensitive_match(interface, "htmlevents"sv)) {
event = TRY(Event::create(realm, ""));
event = TRY(Event::create(realm, FlyString {}));
} else if (Infra::is_ascii_case_insensitive_match(interface, "keyboardevent"sv)) {
event = TRY(UIEvents::KeyboardEvent::create(realm, String {}));
} else if (Infra::is_ascii_case_insensitive_match(interface, "messageevent"sv)) {
event = TRY(HTML::MessageEvent::create(realm, String {}));
} else if (Infra::is_ascii_case_insensitive_match(interface, "mouseevent"sv)
|| Infra::is_ascii_case_insensitive_match(interface, "mouseevents"sv)) {
event = TRY(UIEvents::MouseEvent::create(realm, ""));
event = TRY(UIEvents::MouseEvent::create(realm, FlyString {}));
} else if (Infra::is_ascii_case_insensitive_match(interface, "storageevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create StorageEvent
event = TRY(Event::create(realm, FlyString {})); // FIXME: Create StorageEvent
} else if (Infra::is_ascii_case_insensitive_match(interface, "svgevents"sv)) {
event = TRY(Event::create(realm, ""));
event = TRY(Event::create(realm, FlyString {}));
} else if (Infra::is_ascii_case_insensitive_match(interface, "textevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create CompositionEvent
event = TRY(Event::create(realm, FlyString {})); // FIXME: Create CompositionEvent
} else if (Infra::is_ascii_case_insensitive_match(interface, "touchevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create TouchEvent
event = TRY(Event::create(realm, FlyString {})); // FIXME: Create TouchEvent
} else if (Infra::is_ascii_case_insensitive_match(interface, "uievent"sv)
|| Infra::is_ascii_case_insensitive_match(interface, "uievents"sv)) {
event = TRY(UIEvents::UIEvent::create(realm, ""));
event = TRY(UIEvents::UIEvent::create(realm, FlyString {}));
}
// 3. If constructor is null, then throw a "NotSupportedError" DOMException.
@ -1589,7 +1589,7 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value)
}
// 4. Fire an event named readystatechange at document.
dispatch_event(Event::create(realm(), HTML::EventNames::readystatechange.to_deprecated_fly_string()).release_value_but_fixme_should_propagate_errors());
dispatch_event(Event::create(realm(), HTML::EventNames::readystatechange).release_value_but_fixme_should_propagate_errors());
}
Page* Document::page()
@ -1604,7 +1604,7 @@ Page const* Document::page() const
EventTarget* Document::get_parent(Event const& event)
{
if (event.type() == HTML::EventNames::load.to_deprecated_fly_string())
if (event.type() == HTML::EventNames::load)
return nullptr;
return m_window;
@ -1637,7 +1637,7 @@ void Document::completely_finish_loading()
// 5. Otherwise, if container is non-null, then queue an element task on the DOM manipulation task source given container to fire an event named load at container.
else if (container) {
container->queue_an_element_task(HTML::Task::Source::DOMManipulation, [container] {
container->dispatch_event(DOM::Event::create(container->realm(), HTML::EventNames::load.to_deprecated_fly_string()).release_value_but_fixme_should_propagate_errors());
container->dispatch_event(DOM::Event::create(container->realm(), HTML::EventNames::load).release_value_but_fixme_should_propagate_errors());
});
}
}
@ -1767,7 +1767,7 @@ void Document::update_the_visibility_state(HTML::VisibilityState visibility_stat
// FIXME: 3. Run any page visibility change steps which may be defined in other specifications, with visibility state and document.
// 4. Fire an event named visibilitychange at document, with its bubbles attribute initialized to true.
auto event = DOM::Event::create(realm(), HTML::EventNames::visibilitychange.to_deprecated_fly_string()).release_value_but_fixme_should_propagate_errors();
auto event = DOM::Event::create(realm(), HTML::EventNames::visibilitychange).release_value_but_fixme_should_propagate_errors();
event->set_bubbles(true);
dispatch_event(event);
}
@ -1788,7 +1788,7 @@ void Document::run_the_resize_steps()
return;
m_last_viewport_size = viewport_size;
window().dispatch_event(DOM::Event::create(realm(), UIEvents::EventNames::resize.to_deprecated_fly_string()).release_value_but_fixme_should_propagate_errors());
window().dispatch_event(DOM::Event::create(realm(), UIEvents::EventNames::resize).release_value_but_fixme_should_propagate_errors());
schedule_layout_update();
}
@ -1800,14 +1800,14 @@ void Document::run_the_scroll_steps()
for (auto& target : m_pending_scroll_event_targets) {
// 1. If target is a Document, fire an event named scroll that bubbles at target and fire an event named scroll at the VisualViewport that is associated with target.
if (is<Document>(*target)) {
auto event = DOM::Event::create(realm(), HTML::EventNames::scroll.to_deprecated_fly_string()).release_value_but_fixme_should_propagate_errors();
auto event = DOM::Event::create(realm(), HTML::EventNames::scroll).release_value_but_fixme_should_propagate_errors();
event->set_bubbles(true);
target->dispatch_event(event);
// FIXME: Fire at the associated VisualViewport
}
// 2. Otherwise, fire an event named scroll at target.
else {
auto event = DOM::Event::create(realm(), HTML::EventNames::scroll.to_deprecated_fly_string()).release_value_but_fixme_should_propagate_errors();
auto event = DOM::Event::create(realm(), HTML::EventNames::scroll).release_value_but_fixme_should_propagate_errors();
target->dispatch_event(event);
}
}
@ -1847,7 +1847,7 @@ void Document::evaluate_media_queries_and_report_changes()
CSS::MediaQueryListEventInit init;
init.media = String::from_deprecated_string(media_query_list->media()).release_value_but_fixme_should_propagate_errors();
init.matches = now_matches;
auto event = CSS::MediaQueryListEvent::create(realm(), HTML::EventNames::change.to_deprecated_fly_string(), init).release_value_but_fixme_should_propagate_errors();
auto event = CSS::MediaQueryListEvent::create(realm(), HTML::EventNames::change, init).release_value_but_fixme_should_propagate_errors();
event->set_is_trusted(true);
media_query_list->dispatch_event(*event);
}
@ -2347,7 +2347,7 @@ void Document::unload(bool recursive_flag, Optional<DocumentUnloadTimingInfo> un
// then fire an event named unload at document's relevant global object, with legacy target override flag set.
// FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event()
// We should reorganize this so that the flag appears explicitly here instead.
auto event = DOM::Event::create(realm(), HTML::EventNames::unload.to_deprecated_fly_string()).release_value_but_fixme_should_propagate_errors();
auto event = DOM::Event::create(realm(), HTML::EventNames::unload).release_value_but_fixme_should_propagate_errors();
global_object().dispatch_event(event);
}

View file

@ -14,24 +14,24 @@
namespace Web::DOM {
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Event::create(JS::Realm& realm, DeprecatedFlyString const& event_name, EventInit const& event_init)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Event::create(JS::Realm& realm, FlyString const& event_name, EventInit const& event_init)
{
return MUST_OR_THROW_OOM(realm.heap().allocate<Event>(realm, realm, event_name, event_init));
}
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Event::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, EventInit const& event_init)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Event::construct_impl(JS::Realm& realm, FlyString const& event_name, EventInit const& event_init)
{
return create(realm, event_name, event_init);
}
Event::Event(JS::Realm& realm, DeprecatedFlyString const& type)
Event::Event(JS::Realm& realm, FlyString const& type)
: PlatformObject(realm)
, m_type(type)
, m_initialized(true)
{
}
Event::Event(JS::Realm& realm, DeprecatedFlyString const& type, EventInit const& event_init)
Event::Event(JS::Realm& realm, FlyString const& type, EventInit const& event_init)
: PlatformObject(realm)
, m_type(type)
, m_bubbles(event_init.bubbles)
@ -100,7 +100,7 @@ void Event::set_cancelled_flag()
}
// https://dom.spec.whatwg.org/#concept-event-initialize
void Event::initialize_event(DeprecatedString const& type, bool bubbles, bool cancelable)
void Event::initialize_event(String const& type, bool bubbles, bool cancelable)
{
// 1. Set events initialized flag.
m_initialized = true;
@ -127,7 +127,7 @@ void Event::initialize_event(DeprecatedString const& type, bool bubbles, bool ca
}
// https://dom.spec.whatwg.org/#dom-event-initevent
void Event::init_event(DeprecatedString const& type, bool bubbles, bool cancelable)
void Event::init_event(String const& type, bool bubbles, bool cancelable)
{
// 1. If thiss dispatch flag is set, then return.
if (m_dispatch)

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/DOM/EventTarget.h>
@ -45,18 +45,18 @@ public:
using Path = Vector<PathEntry>;
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> create(JS::Realm&, DeprecatedFlyString const& event_name, EventInit const& event_init = {});
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, EventInit const& event_init);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> create(JS::Realm&, FlyString const& event_name, EventInit const& event_init = {});
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> construct_impl(JS::Realm&, FlyString const& event_name, EventInit const& event_init);
Event(JS::Realm&, DeprecatedFlyString const& type);
Event(JS::Realm&, DeprecatedFlyString const& type, EventInit const& event_init);
Event(JS::Realm&, FlyString const& type);
Event(JS::Realm&, FlyString const& type, EventInit const& event_init);
virtual ~Event() = default;
double time_stamp() const;
DeprecatedFlyString const& type() const { return m_type; }
void set_type(StringView type) { m_type = type; }
FlyString const& type() const { return m_type; }
void set_type(FlyString const& type) { m_type = type; }
JS::GCPtr<EventTarget> target() const { return m_target; }
void set_target(EventTarget* target) { m_target = target; }
@ -137,20 +137,20 @@ public:
m_stop_immediate_propagation = true;
}
void init_event(DeprecatedString const&, bool, bool);
void init_event(String const&, bool, bool);
void set_time_stamp(double time_stamp) { m_time_stamp = time_stamp; }
Vector<JS::Handle<EventTarget>> composed_path() const;
protected:
void initialize_event(DeprecatedString const&, bool, bool);
void initialize_event(String const&, bool, bool);
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual void visit_edges(Visitor&) override;
private:
DeprecatedFlyString m_type;
FlyString m_type;
JS::GCPtr<EventTarget> m_target;
JS::GCPtr<EventTarget> m_related_target;
JS::GCPtr<EventTarget> m_current_target;

View file

@ -1,7 +1,7 @@
#import <DOM/EventTarget.idl>
// https://dom.spec.whatwg.org/#event
[Exposed=*]
[Exposed=*, UseNewAKString]
interface Event {
constructor(DOMString type, optional EventInit eventInitDict = {});

View file

@ -63,7 +63,7 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<JS::Handle<DOM::DOMEvent
continue;
// 1. If events type attribute value is not listeners type, then continue.
if (event.type() != listener->type)
if (event.type().to_deprecated_fly_string() != listener->type)
continue;
// 2. Set found to true.
@ -180,14 +180,14 @@ void EventDispatcher::invoke(Event::PathEntry& struct_, Event& event, Event::Pha
// 2. If events type attribute value is a match for any of the strings in the first column in the following table,
// set events type attribute value to the string in the second column on the same row as the matching string, and return otherwise.
if (event.type() == "animationend")
event.set_type("webkitAnimationEnd"sv);
else if (event.type() == "animationiteration")
event.set_type("webkitAnimationIteration"sv);
else if (event.type() == "animationstart")
event.set_type("webkitAnimationStart"sv);
else if (event.type() == "transitionend")
event.set_type("webkitTransitionEnd"sv);
if (event.type() == HTML::EventNames::animationend)
event.set_type(HTML::EventNames::webkitAnimationEnd);
else if (event.type() == HTML::EventNames::animationiteration)
event.set_type(HTML::EventNames::webkitAnimationIteration);
else if (event.type() == HTML::EventNames::animationstart)
event.set_type(HTML::EventNames::webkitAnimationStart);
else if (event.type() == HTML::EventNames::transitionend)
event.set_type(HTML::EventNames::webkitTransitionEnd);
else
return;
@ -235,7 +235,7 @@ bool EventDispatcher::dispatch(JS::NonnullGCPtr<EventTarget> target, Event& even
event.append_to_path(*target, target_override, related_target, touch_targets, false);
// 4. Let isActivationEvent be true, if event is a MouseEvent object and events type attribute is "click"; otherwise false.
bool is_activation_event = is<UIEvents::MouseEvent>(event) && FlyString::from_deprecated_fly_string(event.type()).release_value() == HTML::EventNames::click;
bool is_activation_event = is<UIEvents::MouseEvent>(event) && event.type() == HTML::EventNames::click;
// 5. If isActivationEvent is true and target has activation behavior, then set activationTarget to target.
if (is_activation_event && target->activation_behavior)

View file

@ -616,7 +616,7 @@ JS::ThrowCompletionOr<void> EventTarget::process_event_handler_for_event(Depreca
// 3. Let special error event handling be true if event is an ErrorEvent object, event's type is error, and event's currentTarget implements the WindowOrWorkerGlobalScope mixin.
// Otherwise, let special error event handling be false.
// FIXME: This doesn't check for WorkerGlobalScape as we don't currently have it.
bool special_error_event_handling = is<HTML::ErrorEvent>(event) && event.type() == HTML::EventNames::error.to_deprecated_fly_string() && is<HTML::Window>(event.current_target().ptr());
bool special_error_event_handling = is<HTML::ErrorEvent>(event) && event.type() == HTML::EventNames::error && is<HTML::Window>(event.current_target().ptr());
// 4. Process the Event object event as follows:
JS::Completion return_value_or_error;