Files
serenity/Userland/Libraries/LibWeb/DOM/CharacterData.h
Timothy Flynn d89c41e4ad LibWeb: Add Document helpers to move its cursor to word boundaries
This implementation is based on the same feature I added to Serenity's
TextEditor:

https://github.com/SerenityOS/serenity/pull/17477

(cherry picked from commit ecf2cc600bea8f8396061f5fe6aba8358a033bbb;
amended to change Unicode::Segmenter to Locale::Segmenter due to
LibLocale and LibUnicode being separate libraries in serenity)
2024-11-26 16:03:32 -05:00

59 lines
1.7 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
#include <AK/Utf16View.h>
#include <LibLocale/Forward.h>
#include <LibWeb/DOM/ChildNode.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/NonDocumentTypeChildNode.h>
namespace Web::DOM {
// https://dom.spec.whatwg.org/#characterdata
class CharacterData
: public Node
, public ChildNode<CharacterData>
, public NonDocumentTypeChildNode<CharacterData> {
WEB_PLATFORM_OBJECT(CharacterData, Node);
JS_DECLARE_ALLOCATOR(CharacterData);
public:
virtual ~CharacterData() override;
String const& data() const { return m_data; }
void set_data(String const&);
unsigned length_in_utf16_code_units() const
{
return AK::utf16_code_unit_length_from_utf8(m_data);
}
WebIDL::ExceptionOr<String> substring_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units) const;
WebIDL::ExceptionOr<void> append_data(String const&);
WebIDL::ExceptionOr<void> insert_data(size_t offset_in_utf16_code_units, String const&);
WebIDL::ExceptionOr<void> delete_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units);
WebIDL::ExceptionOr<void> replace_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units, String const&);
Locale::Segmenter& grapheme_segmenter();
Locale::Segmenter& word_segmenter();
protected:
CharacterData(Document&, NodeType, String const&);
virtual void initialize(JS::Realm&) override;
private:
String m_data;
OwnPtr<Locale::Segmenter> m_grapheme_segmenter;
OwnPtr<Locale::Segmenter> m_word_segmenter;
};
}