HTMLTextAreaElement.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // ^HTMLElement
  45. // https://html.spec.whatwg.org/multipage/forms.html#category-label
  46. virtual bool is_labelable() const override { return true; }
  47. virtual void reset_algorithm() override;
  48. virtual void form_associated_element_was_inserted() override;
  49. virtual void form_associated_element_was_removed(DOM::Node*) 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. unsigned cols() const;
  54. WebIDL::ExceptionOr<void> set_cols(unsigned value);
  55. unsigned rows() const;
  56. WebIDL::ExceptionOr<void> set_rows(unsigned value);
  57. private:
  58. HTMLTextAreaElement(DOM::Document&, DOM::QualifiedName);
  59. virtual void initialize(JS::Realm&) override;
  60. virtual void visit_edges(Cell::Visitor&) override;
  61. // ^DOM::Element
  62. virtual i32 default_tab_index_value() const override;
  63. void create_shadow_tree_if_needed();
  64. JS::GCPtr<DOM::Element> m_inner_text_element;
  65. JS::GCPtr<DOM::Text> m_text_node;
  66. bool m_dirty { false };
  67. String m_raw_value;
  68. };
  69. }