1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/text/nsPlaintextEditor.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,223 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsPlaintextEditor_h__ 1.10 +#define nsPlaintextEditor_h__ 1.11 + 1.12 +#include "nsCOMPtr.h" 1.13 +#include "nsCycleCollectionParticipant.h" 1.14 +#include "nsEditor.h" 1.15 +#include "nsIEditor.h" 1.16 +#include "nsIEditorMailSupport.h" 1.17 +#include "nsIPlaintextEditor.h" 1.18 +#include "nsISupportsImpl.h" 1.19 +#include "nscore.h" 1.20 + 1.21 +class nsIContent; 1.22 +class nsIDOMDataTransfer; 1.23 +class nsIDOMDocument; 1.24 +class nsIDOMElement; 1.25 +class nsIDOMEvent; 1.26 +class nsIDOMEventTarget; 1.27 +class nsIDOMKeyEvent; 1.28 +class nsIDOMNode; 1.29 +class nsIDocumentEncoder; 1.30 +class nsIEditRules; 1.31 +class nsIOutputStream; 1.32 +class nsISelection; 1.33 +class nsISelectionController; 1.34 +class nsITransferable; 1.35 + 1.36 +/** 1.37 + * The text editor implementation. 1.38 + * Use to edit text document represented as a DOM tree. 1.39 + */ 1.40 +class nsPlaintextEditor : public nsEditor, 1.41 + public nsIPlaintextEditor, 1.42 + public nsIEditorMailSupport 1.43 +{ 1.44 + 1.45 +public: 1.46 + 1.47 +// Interfaces for addref and release and queryinterface 1.48 +// NOTE macro used is for classes that inherit from 1.49 +// another class. Only the base class should use NS_DECL_ISUPPORTS 1.50 + NS_DECL_ISUPPORTS_INHERITED 1.51 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsPlaintextEditor, nsEditor) 1.52 + 1.53 + /* below used by TypedText() */ 1.54 + enum ETypingAction { 1.55 + eTypedText, /* user typed text */ 1.56 + eTypedBR, /* user typed shift-enter to get a br */ 1.57 + eTypedBreak /* user typed enter */ 1.58 + }; 1.59 + 1.60 + nsPlaintextEditor(); 1.61 + virtual ~nsPlaintextEditor(); 1.62 + 1.63 + /* ------------ nsIPlaintextEditor methods -------------- */ 1.64 + NS_DECL_NSIPLAINTEXTEDITOR 1.65 + 1.66 + /* ------------ nsIEditorMailSupport overrides -------------- */ 1.67 + NS_DECL_NSIEDITORMAILSUPPORT 1.68 + 1.69 + /* ------------ Overrides of nsEditor interface methods -------------- */ 1.70 + NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement * aElement, 1.71 + const nsAString & aAttribute, 1.72 + const nsAString & aValue, 1.73 + bool aSuppressTransaction); 1.74 + NS_IMETHOD RemoveAttributeOrEquivalent(nsIDOMElement * aElement, 1.75 + const nsAString & aAttribute, 1.76 + bool aSuppressTransaction); 1.77 + 1.78 + /** prepare the editor for use */ 1.79 + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIContent *aRoot, 1.80 + nsISelectionController *aSelCon, uint32_t aFlags, 1.81 + const nsAString& aValue); 1.82 + 1.83 + NS_IMETHOD GetDocumentIsEmpty(bool *aDocumentIsEmpty); 1.84 + NS_IMETHOD GetIsDocumentEditable(bool *aIsDocumentEditable); 1.85 + 1.86 + NS_IMETHOD DeleteSelection(EDirection aAction, 1.87 + EStripWrappers aStripWrappers); 1.88 + 1.89 + NS_IMETHOD SetDocumentCharacterSet(const nsACString & characterSet); 1.90 + 1.91 + NS_IMETHOD Undo(uint32_t aCount); 1.92 + NS_IMETHOD Redo(uint32_t aCount); 1.93 + 1.94 + NS_IMETHOD Cut(); 1.95 + NS_IMETHOD CanCut(bool *aCanCut); 1.96 + NS_IMETHOD Copy(); 1.97 + NS_IMETHOD CanCopy(bool *aCanCopy); 1.98 + NS_IMETHOD Paste(int32_t aSelectionType); 1.99 + NS_IMETHOD CanPaste(int32_t aSelectionType, bool *aCanPaste); 1.100 + NS_IMETHOD PasteTransferable(nsITransferable *aTransferable); 1.101 + NS_IMETHOD CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste); 1.102 + 1.103 + NS_IMETHOD OutputToString(const nsAString& aFormatType, 1.104 + uint32_t aFlags, 1.105 + nsAString& aOutputString); 1.106 + 1.107 + NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream, 1.108 + const nsAString& aFormatType, 1.109 + const nsACString& aCharsetOverride, 1.110 + uint32_t aFlags); 1.111 + 1.112 + 1.113 + /** All editor operations which alter the doc should be prefaced 1.114 + * with a call to StartOperation, naming the action and direction */ 1.115 + NS_IMETHOD StartOperation(EditAction opID, 1.116 + nsIEditor::EDirection aDirection); 1.117 + 1.118 + /** All editor operations which alter the doc should be followed 1.119 + * with a call to EndOperation */ 1.120 + NS_IMETHOD EndOperation(); 1.121 + 1.122 + /** make the given selection span the entire document */ 1.123 + NS_IMETHOD SelectEntireDocument(nsISelection *aSelection); 1.124 + 1.125 + virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent); 1.126 + 1.127 + virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget(); 1.128 + 1.129 + virtual nsresult BeginIMEComposition(mozilla::WidgetCompositionEvent* aEvent); 1.130 + virtual nsresult UpdateIMEComposition(nsIDOMEvent* aTextEvent) MOZ_OVERRIDE; 1.131 + 1.132 + virtual already_AddRefed<nsIContent> GetInputEventTargetContent(); 1.133 + 1.134 + /* ------------ Utility Routines, not part of public API -------------- */ 1.135 + NS_IMETHOD TypedText(const nsAString& aString, ETypingAction aAction); 1.136 + 1.137 + nsresult InsertTextAt(const nsAString &aStringToInsert, 1.138 + nsIDOMNode *aDestinationNode, 1.139 + int32_t aDestOffset, 1.140 + bool aDoDeleteSelection); 1.141 + 1.142 + virtual nsresult InsertFromDataTransfer(mozilla::dom::DataTransfer *aDataTransfer, 1.143 + int32_t aIndex, 1.144 + nsIDOMDocument *aSourceDoc, 1.145 + nsIDOMNode *aDestinationNode, 1.146 + int32_t aDestOffset, 1.147 + bool aDoDeleteSelection); 1.148 + 1.149 + virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent); 1.150 + 1.151 + /** 1.152 + * Extends the selection for given deletion operation 1.153 + * If done, also update aAction to what's actually left to do after the 1.154 + * extension. 1.155 + */ 1.156 + nsresult ExtendSelectionForDelete(nsISelection* aSelection, 1.157 + nsIEditor::EDirection *aAction); 1.158 + 1.159 + // Return true if the data is safe to insert as the source and destination 1.160 + // principals match, or we are in a editor context where this doesn't matter. 1.161 + // Otherwise, the data must be sanitized first. 1.162 + bool IsSafeToInsertData(nsIDOMDocument* aSourceDoc); 1.163 + 1.164 + static void GetDefaultEditorPrefs(int32_t &aNewLineHandling, 1.165 + int32_t &aCaretStyle); 1.166 + 1.167 +protected: 1.168 + 1.169 + NS_IMETHOD InitRules(); 1.170 + void BeginEditorInit(); 1.171 + nsresult EndEditorInit(); 1.172 + 1.173 + // Helpers for output routines 1.174 + NS_IMETHOD GetAndInitDocEncoder(const nsAString& aFormatType, 1.175 + uint32_t aFlags, 1.176 + const nsACString& aCharset, 1.177 + nsIDocumentEncoder** encoder); 1.178 + 1.179 + // key event helpers 1.180 + NS_IMETHOD CreateBR(nsIDOMNode *aNode, int32_t aOffset, 1.181 + nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect = eNone); 1.182 + nsresult CreateBRImpl(nsCOMPtr<nsIDOMNode>* aInOutParent, 1.183 + int32_t* aInOutOffset, 1.184 + nsCOMPtr<nsIDOMNode>* outBRNode, 1.185 + EDirection aSelect); 1.186 + nsresult InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode); 1.187 + 1.188 + // factored methods for handling insertion of data from transferables (drag&drop or clipboard) 1.189 + NS_IMETHOD PrepareTransferable(nsITransferable **transferable); 1.190 + NS_IMETHOD InsertTextFromTransferable(nsITransferable *transferable, 1.191 + nsIDOMNode *aDestinationNode, 1.192 + int32_t aDestOffset, 1.193 + bool aDoDeleteSelection); 1.194 + 1.195 + /** shared outputstring; returns whether selection is collapsed and resulting string */ 1.196 + nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed, nsAString& aResult); 1.197 + 1.198 + /* small utility routine to test the eEditorReadonly bit */ 1.199 + bool IsModifiable(); 1.200 + 1.201 + bool CanCutOrCopy(); 1.202 + bool FireClipboardEvent(int32_t aType, int32_t aSelectionType); 1.203 + 1.204 + bool UpdateMetaCharset(nsIDOMDocument* aDocument, 1.205 + const nsACString& aCharacterSet); 1.206 + 1.207 +// Data members 1.208 +protected: 1.209 + 1.210 + nsCOMPtr<nsIEditRules> mRules; 1.211 + bool mWrapToWindow; 1.212 + int32_t mWrapColumn; 1.213 + int32_t mMaxTextLength; 1.214 + int32_t mInitTriggerCounter; 1.215 + int32_t mNewlineHandling; 1.216 + int32_t mCaretStyle; 1.217 + 1.218 +// friends 1.219 +friend class nsHTMLEditRules; 1.220 +friend class nsTextEditRules; 1.221 +friend class nsAutoEditInitRulesTrigger; 1.222 + 1.223 +}; 1.224 + 1.225 +#endif //nsPlaintextEditor_h__ 1.226 +