AX: attributed strings do not include AXHeading information when a link is contained...
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Dec 2011 18:03:10 +0000 (18:03 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Dec 2011 18:03:10 +0000 (18:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=75059

Reviewed by Darin Adler.

Source/WebCore:

An attributed string should contain the heading level of an ancestor node if it exists.
This change allows the ancestor to be higher up in the hierarchy than just the direct parent.

Test: platform/mac/accessibility/heading-and-link-attributed-string.html

* accessibility/mac/WebAccessibilityObjectWrapper.mm:
  (AXAttributeStringSetHeadingLevel):

Tools:

Support the ability to check if an arbitrary attribute is present within an
attributed string that can be retrieved through an AccessibilityTextMarkerRange.

* DumpRenderTree/AccessibilityUIElement.cpp:
(attributedStringForTextMarkerRangeContainsAttributeCallback):
(AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):
(AccessibilityUIElement::getJSClass):
* DumpRenderTree/AccessibilityUIElement.h:
* DumpRenderTree/mac/AccessibilityUIElementMac.mm:
(AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):
* WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp:
(WTR::AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):
* WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
* WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
* WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
(WTR::AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):

LayoutTests:

* platform/mac/accessibility/heading-and-link-attributed-string-expected.txt: Added.
* platform/mac/accessibility/heading-and-link-attributed-string.html: Added.

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

LayoutTests/ChangeLog
Source/WebCore/ChangeLog
Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm
Tools/ChangeLog
Tools/DumpRenderTree/AccessibilityUIElement.cpp
Tools/DumpRenderTree/AccessibilityUIElement.h
Tools/DumpRenderTree/mac/AccessibilityUIElementMac.mm
Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp
Tools/WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h
Tools/WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl
Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm

index 7637546..a9cc9c0 100644 (file)
@@ -1,5 +1,15 @@
 2011-12-22  Chris Fleizach  <cfleizach@apple.com>
 
+        AX: attributed strings do not include AXHeading information when a link is contained within the heading
+        https://bugs.webkit.org/show_bug.cgi?id=75059
+
+        Reviewed by Darin Adler.
+
+        * platform/mac/accessibility/heading-and-link-attributed-string-expected.txt: Added.
+        * platform/mac/accessibility/heading-and-link-attributed-string.html: Added.
+
+2011-12-22  Chris Fleizach  <cfleizach@apple.com>
+
         AX: Title attribute should not be used in AXTitle
         https://bugs.webkit.org/show_bug.cgi?id=75027
 
index 33b1493..af95024 100644 (file)
@@ -1,5 +1,20 @@
 2011-12-22  Chris Fleizach  <cfleizach@apple.com>
 
+        AX: attributed strings do not include AXHeading information when a link is contained within the heading
+        https://bugs.webkit.org/show_bug.cgi?id=75059
+
+        Reviewed by Darin Adler.
+
+        An attributed string should contain the heading level of an ancestor node if it exists.
+        This change allows the ancestor to be higher up in the hierarchy than just the direct parent.
+
+        Test: platform/mac/accessibility/heading-and-link-attributed-string.html
+
+        * accessibility/mac/WebAccessibilityObjectWrapper.mm:
+          (AXAttributeStringSetHeadingLevel):
+
+2011-12-22  Chris Fleizach  <cfleizach@apple.com>
+
         AX: Title attribute should not be used in AXTitle
         https://bugs.webkit.org/show_bug.cgi?id=75027
 
index 774af3f..13c3e61 100644 (file)
@@ -731,8 +731,15 @@ static void AXAttributeStringSetHeadingLevel(NSMutableAttributedString* attrStri
     if (!renderer)
         return;
     
+    // Sometimes there are objects between the text and the heading. 
+    // In those cases the parent hierarchy should be queried to see if there is a heading level.
+    int parentHeadingLevel = 0;
     AccessibilityObject* parentObject = renderer->document()->axObjectCache()->getOrCreate(renderer->parent());
-    int parentHeadingLevel = parentObject->headingLevel();
+    for (; parentObject; parentObject = parentObject->parentObject()) {
+        parentHeadingLevel = parentObject->headingLevel();
+        if (parentHeadingLevel)
+            break;
+    }
     
     if (parentHeadingLevel)
         [attrString addAttribute:@"AXHeadingLevel" value:[NSNumber numberWithInt:parentHeadingLevel] range:range];
index 3345867..e0c5636 100644 (file)
@@ -1,3 +1,27 @@
+2011-12-22  Chris Fleizach  <cfleizach@apple.com>
+
+        AX: attributed strings do not include AXHeading information when a link is contained within the heading
+        https://bugs.webkit.org/show_bug.cgi?id=75059
+
+        Reviewed by Darin Adler.
+
+        Support the ability to check if an arbitrary attribute is present within an
+        attributed string that can be retrieved through an AccessibilityTextMarkerRange.
+
+        * DumpRenderTree/AccessibilityUIElement.cpp:
+        (attributedStringForTextMarkerRangeContainsAttributeCallback):
+        (AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):
+        (AccessibilityUIElement::getJSClass):
+        * DumpRenderTree/AccessibilityUIElement.h:
+        * DumpRenderTree/mac/AccessibilityUIElementMac.mm:
+        (AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):
+        * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.cpp:
+        (WTR::AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):
+        * WebKitTestRunner/InjectedBundle/AccessibilityUIElement.h:
+        * WebKitTestRunner/InjectedBundle/Bindings/AccessibilityUIElement.idl:
+        * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+        (WTR::AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute):
+
 2011-12-22  David Kilzer  <ddkilzer@apple.com>
 
         run-api-tests: runAllTests() and runTest() should not use global variables
index ddb37b8..67fc4d7 100644 (file)
@@ -492,6 +492,22 @@ static JSValueRef textMarkerRangeForElementCallback(JSContextRef context, JSObje
     return AccessibilityTextMarkerRange::makeJSAccessibilityTextMarkerRange(context, toAXElement(thisObject)->textMarkerRangeForElement(uiElement));
 }
 
+static JSValueRef attributedStringForTextMarkerRangeContainsAttributeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    AccessibilityTextMarkerRange* markerRange = 0;
+    JSStringRef attribute = 0;
+    if (argumentCount == 2) {
+        attribute = JSValueToStringCopy(context, arguments[0], exception);
+        markerRange = toTextMarkerRange(JSValueToObject(context, arguments[1], exception));
+    }
+    
+    JSValueRef result = JSValueMakeBoolean(context, toAXElement(thisObject)->attributedStringForTextMarkerRangeContainsAttribute(attribute, markerRange));
+    if (attribute)
+        JSStringRelease(attribute);
+    
+    return result;    
+}
+
 static JSValueRef textMarkerRangeLengthCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     AccessibilityTextMarkerRange* range = 0;
@@ -949,6 +965,11 @@ JSStringRef AccessibilityUIElement::stringForTextMarkerRange(AccessibilityTextMa
     return 0;
 }
 
+bool AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute(JSStringRef, AccessibilityTextMarkerRange*)
+{
+    return false;
+}
+
 #endif
 
 // Destruction
@@ -1076,6 +1097,7 @@ JSClassRef AccessibilityUIElement::getJSClass()
         { "addSelection", addSelectionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "removeSelection", removeSelectionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "textMarkerRangeForElement", textMarkerRangeForElementCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "attributedStringForTextMarkerRangeContainsAttribute", attributedStringForTextMarkerRangeContainsAttributeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "textMarkerRangeForMarkers", textMarkerRangeForMarkersCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "startTextMarkerForTextMarkerRange", startTextMarkerForTextMarkerRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "endTextMarkerForTextMarkerRange", endTextMarkerForTextMarkerRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index 4e204c7..38d35cf 100644 (file)
@@ -215,6 +215,7 @@ public:
     AccessibilityUIElement accessibilityElementForTextMarker(AccessibilityTextMarker*);
     JSStringRef stringForTextMarkerRange(AccessibilityTextMarkerRange*);
     int textMarkerRangeLength(AccessibilityTextMarkerRange*);
+    bool attributedStringForTextMarkerRangeContainsAttribute(JSStringRef, AccessibilityTextMarkerRange*);
     
     // Notifications
     // Function callback should take one argument, the name of the notification.
index c34fcee..9360ef1 100644 (file)
@@ -1295,6 +1295,21 @@ int AccessibilityUIElement::textMarkerRangeLength(AccessibilityTextMarkerRange*
     return 0;
 }
 
+bool AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute(JSStringRef attribute, AccessibilityTextMarkerRange* range)
+{
+    BEGIN_AX_OBJC_EXCEPTIONS
+    NSAttributedString* string = [m_element accessibilityAttributeValue:@"AXAttributedStringForTextMarkerRange" forParameter:(id)range->platformTextMarkerRange()];
+    if (![string isKindOfClass:[NSAttributedString class]])
+        return false;
+    
+    NSDictionary* attrs = [string attributesAtIndex:0 effectiveRange:nil];
+    if ([attrs objectForKey:[NSString stringWithJSStringRef:attribute]])
+        return true;    
+    END_AX_OBJC_EXCEPTIONS
+    
+    return false;
+}
+
 AccessibilityTextMarker AccessibilityUIElement::previousTextMarker(AccessibilityTextMarker* textMarker)
 {
     BEGIN_AX_OBJC_EXCEPTIONS
index 4f41c88..b38bc65 100644 (file)
@@ -171,6 +171,7 @@ PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::textMarkerForPoint(i
 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::previousTextMarker(AccessibilityTextMarker*) { return 0; }
 PassRefPtr<AccessibilityTextMarker> AccessibilityUIElement::nextTextMarker(AccessibilityTextMarker*) { return 0; }
 JSRetainPtr<JSStringRef> AccessibilityUIElement::stringForTextMarkerRange(AccessibilityTextMarkerRange*) { return 0; }
+bool AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute(JSStringRef, AccessibilityTextMarkerRange*) { return false; }
 #endif
 
 } // namespace WTR
index e2e1f26..b726a82 100644 (file)
@@ -218,7 +218,8 @@ public:
     PassRefPtr<AccessibilityUIElement> accessibilityElementForTextMarker(AccessibilityTextMarker*);
     JSRetainPtr<JSStringRef> stringForTextMarkerRange(AccessibilityTextMarkerRange*);
     int textMarkerRangeLength(AccessibilityTextMarkerRange*);
-    
+    bool attributedStringForTextMarkerRangeContainsAttribute(JSStringRef, AccessibilityTextMarkerRange*);
+
     // Notifications
     // Function callback should take one argument, the name of the notification.
     bool addNotificationListener(JSValueRef functionCallback);
index 919353c..f3b5bee 100644 (file)
@@ -153,7 +153,8 @@ module WTR {
         AccessibilityUIElement accessibilityElementForTextMarker(in AccessibilityTextMarker marker);
         DOMString stringForTextMarkerRange(in AccessibilityTextMarkerRange range);
         int textMarkerRangeLength(in AccessibilityTextMarkerRange range);
-
+        boolean attributedStringForTextMarkerRangeContainsAttribute(in DOMString attr, in AccessibilityTextMarkerRange range);
+        
         // Notification support.
         boolean addNotificationListener(in object callbackFunction);
         boolean removeNotificationListener();
index cfcb7b3..e989880 100644 (file)
@@ -1377,6 +1377,21 @@ PassRefPtr<AccessibilityUIElement> AccessibilityUIElement::accessibilityElementF
     
     return 0;  
 }
+    
+bool AccessibilityUIElement::attributedStringForTextMarkerRangeContainsAttribute(JSStringRef attribute, AccessibilityTextMarkerRange* range)
+{
+    BEGIN_AX_OBJC_EXCEPTIONS
+    NSAttributedString* string = [m_element accessibilityAttributeValue:@"AXAttributedStringForTextMarkerRange" forParameter:(id)range->platformTextMarkerRange()];
+    if (![string isKindOfClass:[NSAttributedString class]])
+        return false;
+    
+    NSDictionary* attrs = [string attributesAtIndex:0 effectiveRange:nil];
+    if ([attrs objectForKey:[NSString stringWithJSStringRef:attribute]])
+        return true;    
+    END_AX_OBJC_EXCEPTIONS
+    
+    return false;
+}
 
 } // namespace WTR