HTMLTextAreaElement.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
  4. * Copyright (c) 2024, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <LibWeb/ARIA/Roles.h>
  10. #include <LibWeb/DOM/Text.h>
  11. #include <LibWeb/HTML/FormAssociatedElement.h>
  12. #include <LibWeb/HTML/HTMLElement.h>
  13. #include <LibWeb/WebIDL/Types.h>
  14. namespace Web::HTML {
  15. class HTMLTextAreaElement final
  16. : public HTMLElement
  17. , public FormAssociatedElement
  18. , public DOM::EditableTextNodeOwner {
  19. WEB_PLATFORM_OBJECT(HTMLTextAreaElement, HTMLElement);
  20. JS_DECLARE_ALLOCATOR(HTMLTextAreaElement);
  21. FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLTextAreaElement)
  22. public:
  23. virtual ~HTMLTextAreaElement() override;
  24. virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
  25. String const& type() const
  26. {
  27. static String const textarea = "textarea"_string;
  28. return textarea;
  29. }
  30. // ^DOM::EditableTextNodeOwner
  31. virtual void did_edit_text_node(Badge<BrowsingContext>) override;
  32. // ^EventTarget
  33. // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-textarea-element
  34. virtual bool is_focusable() const override { return true; }
  35. virtual void did_lose_focus() override;
  36. virtual void did_receive_focus() override;
  37. // ^FormAssociatedElement
  38. // https://html.spec.whatwg.org/multipage/forms.html#category-listed
  39. virtual bool is_listed() const override { return true; }
  40. // https://html.spec.whatwg.org/multipage/forms.html#category-submit
  41. virtual bool is_submittable() const override { return true; }
  42. // https://html.spec.whatwg.org/multipage/forms.html#category-reset
  43. virtual bool is_resettable() 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#category-label
  47. virtual bool is_labelable() const override { return true; }
  48. virtual void reset_algorithm() override;
  49. virtual void form_associated_element_was_inserted() override;
  50. virtual void form_associated_element_was_removed(DOM::Node*) override;
  51. virtual void form_associated_element_attribute_changed(FlyString const&, Optional<String> const&) override;
  52. virtual void children_changed() override;
  53. // https://www.w3.org/TR/html-aria/#el-textarea
  54. virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::textbox; }
  55. String default_value() const;
  56. void set_default_value(String const&);
  57. String value() const override;
  58. void set_value(String const&);
  59. u32 text_length() const;
  60. bool check_validity();
  61. bool report_validity();
  62. void set_custom_validity(String const& error);
  63. WebIDL::Long max_length() const;
  64. WebIDL::ExceptionOr<void> set_max_length(WebIDL::Long);
  65. WebIDL::Long min_length() const;
  66. WebIDL::ExceptionOr<void> set_min_length(WebIDL::Long);
  67. unsigned cols() const;
  68. WebIDL::ExceptionOr<void> set_cols(unsigned);
  69. unsigned rows() const;
  70. WebIDL::ExceptionOr<void> set_rows(unsigned);
  71. private:
  72. HTMLTextAreaElement(DOM::Document&, DOM::QualifiedName);
  73. virtual void initialize(JS::Realm&) override;
  74. virtual void visit_edges(Cell::Visitor&) override;
  75. // ^DOM::Element
  76. virtual i32 default_tab_index_value() const override;
  77. void create_shadow_tree_if_needed();
  78. void handle_readonly_attribute(Optional<String> const& value);
  79. void handle_maxlength_attribute();
  80. void update_placeholder_visibility();
  81. JS::GCPtr<DOM::Element> m_placeholder_element;
  82. JS::GCPtr<DOM::Text> m_placeholder_text_node;
  83. JS::GCPtr<DOM::Element> m_inner_text_element;
  84. JS::GCPtr<DOM::Text> m_text_node;
  85. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-dirty
  86. bool m_dirty_value { false };
  87. // https://html.spec.whatwg.org/multipage/form-elements.html#the-textarea-element:concept-fe-mutable
  88. bool m_is_mutable { true };
  89. // https://html.spec.whatwg.org/multipage/form-elements.html#concept-textarea-raw-value
  90. String m_raw_value;
  91. };
  92. }