<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[197439] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/197439">197439</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2016-03-01 21:31:28 -0800 (Tue, 01 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Contents inside a shadow host with a negative tabindex should not be tab focusable
https://bugs.webkit.org/show_bug.cgi?id=154769

Reviewed by Antti Koivisto.

Source/WebCore:

Contents inside a shadow host with a negative tabindex content attribute should not be included in
the sequential focus navigation order as discussed on https://github.com/w3c/webcomponents/issues/399.

Test: fast/shadow-dom/negative-tabindex-on-shadow-host.html

* dom/Element.cpp:
(WebCore::Element::tabIndexSetExplicitly): Added.
* dom/Element.h:
* page/FocusController.cpp:
(WebCore::shadowAdjustedTabIndex): Renamed from adjustedTabIndex. Return 0 when tabindex content attribute
is not explicitly set since element.tabIndex() would return -1 for HTML elements in such case.
(WebCore::isFocusableOrHasShadowTreeWithoutCustomFocusLogic): Renamed from shouldVisit.
(WebCore::FocusController::findElementWithExactTabIndex):
(WebCore::nextElementWithGreaterTabIndex):
(WebCore::previousElementWithLowerTabIndex):
(WebCore::FocusController::nextFocusableElement):
(WebCore::FocusController::previousFocusableElement):

LayoutTests:

Added a test for navigating across shadow boundaries.

* fast/shadow-dom/negative-tabindex-on-shadow-host-expected.txt: Added.
* fast/shadow-dom/negative-tabindex-on-shadow-host.html: Added.
* platform/ios-simulator/TestExpectations:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformiossimulatorTestExpectations">trunk/LayoutTests/platform/ios-simulator/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomElementcpp">trunk/Source/WebCore/dom/Element.cpp</a></li>
<li><a href="#trunkSourceWebCoredomElementh">trunk/Source/WebCore/dom/Element.h</a></li>
<li><a href="#trunkSourceWebCorepageFocusControllercpp">trunk/Source/WebCore/page/FocusController.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastshadowdomnegativetabindexonshadowhostexpectedtxt">trunk/LayoutTests/fast/shadow-dom/negative-tabindex-on-shadow-host-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastshadowdomnegativetabindexonshadowhosthtml">trunk/LayoutTests/fast/shadow-dom/negative-tabindex-on-shadow-host.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (197438 => 197439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-03-02 04:30:45 UTC (rev 197438)
+++ trunk/LayoutTests/ChangeLog        2016-03-02 05:31:28 UTC (rev 197439)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-02-26  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
+
+        Contents inside a shadow host with a negative tabindex should not be tab focusable
+        https://bugs.webkit.org/show_bug.cgi?id=154769
+
+        Reviewed by Antti Koivisto.
+
+        Added a test for navigating across shadow boundaries.
+
+        * fast/shadow-dom/negative-tabindex-on-shadow-host-expected.txt: Added.
+        * fast/shadow-dom/negative-tabindex-on-shadow-host.html: Added.
+        * platform/ios-simulator/TestExpectations:
+
</ins><span class="cx"> 2016-03-01  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Small-caps non-BMP characters are garbled in the complex text codepath
</span></span></pre></div>
<a id="trunkLayoutTestsfastshadowdomnegativetabindexonshadowhostexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/shadow-dom/negative-tabindex-on-shadow-host-expected.txt (0 => 197439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/shadow-dom/negative-tabindex-on-shadow-host-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/negative-tabindex-on-shadow-host-expected.txt        2016-03-02 05:31:28 UTC (rev 197439)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+Tests for setting a negative tabindex on shadow host. Elements inside such a shadow tree should not be in the sequential navigation order.
+To manually test, press tab key four times. It should traverse focusable elements in the increasing numerical order.
+
+1. First sequentially focusable element outside shadow trees
+2. / 3.2. Shadow host with a positive tabindex
+3.1. Focusable element inside a shadow host with a positive tabindex
+2. / 3.2. Shadow host with a positive tabindex
+4.1. Focusable element inside a shadow host with no tabindex
+4.2. Shadow host with no tabindex
+5. Last sequentially focusable element outside shadow trees
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastshadowdomnegativetabindexonshadowhosthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/shadow-dom/negative-tabindex-on-shadow-host.html (0 => 197439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/shadow-dom/negative-tabindex-on-shadow-host.html                                (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/negative-tabindex-on-shadow-host.html        2016-03-02 05:31:28 UTC (rev 197439)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;body&gt;
+&lt;p&gt;Tests for setting a negative tabindex on shadow host. Elements inside such a shadow tree should not be in the sequential navigation order.&lt;br&gt;
+To manually test, press tab key four times. It should traverse focusable elements in the increasing numerical order.&lt;/p&gt;
+&lt;div id=&quot;test-content&quot;&gt;
+&lt;div id=&quot;first&quot; tabindex=&quot;1&quot; onfocus=&quot;log(this)&quot;&gt;1. First sequentially focusable element outside shadow trees&lt;/div&gt;
+&lt;div id=&quot;host-with-negative-tabindex&quot; tabindex=&quot;-1&quot; onfocus=&quot;log(this)&quot;&gt;Shadow host with a negative tabindex&lt;/div&gt;
+&lt;div id=&quot;host-with-no-tabindex&quot; onfocus=&quot;log(this)&quot;&gt;4.2. Shadow host with no tabindex&lt;/div&gt;
+&lt;div id=&quot;host-with-positive-tabindex&quot; tabindex=&quot;2&quot; onfocus=&quot;log(this)&quot;&gt;2. / 3.2. Shadow host with a positive tabindex&lt;/div&gt;
+&lt;div tabindex=&quot;0&quot; onfocus=&quot;log(this)&quot;&gt;5. Last sequentially focusable element outside shadow trees&lt;/div&gt;
+&lt;/div&gt;
+&lt;pre&gt;&lt;/pre&gt;
+&lt;script&gt;
+
+document.getElementById('host-with-negative-tabindex').attachShadow({mode: 'closed'}).innerHTML = `
+    &lt;div tabindex=&quot;0&quot; onfocus=&quot;log(this)&quot;&gt;Should not be focused as it is inside a shadow host with a negative tabindex&lt;/div&gt;
+`;
+
+document.getElementById('host-with-no-tabindex').attachShadow({mode: 'closed'}).innerHTML = `
+    &lt;div tabindex=&quot;0&quot; onfocus=&quot;log(this)&quot;&gt;4.1. Focusable element inside a shadow host with no tabindex&lt;/div&gt;
+`;
+
+document.getElementById('host-with-positive-tabindex').attachShadow({mode: 'closed'}).innerHTML = `
+    &lt;slot&gt;&lt;/slot&gt;
+    &lt;div tabindex=&quot;0&quot; onfocus=&quot;log(this)&quot;&gt;3.1. Focusable element inside a shadow host with a positive tabindex&lt;/div&gt;
+`;
+
+function log(element) {
+    document.querySelector('pre').textContent += element.textContent + '\n';
+}
+
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+document.getElementById('first').focus();
+
+if (window.eventSender) {
+    eventSender.keyDown('\t');
+    eventSender.keyDown('\t');
+    eventSender.keyDown('\t');
+    eventSender.keyDown('\t');
+    document.getElementById('test-content').style.display = 'none';
+}
+
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformiossimulatorTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (197438 => 197439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/ios-simulator/TestExpectations        2016-03-02 04:30:45 UTC (rev 197438)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations        2016-03-02 05:31:28 UTC (rev 197439)
</span><span class="lines">@@ -235,6 +235,9 @@
</span><span class="cx"> webkit.org/b/149441 fast/shadow-dom/css-scoping-shadow-slotted-rule.html [ ImageOnlyFailure ]
</span><span class="cx"> webkit.org/b/149441 fast/shadow-dom/css-scoping-shadow-slot-display-override.html [ ImageOnlyFailure ]
</span><span class="cx"> 
</span><ins>+# No tab navigation support on iOS
+fast/shadow-dom/negative-tabindex-on-shadow-host.html [ Failure ]
+
</ins><span class="cx"> webkit.org/b/150225 fast/custom-elements [ Pass ]
</span><span class="cx"> 
</span><span class="cx"> # This test needs to be rewritten to use runUIScript to work on iOS
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (197438 => 197439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-02 04:30:45 UTC (rev 197438)
+++ trunk/Source/WebCore/ChangeLog        2016-03-02 05:31:28 UTC (rev 197439)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2016-02-26  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
+
+        Contents inside a shadow host with a negative tabindex should not be tab focusable
+        https://bugs.webkit.org/show_bug.cgi?id=154769
+
+        Reviewed by Antti Koivisto.
+
+        Contents inside a shadow host with a negative tabindex content attribute should not be included in
+        the sequential focus navigation order as discussed on https://github.com/w3c/webcomponents/issues/399.
+
+        Test: fast/shadow-dom/negative-tabindex-on-shadow-host.html
+
+        * dom/Element.cpp:
+        (WebCore::Element::tabIndexSetExplicitly): Added.
+        * dom/Element.h:
+        * page/FocusController.cpp:
+        (WebCore::shadowAdjustedTabIndex): Renamed from adjustedTabIndex. Return 0 when tabindex content attribute
+        is not explicitly set since element.tabIndex() would return -1 for HTML elements in such case.
+        (WebCore::isFocusableOrHasShadowTreeWithoutCustomFocusLogic): Renamed from shouldVisit.
+        (WebCore::FocusController::findElementWithExactTabIndex):
+        (WebCore::nextElementWithGreaterTabIndex):
+        (WebCore::previousElementWithLowerTabIndex):
+        (WebCore::FocusController::nextFocusableElement):
+        (WebCore::FocusController::previousFocusableElement):
+
</ins><span class="cx"> 2016-03-01  Michael Saboff  &lt;msaboff@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (r197426): Missed adding unicode parameter to call to Yarr::parse() in URLFilterParser::addPattern()
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.cpp (197438 => 197439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.cpp        2016-03-02 04:30:45 UTC (rev 197438)
+++ trunk/Source/WebCore/dom/Element.cpp        2016-03-02 05:31:28 UTC (rev 197439)
</span><span class="lines">@@ -212,11 +212,16 @@
</span><span class="cx">     ensureElementRareData().setTabIndexExplicitly(tabIndex);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool Element::supportsFocus() const
</del><ins>+bool Element::tabIndexSetExplicitly() const
</ins><span class="cx"> {
</span><span class="cx">     return hasRareData() &amp;&amp; elementRareData()-&gt;tabIndexSetExplicitly();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool Element::supportsFocus() const
+{
+    return tabIndexSetExplicitly();
+}
+
</ins><span class="cx"> Element* Element::focusDelegate()
</span><span class="cx"> {
</span><span class="cx">     return this;
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.h (197438 => 197439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.h        2016-03-02 04:30:45 UTC (rev 197438)
+++ trunk/Source/WebCore/dom/Element.h        2016-03-02 05:31:28 UTC (rev 197439)
</span><span class="lines">@@ -266,6 +266,7 @@
</span><span class="cx">     virtual void setHovered(bool flag = true);
</span><span class="cx">     virtual void setFocus(bool flag);
</span><span class="cx"> 
</span><ins>+    bool tabIndexSetExplicitly() const;
</ins><span class="cx">     virtual bool supportsFocus() const;
</span><span class="cx">     virtual bool isFocusable() const;
</span><span class="cx">     virtual bool isKeyboardFocusable(KeyboardEvent*) const;
</span></span></pre></div>
<a id="trunkSourceWebCorepageFocusControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FocusController.cpp (197438 => 197439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FocusController.cpp        2016-03-02 04:30:45 UTC (rev 197438)
+++ trunk/Source/WebCore/page/FocusController.cpp        2016-03-02 05:31:28 UTC (rev 197439)
</span><span class="lines">@@ -214,14 +214,16 @@
</span><span class="cx">     return is&lt;Element&gt;(node) &amp;&amp; downcast&lt;Element&gt;(node).isKeyboardFocusable(&amp;event) &amp;&amp; downcast&lt;Element&gt;(node).shadowRoot() &amp;&amp; !hasCustomFocusLogic(downcast&lt;Element&gt;(node));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline int adjustedTabIndex(Node&amp; node, KeyboardEvent&amp; event)
</del><ins>+static inline int shadowAdjustedTabIndex(Element&amp; element, KeyboardEvent&amp; event)
</ins><span class="cx"> {
</span><del>-    if (!is&lt;Element&gt;(node))
-        return 0;
-    return isNonFocusableShadowHost(downcast&lt;Element&gt;(node), event) ? 0 : downcast&lt;Element&gt;(node).tabIndex();
</del><ins>+    if (isNonFocusableShadowHost(element, event)) {
+        if (!element.tabIndexSetExplicitly())
+            return 0; // Treat a shadow host without tabindex if it has tabindex=0 even though HTMLElement::tabIndex returns -1 on such an element.
+    }
+    return element.tabIndex();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline bool shouldVisit(Element&amp; element, KeyboardEvent&amp; event)
</del><ins>+static inline bool isFocusableOrHasShadowTreeWithoutCustomFocusLogic(Element&amp; element, KeyboardEvent&amp; event)
</ins><span class="cx"> {
</span><span class="cx">     return element.isKeyboardFocusable(&amp;event) || isNonFocusableShadowHost(element, event);
</span><span class="cx"> }
</span><span class="lines">@@ -479,7 +481,7 @@
</span><span class="cx">         if (!is&lt;Element&gt;(*node))
</span><span class="cx">             continue;
</span><span class="cx">         Element&amp; element = downcast&lt;Element&gt;(*node);
</span><del>-        if (shouldVisit(element, *event) &amp;&amp; adjustedTabIndex(element, *event) == tabIndex)
</del><ins>+        if (isFocusableOrHasShadowTreeWithoutCustomFocusLogic(element, *event) &amp;&amp; shadowAdjustedTabIndex(element, *event) == tabIndex)
</ins><span class="cx">             return &amp;element;
</span><span class="cx">     }
</span><span class="cx">     return nullptr;
</span><span class="lines">@@ -494,7 +496,7 @@
</span><span class="cx">         if (!is&lt;Element&gt;(*node))
</span><span class="cx">             continue;
</span><span class="cx">         Element&amp; element = downcast&lt;Element&gt;(*node);
</span><del>-        if (shouldVisit(element, event) &amp;&amp; element.tabIndex() &gt; tabIndex &amp;&amp; element.tabIndex() &lt; winningTabIndex) {
</del><ins>+        if (isFocusableOrHasShadowTreeWithoutCustomFocusLogic(element, event) &amp;&amp; element.tabIndex() &gt; tabIndex &amp;&amp; element.tabIndex() &lt; winningTabIndex) {
</ins><span class="cx">             winner = &amp;element;
</span><span class="cx">             winningTabIndex = element.tabIndex();
</span><span class="cx">         }
</span><span class="lines">@@ -512,8 +514,8 @@
</span><span class="cx">         if (!is&lt;Element&gt;(*node))
</span><span class="cx">             continue;
</span><span class="cx">         Element&amp; element = downcast&lt;Element&gt;(*node);
</span><del>-        int currentTabIndex = adjustedTabIndex(element, event);
-        if ((shouldVisit(element, event) || isNonFocusableShadowHost(element, event)) &amp;&amp; currentTabIndex &lt; tabIndex &amp;&amp; currentTabIndex &gt; winningTabIndex) {
</del><ins>+        int currentTabIndex = shadowAdjustedTabIndex(element, event);
+        if ((isFocusableOrHasShadowTreeWithoutCustomFocusLogic(element, event) || isNonFocusableShadowHost(element, event)) &amp;&amp; currentTabIndex &lt; tabIndex &amp;&amp; currentTabIndex &gt; winningTabIndex) {
</ins><span class="cx">             winner = &amp;element;
</span><span class="cx">             winningTabIndex = currentTabIndex;
</span><span class="cx">         }
</span><span class="lines">@@ -535,32 +537,34 @@
</span><span class="cx"> 
</span><span class="cx"> Element* FocusController::nextFocusableElement(const FocusNavigationScope&amp; scope, Node* start, KeyboardEvent* event)
</span><span class="cx"> {
</span><ins>+    int startTabIndex = 0;
+    if (start &amp;&amp; is&lt;Element&gt;(*start))
+        startTabIndex = shadowAdjustedTabIndex(downcast&lt;Element&gt;(*start), *event);
+
</ins><span class="cx">     if (start) {
</span><del>-        int tabIndex = adjustedTabIndex(*start, *event);
</del><span class="cx">         // If a node is excluded from the normal tabbing cycle, the next focusable node is determined by tree order
</span><del>-        if (tabIndex &lt; 0) {
</del><ins>+        if (startTabIndex &lt; 0) {
</ins><span class="cx">             for (Node* node = scope.nextInScope(start); node; node = scope.nextInScope(node)) {
</span><span class="cx">                 if (!is&lt;Element&gt;(*node))
</span><span class="cx">                     continue;
</span><span class="cx">                 Element&amp; element = downcast&lt;Element&gt;(*node);
</span><del>-                if (shouldVisit(element, *event) &amp;&amp; adjustedTabIndex(element, *event) &gt;= 0)
</del><ins>+                if (isFocusableOrHasShadowTreeWithoutCustomFocusLogic(element, *event) &amp;&amp; shadowAdjustedTabIndex(element, *event) &gt;= 0)
</ins><span class="cx">                     return &amp;element;
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // First try to find a node with the same tabindex as start that comes after start in the scope.
</span><del>-        if (Element* winner = findElementWithExactTabIndex(scope, scope.nextInScope(start), tabIndex, event, FocusDirectionForward))
</del><ins>+        if (Element* winner = findElementWithExactTabIndex(scope, scope.nextInScope(start), startTabIndex, event, FocusDirectionForward))
</ins><span class="cx">             return winner;
</span><span class="cx"> 
</span><del>-        if (!tabIndex)
-            // We've reached the last node in the document with a tabindex of 0. This is the end of the tabbing order.
-            return 0;
</del><ins>+        if (!startTabIndex)
+            return nullptr; // We've reached the last node in the document with a tabindex of 0. This is the end of the tabbing order.
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Look for the first Element in the scope that:
</span><span class="cx">     // 1) has the lowest tabindex that is higher than start's tabindex (or 0, if start is null), and
</span><span class="cx">     // 2) comes first in the scope, if there's a tie.
</span><del>-    if (Element* winner = nextElementWithGreaterTabIndex(scope, start ? adjustedTabIndex(*start, *event) : 0, *event))
</del><ins>+    if (Element* winner = nextElementWithGreaterTabIndex(scope, startTabIndex, *event))
</ins><span class="cx">         return winner;
</span><span class="cx"> 
</span><span class="cx">     // There are no nodes with a tabindex greater than start's tabindex,
</span><span class="lines">@@ -578,14 +582,13 @@
</span><span class="cx">     // First try to find the last node in the scope that comes before start and has the same tabindex as start.
</span><span class="cx">     // If start is null, find the last node in the scope with a tabindex of 0.
</span><span class="cx">     Node* startingNode;
</span><del>-    int startingTabIndex;
</del><ins>+    int startingTabIndex = 0;
</ins><span class="cx">     if (start) {
</span><span class="cx">         startingNode = scope.previousInScope(start);
</span><del>-        startingTabIndex = adjustedTabIndex(*start, *event);
-    } else {
</del><ins>+        if (is&lt;Element&gt;(*start))
+            startingTabIndex = shadowAdjustedTabIndex(downcast&lt;Element&gt;(*start), *event);
+    } else
</ins><span class="cx">         startingNode = last;
</span><del>-        startingTabIndex = 0;
-    }
</del><span class="cx"> 
</span><span class="cx">     // However, if a node is excluded from the normal tabbing cycle, the previous focusable node is determined by tree order
</span><span class="cx">     if (startingTabIndex &lt; 0) {
</span><span class="lines">@@ -593,7 +596,7 @@
</span><span class="cx">             if (!is&lt;Element&gt;(*node))
</span><span class="cx">                 continue;
</span><span class="cx">             Element&amp; element = downcast&lt;Element&gt;(*node);
</span><del>-            if (shouldVisit(element, *event) &amp;&amp; adjustedTabIndex(element, *event) &gt;= 0)
</del><ins>+            if (isFocusableOrHasShadowTreeWithoutCustomFocusLogic(element, *event) &amp;&amp; shadowAdjustedTabIndex(element, *event) &gt;= 0)
</ins><span class="cx">                 return &amp;element;
</span><span class="cx">         }
</span><span class="cx">     }
</span></span></pre>
</div>
</div>

</body>
</html>