Skip to content

Commit 21befc8

Browse files
committed
Add matchContainer() method and QueryContainerList interface
1 parent a69ef92 commit 21befc8

1 file changed

Lines changed: 97 additions & 5 deletions

File tree

css-conditional-5/Overview.bs

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,11 +1772,103 @@ The <code>CSSContainerRule</code> interface</h3>
17721772
or simplification based on evaluating results) are not allowed.
17731773
</dl>
17741774

1775-
Issue(6205): Container Queries should have a <code>matchContainer</code> method.
1776-
This will be modeled on {{matchMedia()}} and the {{MediaQueryList}} interface,
1777-
but applied to Elements rather than the Window.
1778-
When measuring layout sizes, it behaves Similar to <code>resizeObserver</code>,
1779-
but it provides the additional Container Query syntax and features.
1775+
<h3 id=the-matchContainer-method>The matchContainer() method</h3>
1776+
1777+
<pre class=idl>
1778+
partial interface Element {
1779+
[NewObject] ContainerQueryList matchContainer(CSSOMString query);
1780+
}
1781+
</pre>
1782+
1783+
1784+
1785+
<h3 id=the-ContainerQueryList-interface>The {{ContainerQueryList}} Interface</h3>
1786+
1787+
This section integrates with the <a for=/>event loop</a> defined in HTML. [[!HTML]]
1788+
1789+
A {{ContainerQueryList}} object has an associated
1790+
<dfn for=ContainerQueryList>container query list</dfn>
1791+
and an associated
1792+
<dfn for=ContainerQueryList>document</dfn> set on creation.
1793+
1794+
A {{ContainerQueryList}} object has an associated
1795+
<dfn for=ContainerQueryList>container</dfn> which is the
1796+
<a lt='serialize a container query list'>serialized</a>
1797+
form of the associated [=ContainerQueryList/container query list=].
1798+
1799+
A {{ContainerQueryList}} object has an associated
1800+
<dfn for=ContainerQueryList>matches state</dfn>
1801+
which is true if the associated [=ContainerQueryList/container query list=]
1802+
matches the state of the <a for=ContainerQueryList>document</a>, and false otherwise.
1803+
1804+
1805+
When asked to <dfn export>evaluate container queries and report changes</dfn>
1806+
for a {{Document}} <var>doc</var>, run these steps:
1807+
1808+
<ol>
1809+
1810+
<li>
1811+
1812+
For each {{ContainerQueryList}} object <var>target</var> that has <var>doc</var> as its <a for=ContainerQueryList>document</a>, in the order they were created, oldest first, run these substeps:
1813+
1814+
<ol>
1815+
1816+
<li>If <var>target</var>'s <a>matches state</a> has changed since the last time these steps were run,
1817+
<a>fire an event</a> named <a event>change</a> at <var>target</var>
1818+
using {{ContainerQueryListEvent}},
1819+
with its {{Event/isTrusted}} attribute initialized to true,
1820+
its {{ContainerQueryList/container}} attribute initialized to <var>target</var>'s <a>container</a>,
1821+
and its {{ContainerQueryListEvent/matches}} attribute initialized to <var>target</var>'s <a>matches state</a>. <!--fingerprint-->
1822+
1823+
</ol>
1824+
1825+
</ol>
1826+
1827+
<div class='example'>
1828+
A simple piece of code that detects changes in the overflow in any of a series of elements can be written as follows:
1829+
1830+
<pre highlight=javascript>
1831+
function handleOverflowChange(event) {
1832+
if(event.matches) // the thing overflowed
1833+
&hellip;
1834+
else
1835+
&hellip;
1836+
}
1837+
var cql = matchContainer("(scroll-state(scrollable))");
1838+
cql.onchange = handleOverflowChange;
1839+
</pre>
1840+
</div>
1841+
1842+
<pre class=idl>
1843+
[Exposed=Window]
1844+
interface ContainerQueryList : EventTarget {
1845+
readonly attribute CSSOMString container;
1846+
readonly attribute boolean matches;
1847+
attribute EventHandler onchange;
1848+
};
1849+
</pre>
1850+
1851+
The <dfn attribute for=ContainerQueryList>container</dfn> attribute must return
1852+
the associated <a>container</a>.
1853+
1854+
The <dfn attribute for=ContainerQueryList>matches</dfn> attribute must return
1855+
the associated <a>matches state</a>. <!--fingerprint-->
1856+
1857+
The following are the <a>event handlers</a> (and their corresponding
1858+
<a>event handler event types</a>) that must be supported, as
1859+
<a>event handler IDL attributes</a>, by all objects implementing the
1860+
{{ContainerQueryList}} interface:
1861+
1862+
<table class="complex data">
1863+
<thead>
1864+
<tr>
1865+
<th><a>Event handler</a>
1866+
<th><a>Event handler event type</a>
1867+
<tbody>
1868+
<tr>
1869+
<td><dfn attribute for=ContainerQueryList>onchange</dfn>
1870+
<td><a event>change</a>
1871+
</table>
17801872

17811873
<h2 class=no-num id="security">Security Considerations</h2>
17821874

0 commit comments

Comments
 (0)