From 1e7f8acc76b9985ede90fb79407404cc732daf0f Mon Sep 17 00:00:00 2001 From: "aaronleventhal%moonset.net" Date: Wed, 17 Aug 2005 17:22:16 +0000 Subject: [PATCH] Bug 304871. Hitting enter with screen reader active will not open new window links. r=timeless, sr=jst --- accessible/src/base/nsAccessible.cpp | 33 ++++++++++++++----- accessible/src/base/nsAccessible.h | 2 +- .../src/html/nsHTMLFormControlAccessible.cpp | 21 ++---------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index e1c770e9403..357273ca0ed 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -2166,17 +2166,29 @@ void nsAccessible::DoCommandCallback(nsITimer *aTimer, void *aClosure) { NS_ASSERTION(gDoCommandTimer, "How did we get here if there was no gDoCommandTimer?"); NS_RELEASE(gDoCommandTimer); - gDoCommandTimer = nsnull; - nsIDOMNode *node = NS_REINTERPRET_CAST(nsIDOMNode*, aClosure); - nsCOMPtr xulElement(do_QueryInterface(node)); + nsIContent *content = NS_REINTERPRET_CAST(nsIContent*, aClosure); + nsCOMPtr xulElement(do_QueryInterface(content)); if (xulElement) { xulElement->Click(); } else { - nsCOMPtr htmlElement(do_QueryInterface(node)); - if (htmlElement) - htmlElement->Click(); + nsIDocument *doc = content->GetDocument(); + if (!doc) { + return; + } + nsIPresShell *presShell = doc->GetShellAt(0); + nsPIDOMWindow *outerWindow = doc->GetWindow(); + if (presShell && outerWindow) { + nsAutoPopupStatePusher popupStatePusher(outerWindow, openAllowed); + + nsMouseEvent clickEvent(PR_TRUE, NS_MOUSE_LEFT_CLICK, nsnull, + nsMouseEvent::eSynthesized); + + nsEventStatus eventStatus = nsEventStatus_eIgnore; + content->HandleDOMEvent(presShell->GetPresContext(), &clickEvent, nsnull, + NS_EVENT_FLAG_INIT, &eventStatus); + } } } @@ -2188,9 +2200,12 @@ void nsAccessible::DoCommandCallback(nsITimer *aTimer, void *aClosure) * nsXXXAccessible::DoAction, it will block AT-Tools(e.g. GOK) that invoke * "action" of mozilla accessibles direclty. */ -nsresult nsAccessible::DoCommand() - +nsresult nsAccessible::DoCommand(nsIContent *aContent) { + nsCOMPtr content = aContent; + if (!content) { + content = do_QueryInterface(mDOMNode); + } if (gDoCommandTimer) { // Already have timer going for another command NS_WARNING("Doubling up on do command timers doesn't work. This wasn't expected."); @@ -2204,7 +2219,7 @@ nsresult nsAccessible::DoCommand() NS_ADDREF(gDoCommandTimer = timer); return gDoCommandTimer->InitWithFuncCallback(DoCommandCallback, - (void*)mDOMNode, 0, + (void*)content, 0, nsITimer::TYPE_ONE_SHOT); } diff --git a/accessible/src/base/nsAccessible.h b/accessible/src/base/nsAccessible.h index 9d27578c83f..6e8d4f76289 100644 --- a/accessible/src/base/nsAccessible.h +++ b/accessible/src/base/nsAccessible.h @@ -185,7 +185,7 @@ protected: // For accessibles that have actions static void DoCommandCallback(nsITimer *aTimer, void *aClosure); - nsresult DoCommand(); + nsresult DoCommand(nsIContent *aContent = nsnull); // Data Members nsCOMPtr mParent; diff --git a/accessible/src/html/nsHTMLFormControlAccessible.cpp b/accessible/src/html/nsHTMLFormControlAccessible.cpp index a50fbb06a12..6497eb4210a 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.cpp +++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp @@ -88,12 +88,7 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetActionName(PRUint8 index, nsAString& NS_IMETHODIMP nsHTMLCheckboxAccessible::DoAction(PRUint8 index) { if (index == 0) { // 0 is the magic value for default action - nsCOMPtr htmlCheckboxElement(do_QueryInterface(mDOMNode)); - if (htmlCheckboxElement) { - htmlCheckboxElement->Click(); - return NS_OK; - } - return NS_ERROR_FAILURE; + return DoCommand(); } return NS_ERROR_INVALID_ARG; } @@ -123,11 +118,7 @@ nsRadioButtonAccessible(aNode, aShell) NS_IMETHODIMP nsHTMLRadioButtonAccessible::DoAction(PRUint8 index) { if (index == eAction_Click) { - nsCOMPtr element(do_QueryInterface(mDOMNode)); - if (element) { - element->Click(); - return NS_OK; - } + return DoCommand(); } return NS_ERROR_INVALID_ARG; } @@ -270,13 +261,7 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetActionName(PRUint8 index, nsAString& _ NS_IMETHODIMP nsHTML4ButtonAccessible::DoAction(PRUint8 index) { if (index == 0) { - nsCOMPtr buttonElement(do_QueryInterface(mDOMNode)); - if ( buttonElement ) - { - buttonElement->Click(); - return NS_OK; - } - return NS_ERROR_FAILURE; + return DoCommand(); } return NS_ERROR_INVALID_ARG; }