Bug 459382 - fix html:img accessible name, r=marcoz, aaronlev

This commit is contained in:
Alexander Surkov 2008-10-13 16:58:58 +08:00
Родитель c6dae5b6ee
Коммит 9d93f56aff
3 изменённых файлов: 24 добавлений и 36 удалений

Просмотреть файл

@ -1863,13 +1863,17 @@ nsresult nsAccessible::GetTextFromRelationID(nsIAtom *aIDProperty, nsString &aNa
nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtree) nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtree)
{ {
nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode); nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode);
if (!content) if (!content) {
aLabel.SetIsVoid(PR_TRUE);
return NS_OK; return NS_OK;
}
nsIContent *labelContent = GetHTMLLabelContent(content); nsIContent *labelContent = GetHTMLLabelContent(content);
if (labelContent) { if (labelContent) {
nsAutoString label; nsAutoString label;
AppendFlatStringFromSubtree(labelContent, &label); nsresult rv = AppendFlatStringFromSubtree(labelContent, &label);
NS_ENSURE_SUCCESS(rv, rv);
label.CompressWhitespace(); label.CompressWhitespace();
if (!label.IsEmpty()) { if (!label.IsEmpty()) {
aLabel = label; aLabel = label;
@ -1880,9 +1884,10 @@ nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtre
if (aCanAggregateSubtree) { if (aCanAggregateSubtree) {
// Don't use AppendFlatStringFromSubtree for container widgets like menulist // Don't use AppendFlatStringFromSubtree for container widgets like menulist
nsresult rv = AppendFlatStringFromSubtree(content, &aLabel); nsresult rv = AppendFlatStringFromSubtree(content, &aLabel);
if (NS_SUCCEEDED(rv) && !aLabel.IsEmpty()) { NS_ENSURE_SUCCESS(rv, rv);
if (!aLabel.IsEmpty())
return NS_OK; return NS_OK;
}
} }
// Still try the title as as fallback method in that case. // Still try the title as as fallback method in that case.
@ -1890,6 +1895,7 @@ nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtre
aLabel)) { aLabel)) {
aLabel.SetIsVoid(PR_TRUE); aLabel.SetIsVoid(PR_TRUE);
} }
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -126,46 +126,28 @@ nsHTMLImageAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsresult
nsHTMLImageAccessible::GetName(nsAString& aName) 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 // 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 // alt="" with no title or aria-labelledby means image is presentational and
// AT should leave accessible name empty // AT should leave accessible name empty
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
PRBool hasAltAttrib = PRBool hasAltAttrib =
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt, aName); content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt, aName);
if (aName.IsEmpty()) { if (!aName.IsEmpty())
if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label) || return NS_OK;
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()) nsresult rv = GetHTMLName(aName, PR_FALSE);
return NS_OK; NS_ENSURE_SUCCESS(rv, rv);
rv = GetHTMLName(aName, PR_FALSE); if (aName.IsVoid() && hasAltAttrib) {
NS_ENSURE_SUCCESS(rv, rv); // 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; return NS_OK;
} }

Просмотреть файл

@ -60,7 +60,6 @@ public:
// nsIAccessible // nsIAccessible
NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState);
NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD GetRole(PRUint32 *_retval);
NS_IMETHOD GetName(nsAString& aName);
NS_IMETHOD GetNumActions(PRUint8 *aNumActions); NS_IMETHOD GetNumActions(PRUint8 *aNumActions);
NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName); NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
NS_IMETHOD DoAction(PRUint8 index); NS_IMETHOD DoAction(PRUint8 index);
@ -77,6 +76,7 @@ public:
NS_DECL_NSIACCESSIBLEIMAGE NS_DECL_NSIACCESSIBLEIMAGE
// nsAccessible // nsAccessible
virtual nsresult GetNameInternal(nsAString& aName);
virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes); virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
protected: protected: