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