1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

LibWeb: Specialize hit testing for text cursor purposes

The text cursor follows slightly different "intuitive" rules than the
regular hit testing. Clicking past the right edge of a text box should
still "hit" the text box, and place the cursor at its end, for example.

We solve this by adding a HitTestType enum that is passed to hit_test()
and determines whether past-the-edge candidates are considered.
This commit is contained in:
Andreas Kling 2020-08-05 16:55:56 +02:00
parent 5cee150a91
commit e2b4fef6c7
11 changed files with 38 additions and 27 deletions

View file

@ -61,19 +61,19 @@ void StackingContext::paint(PaintContext& context, LayoutNode::PaintPhase phase)
}
}
HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position) const
HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestType type) const
{
HitTestResult result;
if (!m_box.is_root()) {
result = m_box.hit_test(position);
result = m_box.hit_test(position, type);
} else {
// NOTE: LayoutDocument::hit_test() merely calls StackingContext::hit_test()
// so we call its base class instead.
result = downcast<LayoutDocument>(m_box).LayoutBlock::hit_test(position);
result = downcast<LayoutDocument>(m_box).LayoutBlock::hit_test(position, type);
}
for (auto* child : m_children) {
auto result_here = child->hit_test(position);
auto result_here = child->hit_test(position, type);
if (result_here.layout_node)
result = result_here;
}