HTMLTextAreaElement.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #pragma once
  10. #include <LibCore/Timer.h>
  11. #include <LibWeb/ARIA/Roles.h>
  12. #include <LibWeb/DOM/Text.h>
  13. #include <LibWeb/HTML/FormAssociatedElement.h>
  14. #include <LibWeb/HTML/HTMLElement.h>
  15. #include <LibWeb/WebIDL/Types.h>
  16. namespace Web::HTML {
  17. class HTMLTextAreaElement final
  18. : public HTMLElement
  19. , public FormAssociatedTextControlElement {
  20. WEB_PLATFORM_OBJECT(HTMLTextAreaElement, HTMLElement);
  21. GC_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. // ^EventTarget
  32. // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-textarea-element
  33. // https://html.spec.whatwg.org/multipage/interaction.html#focusable-area
  34. // https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled
  35. virtual bool is_focusable() const override;
  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 clear_algorithm() override;
  51. virtual WebIDL::ExceptionOr<void> cloned(Node&, bool) override;
  52. virtual void form_associated_element_was_inserted() override;
  53. virtual void form_associated_element_was_removed(DOM::Node*) override;
  54. virtual void form_associated_element_attribute_changed(FlyString const&, Optional<String> const&) override;
  55. virtual void children_changed() override;
  56. // https://www.w3.org/TR/html-aria/#el-textarea
  57. virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::textbox; }
  58. String default_value() const;
  59. void set_default_value(String const&);
  60. String value() const override;
  61. void set_value(String const&);
  62. // https://html.spec.whatwg.org/multipage/form-elements.html#the-textarea-element:concept-fe-api-value-3
  63. String api_value() const;
  64. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-textarea/input-relevant-value
  65. virtual String relevant_value() override { return api_value(); }
  66. virtual WebIDL::ExceptionOr<void> set_relevant_value(String const& value) override;
  67. virtual void set_dirty_value_flag(bool flag) override { m_dirty_value = flag; }
  68. u32 text_length() const;
  69. bool check_validity();
  70. bool report_validity();
  71. void set_custom_validity(String const& error);
  72. WebIDL::Long max_length() const;
  73. WebIDL::ExceptionOr<void> set_max_length(WebIDL::Long);
  74. WebIDL::Long min_length() const;
  75. WebIDL::ExceptionOr<void> set_min_length(WebIDL::Long);
  76. WebIDL::UnsignedLong cols() const;
  77. WebIDL::ExceptionOr<void> set_cols(unsigned);
  78. WebIDL::UnsignedLong rows() const;
  79. WebIDL::ExceptionOr<void> set_rows(WebIDL::UnsignedLong);
  80. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectionstart
  81. WebIDL::UnsignedLong selection_start_binding() const;
  82. WebIDL::ExceptionOr<void> set_selection_start_binding(WebIDL::UnsignedLong const&);
  83. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectionend
  84. WebIDL::UnsignedLong selection_end_binding() const;
  85. WebIDL::ExceptionOr<void> set_selection_end_binding(WebIDL::UnsignedLong const&);
  86. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-textarea/input-selectiondirection
  87. String selection_direction_binding() const;
  88. void set_selection_direction_binding(String const& direction);
  89. void set_dirty_value_flag(Badge<FormAssociatedElement>, bool flag) { m_dirty_value = flag; }
  90. // ^FormAssociatedTextControlElement
  91. virtual void did_edit_text_node() override;
  92. virtual GC::Ptr<DOM::Text> form_associated_element_to_text_node() override { return m_text_node; }
  93. private:
  94. HTMLTextAreaElement(DOM::Document&, DOM::QualifiedName);
  95. virtual void initialize(JS::Realm&) override;
  96. virtual void visit_edges(Cell::Visitor&) override;
  97. void set_raw_value(String);
  98. // ^DOM::Element
  99. virtual i32 default_tab_index_value() const override;
  100. void create_shadow_tree_if_needed();
  101. void handle_readonly_attribute(Optional<String> const& value);
  102. void handle_maxlength_attribute();
  103. void queue_firing_input_event();
  104. void update_placeholder_visibility();
  105. GC::Ptr<DOM::Element> m_placeholder_element;
  106. GC::Ptr<DOM::Text> m_placeholder_text_node;
  107. GC::Ptr<DOM::Element> m_inner_text_element;
  108. GC::Ptr<DOM::Text> m_text_node;
  109. RefPtr<Core::Timer> m_input_event_timer;
  110. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-dirty
  111. bool m_dirty_value { false };
  112. // https://html.spec.whatwg.org/multipage/form-elements.html#the-textarea-element:concept-fe-mutable
  113. bool m_is_mutable { true };
  114. // https://html.spec.whatwg.org/multipage/form-elements.html#concept-textarea-raw-value
  115. String m_raw_value;
  116. // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-api-value
  117. mutable Optional<String> m_api_value;
  118. };
  119. }