michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsPlaintextEditor_h__ michael@0: #define nsPlaintextEditor_h__ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsEditor.h" michael@0: #include "nsIEditor.h" michael@0: #include "nsIEditorMailSupport.h" michael@0: #include "nsIPlaintextEditor.h" michael@0: #include "nsISupportsImpl.h" michael@0: #include "nscore.h" michael@0: michael@0: class nsIContent; michael@0: class nsIDOMDataTransfer; michael@0: class nsIDOMDocument; michael@0: class nsIDOMElement; michael@0: class nsIDOMEvent; michael@0: class nsIDOMEventTarget; michael@0: class nsIDOMKeyEvent; michael@0: class nsIDOMNode; michael@0: class nsIDocumentEncoder; michael@0: class nsIEditRules; michael@0: class nsIOutputStream; michael@0: class nsISelection; michael@0: class nsISelectionController; michael@0: class nsITransferable; michael@0: michael@0: /** michael@0: * The text editor implementation. michael@0: * Use to edit text document represented as a DOM tree. michael@0: */ michael@0: class nsPlaintextEditor : public nsEditor, michael@0: public nsIPlaintextEditor, michael@0: public nsIEditorMailSupport michael@0: { michael@0: michael@0: public: michael@0: michael@0: // Interfaces for addref and release and queryinterface michael@0: // NOTE macro used is for classes that inherit from michael@0: // another class. Only the base class should use NS_DECL_ISUPPORTS michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsPlaintextEditor, nsEditor) michael@0: michael@0: /* below used by TypedText() */ michael@0: enum ETypingAction { michael@0: eTypedText, /* user typed text */ michael@0: eTypedBR, /* user typed shift-enter to get a br */ michael@0: eTypedBreak /* user typed enter */ michael@0: }; michael@0: michael@0: nsPlaintextEditor(); michael@0: virtual ~nsPlaintextEditor(); michael@0: michael@0: /* ------------ nsIPlaintextEditor methods -------------- */ michael@0: NS_DECL_NSIPLAINTEXTEDITOR michael@0: michael@0: /* ------------ nsIEditorMailSupport overrides -------------- */ michael@0: NS_DECL_NSIEDITORMAILSUPPORT michael@0: michael@0: /* ------------ Overrides of nsEditor interface methods -------------- */ michael@0: NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement * aElement, michael@0: const nsAString & aAttribute, michael@0: const nsAString & aValue, michael@0: bool aSuppressTransaction); michael@0: NS_IMETHOD RemoveAttributeOrEquivalent(nsIDOMElement * aElement, michael@0: const nsAString & aAttribute, michael@0: bool aSuppressTransaction); michael@0: michael@0: /** prepare the editor for use */ michael@0: NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIContent *aRoot, michael@0: nsISelectionController *aSelCon, uint32_t aFlags, michael@0: const nsAString& aValue); michael@0: michael@0: NS_IMETHOD GetDocumentIsEmpty(bool *aDocumentIsEmpty); michael@0: NS_IMETHOD GetIsDocumentEditable(bool *aIsDocumentEditable); michael@0: michael@0: NS_IMETHOD DeleteSelection(EDirection aAction, michael@0: EStripWrappers aStripWrappers); michael@0: michael@0: NS_IMETHOD SetDocumentCharacterSet(const nsACString & characterSet); michael@0: michael@0: NS_IMETHOD Undo(uint32_t aCount); michael@0: NS_IMETHOD Redo(uint32_t aCount); michael@0: michael@0: NS_IMETHOD Cut(); michael@0: NS_IMETHOD CanCut(bool *aCanCut); michael@0: NS_IMETHOD Copy(); michael@0: NS_IMETHOD CanCopy(bool *aCanCopy); michael@0: NS_IMETHOD Paste(int32_t aSelectionType); michael@0: NS_IMETHOD CanPaste(int32_t aSelectionType, bool *aCanPaste); michael@0: NS_IMETHOD PasteTransferable(nsITransferable *aTransferable); michael@0: NS_IMETHOD CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste); michael@0: michael@0: NS_IMETHOD OutputToString(const nsAString& aFormatType, michael@0: uint32_t aFlags, michael@0: nsAString& aOutputString); michael@0: michael@0: NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream, michael@0: const nsAString& aFormatType, michael@0: const nsACString& aCharsetOverride, michael@0: uint32_t aFlags); michael@0: michael@0: michael@0: /** All editor operations which alter the doc should be prefaced michael@0: * with a call to StartOperation, naming the action and direction */ michael@0: NS_IMETHOD StartOperation(EditAction opID, michael@0: nsIEditor::EDirection aDirection); michael@0: michael@0: /** All editor operations which alter the doc should be followed michael@0: * with a call to EndOperation */ michael@0: NS_IMETHOD EndOperation(); michael@0: michael@0: /** make the given selection span the entire document */ michael@0: NS_IMETHOD SelectEntireDocument(nsISelection *aSelection); michael@0: michael@0: virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent); michael@0: michael@0: virtual already_AddRefed GetDOMEventTarget(); michael@0: michael@0: virtual nsresult BeginIMEComposition(mozilla::WidgetCompositionEvent* aEvent); michael@0: virtual nsresult UpdateIMEComposition(nsIDOMEvent* aTextEvent) MOZ_OVERRIDE; michael@0: michael@0: virtual already_AddRefed GetInputEventTargetContent(); michael@0: michael@0: /* ------------ Utility Routines, not part of public API -------------- */ michael@0: NS_IMETHOD TypedText(const nsAString& aString, ETypingAction aAction); michael@0: michael@0: nsresult InsertTextAt(const nsAString &aStringToInsert, michael@0: nsIDOMNode *aDestinationNode, michael@0: int32_t aDestOffset, michael@0: bool aDoDeleteSelection); michael@0: michael@0: virtual nsresult InsertFromDataTransfer(mozilla::dom::DataTransfer *aDataTransfer, michael@0: int32_t aIndex, michael@0: nsIDOMDocument *aSourceDoc, michael@0: nsIDOMNode *aDestinationNode, michael@0: int32_t aDestOffset, michael@0: bool aDoDeleteSelection); michael@0: michael@0: virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent); michael@0: michael@0: /** michael@0: * Extends the selection for given deletion operation michael@0: * If done, also update aAction to what's actually left to do after the michael@0: * extension. michael@0: */ michael@0: nsresult ExtendSelectionForDelete(nsISelection* aSelection, michael@0: nsIEditor::EDirection *aAction); michael@0: michael@0: // Return true if the data is safe to insert as the source and destination michael@0: // principals match, or we are in a editor context where this doesn't matter. michael@0: // Otherwise, the data must be sanitized first. michael@0: bool IsSafeToInsertData(nsIDOMDocument* aSourceDoc); michael@0: michael@0: static void GetDefaultEditorPrefs(int32_t &aNewLineHandling, michael@0: int32_t &aCaretStyle); michael@0: michael@0: protected: michael@0: michael@0: NS_IMETHOD InitRules(); michael@0: void BeginEditorInit(); michael@0: nsresult EndEditorInit(); michael@0: michael@0: // Helpers for output routines michael@0: NS_IMETHOD GetAndInitDocEncoder(const nsAString& aFormatType, michael@0: uint32_t aFlags, michael@0: const nsACString& aCharset, michael@0: nsIDocumentEncoder** encoder); michael@0: michael@0: // key event helpers michael@0: NS_IMETHOD CreateBR(nsIDOMNode *aNode, int32_t aOffset, michael@0: nsCOMPtr *outBRNode, EDirection aSelect = eNone); michael@0: nsresult CreateBRImpl(nsCOMPtr* aInOutParent, michael@0: int32_t* aInOutOffset, michael@0: nsCOMPtr* outBRNode, michael@0: EDirection aSelect); michael@0: nsresult InsertBR(nsCOMPtr* outBRNode); michael@0: michael@0: // factored methods for handling insertion of data from transferables (drag&drop or clipboard) michael@0: NS_IMETHOD PrepareTransferable(nsITransferable **transferable); michael@0: NS_IMETHOD InsertTextFromTransferable(nsITransferable *transferable, michael@0: nsIDOMNode *aDestinationNode, michael@0: int32_t aDestOffset, michael@0: bool aDoDeleteSelection); michael@0: michael@0: /** shared outputstring; returns whether selection is collapsed and resulting string */ michael@0: nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed, nsAString& aResult); michael@0: michael@0: /* small utility routine to test the eEditorReadonly bit */ michael@0: bool IsModifiable(); michael@0: michael@0: bool CanCutOrCopy(); michael@0: bool FireClipboardEvent(int32_t aType, int32_t aSelectionType); michael@0: michael@0: bool UpdateMetaCharset(nsIDOMDocument* aDocument, michael@0: const nsACString& aCharacterSet); michael@0: michael@0: // Data members michael@0: protected: michael@0: michael@0: nsCOMPtr mRules; michael@0: bool mWrapToWindow; michael@0: int32_t mWrapColumn; michael@0: int32_t mMaxTextLength; michael@0: int32_t mInitTriggerCounter; michael@0: int32_t mNewlineHandling; michael@0: int32_t mCaretStyle; michael@0: michael@0: // friends michael@0: friend class nsHTMLEditRules; michael@0: friend class nsTextEditRules; michael@0: friend class nsAutoEditInitRulesTrigger; michael@0: michael@0: }; michael@0: michael@0: #endif //nsPlaintextEditor_h__ michael@0: