mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-25 19:51:59 +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
Notes:
sideshowbarker
2024-07-19 03:21:04 +09:00
Author: https://github.com/awesomekling
Commit: d47f77169f
6 changed files with 60 additions and 15 deletions
|
@ -120,4 +120,30 @@ HitTestResult LayoutDocument::hit_test(const Gfx::IntPoint& position, HitTestTyp
|
|||
return stacking_context()->hit_test(position, type);
|
||||
}
|
||||
|
||||
void LayoutDocument::recompute_selection_states()
|
||||
{
|
||||
SelectionState state = SelectionState::None;
|
||||
|
||||
auto selection = this->selection().normalized();
|
||||
|
||||
for_each_in_subtree([&](auto& layout_node) {
|
||||
if (!selection.is_valid()) {
|
||||
// Everything gets SelectionState::None.
|
||||
} else if (&layout_node == selection.start().layout_node && &layout_node == selection.end().layout_node) {
|
||||
state = SelectionState::StartAndEnd;
|
||||
} else if (&layout_node == selection.start().layout_node) {
|
||||
state = SelectionState::Start;
|
||||
} else if (&layout_node == selection.end().layout_node) {
|
||||
state = SelectionState::End;
|
||||
} else {
|
||||
if (state == SelectionState::Start)
|
||||
state = SelectionState::Full;
|
||||
else if (state == SelectionState::End || state == SelectionState::StartAndEnd)
|
||||
state = SelectionState::None;
|
||||
}
|
||||
layout_node.set_selection_state(state);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue