|
@@ -148,27 +148,81 @@ void StackingContext::paint(PaintContext& context)
|
|
|
|
|
|
HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestType type) const
|
|
|
{
|
|
|
+ // NOTE: Hit testing basically happens in reverse painting order.
|
|
|
+ // https://www.w3.org/TR/CSS22/visuren.html#z-index
|
|
|
+
|
|
|
+ // 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.computed_values().z_index().value_or(0) < 0)
|
|
|
+ break;
|
|
|
+ auto result = child.hit_test(position, type);
|
|
|
+ if (result.layout_node)
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
HitTestResult result;
|
|
|
- if (!is<InitialContainingBlock>(m_box)) {
|
|
|
- result = m_box.hit_test(position, type);
|
|
|
- } else {
|
|
|
- // NOTE: InitialContainingBlock::hit_test() merely calls StackingContext::hit_test()
|
|
|
- // so we call its base class instead.
|
|
|
- result = verify_cast<InitialContainingBlock>(m_box).BlockContainer::hit_test(position, type);
|
|
|
+ // 6. the child stacking contexts with stack level 0 and the positioned descendants with stack level 0.
|
|
|
+ m_box.for_each_in_subtree_of_type<Layout::Box>([&](Layout::Box const& box) {
|
|
|
+ if (box.is_positioned() && !box.stacking_context()) {
|
|
|
+ result = box.hit_test(position, type);
|
|
|
+ if (result.layout_node)
|
|
|
+ return IterationDecision::Break;
|
|
|
+ }
|
|
|
+ return IterationDecision::Continue;
|
|
|
+ });
|
|
|
+ if (result.layout_node)
|
|
|
+ return result;
|
|
|
+
|
|
|
+ // 5. the in-flow, inline-level, non-positioned descendants, including inline tables and inline blocks.
|
|
|
+ if (m_box.children_are_inline() && is<BlockContainer>(m_box)) {
|
|
|
+ auto result = m_box.hit_test(position, type);
|
|
|
+ if (result.layout_node)
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
- int z_index = m_box.computed_values().z_index().value_or(0);
|
|
|
+ // 4. the non-positioned floats.
|
|
|
+ m_box.for_each_in_subtree_of_type<Layout::Box>([&](Layout::Box const& box) {
|
|
|
+ if (box.is_floating()) {
|
|
|
+ result = box.hit_test(position, type);
|
|
|
+ if (result.layout_node)
|
|
|
+ return IterationDecision::Break;
|
|
|
+ }
|
|
|
+ return IterationDecision::Continue;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 3. the in-flow, non-inline-level, non-positioned descendants.
|
|
|
+ if (!m_box.children_are_inline()) {
|
|
|
+ m_box.for_each_in_subtree_of_type<Layout::Box>([&](Layout::Box const& box) {
|
|
|
+ if (!box.is_absolutely_positioned() && !box.is_floating()) {
|
|
|
+ result = box.hit_test(position, type);
|
|
|
+ if (result.layout_node)
|
|
|
+ return IterationDecision::Break;
|
|
|
+ }
|
|
|
+ return IterationDecision::Continue;
|
|
|
+ });
|
|
|
+ if (result.layout_node)
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- for (auto* child : m_children) {
|
|
|
- int child_z_index = child->m_box.computed_values().z_index().value_or(0);
|
|
|
- if (result.layout_node && (child_z_index < z_index))
|
|
|
- continue;
|
|
|
+ // 2. the child stacking contexts with negative stack levels (most negative first).
|
|
|
+ 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;
|
|
|
+ auto result = child.hit_test(position, type);
|
|
|
+ if (result.layout_node)
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- auto result_here = child->hit_test(position, type);
|
|
|
- if (result_here.layout_node)
|
|
|
- result = result_here;
|
|
|
+ // 1. the background and borders of the element forming the stacking context.
|
|
|
+ if (m_box.absolute_border_box_rect().contains(position.to_type<float>())) {
|
|
|
+ return HitTestResult {
|
|
|
+ .layout_node = m_box,
|
|
|
+ };
|
|
|
}
|
|
|
- return result;
|
|
|
+
|
|
|
+ return {};
|
|
|
}
|
|
|
|
|
|
void StackingContext::dump(int indent) const
|