HTMLButtonElement.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. TypeAttributeState type_state() const;
  29. WebIDL::ExceptionOr<void> set_type(String const&);
  30. // ^EventTarget
  31. // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-button-element
  32. virtual bool is_focusable() const override { return true; }
  33. // ^FormAssociatedElement
  34. // https://html.spec.whatwg.org/multipage/forms.html#category-listed
  35. virtual bool is_listed() const override { return true; }
  36. // https://html.spec.whatwg.org/multipage/forms.html#category-submit
  37. virtual bool is_submittable() const override { return true; }
  38. // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
  39. virtual bool is_auto_capitalize_inheriting() const override { return true; }
  40. // https://html.spec.whatwg.org/multipage/forms.html#concept-button
  41. // https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element:concept-button
  42. virtual bool is_button() const override { return true; }
  43. virtual bool is_submit_button() const override;
  44. // ^HTMLElement
  45. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  46. virtual bool is_labelable() const override { return true; }
  47. // https://www.w3.org/TR/html-aria/#el-button
  48. virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::button; }
  49. virtual DeprecatedString value() const override;
  50. private:
  51. virtual bool is_html_button_element() const override { return true; }
  52. HTMLButtonElement(DOM::Document&, DOM::QualifiedName);
  53. // ^DOM::Element
  54. virtual i32 default_tab_index_value() const override;
  55. };
  56. }
  57. namespace Web::DOM {
  58. template<>
  59. inline bool Node::fast_is<HTML::HTMLButtonElement>() const { return is_html_button_element(); }
  60. }