Coverage Report

Created: 2025-09-05 06:52

/src/serenity/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2020, the SerenityOS developers.
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <LibWeb/ARIA/Roles.h>
10
#include <LibWeb/HTML/FormAssociatedElement.h>
11
#include <LibWeb/HTML/HTMLElement.h>
12
13
namespace Web::HTML {
14
15
#define ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTES              \
16
0
    __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(submit, Submit) \
17
0
    __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(reset, Reset)   \
18
0
    __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(button, Button)
19
20
class HTMLButtonElement final
21
    : public HTMLElement
22
    , public FormAssociatedElement {
23
    WEB_PLATFORM_OBJECT(HTMLButtonElement, HTMLElement);
24
    JS_DECLARE_ALLOCATOR(HTMLButtonElement);
25
    FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLButtonElement)
26
27
public:
28
    virtual ~HTMLButtonElement() override;
29
30
    virtual void initialize(JS::Realm&) override;
31
32
    enum class TypeAttributeState {
33
#define __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(_, state) state,
34
        ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTES
35
#undef __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE
36
    };
37
38
    TypeAttributeState type_state() const;
39
    WebIDL::ExceptionOr<void> set_type(String const&);
40
41
    // ^EventTarget
42
    // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-button-element
43
0
    virtual bool is_focusable() const override { return true; }
44
45
    // ^FormAssociatedElement
46
    // https://html.spec.whatwg.org/multipage/forms.html#category-listed
47
0
    virtual bool is_listed() const override { return true; }
48
49
    // https://html.spec.whatwg.org/multipage/forms.html#category-submit
50
0
    virtual bool is_submittable() const override { return true; }
51
52
    // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
53
0
    virtual bool is_auto_capitalize_inheriting() const override { return true; }
54
55
    // https://html.spec.whatwg.org/multipage/forms.html#concept-button
56
    // https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:concept-button
57
0
    virtual bool is_button() const override { return true; }
58
59
    virtual bool is_submit_button() const override;
60
61
    // ^HTMLElement
62
    // https://html.spec.whatwg.org/multipage/forms.html#category-label
63
0
    virtual bool is_labelable() const override { return true; }
64
65
    // https://www.w3.org/TR/html-aria/#el-button
66
0
    virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::button; }
67
68
    virtual String value() const override;
69
70
    virtual bool has_activation_behavior() const override;
71
    virtual void activation_behavior(DOM::Event const&) override;
72
73
private:
74
0
    virtual bool is_html_button_element() const override { return true; }
75
76
    HTMLButtonElement(DOM::Document&, DOM::QualifiedName);
77
78
    // ^DOM::Element
79
    virtual i32 default_tab_index_value() const override;
80
};
81
82
}
83
84
namespace Web::DOM {
85
template<>
86
0
inline bool Node::fast_is<HTML::HTMLButtonElement>() const { return is_html_button_element(); }
87
}