2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
#ifndef nsPlaintextEditor_h__
|
|
|
|
#define nsPlaintextEditor_h__
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2001-01-28 23:13:07 +03:00
|
|
|
#include "nsEditor.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsIEditorMailSupport.h"
|
|
|
|
#include "nsIPlaintextEditor.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nscore.h"
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsIContent;
|
|
|
|
class nsIDOMDocument;
|
|
|
|
class nsIDOMElement;
|
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsIDOMKeyEvent;
|
|
|
|
class nsIDOMNode;
|
2001-01-28 23:13:07 +03:00
|
|
|
class nsIDocumentEncoder;
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsIEditRules;
|
|
|
|
class nsIOutputStream;
|
|
|
|
class nsISelectionController;
|
|
|
|
class nsITransferable;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2014-11-02 15:04:13 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Selection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
/**
|
|
|
|
* The text editor implementation.
|
2015-05-28 18:58:42 +03:00
|
|
|
* Use to edit text document represented as a DOM tree.
|
2001-01-28 23:13:07 +03:00
|
|
|
*/
|
|
|
|
class nsPlaintextEditor : public nsEditor,
|
2001-04-06 03:48:01 +04:00
|
|
|
public nsIPlaintextEditor,
|
|
|
|
public nsIEditorMailSupport
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Interfaces for addref and release and queryinterface
|
2015-05-28 18:58:42 +03:00
|
|
|
// NOTE macro used is for classes that inherit from
|
2001-01-28 23:13:07 +03:00
|
|
|
// another class. Only the base class should use NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2009-05-09 08:59:25 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsPlaintextEditor, nsEditor)
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
/* below used by TypedText() */
|
2012-05-22 13:37:17 +04:00
|
|
|
enum ETypingAction {
|
2001-01-28 23:13:07 +03:00
|
|
|
eTypedText, /* user typed text */
|
|
|
|
eTypedBR, /* user typed shift-enter to get a br */
|
|
|
|
eTypedBreak /* user typed enter */
|
|
|
|
};
|
|
|
|
|
2014-07-09 01:23:18 +04:00
|
|
|
nsPlaintextEditor();
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
/* ------------ nsIPlaintextEditor methods -------------- */
|
|
|
|
NS_DECL_NSIPLAINTEXTEDITOR
|
|
|
|
|
2001-04-06 03:48:01 +04:00
|
|
|
/* ------------ nsIEditorMailSupport overrides -------------- */
|
2003-07-28 17:13:50 +04:00
|
|
|
NS_DECL_NSIEDITORMAILSUPPORT
|
2001-04-06 03:48:01 +04:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
/* ------------ Overrides of nsEditor interface methods -------------- */
|
2002-01-25 13:16:52 +03:00
|
|
|
NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement * aElement,
|
2002-03-24 01:08:20 +03:00
|
|
|
const nsAString & aAttribute,
|
2002-09-17 16:04:59 +04:00
|
|
|
const nsAString & aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aSuppressTransaction) override;
|
2002-03-15 18:33:29 +03:00
|
|
|
NS_IMETHOD RemoveAttributeOrEquivalent(nsIDOMElement * aElement,
|
2002-09-17 16:04:59 +04:00
|
|
|
const nsAString & aAttribute,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aSuppressTransaction) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
/** prepare the editor for use */
|
2014-04-14 16:33:47 +04:00
|
|
|
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIContent *aRoot,
|
|
|
|
nsISelectionController *aSelCon, uint32_t aFlags,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsAString& aValue) override;
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD GetDocumentIsEmpty(bool *aDocumentIsEmpty) override;
|
|
|
|
NS_IMETHOD GetIsDocumentEditable(bool *aIsDocumentEditable) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2012-05-10 18:54:33 +04:00
|
|
|
NS_IMETHOD DeleteSelection(EDirection aAction,
|
2015-03-21 19:28:04 +03:00
|
|
|
EStripWrappers aStripWrappers) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD SetDocumentCharacterSet(const nsACString & characterSet) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Undo(uint32_t aCount) override;
|
|
|
|
NS_IMETHOD Redo(uint32_t aCount) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Cut() override;
|
|
|
|
NS_IMETHOD CanCut(bool *aCanCut) override;
|
|
|
|
NS_IMETHOD Copy() override;
|
|
|
|
NS_IMETHOD CanCopy(bool *aCanCopy) override;
|
|
|
|
NS_IMETHOD CanDelete(bool *aCanDelete) override;
|
|
|
|
NS_IMETHOD Paste(int32_t aSelectionType) override;
|
|
|
|
NS_IMETHOD CanPaste(int32_t aSelectionType, bool *aCanPaste) override;
|
|
|
|
NS_IMETHOD PasteTransferable(nsITransferable *aTransferable) override;
|
|
|
|
NS_IMETHOD CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2002-03-26 01:39:19 +03:00
|
|
|
NS_IMETHOD OutputToString(const nsAString& aFormatType,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAString& aOutputString) override;
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
2002-03-24 01:08:20 +03:00
|
|
|
const nsAString& aFormatType,
|
2003-06-17 20:40:34 +04:00
|
|
|
const nsACString& aCharsetOverride,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aFlags) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
/** All editor operations which alter the doc should be prefaced
|
|
|
|
* with a call to StartOperation, naming the action and direction */
|
2012-08-12 22:28:26 +04:00
|
|
|
NS_IMETHOD StartOperation(EditAction opID,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIEditor::EDirection aDirection) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
/** All editor operations which alter the doc should be followed
|
|
|
|
* with a call to EndOperation */
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD EndOperation() override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
/** make the given selection span the entire document */
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult SelectEntireDocument(mozilla::dom::Selection* aSelection) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent) override;
|
2010-06-10 05:16:58 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget() override;
|
2010-06-17 09:30:10 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult BeginIMEComposition(mozilla::WidgetCompositionEvent* aEvent) override;
|
|
|
|
virtual nsresult UpdateIMEComposition(nsIDOMEvent* aTextEvent) override;
|
2010-06-30 08:05:12 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual already_AddRefed<nsIContent> GetInputEventTargetContent() override;
|
2012-03-27 05:36:44 +04:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
/* ------------ Utility Routines, not part of public API -------------- */
|
2012-05-22 13:37:17 +04:00
|
|
|
NS_IMETHOD TypedText(const nsAString& aString, ETypingAction aAction);
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2003-04-26 01:05:32 +04:00
|
|
|
nsresult InsertTextAt(const nsAString &aStringToInsert,
|
|
|
|
nsIDOMNode *aDestinationNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aDestOffset,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDoDeleteSelection);
|
2003-04-26 01:05:32 +04:00
|
|
|
|
2013-07-09 21:54:21 +04:00
|
|
|
virtual nsresult InsertFromDataTransfer(mozilla::dom::DataTransfer *aDataTransfer,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndex,
|
2012-02-17 18:16:59 +04:00
|
|
|
nsIDOMDocument *aSourceDoc,
|
|
|
|
nsIDOMNode *aDestinationNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aDestOffset,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aDoDeleteSelection) override;
|
2012-02-17 18:16:59 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent) override;
|
2012-02-17 18:16:59 +04:00
|
|
|
|
2008-10-16 11:44:32 +04:00
|
|
|
/**
|
|
|
|
* Extends the selection for given deletion operation
|
|
|
|
* If done, also update aAction to what's actually left to do after the
|
|
|
|
* extension.
|
|
|
|
*/
|
2014-11-02 15:04:13 +03:00
|
|
|
nsresult ExtendSelectionForDelete(mozilla::dom::Selection* aSelection,
|
2008-10-16 11:44:32 +04:00
|
|
|
nsIEditor::EDirection *aAction);
|
|
|
|
|
2012-08-15 23:35:08 +04: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 19:56:38 +04:00
|
|
|
static void GetDefaultEditorPrefs(int32_t &aNewLineHandling,
|
|
|
|
int32_t &aCaretStyle);
|
2010-02-01 21:12:31 +03:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
protected:
|
2014-07-09 01:23:18 +04:00
|
|
|
virtual ~nsPlaintextEditor();
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
NS_IMETHOD InitRules();
|
|
|
|
void BeginEditorInit();
|
|
|
|
nsresult EndEditorInit();
|
2005-03-24 22:00:01 +03:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
// Helpers for output routines
|
2002-03-24 01:08:20 +03:00
|
|
|
NS_IMETHOD GetAndInitDocEncoder(const nsAString& aFormatType,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags,
|
2003-06-17 20:40:34 +04:00
|
|
|
const nsACString& aCharset,
|
2001-01-28 23:13:07 +03:00
|
|
|
nsIDocumentEncoder** encoder);
|
|
|
|
|
|
|
|
// key event helpers
|
2015-05-28 18:58:42 +03:00
|
|
|
NS_IMETHOD CreateBR(nsIDOMNode *aNode, int32_t aOffset,
|
2001-01-28 23:13:07 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect = eNone);
|
2014-05-02 15:11:26 +04:00
|
|
|
already_AddRefed<mozilla::dom::Element>
|
|
|
|
CreateBRImpl(nsCOMPtr<nsINode>* aInOutParent, int32_t* aInOutOffset,
|
|
|
|
EDirection aSelect);
|
2012-02-01 14:54:21 +04:00
|
|
|
nsresult CreateBRImpl(nsCOMPtr<nsIDOMNode>* aInOutParent,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* aInOutOffset,
|
2012-02-01 14:54:21 +04:00
|
|
|
nsCOMPtr<nsIDOMNode>* outBRNode,
|
|
|
|
EDirection aSelect);
|
2012-02-01 14:54:21 +04:00
|
|
|
nsresult InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode);
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
// factored methods for handling insertion of data from transferables (drag&drop or clipboard)
|
|
|
|
NS_IMETHOD PrepareTransferable(nsITransferable **transferable);
|
2003-04-26 01:05:32 +04:00
|
|
|
NS_IMETHOD InsertTextFromTransferable(nsITransferable *transferable,
|
|
|
|
nsIDOMNode *aDestinationNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aDestOffset,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDoDeleteSelection);
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2003-07-28 17:13:50 +04:00
|
|
|
/** shared outputstring; returns whether selection is collapsed and resulting string */
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed, nsAString& aResult);
|
2003-07-28 17:13:50 +04:00
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
/* small utility routine to test the eEditorReadonly bit */
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsModifiable();
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2015-01-16 00:47:56 +03:00
|
|
|
enum PasswordFieldAllowed {
|
|
|
|
ePasswordFieldAllowed,
|
|
|
|
ePasswordFieldNotAllowed
|
|
|
|
};
|
|
|
|
bool CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed);
|
2015-05-13 09:51:00 +03:00
|
|
|
bool FireClipboardEvent(int32_t aType, int32_t aSelectionType, bool* aActionTaken = nullptr);
|
2007-07-26 08:14:33 +04:00
|
|
|
|
2012-02-01 14:54:22 +04:00
|
|
|
bool UpdateMetaCharset(nsIDOMDocument* aDocument,
|
|
|
|
const nsACString& aCharacterSet);
|
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
// Data members
|
|
|
|
protected:
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEditRules> mRules;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mWrapToWindow;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mWrapColumn;
|
|
|
|
int32_t mMaxTextLength;
|
|
|
|
int32_t mInitTriggerCounter;
|
|
|
|
int32_t mNewlineHandling;
|
|
|
|
int32_t mCaretStyle;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
|
|
|
// friends
|
|
|
|
friend class nsHTMLEditRules;
|
|
|
|
friend class nsTextEditRules;
|
|
|
|
friend class nsAutoEditInitRulesTrigger;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //nsPlaintextEditor_h__
|
|
|
|
|