Commit 85722a75 authored by David Bokan's avatar David Bokan Committed by Commit Bot

[SpatNav] Hit testing must account for shadow boundaries

The spatial navigation algorithm attempts to select an inner-most
element when fully contained by using a hit test. However, hit testing
descends into shadow DOM so in order for this comparison to work it must
also descend through shadow roots.

Bug: 957240
Change-Id: I5f8d62187548becfa5dc3ad95c255ba54bcdb7b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1586271Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: David Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654874}
parent 035f61af
...@@ -118,12 +118,14 @@ static void ConsiderForBestCandidate(SpatialNavigationDirection direction, ...@@ -118,12 +118,14 @@ static void ConsiderForBestCandidate(SpatialNavigationDirection direction,
.HitTestResultAtLocation( .HitTestResultAtLocation(
location, HitTestRequest::kReadOnly | HitTestRequest::kActive | location, HitTestRequest::kReadOnly | HitTestRequest::kActive |
HitTestRequest::kIgnoreClipping); HitTestRequest::kIgnoreClipping);
if (candidate.visible_node->contains(result.InnerNode())) { if (candidate.visible_node->ContainsIncludingHostElements(
*result.InnerNode())) {
*best_candidate = candidate; *best_candidate = candidate;
*best_distance = distance; *best_distance = distance;
return; return;
} }
if (best_candidate->visible_node->contains(result.InnerNode())) if (best_candidate->visible_node->ContainsIncludingHostElements(
*result.InnerNode()))
return; return;
} }
......
<!DOCTYPE html>
<script src="../../../../../resources/testharness.js"></script>
<script src="../../../../../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/page/spatial_navigation.mojom.js"></script>
<script src="../../../../../fast/spatial-navigation/resources/mock-snav-service.js"></script>
<script src="../../../../../fast/spatial-navigation/resources/snav-testharness.js"></script>
<style>
div {
width: 200px;
height: 200px;
margin: 5px;
border: 1px solid black;
}
input {
margin: 5px;
}
</style>
<div tabindex="0">
<input id="input" type="text" value="second"></input>
</div>
<script>
const input = document.getElementById("input");
// Spatial navigation attempts to determine when one valid target fully
// contains another. In this case, the contained "inner" target should be
// selected. This is done by performing a hit test.
//
// This test ensures the hit test works correctly on an input box. This
// requires special attention because the hit element will be in the input's
// shadow dom.
test(() => {
assert_true(!!window.internals);
snav.triggerMove('Down');
assert_equals(window.internals.interestedElement,
input,
"Expected interest to move to input box.");
}, "Navigation to fully contained input box.");
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment