1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:17:36 +00:00

LibWeb: Implement hit testing a bit closer to spec

We now perform hit testing in reverse paint order as described in CSS2's
section about the z-index property.
This commit is contained in:
Andreas Kling 2022-03-04 15:02:16 +01:00
parent 0401d7da36
commit 15ed0ebdc6
4 changed files with 74 additions and 26 deletions

View file

@ -101,7 +101,7 @@ HitTestResult BlockContainer::hit_test(const Gfx::IntPoint& position, HitTestTyp
if (type == HitTestType::TextCursor && last_good_candidate.layout_node)
return last_good_candidate;
return { absolute_rect().contains(position.x(), position.y()) ? this : nullptr };
return { absolute_border_box_rect().contains(position.x(), position.y()) ? this : nullptr };
}
bool BlockContainer::is_scrollable() const

View file

@ -178,7 +178,7 @@ 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 { absolute_rect().contains(position.x(), position.y()) ? this : nullptr };
HitTestResult result { absolute_border_box_rect().contains(position.x(), position.y()) ? this : nullptr };
for_each_child_in_paint_order([&](auto& child) {
auto child_result = child.hit_test(position, type);
if (child_result.layout_node)

View file

@ -80,15 +80,9 @@ bool Node::establishes_stacking_context() const
return computed_values().opacity() < 1.0f;
}
HitTestResult Node::hit_test(const Gfx::IntPoint& position, HitTestType type) const
HitTestResult Node::hit_test(Gfx::IntPoint const&, HitTestType) const
{
HitTestResult result;
for_each_child_in_paint_order([&](auto& child) {
auto child_result = child.hit_test(position, type);
if (child_result.layout_node)
result = child_result;
});
return result;
VERIFY_NOT_REACHED();
}
HTML::BrowsingContext const& Node::browsing_context() const