diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-21 15:43:37 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-21 15:43:37 +0100 |
commit | 196a3eb239a0e7c1ced45c4957b2aa230056c179 (patch) | |
tree | 85d764744a2bcc77aa82b0cb7b4594a9a29df91f | |
parent | df8ef03957d5a9918562af3c039b83433aff7db3 (diff) | |
download | serenity-196a3eb239a0e7c1ced45c4957b2aa230056c179.zip |
LibWeb: Ignore invisible boxes and stacking contexts during hit testing
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/PaintableBox.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/StackingContext.cpp | 8 |
2 files changed, 10 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 5e512dc12f..9684c1aa8f 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -464,6 +464,9 @@ void PaintableBox::set_stacking_context(NonnullOwnPtr<StackingContext> stacking_ Optional<HitTestResult> PaintableBox::hit_test(Gfx::FloatPoint const& position, HitTestType type) const { + if (!is_visible()) + return {}; + if (layout_box().is_initial_containing_block_box()) { const_cast<Layout::InitialContainingBlock&>(static_cast<Layout::InitialContainingBlock const&>(layout_box())).build_stacking_context_tree_if_needed(); return stacking_context()->hit_test(position, type); @@ -497,7 +500,7 @@ Optional<HitTestResult> PaintableWithLines::hit_test(const Gfx::FloatPoint& posi if (type == HitTestType::TextCursor && last_good_candidate.has_value()) return last_good_candidate; - if (absolute_border_box_rect().contains(position.x(), position.y())) + if (is_visible() && absolute_border_box_rect().contains(position.x(), position.y())) return HitTestResult { *this }; return {}; } diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index c8349e4fd3..308ca77354 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -286,8 +286,10 @@ Optional<HitTestResult> StackingContext::hit_test(Gfx::FloatPoint const& positio // 7. the child stacking contexts with positive stack levels (least positive first). for (ssize_t i = m_children.size() - 1; i >= 0; --i) { auto const& child = *m_children[i]; + if (!child.m_box.is_visible()) + continue; if (child.m_box.computed_values().z_index().value_or(0) < 0) - break; + continue; auto result = child.hit_test(transformed_position, type); if (result.has_value()) return result; @@ -340,7 +342,9 @@ Optional<HitTestResult> StackingContext::hit_test(Gfx::FloatPoint const& positio for (ssize_t i = m_children.size() - 1; i >= 0; --i) { auto const& child = *m_children[i]; if (child.m_box.computed_values().z_index().value_or(0) < 0) - break; + continue; + if (!child.m_box.is_visible()) + continue; auto result = child.hit_test(transformed_position, type); if (result.has_value()) return result; |