From d5c0bf6b9b2033c8bfe48e297a8e3cfd777bb2e1 Mon Sep 17 00:00:00 2001 From: "kyle.yuan%sun.com" Date: Wed, 12 Jun 2002 05:27:37 +0000 Subject: [PATCH] Bug 148902 Implemetation of nsIAccessibleEditableText r=aaronl, sr=jst --- .../public/nsIAccessibleEditableText.idl | 4 +- accessible/src/html/Makefile.in | 1 + accessible/src/html/makefile.win | 1 + .../src/html/nsHTMLFormControlAccessible.cpp | 109 +++++++++++++++++- .../src/html/nsHTMLFormControlAccessible.h | 12 +- 5 files changed, 123 insertions(+), 4 deletions(-) diff --git a/accessible/public/nsIAccessibleEditableText.idl b/accessible/public/nsIAccessibleEditableText.idl index 1c7820209fb1..cb5b272a9c7c 100644 --- a/accessible/public/nsIAccessibleEditableText.idl +++ b/accessible/public/nsIAccessibleEditableText.idl @@ -34,8 +34,8 @@ interface nsIAccessibleEditableText : nsISupports */ void setAttributes (in long startPos, in long endPos, in nsISupports attributes); - boolean setTextContents (in AString text); - void insertText (in AString text, in long length, inout long position); + void setTextContents (in AString text); + void insertText (in AString text, in long position); void copyText (in long startPos, in long endPos); void cutText (in long startPos, in long endPos); void deleteText (in long startPos, in long endPos); diff --git a/accessible/src/html/Makefile.in b/accessible/src/html/Makefile.in index ebf90465989e..f7fd0187aa2f 100644 --- a/accessible/src/html/Makefile.in +++ b/accessible/src/html/Makefile.in @@ -31,6 +31,7 @@ LIBRARY_NAME = accessibility_html_s REQUIRES = content \ docshell \ dom \ + editor \ gfx \ gfx2 \ htmlparser \ diff --git a/accessible/src/html/makefile.win b/accessible/src/html/makefile.win index e79a31c13409..acb56bd7a535 100755 --- a/accessible/src/html/makefile.win +++ b/accessible/src/html/makefile.win @@ -26,6 +26,7 @@ REQUIRES = \ content \ docshell \ dom \ + editor \ gfx \ gfx2 \ htmlparser \ diff --git a/accessible/src/html/nsHTMLFormControlAccessible.cpp b/accessible/src/html/nsHTMLFormControlAccessible.cpp index 49874ff1f7ee..32d02d801f3b 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.cpp +++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp @@ -42,6 +42,7 @@ #include "nsFormControlAccessible.h" #include "nsHTMLAtoms.h" #include "nsHTMLFormControlAccessible.h" +#include "nsIClipboard.h" #include "nsIDOMHTMLButtonElement.h" #include "nsIDOMHTMLFormElement.h" #include "nsIDOMHTMLInputElement.h" @@ -52,8 +53,12 @@ #include "nsIDOMXULButtonElement.h" #include "nsIDOMXULSelectCntrlItemEl.h" #include "nsIDOMXULSelectCntrlEl.h" -#include "nsINameSpaceManager.h" +#include "nsIEditor.h" +#include "nsIEventStateManager.h" #include "nsIFrame.h" +#include "nsIGfxTextControlFrame.h" +#include "nsINameSpaceManager.h" +#include "nsIPlaintextEditor.h" #include "nsISelectionController.h" #include "nsReadableUtils.h" #include "nsWeakReference.h" @@ -310,6 +315,8 @@ nsFormControlAccessible(aNode, aShell) { } +NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLTextFieldAccessible, nsFormControlAccessible, nsIAccessibleEditableText) + NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccRole(PRUint32 *_retval) { *_retval = ROLE_TEXT; @@ -400,6 +407,106 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAccState(PRUint32 *_retval) return NS_OK; } +NS_IMETHODIMP nsHTMLTextFieldAccessible::SetAttributes(PRInt32 aStartPos, PRInt32 aEndPos, nsISupports *aAttributes) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP nsHTMLTextFieldAccessible::SetTextContents(const nsAString &aText) +{ + nsCOMPtr textArea(do_QueryInterface(mDOMNode)); + if (textArea) + return textArea->SetValue(aText); + + nsCOMPtr inputElement(do_QueryInterface(mDOMNode)); + if (inputElement) + return inputElement->SetValue(aText); + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsHTMLTextFieldAccessible::MakeSelection(PRInt32 aStartPos, PRInt32 aEndPos, nsIEditor **aEditor) +{ + nsCOMPtr shell(do_QueryReferent(mPresShell)); + if (!shell) + return NS_ERROR_FAILURE; + + AccTakeFocus(); + + nsCOMPtr content(do_QueryInterface(mDOMNode)); + nsIFrame *frame = nsnull; + shell->GetPrimaryFrameFor(content, &frame); + nsCOMPtr tframe(do_QueryInterface(frame)); + if (!tframe) + return NS_ERROR_FAILURE; + + nsCOMPtr editor; + tframe->SetSelectionRange(aStartPos, aEndPos); + tframe->GetEditor(getter_AddRefs(editor)); + if (!editor) + return NS_ERROR_FAILURE; + + *aEditor = editor; + NS_ADDREF(*aEditor); + + return NS_OK; +} + +NS_IMETHODIMP nsHTMLTextFieldAccessible::InsertText(const nsAString &aText, PRInt32 aPosition) +{ + nsCOMPtr editor; + if (NS_SUCCEEDED(MakeSelection(aPosition, aPosition, getter_AddRefs(editor)))) { + nsCOMPtr peditor(do_QueryInterface(editor)); + peditor->InsertText(aText); + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsHTMLTextFieldAccessible::CopyText(PRInt32 aStartPos, PRInt32 aEndPos) +{ + nsCOMPtr editor; + if (NS_SUCCEEDED(MakeSelection(aStartPos, aEndPos, getter_AddRefs(editor)))) { + editor->Copy(); + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsHTMLTextFieldAccessible::CutText(PRInt32 aStartPos, PRInt32 aEndPos) +{ + nsCOMPtr editor; + if (NS_SUCCEEDED(MakeSelection(aStartPos, aEndPos, getter_AddRefs(editor)))) { + editor->Cut(); + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsHTMLTextFieldAccessible::DeleteText(PRInt32 aStartPos, PRInt32 aEndPos) +{ + nsCOMPtr editor; + if (NS_SUCCEEDED(MakeSelection(aStartPos, aEndPos, getter_AddRefs(editor)))) { + editor->DeleteSelection(nsIEditor::eNone); + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsHTMLTextFieldAccessible::PasteText(PRInt32 aPosition) +{ + nsCOMPtr editor; + if (NS_SUCCEEDED(MakeSelection(aPosition, aPosition, getter_AddRefs(editor)))) { + editor->Paste(nsIClipboard::kGlobalClipboard); + return NS_OK; + } + + return NS_ERROR_FAILURE; +} // --- groupbox ----- diff --git a/accessible/src/html/nsHTMLFormControlAccessible.h b/accessible/src/html/nsHTMLFormControlAccessible.h index 2ba4e2805ac6..2642465c4885 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.h +++ b/accessible/src/html/nsHTMLFormControlAccessible.h @@ -42,6 +42,7 @@ #include "nsBaseWidgetAccessible.h" #include "nsFormControlAccessible.h" +#include "nsIAccessibleEditableText.h" class nsICheckboxControlFrame; @@ -92,13 +93,22 @@ public: NS_IMETHOD AccDoAction(PRUint8 index); }; -class nsHTMLTextFieldAccessible : public nsFormControlAccessible +class nsIEditor; + +class nsHTMLTextFieldAccessible : public nsFormControlAccessible, + public nsIAccessibleEditableText { public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_NSIACCESSIBLEEDITABLETEXT + nsHTMLTextFieldAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); NS_IMETHOD GetAccRole(PRUint32 *_retval); NS_IMETHOD GetAccValue(nsAString& _retval); NS_IMETHOD GetAccState(PRUint32 *_retval); + +protected: + NS_IMETHOD MakeSelection(PRInt32 aStartPos, PRInt32 aEndPos, nsIEditor **aEditor); }; class nsHTMLGroupboxAccessible : public nsAccessible