From 9bc60ce040856918c1c26a3dd3137dde37f27d5e Mon Sep 17 00:00:00 2001 From: "aaronleventhal%moonset.net" Date: Thu, 21 Jul 2005 00:48:09 +0000 Subject: [PATCH] bug 300778. Expose elements with onclick handlers. Patch by Peter Parente. r=aaronlev, sr=neil, a=mkaply --- accessible/src/base/nsAccessibilityAtomList.h | 3 +- .../src/base/nsAccessibilityService.cpp | 1 + accessible/src/base/nsAccessible.cpp | 45 ++++++++++++++++--- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/accessible/src/base/nsAccessibilityAtomList.h b/accessible/src/base/nsAccessibilityAtomList.h index 1fbec804c9a4..25a86204b43d 100755 --- a/accessible/src/base/nsAccessibilityAtomList.h +++ b/accessible/src/base/nsAccessibilityAtomList.h @@ -39,7 +39,7 @@ /****** This file contains the list of all accessibility nsIAtoms and their values - + It is designed to be used as inline input to nsAccessibilityAtoms.cpp *only* through the magic of C preprocessing. @@ -113,6 +113,7 @@ ACCESSIBILITY_ATOM(id, "id") ACCESSIBILITY_ATOM(lang, "lang") ACCESSIBILITY_ATOM(multiline, "multiline") ACCESSIBILITY_ATOM(name, "name") +ACCESSIBILITY_ATOM(onclick, "onclick") ACCESSIBILITY_ATOM(readonly, "readonly") ACCESSIBILITY_ATOM(src, "src") ACCESSIBILITY_ATOM(summary, "summary") diff --git a/accessible/src/base/nsAccessibilityService.cpp b/accessible/src/base/nsAccessibilityService.cpp index 6802b204452c..bdbf53ec1a91 100644 --- a/accessible/src/base/nsAccessibilityService.cpp +++ b/accessible/src/base/nsAccessibilityService.cpp @@ -521,6 +521,7 @@ nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsISupports *aFrame, tag == nsAccessibilityAtoms::tbody || tag == nsAccessibilityAtoms::tfoot || tag == nsAccessibilityAtoms::thead || + content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::onclick) || #else else if ( #endif diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index f9524646a868..66adf6c38dd7 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -1889,21 +1889,56 @@ NS_IMETHODIMP nsAccessible::GetRole(PRUint32 *aRole) } /* PRUint8 getAccNumActions (); */ -NS_IMETHODIMP nsAccessible::GetNumActions(PRUint8 *_retval) +NS_IMETHODIMP nsAccessible::GetNumActions(PRUint8 *aNumActions) { - return NS_ERROR_NOT_IMPLEMENTED; + nsCOMPtr content(do_QueryInterface(mDOMNode)); + if (content && content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::onclick)) { + *aNumActions = 1; + } else { + *aNumActions = 0; + } + return NS_OK; } /* DOMString getAccActionName (in PRUint8 index); */ -NS_IMETHODIMP nsAccessible::GetActionName(PRUint8 index, nsAString& _retval) +NS_IMETHODIMP nsAccessible::GetActionName(PRUint8 index, nsAString& aName) { - return NS_ERROR_NOT_IMPLEMENTED; + nsCOMPtr content(do_QueryInterface(mDOMNode)); + if (content && content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::onclick)) { + // Action 0 (default action): Click on element + if (index == eAction_Click) { + nsAccessible::GetTranslatedString(NS_LITERAL_STRING("click"), aName); + return NS_OK; + } + return NS_ERROR_INVALID_ARG; + } + return NS_ERROR_FAILURE; } /* void doAction (in PRUint8 index); */ NS_IMETHODIMP nsAccessible::DoAction(PRUint8 index) { - return NS_ERROR_NOT_IMPLEMENTED; + nsCOMPtr content(do_QueryInterface(mDOMNode)); + if (content && content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::onclick)) { + // Action 0 (default action): Click on element + if (index == eAction_Click) { + nsCOMPtr presContext(GetPresContext()); + if (presContext && content) { + nsMouseEvent linkClickEvent(PR_TRUE, NS_MOUSE_LEFT_CLICK, nsnull, + nsMouseEvent::eReal); + + nsEventStatus eventStatus = nsEventStatus_eIgnore; + content->HandleDOMEvent(presContext, + &linkClickEvent, + nsnull, + NS_EVENT_FLAG_INIT, + &eventStatus); + return NS_OK; + } + } + return NS_ERROR_INVALID_ARG; + } + return NS_ERROR_FAILURE; } /* DOMString getHelp (); */