mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 451535 - Make nsHTMLImageAccessible return proper number of actions for images with longdescs, provide a name for opening the longdesc, not just an index, r=surkov
This commit is contained in:
parent
ee5ce2182f
commit
a766f8b383
@ -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
|
||||
|
@ -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<nsIDOMHTMLImageElement> 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<nsIContent> 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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 \
|
||||
|
8
accessible/tests/mochitest/longdesc_src.html
Normal file
8
accessible/tests/mochitest/longdesc_src.html
Normal file
@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Mozilla logo</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>This file would contain a longer description of the Mozilla logo, if I knew what it looked like.</p>
|
||||
</body>
|
||||
</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
|
||||
<br>Linked image with empty alt and title:<br>
|
||||
<a href="http://www.mozilla.org"><img id="linkedImageEmptyAltAndTitle" src="moz.png" alt=""
|
||||
title="Link to Mozilla Foundation"/></a>
|
||||
<br>Image with longdesc:<br>
|
||||
<img id="longdesc" src="moz.png" longdesc="longdesc_src.html"
|
||||
alt="Image of Mozilla logo"/>
|
||||
<br>Image with click and longdesc:<br>
|
||||
<img id="clickAndLongdesc" src="moz.png" longdesc="longdesc_src.html"
|
||||
alt="Another image of Mozilla logo" onclick="alert('Clicked!');"/>
|
||||
<br>Image with click:<br>
|
||||
<img id="click" src="moz.png"
|
||||
alt="A third image of Mozilla logo" onclick="alert('Clicked, too!');"/>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user