Skip to content

[cssom-view] Specify subpixel hit testing for Document.elementFromPoint() etc. #4955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xiaochengh opened this issue Apr 15, 2020 · 0 comments

Comments

@xiaochengh
Copy link
Contributor

xiaochengh commented Apr 15, 2020

There seem to be at least two different models for hit testing at (x, y):

  1. Treat the hit test location as a pixel, namely, a 1x1 rectangle with top-left corner at (x, y), and then return elements whose boxes have non-zero intersection with the pixel
  2. Treat the hit test location as a zero-sized point at (x, y), and return elements whose boxes contain the point. Note that boxes are considered as left-closed-right-open and top-closed-bottom-open; In other words, a point on the bottom or right edge of a box doesn't hit the box.

The two models have different behaviors when taking subpixels into account. See fiddle https://jsfiddle.net/bgec7tzo/4/, where the behavior in Chrome is different from Firefox/Safari. Chrome uses model 1, while Firefox and Safari seem closer to model 2.

Also note that in some other cases Safari and Firefox behave differently.

So I think we should make it clear how hit testing works with subpixels.

Btw, neither of the models seems fully natural to me:

  • In model 1, using a 1x1 pixel coordinated at a non-integer location seems weird
  • In model 2, the left-closed-right-open requirement seems artificial, but all browsers follow it so I guess we can't really remove it; This requirement also creates some difficulties when we need to flip the coordinate space for direction and writing-mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants