diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index 335b5f23f22..18e28511ce7 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -1881,7 +1881,10 @@ nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtre } } - if (aCanAggregateSubtree) { + PRBool canAggregateName = mRoleMapEntry ? + mRoleMapEntry->nameRule == eNameOkFromChildren : + aCanAggregateSubtree; + if (canAggregateName) { // Don't use AppendFlatStringFromSubtree for container widgets like menulist nsresult rv = AppendFlatStringFromSubtree(content, &aLabel); NS_ENSURE_SUCCESS(rv, rv); @@ -1987,8 +1990,12 @@ nsresult nsAccessible::GetXULName(nsAString& aLabel, PRBool aCanAggregateSubtree parent = parent->GetParent(); } - // Don't use AppendFlatStringFromSubtree for container widgets like menulist - return aCanAggregateSubtree? AppendFlatStringFromSubtree(content, &aLabel) : NS_OK; + PRBool canAggregateName = mRoleMapEntry ? + mRoleMapEntry->nameRule == eNameOkFromChildren : + aCanAggregateSubtree; + + return canAggregateName ? + AppendFlatStringFromSubtree(content, &aLabel) : NS_OK; } PRBool nsAccessible::IsNodeRelevant(nsIDOMNode *aNode) @@ -3587,18 +3594,15 @@ nsAccessible::GetARIAName(nsAString& aName) nsresult nsAccessible::GetNameInternal(nsAString& aName) { - PRBool canAggregateName = mRoleMapEntry && - mRoleMapEntry->nameRule == eNameOkFromChildren; - nsCOMPtr content = GetRoleContent(mDOMNode); if (!content) return NS_OK; if (content->IsNodeOfType(nsINode::eHTML)) - return GetHTMLName(aName, canAggregateName); + return GetHTMLName(aName, PR_FALSE); if (content->IsNodeOfType(nsINode::eXUL)) - return GetXULName(aName, canAggregateName); + return GetXULName(aName, PR_FALSE); return NS_OK; } diff --git a/accessible/src/html/nsHTMLFormControlAccessible.cpp b/accessible/src/html/nsHTMLFormControlAccessible.cpp index e1ba7929871..04c3b002f12 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.cpp +++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp @@ -278,34 +278,34 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetRole(PRUint32 *_retval) nsresult nsHTMLButtonAccessible::GetNameInternal(nsAString& aName) { - nsAutoString name; - GetHTMLName(name, PR_FALSE); + nsresult rv = nsAccessible::GetNameInternal(aName); + if (!aName.IsEmpty()) + return NS_OK; - if (name.IsEmpty()) { - // no label from HTML or ARIA - nsCOMPtr content(do_QueryInterface(mDOMNode)); - if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, - name) && - !content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt, - name)) { - // Use the button's (default) label if nothing else works - nsIFrame* frame = GetFrame(); - if (frame) { - nsIFormControlFrame* fcFrame; - CallQueryInterface(frame, &fcFrame); - if (fcFrame) - fcFrame->GetFormProperty(nsAccessibilityAtoms::defaultLabel, name); - } - } - if (name.IsEmpty() && - !content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::title, - name) && - !content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::src, - name)) { - content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::data, name); + nsCOMPtr content(do_QueryInterface(mDOMNode)); + + // No name from HTML or ARIA + nsAutoString name; + if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, + name) && + !content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt, + name)) { + // Use the button's (default) label if nothing else works + nsIFrame* frame = GetFrame(); + if (frame) { + nsIFormControlFrame* fcFrame = nsnull; + CallQueryInterface(frame, &fcFrame); + if (fcFrame) + fcFrame->GetFormProperty(nsAccessibilityAtoms::defaultLabel, name); } } + if (name.IsEmpty() && + !content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::src, + name)) { + content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::data, name); + } + name.CompressWhitespace(); aName = name; @@ -370,6 +370,12 @@ nsHTML4ButtonAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) return NS_OK; } +nsresult +nsHTML4ButtonAccessible::GetNameInternal(nsAString& aName) +{ + return GetHTMLName(aName, PR_TRUE); +} + // --- textfield ----- nsHTMLTextFieldAccessible::nsHTMLTextFieldAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): @@ -391,26 +397,20 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetRole(PRUint32 *aRole) return NS_OK; } -NS_IMETHODIMP -nsHTMLTextFieldAccessible::GetName(nsAString& aName) +nsresult +nsHTMLTextFieldAccessible::GetNameInternal(nsAString& aName) { - aName.Truncate(); - - if (IsDefunct()) - return NS_ERROR_FAILURE; - - nsresult rv = GetARIAName(aName); + nsresult rv = nsAccessible::GetNameInternal(aName); NS_ENSURE_SUCCESS(rv, rv); if (!aName.IsEmpty()) return NS_OK; nsCOMPtr content = do_QueryInterface(mDOMNode); - rv = nsAccessible::GetHTMLName(aName, PR_FALSE); - if (NS_FAILED(rv) || !aName.IsEmpty() || !content->GetBindingParent()) { - return rv; - } + if (!content->GetBindingParent()) + return NS_OK; + // XXX: bug 459640 // There's a binding parent. // This means we're part of another control, so use parent accessible for name. // This ensures that a textbox inside of a XUL widget gets diff --git a/accessible/src/html/nsHTMLFormControlAccessible.h b/accessible/src/html/nsHTMLFormControlAccessible.h index 5545ff8cf30..e71100cdba3 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.h +++ b/accessible/src/html/nsHTMLFormControlAccessible.h @@ -101,10 +101,7 @@ public: NS_IMETHOD DoAction(PRUint8 index); // nsAccessible - virtual nsresult GetNameInternal(nsAString& aName) - { - return GetHTMLName(aName, PR_TRUE); - } + virtual nsresult GetNameInternal(nsAString& aName); }; class nsHTMLTextFieldAccessible : public nsHyperTextAccessibleWrap @@ -119,7 +116,6 @@ public: // nsIAccessible NS_IMETHOD GetRole(PRUint32 *_retval); - NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetValue(nsAString& _retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetNumActions(PRUint8 *_retval); @@ -128,6 +124,9 @@ public: // nsIAccessibleEditableText NS_IMETHOD GetAssociatedEditor(nsIEditor **aEditor); + + // nsAccessible + virtual nsresult GetNameInternal(nsAString& aName); }; class nsHTMLGroupboxAccessible : public nsHyperTextAccessibleWrap diff --git a/accessible/src/html/nsHTMLImageAccessible.cpp b/accessible/src/html/nsHTMLImageAccessible.cpp index 1001aab3e65..504b53c4fea 100644 --- a/accessible/src/html/nsHTMLImageAccessible.cpp +++ b/accessible/src/html/nsHTMLImageAccessible.cpp @@ -139,7 +139,7 @@ nsHTMLImageAccessible::GetNameInternal(nsAString& aName) if (!aName.IsEmpty()) return NS_OK; - nsresult rv = GetHTMLName(aName, PR_FALSE); + nsresult rv = nsAccessible::GetNameInternal(aName); NS_ENSURE_SUCCESS(rv, rv); if (aName.IsVoid() && hasAltAttrib) { diff --git a/accessible/src/html/nsHTMLLinkAccessible.cpp b/accessible/src/html/nsHTMLLinkAccessible.cpp index 60f14d0a1b3..289bed06e4a 100644 --- a/accessible/src/html/nsHTMLLinkAccessible.cpp +++ b/accessible/src/html/nsHTMLLinkAccessible.cpp @@ -59,7 +59,7 @@ NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLLinkAccessible, nsHyperTextAccessibleWrap, nsresult nsHTMLLinkAccessible::GetNameInternal(nsAString& aName) -{ +{ nsCOMPtr content(do_QueryInterface(mDOMNode)); nsresult rv = AppendFlatStringFromSubtree(content, &aName); NS_ENSURE_SUCCESS(rv, rv); diff --git a/accessible/src/html/nsHTMLSelectAccessible.h b/accessible/src/html/nsHTMLSelectAccessible.h index df4b912ae16..b0ae3422786 100644 --- a/accessible/src/html/nsHTMLSelectAccessible.h +++ b/accessible/src/html/nsHTMLSelectAccessible.h @@ -84,12 +84,6 @@ public: nsHTMLSelectableAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell); virtual ~nsHTMLSelectableAccessible() {} - // nsAccessible - virtual nsresult GetNameInternal(nsAString &aName) - { - return GetHTMLName(aName, PR_FALSE); - } - protected: NS_IMETHOD ChangeSelection(PRInt32 aIndex, PRUint8 aMethod, PRBool *aSelState); diff --git a/accessible/tests/mochitest/Makefile.in b/accessible/tests/mochitest/Makefile.in index 2bce4b1adf0..905a4bcd528 100644 --- a/accessible/tests/mochitest/Makefile.in +++ b/accessible/tests/mochitest/Makefile.in @@ -70,6 +70,7 @@ _TEST_FILES =\ test_nsIAccessible_editablebody.html \ test_nsIAccessible_editabledoc.html \ test_nsIAccessible_name.html \ + test_nsIAccessible_name_button.html \ test_nsIAccessible_name.xul \ test_nsIAccessible_selects.html \ test_nsIAccessible_states.html \ diff --git a/accessible/tests/mochitest/common.js b/accessible/tests/mochitest/common.js index 01746053abf..c0222d4134e 100644 --- a/accessible/tests/mochitest/common.js +++ b/accessible/tests/mochitest/common.js @@ -91,7 +91,7 @@ function getAccessible(aAccOrElmOrID, aInterfaces, aElmObj) } else { var elm = document.getElementById(aAccOrElmOrID); if (!elm) { - ok(false, "Can't get DOM element for " + aID); + ok(false, "Can't get DOM element for " + aAccOrElmOrID); return null; } } diff --git a/accessible/tests/mochitest/test_nsIAccessible_name_button.html b/accessible/tests/mochitest/test_nsIAccessible_name_button.html new file mode 100644 index 00000000000..d1ee4d80680 --- /dev/null +++ b/accessible/tests/mochitest/test_nsIAccessible_name_button.html @@ -0,0 +1,142 @@ + + + + nsIAccessible::name calculation for HTML buttons + + + + + + + + + + + + + + + Mozilla Bug 459635 + +

+ +
+  
+ + + +
+ + + text + + +
+ + + + + + + + + + + + + + + + +
+ + + text + + +
+ + + + + + + + + + + + + + + + + + + + +