From b08ef7a65db60ec366b9bf80b4d527cafecae07e Mon Sep 17 00:00:00 2001 From: "aaronleventhal@moonset.net" Date: Tue, 14 Aug 2007 09:25:24 -0700 Subject: [PATCH] Bug 390767. Support editable state and interface for contentEditable and designMode documents and their content. r=ginn.chen, a=dsicore --- accessible/src/base/nsAccessibilityAtomList.h | 1 + accessible/src/base/nsDocAccessible.cpp | 75 ++++++++++--------- accessible/src/base/nsDocAccessible.h | 7 +- accessible/src/html/Makefile.in | 3 +- .../src/html/nsHTMLFormControlAccessible.cpp | 35 ++------- .../src/html/nsHTMLFormControlAccessible.h | 12 +-- accessible/src/html/nsHyperTextAccessible.cpp | 62 +++++++++++---- accessible/src/html/nsHyperTextAccessible.h | 5 -- accessible/src/xforms/nsXFormsAccessible.cpp | 37 ++------- accessible/src/xforms/nsXFormsAccessible.h | 11 +-- .../src/xul/nsXULFormControlAccessible.cpp | 35 ++------- .../src/xul/nsXULFormControlAccessible.h | 13 +--- 12 files changed, 121 insertions(+), 175 deletions(-) diff --git a/accessible/src/base/nsAccessibilityAtomList.h b/accessible/src/base/nsAccessibilityAtomList.h index 892bd3dfb2c6..374089bf3b2e 100755 --- a/accessible/src/base/nsAccessibilityAtomList.h +++ b/accessible/src/base/nsAccessibilityAtomList.h @@ -153,6 +153,7 @@ ACCESSIBILITY_ATOM(accesskey, "accesskey") ACCESSIBILITY_ATOM(alt, "alt") ACCESSIBILITY_ATOM(anonid, "anonid") // Used for ID's in XBL ACCESSIBILITY_ATOM(autocomplete, "autocomplete") // Used as attribute value too +ACCESSIBILITY_ATOM(contenteditable, "contenteditable") ACCESSIBILITY_ATOM(control, "control") ACCESSIBILITY_ATOM(cycles, "cycles") // used for XUL cycler attribute ACCESSIBILITY_ATOM(curpos, "curpos") // XUL diff --git a/accessible/src/base/nsDocAccessible.cpp b/accessible/src/base/nsDocAccessible.cpp index 31a7076d3a27..1916e279806c 100644 --- a/accessible/src/base/nsDocAccessible.cpp +++ b/accessible/src/base/nsDocAccessible.cpp @@ -243,7 +243,8 @@ nsDocAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) } } - nsCOMPtr editor = GetEditor(); + nsCOMPtr editor; + GetAssociatedEditor(getter_AddRefs(editor)); if (!editor) { *aState |= nsIAccessibleStates::STATE_READONLY; } @@ -397,37 +398,33 @@ NS_IMETHODIMP nsDocAccessible::GetDocument(nsIDOMDocument **aDOMDoc) return NS_ERROR_FAILURE; } -void nsDocAccessible::SetEditor(nsIEditor* aEditor) +NS_IMETHODIMP nsDocAccessible::GetAssociatedEditor(nsIEditor **aEditor) { - mEditor = aEditor; -} + NS_ENSURE_ARG_POINTER(aEditor); -void nsDocAccessible::CheckForEditor() -{ - if (mEditor) { - return; // Already have editor, don't need to check - } - if (!mDocument) { - return; // No document -- we've been shut down + *aEditor = nsnull; + NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE); + + if (!mDocument->HasFlag(NODE_IS_EDITABLE)) { + return NS_OK; // Document not editable } nsCOMPtr container = mDocument->GetContainer(); nsCOMPtr editingSession(do_GetInterface(container)); if (!editingSession) - return; // No editing session interface + return NS_OK; // No editing session interface nsCOMPtr editor; - editingSession->GetEditorForWindow(mDocument->GetWindow(), - getter_AddRefs(editor)); - SetEditor(editor); - if (!editor) - return; - - // State editable is now set, readonly is now clear - nsCOMPtr event = - new nsAccStateChangeEvent(this, nsIAccessibleStates::EXT_STATE_EDITABLE, - PR_TRUE, PR_TRUE); - FireAccessibleEvent(event); + editingSession->GetEditorForWindow(mDocument->GetWindow(), getter_AddRefs(editor)); + if (!editor) { + return NS_OK; + } + PRBool isEditable; + editor->GetIsDocumentEditable(&isEditable); + if (isEditable) { + NS_ADDREF(*aEditor = editor); + } + return NS_OK; } NS_IMETHODIMP nsDocAccessible::GetCachedAccessNode(void *aUniqueID, nsIAccessNode **aAccessNode) @@ -531,8 +528,6 @@ NS_IMETHODIMP nsDocAccessible::Shutdown() nsCOMPtr treeItem = GetDocShellTreeItemFor(mDOMNode); ShutdownChildDocuments(treeItem); - mEditor = nsnull; - if (mDocLoadTimer) { mDocLoadTimer->Cancel(); mDocLoadTimer = nsnull; @@ -653,14 +648,10 @@ nsresult nsDocAccessible::AddEventListeners() PRBool isContent = (itemType == nsIDocShellTreeItem::typeContent); if (isContent) { - CheckForEditor(); - - if (!mEditor) { - // We're not an editor yet, but we might become one - nsCOMPtr commandManager = do_GetInterface(docShellTreeItem); - if (commandManager) { - commandManager->AddCommandObserver(this, "obs_documentCreated"); - } + // We're not an editor yet, but we might become one + nsCOMPtr commandManager = do_GetInterface(docShellTreeItem); + if (commandManager) { + commandManager->AddCommandObserver(this, "obs_documentCreated"); } } @@ -898,9 +889,12 @@ NS_IMETHODIMP nsDocAccessible::ScrollPositionDidChange(nsIScrollableView *aScrol NS_IMETHODIMP nsDocAccessible::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData) { - if (!nsCRT::strcmp(aTopic,"obs_documentCreated")) { - CheckForEditor(); - NS_ASSERTION(mEditor, "Should have editor if we see obs_documentCreated"); + if (!nsCRT::strcmp(aTopic,"obs_documentCreated")) { + // State editable will now be set, readonly is now clear + nsCOMPtr event = + new nsAccStateChangeEvent(this, nsIAccessibleStates::EXT_STATE_EDITABLE, + PR_TRUE, PR_TRUE); + FireAccessibleEvent(event); } return NS_OK; @@ -1030,6 +1024,15 @@ nsDocAccessible::AttributeChanged(nsIDocument *aDocument, nsIContent* aContent, targetNode, nsnull); } } + + if (aAttribute == nsAccessibilityAtoms::contenteditable) { + nsCOMPtr editableChangeEvent = + new nsAccStateChangeEvent(targetNode, + nsIAccessibleStates::EXT_STATE_EDITABLE, + PR_TRUE); + FireDelayedAccessibleEvent(editableChangeEvent); + return; + } } void diff --git a/accessible/src/base/nsDocAccessible.h b/accessible/src/base/nsDocAccessible.h index c5f4c2bc63ca..5c516eaf11a9 100644 --- a/accessible/src/base/nsDocAccessible.h +++ b/accessible/src/base/nsDocAccessible.h @@ -99,6 +99,9 @@ class nsDocAccessible : public nsHyperTextAccessibleWrap, // nsPIAccessNode NS_IMETHOD_(nsIFrame *) GetFrame(void); + // nsIAccessibleText + NS_IMETHOD GetAssociatedEditor(nsIEditor **aEditor); + /** * Non-virtual method to fire a delayed event after a 0 length timeout * @@ -139,9 +142,6 @@ class nsDocAccessible : public nsHyperTextAccessibleWrap, void RemoveScrollListener(); void RefreshNodes(nsIDOMNode *aStartNode); static void ScrollTimerCallback(nsITimer *aTimer, void *aClosure); - void CheckForEditor(); - virtual void SetEditor(nsIEditor *aEditor); - virtual already_AddRefed GetEditor() { nsIEditor *editor = mEditor; NS_IF_ADDREF(editor); return editor; } /** * Fires accessible events when ARIA attribute is chaned. @@ -180,7 +180,6 @@ class nsDocAccessible : public nsHyperTextAccessibleWrap, PRUint16 mScrollPositionChangedTicks; // Used for tracking scroll events PRPackedBool mIsContentLoaded; nsCOMArray mEventsToFire; - nsCOMPtr mEditor; protected: PRBool mIsAnchor; diff --git a/accessible/src/html/Makefile.in b/accessible/src/html/Makefile.in index 8963102a111c..e717f00c3759 100644 --- a/accessible/src/html/Makefile.in +++ b/accessible/src/html/Makefile.in @@ -47,7 +47,8 @@ MODULE = accessibility LIBRARY_NAME = accessibility_html_s LIBXUL_LIBRARY = 1 -REQUIRES = content \ +REQUIRES = composer \ + content \ docshell \ dom \ editor \ diff --git a/accessible/src/html/nsHTMLFormControlAccessible.cpp b/accessible/src/html/nsHTMLFormControlAccessible.cpp index 8906f251eb09..7fbdccd195bb 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.cpp +++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp @@ -48,6 +48,7 @@ #include "nsIDOMHTMLFormElement.h" #include "nsIDOMHTMLLegendElement.h" #include "nsIDOMHTMLTextAreaElement.h" +#include "nsIEditor.h" #include "nsIFrame.h" #include "nsINameSpaceManager.h" #include "nsISelectionController.h" @@ -372,21 +373,6 @@ nsHyperTextAccessibleWrap(aNode, aShell) { } -NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLTextFieldAccessible, nsHyperTextAccessibleWrap, - nsIAccessibleText) - -NS_IMETHODIMP nsHTMLTextFieldAccessible::Init() -{ - CheckForEditor(); - return nsHyperTextAccessibleWrap::Init(); -} - -NS_IMETHODIMP nsHTMLTextFieldAccessible::Shutdown() -{ - mEditor = nsnull; - return nsHyperTextAccessibleWrap::Shutdown(); -} - NS_IMETHODIMP nsHTMLTextFieldAccessible::GetRole(PRUint32 *aRole) { *aRole = nsIAccessibleRole::ROLE_ENTRY; @@ -542,17 +528,11 @@ NS_IMETHODIMP nsHTMLTextFieldAccessible::DoAction(PRUint8 index) return NS_ERROR_INVALID_ARG; } -void nsHTMLTextFieldAccessible::SetEditor(nsIEditor* aEditor) -{ - mEditor = aEditor; -} - -void nsHTMLTextFieldAccessible::CheckForEditor() +NS_IMETHODIMP nsHTMLTextFieldAccessible::GetAssociatedEditor(nsIEditor **aEditor) { + *aEditor = nsnull; nsCOMPtr editableElt(do_QueryInterface(mDOMNode)); - if (!editableElt) { - return; - } + NS_ENSURE_TRUE(editableElt, NS_ERROR_FAILURE); // nsGenericHTMLElement::GetEditor has a security check. // Make sure we're not restricted by the permissions of @@ -562,16 +542,15 @@ void nsHTMLTextFieldAccessible::CheckForEditor() PRBool pushed = stack && NS_SUCCEEDED(stack->Push(nsnull)); nsCOMPtr editor; - nsresult rv = editableElt->GetEditor(getter_AddRefs(editor)); - if (NS_SUCCEEDED(rv)) { - SetEditor(editor); - } + nsresult rv = editableElt->GetEditor(aEditor); if (pushed) { JSContext* cx; stack->Pop(&cx); NS_ASSERTION(!cx, "context should be null"); } + + return rv; } // --- groupbox ----- diff --git a/accessible/src/html/nsHTMLFormControlAccessible.h b/accessible/src/html/nsHTMLFormControlAccessible.h index 09660b7edbd9..6ad322f62d77 100644 --- a/accessible/src/html/nsHTMLFormControlAccessible.h +++ b/accessible/src/html/nsHTMLFormControlAccessible.h @@ -102,12 +102,8 @@ class nsHTMLTextFieldAccessible : public nsHyperTextAccessibleWrap public: enum { eAction_Click = 0 }; - NS_DECL_ISUPPORTS_INHERITED - nsHTMLTextFieldAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); - NS_IMETHOD Init(); - NS_IMETHOD Shutdown(); NS_IMETHOD GetRole(PRUint32 *_retval); NS_IMETHOD GetName(nsAString& aName); NS_IMETHOD GetValue(nsAString& _retval); @@ -116,12 +112,8 @@ public: NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName); NS_IMETHOD DoAction(PRUint8 index); -protected: - // Editor helpers, subclasses of nsHyperTextAccessible may have editor - virtual void SetEditor(nsIEditor *aEditor); - virtual already_AddRefed GetEditor() { nsIEditor *editor = mEditor; NS_IF_ADDREF(editor); return editor; } - void CheckForEditor(); - nsCOMPtr mEditor; + // nsIAccessibleEditableText + NS_IMETHOD GetAssociatedEditor(nsIEditor **aEditor); }; class nsHTMLGroupboxAccessible : public nsHyperTextAccessibleWrap diff --git a/accessible/src/html/nsHyperTextAccessible.cpp b/accessible/src/html/nsHyperTextAccessible.cpp index 742b64ac3d3e..4226d04a0c30 100644 --- a/accessible/src/html/nsHyperTextAccessible.cpp +++ b/accessible/src/html/nsHyperTextAccessible.cpp @@ -47,12 +47,16 @@ #include "nsIDOMAbstractView.h" #include "nsIDOMCharacterData.h" #include "nsIDOMDocument.h" +#include "nsPIDOMWindow.h" #include "nsIDOMDocumentView.h" #include "nsIDOMRange.h" #include "nsIDOMWindowInternal.h" #include "nsIDOMXULDocument.h" +#include "nsIEditingSession.h" +#include "nsIEditor.h" #include "nsIFontMetrics.h" #include "nsIFrame.h" +#include "nsIInterfaceRequestorUtils.h" #include "nsIPlaintextEditor.h" #include "nsIServiceManager.h" #include "nsTextFragment.h" @@ -64,8 +68,8 @@ static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID); // nsHyperTextAccessible // ------------ -NS_IMPL_ADDREF_INHERITED(nsHyperTextAccessible, nsAccessible) -NS_IMPL_RELEASE_INHERITED(nsHyperTextAccessible, nsAccessible) +NS_IMPL_ADDREF_INHERITED(nsHyperTextAccessible, nsAccessibleWrap) +NS_IMPL_RELEASE_INHERITED(nsHyperTextAccessible, nsAccessibleWrap) nsresult nsHyperTextAccessible::QueryInterface(REFNSIID aIID, void** aInstancePtr) { @@ -169,7 +173,8 @@ nsHyperTextAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) if (!aExtraState) return NS_OK; - nsCOMPtr editor = GetEditor(); + nsCOMPtr editor; + GetAssociatedEditor(getter_AddRefs(editor)); if (editor) { PRUint32 flags; editor->GetFlags(&flags); @@ -195,8 +200,16 @@ void nsHyperTextAccessible::CacheChildren() return; } + // Special case for text entry fields, go directly to editor's root for children if (mAccChildCount == eChildCountUninitialized) { - nsCOMPtr editor = GetEditor(); + PRUint32 role; + GetRole(&role); + if (role != nsIAccessibleRole::ROLE_ENTRY && role != nsIAccessibleRole::ROLE_PASSWORD_TEXT) { + nsAccessible::CacheChildren(); + return; + } + nsCOMPtr editor; + GetAssociatedEditor(getter_AddRefs(editor)); if (!editor) { nsAccessible::CacheChildren(); return; @@ -1152,7 +1165,8 @@ NS_IMETHODIMP nsHyperTextAccessible::SetTextContents(const nsAString &aText) NS_IMETHODIMP nsHyperTextAccessible::InsertText(const nsAString &aText, PRInt32 aPosition) { if (NS_SUCCEEDED(SetCaretOffset(aPosition))) { - nsCOMPtr editor = GetEditor(); + nsCOMPtr editor; + GetAssociatedEditor(getter_AddRefs(editor)); nsCOMPtr peditor(do_QueryInterface(editor)); return peditor ? peditor->InsertText(aText) : NS_ERROR_FAILURE; } @@ -1162,7 +1176,8 @@ NS_IMETHODIMP nsHyperTextAccessible::InsertText(const nsAString &aText, PRInt32 NS_IMETHODIMP nsHyperTextAccessible::CopyText(PRInt32 aStartPos, PRInt32 aEndPos) { - nsCOMPtr editor = GetEditor(); + nsCOMPtr editor; + GetAssociatedEditor(getter_AddRefs(editor)); if (editor && NS_SUCCEEDED(SetSelectionRange(aStartPos, aEndPos))) return editor->Copy(); @@ -1171,7 +1186,8 @@ NS_IMETHODIMP nsHyperTextAccessible::CopyText(PRInt32 aStartPos, PRInt32 aEndPos NS_IMETHODIMP nsHyperTextAccessible::CutText(PRInt32 aStartPos, PRInt32 aEndPos) { - nsCOMPtr editor = GetEditor(); + nsCOMPtr editor; + GetAssociatedEditor(getter_AddRefs(editor)); if (editor && NS_SUCCEEDED(SetSelectionRange(aStartPos, aEndPos))) return editor->Cut(); @@ -1180,7 +1196,8 @@ NS_IMETHODIMP nsHyperTextAccessible::CutText(PRInt32 aStartPos, PRInt32 aEndPos) NS_IMETHODIMP nsHyperTextAccessible::DeleteText(PRInt32 aStartPos, PRInt32 aEndPos) { - nsCOMPtr editor = GetEditor(); + nsCOMPtr editor; + GetAssociatedEditor(getter_AddRefs(editor)); if (editor && NS_SUCCEEDED(SetSelectionRange(aStartPos, aEndPos))) return editor->DeleteSelection(nsIEditor::eNone); @@ -1189,7 +1206,8 @@ NS_IMETHODIMP nsHyperTextAccessible::DeleteText(PRInt32 aStartPos, PRInt32 aEndP NS_IMETHODIMP nsHyperTextAccessible::PasteText(PRInt32 aPosition) { - nsCOMPtr editor = GetEditor(); + nsCOMPtr editor; + GetAssociatedEditor(getter_AddRefs(editor)); if (editor && NS_SUCCEEDED(SetCaretOffset(aPosition))) return editor->Paste(nsIClipboard::kGlobalClipboard); @@ -1201,10 +1219,27 @@ nsHyperTextAccessible::GetAssociatedEditor(nsIEditor **aEditor) { NS_ENSURE_ARG_POINTER(aEditor); - nsCOMPtr editor(GetEditor()); - NS_IF_ADDREF(*aEditor = editor); + *aEditor = nsnull; + nsCOMPtr content = do_QueryInterface(mDOMNode); + NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); - return NS_OK; + if (!content->HasFlag(NODE_IS_EDITABLE)) { + return NS_OK; + } + + nsCOMPtr docShellTreeItem = GetDocShellTreeItemFor(mDOMNode); + nsCOMPtr editingSession(do_GetInterface(docShellTreeItem)); + if (!editingSession) + return NS_OK; // No editing session interface + + nsCOMPtr shell = GetPresShell(); + NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE); + + nsCOMPtr doc = shell->GetDocument(); + NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); + + nsCOMPtr editor; + return editingSession->GetEditorForWindow(doc->GetWindow(), aEditor); } /** @@ -1276,7 +1311,8 @@ nsresult nsHyperTextAccessible::GetSelections(nsISelectionController **aSelCon, *aDomSel = nsnull; } - nsCOMPtr editor = GetEditor(); + nsCOMPtr editor; + GetAssociatedEditor(getter_AddRefs(editor)); if (editor) { if (aSelCon) { editor->GetSelectionController(aSelCon); diff --git a/accessible/src/html/nsHyperTextAccessible.h b/accessible/src/html/nsHyperTextAccessible.h index 65499a22357d..c8f9032e1d7d 100644 --- a/accessible/src/html/nsHyperTextAccessible.h +++ b/accessible/src/html/nsHyperTextAccessible.h @@ -45,7 +45,6 @@ #include "nsIAccessibleHyperText.h" #include "nsIAccessibleEditableText.h" #include "nsAccessibleEventData.h" -#include "nsIEditor.h" #include "nsFrameSelection.h" #include "nsISelectionController.h" @@ -157,10 +156,6 @@ protected: nsIntRect GetBoundsForString(nsIFrame *aFrame, PRUint32 aStartRenderedOffset, PRUint32 aEndRenderedOffset); - // Editor helpers, subclasses of nsHyperTextAccessible may have editor - virtual void SetEditor(nsIEditor *aEditor) { return; } - virtual already_AddRefed GetEditor() { return nsnull; } - // Selection helpers nsresult GetSelections(nsISelectionController **aSelCon, nsISelection **aDomSel); nsresult SetSelectionRange(PRInt32 aStartPos, PRInt32 aEndPos); diff --git a/accessible/src/xforms/nsXFormsAccessible.cpp b/accessible/src/xforms/nsXFormsAccessible.cpp index 7c8c42b6ee36..d5c7ca2cb521 100755 --- a/accessible/src/xforms/nsXFormsAccessible.cpp +++ b/accessible/src/xforms/nsXFormsAccessible.cpp @@ -42,6 +42,7 @@ #include "nsServiceManagerUtils.h" #include "nsIDOMElement.h" #include "nsIDOMNodeList.h" +#include "nsIEditor.h" #include "nsIMutableArray.h" #include "nsIXFormsUtilityService.h" #include "nsIPlaintextEditor.h" @@ -309,7 +310,7 @@ nsXFormsEditableAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) nsresult rv = nsXFormsAccessible::GetState(aState, aExtraState); NS_ENSURE_SUCCESS(rv, rv); - if (!aExtraState || !mEditor) + if (!aExtraState) return NS_OK; PRBool isReadonly = PR_FALSE; @@ -326,8 +327,11 @@ nsXFormsEditableAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) } } + nsCOMPtr editor; + GetAssociatedEditor(getter_AddRefs(editor)); + NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE); PRUint32 flags; - mEditor->GetFlags(&flags); + editor->GetFlags(&flags); if (flags & nsIPlaintextEditor::eEditorSingleLineMask) *aExtraState |= nsIAccessibleStates::EXT_STATE_SINGLE_LINE; else @@ -337,34 +341,9 @@ nsXFormsEditableAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) } NS_IMETHODIMP -nsXFormsEditableAccessible::Init() +nsXFormsEditableAccessible::GetAssociatedEditor(nsIEditor **aEditor) { - nsCOMPtr editor; - sXFormsService->GetEditor(mDOMNode, getter_AddRefs(editor)); - SetEditor(editor); - - return nsXFormsAccessible::Init(); -} - -NS_IMETHODIMP -nsXFormsEditableAccessible::Shutdown() -{ - SetEditor(nsnull); - return nsXFormsAccessible::Shutdown(); -} - -already_AddRefed -nsXFormsEditableAccessible::GetEditor() -{ - nsIEditor *editor = mEditor; - NS_IF_ADDREF(editor); - return editor; -} - -void -nsXFormsEditableAccessible::SetEditor(nsIEditor *aEditor) -{ - mEditor = aEditor; + return sXFormsService->GetEditor(mDOMNode, aEditor); } // nsXFormsSelectableAccessible diff --git a/accessible/src/xforms/nsXFormsAccessible.h b/accessible/src/xforms/nsXFormsAccessible.h index b21c4d9b0426..6116d451ad07 100755 --- a/accessible/src/xforms/nsXFormsAccessible.h +++ b/accessible/src/xforms/nsXFormsAccessible.h @@ -147,15 +147,8 @@ public: NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); - NS_IMETHOD Init(); - NS_IMETHOD Shutdown(); - -protected: - virtual void SetEditor(nsIEditor *aEditor); - virtual already_AddRefed GetEditor(); - -private: - nsCOMPtr mEditor; + // nsIAccessibleEditableText + NS_IMETHOD GetAssociatedEditor(nsIEditor **aEditor); }; diff --git a/accessible/src/xul/nsXULFormControlAccessible.cpp b/accessible/src/xul/nsXULFormControlAccessible.cpp index aae1091946bd..10272d009f33 100644 --- a/accessible/src/xul/nsXULFormControlAccessible.cpp +++ b/accessible/src/xul/nsXULFormControlAccessible.cpp @@ -50,6 +50,7 @@ #include "nsIDOMXULMenuListElement.h" #include "nsIDOMXULSelectCntrlItemEl.h" #include "nsIDOMXULTextboxElement.h" +#include "nsIEditor.h" #include "nsIFrame.h" #include "nsINameSpaceManager.h" #include "nsITextControlFrame.h" @@ -763,21 +764,6 @@ nsXULTextFieldAccessible::nsXULTextFieldAccessible(nsIDOMNode* aNode, nsIWeakRef { } -NS_IMPL_ISUPPORTS_INHERITED1(nsXULTextFieldAccessible, nsHyperTextAccessible, - nsIAccessibleText) - -NS_IMETHODIMP nsXULTextFieldAccessible::Init() -{ - CheckForEditor(); - return nsHyperTextAccessibleWrap::Init(); -} - -NS_IMETHODIMP nsXULTextFieldAccessible::Shutdown() -{ - mEditor = nsnull; - return nsHyperTextAccessibleWrap::Shutdown(); -} - NS_IMETHODIMP nsXULTextFieldAccessible::GetValue(nsAString& aValue) { PRUint32 state; @@ -935,22 +921,11 @@ nsXULTextFieldAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChild return NS_OK; } -void nsXULTextFieldAccessible::SetEditor(nsIEditor* aEditor) -{ - mEditor = aEditor; -} - -void nsXULTextFieldAccessible::CheckForEditor() +NS_IMETHODIMP nsXULTextFieldAccessible::GetAssociatedEditor(nsIEditor **aEditor) { + *aEditor = nsnull; nsCOMPtr inputField = GetInputField(); nsCOMPtr editableElt(do_QueryInterface(inputField)); - if (!editableElt) { - return; - } - - nsCOMPtr editor; - nsresult rv = editableElt->GetEditor(getter_AddRefs(editor)); - if (NS_SUCCEEDED(rv)) { - SetEditor(editor); - } + NS_ENSURE_TRUE(editableElt, NS_ERROR_FAILURE); + return editableElt->GetEditor(aEditor); } diff --git a/accessible/src/xul/nsXULFormControlAccessible.h b/accessible/src/xul/nsXULFormControlAccessible.h index 8d99bd4e7b38..9680e3f9a6ba 100644 --- a/accessible/src/xul/nsXULFormControlAccessible.h +++ b/accessible/src/xul/nsXULFormControlAccessible.h @@ -161,12 +161,8 @@ class nsXULTextFieldAccessible : public nsHyperTextAccessibleWrap public: enum { eAction_Click = 0 }; - NS_DECL_ISUPPORTS_INHERITED - nsXULTextFieldAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell); - NS_IMETHOD Init(); - NS_IMETHOD Shutdown(); NS_IMETHOD GetValue(nsAString& aValue); NS_IMETHOD GetState(PRUint32 *aState, PRUint32 *aExtraState); NS_IMETHOD GetRole(PRUint32 *aRole); @@ -175,14 +171,11 @@ public: NS_IMETHOD DoAction(PRUint8 index); NS_IMETHOD GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren); + // nsIAccessibleEditableText + NS_IMETHOD GetAssociatedEditor(nsIEditor **aEditor); + protected: already_AddRefed GetInputField(); - - // Editor helpers, subclasses of nsHyperTextAccessible may have editor - virtual void SetEditor(nsIEditor *aEditor); - virtual already_AddRefed GetEditor() { nsIEditor *editor = mEditor; NS_IF_ADDREF(editor); return editor; } - void CheckForEditor(); - nsCOMPtr mEditor; };