Skip to content

Conversation

@andreastt
Copy link
Member

Quoting the commit message of the last patch:

Calculating the centre point of a square may produce a decimal
precision number. Given a 1x1 px square the center point will be
(0.5,0.5), but the DOM operates in integer CSS pixels.

Rounding the number would get us the closest positive integer, or 1.
However, the coordinate (1,1) is beyond the bounding box of the
square.

This means we need to floor the number to ensure we always get a
click point that is within the client rect of the element.

An additional complexity is that not all web platform APIs treat
floating point numbers the same way. DOMElement.elementsFromPoint,
which we use for getting the paint tree to determine if the web
element is interactable, will floor the number which deems the
element interactable. However, in Gecko, nsIDOMUtils.sendMouseEvent
ceils the number, causing the actual click point to fall beyond the
square.

Tests will be provided as part of https://bugzilla.mozilla.org/show_bug.cgi?id=1499360, which implements this in geckodriver.

The outer groups are a distraction.
It's misleading to use multiplication by 0.5 since you wouldn't
implement the in-view center point like this.  Instead divide by
2.0, which makes it clear that we expect the result to be a floating
point.
Calculating the centre point of a square may produce a decimal
precision number.  Given a 1x1 px square the center point will be
(0.5,0.5), but the DOM operates in integer CSS pixels.

Rounding the number would get us the closest positive integer, or
1.  However, the coordinate (1,1) is beyond the bounding box of the
square.

This means we need to floor the number to ensure we always get a
click point that is within the client rect of the element.

An additional complexity is that not all web platform APIs treat
floating point numbers the same way.  DOMElement.elementsFromPoint,
which we use for getting the paint tree to determine if the web
element is interactable, will floor the number which deems the
element interactable.  However, in Gecko, nsIDOMUtils.sendMouseEvent
ceils the number, causing the actual click point to fall beyond the
square.
@andreastt andreastt changed the title Center point rounding Make in-view center point CSS pixel aware Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants