diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-10 22:58:19 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-11 00:21:49 +0100 |
commit | f017c1c064e30399a569dde21051b377ab91528d (patch) | |
tree | 03dff8dc884ccaa1a8e3a2c49cb086ee0ebbc521 /Userland/Libraries/LibWeb/Layout | |
parent | cb0c5390ff9a0189ae79cfd690f6c089ba73c4a7 (diff) | |
download | serenity-f017c1c064e30399a569dde21051b377ab91528d.zip |
LibWeb: Make hit testing return a { paintable, offset }
Everything related to hit testing is better off using the painting tree.
The thing being mousemoved over is a paintable, so let's hand that out
directly instead of the corresponding layout node.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/BlockContainer.cpp | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Box.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.h | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp b/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp index dcfa305ae5..bdb925185a 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp @@ -42,16 +42,16 @@ HitTestResult BlockContainer::hit_test(const Gfx::IntPoint& position, HitTestTyp if (enclosing_int_rect(fragment.absolute_rect()).contains(position)) { if (is<BlockContainer>(fragment.layout_node())) return verify_cast<BlockContainer>(fragment.layout_node()).hit_test(position, type); - return { fragment.layout_node(), fragment.text_index_at(position.x()) }; + return { fragment.layout_node().paintable(), fragment.text_index_at(position.x()) }; } if (fragment.absolute_rect().top() <= position.y()) - last_good_candidate = { fragment.layout_node(), fragment.text_index_at(position.x()) }; + last_good_candidate = { fragment.layout_node().paintable(), fragment.text_index_at(position.x()) }; } } - if (type == HitTestType::TextCursor && last_good_candidate.layout_node) + if (type == HitTestType::TextCursor && last_good_candidate.paintable) return last_good_candidate; - return { paint_box()->absolute_border_box_rect().contains(position.x(), position.y()) ? this : nullptr }; + return { paint_box()->absolute_border_box_rect().contains(position.x(), position.y()) ? paintable() : nullptr }; } bool BlockContainer::is_scrollable() const diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index 3c71d8bcb7..a5ab762a43 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -62,10 +62,10 @@ HitTestResult Box::hit_test(const Gfx::IntPoint& position, HitTestType type) con // FIXME: It would be nice if we could confidently skip over hit testing // parts of the layout tree, but currently we can't just check // m_rect.contains() since inline text rects can't be trusted.. - HitTestResult result { paint_box()->absolute_border_box_rect().contains(position.x(), position.y()) ? this : nullptr }; + HitTestResult result { paint_box()->absolute_border_box_rect().contains(position.x(), position.y()) ? paint_box() : nullptr }; for_each_child_in_paint_order([&](auto& child) { auto child_result = child.hit_test(position, type); - if (child_result.layout_node) + if (child_result.paintable) result = child_result; }); return result; diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index e25fe1e0d1..eb1b9f1012 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -27,7 +27,7 @@ enum class LayoutMode { }; struct HitTestResult { - RefPtr<Node> layout_node; + RefPtr<Painting::Paintable> paintable; int index_in_node { 0 }; enum InternalPosition { |