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 __editor_h__
|
|
|
|
#define __editor_h__
|
|
|
|
|
2013-01-28 16:33:17 -08:00
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc.
|
|
|
|
#include "mozilla/TypedEnum.h" // for MOZ_BEGIN_ENUM_CLASS, etc.
|
2014-05-02 05:15:27 -07:00
|
|
|
#include "mozilla/dom/Text.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr
|
|
|
|
#include "nsCOMArray.h" // for nsCOMArray
|
|
|
|
#include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
|
2009-05-08 21:59:25 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-08-29 04:43:24 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2012-07-12 23:33:42 -07: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
|
|
|
|
#include "nsISupportsImpl.h" // for nsEditor::Release, etc
|
|
|
|
#include "nsIWeakReferenceUtils.h" // for nsWeakPtr
|
|
|
|
#include "nsLiteralString.h" // for NS_LITERAL_STRING
|
|
|
|
#include "nsSelectionState.h" // for nsRangeUpdater, etc
|
|
|
|
#include "nsString.h" // for nsCString
|
|
|
|
#include "nsWeakReference.h" // for nsSupportsWeakReference
|
|
|
|
#include "nscore.h" // for nsresult, nsAString, etc
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-12 23:33:42 -07:00
|
|
|
class AddStyleSheetTxn;
|
2012-06-19 06:23:36 -07:00
|
|
|
class DeleteNodeTxn;
|
2007-03-22 10:30:00 -07:00
|
|
|
class EditAggregateTxn;
|
|
|
|
class RemoveStyleSheetTxn;
|
2012-07-12 23:33:42 -07:00
|
|
|
class nsIAtom;
|
|
|
|
class nsIContent;
|
|
|
|
class nsIDOMCharacterData;
|
|
|
|
class nsIDOMDataTransfer;
|
|
|
|
class nsIDOMDocument;
|
|
|
|
class nsIDOMElement;
|
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsIDOMEventListener;
|
|
|
|
class nsIDOMEventTarget;
|
|
|
|
class nsIDOMKeyEvent;
|
|
|
|
class nsIDOMNode;
|
|
|
|
class nsIDocument;
|
|
|
|
class nsIDocumentStateListener;
|
|
|
|
class nsIEditActionListener;
|
2012-11-14 11:23:35 -08:00
|
|
|
class nsIEditorObserver;
|
2012-07-12 23:33:42 -07:00
|
|
|
class nsIInlineSpellChecker;
|
|
|
|
class nsINode;
|
|
|
|
class nsIPresShell;
|
|
|
|
class nsISupports;
|
|
|
|
class nsITransaction;
|
|
|
|
class nsIWidget;
|
|
|
|
class nsRange;
|
|
|
|
class nsString;
|
|
|
|
class nsTransactionManager;
|
2014-11-02 04:04:13 -08:00
|
|
|
struct DOMPoint;
|
2012-07-12 23:33:42 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-06-20 03:32:49 -07:00
|
|
|
class CSSStyleSheet;
|
2014-04-28 04:54:47 -07:00
|
|
|
class ErrorResult;
|
2014-02-12 05:02:55 -08:00
|
|
|
class TextComposition;
|
2012-07-12 23:33:42 -07:00
|
|
|
|
|
|
|
namespace dom {
|
2014-08-29 04:43:23 -07:00
|
|
|
class ChangeAttributeTxn;
|
2014-08-20 05:25:16 -07:00
|
|
|
class CreateElementTxn;
|
2013-07-09 10:54:21 -07:00
|
|
|
class DataTransfer;
|
2014-08-20 05:25:16 -07:00
|
|
|
class DeleteTextTxn;
|
2012-07-12 23:33:42 -07:00
|
|
|
class Element;
|
2013-10-22 16:32:04 -07:00
|
|
|
class EventTarget;
|
2014-08-29 04:43:24 -07:00
|
|
|
class IMETextTxn;
|
2014-08-29 04:43:23 -07:00
|
|
|
class InsertTextTxn;
|
2014-08-20 05:25:17 -07:00
|
|
|
class InsertNodeTxn;
|
2014-11-02 04:04:12 -08:00
|
|
|
class JoinNodeTxn;
|
2014-04-10 09:09:40 -07:00
|
|
|
class Selection;
|
2014-11-02 04:04:13 -08:00
|
|
|
class SplitNodeTxn;
|
2014-05-02 04:11:26 -07:00
|
|
|
class Text;
|
2012-07-12 23:33:42 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-27 03:51:53 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
struct IMEState;
|
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-08-29 04:43:24 -07:00
|
|
|
#define kMOZEditorBogusNodeAttrAtom nsGkAtoms::mozeditorbogusnode
|
2007-03-22 10:30:00 -07:00
|
|
|
#define kMOZEditorBogusNodeValue NS_LITERAL_STRING("TRUE")
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
// This is int32_t instead of int16_t because nsIInlineSpellChecker.idl's
|
2012-08-01 05:22:07 -07:00
|
|
|
// spellCheckAfterEditorChange is defined to take it as a long.
|
2012-08-22 08:56:38 -07:00
|
|
|
MOZ_BEGIN_ENUM_CLASS(EditAction, int32_t)
|
2012-08-01 05:22:07 -07: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
|
2012-08-12 11:28:26 -07:00
|
|
|
MOZ_END_ENUM_CLASS(EditAction)
|
2012-08-01 05:22:07 -07:00
|
|
|
|
2012-08-12 11:28:26 -07:00
|
|
|
inline bool operator!(const EditAction& aOp)
|
2012-08-01 05:22:07 -07:00
|
|
|
{
|
2012-08-12 11:28:26 -07:00
|
|
|
return aOp == EditAction::none;
|
2012-08-01 05:22:07 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/** 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.
|
|
|
|
*/
|
|
|
|
class nsEditor : public nsIEditor,
|
|
|
|
public nsIEditorIMESupport,
|
|
|
|
public nsSupportsWeakReference,
|
2011-09-13 11:58:54 -07:00
|
|
|
public nsIObserver,
|
2011-04-11 13:00:32 -07:00
|
|
|
public nsIPhonetic
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum IterDirection
|
|
|
|
{
|
|
|
|
kIterForward,
|
|
|
|
kIterBackward
|
|
|
|
};
|
|
|
|
|
|
|
|
/** The default constructor. This should suffice. the setting of the interfaces is done
|
|
|
|
* after the construction of the editor class.
|
|
|
|
*/
|
|
|
|
nsEditor();
|
2014-06-23 15:40:02 -07:00
|
|
|
|
|
|
|
protected:
|
2007-03-22 10:30:00 -07:00
|
|
|
/** The default destructor. This should suffice. Should this be pure virtual
|
|
|
|
* for someone to derive from the nsEditor later? I don't believe so.
|
|
|
|
*/
|
|
|
|
virtual ~nsEditor();
|
|
|
|
|
2014-06-23 15:40:02 -07:00
|
|
|
public:
|
2007-03-22 10:30:00 -07:00
|
|
|
//Interfaces for addref and release and queryinterface
|
|
|
|
//NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsEditor
|
2009-05-08 21:59:25 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsEditor,
|
|
|
|
nsIEditor)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* ------------ utility methods -------------- */
|
2012-03-24 01:19:14 -07:00
|
|
|
already_AddRefed<nsIDOMDocument> GetDOMDocument();
|
|
|
|
already_AddRefed<nsIDocument> GetDocument();
|
2011-05-22 05:43:13 -07:00
|
|
|
already_AddRefed<nsIPresShell> GetPresShell();
|
2014-04-10 00:11:37 -07:00
|
|
|
already_AddRefed<nsIWidget> GetWidget();
|
2014-07-30 21:37:59 -07:00
|
|
|
enum NotificationForEditorObservers
|
|
|
|
{
|
|
|
|
eNotifyEditorObserversOfEnd,
|
|
|
|
eNotifyEditorObserversOfBefore,
|
|
|
|
eNotifyEditorObserversOfCancel
|
|
|
|
};
|
|
|
|
void NotifyEditorObservers(NotificationForEditorObservers aNotification);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* ------------ nsIEditor methods -------------- */
|
|
|
|
NS_DECL_NSIEDITOR
|
2013-01-09 15:05:08 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* ------------ nsIEditorIMESupport methods -------------- */
|
|
|
|
NS_DECL_NSIEDITORIMESUPPORT
|
2013-01-09 15:05:08 -08:00
|
|
|
|
2011-09-13 11:58:54 -07:00
|
|
|
/* ------------ nsIObserver methods -------------- */
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIPhonetic
|
|
|
|
NS_DECL_NSIPHONETIC
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2011-11-28 04:53:29 -08:00
|
|
|
virtual bool IsModifiableNode(nsINode *aNode);
|
2013-01-09 15:05:08 -08:00
|
|
|
|
2014-11-02 04:04:13 -08:00
|
|
|
virtual nsresult InsertTextImpl(const nsAString& aStringToInsert,
|
|
|
|
nsCOMPtr<nsINode>* aInOutNode,
|
|
|
|
int32_t* aInOutOffset,
|
|
|
|
nsIDocument* aDoc);
|
2014-05-02 04:11:26 -07:00
|
|
|
nsresult InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
|
2014-08-29 04:43:23 -07:00
|
|
|
mozilla::dom::Text& aTextNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aOffset,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aSuppressIME = false);
|
2012-05-10 07:54:33 -07:00
|
|
|
NS_IMETHOD DeleteSelectionImpl(EDirection aAction,
|
|
|
|
EStripWrappers aStripWrappers);
|
2014-11-02 04:04:13 -08:00
|
|
|
|
|
|
|
already_AddRefed<mozilla::dom::Element>
|
|
|
|
DeleteSelectionAndCreateElement(nsIAtom& aTag);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* helper routines for node/parent manipulations */
|
2012-06-19 06:23:36 -07:00
|
|
|
nsresult DeleteNode(nsINode* aNode);
|
2014-08-20 05:25:17 -07:00
|
|
|
nsresult InsertNode(nsIContent& aNode, nsINode& aParent, int32_t aPosition);
|
2014-08-13 04:53:33 -07:00
|
|
|
enum ECloneAttributes { eDontCloneAttributes, eCloneAttributes };
|
|
|
|
already_AddRefed<mozilla::dom::Element> ReplaceContainer(
|
|
|
|
mozilla::dom::Element* aOldContainer,
|
|
|
|
nsIAtom* aNodeType,
|
|
|
|
nsIAtom* aAttribute = nullptr,
|
2012-07-30 07:20:58 -07:00
|
|
|
const nsAString* aValue = nullptr,
|
2014-08-13 04:53:33 -07:00
|
|
|
ECloneAttributes aCloneAttributes = eDontCloneAttributes);
|
2014-08-18 07:44:50 -07:00
|
|
|
void CloneAttributes(mozilla::dom::Element* aDest,
|
|
|
|
mozilla::dom::Element* aSource);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-20 05:25:16 -07:00
|
|
|
nsresult RemoveContainer(nsIContent* aNode);
|
2014-08-20 05:25:16 -07:00
|
|
|
already_AddRefed<mozilla::dom::Element> InsertContainerAbove(
|
|
|
|
nsIContent* aNode,
|
|
|
|
nsIAtom* aNodeType,
|
|
|
|
nsIAtom* aAttribute = nullptr,
|
2012-07-30 07:20:58 -07:00
|
|
|
const nsAString* aValue = nullptr);
|
2014-11-02 04:04:13 -08:00
|
|
|
nsIContent* SplitNode(nsIContent& aNode, int32_t aOffset,
|
|
|
|
mozilla::ErrorResult& aResult);
|
2014-11-02 04:04:12 -08:00
|
|
|
nsresult JoinNodes(nsINode& aLeftNode, nsINode& aRightNode);
|
2014-08-20 05:25:16 -07:00
|
|
|
nsresult MoveNode(nsIContent* aNode, nsINode* aParent, int32_t aOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* Method to replace certain CreateElementNS() calls.
|
|
|
|
Arguments:
|
2014-08-13 04:53:33 -07:00
|
|
|
nsIAtom* aTag - tag you want
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2014-08-13 04:53:33 -07:00
|
|
|
already_AddRefed<mozilla::dom::Element> CreateHTMLContent(nsIAtom* aTag);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-29 21:05:12 -07:00
|
|
|
// IME event handlers
|
2014-02-12 05:02:55 -08:00
|
|
|
virtual nsresult BeginIMEComposition(mozilla::WidgetCompositionEvent* aEvent);
|
|
|
|
virtual nsresult UpdateIMEComposition(nsIDOMEvent* aDOMTextEvent) = 0;
|
2012-06-19 06:23:36 -07:00
|
|
|
void EndIMEComposition();
|
2010-06-29 21:05:12 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void SwitchTextDirectionTo(uint32_t aDirection);
|
2011-09-15 07:54:50 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2011-09-15 07:54:50 -07:00
|
|
|
nsresult DetermineCurrentDirection();
|
2014-01-17 07:31:18 -08:00
|
|
|
void FireInputEvent();
|
2011-09-15 07:54:50 -07:00
|
|
|
|
2014-08-29 04:43:23 -07:00
|
|
|
/** Create a transaction for setting aAttribute to aValue on aElement. Never
|
|
|
|
* returns null.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2014-08-29 04:43:23 -07:00
|
|
|
already_AddRefed<mozilla::dom::ChangeAttributeTxn>
|
|
|
|
CreateTxnForSetAttribute(mozilla::dom::Element& aElement,
|
|
|
|
nsIAtom& aAttribute, const nsAString& aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-29 04:43:23 -07:00
|
|
|
/** Create a transaction for removing aAttribute on aElement. Never returns
|
|
|
|
* null.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2014-08-29 04:43:23 -07:00
|
|
|
already_AddRefed<mozilla::dom::ChangeAttributeTxn>
|
|
|
|
CreateTxnForRemoveAttribute(mozilla::dom::Element& aElement,
|
|
|
|
nsIAtom& aAttribute);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** create a transaction for creating a new child node of aParent of type aTag.
|
|
|
|
*/
|
2014-08-20 05:25:16 -07:00
|
|
|
already_AddRefed<mozilla::dom::CreateElementTxn>
|
|
|
|
CreateTxnForCreateElement(nsIAtom& aTag,
|
|
|
|
nsINode& aParent,
|
|
|
|
int32_t aPosition);
|
|
|
|
|
|
|
|
already_AddRefed<mozilla::dom::Element> CreateNode(nsIAtom* aTag,
|
|
|
|
nsINode* aParent,
|
|
|
|
int32_t aPosition);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** create a transaction for inserting aNode as a child of aParent.
|
|
|
|
*/
|
2014-08-20 05:25:17 -07:00
|
|
|
already_AddRefed<mozilla::dom::InsertNodeTxn>
|
|
|
|
CreateTxnForInsertNode(nsIContent& aNode, nsINode& aParent, int32_t aOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-19 06:23:36 -07:00
|
|
|
/** create a transaction for removing aNode from its parent.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2012-06-19 06:23:36 -07:00
|
|
|
nsresult CreateTxnForDeleteNode(nsINode* aNode, DeleteNodeTxn** aTxn);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2012-06-12 08:44:44 -07:00
|
|
|
nsresult CreateTxnForDeleteSelection(EDirection aAction,
|
|
|
|
EditAggregateTxn** aTxn,
|
|
|
|
nsINode** aNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aOffset,
|
|
|
|
int32_t* aLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-12 08:44:44 -07:00
|
|
|
nsresult CreateTxnForDeleteInsertionPoint(nsRange* aRange,
|
|
|
|
EDirection aAction,
|
|
|
|
EditAggregateTxn* aTxn,
|
|
|
|
nsINode** aNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aOffset,
|
|
|
|
int32_t* aLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2014-08-29 04:43:23 -07:00
|
|
|
/** Create a transaction for inserting aStringToInsert into aTextNode. Never
|
|
|
|
* returns null.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2014-08-29 04:43:23 -07:00
|
|
|
already_AddRefed<mozilla::dom::InsertTextTxn>
|
|
|
|
CreateTxnForInsertText(const nsAString& aStringToInsert,
|
|
|
|
mozilla::dom::Text& aTextNode, int32_t aOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-29 04:43:24 -07:00
|
|
|
// Never returns null.
|
|
|
|
already_AddRefed<mozilla::dom::IMETextTxn>
|
|
|
|
CreateTxnForIMEText(const nsAString & aStringToInsert);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** create a transaction for adding a style sheet
|
|
|
|
*/
|
2014-06-20 03:32:49 -07:00
|
|
|
NS_IMETHOD CreateTxnForAddStyleSheet(mozilla::CSSStyleSheet* aSheet,
|
|
|
|
AddStyleSheetTxn* *aTxn);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** create a transaction for removing a style sheet
|
|
|
|
*/
|
2014-06-20 03:32:49 -07:00
|
|
|
NS_IMETHOD CreateTxnForRemoveStyleSheet(mozilla::CSSStyleSheet* aSheet,
|
|
|
|
RemoveStyleSheetTxn* *aTxn);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-20 05:25:16 -07:00
|
|
|
nsresult DeleteText(nsGenericDOMDataNode& aElement,
|
|
|
|
uint32_t aOffset, uint32_t aLength);
|
2014-05-02 05:15:27 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// NS_IMETHOD DeleteRange(nsIDOMRange *aRange);
|
|
|
|
|
2014-08-20 05:25:16 -07:00
|
|
|
already_AddRefed<mozilla::dom::DeleteTextTxn>
|
|
|
|
CreateTxnForDeleteText(nsGenericDOMDataNode& aElement,
|
|
|
|
uint32_t aOffset, uint32_t aLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-20 05:25:16 -07:00
|
|
|
already_AddRefed<mozilla::dom::DeleteTextTxn>
|
|
|
|
CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData, uint32_t aOffset,
|
|
|
|
EDirection aDirection);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-11-02 04:04:13 -08:00
|
|
|
already_AddRefed<mozilla::dom::SplitNodeTxn>
|
|
|
|
CreateTxnForSplitNode(nsIContent& aNode, uint32_t aOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-11-02 04:04:12 -08:00
|
|
|
already_AddRefed<mozilla::dom::JoinNodeTxn>
|
|
|
|
CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-21 05:54:26 -07: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();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// called after a transaction is done successfully
|
2012-07-05 00:45:09 -07:00
|
|
|
void DoAfterDoTransaction(nsITransaction *aTxn);
|
2007-03-22 10:30:00 -07:00
|
|
|
// called after a transaction is undone successfully
|
2012-07-05 00:45:09 -07:00
|
|
|
void DoAfterUndoTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
// called after a transaction is redone successfully
|
2012-07-05 00:45:09 -07:00
|
|
|
void DoAfterRedoTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
eDocumentCreated,
|
|
|
|
eDocumentToBeDestroyed,
|
|
|
|
eDocumentStateChanged
|
|
|
|
} TDocumentListenerNotification;
|
|
|
|
|
|
|
|
// tell the doc state listeners that the doc state has changed
|
|
|
|
NS_IMETHOD NotifyDocumentListeners(TDocumentListenerNotification aNotificationType);
|
|
|
|
|
|
|
|
/** make the given selection span the entire document */
|
2014-11-02 04:04:13 -08:00
|
|
|
virtual nsresult SelectEntireDocument(mozilla::dom::Selection* aSelection);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** helper method for scrolling the selection into view after
|
2011-10-17 07:59:28 -07:00
|
|
|
* an edit operation. aScrollToAnchor should be true if you
|
2007-03-22 10:30:00 -07:00
|
|
|
* want to scroll to the point where the selection was started.
|
2011-10-17 07:59:28 -07:00
|
|
|
* If false, it attempts to scroll the end of the selection into view.
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD ScrollSelectionIntoView(bool aScrollToAnchor);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-01 12:53:16 -07:00
|
|
|
// Convenience method; forwards to IsBlockNode(nsINode*).
|
|
|
|
bool IsBlockNode(nsIDOMNode* aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
// stub. see comment in source.
|
2012-07-01 12:53:16 -07:00
|
|
|
virtual bool IsBlockNode(nsINode* aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-28 04:54:03 -08:00
|
|
|
// helper for GetPriorNode and GetNextNode
|
|
|
|
nsIContent* FindNextLeafNode(nsINode *aCurrentNode,
|
|
|
|
bool aGoForward,
|
2012-05-06 00:53:11 -07:00
|
|
|
bool bNoBlockCrossing);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// install the event listeners for the editor
|
2010-04-19 05:20:42 -07:00
|
|
|
virtual nsresult InstallEventListeners();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-15 03:18:35 -07:00
|
|
|
virtual void CreateEventListeners();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// unregister and release our event listeners
|
|
|
|
virtual void RemoveEventListeners();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if spellchecking should be enabled for this editor.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool GetDesiredSpellCheckState();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool CanEnableSpellCheck()
|
2010-08-19 04:27:04 -07:00
|
|
|
{
|
|
|
|
// Check for password/readonly/disabled, which are not spellchecked
|
2011-10-16 19:06:24 -07:00
|
|
|
// regardless of DOM. Also, check to see if spell check should be skipped or not.
|
|
|
|
return !IsPasswordEditor() && !IsReadonly() && !IsDisabled() && !ShouldSkipSpellCheck();
|
2010-08-19 04:27:04 -07:00
|
|
|
}
|
|
|
|
|
2014-02-12 05:02:55 -08:00
|
|
|
/**
|
2014-10-07 03:01:47 -07:00
|
|
|
* EnsureComposition() should be called by composition event handlers. This
|
|
|
|
* tries to get the composition for the event and set it to mComposition.
|
2014-02-12 05:02:55 -08:00
|
|
|
*/
|
|
|
|
void EnsureComposition(mozilla::WidgetGUIEvent* aEvent);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
|
|
|
|
/** 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();
|
|
|
|
|
|
|
|
/** routines for managing the preservation of selection across
|
|
|
|
* various editor actions */
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ArePreservingSelection();
|
2014-04-10 09:09:40 -07:00
|
|
|
void PreserveSelectionAcrossActions(mozilla::dom::Selection* aSel);
|
2014-11-02 04:04:13 -08:00
|
|
|
nsresult RestorePreservedSelection(mozilla::dom::Selection* aSel);
|
2007-03-22 10:30:00 -07:00
|
|
|
void StopPreservingSelection();
|
|
|
|
|
|
|
|
/**
|
2014-11-02 04:04:13 -08: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.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2014-11-02 04:04:13 -08:00
|
|
|
nsresult SplitNodeImpl(nsIContent& aExistingRightNode,
|
|
|
|
int32_t aOffset,
|
|
|
|
nsIContent& aNewLeftNode);
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
* There is no requirement that the two nodes be of the same type.
|
|
|
|
* @param aParent The parent of aNodeToKeep
|
|
|
|
*/
|
2013-07-24 00:39:08 -07:00
|
|
|
nsresult JoinNodesImpl(nsINode* aNodeToKeep,
|
|
|
|
nsINode* aNodeToJoin,
|
|
|
|
nsINode* aParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2012-07-02 04:42:19 -07:00
|
|
|
* Return the offset of aChild in aParent. Asserts fatally if parent or
|
|
|
|
* child is null, or parent is not child's parent.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t GetChildOffset(nsIDOMNode *aChild,
|
2012-07-02 04:42:19 -07:00
|
|
|
nsIDOMNode *aParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2012-07-08 17:45:12 -07:00
|
|
|
* Set outOffset to the offset of aChild in the parent.
|
|
|
|
* Returns the parent of aChild.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2012-07-08 17:45:12 -07:00
|
|
|
static already_AddRefed<nsIDOMNode> GetNodeLocation(nsIDOMNode* aChild,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* outOffset);
|
2013-07-10 03:03:38 -07:00
|
|
|
static nsINode* GetNodeLocation(nsINode* aChild, int32_t* aOffset);
|
2007-03-22 10:30:00 -07: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 08:56:38 -07:00
|
|
|
static nsresult GetLengthOfDOMNode(nsIDOMNode *aNode, uint32_t &aCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** get the node immediately prior to aCurrentNode
|
|
|
|
* @param aCurrentNode the node from which we start the search
|
2011-10-17 07:59:28 -07:00
|
|
|
* @param aEditableNode if true, only return an editable node
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aResultNode [OUT] the node that occurs before aCurrentNode in the tree,
|
2011-10-17 07:59:28 -07:00
|
|
|
* skipping non-editable nodes if aEditableNode is true.
|
2012-07-30 07:20:58 -07:00
|
|
|
* If there is no prior node, aResultNode will be nullptr.
|
2011-11-28 04:54:32 -08:00
|
|
|
* @param bNoBlockCrossing If true, don't move across "block" nodes, whatever that means.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2012-05-05 02:00:05 -07:00
|
|
|
nsIContent* GetPriorNode(nsINode* aCurrentNode, bool aEditableNode,
|
2012-05-06 00:53:11 -07:00
|
|
|
bool aNoBlockCrossing = false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// and another version that takes a {parent,offset} pair rather than a node
|
2012-05-05 02:00:05 -07:00
|
|
|
nsIContent* GetPriorNode(nsINode* aParentNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aOffset,
|
2012-05-05 02:00:05 -07:00
|
|
|
bool aEditableNode,
|
2012-05-06 00:53:11 -07:00
|
|
|
bool aNoBlockCrossing = false);
|
2012-05-05 02:00:05 -07:00
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/** get the node immediately after to aCurrentNode
|
|
|
|
* @param aCurrentNode the node from which we start the search
|
2011-10-17 07:59:28 -07:00
|
|
|
* @param aEditableNode if true, only return an editable node
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aResultNode [OUT] the node that occurs after aCurrentNode in the tree,
|
2011-10-17 07:59:28 -07:00
|
|
|
* skipping non-editable nodes if aEditableNode is true.
|
2012-07-30 07:20:58 -07:00
|
|
|
* If there is no prior node, aResultNode will be nullptr.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2012-02-01 02:54:22 -08:00
|
|
|
nsIContent* GetNextNode(nsINode* aCurrentNode,
|
|
|
|
bool aEditableNode,
|
2012-05-06 00:53:11 -07:00
|
|
|
bool bNoBlockCrossing = false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// and another version that takes a {parent,offset} pair rather than a node
|
2012-05-05 02:00:05 -07:00
|
|
|
nsIContent* GetNextNode(nsINode* aParentNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aOffset,
|
2012-05-05 02:00:05 -07:00
|
|
|
bool aEditableNode,
|
2012-05-06 00:53:11 -07:00
|
|
|
bool aNoBlockCrossing = false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-28 04:54:14 -08:00
|
|
|
// Helper for GetNextNode and GetPriorNode
|
|
|
|
nsIContent* FindNode(nsINode *aCurrentNode,
|
|
|
|
bool aGoForward,
|
|
|
|
bool aEditableNode,
|
2012-05-06 00:53:11 -07:00
|
|
|
bool bNoBlockCrossing);
|
2011-08-11 06:29:59 -07:00
|
|
|
/**
|
|
|
|
* Get the rightmost child of aCurrentNode;
|
2012-07-30 07:20:58 -07:00
|
|
|
* return nullptr if aCurrentNode has no children.
|
2011-08-11 06:29:59 -07:00
|
|
|
*/
|
2011-11-28 04:53:29 -08:00
|
|
|
nsIContent* GetRightmostChild(nsINode *aCurrentNode,
|
|
|
|
bool bNoBlockCrossing = false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-11 06:29:59 -07:00
|
|
|
/**
|
|
|
|
* Get the leftmost child of aCurrentNode;
|
2012-07-30 07:20:58 -07:00
|
|
|
* return nullptr if aCurrentNode has no children.
|
2011-08-11 06:29:59 -07:00
|
|
|
*/
|
2011-11-28 04:53:29 -08:00
|
|
|
nsIContent* GetLeftmostChild(nsINode *aCurrentNode,
|
|
|
|
bool bNoBlockCrossing = false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
/** returns true if aNode is of the type implied by aTag */
|
2011-09-28 23:19:26 -07:00
|
|
|
static inline bool NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return GetTag(aNode) == aTag;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
/** returns true if aParent can contain a child of type aTag */
|
2014-11-02 04:04:13 -08: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
/** returns true if aNode is our root node */
|
2012-05-01 03:01:28 -07:00
|
|
|
bool IsRoot(nsIDOMNode* inNode);
|
|
|
|
bool IsRoot(nsINode* inNode);
|
2012-05-06 00:53:11 -07:00
|
|
|
bool IsEditorRoot(nsINode* aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
/** returns true if aNode is a descendant of our root node */
|
2012-05-01 03:01:28 -07:00
|
|
|
bool IsDescendantOfRoot(nsIDOMNode* inNode);
|
|
|
|
bool IsDescendantOfRoot(nsINode* inNode);
|
2012-05-06 00:53:11 -07:00
|
|
|
bool IsDescendantOfEditorRoot(nsIDOMNode* aNode);
|
2012-05-06 00:53:11 -07:00
|
|
|
bool IsDescendantOfEditorRoot(nsINode* aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
/** returns true if aNode is a container */
|
2014-04-28 04:54:46 -07:00
|
|
|
virtual bool IsContainer(nsINode* aNode);
|
|
|
|
virtual bool IsContainer(nsIDOMNode* aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
/** returns true if aNode is an editable node */
|
2011-10-25 19:32:55 -07:00
|
|
|
bool IsEditable(nsIDOMNode *aNode);
|
2014-04-28 09:03:12 -07:00
|
|
|
virtual bool IsEditable(nsINode* aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
/** returns true if aNode is a MozEditorBogus node */
|
2014-04-28 09:03:12 -07:00
|
|
|
bool IsMozEditorBogusNode(nsINode* aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** counts number of editable child nodes */
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t CountEditableChildren(nsINode* aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-01 02:54:22 -08:00
|
|
|
/** Find the deep first and last children. */
|
|
|
|
nsINode* GetFirstEditableNode(nsINode* aRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-12 05:02:56 -08:00
|
|
|
/**
|
|
|
|
* Returns current composition.
|
|
|
|
*/
|
|
|
|
mozilla::TextComposition* GetComposition() const;
|
2014-02-12 05:02:56 -08:00
|
|
|
/**
|
|
|
|
* Returns true if there is composition string and not fixed.
|
|
|
|
*/
|
|
|
|
bool IsIMEComposing() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** from html rules code - migration in progress */
|
|
|
|
static nsresult GetTagString(nsIDOMNode *aNode, nsAString& outString);
|
|
|
|
static nsIAtom *GetTag(nsIDOMNode *aNode);
|
2012-05-18 01:29:38 -07:00
|
|
|
|
|
|
|
bool NodesSameType(nsIDOMNode *aNode1, nsIDOMNode *aNode2);
|
|
|
|
virtual bool AreNodesSameType(nsIContent* aNode1, nsIContent* aNode2);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsTextNode(nsIDOMNode *aNode);
|
2011-11-28 04:53:29 -08:00
|
|
|
static bool IsTextNode(nsINode *aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static nsCOMPtr<nsIDOMNode> GetChildAt(nsIDOMNode *aParent, int32_t aOffset);
|
|
|
|
static nsCOMPtr<nsIDOMNode> GetNodeAtRangeOffsetPoint(nsIDOMNode* aParentOrNode, int32_t aOffset);
|
2011-07-14 08:25:07 -07:00
|
|
|
|
2014-11-02 04:04:13 -08:00
|
|
|
static nsresult GetStartNodeAndOffset(mozilla::dom::Selection* aSelection,
|
|
|
|
nsIDOMNode** outStartNode,
|
|
|
|
int32_t* outStartOffset);
|
2014-04-10 09:09:40 -07:00
|
|
|
static nsresult GetStartNodeAndOffset(mozilla::dom::Selection* aSelection,
|
2013-07-24 00:39:08 -07:00
|
|
|
nsINode** aStartNode,
|
|
|
|
int32_t* aStartOffset);
|
2014-11-02 04:04:13 -08:00
|
|
|
static nsresult GetEndNodeAndOffset(mozilla::dom::Selection* aSelection,
|
|
|
|
nsIDOMNode** outEndNode,
|
|
|
|
int32_t* outEndOffset);
|
2014-04-10 09:09:40 -07:00
|
|
|
static nsresult GetEndNodeAndOffset(mozilla::dom::Selection* aSelection,
|
2013-07-24 00:39:08 -07:00
|
|
|
nsINode** aEndNode,
|
|
|
|
int32_t* aEndOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
#if DEBUG_JOE
|
2012-08-22 08:56:38 -07:00
|
|
|
static void DumpNode(nsIDOMNode *aNode, int32_t indent=0);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2014-04-10 09:09:40 -07:00
|
|
|
mozilla::dom::Selection* GetSelection();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Helpers to add a node to the selection.
|
|
|
|
// Used by table cell selection methods
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult CreateRange(nsIDOMNode *aStartParent, int32_t aStartOffset,
|
|
|
|
nsIDOMNode *aEndParent, int32_t aEndOffset,
|
2014-11-02 04:04:13 -08:00
|
|
|
nsRange** aRange);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Creates a range with just the supplied node and appends that to the selection
|
|
|
|
nsresult AppendNodeToSelectionAsRange(nsIDOMNode *aNode);
|
|
|
|
// When you are using AppendNodeToSelectionAsRange, call this first to start a new selection
|
|
|
|
nsresult ClearSelection();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult IsPreformatted(nsIDOMNode *aNode, bool *aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult SplitNodeDeep(nsIDOMNode *aNode,
|
|
|
|
nsIDOMNode *aSplitPointParent,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aSplitPointOffset,
|
|
|
|
int32_t *outOffset,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNoEmptyContainers = false,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMNode> *outLeftNode = 0,
|
|
|
|
nsCOMPtr<nsIDOMNode> *outRightNode = 0);
|
2014-11-02 04:04:13 -08:00
|
|
|
::DOMPoint JoinNodeDeep(nsIContent& aLeftNode, nsIContent& aRightNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult GetString(const nsAString& name, nsAString& value);
|
|
|
|
|
2012-06-01 04:03:17 -07:00
|
|
|
void BeginUpdateViewBatch(void);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual nsresult EndUpdateViewBatch(void);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool GetShouldTxnSetSelection();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-09 18:16:58 -07:00
|
|
|
virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
|
|
|
|
|
2012-08-12 11:28:26 -07:00
|
|
|
nsresult HandleInlineSpellCheck(EditAction action,
|
2014-11-02 04:04:13 -08:00
|
|
|
mozilla::dom::Selection* aSelection,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDOMNode *previousSelectedNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t previousSelectedOffset,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDOMNode *aStartNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aStartOffset,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDOMNode *aEndNode,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aEndOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-10-22 16:32:04 -07:00
|
|
|
virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget() = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Fast non-refcounting editor root element accessor
|
2011-12-03 13:50:15 -08:00
|
|
|
mozilla::dom::Element *GetRoot();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-06 00:53:11 -07:00
|
|
|
// Likewise, but gets the editor's root instead, which is different for HTML
|
|
|
|
// editors
|
|
|
|
virtual mozilla::dom::Element* GetEditorRoot();
|
|
|
|
|
2014-01-17 07:31:03 -08:00
|
|
|
// Likewise, but gets the text control element instead of the root for
|
|
|
|
// plaintext editors
|
|
|
|
mozilla::dom::Element* GetExposedRoot();
|
|
|
|
|
2010-04-11 19:35:18 -07:00
|
|
|
// Accessor methods to flags
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsPlaintextEditor() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorPlaintextMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsSingleLineEditor() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorSingleLineMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsPasswordEditor() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorPasswordMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsReadonly() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorReadonlyMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsDisabled() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorDisabledMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsInputFiltered() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorFilterInputMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsMailEditor() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorMailMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsWrapHackEnabled() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorEnableWrapHackMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsFormWidget() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorWidgetMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool NoCSS() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorNoCSSMask) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsInteractionAllowed() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorAllowInteraction) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool DontEchoPassword() const
|
2010-04-11 19:35:18 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorDontEchoPassword) != 0;
|
|
|
|
}
|
2011-10-16 19:06:24 -07:00
|
|
|
|
2012-04-04 02:15:10 -07:00
|
|
|
bool ShouldSkipSpellCheck() const
|
2011-10-16 19:06:24 -07:00
|
|
|
{
|
|
|
|
return (mFlags & nsIPlaintextEditor::eEditorSkipSpellCheck) != 0;
|
|
|
|
}
|
2010-04-11 19:35:18 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsTabbable() const
|
2010-06-09 18:16:58 -07:00
|
|
|
{
|
|
|
|
return IsSingleLineEditor() || IsPasswordEditor() || IsFormWidget() ||
|
|
|
|
IsInteractionAllowed();
|
|
|
|
}
|
|
|
|
|
2013-05-17 17:07:46 -07:00
|
|
|
bool HasIndependentSelection() const
|
|
|
|
{
|
|
|
|
return !!mSelConWeak;
|
|
|
|
}
|
|
|
|
|
2012-03-26 18:36:44 -07:00
|
|
|
// Get the input event target. This might return null.
|
|
|
|
virtual already_AddRefed<nsIContent> GetInputEventTargetContent() = 0;
|
|
|
|
|
2010-10-29 09:30:52 -07:00
|
|
|
// Get the focused content, if we're focused. Returns null otherwise.
|
|
|
|
virtual already_AddRefed<nsIContent> GetFocusedContent();
|
2010-05-04 10:40:39 -07:00
|
|
|
|
2014-03-07 17:20:07 -08:00
|
|
|
// Get the focused content for the argument of some IMEStateManager's
|
2012-11-09 00:40:39 -08:00
|
|
|
// methods.
|
|
|
|
virtual already_AddRefed<nsIContent> GetFocusedContentForIME();
|
|
|
|
|
2010-07-22 09:22:44 -07:00
|
|
|
// Whether the editor is active on the DOM window. Note that when this
|
2010-10-29 09:30:52 -07:00
|
|
|
// returns true but GetFocusedContent() returns null, it means that this editor was
|
2010-07-22 09:22:44 -07:00
|
|
|
// focused when the DOM window was active.
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool IsActiveInDOMWindow();
|
2010-07-22 09:22:44 -07:00
|
|
|
|
|
|
|
// Whether the aEvent should be handled by this editor or not. When this
|
|
|
|
// returns FALSE, The aEvent shouldn't be handled on this editor,
|
|
|
|
// i.e., The aEvent should be handled by another inner editor or ancestor
|
|
|
|
// elements.
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool IsAcceptableInputEvent(nsIDOMEvent* aEvent);
|
2010-07-22 09:22:44 -07:00
|
|
|
|
2010-06-16 22:30:42 -07: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
|
2013-04-02 17:13:10 -07:00
|
|
|
// target isn't a part of this editor, returns nullptr. If this is for
|
2010-06-16 22:30:42 -07:00
|
|
|
// designMode, you should set the document node to aNode except that an
|
|
|
|
// element in the document has focus.
|
|
|
|
virtual already_AddRefed<nsIContent> FindSelectionRoot(nsINode* aNode);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
nsresult InitializeSelection(nsIDOMEventTarget* aFocusEventTarget);
|
|
|
|
|
2011-08-12 12:12:45 -07:00
|
|
|
// This method has to be called by nsEditorEventListener::Focus.
|
|
|
|
// All actions that have to be done when the editor is focused needs to be
|
|
|
|
// added here.
|
|
|
|
void OnFocus(nsIDOMEventTarget* aFocusEventTarget);
|
|
|
|
|
2012-02-17 06:16:59 -08: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.
|
2013-07-09 10:54:21 -07:00
|
|
|
virtual nsresult InsertFromDataTransfer(mozilla::dom::DataTransfer *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) = 0;
|
|
|
|
|
|
|
|
virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent) = 0;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
virtual already_AddRefed<nsIDOMNode> FindUserSelectAllNode(nsIDOMNode* aNode) { return nullptr; }
|
2012-02-17 06:16:59 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
enum Tristate {
|
|
|
|
eTriUnset,
|
|
|
|
eTriFalse,
|
|
|
|
eTriTrue
|
2012-04-23 21:54:11 -07:00
|
|
|
};
|
|
|
|
// Spellchecking
|
|
|
|
nsCString mContentMIMEType; // MIME type of the doc we are editing.
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIInlineSpellChecker> mInlineSpellChecker;
|
|
|
|
|
2012-06-19 06:23:36 -07:00
|
|
|
nsRefPtr<nsTransactionManager> mTxnMgr;
|
2012-04-23 21:54:11 -07:00
|
|
|
nsCOMPtr<mozilla::dom::Element> mRootElement; // cached root node
|
2014-08-29 04:43:24 -07:00
|
|
|
nsRefPtr<mozilla::dom::Text> mIMETextNode; // current IME text node
|
2013-10-22 16:32:04 -07:00
|
|
|
nsCOMPtr<mozilla::dom::EventTarget> mEventTarget; // The form field as an event receiver
|
2012-04-23 21:54:11 -07:00
|
|
|
nsCOMPtr<nsIDOMEventListener> mEventListener;
|
|
|
|
nsWeakPtr mSelConWeak; // weak reference to the nsISelectionController
|
|
|
|
nsWeakPtr mPlaceHolderTxn; // weak reference to placeholder for begin/end batch purposes
|
|
|
|
nsWeakPtr mDocWeak; // weak reference to the nsIDOMDocument
|
|
|
|
nsIAtom *mPlaceHolderName; // name of placeholder transaction
|
|
|
|
nsSelectionState *mSelState; // saved selection state for placeholder txn batching
|
|
|
|
nsString *mPhonetic;
|
2014-02-12 05:02:55 -08:00
|
|
|
// IME composition this is not null between compositionstart and
|
|
|
|
// compositionend.
|
|
|
|
nsRefPtr<mozilla::TextComposition> mComposition;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-23 21:54:11 -07:00
|
|
|
// various listeners
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMArray<nsIEditActionListener> mActionListeners; // listens to all low level actions on the doc
|
2012-11-14 11:23:35 -08:00
|
|
|
nsCOMArray<nsIEditorObserver> mEditorObservers; // just notify once per high level change
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMArray<nsIDocumentStateListener> mDocStateListeners;// listen to overall doc state (dirty or not, just created, etc)
|
|
|
|
|
2012-04-23 21:54:11 -07:00
|
|
|
nsSelectionState mSavedSel; // cached selection for nsAutoSelectionReset
|
|
|
|
nsRangeUpdater mRangeUpdater; // utility class object for maintaining preserved ranges
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mModCount; // number of modifications (for undo/redo stack)
|
|
|
|
uint32_t mFlags; // behavior flags. See nsIPlaintextEditor.idl for the flags we use.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mUpdateCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mPlaceHolderBatch; // nesting count for batching
|
2012-08-12 11:28:26 -07:00
|
|
|
EditAction mAction; // the current editor action
|
2012-04-23 21:54:11 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mIMETextOffset; // offset in text node where IME comp string begins
|
2012-04-23 21:54:11 -07:00
|
|
|
|
|
|
|
EDirection mDirection; // the current direction of editor action
|
2012-08-22 08:56:38 -07:00
|
|
|
int8_t mDocDirtyState; // -1 = not initialized
|
|
|
|
uint8_t mSpellcheckCheckboxState; // a Tristate value
|
2012-04-23 21:54:11 -07:00
|
|
|
|
|
|
|
bool mShouldTxnSetSelection; // turn off for conservative selection adjustment by txns
|
|
|
|
bool mDidPreDestroy; // whether PreDestroy has been called
|
|
|
|
bool mDidPostCreate; // whether PostCreate has been called
|
2012-03-26 18:36:44 -07:00
|
|
|
bool mDispatchInputEvent;
|
2014-08-19 04:54:08 -07:00
|
|
|
bool mIsInEditAction; // true while the instance is handling an edit action
|
2010-12-06 22:30:05 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
friend bool NSCanUnload(nsISupports* serviceMgr);
|
2007-03-22 10:30:00 -07:00
|
|
|
friend class nsAutoTxnsConserveSelection;
|
|
|
|
friend class nsAutoSelectionReset;
|
|
|
|
friend class nsAutoRules;
|
|
|
|
friend class nsRangeUpdater;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|