Skip to content

Commit

Permalink
Convert element coordinates to document origin
Browse files Browse the repository at this point in the history
The spec is supposed to normalise everything to document coordinates
for computing intersections. However element bounding boxes turn out
to be in viewport coordinates, so we need to uncinditionally convert
these before using them.
  • Loading branch information
jgraham committed Nov 2, 2023
1 parent 44aa704 commit 60d5f31
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2436,7 +2436,7 @@ To <dfn>encode a canvas as Base64</dfn> given |canvas| and |format|:
1. Otherwise, let |type| be "image/png" and let |quality| be [=undefined=].

1. Let |file| be [=a serialization of the bitmap as a file=] for |canvas| with
|type| and |quality|.
|type| and |quality|.

1. Let |encoded string| be the [=forgiving-base64 encode=] of |file|.

Expand Down Expand Up @@ -2519,7 +2519,16 @@ The [=remote end steps=] with <var ignore>session</var> and |command parameters|
1. If |element|'s [=node document=] is not |document|, return [=error=] with
[=error code=] [=no such element=].

1. Let |clip rect| be [=get the bounding box=] for |element|.
1. Let |viewport rect| be [=get the origin rectangle=] given
"<code>viewport</code>" and "<code>document</code>".

1. Let |element rect| be [=get the bounding box=] for |element|.

1. Let |clip rect| be a {{DOMRectReadOnly}} with [=x coordinate=]
|element rect|["<code>x</code>"] + |viewport rect|["<code>x</code>"]|,
[=y coordinate=] |element rect|["<code>y</code>"] + |viewport
rect|["<code>y</code>"], width |element rect|["<code>width</code>"],
and height |element rect|["<code>height</code>"].

<dt>|clip| matches the <code>browsingContext.BoxClipRectangle</code> production:
<dd>
Expand All @@ -2530,10 +2539,12 @@ The [=remote end steps=] with <var ignore>session</var> and |command parameters|
coordinate=].

1. Let |clip rect| be a {{DOMRectReadOnly}} with [=x coordinate=] |clip x|,
|clip y|, width |clip|["<code>width</code>"], and height
[=y coordinate=] |clip y|, width |clip|["<code>width</code>"], and height
|clip|["<code>height</code>"].
</dl>

1. Note: All coordiantes are now measured from the origin of the document.

1. Let |rect| be the [=rectangle intersection=] of |origin rect| and |clip rect|.

1. If |rect|'s [=width dimension=] is 0 or |rect|'s [=height dimension=] is 0,
Expand Down

0 comments on commit 60d5f31

Please sign in to comment.