Bug 468451 - Images with empty alt attribute no longer get an empty accessible name, but return NULL instead, r=aaronlev, marcoz, davidb

This commit is contained in:
Alexander Surkov 2008-12-17 00:13:49 +08:00
Родитель 51a061202f
Коммит acb3b8c296
5 изменённых файлов: 29 добавлений и 13 удалений

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

@ -103,7 +103,14 @@ interface nsIAccessible : nsISupports
readonly attribute long indexInParent;
/**
* Accessible name -- the main text equivalent for this node
* Accessible name -- the main text equivalent for this node. The name is
* specified by ARIA or by native markup. Example of ARIA markup is
* aria-labelledby attribute placed on element of this accessible. Example
* of native markup is HTML label linked with HTML element of this accessible.
*
* Value can be string or null. A null value indicates that AT may attempt to
* compute the name. Any string value, including the empty string, should be
* considered author-intentional, and respected.
*/
attribute AString name;

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

@ -308,7 +308,7 @@ nsAccessible::GetName(nsAString& aName)
if (content->GetAttr(kNameSpaceID_None, tooltipAttr, name)) {
name.CompressWhitespace();
aName = name;
} else {
} else if (rv != NS_OK_EMPTY_NAME) {
aName.SetIsVoid(PR_TRUE);
}

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

@ -66,9 +66,14 @@ class nsIDOMNode;
class nsIAtom;
class nsIView;
// see nsAccessible::GetAttrValue
#define NS_OK_NO_ARIA_VALUE \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 0x21)
// see nsAccessible::GetNameInternal
#define NS_OK_EMPTY_NAME \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 0x23)
// Saves a data member -- if child count equals this value we haven't
// cached children or child count yet
enum { eChildCountUninitialized = -1 };
@ -135,7 +140,13 @@ public:
/**
* Returns the accessible name provided by native markup. It doesn't take
* into account ARIA stuffs used to specify the name.
* into account ARIA markup used to specify the name.
*
* @param aName [out] the accessible name
*
* @return NS_OK_EMPTY_NAME points empty name was specified by native markup
* explicitly (see nsIAccessible::name attribute for
* details)
*/
virtual nsresult GetNameInternal(nsAString& aName);

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

@ -127,10 +127,6 @@ nsHTMLImageAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState)
nsresult
nsHTMLImageAccessible::GetNameInternal(nsAString& aName)
{
// 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);
@ -140,10 +136,12 @@ nsHTMLImageAccessible::GetNameInternal(nsAString& aName)
nsresult rv = nsAccessible::GetNameInternal(aName);
NS_ENSURE_SUCCESS(rv, rv);
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();
if (aName.IsEmpty() && hasAltAttrib) {
// No accessible name but empty 'alt' attribute is present. If further name
// computation algorithm doesn't provide non empty name then it means
// an empty 'alt' attribute was used to indicate a decorative image (see
// nsIAccessible::name attribute for details).
return NS_OK_EMPTY_NAME;
}
return NS_OK;

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

@ -147,10 +147,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429659
testThis("linkedImageWithTitle", "Link to MoFo", "moz.png", 93, 42);
// Test simple image with empty alt attribute
// testThis("nonLinkedImageEmptyAlt", "", "moz.png", 89, 38);
testThis("nonLinkedImageEmptyAlt", "", "moz.png", 89, 38);
// Test linked image with empty alt attribute
// testThis("linkedImageEmptyAlt", "", "moz.png", 93, 42);
testThis("linkedImageEmptyAlt", "", "moz.png", 93, 42);
// Test simple image with empty alt attribute and title
testThis("nonLinkedImageEmptyAltAndTitle", "MozillaFoundation", "moz.png", 89, 38);