Bug 420863 - If an HTML element has an onClick attribute, expose its click action on the element rather than its child text leaf node, r=aaronlev, a=dsicore

This commit is contained in:
surkov.alexander@gmail.com 2008-03-15 18:23:41 -07:00
Родитель e095f9de94
Коммит 87844f2e94
3 изменённых файлов: 179 добавлений и 6 удалений

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

@ -2566,20 +2566,52 @@ NS_IMETHODIMP nsAccessible::GetRole(PRUint32 *aRole)
}
/* PRUint8 getAccNumActions (); */
NS_IMETHODIMP nsAccessible::GetNumActions(PRUint8 *aNumActions)
NS_IMETHODIMP
nsAccessible::GetNumActions(PRUint8 *aNumActions)
{
NS_ENSURE_ARG_POINTER(aNumActions);
*aNumActions = 0;
if (IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
PRBool isOnclick = nsAccUtils::HasListener(content,
NS_LITERAL_STRING("click"));
if (isOnclick)
*aNumActions = 1;
return NS_OK;
}
/* DOMString getAccActionName (in PRUint8 index); */
NS_IMETHODIMP nsAccessible::GetActionName(PRUint8 index, nsAString& aName)
NS_IMETHODIMP
nsAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
{
return NS_ERROR_FAILURE;
aName.Truncate();
if (aIndex != 0)
return NS_ERROR_INVALID_ARG;
if (IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
PRBool isOnclick = nsAccUtils::HasListener(content,
NS_LITERAL_STRING("click"));
if (isOnclick) {
aName.AssignLiteral("click");
return NS_OK;
}
return NS_ERROR_INVALID_ARG;
}
/* DOMString getActionDescription (in PRUint8 index); */
NS_IMETHODIMP nsAccessible::GetActionDescription(PRUint8 aIndex, nsAString& aDescription)
NS_IMETHODIMP
nsAccessible::GetActionDescription(PRUint8 aIndex, nsAString& aDescription)
{
// default to localized action name.
nsAutoString name;
@ -2590,9 +2622,23 @@ NS_IMETHODIMP nsAccessible::GetActionDescription(PRUint8 aIndex, nsAString& aDes
}
/* void doAction (in PRUint8 index); */
NS_IMETHODIMP nsAccessible::DoAction(PRUint8 index)
NS_IMETHODIMP
nsAccessible::DoAction(PRUint8 aIndex)
{
return NS_ERROR_FAILURE;
if (aIndex != 0)
return NS_ERROR_INVALID_ARG;
if (IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
PRBool isOnclick = nsAccUtils::HasListener(content,
NS_LITERAL_STRING("click"));
if (isOnclick)
return DoCommand(content);
return NS_ERROR_INVALID_ARG;
}
/* DOMString getHelp (); */

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

@ -47,6 +47,7 @@ include $(topsrcdir)/config/rules.mk
_TEST_FILES =\
test_bug368835.xul \
test_bug420863.html \
test_groupattrs.xul \
test_table_indexes.html \
test_nsIAccessibleTable_1.html \

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

@ -0,0 +1,126 @@
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=420863
-->
<head>
<title>Table indexes chrome tests</title>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript">
var gAccService = null;
var gTdClickAttr = false;
var gTdClickEventHandler = false;
var gClickHandler = null;
var gID = "";
var gNode = null;
var gAcc = null;
function doTest()
{
const nsIAccessibleRetrieval =
Components.interfaces.nsIAccessibleRetrieval;
gAccService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(nsIAccessibleRetrieval);
// Actions should be exposed on any accessible having related DOM node
// with registered 'click' event handler.
//////////////////////////////////////////////////////////////////////////
// generic td
gID = "td1";
gNode = document.getElementById(gID);
gAcc = gAccService.getAccessibleFor(gNode);
is(gAcc.numActions, 0, gID + ": shouldn't have actions");
//////////////////////////////////////////////////////////////////////////
// td with 'onclick' attribute
gID = "td2";
gNode = document.getElementById(gID);
gAcc = gAccService.getAccessibleFor(gNode);
is(gAcc.numActions, 1, gID + ": should have one action");
is(gAcc.getActionName(0), "click", gID + ": should have 'click' action");
gAcc.doAction(0);
// actions are performed via timeout
window.setTimeout(doTest2, 0);
}
function doTest2()
{
//////////////////////////////////////////////////////////////////////////
// td with 'onclick' attribute (sequel, see doTest1())
ok(gTdClickAttr, gID + ": 'click' action hasn't been performed");
//////////////////////////////////////////////////////////////////////////
// td with registered 'click' event handler
gID = "td3";
gNode = document.getElementById(gID);
gAcc = gAccService.getAccessibleFor(gNode);
// register 'click' event handler
gClickHandler = {
handleEvent: function handleEvent(aEvent)
{
gTdClickEventHandler = true;
}
};
gNode.addEventListener("click", gClickHandler, false);
// check actions
is(gAcc.numActions, 1, gID + ": should have one action");
is(gAcc.getActionName(0), "click", gID + ": should have 'click' action");
gAcc.doAction(0);
// actions are performed via timeout
window.setTimeout(doTest3, 0);
}
function doTest3()
{
//////////////////////////////////////////////////////////////////////////
// td with registered 'click' event handler (sequel, see doTest2())
ok(gTdClickEventHandler, gID + ": 'click' action hasn't been performed");
// unregister click event handler
gNode.removeEventListener("click", gClickHandler, false);
// check actions
is(gAcc.numActions, 0, gID + ": shouldn't have actions");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
</script>
</head>
<body>
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=420863"
title="If an HTML element has an onClick attribute, expose its click action on the element rather than its child text leaf node."
target="_blank">Mozilla Bug 420863</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<table>
<tr>
<td id="td1">Can't click this cell</td>
<td onclick="gTdClickAttr = true;"
id="td2">Cell with 'onclick' attribute</td>
<td id="td3">Cell with registered 'click' event handler</td>
</tr>
</table>
</body>
</html>