diff --git a/mozilla/accessible/public/msaa/AccessibleMarshal.c b/mozilla/accessible/public/msaa/AccessibleMarshal.c index e0bfa4880a1..e5a5286d14f 100755 --- a/mozilla/accessible/public/msaa/AccessibleMarshal.c +++ b/mozilla/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/mozilla/accessible/public/msaa/ISimpleDOMText.idl b/mozilla/accessible/public/msaa/ISimpleDOMText.idl new file mode 100755 index 00000000000..723017847a9 --- /dev/null +++ b/mozilla/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/mozilla/accessible/public/msaa/Makefile.in b/mozilla/accessible/public/msaa/Makefile.in index f655244a621..dee917f47ef 100755 --- a/mozilla/accessible/public/msaa/Makefile.in +++ b/mozilla/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/mozilla/accessible/src/atk/Makefile.in b/mozilla/accessible/src/atk/Makefile.in index bf975618faa..7f68ab9ae3d 100644 --- a/mozilla/accessible/src/atk/Makefile.in +++ b/mozilla/accessible/src/atk/Makefile.in @@ -100,6 +100,8 @@ EXPORTS = \ nsAccessibleWrap.h \ nsDocAccessibleWrap.h \ nsRootAccessibleWrap.h \ + nsTextAccessibleWrap.h \ + nsAccessibleText.h \ $(NULL) # we want to force the creation of a static lib. diff --git a/mozilla/accessible/src/atk/nsAccessibleText.h b/mozilla/accessible/src/atk/nsAccessibleText.h index 701fd22bb20..3785308eaaf 100644 --- a/mozilla/accessible/src/atk/nsAccessibleText.h +++ b/mozilla/accessible/src/atk/nsAccessibleText.h @@ -48,6 +48,7 @@ #include "nsIEditor.h" #include "nsISelectionController.h" #include "nsITextControlFrame.h" +#include "nsTextAccessibleWrap.h" #include "nsTextAccessible.h" enum EGetTextType { eGetBefore=-1, eGetAt=0, eGetAfter=1 }; diff --git a/mozilla/accessible/src/atk/nsTextAccessibleWrap.h b/mozilla/accessible/src/atk/nsTextAccessibleWrap.h new file mode 100644 index 00000000000..44583d551a9 --- /dev/null +++ b/mozilla/accessible/src/atk/nsTextAccessibleWrap.h @@ -0,0 +1,46 @@ +/* -*- 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 "nsAccessibleText.h" + +#endif diff --git a/mozilla/accessible/src/base/nsDocAccessible.cpp b/mozilla/accessible/src/base/nsDocAccessible.cpp index 93513e5a4b2..111a7540d64 100644 --- a/mozilla/accessible/src/base/nsDocAccessible.cpp +++ b/mozilla/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/mozilla/accessible/src/base/nsOuterDocAccessible.cpp b/mozilla/accessible/src/base/nsOuterDocAccessible.cpp index 34b061b4f34..9cd6f9b86ac 100644 --- a/mozilla/accessible/src/base/nsOuterDocAccessible.cpp +++ b/mozilla/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/mozilla/accessible/src/base/nsOuterDocAccessible.h b/mozilla/accessible/src/base/nsOuterDocAccessible.h index 7bfb3be35b5..9d5133c590f 100644 --- a/mozilla/accessible/src/base/nsOuterDocAccessible.h +++ b/mozilla/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/mozilla/accessible/src/html/nsHTMLTextAccessible.cpp b/mozilla/accessible/src/html/nsHTMLTextAccessible.cpp index 90bc4df2f3c..7764a265d0b 100644 --- a/mozilla/accessible/src/html/nsHTMLTextAccessible.cpp +++ b/mozilla/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/mozilla/accessible/src/html/nsHTMLTextAccessible.h b/mozilla/accessible/src/html/nsHTMLTextAccessible.h index 0e81f2db3a4..66d2570e19e 100644 --- a/mozilla/accessible/src/html/nsHTMLTextAccessible.h +++ b/mozilla/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/mozilla/accessible/src/mac/Makefile.in b/mozilla/accessible/src/mac/Makefile.in index 1f84e4205a1..3e729b3368d 100644 --- a/mozilla/accessible/src/mac/Makefile.in +++ b/mozilla/accessible/src/mac/Makefile.in @@ -73,6 +73,7 @@ CPPSRCS = \ EXPORTS = \ nsAccessNodeWrap.h \ + nsTextAccessibleWrap.h \ nsAccessibleWrap.h \ nsDocAccessibleWrap.h \ nsRootAccessibleWrap.h \ diff --git a/mozilla/accessible/src/mac/nsTextAccessibleWrap.h b/mozilla/accessible/src/mac/nsTextAccessibleWrap.h new file mode 100755 index 00000000000..3eb56497a4d --- /dev/null +++ b/mozilla/accessible/src/mac/nsTextAccessibleWrap.h @@ -0,0 +1,47 @@ +/* -*- 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" + +typedef class nsTextAccessible nsTextAccessibleWrap; + +#endif diff --git a/mozilla/accessible/src/msaa/Makefile.in b/mozilla/accessible/src/msaa/Makefile.in index e8359253209..da913253a2b 100644 --- a/mozilla/accessible/src/msaa/Makefile.in +++ b/mozilla/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/mozilla/accessible/src/msaa/nsDocAccessibleWrap.cpp b/mozilla/accessible/src/msaa/nsDocAccessibleWrap.cpp index 8702749baf8..0cb4b3cb0ba 100644 --- a/mozilla/accessible/src/msaa/nsDocAccessibleWrap.cpp +++ b/mozilla/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/mozilla/accessible/src/msaa/nsTextAccessibleWrap.cpp b/mozilla/accessible/src/msaa/nsTextAccessibleWrap.cpp new file mode 100755 index 00000000000..1b42a73a550 --- /dev/null +++ b/mozilla/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/mozilla/accessible/src/msaa/nsTextAccessibleWrap.h b/mozilla/accessible/src/msaa/nsTextAccessibleWrap.h new file mode 100755 index 00000000000..1b7698395f6 --- /dev/null +++ b/mozilla/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/mozilla/accessible/src/other/Makefile.in b/mozilla/accessible/src/other/Makefile.in index 1f84e4205a1..3e729b3368d 100755 --- a/mozilla/accessible/src/other/Makefile.in +++ b/mozilla/accessible/src/other/Makefile.in @@ -73,6 +73,7 @@ CPPSRCS = \ EXPORTS = \ nsAccessNodeWrap.h \ + nsTextAccessibleWrap.h \ nsAccessibleWrap.h \ nsDocAccessibleWrap.h \ nsRootAccessibleWrap.h \ diff --git a/mozilla/accessible/src/other/nsTextAccessibleWrap.h b/mozilla/accessible/src/other/nsTextAccessibleWrap.h new file mode 100755 index 00000000000..3eb56497a4d --- /dev/null +++ b/mozilla/accessible/src/other/nsTextAccessibleWrap.h @@ -0,0 +1,47 @@ +/* -*- 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" + +typedef class nsTextAccessible nsTextAccessibleWrap; + +#endif diff --git a/mozilla/accessible/src/xul/nsXULTextAccessible.cpp b/mozilla/accessible/src/xul/nsXULTextAccessible.cpp index 6ac18c22e71..f45b5ebd54d 100644 --- a/mozilla/accessible/src/xul/nsXULTextAccessible.cpp +++ b/mozilla/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/mozilla/accessible/src/xul/nsXULTextAccessible.h b/mozilla/accessible/src/xul/nsXULTextAccessible.h index 38212cd69ad..aa239dd6f2c 100644 --- a/mozilla/accessible/src/xul/nsXULTextAccessible.h +++ b/mozilla/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: