Skip to content

Commit

Permalink
Use an explicit rect, rather than center point and padding, for rect-…
Browse files Browse the repository at this point in the history
…based hit tests

Prior to this patch, a rect-based hit test took as parameters a center point and four padding
values for top, right, bottom, and left padding. Theoretically, a rect-based hit test might have
asymmetric padding, but in practice, this never happens in the code (i.e., it's always true that
top-padding == bottom-padding and left-padding == right-padding).

Additionally, point-based hit tests used the same call path as rect-based hit tests (with zero
padding), which made the code hard to follow.

Finally, there was a bug in the rect-based hit test implementation: point-based hit tests always
create a one-pixel rect with the hit test point at top left and width=height=1. Because rect-based
hit tests used the same code path, the hit test rect was always erroneously expanded by one pixel
to the right and one pixel down.

This patch makes an explicit distinction between point-based and rect-based hit tests; it gets rid
of center-point-and-padding in favor of a simple rect; and it fixes the one-pixel-padding bug.
BUG=827639

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I11e49da328080c03da2e1662cbcc0317ab409740
Reviewed-on: https://chromium-review.googlesource.com/1081331
Reviewed-by: Chris Harrelson <chrishtr@chromium.org>
Reviewed-by: Philip Rogers <pdr@chromium.org>
Commit-Queue: Stefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565556}
  • Loading branch information
szager-chromium authored and Commit Bot committed Jun 8, 2018
1 parent 27aa45d commit 69f57e1
Show file tree
Hide file tree
Showing 25 changed files with 343 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,60 +18,60 @@

window.scrollTo(0, 0);

check(53, 71, 0, 0, 0, 0, [e.body]);
check(53, 71, 10, 0, 0, 0, [e.h1, e.body]);
check(53, 71, 0, 10, 0, 0, [e.p3, e.body]);
check(53, 71, 0, 0, 10, 0, [e.d1, e.body]);
check(53, 71, 0, 0, 0, 10, [e.body]);
check(53, 71, 0, 10, 0, 10, [e.p3, e.body]);
check(53, 71, 10, 0, 10, 0, [e.d1, e.h1, e.body]);
check(53, 71, 10, 10, 10, 10, [e.p3, e.d1, e.h1, e.body]);

check(152, 105, 10, 0, 0, 0, [e.p3, e.body]);
check(152, 105, 0, 10, 0, 0, [e.p4, e.body]);
check(152, 105, 0, 0, 10, 0, [e.body]);
check(152, 105, 0, 0, 0, 10, [e.d1, e.body]);
check(152, 105, 10, 0, 10, 0, [e.p3, e.body]);
check(152, 105, 0, 10, 0, 10, [e.p4, e.d1, e.body]);
check(152, 105, 10, 10, 10, 10, [e.p4, e.p3, e.d1, e.body]);
check(53, 71, 1, 1, [e.body]);
check(53, 61, 1, 11, [e.h1, e.body]);
check(53, 71, 11, 1, [e.p3, e.body]);
check(53, 71, 1, 11, [e.d1, e.body]);
check(43, 71, 11, 1, [e.body]);
check(43, 71, 21, 1, [e.p3, e.body]);
check(53, 61, 1, 21, [e.d1, e.h1, e.body]);
check(43, 61, 21, 21, [e.p3, e.d1, e.h1, e.body]);

check(152, 95, 1, 11, [e.p3, e.body]);
check(152, 105, 11, 1, [e.p4, e.body]);
check(152, 105, 1, 11, [e.body]);
check(142, 105, 11, 1, [e.d1, e.body]);
check(152, 95, 1, 21, [e.p3, e.body]);
check(142, 105, 21, 1, [e.p4, e.d1, e.body]);
check(142, 95, 21, 21, [e.p4, e.p3, e.d1, e.body]);

// e.p1 is invisible and shouldn't appear:
check(153, 193, 0, 0, 0, 0, [e.p5]);
check(153, 193, 1, 1, [e.p5]);
// NOTE: [e.p5, e.d2]) should be returned if we did not stop
// at e.p5, which fully encloses the target rect.
check(153,193,0, 20, 0, 20, [e.p5]);
check(153,193,20, 0, 20, 0, [e.p5, e.body]);
check(133, 193, 41, 1, [e.p5]);
check(153, 173, 1, 41, [e.p5, e.body]);

check(77, 240, 0, 0, 0, 0, [e.p2]);
check(77, 240, 1, 0, 0, 0, [e.p5, e.p2]);
check(77, 240, 0, 0, 1, 0, [e.span, e.p2]);
check(77, 240, 1, 0, 1, 0, [e.p5, e.span, e.p2]);
check(77, 240, 1, 1, [e.p2]);
check(77, 239, 1, 2, [e.p5, e.p2]);
check(77, 240, 1, 2, [e.span, e.p2]);
check(77, 239, 1, 3, [e.p5, e.span, e.p2]);

// Precise pixel checks:
check(144, 183, 0, 0, 0, 0, [e.body]);
check(144, 183, 1, 0, 1, 0, [e.p5, e.body]);
check(144, 183, 0, 1, 0, 1, [e.d2, e.body]);
check(144, 183, 0, 0, 1, 0, [e.p5, e.body]);
check(144, 183, 0, 0, 0, 1, [e.d2, e.body]);
check(144, 183, 0, 0, 1, 1, [e.p5, e.d2, e.body]);
check(144, 183, 1, 1, 1, 1, [e.p5, e.d2, e.body]);
check(77, 240, 0, 0, 0, 0, [e.p2]);
check(77, 240, 0, 1, 0, 1, [e.p2]);
check(77, 240, 1, 0, 0, 0, [e.p5, e.p2]);
check(77, 240, 0, 0, 1, 0, [e.span, e.p2]);
check(77, 240, 1, 0, 1, 0, [e.p5, e.span, e.p2]);
check(77, 240, 1, 1, 1, 1, [e.p5, e.span, e.p2]);
check(144, 183, 1, 1, [e.body]);
check(144, 182, 1, 3, [e.p5, e.body]);
check(143, 183, 3, 1, [e.d2, e.body]);
check(144, 183, 1, 2, [e.p5, e.body]);
check(143, 183, 2, 1, [e.d2, e.body]);
check(143, 183, 2, 2, [e.p5, e.d2, e.body]);
check(143, 182, 3, 3, [e.p5, e.d2, e.body]);
check(77, 240, 1, 1, [e.p2]);
check(76, 240, 3, 1, [e.p2]);
check(77, 239, 1, 2, [e.p5, e.p2]);
check(77, 240, 1, 2, [e.span, e.p2]);
check(77, 239, 1, 3, [e.p5, e.span, e.p2]);
check(76, 239, 3, 3, [e.p5, e.span, e.p2]);

// Expanding area checks:
check(39, 212, 0, 0, 0, 0, [e.body]);
check(39, 212, 10, 0, 0, 0, [e.d2, e.body]);
check(39, 212, 0, 0, 10, 0, [e.p2, e.body]);
check(39, 212, 10, 1, 30, 0, [e.d2, e.p2, e.body]);
check(39, 212, 10, 5, 30, 0, [e.span, e.d2, e.p2, e.body]);
check(39, 212, 10, 15, 30, 0, [e.p5, e.span, e.d2, e.p2, e.body]);
check(39, 212, 10, 0, 10, 0, [e.d2, e.p2, e.body]);
check(39, 212, 0, 10, 0, 10, [e.p5, e.body]);
check(39, 212, 10, 10, 10, 10, [e.p5, e.d2, e.p2, e.body]);
check(39, 212, 1, 1, [e.body]);
check(39, 202, 1, 11, [e.d2, e.body]);
check(39, 212, 1, 11, [e.p2, e.body]);
check(39, 202, 2, 41, [e.d2, e.p2, e.body]);
check(39, 202, 6, 41, [e.span, e.d2, e.p2, e.body]);
check(39, 202, 16, 41, [e.p5, e.span, e.d2, e.p2, e.body]);
check(39, 202, 1, 21, [e.d2, e.p2, e.body]);
check(29, 212, 21, 1, [e.p5, e.body]);
check(29, 202, 21, 21, [e.p5, e.d2, e.p2, e.body]);
}
window.onload = runTest;
</script>
Expand Down Expand Up @@ -100,4 +100,3 @@ <h1 id="h1"></h1>
<span id="console"></span>
</body>
</html>

Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
var iframe1Center = getCenterFor(e.iframe1);

// Elements inside iframe shouldn't be returned:
check(iframe1Center.x, iframe1Center.y, 0, 0, 0, 0, [e.iframe1]);
check(iframe1Center.x, iframe1Center.y, 10, 10, 10, 10, [e.iframe1]);
check(iframe1Center.x, iframe1Center.y, 1, 1, [e.iframe1]);
check(iframe1Center.x - 10, iframe1Center.y - 10, 21, 21, [e.iframe1]);

// NOTE: e.body.childNodes[2] is a TextNode whose content is ' '.
check(a1Center.x, a1Center.y, 0, e.iframe1.getBoundingClientRect().left - a1Center.x, 0, 0, [e.iframe1, e.body.childNodes[2], e.a1.firstChild, e.a1, e.body]);
check(a1Center.x, a1Center.y, e.iframe1.getBoundingClientRect().left - a1Center.x + 1, 1, [e.iframe1, e.body.childNodes[2], e.a1.firstChild, e.a1, e.body]);

// Testing nodesFromRect in an inner node.
var innerDocument = window.frames[0].document;
Expand All @@ -36,9 +36,9 @@
var divCenter = getCenterFor(div);
var divBottom = getBottomFor(div);
var pCenter = getCenterFor(p);
check(divCenter.x, divCenter.y, 0, 0, 0, 0, [div], innerDocument);
check(divCenter.x, divCenter.y, 0, 0, divBottom.y - divCenter.y, 0, [div, body], innerDocument);
check(divCenter.x, divCenter.y, 0, 0, pCenter.y - divCenter.y, 0, [p, div, body], innerDocument);
check(divCenter.x, divCenter.y, 1, 1, [div], innerDocument);
check(divCenter.x, divCenter.y, 1, divBottom.y - divCenter.y + 1, [div, body], innerDocument);
check(divCenter.x, divCenter.y, 1, pCenter.y - divCenter.y + 1, [p, div, body], innerDocument);
}
window.onload = runTest;
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
var topA1 = getTopFor(e.a1);
var centerText = { x : (centerA2.x + centerA1.x) / 2, y : centerA1.y }; //text node between a1 and a2

check(centerA1.x, centerA1.y, 0, 0, 0, 0, [e.a1.firstChild]);
check(centerA1.x, centerA1.y, topA1.y - topP1.y, 0, 0, 0, [e.a1.firstChild, e.a1, e.p1]);
check(centerA1.x, centerA1.y, 1, 1, [e.a1.firstChild]);
check(centerA1.x, centerA1.y - topA1.y + topP1.y, 1, topA1.y - topP1.y + 1, [e.a1.firstChild, e.a1, e.p1]);

check(centerA1.x, centerA1.y, 0, 0, centerA3.y - centerA1.y, 0, [e.a3.firstChild, e.a3, e.p1, e.a1.firstChild, e.a1]);
check(centerA1.x, centerA1.y, 0, centerText.x - centerA1.x, 0, 0, [e.p1.childNodes[2], e.a1.firstChild, e.a1, e.p1]);
check(centerA1.x, centerA1.y, 0, centerA2.x - centerA1.x, 0, 0, [e.a2.firstChild, e.a2, e.p1.childNodes[2], e.a1.firstChild, e.a1, e.p1]);
check(centerA1.x, centerA1.y, 0, centerA2.x - centerA1.x, centerA3.y - centerA1.y, 0, [e.a3.firstChild, e.a3, e.p1, e.a2.firstChild, e.a2, e.p1.childNodes[2], e.a1.firstChild, e.a1]);
check(centerA1.x, centerA1.y, 1, centerA3.y - centerA1.y + 1, [e.a3.firstChild, e.a3, e.p1, e.a1.firstChild, e.a1]);
check(centerA1.x, centerA1.y, centerText.x - centerA1.x + 1, 1, [e.p1.childNodes[2], e.a1.firstChild, e.a1, e.p1]);
check(centerA1.x, centerA1.y, centerA2.x - centerA1.x + 1, 1, [e.a2.firstChild, e.a2, e.p1.childNodes[2], e.a1.firstChild, e.a1, e.p1]);
check(centerA1.x, centerA1.y, centerA2.x - centerA1.x + 1, centerA3.y - centerA1.y + 1, [e.a3.firstChild, e.a3, e.p1, e.a2.firstChild, e.a2, e.p1.childNodes[2], e.a1.firstChild, e.a1]);

}
window.onload = runTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,52 +52,52 @@

window.scrollTo(0, 0);
debug('Check unrotated area-testing for sanity');
check(150, 150, 30, 30, 30, 30, [e.sandbox]);
check(220, 220, 10, 10, 10, 10, [e.fleft]);
check(470, 220, 10, 10, 10, 10, [e.fright]);
check(270, 220, 10, 10, 10, 10, [e.box1]);
check(270, 320, 10, 10, 10, 10, [e.box2]);
check(240, 290, 30, 30, 30, 30, [e.fleft, e.box2, e.box1, e.layer]);
check(180, 220, 10, 30, 10, 0, [e.fleft, e.layer, e.sandbox]);
check(270, 280, 0, 10, 30, 10, [e.box2, e.box1, e.layer]);
check(180, 220, 10, 0, 10, 30, [e.sandbox]);
check(120, 120, 61, 61, [e.sandbox]);
check(210, 210, 21, 21, [e.fleft]);
check(460, 210, 21, 21, [e.fright]);
check(260, 210, 21, 21, [e.box1]);
check(260, 310, 21, 21, [e.box2]);
check(210, 260, 61, 61, [e.fleft, e.box2, e.box1, e.layer]);
check(180, 210, 31, 21, [e.fleft, e.layer, e.sandbox]);
check(260, 280, 21, 31, [e.box2, e.box1, e.layer]);
check(150, 210, 31, 21, [e.sandbox]);


debug('Check rotated 180deg');
e['layer'].setAttribute('class', 'rotate180');
check(150, 150, 30, 30, 30, 30, [e.sandbox]);
check(220, 220, 10, 10, 10, 10, [e.fright]);
check(470, 220, 10, 10, 10, 10, [e.fleft]);
check(270, 220, 10, 10, 10, 10, [e.box3]);
check(270, 320, 10, 10, 10, 10, [e.box2]);
check(240, 290, 30, 30, 30, 30, [e.fright, e.box3, e.box2, e.layer]);
check(180, 220, 10, 30, 10, 0, [e.fright, e.layer, e.sandbox]);
check(270, 280, 0, 10, 30, 10, [e.box3, e.box2, e.layer]);
check(180, 220, 10, 0, 10, 30, [e.sandbox]);
check(120, 120, 61, 61, [e.sandbox]);
check(210, 210, 21, 21, [e.fright]);
check(460, 210, 21, 21, [e.fleft]);
check(260, 210, 21, 21, [e.box3]);
check(260, 310, 21, 21, [e.box2]);
check(210, 260, 61, 61, [e.fright, e.box3, e.box2, e.layer]);
check(180, 210, 31, 21, [e.fright, e.layer, e.sandbox]);
check(260, 280, 21, 31, [e.box3, e.box2, e.layer]);
check(150, 210, 31, 21, [e.sandbox]);

debug('Check rotated 90deg');
e['layer'].setAttribute('class', 'rotate90');
check(150, 150, 30, 30, 30, 30, [e.sandbox]);
check(220, 280, 10, 10, 10, 10, [e.box3]);
check(470, 280, 10, 10, 10, 10, [e.box1]);
check(270, 220, 10, 10, 10, 10, [e.fleft]);
check(270, 470, 10, 10, 10, 10, [e.fright]);
check(290, 240, 30, 30, 30, 30, [e.fleft, e.box3, e.box2, e.layer]);
check(180, 280, 10, 30, 10, 0, [e.box3, e.layer, e.sandbox]);
check(330, 180, 0, 10, 30, 10, [e.fleft, e.layer, e.sandbox]);
check(280, 260, 40, 10, 10, 10, [e.fleft, e.box3, e.layer]);
check(120, 120, 61, 61, [e.sandbox]);
check(210, 270, 21, 21, [e.box3]);
check(460, 270, 21, 21, [e.box1]);
check(260, 210, 21, 21, [e.fleft]);
check(260, 460, 21, 21, [e.fright]);
check(260, 210, 61, 61, [e.fleft, e.box3, e.box2, e.layer]);
check(180, 270, 31, 21, [e.box3, e.layer, e.sandbox]);
check(320, 180, 21, 31, [e.fleft, e.layer, e.sandbox]);
check(270, 220, 21, 51, [e.fleft, e.box3, e.layer]);

debug('Check rotated 45deg');
e['layer'].setAttribute('class', 'rotate45');
check(150, 150, 30, 30, 30, 30, [e.sandbox]);
check(260, 260, 10, 10, 10, 10, [e.fleft]);
check(440, 440, 10, 10, 10, 10, [e.fright]);
check(440, 260, 10, 10, 10, 10, [e.box1]);
check(260, 440, 10, 10, 10, 10, [e.box3]);
check(350, 140, 20, 20, 20, 20, [e.fleft, e.layer, e.sandbox]);
check(350, 140, 20, 20, 70, 20, [e.fleft, e.box1, e.layer, e.sandbox]);
check(350, 350, 40, 40, 40, 40, [e.box3, e.box2, e.box1, e.layer]);
check(260, 260, 1, 27, 1, 27, [e.fleft]);
check(120, 120, 61, 61, [e.sandbox]);
check(250, 250, 21, 21, [e.fleft]);
check(430, 430, 21, 21, [e.fright]);
check(430, 250, 21, 21, [e.box1]);
check(250, 430, 21, 21, [e.box3]);
check(330, 120, 41, 41, [e.fleft, e.layer, e.sandbox]);
check(330, 120, 41, 91, [e.fleft, e.box1, e.layer, e.sandbox]);
check(310, 310, 81, 81, [e.box3, e.box2, e.box1, e.layer]);
check(233, 259, 55, 3, [e.fleft]);

}

Expand All @@ -108,4 +108,3 @@
<span id="console"></span>
</body>
</html>

Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,38 @@

window.scrollTo(0, 0);
debug('Check unscaled area-testing for sanity');
check(150, 150, 30, 30, 30, 30, [e.sandbox]);
check(220, 220, 10, 10, 10, 10, [e.fleft]);
check(370, 220, 10, 10, 10, 10, [e.fright]);
check(270, 220, 10, 10, 10, 10, [e.box1]);
check(270, 320, 10, 10, 10, 10, [e.box2]);
check(240, 290, 30, 30, 30, 30, [e.fleft, e.box2, e.box1, e.layer]);
check(180, 220, 10, 30, 10, 0, [e.fleft, e.layer, e.sandbox]);
check(270, 280, 0, 10, 30, 10, [e.box2, e.box1, e.layer]);
check(180, 220, 10, 0, 10, 30, [e.sandbox]);
check(120, 120, 61, 61, [e.sandbox]);
check(210, 210, 21, 21, [e.fleft]);
check(360, 210, 21, 21, [e.fright]);
check(260, 210, 21, 21, [e.box1]);
check(260, 310, 21, 21, [e.box2]);
check(210, 260, 61, 61, [e.fleft, e.box2, e.box1, e.layer]);
check(180, 210, 31, 21, [e.fleft, e.layer, e.sandbox]);
check(260, 280, 21, 31, [e.box2, e.box1, e.layer]);
check(150, 210, 31, 21, [e.sandbox]);

debug('Check scaling 2X');
e['layer'].setAttribute('class', 'scaleup');
check(150, 150, 30, 30, 30, 30, [e.fleft]);
check(450, 150, 30, 30, 30, 30, [e.fright]);
check(350, 220, 10, 10, 10, 10, [e.box1]);
check(350, 420, 10, 10, 10, 10, [e.box2]);
check(180, 280, 60, 60, 60, 60, [e.fleft, e.box2, e.box1, e.layer]);
check(60, 140, 20, 60, 20, 0, [e.fleft, e.layer, e.sandbox]);
check(240, 260, 0, 20, 60, 20, [e.box2, e.box1, e.layer]);
check(60, 140, 20, 0, 20, 60, [e.sandbox]);
check(120, 120, 61, 61, [e.fleft]);
check(420, 120, 61, 61, [e.fright]);
check(340, 210, 21, 21, [e.box1]);
check(340, 410, 21, 21, [e.box2]);
check(120, 220, 121, 121, [e.fleft, e.box2, e.box1, e.layer]);
check(60, 120, 61, 41, [e.fleft, e.layer, e.sandbox]);
check(220, 260, 41, 61, [e.box2, e.box1, e.layer]);
check(0, 120, 61, 41, [e.sandbox]);

debug('Check scaling 0.5X');
e['layer'].setAttribute('class', 'scaledown');
check(225, 225, 15, 15, 15, 15, [e.sandbox]);
check(260, 260, 5, 5, 5, 5, [e.fleft]);
check(335, 260, 5, 5, 5, 5, [e.fright]);
check(285, 260, 5, 5, 5, 5, [e.box1]);
check(285, 310, 5, 5, 5, 5, [e.box2]);
check(270, 295, 15, 15, 15, 15, [e.fleft, e.box2, e.box1, e.layer]);
check(240, 260, 5, 15, 5, 0, [e.fleft, e.layer, e.sandbox]);
check(285, 290, 0, 5, 15, 5, [e.box2, e.box1, e.layer]);
check(240, 260, 5, 0, 5, 15, [e.sandbox]);
check(210, 210, 31, 31, [e.sandbox]);
check(255, 255, 11, 11, [e.fleft]);
check(330, 255, 11, 11, [e.fright]);
check(280, 255, 11, 11, [e.box1]);
check(280, 305, 11, 11, [e.box2]);
check(255, 280, 31, 31, [e.fleft, e.box2, e.box1, e.layer]);
check(240, 255, 16, 11, [e.fleft, e.layer, e.sandbox]);
check(280, 290, 11, 16, [e.box2, e.box1, e.layer]);
check(225, 255, 16, 11, [e.sandbox]);

}

Expand All @@ -92,4 +92,3 @@
<span id="console"></span>
</body>
</html>

Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@
debug('hit tests are supported inside SVG elements:\n');

debug('Check area hits fully inside SVG element');
check(20, 20, 4, 4, 4, 4, [e.red, e.svg1]);
check(20, 52, 4, 4, 4, 4, [e.yellow, e.svg2]);
check(18, 80, 4, 4, 4, 4, [e.green, e.svg3]);
check(14, 14, 2, 2, 2, 2, [e.svg1]);
check(20, 20, 9, 9, 9, 9, [e.red, e.svg1, e.div1]);
check(16, 16, 9, 9, [e.red, e.svg1]);
check(16, 48, 9, 9, [e.yellow, e.svg2]);
check(14, 76, 9, 9, [e.green, e.svg3]);
check(12, 12, 5, 5, [e.svg1]);
check(11, 11, 19, 19, [e.red, e.svg1, e.div1]);

debug('Check area hits overlapping SVG element');
check(12, 12, 2, 2, 2, 2, [e.svg1, e.div1]);
check(6, 50, 5, 20, 5, 5, [e.svg2, e.div2, e.sandbox]);
check(10, 10, 5, 5, [e.svg1, e.div1]);
check(1, 45, 26, 11, [e.svg2, e.div2, e.sandbox]);

debug('Check area hits across SVG elements');
check(20, 30, 20, 10, 30, 10, [e.svg2, e.div2, e.svg1, e.div1, e.sandbox]);
check(10, 10, 21, 51, [e.svg2, e.div2, e.svg1, e.div1, e.sandbox]);

debug('');
}
Expand All @@ -83,4 +83,3 @@
<span id="console"></span>
</body>
</html>

Loading

0 comments on commit 69f57e1

Please sign in to comment.