mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-28 23:39:02 +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:
parent
84eecbb10e
commit
a71eaefdf6
Notes:
sideshowbarker
2024-07-18 08:59:31 +09:00
Author: https://github.com/awesomekling
Commit: a71eaefdf6
Pull-request: https://github.com/SerenityOS/serenity/pull/21991
11 changed files with 108 additions and 64 deletions
|
@ -15,40 +15,6 @@ JS_DEFINE_ALLOCATOR(HTMLButtonElement);
|
|||
HTMLButtonElement::HTMLButtonElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
||||
: HTMLElement(document, move(qualified_name))
|
||||
{
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:activation-behaviour
|
||||
activation_behavior = [this](auto&) {
|
||||
// 1. If element is disabled, then return.
|
||||
if (!enabled())
|
||||
return;
|
||||
|
||||
// 2. If element does not have a form owner, then return.
|
||||
if (!form())
|
||||
return;
|
||||
|
||||
// 3. If element's node document is not fully active, then return.
|
||||
if (!this->document().is_fully_active())
|
||||
return;
|
||||
|
||||
// 4. Switch on element's type attribute's state:
|
||||
switch (type_state()) {
|
||||
case TypeAttributeState::Submit:
|
||||
// Submit Button
|
||||
// Submit element's form owner from element.
|
||||
form()->submit_form(*this).release_value_but_fixme_should_propagate_errors();
|
||||
break;
|
||||
case TypeAttributeState::Reset:
|
||||
// Reset Button
|
||||
// Reset element's form owner.
|
||||
form()->reset_form();
|
||||
break;
|
||||
case TypeAttributeState::Button:
|
||||
// Button
|
||||
// Do nothing.
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
HTMLButtonElement::~HTMLButtonElement() = default;
|
||||
|
@ -101,4 +67,45 @@ DeprecatedString HTMLButtonElement::value() const
|
|||
return deprecated_attribute(AttributeNames::value);
|
||||
}
|
||||
|
||||
bool HTMLButtonElement::has_activation_behavior() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void HTMLButtonElement::activation_behavior(DOM::Event const&)
|
||||
{
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:activation-behaviour
|
||||
// 1. If element is disabled, then return.
|
||||
if (!enabled())
|
||||
return;
|
||||
|
||||
// 2. If element does not have a form owner, then return.
|
||||
if (!form())
|
||||
return;
|
||||
|
||||
// 3. If element's node document is not fully active, then return.
|
||||
if (!this->document().is_fully_active())
|
||||
return;
|
||||
|
||||
// 4. Switch on element's type attribute's state:
|
||||
switch (type_state()) {
|
||||
case TypeAttributeState::Submit:
|
||||
// Submit Button
|
||||
// Submit element's form owner from element.
|
||||
form()->submit_form(*this).release_value_but_fixme_should_propagate_errors();
|
||||
break;
|
||||
case TypeAttributeState::Reset:
|
||||
// Reset Button
|
||||
// Reset element's form owner.
|
||||
form()->reset_form();
|
||||
break;
|
||||
case TypeAttributeState::Button:
|
||||
// Button
|
||||
// Do nothing.
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue