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/. */
|
1999-02-12 20:18:58 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
#ifndef mozilla_EditorBase_h
|
|
|
|
#define mozilla_EditorBase_h
|
1999-02-12 20:18:58 +03:00
|
|
|
|
2013-01-29 04:33:17 +04:00
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc.
|
2017-01-27 02:24:00 +03:00
|
|
|
#include "mozilla/FlushType.h" // for FlushType enum
|
2015-08-05 15:28:27 +03:00
|
|
|
#include "mozilla/OwningNonNull.h" // for OwningNonNull
|
2016-07-08 08:15:21 +03:00
|
|
|
#include "mozilla/SelectionState.h" // for RangeUpdater, etc.
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheet.h" // for StyleSheet
|
2014-05-02 16:15:27 +04:00
|
|
|
#include "mozilla/dom/Text.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
|
2009-05-09 08:59:25 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-08-29 15:43:24 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2016-07-08 08:15:21 +03:00
|
|
|
#include "nsIEditor.h" // for nsIEditor::EDirection, etc.
|
|
|
|
#include "nsIEditorIMESupport.h" // for NS_DECL_NSIEDITORIMESUPPORT, etc.
|
|
|
|
#include "nsIObserver.h" // for NS_DECL_NSIOBSERVER, etc.
|
|
|
|
#include "nsIPhonetic.h" // for NS_DECL_NSIPHONETIC, etc.
|
|
|
|
#include "nsIPlaintextEditor.h" // for nsIPlaintextEditor, etc.
|
2015-03-08 01:14:07 +03:00
|
|
|
#include "nsISelectionController.h" // for nsISelectionController constants
|
2016-07-08 08:15:21 +03:00
|
|
|
#include "nsISupportsImpl.h" // for EditorBase::Release, etc.
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIWeakReferenceUtils.h" // for nsWeakPtr
|
|
|
|
#include "nsLiteralString.h" // for NS_LITERAL_STRING
|
|
|
|
#include "nsString.h" // for nsCString
|
|
|
|
#include "nsWeakReference.h" // for nsSupportsWeakReference
|
2016-07-08 08:15:21 +03:00
|
|
|
#include "nscore.h" // for nsresult, nsAString, etc.
|
1999-02-12 20:18:58 +03:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsIAtom;
|
|
|
|
class nsIContent;
|
|
|
|
class nsIDOMDocument;
|
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsIDOMEventListener;
|
|
|
|
class nsIDOMEventTarget;
|
|
|
|
class nsIDOMKeyEvent;
|
|
|
|
class nsIDOMNode;
|
|
|
|
class nsIDocument;
|
|
|
|
class nsIDocumentStateListener;
|
|
|
|
class nsIEditActionListener;
|
2012-11-14 23:23:35 +04:00
|
|
|
class nsIEditorObserver;
|
2012-07-13 10:33:42 +04:00
|
|
|
class nsIInlineSpellChecker;
|
|
|
|
class nsINode;
|
|
|
|
class nsIPresShell;
|
|
|
|
class nsISupports;
|
|
|
|
class nsITransaction;
|
|
|
|
class nsIWidget;
|
|
|
|
class nsRange;
|
|
|
|
class nsString;
|
|
|
|
class nsTransactionManager;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
// This is int32_t instead of int16_t because nsIInlineSpellChecker.idl's
|
2012-08-01 16:22:07 +04:00
|
|
|
// spellCheckAfterEditorChange is defined to take it as a long.
|
2016-07-08 07:10:13 +03:00
|
|
|
// XXX EditAction causes unnecessary include of EditorBase from some places.
|
|
|
|
// Why don't you move this to nsIEditor.idl?
|
|
|
|
enum class EditAction : int32_t
|
|
|
|
{
|
2012-08-01 16:22:07 +04:00
|
|
|
ignore = -1,
|
|
|
|
none = 0,
|
|
|
|
undo,
|
|
|
|
redo,
|
|
|
|
insertNode,
|
|
|
|
createNode,
|
|
|
|
deleteNode,
|
|
|
|
splitNode,
|
|
|
|
joinNode,
|
|
|
|
deleteText = 1003,
|
|
|
|
|
|
|
|
// text commands
|
|
|
|
insertText = 2000,
|
|
|
|
insertIMEText = 2001,
|
|
|
|
deleteSelection = 2002,
|
|
|
|
setTextProperty = 2003,
|
|
|
|
removeTextProperty = 2004,
|
|
|
|
outputText = 2005,
|
|
|
|
|
|
|
|
// html only action
|
|
|
|
insertBreak = 3000,
|
|
|
|
makeList = 3001,
|
|
|
|
indent = 3002,
|
|
|
|
outdent = 3003,
|
|
|
|
align = 3004,
|
|
|
|
makeBasicBlock = 3005,
|
|
|
|
removeList = 3006,
|
|
|
|
makeDefListItem = 3007,
|
|
|
|
insertElement = 3008,
|
|
|
|
insertQuotation = 3009,
|
|
|
|
htmlPaste = 3012,
|
|
|
|
loadHTML = 3013,
|
|
|
|
resetTextProperties = 3014,
|
|
|
|
setAbsolutePosition = 3015,
|
|
|
|
removeAbsolutePosition = 3016,
|
|
|
|
decreaseZIndex = 3017,
|
|
|
|
increaseZIndex = 3018
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2012-08-01 16:22:07 +04:00
|
|
|
|
2012-08-12 22:28:26 +04:00
|
|
|
inline bool operator!(const EditAction& aOp)
|
2012-08-01 16:22:07 +04:00
|
|
|
{
|
2012-08-12 22:28:26 +04:00
|
|
|
return aOp == EditAction::none;
|
2012-08-01 16:22:07 +04:00
|
|
|
}
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class AddStyleSheetTransaction;
|
|
|
|
class AutoRules;
|
|
|
|
class AutoSelectionRestorer;
|
|
|
|
class AutoTransactionsConserveSelection;
|
|
|
|
class ChangeAttributeTransaction;
|
|
|
|
class CompositionTransaction;
|
|
|
|
class CreateElementTransaction;
|
|
|
|
class DeleteNodeTransaction;
|
|
|
|
class DeleteTextTransaction;
|
|
|
|
class EditAggregateTransaction;
|
|
|
|
class ErrorResult;
|
|
|
|
class InsertNodeTransaction;
|
|
|
|
class InsertTextTransaction;
|
|
|
|
class JoinNodeTransaction;
|
|
|
|
class RemoveStyleSheetTransaction;
|
|
|
|
class SplitNodeTransaction;
|
|
|
|
class TextComposition;
|
|
|
|
struct EditorDOMPoint;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class DataTransfer;
|
|
|
|
class Element;
|
|
|
|
class EventTarget;
|
|
|
|
class Selection;
|
|
|
|
class Text;
|
|
|
|
} // namespace dom
|
|
|
|
|
|
|
|
namespace widget {
|
|
|
|
struct IMEState;
|
|
|
|
} // namespace widget
|
|
|
|
|
|
|
|
#define kMOZEditorBogusNodeAttrAtom nsGkAtoms::mozeditorbogusnode
|
|
|
|
#define kMOZEditorBogusNodeValue NS_LITERAL_STRING("TRUE")
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of an editor object. it will be the controller/focal point
|
|
|
|
* for the main editor services. i.e. the GUIManager, publishing, transaction
|
|
|
|
* manager, event interfaces. the idea for the event interfaces is to have them
|
|
|
|
* delegate the actual commands to the editor independent of the XPFE
|
|
|
|
* implementation.
|
1999-02-12 20:18:58 +03:00
|
|
|
*/
|
2016-12-20 15:47:31 +03:00
|
|
|
class EditorBase : public nsIEditorIMESupport
|
2016-07-08 07:10:13 +03:00
|
|
|
, public nsSupportsWeakReference
|
|
|
|
, public nsIPhonetic
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-07-08 07:10:13 +03:00
|
|
|
typedef dom::Element Element;
|
|
|
|
typedef dom::Selection Selection;
|
|
|
|
typedef dom::Text Text;
|
1999-05-05 08:05:19 +04:00
|
|
|
|
1999-05-17 16:22:31 +04:00
|
|
|
enum IterDirection
|
|
|
|
{
|
|
|
|
kIterForward,
|
|
|
|
kIterBackward
|
|
|
|
};
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* The default constructor. This should suffice. the setting of the
|
|
|
|
* interfaces is done after the construction of the editor class.
|
1999-02-12 20:18:58 +03:00
|
|
|
*/
|
2016-07-08 07:10:13 +03:00
|
|
|
EditorBase();
|
2014-06-24 02:40:02 +04:00
|
|
|
|
|
|
|
protected:
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* The default destructor. This should suffice. Should this be pure virtual
|
|
|
|
* for someone to derive from the EditorBase later? I don't believe so.
|
1999-02-12 20:18:58 +03:00
|
|
|
*/
|
2016-07-08 07:10:13 +03:00
|
|
|
virtual ~EditorBase();
|
2005-06-16 17:10:58 +04:00
|
|
|
|
2014-06-24 02:40:02 +04:00
|
|
|
public:
|
2009-05-09 08:59:25 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2016-07-08 07:10:13 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(EditorBase, nsIEditor)
|
1999-02-12 20:18:58 +03:00
|
|
|
|
2012-03-24 12:19:14 +04:00
|
|
|
already_AddRefed<nsIDOMDocument> GetDOMDocument();
|
|
|
|
already_AddRefed<nsIDocument> GetDocument();
|
2011-05-22 16:43:13 +04:00
|
|
|
already_AddRefed<nsIPresShell> GetPresShell();
|
2014-04-10 11:11:37 +04:00
|
|
|
already_AddRefed<nsIWidget> GetWidget();
|
2014-07-31 08:37:59 +04:00
|
|
|
enum NotificationForEditorObservers
|
|
|
|
{
|
|
|
|
eNotifyEditorObserversOfEnd,
|
|
|
|
eNotifyEditorObserversOfBefore,
|
|
|
|
eNotifyEditorObserversOfCancel
|
|
|
|
};
|
|
|
|
void NotifyEditorObservers(NotificationForEditorObservers aNotification);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
// nsIEditor methods
|
2001-04-07 04:45:26 +04:00
|
|
|
NS_DECL_NSIEDITOR
|
2013-01-10 03:05:08 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
// nsIEditorIMESupport methods
|
2004-09-12 09:00:57 +04:00
|
|
|
NS_DECL_NSIEDITORIMESUPPORT
|
2013-01-10 03:05:08 +04:00
|
|
|
|
2002-12-18 02:38:04 +03:00
|
|
|
// nsIPhonetic
|
|
|
|
NS_DECL_NSIPHONETIC
|
|
|
|
|
1999-08-09 05:37:50 +04:00
|
|
|
public:
|
2016-07-08 07:10:13 +03:00
|
|
|
virtual bool IsModifiableNode(nsINode* aNode);
|
2013-01-10 03:05:08 +04:00
|
|
|
|
2014-11-02 15:04:13 +03:00
|
|
|
virtual nsresult InsertTextImpl(const nsAString& aStringToInsert,
|
|
|
|
nsCOMPtr<nsINode>* aInOutNode,
|
|
|
|
int32_t* aInOutOffset,
|
|
|
|
nsIDocument* aDoc);
|
2014-05-02 15:11:26 +04:00
|
|
|
nsresult InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
|
2016-05-01 16:15:14 +03:00
|
|
|
Text& aTextNode, int32_t aOffset,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aSuppressIME = false);
|
2012-05-10 18:54:33 +04:00
|
|
|
NS_IMETHOD DeleteSelectionImpl(EDirection aAction,
|
|
|
|
EStripWrappers aStripWrappers);
|
2014-11-02 15:04:13 +03:00
|
|
|
|
2016-05-01 16:15:14 +03:00
|
|
|
already_AddRefed<Element> DeleteSelectionAndCreateElement(nsIAtom& aTag);
|
1999-08-09 05:37:50 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Helper routines for node/parent manipulations.
|
|
|
|
*/
|
2012-06-19 17:23:36 +04:00
|
|
|
nsresult DeleteNode(nsINode* aNode);
|
2014-08-20 16:25:17 +04:00
|
|
|
nsresult InsertNode(nsIContent& aNode, nsINode& aParent, int32_t aPosition);
|
2014-08-13 15:53:33 +04:00
|
|
|
enum ECloneAttributes { eDontCloneAttributes, eCloneAttributes };
|
2016-05-01 16:15:14 +03:00
|
|
|
already_AddRefed<Element> ReplaceContainer(Element* aOldContainer,
|
|
|
|
nsIAtom* aNodeType,
|
|
|
|
nsIAtom* aAttribute = nullptr,
|
|
|
|
const nsAString* aValue = nullptr,
|
|
|
|
ECloneAttributes aCloneAttributes
|
|
|
|
= eDontCloneAttributes);
|
|
|
|
void CloneAttributes(Element* aDest, Element* aSource);
|
2000-06-22 09:39:54 +04:00
|
|
|
|
2014-08-20 16:25:16 +04:00
|
|
|
nsresult RemoveContainer(nsIContent* aNode);
|
2016-05-01 16:15:14 +03:00
|
|
|
already_AddRefed<Element> InsertContainerAbove(nsIContent* aNode,
|
|
|
|
nsIAtom* aNodeType,
|
|
|
|
nsIAtom* aAttribute = nullptr,
|
|
|
|
const nsAString* aValue =
|
|
|
|
nullptr);
|
2014-11-02 15:04:13 +03:00
|
|
|
nsIContent* SplitNode(nsIContent& aNode, int32_t aOffset,
|
2016-05-01 16:15:14 +03:00
|
|
|
ErrorResult& aResult);
|
2014-11-02 15:04:12 +03:00
|
|
|
nsresult JoinNodes(nsINode& aLeftNode, nsINode& aRightNode);
|
2014-08-20 16:25:16 +04:00
|
|
|
nsresult MoveNode(nsIContent* aNode, nsINode* aParent, int32_t aOffset);
|
1999-02-12 20:18:58 +03:00
|
|
|
|
2016-12-20 13:24:08 +03:00
|
|
|
nsresult CloneAttribute(nsIAtom* aAttribute, Element* aDestElement,
|
|
|
|
Element* aSourceElement);
|
|
|
|
nsresult RemoveAttribute(Element* aElement, nsIAtom* aAttribute);
|
|
|
|
virtual nsresult RemoveAttributeOrEquivalent(Element* aElement,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
bool aSuppressTransaction) = 0;
|
|
|
|
nsresult SetAttribute(Element* aElement, nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue);
|
|
|
|
virtual nsresult SetAttributeOrEquivalent(Element* aElement,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
bool aSuppressTransaction) = 0;
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Method to replace certain CreateElementNS() calls.
|
|
|
|
*
|
|
|
|
* @param aTag Tag you want.
|
|
|
|
*/
|
2016-05-01 16:15:14 +03:00
|
|
|
already_AddRefed<Element> CreateHTMLContent(nsIAtom* aTag);
|
2000-07-14 03:15:41 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* IME event handlers.
|
|
|
|
*/
|
|
|
|
virtual nsresult BeginIMEComposition(WidgetCompositionEvent* aEvent);
|
2017-01-17 11:01:17 +03:00
|
|
|
virtual nsresult UpdateIMEComposition(
|
|
|
|
WidgetCompositionEvent* aCompositionChangeEvet) = 0;
|
2012-06-19 17:23:36 +04:00
|
|
|
void EndIMEComposition();
|
2010-06-30 08:05:12 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void SwitchTextDirectionTo(uint32_t aDirection);
|
2011-09-15 18:54:50 +04:00
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
protected:
|
2011-09-15 18:54:50 +04:00
|
|
|
nsresult DetermineCurrentDirection();
|
2014-01-17 19:31:18 +04:00
|
|
|
void FireInputEvent();
|
2011-09-15 18:54:50 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Create a transaction for setting aAttribute to aValue on aElement. Never
|
|
|
|
* returns null.
|
|
|
|
*/
|
|
|
|
already_AddRefed<ChangeAttributeTransaction>
|
|
|
|
CreateTxnForSetAttribute(Element& aElement, nsIAtom& aAttribute,
|
|
|
|
const nsAString& aValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a transaction for removing aAttribute on aElement. Never returns
|
|
|
|
* null.
|
|
|
|
*/
|
|
|
|
already_AddRefed<ChangeAttributeTransaction>
|
|
|
|
CreateTxnForRemoveAttribute(Element& aElement, nsIAtom& aAttribute);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a transaction for creating a new child node of aParent of type aTag.
|
|
|
|
*/
|
|
|
|
already_AddRefed<CreateElementTransaction>
|
|
|
|
CreateTxnForCreateElement(nsIAtom& aTag,
|
|
|
|
nsINode& aParent,
|
|
|
|
int32_t aPosition);
|
2014-08-20 16:25:16 +04:00
|
|
|
|
2016-05-01 16:15:14 +03:00
|
|
|
already_AddRefed<Element> CreateNode(nsIAtom* aTag, nsINode* aParent,
|
|
|
|
int32_t aPosition);
|
1999-02-12 20:18:58 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Create a transaction for inserting aNode as a child of aParent.
|
|
|
|
*/
|
|
|
|
already_AddRefed<InsertNodeTransaction>
|
|
|
|
CreateTxnForInsertNode(nsIContent& aNode, nsINode& aParent,
|
|
|
|
int32_t aOffset);
|
1999-02-12 20:18:58 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Create a transaction for removing aNode from its parent.
|
|
|
|
*/
|
|
|
|
nsresult CreateTxnForDeleteNode(nsINode* aNode,
|
|
|
|
DeleteNodeTransaction** aTransaction);
|
1999-08-09 05:37:50 +04:00
|
|
|
|
2016-07-07 11:11:30 +03:00
|
|
|
nsresult CreateTxnForDeleteSelection(
|
|
|
|
EDirection aAction,
|
2016-07-08 07:10:13 +03:00
|
|
|
EditAggregateTransaction** aTransaction,
|
2016-07-07 11:11:30 +03:00
|
|
|
nsINode** aNode,
|
|
|
|
int32_t* aOffset,
|
|
|
|
int32_t* aLength);
|
|
|
|
|
|
|
|
nsresult CreateTxnForDeleteInsertionPoint(
|
|
|
|
nsRange* aRange,
|
|
|
|
EDirection aAction,
|
2016-07-08 07:10:13 +03:00
|
|
|
EditAggregateTransaction* aTransaction,
|
2016-07-07 11:11:30 +03:00
|
|
|
nsINode** aNode,
|
|
|
|
int32_t* aOffset,
|
|
|
|
int32_t* aLength);
|
1999-08-09 05:37:50 +04:00
|
|
|
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Create a transaction for inserting aStringToInsert into aTextNode. Never
|
|
|
|
* returns null.
|
|
|
|
*/
|
2016-07-07 10:06:41 +03:00
|
|
|
already_AddRefed<mozilla::InsertTextTransaction>
|
2016-07-08 07:10:13 +03:00
|
|
|
CreateTxnForInsertText(const nsAString& aStringToInsert, Text& aTextNode,
|
|
|
|
int32_t aOffset);
|
1999-02-12 20:18:58 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Never returns null.
|
|
|
|
*/
|
2016-07-07 09:42:08 +03:00
|
|
|
already_AddRefed<mozilla::CompositionTransaction>
|
2016-07-08 07:10:13 +03:00
|
|
|
CreateTxnForComposition(const nsAString& aStringToInsert);
|
1999-06-30 00:31:22 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Create a transaction for adding a style sheet.
|
|
|
|
*/
|
2017-01-27 07:29:00 +03:00
|
|
|
already_AddRefed<mozilla::AddStyleSheetTransaction>
|
|
|
|
CreateTxnForAddStyleSheet(StyleSheet* aSheet);
|
1999-07-02 07:57:50 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Create a transaction for removing a style sheet.
|
|
|
|
*/
|
2017-01-27 07:29:00 +03:00
|
|
|
already_AddRefed<mozilla::RemoveStyleSheetTransaction>
|
|
|
|
CreateTxnForRemoveStyleSheet(StyleSheet* aSheet);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2014-08-20 16:25:16 +04:00
|
|
|
nsresult DeleteText(nsGenericDOMDataNode& aElement,
|
|
|
|
uint32_t aOffset, uint32_t aLength);
|
2014-05-02 16:15:27 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
already_AddRefed<DeleteTextTransaction>
|
|
|
|
CreateTxnForDeleteText(nsGenericDOMDataNode& aElement,
|
|
|
|
uint32_t aOffset, uint32_t aLength);
|
2001-05-11 16:43:22 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
already_AddRefed<DeleteTextTransaction>
|
|
|
|
CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData, uint32_t aOffset,
|
|
|
|
EDirection aDirection);
|
2006-04-04 04:57:55 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
already_AddRefed<SplitNodeTransaction>
|
|
|
|
CreateTxnForSplitNode(nsIContent& aNode, uint32_t aOffset);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
already_AddRefed<JoinNodeTransaction>
|
|
|
|
CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode);
|
1999-02-17 22:42:29 +03:00
|
|
|
|
2012-06-21 16:54:26 +04:00
|
|
|
/**
|
|
|
|
* This method first deletes the selection, if it's not collapsed. Then if
|
|
|
|
* the selection lies in a CharacterData node, it splits it. If the
|
|
|
|
* selection is at this point collapsed in a CharacterData node, it's
|
|
|
|
* adjusted to be collapsed right before or after the node instead (which is
|
|
|
|
* always possible, since the node was split).
|
|
|
|
*/
|
|
|
|
nsresult DeleteSelectionAndPrepareToCreateNode();
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Called after a transaction is done successfully.
|
|
|
|
*/
|
2012-07-05 11:45:09 +04:00
|
|
|
void DoAfterDoTransaction(nsITransaction *aTxn);
|
2016-07-08 07:10:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after a transaction is undone successfully.
|
|
|
|
*/
|
|
|
|
|
2012-07-05 11:45:09 +04:00
|
|
|
void DoAfterUndoTransaction();
|
2016-07-08 07:10:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after a transaction is redone successfully.
|
|
|
|
*/
|
2012-07-05 11:45:09 +04:00
|
|
|
void DoAfterRedoTransaction();
|
2002-01-14 23:25:29 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
enum TDocumentListenerNotification
|
|
|
|
{
|
1999-08-03 04:58:38 +04:00
|
|
|
eDocumentCreated,
|
|
|
|
eDocumentToBeDestroyed,
|
|
|
|
eDocumentStateChanged
|
2016-07-08 07:10:13 +03:00
|
|
|
};
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Tell the doc state listeners that the doc state has changed.
|
|
|
|
*/
|
2017-02-02 07:56:57 +03:00
|
|
|
nsresult NotifyDocumentListeners(
|
|
|
|
TDocumentListenerNotification aNotificationType);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Make the given selection span the entire document.
|
|
|
|
*/
|
2016-05-01 16:15:14 +03:00
|
|
|
virtual nsresult SelectEntireDocument(Selection* aSelection);
|
2001-01-09 00:01:29 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Helper method for scrolling the selection into view after
|
|
|
|
* an edit operation. aScrollToAnchor should be true if you
|
|
|
|
* want to scroll to the point where the selection was started.
|
|
|
|
* If false, it attempts to scroll the end of the selection into view.
|
2002-06-14 00:35:12 +04:00
|
|
|
*
|
2016-07-08 07:10:13 +03:00
|
|
|
* Editor methods *should* call this method instead of the versions
|
|
|
|
* in the various selection interfaces, since this version makes sure
|
|
|
|
* that the editor's sync/async settings for reflowing, painting, and
|
|
|
|
* scrolling match.
|
2002-06-14 00:35:12 +04:00
|
|
|
*/
|
2017-02-02 07:56:57 +03:00
|
|
|
nsresult ScrollSelectionIntoView(bool aScrollToAnchor);
|
1999-03-14 03:31:35 +03:00
|
|
|
|
2012-07-01 23:53:16 +04:00
|
|
|
virtual bool IsBlockNode(nsINode* aNode);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Helper for GetPriorNode() and GetNextNode().
|
|
|
|
*/
|
|
|
|
nsIContent* FindNextLeafNode(nsINode* aCurrentNode,
|
|
|
|
bool aGoForward,
|
|
|
|
bool bNoBlockCrossing);
|
2001-12-09 12:24:33 +03:00
|
|
|
|
2010-04-19 16:20:42 +04:00
|
|
|
virtual nsresult InstallEventListeners();
|
2011-07-15 14:18:35 +04:00
|
|
|
virtual void CreateEventListeners();
|
2005-03-24 22:00:01 +03:00
|
|
|
virtual void RemoveEventListeners();
|
|
|
|
|
2006-07-29 04:04:40 +04:00
|
|
|
/**
|
|
|
|
* Return true if spellchecking should be enabled for this editor.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetDesiredSpellCheckState();
|
2006-07-29 04:04:40 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool CanEnableSpellCheck()
|
2010-08-19 15:27:04 +04:00
|
|
|
{
|
|
|
|
// Check for password/readonly/disabled, which are not spellchecked
|
2016-07-08 07:10:13 +03:00
|
|
|
// regardless of DOM. Also, check to see if spell check should be skipped
|
|
|
|
// or not.
|
|
|
|
return !IsPasswordEditor() && !IsReadonly() && !IsDisabled() &&
|
|
|
|
!ShouldSkipSpellCheck();
|
2010-08-19 15:27:04 +04:00
|
|
|
}
|
|
|
|
|
2014-02-12 17:02:55 +04:00
|
|
|
/**
|
2014-10-07 14:01:47 +04:00
|
|
|
* EnsureComposition() should be called by composition event handlers. This
|
|
|
|
* tries to get the composition for the event and set it to mComposition.
|
2016-11-07 18:36:32 +03:00
|
|
|
* However, this may fail because the composition may be committed before
|
|
|
|
* the event comes to the editor.
|
|
|
|
*
|
|
|
|
* @return true if there is a composition. Otherwise, for example,
|
|
|
|
* a composition event handler in web contents moved focus
|
|
|
|
* for committing the composition, returns false.
|
2014-02-12 17:02:55 +04:00
|
|
|
*/
|
2016-11-07 18:36:32 +03:00
|
|
|
bool EnsureComposition(WidgetCompositionEvent* aCompositionEvent);
|
2014-02-12 17:02:55 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
nsresult GetSelection(SelectionType aSelectionType,
|
2016-06-11 05:06:37 +03:00
|
|
|
nsISelection** aSelection);
|
2015-03-08 01:14:07 +03:00
|
|
|
|
1999-05-05 08:05:19 +04:00
|
|
|
public:
|
2016-07-08 07:10:13 +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,
|
2012-05-05 22:52:29 +04:00
|
|
|
nsIEditor::EDirection aDirection);
|
1999-12-07 11:30:19 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* All editor operations which alter the doc should be followed
|
|
|
|
* with a call to EndOperation.
|
|
|
|
*/
|
2000-08-14 06:39:37 +04:00
|
|
|
NS_IMETHOD EndOperation();
|
1999-12-07 11:30:19 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Routines for managing the preservation of selection across
|
|
|
|
* various editor actions.
|
|
|
|
*/
|
|
|
|
bool ArePreservingSelection();
|
|
|
|
void PreserveSelectionAcrossActions(Selection* aSel);
|
2016-05-01 16:15:14 +03:00
|
|
|
nsresult RestorePreservedSelection(Selection* aSel);
|
2016-07-08 07:10:13 +03:00
|
|
|
void StopPreservingSelection();
|
2000-08-26 08:03:50 +04:00
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
/**
|
2014-11-02 15:04:13 +03:00
|
|
|
* SplitNode() creates a new node identical to an existing node, and split
|
|
|
|
* the contents between the two nodes
|
|
|
|
* @param aExistingRightNode The node to split. It will become the new
|
|
|
|
* node's next sibling.
|
|
|
|
* @param aOffset The offset of aExistingRightNode's
|
|
|
|
* content|children to do the split at
|
|
|
|
* @param aNewLeftNode The new node resulting from the split, becomes
|
|
|
|
* aExistingRightNode's previous sibling.
|
1999-05-05 08:05:19 +04:00
|
|
|
*/
|
2014-11-02 15:04:13 +03:00
|
|
|
nsresult SplitNodeImpl(nsIContent& aExistingRightNode,
|
|
|
|
int32_t aOffset,
|
|
|
|
nsIContent& aNewLeftNode);
|
1999-05-05 08:05:19 +04:00
|
|
|
|
2015-05-28 18:58:42 +03:00
|
|
|
/**
|
1999-05-05 08:05:19 +04:00
|
|
|
* JoinNodes() takes 2 nodes and merge their content|children.
|
|
|
|
* @param aNodeToKeep The node that will remain after the join.
|
|
|
|
* @param aNodeToJoin The node that will be joined with aNodeToKeep.
|
2016-07-08 07:10:13 +03:00
|
|
|
* There is no requirement that the two nodes be of the
|
|
|
|
* same type.
|
1999-08-19 17:30:48 +04:00
|
|
|
* @param aParent The parent of aNodeToKeep
|
1999-05-05 08:05:19 +04:00
|
|
|
*/
|
2013-07-24 11:39:08 +04:00
|
|
|
nsresult JoinNodesImpl(nsINode* aNodeToKeep,
|
|
|
|
nsINode* aNodeToJoin,
|
|
|
|
nsINode* aParent);
|
1999-05-05 08:05:19 +04:00
|
|
|
|
|
|
|
/**
|
2012-07-02 15:42:19 +04:00
|
|
|
* Return the offset of aChild in aParent. Asserts fatally if parent or
|
|
|
|
* child is null, or parent is not child's parent.
|
1999-05-05 08:05:19 +04:00
|
|
|
*/
|
2016-07-08 07:10:13 +03:00
|
|
|
static int32_t GetChildOffset(nsIDOMNode* aChild,
|
|
|
|
nsIDOMNode* aParent);
|
1999-05-05 08:05:19 +04:00
|
|
|
|
1999-06-16 09:02:43 +04:00
|
|
|
/**
|
2016-07-08 07:10:13 +03:00
|
|
|
* Set outOffset to the offset of aChild in the parent.
|
|
|
|
* Returns the parent of aChild.
|
1999-06-16 09:02:43 +04:00
|
|
|
*/
|
2012-07-09 04:45:12 +04:00
|
|
|
static already_AddRefed<nsIDOMNode> GetNodeLocation(nsIDOMNode* aChild,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* outOffset);
|
2013-07-10 14:03:38 +04:00
|
|
|
static nsINode* GetNodeLocation(nsINode* aChild, int32_t* aOffset);
|
1999-06-16 09:02:43 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Returns the number of things inside aNode in the out-param aCount.
|
|
|
|
* @param aNode is the node to get the length of.
|
|
|
|
* If aNode is text, returns number of characters.
|
|
|
|
* If not, returns number of children nodes.
|
|
|
|
* @param aCount [OUT] the result of the above calculation.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static nsresult GetLengthOfDOMNode(nsIDOMNode *aNode, uint32_t &aCount);
|
1999-05-05 08:05:19 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Get the node immediately prior to aCurrentNode.
|
|
|
|
* @param aCurrentNode the node from which we start the search
|
|
|
|
* @param aEditableNode if true, only return an editable node
|
|
|
|
* @param aResultNode [OUT] the node that occurs before aCurrentNode in
|
|
|
|
* the tree, skipping non-editable nodes if
|
|
|
|
* aEditableNode is true. If there is no prior
|
|
|
|
* node, aResultNode will be nullptr.
|
|
|
|
* @param bNoBlockCrossing If true, don't move across "block" nodes,
|
|
|
|
* whatever that means.
|
|
|
|
*/
|
2012-05-05 13:00:05 +04:00
|
|
|
nsIContent* GetPriorNode(nsINode* aCurrentNode, bool aEditableNode,
|
2012-05-06 11:53:11 +04:00
|
|
|
bool aNoBlockCrossing = false);
|
1999-05-05 08:51:54 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* And another version that takes a {parent,offset} pair rather than a node.
|
|
|
|
*/
|
2012-05-05 13:00:05 +04:00
|
|
|
nsIContent* GetPriorNode(nsINode* aParentNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aOffset,
|
2012-05-05 13:00:05 +04:00
|
|
|
bool aEditableNode,
|
2012-05-06 11:53:11 +04:00
|
|
|
bool aNoBlockCrossing = false);
|
2012-05-05 13:00:05 +04:00
|
|
|
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Get the node immediately after to aCurrentNode.
|
|
|
|
* @param aCurrentNode the node from which we start the search
|
|
|
|
* @param aEditableNode if true, only return an editable node
|
|
|
|
* @param aResultNode [OUT] the node that occurs after aCurrentNode in the
|
|
|
|
* tree, skipping non-editable nodes if
|
|
|
|
* aEditableNode is true. If there is no prior
|
|
|
|
* node, aResultNode will be nullptr.
|
|
|
|
*/
|
2012-02-01 14:54:22 +04:00
|
|
|
nsIContent* GetNextNode(nsINode* aCurrentNode,
|
|
|
|
bool aEditableNode,
|
2012-05-06 11:53:11 +04:00
|
|
|
bool bNoBlockCrossing = false);
|
1999-05-05 08:05:19 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* And another version that takes a {parent,offset} pair rather than a node.
|
|
|
|
*/
|
2012-05-05 13:00:05 +04:00
|
|
|
nsIContent* GetNextNode(nsINode* aParentNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aOffset,
|
2012-05-05 13:00:05 +04:00
|
|
|
bool aEditableNode,
|
2012-05-06 11:53:11 +04:00
|
|
|
bool aNoBlockCrossing = false);
|
2001-08-22 09:32:44 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Helper for GetNextNode() and GetPriorNode().
|
|
|
|
*/
|
|
|
|
nsIContent* FindNode(nsINode* aCurrentNode,
|
|
|
|
bool aGoForward,
|
|
|
|
bool aEditableNode,
|
|
|
|
bool bNoBlockCrossing);
|
2011-08-11 17:29:59 +04:00
|
|
|
/**
|
|
|
|
* Get the rightmost child of aCurrentNode;
|
2012-07-30 18:20:58 +04:00
|
|
|
* return nullptr if aCurrentNode has no children.
|
2011-08-11 17:29:59 +04:00
|
|
|
*/
|
2016-07-08 07:10:13 +03:00
|
|
|
nsIContent* GetRightmostChild(nsINode* aCurrentNode,
|
|
|
|
bool bNoBlockCrossing = false);
|
1999-05-05 08:05:19 +04:00
|
|
|
|
2011-08-11 17:29:59 +04:00
|
|
|
/**
|
|
|
|
* Get the leftmost child of aCurrentNode;
|
2012-07-30 18:20:58 +04:00
|
|
|
* return nullptr if aCurrentNode has no children.
|
2011-08-11 17:29:59 +04:00
|
|
|
*/
|
2011-11-28 16:53:29 +04:00
|
|
|
nsIContent* GetLeftmostChild(nsINode *aCurrentNode,
|
2016-07-08 07:10:13 +03:00
|
|
|
bool bNoBlockCrossing = false);
|
1999-05-05 08:05:19 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Returns true if aNode is of the type implied by aTag.
|
|
|
|
*/
|
|
|
|
static inline bool NodeIsType(nsIDOMNode* aNode, nsIAtom* aTag)
|
2003-07-15 17:47:15 +04:00
|
|
|
{
|
2003-11-19 04:20:56 +03:00
|
|
|
return GetTag(aNode) == aTag;
|
2003-07-15 17:47:15 +04:00
|
|
|
}
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Returns true if aParent can contain a child of type aTag.
|
|
|
|
*/
|
2014-11-02 15:04:13 +03:00
|
|
|
bool CanContain(nsINode& aParent, nsIContent& aChild);
|
|
|
|
bool CanContainTag(nsINode& aParent, nsIAtom& aTag);
|
|
|
|
bool TagCanContain(nsIAtom& aParentTag, nsIContent& aChild);
|
|
|
|
virtual bool TagCanContainTag(nsIAtom& aParentTag, nsIAtom& aChildTag);
|
2000-02-08 15:53:34 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Returns true if aNode is our root node.
|
|
|
|
*/
|
2012-05-01 14:01:28 +04:00
|
|
|
bool IsRoot(nsIDOMNode* inNode);
|
|
|
|
bool IsRoot(nsINode* inNode);
|
2012-05-06 11:53:11 +04:00
|
|
|
bool IsEditorRoot(nsINode* aNode);
|
2001-08-28 22:21:12 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Returns true if aNode is a descendant of our root node.
|
|
|
|
*/
|
2012-05-01 14:01:28 +04:00
|
|
|
bool IsDescendantOfRoot(nsIDOMNode* inNode);
|
|
|
|
bool IsDescendantOfRoot(nsINode* inNode);
|
2012-05-06 11:53:11 +04:00
|
|
|
bool IsDescendantOfEditorRoot(nsINode* aNode);
|
2000-05-10 01:06:49 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Returns true if aNode is a container.
|
|
|
|
*/
|
2014-04-28 15:54:46 +04:00
|
|
|
virtual bool IsContainer(nsINode* aNode);
|
|
|
|
virtual bool IsContainer(nsIDOMNode* aNode);
|
1999-09-30 00:08:15 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* returns true if aNode is an editable node.
|
|
|
|
*/
|
|
|
|
bool IsEditable(nsIDOMNode* aNode);
|
2014-04-28 20:03:12 +04:00
|
|
|
virtual bool IsEditable(nsINode* aNode);
|
1999-05-05 08:05:19 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Returns true if aNode is a MozEditorBogus node.
|
|
|
|
*/
|
2014-04-28 20:03:12 +04:00
|
|
|
bool IsMozEditorBogusNode(nsINode* aNode);
|
2000-01-19 02:45:35 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Counts number of editable child nodes.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t CountEditableChildren(nsINode* aNode);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Find the deep first and last children.
|
|
|
|
*/
|
2012-02-01 14:54:22 +04:00
|
|
|
nsINode* GetFirstEditableNode(nsINode* aRoot);
|
1999-06-23 01:42:44 +04:00
|
|
|
|
2014-02-12 17:02:56 +04:00
|
|
|
/**
|
|
|
|
* Returns current composition.
|
|
|
|
*/
|
2016-07-08 07:10:13 +03:00
|
|
|
TextComposition* GetComposition() const;
|
|
|
|
|
2014-02-12 17:02:56 +04:00
|
|
|
/**
|
|
|
|
* Returns true if there is composition string and not fixed.
|
|
|
|
*/
|
|
|
|
bool IsIMEComposing() const;
|
2016-07-08 07:10:13 +03:00
|
|
|
|
2015-06-04 20:06:09 +03:00
|
|
|
/**
|
|
|
|
* Returns true when inserting text should be a part of current composition.
|
|
|
|
*/
|
|
|
|
bool ShouldHandleIMEComposition() const;
|
1999-06-23 01:42:44 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* From html rules code - migration in progress.
|
|
|
|
*/
|
|
|
|
static nsresult GetTagString(nsIDOMNode* aNode, nsAString& outString);
|
|
|
|
static nsIAtom* GetTag(nsIDOMNode* aNode);
|
2012-05-18 12:29:38 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
bool NodesSameType(nsIDOMNode* aNode1, nsIDOMNode* aNode2);
|
2012-05-18 12:29:38 +04:00
|
|
|
virtual bool AreNodesSameType(nsIContent* aNode1, nsIContent* aNode2);
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
static bool IsTextNode(nsIDOMNode* aNode);
|
|
|
|
static bool IsTextNode(nsINode* aNode);
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
static nsCOMPtr<nsIDOMNode> GetChildAt(nsIDOMNode* aParent, int32_t aOffset);
|
2016-05-01 17:59:29 +03:00
|
|
|
static nsIContent* GetNodeAtRangeOffsetPoint(nsIDOMNode* aParentOrNode,
|
|
|
|
int32_t aOffset);
|
2011-07-14 19:25:07 +04:00
|
|
|
|
2016-05-01 16:15:14 +03:00
|
|
|
static nsresult GetStartNodeAndOffset(Selection* aSelection,
|
2014-11-02 15:04:13 +03:00
|
|
|
nsIDOMNode** outStartNode,
|
|
|
|
int32_t* outStartOffset);
|
2016-05-01 16:15:14 +03:00
|
|
|
static nsresult GetStartNodeAndOffset(Selection* aSelection,
|
2013-07-24 11:39:08 +04:00
|
|
|
nsINode** aStartNode,
|
|
|
|
int32_t* aStartOffset);
|
2016-05-01 16:15:14 +03:00
|
|
|
static nsresult GetEndNodeAndOffset(Selection* aSelection,
|
2014-11-02 15:04:13 +03:00
|
|
|
nsIDOMNode** outEndNode,
|
|
|
|
int32_t* outEndOffset);
|
2016-05-01 16:15:14 +03:00
|
|
|
static nsresult GetEndNodeAndOffset(Selection* aSelection,
|
2013-07-24 11:39:08 +04:00
|
|
|
nsINode** aEndNode,
|
|
|
|
int32_t* aEndOffset);
|
2002-11-22 06:30:59 +03:00
|
|
|
#if DEBUG_JOE
|
2016-07-08 07:10:13 +03:00
|
|
|
static void DumpNode(nsIDOMNode* aNode, int32_t indent = 0);
|
2002-11-22 06:30:59 +03:00
|
|
|
#endif
|
2016-07-08 07:10:13 +03:00
|
|
|
Selection* GetSelection(SelectionType aSelectionType =
|
|
|
|
SelectionType::eNormal);
|
1999-06-09 05:27:08 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Helpers to add a node to the selection.
|
|
|
|
* Used by table cell selection methods.
|
|
|
|
*/
|
|
|
|
nsresult CreateRange(nsIDOMNode* aStartParent, int32_t aStartOffset,
|
|
|
|
nsIDOMNode* aEndParent, int32_t aEndOffset,
|
2014-11-02 15:04:13 +03:00
|
|
|
nsRange** aRange);
|
2002-01-14 23:25:29 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Creates a range with just the supplied node and appends that to the
|
|
|
|
* selection.
|
|
|
|
*/
|
2000-02-10 08:14:52 +03:00
|
|
|
nsresult AppendNodeToSelectionAsRange(nsIDOMNode *aNode);
|
2016-07-08 07:10:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When you are using AppendNodeToSelectionAsRange(), call this first to
|
|
|
|
* start a new selection.
|
|
|
|
*/
|
2000-02-10 08:14:52 +03:00
|
|
|
nsresult ClearSelection();
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
nsresult IsPreformatted(nsIDOMNode* aNode, bool* aResult);
|
1999-05-17 16:22:31 +04:00
|
|
|
|
2015-08-05 17:54:36 +03:00
|
|
|
enum class EmptyContainers { no, yes };
|
|
|
|
int32_t SplitNodeDeep(nsIContent& aNode, nsIContent& aSplitPointParent,
|
|
|
|
int32_t aSplitPointOffset,
|
|
|
|
EmptyContainers aEmptyContainers =
|
|
|
|
EmptyContainers::yes,
|
|
|
|
nsIContent** outLeftNode = nullptr,
|
|
|
|
nsIContent** outRightNode = nullptr);
|
2016-07-08 07:10:13 +03:00
|
|
|
EditorDOMPoint JoinNodeDeep(nsIContent& aLeftNode,
|
|
|
|
nsIContent& aRightNode);
|
1999-08-31 17:55:18 +04:00
|
|
|
|
2002-03-24 01:16:54 +03:00
|
|
|
nsresult GetString(const nsAString& name, nsAString& value);
|
1999-05-04 02:57:48 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
void BeginUpdateViewBatch();
|
|
|
|
virtual nsresult EndUpdateViewBatch();
|
1999-02-12 20:18:58 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetShouldTxnSetSelection();
|
1999-02-12 20:18:58 +03:00
|
|
|
|
2010-06-10 05:16:58 +04:00
|
|
|
virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
|
|
|
|
|
2012-08-12 22:28:26 +04:00
|
|
|
nsresult HandleInlineSpellCheck(EditAction action,
|
2016-05-01 16:15:14 +03:00
|
|
|
Selection* aSelection,
|
2016-07-08 07:10:13 +03:00
|
|
|
nsIDOMNode* previousSelectedNode,
|
|
|
|
int32_t previousSelectedOffset,
|
|
|
|
nsIDOMNode* aStartNode,
|
|
|
|
int32_t aStartOffset,
|
|
|
|
nsIDOMNode* aEndNode,
|
|
|
|
int32_t aEndOffset);
|
2005-02-02 00:12:53 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
virtual already_AddRefed<dom::EventTarget> GetDOMEventTarget() = 0;
|
2005-03-24 22:00:01 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Fast non-refcounting editor root element accessor
|
|
|
|
*/
|
2016-05-01 16:15:14 +03:00
|
|
|
Element* GetRoot();
|
2005-03-24 22:00:01 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Likewise, but gets the editor's root instead, which is different for HTML
|
|
|
|
* editors.
|
|
|
|
*/
|
2016-05-01 16:15:14 +03:00
|
|
|
virtual Element* GetEditorRoot();
|
2012-05-06 11:53:11 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Likewise, but gets the text control element instead of the root for
|
|
|
|
* plaintext editors.
|
|
|
|
*/
|
2016-05-01 16:15:14 +03:00
|
|
|
Element* GetExposedRoot();
|
2014-01-17 19:31:03 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Accessor methods to flags.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsPlaintextEditor() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorPlaintextMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsSingleLineEditor() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorSingleLineMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsPasswordEditor() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorPasswordMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsReadonly() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorReadonlyMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsDisabled() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorDisabledMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsInputFiltered() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorFilterInputMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsMailEditor() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorMailMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsWrapHackEnabled() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorEnableWrapHackMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsFormWidget() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorWidgetMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool NoCSS() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorNoCSSMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsInteractionAllowed() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorAllowInteraction) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool DontEchoPassword() const
|
2010-04-12 06:35:18 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorDontEchoPassword) != 0;
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2012-04-04 13:15:10 +04:00
|
|
|
bool ShouldSkipSpellCheck() const
|
2011-10-17 06:06:24 +04:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorSkipSpellCheck) != 0;
|
|
|
|
}
|
2010-04-12 06:35:18 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsTabbable() const
|
2010-06-10 05:16:58 +04:00
|
|
|
{
|
|
|
|
return IsSingleLineEditor() || IsPasswordEditor() || IsFormWidget() ||
|
|
|
|
IsInteractionAllowed();
|
|
|
|
}
|
|
|
|
|
2013-05-18 04:07:46 +04:00
|
|
|
bool HasIndependentSelection() const
|
|
|
|
{
|
|
|
|
return !!mSelConWeak;
|
|
|
|
}
|
|
|
|
|
2017-02-03 10:22:50 +03:00
|
|
|
bool IsModifiable() const
|
|
|
|
{
|
|
|
|
return !IsReadonly();
|
|
|
|
}
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Get the input event target. This might return null.
|
|
|
|
*/
|
2012-03-27 05:36:44 +04:00
|
|
|
virtual already_AddRefed<nsIContent> GetInputEventTargetContent() = 0;
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Get the focused content, if we're focused. Returns null otherwise.
|
|
|
|
*/
|
2010-10-29 20:30:52 +04:00
|
|
|
virtual already_AddRefed<nsIContent> GetFocusedContent();
|
2010-05-04 21:40:39 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Get the focused content for the argument of some IMEStateManager's
|
|
|
|
* methods.
|
|
|
|
*/
|
2012-11-09 12:40:39 +04:00
|
|
|
virtual already_AddRefed<nsIContent> GetFocusedContentForIME();
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Whether the editor is active on the DOM window. Note that when this
|
|
|
|
* returns true but GetFocusedContent() returns null, it means that this editor was
|
|
|
|
* focused when the DOM window was active.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool IsActiveInDOMWindow();
|
2010-07-22 20:22:44 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
2017-01-17 11:17:06 +03:00
|
|
|
* Whether the aGUIEvent should be handled by this editor or not. When this
|
|
|
|
* returns false, The aGUIEvent shouldn't be handled on this editor,
|
|
|
|
* i.e., The aGUIEvent should be handled by another inner editor or ancestor
|
2016-07-08 07:10:13 +03:00
|
|
|
* elements.
|
|
|
|
*/
|
2017-01-17 11:17:06 +03:00
|
|
|
virtual bool IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent);
|
2010-07-22 20:22:44 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* FindSelectionRoot() returns a selection root of this editor when aNode
|
|
|
|
* gets focus. aNode must be a content node or a document node. When the
|
|
|
|
* target isn't a part of this editor, returns nullptr. If this is for
|
|
|
|
* designMode, you should set the document node to aNode except that an
|
|
|
|
* element in the document has focus.
|
|
|
|
*/
|
2010-06-17 09:30:42 +04:00
|
|
|
virtual already_AddRefed<nsIContent> FindSelectionRoot(nsINode* aNode);
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Initializes selection and caret for the editor. If aEventTarget isn't
|
|
|
|
* a host of the editor, i.e., the editor doesn't get focus, this does
|
|
|
|
* nothing.
|
|
|
|
*/
|
2010-06-17 09:30:42 +04:00
|
|
|
nsresult InitializeSelection(nsIDOMEventTarget* aFocusEventTarget);
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* This method has to be called by EditorEventListener::Focus.
|
|
|
|
* All actions that have to be done when the editor is focused needs to be
|
|
|
|
* added here.
|
|
|
|
*/
|
2011-08-12 23:12:45 +04:00
|
|
|
void OnFocus(nsIDOMEventTarget* aFocusEventTarget);
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
/**
|
|
|
|
* Used to insert content from a data transfer into the editable area.
|
|
|
|
* This is called for each item in the data transfer, with the index of
|
|
|
|
* each item passed as aIndex.
|
|
|
|
*/
|
|
|
|
virtual nsresult InsertFromDataTransfer(dom::DataTransfer* aDataTransfer,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aIndex,
|
2016-07-08 07:10:13 +03:00
|
|
|
nsIDOMDocument* aSourceDoc,
|
|
|
|
nsIDOMNode* aDestinationNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aDestOffset,
|
2012-02-17 18:16:59 +04:00
|
|
|
bool aDoDeleteSelection) = 0;
|
|
|
|
|
|
|
|
virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent) = 0;
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
virtual already_AddRefed<nsIDOMNode> FindUserSelectAllNode(nsIDOMNode* aNode)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-02-17 18:16:59 +04:00
|
|
|
|
2015-06-04 20:06:09 +03:00
|
|
|
/**
|
|
|
|
* GetIMESelectionStartOffsetIn() returns the start offset of IME selection in
|
|
|
|
* the aTextNode. If there is no IME selection, returns -1.
|
|
|
|
*/
|
|
|
|
int32_t GetIMESelectionStartOffsetIn(nsINode* aTextNode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FindBetterInsertionPoint() tries to look for better insertion point which
|
|
|
|
* is typically the nearest text node and offset in it.
|
|
|
|
*/
|
2016-10-17 08:22:46 +03:00
|
|
|
void FindBetterInsertionPoint(nsCOMPtr<nsIDOMNode>& aNode,
|
|
|
|
int32_t& aOffset);
|
2015-06-04 20:06:09 +03:00
|
|
|
void FindBetterInsertionPoint(nsCOMPtr<nsINode>& aNode,
|
|
|
|
int32_t& aOffset);
|
|
|
|
|
2015-08-17 14:58:38 +03:00
|
|
|
/**
|
|
|
|
* HideCaret() hides caret with nsCaret::AddForceHide() or may show carent
|
|
|
|
* with nsCaret::RemoveForceHide(). This does NOT set visibility of
|
|
|
|
* nsCaret. Therefore, this is stateless.
|
|
|
|
*/
|
|
|
|
void HideCaret(bool aHide);
|
|
|
|
|
2017-01-27 02:24:00 +03:00
|
|
|
void FlushFrames()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc = GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
doc->FlushPendingNotifications(FlushType::Frames);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-09 05:37:50 +04:00
|
|
|
protected:
|
2016-07-08 07:10:13 +03:00
|
|
|
enum Tristate
|
|
|
|
{
|
2006-07-29 04:04:40 +04:00
|
|
|
eTriUnset,
|
|
|
|
eTriFalse,
|
|
|
|
eTriTrue
|
2012-04-24 08:54:11 +04:00
|
|
|
};
|
2016-07-08 07:10:13 +03:00
|
|
|
|
|
|
|
// MIME type of the doc we are editing.
|
|
|
|
nsCString mContentMIMEType;
|
2012-04-24 08:54:11 +04:00
|
|
|
|
2006-07-29 04:04:40 +04:00
|
|
|
nsCOMPtr<nsIInlineSpellChecker> mInlineSpellChecker;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsTransactionManager> mTxnMgr;
|
2016-07-08 07:10:13 +03:00
|
|
|
// Cached root node.
|
|
|
|
nsCOMPtr<Element> mRootElement;
|
|
|
|
// Current IME text node.
|
|
|
|
RefPtr<Text> mIMETextNode;
|
|
|
|
// The form field as an event receiver.
|
|
|
|
nsCOMPtr<dom::EventTarget> mEventTarget;
|
2012-04-24 08:54:11 +04:00
|
|
|
nsCOMPtr<nsIDOMEventListener> mEventListener;
|
2016-07-08 07:10:13 +03:00
|
|
|
// Weak reference to the nsISelectionController.
|
|
|
|
nsWeakPtr mSelConWeak;
|
|
|
|
// Weak reference to placeholder for begin/end batch purposes.
|
|
|
|
nsWeakPtr mPlaceHolderTxn;
|
|
|
|
// Weak reference to the nsIDOMDocument.
|
|
|
|
nsWeakPtr mDocWeak;
|
|
|
|
// Name of placeholder transaction.
|
|
|
|
nsIAtom* mPlaceHolderName;
|
2016-07-07 12:15:53 +03:00
|
|
|
// Saved selection state for placeholder transaction batching.
|
2016-07-08 07:10:13 +03:00
|
|
|
SelectionState* mSelState;
|
|
|
|
nsString* mPhonetic;
|
2014-02-12 17:02:55 +04:00
|
|
|
// IME composition this is not null between compositionstart and
|
|
|
|
// compositionend.
|
2016-07-08 07:10:13 +03:00
|
|
|
RefPtr<TextComposition> mComposition;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
// Listens to all low level actions on the doc.
|
2016-05-01 16:15:14 +03:00
|
|
|
nsTArray<OwningNonNull<nsIEditActionListener>> mActionListeners;
|
2016-07-08 07:10:13 +03:00
|
|
|
// Just notify once per high level change.
|
2016-05-01 16:15:14 +03:00
|
|
|
nsTArray<OwningNonNull<nsIEditorObserver>> mEditorObservers;
|
2016-07-08 08:15:21 +03:00
|
|
|
// Listen to overall doc state (dirty or not, just created, etc.).
|
2016-05-01 16:15:14 +03:00
|
|
|
nsTArray<OwningNonNull<nsIDocumentStateListener>> mDocStateListeners;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
2016-07-07 12:15:53 +03:00
|
|
|
// Cached selection for AutoSelectionRestorer.
|
2016-07-08 07:10:13 +03:00
|
|
|
SelectionState mSavedSel;
|
2016-06-24 09:01:40 +03:00
|
|
|
// Utility class object for maintaining preserved ranges.
|
2016-07-08 07:10:13 +03:00
|
|
|
RangeUpdater mRangeUpdater;
|
2012-04-24 08:54:11 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
// Number of modifications (for undo/redo stack).
|
|
|
|
uint32_t mModCount;
|
|
|
|
// Behavior flags. See nsIPlaintextEditor.idl for the flags we use.
|
|
|
|
uint32_t mFlags;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
int32_t mUpdateCount;
|
2002-12-18 02:38:04 +03:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
// Nesting count for batching.
|
|
|
|
int32_t mPlaceHolderBatch;
|
|
|
|
// The current editor action.
|
|
|
|
EditAction mAction;
|
2012-04-24 08:54:11 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
// Offset in text node where IME comp string begins.
|
|
|
|
uint32_t mIMETextOffset;
|
2015-06-04 20:06:09 +03:00
|
|
|
// The Length of the composition string or commit string. If this is length
|
|
|
|
// of commit string, the length is truncated by maxlength attribute.
|
2016-07-08 07:10:13 +03:00
|
|
|
uint32_t mIMETextLength;
|
|
|
|
|
|
|
|
// The current direction of editor action.
|
|
|
|
EDirection mDirection;
|
|
|
|
// -1 = not initialized
|
|
|
|
int8_t mDocDirtyState;
|
|
|
|
// A Tristate value.
|
|
|
|
uint8_t mSpellcheckCheckboxState;
|
|
|
|
|
|
|
|
// Turn off for conservative selection adjustment by transactions.
|
|
|
|
bool mShouldTxnSetSelection;
|
|
|
|
// Whether PreDestroy has been called.
|
|
|
|
bool mDidPreDestroy;
|
|
|
|
// Whether PostCreate has been called.
|
|
|
|
bool mDidPostCreate;
|
2012-03-27 05:36:44 +04:00
|
|
|
bool mDispatchInputEvent;
|
2016-07-08 07:10:13 +03:00
|
|
|
// True while the instance is handling an edit action.
|
|
|
|
bool mIsInEditAction;
|
|
|
|
// Whether caret is hidden forcibly.
|
|
|
|
bool mHidingCaret;
|
2010-12-07 09:30:05 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
friend bool NSCanUnload(nsISupports* serviceMgr);
|
2016-07-08 07:10:13 +03:00
|
|
|
friend class AutoRules;
|
|
|
|
friend class AutoSelectionRestorer;
|
|
|
|
friend class AutoTransactionsConserveSelection;
|
|
|
|
friend class RangeUpdater;
|
1999-06-08 10:04:51 +04:00
|
|
|
};
|
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
} // namespace mozilla
|
1999-06-03 09:58:20 +04:00
|
|
|
|
2016-07-08 07:10:13 +03:00
|
|
|
#endif // #ifndef mozilla_EditorBase_h
|