/
nsPlaintextEditor.h
265 lines (213 loc) · 10.3 KB
/
nsPlaintextEditor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/* -*- 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 Netscape 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/NPL/
*
* 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 Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Glazman <glazman@netscape.com>
*
*
* 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 nsPlaintextEditor_h__
#define nsPlaintextEditor_h__
#include "nsCOMPtr.h"
#include "nsIPlaintextEditor.h"
#include "nsIEditorMailSupport.h"
#include "nsEditor.h"
#include "nsIDOMElement.h"
#include "nsIDOMEventListener.h"
#include "nsEditRules.h"
class nsIDOMKeyEvent;
class nsITransferable;
class nsIDOMEventReceiver;
class nsIDocumentEncoder;
/**
* The text editor implementation.
* Use to edit text document represented as a DOM tree.
*/
class nsPlaintextEditor : public nsEditor,
public nsIPlaintextEditor,
public nsIEditorMailSupport
{
public:
// Interfaces for addref and release and queryinterface
// NOTE macro used is for classes that inherit from
// another class. Only the base class should use NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
/* below used by TypedText() */
enum {
eTypedText, /* user typed text */
eTypedBR, /* user typed shift-enter to get a br */
eTypedBreak /* user typed enter */
};
nsPlaintextEditor();
virtual ~nsPlaintextEditor();
/* ------------ nsIPlaintextEditor methods -------------- */
NS_DECL_NSIPLAINTEXTEDITOR
/* ------------ nsIEditorMailSupport overrides -------------- */
NS_IMETHOD InsertTextWithQuotations(const nsAString &aStringToInsert);
NS_IMETHOD PasteAsQuotation(PRInt32 aSelectionType);
NS_IMETHOD InsertAsQuotation(const nsAString& aQuotedText,
nsIDOMNode** aNodeInserted);
NS_IMETHOD PasteAsCitedQuotation(const nsAString& aCitation,
PRInt32 aSelectionType);
NS_IMETHOD InsertAsCitedQuotation(const nsAString& aQuotedText,
const nsAString& aCitation,
PRBool aInsertHTML,
const nsAString& aCharset,
nsIDOMNode** aNodeInserted);
NS_IMETHOD Rewrap(PRBool aRespectNewlines);
NS_IMETHOD StripCites();
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray** aNodeList);
/* ------------ nsIEditorIMESupport overrides -------------- */
NS_IMETHOD SetCompositionString(const nsAString & aCompositionString, nsIPrivateTextRangeList * aTextRange, nsTextEventReply * aReply);
NS_IMETHOD GetReconversionString(nsReconversionEventReply* aReply);
/* ------------ Overrides of nsEditor interface methods -------------- */
NS_IMETHOD BeginComposition(nsTextEventReply* aReply);
NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement * aElement,
const nsAString & aAttribute,
const nsAString & aValue,
PRBool aSuppressTransaction);
NS_IMETHOD RemoveAttributeOrEquivalent(nsIDOMElement * aElement,
const nsAString & aAttribute,
PRBool aSuppressTransaction);
/** prepare the editor for use */
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, nsIContent *aRoot, nsISelectionController *aSelCon, PRUint32 aFlags);
NS_IMETHOD GetDocumentIsEmpty(PRBool *aDocumentIsEmpty);
NS_IMETHOD GetIsDocumentEditable(PRBool *aIsDocumentEditable);
NS_IMETHOD DeleteSelection(EDirection aAction);
NS_IMETHOD SetDocumentCharacterSet(const nsAString & characterSet);
/** we override this here to install event listeners */
NS_IMETHOD PostCreate();
NS_IMETHOD GetFlags(PRUint32 *aFlags);
NS_IMETHOD SetFlags(PRUint32 aFlags);
NS_IMETHOD Undo(PRUint32 aCount);
NS_IMETHOD Redo(PRUint32 aCount);
NS_IMETHOD Cut();
NS_IMETHOD CanCut(PRBool *aCanCut);
NS_IMETHOD Copy();
NS_IMETHOD CanCopy(PRBool *aCanCopy);
NS_IMETHOD Paste(PRInt32 aSelectionType);
NS_IMETHOD CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste);
NS_IMETHOD CanDrag(nsIDOMEvent *aDragEvent, PRBool *aCanDrag);
NS_IMETHOD DoDrag(nsIDOMEvent *aDragEvent);
NS_IMETHOD InsertFromDrop(nsIDOMEvent* aDropEvent);
NS_IMETHOD OutputToString(const nsAString& aFormatType,
PRUint32 aFlags,
nsAString& aOutputString);
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
const nsAString& aFormatType,
const nsAString& aCharsetOverride,
PRUint32 aFlags);
/** All editor operations which alter the doc should be prefaced
* with a call to StartOperation, naming the action and direction */
NS_IMETHOD StartOperation(PRInt32 opID, nsIEditor::EDirection aDirection);
/** All editor operations which alter the doc should be followed
* with a call to EndOperation */
NS_IMETHOD EndOperation();
/** make the given selection span the entire document */
NS_IMETHOD SelectEntireDocument(nsISelection *aSelection);
/* ------------ Utility Routines, not part of public API -------------- */
NS_IMETHOD TypedText(const nsAString& aString, PRInt32 aAction);
/** returns the absolute position of the end points of aSelection
* in the document as a text stream.
*/
nsresult GetTextSelectionOffsets(nsISelection *aSelection,
PRInt32 &aStartOffset,
PRInt32 &aEndOffset);
nsresult GetAbsoluteOffsetsForPoints(nsIDOMNode *aInStartNode,
PRInt32 aInStartOffset,
nsIDOMNode *aInEndNode,
PRInt32 aInEndOffset,
nsIDOMNode *aInCommonParentNode,
PRInt32 &aOutStartOffset,
PRInt32 &aEndOffset);
protected:
NS_IMETHOD InitRules();
void BeginEditorInit();
nsresult EndEditorInit();
/** install the event listeners for the editor
* used to be part of Init, but now broken out into a separate method
* called by PostCreate, giving the caller the chance to interpose
* their own listeners before we install our own backstops.
*/
NS_IMETHOD InstallEventListeners();
/** returns the layout object (nsIFrame in the real world) for aNode
* @param aNode the content to get a frame for
* @param aLayoutObject the "primary frame" for aNode, if one exists. May be null
* @return NS_OK whether a frame is found or not
* an error if some serious error occurs
*/
NS_IMETHOD GetLayoutObject(nsIDOMNode *aInNode, nsISupports **aOutLayoutObject);
// Helpers for output routines
NS_IMETHOD GetAndInitDocEncoder(const nsAString& aFormatType,
PRUint32 aFlags,
const nsAString& aCharset,
nsIDocumentEncoder** encoder);
// key event helpers
NS_IMETHOD CreateBR(nsIDOMNode *aNode, PRInt32 aOffset,
nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect = eNone);
NS_IMETHOD CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent,
PRInt32 *aInOutOffset,
nsCOMPtr<nsIDOMNode> *outBRNode,
EDirection aSelect);
NS_IMETHOD InsertBR(nsCOMPtr<nsIDOMNode> *outBRNode);
NS_IMETHOD IsRootTag(nsString &aTag, PRBool &aIsTag);
// factored methods for handling insertion of data from transferables (drag&drop or clipboard)
NS_IMETHOD PrepareTransferable(nsITransferable **transferable);
NS_IMETHOD InsertTextFromTransferable(nsITransferable *transferable);
/** simple utility to handle any error with event listener allocation or registration */
void HandleEventListenerError();
/* small utility routine to test the eEditorReadonly bit */
PRBool IsModifiable();
nsresult GetDOMEventReceiver(nsIDOMEventReceiver **aEventReceiver);
//XXX Kludge: Used to suppress spurious drag/drop events (bug 50703)
PRBool mIgnoreSpuriousDragEvent;
NS_IMETHOD IgnoreSpuriousDragEvent(PRBool aIgnoreSpuriousDragEvent) {mIgnoreSpuriousDragEvent = aIgnoreSpuriousDragEvent; return NS_OK;}
// Data members
protected:
nsCOMPtr<nsIEditRules> mRules;
nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
nsCOMPtr<nsIDOMEventListener> mTextListenerP;
nsCOMPtr<nsIDOMEventListener> mCompositionListenerP;
nsCOMPtr<nsIDOMEventListener> mDragListenerP;
nsCOMPtr<nsIDOMEventListener> mFocusListenerP;
PRBool mWrapToWindow;
PRInt32 mWrapColumn;
PRInt32 mMaxTextLength;
PRInt32 mInitTriggerCounter;
// friends
friend class nsHTMLEditRules;
friend class nsTextEditRules;
friend class nsAutoEditInitRulesTrigger;
};
#endif //nsPlaintextEditor_h__