diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 2c0ec8c0a1f..598d6457a0f 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -441,6 +441,7 @@ set(SOURCES HTML/Numbers.cpp HTML/PageTransitionEvent.cpp HTML/PolicyContainers.cpp + HTML/PopoverInvokerElement.cpp HTML/PopStateEvent.cpp HTML/Parser/Entities.cpp HTML/Parser/HTMLEncodingDetection.cpp diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.cpp b/Libraries/LibWeb/HTML/HTMLButtonElement.cpp index 8fdfe3e8432..90e8e9207b8 100644 --- a/Libraries/LibWeb/HTML/HTMLButtonElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLButtonElement.cpp @@ -45,6 +45,11 @@ WebIDL::ExceptionOr HTMLButtonElement::set_type(String const& type) return set_attribute(HTML::AttributeNames::type, type); } +void HTMLButtonElement::form_associated_element_attribute_changed(FlyString const& name, Optional const& value, Optional const& namespace_) +{ + PopoverInvokerElement::associated_attribute_changed(name, value, namespace_); +} + void HTMLButtonElement::visit_edges(Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.h b/Libraries/LibWeb/HTML/HTMLButtonElement.h index b1531848d87..44876b2a88e 100644 --- a/Libraries/LibWeb/HTML/HTMLButtonElement.h +++ b/Libraries/LibWeb/HTML/HTMLButtonElement.h @@ -40,6 +40,8 @@ public: TypeAttributeState type_state() const; WebIDL::ExceptionOr set_type(String const&); + virtual void form_associated_element_attribute_changed(FlyString const& name, Optional const& value, Optional const& namespace_) override; + // ^EventTarget // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-button-element // https://html.spec.whatwg.org/multipage/interaction.html#focusable-area diff --git a/Libraries/LibWeb/HTML/PopoverInvokerElement.cpp b/Libraries/LibWeb/HTML/PopoverInvokerElement.cpp new file mode 100644 index 00000000000..fae92643af4 --- /dev/null +++ b/Libraries/LibWeb/HTML/PopoverInvokerElement.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024, Tim Ledbetter + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::HTML { + +void PopoverInvokerElement::associated_attribute_changed(FlyString const& name, Optional const&, Optional const& namespace_) +{ + // From: https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributess + // For element reflected targets only: the following attribute change steps, given element, localName, oldValue, value, and namespace, + // are used to synchronize between the content attribute and the IDL attribute: + + // 1. If localName is not attr or namespace is not null, then return. + if (name != HTML::AttributeNames::popovertarget || namespace_.has_value()) + return; + + // 2. Set element's explicitly set attr-elements to null. + m_popover_target_element = nullptr; +} + +void PopoverInvokerElement::visit_edges(JS::Cell::Visitor& visitor) +{ + visitor.visit(m_popover_target_element); +} + +} diff --git a/Libraries/LibWeb/HTML/PopoverInvokerElement.h b/Libraries/LibWeb/HTML/PopoverInvokerElement.h index 0187eaaeeac..6cd95d0bcef 100644 --- a/Libraries/LibWeb/HTML/PopoverInvokerElement.h +++ b/Libraries/LibWeb/HTML/PopoverInvokerElement.h @@ -22,10 +22,8 @@ public: void set_popover_target_element(GC::Ptr value) { m_popover_target_element = value; } protected: - void visit_edges(JS::Cell::Visitor& visitor) - { - visitor.visit(m_popover_target_element); - } + void visit_edges(JS::Cell::Visitor&); + void associated_attribute_changed(FlyString const& name, Optional const& value, Optional const& namespace_); private: GC::Ptr m_popover_target_element; diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/popovers/popovertarget-reflection.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/popovers/popovertarget-reflection.txt new file mode 100644 index 00000000000..2c748ed1e34 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/popovers/popovertarget-reflection.txt @@ -0,0 +1,6 @@ +Harness status: OK + +Found 1 tests + +1 Pass +Pass Element attribute reflection of popoverTargetElement/popovertarget should be kept in sync. \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/popovers/popovertarget-reflection.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/popovers/popovertarget-reflection.html new file mode 100644 index 00000000000..4b1a1d8a3e1 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/popovers/popovertarget-reflection.html @@ -0,0 +1,53 @@ + + + + + + + + + +
popover
+ +