1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 11:55:08 +00:00

LibHTML: Build some foundation for text selection

Add LayoutPosition and LayoutRange classes. The layout tree root node
now has a selection() LayoutRange. It's essentially a start and end
LayoutPosition.

A LayoutPosition is a LayoutNode, and an optional index into that node.
The index is only relevant for text nodes, where it's the character
index into the rendered text.

HtmlView now updates the selection start/end of the LayoutDocument when
clicking and dragging with the left mouse button.

We don't paint the selection yet, and there's no way to copy what's
selected. It only exists as a LayoutRange.
This commit is contained in:
Andreas Kling 2019-11-05 22:13:26 +01:00
parent 2755184e11
commit f3f0b08d43
8 changed files with 119 additions and 2 deletions

View file

@ -293,7 +293,7 @@ HitTestResult LayoutBlock::hit_test(const Point& position) const
for (auto& line_box : m_line_boxes) {
for (auto& fragment : line_box.fragments()) {
if (enclosing_int_rect(fragment.rect()).contains(position)) {
return { fragment.layout_node() };
return { fragment.layout_node(), fragment.text_index_at(position.x()) };
}
}
}