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

LibWeb: Make EventTarget::activation_behavior a virtual function

(Instead of using an AK::Function on EventTarget). This shaves 48 bytes
off of every EventTarget instance.
This commit is contained in:
Andreas Kling 2023-11-18 10:48:09 +01:00
parent 84eecbb10e
commit a71eaefdf6
11 changed files with 108 additions and 64 deletions

View file

@ -242,7 +242,7 @@ bool EventDispatcher::dispatch(JS::NonnullGCPtr<EventTarget> target, Event& even
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)
if (is_activation_event && target->has_activation_behavior())
activation_target = target;
// 6. Let slottable be target, if target is a slottable and is assigned, and null otherwise.
@ -293,7 +293,7 @@ bool EventDispatcher::dispatch(JS::NonnullGCPtr<EventTarget> target, Event& even
if (is<HTML::Window>(parent)
|| (is<Node>(parent) && verify_cast<Node>(*target).root().is_shadow_including_inclusive_ancestor_of(verify_cast<Node>(*parent)))) {
// 1. If isActivationEvent is true, events bubbles attribute is true, activationTarget is null, and parent has activation behavior, then set activationTarget to parent.
if (is_activation_event && event.bubbles() && !activation_target && parent->activation_behavior)
if (is_activation_event && event.bubbles() && !activation_target && parent->has_activation_behavior())
activation_target = parent;
// 2. Append to an event path with event, parent, null, relatedTarget, touchTargets, and slot-in-closed-tree.
@ -309,7 +309,7 @@ bool EventDispatcher::dispatch(JS::NonnullGCPtr<EventTarget> target, Event& even
target = *parent;
// 1. If isActivationEvent is true, activationTarget is null, and target has activation behavior, then set activationTarget to target.
if (is_activation_event && !activation_target && target->activation_behavior)
if (is_activation_event && !activation_target && target->has_activation_behavior())
activation_target = target;
// 2. Append to an event path with event, parent, target, relatedTarget, touchTargets, and slot-in-closed-tree.

View file

@ -816,4 +816,13 @@ bool EventTarget::has_event_listeners() const
return !m_event_listener_list.is_empty();
}
bool EventTarget::has_activation_behavior() const
{
return false;
}
void EventTarget::activation_behavior(Event const&)
{
}
}

View file

@ -45,7 +45,8 @@ public:
Vector<JS::Handle<DOMEventListener>> event_listener_list();
Function<void(Event const&)> activation_behavior;
virtual bool has_activation_behavior() const;
virtual void activation_behavior(Event const&);
// NOTE: These only exist for checkbox and radio input elements.
virtual void legacy_pre_activation_behavior() { }