2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
#ifndef mozilla_TextEditor_h
|
|
|
|
#define mozilla_TextEditor_h
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-08 04:10:13 +00:00
|
|
|
#include "mozilla/EditorBase.h"
|
2001-01-28 20:13:07 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsIEditorMailSupport.h"
|
|
|
|
#include "nsIPlaintextEditor.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nscore.h"
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2012-07-13 06:33:42 +00:00
|
|
|
class nsIContent;
|
|
|
|
class nsIDOMDocument;
|
|
|
|
class nsIDOMElement;
|
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsIDOMNode;
|
2001-01-28 20:13:07 +00:00
|
|
|
class nsIDocumentEncoder;
|
2012-07-13 06:33:42 +00:00
|
|
|
class nsIEditRules;
|
|
|
|
class nsIOutputStream;
|
|
|
|
class nsISelectionController;
|
|
|
|
class nsITransferable;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2014-11-02 12:04:13 +00:00
|
|
|
namespace mozilla {
|
2016-07-09 02:54:50 +00:00
|
|
|
|
2016-06-23 10:18:13 +00:00
|
|
|
class AutoEditInitRulesTrigger;
|
2016-07-07 10:05:51 +00:00
|
|
|
class HTMLEditRules;
|
2016-07-09 02:34:41 +00:00
|
|
|
class TextEditRules;
|
2014-11-02 12:04:13 +00:00
|
|
|
namespace dom {
|
|
|
|
class Selection;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
2014-11-02 12:04:13 +00:00
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
/**
|
|
|
|
* The text editor implementation.
|
2015-05-28 15:58:42 +00:00
|
|
|
* Use to edit text document represented as a DOM tree.
|
2001-01-28 20:13:07 +00:00
|
|
|
*/
|
2016-07-08 04:10:13 +00:00
|
|
|
class TextEditor : public EditorBase
|
2016-07-09 02:54:50 +00:00
|
|
|
, public nsIPlaintextEditor
|
|
|
|
, public nsIEditorMailSupport
|
2001-01-28 20:13:07 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2016-07-08 04:10:13 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextEditor, EditorBase)
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
enum ETypingAction
|
|
|
|
{
|
2001-01-28 20:13:07 +00:00
|
|
|
eTypedText, /* user typed text */
|
|
|
|
eTypedBR, /* user typed shift-enter to get a br */
|
|
|
|
eTypedBreak /* user typed enter */
|
|
|
|
};
|
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
TextEditor();
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
// nsIPlaintextEditor methods
|
2001-01-28 20:13:07 +00:00
|
|
|
NS_DECL_NSIPLAINTEXTEDITOR
|
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
// nsIEditorMailSupport overrides
|
2003-07-28 13:13:50 +00:00
|
|
|
NS_DECL_NSIEDITORMAILSUPPORT
|
2001-04-05 23:48:01 +00:00
|
|
|
|
2016-12-20 10:24:08 +00:00
|
|
|
// Overrides of EditorBase
|
|
|
|
virtual nsresult RemoveAttributeOrEquivalent(
|
|
|
|
Element* aElement,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
bool aSuppressTransaction) override;
|
|
|
|
virtual nsresult SetAttributeOrEquivalent(Element* aElement,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
bool aSuppressTransaction) override;
|
|
|
|
using EditorBase::RemoveAttributeOrEquivalent;
|
|
|
|
using EditorBase::SetAttributeOrEquivalent;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
NS_IMETHOD Init(nsIDOMDocument* aDoc, nsIContent* aRoot,
|
|
|
|
nsISelectionController* aSelCon, uint32_t aFlags,
|
2015-03-21 16:28:04 +00:00
|
|
|
const nsAString& aValue) override;
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
NS_IMETHOD GetDocumentIsEmpty(bool* aDocumentIsEmpty) override;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2012-05-10 14:54:33 +00:00
|
|
|
NS_IMETHOD DeleteSelection(EDirection aAction,
|
2015-03-21 16:28:04 +00:00
|
|
|
EStripWrappers aStripWrappers) override;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
NS_IMETHOD SetDocumentCharacterSet(const nsACString& characterSet) override;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD Undo(uint32_t aCount) override;
|
|
|
|
NS_IMETHOD Redo(uint32_t aCount) override;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD Cut() override;
|
2016-07-09 02:54:50 +00:00
|
|
|
NS_IMETHOD CanCut(bool* aCanCut) override;
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD Copy() override;
|
2016-07-09 02:54:50 +00:00
|
|
|
NS_IMETHOD CanCopy(bool* aCanCopy) override;
|
|
|
|
NS_IMETHOD CanDelete(bool* aCanDelete) override;
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD Paste(int32_t aSelectionType) override;
|
2016-07-09 02:54:50 +00:00
|
|
|
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 20:13:07 +00:00
|
|
|
|
2002-03-25 22:39:19 +00:00
|
|
|
NS_IMETHOD OutputToString(const nsAString& aFormatType,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsAString& aOutputString) override;
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
2002-03-23 22:08:20 +00:00
|
|
|
const nsAString& aFormatType,
|
2003-06-17 16:40:34 +00:00
|
|
|
const nsACString& aCharsetOverride,
|
2015-03-21 16:28:04 +00:00
|
|
|
uint32_t aFlags) override;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
/**
|
|
|
|
* All editor operations which alter the doc should be prefaced
|
|
|
|
* with a call to StartOperation, naming the action and direction.
|
|
|
|
*/
|
2012-08-12 18:28:26 +00:00
|
|
|
NS_IMETHOD StartOperation(EditAction opID,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsIEditor::EDirection aDirection) override;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
/**
|
|
|
|
* All editor operations which alter the doc should be followed
|
|
|
|
* with a call to EndOperation.
|
|
|
|
*/
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD EndOperation() override;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
/**
|
|
|
|
* Make the given selection span the entire document.
|
|
|
|
*/
|
2016-05-01 13:15:14 +00:00
|
|
|
virtual nsresult SelectEntireDocument(Selection* aSelection) override;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2017-02-08 11:18:17 +00:00
|
|
|
virtual nsresult HandleKeyPressEvent(
|
|
|
|
WidgetKeyboardEvent* aKeyboardEvent) override;
|
2010-06-10 01:16:58 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
virtual already_AddRefed<dom::EventTarget> GetDOMEventTarget() override;
|
2010-06-17 05:30:10 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
virtual nsresult BeginIMEComposition(WidgetCompositionEvent* aEvent) override;
|
2017-01-17 08:01:17 +00:00
|
|
|
virtual nsresult UpdateIMEComposition(
|
|
|
|
WidgetCompositionEvent* aCompositionChangeEvet) override;
|
2010-06-30 04:05:12 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual already_AddRefed<nsIContent> GetInputEventTargetContent() override;
|
2012-03-27 01:36:44 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
// Utility Routines, not part of public API
|
2012-05-22 09:37:17 +00:00
|
|
|
NS_IMETHOD TypedText(const nsAString& aString, ETypingAction aAction);
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
nsresult InsertTextAt(const nsAString& aStringToInsert,
|
|
|
|
nsIDOMNode* aDestinationNode,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aDestOffset,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aDoDeleteSelection);
|
2003-04-25 21:05:32 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
virtual nsresult InsertFromDataTransfer(dom::DataTransfer* aDataTransfer,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aIndex,
|
2016-07-09 02:54:50 +00:00
|
|
|
nsIDOMDocument* aSourceDoc,
|
|
|
|
nsIDOMNode* aDestinationNode,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aDestOffset,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aDoDeleteSelection) override;
|
2012-02-17 14:16:59 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent) override;
|
2012-02-17 14:16:59 +00:00
|
|
|
|
2008-10-16 07:44:32 +00:00
|
|
|
/**
|
|
|
|
* Extends the selection for given deletion operation
|
|
|
|
* If done, also update aAction to what's actually left to do after the
|
|
|
|
* extension.
|
|
|
|
*/
|
2016-05-01 13:15:14 +00:00
|
|
|
nsresult ExtendSelectionForDelete(Selection* aSelection,
|
2016-07-09 02:54:50 +00:00
|
|
|
nsIEditor::EDirection* aAction);
|
2008-10-16 07:44:32 +00:00
|
|
|
|
2016-07-09 02:54:50 +00: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.
|
|
|
|
*/
|
2012-08-15 19:35:08 +00:00
|
|
|
bool IsSafeToInsertData(nsIDOMDocument* aSourceDoc);
|
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
static void GetDefaultEditorPrefs(int32_t& aNewLineHandling,
|
|
|
|
int32_t& aCaretStyle);
|
2010-02-01 18:12:31 +00:00
|
|
|
|
2017-06-20 13:57:08 +00:00
|
|
|
int32_t MaxTextLength() const { return mMaxTextLength; }
|
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
protected:
|
2016-07-09 02:54:50 +00:00
|
|
|
virtual ~TextEditor();
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
NS_IMETHOD InitRules();
|
|
|
|
void BeginEditorInit();
|
|
|
|
nsresult EndEditorInit();
|
2005-03-24 19:00:01 +00:00
|
|
|
|
2017-04-17 08:29:46 +00:00
|
|
|
already_AddRefed<nsIDocumentEncoder> GetAndInitDocEncoder(
|
|
|
|
const nsAString& aFormatType,
|
|
|
|
uint32_t aFlags,
|
|
|
|
const nsACString& aCharset);
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
NS_IMETHOD CreateBR(nsIDOMNode* aNode, int32_t aOffset,
|
|
|
|
nsCOMPtr<nsIDOMNode>* outBRNode,
|
|
|
|
EDirection aSelect = eNone);
|
2016-07-12 15:58:13 +00:00
|
|
|
already_AddRefed<Element> CreateBRImpl(nsCOMPtr<nsINode>* aInOutParent,
|
|
|
|
int32_t* aInOutOffset,
|
|
|
|
EDirection aSelect);
|
2012-02-01 10:54:21 +00:00
|
|
|
nsresult CreateBRImpl(nsCOMPtr<nsIDOMNode>* aInOutParent,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t* aInOutOffset,
|
2012-02-01 10:54:21 +00:00
|
|
|
nsCOMPtr<nsIDOMNode>* outBRNode,
|
|
|
|
EDirection aSelect);
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
/**
|
|
|
|
* Factored methods for handling insertion of data from transferables
|
|
|
|
* (drag&drop or clipboard).
|
|
|
|
*/
|
|
|
|
NS_IMETHOD PrepareTransferable(nsITransferable** transferable);
|
2017-02-02 04:55:09 +00:00
|
|
|
nsresult InsertTextFromTransferable(nsITransferable* transferable,
|
|
|
|
nsIDOMNode* aDestinationNode,
|
|
|
|
int32_t aDestOffset,
|
|
|
|
bool aDoDeleteSelection);
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
/**
|
|
|
|
* Shared outputstring; returns whether selection is collapsed and resulting
|
|
|
|
* string.
|
|
|
|
*/
|
|
|
|
nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed,
|
|
|
|
nsAString& aResult);
|
2003-07-28 13:13:50 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
enum PasswordFieldAllowed
|
|
|
|
{
|
2015-01-15 21:47:56 +00:00
|
|
|
ePasswordFieldAllowed,
|
|
|
|
ePasswordFieldNotAllowed
|
|
|
|
};
|
|
|
|
bool CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed);
|
2016-07-09 02:54:50 +00:00
|
|
|
bool FireClipboardEvent(EventMessage aEventMessage,
|
2015-08-26 12:56:59 +00:00
|
|
|
int32_t aSelectionType,
|
|
|
|
bool* aActionTaken = nullptr);
|
2007-07-26 04:14:33 +00:00
|
|
|
|
2017-03-17 07:32:06 +00:00
|
|
|
bool UpdateMetaCharset(nsIDocument& aDocument,
|
2012-02-01 10:54:22 +00:00
|
|
|
const nsACString& aCharacterSet);
|
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
protected:
|
2016-07-09 02:54:50 +00:00
|
|
|
nsCOMPtr<nsIEditRules> mRules;
|
2017-04-17 08:29:46 +00:00
|
|
|
nsCOMPtr<nsIDocumentEncoder> mCachedDocumentEncoder;
|
|
|
|
nsString mCachedDocumentEncoderType;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mWrapColumn;
|
|
|
|
int32_t mMaxTextLength;
|
|
|
|
int32_t mInitTriggerCounter;
|
|
|
|
int32_t mNewlineHandling;
|
|
|
|
int32_t mCaretStyle;
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
friend class AutoEditInitRulesTrigger;
|
|
|
|
friend class HTMLEditRules;
|
|
|
|
friend class TextEditRules;
|
2001-01-28 20:13:07 +00:00
|
|
|
};
|
|
|
|
|
2017-08-03 21:18:50 +00:00
|
|
|
TextEditor*
|
|
|
|
EditorBase::AsTextEditor()
|
|
|
|
{
|
|
|
|
return static_cast<TextEditor*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const TextEditor*
|
|
|
|
EditorBase::AsTextEditor() const
|
|
|
|
{
|
|
|
|
return static_cast<const TextEditor*>(this);
|
|
|
|
}
|
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
} // namespace mozilla
|
2001-01-28 20:13:07 +00:00
|
|
|
|
2016-07-09 02:54:50 +00:00
|
|
|
#endif // #ifndef mozilla_TextEditor_h
|