Title: [288027] trunk/Source/WebCore
Revision
288027
Author
[email protected]
Date
2022-01-14 13:04:10 -0800 (Fri, 14 Jan 2022)

Log Message

AX: AXIsolatedObject::initializeAttributeData should compute AXAncestorFlags if they are unexpectedly uninitialized
https://bugs.webkit.org/show_bug.cgi?id=235189

Reviewed by Andres Gonzalez.

Currently in AXIsolatedObject::initializeAttributeData, we don't store
any ancestor flags if they are unexpectedly uninitialized (i.e. we're
asked to initialize an isolated object for a live AX object that has
not been added to the live AX tree).

Rather than not storing flags and thus creating an isolated object
with incorrect properties, we should do a single traversal to initialize them.
We should have to do this very rarely since we generally expect to be
given live AX objects with initialized flags here (and debug ASSERT that this is the case).

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::computeAncestorFlagsWithTraversal const):
Added.
* accessibility/AccessibilityObject.h:
* accessibility/AccessibilityObjectInterface.h:
(WebCore::Accessibility::enumerateAncestors):
Added.
* accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::initializeAttributeData):
Compute ancestor flags with a single traversal if they are unexpected uninitialized.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288026 => 288027)


--- trunk/Source/WebCore/ChangeLog	2022-01-14 20:43:18 UTC (rev 288026)
+++ trunk/Source/WebCore/ChangeLog	2022-01-14 21:04:10 UTC (rev 288027)
@@ -1,3 +1,31 @@
+2022-01-14  Tyler Wilcock  <[email protected]>
+
+        AX: AXIsolatedObject::initializeAttributeData should compute AXAncestorFlags if they are unexpectedly uninitialized
+        https://bugs.webkit.org/show_bug.cgi?id=235189
+
+        Reviewed by Andres Gonzalez.
+
+        Currently in AXIsolatedObject::initializeAttributeData, we don't store
+        any ancestor flags if they are unexpectedly uninitialized (i.e. we're
+        asked to initialize an isolated object for a live AX object that has
+        not been added to the live AX tree).
+
+        Rather than not storing flags and thus creating an isolated object
+        with incorrect properties, we should do a single traversal to initialize them.
+        We should have to do this very rarely since we generally expect to be
+        given live AX objects with initialized flags here (and debug ASSERT that this is the case).
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::computeAncestorFlagsWithTraversal const):
+        Added.
+        * accessibility/AccessibilityObject.h:
+        * accessibility/AccessibilityObjectInterface.h:
+        (WebCore::Accessibility::enumerateAncestors):
+        Added.
+        * accessibility/isolatedtree/AXIsolatedObject.cpp:
+        (WebCore::AXIsolatedObject::initializeAttributeData):
+        Compute ancestor flags with a single traversal if they are unexpected uninitialized.
+
 2022-01-14  Kimmo Kinnunen  <[email protected]>
 
         MediaPlayerPrivateMediaStreamAVFObjC::m_videoTransform is redundant

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.cpp (288026 => 288027)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2022-01-14 20:43:18 UTC (rev 288026)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.cpp	2022-01-14 21:04:10 UTC (rev 288027)
@@ -146,6 +146,19 @@
     return computedFlags;
 }
 
+OptionSet<AXAncestorFlag> AccessibilityObject::computeAncestorFlagsWithTraversal() const
+{
+    // If this object's flags are initialized, this traversal is unnecessary. Use AccessibilityObject::ancestorFlags() instead.
+    ASSERT(!ancestorFlagsAreInitialized());
+
+    OptionSet<AXAncestorFlag> computedFlags;
+    computedFlags.set(AXAncestorFlag::FlagsInitialized, true);
+    Accessibility::enumerateAncestors<AccessibilityObject>(*this, false, [&] (const AccessibilityObject& ancestor) {
+        computedFlags.add(ancestor.computeAncestorFlags());
+    });
+    return computedFlags;
+}
+
 void AccessibilityObject::initializeAncestorFlags(const OptionSet<AXAncestorFlag>& flags)
 {
     m_ancestorFlags.set(AXAncestorFlag::FlagsInitialized, true);

Modified: trunk/Source/WebCore/accessibility/AccessibilityObject.h (288026 => 288027)


--- trunk/Source/WebCore/accessibility/AccessibilityObject.h	2022-01-14 20:43:18 UTC (rev 288026)
+++ trunk/Source/WebCore/accessibility/AccessibilityObject.h	2022-01-14 21:04:10 UTC (rev 288027)
@@ -94,7 +94,10 @@
 
     void addAncestorFlags(const OptionSet<AXAncestorFlag>& flags) { m_ancestorFlags.add(flags); }
     bool ancestorFlagsAreInitialized() const { return m_ancestorFlags.contains(AXAncestorFlag::FlagsInitialized); }
+    // Computes the flags that this object matches (no traversal is done).
     OptionSet<AXAncestorFlag> computeAncestorFlags() const;
+    // Computes the flags that this object and all ancestors match, traversing all the way to the root.
+    OptionSet<AXAncestorFlag> computeAncestorFlagsWithTraversal() const;
     void initializeAncestorFlags(const OptionSet<AXAncestorFlag>&);
     bool hasAncestorMatchingFlag(AXAncestorFlag) const;
     bool matchesAncestorFlag(AXAncestorFlag) const;

Modified: trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h (288026 => 288027)


--- trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h	2022-01-14 20:43:18 UTC (rev 288026)
+++ trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h	2022-01-14 21:04:10 UTC (rev 288027)
@@ -1641,6 +1641,16 @@
 void findMatchingObjects(AccessibilitySearchCriteria const&, AXCoreObject::AccessibilityChildrenVector&);
 
 template<typename T, typename F>
+void enumerateAncestors(const T& object, bool includeSelf, const F& lambda)
+{
+    if (includeSelf)
+        lambda(object);
+
+    if (auto* parent = object.parentObject())
+        enumerateAncestors(*parent, true, lambda);
+}
+
+template<typename T, typename F>
 void enumerateDescendants(T& object, bool includeSelf, const F& lambda)
 {
     if (includeSelf)

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp (288026 => 288027)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp	2022-01-14 20:43:18 UTC (rev 288026)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp	2022-01-14 21:04:10 UTC (rev 288027)
@@ -76,11 +76,11 @@
     setProperty(AXPropertyName::AccessibilityDescription, object.accessibilityDescription().isolatedCopy());
 
     // For all objects besides the root, the ancestry flags should've been set by now.
-    ASSERT(isRoot ? true : object.ancestorFlagsAreInitialized());
-    auto ancestorFlags = object.ancestorFlags();
-    // Only store the object's ancestor flags if any are set (excluding the "is initialized" flag).
-    if (ancestorFlags ^ AXAncestorFlag::FlagsInitialized)
+    ASSERT(isRoot || object.ancestorFlagsAreInitialized());
+    if (object.ancestorFlagsAreInitialized())
         setProperty(AXPropertyName::AncestorFlags, object.ancestorFlags());
+    else
+        setProperty(AXPropertyName::AncestorFlags, object.computeAncestorFlagsWithTraversal());
 
     setProperty(AXPropertyName::BoundingBoxRect, object.boundingBoxRect());
     setProperty(AXPropertyName::ElementRect, object.elementRect());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to