HTMLButtonElement.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLButtonElement)
  20. public:
  21. virtual ~HTMLButtonElement() override;
  22. virtual void initialize(JS::Realm&) override;
  23. enum class TypeAttributeState {
  24. #define __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE(_, state) state,
  25. ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTES
  26. #undef __ENUMERATE_HTML_BUTTON_TYPE_ATTRIBUTE
  27. };
  28. StringView type() const;
  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. virtual bool is_focusable() const override { return true; }
  34. // ^FormAssociatedElement
  35. // https://html.spec.whatwg.org/multipage/forms.html#category-listed
  36. virtual bool is_listed() const override { return true; }
  37. // https://html.spec.whatwg.org/multipage/forms.html#category-submit
  38. virtual bool is_submittable() const override { return true; }
  39. // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
  40. virtual bool is_auto_capitalize_inheriting() const override { return true; }
  41. // https://html.spec.whatwg.org/multipage/forms.html#concept-button
  42. // https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:concept-button
  43. virtual bool is_button() const override { return true; }
  44. virtual bool is_submit_button() const override;
  45. // ^HTMLElement
  46. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  47. virtual bool is_labelable() const override { return true; }
  48. // https://www.w3.org/TR/html-aria/#el-button
  49. virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::button; }
  50. virtual DeprecatedString value() const override;
  51. private:
  52. virtual bool is_html_button_element() const override { return true; }
  53. HTMLButtonElement(DOM::Document&, DOM::QualifiedName);
  54. // ^DOM::Element
  55. virtual i32 default_tab_index_value() const override;
  56. };
  57. }
  58. namespace Web::DOM {
  59. template<>
  60. inline bool Node::fast_is<HTML::HTMLButtonElement>() const { return is_html_button_element(); }
  61. }