2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2023-08-30 14:38:58 +01:00
|
|
|
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-06-15 18:55:47 +02:00
|
|
|
#pragma once
|
|
|
|
|
2020-03-07 10:32:51 +01:00
|
|
|
#include <LibWeb/DOM/CharacterData.h>
|
2024-09-18 11:09:07 +01:00
|
|
|
#include <LibWeb/DOM/Element.h>
|
2023-09-05 13:07:35 -04:00
|
|
|
#include <LibWeb/DOM/Slottable.h>
|
2019-06-15 18:55:47 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
namespace Web::DOM {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2023-09-05 13:07:35 -04:00
|
|
|
class Text
|
|
|
|
: public CharacterData
|
|
|
|
, public SlottableMixin {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(Text, CharacterData);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(Text);
|
2020-08-03 20:50:45 +02:00
|
|
|
|
2022-08-28 13:42:07 +02:00
|
|
|
public:
|
2022-03-14 13:21:51 -06:00
|
|
|
virtual ~Text() override = default;
|
2019-06-15 18:55:47 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
static WebIDL::ExceptionOr<GC::Ref<Text>> construct_impl(JS::Realm& realm, String const& data);
|
2021-09-06 01:07:11 +01:00
|
|
|
|
2021-02-10 18:23:02 +01:00
|
|
|
// ^Node
|
2023-09-17 10:51:43 +12:00
|
|
|
virtual FlyString node_name() const override { return "#text"_fly_string; }
|
2019-09-28 22:59:16 +02:00
|
|
|
|
2024-03-01 08:49:04 +01:00
|
|
|
Optional<size_t> max_length() const { return m_max_length; }
|
|
|
|
void set_max_length(Optional<size_t> max_length) { m_max_length = move(max_length); }
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<Text>> split_text(size_t offset);
|
2024-07-19 13:57:24 -06:00
|
|
|
String whole_text();
|
2022-03-21 18:57:10 +01:00
|
|
|
|
2022-11-05 17:19:00 +01:00
|
|
|
bool is_password_input() const { return m_is_password_input; }
|
|
|
|
void set_is_password_input(Badge<HTML::HTMLInputElement>, bool b) { m_is_password_input = b; }
|
|
|
|
|
2024-09-18 11:09:07 +01:00
|
|
|
Optional<Element::Directionality> directionality() const;
|
|
|
|
|
2022-06-27 21:20:59 +01:00
|
|
|
protected:
|
2023-09-06 15:17:20 +12:00
|
|
|
Text(Document&, String const&);
|
|
|
|
Text(Document&, NodeType, String const&);
|
2022-06-27 21:20:59 +01:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-28 13:42:07 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2019-06-15 18:55:47 +02:00
|
|
|
private:
|
2024-03-01 08:49:04 +01:00
|
|
|
Optional<size_t> m_max_length {};
|
2022-11-05 17:19:00 +01:00
|
|
|
bool m_is_password_input { false };
|
2019-06-15 18:55:47 +02:00
|
|
|
};
|
2019-10-06 20:37:39 +02:00
|
|
|
|
2022-03-29 23:28:17 +02:00
|
|
|
template<>
|
|
|
|
inline bool Node::fast_is<Text>() const { return is_text(); }
|
|
|
|
|
2019-10-06 20:37:39 +02:00
|
|
|
}
|