Skip to content

Commit 2c25d17

Browse files
committed
1. Restore default sizing algorithm to its previous scope.
2. Add contain/cover sizing as a separate algorithm, using same wording as object-fit's contain/cover values 3. Better explanations of how these algorithms relate to the rest of CSS.
1 parent 6a594c6 commit 2c25d17

2 files changed

Lines changed: 136 additions & 85 deletions

File tree

css3-images/Overview.html

Lines changed: 91 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,15 @@ <h2 class="no-num no-toc" id=contents>Table of contents</h2>
249249
<li><a href="#object-negotiation"><span class=secno>5.2. </span>
250250
CSS&#x21CB;Object Negotiation</a>
251251

252-
<li><a href="#default-sizing"><span class=secno>5.3. </span> Default
252+
<li><a href="#concrete-size-resolution"><span class=secno>5.3. </span>
253253
Concrete Object Size Resolution</a>
254+
<ul class=toc>
255+
<li><a href="#default-sizing"><span class=secno>5.3.1. </span> Default
256+
Sizing Algorithm</a>
257+
258+
<li><a href="#cover-contain"><span class=secno>5.3.2. </span> Cover
259+
and Contain Constraint Sizing</a>
260+
</ul>
254261

255262
<li><a href="#object-sizing-examples"><span class=secno>5.4. </span>
256263
Examples of CSS Object Sizing</a>
@@ -1679,13 +1686,12 @@ <h3 id=sizing-terms><span class=secno>5.1. </span> Object-Sizing
16791686

16801687
<dt><dfn id=specified-size>specified size</dfn>
16811688

1682-
<dd>The specified size of an object is a set of constraints given by CSS,
1683-
such as through the &lsquo;<code class=property>width</code>&rsquo; and
1684-
&lsquo;<code class=property>height</code>&rsquo; or &lsquo;<code
1689+
<dd>The specified size of an object is given by CSS, such as through the
1690+
&lsquo;<code class=property>width</code>&rsquo; and &lsquo;<code
1691+
class=property>height</code>&rsquo; or &lsquo;<code
16851692
class=property>background-size</code>&rsquo; properties. The specified
1686-
size may be a width and/or a height, or alternately a "cover" or
1687-
"contain" constraint. Additionally, the specified size may have a
1688-
horizontal or vertical "rounding" constraint.
1693+
size can be a definite width and height, a set of constraints, or a
1694+
combination thereof.
16891695

16901696
<dt><dfn id=concrete-object-size>concrete object size</dfn>
16911697

@@ -1746,32 +1752,53 @@ <h3 id=object-negotiation><span class=secno>5.2. </span> CSS&#x21CB;Object
17461752
</ol>
17471753
<!-- ====================================================================== -->
17481754

1749-
<h3 id=default-sizing><span class=secno>5.3. </span> Default Concrete
1755+
<h3 id=concrete-size-resolution><span class=secno>5.3. </span> Concrete
17501756
Object Size Resolution</h3>
17511757

1752-
<p>In the absence of more specific rules, an object's <a
1753-
href="#intrinsic-dimensions"><i>intrinsic dimensions</i></a> are resolved
1754-
to a <a href="#concrete-object-size"><i>concrete object size</i></a> with
1755-
the <dfn id=default-sizing-algorithm>default sizing algorithm</dfn>, as
1756-
follows:
1758+
<p>Currently the rules for sizing objects are described in each context
1759+
that such objects are used. This section defines some common sizing
1760+
constraints and how to resolve them so that future specs can refer to them
1761+
instead of redefining size resolution in each instance.
1762+
1763+
<h4 id=default-sizing><span class=secno>5.3.1. </span> Default Sizing
1764+
Algorithm</h4>
1765+
1766+
<p>The <dfn id=default-sizing-algorithm>default sizing algorithm</dfn> is a
1767+
set of rules commonly used to find an object's <a
1768+
href="#concrete-object-size"><i>concrete object size</i></a>. It resolves
1769+
the simultaneous constraints presented by the object's <a
1770+
href="#intrinsic-dimensions"><i>intrinsic dimensions</i></a> and either an
1771+
unconstrained <a href="#specified-size"><i>specified size</i></a> or one
1772+
consisting of only a definite width and/or height.
1773+
1774+
<p>Some object sizing rules (such as those for &lsquo;<code
1775+
class=property>list-style-image</code>&rsquo;) correspond exactly to the
1776+
<a href="#default-sizing-algorithm"><i>default sizing algorithm</i></a>.
1777+
Others (such as those for &lsquo;<code
1778+
class=property>border-image</code>&rsquo;) invoke the default sizing
1779+
algorithm but also apply additional sizing rules before arriving at a
1780+
final <a href="#concrete-object-size"><i>concrete object size</i></a>.
1781+
1782+
<p>The <a href="#default-sizing-algorithm"><i>default sizing
1783+
algorithm</i></a> is defined as follows:
17571784

17581785
<ul>
17591786
<li>If the <a href="#specified-size"><i>specified size</i></a> is a
17601787
definite width and height, the <a
17611788
href="#concrete-object-size"><i>concrete object size</i></a> is given
17621789
that width and height.
17631790

1764-
<li>If the <a href="#specified-size"><i>specified size</i></a> has only a
1765-
width or height, but not both, then the <a
1791+
<li>If the <a href="#specified-size"><i>specified size</i></a> is only a
1792+
width or height (but not both) then the <a
17661793
href="#concrete-object-size"><i>concrete object size</i></a> is given
17671794
that specified width or height. The other dimension is calculated as
17681795
follows:
17691796
<ol>
17701797
<li>If the object has an <a href="#intrinsic-aspect-ratio"><i>intrinsic
17711798
aspect ratio</i></a>, the missing dimension of the <a
17721799
href="#concrete-object-size"><i>concrete object size</i></a> is
1773-
calculated using the <i>intrinsic aspect-ratio</i> and the present
1774-
dimension.
1800+
calculated using the <a href="#intrinsic-aspect-ratio"><i>intrinsic
1801+
aspect ratio</i></a> and the present dimension.
17751802

17761803
<li>Otherwise, if the missing dimension is present in the object's <a
17771804
href="#intrinsic-dimensions"><i>intrinsic dimensions</i></a>, the
@@ -1783,25 +1810,8 @@ <h3 id=default-sizing><span class=secno>5.3. </span> Default Concrete
17831810
from the <a href="#default-object-size"><i>default object size</i></a>.
17841811
</ol>
17851812

1786-
<li>If the <a href="#specified-size"><i>specified size</i></a> is a
1787-
"contain" constraint and the object has an intrinsic aspect ratio, the <a
1788-
href="#concrete-object-size"><i>concrete object size</i></a> is the
1789-
largest rectangle with that aspect ratio that completely fits within the
1790-
<a href="#default-object-size"><i>default object size</i></a>. If the
1791-
object doesnt' have an intrinsic aspec tratio, the <a
1792-
href="#concrete-object-size"><i>concrete object size</i></a> is the <a
1793-
href="#default-object-size"><i>default object size</i></a>.
1794-
1795-
<li>If the <a href="#specified-size"><i>specified size</i></a> is a
1796-
"cover" constraint and the object has an intrinsic aspect ratio, the <a
1797-
href="#concrete-object-size"><i>concrete object size</i></a> is the
1798-
smallest rectangle with that aspect ratio that can completely cover
1799-
within the <a href="#default-object-size"><i>default object size</i></a>.
1800-
If the object doesnt' have an intrinsic aspec tratio, the <a
1801-
href="#concrete-object-size"><i>concrete object size</i></a> is the <a
1802-
href="#default-object-size"><i>default object size</i></a>.
1803-
1804-
<li>Otherwise:
1813+
<li>If the <a href="#specified-size"><i>specified size</i></a> has no
1814+
constraints:
18051815
<ol>
18061816
<li>If the object has only an <a
18071817
href="#intrinsic-aspect-ratio"><i>intrinsic aspect ratio</i></a>, the
@@ -1825,33 +1835,35 @@ <h3 id=default-sizing><span class=secno>5.3. </span> Default Concrete
18251835
</ol>
18261836
</ul>
18271837

1828-
<p>If the <a href="#specified-size"><i>specified size</i></a> has a
1829-
horizontal or vertical rounding constraint and the <a
1830-
href="#concrete-object-size"><i>concrete object size</i></a> in that
1831-
dimension is non-zero, the <a href="#concrete-object-size"><i>concrete
1832-
object size</i></a> is then adjusted in that dimension so that it fits a
1833-
whole number of times into the <a href="#default-object-size"><i>default
1834-
object size</i></a>, as follows:
1835-
1836-
<blockquote>
1837-
<p>If <var>X</var> is the size of the <a
1838-
href="#concrete-object-size"><i>concrete object size</i></a> in the given
1839-
dimension and <var>W</var> is the size of the <a
1840-
href="#default-object-size"><i>default object size</i></a> in the same
1841-
dimension, the <a href="#concrete-object-size"><i>concrete object
1842-
size</i></a> in that dimension is changed to <var>X'</var> = <var>W</var>
1843-
/ round(<var>W</var> / <var>X</var>), where round() is a function that
1844-
returns the nearest natural number.
1845-
</blockquote>
1846-
1847-
<p>Then, if the object has an intrinsic aspect ratio and the <a
1848-
href="#specified-size"><i>specified size</i></a> had a horizontal rounding
1849-
constraint but no height, the height of the <a
1850-
href="#concrete-object-size"><i>concrete object size</i></a> is adjust so
1851-
that the <a href="#concrete-object-size"><i>concrete object size</i></a>
1852-
has the same aspect ratio as the object's intrinsic aspect ratio (and
1853-
analogously for a <a href="#specified-size"><i>specified size</i></a> with
1854-
a vertical rounding constraint but no width).
1838+
<h4 id=cover-contain><span class=secno>5.3.2. </span> Cover and Contain
1839+
Constraint Sizing</h4>
1840+
1841+
<p>Two other common specified sizes are the <a
1842+
href="#contain-constraint"><i>contain constraint</i></a> and the <a
1843+
href="#cover-constraint"><i>cover constraint</i></a>, both of which are
1844+
resolved against a specified <dfn id=constraint-rectangle>constraint
1845+
rectangle</dfn> using the object's <a
1846+
href="#intrinsic-aspect-ratio"><i>intrinsic aspect ratio</i></a>:
1847+
1848+
<ul>
1849+
<li>A <dfn id=contain-constraint>contain constraint</dfn> is resolved by
1850+
setting the <a href="#concrete-object-size"><i>concrete object
1851+
size</i></a> to the largest rectangle that has the object's <a
1852+
href="#intrinsic-aspect-ratio"><i>intrinsic aspect ratio</i></a> and
1853+
additionally has neither width nor height larger than the constraint
1854+
rectangle's width and height, respectively.
1855+
1856+
<li>A <dfn id=cover-constraint>cover constraint</dfn> is resolved by
1857+
setting the <a href="#concrete-object-size"><i>concrete object
1858+
size</i></a> to the smallest rectangle that has the object's <a
1859+
href="#intrinsic-aspect-ratio"><i>intrinsic aspect ratio</i></a> and
1860+
additionally has neither width nor height smaller than the constraint
1861+
rectangle's width and height, respectively.
1862+
</ul>
1863+
1864+
<p>In both cases, if the object doesn't have an intrinsic aspect ratio, the
1865+
<a href="#concrete-object-size"><i>concrete object size</i></a> is the
1866+
specified constraint rectangle.
18551867

18561868
<h3 id=object-sizing-examples><span class=secno>5.4. </span> Examples of
18571869
CSS Object Sizing</h3>
@@ -1880,11 +1892,12 @@ <h3 id=object-sizing-examples><span class=secno>5.4. </span> Examples of
18801892
&lsquo;<code class=property>background-size</code>&rsquo; property can
18811893
give a sizing constraint, invoking either the <a
18821894
href="#default-sizing-algorithm"><i>default sizing algorithm</i></a> or
1883-
one of the <i title="contain constraint">contain</i> or <i
1884-
title="cover constraint">cover</i> constraints. The concrete object size
1885-
is further adjusted in later steps if &lsquo;<code
1886-
class=property>background-repeat</code>&rsquo; has a &lsquo;<code
1887-
class=css>round</code>&rsquo; value. <a href="#CSS3BG"
1895+
one of the <a href="#contain-constraint"><i
1896+
title="contain constraint">contain</i></a> or <a
1897+
href="#cover-constraint"><i title="cover constraint">cover</i></a>
1898+
constraints. The concrete object size is further adjusted in later steps
1899+
if &lsquo;<code class=property>background-repeat</code>&rsquo; has a
1900+
&lsquo;<code class=css>round</code>&rsquo; value. <a href="#CSS3BG"
18881901
rel=biblioentry>[CSS3BG]<!--{{CSS3BG}}--></a>
18891902

18901903
<dt>&lsquo;<code class=property>list-style-image</code>&rsquo;
@@ -2767,11 +2780,20 @@ <h2 class=no-num id=index>Index</h2>
27672780
<li>concrete object size, <a href="#concrete-object-size"
27682781
title="concrete object size"><strong>5.1.</strong></a>
27692782

2783+
<li>constraint rectangle, <a href="#constraint-rectangle"
2784+
title="constraint rectangle"><strong>5.3.2.</strong></a>
2785+
2786+
<li>contain constraint, <a href="#contain-constraint"
2787+
title="contain constraint"><strong>5.3.2.</strong></a>
2788+
2789+
<li>cover constraint, <a href="#cover-constraint"
2790+
title="cover constraint"><strong>5.3.2.</strong></a>
2791+
27702792
<li>default object size, <a href="#default-object-size"
27712793
title="default object size"><strong>5.1.</strong></a>
27722794

27732795
<li>default sizing algorithm, <a href="#default-sizing-algorithm"
2774-
title="default sizing algorithm"><strong>5.3.</strong></a>
2796+
title="default sizing algorithm"><strong>5.3.1.</strong></a>
27752797

27762798
<li>&lsquo;<code class=css>dpcm</code>&rsquo;, <a href="#dpcm"
27772799
title="''dpcm''"><strong>2.</strong></a>

css3-images/Overview.src.html

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ <h3 id="sizing-terms">
10621062
</dd>
10631063

10641064
<dt><dfn>specified size</dfn></dt>
1065-
<dd>The specified size of an object is a set of constraints given by CSS, such as through the 'width' and 'height' or 'background-size' properties. The specified size may be a width and/or a height, or alternately a "cover" or "contain" constraint. Additionally, the specified size may have a horizontal or vertical "rounding" constraint.</dd>
1065+
<dd>The specified size of an object is given by CSS, such as through the 'width' and 'height' or 'background-size' properties. The specified size can be a definite width and height, a set of constraints, or a combination thereof.</dd>
10661066

10671067
<dt><dfn>concrete object size</dfn></dt>
10681068
<dd>The <i>concrete object size</i> is the result of combining an object's <i>intrinsic dimensions</i> and <i>specified size</i> with the <i>default object size</i> of the context it's used in, producing a rectangle with a definite width and height.</dd>
@@ -1107,30 +1107,45 @@ <h3 id="object-negotiation">
11071107

11081108
<!-- ====================================================================== -->
11091109

1110-
<h3 id="default-sizing">
1111-
Default Concrete Object Size Resolution</h3>
1110+
<h3 id="concrete-size-resolution">
1111+
Concrete Object Size Resolution</h3>
11121112

1113-
<p>In the absence of more specific rules, an object's <i>intrinsic dimensions</i> are resolved to a <i>concrete object size</i> with the <dfn>default sizing algorithm</dfn>, as follows:</p>
1113+
<p>Currently the rules for sizing objects are described in each context that
1114+
such objects are used. This section defines some common sizing constraints
1115+
and how to resolve them so that future specs can refer to them instead of
1116+
redefining size resolution in each instance.
1117+
1118+
<h4 id="default-sizing">
1119+
Default Sizing Algorithm</h4>
1120+
1121+
<p>The <dfn>default sizing algorithm</dfn> is a set of rules commonly used
1122+
to find an object's <i>concrete object size</i>. It resolves the simultaneous
1123+
constraints presented by the object's <i>intrinsic dimensions</i> and either an
1124+
unconstrained <i>specified size</i> or one consisting of only a definite width
1125+
and/or height.
1126+
1127+
<p>Some object sizing rules (such as those for 'list-style-image') correspond
1128+
exactly to the <i>default sizing algorithm</i>. Others (such as those for
1129+
'border-image') invoke the default sizing algorithm but also apply additional
1130+
sizing rules before arriving at a final <i>concrete object size</i>.
1131+
1132+
<p>The <i>default sizing algorithm</i> is defined as follows:
11141133

11151134
<ul>
11161135
<li>If the <i>specified size</i> is a definite width and height, the <i>concrete object size</i> is given that width and height.</li>
11171136

1118-
<li>If the <i>specified size</i> has only a width or height, but not both, then the <i>concrete object size</i> is given that specified width or height. The other dimension is calculated as follows:
1137+
<li>If the <i>specified size</i> is only a width or height (but not both) then the <i>concrete object size</i> is given that specified width or height. The other dimension is calculated as follows:
11191138

11201139
<ol>
1121-
<li>If the object has an <i>intrinsic aspect ratio</i>, the missing dimension of the <i>concrete object size</i> is calculated using the <i>intrinsic aspect-ratio</i> and the present dimension.</li>
1140+
<li>If the object has an <i>intrinsic aspect ratio</i>, the missing dimension of the <i>concrete object size</i> is calculated using the <i>intrinsic aspect ratio</i> and the present dimension.</li>
11221141

11231142
<li>Otherwise, if the missing dimension is present in the object's <i>intrinsic dimensions</i>, the missing dimension is taken from the object's <i>intrinsic dimensions</i>.</li>
11241143

11251144
<li>Otherwise, the missing dimension of the <i>concrete object size</i> is taken from the <i>default object size</i>.</li>
11261145
</ol>
11271146
</li>
11281147

1129-
<li>If the <i>specified size</i> is a "contain" constraint and the object has an intrinsic aspect ratio, the <i>concrete object size</i> is the largest rectangle with that aspect ratio that completely fits within the <i>default object size</i>. If the object doesnt' have an intrinsic aspec tratio, the <i>concrete object size</i> is the <i>default object size</i>.</li>
1130-
1131-
<li>If the <i>specified size</i> is a "cover" constraint and the object has an intrinsic aspect ratio, the <i>concrete object size</i> is the smallest rectangle with that aspect ratio that can completely cover within the <i>default object size</i>. If the object doesnt' have an intrinsic aspec tratio, the <i>concrete object size</i> is the <i>default object size</i>.</li>
1132-
1133-
<li>Otherwise:
1148+
<li>If the <i>specified size</i> has no constraints:
11341149

11351150
<ol>
11361151
<li>If the object has only an <i>intrinsic aspect ratio</i>, the <i>concrete object size</i> must have that aspect ratio, and additionally be as large as possible without either its height or width exceeding the height or width of the <i>default object size</i>. Otherwise, the width and height of the <i>concrete object size</i> is the same as the object's <i>intrinsic width</i> and <i>intrinsic height</i>, if they exist.</li>
@@ -1140,13 +1155,27 @@ <h3 id="default-sizing">
11401155
</li>
11411156
</ul>
11421157

1143-
<p>If the <i>specified size</i> has a horizontal or vertical rounding constraint and the <i>concrete object size</i> in that dimension is non-zero, the <i>concrete object size</i> is then adjusted in that dimension so that it fits a whole number of times into the <i>default object size</i>, as follows:</p>
1158+
<h4 id="cover-contain">
1159+
Cover and Contain Constraint Sizing</h4>
1160+
1161+
<p>Two other common specified sizes are the <i>contain constraint</i> and
1162+
the <i>cover constraint</i>, both of which are resolved against a specified
1163+
<dfn>constraint rectangle</dfn> using the object's <i>intrinsic aspect ratio</i>:
11441164

1145-
<blockquote>
1146-
<p>If <var>X</var> is the size of the <i>concrete object size</i> in the given dimension and <var>W</var> is the size of the <i>default object size</i> in the same dimension, the <i>concrete object size</i> in that dimension is changed to <var>X'</var> = <var>W</var> / round(<var>W</var> / <var>X</var>), where round() is a function that returns the nearest natural number.</p>
1147-
</blockquote>
1165+
<ul>
1166+
<li>A <dfn>contain constraint</dfn> is resolved by setting the
1167+
<i>concrete object size</i> to the largest rectangle that has the object's
1168+
<i>intrinsic aspect ratio</i> and additionally has neither width nor height
1169+
larger than the constraint rectangle's width and height, respectively.</li>
1170+
1171+
<li>A <dfn>cover constraint</dfn> is resolved by setting the
1172+
<i>concrete object size</i> to the smallest rectangle that has the object's
1173+
<i>intrinsic aspect ratio</i> and additionally has neither width nor height
1174+
smaller than the constraint rectangle's width and height, respectively.</li>
1175+
</ul>
11481176

1149-
<p>Then, if the object has an intrinsic aspect ratio and the <i>specified size</i> had a horizontal rounding constraint but no height, the height of the <i>concrete object size</i> is adjust so that the <i>concrete object size</i> has the same aspect ratio as the object's intrinsic aspect ratio (and analogously for a <i>specified size</i> with a vertical rounding constraint but no width).</p>
1177+
<p>In both cases, if the object doesn't have an intrinsic aspect ratio,
1178+
the <i>concrete object size</i> is the specified constraint rectangle.
11501179

11511180
<h3 id='object-sizing-examples'>
11521181
Examples of CSS Object Sizing</h3>

0 commit comments

Comments
 (0)