<!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>[288405] trunk/Source/WebCore</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/288405">288405</a></dd>
<dt>Author</dt> <dd>andresg_22@apple.com</dd>
<dt>Date</dt> <dd>2022-01-22 10:17:10 -0800 (Sat, 22 Jan 2022)</dd>
</dl>

<h3>Log Message</h3>
<pre>Create ancestry of isolated objects instead of generating the entire subtree for an ancestor.
https://bugs.webkit.org/show_bug.cgi?id=235389
<rdar://problem/87803473>

Reviewed by Chris Fleizach.

AXIsolatedTree::updateChildren may be called for an AXObject that has no
corresponding IsolatedObject. That is the case of empty canvas and some
empty div elements. In those cases we were generating the subtree of the
first available ancestor in the isolated tre. This can be expensive
because in some cases the immediate exisiting ancestor was the webarea,
causing the re-generation of the entire isolated tree. With this patch,
only the IsolatedObjects that are missing in the isolated tree are added
to the tree.

* accessibility/isolatedtree/AXIsolatedTree.cpp:
(WebCore::AXIsolatedTree::nodeChangeForObject):
(WebCore::AXIsolatedTree::queueChanges):
The above two methods are added to avoid coude duplication and to be
able to decouple the creation of new isolated objects from the addition
of those objects to the isolated tree.
(WebCore::AXIsolatedTree::createSubtree):
(WebCore::AXIsolatedTree::updateChildren):
* accessibility/isolatedtree/AXIsolatedTree.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreaccessibilityisolatedtreeAXIsolatedTreecpp">trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp</a></li>
<li><a href="#trunkSourceWebCoreaccessibilityisolatedtreeAXIsolatedTreeh">trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (288404 => 288405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2022-01-22 17:26:35 UTC (rev 288404)
+++ trunk/Source/WebCore/ChangeLog      2022-01-22 18:17:10 UTC (rev 288405)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2022-01-22  Andres Gonzalez  <andresg_22@apple.com>
+
+        Create ancestry of isolated objects instead of generating the entire subtree for an ancestor.
+        https://bugs.webkit.org/show_bug.cgi?id=235389
+        <rdar://problem/87803473>
+
+        Reviewed by Chris Fleizach.
+
+        AXIsolatedTree::updateChildren may be called for an AXObject that has no
+        corresponding IsolatedObject. That is the case of empty canvas and some
+        empty div elements. In those cases we were generating the subtree of the
+        first available ancestor in the isolated tre. This can be expensive
+        because in some cases the immediate exisiting ancestor was the webarea,
+        causing the re-generation of the entire isolated tree. With this patch,
+        only the IsolatedObjects that are missing in the isolated tree are added
+        to the tree.
+
+        * accessibility/isolatedtree/AXIsolatedTree.cpp:
+        (WebCore::AXIsolatedTree::nodeChangeForObject):
+        (WebCore::AXIsolatedTree::queueChanges):
+        The above two methods are added to avoid coude duplication and to be
+        able to decouple the creation of new isolated objects from the addition
+        of those objects to the isolated tree.
+        (WebCore::AXIsolatedTree::createSubtree):
+        (WebCore::AXIsolatedTree::updateChildren):
+        * accessibility/isolatedtree/AXIsolatedTree.h:
+
</ins><span class="cx"> 2022-01-22  Oriol Brufau  <obrufau@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         [CSS Cascade Layers] Enable CSSImportRule.layerName for WebKitGTK
</span></span></pre></div>
<a id="trunkSourceWebCoreaccessibilityisolatedtreeAXIsolatedTreecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp (288404 => 288405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp       2022-01-22 17:26:35 UTC (rev 288404)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.cpp  2022-01-22 18:17:10 UTC (rev 288405)
</span><span class="lines">@@ -202,25 +202,20 @@
</span><span class="cx">         updateChildrenIDs(axParent->objectID(), axParent->childrenIDs());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Ref<AXIsolatedObject> AXIsolatedTree::createSubtree(AXCoreObject& axObject, AXID parentID, bool attachWrapper)
</del><ins>+AXIsolatedTree::NodeChange AXIsolatedTree::nodeChangeForObject(AXCoreObject& axObject, AXID parentID, bool attachWrapper)
</ins><span class="cx"> {
</span><del>-    AXTRACE("AXIsolatedTree::createSubtree");
</del><span class="cx">     ASSERT(isMainThread());
</span><span class="cx"> 
</span><del>-    if (!m_creatingSubtree)
-        axObjectCache()->processDeferredChildrenChangedList();
-    SetForScope<bool> creatingSubtree(m_creatingSubtree, true);
</del><ins>+    auto object = AXIsolatedObject::create(axObject, this, parentID);
+    NodeChange nodeChange { object, nullptr };
</ins><span class="cx"> 
</span><del>-    auto object = AXIsolatedObject::create(axObject, this, parentID);
</del><span class="cx">     if (!object->objectID().isValid()) {
</span><span class="cx">         // Either the axObject has an invalid ID or something else went terribly wrong. Don't bother doing anything else.
</span><span class="cx">         ASSERT_NOT_REACHED();
</span><del>-        return object;
</del><ins>+        return nodeChange;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ASSERT(axObject.wrapper());
</span><del>-
-    NodeChange nodeChange { object, nullptr };
</del><span class="cx">     if (attachWrapper)
</span><span class="cx">         object->attachPlatformWrapper(axObject.wrapper());
</span><span class="cx">     else {
</span><span class="lines">@@ -228,6 +223,29 @@
</span><span class="cx">         nodeChange.wrapper = axObject.wrapper();
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    return nodeChange;
+}
+
+void AXIsolatedTree::queueChanges(const NodeChange& nodeChange, Vector<AXID>&& childrenIDs)
+{
+    ASSERT(isMainThread());
+
+    Locker locker { m_changeLogLock };
+    m_pendingAppends.append(nodeChange);
+    updateChildrenIDs(nodeChange.isolatedObject->objectID(), WTFMove(childrenIDs));
+}
+
+Ref<AXIsolatedObject> AXIsolatedTree::createSubtree(AXCoreObject& axObject, AXID parentID, bool attachWrapper)
+{
+    AXTRACE("AXIsolatedTree::createSubtree");
+    ASSERT(isMainThread());
+
+    if (!m_creatingSubtree)
+        axObjectCache()->processDeferredChildrenChangedList();
+    SetForScope<bool> creatingSubtree(m_creatingSubtree, true);
+
+    auto nodeChange = nodeChangeForObject(axObject, parentID, attachWrapper);
+
</ins><span class="cx">     auto axChildren = axObject.children();
</span><span class="cx">     Vector<AXID> childrenIDs;
</span><span class="cx">     childrenIDs.reserveCapacity(axChildren.size());
</span><span class="lines">@@ -236,13 +254,9 @@
</span><span class="cx">         childrenIDs.uncheckedAppend(child->objectID());
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    {
-        Locker locker { m_changeLogLock };
-        m_pendingAppends.append(WTFMove(nodeChange));
-        updateChildrenIDs(object->objectID(), WTFMove(childrenIDs));
-    }
</del><ins>+    queueChanges(nodeChange, WTFMove(childrenIDs));
</ins><span class="cx"> 
</span><del>-    return object;
</del><ins>+    return nodeChange.isolatedObject;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void AXIsolatedTree::updateNode(AXCoreObject& axObject)
</span><span class="lines">@@ -322,12 +336,19 @@
</span><span class="cx">     // is added a new child. So find the closest ancestor of axObject that has
</span><span class="cx">     // an associated isolated object and update its children.
</span><span class="cx">     auto iterator = m_nodeMap.end();
</span><del>-    auto* axAncestor = Accessibility::findAncestor(axObject, true, [&iterator, this] (const AXCoreObject& ancestor) {
</del><ins>+    auto* axAncestor = Accessibility::findAncestor(axObject, true, [&iterator, this] (auto& ancestor) {
</ins><span class="cx">         auto it = m_nodeMap.find(ancestor.objectID());
</span><span class="cx">         if (it != m_nodeMap.end()) {
</span><span class="cx">             iterator = it;
</span><span class="cx">             return true;
</span><span class="cx">         }
</span><ins>+
+        // ancestor has no node in the isolated tree, thus add it.
+        auto* axParent = ancestor.parentObject();
+        AXID axParentID = axParent ? axParent->objectID() : AXID();
+        auto nodeChange = nodeChangeForObject(ancestor, axParentID, true);
+        queueChanges(nodeChange, ancestor.childrenIDs());
+
</ins><span class="cx">         return false;
</span><span class="cx">     });
</span><span class="cx">     if (!axAncestor || !axAncestor->objectID().isValid() || iterator == m_nodeMap.end()) {
</span><span class="lines">@@ -368,9 +389,6 @@
</span><span class="cx">         // Make the children IDs of the isolated object to be the same as the AXObject's.
</span><span class="cx">         Locker locker { m_changeLogLock };
</span><span class="cx">         updateChildrenIDs(axAncestor->objectID(), WTFMove(axChildrenIDs));
</span><del>-    } else {
-        // Nothing was updated. As a last resort, update the subtree.
-        updateSubtree(*axAncestor);
</del><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreaccessibilityisolatedtreeAXIsolatedTreeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h (288404 => 288405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h 2022-01-22 17:26:35 UTC (rev 288404)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h    2022-01-22 18:17:10 UTC (rev 288405)
</span><span class="lines">@@ -386,7 +386,9 @@
</span><span class="cx">     static HashMap<AXIsolatedTreeID, Ref<AXIsolatedTree>>& treeIDCache() WTF_REQUIRES_LOCK(s_cacheLock);
</span><span class="cx">     static HashMap<PageIdentifier, Ref<AXIsolatedTree>>& treePageCache() WTF_REQUIRES_LOCK(s_cacheLock);
</span><span class="cx"> 
</span><del>-    // Call on main thread
</del><ins>+    // Called on main thread.
+    NodeChange nodeChangeForObject(AXCoreObject&, AXID parentID, bool attachWrapper);
+    void queueChanges(const NodeChange&, Vector<AXID>&& childrenIDs);
</ins><span class="cx">     Ref<AXIsolatedObject> createSubtree(AXCoreObject&, AXID parentID, bool attachWrapper);
</span><span class="cx">     // Called on main thread to update both m_nodeMap and m_pendingChildrenUpdates.
</span><span class="cx">     void updateChildrenIDs(AXID parentID, Vector<AXID>&& childrenIDs) WTF_REQUIRES_LOCK(m_changeLogLock);
</span></span></pre>
</div>
</div>

</body>
</html>