Re: [cssom-view] elementFromPoint vagueness and "hit testing"

On Aug 17, 2010, at 1:22 PM, David Flanagan wrote:

> The elementFromPoint() method is specified to return an element "at the coordinates x,y .... determined through hit testing".  The specification (and even the definition) of "hit testing" is pushed off to a future version of CSS or HTML.  If I'm reading this correctly, an implementation that always returned document.documentElement would be conforming.
> 
> Can we be a little more specific than this?  For example, is it appropriate to add something like this to the Note about hit testing: "Until hit testing is formally defined, implementors are encouraged to select the topmost, innermost element at the point x,y."
> 
> That is the intent, isn't it?  I assume that the hit-testing algorithm would be something like this (off the top of my head):
> 
> 1) Make a list of all elements whose border edges include the point x,y.
> 
> 2) Find the maximum z-index among those elements, and discard all elements in the list with a smaller z-index.
> 
> 3) If only one element remains, return it.
> 
> 4) For each element in the list, discard any ancestors of that element that are on the list.
> 
> 5) If only one element remains, return it.
> 
> 6) Return the element that appears last in document order.

Hit testing behaves like painting in reverse, so perhaps it could be defined more simply in terms of rendering.

Simon

Received on Tuesday, 17 August 2010 20:42:07 UTC