diff --git a/accessible/src/base/nsAccessibilityAtomList.h b/accessible/src/base/nsAccessibilityAtomList.h index e565c278826d..3f548ae5ae0c 100755 --- a/accessible/src/base/nsAccessibilityAtomList.h +++ b/accessible/src/base/nsAccessibilityAtomList.h @@ -170,6 +170,7 @@ ACCESSIBILITY_ATOM(href, "href") // XUL, XLink ACCESSIBILITY_ATOM(increment, "increment") // XUL ACCESSIBILITY_ATOM(lang, "lang") ACCESSIBILITY_ATOM(linkedPanel, "linkedpanel") // XUL +ACCESSIBILITY_ATOM(longDesc, "longdesc") ACCESSIBILITY_ATOM(maxpos, "maxpos") // XUL ACCESSIBILITY_ATOM(minpos, "minpos") // XUL ACCESSIBILITY_ATOM(multiline, "multiline") // XUL diff --git a/accessible/src/html/nsHTMLImageAccessible.cpp b/accessible/src/html/nsHTMLImageAccessible.cpp index 4abf0387a454..e980f79e0bfe 100644 --- a/accessible/src/html/nsHTMLImageAccessible.cpp +++ b/accessible/src/html/nsHTMLImageAccessible.cpp @@ -210,9 +210,46 @@ void nsHTMLImageAccessible::CacheChildren() mAccChildCount = childCount; } -NS_IMETHODIMP nsHTMLImageAccessible::DoAction(PRUint8 index) +NS_IMETHODIMP +nsHTMLImageAccessible::GetNumActions(PRUint8 *aNumActions) { - if (index == eAction_ShowLongDescription) { + NS_ENSURE_ARG_POINTER(aNumActions); + *aNumActions = 0; + + if (IsDefunct()) + return NS_ERROR_FAILURE; + + nsresult rv= nsLinkableAccessible::GetNumActions(aNumActions); + NS_ENSURE_SUCCESS(rv, rv); + + if (HasLongDesc()) + (*aNumActions)++; + + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLImageAccessible::GetActionName(PRUint8 aIndex, nsAString& aName) +{ + aName.Truncate(); + + if (IsDefunct()) + return NS_ERROR_FAILURE; + + if (IsValidLongDescIndex(aIndex)) { + aName.AssignLiteral("showlongdesc"); + return NS_OK; + } + return nsLinkableAccessible::GetActionName(aIndex, aName); +} + +NS_IMETHODIMP +nsHTMLImageAccessible::DoAction(PRUint8 aIndex) +{ + if (IsDefunct()) + return NS_ERROR_FAILURE; + + if (IsValidLongDescIndex(aIndex)) { //get the long description uri and open in a new window nsCOMPtr element(do_QueryInterface(mDOMNode)); NS_ENSURE_TRUE(element, NS_ERROR_FAILURE); @@ -230,7 +267,7 @@ NS_IMETHODIMP nsHTMLImageAccessible::DoAction(PRUint8 index) return win->Open(longDesc, NS_LITERAL_STRING(""), NS_LITERAL_STRING(""), getter_AddRefs(tmp)); } - return nsLinkableAccessible::DoAction(index); + return nsLinkableAccessible::DoAction(aIndex); } //////////////////////////////////////////////////////////////////////////////// @@ -405,3 +442,29 @@ nsHTMLImageAccessible::GetAreaAccessible(nsIDOMHTMLCollection *aAreaCollection, return accessible; } + +//////////////////////////////////////////////////////////////////////////////// +// Private methods + +PRBool +nsHTMLImageAccessible::HasLongDesc() +{ + if (IsDefunct()) + return PR_FALSE; + + nsCOMPtr content(do_QueryInterface(mDOMNode)); + return (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::longDesc)); +} + +PRBool +nsHTMLImageAccessible::IsValidLongDescIndex(PRUint8 aIndex) +{ + if (!HasLongDesc()) + return PR_FALSE; + + PRUint8 numActions = 0; + nsresult rv = nsLinkableAccessible::GetNumActions(&numActions); + NS_ENSURE_SUCCESS(rv, PR_FALSE); + + return (aIndex == numActions); +} diff --git a/accessible/src/html/nsHTMLImageAccessible.h b/accessible/src/html/nsHTMLImageAccessible.h index 2fe1e2acd845..49123d020c5f 100644 --- a/accessible/src/html/nsHTMLImageAccessible.h +++ b/accessible/src/html/nsHTMLImageAccessible.h @@ -55,15 +55,14 @@ class nsHTMLImageAccessible : public nsLinkableAccessible, NS_DECL_ISUPPORTS_INHERITED public: - //action0 may exist depends on whether an onclick is associated with it - enum { eAction_ShowLongDescription = 1 }; - nsHTMLImageAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell); // nsIAccessible NS_IMETHOD GetName(nsAString& _retval); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetRole(PRUint32 *_retval); + NS_IMETHOD GetNumActions(PRUint8 *aNumActions); + NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName); NS_IMETHOD DoAction(PRUint8 index); // nsIAccessibleHyperLink @@ -95,6 +94,25 @@ protected: // share area elements but we need to have separate area accessibles for // each image accessible. nsAccessNodeHashtable *mAccessNodeCache; + +private: + /** + * Determine if this image accessible has a longdesc attribute. + * + * @returns true if the longdesc attribute is present. + */ + PRBool HasLongDesc(); + + /** + * Used by GetActionName and DoAction to ensure the index for opening the + * longdesc URL is valid. + * It is always assumed that the highest possible index opens the longdesc. + * + * @param aIndex The 0-based index to be tested. + * + * @returns true if index is valid for longdesc action. + */ + PRBool IsValidLongDescIndex(PRUint8 aIndex); }; #endif diff --git a/accessible/tests/mochitest/Makefile.in b/accessible/tests/mochitest/Makefile.in index 941f987b436d..716e74f688f2 100644 --- a/accessible/tests/mochitest/Makefile.in +++ b/accessible/tests/mochitest/Makefile.in @@ -47,6 +47,7 @@ include $(topsrcdir)/config/rules.mk _TEST_FILES =\ moz.png \ + longdesc_src.html \ nsIAccessible_actions.js \ nsIAccessible_name.css \ nsIAccessible_name.xbl \ diff --git a/accessible/tests/mochitest/longdesc_src.html b/accessible/tests/mochitest/longdesc_src.html new file mode 100644 index 000000000000..37248795dd77 --- /dev/null +++ b/accessible/tests/mochitest/longdesc_src.html @@ -0,0 +1,8 @@ + + +Mozilla logo + + +

This file would contain a longer description of the Mozilla logo, if I knew what it looked like.

+ + diff --git a/accessible/tests/mochitest/test_nsIAccessibleImage.html b/accessible/tests/mochitest/test_nsIAccessibleImage.html index e8e09bf1260c..911016a8aca1 100644 --- a/accessible/tests/mochitest/test_nsIAccessibleImage.html +++ b/accessible/tests/mochitest/test_nsIAccessibleImage.html @@ -85,7 +85,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429659 is(height.value, aHeight, "wrong height for " + aID + "!"); } - function testThis(aID, aName, aSRC, aWidth, aHeight) + function testThis(aID, aName, aSRC, aWidth, aHeight, + aNumActions, aActionNames) { var elem = document.getElementById(aID); var acc; @@ -110,6 +111,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429659 ok(attributes, "no attributes on " + aID + "!"); is(attributes.getStringProperty("src"), aSRC, "no correct src attribute for " + aID + "!"); + + if (aNumActions) { + is(acc.numActions, aNumActions, + "Wrong number of actions for " + aID + "!"); + + for (index = 0; index < aActionNames.length; index++) { + is(acc.getActionName(index), aActionNames[index], + "Wrong action name for " + aID + ", index " + index +"!"); + } + } } function doTest() @@ -147,6 +158,23 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429659 // Test linked image with empty alt attribute and title testThis("linkedImageEmptyAltAndTitle", "Link to Mozilla Foundation", "moz.png", 93, 42); + // Image with long desc + var actionNamesArray = new Array("showlongdesc"); + testThis("longdesc", "Image of Mozilla logo", "moz.png", 89, 38, 1, + actionNamesArray); + + // Image with click and long desc + actionNamesArray = null; + actionNamesArray = new Array("click", "showlongdesc"); + testThis("clickAndLongdesc", "Another image of Mozilla logo", "moz.png", + 89, 38, 2, actionNamesArray); + + // Image with click + actionNamesArray = null; + actionNamesArray = new Array("click"); + testThis("click", "A third image of Mozilla logo", "moz.png", + 89, 38, 1, actionNamesArray); + SimpleTest.finish(); } @@ -182,5 +210,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429659
Linked image with empty alt and title:
+
Image with longdesc:
+ Image of Mozilla logo +
Image with click and longdesc:
+ Another image of Mozilla logo +
Image with click:
+ A third image of Mozilla logo