Back to index

lightning-sunbird  0.9+nobinonly
nsAccessibleText.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public
00006  * License Version 1.1 (the "License"); you may not use this file
00007  * except in compliance with the License. You may obtain a copy of
00008  * the License at http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS
00011  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
00012  * implied. See the License for the specific language governing
00013  * rights and limitations under the License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is Sun Microsystems, Inc.
00018  * Portions created by Sun Microsystems are Copyright (C) 2002 Sun
00019  * Microsystems, Inc. All Rights Reserved.
00020  *
00021  * Original Author: Kyle Yuan (kyle.yuan@sun.com)
00022  *
00023  * Contributor(s):
00024  *
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the NPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the NPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #ifndef _nsAccessibleText_H_
00041 #define _nsAccessibleText_H_
00042 
00043 #include "nsAccessibleEventData.h"
00044 #include "nsBaseWidgetAccessible.h"
00045 #include "nsIAccessibleEditableText.h"
00046 #include "nsIAccessibleText.h"
00047 #include "nsIEditActionListener.h"
00048 #include "nsIEditor.h"
00049 #include "nsISelectionController.h"
00050 #include "nsITextControlFrame.h"
00051 #include "nsTextAccessibleWrap.h"
00052 #include "nsTextAccessible.h"
00053 
00054 enum EGetTextType { eGetBefore=-1, eGetAt=0, eGetAfter=1 };
00055 
00056 class nsAccessibleText : public nsIAccessibleText
00057 {
00058 public:
00059   NS_DECL_ISUPPORTS
00060   NS_DECL_NSIACCESSIBLETEXT
00061 
00062   nsAccessibleText(nsIDOMNode *aNode);
00063   virtual ~nsAccessibleText() {};
00064 
00065   static PRBool gSuppressedNotifySelectionChanged;
00066 
00067 protected:
00068   nsCOMPtr<nsIDOMNode> mTextNode;
00069 
00070   virtual nsresult GetSelections(nsISelectionController **aSelCon, nsISelection **aDomSel);
00071   nsresult GetTextHelperCore(EGetTextType aType, nsAccessibleTextBoundary aBoundaryType,
00072                              PRInt32 aOffset, PRInt32 *aStartOffset, PRInt32 *aEndOffset,
00073                              nsISelectionController *aSelCon, nsISelection *aDomSel,
00074                              nsISupports *aClosure, nsAString & aText);
00075   nsresult GetTextHelper(EGetTextType aType, nsAccessibleTextBoundary aBoundaryType,
00076                          PRInt32 aOffset, PRInt32 *aStartOffset, PRInt32 *aEndOffset,
00077                          nsISupports *aClosure, nsAString & aText);
00078 
00079   static nsresult DOMPointToOffset(nsISupports *aClosure, nsIDOMNode* aNode, PRInt32 aNodeOffset, PRInt32 *aResult);
00080   static nsresult OffsetToDOMPoint(nsISupports *aClosure, PRInt32 aOffset, nsIDOMNode** aResult, PRInt32* aPosition);
00081   static nsresult GetCurrentOffset(nsISupports *aClosure, nsISelection *aDomSel, PRInt32 *aOffset);
00082 
00083   friend class nsAccessibleHyperText;
00084 };
00085 
00086 class nsAccessibleEditableText : public nsAccessibleText,
00087                                  public nsIAccessibleEditableText,
00088                                  public nsIEditActionListener
00089 {
00090 public:
00091   NS_DECL_ISUPPORTS
00092   NS_DECL_NSIACCESSIBLEEDITABLETEXT
00093   NS_DECL_NSIEDITACTIONLISTENER
00094 
00095   nsAccessibleEditableText(nsIDOMNode *aNode);
00096   virtual ~nsAccessibleEditableText() {};
00097 
00098   NS_IMETHOD GetCaretOffset(PRInt32 *aCaretOffset);
00099   NS_IMETHOD SetCaretOffset(PRInt32 aCaretOffset);
00100   NS_IMETHOD GetCharacterCount(PRInt32 *aCharacterCount);
00101   NS_IMETHOD GetText(PRInt32 startOffset, PRInt32 endOffset, nsAString & aText);
00102   NS_IMETHOD GetTextBeforeOffset(PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType,
00103                                  PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString & aText);
00104   NS_IMETHOD GetTextAtOffset(PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType,
00105                              PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString & aText);
00106   NS_IMETHOD GetTextAfterOffset(PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType,
00107                                 PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString & aText);
00108 
00109   void ShutdownEditor();
00110 
00111   static PRBool IsSingleLineTextControl(nsIDOMNode *aDomNode);
00112 
00113 protected:
00114   virtual nsresult GetSelections(nsISelectionController **aSelCon, nsISelection **aDomSel);
00115 
00116   void SetEditor(nsIEditor *aEditor);
00117   nsITextControlFrame* GetTextFrame();
00118   nsresult GetSelectionRange(PRInt32 *aStartPos, PRInt32 *aEndPos);
00119   nsresult SetSelectionRange(PRInt32 aStartPos, PRInt32 aEndPos);
00120   nsresult FireTextChangeEvent(AtkTextChange *aTextData);
00121 
00122   // To solve the naming conflict with nsDocAccessible::mEditor, we have to name it
00123   // "mPlainEditor", though it's not necessary to be a "plaintext" editor.
00124   nsCOMPtr<nsIEditor>  mPlainEditor;
00125 };
00126 
00127 class nsTextAccessibleWrap : public nsTextAccessible,
00128                              public nsAccessibleText
00129 {
00130 public:
00131   NS_DECL_ISUPPORTS_INHERITED
00132 
00133   nsTextAccessibleWrap(nsIDOMNode* aDomNode, nsIWeakReference* aShell);
00134 };
00135 
00136 #endif
00137