Bug 459382 - fix html:img accessible name, r=marcoz, aaronlev
authorAlexander Surkov <surkov.alexander@gmail.com>
Mon, 13 Oct 2008 16:58:58 +0800
changeset 20362 2be597825ef2b0758eeac3dab54e2ea34dcbc23c
parent 20361 979c128d2e6325aa0c1b8cbb7afe814f239e5be0
child 20363 163e9f2fa5c1ce54eca9e04207a352ae5f1dba6c
push id2839
push usersurkov.alexander@gmail.com
push dateMon, 13 Oct 2008 07:59:26 +0000
treeherdermozilla-central@2be597825ef2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarcoz, aaronlev
bugs459382
milestone1.9.1b2pre
Bug 459382 - fix html:img accessible name, r=marcoz, aaronlev
accessible/src/base/nsAccessible.cpp
accessible/src/html/nsHTMLImageAccessible.cpp
accessible/src/html/nsHTMLImageAccessible.h
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -1858,43 +1858,49 @@ nsresult nsAccessible::GetTextFromRelati
 /**
   * Only called if the element is not a nsIDOMXULControlElement. Initially walks up
   *   the DOM tree to the form, concatonating label elements as it goes. Then checks for
   *   labels with the for="controlID" property.
   */
 nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtree)
 {
   nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode);
-  if (!content)
+  if (!content) {
+    aLabel.SetIsVoid(PR_TRUE);
     return NS_OK;
+  }
 
   nsIContent *labelContent = GetHTMLLabelContent(content);
   if (labelContent) {
     nsAutoString label;
-    AppendFlatStringFromSubtree(labelContent, &label);
+    nsresult rv = AppendFlatStringFromSubtree(labelContent, &label);
+    NS_ENSURE_SUCCESS(rv, rv);
+
     label.CompressWhitespace();
     if (!label.IsEmpty()) {
       aLabel = label;
       return NS_OK;
     }
   }
 
   if (aCanAggregateSubtree) {
     // Don't use AppendFlatStringFromSubtree for container widgets like menulist
     nsresult rv = AppendFlatStringFromSubtree(content, &aLabel);
-    if (NS_SUCCEEDED(rv) && !aLabel.IsEmpty()) {
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    if (!aLabel.IsEmpty())
       return NS_OK;
-    }
   }
 
   // Still try the title as as fallback method in that case.
   if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::title,
                         aLabel)) {
     aLabel.SetIsVoid(PR_TRUE);
   }
+
   return NS_OK;
 }
 
 /**
   * 3 main cases for XUL Controls to be labeled
   *   1 - control contains label="foo"
   *   2 - control has, as a child, a label element
   *        - label has either value="foo" or children
--- a/accessible/src/html/nsHTMLImageAccessible.cpp
+++ b/accessible/src/html/nsHTMLImageAccessible.cpp
@@ -121,56 +121,38 @@ nsHTMLImageAccessible::GetState(PRUint32
     imgContainer->GetNumFrames(&numFrames);
     if (numFrames > 1)
       *aState |= nsIAccessibleStates::STATE_ANIMATED;
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsHTMLImageAccessible::GetName(nsAString& aName)
+nsresult
+nsHTMLImageAccessible::GetNameInternal(nsAString& aName)
 {
-  aName.Truncate();
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-  
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-    
   // No alt attribute means AT can repair if there is no accessible name
   // alt="" with no title or aria-labelledby means image is presentational and 
   // AT should leave accessible name empty
+
+  nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
   PRBool hasAltAttrib =
     content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt, aName);
-  if (aName.IsEmpty()) {
-    if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label) ||
-        content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_labelledby)) {
-      // Use HTML label or DHTML accessibility's label or labelledby attribute for name
-      // GetHTMLName will also try title attribute as a last resort
-      nsresult rv = GetARIAName(aName);
-      NS_ENSURE_SUCCESS(rv, rv);
+  if (!aName.IsEmpty())
+    return NS_OK;
 
-      if (!aName.IsEmpty())
-        return NS_OK;
+  nsresult rv = GetHTMLName(aName, PR_FALSE);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-      rv = GetHTMLName(aName, PR_FALSE);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
+  if (aName.IsVoid() && hasAltAttrib) {
+    // No accessible name but empty alt attribute is present. This means a name
+    // was provided by author and AT repair of the name isn't allowed.
+    aName.Truncate();
+  }
 
-    if (aName.IsEmpty()) { // No name from alt or aria-labelledby
-      content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::title, aName);
-      if (!hasAltAttrib && aName.IsEmpty()) { 
-        // Still no accessible name and no alt attribute is present.
-        // SetIsVoid() is different from empty string -- this means a name was not 
-        // provided by author and AT repair of the name is allowed.
-        aName.SetIsVoid(PR_TRUE);
-      }
-    }
-  }
   return NS_OK;
 }
 
 /* wstring getRole (); */
 NS_IMETHODIMP nsHTMLImageAccessible::GetRole(PRUint32 *_retval)
 {
   *_retval = mMapElement ? nsIAccessibleRole::ROLE_IMAGE_MAP :
                            nsIAccessibleRole::ROLE_GRAPHIC;
--- a/accessible/src/html/nsHTMLImageAccessible.h
+++ b/accessible/src/html/nsHTMLImageAccessible.h
@@ -55,33 +55,33 @@ class nsHTMLImageAccessible : public nsL
   NS_DECL_ISUPPORTS_INHERITED
 
 public:
   nsHTMLImageAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
 
   // nsIAccessible
   NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
   NS_IMETHOD GetRole(PRUint32 *_retval);
-  NS_IMETHOD GetName(nsAString& aName);
   NS_IMETHOD GetNumActions(PRUint8 *aNumActions);
   NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
   NS_IMETHOD DoAction(PRUint8 index);
 
   // nsIAccessibleHyperLink
   NS_IMETHOD GetAnchorCount(PRInt32 *aAnchorCount);
   NS_IMETHOD GetURI(PRInt32 aIndex, nsIURI **aURI);
   NS_IMETHOD GetAnchor(PRInt32 aIndex, nsIAccessible **aAccessible);
 
   // nsPIAccessNode
   NS_IMETHOD Shutdown();
 
   // nsIAccessibleImage
   NS_DECL_NSIACCESSIBLEIMAGE
 
   // nsAccessible
+  virtual nsresult GetNameInternal(nsAString& aName);
   virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
 
 protected:
   // nsAccessible
   virtual void CacheChildren();
 
   already_AddRefed<nsIDOMHTMLCollection> GetAreaCollection();
   already_AddRefed<nsIAccessible>