зеркало из https://github.com/mozilla/gecko-dev.git
Bug 459382 - fix html:img accessible name, r=marcoz, aaronlev
This commit is contained in:
Родитель
c6dae5b6ee
Коммит
9d93f56aff
|
@ -1863,13 +1863,17 @@ nsresult nsAccessible::GetTextFromRelationID(nsIAtom *aIDProperty, nsString &aNa
|
|||
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;
|
||||
|
@ -1880,9 +1884,10 @@ nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtre
|
|||
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.
|
||||
|
@ -1890,6 +1895,7 @@ nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtre
|
|||
aLabel)) {
|
||||
aLabel.SetIsVoid(PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -126,46 +126,28 @@ nsHTMLImageAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
|
|||
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.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);
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ public:
|
|||
// 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);
|
||||
|
@ -77,6 +76,7 @@ public:
|
|||
NS_DECL_NSIACCESSIBLEIMAGE
|
||||
|
||||
// nsAccessible
|
||||
virtual nsresult GetNameInternal(nsAString& aName);
|
||||
virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
|
||||
|
||||
protected:
|
||||
|
|
Загрузка…
Ссылка в новой задаче