From 87844f2e94a295460ef7d7afaaea801da531d25b Mon Sep 17 00:00:00 2001 From: "surkov.alexander@gmail.com" Date: Sat, 15 Mar 2008 18:23:41 -0700 Subject: [PATCH] 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 --- accessible/src/base/nsAccessible.cpp | 58 +++++++- accessible/tests/mochitest/Makefile.in | 1 + .../tests/mochitest/test_bug420863.html | 126 ++++++++++++++++++ 3 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 accessible/tests/mochitest/test_bug420863.html diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index 2f83c6dd80b..24c9251956f 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -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 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 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 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 (); */ diff --git a/accessible/tests/mochitest/Makefile.in b/accessible/tests/mochitest/Makefile.in index b29bbced081..ee275ec51a4 100644 --- a/accessible/tests/mochitest/Makefile.in +++ b/accessible/tests/mochitest/Makefile.in @@ -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 \ diff --git a/accessible/tests/mochitest/test_bug420863.html b/accessible/tests/mochitest/test_bug420863.html new file mode 100644 index 00000000000..89f5ca5212e --- /dev/null +++ b/accessible/tests/mochitest/test_bug420863.html @@ -0,0 +1,126 @@ + + + + + Table indexes chrome tests + + + + + + + + + + Mozilla Bug 420863 +

+ +
+  
+ + + + + + + +
Can't click this cellCell with 'onclick' attributeCell with registered 'click' event handler
+ + +