From a276cf2d5e8c54dc76568b69b29b467df41f6b43 Mon Sep 17 00:00:00 2001 From: Nathan van der Kamp Date: Sat, 23 Nov 2024 23:06:06 +0100 Subject: [PATCH] LibWeb: Add PopOverInvokerElement and use it in HTMLButtonElement The popoverTargetElement seems to be one of the only cases of a reflected Element? attribute in the HTML spec, the behaviour of which is specified in section 2.6.1. Buttons can't actually toggle popovers yet because showing/hiding popovers is not implemented yet. --- Libraries/LibWeb/Forward.h | 1 + Libraries/LibWeb/HTML/AttributeNames.h | 2 ++ Libraries/LibWeb/HTML/HTMLButtonElement.cpp | 6 ++++ Libraries/LibWeb/HTML/HTMLButtonElement.h | 6 +++- Libraries/LibWeb/HTML/HTMLButtonElement.idl | 3 +- Libraries/LibWeb/HTML/PopoverInvokerElement.h | 34 +++++++++++++++++++ .../LibWeb/HTML/PopoverInvokerElement.idl | 13 +++++++ .../HTML/popover-invoker-attributes.txt | 5 +++ .../HTML/popover-invoker-attributes.html | 29 ++++++++++++++++ 9 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 Libraries/LibWeb/HTML/PopoverInvokerElement.h create mode 100644 Libraries/LibWeb/HTML/PopoverInvokerElement.idl create mode 100644 Tests/LibWeb/Text/expected/HTML/popover-invoker-attributes.txt create mode 100644 Tests/LibWeb/Text/input/HTML/popover-invoker-attributes.html diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index f8b4333471..966a8a858d 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -513,6 +513,7 @@ class PageTransitionEvent; class Path2D; class Plugin; class PluginArray; +class PopoverInvokerElement; class PromiseRejectionEvent; class RadioNodeList; class SelectedFile; diff --git a/Libraries/LibWeb/HTML/AttributeNames.h b/Libraries/LibWeb/HTML/AttributeNames.h index 439857945b..d82b5ddf47 100644 --- a/Libraries/LibWeb/HTML/AttributeNames.h +++ b/Libraries/LibWeb/HTML/AttributeNames.h @@ -238,6 +238,8 @@ namespace AttributeNames { __ENUMERATE_HTML_ATTRIBUTE(placeholder) \ __ENUMERATE_HTML_ATTRIBUTE(playsinline) \ __ENUMERATE_HTML_ATTRIBUTE(popover) \ + __ENUMERATE_HTML_ATTRIBUTE(popovertarget) \ + __ENUMERATE_HTML_ATTRIBUTE(popovertargetaction) \ __ENUMERATE_HTML_ATTRIBUTE(poster) \ __ENUMERATE_HTML_ATTRIBUTE(preload) \ __ENUMERATE_HTML_ATTRIBUTE(readonly) \ diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.cpp b/Libraries/LibWeb/HTML/HTMLButtonElement.cpp index 24ee0d8676..8fdfe3e843 100644 --- a/Libraries/LibWeb/HTML/HTMLButtonElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLButtonElement.cpp @@ -45,6 +45,12 @@ WebIDL::ExceptionOr HTMLButtonElement::set_type(String const& type) return set_attribute(HTML::AttributeNames::type, type); } +void HTMLButtonElement::visit_edges(Visitor& visitor) +{ + Base::visit_edges(visitor); + PopoverInvokerElement::visit_edges(visitor); +} + // https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex i32 HTMLButtonElement::default_tab_index_value() const { diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.h b/Libraries/LibWeb/HTML/HTMLButtonElement.h index a1a834645c..b1531848d8 100644 --- a/Libraries/LibWeb/HTML/HTMLButtonElement.h +++ b/Libraries/LibWeb/HTML/HTMLButtonElement.h @@ -9,6 +9,7 @@ #include #include #include +#include namespace Web::HTML { @@ -19,7 +20,8 @@ namespace Web::HTML { class HTMLButtonElement final : public HTMLElement - , public FormAssociatedElement { + , public FormAssociatedElement + , public PopoverInvokerElement { WEB_PLATFORM_OBJECT(HTMLButtonElement, HTMLElement); GC_DECLARE_ALLOCATOR(HTMLButtonElement); FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLButtonElement) @@ -73,6 +75,8 @@ public: virtual void activation_behavior(DOM::Event const&) override; private: + virtual void visit_edges(Visitor&) override; + virtual bool is_html_button_element() const override { return true; } HTMLButtonElement(DOM::Document&, DOM::QualifiedName); diff --git a/Libraries/LibWeb/HTML/HTMLButtonElement.idl b/Libraries/LibWeb/HTML/HTMLButtonElement.idl index 4f836f0a37..501a1d7898 100644 --- a/Libraries/LibWeb/HTML/HTMLButtonElement.idl +++ b/Libraries/LibWeb/HTML/HTMLButtonElement.idl @@ -1,5 +1,6 @@ #import #import +#import [MissingValueDefault=submit, InvalidValueDefault=submit] enum ButtonTypeState { @@ -33,4 +34,4 @@ interface HTMLButtonElement : HTMLElement { readonly attribute NodeList labels; }; -// FIXME: HTMLButtonElement includes PopoverInvokerElement; +HTMLButtonElement includes PopoverInvokerElement; diff --git a/Libraries/LibWeb/HTML/PopoverInvokerElement.h b/Libraries/LibWeb/HTML/PopoverInvokerElement.h new file mode 100644 index 0000000000..0187eaaeea --- /dev/null +++ b/Libraries/LibWeb/HTML/PopoverInvokerElement.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, Nathan van der Kamp + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Web::HTML { + +class PopoverInvokerElement { + +public: + PopoverInvokerElement() { } + + GC::Ptr get_popover_target_element() { return m_popover_target_element; } + + 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); + } + +private: + GC::Ptr m_popover_target_element; +}; + +} diff --git a/Libraries/LibWeb/HTML/PopoverInvokerElement.idl b/Libraries/LibWeb/HTML/PopoverInvokerElement.idl new file mode 100644 index 0000000000..2df03af286 --- /dev/null +++ b/Libraries/LibWeb/HTML/PopoverInvokerElement.idl @@ -0,0 +1,13 @@ +// https://html.spec.whatwg.org/multipage/popover.html#attr-popovertargetaction +[MissingValueDefault=toggle, InvalidValueDefault=toggle] +enum PopoverTargetActionAttribute { + "toggle", + "show", + "hide" +}; + +// https://html.spec.whatwg.org/multipage/popover.html#popoverinvokerelement +interface mixin PopoverInvokerElement { + [Reflect=popovertarget, CEReactions] attribute Element? popoverTargetElement; + [Reflect=popovertargetaction, Enumerated=PopoverTargetActionAttribute, CEReactions] attribute DOMString popoverTargetAction; +}; diff --git a/Tests/LibWeb/Text/expected/HTML/popover-invoker-attributes.txt b/Tests/LibWeb/Text/expected/HTML/popover-invoker-attributes.txt new file mode 100644 index 0000000000..137813d0a2 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/popover-invoker-attributes.txt @@ -0,0 +1,5 @@ +PASS +PASS +PASS +PASS +PASS diff --git a/Tests/LibWeb/Text/input/HTML/popover-invoker-attributes.html b/Tests/LibWeb/Text/input/HTML/popover-invoker-attributes.html new file mode 100644 index 0000000000..d3869d9821 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/popover-invoker-attributes.html @@ -0,0 +1,29 @@ + + +
Popover content
+ +