diff --git a/mozilla/accessible/src/html/nsHTMLImageAccessible.cpp b/mozilla/accessible/src/html/nsHTMLImageAccessible.cpp index 6e1a72f18d7..4abf0387a45 100644 --- a/mozilla/accessible/src/html/nsHTMLImageAccessible.cpp +++ b/mozilla/accessible/src/html/nsHTMLImageAccessible.cpp @@ -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 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; } diff --git a/mozilla/accessible/src/msaa/CAccessibleAction.cpp b/mozilla/accessible/src/msaa/CAccessibleAction.cpp index 1772d4b6bbd..ac50acf7ca6 100755 --- a/mozilla/accessible/src/msaa/CAccessibleAction.cpp +++ b/mozilla/accessible/src/msaa/CAccessibleAction.cpp @@ -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(), diff --git a/mozilla/accessible/src/msaa/nsAccessibleWrap.cpp b/mozilla/accessible/src/msaa/nsAccessibleWrap.cpp index 079a7b65d2c..5cc62265db6 100644 --- a/mozilla/accessible/src/msaa/nsAccessibleWrap.cpp +++ b/mozilla/accessible/src/msaa/nsAccessibleWrap.cpp @@ -291,19 +291,29 @@ __try { *pszName = NULL; nsCOMPtr 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;