Skip to content

Commit b71dd51

Browse files
dbaronmfreed7
authored andcommitted
Make computation of directionality account for shadow trees
This specifies (with some additional detail) the proposal in whatwg#3699 (comment). This changes three things: * the inheritance of directionality, * the inheritance of language, and * the computation of dir=auto to account for shadow trees. 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. Fixes whatwg#3699.
1 parent d71617b commit b71dd51

File tree

1 file changed

+135
-46
lines changed

1 file changed

+135
-46
lines changed

source

Lines changed: 135 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13287,7 +13287,8 @@ Transport Protocol">HTTP&lt;/abbr> today.&lt;/p></code></pre> <!-- DO NOT REWRAP
1328713287
<ref>XML</ref></p>
1328813288

1328913289
<p>If these attributes are omitted from an element, then the language of this element is the same
13290-
as the language of its parent element, if any.</p>
13290+
as the language of its parent element, if any (except for <code>slot</code> elements in a
13291+
<span>shadow tree</span>).</p>
1329113292

1329213293
<p>The <code data-x="attr-lang">lang</code> attribute in no namespace may be used on any <span
1329313294
data-x="HTML elements">HTML element</span>.</p>
@@ -13318,28 +13319,36 @@ Transport Protocol">HTTP&lt;/abbr> today.&lt;/p></code></pre> <!-- DO NOT REWRAP
1331813319

1331913320
<hr>
1332013321

13321-
<p>To determine the <dfn export for="Node">language</dfn> of a node, user agents must look at the
13322-
nearest ancestor element (including the element itself if the node is an element) that has a <span
13323-
data-x="attr-xml-lang"><code data-x="">lang</code> attribute in the <span>XML
13324-
namespace</span></span> set or is an <span data-x="HTML elements">HTML element</span> and has a
13325-
<code data-x="attr-lang">lang</code> in no namespace attribute set. That attribute specifies the
13326-
language of the node (regardless of its value).</p>
13327-
13328-
<p>If both the <code data-x="attr-lang">lang</code> attribute in no namespace and the <span
13329-
data-x="attr-xml-lang"><code data-x="">lang</code> attribute in the <span>XML
13330-
namespace</span></span> are set on an element, user agents must use the <span
13331-
data-x="attr-xml-lang"><code data-x="">lang</code> attribute in the <span>XML
13332-
namespace</span></span>, and the <code data-x="attr-lang">lang</code> attribute in no namespace
13333-
must be <span data-x="ignore">ignored</span> for the purposes of determining the element's
13334-
language.</p>
13322+
<p>To determine the <dfn export for="Node">language</dfn> of a node, user agents must use the
13323+
first appropriate step in the following list:</p>
13324+
13325+
<dl class="switch">
13326+
<dt>If the node is an element that has a <span data-x="attr-xml-lang"><code data-x="">lang</code>
13327+
attribute in the <span>XML namespace</span></span> set</dt>
13328+
<dd><p>Use the value of that attribute.</p></dd>
13329+
13330+
<dt>If the node is an <span data-x="HTML elements">HTML element</span> and has a <code
13331+
data-x="attr-lang">lang</code> in no namespace attribute set.</dt>
13332+
<dd><p>Use the value of that attribute.</p></dd>
1333513333

13336-
<p>If node's <span data-x="inclusive ancestor">inclusive ancestors</span> do not have either
13337-
attribute set, but there is a <span>pragma-set default language</span> set, then that is the
13338-
language of the node. If there is no <span>pragma-set default language</span> set, then language
13339-
information from a higher-level protocol (such as HTTP), if any, must be used as the final
13340-
fallback language instead. In the absence of any such language information, and in cases where the
13341-
higher-level protocol reports multiple languages, the language of the node is unknown, and the
13342-
corresponding language tag is the empty string.</p>
13334+
<dt>If the node's parent is a <span>shadow root</span></dt>
13335+
<dt>If the node is a <code>slot</code> element whose <span>root</span> is a <span>shadow
13336+
root</span></dt>
13337+
<dd><p>Use the <span>language</span> of that <span>shadow root</span>'s <span
13338+
data-x="concept-DocumentFragment-host">host</span>.</p></dd>
13339+
13340+
<!-- this assumes that if there's an ancestor element, the parent must be an element -->
13341+
<dt>If the node's <span>parent element</span> is not null</dt>
13342+
<dd><p>Use the <span>language</span> of that <span>parent element</span>.</p></dd>
13343+
13344+
<dt>Otherwise</dt>
13345+
<dd><p>If there is a <span>pragma-set default language</span> set, then that is the language of
13346+
the node. If there is no <span>pragma-set default language</span> set, then language information
13347+
from a higher-level protocol (such as HTTP), if any, must be used as the final fallback language
13348+
instead. In the absence of any such language information, and in cases where the higher-level
13349+
protocol reports multiple languages, the language of the node is unknown, and the corresponding
13350+
language tag is the empty string.</p></dd>
13351+
</dl>
1334313352

1334413353
<p>If the resulting value is not a recognized language tag, then it must be treated as an unknown
1334513354
language having the given language tag, distinct from all other languages. For the purposes of
@@ -13555,7 +13564,17 @@ Transport Protocol">HTTP&lt;/abbr> today.&lt;/p></code></pre> <!-- DO NOT REWRAP
1355513564
<dd><p>Return '<span data-x="concept-rtl">rtl</span>'.</p></dd>
1355613565

1355713566
<dt><span data-x="attr-dir-auto-state">auto</span></dt>
13558-
<dd><p>Return the <span>auto directionality</span> of <var>element</var>.</p></dd>
13567+
<dd>
13568+
<ol>
13569+
<li><p>Let <var>result</var> be the <span>auto directionality</span> of
13570+
<var>element</var>.</p></li>
13571+
13572+
<li><p>If <var>result</var> is null, then return the <span>parent directionality</span> of
13573+
<var>element</var>.</p></li>
13574+
13575+
<li><p>Return <var>result</var>.</p></li>
13576+
</ol>
13577+
</dd>
1355913578

1356013579
<dt><span data-x="attr-dir-undefined-state">undefined</span></dt>
1356113580
<dd>
@@ -13598,47 +13617,106 @@ Transport Protocol">HTTP&lt;/abbr> today.&lt;/p></code></pre> <!-- DO NOT REWRAP
1359813617
<li><p>If <var>element</var>'s <span data-x="concept-fe-value">value</span> is not the empty
1359913618
string, then return '<span data-x="concept-ltr">ltr</span>'.</p></li>
1360013619

13601-
<li><p>Return the <span>parent directionality</span> of <var>element</var>.</p></li>
13620+
<li><p>Return null.</p></li>
1360213621
</ol>
1360313622
</li>
1360413623

13605-
<li><p>Let <var>codePoint</var> be null.</p></li>
13624+
<li>
13625+
<p>If <var>element</var> is a <code>slot</code> element whose <span>root</span> is a
13626+
<span>shadow root</span> and <var>element</var>'s <span>assigned nodes</span> are not empty:</p>
13627+
13628+
<ol>
13629+
<li>
13630+
<p><span data-x="list iterate">For each</span> node <var>child</var> of <var>element</var>'s
13631+
<span>assigned nodes</span>:</p>
13632+
13633+
<ol>
13634+
<li><p>Let <var>childDirection</var> be null.</p></li>
13635+
13636+
<li><p>If <var>child</var> is a <code>Text</code> node, then set <var>childDirection</var> to
13637+
the <span>text node directionality</span> of <var>child</var>.</p></li>
13638+
13639+
<li>
13640+
<p>Otherwise:</p>
13641+
13642+
<ol>
13643+
<li><p><span>Assert</span>: <var>child</var> is an <code>Element</code> node.</p></li>
13644+
13645+
<li><p>Set <var>childDirection</var> to the <span>auto directionality</span> of
13646+
<var>child</var>.</p></li>
13647+
</ol>
13648+
</li>
13649+
13650+
<li><p>If <var>childDirection</var> is not null, then return
13651+
<var>childDirection</var>.</p></li>
13652+
</ol>
13653+
</li>
13654+
13655+
<li><p>Return null.</p></li>
13656+
</ol>
13657+
</li>
1360613658

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

1361113664
<ol>
1361213665
<li>
13613-
<p>If <var>text</var> has an ancestor element that is a descendant of <var>element</var> and
13614-
is also one of</p>
13666+
<p>If <var>descendant</var> has an ancestor element that is a descendant of <var>element</var>
13667+
and is also one of</p>
1361513668

1361613669
<ul class="brief">
1361713670
<li>a <code>bdi</code> element</li>
1361813671
<li>a <code>script</code> element</li>
1361913672
<li>a <code>style</code> element</li>
1362013673
<li>a <code>textarea</code> element</li>
13674+
<li>a <code>slot</code> element whose <span>root</span> is a <span>shadow
13675+
root</span></li>
1362113676
<li>an element whose <code data-x="attr-dir">dir</code> attribute is not in the <span
1362213677
data-x="attr-dir-undefined-state">undefined</span> state</li>
1362313678
</ul>
1362413679

1362513680
<p>then <span>continue</span>.</p>
1362613681
</li>
1362713682

13628-
<li><p>If <var>text</var>'s <span data-x="concept-cd-data">data</span> does not contain a code
13629-
point whose bidirectional character type is L, AL, or R, then <span>continue</span>.
13630-
<ref>BIDI</ref></p></li>
13683+
<li>
13684+
<p>If <var>descendant</var> is a <code>slot</code> element whose <span>root</span> is a
13685+
<span>shadow root</span>, then:</p>
1363113686

13632-
<li><p>Set <var>codePoint</var> to the first code point in <var>text</var>'s <span
13633-
data-x="concept-cd-data">data</span> whose bidirectional character type is L, AL, or
13634-
R.</p></li>
13687+
<ol>
13688+
<li><p>Let <var>result</var> be the <span>auto directionality</span> of
13689+
<var>descendant</var>.</p></li>.
13690+
13691+
<li><p>If <var>result</var> is not null, then return <var>result</var>.</p></li>
1363513692

13636-
<li><p><span>Break</span>.</p></li>
13693+
<li><p>Return '<span data-x="concept-ltr">ltr</span>'.</p></li>
13694+
</ol>
13695+
</li>
13696+
13697+
<li><p>If <var>descendant</var> is not a <code>Text</code> node, then
13698+
<span>continue</span>.</p></li>
13699+
13700+
<li><p>Let <var>result</var> be the <span>text node directionality</span> of
13701+
<var>descendant</var>.</li>
13702+
13703+
<li><p>If <var>result</var> is not null, then return <var>result</var>.</p></li>
1363713704
</ol>
1363813705
</li>
1363913706

13640-
<li><p>If <var>codePoint</var> is null, then return the <span>parent directionality</span> of
13641-
<var>element</var>.</p></li>
13707+
<li><p>Return null.</p></li>
13708+
</ol>
13709+
13710+
<p>To compute the <dfn>text node directionality</dfn> given a <code>Text</code> node
13711+
<var>text</var>:</p>
13712+
13713+
<ol>
13714+
<li><p>If <var>text</var>'s <span data-x="concept-cd-data">data</span> does not contain a code
13715+
point whose bidirectional character type is L, AL, or R, then return null.
13716+
<ref>BIDI</ref></p></li>
13717+
13718+
<li><p>Let <var>codePoint</var> be the first code point in <var>text</var>'s <span
13719+
data-x="concept-cd-data">data</span> whose bidirectional character type is L, AL, or R.</p></li>
1364213720

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

1365213730
<ol>
13653-
<li><p>If <var>element</var> has no <span>parent element</span>, then return '<span
13654-
data-x="concept-ltr">ltr</span>'.</p></li>
13731+
<li><p>If <var>element</var> is a <code>slot</code> element whose <span>root</span> is a
13732+
<span>shadow root</span>, then return the <span data-x="the directionality">directionality</span>
13733+
of <var>element</var>'s <span>root</span>'s <span
13734+
data-x="concept-DocumentFragment-host">host</span>.</p></li>
13735+
13736+
<li><p>Let <var>parentNode</var> be <var>element</var>'s parent node.</p></li>
13737+
13738+
<li><p>If <var>parentNode</var> is a <span>shadow root</span>, then return the <span data-x="the
13739+
directionality">directionality</span> of <var>parentNode</var>'s <span
13740+
data-x="concept-DocumentFragment-host">host</span>.</p></li>
13741+
13742+
<li><p>If <var>parentNode</var> is an element, then return the <span data-x="the
13743+
directionality">directionality</span> of <var>parentNode</var>.</p></li>
1365513744

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

1366013748
<div w-nodev>
@@ -129536,15 +129624,16 @@ br[clear=all i], br[clear=both i] { clear: both; }</code></pre>
129536129624

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

129539-
[dir]:dir(ltr), bdi:dir(ltr), input[type=tel i]:dir(ltr) { direction: ltr; }
129540-
[dir]:dir(rtl), bdi:dir(rtl) { direction: rtl; }
129627+
[dir]:dir(ltr), slot:dir(ltr), bdi:dir(ltr), input[type=tel i]:dir(ltr) { direction: ltr; }
129628+
[dir]:dir(rtl), slot:dir(rtl), bdi:dir(rtl) { direction: rtl; }
129541129629

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

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

0 commit comments

Comments
 (0)