Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 01fc476

Browse files
kojiishichromium-wpt-export-bot
authored andcommitted
[LayoutNG] Fix hit-testing image list markers
This patch fixes hit-testing image list markers. The previous fix for hit-testing list markers (r682470 crrev.com/c/1726571) didn't cover image list markers, and unfortunately the test did not cover the case. Bug: 1002417 Change-Id: Ieefcfa91240570a3d59265cf7e75c802396da6d4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1862873 Reviewed-by: Ian Kilpatrick <[email protected]> Commit-Queue: Koji Ishii <[email protected]> Cr-Commit-Position: refs/heads/master@{#706094}
1 parent 9a5320a commit 01fc476

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

css/cssom-view/elementFromPoint-list-001.html

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,79 @@
55
<script src="/resources/testharness.js"></script>
66
<script src="/resources/testharnessreport.js"></script>
77
<style>
8+
ul {
9+
font-size: 10px;
10+
}
811
ul.inside {
912
list-style-position: inside;
1013
}
14+
.image {
15+
list-style-image: url(../../images/green-16x16.png);
16+
}
17+
.debug-marker {
18+
position: absolute;
19+
width: 0;
20+
height: 0;
21+
outline: 2px solid red;
22+
}
1123
</style>
1224
<body>
1325
<ul>
1426
<li>Outside 1</li>
1527
<li>Outside 2</li>
1628
<li>Outside 3</li>
29+
<li class="image">Image Outside 1</li>
30+
<li class="image">Image Outside 2</li>
1731
</ul>
1832
<ul class="inside">
1933
<li>Inside 1</li>
2034
<li>Inside 2</li>
2135
<li>Inside 3</li>
36+
<li class="image">Image Inside 1</li>
37+
<li class="image">Image Inside 2</li>
2238
</ul>
2339
<script>
24-
for (let li of document.getElementsByTagName('li')) {
25-
test(() => {
26-
let bounds = li.getBoundingClientRect();
27-
let target = document.elementFromPoint(bounds.x + 1, bounds.y + 1);
28-
assert_equals(target, li);
29-
}, `<li>${li.textContent}</li>`);
40+
setup({explicit_done:true});
41+
window.onload = function() {
42+
for (let li of document.getElementsByTagName('li')) {
43+
test(() => {
44+
let bounds = li.getBoundingClientRect();
45+
let style = window.getComputedStyle(li);
46+
let y = (bounds.top + bounds.bottom) / 2;
47+
if (style.listStylePosition === 'inside') {
48+
// Inside markers are normal inline boxes.
49+
// It is safe to assume "left + 1" is in the box.
50+
let x = bounds.left + 1;
51+
addDebugMarker(x, y);
52+
let result = document.elementFromPoint(x, y);
53+
assert_equals(result, li);
54+
} else {
55+
// The spec does not define outside marker position.
56+
// This code assumes that the marker is within "left - 40" to "left - 1".
57+
// This is heuristic, but all browsers seem to pass with this method.
58+
let result = null;
59+
for (let x = bounds.left - 40; x < bounds.left; x++) {
60+
result = document.elementFromPoint(x, y);
61+
if (result === li) {
62+
addDebugMarker(x, y);
63+
break;
64+
}
65+
}
66+
assert_equals(result, li);
67+
}
68+
}, `<li>${li.textContent}</li>`);
69+
}
70+
done();
71+
};
72+
73+
// Show a marker for the debugging purposes, in case the heuristic doesn't apply.
74+
function addDebugMarker(x, y) {
75+
let div = document.createElement('div');
76+
div.className = 'debug-marker';
77+
let style = div.style;
78+
style.left = x + 'px';
79+
style.top = y + 'px';
80+
document.body.appendChild(div);
3081
}
3182
</script>
3283
</body>

0 commit comments

Comments
 (0)