mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +00:00
LibWeb: Port text segmentation to the ICU text segmenter
This commit is contained in:
parent
14071c52f9
commit
12f177e9e9
Notes:
sideshowbarker
2024-07-17 03:27:40 +09:00
Author: https://github.com/trflynn89
Commit: 12f177e9e9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/218
5 changed files with 40 additions and 20 deletions
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibLocale/Segmenter.h>
|
||||
#include <LibWeb/Bindings/CharacterDataPrototype.h>
|
||||
#include <LibWeb/DOM/CharacterData.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
|
@ -22,6 +23,8 @@ CharacterData::CharacterData(Document& document, NodeType type, String const& da
|
|||
{
|
||||
}
|
||||
|
||||
CharacterData::~CharacterData() = default;
|
||||
|
||||
void CharacterData::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
|
@ -124,6 +127,10 @@ WebIDL::ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t coun
|
|||
static_cast<Layout::TextNode&>(*layout_node).invalidate_text_for_rendering();
|
||||
|
||||
document().set_needs_layout();
|
||||
|
||||
if (m_segmenter)
|
||||
m_segmenter->set_segmented_text(m_data);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -148,4 +155,14 @@ WebIDL::ExceptionOr<void> CharacterData::delete_data(size_t offset, size_t count
|
|||
return replace_data(offset, count, String {});
|
||||
}
|
||||
|
||||
Locale::Segmenter& CharacterData::segmenter()
|
||||
{
|
||||
if (!m_segmenter) {
|
||||
m_segmenter = Locale::Segmenter::create(Locale::SegmenterGranularity::Grapheme);
|
||||
m_segmenter->set_segmented_text(m_data);
|
||||
}
|
||||
|
||||
return *m_segmenter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue