2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsPlaintextEditor_h__
|
|
|
|
#define nsPlaintextEditor_h__
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsEditor.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsIEditorMailSupport.h"
|
|
|
|
#include "nsIPlaintextEditor.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nscore.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-12 23:33:42 -07:00
|
|
|
class nsIContent;
|
|
|
|
class nsIDOMDataTransfer;
|
|
|
|
class nsIDOMDocument;
|
|
|
|
class nsIDOMElement;
|
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsIDOMEventTarget;
|
|
|
|
class nsIDOMKeyEvent;
|
|
|
|
class nsIDOMNode;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIDocumentEncoder;
|
2012-07-12 23:33:42 -07:00
|
|
|
class nsIEditRules;
|
|
|
|
class nsIOutputStream;
|
|
|
|
class nsIPrivateTextRangeList;
|
|
|
|
class nsISelection;
|
|
|
|
class nsISelectionController;
|
|
|
|
class nsITransferable;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2009-05-08 21:59:25 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsPlaintextEditor, nsEditor)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* below used by TypedText() */
|
2012-05-22 02:37:17 -07:00
|
|
|
enum ETypingAction {
|
2007-03-22 10:30:00 -07:00
|
|
|
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_DECL_NSIEDITORMAILSUPPORT
|
|
|
|
|
|
|
|
/* ------------ Overrides of nsEditor interface methods -------------- */
|
|
|
|
NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement * aElement,
|
|
|
|
const nsAString & aAttribute,
|
|
|
|
const nsAString & aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aSuppressTransaction);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD RemoveAttributeOrEquivalent(nsIDOMElement * aElement,
|
|
|
|
const nsAString & aAttribute,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aSuppressTransaction);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** prepare the editor for use */
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIContent *aRoot, nsISelectionController *aSelCon, uint32_t aFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD GetDocumentIsEmpty(bool *aDocumentIsEmpty);
|
|
|
|
NS_IMETHOD GetIsDocumentEditable(bool *aIsDocumentEditable);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-10 07:54:33 -07:00
|
|
|
NS_IMETHOD DeleteSelection(EDirection aAction,
|
|
|
|
EStripWrappers aStripWrappers);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD SetDocumentCharacterSet(const nsACString & characterSet);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD Undo(uint32_t aCount);
|
|
|
|
NS_IMETHOD Redo(uint32_t aCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Cut();
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD CanCut(bool *aCanCut);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD Copy();
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD CanCopy(bool *aCanCopy);
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD Paste(int32_t aSelectionType);
|
|
|
|
NS_IMETHOD CanPaste(int32_t aSelectionType, bool *aCanPaste);
|
2010-01-10 17:45:45 -08:00
|
|
|
NS_IMETHOD PasteTransferable(nsITransferable *aTransferable);
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD OutputToString(const nsAString& aFormatType,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAString& aOutputString);
|
|
|
|
|
|
|
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
|
|
|
const nsAString& aFormatType,
|
|
|
|
const nsACString& aCharsetOverride,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
/** All editor operations which alter the doc should be prefaced
|
|
|
|
* with a call to StartOperation, naming the action and direction */
|
2012-08-12 11:28:26 -07:00
|
|
|
NS_IMETHOD StartOperation(EditAction opID,
|
2012-05-05 11:52:29 -07:00
|
|
|
nsIEditor::EDirection aDirection);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** 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);
|
|
|
|
|
2010-06-09 18:16:58 -07:00
|
|
|
virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
|
|
|
|
|
2013-10-22 16:32:04 -07:00
|
|
|
virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget();
|
2010-06-16 22:30:10 -07:00
|
|
|
|
2010-06-29 21:05:12 -07:00
|
|
|
virtual nsresult BeginIMEComposition();
|
|
|
|
virtual nsresult UpdateIMEComposition(const nsAString &aCompositionString,
|
|
|
|
nsIPrivateTextRangeList *aTextRange);
|
|
|
|
|
2012-03-26 18:36:44 -07:00
|
|
|
virtual already_AddRefed<nsIContent> GetInputEventTargetContent();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* ------------ Utility Routines, not part of public API -------------- */
|
2012-05-22 02:37:17 -07:00
|
|
|
NS_IMETHOD TypedText(const nsAString& aString, ETypingAction aAction);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult InsertTextAt(const nsAString &aStringToInsert,
|
|
|
|
nsIDOMNode *aDestinationNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aDestOffset,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDoDeleteSelection);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-17 06:16:59 -08:00
|
|
|
virtual nsresult InsertFromDataTransfer(nsIDOMDataTransfer *aDataTransfer,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIndex,
|
2012-02-17 06:16:59 -08:00
|
|
|
nsIDOMDocument *aSourceDoc,
|
|
|
|
nsIDOMNode *aDestinationNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aDestOffset,
|
2012-02-17 06:16:59 -08:00
|
|
|
bool aDoDeleteSelection);
|
|
|
|
|
|
|
|
virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent);
|
|
|
|
|
2008-10-16 00:44:32 -07:00
|
|
|
/**
|
|
|
|
* Extends the selection for given deletion operation
|
|
|
|
* If done, also update aAction to what's actually left to do after the
|
|
|
|
* extension.
|
|
|
|
*/
|
|
|
|
nsresult ExtendSelectionForDelete(nsISelection* aSelection,
|
|
|
|
nsIEditor::EDirection *aAction);
|
|
|
|
|
2012-08-15 12:35:08 -07:00
|
|
|
// Return true if the data is safe to insert as the source and destination
|
|
|
|
// principals match, or we are in a editor context where this doesn't matter.
|
|
|
|
// Otherwise, the data must be sanitized first.
|
|
|
|
bool IsSafeToInsertData(nsIDOMDocument* aSourceDoc);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static void GetDefaultEditorPrefs(int32_t &aNewLineHandling,
|
|
|
|
int32_t &aCaretStyle);
|
2010-02-01 10:12:31 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
|
|
|
|
NS_IMETHOD InitRules();
|
|
|
|
void BeginEditorInit();
|
|
|
|
nsresult EndEditorInit();
|
|
|
|
|
|
|
|
// Helpers for output routines
|
|
|
|
NS_IMETHOD GetAndInitDocEncoder(const nsAString& aFormatType,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsACString& aCharset,
|
|
|
|
nsIDocumentEncoder** encoder);
|
|
|
|
|
|
|
|
// key event helpers
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD CreateBR(nsIDOMNode *aNode, int32_t aOffset,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect = eNone);
|
2012-02-01 02:54:21 -08:00
|
|
|
nsresult CreateBRImpl(nsCOMPtr<nsIDOMNode>* aInOutParent,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aInOutOffset,
|
2012-02-01 02:54:21 -08:00
|
|
|
nsCOMPtr<nsIDOMNode>* outBRNode,
|
|
|
|
EDirection aSelect);
|
2012-02-01 02:54:21 -08:00
|
|
|
nsresult InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// factored methods for handling insertion of data from transferables (drag&drop or clipboard)
|
|
|
|
NS_IMETHOD PrepareTransferable(nsITransferable **transferable);
|
|
|
|
NS_IMETHOD InsertTextFromTransferable(nsITransferable *transferable,
|
|
|
|
nsIDOMNode *aDestinationNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aDestOffset,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDoDeleteSelection);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** shared outputstring; returns whether selection is collapsed and resulting string */
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed, nsAString& aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* small utility routine to test the eEditorReadonly bit */
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsModifiable();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool CanCutOrCopy();
|
2013-08-07 11:52:38 -07:00
|
|
|
bool FireClipboardEvent(int32_t aType, int32_t aSelectionType);
|
2007-07-25 21:14:33 -07:00
|
|
|
|
2012-02-01 02:54:22 -08:00
|
|
|
bool UpdateMetaCharset(nsIDOMDocument* aDocument,
|
|
|
|
const nsACString& aCharacterSet);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Data members
|
|
|
|
protected:
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEditRules> mRules;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mWrapToWindow;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mWrapColumn;
|
|
|
|
int32_t mMaxTextLength;
|
|
|
|
int32_t mInitTriggerCounter;
|
|
|
|
int32_t mNewlineHandling;
|
|
|
|
int32_t mCaretStyle;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// friends
|
|
|
|
friend class nsHTMLEditRules;
|
|
|
|
friend class nsTextEditRules;
|
|
|
|
friend class nsAutoEditInitRulesTrigger;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //nsPlaintextEditor_h__
|
|
|
|
|