2020-08-01 03:04:26 +01:00
|
|
|
/*
|
2021-04-28 22:46:44 +02:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2020-08-01 03:04:26 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 03:04:26 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-01-28 22:23:16 +00:00
|
|
|
#include <LibWeb/ARIA/Roles.h>
|
2021-10-14 16:18:49 +01:00
|
|
|
#include <LibWeb/HTML/FormAssociatedElement.h>
|
2022-03-23 18:55:54 -04:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
2024-11-23 23:06:06 +01:00
|
|
|
#include <LibWeb/HTML/PopoverInvokerElement.h>
|
2020-08-01 03:04:26 +01:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2022-03-01 21:06:29 +00:00
|
|
|
#define ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTES \
|
|
|
|
__ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(submit, Submit) \
|
|
|
|
__ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(reset, Reset) \
|
2025-02-20 17:01:28 +00:00
|
|
|
__ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(button, Button) \
|
|
|
|
__ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(auto, Auto)
|
2022-03-01 21:06:29 +00:00
|
|
|
|
2022-03-23 18:55:54 -04:00
|
|
|
class HTMLButtonElement final
|
|
|
|
: public HTMLElement
|
2024-11-23 23:06:06 +01:00
|
|
|
, public FormAssociatedElement
|
|
|
|
, public PopoverInvokerElement {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLButtonElement, HTMLElement);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(HTMLButtonElement);
|
2022-03-23 18:55:54 -04:00
|
|
|
FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLButtonElement)
|
|
|
|
|
2020-08-01 03:04:26 +01:00
|
|
|
public:
|
|
|
|
virtual ~HTMLButtonElement() override;
|
2022-03-01 21:03:30 +00:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2023-01-10 06:28:20 -05:00
|
|
|
|
2022-03-01 21:06:29 +00:00
|
|
|
enum class TypeAttributeState {
|
|
|
|
#define __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(_, state) state,
|
|
|
|
ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTES
|
|
|
|
#undef __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE
|
|
|
|
};
|
|
|
|
|
|
|
|
TypeAttributeState type_state() const;
|
2025-02-20 17:01:28 +00:00
|
|
|
String type_for_bindings() const;
|
|
|
|
WebIDL::ExceptionOr<void> set_type_for_bindings(String const&);
|
2022-03-01 21:06:29 +00:00
|
|
|
|
2025-07-22 00:58:28 +02:00
|
|
|
virtual void form_associated_element_attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
|
2024-12-12 19:53:04 +00:00
|
|
|
|
2022-03-26 18:05:48 +00:00
|
|
|
// ^EventTarget
|
|
|
|
// https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-button-element
|
2024-11-02 19:17:20 +01:00
|
|
|
// https://html.spec.whatwg.org/multipage/interaction.html#focusable-area
|
|
|
|
// https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled
|
|
|
|
virtual bool is_focusable() const override;
|
2022-03-26 18:05:48 +00:00
|
|
|
|
2022-03-01 21:03:30 +00:00
|
|
|
// ^FormAssociatedElement
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-listed
|
|
|
|
virtual bool is_listed() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-submit
|
|
|
|
virtual bool is_submittable() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
|
2025-05-26 16:21:29 +12:00
|
|
|
virtual bool is_autocapitalize_and_autocorrect_inheriting() const override { return true; }
|
2022-03-01 21:03:30 +00:00
|
|
|
|
2023-06-18 15:08:15 +01:00
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#concept-button
|
|
|
|
// https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:concept-button
|
|
|
|
virtual bool is_button() const override { return true; }
|
|
|
|
|
|
|
|
virtual bool is_submit_button() const override;
|
|
|
|
|
2022-03-01 21:03:30 +00:00
|
|
|
// ^HTMLElement
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-label
|
|
|
|
virtual bool is_labelable() const override { return true; }
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2022-11-28 17:58:13 -06:00
|
|
|
// https://www.w3.org/TR/html-aria/#el-button
|
2023-01-28 22:23:16 +00:00
|
|
|
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::button; }
|
2022-11-28 17:58:13 -06:00
|
|
|
|
2025-07-26 12:19:56 -04:00
|
|
|
virtual Utf16String value() const override;
|
2025-07-08 11:28:10 +01:00
|
|
|
virtual Optional<String> optional_value() const override;
|
2023-06-18 15:08:15 +01:00
|
|
|
|
2023-11-18 10:48:09 +01:00
|
|
|
virtual bool has_activation_behavior() const override;
|
|
|
|
virtual void activation_behavior(DOM::Event const&) override;
|
|
|
|
|
2025-04-04 01:16:44 +02:00
|
|
|
String command() const;
|
2025-04-04 01:27:55 +02:00
|
|
|
WebIDL::ExceptionOr<void> set_command(String const&);
|
|
|
|
|
|
|
|
GC::Ptr<DOM::Element> command_for_element() { return m_command_for_element; }
|
|
|
|
void set_command_for_element(GC::Ptr<DOM::Element> value) { m_command_for_element = value; }
|
2025-04-04 01:16:44 +02:00
|
|
|
|
2025-08-15 09:42:52 +02:00
|
|
|
// https://html.spec.whatwg.org/multipage/rendering.html#the-button-element-2:button-layout-2
|
|
|
|
virtual bool uses_button_layout() const override { return true; }
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
private:
|
2024-11-23 23:06:06 +01:00
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
|
2023-09-09 17:13:41 +02:00
|
|
|
virtual bool is_html_button_element() const override { return true; }
|
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
HTMLButtonElement(DOM::Document&, DOM::QualifiedName);
|
2022-11-05 03:58:14 +00:00
|
|
|
|
|
|
|
// ^DOM::Element
|
|
|
|
virtual i32 default_tab_index_value() const override;
|
2025-04-04 01:27:55 +02:00
|
|
|
|
|
|
|
GC::Ptr<DOM::Element> m_command_for_element;
|
2020-08-01 03:04:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2023-09-09 17:13:41 +02:00
|
|
|
|
|
|
|
namespace Web::DOM {
|
2025-05-13 07:06:33 -04:00
|
|
|
|
2023-09-09 17:13:41 +02:00
|
|
|
template<>
|
|
|
|
inline bool Node::fast_is<HTML::HTMLButtonElement>() const { return is_html_button_element(); }
|
2025-05-13 07:06:33 -04:00
|
|
|
|
2023-09-09 17:13:41 +02:00
|
|
|
}
|