mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 14:35:07 +00:00
LibWeb: Remember the selection state of each LayoutNode
Instead of computing it on the fly while painting each layout node, they now remember their selection state. This avoids a whole bunch of tree traversal while painting with anything selected.
This commit is contained in:
parent
cf4870c93e
commit
d47f77169f
6 changed files with 60 additions and 15 deletions
|
@ -100,6 +100,12 @@ int LineBoxFragment::text_index_at(float x) const
|
|||
|
||||
Gfx::FloatRect LineBoxFragment::selection_rect(const Gfx::Font& font) const
|
||||
{
|
||||
if (layout_node().selection_state() == LayoutNode::SelectionState::None)
|
||||
return {};
|
||||
|
||||
if (layout_node().selection_state() == LayoutNode::SelectionState::Full)
|
||||
return absolute_rect();
|
||||
|
||||
auto selection = layout_node().root().selection().normalized();
|
||||
if (!selection.is_valid())
|
||||
return {};
|
||||
|
@ -110,7 +116,7 @@ Gfx::FloatRect LineBoxFragment::selection_rect(const Gfx::Font& font) const
|
|||
const auto end_index = m_start + m_length;
|
||||
auto text = this->text();
|
||||
|
||||
if (&layout_node() == selection.start().layout_node && &layout_node() == selection.end().layout_node) {
|
||||
if (layout_node().selection_state() == LayoutNode::SelectionState::StartAndEnd) {
|
||||
// we are in the start/end node (both the same)
|
||||
if (start_index > selection.end().index_in_node)
|
||||
return {};
|
||||
|
@ -128,7 +134,7 @@ Gfx::FloatRect LineBoxFragment::selection_rect(const Gfx::Font& font) const
|
|||
|
||||
return rect;
|
||||
}
|
||||
if (&layout_node() == selection.start().layout_node) {
|
||||
if (layout_node().selection_state() == LayoutNode::SelectionState::Start) {
|
||||
// we are in the start node
|
||||
if (end_index < selection.start().index_in_node)
|
||||
return {};
|
||||
|
@ -144,7 +150,7 @@ Gfx::FloatRect LineBoxFragment::selection_rect(const Gfx::Font& font) const
|
|||
|
||||
return rect;
|
||||
}
|
||||
if (&layout_node() == selection.end().layout_node) {
|
||||
if (layout_node().selection_state() == LayoutNode::SelectionState::End) {
|
||||
// we are in the end node
|
||||
if (start_index > selection.end().index_in_node)
|
||||
return {};
|
||||
|
@ -160,18 +166,6 @@ Gfx::FloatRect LineBoxFragment::selection_rect(const Gfx::Font& font) const
|
|||
|
||||
return rect;
|
||||
}
|
||||
|
||||
// are we in between start and end?
|
||||
auto* node = selection.start().layout_node.ptr();
|
||||
bool is_fully_selected = false;
|
||||
for (; node && node != selection.end().layout_node.ptr(); node = node->next_in_pre_order()) {
|
||||
if (node == &layout_node()) {
|
||||
is_fully_selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_fully_selected)
|
||||
return absolute_rect();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue