2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-10-12 18:26:47 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2025-07-24 13:05:52 -03:00
|
|
|
#include <AK/Utf16String.h>
|
2024-07-30 07:46:30 -03:00
|
|
|
#include <AK/Utf16View.h>
|
2024-06-23 10:14:27 -03:00
|
|
|
#include <LibUnicode/Forward.h>
|
2021-09-29 12:25:48 -03:00
|
|
|
#include <LibWeb/DOM/ChildNode.h>
|
2020-03-07 06:32:51 -03:00
|
|
|
#include <LibWeb/DOM/Node.h>
|
2020-08-03 15:30:02 -03:00
|
|
|
#include <LibWeb/DOM/NonDocumentTypeChildNode.h>
|
2025-07-19 23:35:33 -03:00
|
|
|
#include <LibWeb/Export.h>
|
2019-10-12 18:26:47 -03:00
|
|
|
|
2020-07-26 14:37:56 -03:00
|
|
|
namespace Web::DOM {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2023-12-22 04:41:34 -03:00
|
|
|
// https://dom.spec.whatwg.org/#characterdata
|
2025-07-19 23:35:33 -03:00
|
|
|
class WEB_API CharacterData
|
2020-08-03 15:30:02 -03:00
|
|
|
: public Node
|
2021-09-29 12:25:48 -03:00
|
|
|
, public ChildNode<CharacterData>
|
2020-08-03 15:30:02 -03:00
|
|
|
, public NonDocumentTypeChildNode<CharacterData> {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(CharacterData, Node);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(CharacterData);
|
2020-08-03 15:50:45 -03:00
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
public:
|
2024-06-19 10:02:21 -03:00
|
|
|
virtual ~CharacterData() override;
|
2019-10-12 18:26:47 -03:00
|
|
|
|
2025-07-24 13:05:52 -03:00
|
|
|
Utf16String const& data() const { return m_data; }
|
|
|
|
|
void set_data(Utf16String const&);
|
2019-10-12 18:26:47 -03:00
|
|
|
|
2025-07-24 13:05:52 -03:00
|
|
|
unsigned length_in_utf16_code_units() const { return m_data.length_in_code_units(); }
|
2020-08-03 15:50:45 -03:00
|
|
|
|
2025-07-24 13:05:52 -03:00
|
|
|
WebIDL::ExceptionOr<Utf16String> substring_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units) const;
|
|
|
|
|
WebIDL::ExceptionOr<void> append_data(Utf16View const&);
|
|
|
|
|
WebIDL::ExceptionOr<void> insert_data(size_t offset_in_utf16_code_units, Utf16View const&);
|
2023-12-22 04:41:34 -03:00
|
|
|
WebIDL::ExceptionOr<void> delete_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units);
|
2025-07-24 13:05:52 -03:00
|
|
|
WebIDL::ExceptionOr<void> replace_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units, Utf16View const&);
|
2022-03-21 13:20:42 -03:00
|
|
|
|
2024-09-22 11:03:23 -03:00
|
|
|
Unicode::Segmenter& grapheme_segmenter() const;
|
|
|
|
|
Unicode::Segmenter& word_segmenter() const;
|
2024-06-19 10:02:21 -03:00
|
|
|
|
2019-10-12 18:26:47 -03:00
|
|
|
protected:
|
2025-07-24 13:05:52 -03:00
|
|
|
CharacterData(Document&, NodeType, Utf16String);
|
2019-10-12 18:26:47 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2023-01-10 08:28:20 -03:00
|
|
|
|
2019-10-12 18:26:47 -03:00
|
|
|
private:
|
2025-07-24 13:05:52 -03:00
|
|
|
Utf16String m_data;
|
2024-06-19 10:02:21 -03:00
|
|
|
|
2024-09-22 11:03:23 -03:00
|
|
|
mutable OwnPtr<Unicode::Segmenter> m_grapheme_segmenter;
|
|
|
|
|
mutable OwnPtr<Unicode::Segmenter> m_word_segmenter;
|
2019-10-12 18:26:47 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|