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 763754603c128576dd6137e1683682d97efbdced..a9cc9c00e92bc12f9b79307fe4947b2c39e6042b 100644 (file)
@@ -1,3 +1,13 @@
+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
index 33b1493988971b9cab58e42a714af7dd3d3e76b1..af950245c108fa00dd86df1b14fd1c3d02b83673 100644 (file)
@@ -1,3 +1,18 @@
+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
index 774af3f5aa4b6f97bcb01f76f2c5c72767e9f779..13c3e61c8bc29f116061b3415e3b33412e39940a 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 3345867e70d3aebe0041aff7cb2790ff8768f629..e0c56367e66605ea33d5a11eaa4ead415573c93d 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 ddb37b8531a41af2bcfc6840a01482fb418e7d7f..67fc4d73c92c49c4f8123e4d182fa052ebcef6ff 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 4e204c7bd20afbb4cca99a66c6d9b7d03281e5e6..38d35cf58324e55bee616ba53df970c75b22ba24 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 c34fceea72df2a1549008066894f1a9f58c4038c..9360ef1e7e04389175980587aa8474bec3ad6ec6 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 4f41c88f220856ba10da030caead605bd6419ab1..b38bc65ea5aeefd5be866d7667ca7c4854a5cc63 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 e2e1f26d9740fb38f29b15757ae0ec48d51a4cee..b726a8296ae97bafa2ddf2ad2547e2bd83cfc466 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 919353c71026ab3743c20f08ffb43a87bce46fae..f3b5bee13d1dd4ed62448e5ce1154c1680b0928e 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 cfcb7b3118e0d71cc595a1fc86e1c61df86604c7..e989880e5349a70528b783d2878366678f39b85d 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