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
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
#ifndef mozilla_TextEditor_h
|
|
|
|
#define mozilla_TextEditor_h
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
#include "mozilla/EditorBase.h"
|
2001-01-28 23:13:07 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#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 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 {
|
2016-07-09 05:54:50 +03:00
|
|
|
|
2016-06-23 13:18:13 +03:00
|
|
|
class AutoEditInitRulesTrigger;
|
2016-07-07 13:05:51 +03:00
|
|
|
class HTMLEditRules;
|
2016-07-09 05:34:41 +03:00
|
|
|
class TextEditRules;
|
2014-11-02 15:04:13 +03:00
|
|
|
namespace dom {
|
|
|
|
class Selection;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2014-11-02 15:04:13 +03:00
|
|
|
|
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
|
|
|
*/
|
2016-07-08 07:10:13 +03:00
|
|
|
class TextEditor : public EditorBase
|
2016-07-09 05:54:50 +03:00
|
|
|
, public nsIPlaintextEditor
|
|
|
|
, public nsIEditorMailSupport
|
2001-01-28 23:13:07 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2016-07-08 07:10:13 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextEditor, EditorBase)
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03: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 */
|
|
|
|
};
|
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
TextEditor();
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2017-03-10 08:05:37 +03:00
|
|
|
virtual TextEditor* AsTextEditor() override { return this; }
|
|
|
|
virtual const TextEditor* AsTextEditor() const override { return this; }
|
2017-03-09 12:38:41 +03:00
|
|
|
virtual HTMLEditor* AsHTMLEditor() override;
|
|
|
|
virtual const HTMLEditor* AsHTMLEditor() const override;
|
2017-03-10 08:05:37 +03:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
// nsIPlaintextEditor methods
|
2001-01-28 23:13:07 +03:00
|
|
|
NS_DECL_NSIPLAINTEXTEDITOR
|
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
// nsIEditorMailSupport overrides
|
2003-07-28 17:13:50 +04:00
|
|
|
NS_DECL_NSIEDITORMAILSUPPORT
|
2001-04-06 03:48:01 +04:00
|
|
|
|
2016-12-20 13:24:08 +03: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 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03: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
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
NS_IMETHOD GetDocumentIsEmpty(bool* aDocumentIsEmpty) 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
|
|
|
|
2016-07-09 05:54:50 +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;
|
2016-07-09 05:54:50 +03:00
|
|
|
NS_IMETHOD CanCut(bool* aCanCut) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Copy() override;
|
2016-07-09 05:54:50 +03:00
|
|
|
NS_IMETHOD CanCopy(bool* aCanCopy) override;
|
|
|
|
NS_IMETHOD CanDelete(bool* aCanDelete) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Paste(int32_t aSelectionType) override;
|
2016-07-09 05:54:50 +03: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 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
|
|
|
|
2016-07-09 05:54:50 +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
|
|
|
|
2016-07-09 05:54:50 +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
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
/**
|
|
|
|
* Make the given selection span the entire document.
|
|
|
|
*/
|
2016-05-01 16:15:14 +03:00
|
|
|
virtual nsresult SelectEntireDocument(Selection* aSelection) override;
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2017-02-08 14:18:17 +03:00
|
|
|
virtual nsresult HandleKeyPressEvent(
|
|
|
|
WidgetKeyboardEvent* aKeyboardEvent) override;
|
2010-06-10 05:16:58 +04:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
virtual already_AddRefed<dom::EventTarget> GetDOMEventTarget() override;
|
2010-06-17 09:30:10 +04:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
virtual nsresult BeginIMEComposition(WidgetCompositionEvent* aEvent) override;
|
2017-01-17 11:01:17 +03:00
|
|
|
virtual nsresult UpdateIMEComposition(
|
|
|
|
WidgetCompositionEvent* aCompositionChangeEvet) 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
|
|
|
|
2016-07-09 05:54:50 +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
|
|
|
|
2016-07-09 05:54:50 +03: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
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
virtual nsresult InsertFromDataTransfer(dom::DataTransfer* aDataTransfer,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndex,
|
2016-07-09 05:54:50 +03: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.
|
|
|
|
*/
|
2016-05-01 16:15:14 +03:00
|
|
|
nsresult ExtendSelectionForDelete(Selection* aSelection,
|
2016-07-09 05:54:50 +03:00
|
|
|
nsIEditor::EDirection* aAction);
|
2008-10-16 11:44:32 +04:00
|
|
|
|
2016-07-09 05:54:50 +03: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 23:35:08 +04:00
|
|
|
bool IsSafeToInsertData(nsIDOMDocument* aSourceDoc);
|
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
static void GetDefaultEditorPrefs(int32_t& aNewLineHandling,
|
|
|
|
int32_t& aCaretStyle);
|
2010-02-01 21:12:31 +03:00
|
|
|
|
2017-06-20 16:57:08 +03:00
|
|
|
int32_t MaxTextLength() const { return mMaxTextLength; }
|
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
protected:
|
2016-07-09 05:54:50 +03:00
|
|
|
virtual ~TextEditor();
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
NS_IMETHOD InitRules();
|
|
|
|
void BeginEditorInit();
|
|
|
|
nsresult EndEditorInit();
|
2005-03-24 22:00:01 +03:00
|
|
|
|
2017-04-17 11:29:46 +03:00
|
|
|
already_AddRefed<nsIDocumentEncoder> GetAndInitDocEncoder(
|
|
|
|
const nsAString& aFormatType,
|
|
|
|
uint32_t aFlags,
|
|
|
|
const nsACString& aCharset);
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
NS_IMETHOD CreateBR(nsIDOMNode* aNode, int32_t aOffset,
|
|
|
|
nsCOMPtr<nsIDOMNode>* outBRNode,
|
|
|
|
EDirection aSelect = eNone);
|
2016-07-12 18:58:13 +03:00
|
|
|
already_AddRefed<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);
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
/**
|
|
|
|
* Factored methods for handling insertion of data from transferables
|
|
|
|
* (drag&drop or clipboard).
|
|
|
|
*/
|
|
|
|
NS_IMETHOD PrepareTransferable(nsITransferable** transferable);
|
2017-02-02 07:55:09 +03:00
|
|
|
nsresult InsertTextFromTransferable(nsITransferable* transferable,
|
|
|
|
nsIDOMNode* aDestinationNode,
|
|
|
|
int32_t aDestOffset,
|
|
|
|
bool aDoDeleteSelection);
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
/**
|
|
|
|
* Shared outputstring; returns whether selection is collapsed and resulting
|
|
|
|
* string.
|
|
|
|
*/
|
|
|
|
nsresult SharedOutputString(uint32_t aFlags, bool* aIsCollapsed,
|
|
|
|
nsAString& aResult);
|
2003-07-28 17:13:50 +04:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
enum PasswordFieldAllowed
|
|
|
|
{
|
2015-01-16 00:47:56 +03:00
|
|
|
ePasswordFieldAllowed,
|
|
|
|
ePasswordFieldNotAllowed
|
|
|
|
};
|
|
|
|
bool CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed);
|
2016-07-09 05:54:50 +03:00
|
|
|
bool FireClipboardEvent(EventMessage aEventMessage,
|
2015-08-26 15:56:59 +03:00
|
|
|
int32_t aSelectionType,
|
|
|
|
bool* aActionTaken = nullptr);
|
2007-07-26 08:14:33 +04:00
|
|
|
|
2017-03-17 10:32:06 +03:00
|
|
|
bool UpdateMetaCharset(nsIDocument& aDocument,
|
2012-02-01 14:54:22 +04:00
|
|
|
const nsACString& aCharacterSet);
|
|
|
|
|
2001-01-28 23:13:07 +03:00
|
|
|
protected:
|
2016-07-09 05:54:50 +03:00
|
|
|
nsCOMPtr<nsIEditRules> mRules;
|
2017-04-17 11:29:46 +03:00
|
|
|
nsCOMPtr<nsIDocumentEncoder> mCachedDocumentEncoder;
|
|
|
|
nsString mCachedDocumentEncoderType;
|
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
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
friend class AutoEditInitRulesTrigger;
|
|
|
|
friend class HTMLEditRules;
|
|
|
|
friend class TextEditRules;
|
2001-01-28 23:13:07 +03:00
|
|
|
};
|
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
} // namespace mozilla
|
2001-01-28 23:13:07 +03:00
|
|
|
|
2016-07-09 05:54:50 +03:00
|
|
|
#endif // #ifndef mozilla_TextEditor_h
|