<!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>[210265] 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/210265">210265</a></dd>
<dt>Author</dt> <dd>n_wang@apple.com</dd>
<dt>Date</dt> <dd>2017-01-03 19:07:03 -0800 (Tue, 03 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>AX: Focus should jump into modal dialogs when one appears
https://bugs.webkit.org/show_bug.cgi?id=166670

Reviewed by Chris Fleizach.

Source/WebCore:

Added a timer to let focus jump into a modal dialog if the web
author didn't handle the focus movement.

Test: accessibility/mac/aria-modal-auto-focus.html

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::AXObjectCache):
(WebCore::AXObjectCache::~AXObjectCache):
(WebCore::firstFocusableChild):
(WebCore::AXObjectCache::focusAriaModalNode):
(WebCore::AXObjectCache::focusAriaModalNodeTimerFired):
(WebCore::AXObjectCache::handleAriaModalChange):
* accessibility/AXObjectCache.h:
(WebCore::AXObjectCache::focusAriaModalNode):

LayoutTests:

* accessibility/mac/aria-modal-auto-focus-expected.txt: Added.
* accessibility/mac/aria-modal-auto-focus.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreaccessibilityAXObjectCachecpp">trunk/Source/WebCore/accessibility/AXObjectCache.cpp</a></li>
<li><a href="#trunkSourceWebCoreaccessibilityAXObjectCacheh">trunk/Source/WebCore/accessibility/AXObjectCache.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsaccessibilitymacariamodalautofocusexpectedtxt">trunk/LayoutTests/accessibility/mac/aria-modal-auto-focus-expected.txt</a></li>
<li><a href="#trunkLayoutTestsaccessibilitymacariamodalautofocushtml">trunk/LayoutTests/accessibility/mac/aria-modal-auto-focus.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (210264 => 210265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2017-01-04 02:10:55 UTC (rev 210264)
+++ trunk/LayoutTests/ChangeLog        2017-01-04 03:07:03 UTC (rev 210265)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2017-01-03  Nan Wang  &lt;n_wang@apple.com&gt;
+
+        AX: Focus should jump into modal dialogs when one appears
+        https://bugs.webkit.org/show_bug.cgi?id=166670
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/mac/aria-modal-auto-focus-expected.txt: Added.
+        * accessibility/mac/aria-modal-auto-focus.html: Added.
+
</ins><span class="cx"> 2017-01-03  Brian Burg  &lt;bburg@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: WrappedPromise constructor should behave like the Promise constructor
</span></span></pre></div>
<a id="trunkLayoutTestsaccessibilitymacariamodalautofocusexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/accessibility/mac/aria-modal-auto-focus-expected.txt (0 => 210265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/accessibility/mac/aria-modal-auto-focus-expected.txt                                (rev 0)
+++ trunk/LayoutTests/accessibility/mac/aria-modal-auto-focus-expected.txt        2017-01-04 03:07:03 UTC (rev 210265)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+This tests that focus will automatically move to aria-modal dialogs
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS backgroundAccessible() is true
+PASS newBtn.isFocused is true
+PASS closeBtn.isFocused is true
+PASS okBtn.isFocused is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Other page content with a dummy focusable element
+
+Display a dialog
+
+Just an example.
+
+OK  New
</ins></span></pre></div>
<a id="trunkLayoutTestsaccessibilitymacariamodalautofocushtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/accessibility/mac/aria-modal-auto-focus.html (0 => 210265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/accessibility/mac/aria-modal-auto-focus.html                                (rev 0)
+++ trunk/LayoutTests/accessibility/mac/aria-modal-auto-focus.html        2017-01-04 03:07:03 UTC (rev 210265)
</span><span class="lines">@@ -0,0 +1,95 @@
</span><ins>+&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML//EN&quot;&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+
+&lt;style&gt;
+.box-hidden {
+    display: none;
+}
+&lt;/style&gt;
+
+&lt;body id=&quot;body&quot;&gt;
+
+&lt;div id=&quot;bg&quot;&gt;
+&lt;p id=&quot;bgContent&quot;&gt;Other page content with &lt;a href=&quot;#&quot;&gt;a dummy focusable element&lt;/a&gt;&lt;/p&gt;
+&lt;p&gt;&lt;a onclick=&quot;toggleDialog(document.getElementById('box'),'show'); document.getElementById('new').focus(); return false;&quot; href=&quot;#&quot; role=&quot;button&quot; id=&quot;displayBtn&quot;&gt;Display a dialog&lt;/a&gt;&lt;/p&gt;
+&lt;/div&gt;
+
+&lt;div role=&quot;dialog&quot; aria-labelledby=&quot;myDialog&quot; id=&quot;box&quot; class=&quot;box-hidden&quot; tabindex=&quot;-1&quot; aria-modal=&quot;false&quot;&gt;
+    &lt;h3 id=&quot;myDialog&quot;&gt;Just an example.&lt;/h3&gt;
+    &lt;button id=&quot;ok&quot; onclick=&quot;toggleDialog(document.getElementById('box'),'hide');&quot; class=&quot;close-button&quot;&gt;OK&lt;/button&gt;
+    &lt;button onclick=&quot;toggleDialog(document.getElementById('box2'),'show');&quot; id=&quot;new&quot;&gt;New&lt;/button&gt;
+&lt;/div&gt;
+
+&lt;div role=&quot;dialog&quot; aria-labelledby=&quot;myDialog2&quot; id=&quot;box2&quot; class=&quot;box-hidden&quot; tabindex=&quot;-1&quot;&gt;
+    &lt;h3 id=&quot;myDialog2&quot;&gt;Another dialog.&lt;/h3&gt;
+    &lt;button id=&quot;close&quot; onclick=&quot;toggleDialog(document.getElementById('box2'),'hide');&quot; class=&quot;close-button&quot;&gt;Close&lt;/button&gt;
+&lt;/div&gt;
+
+
+&lt;script&gt;
+
+    description(&quot;This tests that focus will automatically move to aria-modal dialogs&quot;);
+
+    if (window.accessibilityController) {
+        window.jsTestIsAsync = true;
+
+        shouldBeTrue(&quot;backgroundAccessible()&quot;);
+        var newBtn;
+        var okBtn;
+        var closeBtn;
+        
+        // 1. Click the display button, dialog1 shows and focus shouldn't move since we have
+        // javascript code to focus on the &quot;new&quot; button.
+        document.getElementById(&quot;displayBtn&quot;).click();
+        newBtn = accessibilityController.accessibleElementById(&quot;new&quot;);
+        setTimeout(function(){ 
+            shouldBeTrue(&quot;newBtn.isFocused&quot;);
+            
+            // 2. Click the new button, dialog2 shows and focus should move to the close button.
+            document.getElementById(&quot;new&quot;).click();
+            closeBtn = accessibilityController.accessibleElementById(&quot;close&quot;);
+            setTimeout(function(){ 
+                shouldBeTrue(&quot;closeBtn.isFocused&quot;);
+                
+                // 3. Click the close button, dialog2 closes and focus should go back to the
+                // first focusable child of dialog1.
+                document.getElementById(&quot;close&quot;).click();
+                okBtn = accessibilityController.accessibleElementById(&quot;ok&quot;);
+                setTimeout(function(){
+                    shouldBeTrue(&quot;okBtn.isFocused&quot;);
+                    finishJSTest();
+                }, 50);
+            }, 50);
+        }, 50);
+    }
+    
+    function backgroundAccessible() {
+        var displayBtn = accessibilityController.accessibleElementById(&quot;displayBtn&quot;);
+        var bgContent = accessibilityController.accessibleElementById(&quot;bgContent&quot;);
+        
+        if (!displayBtn || !bgContent)
+            return false;
+        
+        return !displayBtn.isIgnored &amp;&amp; !bgContent.isIgnored;
+    }
+    
+    function toggleDialog(dialog, sh) {
+        if (sh == &quot;show&quot;) {
+            // show the dialog 
+            dialog.style.display = 'block';
+            dialog.setAttribute(&quot;aria-modal&quot;, &quot;true&quot;);
+        } else {
+            dialog.style.display = 'none';
+            dialog.setAttribute(&quot;aria-modal&quot;, &quot;false&quot;); 
+        }
+    }
+
+&lt;/script&gt;
+
+
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (210264 => 210265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-04 02:10:55 UTC (rev 210264)
+++ trunk/Source/WebCore/ChangeLog        2017-01-04 03:07:03 UTC (rev 210265)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2017-01-03  Nan Wang  &lt;n_wang@apple.com&gt;
+
+        AX: Focus should jump into modal dialogs when one appears
+        https://bugs.webkit.org/show_bug.cgi?id=166670
+
+        Reviewed by Chris Fleizach.
+
+        Added a timer to let focus jump into a modal dialog if the web
+        author didn't handle the focus movement.
+
+        Test: accessibility/mac/aria-modal-auto-focus.html
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::AXObjectCache::AXObjectCache):
+        (WebCore::AXObjectCache::~AXObjectCache):
+        (WebCore::firstFocusableChild):
+        (WebCore::AXObjectCache::focusAriaModalNode):
+        (WebCore::AXObjectCache::focusAriaModalNodeTimerFired):
+        (WebCore::AXObjectCache::handleAriaModalChange):
+        * accessibility/AXObjectCache.h:
+        (WebCore::AXObjectCache::focusAriaModalNode):
+
</ins><span class="cx"> 2017-01-03  Andy Estes  &lt;aestes@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Rename SharedBufferMac.mm to SharedBufferCocoa.mm
</span></span></pre></div>
<a id="trunkSourceWebCoreaccessibilityAXObjectCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/accessibility/AXObjectCache.cpp (210264 => 210265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/accessibility/AXObjectCache.cpp        2017-01-04 02:10:55 UTC (rev 210264)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.cpp        2017-01-04 03:07:03 UTC (rev 210265)
</span><span class="lines">@@ -112,6 +112,7 @@
</span><span class="cx"> // Post value change notifications for password fields or elements contained in password fields at a 40hz interval to thwart analysis of typing cadence
</span><span class="cx"> static double AccessibilityPasswordValueChangeNotificationInterval = 0.025;
</span><span class="cx"> static double AccessibilityLiveRegionChangedNotificationInterval = 0.020;
</span><ins>+static double AccessibilityFocusAriaModalNodeNotificationInterval = 0.050;
</ins><span class="cx"> 
</span><span class="cx"> AccessibilityObjectInclusion AXComputedObjectAttributeCache::getIgnored(AXID id) const
</span><span class="cx"> {
</span><span class="lines">@@ -187,6 +188,7 @@
</span><span class="cx">     , m_notificationPostTimer(*this, &amp;AXObjectCache::notificationPostTimerFired)
</span><span class="cx">     , m_passwordNotificationPostTimer(*this, &amp;AXObjectCache::passwordNotificationPostTimerFired)
</span><span class="cx">     , m_liveRegionChangedPostTimer(*this, &amp;AXObjectCache::liveRegionChangedNotificationPostTimerFired)
</span><ins>+    , m_focusAriaModalNodeTimer(*this, &amp;AXObjectCache::focusAriaModalNodeTimerFired)
</ins><span class="cx">     , m_currentAriaModalNode(nullptr)
</span><span class="cx"> {
</span><span class="cx">     findAriaModalNodes();
</span><span class="lines">@@ -196,6 +198,7 @@
</span><span class="cx"> {
</span><span class="cx">     m_notificationPostTimer.stop();
</span><span class="cx">     m_liveRegionChangedPostTimer.stop();
</span><ins>+    m_focusAriaModalNodeTimer.stop();
</ins><span class="cx"> 
</span><span class="cx">     for (const auto&amp; object : m_objects.values()) {
</span><span class="cx">         detachWrapper(object.get(), CacheDestroyed);
</span><span class="lines">@@ -1350,6 +1353,44 @@
</span><span class="cx">     m_liveRegionObjectsSet.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static AccessibilityObject* firstFocusableChild(AccessibilityObject* obj)
+{
+    if (!obj)
+        return nullptr;
+    
+    for (auto* child = obj-&gt;firstChild(); child; child = child-&gt;nextSibling()) {
+        if (child-&gt;canSetFocusAttribute())
+            return child;
+        if (AccessibilityObject* focusable = firstFocusableChild(child))
+            return focusable;
+    }
+    return nullptr;
+}
+
+void AXObjectCache::focusAriaModalNode()
+{
+    if (m_focusAriaModalNodeTimer.isActive())
+        m_focusAriaModalNodeTimer.stop();
+    
+    m_focusAriaModalNodeTimer.startOneShot(AccessibilityFocusAriaModalNodeNotificationInterval);
+}
+
+void AXObjectCache::focusAriaModalNodeTimerFired()
+{
+    if (!m_currentAriaModalNode)
+        return;
+    
+    // Don't set focus if we are already focusing onto some element within
+    // the dialog.
+    if (m_currentAriaModalNode-&gt;contains(document().focusedElement()))
+        return;
+    
+    if (AccessibilityObject* currentAriaModalNodeObject = getOrCreate(m_currentAriaModalNode)) {
+        if (AccessibilityObject* focusable = firstFocusableChild(currentAriaModalNodeObject))
+            focusable-&gt;setFocused(true);
+    }
+}
+
</ins><span class="cx"> void AXObjectCache::handleScrollbarUpdate(ScrollView* view)
</span><span class="cx"> {
</span><span class="cx">     if (!view)
</span><span class="lines">@@ -1439,6 +1480,9 @@
</span><span class="cx">         m_ariaModalNodesSet.remove(node);
</span><span class="cx">         updateCurrentAriaModalNode();
</span><span class="cx">     }
</span><ins>+    if (m_currentAriaModalNode)
+        focusAriaModalNode();
+    
</ins><span class="cx">     startCachingComputedObjectAttributesUntilTreeMutates();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreaccessibilityAXObjectCacheh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/accessibility/AXObjectCache.h (210264 => 210265)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/accessibility/AXObjectCache.h        2017-01-04 02:10:55 UTC (rev 210264)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.h        2017-01-04 03:07:03 UTC (rev 210265)
</span><span class="lines">@@ -302,6 +302,7 @@
</span><span class="cx">     void postTextStateChangeNotification(Node*, const AXTextStateChangeIntent&amp;, const VisibleSelection&amp;);
</span><span class="cx">     void postTextStateChangeNotification(const Position&amp;, const AXTextStateChangeIntent&amp;, const VisibleSelection&amp;);
</span><span class="cx">     void postLiveRegionChangeNotification(AccessibilityObject*);
</span><ins>+    void focusAriaModalNode();
</ins><span class="cx"> 
</span><span class="cx">     enum AXLoadingEvent {
</span><span class="cx">         AXLoadingStarted,
</span><span class="lines">@@ -382,6 +383,8 @@
</span><span class="cx">     void notificationPostTimerFired();
</span><span class="cx"> 
</span><span class="cx">     void liveRegionChangedNotificationPostTimerFired();
</span><ins>+    
+    void focusAriaModalNodeTimerFired();
</ins><span class="cx"> 
</span><span class="cx">     void postTextStateChangeNotification(AccessibilityObject*, const AXTextStateChangeIntent&amp;, const VisibleSelection&amp;);
</span><span class="cx"> 
</span><span class="lines">@@ -419,6 +422,7 @@
</span><span class="cx">     Timer m_liveRegionChangedPostTimer;
</span><span class="cx">     ListHashSet&lt;RefPtr&lt;AccessibilityObject&gt;&gt; m_liveRegionObjectsSet;
</span><span class="cx">     
</span><ins>+    Timer m_focusAriaModalNodeTimer;
</ins><span class="cx">     Node* m_currentAriaModalNode;
</span><span class="cx">     ListHashSet&lt;Node*&gt; m_ariaModalNodesSet;
</span><span class="cx"> 
</span><span class="lines">@@ -495,6 +499,7 @@
</span><span class="cx"> inline void AXObjectCache::postNotification(Node*, AXNotification, PostTarget, PostType) { }
</span><span class="cx"> inline void AXObjectCache::postPlatformNotification(AccessibilityObject*, AXNotification) { }
</span><span class="cx"> inline void AXObjectCache::postLiveRegionChangeNotification(AccessibilityObject*) { }
</span><ins>+inline void AXObjectCache::focusAriaModalNode() { }
</ins><span class="cx"> inline RefPtr&lt;Range&gt; AXObjectCache::rangeForNodeContents(Node*) { return nullptr; }
</span><span class="cx"> inline void AXObjectCache::remove(AXID) { }
</span><span class="cx"> inline void AXObjectCache::remove(RenderObject*) { }
</span></span></pre>
</div>
</div>

</body>
</html>