2008-04-30 Beth Dakin <bdakin@apple.com>
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 May 2008 00:08:14 +0000 (00:08 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 May 2008 00:08:14 +0000 (00:08 +0000)
        Reviewed by Sam Weinig.

        This patch does three things:
        1. Adds support for the "img" ARIA role
        2. Switches over to a HashMap for converting ARIA role attributes
        to WebCore's AccessibilityRole type.
        3. Fixes a crash in the new ARIA code that I ran into while
        browsing with VoiceOver enabled.

        * page/AccessibilityObject.cpp:
        (WebCore::AccessibilityObject::headingLevel): This is the crash
        fix. Make sure the node's renderer is not null before looking up
        its corresponding AccessibilityObject in the cache.
        (WebCore::AccessibilityObject::accessibilityIsIgnored): Account for
        ARIA images.
        (WebCore::createARIARoleMap): Switch to HashMap, and add "img" to
        the Map.
        (WebCore::RoleEntry::): Same.
        (WebCore::ariaRoleToWebCoreRole): Same.
        (WebCore::AccessibilityObject::ariaRoleAttribute): Same.

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

WebCore/ChangeLog
WebCore/page/AccessibilityObject.cpp

index fb1fed224d60784ccf95c30a0b5f070a536cc056..e03843bbab49040c60c855c13c05ab5124118217 100644 (file)
@@ -1,3 +1,26 @@
+2008-04-30  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        This patch does three things:
+        1. Adds support for the "img" ARIA role
+        2. Switches over to a HashMap for converting ARIA role attributes 
+        to WebCore's AccessibilityRole type. 
+        3. Fixes a crash in the new ARIA code that I ran into while 
+        browsing with VoiceOver enabled.
+
+        * page/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::headingLevel): This is the crash 
+        fix. Make sure the node's renderer is not null before looking up 
+        its corresponding AccessibilityObject in the cache.
+        (WebCore::AccessibilityObject::accessibilityIsIgnored): Account for 
+        ARIA images.
+        (WebCore::createARIARoleMap): Switch to HashMap, and add "img" to 
+        the Map.
+        (WebCore::RoleEntry::): Same.
+        (WebCore::ariaRoleToWebCoreRole): Same.
+        (WebCore::AccessibilityObject::ariaRoleAttribute): Same.
+
 2008-04-30  Rob Buis  <buis@kde.org>
 
         Reviewed by Nikolas.
index d7d5759b50e4796537e41120a4266b940c244994..0ff84b86ad1a2a172d1c04b914d7336eaf2d2077 100644 (file)
@@ -289,7 +289,11 @@ int AccessibilityObject::headingLevel(Node* node)
         return 6;
 
     // FIXME: When we implement ARIA's level property, this needs to return that instead of 1.
-    AccessibilityObject* axObjectForNode = node->document()->axObjectCache()->get(node->renderer());
+    RenderObject* renderer = node->renderer();
+    if (!renderer)
+        return 0;
+
+    AccessibilityObject* axObjectForNode = node->document()->axObjectCache()->get(renderer);
     if (axObjectForNode->ariaRoleAttribute() == HeadingRole)
         return 1;
 
@@ -685,7 +689,7 @@ bool AccessibilityObject::accessibilityIsIgnored() const
         return !static_cast<RenderBlock*>(m_renderer)->firstLineBox() && !mouseButtonListener();
 
     // ignore images seemingly used as spacers
-    if (m_renderer->isRenderImage()) {
+    if (isImage()) {
         // informal standard is to ignore images with zero-length alt strings
         Node* node = m_renderer->element();
         if (node && node->isElementNode()) {
@@ -700,10 +704,12 @@ bool AccessibilityObject::accessibilityIsIgnored() const
             return true;
 
         // check whether rendered image was stretched from one-dimensional file image
-        RenderImage* image = static_cast<RenderImage*>(m_renderer);
-        if (image->cachedImage()) {
-            IntSize imageSize = image->cachedImage()->imageSize(image->view()->zoomFactor());
-            return imageSize.height() <= 1 || imageSize.width() <= 1;
+        if (isNativeImage()) {
+            RenderImage* image = static_cast<RenderImage*>(m_renderer);
+            if (image->cachedImage()) {
+                IntSize imageSize = image->cachedImage()->imageSize(image->view()->zoomFactor());
+                return imageSize.height() <= 1 || imageSize.width() <= 1;
+            }
         }
 
         return false;
@@ -1876,6 +1882,39 @@ AccessibilityObject* AccessibilityObject::observableObject() const
     return 0;
 }
 
+typedef HashMap<String, AccessibilityRole, CaseFoldingHash> ARIARoleMap;
+
+static const ARIARoleMap& createARIARoleMap()
+{
+    struct RoleEntry {
+        String ariaRole;
+        AccessibilityRole webcoreRole;
+    };
+    
+    static const RoleEntry roles[] = {
+        { String("button"), ButtonRole },
+        { String("checkbox"), CheckBoxRole },
+        { String("heading"), HeadingRole },
+        { String("img"), ImageRole },
+        { String("link"), WebCoreLinkRole },
+        { String("radio"), RadioButtonRole },
+        { String("textbox"), TextAreaRole }
+    };
+    ARIARoleMap& roleMap = *new ARIARoleMap;
+    
+    const unsigned numRoles = sizeof(roles) / sizeof(roles[0]);
+    for (unsigned i = 0; i < numRoles; ++i)
+        roleMap.set(roles[i].ariaRole, roles[i].webcoreRole);
+    return roleMap;
+}
+
+static AccessibilityRole ariaRoleToWebCoreRole(String value)
+{
+    ASSERT(!value.isEmpty() && !value.isNull());
+    static const ARIARoleMap& roleMap = createARIARoleMap();
+    return roleMap.get(value);
+}
+
 AccessibilityRole AccessibilityObject::ariaRoleAttribute() const
 {
     Node* node = m_renderer->node();
@@ -1887,19 +1926,9 @@ AccessibilityRole AccessibilityObject::ariaRoleAttribute() const
     if (ariaRole.isNull() || ariaRole.isEmpty())
         return UnknownRole;
     
-    if (equalIgnoringCase(ariaRole, "button"))
-        return ButtonRole;
-    if (equalIgnoringCase(ariaRole, "checkbox"))
-        return CheckBoxRole;
-    if (equalIgnoringCase(ariaRole, "heading"))
-        return HeadingRole;
-    if (equalIgnoringCase(ariaRole, "link"))
-        return WebCoreLinkRole;
-    if (equalIgnoringCase(ariaRole, "radio"))
-        return RadioButtonRole;
-    if (equalIgnoringCase(ariaRole, "textbox"))
-        return TextAreaRole;
-    
+    AccessibilityRole role = ariaRoleToWebCoreRole(ariaRole);
+    if (role)
+        return role;
     return UnknownRole;
 }