HTMLButtonElement.h 3.0 KB

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