AX: cleanup style and naming and code in accessibility search mechanism
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Nov 2011 21:15:55 +0000 (21:15 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 Nov 2011 21:15:55 +0000 (21:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=72570

Reviewed by Beth Dakin.

Cleanup the naming and code style within the element searching mechanism.

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::isAccessibilityObjectSearchMatch):
(WebCore::AccessibilityObject::isAccessibilityTextSearchMatch):
(WebCore::AccessibilityObject::firstAccessibleObjectFromNode):
(WebCore::AccessibilityObject::findMatchingObjects):
* accessibility/AccessibilityObject.h:
* accessibility/mac/WebAccessibilityObjectWrapper.mm:
(-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@100662 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/accessibility/AccessibilityObject.h
Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm

index 59dfc2a..c8200d7 100644 (file)
@@ -1,3 +1,21 @@
+2011-11-17  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: cleanup style and naming and code in accessibility search mechanism
+        https://bugs.webkit.org/show_bug.cgi?id=72570
+
+        Reviewed by Beth Dakin.
+
+        Cleanup the naming and code style within the element searching mechanism.
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::isAccessibilityObjectSearchMatch):
+        (WebCore::AccessibilityObject::isAccessibilityTextSearchMatch):
+        (WebCore::AccessibilityObject::firstAccessibleObjectFromNode):
+        (WebCore::AccessibilityObject::findMatchingObjects):
+        * accessibility/AccessibilityObject.h:
+        * accessibility/mac/WebAccessibilityObjectWrapper.mm:
+        (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:forParameter:]):
+
 2011-11-17  Julien Chaffraix  <jchaffraix@webkit.org>
 
         CSS table with 100% width can overflow their containing block
index 15a691c..2342c8c 100644 (file)
@@ -89,20 +89,20 @@ void AccessibilityObject::detach()
 #endif    
 }
 
-bool AccessibilityObject::isAccessibilityObjectSearchMatch(AccessibilityObject* axObject, AccessibilitySearchPredicate* axSearchPredicate)
+bool AccessibilityObject::isAccessibilityObjectSearchMatch(AccessibilityObject* axObject, AccessibilitySearchCriteria* criteria)
 {
-    if (!axObject || !axSearchPredicate)
+    if (!axObject || !criteria)
         return false;
     
-    switch (axSearchPredicate->axSearchKey) {
+    switch (criteria->searchKey) {
     // The AnyTypeSearchKey matches any non-null AccessibilityObject.
     case AnyTypeSearchKey:
         return true;
         
     case BlockquoteSameLevelSearchKey:
-        return axSearchPredicate->axStartObject
+        return criteria->startObject
             && axObject->isBlockquote()
-            && axObject->blockquoteLevel() == axSearchPredicate->axStartObject->blockquoteLevel();
+            && axObject->blockquoteLevel() == criteria->startObject->blockquoteLevel();
         
     case BlockquoteSearchKey:
         return axObject->isBlockquote();
@@ -120,16 +120,16 @@ bool AccessibilityObject::isAccessibilityObjectSearchMatch(AccessibilityObject*
         return axObject->isControl();
         
     case DifferentTypeSearchKey:
-        return axSearchPredicate->axStartObject
-            && axObject->roleValue() != axSearchPredicate->axStartObject->roleValue();
+        return criteria->startObject
+            && axObject->roleValue() != criteria->startObject->roleValue();
         
     case FontChangeSearchKey:
-        return axSearchPredicate->axStartObject
-            && !axObject->hasSameFont(axSearchPredicate->axStartObject->renderer());
+        return criteria->startObject
+            && !axObject->hasSameFont(criteria->startObject->renderer());
         
     case FontColorChangeSearchKey:
-        return axSearchPredicate->axStartObject
-            && !axObject->hasSameFontColor(axSearchPredicate->axStartObject->renderer());
+        return criteria->startObject
+            && !axObject->hasSameFontColor(criteria->startObject->renderer());
         
     // FIXME: Handle this search key.
     case FrameSearchKey:
@@ -157,9 +157,9 @@ bool AccessibilityObject::isAccessibilityObjectSearchMatch(AccessibilityObject*
         return axObject->headingLevel() == 6;
         
     case HeadingSameLevelSearchKey:
-        return axSearchPredicate->axStartObject
+        return criteria->startObject
             && axObject->isHeading()
-            && axObject->headingLevel() == axSearchPredicate->axStartObject->headingLevel();
+            && axObject->headingLevel() == criteria->startObject->headingLevel();
         
     case HeadingSearchKey:
         return axObject->isHeading();
@@ -189,20 +189,20 @@ bool AccessibilityObject::isAccessibilityObjectSearchMatch(AccessibilityObject*
         return axObject->isRadioGroup();
         
     case SameTypeSearchKey:
-        return axSearchPredicate->axStartObject
-            && axObject->roleValue() == axSearchPredicate->axStartObject->roleValue();
+        return criteria->startObject
+            && axObject->roleValue() == criteria->startObject->roleValue();
         
     case StaticTextSearchKey:
         return axObject->hasStaticText();
         
     case StyleChangeSearchKey:
-        return axSearchPredicate->axStartObject
-            && !axObject->hasSameStyle(axSearchPredicate->axStartObject->renderer());
+        return criteria->startObject
+            && !axObject->hasSameStyle(criteria->startObject->renderer());
         
     case TableSameLevelSearchKey:
-        return axSearchPredicate->axStartObject
+        return criteria->startObject
             && axObject->isAccessibilityTable()
-            && axObject->tableLevel() == axSearchPredicate->axStartObject->tableLevel();
+            && axObject->tableLevel() == criteria->startObject->tableLevel();
         
     case TableSearchKey:
         return axObject->isAccessibilityTable();
@@ -224,12 +224,12 @@ bool AccessibilityObject::isAccessibilityObjectSearchMatch(AccessibilityObject*
     }
 }
 
-bool AccessibilityObject::isAccessibilityTextSearchMatch(AccessibilityObject* axObject, AccessibilitySearchPredicate* axSearchPredicate)
+bool AccessibilityObject::isAccessibilityTextSearchMatch(AccessibilityObject* axObject, AccessibilitySearchCriteria* criteria)
 {
-    if (!axObject || !axSearchPredicate)
+    if (!axObject || !criteria)
         return false;
     
-    return axObject->accessibilityObjectContainsText(axSearchPredicate->searchText);
+    return axObject->accessibilityObjectContainsText(criteria->searchText);
 }
 
 bool AccessibilityObject::accessibilityObjectContainsText(String* text) const
@@ -247,7 +247,6 @@ bool AccessibilityObject::isBlockquote() const
     return node() && node()->hasTagName(blockquoteTag);
 }
 
-
 bool AccessibilityObject::isARIATextControl() const
 {
     return ariaRoleAttribute() == TextAreaRole || ariaRoleAttribute() == TextFieldRole;
@@ -330,8 +329,6 @@ AccessibilityObject* AccessibilityObject::parentObjectUnignored() const
 
 AccessibilityObject* AccessibilityObject::firstAccessibleObjectFromNode(const Node* node)
 {
-    ASSERT(AXObjectCache::accessibilityEnabled());
-
     if (!node)
         return 0;
 
@@ -357,37 +354,42 @@ AccessibilityObject* AccessibilityObject::firstAccessibleObjectFromNode(const No
     return accessibleObject;
 }
 
-void AccessibilityObject::accessibleObjectsWithAccessibilitySearchPredicate(AccessibilitySearchPredicate* axSearchPredicate, AccessibilityChildrenVector& axResults)
+void AccessibilityObject::findMatchingObjects(AccessibilitySearchCriteria* criteria, AccessibilityChildrenVector& results)
 {
-    ASSERT(AXObjectCache::accessibilityEnabled());
+    ASSERT(criteria);
     
-    if (!axSearchPredicate)
+    if (!criteria)
         return;
     
-    AccessibilityChildrenVector axChildren;
-    if (axSearchPredicate->axContainerObject)
-        axChildren.append(axSearchPredicate->axContainerObject);
+    AccessibilityObject* startObject = criteria->startObject;
+    AccessibilityChildrenVector searchStack;
+    searchStack.append(this);
     
-    bool isSearchDirectionNext = (axSearchPredicate->axSearchDirection == SearchDirectionNext);
-    bool didFindAXStartObject = (!axSearchPredicate->axStartObject);
+    bool isForward = criteria->searchDirection == SearchDirectionNext;
+    bool didFindStartObject = !criteria->startObject;
     
     // FIXME: Iterate the AccessibilityObject cache creating and adding objects if nessesary.
-    while (!axChildren.isEmpty() && axResults.size() < axSearchPredicate->resultsLimit) {
-        AccessibilityObject* axChild = axChildren.last().get();
-        axChildren.removeLast();
+    while (!searchStack.isEmpty()) {
+        AccessibilityObject* searchObject = searchStack.last().get();
+        searchStack.removeLast();
         
-        if (didFindAXStartObject) {
-            if (isAccessibilityObjectSearchMatch(axChild, axSearchPredicate)
-                && isAccessibilityTextSearchMatch(axChild, axSearchPredicate))
-                axResults.append(axChild);
-        } else if (axChild == axSearchPredicate->axStartObject)
-            didFindAXStartObject = true;
+        if (didFindStartObject) {
+            if (isAccessibilityObjectSearchMatch(searchObject, criteria) && isAccessibilityTextSearchMatch(searchObject, criteria)) {
+                results.append(searchObject);
+             
+                // Enough results were found to stop searching.
+                if (results.size() >= criteria->resultsLimit)
+                    break;
+            }
+        } else if (searchObject == startObject)
+            didFindStartObject = true;
         
-        AccessibilityChildrenVector axGrandchildren = axChild->children();
-        unsigned axGrandchildrenSize = axChild->children().size();
-        for (unsigned i = (isSearchDirectionNext) ? axGrandchildrenSize : 0; (isSearchDirectionNext) ? i > 0 : i < axGrandchildrenSize; (isSearchDirectionNext) ? i-- : i++)
+        AccessibilityChildrenVector searchChildren = searchObject->children();
+        size_t childrenSize = searchChildren.size();
+        for (size_t i = isForward ? childrenSize : 0; isForward ? i > 0 : i < childrenSize; isForward ? i-- : i++) {
             // FIXME: Handle attachments.
-            axChildren.append(axGrandchildren.at((isSearchDirectionNext) ? i - 1 : i).get());
+            searchStack.append(searchChildren.at(isForward ? i - 1 : i).get());
+        }
     }
 }
 
index b402f3d..bbec914 100644 (file)
@@ -273,11 +273,10 @@ enum AccessibilitySearchKey {
     VisitedLinkSearchKey
 };
 
-struct AccessibilitySearchPredicate {
-    AccessibilityObject* axContainerObject;
-    AccessibilityObject* axStartObject;
-    AccessibilitySearchDirection axSearchDirection;
-    AccessibilitySearchKey axSearchKey;
+struct AccessibilitySearchCriteria {
+    AccessibilityObject* startObject;
+    AccessibilitySearchDirection searchDirection;
+    AccessibilitySearchKey searchKey;
     String* searchText;
     unsigned resultsLimit;
 };
@@ -319,9 +318,6 @@ class AccessibilityObject : public RefCounted<AccessibilityObject> {
 protected:
     AccessibilityObject();
     
-    // Should only be called by accessibleObjectsWithAccessibilitySearchPredicate for AccessibilityObject searching.
-    static bool isAccessibilityObjectSearchMatch(AccessibilityObject*, AccessibilitySearchPredicate*);
-    static bool isAccessibilityTextSearchMatch(AccessibilityObject*, AccessibilitySearchPredicate*);
 public:
     virtual ~AccessibilityObject();
     virtual void detach();
@@ -483,7 +479,7 @@ public:
     virtual AccessibilityObject* parentObjectUnignored() const;
     virtual AccessibilityObject* parentObjectIfExists() const { return 0; }
     static AccessibilityObject* firstAccessibleObjectFromNode(const Node*);
-    static void accessibleObjectsWithAccessibilitySearchPredicate(AccessibilitySearchPredicate*, AccessibilityChildrenVector&);
+    void findMatchingObjects(AccessibilitySearchCriteria*, AccessibilityChildrenVector&);
 
     virtual AccessibilityObject* observableObject() const { return 0; }
     virtual void linkedUIElements(AccessibilityChildrenVector&) const { }
@@ -689,7 +685,9 @@ protected:
     AccessibilityRole m_role;
     
     virtual bool isDetached() const { return true; }
-    
+    static bool isAccessibilityObjectSearchMatch(AccessibilityObject*, AccessibilitySearchCriteria*);
+    static bool isAccessibilityTextSearchMatch(AccessibilityObject*, AccessibilitySearchCriteria*);
+
 #if PLATFORM(GTK)
     bool allowsTextRanges() const;
     unsigned getLengthForTextRange() const;
index 504e8b2..f1b5620 100644 (file)
@@ -2802,17 +2802,17 @@ static RenderObject* rendererForView(NSView* view)
     
     // dispatch
     if ([attribute isEqualToString:NSAccessibilityUIElementsForSearchPredicateParameterizedAttribute]) {
-        AccessibilityObject* axStartObject = 0;
+        AccessibilityObject* startObject = 0;
         if ([[dictionary objectForKey:@"AXStartElement"] isKindOfClass:[WebAccessibilityObjectWrapper self]])
-            axStartObject = [(WebAccessibilityObjectWrapper*)[dictionary objectForKey:@"AXStartElement"] accessibilityObject];
+            startObject = [(WebAccessibilityObjectWrapper*)[dictionary objectForKey:@"AXStartElement"] accessibilityObject];
         
-        AccessibilitySearchDirection axSearchDirection = SearchDirectionNext;
+        AccessibilitySearchDirection searchDirection = SearchDirectionNext;
         if ([[dictionary objectForKey:@"AXDirection"] isKindOfClass:[NSString self]])
-            axSearchDirection = ([(NSString*)[dictionary objectForKey:@"AXDirection"] isEqualToString:@"AXDirectionNext"]) ? SearchDirectionNext : SearchDirectionPrevious;
+            searchDirection = ([(NSString*)[dictionary objectForKey:@"AXDirection"] isEqualToString:@"AXDirectionNext"]) ? SearchDirectionNext : SearchDirectionPrevious;
         
-        AccessibilitySearchKey axSearchKey = AnyTypeSearchKey;
+        AccessibilitySearchKey searchKey = AnyTypeSearchKey;
         if ([[dictionary objectForKey:@"AXSearchKey"] isKindOfClass:[NSString self]])
-            axSearchKey = accessibilitySearchKeyForString((CFStringRef)[dictionary objectForKey:@"AXSearchKey"]);
+            searchKey = accessibilitySearchKeyForString((CFStringRef)[dictionary objectForKey:@"AXSearchKey"]);
         
         String searchText;
         if ([[dictionary objectForKey:@"AXSearchText"] isKindOfClass:[NSString self]])
@@ -2822,11 +2822,12 @@ static RenderObject* rendererForView(NSView* view)
         if ([[dictionary objectForKey:@"AXResultsLimit"] isKindOfClass:[NSNumber self]])
             resultsLimit = [(NSNumber*)[dictionary objectForKey:@"AXResultsLimit"] unsignedIntValue];
         
-        AccessibilitySearchPredicate axSearchPredicate = {m_object, axStartObject, axSearchDirection, axSearchKey, &searchText, resultsLimit};
-        AccessibilityObject::AccessibilityChildrenVector axResults;
-        AccessibilityObject::accessibleObjectsWithAccessibilitySearchPredicate(&axSearchPredicate, axResults);
+        AccessibilitySearchCriteria criteria = {startObject, searchDirection, searchKey, &searchText, resultsLimit};
+
+        AccessibilityObject::AccessibilityChildrenVector results;
+        m_object->findMatchingObjects(&criteria, results);
         
-        return convertToNSArray(axResults);
+        return convertToNSArray(results);
     }
 
     if ([attribute isEqualToString:@"AXUIElementForTextMarker"]) {