Skip to content

Commit

Permalink
Add HTMLImageElement.isTypeSupported()
Browse files Browse the repository at this point in the history
Give web developers a means to determine which formats are supported by the img element.

Fixes #6324.
  • Loading branch information
annevk committed Jan 12, 2024
1 parent 1b64254 commit 7f6b6bb
Showing 1 changed file with 53 additions and 7 deletions.
60 changes: 53 additions & 7 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -28840,6 +28840,8 @@ interface <dfn interface>HTMLSourceElement</dfn> : <span>HTMLElement</span> {
interface <dfn interface>HTMLImageElement</dfn> : <span>HTMLElement</span> {
[<span>HTMLConstructor</span>] constructor();

static Promise&lt;boolean&gt; <span data-x="dom-img-isTypeSupported()">isTypeSupported</span>(DOMString <var>mimeType</var>);

[<span>CEReactions</span>] attribute DOMString <span data-x="dom-img-alt">alt</span>;
[<span>CEReactions</span>] attribute USVString <span data-x="dom-img-src">src</span>;
[<span>CEReactions</span>] attribute USVString <span data-x="dom-img-srcset">srcset</span>;
Expand Down Expand Up @@ -29217,9 +29219,17 @@ interface <dfn interface>HTMLImageElement</dfn> : <span>HTMLElement</span> {
</div>

<dl class="domintro">
<dt><code data-x=""><var>supported</var> = await <span>HTMLImageElement</span>.<span subdfn data-x="dom-img-isTypeSupported">isTypeSupported</span>(<var>mimeType</var>)</code></dt>
<dd>
<p>Returns a promise resolved with true, if <var>mimeType</var> is supported for the
<code>img</code> element by the user agent; otherwise false.</p>

<p>The promise will be rejected with a <code>TypeError</code> if <var>mimeType</var> cannot be
parsed.</p>
</dd>

<dt><code data-x=""><var>image</var>.<span subdfn data-x="dom-img-width">width</span> [ = <var>value</var> ]</code></dt>
<dt><code data-x=""><var>image</var>.<span subdfn data-x="dom-img-height">height</span> [ = <var>value</var> ]</code></dt>

<dd>
<p>These attributes return the actual rendered dimensions of the image, or 0 if the dimensions
are not known.</p>
Expand All @@ -29229,25 +29239,21 @@ interface <dfn interface>HTMLImageElement</dfn> : <span>HTMLElement</span> {

<dt><code data-x=""><var>image</var>.<span subdfn data-x="dom-img-naturalWidth">naturalWidth</span></code></dt>
<dt><code data-x=""><var>image</var>.<span subdfn data-x="dom-img-naturalHeight">naturalHeight</span></code></dt>

<dd>
<p>These attributes return the natural dimensions of the image, or 0 if the dimensions are not
known.</p>
</dd>

<dt><code data-x=""><var>image</var>.<span subdfn data-x="dom-img-complete">complete</span></code></dt>

<dd>
<p>Returns true if the image has been completely downloaded or if no image is specified;
otherwise, returns false.</p>
</dd>

<dt><code data-x=""><var>image</var>.<span subdfn data-x="dom-img-currentSrc">currentSrc</span></code></dt>

<dd><p>Returns the image's <span>absolute URL</span>.</p></dd>

<dt><code data-x=""><var>image</var>.<span subdfn data-x="dom-img-decode">decode</span>()</code></dt>

<dd>
<p>This method causes the user agent to <span data-x="img-decoding-process">decode</span> the
image <span>in parallel</span>, returning a promise that fulfills when decoding is complete.</p>
Expand All @@ -29257,7 +29263,6 @@ interface <dfn interface>HTMLImageElement</dfn> : <span>HTMLElement</span> {
</dd>

<dt><code data-x=""><var>image</var> = new <span subdfn data-x="dom-image">Image</span>([ <var>width</var> [, <var>height</var> ] ])</code></dt>

<dd>
<p>Returns a new <code>img</code> element, with the <code data-x="attr-dim-width">width</code>
and <code data-x="attr-dim-height">height</code> attributes set to the values passed in the
Expand All @@ -29267,6 +29272,44 @@ interface <dfn interface>HTMLImageElement</dfn> : <span>HTMLElement</span> {

<div w-nodev>

<p>The static <dfn method for="HTMLImageElement"
data-x="dom-img-isTypeSupported"><code>isTypeSupported(<var>mimeType</var>)</code></dfn> method
steps are:</p>

<ol>
<li><p>Let <var>mimeTypeRecord</var> be the result of <span data-x="parse a MIME type">parsing a
MIME type</span> given <var>mimeType</var>.</p></li>

<li><p>If <var>mimeTypeRecord</var> is failure, then return <span>a promise rejected with</span>
a <code>TypeError</code>.</p></li>

<li><p>Let <var>promise</var> be a new promise.</p></li>

<li><p>Let <var>global</var> be the <span>current global object</span>.</p></li>

<li>
<p><span>In parallel</span>:</p>

<ol>
<li><p>Let <var>supported</var> be false.</p></li>

<li><p>If <var>mimeTypeRecord</var> is in the user agent's <span>supported image MIME
types</span> (and the user agent thus recognizes the <span data-x="MIME type
essence">essence</span> and all parameters (if any)), set <var>supported</var> to
true.</p></li>

<li><p><span>Queue a global task</span> on the <span>DOM manipulation task source</span> given
<var>global</var> to resolve <var>promise</var> with <var>supported</var>.</p></li>
</ol>
</li>

<li><p>Return <var>promise</var>.</p></li>
</ol>

<p class="note">This is modeled after <code data-x="">ImageDecoder.isTypeSupported()</code>, but
is its own method as user agents can support non-image formats through the <code>img</code>
element.</p>

<p>The IDL attributes <dfn attribute for="HTMLImageElement"
data-x="dom-img-width"><code>width</code></dfn> and <dfn attribute for="HTMLImageElement"
data-x="dom-img-height"><code>height</code></dfn> must return the rendered width and height of the
Expand Down Expand Up @@ -30488,7 +30531,9 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</code
of a multipage resource (e.g. a PDF file). User agents must not allow the resource to act in an
interactive fashion, but should honour any animation in the resource.</p>

<p>This specification does not specify which image types are to be supported.</p>
<p>A user agent has an associated <dfn>supported image MIME types</dfn> (a <span>set</span> of
<span data-x="MIME type">MIME types</span>). A user agent's <span>supported image MIME
types</span> is <span>implementation-defined</span>.</p>


<h6>When to obtain images</h6>
Expand Down Expand Up @@ -141942,6 +141987,7 @@ INSERT INTERFACES HERE
Matthew Gregan,
Matthew Mastracci,
Matthew Noorenberghe,
Matthew Petroff,
Matthew Raymond,
Matthew Thomas,
Matthew Tylee Atkinson, <!-- matatk on GitHub -->
Expand Down

0 comments on commit 7f6b6bb

Please sign in to comment.