summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Layout/LineBoxFragment.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-21 17:50:41 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-21 17:57:24 +0200
commitd47f77169f8c3bdb6675a67a736b5591a752b52c (patch)
tree4ad2cb19410f7fafd5e17a05548dc18ecd3e6612 /Libraries/LibWeb/Layout/LineBoxFragment.cpp
parentcf4870c93e274ad7f0620f86241b85de9a2adc76 (diff)
downloadserenity-d47f77169f8c3bdb6675a67a736b5591a752b52c.zip
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.
Diffstat (limited to 'Libraries/LibWeb/Layout/LineBoxFragment.cpp')
-rw-r--r--Libraries/LibWeb/Layout/LineBoxFragment.cpp24
1 files changed, 9 insertions, 15 deletions
diff --git a/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Libraries/LibWeb/Layout/LineBoxFragment.cpp
index 719ee8a5cd..af95972d18 100644
--- a/Libraries/LibWeb/Layout/LineBoxFragment.cpp
+++ b/Libraries/LibWeb/Layout/LineBoxFragment.cpp
@@ -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 {};
}