Bug 827007: Implement Stop for UserMediaStreams; add NotifyRemoved for MediaStream...
[gecko.git] / editor / libeditor / text / nsPlaintextEditor.h
blob5c065b1e59868bd8e4efe9c855b009331bb646de
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsPlaintextEditor_h__
7 #define nsPlaintextEditor_h__
9 #include "nsCOMPtr.h"
10 #include "nsCycleCollectionParticipant.h"
11 #include "nsEditor.h"
12 #include "nsIEditor.h"
13 #include "nsIEditorMailSupport.h"
14 #include "nsIPlaintextEditor.h"
15 #include "nsISupportsImpl.h"
16 #include "nscore.h"
18 class nsIContent;
19 class nsIDOMDataTransfer;
20 class nsIDOMDocument;
21 class nsIDOMElement;
22 class nsIDOMEvent;
23 class nsIDOMEventTarget;
24 class nsIDOMKeyEvent;
25 class nsIDOMNode;
26 class nsIDocumentEncoder;
27 class nsIEditRules;
28 class nsIOutputStream;
29 class nsIPrivateTextRangeList;
30 class nsISelection;
31 class nsISelectionController;
32 class nsITransferable;
34 /**
35 * The text editor implementation.
36 * Use to edit text document represented as a DOM tree.
38 class nsPlaintextEditor : public nsEditor,
39 public nsIPlaintextEditor,
40 public nsIEditorMailSupport
43 public:
45 // Interfaces for addref and release and queryinterface
46 // NOTE macro used is for classes that inherit from
47 // another class. Only the base class should use NS_DECL_ISUPPORTS
48 NS_DECL_ISUPPORTS_INHERITED
49 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsPlaintextEditor, nsEditor)
51 /* below used by TypedText() */
52 enum ETypingAction {
53 eTypedText, /* user typed text */
54 eTypedBR, /* user typed shift-enter to get a br */
55 eTypedBreak /* user typed enter */
58 nsPlaintextEditor();
59 virtual ~nsPlaintextEditor();
61 /* ------------ nsIPlaintextEditor methods -------------- */
62 NS_DECL_NSIPLAINTEXTEDITOR
64 /* ------------ nsIEditorMailSupport overrides -------------- */
65 NS_DECL_NSIEDITORMAILSUPPORT
67 /* ------------ Overrides of nsEditor interface methods -------------- */
68 NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement * aElement,
69 const nsAString & aAttribute,
70 const nsAString & aValue,
71 bool aSuppressTransaction);
72 NS_IMETHOD RemoveAttributeOrEquivalent(nsIDOMElement * aElement,
73 const nsAString & aAttribute,
74 bool aSuppressTransaction);
76 /** prepare the editor for use */
77 NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIContent *aRoot, nsISelectionController *aSelCon, uint32_t aFlags);
79 NS_IMETHOD GetDocumentIsEmpty(bool *aDocumentIsEmpty);
80 NS_IMETHOD GetIsDocumentEditable(bool *aIsDocumentEditable);
82 NS_IMETHOD DeleteSelection(EDirection aAction,
83 EStripWrappers aStripWrappers);
85 NS_IMETHOD SetDocumentCharacterSet(const nsACString & characterSet);
87 NS_IMETHOD Undo(uint32_t aCount);
88 NS_IMETHOD Redo(uint32_t aCount);
90 NS_IMETHOD Cut();
91 NS_IMETHOD CanCut(bool *aCanCut);
92 NS_IMETHOD Copy();
93 NS_IMETHOD CanCopy(bool *aCanCopy);
94 NS_IMETHOD Paste(int32_t aSelectionType);
95 NS_IMETHOD CanPaste(int32_t aSelectionType, bool *aCanPaste);
96 NS_IMETHOD PasteTransferable(nsITransferable *aTransferable);
97 NS_IMETHOD CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste);
99 NS_IMETHOD OutputToString(const nsAString& aFormatType,
100 uint32_t aFlags,
101 nsAString& aOutputString);
103 NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
104 const nsAString& aFormatType,
105 const nsACString& aCharsetOverride,
106 uint32_t aFlags);
109 /** All editor operations which alter the doc should be prefaced
110 * with a call to StartOperation, naming the action and direction */
111 NS_IMETHOD StartOperation(EditAction opID,
112 nsIEditor::EDirection aDirection);
114 /** All editor operations which alter the doc should be followed
115 * with a call to EndOperation */
116 NS_IMETHOD EndOperation();
118 /** make the given selection span the entire document */
119 NS_IMETHOD SelectEntireDocument(nsISelection *aSelection);
121 virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
123 virtual already_AddRefed<nsIDOMEventTarget> GetDOMEventTarget();
125 virtual nsresult BeginIMEComposition();
126 virtual nsresult UpdateIMEComposition(const nsAString &aCompositionString,
127 nsIPrivateTextRangeList *aTextRange);
129 virtual already_AddRefed<nsIContent> GetInputEventTargetContent();
131 /* ------------ Utility Routines, not part of public API -------------- */
132 NS_IMETHOD TypedText(const nsAString& aString, ETypingAction aAction);
134 nsresult InsertTextAt(const nsAString &aStringToInsert,
135 nsIDOMNode *aDestinationNode,
136 int32_t aDestOffset,
137 bool aDoDeleteSelection);
139 virtual nsresult InsertFromDataTransfer(nsIDOMDataTransfer *aDataTransfer,
140 int32_t aIndex,
141 nsIDOMDocument *aSourceDoc,
142 nsIDOMNode *aDestinationNode,
143 int32_t aDestOffset,
144 bool aDoDeleteSelection);
146 virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent);
149 * Extends the selection for given deletion operation
150 * If done, also update aAction to what's actually left to do after the
151 * extension.
153 nsresult ExtendSelectionForDelete(nsISelection* aSelection,
154 nsIEditor::EDirection *aAction);
156 // Return true if the data is safe to insert as the source and destination
157 // principals match, or we are in a editor context where this doesn't matter.
158 // Otherwise, the data must be sanitized first.
159 bool IsSafeToInsertData(nsIDOMDocument* aSourceDoc);
161 static void GetDefaultEditorPrefs(int32_t &aNewLineHandling,
162 int32_t &aCaretStyle);
164 protected:
166 NS_IMETHOD InitRules();
167 void BeginEditorInit();
168 nsresult EndEditorInit();
170 // Helpers for output routines
171 NS_IMETHOD GetAndInitDocEncoder(const nsAString& aFormatType,
172 uint32_t aFlags,
173 const nsACString& aCharset,
174 nsIDocumentEncoder** encoder);
176 // key event helpers
177 NS_IMETHOD CreateBR(nsIDOMNode *aNode, int32_t aOffset,
178 nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect = eNone);
179 nsresult CreateBRImpl(nsCOMPtr<nsIDOMNode>* aInOutParent,
180 int32_t* aInOutOffset,
181 nsCOMPtr<nsIDOMNode>* outBRNode,
182 EDirection aSelect);
183 nsresult InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode);
185 // factored methods for handling insertion of data from transferables (drag&drop or clipboard)
186 NS_IMETHOD PrepareTransferable(nsITransferable **transferable);
187 NS_IMETHOD InsertTextFromTransferable(nsITransferable *transferable,
188 nsIDOMNode *aDestinationNode,
189 int32_t aDestOffset,
190 bool aDoDeleteSelection);
192 /** shared outputstring; returns whether selection is collapsed and resulting string */
193 nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed, nsAString& aResult);
195 /* small utility routine to test the eEditorReadonly bit */
196 bool IsModifiable();
198 bool CanCutOrCopy();
199 bool FireClipboardEvent(int32_t aType);
201 bool UpdateMetaCharset(nsIDOMDocument* aDocument,
202 const nsACString& aCharacterSet);
204 // Data members
205 protected:
207 nsCOMPtr<nsIEditRules> mRules;
208 bool mWrapToWindow;
209 int32_t mWrapColumn;
210 int32_t mMaxTextLength;
211 int32_t mInitTriggerCounter;
212 int32_t mNewlineHandling;
213 int32_t mCaretStyle;
215 // friends
216 friend class nsHTMLEditRules;
217 friend class nsTextEditRules;
218 friend class nsAutoEditInitRulesTrigger;
222 #endif //nsPlaintextEditor_h__