2020-08-01 05:07:00 +03:00
|
|
|
/*
|
2021-04-28 23:46:44 +03:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2022-03-02 00:03:30 +03:00
|
|
|
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
|
2024-03-01 10:49:04 +03:00
|
|
|
* Copyright (c) 2024, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
|
2020-08-01 05:07:00 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 05:07:00 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-03-16 13:44:18 +03:00
|
|
|
#include <LibCore/Timer.h>
|
2023-01-29 01:23:16 +03:00
|
|
|
#include <LibWeb/ARIA/Roles.h>
|
2023-08-30 19:10:38 +03:00
|
|
|
#include <LibWeb/DOM/Text.h>
|
2021-10-14 18:18:49 +03:00
|
|
|
#include <LibWeb/HTML/FormAssociatedElement.h>
|
2022-03-24 01:55:54 +03:00
|
|
|
#include <LibWeb/HTML/HTMLElement.h>
|
2024-03-01 10:49:04 +03:00
|
|
|
#include <LibWeb/WebIDL/Types.h>
|
2020-08-01 05:07:00 +03:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2022-03-24 01:55:54 +03:00
|
|
|
class HTMLTextAreaElement final
|
|
|
|
: public HTMLElement
|
2023-08-30 19:10:38 +03:00
|
|
|
, public FormAssociatedElement
|
|
|
|
, public DOM::EditableTextNodeOwner {
|
2022-08-28 14:42:07 +03:00
|
|
|
WEB_PLATFORM_OBJECT(HTMLTextAreaElement, HTMLElement);
|
2023-11-19 21:47:52 +03:00
|
|
|
JS_DECLARE_ALLOCATOR(HTMLTextAreaElement);
|
2022-03-24 01:55:54 +03:00
|
|
|
FORM_ASSOCIATED_ELEMENT(HTMLElement, HTMLTextAreaElement)
|
|
|
|
|
2020-08-01 05:07:00 +03:00
|
|
|
public:
|
|
|
|
virtual ~HTMLTextAreaElement() override;
|
|
|
|
|
2024-03-07 23:27:37 +03:00
|
|
|
virtual void adjust_computed_style(CSS::StyleProperties&) override;
|
2023-08-30 19:10:38 +03:00
|
|
|
|
2023-11-26 00:59:52 +03:00
|
|
|
String const& type() const
|
2020-09-18 10:49:51 +03:00
|
|
|
{
|
2023-11-26 00:59:52 +03:00
|
|
|
static String const textarea = "textarea"_string;
|
2020-08-01 05:07:00 +03:00
|
|
|
return textarea;
|
|
|
|
}
|
2022-03-02 00:03:30 +03:00
|
|
|
|
2023-08-30 19:10:38 +03:00
|
|
|
// ^DOM::EditableTextNodeOwner
|
|
|
|
virtual void did_edit_text_node(Badge<BrowsingContext>) override;
|
|
|
|
|
2022-03-26 21:05:48 +03:00
|
|
|
// ^EventTarget
|
|
|
|
// https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-textarea-element
|
|
|
|
virtual bool is_focusable() const override { return true; }
|
2023-08-30 19:10:38 +03:00
|
|
|
virtual void did_lose_focus() override;
|
|
|
|
virtual void did_receive_focus() override;
|
2022-03-26 21:05:48 +03:00
|
|
|
|
2022-03-02 00:03:30 +03:00
|
|
|
// ^FormAssociatedElement
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-listed
|
|
|
|
virtual bool is_listed() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-submit
|
|
|
|
virtual bool is_submittable() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-reset
|
|
|
|
virtual bool is_resettable() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-autocapitalize
|
|
|
|
virtual bool is_auto_capitalize_inheriting() const override { return true; }
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#category-label
|
|
|
|
virtual bool is_labelable() const override { return true; }
|
2022-08-28 14:42:07 +03:00
|
|
|
|
2022-12-23 03:58:21 +03:00
|
|
|
virtual void reset_algorithm() override;
|
|
|
|
|
2023-08-30 19:10:38 +03:00
|
|
|
virtual void form_associated_element_was_inserted() override;
|
2023-11-30 02:22:16 +03:00
|
|
|
virtual void form_associated_element_was_removed(DOM::Node*) override;
|
2024-02-03 17:33:33 +03:00
|
|
|
virtual void form_associated_element_attribute_changed(FlyString const&, Optional<String> const&) override;
|
2023-08-30 19:10:38 +03:00
|
|
|
|
|
|
|
virtual void children_changed() override;
|
|
|
|
|
2022-11-29 02:58:13 +03:00
|
|
|
// https://www.w3.org/TR/html-aria/#el-textarea
|
2023-01-29 01:23:16 +03:00
|
|
|
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::textbox; }
|
2022-11-29 02:58:13 +03:00
|
|
|
|
2023-12-10 19:48:42 +03:00
|
|
|
String default_value() const;
|
|
|
|
void set_default_value(String const&);
|
|
|
|
|
|
|
|
String value() const override;
|
|
|
|
void set_value(String const&);
|
|
|
|
|
|
|
|
u32 text_length() const;
|
|
|
|
|
2024-03-06 22:44:05 +03:00
|
|
|
bool check_validity();
|
|
|
|
bool report_validity();
|
|
|
|
void set_custom_validity(String const& error);
|
|
|
|
|
2024-03-14 17:05:07 +03:00
|
|
|
WebIDL::UnsignedLong selection_start() const;
|
|
|
|
WebIDL::ExceptionOr<void> set_selection_start(WebIDL::UnsignedLong);
|
|
|
|
|
|
|
|
WebIDL::UnsignedLong selection_end() const;
|
|
|
|
WebIDL::ExceptionOr<void> set_selection_end(WebIDL::UnsignedLong);
|
|
|
|
|
2024-03-01 10:49:04 +03:00
|
|
|
WebIDL::Long max_length() const;
|
|
|
|
WebIDL::ExceptionOr<void> set_max_length(WebIDL::Long);
|
|
|
|
|
|
|
|
WebIDL::Long min_length() const;
|
|
|
|
WebIDL::ExceptionOr<void> set_min_length(WebIDL::Long);
|
|
|
|
|
2023-11-24 19:39:38 +03:00
|
|
|
unsigned cols() const;
|
2023-12-10 19:48:42 +03:00
|
|
|
WebIDL::ExceptionOr<void> set_cols(unsigned);
|
2023-11-24 19:39:38 +03:00
|
|
|
|
|
|
|
unsigned rows() const;
|
2023-12-10 19:48:42 +03:00
|
|
|
WebIDL::ExceptionOr<void> set_rows(unsigned);
|
2023-11-24 19:39:38 +03:00
|
|
|
|
2022-08-28 14:42:07 +03:00
|
|
|
private:
|
|
|
|
HTMLTextAreaElement(DOM::Document&, DOM::QualifiedName);
|
2022-11-05 06:58:14 +03:00
|
|
|
|
2023-08-07 09:41:28 +03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2023-08-30 19:10:38 +03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2023-01-10 14:28:20 +03:00
|
|
|
|
2024-03-14 14:26:26 +03:00
|
|
|
void set_raw_value(String);
|
|
|
|
String api_value() const;
|
|
|
|
|
2022-11-05 06:58:14 +03:00
|
|
|
// ^DOM::Element
|
|
|
|
virtual i32 default_tab_index_value() const override;
|
2023-08-30 19:10:38 +03:00
|
|
|
|
|
|
|
void create_shadow_tree_if_needed();
|
|
|
|
|
2024-02-26 21:12:32 +03:00
|
|
|
void handle_readonly_attribute(Optional<String> const& value);
|
2024-03-01 10:49:04 +03:00
|
|
|
void handle_maxlength_attribute();
|
2024-02-26 21:12:32 +03:00
|
|
|
|
2024-03-06 23:14:20 +03:00
|
|
|
void queue_firing_input_event();
|
|
|
|
|
2023-12-21 20:13:16 +03:00
|
|
|
void update_placeholder_visibility();
|
|
|
|
JS::GCPtr<DOM::Element> m_placeholder_element;
|
|
|
|
JS::GCPtr<DOM::Text> m_placeholder_text_node;
|
|
|
|
|
2023-08-30 19:10:38 +03:00
|
|
|
JS::GCPtr<DOM::Element> m_inner_text_element;
|
|
|
|
JS::GCPtr<DOM::Text> m_text_node;
|
|
|
|
|
2024-03-16 13:44:18 +03:00
|
|
|
RefPtr<Core::Timer> m_input_event_timer;
|
2024-03-06 23:14:20 +03:00
|
|
|
|
2024-02-26 21:12:32 +03:00
|
|
|
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-dirty
|
|
|
|
bool m_dirty_value { false };
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/form-elements.html#the-textarea-element:concept-fe-mutable
|
|
|
|
bool m_is_mutable { true };
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-textarea-raw-value
|
2023-11-26 00:59:52 +03:00
|
|
|
String m_raw_value;
|
2024-03-14 14:26:26 +03:00
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-api-value
|
|
|
|
mutable Optional<String> m_api_value;
|
2020-08-01 05:07:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|