Skip to content
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

[css-highlight-api-1] Add highlightsFromPoint() to CSS.highlights #7513 #11507

Merged
merged 3 commits into from
Jan 25, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion css-highlight-api-1/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ Registering Custom Highlights</h3>
};

[Exposed=Window]
interface HighlightRegistry {
partial interface HighlightRegistry {
maplike<DOMString, Highlight>;
};
</xmp>
Expand Down Expand Up @@ -579,6 +579,42 @@ Range Updating and Invalidation</h3>
is not <a spec=dom for="StaticRange">valid</a>,
the user agent must ignore that [=range=].

<h2 id="interactions">
Interacting with Custom Highlights</h2>

User interaction with [=custom highlights=] can be done via the
ffiori marked this conversation as resolved.
Show resolved Hide resolved
{{highlightsFromPoint}}(<var>x</var>, <var>y</var>, <var>options</var>) method.
ffiori marked this conversation as resolved.
Show resolved Hide resolved

<pre class=idl>
partial interface HighlightRegistry {
sequence&lt;Highlight> highlightsFromPoint(float x, float y, optional <span>HighlightsFromPointOptions</span> options = {});
};

dictionary <dfn dictionary>HighlightsFromPointOptions</dfn> {
sequence&lt;ShadowRoot> <dfn dict-member for="HighlightsFromPointOptions">shadowRoots</dfn> = [];
};
</pre>

The <dfn method for="HighlightRegistry">highlightsFromPoint(<var>x</var>, <var>y</var>, <var>options</var>)</dfn>
method must return the result of running these steps:

1. If there is no <a>viewport</a> associated with the document, return the empty sequence.
ffiori marked this conversation as resolved.
Show resolved Hide resolved
1. If either argument is negative, <var>x</var> is greater
ffiori marked this conversation as resolved.
Show resolved Hide resolved
than the <a>viewport</a> width excluding the size of a rendered
scroll bar (if any), or <var>y</var> is greater than the
<a>viewport</a> height excluding the size of a rendered scroll bar
(if any), return the empty sequence.
1. Otherwise, return a sequence of custom higlights ordered by [=priority=],
ffiori marked this conversation as resolved.
Show resolved Hide resolved
where each highlight contains at least one range that satisfies the following constraints:
ffiori marked this conversation as resolved.
Show resolved Hide resolved
ffiori marked this conversation as resolved.
Show resolved Hide resolved
1. The coordinates <var>x</var>,<var>y</var> fall inside at least one of the rectangles returned by calling getClientRects() on it.
ffiori marked this conversation as resolved.
Show resolved Hide resolved
1. The range's {{commonAncestorContainer}} is not in a shadow DOM, or is one of the shadow roots passed in <var>options</var> or a
ffiori marked this conversation as resolved.
Show resolved Hide resolved
descendant of one of them.

Note: The specifics of hit testing are out of scope of this
ffiori marked this conversation as resolved.
Show resolved Hide resolved
specification and therefore the exact details of
{{highlightsFromPoint()}} are therefore too. Hit testing
will hopefully be defined in a future revision of CSS or HTML.

<h2 id=events>
Event Handling</h2>

Expand Down Expand Up @@ -629,6 +665,9 @@ Changes since the <a href="https://www.w3.org/TR/2020/WD-css-highlight-api-1-202
In addition to various editorial improvements and minor tweaks,
the main changes are:

* Added a {{HighlightRegistry/highlightsFromPoint}} method to
{{HighlightRegistry}}.
(See <a href="https://github.com/w3c/csswg-drafts/pull/7513">Issue 7513</a>)
* Specified that highlight repainting has to be done asynchronously.
(See <a href="https://github.com/w3c/csswg-drafts/pull/6987">Issue 6987</a>)
* Clarify that UAs cannot specify paired default highlight colors for custom highlights.
Expand Down