Skip to content

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

Open
@xiaochengh

Description

@xiaochengh

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions