HTMLTextAreaElement.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 <LibCore/Timer.h>
  10. #include <LibWeb/ARIA/Roles.h>
  11. #include <LibWeb/DOM/Text.h>
  12. #include <LibWeb/HTML/FormAssociatedElement.h>
  13. #include <LibWeb/HTML/HTMLElement.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::UnsignedLong selection_start() const;
  65. WebIDL::ExceptionOr<void> set_selection_start(WebIDL::UnsignedLong);
  66. WebIDL::UnsignedLong selection_end() const;
  67. WebIDL::ExceptionOr<void> set_selection_end(WebIDL::UnsignedLong);
  68. WebIDL::Long max_length() const;
  69. WebIDL::ExceptionOr<void> set_max_length(WebIDL::Long);
  70. WebIDL::Long min_length() const;
  71. WebIDL::ExceptionOr<void> set_min_length(WebIDL::Long);
  72. unsigned cols() const;
  73. WebIDL::ExceptionOr<void> set_cols(unsigned);
  74. unsigned rows() const;
  75. WebIDL::ExceptionOr<void> set_rows(unsigned);
  76. private:
  77. HTMLTextAreaElement(DOM::Document&, DOM::QualifiedName);
  78. virtual void initialize(JS::Realm&) override;
  79. virtual void visit_edges(Cell::Visitor&) override;
  80. void set_raw_value(String);
  81. String api_value() const;
  82. // ^DOM::Element
  83. virtual i32 default_tab_index_value() const override;
  84. void create_shadow_tree_if_needed();
  85. void handle_readonly_attribute(Optional<String> const& value);
  86. void handle_maxlength_attribute();
  87. void queue_firing_input_event();
  88. void update_placeholder_visibility();
  89. JS::GCPtr<DOM::Element> m_placeholder_element;
  90. JS::GCPtr<DOM::Text> m_placeholder_text_node;
  91. JS::GCPtr<DOM::Element> m_inner_text_element;
  92. JS::GCPtr<DOM::Text> m_text_node;
  93. RefPtr<Core::Timer> m_input_event_timer;
  94. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-dirty
  95. bool m_dirty_value { false };
  96. // https://html.spec.whatwg.org/multipage/form-elements.html#the-textarea-element:concept-fe-mutable
  97. bool m_is_mutable { true };
  98. // https://html.spec.whatwg.org/multipage/form-elements.html#concept-textarea-raw-value
  99. String m_raw_value;
  100. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-api-value
  101. mutable Optional<String> m_api_value;
  102. };
  103. }