HTMLButtonElement.h 3.3 KB

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