Skip to content

Commit

Permalink
Make ShadowRoot.elementsFromPoint always return document element
Browse files Browse the repository at this point in the history
Currently in some cases, ShadowRoot.elementsFromPoint may not return
the document element even when Document.elementsFromPoint returns the
document element such as when the document element height is shorter than
the hit-tested element's position. This CL fixes it by removing a check
in TreeScope::ElementsFromHitTestResult.

See example live case detailed in this comment:
https://bugs.chromium.org/p/chromium/issues/detail?id=843215#c16

Bug: 843215
Change-Id: I5b774d1a091f3c3f72345c55bca188fad309ba58
Reviewed-on: https://chromium-review.googlesource.com/1131023
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: Hayato Ito <hayato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574104}
  • Loading branch information
rakina authored and chromium-wpt-export-bot committed Jul 11, 2018
1 parent dce8e95 commit 7464bf6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions shadow-dom/DocumentOrShadowRoot-prototype-elementFromPoint.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@

const displayValues = ['inline', 'block', 'inline-block'];
var container = document.getElementById('container');
customElements.define('test-element', class extends HTMLElement {
constructor() {
super();
}
});

displayValues.forEach(function (displayValue) {
test(function () {
Expand Down Expand Up @@ -228,6 +233,21 @@
}, 'document.elementsFromPoint must return the shadow host and its ancestors and shadowRoot.elementsFromPoint must return the slot parent of the fallback text and its non-shadow ancestors when the hit-tested text node is a fallback content and the host has display: ' + displayValue);
});

test(function () {
container.innerHTML = '';
let host = document.createElement('test-element');
host.style.display = 'block';
let shadow = host.attachShadow({mode: 'closed'});
shadow.innerHTML = '<div style="margin: 2px;">not hit</div>';
let aboveHost = document.createElement("div");
aboveHost.appendChild(host);
container.appendChild(aboveHost);
document.documentElement.style = 'background-attachment: scroll; height: 2px;';
let boundingRect = host.getBoundingClientRect();
assert_array_equals(document.elementsFromPoint(boundingRect.x, boundingRect.y), [host, aboveHost, container, document.body, document.documentElement]);
assert_array_equals(shadow.elementsFromPoint(boundingRect.x, boundingRect.y), [host, aboveHost, container, document.body, document.documentElement]);
}, 'shadowRoot.elementsFromPoint must behave the same with document.elementsFromPoint regarding HTML element');

container.innerHTML = '';

</script>
Expand Down

0 comments on commit 7464bf6

Please sign in to comment.