Skip to content

Commit 12b4187

Browse files
authored
Be explicit about image request state
This also changes createImageBitmap() to use fully decodeable rather than completely available. Tests: web-platform-tests/wpt#8389. Fixes #3158.
1 parent 19f5cce commit 12b4187

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

source

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25794,9 +25794,11 @@ interface <dfn>HTMLImageElement</dfn> : <span>HTMLElement</span> {
2579425794
task">queued</span> by the <span>networking task source</span> once the resource has been fetched
2579525795
has been <span data-x="queue a task">queued</span>.
2579625796

25797-
<li>The <code>img</code> element is <span data-x="img-all">completely available</span>.
25797+
<li>The <code>img</code> element's <span>current request</span>'s <span
25798+
data-x="img-req-state">state</span> is <span data-x="img-all">completely available</span>.
2579825799

25799-
<li>The <code>img</code> element is <span data-x="img-error">broken</span>.
25800+
<li>The <code>img</code> element's <span>current request</span>'s <span
25801+
data-x="img-req-state">state</span> is <span data-x="img-error">broken</span>.
2580025802

2580125803
</ul>
2580225804

@@ -25862,7 +25864,8 @@ img.decode();</pre>
2586225864
<code>DOMException</code>.</p>
2586325865
</dd>
2586425866

25865-
<dt>This <code>img</code> element becomes <span data-x="img-all">completely
25867+
<dt>This <code>img</code> element's <span>current request</span>'s <span
25868+
data-x="img-req-state">state</span> becomes <span data-x="img-all">completely
2586625869
available</span></dt>
2586725870

2586825871
<dd>
@@ -26796,21 +26799,21 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2679626799

2679726800
<h5 id="images-processing-model">Processing model</h5>
2679826801

26799-
<p>The <span>task source</span> for the <span data-x="concept-task">tasks</span> <span data-x="queue
26800-
a task">queued</span> by algorithms in this section is the <span>DOM manipulation task
26801-
source</span>.</p>
26802+
<p>The <span>task source</span> for the <span data-x="concept-task">tasks</span> <span
26803+
data-x="queue a task">queued</span> by algorithms in this section is the <span>DOM manipulation
26804+
task source</span>.</p>
2680226805

2680326806
<hr>
2680426807

2680526808
<p>An <code>img</code> element has a <dfn>current request</dfn> and a <dfn>pending request</dfn>.
2680626809
The <span>current request</span> is initially set to a new <span>image request</span>.
26807-
The <span>pending request</span> is initially set to null.
26808-
The <span>current request</span> is usually referred to as the <code>img</code> element itself.</p>
26810+
The <span>pending request</span> is initially set to null.</p>
2680926811

2681026812
<p>An <dfn>image request</dfn> has a <dfn data-x="img-req-state">state</dfn>, <dfn
2681126813
data-x="img-req-url">current URL</dfn>, and <dfn data-x="img-req-data">image data</dfn>.</p>
2681226814

26813-
<p>An <span>image request</span>'s <span data-x="img-req-state">state</span> is one of the following:</p>
26815+
<p>An <span>image request</span>'s <span data-x="img-req-state">state</span> is one of the
26816+
following:</p>
2681426817

2681526818
<dl>
2681626819

@@ -26834,27 +26837,30 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2683426837

2683526838
</dl>
2683626839

26837-
<p>An <span>image request</span>'s <span data-x="img-req-url">current URL</span> is initially the empty string.</p>
26840+
<p>An <span>image request</span>'s <span data-x="img-req-url">current URL</span> is initially the
26841+
empty string.</p>
2683826842

26839-
<p>An <span>image request</span>'s <span data-x="img-req-data">image data</span> is the decoded image data.</p>
26843+
<p>An <span>image request</span>'s <span data-x="img-req-data">image data</span> is the decoded
26844+
image data.</p>
2684026845

2684126846
<p>When an <span>image request</span>'s <span data-x="img-req-state">state</span> is either <span
2684226847
data-x="img-inc">partially available</span> or <span data-x="img-all">completely available</span>,
2684326848
the <span>image request</span> is said to be <dfn data-x="img-available">available</dfn>.</p>
2684426849

26845-
<p>When an <code>img</code> element is in the <span data-x="img-all">completely available</span>
26846-
state <em>and</em> the user agent can decode the media data without errors, then the
26847-
<code>img</code> element is said to be <dfn data-x="img-good">fully decodable</dfn>.</p>
26848-
<!-- TODO: https://github.com/whatwg/html/issues/3158 (img element state) -->
26850+
<p>When an <code>img</code> element's <span>current request</span>'s <span
26851+
data-x="img-req-state">state</span> is <span data-x="img-all">completely available</span> and the
26852+
user agent can decode the media data without errors, then the <code>img</code> element is said to
26853+
be <dfn data-x="img-good">fully decodable</dfn>.</p>
2684926854

2685026855
<p>An <span>image request</span>'s <span data-x="img-req-state">state</span> is initially <span
2685126856
data-x="img-none">unavailable</span>.</p>
2685226857

26853-
<p>When an <code>img</code> element is <span data-x="img-available">available</span>,
26854-
it provides a <span>paint source</span>
26855-
whose width is the image's <span data-x="density-corrected intrinsic width and height">density-corrected intrinsic width</span> (if any),
26856-
whose height is the image's <span data-x="density-corrected intrinsic width and height">density-corrected intrinsic height</span> (if any),
26857-
and whose appearance is the intrinsic appearance of the image.</p>
26858+
<p>When an <code>img</code> element's <span>current request</span> is <span
26859+
data-x="img-available">available</span>, the <code>img</code> element provides a <span>paint
26860+
source</span> whose width is the image's <span data-x="density-corrected intrinsic width and
26861+
height">density-corrected intrinsic width</span> (if any), whose height is the image's <span
26862+
data-x="density-corrected intrinsic width and height">density-corrected intrinsic height</span>
26863+
(if any), and whose appearance is the intrinsic appearance of the image.</p>
2685826864

2685926865
<hr>
2686026866

@@ -26938,12 +26944,12 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2693826944
whenever that element is created or has experienced <span>relevant mutations</span>.</p>
2693926945

2694026946
<p>A user agent that obtains images on demand must <span>update the image data</span> of an
26941-
<code>img</code> element whenever it needs the image data (i.e. on demand),
26942-
but only if the <code>img</code> element is in the
26943-
<span data-x="img-none">unavailable</span> state. When an <code>img</code> element
26944-
has experienced <span>relevant mutations</span>, if the user
26945-
agent only obtains images on demand, the <code>img</code> element must return to the <span
26946-
data-x="img-none">unavailable</span> state.</p>
26947+
<code>img</code> element whenever it needs the image data (i.e., on demand), but only if the
26948+
<code>img</code> element's <span>current request</span>'s <span
26949+
data-x="img-req-state">state</span> is <span data-x="img-none">unavailable</span>. When an
26950+
<code>img</code> element has experienced <span>relevant mutations</span>, if the user agent only
26951+
obtains images on demand, the <code>img</code> element's <span>current request</span>'s <span
26952+
data-x="img-req-state">state</span> must return to <span data-x="img-none">unavailable</span>.</p>
2694726953

2694826954

2694926955
<h6>Reacting to DOM mutations</h6>
@@ -27314,11 +27320,12 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
2731427320
task">queued</span> by the <span>networking task source</span> while the image is being
2731527321
fetched must update the presentation of the image, but as each new body part comes in, it must
2731627322
replace the previous image. Once one body part has been completely decoded, the user agent
27317-
must set the <code>img</code> element to the <span data-x="img-all">completely
27318-
available</span> state and <span>queue a task</span> to <span data-x="concept-event-fire">fire
27319-
an event</span> named <code data-x="event-load">load</code> at the <code>img</code>
27320-
element.</p>
27321-
<!--TODO what if the image is broken? -->
27323+
must set the <code>img</code> element's <span>current request</span>'s <span
27324+
data-x="img-req-state">state</span> to <span data-x="img-all">completely available</span> and
27325+
<span>queue a task</span> to <span data-x="concept-event-fire">fire an event</span> named
27326+
<code data-x="event-load">load</code> at the <code>img</code> element.</p>
27327+
<!--TODO what if the image is broken?
27328+
TODO change state and fire in the same task? -->
2732227329

2732327330
<p class="note">The <code data-x="event-progress">progress</code> and <code
2732427331
data-x="event-loadend">loadend</code> events are not fired for
@@ -62230,9 +62237,10 @@ try {
6223062237

6223162238
<ol>
6223262239

62233-
<li><p>If <var>image</var> is an <code>HTMLOrSVGImageElement</code> object that is in the <span
62234-
data-x="img-error">broken</span> state, then throw an
62235-
<span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.</p></li>
62240+
<li><p>If <var>image</var> is an <code>HTMLOrSVGImageElement</code> object whose <span>current
62241+
request</span>'s <span data-x="img-req-state">state</span> is <span
62242+
data-x="img-error">broken</span>, then throw an <span>"<code>InvalidStateError</code>"</span>
62243+
<code>DOMException</code>.</p></li>
6223662244

6223762245
<li><p>If <var>image</var> is an <code>HTMLOrSVGImageElement</code> object that is not <span
6223862246
data-x="img-good">fully decodable</span>, or if <var>image</var> is an
@@ -92717,8 +92725,8 @@ dictionary <dfn>ImageBitmapOptions</dfn> {
9271792725
<li><p>If either the <var>sw</var> or <var>sh</var> arguments are specified but zero, return a
9271892726
promise rejected with a <code data-x="js-RangeError">RangeError</code>.</p></li>
9271992727

92720-
<li><p>If <var>image</var> is not <span data-x="img-all">completely available</span>, then
92721-
return a promise rejected with an <span>"<code>InvalidStateError</code>"</span>
92728+
<li><p>If <var>image</var> is not <span data-x="img-good">fully decodeable</span>, then return
92729+
a promise rejected with an <span>"<code>InvalidStateError</code>"</span>
9272292730
<code>DOMException</code>.</p></li>
9272392731

9272492732
<li><p>If <var>image</var>'s media data has no <span>intrinsic dimensions</span> (e.g. it's a

0 commit comments

Comments
 (0)