Skip to content

Commit 6061c4f

Browse files
committed
[css-typed-om] rework of images, added fonts.
1 parent 2c88580 commit 6061c4f

File tree

1 file changed

+69
-27
lines changed

1 file changed

+69
-27
lines changed

css-typed-om/Overview.bs

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -610,18 +610,51 @@ document.querySelector('.example').styleMap.get('background-position').y;
610610

611611
</div>
612612

613-
{{CSSImageValue}} objects {#image-objects}
614-
-------------------------------------
613+
{{CSSResourceValue}} objects {#resourcevalue-objects}
614+
-----------------------------------------------------
615615

616616
<pre class='idl'>
617617

618-
enum CSSImageState {"ready", "pending", "invalid"};
618+
enum CSSResourceState {"unloaded", "loading", "loaded", "error"};
619619

620-
interface CSSImageValue : CSSStyleValue {
621-
readonly attribute CSSImageState state;
622-
readonly attribute Drawable? drawable;
620+
interface CSSResourceValue {
621+
readonly attribute CSSResourceState state;
623622
};
624623

624+
</pre>
625+
626+
{{CSSResourceValue}} objects represent CSS values that may require an asynchronous network fetch
627+
before being usable.
628+
629+
A {{CSSResourceValue}} is in one of the following states, as reflected in the value of the
630+
<a attribute for=CSSResourceValue>state</a> attribute:
631+
632+
: ''unloaded''
633+
:: The resource is not ready and is not actively being fetched
634+
: ''loading''
635+
:: The resource is not ready, but is in the process of being fetched
636+
: ''loaded''
637+
:: The resource is ready for rendering
638+
: ''error''
639+
:: The resource can't be fetched, or the fetched resource is invalid
640+
641+
<div class='example'>
642+
For example, images that match the <<url>> production can be used immediately, but will not result
643+
in a visual change until the image data is fetched. {{CSSResourceValue}} objects represent this by
644+
providing values that track loaded state via the {{CSSResourceState}} enum.
645+
</div>
646+
647+
{{CSSImageValue}} objects {#imagevalue-objects}
648+
-----------------------------------------------
649+
650+
<pre class='idl'>
651+
652+
interface CSSImageValue : CSSResourceValue {
653+
readonly attribute double intrinsicWidth;
654+
readonly attribute double intrinsicHeight;
655+
};
656+
657+
[Constructor(DOMString url)]
625658
interface CSSURLImageValue : CSSImageValue {
626659
readonly attribute DOMString url;
627660
};
@@ -631,22 +664,33 @@ interface CSSURLImageValue : CSSImageValue {
631664
{{CSSImageValue}} objects represent values for properties that take <<image>> productions,
632665
for example 'background-image', 'list-style-image', and 'border-image-source'.
633666

634-
The <a attribute for=CSSImageValue>state</a> attribute is set to "pending" if the image requires
635-
network data that has not yet been fetched, to "invalid" if an error means that the image can't be
636-
rendered, and to "ready" otherwise.
667+
{{CSSImageValue}} objects that do not require network data (for example linear and radial gradients)
668+
are initialized with <a attribute for=CSSResourceValue>state</a> ''loaded''.
637669

638-
The <a attribute for=CSSImageValue>drawable</a> attribute is null if <a attribute for=CSSImageValue>state</a>
639-
is "pending" or "invalid". Otherwise, the {{Drawable}} can be used to render image data via the canvas
640-
API.
670+
If <a attribute for=CSSResourceValue>state</a> is ''unloaded'', ''loading'', or ''error'', then
671+
<a attribute for=CSSImageValue>intrinsicWidth</a> and <a attribute for=CSSImageValue>intrinsicHeight</a>
672+
are 0. Otherwise, the attributes are set to the intrinsic width and height of the referenced image.
641673

642-
Issue: clean up the above wording once Drawables are a thing.
674+
Issue: Does the loading lifecycle need to be described here?
643675

644676
{{CSSURLImageValue}} objects represent {{CSSImageValue}}s that match the <<url>> production. For these
645-
objects, the <a attribute for=CSSURLImageValue>url</a> attribute contains the URL that contains the image.
677+
objects, the <a attribute for=CSSURLImageValue>url</a> attribute contains the URL that references the image.
678+
679+
{{CSSFontFaceValue}} objects {#fontfacevalue-objects}
680+
-----------------------------------------------------
681+
682+
<pre class='idl'>
646683

647-
Issue: We should add a promise that waits for the {{CSSImageState}} to become ready, but
648-
this should probably be deferred until we have cancellable promises.
684+
[Constructor(DOMString fontFaceName)]
685+
interface CSSFontFaceValue : CSSResourceValue {
686+
readonly attribute DOMString fontFaceName;
687+
};
649688

689+
</pre>
690+
691+
{{CSSFontFaceValue}} objects represent font faces that can be used to render text. As
692+
font data may need to be fetched from a remote source, {{CSSFontFaceValue}} is a subclass
693+
of {{CSSResourceValue}}.
650694

651695
Mapping of properties to accepted types {#mapping-of-properties-to-accepted-types}
652696
==================================================================================
@@ -1261,22 +1305,20 @@ The following process sets a value for either <var>x</var> or<var>y</var>, depen
12611305
1. amend <var>x</var> (if <var>bias</var> is horizontal) or <var>y</var> (if <var>bias</var> is vertical) by
12621306
adding <var>adjustment</var> to it.
12631307

1264-
{{CSSImageValue}} normalization {#imagevalue-normalization}
1265-
-----------------------------------------------------------
1308+
{{CSSResourceValue}} normalization {#resourcevalue-normalization}
1309+
--------------------------------------------------------------
12661310

1267-
Image references are normalized by determining whether the reference is invalid
1268-
(in which case <a attribute for=CSSImageValue>state</a> is set to "invalid") or
1269-
requires network data (in which case <a attribute for=CSSImageValue>state</a>
1270-
is set to "pending"). If data is not required and the reference is valid then
1271-
<a attribute for=CSSImageValue>state</a> is set to "ready" and the
1272-
<a attribute for=CSSImageValue>drawable</a> attribute is provided with a
1273-
{{Drawable}} representing the image.
1311+
Resource references are normalized by determining whether the reference is invalid
1312+
(in which case <a attribute for=CSSResourceValue>state</a> is set to ''error'') or
1313+
requires network data (in which case <a attribute for=CSSResourceValue>state</a>
1314+
is set to ''loading''). If data is not required and the reference is valid then
1315+
<a attribute for=CSSResourceValue>state</a> is set to ''loaded''.
12741316

1275-
If <a attribute for=CSSImageValue>state</a> is set to "pending" then the image
1317+
If <a attribute for=CSSResourceValue>state</a> is set to ''loading'' then the image
12761318
reference is reevaluated once the pending data becomes available, according to the
12771319
same rules referenced above.
12781320

1279-
Normalization does not fail for {{CSSImageValue}} objects.
1321+
Normalization does not fail for {{CSSResourceValue}} objects.
12801322

12811323
Security Considerations {#security-considerations}
12821324
==================================================

0 commit comments

Comments
 (0)