LibWeb: Remove text storage from TextPaintable

Instead of copying the layout node's text, retrieve the text from the
layout node directly.
This commit is contained in:
Jelle Raaijmakers 2025-09-10 15:52:34 +02:00 committed by Tim Flynn
commit d1076c1e6e
Notes: github-actions[bot] 2025-09-12 19:35:17 +00:00
5 changed files with 8 additions and 13 deletions

View file

@ -555,7 +555,7 @@ Optional<TextNode::Chunk> TextNode::ChunkIterator::try_commit_chunk(size_t start
GC::Ptr<Painting::Paintable> TextNode::create_paintable() const
{
return Painting::TextPaintable::create(*this, text_for_rendering());
return Painting::TextPaintable::create(*this);
}
}

View file

@ -986,7 +986,7 @@ EventResult EventHandler::handle_doubleclick(CSSPixelPoint viewport_position, CS
next_boundary = hit_dom_node.length_in_utf16_code_units();
} else {
auto& segmenter = word_segmenter();
segmenter.set_segmented_text(hit_paintable.text_for_rendering());
segmenter.set_segmented_text(hit_paintable.layout_node().text_for_rendering());
previous_boundary = segmenter.previous_boundary(result->index_in_node, Unicode::Segmenter::Inclusive::Yes).value_or(0);
next_boundary = segmenter.next_boundary(result->index_in_node).value_or(hit_dom_node.length());

View file

@ -208,7 +208,7 @@ Utf16View PaintableFragment::text() const
{
if (!is<TextPaintable>(paintable()))
return {};
return static_cast<TextPaintable const&>(paintable()).text_for_rendering().substring_view(m_start_offset, m_length_in_code_units);
return as<TextPaintable>(paintable()).layout_node().text_for_rendering().substring_view(m_start_offset, m_length_in_code_units);
}
}

View file

@ -14,14 +14,13 @@ namespace Web::Painting {
GC_DEFINE_ALLOCATOR(TextPaintable);
GC::Ref<TextPaintable> TextPaintable::create(Layout::TextNode const& layout_node, Utf16String text_for_rendering)
GC::Ref<TextPaintable> TextPaintable::create(Layout::TextNode const& layout_node)
{
return layout_node.heap().allocate<TextPaintable>(layout_node, move(text_for_rendering));
return layout_node.heap().allocate<TextPaintable>(layout_node);
}
TextPaintable::TextPaintable(Layout::TextNode const& layout_node, Utf16String text_for_rendering)
TextPaintable::TextPaintable(Layout::TextNode const& layout_node)
: Paintable(layout_node)
, m_text_for_rendering(move(text_for_rendering))
{
}

View file

@ -16,7 +16,7 @@ class TextPaintable final : public Paintable {
GC_DECLARE_ALLOCATOR(TextPaintable);
public:
static GC::Ref<TextPaintable> create(Layout::TextNode const&, Utf16String text_for_rendering);
static GC::Ref<TextPaintable> create(Layout::TextNode const&);
Layout::TextNode const& layout_node() const { return static_cast<Layout::TextNode const&>(Paintable::layout_node()); }
@ -25,14 +25,10 @@ public:
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
Utf16String const& text_for_rendering() const { return m_text_for_rendering; }
private:
virtual bool is_text_paintable() const override { return true; }
TextPaintable(Layout::TextNode const&, Utf16String text_for_rendering);
Utf16String m_text_for_rendering;
TextPaintable(Layout::TextNode const&);
};
}