HTMLTextAreaElement.h 3.8 KB

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