From 39719216baab9dce6c5e5f611d949fab8b35e98f Mon Sep 17 00:00:00 2001 From: "aaronl%netscape.com" Date: Sat, 12 Jan 2002 00:23:06 +0000 Subject: [PATCH] Bug 118851. Active Accessibility: return i18n compatible names again. r=jgaunt, sr=hewitt. Bug 119312. Active Accessibility: GetAccFocused needs to return the IAccessible for the currently focused node. r=jgaunt, sr=alecf --- accessible/src/base/accessible.properties | 3 +- accessible/src/base/nsAccessible.cpp | 38 +++++++------------ accessible/src/base/nsAccessible.h | 2 +- .../src/base/nsBaseWidgetAccessible.cpp | 2 +- .../src/base/nsFormControlAccessible.cpp | 2 +- accessible/src/base/nsSelectAccessible.cpp | 4 +- .../src/html/nsHTMLFormControlAccessible.cpp | 8 ++-- .../src/xul/nsXULFormControlAccessible.cpp | 2 +- accessible/src/xul/nsXULTabAccessible.cpp | 2 +- 9 files changed, 26 insertions(+), 37 deletions(-) diff --git a/accessible/src/base/accessible.properties b/accessible/src/base/accessible.properties index a4d47e31314..3a3e9aceb29 100644 --- a/accessible/src/base/accessible.properties +++ b/accessible/src/base/accessible.properties @@ -4,4 +4,5 @@ check = Check uncheck = Uncheck select = Select open = Open -close = Close \ No newline at end of file +close = Close +switch = Switch diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index 4a2ed323f78..df36b7b1fd8 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -572,7 +572,7 @@ NS_IMETHODIMP nsAccessible::GetAccChildCount(PRInt32 *aAccChildCount) return NS_OK; } -nsresult nsAccessible::GetTranslatedString(PRUnichar *aKey, nsAWritableString *aStringOut) +nsresult nsAccessible::GetTranslatedString(const nsAReadableString& aKey, nsAWritableString& aStringOut) { static nsCOMPtr stringBundle; static PRBool firstTime = PR_TRUE; @@ -582,7 +582,6 @@ nsresult nsAccessible::GetTranslatedString(PRUnichar *aKey, nsAWritableString *a nsresult rv; nsCOMPtr stringBundleService = do_GetService(kStringBundleServiceCID, &rv); - // nsCOMPtr stringBundleService(do_GetService(kStringBundleServiceCID, &rv)); if (!stringBundleService) { NS_WARNING("ERROR: Failed to get StringBundle Service instance.\n"); return NS_ERROR_FAILURE; @@ -592,10 +591,10 @@ nsresult nsAccessible::GetTranslatedString(PRUnichar *aKey, nsAWritableString *a nsXPIDLString xsValue; if (!stringBundle || - NS_FAILED(stringBundle->GetStringFromName(aKey, getter_Copies(xsValue)))) + NS_FAILED(stringBundle->GetStringFromName(PromiseFlatString(aKey).get(), getter_Copies(xsValue)))) return NS_ERROR_FAILURE; - aStringOut->Assign(xsValue); + aStringOut.Assign(xsValue); return NS_OK; } @@ -709,33 +708,22 @@ NS_IMETHODIMP nsAccessible::GetAccState(PRUint32 *aAccState) /* readonly attribute boolean accFocused; */ NS_IMETHODIMP nsAccessible::GetAccFocused(nsIAccessible * *aAccFocused) { + *aAccFocused = nsnull; + + nsCOMPtr accService(do_GetService("@mozilla.org/accessibilityService;1")); + nsCOMPtr focusedElement; - nsIFrame *frame = nsnull; - - if (NS_SUCCEEDED(GetFocusedElement(getter_AddRefs(focusedElement)))) { - nsCOMPtr shell(do_QueryReferent(mPresShell)); - if (!shell) { - *aAccFocused = nsnull; - return NS_OK; - } - - nsCOMPtr content(do_QueryInterface(focusedElement)); - if (shell && content) - shell->GetPrimaryFrameFor(content, &frame); - } - - if (frame) { - nsCOMPtr acc(do_QueryInterface(frame)); - if (acc) { - *aAccFocused = acc; + if (accService && NS_SUCCEEDED(GetFocusedElement(getter_AddRefs(focusedElement)))) { + nsCOMPtr focusedNode(do_QueryInterface(focusedElement)); + nsCOMPtr accessible; + if (NS_SUCCEEDED(accService->GetAccessibleFor(focusedNode, getter_AddRefs(accessible)))) { + *aAccFocused = accessible; NS_ADDREF(*aAccFocused); return NS_OK; } } - *aAccFocused = nsnull; - - return NS_OK; + return NS_ERROR_FAILURE; } /* nsIAccessible accGetChildAt (in long x, in long y); */ diff --git a/accessible/src/base/nsAccessible.h b/accessible/src/base/nsAccessible.h index 0685add3f3d..8208ac2d578 100644 --- a/accessible/src/base/nsAccessible.h +++ b/accessible/src/base/nsAccessible.h @@ -107,7 +107,7 @@ protected: NS_IMETHOD CacheOptimizations(nsIAccessible *aParent, PRInt32 aSiblingIndex, nsIDOMNodeList *aSiblingList); // helper method to verify frames static PRBool IsCorrectFrameType(nsIFrame* aFrame, nsIAtom* aAtom); - static nsresult GetTranslatedString(PRUnichar *aKey, nsAWritableString *aStringOut); + static nsresult GetTranslatedString(const nsAReadableString& aKey, nsAWritableString& aStringOut); void GetScreenOrigin(nsIPresContext *aPresContext, nsIFrame *aFrame, nsRect *aRect); // Data Members diff --git a/accessible/src/base/nsBaseWidgetAccessible.cpp b/accessible/src/base/nsBaseWidgetAccessible.cpp index 654dabaa6d2..df6d99755f1 100644 --- a/accessible/src/base/nsBaseWidgetAccessible.cpp +++ b/accessible/src/base/nsBaseWidgetAccessible.cpp @@ -281,7 +281,7 @@ NS_IMETHODIMP nsLinkableAccessible::GetAccActionName(PRUint8 index, nsAWritableS // Action 0 (default action): Jump to link if (index == eAction_Jump) { if (IsALink()) { - _retval = NS_LITERAL_STRING("jump"); + nsAccessible::GetTranslatedString(NS_LITERAL_STRING("jump"), _retval); return NS_OK; } } diff --git a/accessible/src/base/nsFormControlAccessible.cpp b/accessible/src/base/nsFormControlAccessible.cpp index a345ba58d83..c03ea885704 100644 --- a/accessible/src/base/nsFormControlAccessible.cpp +++ b/accessible/src/base/nsFormControlAccessible.cpp @@ -162,7 +162,7 @@ NS_IMETHODIMP nsRadioButtonAccessible::GetAccNumActions(PRUint8 *_retval) NS_IMETHODIMP nsRadioButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) { if (index == eAction_Click) { - _retval = NS_LITERAL_STRING("select"); + nsAccessible::GetTranslatedString(NS_LITERAL_STRING("select"), _retval); return NS_OK; } return NS_ERROR_INVALID_ARG; diff --git a/accessible/src/base/nsSelectAccessible.cpp b/accessible/src/base/nsSelectAccessible.cpp index 1bdd8e05d83..bf8e892dc0c 100644 --- a/accessible/src/base/nsSelectAccessible.cpp +++ b/accessible/src/base/nsSelectAccessible.cpp @@ -535,9 +535,9 @@ NS_IMETHODIMP nsComboboxButtonAccessible::GetAccActionName(PRUint8 index, nsAWri return NS_ERROR_FAILURE; comboFrame->IsDroppedDown(&isOpen); if (isOpen) - _retval = NS_LITERAL_STRING("close"); + nsAccessible::GetTranslatedString(NS_LITERAL_STRING("close"), _retval); else - _retval = NS_LITERAL_STRING("open"); + nsAccessible::GetTranslatedString(NS_LITERAL_STRING("open"), _retval); return NS_OK; } diff --git a/accessible/src/html/nsHTMLFormControlAccessible.cpp b/accessible/src/html/nsHTMLFormControlAccessible.cpp index 93e4646dbe9..f8516895424 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.cpp +++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp @@ -84,9 +84,9 @@ NS_IMETHODIMP nsHTMLCheckboxAccessible::GetAccActionName(PRUint8 index, nsAWrita GetAccState(&state); if (state & STATE_CHECKED) - _retval = NS_LITERAL_STRING("uncheck"); + nsAccessible::GetTranslatedString(NS_LITERAL_STRING("uncheck"), _retval); else - _retval = NS_LITERAL_STRING("check"); + nsAccessible::GetTranslatedString(NS_LITERAL_STRING("check"), _retval); return NS_OK; } @@ -171,7 +171,7 @@ NS_IMETHODIMP nsHTMLButtonAccessible::GetAccNumActions(PRUint8 *_retval) NS_IMETHODIMP nsHTMLButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) { if (index == eAction_Click) { - _retval = NS_LITERAL_STRING("press"); + nsAccessible::GetTranslatedString(NS_LITERAL_STRING("press"), _retval); return NS_OK; } return NS_ERROR_INVALID_ARG; @@ -225,7 +225,7 @@ NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccNumActions(PRUint8 *_retval) NS_IMETHODIMP nsHTML4ButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) { if (index == eAction_Click) { - _retval = NS_LITERAL_STRING("press"); + nsAccessible::GetTranslatedString(NS_LITERAL_STRING("press"), _retval); return NS_OK; } return NS_ERROR_INVALID_ARG; diff --git a/accessible/src/xul/nsXULFormControlAccessible.cpp b/accessible/src/xul/nsXULFormControlAccessible.cpp index c88b24fb4eb..d40a181c0be 100644 --- a/accessible/src/xul/nsXULFormControlAccessible.cpp +++ b/accessible/src/xul/nsXULFormControlAccessible.cpp @@ -88,7 +88,7 @@ NS_IMETHODIMP nsXULButtonAccessible::GetAccNumActions(PRUint8 *_retval) NS_IMETHODIMP nsXULButtonAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) { if (index == eAction_Click) { - _retval = NS_LITERAL_STRING("press"); + nsAccessible::GetTranslatedString(NS_LITERAL_STRING("press"), _retval); return NS_OK; } return NS_ERROR_INVALID_ARG; diff --git a/accessible/src/xul/nsXULTabAccessible.cpp b/accessible/src/xul/nsXULTabAccessible.cpp index f28d60648de..6c85de8c6e3 100644 --- a/accessible/src/xul/nsXULTabAccessible.cpp +++ b/accessible/src/xul/nsXULTabAccessible.cpp @@ -74,7 +74,7 @@ NS_IMETHODIMP nsXULTabAccessible::GetAccNumActions(PRUint8 *_retval) NS_IMETHODIMP nsXULTabAccessible::GetAccActionName(PRUint8 index, nsAWritableString& _retval) { if (index == eAction_Click) { - _retval = NS_LITERAL_STRING("switch"); + nsAccessible::GetTranslatedString(NS_LITERAL_STRING("switch"), _retval); return NS_OK; } return NS_ERROR_INVALID_ARG;