Skip to content

Commit

Permalink
Make computation of directionality account for Shadow DOM.
Browse files Browse the repository at this point in the history
This specifies (with some additional detail) the proposal in
whatwg#3699 (comment) .
This changes three things:
 * the inheritance of directionality
 * the inheritance of language
 * the computation of dir=auto
to account for Shadow DOM.

This builds on the work in whatwg#9452 and whatwg#9554 to refactor this section, and
builds on work by Brian Kardell, Eric Meyer, and others in whatwg#7424 and
in whatwg#9166 and work by fantasai, rniwa, smaug, MyIdShin, Brian Kardell,
and others in whatwg#3699.

Closes whatwg#9166.

Fixes whatwg#3699.
  • Loading branch information
dbaron committed Sep 26, 2023
1 parent e4ce01e commit 63affd1
Showing 1 changed file with 107 additions and 26 deletions.
133 changes: 107 additions & 26 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -13274,8 +13274,18 @@ Transport Protocol">HTTP&lt;/abbr> today.&lt;/p></code></pre> <!-- DO NOT REWRAP
data-x="">lang</code></dfn> attribute in the <span>XML namespace</span> is defined in XML.
<ref>XML</ref></p>

<p>If these attributes are omitted from an element, then the language of this element is the same
as the language of its parent element, if any.</p>
<p>If these attributes are omitted from an element, then the language of this element is:</p>

<dl class="switch">
<dt>If the element's parent is a <span>shadow root</span></dt>
<dt>If the element itself is a <code>slot</code> element that has a <span
data-x="concept-element-shadow-root">shadow root</span> as its root</dt>
<dd>the same as the language of its <span>shadow root</span>'s <span
data-x="dom-hyperlink-host">host</span> element, if any.</dd>

<dt>Otherwise</dt>
<dd>the same as the language of its parent element, if any.</dd>
</dl>

<p>The <code data-x="attr-lang">lang</code> attribute in no namespace may be used on any <span
data-x="HTML elements">HTML element</span>.</p>
Expand Down Expand Up @@ -13543,7 +13553,17 @@ Transport Protocol">HTTP&lt;/abbr> today.&lt;/p></code></pre> <!-- DO NOT REWRAP
<dd><p>Return '<span data-x="concept-rtl">rtl</span>'.</p></dd>

<dt><span data-x="attr-dir-auto-state">auto</span></dt>
<dd><p>Return the <span>auto directionality</span> of <var>element</var>.</p></dd>
<dd>
<ol>
<li><p>Let <var>result</var> be the <span>auto directionality</span> of
<var>element</var>.</p></li>

<li><p>If <var>result</var> is null, then set <var>result</var> to the <span>parent
directionality</span> of <var>element</var>.</p></li>

<li><p>Return <var>result</var>.</p></li>
</ol>
</dd>

<dt><span data-x="attr-dir-undefined-state">undefined</span></dt>
<dd>
Expand Down Expand Up @@ -13586,47 +13606,99 @@ Transport Protocol">HTTP&lt;/abbr> today.&lt;/p></code></pre> <!-- DO NOT REWRAP
<li><p>If <var>element</var>'s <span data-x="concept-fe-value">value</span> is not the empty
string, then return '<span data-x="concept-ltr">ltr</span>'.</p></li>

<li><p>Return the <span>parent directionality</span> of <var>element</var>.</p></li>
<li><p>Return null.</p></li>
</ol>
</li>

<li><p>Let <var>codePoint</var> be null.</p></li>
<li>
<p>If <var>element</var> is a <code>slot</code> element that is in a <span>shadow
tree</span> whose <span>assigned nodes</span> are not empty:</p>

<ol>
<li>
<p>For each node <var>child</var> in <var>element</var>'s <span>assigned nodes</span>:</p>

<ol>
<li><p>Let <var>childDirection</var> be null.</p></li>

<li><p>If <var>child</var> is a <code>Text</code> node, then set <var>childDirection</var> to
the <span>text node directionality</span> of <var>child</var>.</p></li>

<li><p>If <var>child</var> is an <code>Element</code> node, then set
<var>childDirection</var> to the <span>auto directionality</span> of
<var>child</var>.</p></li>

<li><p>If <var>childDirection</var> is not null, then return
<var>childDirection</var>.</p></li>
</ol>
</li>

<li><p>Return null.</p></li>
</ol>
</li>

<li>
<p>For each <code>Text</code> node <var>text</var> that is a descendant of <var>element</var>,
in <span>tree order</span>:</p>
<p><span data-x="list iterate">For each</span> node <var>descendant</var> of
<var>element</var>'s <span data-x="descendant">descendants</span>, in <span>tree
order</span>:</p>

<ol>
<li>
<p>If <var>text</var> has an ancestor element that is a descendant of <var>element</var> and
is also one of</p>
<p>If <var>descendant</var> has an ancestor element that is a descendant of <var>element</var>
and is also one of</p>

<ul class="brief">
<li>a <code>bdi</code> element</li>
<li>a <code>script</code> element</li>
<li>a <code>style</code> element</li>
<li>a <code>textarea</code> element</li>
<li>a <code>slot</code> element that is in a <span>shadow tree</span></li>
<li>an element whose <code data-x="attr-dir">dir</code> attribute is not in the <span
data-x="attr-dir-undefined-state">undefined</span> state</li>
</ul>

<p>then <span>continue</span>.</p>
</li>

<li><p>If <var>text</var>'s <span data-x="concept-cd-data">data</span> does not contain a code
point whose bidirectional character type is L, AL, or R, then <span>continue</span>.
<ref>BIDI</ref></p></li>
<li>
<p>If <var>descendant</var> is a <code>slot</code> element that is in a <span>shadow
tree</span>, then:</p>

<ol>
<li><p>Let <var>result</var> be the <span>auto directionality</span> of
<var>descendant</var>.</p></li>.

<li><p>If <var>result</var> is null, then set <var>result</var> to '<span
data-x="concept-ltr">ltr</span>'.</p></li>

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

<li><p>If <var>descendant</var> is not a <code>Text</code> node, then
<span>continue</span>.</p></li>

<li><p>Set <var>codePoint</var> to the first code point in <var>text</var>'s <span
data-x="concept-cd-data">data</span> whose bidirectional character type is L, AL, or
R.</p></li>
<li><p>Let <var>result</var> be the <span>text node directionality</span> of
<var>descendant</var>.</li>

<li><p><span>Break</span>.</p></li>
<li><p>If <var>result</var> is not null, then return <var>result</var>.</p></li>
</ol>
</li>

<li><p>If <var>codePoint</var> is null, then return the <span>parent directionality</span> of
<var>element</var>.</p></li>
<li><p>Return null.</p></li>

</ol>

<p>To compute the <dfn>text node directionality</dfn> given a <code>Text</code> node
<var>text</var>:</p>

<ol>
<li><p>If <var>text</var>'s <span data-x="concept-cd-data">data</span> does not contain a code
point whose bidirectional character type is L, AL, or R, then return null.
<ref>BIDI</ref></p></li>

<li><p>Let <var>codePoint</var> be the first code point in <var>text</var>'s <span
data-x="concept-cd-data">data</span> whose bidirectional character type is L, AL, or R.</p></li>

<li><p>If <var>codePoint</var> is of bidirectional character type AL or R, then return '<span
data-x="concept-rtl">rtl</span>'.</p></li>
Expand All @@ -13638,11 +13710,19 @@ Transport Protocol">HTTP&lt;/abbr> today.&lt;/p></code></pre> <!-- DO NOT REWRAP
<p>To compute the <dfn>parent directionality</dfn> given an element <var>element</var>:</p>

<ol>
<li><p>If <var>element</var> has no <span>parent element</span>, then return '<span
data-x="concept-ltr">ltr</span>'.</p></li>
<li><p>If <var>element</var> is a <code>slot</code> element and is in a <span>shadow tree</span>,
then return the <span data-x="the directionality">directionality</span> of <var>element</var>'s
<span>root</span>'s <span data-x="concept-DocumentFragment-host">host</span>.</p></li>

<li><p>Let <var>parentNode</var> be <var>element</var>'s parent node.</p></li>

<li><p>If <var>parentNode</var> is a <span>shadow root</span>, then return the directionality of
<var>parentNode</var>'s <span data-x="concept-DocumentFragment-host">host</span>.</p></li>

<li><p>If <var>parentNode</var> is an element, then return <span data-x="the
directionality">directionality</span> of <var>parentNode</var>.</p></li>

<li><p>Return <span data-x="the directionality">directionality</span> of <var>element</var>'s
<span data-x="parent element">parent</span>.</p></li>
<li><p>Return '<span data-x="concept-ltr">ltr</span>'.</p></li>
</ol>

<div w-nodev>
Expand Down Expand Up @@ -129138,15 +129218,16 @@ br[clear=all i], br[clear=both i] { clear: both; }</code></pre>

<pre><code class="css">@namespace "http://www.w3.org/1999/xhtml";

[dir]:dir(ltr), bdi:dir(ltr), input[type=tel i]:dir(ltr) { direction: ltr; }
[dir]:dir(rtl), bdi:dir(rtl) { direction: rtl; }
[dir]:dir(ltr), slot:dir(ltr), bdi:dir(ltr), input[type=tel i]:dir(ltr) { direction: ltr; }
[dir]:dir(rtl), slot:dir(rtl), bdi:dir(rtl) { direction: rtl; }

address, blockquote, center, div, figure, figcaption, footer, form, header, hr,
legend, listing, main, p, plaintext, pre, summary, xmp, article, aside, h1, h2,
h3, h4, h5, h6, hgroup, nav, section, search, table, caption, colgroup, col,
thead, tbody, tfoot, tr, td, th, dir, dd, dl, dt, menu, ol, ul, li, bdi, output,
[dir=ltr i], [dir=rtl i], [dir=auto i] {
unicode-bidi: isolate; <!-- anything that's similar to display:block, plus <bdi>, <output>, and dir="" -->
slot, [dir=ltr i], [dir=rtl i], [dir=auto i] {
unicode-bidi: isolate; <!-- anything that's similar to display:block, plus
<bdi>, <output>, <slot>, and dir="" -->
}

bdo, bdo[dir] { unicode-bidi: isolate-override; } <!-- bdo[dir] rule is to override the otherwise higher-specificity attribute selectors in the previous rule -->
Expand Down

0 comments on commit 63affd1

Please sign in to comment.