Bug 429656. Use title attribute for image names when alt attribute is explicitly empty. r=marcoz, r=surkov, a=dsicore

git-svn-id: svn://10.0.0.236/trunk@250746 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
aaronleventhal%moonset.net 2008-04-24 06:01:29 +00:00
parent 9dfd49d5d9
commit f0b043228d
3 changed files with 42 additions and 22 deletions

View File

@ -130,24 +130,34 @@ nsHTMLImageAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
/* wstring getName (); */
NS_IMETHODIMP nsHTMLImageAccessible::GetName(nsAString& aName)
{
aName.Truncate();
if (IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
if (!content) {
return NS_ERROR_FAILURE; // Node has been shut down
}
if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt,
aName)) {
if (mRoleMapEntry) {
NS_ASSERTION(content, "Image node always supports nsIContent");
// 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
PRBool hasAltAttrib =
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::alt, aName);
if (aName.IsEmpty()) {
if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_labelledby)) {
// Use HTML label or DHTML accessibility's labelledby attribute for name
// GetHTMLName will also try title attribute as a last resort
return GetHTMLName(aName, PR_FALSE);
GetHTMLName(aName, PR_FALSE);
}
if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::title,
aName)) {
aName.SetIsVoid(PR_TRUE); // No alt or title
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;
}

View File

@ -120,7 +120,7 @@ __try {
if (NS_FAILED(rv))
return GetHRESULT(rv);
if (description.IsVoid())
if (description.IsEmpty())
return S_FALSE;
*aDescription = ::SysAllocStringLen(description.get(),

View File

@ -291,19 +291,29 @@ __try {
*pszName = NULL;
nsCOMPtr<nsIAccessible> xpAccessible;
GetXPAccessibleFor(varChild, getter_AddRefs(xpAccessible));
if (xpAccessible) {
nsAutoString name;
if (NS_FAILED(xpAccessible->GetName(name)))
return E_FAIL;
if (!xpAccessible)
return E_FAIL;
nsAutoString name;
nsresult rv = xpAccessible->GetName(name);
if (NS_FAILED(rv))
return GetHRESULT(rv);
if (name.IsVoid()) {
// Valid return value for the name:
// The name was not provided, e.g. no alt attribute for an image.
// A screen reader may choose to invent its own accessible name, e.g. from
// an image src attribute.
// See nsHTMLImageAccessible::GetName()
return S_OK;
}
*pszName = ::SysAllocStringLen(name.get(), name.Length());
if (!*pszName)
return E_OUTOFMEMORY;
*pszName = ::SysAllocStringLen(name.get(), name.Length());
if (!*pszName)
return E_OUTOFMEMORY;
#ifdef DEBUG_A11Y
NS_ASSERTION(mIsInitialized, "Access node was not initialized");
NS_ASSERTION(mIsInitialized, "Access node was not initialized");
#endif
}
} __except(FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
return S_OK;