From 653e5df5d2c0ab15bffc2dc13afd9fb3a862f9fa Mon Sep 17 00:00:00 2001 From: "aaronl%netscape.com" Date: Sat, 17 May 2003 09:00:57 +0000 Subject: [PATCH] Bug 185846. Create ISimpleDOMText for accessibility API support of pieces of text smaller than a node. r=bolian, sr=alecf, a=asa --- accessible/public/msaa/AccessibleMarshal.c | 3 +- accessible/public/msaa/ISimpleDOMText.idl | 50 ++++ accessible/public/msaa/Makefile.in | 10 +- accessible/src/atk/nsAccessibleText.cpp | 123 ++++---- accessible/src/atk/nsAccessibleText.h | 7 +- accessible/src/base/nsDocAccessible.cpp | 57 +++- accessible/src/base/nsOuterDocAccessible.cpp | 5 + accessible/src/base/nsOuterDocAccessible.h | 2 + accessible/src/html/nsHTMLTextAccessible.cpp | 2 +- accessible/src/html/nsHTMLTextAccessible.h | 4 +- accessible/src/msaa/Makefile.in | 2 + accessible/src/msaa/nsDocAccessibleWrap.cpp | 10 +- accessible/src/msaa/nsTextAccessibleWrap.cpp | 262 ++++++++++++++++++ accessible/src/msaa/nsTextAccessibleWrap.h | 98 +++++++ accessible/src/xul/nsXULTextAccessible.cpp | 2 +- accessible/src/xul/nsXULTextAccessible.h | 4 +- .../base/public/nsISelectionController.idl | 4 +- content/base/src/nsSelection.cpp | 2 + layout/generic/nsSelection.cpp | 2 + 19 files changed, 559 insertions(+), 90 deletions(-) create mode 100755 accessible/public/msaa/ISimpleDOMText.idl create mode 100755 accessible/src/msaa/nsTextAccessibleWrap.cpp create mode 100755 accessible/src/msaa/nsTextAccessibleWrap.h diff --git a/accessible/public/msaa/AccessibleMarshal.c b/accessible/public/msaa/AccessibleMarshal.c index e0bfa4880a19..e5a5286d14f8 100755 --- a/accessible/public/msaa/AccessibleMarshal.c +++ b/accessible/public/msaa/AccessibleMarshal.c @@ -6,12 +6,13 @@ extern "C" { EXTERN_PROXY_FILE( ISimpleDOMDocument ) EXTERN_PROXY_FILE( ISimpleDOMNode ) - +EXTERN_PROXY_FILE( ISimpleDOMText ) PROXYFILE_LIST_START /* Start of list */ REFERENCE_PROXY_FILE( ISimpleDOMDocument ), REFERENCE_PROXY_FILE( ISimpleDOMNode ), + REFERENCE_PROXY_FILE( ISimpleDOMText ), /* End of list */ PROXYFILE_LIST_END diff --git a/accessible/public/msaa/ISimpleDOMText.idl b/accessible/public/msaa/ISimpleDOMText.idl new file mode 100755 index 000000000000..723017847a94 --- /dev/null +++ b/accessible/public/msaa/ISimpleDOMText.idl @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1999 Netscape Communications Corporation. All + * Rights Reserved. + * + * Original Author: Aaron Leventhal (aaronl@netscape.com) + * + */ + +import "objidl.idl"; +import "oaidl.idl"; + +[object, uuid(aa24e510-a4e6-4112-a258-0ba7f12e85a9)] +interface ISimpleDOMText: IUnknown +{ + // Includes whitespace in DOM + [propget] HRESULT domText([out, retval] BSTR *domText); + + HRESULT get_clippedSubstringBounds([in] unsigned int startIndex, + [in] unsigned int endIndex, + [out] int *x, + [out] int *y, + [out] int *width, + [out] int *height); + + HRESULT get_unclippedSubstringBounds([in] unsigned int startIndex, + [in] unsigned int endIndex, + [out] int *x, + [out] int *y, + [out] int *width, + [out] int *height); + + HRESULT scrollToSubstring([in] unsigned int startIndex, + [in] unsigned int endIndex); +}; + diff --git a/accessible/public/msaa/Makefile.in b/accessible/public/msaa/Makefile.in index f655244a621e..dee917f47ef3 100755 --- a/accessible/public/msaa/Makefile.in +++ b/accessible/public/msaa/Makefile.in @@ -65,6 +65,8 @@ CSRCS = \ ISimpleDOMNode_i.c \ ISimpleDOMDocument_p.c \ ISimpleDOMDocument_i.c \ + ISimpleDOMText_p.c \ + ISimpleDOMText_i.c \ $(NULL) MIDL_GENERATED_FILES = \ @@ -74,6 +76,9 @@ MIDL_GENERATED_FILES = \ ISimpleDOMDocument.h \ ISimpleDOMDocument_p.c \ ISimpleDOMDocument_i.c \ + ISimpleDOMText.h \ + ISimpleDOMText_p.c \ + ISimpleDOMText_i.c \ $(NULL) SRCDIR_CSRCS = $(addprefix $(srcdir)/,$(CSRCS)) @@ -88,9 +93,10 @@ OS_LIBS = \ $(MIDL_GENERATED_FILES): done_gen -done_gen: ISimpleDOMNode.idl ISimpleDOMDocument.idl +done_gen: ISimpleDOMNode.idl ISimpleDOMDocument.idl ISimpleDOMText.idl "$(MIDL)" $(srcdir)/ISimpleDOMNode.idl "$(MIDL)" $(srcdir)/ISimpleDOMDocument.idl + "$(MIDL)" $(srcdir)/ISimpleDOMText.idl touch $@ EXPORTS = \ @@ -98,6 +104,8 @@ EXPORTS = \ ISimpleDOMNode_i.c \ ISimpleDOMDocument.h \ ISimpleDOMDocument_i.c \ + ISimpleDOMText.h \ + ISimpleDOMText_i.c \ $(NULL) export:: done_gen diff --git a/accessible/src/atk/nsAccessibleText.cpp b/accessible/src/atk/nsAccessibleText.cpp index 307d4d3ff610..5bf9ae0d21f2 100644 --- a/accessible/src/atk/nsAccessibleText.cpp +++ b/accessible/src/atk/nsAccessibleText.cpp @@ -38,7 +38,7 @@ * ***** END LICENSE BLOCK ***** */ // NOTE: alphabetically ordered -#include "nsAccessibleText.h" +#include "nsTextAccessibleWrap.h" #include "nsContentCID.h" #include "nsIAccessibleEventReceiver.h" #include "nsIClipboard.h" @@ -67,29 +67,31 @@ static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID); -// -------------------------------------------------------- -// nsAccessibleText Accessible -// -------------------------------------------------------- -PRBool nsAccessibleText::gSuppressedNotifySelectionChanged = PR_FALSE; +PRBool nsTextAccessibleWrap::gSuppressedNotifySelectionChanged = PR_FALSE; -NS_IMPL_ISUPPORTS1(nsAccessibleText, nsIAccessibleText) +// -------------------------------------------------------- +// nsTextAccessibleWrap Accessible +// -------------------------------------------------------- + +NS_IMPL_ISUPPORTS_INHERITED1(nsTextAccessibleWrap, nsTextAccessible, nsIAccessibleText) + +nsTextAccessibleWrap::nsTextAccessibleWrap(nsIDOMNode* aDOMNode, nsIWeakReference* aShell): +nsTextAccessible(aDOMNode, aShell) +{ +} /** - * nsAccessibleText implements the nsIAccessibleText interface for static text which mTextNode + * nsTextAccessibleWrap implements the nsIAccessibleText interface for static text which mDOMNode * has nsITextContent interface */ -nsAccessibleText::nsAccessibleText(nsIDOMNode *aNode) -{ - mTextNode = aNode; -} /** * nsIAccessibleText helpers */ -nsresult nsAccessibleText::GetSelections(nsISelectionController **aSelCon, nsISelection **aDomSel) +nsresult nsTextAccessibleWrap::GetSelections(nsISelectionController **aSelCon, nsISelection **aDomSel) { nsCOMPtr domDoc; - mTextNode->GetOwnerDocument(getter_AddRefs(domDoc)); + mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc)); nsCOMPtr doc(do_QueryInterface(domDoc)); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); @@ -97,7 +99,7 @@ nsresult nsAccessibleText::GetSelections(nsISelectionController **aSelCon, nsISe doc->GetShellAt(0, getter_AddRefs(shell)); NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE); - nsCOMPtr content(do_QueryInterface(mTextNode)); + nsCOMPtr content(do_QueryInterface(mDOMNode)); nsIFrame *frame = nsnull; shell->GetPrimaryFrameFor(content, &frame); NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); @@ -131,7 +133,7 @@ nsresult nsAccessibleText::GetSelections(nsISelectionController **aSelCon, nsISe return NS_OK; } -nsresult nsAccessibleText::DOMPointToOffset(nsISupports *aClosure, nsIDOMNode* aNode, PRInt32 aNodeOffset, PRInt32* aResult) +nsresult nsTextAccessibleWrap::DOMPointToOffset(nsISupports *aClosure, nsIDOMNode* aNode, PRInt32 aNodeOffset, PRInt32* aResult) { NS_ENSURE_ARG_POINTER(aNode && aResult); @@ -227,7 +229,7 @@ nsresult nsAccessibleText::DOMPointToOffset(nsISupports *aClosure, nsIDOMNode* a return NS_OK; } -nsresult nsAccessibleText::OffsetToDOMPoint(nsISupports *aClosure, PRInt32 aOffset, nsIDOMNode** aResult, PRInt32* aPosition) +nsresult nsTextAccessibleWrap::OffsetToDOMPoint(nsISupports *aClosure, PRInt32 aOffset, nsIDOMNode** aResult, PRInt32* aPosition) { NS_ENSURE_ARG_POINTER(aResult && aPosition); @@ -319,7 +321,7 @@ nsresult nsAccessibleText::OffsetToDOMPoint(nsISupports *aClosure, PRInt32 aOffs return NS_ERROR_FAILURE; } -nsresult nsAccessibleText::GetCurrectOffset(nsISupports *aClosure, nsISelection *aDomSel, PRInt32 *aOffset) +nsresult nsTextAccessibleWrap::GetCurrectOffset(nsISupports *aClosure, nsISelection *aDomSel, PRInt32 *aOffset) { nsCOMPtr focusNode; aDomSel->GetFocusNode(getter_AddRefs(focusNode)); @@ -353,10 +355,10 @@ ATK_TEXT_BOUNDARY_LINE_START ATK_TEXT_BOUNDARY_LINE_END The returned string is from the line end before/at/after the offset to the next line start. */ -nsresult nsAccessibleText::GetTextHelperCore(EGetTextType aType, nsAccessibleTextBoundary aBoundaryType, - PRInt32 aOffset, PRInt32 *aStartOffset, PRInt32 *aEndOffset, - nsISelectionController *aSelCon, nsISelection *aDomSel, - nsISupports *aClosure, nsAString &aText) +nsresult nsTextAccessibleWrap::GetTextHelperCore(EGetTextType aType, nsTextAccessibleWrapBoundary aBoundaryType, + PRInt32 aOffset, PRInt32 *aStartOffset, PRInt32 *aEndOffset, + nsISelectionController *aSelCon, nsISelection *aDomSel, + nsISupports *aClosure, nsAString &aText) { PRInt32 rangeCount; nsCOMPtr range, oldRange; @@ -393,7 +395,7 @@ nsresult nsAccessibleText::GetTextHelperCore(EGetTextType aType, nsAccessibleTex return NS_ERROR_INVALID_ARG; } - // The start/end focus node may be not our mTextNode + // The start/end focus node may be not our mDOMNode nsCOMPtr startFocusNode, endFocusNode; switch (aBoundaryType) { @@ -465,7 +467,7 @@ nsresult nsAccessibleText::GetTextHelperCore(EGetTextType aType, nsAccessibleTex return NS_OK; } -nsresult nsAccessibleText::GetTextHelper(EGetTextType aType, nsAccessibleTextBoundary aBoundaryType, +nsresult nsTextAccessibleWrap::GetTextHelper(EGetTextType aType, nsTextAccessibleWrapBoundary aBoundaryType, PRInt32 aOffset, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsISupports *aClosure, nsAString &aText) { @@ -513,7 +515,7 @@ nsresult nsAccessibleText::GetTextHelper(EGetTextType aType, nsAccessibleTextBou /* * Gets the offset position of the caret (cursor). */ -NS_IMETHODIMP nsAccessibleText::GetCaretOffset(PRInt32 *aCaretOffset) +NS_IMETHODIMP nsTextAccessibleWrap::GetCaretOffset(PRInt32 *aCaretOffset) { nsCOMPtr domSel; nsresult rv = GetSelections(nsnull, getter_AddRefs(domSel)); @@ -521,7 +523,7 @@ NS_IMETHODIMP nsAccessibleText::GetCaretOffset(PRInt32 *aCaretOffset) nsCOMPtr focusNode; domSel->GetFocusNode(getter_AddRefs(focusNode)); - if (focusNode != mTextNode) + if (focusNode != mDOMNode) return NS_ERROR_FAILURE; return domSel->GetFocusOffset(aCaretOffset); @@ -530,7 +532,7 @@ NS_IMETHODIMP nsAccessibleText::GetCaretOffset(PRInt32 *aCaretOffset) /* * Sets the caret (cursor) position to the specified offset. */ -NS_IMETHODIMP nsAccessibleText::SetCaretOffset(PRInt32 aCaretOffset) +NS_IMETHODIMP nsTextAccessibleWrap::SetCaretOffset(PRInt32 aCaretOffset) { nsCOMPtr domSel; nsresult rv = GetSelections(nsnull, getter_AddRefs(domSel)); @@ -539,8 +541,8 @@ NS_IMETHODIMP nsAccessibleText::SetCaretOffset(PRInt32 aCaretOffset) nsCOMPtr range(do_CreateInstance(kRangeCID)); NS_ENSURE_TRUE(range, NS_ERROR_OUT_OF_MEMORY); - range->SetStart(mTextNode, aCaretOffset); - range->SetEnd(mTextNode, aCaretOffset); + range->SetStart(mDOMNode, aCaretOffset); + range->SetEnd(mDOMNode, aCaretOffset); domSel->RemoveAllRanges(); return domSel->AddRange(range); } @@ -548,9 +550,9 @@ NS_IMETHODIMP nsAccessibleText::SetCaretOffset(PRInt32 aCaretOffset) /* * Gets the character count. */ -NS_IMETHODIMP nsAccessibleText::GetCharacterCount(PRInt32 *aCharacterCount) +NS_IMETHODIMP nsTextAccessibleWrap::GetCharacterCount(PRInt32 *aCharacterCount) { - nsCOMPtr textContent(do_QueryInterface(mTextNode)); + nsCOMPtr textContent(do_QueryInterface(mDOMNode)); if (!textContent) return NS_ERROR_FAILURE; @@ -560,7 +562,7 @@ NS_IMETHODIMP nsAccessibleText::GetCharacterCount(PRInt32 *aCharacterCount) /* * Gets the number of selected regions. */ -NS_IMETHODIMP nsAccessibleText::GetSelectionCount(PRInt32 *aSelectionCount) +NS_IMETHODIMP nsTextAccessibleWrap::GetSelectionCount(PRInt32 *aSelectionCount) { nsCOMPtr domSel; nsresult rv = GetSelections(nsnull, getter_AddRefs(domSel)); @@ -582,27 +584,27 @@ NS_IMETHODIMP nsAccessibleText::GetSelectionCount(PRInt32 *aSelectionCount) /* * Gets the specified text. */ -NS_IMETHODIMP nsAccessibleText::GetText(PRInt32 aStartOffset, PRInt32 aEndOffset, nsAString &aText) +NS_IMETHODIMP nsTextAccessibleWrap::GetText(PRInt32 aStartOffset, PRInt32 aEndOffset, nsAString &aText) { nsAutoString text; - mTextNode->GetNodeValue(text); + mDOMNode->GetNodeValue(text); aText = Substring(text, aStartOffset, aEndOffset - aStartOffset); return NS_OK; } -NS_IMETHODIMP nsAccessibleText::GetTextBeforeOffset(PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType, +NS_IMETHODIMP nsTextAccessibleWrap::GetTextBeforeOffset(PRInt32 aOffset, nsTextAccessibleWrapBoundary aBoundaryType, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString & aText) { return GetTextHelper(eGetBefore, aBoundaryType, aOffset, aStartOffset, aEndOffset, nsnull, aText); } -NS_IMETHODIMP nsAccessibleText::GetTextAtOffset(PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType, +NS_IMETHODIMP nsTextAccessibleWrap::GetTextAtOffset(PRInt32 aOffset, nsTextAccessibleWrapBoundary aBoundaryType, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString & aText) { return GetTextHelper(eGetAt, aBoundaryType, aOffset, aStartOffset, aEndOffset, nsnull, aText); } -NS_IMETHODIMP nsAccessibleText::GetTextAfterOffset(PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType, +NS_IMETHODIMP nsTextAccessibleWrap::GetTextAfterOffset(PRInt32 aOffset, nsTextAccessibleWrapBoundary aBoundaryType, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString & aText) { return GetTextHelper(eGetAfter, aBoundaryType, aOffset, aStartOffset, aEndOffset, nsnull, aText); @@ -611,7 +613,7 @@ NS_IMETHODIMP nsAccessibleText::GetTextAfterOffset(PRInt32 aOffset, nsAccessible /* * Gets the specified text. */ -NS_IMETHODIMP nsAccessibleText::GetCharacterAtOffset(PRInt32 aOffset, PRUnichar *aCharacter) +NS_IMETHODIMP nsTextAccessibleWrap::GetCharacterAtOffset(PRInt32 aOffset, PRUnichar *aCharacter) { nsAutoString text; nsresult rv = GetText(aOffset, aOffset + 1, text); @@ -620,7 +622,7 @@ NS_IMETHODIMP nsAccessibleText::GetCharacterAtOffset(PRInt32 aOffset, PRUnichar return NS_OK; } -NS_IMETHODIMP nsAccessibleText::GetAttributeRange(PRInt32 aOffset, PRInt32 *aRangeStartOffset, +NS_IMETHODIMP nsTextAccessibleWrap::GetAttributeRange(PRInt32 aOffset, PRInt32 *aRangeStartOffset, PRInt32 *aRangeEndOffset, nsISupports **aAttribute) { // will do better job later @@ -633,12 +635,12 @@ NS_IMETHODIMP nsAccessibleText::GetAttributeRange(PRInt32 aOffset, PRInt32 *aRan /* * Given an offset, the x, y, width, and height values are filled appropriately. */ -NS_IMETHODIMP nsAccessibleText::GetCharacterExtents(PRInt32 aOffset, +NS_IMETHODIMP nsTextAccessibleWrap::GetCharacterExtents(PRInt32 aOffset, PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight, nsAccessibleCoordType aCoordType) { nsCOMPtr domDoc; - mTextNode->GetOwnerDocument(getter_AddRefs(domDoc)); + mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc)); nsCOMPtr doc(do_QueryInterface(domDoc)); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); @@ -650,7 +652,7 @@ NS_IMETHODIMP nsAccessibleText::GetCharacterExtents(PRInt32 aOffset, shell->GetPresContext(getter_AddRefs(context)); NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); - nsCOMPtr content(do_QueryInterface(mTextNode)); + nsCOMPtr content(do_QueryInterface(mDOMNode)); NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); nsIFrame *frame = nsnull; @@ -777,7 +779,7 @@ NS_IMETHODIMP nsAccessibleText::GetCharacterExtents(PRInt32 aOffset, * Gets the offset of the character located at coordinates x and y. x and y are interpreted as being relative to * the screen or this widget's window depending on coords. */ -NS_IMETHODIMP nsAccessibleText::GetOffsetAtPoint(PRInt32 aX, PRInt32 aY, nsAccessibleCoordType aCoordType, PRInt32 *aOffset) +NS_IMETHODIMP nsTextAccessibleWrap::GetOffsetAtPoint(PRInt32 aX, PRInt32 aY, nsAccessibleCoordType aCoordType, PRInt32 *aOffset) { // will do better job later *aOffset = 0; @@ -787,7 +789,7 @@ NS_IMETHODIMP nsAccessibleText::GetOffsetAtPoint(PRInt32 aX, PRInt32 aY, nsAcces /* * Gets the start and end offset of the specified selection. */ -NS_IMETHODIMP nsAccessibleText::GetSelectionBounds(PRInt32 aSelectionNum, PRInt32 *aStartOffset, PRInt32 *aEndOffset) +NS_IMETHODIMP nsTextAccessibleWrap::GetSelectionBounds(PRInt32 aSelectionNum, PRInt32 *aStartOffset, PRInt32 *aEndOffset) { nsCOMPtr domSel; nsresult rv = GetSelections(nsnull, getter_AddRefs(domSel)); @@ -808,7 +810,7 @@ NS_IMETHODIMP nsAccessibleText::GetSelectionBounds(PRInt32 aSelectionNum, PRInt3 /* * Changes the start and end offset of the specified selection. */ -NS_IMETHODIMP nsAccessibleText::SetSelectionBounds(PRInt32 aSelectionNum, PRInt32 aStartOffset, PRInt32 aEndOffset) +NS_IMETHODIMP nsTextAccessibleWrap::SetSelectionBounds(PRInt32 aSelectionNum, PRInt32 aStartOffset, PRInt32 aEndOffset) { nsCOMPtr domSel; nsresult rv = GetSelections(nsnull, getter_AddRefs(domSel)); @@ -843,7 +845,7 @@ NS_IMETHODIMP nsAccessibleText::SetSelectionBounds(PRInt32 aSelectionNum, PRInt3 /* * Adds a selection bounded by the specified offsets. */ -NS_IMETHODIMP nsAccessibleText::AddSelection(PRInt32 aStartOffset, PRInt32 aEndOffset) +NS_IMETHODIMP nsTextAccessibleWrap::AddSelection(PRInt32 aStartOffset, PRInt32 aEndOffset) { nsCOMPtr selCon; nsCOMPtr domSel; @@ -855,15 +857,15 @@ NS_IMETHODIMP nsAccessibleText::AddSelection(PRInt32 aStartOffset, PRInt32 aEndO if (! range) return NS_ERROR_OUT_OF_MEMORY; - range->SetStart(mTextNode, aStartOffset); - range->SetEnd(mTextNode, aEndOffset); + range->SetStart(mDOMNode, aStartOffset); + range->SetEnd(mDOMNode, aEndOffset); return domSel->AddRange(range); } /* * Removes the specified selection. */ -NS_IMETHODIMP nsAccessibleText::RemoveSelection(PRInt32 aSelectionNum) +NS_IMETHODIMP nsTextAccessibleWrap::RemoveSelection(PRInt32 aSelectionNum) { nsCOMPtr domSel; nsresult rv = GetSelections(nsnull, getter_AddRefs(domSel)); @@ -889,7 +891,7 @@ NS_IMETHODIMP nsAccessibleText::RemoveSelection(PRInt32 aSelectionNum) NS_IMPL_ISUPPORTS3(nsAccessibleEditableText, nsIAccessibleText, nsIAccessibleEditableText, nsIEditActionListener) nsAccessibleEditableText::nsAccessibleEditableText(nsIDOMNode *aNode): -nsAccessibleText(aNode) +nsTextAccessibleWrap(aNode) { } @@ -934,7 +936,7 @@ nsresult nsAccessibleEditableText::FireTextChangeEvent(AtkTextChange *aTextData) nsITextControlFrame* nsAccessibleEditableText::GetTextFrame() { nsCOMPtr domDoc; - mTextNode->GetOwnerDocument(getter_AddRefs(domDoc)); + mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc)); nsCOMPtr doc(do_QueryInterface(domDoc)); NS_ENSURE_TRUE(doc, nsnull); @@ -942,7 +944,7 @@ nsITextControlFrame* nsAccessibleEditableText::GetTextFrame() doc->GetShellAt(0, getter_AddRefs(shell)); NS_ENSURE_TRUE(shell, nsnull); - nsCOMPtr content(do_QueryInterface(mTextNode)); + nsCOMPtr content(do_QueryInterface(mDOMNode)); nsIFrame *frame = nsnull; shell->GetPrimaryFrameFor(content, &frame); NS_ENSURE_TRUE(frame, nsnull); @@ -1050,19 +1052,19 @@ NS_IMETHODIMP nsAccessibleEditableText::GetText(PRInt32 aStartOffset, PRInt32 aE return NS_ERROR_FAILURE; } -NS_IMETHODIMP nsAccessibleEditableText::GetTextBeforeOffset(PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType, +NS_IMETHODIMP nsAccessibleEditableText::GetTextBeforeOffset(PRInt32 aOffset, nsTextAccessibleWrapBoundary aBoundaryType, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString & aText) { return GetTextHelper(eGetBefore, aBoundaryType, aOffset, aStartOffset, aEndOffset, mEditor, aText); } -NS_IMETHODIMP nsAccessibleEditableText::GetTextAtOffset(PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType, +NS_IMETHODIMP nsAccessibleEditableText::GetTextAtOffset(PRInt32 aOffset, nsTextAccessibleWrapBoundary aBoundaryType, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString & aText) { return GetTextHelper(eGetAt, aBoundaryType, aOffset, aStartOffset, aEndOffset, mEditor, aText); } -NS_IMETHODIMP nsAccessibleEditableText::GetTextAfterOffset(PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType, +NS_IMETHODIMP nsAccessibleEditableText::GetTextAfterOffset(PRInt32 aOffset, nsTextAccessibleWrapBoundary aBoundaryType, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString & aText) { return GetTextHelper(eGetAfter, aBoundaryType, aOffset, aStartOffset, aEndOffset, mEditor, aText); @@ -1078,11 +1080,11 @@ NS_IMETHODIMP nsAccessibleEditableText::SetAttributes(PRInt32 aStartPos, PRInt32 NS_IMETHODIMP nsAccessibleEditableText::SetTextContents(const nsAString &aText) { - nsCOMPtr textArea(do_QueryInterface(mTextNode)); + nsCOMPtr textArea(do_QueryInterface(mDOMNode)); if (textArea) return textArea->SetValue(aText); - nsCOMPtr inputElement(do_QueryInterface(mTextNode)); + nsCOMPtr inputElement(do_QueryInterface(mDOMNode)); if (inputElement) return inputElement->SetValue(aText); @@ -1263,12 +1265,3 @@ NS_IMETHODIMP nsAccessibleEditableText::DidDeleteSelection(nsISelection *aSelect return NS_OK; } -// -------------------------------------------------------- -// nsTextAccessibleWrap Accessible -// -------------------------------------------------------- -NS_IMPL_ISUPPORTS_INHERITED1(nsTextAccessibleWrap, nsTextAccessible, nsAccessibleText) - -nsTextAccessibleWrap::nsTextAccessibleWrap(nsIDOMNode* aDOMNode, nsIWeakReference* aShell): -nsTextAccessible(aDOMNode, aShell), nsAccessibleText(aDOMNode) -{ -} diff --git a/accessible/src/atk/nsAccessibleText.h b/accessible/src/atk/nsAccessibleText.h index 701fd22bb206..75aa57d10c76 100644 --- a/accessible/src/atk/nsAccessibleText.h +++ b/accessible/src/atk/nsAccessibleText.h @@ -52,10 +52,11 @@ enum EGetTextType { eGetBefore=-1, eGetAt=0, eGetAfter=1 }; -class nsAccessibleText : public nsIAccessibleText +class nsTextAccessibleWrap : public nsTextAccessible, + public nsIAccessibleText { public: - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIACCESSIBLETEXT nsAccessibleText(nsIDOMNode *aNode); @@ -64,8 +65,6 @@ public: static PRBool gSuppressedNotifySelectionChanged; protected: - nsCOMPtr mTextNode; - nsresult GetSelections(nsISelectionController **aSelCon, nsISelection **aDomSel); nsresult GetTextHelperCore(EGetTextType aType, nsAccessibleTextBoundary aBoundaryType, PRInt32 aOffset, PRInt32 *aStartOffset, PRInt32 *aEndOffset, diff --git a/accessible/src/base/nsDocAccessible.cpp b/accessible/src/base/nsDocAccessible.cpp index 93513e5a4b27..111a7540d64c 100644 --- a/accessible/src/base/nsDocAccessible.cpp +++ b/accessible/src/base/nsDocAccessible.cpp @@ -98,15 +98,16 @@ nsDocAccessible::nsDocAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell) nsCOMPtr vm; shell->GetViewManager(getter_AddRefs(vm)); nsCOMPtr widget; - vm->GetWidget(getter_AddRefs(widget)); - mWnd = widget->GetNativeData(NS_NATIVE_WINDOW); + if (vm) { + vm->GetWidget(getter_AddRefs(widget)); + if (widget) { + mWnd = widget->GetNativeData(NS_NATIVE_WINDOW); + } + } } NS_ASSERTION(gGlobalDocAccessibleCache, "No global doc accessible cache"); PutCacheEntry(gGlobalDocAccessibleCache, mWeakShell, this); -#ifdef DEBUG - printf("\nATTENTION: New doc accessible for weak shell %x\n", mWeakShell.get()); -#endif // XXX aaronl should we use an algorithm for the initial cache size? #ifdef OLD_HASH @@ -408,10 +409,52 @@ nsIFrame* nsDocAccessible::GetFrame() void nsDocAccessible::GetBounds(nsRect& aBounds, nsIFrame** aRelativeFrame) { *aRelativeFrame = GetFrame(); - if (*aRelativeFrame) - (*aRelativeFrame)->GetRect(aBounds); + + nsCOMPtr document(mDocument); + nsRect viewBounds; + nsCOMPtr vm; + nsCOMPtr parentDoc; + + while (document) { + nsCOMPtr presShell; + document->GetShellAt(0, getter_AddRefs(presShell)); + if (!presShell) { + return; + } + presShell->GetViewManager(getter_AddRefs(vm)); + + nsIScrollableView* scrollableView = nsnull; + if (vm) + vm->GetRootScrollableView(&scrollableView); + + if (scrollableView) { + const nsIView *view = nsnull; + scrollableView->GetClipView(&view); + if (view) { + view->GetBounds(viewBounds); + } + } + else { + nsIView *view; + vm->GetRootView(view); + if (view) { + view->GetBounds(viewBounds); + } + } + + if (parentDoc) { // After first time thru loop + aBounds.IntersectRect(viewBounds, aBounds); + } + else { // First time through loop + aBounds = viewBounds; + } + + document->GetParentDocument(getter_AddRefs(parentDoc)); + document = parentDoc; + } } + void nsDocAccessible::AddContentDocListeners() { // 1) Set up scroll position listener diff --git a/accessible/src/base/nsOuterDocAccessible.cpp b/accessible/src/base/nsOuterDocAccessible.cpp index 34b061b4f340..9cd6f9b86ace 100644 --- a/accessible/src/base/nsOuterDocAccessible.cpp +++ b/accessible/src/base/nsOuterDocAccessible.cpp @@ -82,3 +82,8 @@ NS_IMETHODIMP nsOuterDocAccessible::GetAccState(PRUint32 *aAccState) return nsAccessible::GetAccState(aAccState); } +NS_IMETHODIMP nsOuterDocAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, + PRInt32 *width, PRInt32 *height) +{ + return mFirstChild? mFirstChild->AccGetBounds(x, y, width, height): NS_ERROR_FAILURE; +} diff --git a/accessible/src/base/nsOuterDocAccessible.h b/accessible/src/base/nsOuterDocAccessible.h index 7bfb3be35b5d..9d5133c590ff 100644 --- a/accessible/src/base/nsOuterDocAccessible.h +++ b/accessible/src/base/nsOuterDocAccessible.h @@ -57,6 +57,8 @@ class nsOuterDocAccessible : public nsBlockAccessible NS_IMETHOD GetAccValue(nsAString& AccValue); NS_IMETHOD GetAccRole(PRUint32 *aAccRole); NS_IMETHOD GetAccState(PRUint32 *aAccState); + NS_IMETHOD AccGetBounds(PRInt32 *x, PRInt32 *y, + PRInt32 *width, PRInt32 *height); }; #endif diff --git a/accessible/src/html/nsHTMLTextAccessible.cpp b/accessible/src/html/nsHTMLTextAccessible.cpp index 90bc4df2f3c3..7764a265d0be 100644 --- a/accessible/src/html/nsHTMLTextAccessible.cpp +++ b/accessible/src/html/nsHTMLTextAccessible.cpp @@ -46,7 +46,7 @@ #include "nsISelectionController.h" nsHTMLTextAccessible::nsHTMLTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): -nsTextAccessible(aDomNode, aShell) +nsTextAccessibleWrap(aDomNode, aShell) { } diff --git a/accessible/src/html/nsHTMLTextAccessible.h b/accessible/src/html/nsHTMLTextAccessible.h index 0e81f2db3a44..66d2570e19e6 100644 --- a/accessible/src/html/nsHTMLTextAccessible.h +++ b/accessible/src/html/nsHTMLTextAccessible.h @@ -40,11 +40,11 @@ #ifndef _nsHTMLTextAccessible_H_ #define _nsHTMLTextAccessible_H_ -#include "nsTextAccessible.h" +#include "nsTextAccessibleWrap.h" class nsIWeakReference; -class nsHTMLTextAccessible : public nsTextAccessible +class nsHTMLTextAccessible : public nsTextAccessibleWrap { public: diff --git a/accessible/src/msaa/Makefile.in b/accessible/src/msaa/Makefile.in index e8359253209d..da913253a2bb 100644 --- a/accessible/src/msaa/Makefile.in +++ b/accessible/src/msaa/Makefile.in @@ -67,6 +67,7 @@ REQUIRES = content \ CPPSRCS = \ nsAccessNodeWrap.cpp \ nsAccessibleWrap.cpp \ + nsTextAccessibleWrap.cpp \ nsDocAccessibleWrap.cpp \ nsRootAccessibleWrap.cpp \ nsHTMLWin32ObjectAccessible.cpp \ @@ -75,6 +76,7 @@ CPPSRCS = \ EXPORTS = \ nsAccessNodeWrap.h \ nsAccessibleWrap.h \ + nsTextAccessibleWrap.h \ nsDocAccessibleWrap.h \ nsRootAccessibleWrap.h \ nsHTMLWin32ObjectAccessible.h \ diff --git a/accessible/src/msaa/nsDocAccessibleWrap.cpp b/accessible/src/msaa/nsDocAccessibleWrap.cpp index 8702749baf89..0cb4b3cb0ba6 100644 --- a/accessible/src/msaa/nsDocAccessibleWrap.cpp +++ b/accessible/src/msaa/nsDocAccessibleWrap.cpp @@ -138,10 +138,12 @@ STDMETHODIMP nsDocAccessibleWrap::get_accChild( getter_AddRefs(parentDocAccessible)); nsCOMPtr accessible(do_QueryInterface(parentDocAccessible)); IAccessible *msaaParentDoc; - accessible->GetNativeInterface((void**)&msaaParentDoc); - HRESULT rv = msaaParentDoc->get_accChild(varChild, ppdispChild); - msaaParentDoc->Release(); - return rv; + if (accessible) { + accessible->GetNativeInterface((void**)&msaaParentDoc); + HRESULT rv = msaaParentDoc->get_accChild(varChild, ppdispChild); + msaaParentDoc->Release(); + return rv; + } } } } diff --git a/accessible/src/msaa/nsTextAccessibleWrap.cpp b/accessible/src/msaa/nsTextAccessibleWrap.cpp new file mode 100755 index 000000000000..1b42a73a550a --- /dev/null +++ b/accessible/src/msaa/nsTextAccessibleWrap.cpp @@ -0,0 +1,262 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape Corp. + * Portions created by Netscape Corp.are Copyright (C) 2003 Netscape + * Corp. All Rights Reserved. + * + * Original Author: Aaron Leventhal + * + * Contributor(s): + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// NOTE: alphabetically ordered +#include "nsTextAccessibleWrap.h" +#include "ISimpleDOMText_i.c" +#include "nsContentCID.h" +#include "nsIDOMRange.h" +#include "nsIFrame.h" +#include "nsIPresContext.h" +#include "nsIPresShell.h" +#include "nsIRenderingContext.h" +#include "nsISelection.h" +#include "nsISelectionController.h" +#include "nsIViewManager.h" +#include "nsIWidget.h" + +static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID); + +// -------------------------------------------------------- +// nsTextAccessibleWrap Accessible +// -------------------------------------------------------- + +nsTextAccessibleWrap::nsTextAccessibleWrap(nsIDOMNode* aDOMNode, nsIWeakReference* aShell): +nsTextAccessible(aDOMNode, aShell) +{ +} + +STDMETHODIMP_(ULONG) nsTextAccessibleWrap::AddRef() +{ + return nsAccessNode::AddRef(); +} + +STDMETHODIMP_(ULONG) nsTextAccessibleWrap::Release() +{ + return nsAccessNode::Release(); +} + +STDMETHODIMP nsTextAccessibleWrap::QueryInterface(REFIID iid, void** ppv) +{ + *ppv = nsnull; + + if (IID_IUnknown == iid || IID_ISimpleDOMText == iid) + *ppv = NS_STATIC_CAST(ISimpleDOMText*, this); + + if (nsnull == *ppv) + return nsAccessibleWrap::QueryInterface(iid, ppv); + + (NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef(); + return S_OK; +} + +STDMETHODIMP nsTextAccessibleWrap::get_domText( + /* [retval][out] */ BSTR __RPC_FAR *aDomText) +{ + nsAutoString nodeValue; + + mDOMNode->GetNodeValue(nodeValue); + *aDomText = ::SysAllocString(nodeValue.get()); + + return S_OK; +} + +STDMETHODIMP nsTextAccessibleWrap::get_clippedSubstringBounds( + /* [in] */ unsigned int aStartIndex, + /* [in] */ unsigned int aEndIndex, + /* [out] */ int __RPC_FAR *aX, + /* [out] */ int __RPC_FAR *aY, + /* [out] */ int __RPC_FAR *aWidth, + /* [out] */ int __RPC_FAR *aHeight) +{ + nscoord x, y, width, height, docX, docY, docWidth, docHeight; + get_unclippedSubstringBounds(aStartIndex, aEndIndex, &x, &y, &width, &height); + + nsCOMPtr docAccessible(GetDocAccessible()); + nsCOMPtr accessible(do_QueryInterface(docAccessible)); + NS_ASSERTION(accessible, "There must always be a doc accessible, but there isn't"); + + accessible->AccGetBounds(&docX, &docY, &docWidth, &docHeight); + + nsRect unclippedRect(x, y, width, height); + nsRect docRect(docX, docY, docWidth, docHeight); + nsRect clippedRect; + + clippedRect.IntersectRect(unclippedRect, docRect); + + *aX = clippedRect.x; + *aY = clippedRect.y; + *aWidth = clippedRect.width; + *aHeight = clippedRect.height; + + return S_OK; +} + +STDMETHODIMP nsTextAccessibleWrap::get_unclippedSubstringBounds( + /* [in] */ unsigned int aStartIndex, + /* [in] */ unsigned int aEndIndex, + /* [out] */ int __RPC_FAR *aX, + /* [out] */ int __RPC_FAR *aY, + /* [out] */ int __RPC_FAR *aWidth, + /* [out] */ int __RPC_FAR *aHeight) +{ + if (NS_FAILED(GetCharacterExtents(aStartIndex, aEndIndex, + aX, aY, aWidth, aHeight))) { + return NS_ERROR_FAILURE; + } + + // Add offsets for entire accessible + PRInt32 nodeX, nodeY, nodeWidth, nodeHeight; + AccGetBounds(&nodeX, &nodeY, &nodeWidth, &nodeHeight); + *aX += nodeX; + *aY += nodeY; + + return S_OK; +} + + +STDMETHODIMP nsTextAccessibleWrap::scrollToSubstring( + /* [in] */ unsigned int aStartIndex, + /* [in] */ unsigned int aEndIndex) +{ + nsCOMPtr presShell(GetPresShell()); + nsIFrame *frame = GetFrame(); + + if (!frame || !presShell) { + return E_FAIL; // This accessible has been shut down + } + + nsCOMPtr presContext; + presShell->GetPresContext(getter_AddRefs(presContext)); + nsCOMPtr scrollToRange = do_CreateInstance(kRangeCID); + nsCOMPtr selCon; + frame->GetSelectionController(presContext, getter_AddRefs(selCon)); + if (!presContext || !scrollToRange || !selCon) { + return E_FAIL; + } + + scrollToRange->SetStart(mDOMNode, aStartIndex); + scrollToRange->SetEnd(mDOMNode, aEndIndex); + nsCOMPtr domSel; + selCon->GetSelection(nsISelectionController::SELECTION_ACCESSIBILITY, + getter_AddRefs(domSel)); + if (domSel) { + domSel->RemoveAllRanges(); + domSel->AddRange(scrollToRange); + + selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_ACCESSIBILITY, + nsISelectionController::SELECTION_ANCHOR_REGION, PR_TRUE); + + domSel->CollapseToStart(); + } + + return S_OK; +} + +nsIFrame* nsTextAccessibleWrap::GetPointFromOffset(nsIFrame *aContainingFrame, + nsIPresContext *aPresContext, + nsIRenderingContext *aRendContext, + PRInt32 aOffset, + nsPoint& aOutPoint) +{ + nsIFrame *textFrame = nsnull; + PRInt32 outOffset; + aContainingFrame->GetChildFrameContainingOffset(aOffset, PR_FALSE, &outOffset, &textFrame); + if (!textFrame) { + return nsnull; + } + + textFrame->GetPointFromOffset(aPresContext, aRendContext, aOffset, &aOutPoint); + return textFrame; +} + +/* + * Given an offset, the x, y, width, and height values are filled appropriately. + */ +nsresult nsTextAccessibleWrap::GetCharacterExtents(PRInt32 aStartOffset, PRInt32 aEndOffset, + PRInt32* aX, PRInt32* aY, + PRInt32* aWidth, PRInt32* aHeight) +{ + nsCOMPtr presShell(GetPresShell()); + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); + + nsCOMPtr presContext; + presShell->GetPresContext(getter_AddRefs(presContext)); + NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); + float t2p; + if (NS_FAILED(presContext->GetTwipsToPixels(&t2p))) { + return NS_ERROR_FAILURE; + } + + nsIFrame *frame = nsnull; + nsCOMPtr content(do_QueryInterface(mDOMNode)); + presShell->GetPrimaryFrameFor(content, &frame); + NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE); + + nsCOMPtr viewManager; + presShell->GetViewManager(getter_AddRefs(viewManager)); + NS_ASSERTION(viewManager, "No view manager for pres shell"); + + nsCOMPtr widget; + viewManager->GetWidget(getter_AddRefs(widget)); + + nsIRenderingContext *rendContext; + rendContext = widget->GetRenderingContext(); + + nsPoint startPoint, endPoint; + nsIFrame *startFrame = GetPointFromOffset(frame, presContext, rendContext, + aStartOffset, startPoint); + nsIFrame *endFrame = GetPointFromOffset(frame, presContext, rendContext, + aEndOffset, endPoint); + if (!startFrame || !endFrame) { + return E_FAIL; + } + + nsRect startRect, endRect; + startFrame->GetRect(startRect); + endFrame->GetRect(endRect); + + *aX = NSTwipsToIntPixels(startPoint.x + startRect.x, t2p); + *aY = NSTwipsToIntPixels(startPoint.y, t2p); + *aWidth = NSTwipsToIntPixels(endPoint.x + endRect.x, t2p) - *aX; + *aHeight = NSTwipsToIntPixels(endRect.y + endRect.height - + startPoint.y - startRect.y , t2p); + + return NS_OK; +} diff --git a/accessible/src/msaa/nsTextAccessibleWrap.h b/accessible/src/msaa/nsTextAccessibleWrap.h new file mode 100755 index 000000000000..1b7698395f6e --- /dev/null +++ b/accessible/src/msaa/nsTextAccessibleWrap.h @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape Corp. + * Portions created by Netscape Corp.are Copyright (C) 2003 Netscape + * Corp. All Rights Reserved. + * + * Original Author: Aaron Leventhal + * + * Contributor(s): + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef _nsTextAccessibleWrap_H_ +#define _nsTextAccessibleWrap_H_ + +#include "nsTextAccessible.h" +#include "ISimpleDOMText.h" +#include "nsRect.h" + +class nsIFrame; +class nsIPresContext; +class nsIRenderingContext; + +class nsTextAccessibleWrap : public nsTextAccessible, + public ISimpleDOMText +{ + public: + nsTextAccessibleWrap(nsIDOMNode *, nsIWeakReference* aShell); + virtual ~nsTextAccessibleWrap() {} + + // IUnknown methods - see iunknown.h for documentation + STDMETHODIMP_(ULONG) AddRef(); + STDMETHODIMP_(ULONG) Release(); + STDMETHODIMP QueryInterface(REFIID, void**); + + virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_domText( + /* [retval][out] */ BSTR __RPC_FAR *domText); + + virtual HRESULT STDMETHODCALLTYPE get_clippedSubstringBounds( + /* [in] */ unsigned int startIndex, + /* [in] */ unsigned int endIndex, + /* [out] */ int __RPC_FAR *x, + /* [out] */ int __RPC_FAR *y, + /* [out] */ int __RPC_FAR *width, + /* [out] */ int __RPC_FAR *height); + + virtual HRESULT STDMETHODCALLTYPE get_unclippedSubstringBounds( + /* [in] */ unsigned int startIndex, + /* [in] */ unsigned int endIndex, + /* [out] */ int __RPC_FAR *x, + /* [out] */ int __RPC_FAR *y, + /* [out] */ int __RPC_FAR *width, + /* [out] */ int __RPC_FAR *height); + + virtual HRESULT STDMETHODCALLTYPE scrollToSubstring( + /* [in] */ unsigned int startIndex, + /* [in] */ unsigned int endIndex); + + protected: + nsresult GetCharacterExtents(PRInt32 aStartOffset, PRInt32 aEndOffset, + PRInt32* aX, PRInt32* aY, + PRInt32* aWidth, PRInt32* aHeight); + + // Return child frame containing offset on success + nsIFrame* GetPointFromOffset(nsIFrame *aContainingFrame, nsIPresContext *aPresContext, + nsIRenderingContext *aRenderingContext, + PRInt32 aOffset, nsPoint& aOutPoint); +}; + +#endif + diff --git a/accessible/src/xul/nsXULTextAccessible.cpp b/accessible/src/xul/nsXULTextAccessible.cpp index 6ac18c22e718..f45b5ebd54d4 100644 --- a/accessible/src/xul/nsXULTextAccessible.cpp +++ b/accessible/src/xul/nsXULTextAccessible.cpp @@ -46,7 +46,7 @@ * For XUL descriptions and labels */ nsXULTextAccessible::nsXULTextAccessible(nsIDOMNode* aDomNode, nsIWeakReference* aShell): -nsTextAccessible(aDomNode, aShell) +nsTextAccessibleWrap(aDomNode, aShell) { } diff --git a/accessible/src/xul/nsXULTextAccessible.h b/accessible/src/xul/nsXULTextAccessible.h index 38212cd69ad7..aa239dd6f2ce 100644 --- a/accessible/src/xul/nsXULTextAccessible.h +++ b/accessible/src/xul/nsXULTextAccessible.h @@ -41,11 +41,11 @@ #ifndef _nsXULTextAccessible_H_ #define _nsXULTextAccessible_H_ -#include "nsTextAccessible.h" +#include "nsTextAccessibleWrap.h" class nsIWeakReference; -class nsXULTextAccessible : public nsTextAccessible +class nsXULTextAccessible : public nsTextAccessibleWrap { public: diff --git a/content/base/public/nsISelectionController.idl b/content/base/public/nsISelectionController.idl index 5898efcfa0f3..ad32dc879da9 100644 --- a/content/base/public/nsISelectionController.idl +++ b/content/base/public/nsISelectionController.idl @@ -45,8 +45,8 @@ interface nsISelectionController : nsISelectionDisplay const short SELECTION_IME_SELECTEDRAWTEXT=8; const short SELECTION_IME_CONVERTEDTEXT=16; const short SELECTION_IME_SELECTEDCONVERTEDTEXT=32; - const short NUM_SELECTIONTYPES=6; - + const short SELECTION_ACCESSIBILITY=64; // For accessibility API usage + const short NUM_SELECTIONTYPES=8; const short SELECTION_ANCHOR_REGION = 0; const short SELECTION_FOCUS_REGION = 1; diff --git a/content/base/src/nsSelection.cpp b/content/base/src/nsSelection.cpp index 633561ed5eaf..e7f3b2f256c1 100644 --- a/content/base/src/nsSelection.cpp +++ b/content/base/src/nsSelection.cpp @@ -699,6 +699,7 @@ GetIndexFromSelectionType(SelectionType aType) case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT: return 3; break; case nsISelectionController::SELECTION_IME_CONVERTEDTEXT: return 4; break; case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT: return 5; break; + case nsISelectionController::SELECTION_ACCESSIBILITY: return 6; break; default:return -1;break; } /* NOTREACHED */ @@ -716,6 +717,7 @@ GetSelectionTypeFromIndex(PRInt8 aIndex) case 3: return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;break; case 4: return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;break; case 5: return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT;break; + case 6: return nsISelectionController::SELECTION_ACCESSIBILITY;break; default: return nsISelectionController::SELECTION_NORMAL;break; } diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index 633561ed5eaf..e7f3b2f256c1 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -699,6 +699,7 @@ GetIndexFromSelectionType(SelectionType aType) case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT: return 3; break; case nsISelectionController::SELECTION_IME_CONVERTEDTEXT: return 4; break; case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT: return 5; break; + case nsISelectionController::SELECTION_ACCESSIBILITY: return 6; break; default:return -1;break; } /* NOTREACHED */ @@ -716,6 +717,7 @@ GetSelectionTypeFromIndex(PRInt8 aIndex) case 3: return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;break; case 4: return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;break; case 5: return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT;break; + case 6: return nsISelectionController::SELECTION_ACCESSIBILITY;break; default: return nsISelectionController::SELECTION_NORMAL;break; }