Make dir=auto fall back to the parent's directionality rather than ltr.

When dir=auto fails to find text with strong directionality (or a <slot>
element) to determine the directionality of the element, it should fall
back to the directionality that it would have inherited from its parent
(or, for <slot>, its shadow host) rather than falling back to ltr.

This requires updating directionality invalidation to account for the
possibility that elements with dir=auto can inherit directionality.

This is based on the proposed behavior described in:
https://github.com/whatwg/html/issues/3699#issuecomment-951423468
which is in the process of being specified in:
https://github.com/whatwg/html/pull/9554
https://github.com/whatwg/html/pull/9796

This is one of two changes needed to fix the failure of:
external/wpt/html/dom/elements/global-attributes/dir-shadow-41.html
in the still-unlanded WPT PR at
https://github.com/web-platform-tests/wpt/pull/29820

Bug: 576815
Change-Id: I9fc7c85875074ad41704ab45ec70c7632c3f8d31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4805163
Commit-Queue: David Baron <dbaron@chromium.org>
Reviewed-by: Di Zhang <dizhangg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1202893}
diff --git a/html/dom/elements/global-attributes/dir_auto-N-EN-ref.html b/html/dom/elements/global-attributes/dir_auto-N-EN-ref.html
index 496d699..0d938b2 100644
--- a/html/dom/elements/global-attributes/dir_auto-N-EN-ref.html
+++ b/html/dom/elements/global-attributes/dir_auto-N-EN-ref.html
@@ -10,7 +10,7 @@
     <meta name="assert" content="
       When dir='auto', the direction is set according to the first strong character
       of the text, ignoring neutrals and numbers.
-      If there is no strong character, as in this test, the direction defaults to LTR." />
+      If there is no strong character, as in this test, the direction defaults to the parent." />
     <style>
       input, textarea {
         font-size:1em;
@@ -35,7 +35,7 @@
         <p dir="ltr">@123!</p>
       </div>
       <div dir="rtl">
-        <p dir="ltr">@123!</p>
+        <p dir="rtl">@123!</p>
       </div>
     </div>
     <div class="ref">
@@ -43,7 +43,7 @@
         <p dir="ltr">@123!</p>
       </div>
       <div dir="rtl">
-        <p dir="ltr">@123!</p>
+        <p dir="rtl">@123!</p>
       </div>
     </div>
   </body>
diff --git a/html/dom/elements/global-attributes/dir_auto-N-EN.html b/html/dom/elements/global-attributes/dir_auto-N-EN.html
index 5d948d3..467b4d0 100644
--- a/html/dom/elements/global-attributes/dir_auto-N-EN.html
+++ b/html/dom/elements/global-attributes/dir_auto-N-EN.html
@@ -11,7 +11,7 @@
     <meta name="assert" content="
       When dir='auto', the direction is set according to the first strong character
       of the text, ignoring neutrals and numbers.
-      If there is no strong character, as in this test, the direction defaults to LTR." />
+      If there is no strong character, as in this test, the direction defaults to the parent." />
     <style>
       input, textarea {
         font-size:1em;
@@ -44,7 +44,7 @@
         <p dir="ltr">@123!</p>
       </div>
       <div dir="rtl">
-        <p dir="ltr">@123!</p>
+        <p dir="rtl">@123!</p>
       </div>
     </div>
   </body>