LibWeb: Pass the old attribute value to Element::attribute_changed()

This commit is contained in:
Tim Ledbetter 2024-07-09 20:18:41 +01:00 committed by Andreas Kling
commit a552bda8d9
Notes: sideshowbarker 2024-07-17 18:13:59 +09:00
71 changed files with 132 additions and 132 deletions

View file

@ -19,33 +19,33 @@ namespace Web::HTML {
// HTMLElement::inserted() -> Use form_associated_element_was_inserted()
// HTMLElement::removed_from() -> Use form_associated_element_was_removed()
//
#define FORM_ASSOCIATED_ELEMENT(ElementBaseClass, ElementClass) \
private: \
virtual HTMLElement& form_associated_element_to_html_element() override \
{ \
static_assert(IsBaseOf<HTMLElement, ElementClass>); \
return *this; \
} \
\
virtual void inserted() override \
{ \
ElementBaseClass::inserted(); \
form_node_was_inserted(); \
form_associated_element_was_inserted(); \
} \
\
virtual void removed_from(DOM::Node* node) override \
{ \
ElementBaseClass::removed_from(node); \
form_node_was_removed(); \
form_associated_element_was_removed(node); \
} \
\
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override \
{ \
ElementBaseClass::attribute_changed(name, value); \
form_node_attribute_changed(name, value); \
form_associated_element_attribute_changed(name, value); \
#define FORM_ASSOCIATED_ELEMENT(ElementBaseClass, ElementClass) \
private: \
virtual HTMLElement& form_associated_element_to_html_element() override \
{ \
static_assert(IsBaseOf<HTMLElement, ElementClass>); \
return *this; \
} \
\
virtual void inserted() override \
{ \
ElementBaseClass::inserted(); \
form_node_was_inserted(); \
form_associated_element_was_inserted(); \
} \
\
virtual void removed_from(DOM::Node* node) override \
{ \
ElementBaseClass::removed_from(node); \
form_node_was_removed(); \
form_associated_element_was_removed(node); \
} \
\
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override \
{ \
ElementBaseClass::attribute_changed(name, old_value, value); \
form_node_attribute_changed(name, value); \
form_associated_element_attribute_changed(name, value); \
}
class FormAssociatedElement {

View file

@ -40,9 +40,9 @@ void HTMLAnchorElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_rel_list);
}
void HTMLAnchorElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLAnchorElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
HTMLElement::attribute_changed(name, old_value, value);
if (name == HTML::AttributeNames::href) {
set_the_url();
} else if (name == HTML::AttributeNames::rel) {

View file

@ -45,7 +45,7 @@ private:
virtual void activation_behavior(Web::DOM::Event const&) override;
// ^DOM::Element
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
virtual i32 default_tab_index_value() const override;
// ^HTML::HTMLHyperlinkElementUtils

View file

@ -33,9 +33,9 @@ void HTMLAreaElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_rel_list);
}
void HTMLAreaElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLAreaElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
HTMLElement::attribute_changed(name, old_value, value);
if (name == HTML::AttributeNames::href) {
set_the_url();
} else if (name == HTML::AttributeNames::rel) {

View file

@ -29,7 +29,7 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
// ^DOM::Element
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
virtual i32 default_tab_index_value() const override;
// ^HTML::HTMLHyperlinkElementUtils

View file

@ -46,9 +46,9 @@ void HTMLBaseElement::removed_from(Node* parent)
document().update_base_element({});
}
void HTMLBaseElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLBaseElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
HTMLElement::attribute_changed(name, old_value, value);
// The frozen base URL must be immediately set for an element whenever any of the following situations occur:
// - The base element is the first base element in tree order with an href content attribute in its Document, and its href content attribute is changed.

View file

@ -24,7 +24,7 @@ public:
virtual void inserted() override;
virtual void removed_from(Node*) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
private:
HTMLBaseElement(DOM::Document&, DOM::QualifiedName);

View file

@ -59,9 +59,9 @@ void HTMLBodyElement::apply_presentational_hints(CSS::StyleProperties& style) co
});
}
void HTMLBodyElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLBodyElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
HTMLElement::attribute_changed(name, old_value, value);
if (name.equals_ignoring_ascii_case("link"sv)) {
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-3
auto color = parse_legacy_color_value(value.value_or(String {}));

View file

@ -21,7 +21,7 @@ class HTMLBodyElement final
public:
virtual ~HTMLBodyElement() override;
virtual void attribute_changed(FlyString const&, Optional<String> const&) override;
virtual void attribute_changed(FlyString const&, Optional<String> const& old_value, Optional<String> const&) override;
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
// https://www.w3.org/TR/html-aria/#el-body

View file

@ -53,9 +53,9 @@ void HTMLDetailsElement::removed_from(DOM::Node*)
set_shadow_root(nullptr);
}
void HTMLDetailsElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLDetailsElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
Base::attribute_changed(name, value);
Base::attribute_changed(name, old_value, value);
// https://html.spec.whatwg.org/multipage/interactive-elements.html#details-notification-task-steps
if (name == HTML::AttributeNames::open) {

View file

@ -34,7 +34,7 @@ private:
virtual void inserted() override;
virtual void removed_from(DOM::Node*) override;
virtual void children_changed() override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
void queue_a_details_toggle_event_task(String old_state, String new_state);

View file

@ -358,9 +358,9 @@ bool HTMLElement::cannot_navigate() const
return !is<HTML::HTMLAnchorElement>(this) && !is_connected();
}
void HTMLElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
Element::attribute_changed(name, value);
Element::attribute_changed(name, old_value, value);
if (name == HTML::AttributeNames::contenteditable) {
if (!value.has_value()) {

View file

@ -85,7 +85,7 @@ protected:
virtual void initialize(JS::Realm&) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
virtual void visit_edges(Cell::Visitor&) override;

View file

@ -622,9 +622,9 @@ WebIDL::ExceptionOr<void> HTMLFormElement::set_action(String const& value)
return set_attribute(AttributeNames::action, value);
}
void HTMLFormElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLFormElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
HTMLElement::attribute_changed(name, old_value, value);
if (name == HTML::AttributeNames::rel) {
if (m_rel_list)
m_rel_list->associated_attribute_changed(value.value_or(String {}));

View file

@ -111,7 +111,7 @@ private:
virtual Vector<FlyString> supported_property_names() const override;
virtual bool is_supported_property_index(u32) const override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
ErrorOr<String> pick_an_encoding() const;

View file

@ -26,9 +26,9 @@ void HTMLFrameSetElement::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLFrameSetElement);
}
void HTMLFrameSetElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLFrameSetElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
HTMLElement::attribute_changed(name, old_value, value);
#undef __ENUMERATE
#define __ENUMERATE(attribute_name, event_name) \

View file

@ -25,7 +25,7 @@ private:
HTMLFrameSetElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
virtual void attribute_changed(FlyString const&, Optional<String> const&) override;
virtual void attribute_changed(FlyString const&, Optional<String> const& old_value, Optional<String> const&) override;
// ^HTML::GlobalEventHandlers
virtual JS::GCPtr<EventTarget> global_event_handlers_to_event_target(FlyString const& event_name) override;

View file

@ -37,9 +37,9 @@ JS::GCPtr<Layout::Node> HTMLIFrameElement::create_layout_node(NonnullRefPtr<CSS:
return heap().allocate_without_realm<Layout::FrameBox>(document(), *this, move(style));
}
void HTMLIFrameElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLIFrameElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
HTMLElement::attribute_changed(name, old_value, value);
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:process-the-iframe-attributes-2
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:process-the-iframe-attributes-3

View file

@ -40,7 +40,7 @@ private:
// ^DOM::Element
virtual void inserted() override;
virtual void removed_from(Node*) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
virtual i32 default_tab_index_value() const override;
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:dimension-attributes

View file

@ -128,9 +128,9 @@ bool HTMLLinkElement::has_loaded_icon() const
return m_relationship & Relationship::Icon && resource() && resource()->is_loaded() && resource()->has_encoded_data();
}
void HTMLLinkElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLLinkElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
HTMLElement::attribute_changed(name, old_value, value);
// 4.6.7 Link types - https://html.spec.whatwg.org/multipage/links.html#linkTypes
if (name == HTML::AttributeNames::rel) {

View file

@ -47,7 +47,7 @@ private:
HTMLLinkElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
virtual void attribute_changed(FlyString const&, Optional<String> const&) override;
virtual void attribute_changed(FlyString const&, Optional<String> const& old_value, Optional<String> const&) override;
// ^ResourceClient
virtual void resource_did_fail() override;

View file

@ -98,9 +98,9 @@ void HTMLMediaElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_pending_play_promises);
}
void HTMLMediaElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLMediaElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
Base::attribute_changed(name, value);
Base::attribute_changed(name, old_value, value);
if (name == HTML::AttributeNames::src) {
load_element().release_value_but_fixme_should_propagate_errors();

View file

@ -139,7 +139,7 @@ protected:
virtual void finalize() override;
virtual void visit_edges(Cell::Visitor&) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
virtual void removed_from(DOM::Node*) override;
virtual void children_changed() override;

View file

@ -34,9 +34,9 @@ void HTMLOptionElement::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLOptionElement);
}
void HTMLOptionElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLOptionElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
HTMLElement::attribute_changed(name, old_value, value);
if (name == HTML::AttributeNames::selected) {
if (!value.has_value()) {

View file

@ -43,7 +43,7 @@ private:
virtual void initialize(JS::Realm&) override;
void attribute_changed(FlyString const& name, Optional<String> const& value) override;
void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
void ask_for_a_reset();

View file

@ -50,9 +50,9 @@ void HTMLScriptElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_preparation_time_document);
}
void HTMLScriptElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLScriptElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
Base::attribute_changed(name, value);
Base::attribute_changed(name, old_value, value);
if (name == HTML::AttributeNames::crossorigin) {
m_crossorigin = cors_setting_attribute_from_keyword(value);

View file

@ -70,7 +70,7 @@ private:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
// https://html.spec.whatwg.org/multipage/scripting.html#prepare-the-script-element
void prepare_script();

View file

@ -102,9 +102,9 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
});
}
void HTMLTableElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLTableElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
Base::attribute_changed(name, value);
Base::attribute_changed(name, old_value, value);
if (name == HTML::AttributeNames::cellpadding) {
if (value.has_value())
m_padding = max(0, parse_integer(value.value()).value_or(0));

View file

@ -59,7 +59,7 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
JS::GCPtr<DOM::HTMLCollection> mutable m_rows;
JS::GCPtr<DOM::HTMLCollection> mutable m_t_bodies;

View file

@ -35,9 +35,9 @@ void HTMLTrackElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_track);
}
void HTMLTrackElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLTrackElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
HTMLElement::attribute_changed(name, value);
HTMLElement::attribute_changed(name, old_value, value);
// https://html.spec.whatwg.org/multipage/media.html#sourcing-out-of-band-text-tracks
// As the kind, label, and srclang attributes are set, changed, or removed, the text track must update accordingly, as per the definitions above.

View file

@ -28,7 +28,7 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
// ^DOM::Element
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
JS::GCPtr<TextTrack> m_track;
};

View file

@ -53,9 +53,9 @@ void HTMLVideoElement::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_fetch_controller);
}
void HTMLVideoElement::attribute_changed(FlyString const& name, Optional<String> const& value)
void HTMLVideoElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
{
Base::attribute_changed(name, value);
Base::attribute_changed(name, old_value, value);
if (name == HTML::AttributeNames::poster) {
determine_element_poster_frame(value).release_value_but_fixme_should_propagate_errors();

View file

@ -49,7 +49,7 @@ private:
virtual void finalize() override;
virtual void visit_edges(Cell::Visitor&) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override;
// https://html.spec.whatwg.org/multipage/media.html#the-video-element:dimension-attributes
virtual bool supports_dimension_attributes() const override { return true; }