HTMLTextAreaElement.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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/Platform/Timer.h>
  14. #include <LibWeb/WebIDL/Types.h>
  15. namespace Web::HTML {
  16. class HTMLTextAreaElement final
  17. : public HTMLElement
  18. , public FormAssociatedElement
  19. , public DOM::EditableTextNodeOwner {
  20. WEB_PLATFORM_OBJECT(HTMLTextAreaElement, HTMLElement);
  21. JS_DECLARE_ALLOCATOR(HTMLTextAreaElement);
  22. FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLTextAreaElement)
  23. public:
  24. virtual ~HTMLTextAreaElement() override;
  25. virtual void adjust_computed_style(CSS::StyleProperties&) override;
  26. String const& type() const
  27. {
  28. static String const textarea = "textarea"_string;
  29. return textarea;
  30. }
  31. // ^DOM::EditableTextNodeOwner
  32. virtual void did_edit_text_node(Badge<BrowsingContext>) override;
  33. // ^EventTarget
  34. // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-textarea-element
  35. virtual bool is_focusable() const override { return true; }
  36. virtual void did_lose_focus() override;
  37. virtual void did_receive_focus() override;
  38. // ^FormAssociatedElement
  39. // https://html.spec.whatwg.org/multipage/forms.html#category-listed
  40. virtual bool is_listed() const override { return true; }
  41. // https://html.spec.whatwg.org/multipage/forms.html#category-submit
  42. virtual bool is_submittable() const override { return true; }
  43. // https://html.spec.whatwg.org/multipage/forms.html#category-reset
  44. virtual bool is_resettable() const override { return true; }
  45. // https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
  46. virtual bool is_auto_capitalize_inheriting() const override { return true; }
  47. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  48. virtual bool is_labelable() const override { return true; }
  49. virtual void reset_algorithm() override;
  50. virtual void form_associated_element_was_inserted() override;
  51. virtual void form_associated_element_was_removed(DOM::Node*) override;
  52. virtual void form_associated_element_attribute_changed(FlyString const&, Optional<String> const&) override;
  53. virtual void children_changed() override;
  54. // https://www.w3.org/TR/html-aria/#el-textarea
  55. virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::textbox; }
  56. String default_value() const;
  57. void set_default_value(String const&);
  58. String value() const override;
  59. void set_value(String const&);
  60. u32 text_length() const;
  61. bool check_validity();
  62. bool report_validity();
  63. void set_custom_validity(String const& error);
  64. WebIDL::Long max_length() const;
  65. WebIDL::ExceptionOr<void> set_max_length(WebIDL::Long);
  66. WebIDL::Long min_length() const;
  67. WebIDL::ExceptionOr<void> set_min_length(WebIDL::Long);
  68. unsigned cols() const;
  69. WebIDL::ExceptionOr<void> set_cols(unsigned);
  70. unsigned rows() const;
  71. WebIDL::ExceptionOr<void> set_rows(unsigned);
  72. private:
  73. HTMLTextAreaElement(DOM::Document&, DOM::QualifiedName);
  74. virtual void initialize(JS::Realm&) override;
  75. virtual void visit_edges(Cell::Visitor&) override;
  76. void set_raw_value(String);
  77. String api_value() const;
  78. // ^DOM::Element
  79. virtual i32 default_tab_index_value() const override;
  80. void create_shadow_tree_if_needed();
  81. void handle_readonly_attribute(Optional<String> const& value);
  82. void handle_maxlength_attribute();
  83. void queue_firing_input_event();
  84. void update_placeholder_visibility();
  85. JS::GCPtr<DOM::Element> m_placeholder_element;
  86. JS::GCPtr<DOM::Text> m_placeholder_text_node;
  87. JS::GCPtr<DOM::Element> m_inner_text_element;
  88. JS::GCPtr<DOM::Text> m_text_node;
  89. RefPtr<Web::Platform::Timer> m_input_event_timer;
  90. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-dirty
  91. bool m_dirty_value { false };
  92. // https://html.spec.whatwg.org/multipage/form-elements.html#the-textarea-element:concept-fe-mutable
  93. bool m_is_mutable { true };
  94. // https://html.spec.whatwg.org/multipage/form-elements.html#concept-textarea-raw-value
  95. String m_raw_value;
  96. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-api-value
  97. mutable Optional<String> m_api_value;
  98. };
  99. }