--- a/dom/events/ContentEventHandler.cpp
+++ b/dom/events/ContentEventHandler.cpp
@@ -155,17 +155,17 @@ ContentEventHandler::InitRootContent(Sel
RefPtr<nsRange> range(aNormalSelection->GetRangeAt(0));
if (NS_WARN_IF(!range)) {
return NS_ERROR_UNEXPECTED;
}
// If there is a selection, we should retrieve the selection root from
// the range since when the window is inactivated, the ancestor limiter
- // of selection was cleared by blur event handler of nsEditor but the
+ // of selection was cleared by blur event handler of EditorBase but the
// selection range still keeps storing the nodes. If the active element of
// the deactive window is <input> or <textarea>, we can compute the
// selection root from them.
nsINode* startNode = range->GetStartParent();
nsINode* endNode = range->GetEndParent();
if (NS_WARN_IF(!startNode) || NS_WARN_IF(!endNode)) {
return NS_ERROR_FAILURE;
}
@@ -2049,17 +2049,17 @@ ContentEventHandler::AdjustCollapsedRang
// If the node is text node, we don't need to modify aRange.
if (parentNode->IsNodeOfType(nsINode::eTEXT)) {
return NS_OK;
}
// If the parent is not a text node but it has a text node at the offset,
// we should adjust the range into the text node.
- // NOTE: This is emulating similar situation of nsEditor.
+ // NOTE: This is emulating similar situation of EditorBase.
nsINode* childNode = nullptr;
int32_t offsetInChildNode = -1;
if (!offsetInParentNode && parentNode->HasChildren()) {
// If the range is the start of the parent, adjusted the range to the
// start of the first child.
childNode = parentNode->GetFirstChild();
offsetInChildNode = 0;
} else if (static_cast<uint32_t>(offsetInParentNode) <
--- a/dom/events/EventNameList.h
+++ b/dom/events/EventNameList.h
@@ -714,17 +714,17 @@ NON_IDL_EVENT(warning,
NON_IDL_EVENT(speakerforcedchange,
eSpeakerForcedChange,
EventNameType_None,
eBasicEventClass)
// Events that only have on* attributes on XUL elements
- // "text" event is legacy event for modifying composition string in nsEditor.
+ // "text" event is legacy event for modifying composition string in EditorBase.
// This shouldn't be used by web/xul apps. "compositionupdate" should be
// used instead.
NON_IDL_EVENT(text,
eCompositionChange,
EventNameType_XUL,
eCompositionEventClass)
NON_IDL_EVENT(compositionstart,
eCompositionStart,
--- a/dom/events/IMEContentObserver.cpp
+++ b/dom/events/IMEContentObserver.cpp
@@ -636,17 +636,17 @@ IMEContentObserver::IsEditorHandlingEven
}
bool
IMEContentObserver::IsEditorComposing() const
{
// Note that don't use TextComposition here. The important thing is,
// whether the editor already started to handle composition because
// web contents can change selection, text content and/or something from
- // compositionstart event listener which is run before nsEditor handles it.
+ // compositionstart event listener which is run before EditorBase handles it.
nsCOMPtr<nsIEditorIMESupport> editorIMESupport = do_QueryInterface(mEditor);
if (NS_WARN_IF(!editorIMESupport)) {
return false;
}
bool isComposing = false;
nsresult rv = editorIMESupport->GetComposing(&isComposing);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
--- a/dom/events/IMEStateManager.cpp
+++ b/dom/events/IMEStateManager.cpp
@@ -875,18 +875,18 @@ IMEStateManager::GetNewIMEState(nsPresCo
}
MOZ_LOG(sISMLog, LogLevel::Debug,
(" GetNewIMEState() returns DISABLED because "
"no content has focus"));
return IMEState(IMEState::DISABLED);
}
// nsIContent::GetDesiredIMEState() may cause a call of UpdateIMEState()
- // from nsEditor::PostCreate() because GetDesiredIMEState() needs to retrieve
- // an editor instance for the element if it's editable element.
+ // from EditorBase::PostCreate() because GetDesiredIMEState() needs to
+ // retrieve an editor instance for the element if it's editable element.
// For avoiding such nested IME state updates, we should set
// sIsGettingNewIMEState here and UpdateIMEState() should check it.
GettingNewIMEStateBlocker blocker;
IMEState newIMEState = aContent->GetDesiredIMEState();
MOZ_LOG(sISMLog, LogLevel::Debug,
(" GetNewIMEState() returns { mEnabled=%s, "
"mOpen=%s }",
--- a/editor/libeditor/CompositionTransaction.cpp
+++ b/editor/libeditor/CompositionTransaction.cpp
@@ -1,42 +1,42 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "CompositionTransaction.h"
+#include "mozilla/EditorBase.h" // mEditorBase
#include "mozilla/dom/Selection.h" // local var
#include "mozilla/dom/Text.h" // mTextNode
#include "nsAString.h" // params
#include "nsDebug.h" // for NS_ASSERTION, etc
-#include "nsEditor.h" // mEditor
#include "nsError.h" // for NS_SUCCEEDED, NS_FAILED, etc
#include "nsIPresShell.h" // nsISelectionController constants
#include "nsRange.h" // local var
#include "nsQueryObject.h" // for do_QueryObject
namespace mozilla {
using namespace dom;
CompositionTransaction::CompositionTransaction(
Text& aTextNode,
uint32_t aOffset,
uint32_t aReplaceLength,
TextRangeArray* aTextRangeArray,
const nsAString& aStringToInsert,
- nsEditor& aEditor)
+ EditorBase& aEditorBase)
: mTextNode(&aTextNode)
, mOffset(aOffset)
, mReplaceLength(aReplaceLength)
, mRanges(aTextRangeArray)
, mStringToInsert(aStringToInsert)
- , mEditor(aEditor)
+ , mEditorBase(aEditorBase)
, mFixed(false)
{
}
CompositionTransaction::~CompositionTransaction()
{
}
@@ -53,17 +53,17 @@ NS_INTERFACE_MAP_END_INHERITING(EditTran
NS_IMPL_ADDREF_INHERITED(CompositionTransaction, EditTransactionBase)
NS_IMPL_RELEASE_INHERITED(CompositionTransaction, EditTransactionBase)
NS_IMETHODIMP
CompositionTransaction::DoTransaction()
{
// Fail before making any changes if there's no selection controller
nsCOMPtr<nsISelectionController> selCon;
- mEditor.GetSelectionController(getter_AddRefs(selCon));
+ mEditorBase.GetSelectionController(getter_AddRefs(selCon));
NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
// Advance caret: This requires the presentation shell to get the selection.
nsresult res;
if (mReplaceLength == 0) {
res = mTextNode->InsertData(mOffset, mStringToInsert);
} else {
res = mTextNode->ReplaceData(mOffset, mReplaceLength, mStringToInsert);
@@ -76,17 +76,17 @@ CompositionTransaction::DoTransaction()
return NS_OK;
}
NS_IMETHODIMP
CompositionTransaction::UndoTransaction()
{
// Get the selection first so we'll fail before making any changes if we
// can't get it
- RefPtr<Selection> selection = mEditor.GetSelection();
+ RefPtr<Selection> selection = mEditorBase.GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
nsresult res = mTextNode->DeleteData(mOffset, mStringToInsert.Length());
NS_ENSURE_SUCCESS(res, res);
// set the selection to the insertion point where the string was removed
res = selection->Collapse(mTextNode, mOffset);
NS_ASSERTION(NS_SUCCEEDED(res),
@@ -137,44 +137,44 @@ CompositionTransaction::GetTxnDescriptio
return NS_OK;
}
/* ============ private methods ================== */
nsresult
CompositionTransaction::SetSelectionForRanges()
{
- return SetIMESelection(mEditor, mTextNode, mOffset,
+ return SetIMESelection(mEditorBase, mTextNode, mOffset,
mStringToInsert.Length(), mRanges);
}
// static
nsresult
-CompositionTransaction::SetIMESelection(nsEditor& aEditor,
+CompositionTransaction::SetIMESelection(EditorBase& aEditorBase,
Text* aTextNode,
uint32_t aOffsetInNode,
uint32_t aLengthOfCompositionString,
const TextRangeArray* aRanges)
{
- RefPtr<Selection> selection = aEditor.GetSelection();
+ RefPtr<Selection> selection = aEditorBase.GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
nsresult rv = selection->StartBatchChanges();
NS_ENSURE_SUCCESS(rv, rv);
// First, remove all selections of IME composition.
static const RawSelectionType kIMESelections[] = {
nsISelectionController::SELECTION_IME_RAWINPUT,
nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT,
nsISelectionController::SELECTION_IME_CONVERTEDTEXT,
nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT
};
nsCOMPtr<nsISelectionController> selCon;
- aEditor.GetSelectionController(getter_AddRefs(selCon));
+ aEditorBase.GetSelectionController(getter_AddRefs(selCon));
NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
for (uint32_t i = 0; i < ArrayLength(kIMESelections); ++i) {
nsCOMPtr<nsISelection> selectionOfIME;
if (NS_FAILED(selCon->GetSelection(kIMESelections[i],
getter_AddRefs(selectionOfIME)))) {
continue;
}
@@ -197,30 +197,31 @@ CompositionTransaction::SetIMESelection(
// composition.
for (uint32_t i = 0; i < countOfRanges; ++i) {
const TextRange& textRange = aRanges->ElementAt(i);
// Caret needs special handling since its length may be 0 and if it's not
// specified explicitly, we need to handle it ourselves later.
if (textRange.mRangeType == TextRangeType::eCaret) {
NS_ASSERTION(!setCaret, "The ranges already has caret position");
- NS_ASSERTION(!textRange.Length(), "nsEditor doesn't support wide caret");
+ NS_ASSERTION(!textRange.Length(),
+ "EditorBase doesn't support wide caret");
int32_t caretOffset = static_cast<int32_t>(
aOffsetInNode +
std::min(textRange.mStartOffset, aLengthOfCompositionString));
MOZ_ASSERT(caretOffset >= 0 &&
static_cast<uint32_t>(caretOffset) <= maxOffset);
rv = selection->Collapse(aTextNode, caretOffset);
setCaret = setCaret || NS_SUCCEEDED(rv);
if (NS_WARN_IF(!setCaret)) {
continue;
}
// If caret range is specified explicitly, we should show the caret if
// it should be so.
- aEditor.HideCaret(false);
+ aEditorBase.HideCaret(false);
continue;
}
// If the clause length is 0, it should be a bug.
if (!textRange.Length()) {
NS_WARNING("Any clauses must not be empty");
continue;
}
@@ -282,17 +283,17 @@ CompositionTransaction::SetIMESelection(
MOZ_ASSERT(caretOffset >= 0 &&
static_cast<uint32_t>(caretOffset) <= maxOffset);
rv = selection->Collapse(aTextNode, caretOffset);
NS_ASSERTION(NS_SUCCEEDED(rv),
"Failed to set caret at the end of composition string");
// If caret range isn't specified explicitly, we should hide the caret.
// Hiding the caret benefits a Windows build (see bug 555642 comment #6).
- aEditor.HideCaret(true);
+ aEditorBase.HideCaret(true);
}
rv = selection->EndBatchChangesInternal();
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to end batch changes");
return rv;
}
--- a/editor/libeditor/CompositionTransaction.h
+++ b/editor/libeditor/CompositionTransaction.h
@@ -5,24 +5,23 @@
#ifndef CompositionTransaction_h
#define CompositionTransaction_h
#include "EditTransactionBase.h" // base class
#include "nsCycleCollectionParticipant.h" // various macros
#include "nsString.h" // mStringToInsert
-class nsEditor;
-
#define NS_IMETEXTTXN_IID \
{ 0xb391355d, 0x346c, 0x43d1, \
{ 0x85, 0xed, 0x9e, 0x65, 0xbe, 0xe7, 0x7e, 0x48 } }
namespace mozilla {
+class EditorBase;
class TextRangeArray;
namespace dom {
class Text;
} // namespace dom
/**
* CompositionTransaction stores all edit for a composition, i.e.,
@@ -38,36 +37,36 @@ public:
/**
* @param aTextNode The text content node.
* @param aOffset The location in aTextNode to do the insertion.
* @param aReplaceLength The length of text to replace. 0 means not
* replacing existing text.
* @param aTextRangeArray Clauses and/or caret information. This may be
* null.
* @param aString The new text to insert.
- * @param aEditor Used to get and set the selection.
+ * @param aEditorBase Used to get and set the selection.
*/
CompositionTransaction(dom::Text& aTextNode,
uint32_t aOffset, uint32_t aReplaceLength,
TextRangeArray* aTextRangeArray,
const nsAString& aString,
- nsEditor& aEditor);
+ EditorBase& aEditorBase);
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CompositionTransaction,
EditTransactionBase)
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_EDITTRANSACTIONBASE
NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
void MarkFixed();
- static nsresult SetIMESelection(nsEditor& aEditor,
+ static nsresult SetIMESelection(EditorBase& aEditorBase,
dom::Text* aTextNode,
uint32_t aOffsetInNode,
uint32_t aLengthOfCompositionString,
const TextRangeArray* aRanges);
private:
~CompositionTransaction();
@@ -83,17 +82,17 @@ private:
// The range list.
RefPtr<TextRangeArray> mRanges;
// The text to insert into mTextNode at mOffset.
nsString mStringToInsert;
// The editor, which is used to get the selection controller.
- nsEditor& mEditor;
+ EditorBase& mEditorBase;
bool mFixed;
};
NS_DEFINE_STATIC_IID_ACCESSOR(CompositionTransaction, NS_IMETEXTTXN_IID)
} // namespace mozilla
--- a/editor/libeditor/CreateElementTransaction.cpp
+++ b/editor/libeditor/CreateElementTransaction.cpp
@@ -7,42 +7,42 @@
#include <algorithm>
#include <stdio.h>
#include "mozilla/dom/Element.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/Casting.h"
+#include "mozilla/EditorBase.h"
#include "nsAlgorithm.h"
#include "nsAString.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsIContent.h"
#include "nsIDOMCharacterData.h"
#include "nsIEditor.h"
#include "nsINode.h"
#include "nsISupportsUtils.h"
#include "nsMemory.h"
#include "nsReadableUtils.h"
#include "nsStringFwd.h"
#include "nsString.h"
namespace mozilla {
using namespace dom;
-CreateElementTransaction::CreateElementTransaction(nsEditor& aEditor,
+CreateElementTransaction::CreateElementTransaction(EditorBase& aEditorBase,
nsIAtom& aTag,
nsINode& aParent,
int32_t aOffsetInParent)
: EditTransactionBase()
- , mEditor(&aEditor)
+ , mEditorBase(&aEditorBase)
, mTag(&aTag)
, mParent(&aParent)
, mOffsetInParent(aOffsetInParent)
{
}
CreateElementTransaction::~CreateElementTransaction()
{
@@ -58,23 +58,23 @@ NS_IMPL_ADDREF_INHERITED(CreateElementTr
NS_IMPL_RELEASE_INHERITED(CreateElementTransaction, EditTransactionBase)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CreateElementTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
NS_IMETHODIMP
CreateElementTransaction::DoTransaction()
{
- MOZ_ASSERT(mEditor && mTag && mParent);
+ MOZ_ASSERT(mEditorBase && mTag && mParent);
- mNewNode = mEditor->CreateHTMLContent(mTag);
+ mNewNode = mEditorBase->CreateHTMLContent(mTag);
NS_ENSURE_STATE(mNewNode);
// Try to insert formatting whitespace for the new node:
- mEditor->MarkNodeDirty(GetAsDOMNode(mNewNode));
+ mEditorBase->MarkNodeDirty(GetAsDOMNode(mNewNode));
// Insert the new node
ErrorResult rv;
if (mOffsetInParent == -1) {
mParent->AppendChild(*mNewNode, rv);
return rv.StealNSResult();
}
@@ -83,45 +83,45 @@ CreateElementTransaction::DoTransaction(
// Note, it's ok for mRefNode to be null. That means append
mRefNode = mParent->GetChildAt(mOffsetInParent);
mParent->InsertBefore(*mNewNode, mRefNode, rv);
NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
// Only set selection to insertion point if editor gives permission
- if (!mEditor->GetShouldTxnSetSelection()) {
+ if (!mEditorBase->GetShouldTxnSetSelection()) {
// Do nothing - DOM range gravity will adjust selection
return NS_OK;
}
- RefPtr<Selection> selection = mEditor->GetSelection();
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
rv = selection->CollapseNative(mParent, mParent->IndexOf(mNewNode) + 1);
NS_ASSERTION(!rv.Failed(),
"selection could not be collapsed after insert");
return NS_OK;
}
NS_IMETHODIMP
CreateElementTransaction::UndoTransaction()
{
- MOZ_ASSERT(mEditor && mParent);
+ MOZ_ASSERT(mEditorBase && mParent);
ErrorResult rv;
mParent->RemoveChild(*mNewNode, rv);
return rv.StealNSResult();
}
NS_IMETHODIMP
CreateElementTransaction::RedoTransaction()
{
- MOZ_ASSERT(mEditor && mParent);
+ MOZ_ASSERT(mEditorBase && mParent);
// First, reset mNewNode so it has no attributes or content
// XXX We never actually did this, we only cleared mNewNode's contents if it
// was a CharacterData node (which it's not, it's an Element)
// Now, reinsert mNewNode
ErrorResult rv;
mParent->InsertBefore(*mNewNode, mRefNode, rv);
--- a/editor/libeditor/CreateElementTransaction.h
+++ b/editor/libeditor/CreateElementTransaction.h
@@ -6,44 +6,44 @@
#ifndef CreateElementTransaction_h
#define CreateElementTransaction_h
#include "EditTransactionBase.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsISupportsImpl.h"
-class nsEditor;
class nsIAtom;
class nsIContent;
class nsINode;
/**
* A transaction that creates a new node in the content tree.
*/
namespace mozilla {
+class EditorBase;
namespace dom {
class Element;
} // namespace dom
class CreateElementTransaction final : public EditTransactionBase
{
public:
/**
* Initialize the transaction.
- * @param aEditor The provider of basic editing functionality.
+ * @param aEditorBase The provider of basic editing functionality.
* @param aTag The tag (P, HR, TABLE, etc.) for the new element.
* @param aParent The node into which the new element will be
* inserted.
* @param aOffsetInParent The location in aParent to insert the new element.
* If eAppend, the new element is appended as the last
* child.
*/
- CreateElementTransaction(nsEditor& aEditor,
+ CreateElementTransaction(EditorBase& aEditorBase,
nsIAtom& aTag,
nsINode& aParent,
int32_t aOffsetInParent);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CreateElementTransaction,
EditTransactionBase)
@@ -52,17 +52,17 @@ public:
NS_IMETHOD RedoTransaction() override;
already_AddRefed<dom::Element> GetNewNode();
protected:
virtual ~CreateElementTransaction();
// The document into which the new node will be inserted.
- nsEditor* mEditor;
+ EditorBase* mEditorBase;
// The tag (mapping to object type) for the new element.
nsCOMPtr<nsIAtom> mTag;
// The node into which the new node will be inserted.
nsCOMPtr<nsINode> mParent;
// The index in mParent for the new node.
--- a/editor/libeditor/DeleteNodeTransaction.cpp
+++ b/editor/libeditor/DeleteNodeTransaction.cpp
@@ -1,24 +1,24 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "DeleteNodeTransaction.h"
+#include "mozilla/EditorBase.h"
#include "mozilla/SelectionState.h" // RangeUpdater
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsAString.h"
namespace mozilla {
DeleteNodeTransaction::DeleteNodeTransaction()
- : mEditor(nullptr)
+ : mEditorBase(nullptr)
, mRangeUpdater(nullptr)
{
}
DeleteNodeTransaction::~DeleteNodeTransaction()
{
}
@@ -28,27 +28,27 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(Delet
mRefNode)
NS_IMPL_ADDREF_INHERITED(DeleteNodeTransaction, EditTransactionBase)
NS_IMPL_RELEASE_INHERITED(DeleteNodeTransaction, EditTransactionBase)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteNodeTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
nsresult
-DeleteNodeTransaction::Init(nsEditor* aEditor,
+DeleteNodeTransaction::Init(EditorBase* aEditorBase,
nsINode* aNode,
RangeUpdater* aRangeUpdater)
{
- NS_ENSURE_TRUE(aEditor && aNode, NS_ERROR_NULL_POINTER);
- mEditor = aEditor;
+ NS_ENSURE_TRUE(aEditorBase && aNode, NS_ERROR_NULL_POINTER);
+ mEditorBase = aEditorBase;
mNode = aNode;
mParent = aNode->GetParentNode();
// do nothing if the node has a parent and it's read-only
- NS_ENSURE_TRUE(!mParent || mEditor->IsModifiableNode(mParent),
+ NS_ENSURE_TRUE(!mParent || mEditorBase->IsModifiableNode(mParent),
NS_ERROR_FAILURE);
mRangeUpdater = aRangeUpdater;
return NS_OK;
}
NS_IMETHODIMP
DeleteNodeTransaction::DoTransaction()
--- a/editor/libeditor/DeleteNodeTransaction.h
+++ b/editor/libeditor/DeleteNodeTransaction.h
@@ -9,33 +9,32 @@
#include "EditTransactionBase.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIContent.h"
#include "nsINode.h"
#include "nsISupportsImpl.h"
#include "nscore.h"
-class nsEditor;
-
namespace mozilla {
+class EditorBase;
class RangeUpdater;
/**
* A transaction that deletes a single element
*/
class DeleteNodeTransaction final : public EditTransactionBase
{
public:
/**
* Initialize the transaction.
* @param aElement The node to delete.
*/
- nsresult Init(nsEditor* aEditor, nsINode* aNode,
+ nsresult Init(EditorBase* aEditorBase, nsINode* aNode,
RangeUpdater* aRangeUpdater);
DeleteNodeTransaction();
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteNodeTransaction,
EditTransactionBase)
@@ -51,17 +50,17 @@ protected:
// Parent of node to delete.
nsCOMPtr<nsINode> mParent;
// Next sibling to remember for undo/redo purposes.
nsCOMPtr<nsIContent> mRefNode;
// The editor for this transaction.
- nsEditor* mEditor;
+ EditorBase* mEditorBase;
// Range updater object.
RangeUpdater* mRangeUpdater;
};
} // namespace mozilla
#endif // #ifndef DeleteNodeTransaction_h
--- a/editor/libeditor/DeleteRangeTransaction.cpp
+++ b/editor/libeditor/DeleteRangeTransaction.cpp
@@ -3,71 +3,71 @@
* 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/. */
#include "DeleteRangeTransaction.h"
#include "DeleteNodeTransaction.h"
#include "DeleteTextTransaction.h"
#include "mozilla/Assertions.h"
+#include "mozilla/EditorBase.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/mozalloc.h"
#include "nsCOMPtr.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsIDOMCharacterData.h"
#include "nsINode.h"
#include "nsAString.h"
namespace mozilla {
using namespace dom;
-// note that aEditor is not refcounted
+// note that aEditorBase is not refcounted
DeleteRangeTransaction::DeleteRangeTransaction()
- : mEditor(nullptr)
+ : mEditorBase(nullptr)
, mRangeUpdater(nullptr)
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(DeleteRangeTransaction,
EditAggregateTransaction,
mRange)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteRangeTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditAggregateTransaction)
nsresult
-DeleteRangeTransaction::Init(nsEditor* aEditor,
+DeleteRangeTransaction::Init(EditorBase* aEditorBase,
nsRange* aRange,
RangeUpdater* aRangeUpdater)
{
- MOZ_ASSERT(aEditor && aRange);
+ MOZ_ASSERT(aEditorBase && aRange);
- mEditor = aEditor;
+ mEditorBase = aEditorBase;
mRange = aRange->CloneRange();
mRangeUpdater = aRangeUpdater;
- NS_ENSURE_TRUE(mEditor->IsModifiableNode(mRange->GetStartParent()),
+ NS_ENSURE_TRUE(mEditorBase->IsModifiableNode(mRange->GetStartParent()),
NS_ERROR_FAILURE);
- NS_ENSURE_TRUE(mEditor->IsModifiableNode(mRange->GetEndParent()),
+ NS_ENSURE_TRUE(mEditorBase->IsModifiableNode(mRange->GetEndParent()),
NS_ERROR_FAILURE);
- NS_ENSURE_TRUE(mEditor->IsModifiableNode(mRange->GetCommonAncestor()),
+ NS_ENSURE_TRUE(mEditorBase->IsModifiableNode(mRange->GetCommonAncestor()),
NS_ERROR_FAILURE);
return NS_OK;
}
NS_IMETHODIMP
DeleteRangeTransaction::DoTransaction()
{
- MOZ_ASSERT(mRange && mEditor);
+ MOZ_ASSERT(mRange && mEditorBase);
nsresult res;
// build the child transactions
nsCOMPtr<nsINode> startParent = mRange->GetStartParent();
int32_t startOffset = mRange->StartOffset();
nsCOMPtr<nsINode> endParent = mRange->GetEndParent();
int32_t endOffset = mRange->EndOffset();
MOZ_ASSERT(startParent && endParent);
@@ -90,40 +90,40 @@ DeleteRangeTransaction::DoTransaction()
}
// if we've successfully built this aggregate transaction, then do it.
res = EditAggregateTransaction::DoTransaction();
NS_ENSURE_SUCCESS(res, res);
// only set selection to deletion point if editor gives permission
bool bAdjustSelection;
- mEditor->ShouldTxnSetSelection(&bAdjustSelection);
+ mEditorBase->ShouldTxnSetSelection(&bAdjustSelection);
if (bAdjustSelection) {
- RefPtr<Selection> selection = mEditor->GetSelection();
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
res = selection->Collapse(startParent, startOffset);
NS_ENSURE_SUCCESS(res, res);
}
// else do nothing - dom range gravity will adjust selection
return NS_OK;
}
NS_IMETHODIMP
DeleteRangeTransaction::UndoTransaction()
{
- MOZ_ASSERT(mRange && mEditor);
+ MOZ_ASSERT(mRange && mEditorBase);
return EditAggregateTransaction::UndoTransaction();
}
NS_IMETHODIMP
DeleteRangeTransaction::RedoTransaction()
{
- MOZ_ASSERT(mRange && mEditor);
+ MOZ_ASSERT(mRange && mEditorBase);
return EditAggregateTransaction::RedoTransaction();
}
NS_IMETHODIMP
DeleteRangeTransaction::GetTxnDescription(nsAString& aString)
{
aString.AssignLiteral("DeleteRangeTransaction");
@@ -144,33 +144,33 @@ DeleteRangeTransaction::CreateTxnsToDele
} else {
numToDel = aEndOffset - aStartOffset;
}
RefPtr<nsGenericDOMDataNode> charDataNode =
static_cast<nsGenericDOMDataNode*>(aNode);
RefPtr<DeleteTextTransaction> transaction =
- new DeleteTextTransaction(*mEditor, *charDataNode, aStartOffset, numToDel,
- mRangeUpdater);
+ new DeleteTextTransaction(*mEditorBase, *charDataNode, aStartOffset,
+ numToDel, mRangeUpdater);
nsresult res = transaction->Init();
NS_ENSURE_SUCCESS(res, res);
AppendChild(transaction);
return NS_OK;
}
nsCOMPtr<nsIContent> child = aNode->GetChildAt(aStartOffset);
NS_ENSURE_STATE(child);
nsresult res = NS_OK;
for (int32_t i = aStartOffset; i < aEndOffset; ++i) {
RefPtr<DeleteNodeTransaction> transaction = new DeleteNodeTransaction();
- res = transaction->Init(mEditor, child, mRangeUpdater);
+ res = transaction->Init(mEditorBase, child, mRangeUpdater);
if (NS_SUCCEEDED(res)) {
AppendChild(transaction);
}
child = child->GetNextSibling();
}
NS_ENSURE_SUCCESS(res, res);
@@ -193,17 +193,17 @@ DeleteRangeTransaction::CreateTxnsToDele
start = 0;
numToDelete = aOffset;
}
if (numToDelete) {
RefPtr<nsGenericDOMDataNode> dataNode =
static_cast<nsGenericDOMDataNode*>(aNode);
RefPtr<DeleteTextTransaction> transaction =
- new DeleteTextTransaction(*mEditor, *dataNode, start, numToDelete,
+ new DeleteTextTransaction(*mEditorBase, *dataNode, start, numToDelete,
mRangeUpdater);
nsresult res = transaction->Init();
NS_ENSURE_SUCCESS(res, res);
AppendChild(transaction);
}
}
@@ -219,17 +219,17 @@ DeleteRangeTransaction::CreateTxnsToDele
nsresult res = iter->Init(mRange);
NS_ENSURE_SUCCESS(res, res);
while (!iter->IsDone()) {
nsCOMPtr<nsINode> node = iter->GetCurrentNode();
NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
RefPtr<DeleteNodeTransaction> transaction = new DeleteNodeTransaction();
- res = transaction->Init(mEditor, node, mRangeUpdater);
+ res = transaction->Init(mEditorBase, node, mRangeUpdater);
NS_ENSURE_SUCCESS(res, res);
AppendChild(transaction);
iter->Next();
}
return NS_OK;
}
--- a/editor/libeditor/DeleteRangeTransaction.h
+++ b/editor/libeditor/DeleteRangeTransaction.h
@@ -9,35 +9,35 @@
#include "EditAggregateTransaction.h"
#include "nsCycleCollectionParticipant.h"
#include "nsID.h"
#include "nsIEditor.h"
#include "nsISupportsImpl.h"
#include "nsRange.h"
#include "nscore.h"
-class nsEditor;
class nsINode;
namespace mozilla {
+class EditorBase;
class RangeUpdater;
/**
* A transaction that deletes an entire range in the content tree
*/
class DeleteRangeTransaction final : public EditAggregateTransaction
{
public:
/**
* Initialize the transaction.
- * @param aEditor The object providing basic editing operations.
+ * @param aEditorBase The object providing basic editing operations.
* @param aRange The range to delete.
*/
- nsresult Init(nsEditor* aEditor,
+ nsresult Init(EditorBase* aEditorBase,
nsRange* aRange,
RangeUpdater* aRangeUpdater);
DeleteRangeTransaction();
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteRangeTransaction,
EditAggregateTransaction)
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
@@ -62,17 +62,17 @@ protected:
nsresult CreateTxnsToDeleteContent(nsINode* aParent,
int32_t aOffset,
nsIEditor::EDirection aAction);
// P1 in the range.
RefPtr<nsRange> mRange;
// The editor for this transaction.
- nsEditor* mEditor;
+ EditorBase* mEditorBase;
// Range updater object.
RangeUpdater* mRangeUpdater;
};
} // namespace mozilla
#endif // #ifndef DeleteRangeTransaction_h
--- a/editor/libeditor/DeleteTextTransaction.cpp
+++ b/editor/libeditor/DeleteTextTransaction.cpp
@@ -1,35 +1,36 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "DeleteTextTransaction.h"
+
#include "mozilla/Assertions.h"
+#include "mozilla/EditorBase.h"
#include "mozilla/SelectionState.h"
#include "mozilla/dom/Selection.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsIEditor.h"
#include "nsISupportsImpl.h"
#include "nsAString.h"
namespace mozilla {
using namespace dom;
DeleteTextTransaction::DeleteTextTransaction(
- nsEditor& aEditor,
+ EditorBase& aEditorBase,
nsGenericDOMDataNode& aCharData,
uint32_t aOffset,
uint32_t aNumCharsToDelete,
RangeUpdater* aRangeUpdater)
- : mEditor(aEditor)
+ : mEditorBase(aEditorBase)
, mCharData(&aCharData)
, mOffset(aOffset)
, mNumCharsToDelete(aNumCharsToDelete)
, mRangeUpdater(aRangeUpdater)
{
NS_ASSERTION(mCharData->Length() >= aOffset + aNumCharsToDelete,
"Trying to delete more characters than in node");
}
@@ -39,17 +40,17 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(Delet
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DeleteTextTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
nsresult
DeleteTextTransaction::Init()
{
// Do nothing if the node is read-only
- if (!mEditor.IsModifiableNode(mCharData)) {
+ if (!mEditorBase.IsModifiableNode(mCharData)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
DeleteTextTransaction::DoTransaction()
@@ -63,18 +64,18 @@ DeleteTextTransaction::DoTransaction()
res = mCharData->DeleteData(mOffset, mNumCharsToDelete);
NS_ENSURE_SUCCESS(res, res);
if (mRangeUpdater) {
mRangeUpdater->SelAdjDeleteText(mCharData, mOffset, mNumCharsToDelete);
}
// Only set selection to deletion point if editor gives permission
- if (mEditor.GetShouldTxnSetSelection()) {
- RefPtr<Selection> selection = mEditor.GetSelection();
+ if (mEditorBase.GetShouldTxnSetSelection()) {
+ RefPtr<Selection> selection = mEditorBase.GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
res = selection->Collapse(mCharData, mOffset);
NS_ASSERTION(NS_SUCCEEDED(res),
"Selection could not be collapsed after undo of deletetext");
NS_ENSURE_SUCCESS(res, res);
}
// Else do nothing - DOM Range gravity will adjust selection
return NS_OK;
--- a/editor/libeditor/DeleteTextTransaction.h
+++ b/editor/libeditor/DeleteTextTransaction.h
@@ -9,37 +9,36 @@
#include "EditTransactionBase.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsGenericDOMDataNode.h"
#include "nsID.h"
#include "nsString.h"
#include "nscore.h"
-class nsEditor;
-
namespace mozilla {
+class EditorBase;
class RangeUpdater;
/**
* A transaction that removes text from a content node.
*/
class DeleteTextTransaction final : public EditTransactionBase
{
public:
/**
* Initialize the transaction.
- * @param aEditor The provider of basic editing operations.
+ * @param aEditorBase The provider of basic editing operations.
* @param aElement The content node to remove text from.
* @param aOffset The location in aElement to begin the deletion.
* @param aNumCharsToDelete The number of characters to delete. Not the
* number of bytes!
*/
- DeleteTextTransaction(nsEditor& aEditor,
+ DeleteTextTransaction(EditorBase& aEditorBase,
nsGenericDOMDataNode& aCharData,
uint32_t aOffset,
uint32_t aNumCharsToDelete,
RangeUpdater* aRangeUpdater);
nsresult Init();
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DeleteTextTransaction,
@@ -49,17 +48,17 @@ public:
NS_DECL_EDITTRANSACTIONBASE
uint32_t GetOffset() { return mOffset; }
uint32_t GetNumCharsToDelete() { return mNumCharsToDelete; }
protected:
// The provider of basic editing operations.
- nsEditor& mEditor;
+ EditorBase& mEditorBase;
// The CharacterData node to operate upon.
RefPtr<nsGenericDOMDataNode> mCharData;
// The offset into mCharData where the deletion is to take place.
uint32_t mOffset;
// The number of characters to delete.
rename from editor/libeditor/nsEditor.cpp
rename to editor/libeditor/EditorBase.cpp
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1,14 +1,14 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
-#include "nsEditor.h"
+#include "mozilla/EditorBase.h"
#include "mozilla/DebugOnly.h" // for DebugOnly
#include <stdio.h> // for nullptr, stdout
#include <string.h> // for strcmp
#include "ChangeAttributeTransaction.h" // for ChangeAttributeTransaction
#include "CompositionTransaction.h" // for CompositionTransaction
@@ -109,84 +109,83 @@
class nsIOutputStream;
class nsIParserService;
class nsITransferable;
#ifdef DEBUG
#include "nsIDOMHTMLDocument.h" // for nsIDOMHTMLDocument
#endif
-using namespace mozilla;
-using namespace mozilla::dom;
-using namespace mozilla::widget;
-
// Defined in nsEditorRegistration.cpp
extern nsIParserService *sParserService;
-//---------------------------------------------------------------------------
-//
-// nsEditor: base editor class implementation
-//
-//---------------------------------------------------------------------------
-
-nsEditor::nsEditor()
-: mPlaceHolderName(nullptr)
-, mSelState(nullptr)
-, mPhonetic(nullptr)
-, mModCount(0)
-, mFlags(0)
-, mUpdateCount(0)
-, mPlaceHolderBatch(0)
-, mAction(EditAction::none)
-, mIMETextOffset(0)
-, mIMETextLength(0)
-, mDirection(eNone)
-, mDocDirtyState(-1)
-, mSpellcheckCheckboxState(eTriUnset)
-, mShouldTxnSetSelection(true)
-, mDidPreDestroy(false)
-, mDidPostCreate(false)
-, mDispatchInputEvent(true)
-, mIsInEditAction(false)
-, mHidingCaret(false)
-{
-}
-
-nsEditor::~nsEditor()
+namespace mozilla {
+
+using namespace dom;
+using namespace widget;
+
+/*****************************************************************************
+ * mozilla::EditorBase
+ *****************************************************************************/
+
+EditorBase::EditorBase()
+ : mPlaceHolderName(nullptr)
+ , mSelState(nullptr)
+ , mPhonetic(nullptr)
+ , mModCount(0)
+ , mFlags(0)
+ , mUpdateCount(0)
+ , mPlaceHolderBatch(0)
+ , mAction(EditAction::none)
+ , mIMETextOffset(0)
+ , mIMETextLength(0)
+ , mDirection(eNone)
+ , mDocDirtyState(-1)
+ , mSpellcheckCheckboxState(eTriUnset)
+ , mShouldTxnSetSelection(true)
+ , mDidPreDestroy(false)
+ , mDidPostCreate(false)
+ , mDispatchInputEvent(true)
+ , mIsInEditAction(false)
+ , mHidingCaret(false)
+{
+}
+
+EditorBase::~EditorBase()
{
NS_ASSERTION(!mDocWeak || mDidPreDestroy, "Why PreDestroy hasn't been called?");
if (mComposition) {
mComposition->OnEditorDestroyed();
mComposition = nullptr;
}
// If this editor is still hiding the caret, we need to restore it.
HideCaret(false);
mTxnMgr = nullptr;
delete mPhonetic;
}
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsEditor)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsEditor)
+NS_IMPL_CYCLE_COLLECTION_CLASS(EditorBase)
+
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(EditorBase)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRootElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mInlineSpellChecker)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTxnMgr)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIMETextNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mActionListeners)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEditorObservers)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocStateListeners)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEventTarget)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEventListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSavedSel);
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRangeUpdater);
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsEditor)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(EditorBase)
nsIDocument* currentDoc =
tmp->mRootElement ? tmp->mRootElement->GetUncomposedDoc() : nullptr;
if (currentDoc &&
nsCCUncollectableMarker::InGeneration(cb, currentDoc->GetMarkedCCGeneration())) {
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRootElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInlineSpellChecker)
@@ -196,32 +195,34 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEditorObservers)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocStateListeners)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEventTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEventListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSavedSel);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRangeUpdater);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsEditor)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EditorBase)
NS_INTERFACE_MAP_ENTRY(nsIPhonetic)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIEditorIMESupport)
NS_INTERFACE_MAP_ENTRY(nsIEditor)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditor)
NS_INTERFACE_MAP_END
-NS_IMPL_CYCLE_COLLECTING_ADDREF(nsEditor)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(nsEditor)
+NS_IMPL_CYCLE_COLLECTING_ADDREF(EditorBase)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(EditorBase)
NS_IMETHODIMP
-nsEditor::Init(nsIDOMDocument *aDoc, nsIContent *aRoot,
- nsISelectionController *aSelCon, uint32_t aFlags,
- const nsAString& aValue)
+EditorBase::Init(nsIDOMDocument* aDoc,
+ nsIContent* aRoot,
+ nsISelectionController* aSelCon,
+ uint32_t aFlags,
+ const nsAString& aValue)
{
NS_PRECONDITION(aDoc, "bad arg");
if (!aDoc)
return NS_ERROR_NULL_POINTER;
// First only set flags, but other stuff shouldn't be initialized now.
// Don't move this call after initializing mDocWeak.
// SetFlags() can check whether it's called during initialization or not by
@@ -272,19 +273,18 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsI
// Make sure that the editor will be destroyed properly
mDidPreDestroy = false;
// Make sure that the ediotr will be created properly
mDidPostCreate = false;
return NS_OK;
}
-
NS_IMETHODIMP
-nsEditor::PostCreate()
+EditorBase::PostCreate()
{
// Synchronize some stuff for the flags. SetFlags() will initialize
// something by the flag difference. This is first time of that, so, all
// initializations must be run. For such reason, we need to invert mFlags
// value first.
mFlags = ~mFlags;
nsresult rv = SetFlags(~mFlags);
NS_ENSURE_SUCCESS(rv, rv);
@@ -330,28 +330,27 @@ nsEditor::PostCreate()
}
// FYI: This call might cause destroying this editor.
IMEStateManager::OnEditorInitialized(this);
return NS_OK;
}
-/* virtual */
void
-nsEditor::CreateEventListeners()
+EditorBase::CreateEventListeners()
{
// Don't create the handler twice
if (!mEventListener) {
mEventListener = new EditorEventListener();
}
}
nsresult
-nsEditor::InstallEventListeners()
+EditorBase::InstallEventListeners()
{
NS_ENSURE_TRUE(mDocWeak && mEventListener,
NS_ERROR_NOT_INITIALIZED);
// Initialize the event target.
nsCOMPtr<nsIContent> rootContent = GetRoot();
NS_ENSURE_TRUE(rootContent, NS_ERROR_NOT_AVAILABLE);
mEventTarget = do_QueryInterface(rootContent->GetParent());
@@ -363,32 +362,32 @@ nsEditor::InstallEventListeners()
if (mComposition) {
// Restart to handle composition with new editor contents.
mComposition->StartHandlingComposition(this);
}
return rv;
}
void
-nsEditor::RemoveEventListeners()
+EditorBase::RemoveEventListeners()
{
if (!mDocWeak || !mEventListener) {
return;
}
reinterpret_cast<EditorEventListener*>(mEventListener.get())->Disconnect();
if (mComposition) {
// Even if this is called, don't release mComposition because this is
// may be reused after reframing.
mComposition->EndHandlingComposition(this);
}
mEventTarget = nullptr;
}
bool
-nsEditor::GetDesiredSpellCheckState()
+EditorBase::GetDesiredSpellCheckState()
{
// Check user override on this element
if (mSpellcheckCheckboxState != eTriUnset) {
return (mSpellcheckCheckboxState == eTriTrue);
}
// Check user preferences
int32_t spellcheckLevel = Preferences::GetInt("layout.spellcheckDefault", 1);
@@ -430,17 +429,17 @@ nsEditor::GetDesiredSpellCheckState()
bool enable;
element->GetSpellcheck(&enable);
return enable;
}
NS_IMETHODIMP
-nsEditor::PreDestroy(bool aDestroyingFrames)
+EditorBase::PreDestroy(bool aDestroyingFrames)
{
if (mDidPreDestroy)
return NS_OK;
IMEStateManager::OnEditorDestroying(this);
// Let spellchecker clean up its observers etc. It is important not to
// actually free the spellchecker here, since the spellchecker could have
@@ -465,24 +464,24 @@ nsEditor::PreDestroy(bool aDestroyingFra
mSpellcheckCheckboxState = eTriUnset;
mRootElement = nullptr;
mDidPreDestroy = true;
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetFlags(uint32_t *aFlags)
+EditorBase::GetFlags(uint32_t* aFlags)
{
*aFlags = mFlags;
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::SetFlags(uint32_t aFlags)
+EditorBase::SetFlags(uint32_t aFlags)
{
if (mFlags == aFlags) {
return NS_OK;
}
bool spellcheckerWasEnabled = CanEnableSpellCheck();
mFlags = aFlags;
@@ -518,104 +517,104 @@ nsEditor::SetFlags(uint32_t aFlags)
IMEStateManager::UpdateIMEState(newState, content, this);
}
}
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetIsSelectionEditable(bool *aIsSelectionEditable)
+EditorBase::GetIsSelectionEditable(bool* aIsSelectionEditable)
{
NS_ENSURE_ARG_POINTER(aIsSelectionEditable);
// get current selection
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
// XXX we just check that the anchor node is editable at the moment
// we should check that all nodes in the selection are editable
nsCOMPtr<nsINode> anchorNode = selection->GetAnchorNode();
*aIsSelectionEditable = anchorNode && IsEditable(anchorNode);
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetIsDocumentEditable(bool *aIsDocumentEditable)
+EditorBase::GetIsDocumentEditable(bool* aIsDocumentEditable)
{
NS_ENSURE_ARG_POINTER(aIsDocumentEditable);
nsCOMPtr<nsIDocument> doc = GetDocument();
*aIsDocumentEditable = !!doc;
return NS_OK;
}
already_AddRefed<nsIDocument>
-nsEditor::GetDocument()
+EditorBase::GetDocument()
{
NS_PRECONDITION(mDocWeak, "bad state, mDocWeak weak pointer not initialized");
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
return doc.forget();
}
already_AddRefed<nsIDOMDocument>
-nsEditor::GetDOMDocument()
+EditorBase::GetDOMDocument()
{
NS_PRECONDITION(mDocWeak, "bad state, mDocWeak weak pointer not initialized");
nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(mDocWeak);
return doc.forget();
}
NS_IMETHODIMP
-nsEditor::GetDocument(nsIDOMDocument **aDoc)
+EditorBase::GetDocument(nsIDOMDocument** aDoc)
{
*aDoc = GetDOMDocument().take();
return *aDoc ? NS_OK : NS_ERROR_NOT_INITIALIZED;
}
already_AddRefed<nsIPresShell>
-nsEditor::GetPresShell()
+EditorBase::GetPresShell()
{
NS_PRECONDITION(mDocWeak, "bad state, null mDocWeak");
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
NS_ENSURE_TRUE(doc, nullptr);
nsCOMPtr<nsIPresShell> ps = doc->GetShell();
return ps.forget();
}
already_AddRefed<nsIWidget>
-nsEditor::GetWidget()
+EditorBase::GetWidget()
{
nsCOMPtr<nsIPresShell> ps = GetPresShell();
NS_ENSURE_TRUE(ps, nullptr);
nsPresContext* pc = ps->GetPresContext();
NS_ENSURE_TRUE(pc, nullptr);
nsCOMPtr<nsIWidget> widget = pc->GetRootWidget();
NS_ENSURE_TRUE(widget.get(), nullptr);
return widget.forget();
}
NS_IMETHODIMP
-nsEditor::GetContentsMIMEType(char * *aContentsMIMEType)
+EditorBase::GetContentsMIMEType(char** aContentsMIMEType)
{
NS_ENSURE_ARG_POINTER(aContentsMIMEType);
*aContentsMIMEType = ToNewCString(mContentMIMEType);
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::SetContentsMIMEType(const char * aContentsMIMEType)
+EditorBase::SetContentsMIMEType(const char* aContentsMIMEType)
{
mContentMIMEType.Assign(aContentsMIMEType ? aContentsMIMEType : "");
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetSelectionController(nsISelectionController **aSel)
+EditorBase::GetSelectionController(nsISelectionController** aSel)
{
NS_ENSURE_TRUE(aSel, NS_ERROR_NULL_POINTER);
*aSel = nullptr; // init out param
nsCOMPtr<nsISelectionController> selCon;
if (mSelConWeak) {
selCon = do_QueryReferent(mSelConWeak);
} else {
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
@@ -623,58 +622,58 @@ nsEditor::GetSelectionController(nsISele
}
if (!selCon) {
return NS_ERROR_NOT_INITIALIZED;
}
NS_ADDREF(*aSel = selCon);
return NS_OK;
}
-
NS_IMETHODIMP
-nsEditor::DeleteSelection(EDirection aAction, EStripWrappers aStripWrappers)
+EditorBase::DeleteSelection(EDirection aAction,
+ EStripWrappers aStripWrappers)
{
MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
return DeleteSelectionImpl(aAction, aStripWrappers);
}
-
NS_IMETHODIMP
-nsEditor::GetSelection(nsISelection** aSelection)
+EditorBase::GetSelection(nsISelection** aSelection)
{
return GetSelection(SelectionType::eNormal, aSelection);
}
nsresult
-nsEditor::GetSelection(SelectionType aSelectionType, nsISelection** aSelection)
+EditorBase::GetSelection(SelectionType aSelectionType,
+ nsISelection** aSelection)
{
NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
*aSelection = nullptr;
nsCOMPtr<nsISelectionController> selcon;
GetSelectionController(getter_AddRefs(selcon));
if (!selcon) {
return NS_ERROR_NOT_INITIALIZED;
}
return selcon->GetSelection(ToRawSelectionType(aSelectionType), aSelection);
}
Selection*
-nsEditor::GetSelection(SelectionType aSelectionType)
+EditorBase::GetSelection(SelectionType aSelectionType)
{
nsCOMPtr<nsISelection> sel;
nsresult res = GetSelection(aSelectionType, getter_AddRefs(sel));
if (NS_WARN_IF(NS_FAILED(res)) || NS_WARN_IF(!sel)) {
return nullptr;
}
return sel->AsSelection();
}
NS_IMETHODIMP
-nsEditor::DoTransaction(nsITransaction* aTxn)
+EditorBase::DoTransaction(nsITransaction* aTxn)
{
if (mPlaceHolderBatch && !mPlaceHolderTxn) {
nsCOMPtr<nsIAbsorbingTransaction> placeholderTransaction =
new PlaceholderTransaction();
// Save off weak reference to placeholder transaction
mPlaceHolderTxn = do_GetWeakReference(placeholderTransaction);
placeholderTransaction->Init(mPlaceHolderName, mSelState, this);
@@ -742,72 +741,71 @@ nsEditor::DoTransaction(nsITransaction*
selection->EndBatchChanges();
NS_ENSURE_SUCCESS(res, res);
}
return NS_OK;
}
-
NS_IMETHODIMP
-nsEditor::EnableUndo(bool aEnable)
+EditorBase::EnableUndo(bool aEnable)
{
if (aEnable) {
if (!mTxnMgr) {
mTxnMgr = new nsTransactionManager();
}
mTxnMgr->SetMaxTransactionCount(-1);
} else if (mTxnMgr) {
// disable the transaction manager if it is enabled
mTxnMgr->Clear();
mTxnMgr->SetMaxTransactionCount(0);
}
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetNumberOfUndoItems(int32_t* aNumItems)
+EditorBase::GetNumberOfUndoItems(int32_t* aNumItems)
{
*aNumItems = 0;
return mTxnMgr ? mTxnMgr->GetNumberOfUndoItems(aNumItems) : NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetNumberOfRedoItems(int32_t* aNumItems)
+EditorBase::GetNumberOfRedoItems(int32_t* aNumItems)
{
*aNumItems = 0;
return mTxnMgr ? mTxnMgr->GetNumberOfRedoItems(aNumItems) : NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetTransactionManager(nsITransactionManager* *aTxnManager)
+EditorBase::GetTransactionManager(nsITransactionManager** aTxnManager)
{
NS_ENSURE_ARG_POINTER(aTxnManager);
*aTxnManager = nullptr;
NS_ENSURE_TRUE(mTxnMgr, NS_ERROR_FAILURE);
NS_ADDREF(*aTxnManager = mTxnMgr);
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::SetTransactionManager(nsITransactionManager *aTxnManager)
+EditorBase::SetTransactionManager(nsITransactionManager* aTxnManager)
{
NS_ENSURE_TRUE(aTxnManager, NS_ERROR_FAILURE);
// nsITransactionManager is builtinclass, so this is safe
mTxnMgr = static_cast<nsTransactionManager*>(aTxnManager);
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::Undo(uint32_t aCount)
+EditorBase::Undo(uint32_t aCount)
{
ForceCompositionEnd();
bool hasTxnMgr, hasTransaction = false;
CanUndo(&hasTxnMgr, &hasTransaction);
NS_ENSURE_TRUE(hasTransaction, NS_OK);
AutoRules beginRulesSniffing(this, EditAction::undo, nsIEditor::eNone);
@@ -821,34 +819,34 @@ nsEditor::Undo(uint32_t aCount)
NS_ENSURE_SUCCESS(rv, rv);
DoAfterUndoTransaction();
}
return NS_OK;
}
-
-NS_IMETHODIMP nsEditor::CanUndo(bool *aIsEnabled, bool *aCanUndo)
+NS_IMETHODIMP
+EditorBase::CanUndo(bool* aIsEnabled,
+ bool* aCanUndo)
{
NS_ENSURE_TRUE(aIsEnabled && aCanUndo, NS_ERROR_NULL_POINTER);
*aIsEnabled = !!mTxnMgr;
if (*aIsEnabled) {
int32_t numTxns = 0;
mTxnMgr->GetNumberOfUndoItems(&numTxns);
*aCanUndo = !!numTxns;
} else {
*aCanUndo = false;
}
return NS_OK;
}
-
NS_IMETHODIMP
-nsEditor::Redo(uint32_t aCount)
+EditorBase::Redo(uint32_t aCount)
{
bool hasTxnMgr, hasTransaction = false;
CanRedo(&hasTxnMgr, &hasTransaction);
NS_ENSURE_TRUE(hasTransaction, NS_OK);
AutoRules beginRulesSniffing(this, EditAction::redo, nsIEditor::eNone);
if (!mTxnMgr) {
@@ -860,47 +858,46 @@ nsEditor::Redo(uint32_t aCount)
NS_ENSURE_SUCCESS(rv, rv);
DoAfterRedoTransaction();
}
return NS_OK;
}
-
-NS_IMETHODIMP nsEditor::CanRedo(bool *aIsEnabled, bool *aCanRedo)
+NS_IMETHODIMP
+EditorBase::CanRedo(bool* aIsEnabled, bool* aCanRedo)
{
NS_ENSURE_TRUE(aIsEnabled && aCanRedo, NS_ERROR_NULL_POINTER);
*aIsEnabled = !!mTxnMgr;
if (*aIsEnabled) {
int32_t numTxns = 0;
mTxnMgr->GetNumberOfRedoItems(&numTxns);
*aCanRedo = !!numTxns;
} else {
*aCanRedo = false;
}
return NS_OK;
}
-
NS_IMETHODIMP
-nsEditor::BeginTransaction()
+EditorBase::BeginTransaction()
{
BeginUpdateViewBatch();
if (mTxnMgr) {
mTxnMgr->BeginBatch(nullptr);
}
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::EndTransaction()
+EditorBase::EndTransaction()
{
if (mTxnMgr) {
mTxnMgr->EndBatch(false);
}
EndUpdateViewBatch();
return NS_OK;
@@ -910,17 +907,17 @@ nsEditor::EndTransaction()
// These two routines are similar to the above, but do not use
// the transaction managers batching feature. Instead we use
// a placeholder transaction to wrap up any further transaction
// while the batch is open. The advantage of this is that
// placeholder transactions can later merge, if needed. Merging
// is unavailable between transaction manager batches.
NS_IMETHODIMP
-nsEditor::BeginPlaceHolderTransaction(nsIAtom *aName)
+EditorBase::BeginPlaceHolderTransaction(nsIAtom* aName)
{
NS_PRECONDITION(mPlaceHolderBatch >= 0, "negative placeholder batch count!");
if (!mPlaceHolderBatch)
{
NotifyEditorObservers(eNotifyEditorObserversOfBefore);
// time to turn on the batch
BeginUpdateViewBatch();
mPlaceHolderTxn = nullptr;
@@ -932,17 +929,17 @@ nsEditor::BeginPlaceHolderTransaction(ns
}
}
mPlaceHolderBatch++;
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::EndPlaceHolderTransaction()
+EditorBase::EndPlaceHolderTransaction()
{
NS_PRECONDITION(mPlaceHolderBatch > 0, "zero or negative placeholder batch count when ending batch!");
if (mPlaceHolderBatch == 1)
{
RefPtr<Selection> selection = GetSelection();
// By making the assumption that no reflow happens during the calls
// to EndUpdateViewBatch and ScrollSelectionIntoView, we are able to
@@ -1007,55 +1004,57 @@ nsEditor::EndPlaceHolderTransaction()
}
}
mPlaceHolderBatch--;
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::ShouldTxnSetSelection(bool *aResult)
+EditorBase::ShouldTxnSetSelection(bool* aResult)
{
NS_ENSURE_TRUE(aResult, NS_ERROR_NULL_POINTER);
*aResult = mShouldTxnSetSelection;
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::SetShouldTxnSetSelection(bool aShould)
+EditorBase::SetShouldTxnSetSelection(bool aShould)
{
mShouldTxnSetSelection = aShould;
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetDocumentIsEmpty(bool *aDocumentIsEmpty)
+EditorBase::GetDocumentIsEmpty(bool* aDocumentIsEmpty)
{
*aDocumentIsEmpty = true;
dom::Element* root = GetRoot();
NS_ENSURE_TRUE(root, NS_ERROR_NULL_POINTER);
*aDocumentIsEmpty = !root->HasChildren();
return NS_OK;
}
-
-// XXX: the rule system should tell us which node to select all on (ie, the root, or the body)
-NS_IMETHODIMP nsEditor::SelectAll()
+// XXX: The rule system should tell us which node to select all on (ie, the
+// root, or the body)
+NS_IMETHODIMP
+EditorBase::SelectAll()
{
if (!mDocWeak) { return NS_ERROR_NOT_INITIALIZED; }
ForceCompositionEnd();
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
return SelectEntireDocument(selection);
}
-NS_IMETHODIMP nsEditor::BeginningOfDocument()
+NS_IMETHODIMP
+EditorBase::BeginningOfDocument()
{
if (!mDocWeak) { return NS_ERROR_NOT_INITIALIZED; }
// get the selection
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
// get the root element
@@ -1080,17 +1079,17 @@ NS_IMETHODIMP nsEditor::BeginningOfDocum
return NS_ERROR_NULL_POINTER;
}
int32_t offsetInParent = parent->IndexOf(firstNode);
return selection->CollapseNative(parent, offsetInParent);
}
NS_IMETHODIMP
-nsEditor::EndOfDocument()
+EditorBase::EndOfDocument()
{
NS_ENSURE_TRUE(mDocWeak, NS_ERROR_NOT_INITIALIZED);
// get selection
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
// get the root element
@@ -1103,119 +1102,121 @@ nsEditor::EndOfDocument()
child = node->GetLastChild();
}
uint32_t length = node->Length();
return selection->CollapseNative(node, int32_t(length));
}
NS_IMETHODIMP
-nsEditor::GetDocumentModified(bool *outDocModified)
+EditorBase::GetDocumentModified(bool* outDocModified)
{
NS_ENSURE_TRUE(outDocModified, NS_ERROR_NULL_POINTER);
int32_t modCount = 0;
GetModificationCount(&modCount);
*outDocModified = (modCount != 0);
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetDocumentCharacterSet(nsACString &characterSet)
+EditorBase::GetDocumentCharacterSet(nsACString& characterSet)
{
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
characterSet = doc->GetDocumentCharacterSet();
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::SetDocumentCharacterSet(const nsACString& characterSet)
+EditorBase::SetDocumentCharacterSet(const nsACString& characterSet)
{
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
doc->SetDocumentCharacterSet(characterSet);
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::Cut()
+EditorBase::Cut()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
-nsEditor::CanCut(bool *aCanCut)
+EditorBase::CanCut(bool* aCanCut)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
-nsEditor::Copy()
+EditorBase::Copy()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
-nsEditor::CanCopy(bool *aCanCut)
+EditorBase::CanCopy(bool* aCanCut)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
-nsEditor::CanDelete(bool *aCanDelete)
+EditorBase::CanDelete(bool* aCanDelete)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
-nsEditor::Paste(int32_t aSelectionType)
+EditorBase::Paste(int32_t aSelectionType)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
-nsEditor::PasteTransferable(nsITransferable *aTransferable)
+EditorBase::PasteTransferable(nsITransferable* aTransferable)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
-nsEditor::CanPaste(int32_t aSelectionType, bool *aCanPaste)
+EditorBase::CanPaste(int32_t aSelectionType, bool* aCanPaste)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
-nsEditor::CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste)
+EditorBase::CanPasteTransferable(nsITransferable* aTransferable,
+ bool* aCanPaste)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
-nsEditor::SetAttribute(nsIDOMElement* aElement, const nsAString& aAttribute,
- const nsAString& aValue)
+EditorBase::SetAttribute(nsIDOMElement* aElement,
+ const nsAString& aAttribute,
+ const nsAString& aValue)
{
nsCOMPtr<Element> element = do_QueryInterface(aElement);
NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIAtom> attribute = NS_Atomize(aAttribute);
RefPtr<ChangeAttributeTransaction> transaction =
CreateTxnForSetAttribute(*element, *attribute, aValue);
return DoTransaction(transaction);
}
NS_IMETHODIMP
-nsEditor::GetAttributeValue(nsIDOMElement *aElement,
- const nsAString & aAttribute,
- nsAString & aResultValue,
- bool *aResultIsSet)
+EditorBase::GetAttributeValue(nsIDOMElement* aElement,
+ const nsAString& aAttribute,
+ nsAString& aResultValue,
+ bool* aResultIsSet)
{
NS_ENSURE_TRUE(aResultIsSet, NS_ERROR_NULL_POINTER);
*aResultIsSet = false;
if (!aElement) {
return NS_OK;
}
nsAutoString value;
nsresult rv = aElement->GetAttribute(aAttribute, value);
@@ -1223,55 +1224,55 @@ nsEditor::GetAttributeValue(nsIDOMElemen
if (!DOMStringIsNull(value)) {
*aResultIsSet = true;
aResultValue = value;
}
return rv;
}
NS_IMETHODIMP
-nsEditor::RemoveAttribute(nsIDOMElement* aElement, const nsAString& aAttribute)
+EditorBase::RemoveAttribute(nsIDOMElement* aElement,
+ const nsAString& aAttribute)
{
nsCOMPtr<Element> element = do_QueryInterface(aElement);
NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIAtom> attribute = NS_Atomize(aAttribute);
RefPtr<ChangeAttributeTransaction> transaction =
CreateTxnForRemoveAttribute(*element, *attribute);
return DoTransaction(transaction);
}
-
bool
-nsEditor::OutputsMozDirty()
+EditorBase::OutputsMozDirty()
{
// Return true for Composer (!eEditorAllowInteraction) or mail
// (eEditorMailMask), but false for webpages.
return !(mFlags & nsIPlaintextEditor::eEditorAllowInteraction) ||
(mFlags & nsIPlaintextEditor::eEditorMailMask);
}
-
NS_IMETHODIMP
-nsEditor::MarkNodeDirty(nsIDOMNode* aNode)
+EditorBase::MarkNodeDirty(nsIDOMNode* aNode)
{
// Mark the node dirty, but not for webpages (bug 599983)
if (!OutputsMozDirty()) {
return NS_OK;
}
nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
if (element) {
element->SetAttr(kNameSpaceID_None, nsGkAtoms::mozdirty,
EmptyString(), false);
}
return NS_OK;
}
-NS_IMETHODIMP nsEditor::GetInlineSpellChecker(bool autoCreate,
- nsIInlineSpellChecker ** aInlineSpellChecker)
+NS_IMETHODIMP
+EditorBase::GetInlineSpellChecker(bool autoCreate,
+ nsIInlineSpellChecker** aInlineSpellChecker)
{
NS_ENSURE_ARG_POINTER(aInlineSpellChecker);
if (mDidPreDestroy) {
// Don't allow people to get or create the spell checker once the editor
// is going away.
*aInlineSpellChecker = nullptr;
return autoCreate ? NS_ERROR_NOT_AVAILABLE : NS_OK;
@@ -1297,17 +1298,18 @@ NS_IMETHODIMP nsEditor::GetInlineSpellCh
NS_ENSURE_SUCCESS(rv, rv);
}
NS_IF_ADDREF(*aInlineSpellChecker = mInlineSpellChecker);
return NS_OK;
}
-NS_IMETHODIMP nsEditor::SyncRealTimeSpell()
+NS_IMETHODIMP
+EditorBase::SyncRealTimeSpell()
{
bool enable = GetDesiredSpellCheckState();
// Initializes mInlineSpellChecker
nsCOMPtr<nsIInlineSpellChecker> spellChecker;
GetInlineSpellChecker(enable, getter_AddRefs(spellChecker));
if (mInlineSpellChecker) {
@@ -1315,41 +1317,42 @@ NS_IMETHODIMP nsEditor::SyncRealTimeSpel
// available since we don't destroy the mInlineSpellChecker when the last
// dictionariy is removed, but in that case spellChecker is null
mInlineSpellChecker->SetEnableRealTimeSpell(enable && spellChecker);
}
return NS_OK;
}
-NS_IMETHODIMP nsEditor::SetSpellcheckUserOverride(bool enable)
+NS_IMETHODIMP
+EditorBase::SetSpellcheckUserOverride(bool enable)
{
mSpellcheckCheckboxState = enable ? eTriTrue : eTriFalse;
return SyncRealTimeSpell();
}
NS_IMETHODIMP
-nsEditor::CreateNode(const nsAString& aTag,
- nsIDOMNode* aParent,
- int32_t aPosition,
- nsIDOMNode** aNewNode)
+EditorBase::CreateNode(const nsAString& aTag,
+ nsIDOMNode* aParent,
+ int32_t aPosition,
+ nsIDOMNode** aNewNode)
{
nsCOMPtr<nsIAtom> tag = NS_Atomize(aTag);
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
NS_ENSURE_STATE(parent);
*aNewNode = GetAsDOMNode(CreateNode(tag, parent, aPosition).take());
NS_ENSURE_STATE(*aNewNode);
return NS_OK;
}
already_AddRefed<Element>
-nsEditor::CreateNode(nsIAtom* aTag,
- nsINode* aParent,
- int32_t aPosition)
+EditorBase::CreateNode(nsIAtom* aTag,
+ nsINode* aParent,
+ int32_t aPosition)
{
MOZ_ASSERT(aTag && aParent);
AutoRules beginRulesSniffing(this, EditAction::createNode, nsIEditor::eNext);
for (auto& listener : mActionListeners) {
listener->WillCreateNode(nsDependentAtomString(aTag),
GetAsDOMNode(aParent), aPosition);
@@ -1370,29 +1373,32 @@ nsEditor::CreateNode(nsIAtom* aTag,
for (auto& listener : mActionListeners) {
listener->DidCreateNode(nsDependentAtomString(aTag), GetAsDOMNode(ret),
GetAsDOMNode(aParent), aPosition, res);
}
return ret.forget();
}
-
NS_IMETHODIMP
-nsEditor::InsertNode(nsIDOMNode* aNode, nsIDOMNode* aParent, int32_t aPosition)
+EditorBase::InsertNode(nsIDOMNode* aNode,
+ nsIDOMNode* aParent,
+ int32_t aPosition)
{
nsCOMPtr<nsIContent> node = do_QueryInterface(aNode);
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
NS_ENSURE_TRUE(node && parent, NS_ERROR_NULL_POINTER);
return InsertNode(*node, *parent, aPosition);
}
nsresult
-nsEditor::InsertNode(nsIContent& aNode, nsINode& aParent, int32_t aPosition)
+EditorBase::InsertNode(nsIContent& aNode,
+ nsINode& aParent,
+ int32_t aPosition)
{
AutoRules beginRulesSniffing(this, EditAction::insertNode, nsIEditor::eNext);
for (auto& listener : mActionListeners) {
listener->WillInsertNode(aNode.AsDOMNode(), aParent.AsDOMNode(),
aPosition);
}
@@ -1406,30 +1412,32 @@ nsEditor::InsertNode(nsIContent& aNode,
listener->DidInsertNode(aNode.AsDOMNode(), aParent.AsDOMNode(), aPosition,
rv);
}
return rv;
}
NS_IMETHODIMP
-nsEditor::SplitNode(nsIDOMNode* aNode,
- int32_t aOffset,
- nsIDOMNode** aNewLeftNode)
+EditorBase::SplitNode(nsIDOMNode* aNode,
+ int32_t aOffset,
+ nsIDOMNode** aNewLeftNode)
{
nsCOMPtr<nsIContent> node = do_QueryInterface(aNode);
NS_ENSURE_STATE(node);
ErrorResult rv;
nsCOMPtr<nsIContent> newNode = SplitNode(*node, aOffset, rv);
*aNewLeftNode = GetAsDOMNode(newNode.forget().take());
return rv.StealNSResult();
}
nsIContent*
-nsEditor::SplitNode(nsIContent& aNode, int32_t aOffset, ErrorResult& aResult)
+EditorBase::SplitNode(nsIContent& aNode,
+ int32_t aOffset,
+ ErrorResult& aResult)
{
AutoRules beginRulesSniffing(this, EditAction::splitNode, nsIEditor::eNext);
for (auto& listener : mActionListeners) {
listener->WillSplitNode(aNode.AsDOMNode(), aOffset);
}
RefPtr<SplitNodeTransaction> transaction =
@@ -1448,30 +1456,30 @@ nsEditor::SplitNode(nsIContent& aNode, i
}
// Note: result might be a success code, so we can't use Throw() to
// set it on aResult.
aResult = result;
return newNode;
}
-
NS_IMETHODIMP
-nsEditor::JoinNodes(nsIDOMNode* aLeftNode,
- nsIDOMNode* aRightNode,
- nsIDOMNode*)
+EditorBase::JoinNodes(nsIDOMNode* aLeftNode,
+ nsIDOMNode* aRightNode,
+ nsIDOMNode*)
{
nsCOMPtr<nsINode> leftNode = do_QueryInterface(aLeftNode);
nsCOMPtr<nsINode> rightNode = do_QueryInterface(aRightNode);
NS_ENSURE_STATE(leftNode && rightNode && leftNode->GetParentNode());
return JoinNodes(*leftNode, *rightNode);
}
nsresult
-nsEditor::JoinNodes(nsINode& aLeftNode, nsINode& aRightNode)
+EditorBase::JoinNodes(nsINode& aLeftNode,
+ nsINode& aRightNode)
{
nsCOMPtr<nsINode> parent = aLeftNode.GetParentNode();
MOZ_ASSERT(parent);
AutoRules beginRulesSniffing(this, EditAction::joinNode,
nsIEditor::ePrevious);
// Remember some values; later used for saved selection updating.
@@ -1498,27 +1506,26 @@ nsEditor::JoinNodes(nsINode& aLeftNode,
for (auto& listener : mActionListeners) {
listener->DidJoinNodes(aLeftNode.AsDOMNode(), aRightNode.AsDOMNode(),
parent->AsDOMNode(), result);
}
return result;
}
-
NS_IMETHODIMP
-nsEditor::DeleteNode(nsIDOMNode* aNode)
+EditorBase::DeleteNode(nsIDOMNode* aNode)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_ENSURE_STATE(node);
return DeleteNode(node);
}
nsresult
-nsEditor::DeleteNode(nsINode* aNode)
+EditorBase::DeleteNode(nsINode* aNode)
{
AutoRules beginRulesSniffing(this, EditAction::createNode,
nsIEditor::ePrevious);
// save node location for selection updating code.
for (auto& listener : mActionListeners) {
listener->WillDeleteNode(aNode->AsDOMNode());
}
@@ -1532,27 +1539,27 @@ nsEditor::DeleteNode(nsINode* aNode)
for (auto& listener : mActionListeners) {
listener->DidDeleteNode(aNode->AsDOMNode(), rv);
}
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
-///////////////////////////////////////////////////////////////////////////
-// ReplaceContainer: replace inNode with a new node (outNode) which is contructed
-// to be of type aNodeType. Put inNodes children into outNode.
-// Callers responsibility to make sure inNode's children can
-// go in outNode.
+/**
+ * ReplaceContainer() replaces inNode with a new node (outNode) which is
+ * constructed to be of type aNodeType. Put inNodes children into outNode.
+ * Callers responsibility to make sure inNode's children can go in outNode.
+ */
already_AddRefed<Element>
-nsEditor::ReplaceContainer(Element* aOldContainer,
- nsIAtom* aNodeType,
- nsIAtom* aAttribute,
- const nsAString* aValue,
- ECloneAttributes aCloneAttributes)
+EditorBase::ReplaceContainer(Element* aOldContainer,
+ nsIAtom* aNodeType,
+ nsIAtom* aAttribute,
+ const nsAString* aValue,
+ ECloneAttributes aCloneAttributes)
{
MOZ_ASSERT(aOldContainer && aNodeType);
nsCOMPtr<nsIContent> parent = aOldContainer->GetParent();
NS_ENSURE_TRUE(parent, nullptr);
int32_t offset = parent->IndexOf(aOldContainer);
@@ -1594,22 +1601,22 @@ nsEditor::ReplaceContainer(Element* aOld
// delete old container
res = DeleteNode(aOldContainer);
NS_ENSURE_SUCCESS(res, nullptr);
return ret.forget();
}
-///////////////////////////////////////////////////////////////////////////////
-// RemoveContainer: remove inNode, reparenting its children (if any) into the
-// parent of inNode
-//
+/**
+ * RemoveContainer() removes inNode, reparenting its children (if any) into the
+ * parent of inNode.
+ */
nsresult
-nsEditor::RemoveContainer(nsIContent* aNode)
+EditorBase::RemoveContainer(nsIContent* aNode)
{
MOZ_ASSERT(aNode);
nsCOMPtr<nsINode> parent = aNode->GetParentNode();
NS_ENSURE_STATE(parent);
int32_t offset = parent->IndexOf(aNode);
@@ -1627,28 +1634,27 @@ nsEditor::RemoveContainer(nsIContent* aN
rv = InsertNode(*child, *parent, offset);
NS_ENSURE_SUCCESS(rv, rv);
}
return DeleteNode(aNode);
}
-
-///////////////////////////////////////////////////////////////////////////////
-// InsertContainerAbove: Insert a new parent for inNode, which is contructed to
-// be of type aNodeType. outNode becomes a child of
-// inNode's earlier parent. Caller's responsibility to
-// make sure inNode's can be child of outNode, and
-// outNode can be child of old parent.
+/**
+ * InsertContainerAbove() inserts a new parent for inNode, which is contructed
+ * to be of type aNodeType. outNode becomes a child of inNode's earlier
+ * parent. Caller's responsibility to make sure inNode's can be child of
+ * outNode, and outNode can be child of old parent.
+ */
already_AddRefed<Element>
-nsEditor::InsertContainerAbove(nsIContent* aNode,
- nsIAtom* aNodeType,
- nsIAtom* aAttribute,
- const nsAString* aValue)
+EditorBase::InsertContainerAbove(nsIContent* aNode,
+ nsIAtom* aNodeType,
+ nsIAtom* aAttribute,
+ const nsAString* aValue)
{
MOZ_ASSERT(aNode && aNodeType);
nsCOMPtr<nsIContent> parent = aNode->GetParent();
NS_ENSURE_TRUE(parent, nullptr);
int32_t offset = parent->IndexOf(aNode);
// Create new container
@@ -1677,20 +1683,23 @@ nsEditor::InsertContainerAbove(nsIConten
// Put new parent in doc
res = InsertNode(*newContent, *parent, offset);
NS_ENSURE_SUCCESS(res, nullptr);
return newContent.forget();
}
-///////////////////////////////////////////////////////////////////////////
-// MoveNode: move aNode to {aParent,aOffset}
+/**
+ * MoveNode() moves aNode to {aParent,aOffset}.
+ */
nsresult
-nsEditor::MoveNode(nsIContent* aNode, nsINode* aParent, int32_t aOffset)
+EditorBase::MoveNode(nsIContent* aNode,
+ nsINode* aParent,
+ int32_t aOffset)
{
MOZ_ASSERT(aNode);
MOZ_ASSERT(aParent);
MOZ_ASSERT(aOffset == -1 ||
(0 <= aOffset &&
AssertedCast<uint32_t>(aOffset) <= aParent->Length()));
nsCOMPtr<nsINode> oldParent = aNode->GetParentNode();
@@ -1720,71 +1729,69 @@ nsEditor::MoveNode(nsIContent* aNode, ns
nsCOMPtr<nsINode> kungFuDeathGrip = aNode;
nsresult rv = DeleteNode(aNode);
NS_ENSURE_SUCCESS(rv, rv);
return InsertNode(*aNode, *aParent, aOffset);
}
-
NS_IMETHODIMP
-nsEditor::AddEditorObserver(nsIEditorObserver *aObserver)
+EditorBase::AddEditorObserver(nsIEditorObserver* aObserver)
{
// we don't keep ownership of the observers. They must
// remove themselves as observers before they are destroyed.
NS_ENSURE_TRUE(aObserver, NS_ERROR_NULL_POINTER);
// Make sure the listener isn't already on the list
if (!mEditorObservers.Contains(aObserver)) {
mEditorObservers.AppendElement(*aObserver);
}
return NS_OK;
}
-
NS_IMETHODIMP
-nsEditor::RemoveEditorObserver(nsIEditorObserver *aObserver)
+EditorBase::RemoveEditorObserver(nsIEditorObserver* aObserver)
{
NS_ENSURE_TRUE(aObserver, NS_ERROR_FAILURE);
mEditorObservers.RemoveElement(aObserver);
return NS_OK;
}
-class EditorInputEventDispatcher : public Runnable
+class EditorInputEventDispatcher final : public Runnable
{
public:
- EditorInputEventDispatcher(nsEditor* aEditor,
+ EditorInputEventDispatcher(EditorBase* aEditorBase,
nsIContent* aTarget,
bool aIsComposing)
- : mEditor(aEditor)
+ : mEditorBase(aEditorBase)
, mTarget(aTarget)
, mIsComposing(aIsComposing)
{
}
NS_IMETHOD Run()
{
// Note that we don't need to check mDispatchInputEvent here. We need
// to check it only when the editor requests to dispatch the input event.
if (!mTarget->IsInComposedDoc()) {
return NS_OK;
}
- nsCOMPtr<nsIPresShell> ps = mEditor->GetPresShell();
+ nsCOMPtr<nsIPresShell> ps = mEditorBase->GetPresShell();
if (!ps) {
return NS_OK;
}
- nsCOMPtr<nsIWidget> widget = mEditor->GetWidget();
+ nsCOMPtr<nsIWidget> widget = mEditorBase->GetWidget();
if (!widget) {
return NS_OK;
}
// Even if the change is caused by untrusted event, we need to dispatch
// trusted input event since it's a fact.
InternalEditorInputEvent inputEvent(true, eEditorInput, widget);
inputEvent.mTime = static_cast<uint64_t>(PR_Now() / 1000);
@@ -1792,23 +1799,23 @@ public:
nsEventStatus status = nsEventStatus_eIgnore;
nsresult rv =
ps->HandleEventWithTarget(&inputEvent, nullptr, mTarget, &status);
NS_ENSURE_SUCCESS(rv, NS_OK); // print the warning if error
return NS_OK;
}
private:
- RefPtr<nsEditor> mEditor;
+ RefPtr<EditorBase> mEditorBase;
nsCOMPtr<nsIContent> mTarget;
bool mIsComposing;
};
void
-nsEditor::NotifyEditorObservers(NotificationForEditorObservers aNotification)
+EditorBase::NotifyEditorObservers(NotificationForEditorObservers aNotification)
{
// Copy the observers since EditAction()s can modify mEditorObservers.
nsTArray<mozilla::OwningNonNull<nsIEditorObserver>> observers(mEditorObservers);
switch (aNotification) {
case eNotifyEditorObserversOfEnd:
mIsInEditAction = false;
for (auto& observer : observers) {
observer->EditAction();
@@ -1837,17 +1844,17 @@ nsEditor::NotifyEditorObservers(Notifica
break;
default:
MOZ_CRASH("Handle all notifications here");
break;
}
}
void
-nsEditor::FireInputEvent()
+EditorBase::FireInputEvent()
{
// We don't need to dispatch multiple input events if there is a pending
// input event. However, it may have different event target. If we resolved
// this issue, we need to manage the pending events in an array. But it's
// overwork. We don't need to do it for the very rare case.
nsCOMPtr<nsIContent> target = GetInputEventTargetContent();
NS_ENSURE_TRUE_VOID(target);
@@ -1855,178 +1862,173 @@ nsEditor::FireInputEvent()
// NOTE: Don't refer IsIMEComposing() because it returns false even before
// compositionend. However, DOM Level 3 Events defines it should be
// true after compositionstart and before compositionend.
nsContentUtils::AddScriptRunner(
new EditorInputEventDispatcher(this, target, !!GetComposition()));
}
NS_IMETHODIMP
-nsEditor::AddEditActionListener(nsIEditActionListener *aListener)
+EditorBase::AddEditActionListener(nsIEditActionListener* aListener)
{
NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
// Make sure the listener isn't already on the list
if (!mActionListeners.Contains(aListener)) {
mActionListeners.AppendElement(*aListener);
}
return NS_OK;
}
-
NS_IMETHODIMP
-nsEditor::RemoveEditActionListener(nsIEditActionListener *aListener)
+EditorBase::RemoveEditActionListener(nsIEditActionListener* aListener)
{
NS_ENSURE_TRUE(aListener, NS_ERROR_FAILURE);
mActionListeners.RemoveElement(aListener);
return NS_OK;
}
-
NS_IMETHODIMP
-nsEditor::AddDocumentStateListener(nsIDocumentStateListener *aListener)
+EditorBase::AddDocumentStateListener(nsIDocumentStateListener* aListener)
{
NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
if (!mDocStateListeners.Contains(aListener)) {
mDocStateListeners.AppendElement(*aListener);
}
return NS_OK;
}
-
NS_IMETHODIMP
-nsEditor::RemoveDocumentStateListener(nsIDocumentStateListener *aListener)
+EditorBase::RemoveDocumentStateListener(nsIDocumentStateListener* aListener)
{
NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
mDocStateListeners.RemoveElement(aListener);
return NS_OK;
}
-
-NS_IMETHODIMP nsEditor::OutputToString(const nsAString& aFormatType,
- uint32_t aFlags,
- nsAString& aOutputString)
+NS_IMETHODIMP
+EditorBase::OutputToString(const nsAString& aFormatType,
+ uint32_t aFlags,
+ nsAString& aOutputString)
{
// these should be implemented by derived classes.
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
-nsEditor::OutputToStream(nsIOutputStream* aOutputStream,
- const nsAString& aFormatType,
- const nsACString& aCharsetOverride,
- uint32_t aFlags)
+EditorBase::OutputToStream(nsIOutputStream* aOutputStream,
+ const nsAString& aFormatType,
+ const nsACString& aCharsetOverride,
+ uint32_t aFlags)
{
// these should be implemented by derived classes.
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
-nsEditor::DumpContentTree()
+EditorBase::DumpContentTree()
{
#ifdef DEBUG
if (mRootElement) {
mRootElement->List(stdout);
}
#endif
return NS_OK;
}
-
NS_IMETHODIMP
-nsEditor::DebugDumpContent()
+EditorBase::DebugDumpContent()
{
#ifdef DEBUG
nsCOMPtr<nsIDOMHTMLDocument> doc = do_QueryReferent(mDocWeak);
NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIDOMHTMLElement>bodyElem;
doc->GetBody(getter_AddRefs(bodyElem));
nsCOMPtr<nsIContent> content = do_QueryInterface(bodyElem);
if (content)
content->List();
#endif
return NS_OK;
}
-
NS_IMETHODIMP
-nsEditor::DebugUnitTests(int32_t *outNumTests, int32_t *outNumTestsFailed)
+EditorBase::DebugUnitTests(int32_t* outNumTests,
+ int32_t* outNumTestsFailed)
{
#ifdef DEBUG
NS_NOTREACHED("This should never get called. Overridden by subclasses");
#endif
return NS_OK;
}
-
bool
-nsEditor::ArePreservingSelection()
+EditorBase::ArePreservingSelection()
{
return !(mSavedSel.IsEmpty());
}
void
-nsEditor::PreserveSelectionAcrossActions(Selection* aSel)
+EditorBase::PreserveSelectionAcrossActions(Selection* aSel)
{
mSavedSel.SaveSelection(aSel);
mRangeUpdater.RegisterSelectionState(mSavedSel);
}
nsresult
-nsEditor::RestorePreservedSelection(Selection* aSel)
+EditorBase::RestorePreservedSelection(Selection* aSel)
{
if (mSavedSel.IsEmpty()) return NS_ERROR_FAILURE;
mSavedSel.RestoreSelection(aSel);
StopPreservingSelection();
return NS_OK;
}
void
-nsEditor::StopPreservingSelection()
+EditorBase::StopPreservingSelection()
{
mRangeUpdater.DropSelectionState(mSavedSel);
mSavedSel.MakeEmpty();
}
void
-nsEditor::EnsureComposition(mozilla::WidgetCompositionEvent* aCompositionEvent)
+EditorBase::EnsureComposition(WidgetCompositionEvent* aCompositionEvent)
{
if (mComposition) {
return;
}
// The compositionstart event must cause creating new TextComposition
// instance at being dispatched by IMEStateManager.
mComposition = IMEStateManager::GetTextCompositionFor(aCompositionEvent);
if (!mComposition) {
MOZ_CRASH("IMEStateManager doesn't return proper composition");
}
mComposition->StartHandlingComposition(this);
}
nsresult
-nsEditor::BeginIMEComposition(WidgetCompositionEvent* aCompositionEvent)
+EditorBase::BeginIMEComposition(WidgetCompositionEvent* aCompositionEvent)
{
MOZ_ASSERT(!mComposition, "There is composition already");
EnsureComposition(aCompositionEvent);
if (mPhonetic) {
mPhonetic->Truncate(0);
}
return NS_OK;
}
void
-nsEditor::EndIMEComposition()
+EditorBase::EndIMEComposition()
{
NS_ENSURE_TRUE_VOID(mComposition); // nothing to do
// commit the IME transaction..we can get at it via the transaction mgr.
// Note that this means IME won't work without an undo stack!
if (mTxnMgr) {
nsCOMPtr<nsITransaction> txn = mTxnMgr->PeekUndoStack();
nsCOMPtr<nsIAbsorbingTransaction> plcTxn = do_QueryInterface(txn);
@@ -2047,46 +2049,45 @@ nsEditor::EndIMEComposition()
mIMETextLength = 0;
mComposition->EndHandlingComposition(this);
mComposition = nullptr;
// notify editor observers of action
NotifyEditorObservers(eNotifyEditorObserversOfEnd);
}
-
NS_IMETHODIMP
-nsEditor::GetPhonetic(nsAString& aPhonetic)
+EditorBase::GetPhonetic(nsAString& aPhonetic)
{
if (mPhonetic)
aPhonetic = *mPhonetic;
else
aPhonetic.Truncate(0);
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::ForceCompositionEnd()
+EditorBase::ForceCompositionEnd()
{
nsCOMPtr<nsIPresShell> ps = GetPresShell();
if (!ps) {
return NS_ERROR_NOT_AVAILABLE;
}
nsPresContext* pc = ps->GetPresContext();
if (!pc) {
return NS_ERROR_NOT_AVAILABLE;
}
return mComposition ?
IMEStateManager::NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, pc) : NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetPreferredIMEState(IMEState *aState)
+EditorBase::GetPreferredIMEState(IMEState* aState)
{
NS_ENSURE_ARG_POINTER(aState);
aState->mEnabled = IMEState::ENABLED;
aState->mOpen = IMEState::DONT_CHANGE_OPEN_STATE;
if (IsReadonly() || IsDisabled()) {
aState->mEnabled = IMEState::DISABLED;
return NS_OK;
@@ -2114,61 +2115,62 @@ nsEditor::GetPreferredIMEState(IMEState
aState->mOpen = IMEState::CLOSED;
break;
}
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetComposing(bool* aResult)
+EditorBase::GetComposing(bool* aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = IsIMEComposing();
return NS_OK;
}
-
-/* Non-interface, public methods */
-
NS_IMETHODIMP
-nsEditor::GetRootElement(nsIDOMElement **aRootElement)
+EditorBase::GetRootElement(nsIDOMElement** aRootElement)
{
NS_ENSURE_ARG_POINTER(aRootElement);
NS_ENSURE_TRUE(mRootElement, NS_ERROR_NOT_AVAILABLE);
nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(mRootElement);
rootElement.forget(aRootElement);
return NS_OK;
}
-
-/** All editor operations which alter the doc should be prefaced
- * with a call to StartOperation, naming the action and direction */
+/**
+ * All editor operations which alter the doc should be prefaced
+ * with a call to StartOperation, naming the action and direction.
+ */
NS_IMETHODIMP
-nsEditor::StartOperation(EditAction opID, nsIEditor::EDirection aDirection)
+EditorBase::StartOperation(EditAction opID,
+ nsIEditor::EDirection aDirection)
{
mAction = opID;
mDirection = aDirection;
return NS_OK;
}
-
-/** All editor operations which alter the doc should be followed
- * with a call to EndOperation */
+/**
+ * All editor operations which alter the doc should be followed
+ * with a call to EndOperation.
+ */
NS_IMETHODIMP
-nsEditor::EndOperation()
+EditorBase::EndOperation()
{
mAction = EditAction::none;
mDirection = eNone;
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::CloneAttribute(const nsAString & aAttribute,
- nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
+EditorBase::CloneAttribute(const nsAString& aAttribute,
+ nsIDOMNode* aDestNode,
+ nsIDOMNode* aSourceNode)
{
NS_ENSURE_TRUE(aDestNode && aSourceNode, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMElement> destElement = do_QueryInterface(aDestNode);
nsCOMPtr<nsIDOMElement> sourceElement = do_QueryInterface(aSourceNode);
NS_ENSURE_TRUE(destElement && sourceElement, NS_ERROR_NO_INTERFACE);
nsAutoString attrValue;
@@ -2181,33 +2183,38 @@ nsEditor::CloneAttribute(const nsAString
if (isAttrSet)
rv = SetAttribute(destElement, aAttribute, attrValue);
else
rv = RemoveAttribute(destElement, aAttribute);
return rv;
}
-// Objects must be DOM elements
+/**
+ * @param aDest Must be a DOM element.
+ * @param aSource Must be a DOM element.
+ */
NS_IMETHODIMP
-nsEditor::CloneAttributes(nsIDOMNode* aDest, nsIDOMNode* aSource)
+EditorBase::CloneAttributes(nsIDOMNode* aDest,
+ nsIDOMNode* aSource)
{
NS_ENSURE_TRUE(aDest && aSource, NS_ERROR_NULL_POINTER);
nsCOMPtr<Element> dest = do_QueryInterface(aDest);
nsCOMPtr<Element> source = do_QueryInterface(aSource);
NS_ENSURE_TRUE(dest && source, NS_ERROR_NO_INTERFACE);
CloneAttributes(dest, source);
return NS_OK;
}
void
-nsEditor::CloneAttributes(Element* aDest, Element* aSource)
+EditorBase::CloneAttributes(Element* aDest,
+ Element* aSource)
{
MOZ_ASSERT(aDest && aSource);
AutoEditBatch beginBatching(this);
// Use transaction system for undo only if destination is already in the
// document
NS_ENSURE_TRUE(GetRoot(), );
@@ -2239,18 +2246,18 @@ nsEditor::CloneAttributes(Element* aDest
// The element is not inserted in the document yet, we don't want to put
// a transaction on the UndoStack
SetAttributeOrEquivalent(static_cast<nsIDOMElement*>(GetAsDOMNode(aDest)),
attr->NodeName(), value, true);
}
}
}
-
-NS_IMETHODIMP nsEditor::ScrollSelectionIntoView(bool aScrollToAnchor)
+NS_IMETHODIMP
+EditorBase::ScrollSelectionIntoView(bool aScrollToAnchor)
{
nsCOMPtr<nsISelectionController> selCon;
if (NS_SUCCEEDED(GetSelectionController(getter_AddRefs(selCon))) && selCon)
{
int16_t region = nsISelectionController::SELECTION_FOCUS_REGION;
if (aScrollToAnchor)
region = nsISelectionController::SELECTION_ANCHOR_REGION;
@@ -2258,18 +2265,18 @@ NS_IMETHODIMP nsEditor::ScrollSelectionI
selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL,
region, nsISelectionController::SCROLL_OVERFLOW_HIDDEN);
}
return NS_OK;
}
void
-nsEditor::FindBetterInsertionPoint(nsCOMPtr<nsINode>& aNode,
- int32_t& aOffset)
+EditorBase::FindBetterInsertionPoint(nsCOMPtr<nsINode>& aNode,
+ int32_t& aOffset)
{
if (aNode->IsNodeOfType(nsINode::eTEXT)) {
// There is no "better" insertion point.
return;
}
if (!IsPlaintextEditor()) {
// We cannot find "better" insertion point in HTML editor.
@@ -2322,20 +2329,20 @@ nsEditor::FindBetterInsertionPoint(nsCOM
aNode = node->GetParentNode();
aOffset = 0;
return;
}
}
}
nsresult
-nsEditor::InsertTextImpl(const nsAString& aStringToInsert,
- nsCOMPtr<nsINode>* aInOutNode,
- int32_t* aInOutOffset,
- nsIDocument* aDoc)
+EditorBase::InsertTextImpl(const nsAString& aStringToInsert,
+ nsCOMPtr<nsINode>* aInOutNode,
+ int32_t* aInOutOffset,
+ nsIDocument* aDoc)
{
// NOTE: caller *must* have already used AutoTransactionsConserveSelection
// stack-based class to turn off txn selection updating. Caller also turned
// on rules sniffing if desired.
NS_ENSURE_TRUE(aInOutNode && *aInOutNode && aInOutOffset && aDoc,
NS_ERROR_NULL_POINTER);
@@ -2397,21 +2404,21 @@ nsEditor::InsertTextImpl(const nsAString
}
}
*aInOutNode = node;
*aInOutOffset = offset;
return NS_OK;
}
-
nsresult
-nsEditor::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
- Text& aTextNode,
- int32_t aOffset, bool aSuppressIME)
+EditorBase::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
+ Text& aTextNode,
+ int32_t aOffset,
+ bool aSuppressIME)
{
RefPtr<EditTransactionBase> transaction;
bool isIMETransaction = false;
int32_t replacedOffset = 0;
int32_t replacedLength = 0;
// aSuppressIME is used when editor must insert text, yet this text is not
// part of the current IME operation. Example: adjusting whitespace around an
// IME insertion.
@@ -2492,45 +2499,43 @@ nsEditor::InsertTextIntoTextNodeImpl(con
mIMETextNode = nullptr;
static_cast<CompositionTransaction*>(transaction.get())->MarkFixed();
}
}
return rv;
}
-
nsresult
-nsEditor::SelectEntireDocument(Selection* aSelection)
+EditorBase::SelectEntireDocument(Selection* aSelection)
{
if (!aSelection) { return NS_ERROR_NULL_POINTER; }
nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(GetRoot());
if (!rootElement) { return NS_ERROR_NOT_INITIALIZED; }
return aSelection->SelectAllChildren(rootElement);
}
-
nsINode*
-nsEditor::GetFirstEditableNode(nsINode* aRoot)
+EditorBase::GetFirstEditableNode(nsINode* aRoot)
{
MOZ_ASSERT(aRoot);
nsIContent* node = GetLeftmostChild(aRoot);
if (node && !IsEditable(node)) {
node = GetNextNode(node, /* aEditableNode = */ true);
}
return (node != aRoot) ? node : nullptr;
}
-
NS_IMETHODIMP
-nsEditor::NotifyDocumentListeners(TDocumentListenerNotification aNotificationType)
+EditorBase::NotifyDocumentListeners(
+ TDocumentListenerNotification aNotificationType)
{
if (!mDocStateListeners.Length()) {
// Maybe there just aren't any.
return NS_OK;
}
nsTArray<OwningNonNull<nsIDocumentStateListener>>
listeners(mDocStateListeners);
@@ -2575,29 +2580,30 @@ nsEditor::NotifyDocumentListeners(TDocum
default:
NS_NOTREACHED("Unknown notification");
}
return rv;
}
-
already_AddRefed<InsertTextTransaction>
-nsEditor::CreateTxnForInsertText(const nsAString& aStringToInsert,
- Text& aTextNode, int32_t aOffset)
+EditorBase::CreateTxnForInsertText(const nsAString& aStringToInsert,
+ Text& aTextNode,
+ int32_t aOffset)
{
RefPtr<InsertTextTransaction> transaction =
new InsertTextTransaction(aTextNode, aOffset, aStringToInsert, *this);
return transaction.forget();
}
nsresult
-nsEditor::DeleteText(nsGenericDOMDataNode& aCharData, uint32_t aOffset,
- uint32_t aLength)
+EditorBase::DeleteText(nsGenericDOMDataNode& aCharData,
+ uint32_t aOffset,
+ uint32_t aLength)
{
RefPtr<DeleteTextTransaction> transaction =
CreateTxnForDeleteText(aCharData, aOffset, aLength);
NS_ENSURE_STATE(transaction);
AutoRules beginRulesSniffing(this, EditAction::deleteText,
nsIEditor::ePrevious);
@@ -2616,64 +2622,63 @@ nsEditor::DeleteText(nsGenericDOMDataNod
static_cast<nsIDOMCharacterData*>(GetAsDOMNode(&aCharData)), aOffset,
aLength, rv);
}
return rv;
}
already_AddRefed<DeleteTextTransaction>
-nsEditor::CreateTxnForDeleteText(nsGenericDOMDataNode& aCharData,
- uint32_t aOffset, uint32_t aLength)
+EditorBase::CreateTxnForDeleteText(nsGenericDOMDataNode& aCharData,
+ uint32_t aOffset,
+ uint32_t aLength)
{
RefPtr<DeleteTextTransaction> transaction =
new DeleteTextTransaction(*this, aCharData, aOffset, aLength,
&mRangeUpdater);
nsresult rv = transaction->Init();
NS_ENSURE_SUCCESS(rv, nullptr);
return transaction.forget();
}
already_AddRefed<SplitNodeTransaction>
-nsEditor::CreateTxnForSplitNode(nsIContent& aNode, uint32_t aOffset)
+EditorBase::CreateTxnForSplitNode(nsIContent& aNode,
+ uint32_t aOffset)
{
RefPtr<SplitNodeTransaction> transaction =
new SplitNodeTransaction(*this, aNode, aOffset);
return transaction.forget();
}
already_AddRefed<JoinNodeTransaction>
-nsEditor::CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode)
+EditorBase::CreateTxnForJoinNode(nsINode& aLeftNode,
+ nsINode& aRightNode)
{
RefPtr<JoinNodeTransaction> transaction =
new JoinNodeTransaction(*this, aLeftNode, aRightNode);
NS_ENSURE_SUCCESS(transaction->CheckValidity(), nullptr);
return transaction.forget();
}
-// END nsEditor core implementation
-
-
-// BEGIN nsEditor public helper methods
-
-struct SavedRange {
+struct SavedRange final
+{
RefPtr<Selection> mSelection;
nsCOMPtr<nsINode> mStartNode;
nsCOMPtr<nsINode> mEndNode;
int32_t mStartOffset;
int32_t mEndOffset;
};
nsresult
-nsEditor::SplitNodeImpl(nsIContent& aExistingRightNode,
- int32_t aOffset,
- nsIContent& aNewLeftNode)
+EditorBase::SplitNodeImpl(nsIContent& aExistingRightNode,
+ int32_t aOffset,
+ nsIContent& aNewLeftNode)
{
// Remember all selection points.
AutoTArray<SavedRange, 10> savedRanges;
for (size_t i = 0; i < kPresentSelectionTypeCount; ++i) {
SelectionType selectionType(ToSelectionType(1 << i));
SavedRange range;
range.mSelection = GetSelection(selectionType);
if (selectionType == SelectionType::eNormal) {
@@ -2796,19 +2801,19 @@ nsEditor::SplitNodeImpl(nsIContent& aExi
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
selection->Collapse(&aNewLeftNode, aOffset);
}
return NS_OK;
}
nsresult
-nsEditor::JoinNodesImpl(nsINode* aNodeToKeep,
- nsINode* aNodeToJoin,
- nsINode* aParent)
+EditorBase::JoinNodesImpl(nsINode* aNodeToKeep,
+ nsINode* aNodeToJoin,
+ nsINode* aParent)
{
MOZ_ASSERT(aNodeToKeep);
MOZ_ASSERT(aNodeToJoin);
MOZ_ASSERT(aParent);
uint32_t firstNodeLength = aNodeToJoin->Length();
int32_t joinOffset;
@@ -2945,83 +2950,87 @@ nsEditor::JoinNodesImpl(nsINode* aNodeTo
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
selection->Collapse(aNodeToKeep, AssertedCast<int32_t>(firstNodeLength));
}
return err.StealNSResult();
}
-
int32_t
-nsEditor::GetChildOffset(nsIDOMNode* aChild, nsIDOMNode* aParent)
+EditorBase::GetChildOffset(nsIDOMNode* aChild,
+ nsIDOMNode* aParent)
{
MOZ_ASSERT(aChild && aParent);
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
nsCOMPtr<nsINode> child = do_QueryInterface(aChild);
MOZ_ASSERT(parent && child);
int32_t idx = parent->IndexOf(child);
MOZ_ASSERT(idx != -1);
return idx;
}
// static
already_AddRefed<nsIDOMNode>
-nsEditor::GetNodeLocation(nsIDOMNode* aChild, int32_t* outOffset)
+EditorBase::GetNodeLocation(nsIDOMNode* aChild,
+ int32_t* outOffset)
{
MOZ_ASSERT(aChild && outOffset);
NS_ENSURE_TRUE(aChild && outOffset, nullptr);
*outOffset = -1;
nsCOMPtr<nsIDOMNode> parent;
MOZ_ALWAYS_SUCCEEDS(aChild->GetParentNode(getter_AddRefs(parent)));
if (parent) {
*outOffset = GetChildOffset(aChild, parent);
}
return parent.forget();
}
nsINode*
-nsEditor::GetNodeLocation(nsINode* aChild, int32_t* aOffset)
+EditorBase::GetNodeLocation(nsINode* aChild,
+ int32_t* aOffset)
{
MOZ_ASSERT(aChild);
MOZ_ASSERT(aOffset);
nsINode* parent = aChild->GetParentNode();
if (parent) {
*aOffset = parent->IndexOf(aChild);
MOZ_ASSERT(*aOffset != -1);
} else {
*aOffset = -1;
}
return parent;
}
-// returns the number of things inside aNode.
-// If aNode is text, returns number of characters. If not, returns number of children nodes.
+/**
+ * Returns the number of things inside aNode. If aNode is text, returns number
+ * of characters. If not, returns number of children nodes.
+ */
nsresult
-nsEditor::GetLengthOfDOMNode(nsIDOMNode *aNode, uint32_t &aCount)
+EditorBase::GetLengthOfDOMNode(nsIDOMNode* aNode,
+ uint32_t& aCount)
{
aCount = 0;
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
aCount = node->Length();
return NS_OK;
}
-
nsIContent*
-nsEditor::GetPriorNode(nsINode* aParentNode,
- int32_t aOffset,
- bool aEditableNode,
- bool aNoBlockCrossing)
+EditorBase::GetPriorNode(nsINode* aParentNode,
+ int32_t aOffset,
+ bool aEditableNode,
+ bool aNoBlockCrossing)
{
MOZ_ASSERT(aParentNode);
// If we are at the beginning of the node, or it is a text node, then just
// look before it.
if (!aOffset || aParentNode->NodeType() == nsIDOMNode::TEXT_NODE) {
if (aNoBlockCrossing && IsBlockNode(aParentNode)) {
// If we aren't allowed to cross blocks, don't look before this block.
@@ -3041,22 +3050,21 @@ nsEditor::GetPriorNode(nsINode* aParentN
if (!resultNode || !aEditableNode || IsEditable(resultNode)) {
return resultNode;
}
// restart the search from the non-editable node we just found
return GetPriorNode(resultNode, aEditableNode, aNoBlockCrossing);
}
-
nsIContent*
-nsEditor::GetNextNode(nsINode* aParentNode,
- int32_t aOffset,
- bool aEditableNode,
- bool aNoBlockCrossing)
+EditorBase::GetNextNode(nsINode* aParentNode,
+ int32_t aOffset,
+ bool aEditableNode,
+ bool aNoBlockCrossing)
{
MOZ_ASSERT(aParentNode);
// if aParentNode is a text node, use its location instead
if (aParentNode->NodeType() == nsIDOMNode::TEXT_NODE) {
nsINode* parent = aParentNode->GetParentNode();
NS_ENSURE_TRUE(parent, nullptr);
aOffset = parent->IndexOf(aParentNode) + 1; // _after_ the text node
@@ -3092,34 +3100,34 @@ nsEditor::GetNextNode(nsINode* aParentNo
if (aNoBlockCrossing && IsBlockNode(aParentNode)) {
// don't cross out of parent block
return nullptr;
}
return GetNextNode(aParentNode, aEditableNode, aNoBlockCrossing);
}
-
nsIContent*
-nsEditor::GetPriorNode(nsINode* aCurrentNode, bool aEditableNode,
- bool aNoBlockCrossing /* = false */)
+EditorBase::GetPriorNode(nsINode* aCurrentNode,
+ bool aEditableNode,
+ bool aNoBlockCrossing /* = false */)
{
MOZ_ASSERT(aCurrentNode);
if (!IsDescendantOfEditorRoot(aCurrentNode)) {
return nullptr;
}
return FindNode(aCurrentNode, false, aEditableNode, aNoBlockCrossing);
}
nsIContent*
-nsEditor::FindNextLeafNode(nsINode *aCurrentNode,
- bool aGoForward,
- bool bNoBlockCrossing)
+EditorBase::FindNextLeafNode(nsINode* aCurrentNode,
+ bool aGoForward,
+ bool bNoBlockCrossing)
{
// called only by GetPriorNode so we don't need to check params.
NS_PRECONDITION(IsDescendantOfEditorRoot(aCurrentNode) &&
!IsEditorRoot(aCurrentNode),
"Bogus arguments");
nsINode* cur = aCurrentNode;
for (;;) {
@@ -3159,34 +3167,34 @@ nsEditor::FindNextLeafNode(nsINode *aCu
cur = parent;
}
NS_NOTREACHED("What part of for(;;) do you not understand?");
return nullptr;
}
nsIContent*
-nsEditor::GetNextNode(nsINode* aCurrentNode,
- bool aEditableNode,
- bool bNoBlockCrossing)
+EditorBase::GetNextNode(nsINode* aCurrentNode,
+ bool aEditableNode,
+ bool bNoBlockCrossing)
{
MOZ_ASSERT(aCurrentNode);
if (!IsDescendantOfEditorRoot(aCurrentNode)) {
return nullptr;
}
return FindNode(aCurrentNode, true, aEditableNode, bNoBlockCrossing);
}
nsIContent*
-nsEditor::FindNode(nsINode *aCurrentNode,
- bool aGoForward,
- bool aEditableNode,
- bool bNoBlockCrossing)
+EditorBase::FindNode(nsINode* aCurrentNode,
+ bool aGoForward,
+ bool aEditableNode,
+ bool bNoBlockCrossing)
{
if (IsEditorRoot(aCurrentNode)) {
// Don't allow traversal above the root node! This helps
// prevent us from accidentally editing browser content
// when the editor is in a text widget.
return nullptr;
}
@@ -3201,18 +3209,18 @@ nsEditor::FindNode(nsINode *aCurrentNode
if (!aEditableNode || IsEditable(candidate)) {
return candidate;
}
return FindNode(candidate, aGoForward, aEditableNode, bNoBlockCrossing);
}
nsIContent*
-nsEditor::GetRightmostChild(nsINode *aCurrentNode,
- bool bNoBlockCrossing)
+EditorBase::GetRightmostChild(nsINode* aCurrentNode,
+ bool bNoBlockCrossing)
{
NS_ENSURE_TRUE(aCurrentNode, nullptr);
nsIContent *cur = aCurrentNode->GetLastChild();
if (!cur) {
return nullptr;
}
for (;;) {
if (bNoBlockCrossing && IsBlockNode(cur)) {
@@ -3225,18 +3233,18 @@ nsEditor::GetRightmostChild(nsINode *aCu
cur = next;
}
NS_NOTREACHED("What part of for(;;) do you not understand?");
return nullptr;
}
nsIContent*
-nsEditor::GetLeftmostChild(nsINode *aCurrentNode,
- bool bNoBlockCrossing)
+EditorBase::GetLeftmostChild(nsINode* aCurrentNode,
+ bool bNoBlockCrossing)
{
NS_ENSURE_TRUE(aCurrentNode, nullptr);
nsIContent *cur = aCurrentNode->GetFirstChild();
if (!cur) {
return nullptr;
}
for (;;) {
if (bNoBlockCrossing && IsBlockNode(cur)) {
@@ -3249,134 +3257,138 @@ nsEditor::GetLeftmostChild(nsINode *aCur
cur = next;
}
NS_NOTREACHED("What part of for(;;) do you not understand?");
return nullptr;
}
bool
-nsEditor::IsBlockNode(nsINode* aNode)
+EditorBase::IsBlockNode(nsINode* aNode)
{
// stub to be overridden in HTMLEditor.
// screwing around with the class hierarchy here in order
// to not duplicate the code in GetNextNode/GetPrevNode
- // across both nsEditor/HTMLEditor.
+ // across both EditorBase/HTMLEditor.
return false;
}
bool
-nsEditor::CanContain(nsINode& aParent, nsIContent& aChild)
+EditorBase::CanContain(nsINode& aParent,
+ nsIContent& aChild)
{
switch (aParent.NodeType()) {
case nsIDOMNode::ELEMENT_NODE:
case nsIDOMNode::DOCUMENT_FRAGMENT_NODE:
return TagCanContain(*aParent.NodeInfo()->NameAtom(), aChild);
}
return false;
}
bool
-nsEditor::CanContainTag(nsINode& aParent, nsIAtom& aChildTag)
+EditorBase::CanContainTag(nsINode& aParent,
+ nsIAtom& aChildTag)
{
switch (aParent.NodeType()) {
case nsIDOMNode::ELEMENT_NODE:
case nsIDOMNode::DOCUMENT_FRAGMENT_NODE:
return TagCanContainTag(*aParent.NodeInfo()->NameAtom(), aChildTag);
}
return false;
}
bool
-nsEditor::TagCanContain(nsIAtom& aParentTag, nsIContent& aChild)
+EditorBase::TagCanContain(nsIAtom& aParentTag,
+ nsIContent& aChild)
{
switch (aChild.NodeType()) {
case nsIDOMNode::TEXT_NODE:
case nsIDOMNode::ELEMENT_NODE:
case nsIDOMNode::DOCUMENT_FRAGMENT_NODE:
return TagCanContainTag(aParentTag, *aChild.NodeInfo()->NameAtom());
}
return false;
}
bool
-nsEditor::TagCanContainTag(nsIAtom& aParentTag, nsIAtom& aChildTag)
+EditorBase::TagCanContainTag(nsIAtom& aParentTag,
+ nsIAtom& aChildTag)
{
return true;
}
bool
-nsEditor::IsRoot(nsIDOMNode* inNode)
+EditorBase::IsRoot(nsIDOMNode* inNode)
{
NS_ENSURE_TRUE(inNode, false);
nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(GetRoot());
return inNode == rootNode;
}
bool
-nsEditor::IsRoot(nsINode* inNode)
+EditorBase::IsRoot(nsINode* inNode)
{
NS_ENSURE_TRUE(inNode, false);
nsCOMPtr<nsINode> rootNode = GetRoot();
return inNode == rootNode;
}
bool
-nsEditor::IsEditorRoot(nsINode* aNode)
+EditorBase::IsEditorRoot(nsINode* aNode)
{
NS_ENSURE_TRUE(aNode, false);
nsCOMPtr<nsINode> rootNode = GetEditorRoot();
return aNode == rootNode;
}
bool
-nsEditor::IsDescendantOfRoot(nsIDOMNode* inNode)
+EditorBase::IsDescendantOfRoot(nsIDOMNode* inNode)
{
nsCOMPtr<nsINode> node = do_QueryInterface(inNode);
return IsDescendantOfRoot(node);
}
bool
-nsEditor::IsDescendantOfRoot(nsINode* inNode)
+EditorBase::IsDescendantOfRoot(nsINode* inNode)
{
NS_ENSURE_TRUE(inNode, false);
nsCOMPtr<nsIContent> root = GetRoot();
NS_ENSURE_TRUE(root, false);
return nsContentUtils::ContentIsDescendantOf(inNode, root);
}
bool
-nsEditor::IsDescendantOfEditorRoot(nsINode* aNode)
+EditorBase::IsDescendantOfEditorRoot(nsINode* aNode)
{
NS_ENSURE_TRUE(aNode, false);
nsCOMPtr<nsIContent> root = GetEditorRoot();
NS_ENSURE_TRUE(root, false);
return nsContentUtils::ContentIsDescendantOf(aNode, root);
}
bool
-nsEditor::IsContainer(nsINode* aNode)
+EditorBase::IsContainer(nsINode* aNode)
{
return aNode ? true : false;
}
bool
-nsEditor::IsContainer(nsIDOMNode* aNode)
+EditorBase::IsContainer(nsIDOMNode* aNode)
{
return aNode ? true : false;
}
static inline bool
-IsElementVisible(dom::Element* aElement)
+IsElementVisible(Element* aElement)
{
if (aElement->GetPrimaryFrame()) {
// It's visible, for our purposes
return true;
}
nsIContent *cur = aElement;
for (; ;) {
@@ -3424,24 +3436,24 @@ IsElementVisible(dom::Element* aElement)
nullptr, nullptr);
if (styleContext) {
return styleContext->StyleDisplay()->mDisplay != NS_STYLE_DISPLAY_NONE;
}
return false;
}
bool
-nsEditor::IsEditable(nsIDOMNode *aNode)
+EditorBase::IsEditable(nsIDOMNode* aNode)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
return IsEditable(content);
}
bool
-nsEditor::IsEditable(nsINode* aNode)
+EditorBase::IsEditable(nsINode* aNode)
{
NS_ENSURE_TRUE(aNode, false);
if (!aNode->IsNodeOfType(nsINode::eCONTENT) || IsMozEditorBogusNode(aNode) ||
!IsModifiableNode(aNode)) {
return false;
}
@@ -3458,214 +3470,195 @@ nsEditor::IsEditable(nsINode* aNode)
case nsIDOMNode::TEXT_NODE:
return true; // element or text node; not invisible
default:
return false;
}
}
bool
-nsEditor::IsMozEditorBogusNode(nsINode* element)
+EditorBase::IsMozEditorBogusNode(nsINode* element)
{
return element && element->IsElement() &&
element->AsElement()->AttrValueIs(kNameSpaceID_None,
kMOZEditorBogusNodeAttrAtom, kMOZEditorBogusNodeValue,
eCaseMatters);
}
uint32_t
-nsEditor::CountEditableChildren(nsINode* aNode)
+EditorBase::CountEditableChildren(nsINode* aNode)
{
MOZ_ASSERT(aNode);
uint32_t count = 0;
for (nsIContent* child = aNode->GetFirstChild();
child;
child = child->GetNextSibling()) {
if (IsEditable(child)) {
++count;
}
}
return count;
}
-//END nsEditor static utility methods
-
-
-NS_IMETHODIMP nsEditor::IncrementModificationCount(int32_t inNumMods)
+NS_IMETHODIMP
+EditorBase::IncrementModificationCount(int32_t inNumMods)
{
uint32_t oldModCount = mModCount;
mModCount += inNumMods;
if ((oldModCount == 0 && mModCount != 0)
|| (oldModCount != 0 && mModCount == 0))
NotifyDocumentListeners(eDocumentStateChanged);
return NS_OK;
}
-NS_IMETHODIMP nsEditor::GetModificationCount(int32_t *outModCount)
+NS_IMETHODIMP
+EditorBase::GetModificationCount(int32_t* outModCount)
{
NS_ENSURE_ARG_POINTER(outModCount);
*outModCount = mModCount;
return NS_OK;
}
-NS_IMETHODIMP nsEditor::ResetModificationCount()
+NS_IMETHODIMP
+EditorBase::ResetModificationCount()
{
bool doNotify = (mModCount != 0);
mModCount = 0;
if (doNotify)
NotifyDocumentListeners(eDocumentStateChanged);
return NS_OK;
}
-//END nsEditor Private methods
-
-
-
-///////////////////////////////////////////////////////////////////////////
-// GetTag: digs out the atom for the tag of this node
-//
-nsIAtom *
-nsEditor::GetTag(nsIDOMNode *aNode)
+nsIAtom*
+EditorBase::GetTag(nsIDOMNode* aNode)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
if (!content)
{
- NS_ASSERTION(aNode, "null node passed to nsEditor::GetTag()");
+ NS_ASSERTION(aNode, "null node passed to EditorBase::GetTag()");
return nullptr;
}
return content->NodeInfo()->NameAtom();
}
-
-///////////////////////////////////////////////////////////////////////////
-// GetTagString: digs out string for the tag of this node
-//
nsresult
-nsEditor::GetTagString(nsIDOMNode *aNode, nsAString& outString)
+EditorBase::GetTagString(nsIDOMNode* aNode,
+ nsAString& outString)
{
if (!aNode)
{
- NS_NOTREACHED("null node passed to nsEditor::GetTagString()");
+ NS_NOTREACHED("null node passed to EditorBase::GetTagString()");
return NS_ERROR_NULL_POINTER;
}
nsIAtom *atom = GetTag(aNode);
if (!atom)
{
return NS_ERROR_FAILURE;
}
atom->ToString(outString);
return NS_OK;
}
-
-///////////////////////////////////////////////////////////////////////////
-// NodesSameType: do these nodes have the same tag?
-//
bool
-nsEditor::NodesSameType(nsIDOMNode *aNode1, nsIDOMNode *aNode2)
+EditorBase::NodesSameType(nsIDOMNode* aNode1,
+ nsIDOMNode* aNode2)
{
if (!aNode1 || !aNode2) {
- NS_NOTREACHED("null node passed to nsEditor::NodesSameType()");
+ NS_NOTREACHED("null node passed to EditorBase::NodesSameType()");
return false;
}
nsCOMPtr<nsIContent> content1 = do_QueryInterface(aNode1);
NS_ENSURE_TRUE(content1, false);
nsCOMPtr<nsIContent> content2 = do_QueryInterface(aNode2);
NS_ENSURE_TRUE(content2, false);
return AreNodesSameType(content1, content2);
}
-/* virtual */
bool
-nsEditor::AreNodesSameType(nsIContent* aNode1, nsIContent* aNode2)
+EditorBase::AreNodesSameType(nsIContent* aNode1,
+ nsIContent* aNode2)
{
MOZ_ASSERT(aNode1);
MOZ_ASSERT(aNode2);
return aNode1->NodeInfo()->NameAtom() == aNode2->NodeInfo()->NameAtom();
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsTextNode: true if node of dom type text
-//
bool
-nsEditor::IsTextNode(nsIDOMNode *aNode)
+EditorBase::IsTextNode(nsIDOMNode* aNode)
{
if (!aNode)
{
NS_NOTREACHED("null node passed to IsTextNode()");
return false;
}
uint16_t nodeType;
aNode->GetNodeType(&nodeType);
return (nodeType == nsIDOMNode::TEXT_NODE);
}
bool
-nsEditor::IsTextNode(nsINode *aNode)
+EditorBase::IsTextNode(nsINode* aNode)
{
return aNode->NodeType() == nsIDOMNode::TEXT_NODE;
}
-///////////////////////////////////////////////////////////////////////////
-// GetChildAt: returns the node at this position index in the parent
-//
nsCOMPtr<nsIDOMNode>
-nsEditor::GetChildAt(nsIDOMNode *aParent, int32_t aOffset)
+EditorBase::GetChildAt(nsIDOMNode* aParent, int32_t aOffset)
{
nsCOMPtr<nsIDOMNode> resultNode;
nsCOMPtr<nsIContent> parent = do_QueryInterface(aParent);
NS_ENSURE_TRUE(parent, resultNode);
resultNode = do_QueryInterface(parent->GetChildAt(aOffset));
return resultNode;
}
-///////////////////////////////////////////////////////////////////////////
-// GetNodeAtRangeOffsetPoint: returns the node at this position in a range,
-// assuming that aParentOrNode is the node itself if it's a text node, or
-// the node's parent otherwise.
-//
+/**
+ * GetNodeAtRangeOffsetPoint() returns the node at this position in a range,
+ * assuming that aParentOrNode is the node itself if it's a text node, or
+ * the node's parent otherwise.
+ */
nsIContent*
-nsEditor::GetNodeAtRangeOffsetPoint(nsIDOMNode* aParentOrNode, int32_t aOffset)
+EditorBase::GetNodeAtRangeOffsetPoint(nsIDOMNode* aParentOrNode,
+ int32_t aOffset)
{
nsCOMPtr<nsINode> parentOrNode = do_QueryInterface(aParentOrNode);
NS_ENSURE_TRUE(parentOrNode || !aParentOrNode, nullptr);
if (parentOrNode->GetAsText()) {
return parentOrNode->AsContent();
}
return parentOrNode->GetChildAt(aOffset);
}
-
-///////////////////////////////////////////////////////////////////////////
-// GetStartNodeAndOffset: returns whatever the start parent & offset is of
-// the first range in the selection.
+/**
+ * GetStartNodeAndOffset() returns whatever the start parent & offset is of
+ * the first range in the selection.
+ */
nsresult
-nsEditor::GetStartNodeAndOffset(Selection* aSelection,
- nsIDOMNode **outStartNode,
- int32_t *outStartOffset)
+EditorBase::GetStartNodeAndOffset(Selection* aSelection,
+ nsIDOMNode** outStartNode,
+ int32_t* outStartOffset)
{
NS_ENSURE_TRUE(outStartNode && outStartOffset && aSelection, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsINode> startNode;
nsresult rv = GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode),
outStartOffset);
if (NS_FAILED(rv)) {
return rv;
@@ -3675,18 +3668,19 @@ nsEditor::GetStartNodeAndOffset(Selectio
NS_ADDREF(*outStartNode = startNode->AsDOMNode());
} else {
*outStartNode = nullptr;
}
return NS_OK;
}
nsresult
-nsEditor::GetStartNodeAndOffset(Selection* aSelection, nsINode** aStartNode,
- int32_t* aStartOffset)
+EditorBase::GetStartNodeAndOffset(Selection* aSelection,
+ nsINode** aStartNode,
+ int32_t* aStartOffset)
{
MOZ_ASSERT(aSelection);
MOZ_ASSERT(aStartNode);
MOZ_ASSERT(aStartOffset);
*aStartNode = nullptr;
*aStartOffset = 0;
@@ -3699,24 +3693,24 @@ nsEditor::GetStartNodeAndOffset(Selectio
NS_ENSURE_TRUE(range->IsPositioned(), NS_ERROR_FAILURE);
NS_IF_ADDREF(*aStartNode = range->GetStartParent());
*aStartOffset = range->StartOffset();
return NS_OK;
}
-
-///////////////////////////////////////////////////////////////////////////
-// GetEndNodeAndOffset: returns whatever the end parent & offset is of
-// the first range in the selection.
+/**
+ * GetEndNodeAndOffset() returns whatever the end parent & offset is of
+ * the first range in the selection.
+ */
nsresult
-nsEditor::GetEndNodeAndOffset(Selection* aSelection,
- nsIDOMNode **outEndNode,
- int32_t *outEndOffset)
+EditorBase::GetEndNodeAndOffset(Selection* aSelection,
+ nsIDOMNode** outEndNode,
+ int32_t* outEndOffset)
{
NS_ENSURE_TRUE(outEndNode && outEndOffset && aSelection, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsINode> endNode;
nsresult rv = GetEndNodeAndOffset(aSelection, getter_AddRefs(endNode),
outEndOffset);
NS_ENSURE_SUCCESS(rv, rv);
@@ -3724,18 +3718,19 @@ nsEditor::GetEndNodeAndOffset(Selection*
NS_ADDREF(*outEndNode = endNode->AsDOMNode());
} else {
*outEndNode = nullptr;
}
return NS_OK;
}
nsresult
-nsEditor::GetEndNodeAndOffset(Selection* aSelection, nsINode** aEndNode,
- int32_t* aEndOffset)
+EditorBase::GetEndNodeAndOffset(Selection* aSelection,
+ nsINode** aEndNode,
+ int32_t* aEndOffset)
{
MOZ_ASSERT(aSelection);
MOZ_ASSERT(aEndNode);
MOZ_ASSERT(aEndOffset);
*aEndNode = nullptr;
*aEndOffset = 0;
@@ -3746,22 +3741,23 @@ nsEditor::GetEndNodeAndOffset(Selection*
NS_ENSURE_TRUE(range->IsPositioned(), NS_ERROR_FAILURE);
NS_IF_ADDREF(*aEndNode = range->GetEndParent());
*aEndOffset = range->EndOffset();
return NS_OK;
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsPreformatted: checks the style info for the node for the preformatted
-// text style.
+/**
+ * IsPreformatted() checks the style info for the node for the preformatted
+ * text style.
+ */
nsresult
-nsEditor::IsPreformatted(nsIDOMNode *aNode, bool *aResult)
+EditorBase::IsPreformatted(nsIDOMNode* aNode,
+ bool* aResult)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
NS_ENSURE_TRUE(aResult && content, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIPresShell> ps = GetPresShell();
NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
@@ -3801,34 +3797,34 @@ nsEditor::IsPreformatted(nsIDOMNode *aNo
* that's why you were splitting the node.
*
* -1 is returned on failure, in unlikely cases like the selection being
* unavailable or cloning the node failing. Make sure not to use the returned
* offset for anything without checking that it's valid! If you're not using
* the offset, it's okay to ignore the return value.
*/
int32_t
-nsEditor::SplitNodeDeep(nsIContent& aNode,
- nsIContent& aSplitPointParent,
- int32_t aSplitPointOffset,
- EmptyContainers aEmptyContainers,
- nsIContent** aOutLeftNode,
- nsIContent** aOutRightNode)
+EditorBase::SplitNodeDeep(nsIContent& aNode,
+ nsIContent& aSplitPointParent,
+ int32_t aSplitPointOffset,
+ EmptyContainers aEmptyContainers,
+ nsIContent** aOutLeftNode,
+ nsIContent** aOutRightNode)
{
MOZ_ASSERT(&aSplitPointParent == &aNode ||
EditorUtils::IsDescendantOf(&aSplitPointParent, &aNode));
int32_t offset = aSplitPointOffset;
nsCOMPtr<nsIContent> leftNode, rightNode;
OwningNonNull<nsIContent> nodeToSplit = aSplitPointParent;
while (true) {
// Need to insert rules code call here to do things like not split a list
// if you are after the last <li> or before the first, etc. For now we
// just have some smarts about unneccessarily splitting text nodes, which
- // should be universal enough to put straight in this nsEditor routine.
+ // should be universal enough to put straight in this EditorBase routine.
bool didSplit = false;
if ((aEmptyContainers == EmptyContainers::yes &&
!nodeToSplit->GetAsText()) ||
(offset && offset != (int32_t)nodeToSplit->Length())) {
didSplit = true;
ErrorResult rv;
@@ -3864,23 +3860,23 @@ nsEditor::SplitNodeDeep(nsIContent& aNod
}
if (aOutRightNode) {
rightNode.forget(aOutRightNode);
}
return offset;
}
-
/**
* This joins two like nodes "deeply", joining children as appropriate.
* Returns the point of the join, or (nullptr, -1) in case of error.
*/
EditorDOMPoint
-nsEditor::JoinNodeDeep(nsIContent& aLeftNode, nsIContent& aRightNode)
+EditorBase::JoinNodeDeep(nsIContent& aLeftNode,
+ nsIContent& aRightNode)
{
// While the rightmost children and their descendants of the left node match
// the leftmost children and their descendants of the right node, join them
// up.
nsCOMPtr<nsIContent> leftNodeToJoin = &aLeftNode;
nsCOMPtr<nsIContent> rightNodeToJoin = &aRightNode;
nsCOMPtr<nsINode> parentNode = aRightNode.GetParentNode();
@@ -3923,17 +3919,17 @@ nsEditor::JoinNodeDeep(nsIContent& aLeft
return ret;
}
}
return ret;
}
void
-nsEditor::BeginUpdateViewBatch()
+EditorBase::BeginUpdateViewBatch()
{
NS_PRECONDITION(mUpdateCount >= 0, "bad state");
if (0 == mUpdateCount)
{
// Turn off selection updates and notifications.
RefPtr<Selection> selection = GetSelection();
@@ -3941,18 +3937,18 @@ nsEditor::BeginUpdateViewBatch()
if (selection) {
selection->StartBatchChanges();
}
}
mUpdateCount++;
}
-
-nsresult nsEditor::EndUpdateViewBatch()
+nsresult
+EditorBase::EndUpdateViewBatch()
{
NS_PRECONDITION(mUpdateCount > 0, "bad state");
if (mUpdateCount <= 0)
{
mUpdateCount = 0;
return NS_ERROR_FAILURE;
}
@@ -3968,25 +3964,24 @@ nsresult nsEditor::EndUpdateViewBatch()
selection->EndBatchChanges();
}
}
return NS_OK;
}
bool
-nsEditor::GetShouldTxnSetSelection()
+EditorBase::GetShouldTxnSetSelection()
{
return mShouldTxnSetSelection;
}
-
NS_IMETHODIMP
-nsEditor::DeleteSelectionImpl(EDirection aAction,
- EStripWrappers aStripWrappers)
+EditorBase::DeleteSelectionImpl(EDirection aAction,
+ EStripWrappers aStripWrappers)
{
MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_STATE(selection);
RefPtr<EditAggregateTransaction> transaction;
nsCOMPtr<nsINode> deleteNode;
int32_t deleteCharOffset = 0, deleteCharLength = 0;
@@ -4032,17 +4027,17 @@ nsEditor::DeleteSelectionImpl(EDirection
}
}
}
return rv;
}
already_AddRefed<Element>
-nsEditor::DeleteSelectionAndCreateElement(nsIAtom& aTag)
+EditorBase::DeleteSelectionAndCreateElement(nsIAtom& aTag)
{
nsresult res = DeleteSelectionAndPrepareToCreateNode();
NS_ENSURE_SUCCESS(res, nullptr);
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, nullptr);
nsCOMPtr<nsINode> node = selection->GetAnchorNode();
@@ -4052,42 +4047,39 @@ nsEditor::DeleteSelectionAndCreateElemen
// We want the selection to be just after the new node
res = selection->Collapse(node, offset + 1);
NS_ENSURE_SUCCESS(res, nullptr);
return newElement.forget();
}
-
-/* Non-interface, protected methods */
-
TextComposition*
-nsEditor::GetComposition() const
+EditorBase::GetComposition() const
{
return mComposition;
}
bool
-nsEditor::IsIMEComposing() const
+EditorBase::IsIMEComposing() const
{
return mComposition && mComposition->IsComposing();
}
bool
-nsEditor::ShouldHandleIMEComposition() const
+EditorBase::ShouldHandleIMEComposition() const
{
// When the editor is being reframed, the old value may be restored with
// InsertText(). In this time, the text should be inserted as not a part
// of the composition.
return mComposition && mDidPostCreate;
}
nsresult
-nsEditor::DeleteSelectionAndPrepareToCreateNode()
+EditorBase::DeleteSelectionAndPrepareToCreateNode()
{
nsresult res;
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
MOZ_ASSERT(selection->GetAnchorFocusRange());
if (!selection->GetAnchorFocusRange()->Collapsed()) {
res = DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
@@ -4129,20 +4121,18 @@ nsEditor::DeleteSelectionAndPrepareToCre
node->GetParentNode()->IndexOf(node));
MOZ_ASSERT(NS_SUCCEEDED(res));
NS_ENSURE_SUCCESS(res, res);
}
}
return NS_OK;
}
-
-
void
-nsEditor::DoAfterDoTransaction(nsITransaction *aTxn)
+EditorBase::DoAfterDoTransaction(nsITransaction* aTxn)
{
bool isTransientTransaction;
MOZ_ALWAYS_SUCCEEDS(aTxn->GetIsTransient(&isTransientTransaction));
if (!isTransientTransaction)
{
// we need to deal here with the case where the user saved after some
// edits, then undid one or more times. Then, the undo count is -ve,
@@ -4153,142 +4143,138 @@ nsEditor::DoAfterDoTransaction(nsITransa
if (modCount < 0)
modCount = -modCount;
// don't count transient transactions
MOZ_ALWAYS_SUCCEEDS(IncrementModificationCount(1));
}
}
-
void
-nsEditor::DoAfterUndoTransaction()
+EditorBase::DoAfterUndoTransaction()
{
// all undoable transactions are non-transient
MOZ_ALWAYS_SUCCEEDS(IncrementModificationCount(-1));
}
void
-nsEditor::DoAfterRedoTransaction()
+EditorBase::DoAfterRedoTransaction()
{
// all redoable transactions are non-transient
MOZ_ALWAYS_SUCCEEDS(IncrementModificationCount(1));
}
already_AddRefed<ChangeAttributeTransaction>
-nsEditor::CreateTxnForSetAttribute(Element& aElement, nsIAtom& aAttribute,
- const nsAString& aValue)
+EditorBase::CreateTxnForSetAttribute(Element& aElement,
+ nsIAtom& aAttribute,
+ const nsAString& aValue)
{
RefPtr<ChangeAttributeTransaction> transaction =
new ChangeAttributeTransaction(aElement, aAttribute, &aValue);
return transaction.forget();
}
-
already_AddRefed<ChangeAttributeTransaction>
-nsEditor::CreateTxnForRemoveAttribute(Element& aElement, nsIAtom& aAttribute)
+EditorBase::CreateTxnForRemoveAttribute(Element& aElement,
+ nsIAtom& aAttribute)
{
RefPtr<ChangeAttributeTransaction> transaction =
new ChangeAttributeTransaction(aElement, aAttribute, nullptr);
return transaction.forget();
}
-
already_AddRefed<CreateElementTransaction>
-nsEditor::CreateTxnForCreateElement(nsIAtom& aTag,
- nsINode& aParent,
- int32_t aPosition)
+EditorBase::CreateTxnForCreateElement(nsIAtom& aTag,
+ nsINode& aParent,
+ int32_t aPosition)
{
RefPtr<CreateElementTransaction> transaction =
new CreateElementTransaction(*this, aTag, aParent, aPosition);
return transaction.forget();
}
already_AddRefed<InsertNodeTransaction>
-nsEditor::CreateTxnForInsertNode(nsIContent& aNode,
- nsINode& aParent,
- int32_t aPosition)
+EditorBase::CreateTxnForInsertNode(nsIContent& aNode,
+ nsINode& aParent,
+ int32_t aPosition)
{
RefPtr<InsertNodeTransaction> transaction =
new InsertNodeTransaction(aNode, aParent, aPosition, *this);
return transaction.forget();
}
nsresult
-nsEditor::CreateTxnForDeleteNode(nsINode* aNode,
- DeleteNodeTransaction** aTransaction)
+EditorBase::CreateTxnForDeleteNode(nsINode* aNode,
+ DeleteNodeTransaction** aTransaction)
{
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
RefPtr<DeleteNodeTransaction> transaction = new DeleteNodeTransaction();
nsresult rv = transaction->Init(this, aNode, &mRangeUpdater);
NS_ENSURE_SUCCESS(rv, rv);
transaction.forget(aTransaction);
return NS_OK;
}
already_AddRefed<CompositionTransaction>
-nsEditor::CreateTxnForComposition(const nsAString& aStringToInsert)
+EditorBase::CreateTxnForComposition(const nsAString& aStringToInsert)
{
MOZ_ASSERT(mIMETextNode);
// During handling IME composition, mComposition must have been initialized.
// TODO: We can simplify CompositionTransaction::Init() with TextComposition
// class.
RefPtr<CompositionTransaction> transaction =
new CompositionTransaction(*mIMETextNode, mIMETextOffset, mIMETextLength,
mComposition->GetRanges(), aStringToInsert,
*this);
return transaction.forget();
}
NS_IMETHODIMP
-nsEditor::CreateTxnForAddStyleSheet(StyleSheetHandle aSheet,
- AddStyleSheetTransaction** aTransaction)
+EditorBase::CreateTxnForAddStyleSheet(StyleSheetHandle aSheet,
+ AddStyleSheetTransaction** aTransaction)
{
RefPtr<AddStyleSheetTransaction> transaction = new AddStyleSheetTransaction();
nsresult rv = transaction->Init(this, aSheet);
if (NS_SUCCEEDED(rv)) {
transaction.forget(aTransaction);
}
return rv;
}
-
-
NS_IMETHODIMP
-nsEditor::CreateTxnForRemoveStyleSheet(
- StyleSheetHandle aSheet,
- RemoveStyleSheetTransaction** aTransaction)
+EditorBase::CreateTxnForRemoveStyleSheet(
+ StyleSheetHandle aSheet,
+ RemoveStyleSheetTransaction** aTransaction)
{
RefPtr<RemoveStyleSheetTransaction> transaction =
new RemoveStyleSheetTransaction();
nsresult rv = transaction->Init(this, aSheet);
if (NS_SUCCEEDED(rv)) {
transaction.forget(aTransaction);
}
return rv;
}
-
nsresult
-nsEditor::CreateTxnForDeleteSelection(EDirection aAction,
- EditAggregateTransaction** aTransaction,
- nsINode** aNode,
- int32_t* aOffset,
- int32_t* aLength)
+EditorBase::CreateTxnForDeleteSelection(EDirection aAction,
+ EditAggregateTransaction** aTransaction,
+ nsINode** aNode,
+ int32_t* aOffset,
+ int32_t* aLength)
{
MOZ_ASSERT(aTransaction);
*aTransaction = nullptr;
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_STATE(selection);
// Check whether the selection is collapsed and we should do nothing:
@@ -4321,18 +4307,19 @@ nsEditor::CreateTxnForDeleteSelection(ED
}
aggregateTransaction.forget(aTransaction);
return NS_OK;
}
already_AddRefed<DeleteTextTransaction>
-nsEditor::CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData,
- uint32_t aOffset, EDirection aDirection)
+EditorBase::CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData,
+ uint32_t aOffset,
+ EDirection aDirection)
{
NS_ASSERTION(aDirection == eNext || aDirection == ePrevious,
"Invalid direction");
nsAutoString data;
aData.GetData(data);
NS_ASSERTION(data.Length(), "Trying to delete from a zero-length node");
NS_ENSURE_TRUE(data.Length(), nullptr);
@@ -4356,23 +4343,23 @@ nsEditor::CreateTxnForDeleteCharacter(ns
return nullptr;
}
return CreateTxnForDeleteText(aData, segOffset, segLength);
}
//XXX: currently, this doesn't handle edge conditions because GetNext/GetPrior
//are not implemented
nsresult
-nsEditor::CreateTxnForDeleteInsertionPoint(
- nsRange* aRange,
- EDirection aAction,
- EditAggregateTransaction* aTransaction,
- nsINode** aNode,
- int32_t* aOffset,
- int32_t* aLength)
+EditorBase::CreateTxnForDeleteInsertionPoint(
+ nsRange* aRange,
+ EDirection aAction,
+ EditAggregateTransaction* aTransaction,
+ nsINode** aNode,
+ int32_t* aOffset,
+ int32_t* aLength)
{
MOZ_ASSERT(aAction != eNone);
nsresult res;
// get the node and offset of the insertion point
nsCOMPtr<nsINode> node = aRange->GetStartParent();
NS_ENSURE_STATE(node);
@@ -4523,26 +4510,28 @@ nsEditor::CreateTxnForDeleteInsertionPoi
NS_ADDREF(*aNode = selectedNode);
}
return NS_OK;
}
nsresult
-nsEditor::CreateRange(nsIDOMNode *aStartParent, int32_t aStartOffset,
- nsIDOMNode *aEndParent, int32_t aEndOffset,
- nsRange** aRange)
+EditorBase::CreateRange(nsIDOMNode* aStartParent,
+ int32_t aStartOffset,
+ nsIDOMNode* aEndParent,
+ int32_t aEndOffset,
+ nsRange** aRange)
{
return nsRange::CreateRange(aStartParent, aStartOffset, aEndParent,
aEndOffset, aRange);
}
nsresult
-nsEditor::AppendNodeToSelectionAsRange(nsIDOMNode *aNode)
+EditorBase::AppendNodeToSelectionAsRange(nsIDOMNode* aNode)
{
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMNode> parentNode;
nsresult res = aNode->GetParentNode(getter_AddRefs(parentNode));
NS_ENSURE_SUCCESS(res, res);
@@ -4553,64 +4542,65 @@ nsEditor::AppendNodeToSelectionAsRange(n
RefPtr<nsRange> range;
res = CreateRange(parentNode, offset, parentNode, offset+1, getter_AddRefs(range));
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
return selection->AddRange(range);
}
-nsresult nsEditor::ClearSelection()
+nsresult
+EditorBase::ClearSelection()
{
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
return selection->RemoveAllRanges();
}
already_AddRefed<Element>
-nsEditor::CreateHTMLContent(nsIAtom* aTag)
+EditorBase::CreateHTMLContent(nsIAtom* aTag)
{
MOZ_ASSERT(aTag);
nsCOMPtr<nsIDocument> doc = GetDocument();
if (!doc) {
return nullptr;
}
// XXX Wallpaper over editor bug (editor tries to create elements with an
// empty nodename).
if (aTag == nsGkAtoms::_empty) {
- NS_ERROR("Don't pass an empty tag to nsEditor::CreateHTMLContent, "
+ NS_ERROR("Don't pass an empty tag to EditorBase::CreateHTMLContent, "
"check caller.");
return nullptr;
}
return doc->CreateElem(nsDependentAtomString(aTag), nullptr,
kNameSpaceID_XHTML);
}
nsresult
-nsEditor::SetAttributeOrEquivalent(nsIDOMElement * aElement,
- const nsAString & aAttribute,
- const nsAString & aValue,
- bool aSuppressTransaction)
+EditorBase::SetAttributeOrEquivalent(nsIDOMElement* aElement,
+ const nsAString& aAttribute,
+ const nsAString& aValue,
+ bool aSuppressTransaction)
{
return SetAttribute(aElement, aAttribute, aValue);
}
nsresult
-nsEditor::RemoveAttributeOrEquivalent(nsIDOMElement * aElement,
- const nsAString & aAttribute,
- bool aSuppressTransaction)
+EditorBase::RemoveAttributeOrEquivalent(nsIDOMElement* aElement,
+ const nsAString& aAttribute,
+ bool aSuppressTransaction)
{
return RemoveAttribute(aElement, aAttribute);
}
nsresult
-nsEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
+EditorBase::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
{
// NOTE: When you change this method, you should also change:
// * editor/libeditor/tests/test_texteditor_keyevent_handling.html
// * editor/libeditor/tests/test_htmleditor_keyevent_handling.html
//
// And also when you add new key handling, you need to change the subclass's
// HandleKeyPressEvent()'s switch statement.
@@ -4658,43 +4648,43 @@ nsEditor::HandleKeyPressEvent(nsIDOMKeyE
DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);
aKeyEvent->AsEvent()->PreventDefault(); // consumed
return NS_OK;
}
return NS_OK;
}
nsresult
-nsEditor::HandleInlineSpellCheck(EditAction action,
+EditorBase::HandleInlineSpellCheck(EditAction action,
Selection* aSelection,
- nsIDOMNode *previousSelectedNode,
+ nsIDOMNode* previousSelectedNode,
int32_t previousSelectedOffset,
- nsIDOMNode *aStartNode,
+ nsIDOMNode* aStartNode,
int32_t aStartOffset,
- nsIDOMNode *aEndNode,
+ nsIDOMNode* aEndNode,
int32_t aEndOffset)
{
// Have to cast action here because this method is from an IDL
return mInlineSpellChecker ? mInlineSpellChecker->SpellCheckAfterEditorChange(
(int32_t)action, aSelection,
previousSelectedNode, previousSelectedOffset,
aStartNode, aStartOffset, aEndNode,
aEndOffset)
: NS_OK;
}
already_AddRefed<nsIContent>
-nsEditor::FindSelectionRoot(nsINode *aNode)
+EditorBase::FindSelectionRoot(nsINode* aNode)
{
nsCOMPtr<nsIContent> rootContent = GetRoot();
return rootContent.forget();
}
nsresult
-nsEditor::InitializeSelection(nsIDOMEventTarget* aFocusEventTarget)
+EditorBase::InitializeSelection(nsIDOMEventTarget* aFocusEventTarget)
{
nsCOMPtr<nsINode> targetNode = do_QueryInterface(aFocusEventTarget);
NS_ENSURE_TRUE(targetNode, NS_ERROR_INVALID_ARG);
nsCOMPtr<nsIContent> selectionRootContent = FindSelectionRoot(targetNode);
if (!selectionRootContent) {
return NS_OK;
}
@@ -4766,17 +4756,17 @@ nsEditor::InitializeSelection(nsIDOMEven
mComposition->GetRanges());
}
}
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::FinalizeSelection()
+EditorBase::FinalizeSelection()
{
nsCOMPtr<nsISelectionController> selCon;
nsresult rv = GetSelectionController(getter_AddRefs(selCon));
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_STATE(selection);
@@ -4817,51 +4807,51 @@ nsEditor::FinalizeSelection()
// independent selection should be marked as disabled.
selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED);
}
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
return NS_OK;
}
-dom::Element *
-nsEditor::GetRoot()
+Element*
+EditorBase::GetRoot()
{
if (!mRootElement)
{
nsCOMPtr<nsIDOMElement> root;
// Let GetRootElement() do the work
GetRootElement(getter_AddRefs(root));
}
return mRootElement;
}
-dom::Element*
-nsEditor::GetEditorRoot()
+Element*
+EditorBase::GetEditorRoot()
{
return GetRoot();
}
Element*
-nsEditor::GetExposedRoot()
+EditorBase::GetExposedRoot()
{
Element* rootElement = GetRoot();
// For plaintext editors, we need to ask the input/textarea element directly.
if (rootElement && rootElement->IsRootOfNativeAnonymousSubtree()) {
rootElement = rootElement->GetParent()->AsElement();
}
return rootElement;
}
nsresult
-nsEditor::DetermineCurrentDirection()
+EditorBase::DetermineCurrentDirection()
{
// Get the current root direction from its frame
nsIContent* rootElement = GetExposedRoot();
NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
// If we don't have an explicit direction, determine our direction
// from the content's direction
if (!(mFlags & (nsIPlaintextEditor::eEditorLeftToRight |
@@ -4878,17 +4868,17 @@ nsEditor::DetermineCurrentDirection()
mFlags |= nsIPlaintextEditor::eEditorLeftToRight;
}
}
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::SwitchTextDirection()
+EditorBase::SwitchTextDirection()
{
// Get the current root direction from its frame
nsIContent* rootElement = GetExposedRoot();
nsresult rv = DetermineCurrentDirection();
NS_ENSURE_SUCCESS(rv, rv);
// Apply the opposite direction
@@ -4909,17 +4899,17 @@ nsEditor::SwitchTextDirection()
if (NS_SUCCEEDED(rv)) {
FireInputEvent();
}
return rv;
}
void
-nsEditor::SwitchTextDirectionTo(uint32_t aDirection)
+EditorBase::SwitchTextDirectionTo(uint32_t aDirection)
{
// Get the current root direction from its frame
nsIContent* rootElement = GetExposedRoot();
nsresult rv = DetermineCurrentDirection();
NS_ENSURE_SUCCESS_VOID(rv);
// Apply the requested direction
@@ -4941,17 +4931,18 @@ nsEditor::SwitchTextDirectionTo(uint32_t
if (NS_SUCCEEDED(rv)) {
FireInputEvent();
}
}
#if DEBUG_JOE
void
-nsEditor::DumpNode(nsIDOMNode *aNode, int32_t indent)
+EditorBase::DumpNode(nsIDOMNode* aNode,
+ int32_t indent)
{
int32_t i;
for (i=0; i<indent; i++)
printf(" ");
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
nsCOMPtr<nsIDOMDocumentFragment> docfrag = do_QueryInterface(aNode);
@@ -4990,50 +4981,50 @@ nsEditor::DumpNode(nsIDOMNode *aNode, in
LossyCopyUTF16toASCII(str, cstr);
cstr.ReplaceChar('\n', ' ');
printf("<textnode> %s\n", cstr.get());
}
}
#endif
bool
-nsEditor::IsModifiableNode(nsIDOMNode *aNode)
+EditorBase::IsModifiableNode(nsIDOMNode* aNode)
{
return true;
}
bool
-nsEditor::IsModifiableNode(nsINode *aNode)
+EditorBase::IsModifiableNode(nsINode* aNode)
{
return true;
}
already_AddRefed<nsIContent>
-nsEditor::GetFocusedContent()
+EditorBase::GetFocusedContent()
{
nsCOMPtr<nsIDOMEventTarget> piTarget = GetDOMEventTarget();
if (!piTarget) {
return nullptr;
}
nsFocusManager* fm = nsFocusManager::GetFocusManager();
NS_ENSURE_TRUE(fm, nullptr);
nsCOMPtr<nsIContent> content = fm->GetFocusedContent();
return SameCOMIdentity(content, piTarget) ? content.forget() : nullptr;
}
already_AddRefed<nsIContent>
-nsEditor::GetFocusedContentForIME()
+EditorBase::GetFocusedContentForIME()
{
return GetFocusedContent();
}
bool
-nsEditor::IsActiveInDOMWindow()
+EditorBase::IsActiveInDOMWindow()
{
nsCOMPtr<nsIDOMEventTarget> piTarget = GetDOMEventTarget();
if (!piTarget) {
return false;
}
nsFocusManager* fm = nsFocusManager::GetFocusManager();
NS_ENSURE_TRUE(fm, false);
@@ -5043,17 +5034,17 @@ nsEditor::IsActiveInDOMWindow()
nsCOMPtr<nsPIDOMWindowOuter> win;
nsIContent* content =
nsFocusManager::GetFocusedDescendant(ourWindow, false,
getter_AddRefs(win));
return SameCOMIdentity(content, piTarget);
}
bool
-nsEditor::IsAcceptableInputEvent(nsIDOMEvent* aEvent)
+EditorBase::IsAcceptableInputEvent(nsIDOMEvent* aEvent)
{
// If the event is trusted, the event should always cause input.
NS_ENSURE_TRUE(aEvent, false);
WidgetEvent* widgetEvent = aEvent->WidgetEventPtr();
if (NS_WARN_IF(!widgetEvent)) {
return false;
}
@@ -5109,49 +5100,49 @@ nsEditor::IsAcceptableInputEvent(nsIDOME
}
// Otherwise, we shouldn't handle any input events when we're not an active
// element of the DOM window.
return IsActiveInDOMWindow();
}
void
-nsEditor::OnFocus(nsIDOMEventTarget* aFocusEventTarget)
+EditorBase::OnFocus(nsIDOMEventTarget* aFocusEventTarget)
{
InitializeSelection(aFocusEventTarget);
if (mInlineSpellChecker) {
mInlineSpellChecker->UpdateCurrentDictionary();
}
}
NS_IMETHODIMP
-nsEditor::GetSuppressDispatchingInputEvent(bool *aSuppressed)
+EditorBase::GetSuppressDispatchingInputEvent(bool* aSuppressed)
{
NS_ENSURE_ARG_POINTER(aSuppressed);
*aSuppressed = !mDispatchInputEvent;
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::SetSuppressDispatchingInputEvent(bool aSuppress)
+EditorBase::SetSuppressDispatchingInputEvent(bool aSuppress)
{
mDispatchInputEvent = !aSuppress;
return NS_OK;
}
NS_IMETHODIMP
-nsEditor::GetIsInEditAction(bool* aIsInEditAction)
+EditorBase::GetIsInEditAction(bool* aIsInEditAction)
{
MOZ_ASSERT(aIsInEditAction, "aIsInEditAction must not be null");
*aIsInEditAction = mIsInEditAction;
return NS_OK;
}
int32_t
-nsEditor::GetIMESelectionStartOffsetIn(nsINode* aTextNode)
+EditorBase::GetIMESelectionStartOffsetIn(nsINode* aTextNode)
{
MOZ_ASSERT(aTextNode, "aTextNode must not be nullptr");
nsCOMPtr<nsISelectionController> selectionController;
nsresult rv = GetSelectionController(getter_AddRefs(selectionController));
NS_ENSURE_SUCCESS(rv, -1);
NS_ENSURE_TRUE(selectionController, -1);
@@ -5187,17 +5178,17 @@ nsEditor::GetIMESelectionStartOffsetIn(n
minOffset = std::min(minOffset, range->EndOffset());
}
}
}
return minOffset < INT32_MAX ? minOffset : -1;
}
void
-nsEditor::HideCaret(bool aHide)
+EditorBase::HideCaret(bool aHide)
{
if (mHidingCaret == aHide) {
return;
}
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
NS_ENSURE_TRUE_VOID(presShell);
RefPtr<nsCaret> caret = presShell->GetCaret();
@@ -5205,8 +5196,10 @@ nsEditor::HideCaret(bool aHide)
mHidingCaret = aHide;
if (aHide) {
caret->AddForceHide();
} else {
caret->RemoveForceHide();
}
}
+
+} // namespace mozilla
rename from editor/libeditor/nsEditor.h
rename to editor/libeditor/EditorBase.h
--- a/editor/libeditor/nsEditor.h
+++ b/editor/libeditor/EditorBase.h
@@ -1,31 +1,31 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
-#ifndef __editor_h__
-#define __editor_h__
+#ifndef mozilla_EditorBase_h
+#define mozilla_EditorBase_h
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc.
#include "mozilla/OwningNonNull.h" // for OwningNonNull
#include "mozilla/SelectionState.h" // for RangeUpdater, etc
#include "mozilla/StyleSheetHandle.h" // for StyleSheetHandle
#include "mozilla/dom/Text.h"
#include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
#include "nsCycleCollectionParticipant.h"
#include "nsGkAtoms.h"
#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 "nsISelectionController.h" // for nsISelectionController constants
-#include "nsISupportsImpl.h" // for nsEditor::Release, etc
+#include "nsISupportsImpl.h" // for EditorBase::Release, etc
#include "nsIWeakReferenceUtils.h" // for nsWeakPtr
#include "nsLiteralString.h" // for NS_LITERAL_STRING
#include "nsString.h" // for nsCString
#include "nsWeakReference.h" // for nsSupportsWeakReference
#include "nscore.h" // for nsresult, nsAString, etc
class nsIAtom;
class nsIContent;
@@ -44,57 +44,22 @@ class nsINode;
class nsIPresShell;
class nsISupports;
class nsITransaction;
class nsIWidget;
class nsRange;
class nsString;
class nsTransactionManager;
-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 mozilla
-
-namespace mozilla {
-namespace widget {
-struct IMEState;
-} // namespace widget
-} // namespace mozilla
-
-#define kMOZEditorBogusNodeAttrAtom nsGkAtoms::mozeditorbogusnode
-#define kMOZEditorBogusNodeValue NS_LITERAL_STRING("TRUE")
-
// This is int32_t instead of int16_t because nsIInlineSpellChecker.idl's
// spellCheckAfterEditorChange is defined to take it as a long.
-enum class EditAction : int32_t {
+// XXX EditAction causes unnecessary include of EditorBase from some places.
+// Why don't you move this to nsIEditor.idl?
+enum class EditAction : int32_t
+{
ignore = -1,
none = 0,
undo,
redo,
insertNode,
createNode,
deleteNode,
splitNode,
@@ -129,96 +94,130 @@ enum class EditAction : int32_t {
increaseZIndex = 3018
};
inline bool operator!(const EditAction& aOp)
{
return aOp == EditAction::none;
}
-/** 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.
+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.
*/
-class nsEditor : public nsIEditor,
- public nsIEditorIMESupport,
- public nsSupportsWeakReference,
- public nsIPhonetic
+class EditorBase : public nsIEditor
+ , public nsIEditorIMESupport
+ , public nsSupportsWeakReference
+ , public nsIPhonetic
{
public:
- typedef mozilla::ErrorResult ErrorResult;
- typedef mozilla::dom::Element Element;
- typedef mozilla::dom::Selection Selection;
- typedef mozilla::dom::Text Text;
- template<typename T> using OwningNonNull = mozilla::OwningNonNull<T>;
+ typedef dom::Element Element;
+ typedef dom::Selection Selection;
+ typedef dom::Text Text;
enum IterDirection
{
kIterForward,
kIterBackward
};
- /** The default constructor. This should suffice. the setting of the interfaces is done
- * after the construction of the editor class.
+ /**
+ * The default constructor. This should suffice. the setting of the
+ * interfaces is done after the construction of the editor class.
*/
- nsEditor();
+ EditorBase();
protected:
- /** The default destructor. This should suffice. Should this be pure virtual
- * for someone to derive from the nsEditor later? I don't believe so.
+ /**
+ * The default destructor. This should suffice. Should this be pure virtual
+ * for someone to derive from the EditorBase later? I don't believe so.
*/
- virtual ~nsEditor();
+ virtual ~EditorBase();
public:
-//Interfaces for addref and release and queryinterface
-//NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsEditor
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
- NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsEditor,
- nsIEditor)
+ NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(EditorBase, nsIEditor)
- /* ------------ utility methods -------------- */
already_AddRefed<nsIDOMDocument> GetDOMDocument();
already_AddRefed<nsIDocument> GetDocument();
already_AddRefed<nsIPresShell> GetPresShell();
already_AddRefed<nsIWidget> GetWidget();
enum NotificationForEditorObservers
{
eNotifyEditorObserversOfEnd,
eNotifyEditorObserversOfBefore,
eNotifyEditorObserversOfCancel
};
void NotifyEditorObservers(NotificationForEditorObservers aNotification);
- /* ------------ nsIEditor methods -------------- */
+ // nsIEditor methods
NS_DECL_NSIEDITOR
- /* ------------ nsIEditorIMESupport methods -------------- */
+ // nsIEditorIMESupport methods
NS_DECL_NSIEDITORIMESUPPORT
// nsIPhonetic
NS_DECL_NSIPHONETIC
public:
-
- virtual bool IsModifiableNode(nsINode *aNode);
+ virtual bool IsModifiableNode(nsINode* aNode);
virtual nsresult InsertTextImpl(const nsAString& aStringToInsert,
nsCOMPtr<nsINode>* aInOutNode,
int32_t* aInOutOffset,
nsIDocument* aDoc);
nsresult InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
Text& aTextNode, int32_t aOffset,
bool aSuppressIME = false);
NS_IMETHOD DeleteSelectionImpl(EDirection aAction,
EStripWrappers aStripWrappers);
already_AddRefed<Element> DeleteSelectionAndCreateElement(nsIAtom& aTag);
- /* helper routines for node/parent manipulations */
+ /**
+ * Helper routines for node/parent manipulations.
+ */
nsresult DeleteNode(nsINode* aNode);
nsresult InsertNode(nsIContent& aNode, nsINode& aParent, int32_t aPosition);
enum ECloneAttributes { eDontCloneAttributes, eCloneAttributes };
already_AddRefed<Element> ReplaceContainer(Element* aOldContainer,
nsIAtom* aNodeType,
nsIAtom* aAttribute = nullptr,
const nsAString* aValue = nullptr,
ECloneAttributes aCloneAttributes
@@ -231,220 +230,250 @@ public:
nsIAtom* aAttribute = nullptr,
const nsAString* aValue =
nullptr);
nsIContent* SplitNode(nsIContent& aNode, int32_t aOffset,
ErrorResult& aResult);
nsresult JoinNodes(nsINode& aLeftNode, nsINode& aRightNode);
nsresult MoveNode(nsIContent* aNode, nsINode* aParent, int32_t aOffset);
- /* Method to replace certain CreateElementNS() calls.
- Arguments:
- nsIAtom* aTag - tag you want
- */
+ /**
+ * Method to replace certain CreateElementNS() calls.
+ *
+ * @param aTag Tag you want.
+ */
already_AddRefed<Element> CreateHTMLContent(nsIAtom* aTag);
- // IME event handlers
- virtual nsresult BeginIMEComposition(mozilla::WidgetCompositionEvent* aEvent);
+ /**
+ * IME event handlers.
+ */
+ virtual nsresult BeginIMEComposition(WidgetCompositionEvent* aEvent);
virtual nsresult UpdateIMEComposition(nsIDOMEvent* aDOMTextEvent) = 0;
void EndIMEComposition();
void SwitchTextDirectionTo(uint32_t aDirection);
protected:
nsresult DetermineCurrentDirection();
void FireInputEvent();
- /** Create a transaction for setting aAttribute to aValue on aElement. Never
- * returns null.
- */
- already_AddRefed<mozilla::ChangeAttributeTransaction>
- CreateTxnForSetAttribute(Element& aElement, nsIAtom& aAttribute,
- const nsAString& aValue);
+ /**
+ * 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<mozilla::ChangeAttributeTransaction>
- CreateTxnForRemoveAttribute(Element& aElement, nsIAtom& aAttribute);
+ /**
+ * 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<mozilla::CreateElementTransaction>
- CreateTxnForCreateElement(nsIAtom& aTag,
- nsINode& aParent,
- int32_t aPosition);
+ /**
+ * 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);
already_AddRefed<Element> CreateNode(nsIAtom* aTag, nsINode* aParent,
int32_t aPosition);
- /** create a transaction for inserting aNode as a child of aParent.
- */
- already_AddRefed<mozilla::InsertNodeTransaction>
- CreateTxnForInsertNode(nsIContent& aNode, nsINode& aParent, int32_t aOffset);
+ /**
+ * Create a transaction for inserting aNode as a child of aParent.
+ */
+ already_AddRefed<InsertNodeTransaction>
+ CreateTxnForInsertNode(nsIContent& aNode, nsINode& aParent,
+ int32_t aOffset);
- /** create a transaction for removing aNode from its parent.
- */
- nsresult CreateTxnForDeleteNode(
- nsINode* aNode,
- mozilla::DeleteNodeTransaction** aTransaction);
+ /**
+ * Create a transaction for removing aNode from its parent.
+ */
+ nsresult CreateTxnForDeleteNode(nsINode* aNode,
+ DeleteNodeTransaction** aTransaction);
nsresult CreateTxnForDeleteSelection(
EDirection aAction,
- mozilla::EditAggregateTransaction** aTransaction,
+ EditAggregateTransaction** aTransaction,
nsINode** aNode,
int32_t* aOffset,
int32_t* aLength);
nsresult CreateTxnForDeleteInsertionPoint(
nsRange* aRange,
EDirection aAction,
- mozilla::EditAggregateTransaction* aTransaction,
+ EditAggregateTransaction* aTransaction,
nsINode** aNode,
int32_t* aOffset,
int32_t* aLength);
- /** Create a transaction for inserting aStringToInsert into aTextNode. Never
- * returns null.
- */
+ /**
+ * Create a transaction for inserting aStringToInsert into aTextNode. Never
+ * returns null.
+ */
already_AddRefed<mozilla::InsertTextTransaction>
- CreateTxnForInsertText(const nsAString& aStringToInsert, Text& aTextNode,
- int32_t aOffset);
+ CreateTxnForInsertText(const nsAString& aStringToInsert, Text& aTextNode,
+ int32_t aOffset);
- // Never returns null.
+ /**
+ * Never returns null.
+ */
already_AddRefed<mozilla::CompositionTransaction>
- CreateTxnForComposition(const nsAString& aStringToInsert);
+ CreateTxnForComposition(const nsAString& aStringToInsert);
- /** create a transaction for adding a style sheet
- */
+ /**
+ * Create a transaction for adding a style sheet.
+ */
NS_IMETHOD CreateTxnForAddStyleSheet(
- mozilla::StyleSheetHandle aSheet,
- mozilla::AddStyleSheetTransaction** aTransaction);
+ StyleSheetHandle aSheet,
+ AddStyleSheetTransaction** aTransaction);
- /** create a transaction for removing a style sheet
- */
+ /**
+ * Create a transaction for removing a style sheet.
+ */
NS_IMETHOD CreateTxnForRemoveStyleSheet(
- mozilla::StyleSheetHandle aSheet,
- mozilla::RemoveStyleSheetTransaction** aTransaction);
+ StyleSheetHandle aSheet,
+ RemoveStyleSheetTransaction** aTransaction);
nsresult DeleteText(nsGenericDOMDataNode& aElement,
uint32_t aOffset, uint32_t aLength);
-// NS_IMETHOD DeleteRange(nsIDOMRange *aRange);
-
- already_AddRefed<mozilla::DeleteTextTransaction>
- CreateTxnForDeleteText(nsGenericDOMDataNode& aElement,
- uint32_t aOffset, uint32_t aLength);
+ already_AddRefed<DeleteTextTransaction>
+ CreateTxnForDeleteText(nsGenericDOMDataNode& aElement,
+ uint32_t aOffset, uint32_t aLength);
- already_AddRefed<mozilla::DeleteTextTransaction>
- CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData, uint32_t aOffset,
- EDirection aDirection);
+ already_AddRefed<DeleteTextTransaction>
+ CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData, uint32_t aOffset,
+ EDirection aDirection);
- already_AddRefed<mozilla::SplitNodeTransaction>
- CreateTxnForSplitNode(nsIContent& aNode, uint32_t aOffset);
+ already_AddRefed<SplitNodeTransaction>
+ CreateTxnForSplitNode(nsIContent& aNode, uint32_t aOffset);
- already_AddRefed<mozilla::JoinNodeTransaction>
- CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode);
+ already_AddRefed<JoinNodeTransaction>
+ CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode);
/**
* 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();
-
- // called after a transaction is done successfully
+ /**
+ * Called after a transaction is done successfully.
+ */
void DoAfterDoTransaction(nsITransaction *aTxn);
- // called after a transaction is undone successfully
+
+ /**
+ * Called after a transaction is undone successfully.
+ */
+
void DoAfterUndoTransaction();
- // called after a transaction is redone successfully
+
+ /**
+ * Called after a transaction is redone successfully.
+ */
void DoAfterRedoTransaction();
- typedef enum {
+ enum TDocumentListenerNotification
+ {
eDocumentCreated,
eDocumentToBeDestroyed,
eDocumentStateChanged
- } TDocumentListenerNotification;
+ };
- // tell the doc state listeners that the doc state has changed
- NS_IMETHOD NotifyDocumentListeners(TDocumentListenerNotification aNotificationType);
+ /**
+ * Tell the doc state listeners that the doc state has changed.
+ */
+ NS_IMETHOD NotifyDocumentListeners(
+ TDocumentListenerNotification aNotificationType);
- /** make the given selection span the entire document */
+ /**
+ * Make the given selection span the entire document.
+ */
virtual nsresult SelectEntireDocument(Selection* aSelection);
- /** 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.
+ /**
+ * 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.
*
- * 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.
+ * 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.
*/
NS_IMETHOD ScrollSelectionIntoView(bool aScrollToAnchor);
- // stub. see comment in source.
virtual bool IsBlockNode(nsINode* aNode);
- // helper for GetPriorNode and GetNextNode
- nsIContent* FindNextLeafNode(nsINode *aCurrentNode,
- bool aGoForward,
- bool bNoBlockCrossing);
+ /**
+ * Helper for GetPriorNode() and GetNextNode().
+ */
+ nsIContent* FindNextLeafNode(nsINode* aCurrentNode,
+ bool aGoForward,
+ bool bNoBlockCrossing);
- // install the event listeners for the editor
virtual nsresult InstallEventListeners();
-
virtual void CreateEventListeners();
-
- // unregister and release our event listeners
virtual void RemoveEventListeners();
/**
* Return true if spellchecking should be enabled for this editor.
*/
bool GetDesiredSpellCheckState();
bool CanEnableSpellCheck()
{
// Check for password/readonly/disabled, which are not spellchecked
- // regardless of DOM. Also, check to see if spell check should be skipped or not.
- return !IsPasswordEditor() && !IsReadonly() && !IsDisabled() && !ShouldSkipSpellCheck();
+ // regardless of DOM. Also, check to see if spell check should be skipped
+ // or not.
+ return !IsPasswordEditor() && !IsReadonly() && !IsDisabled() &&
+ !ShouldSkipSpellCheck();
}
/**
* EnsureComposition() should be called by composition event handlers. This
* tries to get the composition for the event and set it to mComposition.
*/
- void EnsureComposition(mozilla::WidgetCompositionEvent* aCompositionEvent);
+ void EnsureComposition(WidgetCompositionEvent* aCompositionEvent);
- nsresult GetSelection(mozilla::SelectionType aSelectionType,
+ nsresult GetSelection(SelectionType aSelectionType,
nsISelection** aSelection);
public:
-
- /** All editor operations which alter the doc should be prefaced
- * with a call to StartOperation, naming the action and direction */
+ /**
+ * All editor operations which alter the doc should be prefaced
+ * with a call to StartOperation, naming the action and direction.
+ */
NS_IMETHOD StartOperation(EditAction opID,
nsIEditor::EDirection aDirection);
- /** All editor operations which alter the doc should be followed
- * with a call to EndOperation */
+ /**
+ * 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 */
- bool ArePreservingSelection();
- void PreserveSelectionAcrossActions(Selection* aSel);
+ /**
+ * Routines for managing the preservation of selection across
+ * various editor actions.
+ */
+ bool ArePreservingSelection();
+ void PreserveSelectionAcrossActions(Selection* aSel);
nsresult RestorePreservedSelection(Selection* aSel);
- void StopPreservingSelection();
+ void StopPreservingSelection();
/**
* 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
@@ -454,239 +483,291 @@ public:
nsresult SplitNodeImpl(nsIContent& aExistingRightNode,
int32_t aOffset,
nsIContent& aNewLeftNode);
/**
* 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.
+ * There is no requirement that the two nodes be of the
+ * same type.
* @param aParent The parent of aNodeToKeep
*/
nsresult JoinNodesImpl(nsINode* aNodeToKeep,
nsINode* aNodeToJoin,
nsINode* aParent);
/**
* Return the offset of aChild in aParent. Asserts fatally if parent or
* child is null, or parent is not child's parent.
*/
- static int32_t GetChildOffset(nsIDOMNode *aChild,
- nsIDOMNode *aParent);
+ static int32_t GetChildOffset(nsIDOMNode* aChild,
+ nsIDOMNode* aParent);
/**
- * Set outOffset to the offset of aChild in the parent.
- * Returns the parent of aChild.
+ * Set outOffset to the offset of aChild in the parent.
+ * Returns the parent of aChild.
*/
static already_AddRefed<nsIDOMNode> GetNodeLocation(nsIDOMNode* aChild,
int32_t* outOffset);
static nsINode* GetNodeLocation(nsINode* aChild, int32_t* aOffset);
- /** 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.
- */
+ /**
+ * 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.
+ */
static nsresult GetLengthOfDOMNode(nsIDOMNode *aNode, uint32_t &aCount);
- /** 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.
- */
+ /**
+ * 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.
+ */
nsIContent* GetPriorNode(nsINode* aCurrentNode, bool aEditableNode,
bool aNoBlockCrossing = false);
- // and another version that takes a {parent,offset} pair rather than a node
+ /**
+ * And another version that takes a {parent,offset} pair rather than a node.
+ */
nsIContent* GetPriorNode(nsINode* aParentNode,
int32_t aOffset,
bool aEditableNode,
bool aNoBlockCrossing = false);
- /** 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.
- */
+ /**
+ * 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.
+ */
nsIContent* GetNextNode(nsINode* aCurrentNode,
bool aEditableNode,
bool bNoBlockCrossing = false);
- // and another version that takes a {parent,offset} pair rather than a node
+ /**
+ * And another version that takes a {parent,offset} pair rather than a node.
+ */
nsIContent* GetNextNode(nsINode* aParentNode,
int32_t aOffset,
bool aEditableNode,
bool aNoBlockCrossing = false);
- // Helper for GetNextNode and GetPriorNode
- nsIContent* FindNode(nsINode *aCurrentNode,
- bool aGoForward,
- bool aEditableNode,
- bool bNoBlockCrossing);
+ /**
+ * Helper for GetNextNode() and GetPriorNode().
+ */
+ nsIContent* FindNode(nsINode* aCurrentNode,
+ bool aGoForward,
+ bool aEditableNode,
+ bool bNoBlockCrossing);
/**
* Get the rightmost child of aCurrentNode;
* return nullptr if aCurrentNode has no children.
*/
- nsIContent* GetRightmostChild(nsINode *aCurrentNode,
- bool bNoBlockCrossing = false);
+ nsIContent* GetRightmostChild(nsINode* aCurrentNode,
+ bool bNoBlockCrossing = false);
/**
* Get the leftmost child of aCurrentNode;
* return nullptr if aCurrentNode has no children.
*/
nsIContent* GetLeftmostChild(nsINode *aCurrentNode,
- bool bNoBlockCrossing = false);
+ bool bNoBlockCrossing = false);
- /** returns true if aNode is of the type implied by aTag */
- static inline bool NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag)
+ /**
+ * Returns true if aNode is of the type implied by aTag.
+ */
+ static inline bool NodeIsType(nsIDOMNode* aNode, nsIAtom* aTag)
{
return GetTag(aNode) == aTag;
}
- /** returns true if aParent can contain a child of type aTag */
+ /**
+ * Returns true if aParent can contain a child of type aTag.
+ */
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);
- /** returns true if aNode is our root node */
+ /**
+ * Returns true if aNode is our root node.
+ */
bool IsRoot(nsIDOMNode* inNode);
bool IsRoot(nsINode* inNode);
bool IsEditorRoot(nsINode* aNode);
- /** returns true if aNode is a descendant of our root node */
+ /**
+ * Returns true if aNode is a descendant of our root node.
+ */
bool IsDescendantOfRoot(nsIDOMNode* inNode);
bool IsDescendantOfRoot(nsINode* inNode);
bool IsDescendantOfEditorRoot(nsINode* aNode);
- /** returns true if aNode is a container */
+ /**
+ * Returns true if aNode is a container.
+ */
virtual bool IsContainer(nsINode* aNode);
virtual bool IsContainer(nsIDOMNode* aNode);
- /** returns true if aNode is an editable node */
- bool IsEditable(nsIDOMNode *aNode);
+ /**
+ * returns true if aNode is an editable node.
+ */
+ bool IsEditable(nsIDOMNode* aNode);
virtual bool IsEditable(nsINode* aNode);
- /** returns true if aNode is a MozEditorBogus node */
+ /**
+ * Returns true if aNode is a MozEditorBogus node.
+ */
bool IsMozEditorBogusNode(nsINode* aNode);
- /** counts number of editable child nodes */
+ /**
+ * Counts number of editable child nodes.
+ */
uint32_t CountEditableChildren(nsINode* aNode);
- /** Find the deep first and last children. */
+ /**
+ * Find the deep first and last children.
+ */
nsINode* GetFirstEditableNode(nsINode* aRoot);
/**
* Returns current composition.
*/
- mozilla::TextComposition* GetComposition() const;
+ TextComposition* GetComposition() const;
+
/**
* Returns true if there is composition string and not fixed.
*/
bool IsIMEComposing() const;
+
/**
* Returns true when inserting text should be a part of current composition.
*/
bool ShouldHandleIMEComposition() const;
- /** from html rules code - migration in progress */
- static nsresult GetTagString(nsIDOMNode *aNode, nsAString& outString);
- static nsIAtom *GetTag(nsIDOMNode *aNode);
+ /**
+ * From html rules code - migration in progress.
+ */
+ static nsresult GetTagString(nsIDOMNode* aNode, nsAString& outString);
+ static nsIAtom* GetTag(nsIDOMNode* aNode);
- bool NodesSameType(nsIDOMNode *aNode1, nsIDOMNode *aNode2);
+ bool NodesSameType(nsIDOMNode* aNode1, nsIDOMNode* aNode2);
virtual bool AreNodesSameType(nsIContent* aNode1, nsIContent* aNode2);
- static bool IsTextNode(nsIDOMNode *aNode);
- static bool IsTextNode(nsINode *aNode);
+ static bool IsTextNode(nsIDOMNode* aNode);
+ static bool IsTextNode(nsINode* aNode);
- static nsCOMPtr<nsIDOMNode> GetChildAt(nsIDOMNode *aParent, int32_t aOffset);
+ static nsCOMPtr<nsIDOMNode> GetChildAt(nsIDOMNode* aParent, int32_t aOffset);
static nsIContent* GetNodeAtRangeOffsetPoint(nsIDOMNode* aParentOrNode,
int32_t aOffset);
static nsresult GetStartNodeAndOffset(Selection* aSelection,
nsIDOMNode** outStartNode,
int32_t* outStartOffset);
static nsresult GetStartNodeAndOffset(Selection* aSelection,
nsINode** aStartNode,
int32_t* aStartOffset);
static nsresult GetEndNodeAndOffset(Selection* aSelection,
nsIDOMNode** outEndNode,
int32_t* outEndOffset);
static nsresult GetEndNodeAndOffset(Selection* aSelection,
nsINode** aEndNode,
int32_t* aEndOffset);
#if DEBUG_JOE
- static void DumpNode(nsIDOMNode *aNode, int32_t indent=0);
+ static void DumpNode(nsIDOMNode* aNode, int32_t indent = 0);
#endif
- Selection* GetSelection(mozilla::SelectionType aSelectionType =
- mozilla::SelectionType::eNormal);
+ Selection* GetSelection(SelectionType aSelectionType =
+ SelectionType::eNormal);
- // 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,
+ /**
+ * 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,
nsRange** aRange);
- // Creates a range with just the supplied node and appends that to the selection
+ /**
+ * 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
+
+ /**
+ * When you are using AppendNodeToSelectionAsRange(), call this first to
+ * start a new selection.
+ */
nsresult ClearSelection();
- nsresult IsPreformatted(nsIDOMNode *aNode, bool *aResult);
+ nsresult IsPreformatted(nsIDOMNode* aNode, bool* aResult);
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);
- mozilla::EditorDOMPoint JoinNodeDeep(nsIContent& aLeftNode,
- nsIContent& aRightNode);
+ EditorDOMPoint JoinNodeDeep(nsIContent& aLeftNode,
+ nsIContent& aRightNode);
nsresult GetString(const nsAString& name, nsAString& value);
- void BeginUpdateViewBatch(void);
- virtual nsresult EndUpdateViewBatch(void);
+ void BeginUpdateViewBatch();
+ virtual nsresult EndUpdateViewBatch();
bool GetShouldTxnSetSelection();
virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
nsresult HandleInlineSpellCheck(EditAction action,
Selection* aSelection,
- nsIDOMNode *previousSelectedNode,
- int32_t previousSelectedOffset,
- nsIDOMNode *aStartNode,
- int32_t aStartOffset,
- nsIDOMNode *aEndNode,
- int32_t aEndOffset);
+ nsIDOMNode* previousSelectedNode,
+ int32_t previousSelectedOffset,
+ nsIDOMNode* aStartNode,
+ int32_t aStartOffset,
+ nsIDOMNode* aEndNode,
+ int32_t aEndOffset);
- virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget() = 0;
+ virtual already_AddRefed<dom::EventTarget> GetDOMEventTarget() = 0;
- // Fast non-refcounting editor root element accessor
+ /**
+ * Fast non-refcounting editor root element accessor
+ */
Element* GetRoot();
- // Likewise, but gets the editor's root instead, which is different for HTML
- // editors
+ /**
+ * Likewise, but gets the editor's root instead, which is different for HTML
+ * editors.
+ */
virtual Element* GetEditorRoot();
- // Likewise, but gets the text control element instead of the root for
- // plaintext editors
+ /**
+ * Likewise, but gets the text control element instead of the root for
+ * plaintext editors.
+ */
Element* GetExposedRoot();
- // Accessor methods to flags
+ /**
+ * Accessor methods to flags.
+ */
bool IsPlaintextEditor() const
{
return (mFlags & nsIPlaintextEditor::eEditorPlaintextMask) != 0;
}
bool IsSingleLineEditor() const
{
return (mFlags & nsIPlaintextEditor::eEditorSingleLineMask) != 0;
@@ -753,67 +834,88 @@ public:
IsInteractionAllowed();
}
bool HasIndependentSelection() const
{
return !!mSelConWeak;
}
- // Get the input event target. This might return null.
+ /**
+ * Get the input event target. This might return null.
+ */
virtual already_AddRefed<nsIContent> GetInputEventTargetContent() = 0;
- // Get the focused content, if we're focused. Returns null otherwise.
+ /**
+ * Get the focused content, if we're focused. Returns null otherwise.
+ */
virtual already_AddRefed<nsIContent> GetFocusedContent();
- // Get the focused content for the argument of some IMEStateManager's
- // methods.
+ /**
+ * Get the focused content for the argument of some IMEStateManager's
+ * methods.
+ */
virtual already_AddRefed<nsIContent> GetFocusedContentForIME();
- // 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.
+ /**
+ * 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.
+ */
virtual bool IsActiveInDOMWindow();
- // 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.
+ /**
+ * 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.
+ */
virtual bool IsAcceptableInputEvent(nsIDOMEvent* aEvent);
- // 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.
+ /**
+ * 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.
+ */
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.
+ /**
+ * 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);
- // 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.
+ /**
+ * 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.
+ */
void OnFocus(nsIDOMEventTarget* aFocusEventTarget);
- // 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(mozilla::dom::DataTransfer *aDataTransfer,
+ /**
+ * 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,
int32_t aIndex,
- nsIDOMDocument *aSourceDoc,
- nsIDOMNode *aDestinationNode,
+ nsIDOMDocument* aSourceDoc,
+ nsIDOMNode* aDestinationNode,
int32_t aDestOffset,
bool aDoDeleteSelection) = 0;
virtual nsresult InsertFromDrop(nsIDOMEvent* aDropEvent) = 0;
- virtual already_AddRefed<nsIDOMNode> FindUserSelectAllNode(nsIDOMNode* aNode) { return nullptr; }
+ virtual already_AddRefed<nsIDOMNode> FindUserSelectAllNode(nsIDOMNode* aNode)
+ {
+ return nullptr;
+ }
/**
* GetIMESelectionStartOffsetIn() returns the start offset of IME selection in
* the aTextNode. If there is no IME selection, returns -1.
*/
int32_t GetIMESelectionStartOffsetIn(nsINode* aTextNode);
/**
@@ -826,80 +928,102 @@ public:
/**
* 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);
protected:
- enum Tristate {
+ enum Tristate
+ {
eTriUnset,
eTriFalse,
eTriTrue
};
- // Spellchecking
- nsCString mContentMIMEType; // MIME type of the doc we are editing.
+
+ // MIME type of the doc we are editing.
+ nsCString mContentMIMEType;
nsCOMPtr<nsIInlineSpellChecker> mInlineSpellChecker;
RefPtr<nsTransactionManager> mTxnMgr;
- nsCOMPtr<Element> mRootElement; // cached root node
- RefPtr<Text> mIMETextNode; // current IME text node
- nsCOMPtr<mozilla::dom::EventTarget> mEventTarget; // The form field as an event receiver
+ // Cached root node.
+ nsCOMPtr<Element> mRootElement;
+ // Current IME text node.
+ RefPtr<Text> mIMETextNode;
+ // The form field as an event receiver.
+ nsCOMPtr<dom::EventTarget> mEventTarget;
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
+ // 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;
// Saved selection state for placeholder transaction batching.
- mozilla::SelectionState* mSelState;
- nsString *mPhonetic;
+ SelectionState* mSelState;
+ nsString* mPhonetic;
// IME composition this is not null between compositionstart and
// compositionend.
- RefPtr<mozilla::TextComposition> mComposition;
+ RefPtr<TextComposition> mComposition;
- // various listeners
- // Listens to all low level actions on the doc
+ // Listens to all low level actions on the doc.
nsTArray<OwningNonNull<nsIEditActionListener>> mActionListeners;
- // Just notify once per high level change
+ // Just notify once per high level change.
nsTArray<OwningNonNull<nsIEditorObserver>> mEditorObservers;
- // Listen to overall doc state (dirty or not, just created, etc)
+ // Listen to overall doc state (dirty or not, just created, etc).
nsTArray<OwningNonNull<nsIDocumentStateListener>> mDocStateListeners;
// Cached selection for AutoSelectionRestorer.
- mozilla::SelectionState mSavedSel;
+ SelectionState mSavedSel;
// Utility class object for maintaining preserved ranges.
- mozilla::RangeUpdater mRangeUpdater;
+ RangeUpdater mRangeUpdater;
- uint32_t mModCount; // number of modifications (for undo/redo stack)
- uint32_t mFlags; // behavior flags. See nsIPlaintextEditor.idl for the flags we use.
+ // Number of modifications (for undo/redo stack).
+ uint32_t mModCount;
+ // Behavior flags. See nsIPlaintextEditor.idl for the flags we use.
+ uint32_t mFlags;
- int32_t mUpdateCount;
+ int32_t mUpdateCount;
- int32_t mPlaceHolderBatch; // nesting count for batching
- EditAction mAction; // the current editor action
+ // Nesting count for batching.
+ int32_t mPlaceHolderBatch;
+ // The current editor action.
+ EditAction mAction;
- uint32_t mIMETextOffset; // offset in text node where IME comp string begins
+ // Offset in text node where IME comp string begins.
+ uint32_t mIMETextOffset;
// The Length of the composition string or commit string. If this is length
// of commit string, the length is truncated by maxlength attribute.
- uint32_t mIMETextLength;
+ uint32_t mIMETextLength;
- EDirection mDirection; // the current direction of editor action
- int8_t mDocDirtyState; // -1 = not initialized
- uint8_t mSpellcheckCheckboxState; // a Tristate value
+ // The current direction of editor action.
+ EDirection mDirection;
+ // -1 = not initialized
+ int8_t mDocDirtyState;
+ // A Tristate value.
+ uint8_t mSpellcheckCheckboxState;
- bool mShouldTxnSetSelection; // turn off for conservative selection adjustment by txns
- bool mDidPreDestroy; // whether PreDestroy has been called
- bool mDidPostCreate; // whether PostCreate has been called
+ // Turn off for conservative selection adjustment by transactions.
+ bool mShouldTxnSetSelection;
+ // Whether PreDestroy has been called.
+ bool mDidPreDestroy;
+ // Whether PostCreate has been called.
+ bool mDidPostCreate;
bool mDispatchInputEvent;
- bool mIsInEditAction; // true while the instance is handling an edit action
- bool mHidingCaret; // whether caret is hidden forcibly.
+ // True while the instance is handling an edit action.
+ bool mIsInEditAction;
+ // Whether caret is hidden forcibly.
+ bool mHidingCaret;
friend bool NSCanUnload(nsISupports* serviceMgr);
- friend class mozilla::AutoRules;
- friend class mozilla::AutoSelectionRestorer;
- friend class mozilla::AutoTransactionsConserveSelection;
- friend class mozilla::RangeUpdater;
+ friend class AutoRules;
+ friend class AutoSelectionRestorer;
+ friend class AutoTransactionsConserveSelection;
+ friend class RangeUpdater;
};
+} // namespace mozilla
-#endif
+#endif // #ifndef mozilla_EditorBase_h
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -2,28 +2,28 @@
/* vim: set ts=4 sw=2 et tw=78: */
/* 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/. */
#include "EditorEventListener.h"
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
+#include "mozilla/EditorBase.h" // for EditorBase, etc
#include "mozilla/EventListenerManager.h" // for EventListenerManager
#include "mozilla/IMEStateManager.h" // for IMEStateManager
#include "mozilla/Preferences.h" // for Preferences
#include "mozilla/TextEvents.h" // for WidgetCompositionEvent
#include "mozilla/dom/Element.h" // for Element
#include "mozilla/dom/Event.h" // for Event
#include "mozilla/dom/EventTarget.h" // for EventTarget
#include "mozilla/dom/Selection.h"
#include "nsAString.h"
#include "nsCaret.h" // for nsCaret
#include "nsDebug.h" // for NS_ENSURE_TRUE, etc
-#include "nsEditor.h" // for nsEditor, etc
#include "nsFocusManager.h" // for nsFocusManager
#include "nsGkAtoms.h" // for nsGkAtoms, nsGkAtoms::input
#include "nsIClipboard.h" // for nsIClipboard, etc
#include "nsIContent.h" // for nsIContent
#include "nsIController.h" // for nsIController
#include "nsID.h"
#include "mozilla/dom/DOMStringList.h"
#include "mozilla/dom/DataTransfer.h"
@@ -31,17 +31,17 @@
#include "nsIDOMDragEvent.h" // for nsIDOMDragEvent
#include "nsIDOMElement.h" // for nsIDOMElement
#include "nsIDOMEvent.h" // for nsIDOMEvent
#include "nsIDOMEventTarget.h" // for nsIDOMEventTarget
#include "nsIDOMKeyEvent.h" // for nsIDOMKeyEvent
#include "nsIDOMMouseEvent.h" // for nsIDOMMouseEvent
#include "nsIDOMNode.h" // for nsIDOMNode
#include "nsIDocument.h" // for nsIDocument
-#include "nsIEditor.h" // for nsEditor::GetSelection, etc
+#include "nsIEditor.h" // for EditorBase::GetSelection, etc
#include "nsIEditorIMESupport.h"
#include "nsIEditorMailSupport.h" // for nsIEditorMailSupport
#include "nsIFocusManager.h" // for nsIFocusManager
#include "nsIFormControl.h" // for nsIFormControl, etc
#include "nsIHTMLEditor.h" // for nsIHTMLEditor
#include "nsINode.h" // for nsINode, ::NODE_IS_EDITABLE, etc
#include "nsIPlaintextEditor.h" // for nsIPlaintextEditor, etc
#include "nsIPresShell.h" // for nsIPresShell
@@ -93,65 +93,65 @@ DoCommandCallback(Command aCommand, void
nsresult rv = controller->IsCommandEnabled(commandStr, &commandEnabled);
NS_ENSURE_SUCCESS_VOID(rv);
if (commandEnabled) {
controller->DoCommand(commandStr);
}
}
EditorEventListener::EditorEventListener()
- : mEditor(nullptr)
+ : mEditorBase(nullptr)
, mCommitText(false)
, mInTransaction(false)
, mMouseDownOrUpConsumedByIME(false)
#ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
, mHaveBidiKeyboards(false)
, mShouldSwitchTextDirection(false)
, mSwitchToRTL(false)
#endif
{
}
EditorEventListener::~EditorEventListener()
{
- if (mEditor) {
+ if (mEditorBase) {
NS_WARNING("We're not uninstalled");
Disconnect();
}
}
nsresult
-EditorEventListener::Connect(nsEditor* aEditor)
+EditorEventListener::Connect(EditorBase* aEditorBase)
{
- NS_ENSURE_ARG(aEditor);
+ NS_ENSURE_ARG(aEditorBase);
#ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
nsIBidiKeyboard* bidiKeyboard = nsContentUtils::GetBidiKeyboard();
if (bidiKeyboard) {
bool haveBidiKeyboards = false;
bidiKeyboard->GetHaveBidiKeyboards(&haveBidiKeyboards);
mHaveBidiKeyboards = haveBidiKeyboards;
}
#endif
- mEditor = aEditor;
+ mEditorBase = aEditorBase;
nsresult rv = InstallToEditor();
if (NS_FAILED(rv)) {
Disconnect();
}
return rv;
}
nsresult
EditorEventListener::InstallToEditor()
{
- NS_PRECONDITION(mEditor, "The caller must set mEditor");
+ NS_PRECONDITION(mEditorBase, "The caller must set mEditorBase");
- nsCOMPtr<EventTarget> piTarget = mEditor->GetDOMEventTarget();
+ nsCOMPtr<EventTarget> piTarget = mEditorBase->GetDOMEventTarget();
NS_ENSURE_TRUE(piTarget, NS_ERROR_FAILURE);
// register the event listeners with the listener manager
EventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
NS_ENSURE_STATE(elmP);
#ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
elmP->AddEventListenerByType(this,
@@ -209,42 +209,42 @@ EditorEventListener::InstallToEditor()
TrustedEventsAtSystemGroupBubble());
return NS_OK;
}
void
EditorEventListener::Disconnect()
{
- if (!mEditor) {
+ if (!mEditorBase) {
return;
}
UninstallFromEditor();
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> domFocus;
fm->GetFocusedElement(getter_AddRefs(domFocus));
nsCOMPtr<nsINode> focusedElement = do_QueryInterface(domFocus);
- mozilla::dom::Element* root = mEditor->GetRoot();
+ mozilla::dom::Element* root = mEditorBase->GetRoot();
if (focusedElement && root &&
nsContentUtils::ContentIsDescendantOf(focusedElement, root)) {
// Reset the Selection ancestor limiter and SelectionController state
- // that nsEditor::InitializeSelection set up.
- mEditor->FinalizeSelection();
+ // that EditorBase::InitializeSelection set up.
+ mEditorBase->FinalizeSelection();
}
}
- mEditor = nullptr;
+ mEditorBase = nullptr;
}
void
EditorEventListener::UninstallFromEditor()
{
- nsCOMPtr<EventTarget> piTarget = mEditor->GetDOMEventTarget();
+ nsCOMPtr<EventTarget> piTarget = mEditorBase->GetDOMEventTarget();
if (!piTarget) {
return;
}
EventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
if (!elmP) {
return;
}
@@ -296,34 +296,34 @@ EditorEventListener::UninstallFromEditor
elmP->RemoveEventListenerByType(this,
NS_LITERAL_STRING("compositionend"),
TrustedEventsAtSystemGroupBubble());
}
already_AddRefed<nsIPresShell>
EditorEventListener::GetPresShell()
{
- NS_PRECONDITION(mEditor,
+ NS_PRECONDITION(mEditorBase,
"The caller must check whether this is connected to an editor");
- return mEditor->GetPresShell();
+ return mEditorBase->GetPresShell();
}
nsPresContext*
EditorEventListener::GetPresContext()
{
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
return presShell ? presShell->GetPresContext() : nullptr;
}
nsIContent*
EditorEventListener::GetFocusedRootContent()
{
- NS_ENSURE_TRUE(mEditor, nullptr);
+ NS_ENSURE_TRUE(mEditorBase, nullptr);
- nsCOMPtr<nsIContent> focusedContent = mEditor->GetFocusedContent();
+ nsCOMPtr<nsIContent> focusedContent = mEditorBase->GetFocusedContent();
if (!focusedContent) {
return nullptr;
}
nsIDocument* composedDoc = focusedContent->GetComposedDoc();
NS_ENSURE_TRUE(composedDoc, nullptr);
if (composedDoc->HasFlag(NODE_IS_EDITABLE)) {
@@ -331,34 +331,34 @@ EditorEventListener::GetFocusedRootConte
}
return focusedContent;
}
bool
EditorEventListener::EditorHasFocus()
{
- NS_PRECONDITION(mEditor,
+ NS_PRECONDITION(mEditorBase,
"The caller must check whether this is connected to an editor");
- nsCOMPtr<nsIContent> focusedContent = mEditor->GetFocusedContent();
+ nsCOMPtr<nsIContent> focusedContent = mEditorBase->GetFocusedContent();
if (!focusedContent) {
return false;
}
nsIDocument* composedDoc = focusedContent->GetComposedDoc();
return !!composedDoc;
}
NS_IMPL_ISUPPORTS(EditorEventListener, nsIDOMEventListener)
NS_IMETHODIMP
EditorEventListener::HandleEvent(nsIDOMEvent* aEvent)
{
- NS_ENSURE_TRUE(mEditor, NS_ERROR_FAILURE);
+ NS_ENSURE_TRUE(mEditorBase, NS_ERROR_FAILURE);
- nsCOMPtr<nsIEditor> kungFuDeathGrip = mEditor;
+ nsCOMPtr<nsIEditor> kungFuDeathGrip = mEditorBase;
WidgetEvent* internalEvent = aEvent->WidgetEventPtr();
// Let's handle each event with the message of the internal event of the
// coming event. If the DOM event was created with improper interface,
// e.g., keydown event is created with |new MouseEvent("keydown", {});|,
// its message is always 0. Therefore, we can ban such strange event easy.
// However, we need to handle strange "focus" and "blur" event. See the
@@ -545,18 +545,18 @@ EditorEventListener::KeyUp(nsIDOMKeyEven
if (!mHaveBidiKeyboards) {
return NS_OK;
}
uint32_t keyCode = 0;
aKeyEvent->GetKeyCode(&keyCode);
if ((keyCode == nsIDOMKeyEvent::DOM_VK_SHIFT ||
keyCode == nsIDOMKeyEvent::DOM_VK_CONTROL) &&
- mShouldSwitchTextDirection && mEditor->IsPlaintextEditor()) {
- mEditor->SwitchTextDirectionTo(mSwitchToRTL ?
+ mShouldSwitchTextDirection && mEditorBase->IsPlaintextEditor()) {
+ mEditorBase->SwitchTextDirectionTo(mSwitchToRTL ?
nsIPlaintextEditor::eEditorRightToLeft :
nsIPlaintextEditor::eEditorLeftToRight);
mShouldSwitchTextDirection = false;
}
return NS_OK;
}
nsresult
@@ -584,33 +584,33 @@ EditorEventListener::KeyDown(nsIDOMKeyEv
}
#endif
nsresult
EditorEventListener::KeyPress(nsIDOMKeyEvent* aKeyEvent)
{
NS_ENSURE_TRUE(aKeyEvent, NS_OK);
- if (!mEditor->IsAcceptableInputEvent(aKeyEvent->AsEvent())) {
+ if (!mEditorBase->IsAcceptableInputEvent(aKeyEvent->AsEvent())) {
return NS_OK;
}
// DOM event handling happens in two passes, the client pass and the system
// pass. We do all of our processing in the system pass, to allow client
// handlers the opportunity to cancel events and prevent typing in the editor.
// If the client pass cancelled the event, defaultPrevented will be true
// below.
bool defaultPrevented;
aKeyEvent->AsEvent()->GetDefaultPrevented(&defaultPrevented);
if (defaultPrevented) {
return NS_OK;
}
- nsresult rv = mEditor->HandleKeyPressEvent(aKeyEvent);
+ nsresult rv = mEditorBase->HandleKeyPressEvent(aKeyEvent);
NS_ENSURE_SUCCESS(rv, rv);
aKeyEvent->AsEvent()->GetDefaultPrevented(&defaultPrevented);
if (defaultPrevented) {
return NS_OK;
}
if (!ShouldHandleNativeKeyBindings(aKeyEvent)) {
@@ -626,32 +626,32 @@ EditorEventListener::KeyPress(nsIDOMKeyE
// If the event is created by chrome script, the widget is always nullptr.
if (!widget) {
nsCOMPtr<nsIPresShell> ps = GetPresShell();
nsPresContext* pc = ps ? ps->GetPresContext() : nullptr;
widget = pc ? pc->GetNearestWidget() : nullptr;
NS_ENSURE_TRUE(widget, NS_OK);
}
- nsCOMPtr<nsIDocument> doc = mEditor->GetDocument();
+ nsCOMPtr<nsIDocument> doc = mEditorBase->GetDocument();
bool handled = widget->ExecuteNativeKeyBinding(
nsIWidget::NativeKeyBindingsForRichTextEditor,
*keyEvent, DoCommandCallback, doc);
if (handled) {
aKeyEvent->AsEvent()->PreventDefault();
}
return NS_OK;
}
nsresult
EditorEventListener::MouseClick(nsIDOMMouseEvent* aMouseEvent)
{
// nothing to do if editor isn't editable or clicked on out of the editor.
- if (mEditor->IsReadonly() || mEditor->IsDisabled() ||
- !mEditor->IsAcceptableInputEvent(aMouseEvent->AsEvent())) {
+ if (mEditorBase->IsReadonly() || mEditorBase->IsDisabled() ||
+ !mEditorBase->IsAcceptableInputEvent(aMouseEvent->AsEvent())) {
return NS_OK;
}
// Notifies clicking on editor to IMEStateManager even when the event was
// consumed.
if (EditorHasFocus()) {
nsPresContext* presContext = GetPresContext();
if (presContext) {
@@ -664,17 +664,17 @@ EditorEventListener::MouseClick(nsIDOMMo
nsresult rv = aMouseEvent->AsEvent()->GetDefaultPrevented(&preventDefault);
if (NS_FAILED(rv) || preventDefault) {
// We're done if 'preventdefault' is true (see for example bug 70698).
return rv;
}
// If we got a mouse down inside the editing area, we should force the
// IME to commit before we change the cursor position
- mEditor->ForceCompositionEnd();
+ mEditorBase->ForceCompositionEnd();
int16_t button = -1;
aMouseEvent->GetButton(&button);
if (button == 1) {
return HandleMiddleClickPaste(aMouseEvent);
}
return NS_OK;
}
@@ -692,29 +692,29 @@ EditorEventListener::HandleMiddleClickPa
if (NS_FAILED(aMouseEvent->GetRangeParent(getter_AddRefs(parent)))) {
return NS_ERROR_NULL_POINTER;
}
int32_t offset = 0;
if (NS_FAILED(aMouseEvent->GetRangeOffset(&offset))) {
return NS_ERROR_NULL_POINTER;
}
- RefPtr<Selection> selection = mEditor->GetSelection();
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
if (selection) {
selection->Collapse(parent, offset);
}
// If the ctrl key is pressed, we'll do paste as quotation.
// Would've used the alt key, but the kde wmgr treats alt-middle specially.
bool ctrlKey = false;
aMouseEvent->GetCtrlKey(&ctrlKey);
nsCOMPtr<nsIEditorMailSupport> mailEditor;
if (ctrlKey) {
- mailEditor = do_QueryObject(mEditor);
+ mailEditor = do_QueryObject(mEditorBase);
}
nsresult rv;
int32_t clipboard = nsIClipboard::kGlobalClipboard;
nsCOMPtr<nsIClipboard> clipboardService =
do_GetService("@mozilla.org/widget/clipboard;1", &rv);
if (NS_SUCCEEDED(rv)) {
bool selectionSupported;
@@ -722,17 +722,17 @@ EditorEventListener::HandleMiddleClickPa
if (NS_SUCCEEDED(rv) && selectionSupported) {
clipboard = nsIClipboard::kSelectionClipboard;
}
}
if (mailEditor) {
mailEditor->PasteAsQuotation(clipboard);
} else {
- mEditor->Paste(clipboard);
+ mEditorBase->Paste(clipboard);
}
// Prevent the event from propagating up to be possibly handled
// again by the containing window:
aMouseEvent->AsEvent()->StopPropagation();
aMouseEvent->AsEvent()->PreventDefault();
// We processed the event, whether drop/paste succeeded or not
@@ -760,33 +760,33 @@ EditorEventListener::NotifyIMEOfMouseBut
aMouseEvent);
}
nsresult
EditorEventListener::MouseDown(nsIDOMMouseEvent* aMouseEvent)
{
// FYI: This may be called by HTMLEditorEventListener::MouseDown() even
// when the event is not acceptable for committing composition.
- mEditor->ForceCompositionEnd();
+ mEditorBase->ForceCompositionEnd();
return NS_OK;
}
nsresult
EditorEventListener::HandleText(nsIDOMEvent* aTextEvent)
{
- if (!mEditor->IsAcceptableInputEvent(aTextEvent)) {
+ if (!mEditorBase->IsAcceptableInputEvent(aTextEvent)) {
return NS_OK;
}
// if we are readonly or disabled, then do nothing.
- if (mEditor->IsReadonly() || mEditor->IsDisabled()) {
+ if (mEditorBase->IsReadonly() || mEditorBase->IsDisabled()) {
return NS_OK;
}
- return mEditor->UpdateIMEComposition(aTextEvent);
+ return mEditorBase->UpdateIMEComposition(aTextEvent);
}
/**
* Drag event implementation
*/
nsresult
EditorEventListener::DragEnter(nsIDOMDragEvent* aDragEvent)
@@ -899,37 +899,37 @@ EditorEventListener::Drop(nsIDOMDragEven
nsCOMPtr<nsIDOMNode> parent;
aDragEvent->GetRangeParent(getter_AddRefs(parent));
nsCOMPtr<nsIContent> dropParent = do_QueryInterface(parent);
NS_ENSURE_TRUE(dropParent, NS_ERROR_FAILURE);
if (!dropParent->IsEditable() || !CanDrop(aDragEvent)) {
// was it because we're read-only?
- if ((mEditor->IsReadonly() || mEditor->IsDisabled()) &&
+ if ((mEditorBase->IsReadonly() || mEditorBase->IsDisabled()) &&
!IsFileControlTextBox()) {
// it was decided to "eat" the event as this is the "least surprise"
// since someone else handling it might be unintentional and the
// user could probably re-drag to be not over the disabled/readonly
// editfields if that is what is desired.
return aDragEvent->AsEvent()->StopPropagation();
}
return NS_OK;
}
aDragEvent->AsEvent()->StopPropagation();
aDragEvent->AsEvent()->PreventDefault();
- return mEditor->InsertFromDrop(aDragEvent->AsEvent());
+ return mEditorBase->InsertFromDrop(aDragEvent->AsEvent());
}
bool
EditorEventListener::CanDrop(nsIDOMDragEvent* aEvent)
{
// if the target doc is read-only, we can't drop
- if (mEditor->IsReadonly() || mEditor->IsDisabled()) {
+ if (mEditorBase->IsReadonly() || mEditorBase->IsDisabled()) {
return false;
}
nsCOMPtr<nsIDOMDataTransfer> domDataTransfer;
aEvent->GetDataTransfer(getter_AddRefs(domDataTransfer));
nsCOMPtr<DataTransfer> dataTransfer = do_QueryInterface(domDataTransfer);
NS_ENSURE_TRUE(dataTransfer, false);
@@ -938,17 +938,17 @@ EditorEventListener::CanDrop(nsIDOMDragE
if (NS_WARN_IF(err.Failed())) {
return false;
}
// Plaintext editors only support dropping text. Otherwise, HTML and files
// can be dropped as well.
if (!types->Contains(NS_LITERAL_STRING(kTextMime)) &&
!types->Contains(NS_LITERAL_STRING(kMozTextInternal)) &&
- (mEditor->IsPlaintextEditor() ||
+ (mEditorBase->IsPlaintextEditor() ||
(!types->Contains(NS_LITERAL_STRING(kHTMLMime)) &&
!types->Contains(NS_LITERAL_STRING(kFileMime))))) {
return false;
}
// If there is no source node, this is probably an external drag and the
// drop is allowed. The later checks rely on checking if the drag target
// is the same as the drag source.
@@ -956,17 +956,17 @@ EditorEventListener::CanDrop(nsIDOMDragE
dataTransfer->GetMozSourceNode(getter_AddRefs(sourceNode));
if (!sourceNode) {
return true;
}
// There is a source node, so compare the source documents and this document.
// Disallow drops on the same document.
- nsCOMPtr<nsIDOMDocument> domdoc = mEditor->GetDOMDocument();
+ nsCOMPtr<nsIDOMDocument> domdoc = mEditorBase->GetDOMDocument();
NS_ENSURE_TRUE(domdoc, false);
nsCOMPtr<nsIDOMDocument> sourceDoc;
nsresult rv = sourceNode->GetOwnerDocument(getter_AddRefs(sourceDoc));
NS_ENSURE_SUCCESS(rv, false);
// If the source and the dest are not same document, allow to drop it always.
if (domdoc != sourceDoc) {
@@ -976,17 +976,17 @@ EditorEventListener::CanDrop(nsIDOMDragE
// If the source node is a remote browser, treat this as coming from a
// different document and allow the drop.
nsCOMPtr<nsIContent> sourceContent = do_QueryInterface(sourceNode);
TabParent* tp = TabParent::GetFrom(sourceContent);
if (tp) {
return true;
}
- RefPtr<Selection> selection = mEditor->GetSelection();
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
if (!selection) {
return false;
}
// If selection is collapsed, allow to drop it always.
if (selection->Collapsed()) {
return true;
}
@@ -1020,47 +1020,47 @@ EditorEventListener::CanDrop(nsIDOMDragE
}
}
return true;
}
nsresult
EditorEventListener::HandleStartComposition(nsIDOMEvent* aCompositionEvent)
{
- if (!mEditor->IsAcceptableInputEvent(aCompositionEvent)) {
+ if (!mEditorBase->IsAcceptableInputEvent(aCompositionEvent)) {
return NS_OK;
}
WidgetCompositionEvent* compositionStart =
aCompositionEvent->WidgetEventPtr()->AsCompositionEvent();
- return mEditor->BeginIMEComposition(compositionStart);
+ return mEditorBase->BeginIMEComposition(compositionStart);
}
void
EditorEventListener::HandleEndComposition(nsIDOMEvent* aCompositionEvent)
{
- if (!mEditor->IsAcceptableInputEvent(aCompositionEvent)) {
+ if (!mEditorBase->IsAcceptableInputEvent(aCompositionEvent)) {
return;
}
- mEditor->EndIMEComposition();
+ mEditorBase->EndIMEComposition();
}
nsresult
EditorEventListener::Focus(nsIDOMEvent* aEvent)
{
NS_ENSURE_TRUE(aEvent, NS_OK);
// Don't turn on selection and caret when the editor is disabled.
- if (mEditor->IsDisabled()) {
+ if (mEditorBase->IsDisabled()) {
return NS_OK;
}
// Spell check a textarea the first time that it is focused.
SpellCheckIfNeeded();
- if (!mEditor) {
+ if (!mEditorBase) {
// In e10s, this can cause us to flush notifications, which can destroy
// the node we're about to focus.
return NS_OK;
}
nsCOMPtr<nsIDOMEventTarget> target;
aEvent->GetTarget(getter_AddRefs(target));
nsCOMPtr<nsINode> node = do_QueryInterface(target);
@@ -1075,39 +1075,39 @@ EditorEventListener::Focus(nsIDOMEvent*
if (node->IsNodeOfType(nsINode::eCONTENT)) {
// XXX If the focus event target is a form control in contenteditable
// element, perhaps, the parent HTML editor should do nothing by this
// handler. However, FindSelectionRoot() returns the root element of the
// contenteditable editor. So, the editableRoot value is invalid for
// the plain text editor, and it will be set to the wrong limiter of
// the selection. However, fortunately, actual bugs are not found yet.
- nsCOMPtr<nsIContent> editableRoot = mEditor->FindSelectionRoot(node);
+ nsCOMPtr<nsIContent> editableRoot = mEditorBase->FindSelectionRoot(node);
// make sure that the element is really focused in case an earlier
// listener in the chain changed the focus.
if (editableRoot) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
NS_ENSURE_TRUE(fm, NS_OK);
nsCOMPtr<nsIDOMElement> element;
fm->GetFocusedElement(getter_AddRefs(element));
if (!SameCOMIdentity(element, target)) {
return NS_OK;
}
}
}
- mEditor->OnFocus(target);
+ mEditorBase->OnFocus(target);
nsCOMPtr<nsIPresShell> ps = GetPresShell();
NS_ENSURE_TRUE(ps, NS_OK);
- nsCOMPtr<nsIContent> focusedContent = mEditor->GetFocusedContentForIME();
+ nsCOMPtr<nsIContent> focusedContent = mEditorBase->GetFocusedContentForIME();
IMEStateManager::OnFocusInEditor(ps->GetPresContext(), focusedContent,
- mEditor);
+ mEditorBase);
return NS_OK;
}
nsresult
EditorEventListener::Blur(nsIDOMEvent* aEvent)
{
NS_ENSURE_TRUE(aEvent, NS_OK);
@@ -1115,38 +1115,38 @@ EditorEventListener::Blur(nsIDOMEvent* a
// check if something else is focused. If another element is focused, then
// we should not change the selection.
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
NS_ENSURE_TRUE(fm, NS_OK);
nsCOMPtr<nsIDOMElement> element;
fm->GetFocusedElement(getter_AddRefs(element));
if (!element) {
- mEditor->FinalizeSelection();
+ mEditorBase->FinalizeSelection();
}
return NS_OK;
}
void
EditorEventListener::SpellCheckIfNeeded()
{
// If the spell check skip flag is still enabled from creation time,
// disable it because focused editors are allowed to spell check.
uint32_t currentFlags = 0;
- mEditor->GetFlags(¤tFlags);
+ mEditorBase->GetFlags(¤tFlags);
if(currentFlags & nsIPlaintextEditor::eEditorSkipSpellCheck) {
currentFlags ^= nsIPlaintextEditor::eEditorSkipSpellCheck;
- mEditor->SetFlags(currentFlags);
+ mEditorBase->SetFlags(currentFlags);
}
}
bool
EditorEventListener::IsFileControlTextBox()
{
- dom::Element* root = mEditor->GetRoot();
+ Element* root = mEditorBase->GetRoot();
if (!root || !root->ChromeOnlyAccess()) {
return false;
}
nsIContent* parent = root->FindFirstNonChromeOnlyAccessContent();
if (!parent || !parent->IsHTMLElement(nsGkAtoms::input)) {
return false;
}
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(parent);
@@ -1167,22 +1167,22 @@ EditorEventListener::ShouldHandleNativeK
nsCOMPtr<nsIDOMEventTarget> target;
aKeyEvent->AsEvent()->GetTarget(getter_AddRefs(target));
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(target);
if (!targetContent) {
return false;
}
nsCOMPtr<nsIHTMLEditor> htmlEditor =
- do_QueryInterface(static_cast<nsIEditor*>(mEditor));
+ do_QueryInterface(static_cast<nsIEditor*>(mEditorBase));
if (!htmlEditor) {
return false;
}
- nsCOMPtr<nsIDocument> doc = mEditor->GetDocument();
+ nsCOMPtr<nsIDocument> doc = mEditorBase->GetDocument();
if (doc->HasFlag(NODE_IS_EDITABLE)) {
// Don't need to perform any checks in designMode documents.
return true;
}
nsIContent* editingHost = htmlEditor->GetActiveEditingHost();
if (!editingHost) {
return false;
--- a/editor/libeditor/EditorEventListener.h
+++ b/editor/libeditor/EditorEventListener.h
@@ -14,37 +14,38 @@
class nsCaret;
class nsIContent;
class nsIDOMDragEvent;
class nsIDOMEvent;
class nsIDOMKeyEvent;
class nsIDOMMouseEvent;
class nsIPresShell;
-class nsEditor;
class nsPresContext;
// X.h defines KeyPress
#ifdef KeyPress
#undef KeyPress
#endif
#ifdef XP_WIN
// On Windows, we support switching the text direction by pressing Ctrl+Shift
#define HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
#endif
namespace mozilla {
+class EditorBase;
+
class EditorEventListener : public nsIDOMEventListener
{
public:
EditorEventListener();
- virtual nsresult Connect(nsEditor* aEditor);
+ virtual nsresult Connect(EditorBase* aEditorBase);
void Disconnect();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMEVENTLISTENER
void SpellCheckIfNeeded();
@@ -80,17 +81,17 @@ protected:
nsIContent* GetFocusedRootContent();
// Returns true if IME consumes the mouse event.
bool NotifyIMEOfMouseButtonEvent(nsIDOMMouseEvent* aMouseEvent);
bool EditorHasFocus();
bool IsFileControlTextBox();
bool ShouldHandleNativeKeyBindings(nsIDOMKeyEvent* aKeyEvent);
nsresult HandleMiddleClickPaste(nsIDOMMouseEvent* aMouseEvent);
- nsEditor* mEditor; // weak
+ EditorBase* mEditorBase; // weak
RefPtr<nsCaret> mCaret;
bool mCommitText;
bool mInTransaction;
bool mMouseDownOrUpConsumedByIME;
#ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
bool mHaveBidiKeyboards;
bool mShouldSwitchTextDirection;
bool mSwitchToRTL;
--- a/editor/libeditor/EditorUtils.cpp
+++ b/editor/libeditor/EditorUtils.cpp
@@ -29,50 +29,50 @@ namespace mozilla {
using namespace dom;
/******************************************************************************
* AutoSelectionRestorer
*****************************************************************************/
AutoSelectionRestorer::AutoSelectionRestorer(
Selection* aSelection,
- nsEditor* aEditor
+ EditorBase* aEditorBase
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
- : mEditor(nullptr)
+ : mEditorBase(nullptr)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
- if (NS_WARN_IF(!aSelection) || NS_WARN_IF(!aEditor)) {
+ if (NS_WARN_IF(!aSelection) || NS_WARN_IF(!aEditorBase)) {
return;
}
- if (aEditor->ArePreservingSelection()) {
+ if (aEditorBase->ArePreservingSelection()) {
// We already have initialized mSavedSel, so this must be nested call.
return;
}
mSelection = aSelection;
- mEditor = aEditor;
- mEditor->PreserveSelectionAcrossActions(mSelection);
+ mEditorBase = aEditorBase;
+ mEditorBase->PreserveSelectionAcrossActions(mSelection);
}
AutoSelectionRestorer::~AutoSelectionRestorer()
{
- NS_ASSERTION(!mSelection || mEditor,
- "mEditor should be non-null when mSelection is");
+ NS_ASSERTION(!mSelection || mEditorBase,
+ "mEditorBase should be non-null when mSelection is");
// mSelection will be null if this was nested call.
- if (mSelection && mEditor->ArePreservingSelection()) {
- mEditor->RestorePreservedSelection(mSelection);
+ if (mSelection && mEditorBase->ArePreservingSelection()) {
+ mEditorBase->RestorePreservedSelection(mSelection);
}
}
void
AutoSelectionRestorer::Abort()
{
- NS_ASSERTION(!mSelection || mEditor,
- "mEditor should be non-null when mSelection is");
+ NS_ASSERTION(!mSelection || mEditorBase,
+ "mEditorBase should be non-null when mSelection is");
if (mSelection) {
- mEditor->StopPreservingSelection();
+ mEditorBase->StopPreservingSelection();
}
}
/******************************************************************************
* some helper classes for iterating the dom tree
*****************************************************************************/
DOMIterator::DOMIterator(nsINode& aNode MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
--- a/editor/libeditor/EditorUtils.h
+++ b/editor/libeditor/EditorUtils.h
@@ -2,23 +2,23 @@
/* 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/. */
#ifndef EditorUtils_h
#define EditorUtils_h
+#include "mozilla/EditorBase.h"
+#include "mozilla/GuardObjects.h"
#include "nsCOMPtr.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsIDOMNode.h"
#include "nsIEditor.h"
#include "nscore.h"
-#include "mozilla/GuardObjects.h"
class nsIAtom;
class nsIContentIterator;
class nsIDOMDocument;
class nsIDOMEvent;
class nsISimpleEnumerator;
class nsITransferable;
class nsRange;
@@ -83,26 +83,26 @@ public:
* stack based helper class for saving/restoring selection. Note that this
* assumes that the nodes involved are still around afterwards!
*/
class MOZ_RAII AutoSelectionRestorer final
{
private:
// Ref-counted reference to the selection that we are supposed to restore.
RefPtr<dom::Selection> mSelection;
- nsEditor* mEditor; // Non-owning ref to nsEditor.
+ EditorBase* mEditorBase; // Non-owning ref to EditorBase.
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
public:
/**
* Constructor responsible for remembering all state needed to restore
* aSelection.
*/
AutoSelectionRestorer(dom::Selection* aSelection,
- nsEditor* aEditor
+ EditorBase* aEditorBase
MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
/**
* Destructor restores mSelection to its former state
*/
~AutoSelectionRestorer();
/**
@@ -112,103 +112,103 @@ public:
};
/***************************************************************************
* stack based helper class for StartOperation()/EndOperation() sandwich
*/
class MOZ_RAII AutoRules final
{
public:
- AutoRules(nsEditor* aEditor, EditAction aAction,
+ AutoRules(EditorBase* aEditorBase, EditAction aAction,
nsIEditor::EDirection aDirection
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
- : mEditor(aEditor)
+ : mEditorBase(aEditorBase)
, mDoNothing(false)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
// mAction will already be set if this is nested call
- if (mEditor && !mEditor->mAction) {
- mEditor->StartOperation(aAction, aDirection);
+ if (mEditorBase && !mEditorBase->mAction) {
+ mEditorBase->StartOperation(aAction, aDirection);
} else {
mDoNothing = true; // nested calls will end up here
}
}
~AutoRules()
{
- if (mEditor && !mDoNothing) {
- mEditor->EndOperation();
+ if (mEditorBase && !mDoNothing) {
+ mEditorBase->EndOperation();
}
}
protected:
- nsEditor* mEditor;
+ EditorBase* mEditorBase;
bool mDoNothing;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
/***************************************************************************
* stack based helper class for turning off active selection adjustment
* by low level transactions
*/
class MOZ_RAII AutoTransactionsConserveSelection final
{
public:
- explicit AutoTransactionsConserveSelection(nsEditor* aEditor
+ explicit AutoTransactionsConserveSelection(EditorBase* aEditorBase
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
- : mEditor(aEditor)
+ : mEditorBase(aEditorBase)
, mOldState(true)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
- if (mEditor) {
- mOldState = mEditor->GetShouldTxnSetSelection();
- mEditor->SetShouldTxnSetSelection(false);
+ if (mEditorBase) {
+ mOldState = mEditorBase->GetShouldTxnSetSelection();
+ mEditorBase->SetShouldTxnSetSelection(false);
}
}
~AutoTransactionsConserveSelection()
{
- if (mEditor) {
- mEditor->SetShouldTxnSetSelection(mOldState);
+ if (mEditorBase) {
+ mEditorBase->SetShouldTxnSetSelection(mOldState);
}
}
protected:
- nsEditor* mEditor;
+ EditorBase* mEditorBase;
bool mOldState;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
/***************************************************************************
* stack based helper class for batching reflow and paint requests.
*/
class MOZ_RAII AutoUpdateViewBatch final
{
public:
- explicit AutoUpdateViewBatch(nsEditor* aEditor
+ explicit AutoUpdateViewBatch(EditorBase* aEditorBase
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
- : mEditor(aEditor)
+ : mEditorBase(aEditorBase)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
- NS_ASSERTION(mEditor, "null mEditor pointer!");
+ NS_ASSERTION(mEditorBase, "null mEditorBase pointer!");
- if (mEditor) {
- mEditor->BeginUpdateViewBatch();
+ if (mEditorBase) {
+ mEditorBase->BeginUpdateViewBatch();
}
}
~AutoUpdateViewBatch()
{
- if (mEditor) {
- mEditor->EndUpdateViewBatch();
+ if (mEditorBase) {
+ mEditorBase->EndUpdateViewBatch();
}
}
protected:
- nsEditor* mEditor;
+ EditorBase* mEditorBase;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
/******************************************************************************
* some helper classes for iterating the dom tree
*****************************************************************************/
class BoolDomIterFunctor
--- a/editor/libeditor/HTMLAbsPositionEditor.cpp
+++ b/editor/libeditor/HTMLAbsPositionEditor.cpp
@@ -15,17 +15,16 @@
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/Element.h"
#include "mozilla/mozalloc.h"
#include "nsAString.h"
#include "nsAlgorithm.h"
#include "nsCOMPtr.h"
#include "nsComputedDOMStyle.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
#include "nsIContent.h"
#include "nsROCSSPrimitiveValue.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMElement.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMEventTarget.h"
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -24,17 +24,16 @@
#include "nsAutoPtr.h"
#include "nsAString.h"
#include "nsAlgorithm.h"
#include "nsCRT.h"
#include "nsCRTGlue.h"
#include "nsComponentManagerUtils.h"
#include "nsContentUtils.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
#include "nsIAtom.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsID.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMDocument.h"
@@ -1150,17 +1149,17 @@ HTMLEditRules::AppendInnerFormatNodes(ns
nsresult
HTMLEditRules::GetFormatString(nsIDOMNode* aNode,
nsAString& outFormat)
{
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
if (HTMLEditUtils::IsFormatNode(aNode)) {
- nsCOMPtr<nsIAtom> atom = nsEditor::GetTag(aNode);
+ nsCOMPtr<nsIAtom> atom = EditorBase::GetTag(aNode);
atom->ToString(outFormat);
}
else
outFormat.Truncate();
return NS_OK;
}
@@ -2922,17 +2921,17 @@ HTMLEditRules::DidDeleteSelection(Select
if (citeNode) {
bool isEmpty = true, seenBR = false;
NS_ENSURE_STATE(mHTMLEditor);
mHTMLEditor->IsEmptyNodeImpl(citeNode, &isEmpty, true, true, false,
&seenBR);
if (isEmpty)
{
int32_t offset;
- nsCOMPtr<nsINode> parent = nsEditor::GetNodeLocation(citeNode, &offset);
+ nsCOMPtr<nsINode> parent = EditorBase::GetNodeLocation(citeNode, &offset);
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->DeleteNode(citeNode);
NS_ENSURE_SUCCESS(res, res);
if (parent && seenBR)
{
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<Element> brNode = mHTMLEditor->CreateBR(parent, offset);
NS_ENSURE_STATE(brNode);
@@ -3064,17 +3063,17 @@ HTMLEditRules::WillMakeList(Selection* a
nsCOMPtr<Element> curList, prevListItem;
for (uint32_t i = 0; i < listCount; i++) {
// here's where we actually figure out what to do
nsCOMPtr<Element> newBlock;
NS_ENSURE_STATE(arrayOfNodes[i]->IsContent());
OwningNonNull<nsIContent> curNode = *arrayOfNodes[i]->AsContent();
int32_t offset;
- curParent = nsEditor::GetNodeLocation(curNode, &offset);
+ curParent = EditorBase::GetNodeLocation(curNode, &offset);
// make sure we don't assemble content that is in different table cells
// into the same list. respect table cell boundaries when listifying.
if (curList && InDifferentTableElements(curList, curNode)) {
curList = nullptr;
}
// if curNode is a Break, delete it, and quit remembering prev list item
@@ -3128,18 +3127,18 @@ HTMLEditRules::WillMakeList(Selection* a
NS_ENSURE_STATE(mHTMLEditor);
NS_ENSURE_STATE(curParent->IsContent());
ErrorResult rv;
nsCOMPtr<nsIContent> splitNode =
mHTMLEditor->SplitNode(*curParent->AsContent(), offset, rv);
NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
newBlock = splitNode ? splitNode->AsElement() : nullptr;
int32_t offset;
- nsCOMPtr<nsINode> parent = nsEditor::GetNodeLocation(curParent,
- &offset);
+ nsCOMPtr<nsINode> parent = EditorBase::GetNodeLocation(curParent,
+ &offset);
NS_ENSURE_STATE(mHTMLEditor);
curList = mHTMLEditor->CreateNode(listType, parent, offset);
NS_ENSURE_STATE(curList);
}
// move list item to new list
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->MoveNode(curNode, curList, -1);
NS_ENSURE_SUCCESS(res, res);
@@ -5133,35 +5132,36 @@ HTMLEditRules::NormalizeSelection(Select
// of going "down" into a block and "up" out of a block.
if (wsEndObj.mStartReason == WSType::otherBlock) {
// endpoint is just after the close of a block.
nsCOMPtr<nsIDOMNode> child =
GetAsDOMNode(mHTMLEditor->GetRightmostChild(wsEndObj.mStartReasonNode,
true));
if (child)
{
- newEndNode = nsEditor::GetNodeLocation(child, &newEndOffset);
+ newEndNode = EditorBase::GetNodeLocation(child, &newEndOffset);
++newEndOffset; // offset *after* child
}
// else block is empty - we can leave selection alone here, i think.
} else if (wsEndObj.mStartReason == WSType::thisBlock) {
// endpoint is just after start of this block
nsCOMPtr<nsIDOMNode> child;
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->GetPriorHTMLNode(endNode, endOffset, address_of(child));
if (child)
{
- newEndNode = nsEditor::GetNodeLocation(child, &newEndOffset);
+ newEndNode = EditorBase::GetNodeLocation(child, &newEndOffset);
++newEndOffset; // offset *after* child
}
// else block is empty - we can leave selection alone here, i think.
} else if (wsEndObj.mStartReason == WSType::br) {
// endpoint is just after break. lets adjust it to before it.
- newEndNode = nsEditor::GetNodeLocation(GetAsDOMNode(wsEndObj.mStartReasonNode),
- &newEndOffset);
+ newEndNode =
+ EditorBase::GetNodeLocation(GetAsDOMNode(wsEndObj.mStartReasonNode),
+ &newEndOffset);
}
}
// similar dealio for start of range
WSRunObject wsStartObj(mHTMLEditor, startNode, startOffset);
// is there any intervening visible whitespace? if so we can't push selection past that,
// it would visibly change maening of users selection
@@ -5173,33 +5173,34 @@ HTMLEditRules::NormalizeSelection(Select
// of going "down" into a block and "up" out of a block.
if (wsStartObj.mEndReason == WSType::otherBlock) {
// startpoint is just before the start of a block.
nsCOMPtr<nsIDOMNode> child =
GetAsDOMNode(mHTMLEditor->GetLeftmostChild(wsStartObj.mEndReasonNode,
true));
if (child)
{
- newStartNode = nsEditor::GetNodeLocation(child, &newStartOffset);
+ newStartNode = EditorBase::GetNodeLocation(child, &newStartOffset);
}
// else block is empty - we can leave selection alone here, i think.
} else if (wsStartObj.mEndReason == WSType::thisBlock) {
// startpoint is just before end of this block
nsCOMPtr<nsIDOMNode> child;
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->GetNextHTMLNode(startNode, startOffset, address_of(child));
if (child)
{
- newStartNode = nsEditor::GetNodeLocation(child, &newStartOffset);
+ newStartNode = EditorBase::GetNodeLocation(child, &newStartOffset);
}
// else block is empty - we can leave selection alone here, i think.
} else if (wsStartObj.mEndReason == WSType::br) {
// startpoint is just before a break. lets adjust it to after it.
- newStartNode = nsEditor::GetNodeLocation(GetAsDOMNode(wsStartObj.mEndReasonNode),
- &newStartOffset);
+ newStartNode =
+ EditorBase::GetNodeLocation(GetAsDOMNode(wsStartObj.mEndReasonNode),
+ &newStartOffset);
++newStartOffset; // offset *after* break
}
}
// there is a demented possiblity we have to check for. We might have a very strange selection
// that is not collapsed and yet does not contain any editable content, and satisfies some of the
// above conditions that cause tweaking. In this case we don't want to tweak the selection into
// a block it was never in, etc. There are a variety of strategies one might use to try to
@@ -5511,19 +5512,19 @@ HTMLEditRules::PromoteRange(nsRange& aRa
GetPromotedPoint(kStart, GetAsDOMNode(startNode), startOffset,
aOperationType, address_of(opStartNode), &opStartOffset);
GetPromotedPoint(kEnd, GetAsDOMNode(endNode), endOffset, aOperationType,
address_of(opEndNode), &opEndOffset);
// Make sure that the new range ends up to be in the editable section.
if (!mHTMLEditor->IsDescendantOfEditorRoot(
- nsEditor::GetNodeAtRangeOffsetPoint(opStartNode, opStartOffset)) ||
+ EditorBase::GetNodeAtRangeOffsetPoint(opStartNode, opStartOffset)) ||
!mHTMLEditor->IsDescendantOfEditorRoot(
- nsEditor::GetNodeAtRangeOffsetPoint(opEndNode, opEndOffset - 1))) {
+ EditorBase::GetNodeAtRangeOffsetPoint(opEndNode, opEndOffset - 1))) {
return;
}
DebugOnly<nsresult> res = aRange.SetStart(opStartNode, opStartOffset);
MOZ_ASSERT(NS_SUCCEEDED(res));
res = aRange.SetEnd(opEndNode, opEndOffset);
MOZ_ASSERT(NS_SUCCEEDED(res));
}
@@ -5907,33 +5908,33 @@ HTMLEditRules::BustUpInlinesAtRangeEndpo
if (endInline && !isCollapsed)
{
nsCOMPtr<nsINode> resultEndNode = endInline->GetParentNode();
NS_ENSURE_STATE(mHTMLEditor);
// item.endNode must be content if endInline isn't null
int32_t resultEndOffset =
mHTMLEditor->SplitNodeDeep(*endInline, *item.endNode->AsContent(),
item.endOffset,
- nsEditor::EmptyContainers::no);
+ EditorBase::EmptyContainers::no);
NS_ENSURE_TRUE(resultEndOffset != -1, NS_ERROR_FAILURE);
// reset range
item.endNode = resultEndNode;
item.endOffset = resultEndOffset;
}
nsCOMPtr<nsIContent> startInline = GetHighestInlineParent(*item.startNode);
if (startInline)
{
nsCOMPtr<nsINode> resultStartNode = startInline->GetParentNode();
NS_ENSURE_STATE(mHTMLEditor);
int32_t resultStartOffset =
mHTMLEditor->SplitNodeDeep(*startInline, *item.startNode->AsContent(),
item.startOffset,
- nsEditor::EmptyContainers::no);
+ EditorBase::EmptyContainers::no);
NS_ENSURE_TRUE(resultStartOffset != -1, NS_ERROR_FAILURE);
// reset range
item.startNode = resultStartNode;
item.startOffset = resultStartOffset;
}
return NS_OK;
}
@@ -6213,17 +6214,17 @@ HTMLEditRules::ReturnInParagraph(Selecti
if (!aSelection || !aPara || !node || !aCancel || !aHandled) {
return NS_ERROR_NULL_POINTER;
}
*aCancel = false;
*aHandled = false;
nsresult res;
int32_t offset;
- nsCOMPtr<nsINode> parent = nsEditor::GetNodeLocation(node, &offset);
+ nsCOMPtr<nsINode> parent = EditorBase::GetNodeLocation(node, &offset);
NS_ENSURE_STATE(mHTMLEditor);
bool doesCRCreateNewP = mHTMLEditor->GetReturnInParagraphCreatesNewParagraph();
bool newBRneeded = false;
bool newSelNode = false;
nsCOMPtr<nsIContent> sibling;
nsCOMPtr<nsIDOMNode> selNode = aNode;
@@ -6374,17 +6375,17 @@ HTMLEditRules::SplitParagraph(nsIDOMNode
if (mHTMLEditor->IsTextNode(child) ||
mHTMLEditor->IsContainer(child))
{
aSelection->Collapse(child,0);
}
else
{
int32_t offset;
- nsCOMPtr<nsIDOMNode> parent = nsEditor::GetNodeLocation(child, &offset);
+ nsCOMPtr<nsIDOMNode> parent = EditorBase::GetNodeLocation(child, &offset);
aSelection->Collapse(parent,offset);
}
return res;
}
/**
* ReturnInListItem: do the right thing for returns pressed in list items
*/
@@ -6735,17 +6736,17 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<
// new block of correct type.
// XXX: pre can't hold everything the others can
if (HTMLEditUtils::IsMozDiv(curNode) ||
HTMLEditUtils::IsFormatNode(curNode)) {
// Forget any previous block used for previous inline nodes
curBlock = nullptr;
newBlock = mHTMLEditor->ReplaceContainer(curNode->AsElement(),
&aBlockTag, nullptr, nullptr,
- nsEditor::eCloneAttributes);
+ EditorBase::eCloneAttributes);
NS_ENSURE_STATE(newBlock);
} else if (HTMLEditUtils::IsTable(curNode) ||
HTMLEditUtils::IsList(curNode) ||
curNode->IsAnyOfHTMLElements(nsGkAtoms::tbody,
nsGkAtoms::tr,
nsGkAtoms::td,
nsGkAtoms::li,
nsGkAtoms::blockquote,
@@ -7158,37 +7159,37 @@ HTMLEditRules::PinSelectionToNewBlock(Se
// selection is after block. put at end of block.
nsCOMPtr<nsIDOMNode> tmp = GetAsDOMNode(mNewBlock);
NS_ENSURE_STATE(mHTMLEditor);
tmp = GetAsDOMNode(mHTMLEditor->GetLastEditableChild(*block));
uint32_t endPoint;
if (mHTMLEditor->IsTextNode(tmp) ||
mHTMLEditor->IsContainer(tmp))
{
- res = nsEditor::GetLengthOfDOMNode(tmp, endPoint);
+ res = EditorBase::GetLengthOfDOMNode(tmp, endPoint);
NS_ENSURE_SUCCESS(res, res);
}
else
{
- tmp = nsEditor::GetNodeLocation(tmp, (int32_t*)&endPoint);
+ tmp = EditorBase::GetNodeLocation(tmp, (int32_t*)&endPoint);
endPoint++; // want to be after this node
}
return aSelection->Collapse(tmp, (int32_t)endPoint);
}
else
{
// selection is before block. put at start of block.
nsCOMPtr<nsIDOMNode> tmp = GetAsDOMNode(mNewBlock);
NS_ENSURE_STATE(mHTMLEditor);
tmp = GetAsDOMNode(mHTMLEditor->GetFirstEditableChild(*block));
int32_t offset;
if (mHTMLEditor->IsTextNode(tmp) ||
mHTMLEditor->IsContainer(tmp))
{
- tmp = nsEditor::GetNodeLocation(tmp, &offset);
+ tmp = EditorBase::GetNodeLocation(tmp, &offset);
}
return aSelection->Collapse(tmp, 0);
}
}
void
HTMLEditRules::CheckInterlinePosition(Selection& aSelection)
{
@@ -7251,17 +7252,17 @@ HTMLEditRules::AdjustSelection(Selection
NS_ENSURE_SUCCESS(res, res);
temp = selNode;
// are we in an editable node?
NS_ENSURE_STATE(mHTMLEditor);
while (!mHTMLEditor->IsEditable(selNode))
{
// scan up the tree until we find an editable place to be
- selNode = nsEditor::GetNodeLocation(temp, &selOffset);
+ selNode = EditorBase::GetNodeLocation(temp, &selOffset);
NS_ENSURE_TRUE(selNode, NS_ERROR_FAILURE);
temp = selNode;
NS_ENSURE_STATE(mHTMLEditor);
}
// make sure we aren't in an empty block - user will see no cursor. If this
// is happening, put a <br> in the block if allowed.
NS_ENSURE_STATE(mHTMLEditor);
@@ -7318,17 +7319,17 @@ HTMLEditRules::AdjustSelection(Selection
// need to insert special moz BR. Why? Because if we don't
// the user will see no new line for the break. Also, things
// like table cells won't grow in height.
nsCOMPtr<nsIDOMNode> brNode;
res = CreateMozBR(GetAsDOMNode(selNode), selOffset,
getter_AddRefs(brNode));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> brParent =
- nsEditor::GetNodeLocation(brNode, &selOffset);
+ EditorBase::GetNodeLocation(brNode, &selOffset);
// selection stays *before* moz-br, sticking to it
aSelection->SetInterlinePosition(true);
res = aSelection->Collapse(brParent, selOffset);
NS_ENSURE_SUCCESS(res, res);
}
else
{
NS_ENSURE_STATE(mHTMLEditor);
@@ -7343,26 +7344,26 @@ HTMLEditRules::AdjustSelection(Selection
}
}
}
// we aren't in a textnode: are we adjacent to text or a break or an image?
NS_ENSURE_STATE(mHTMLEditor);
nearNode = mHTMLEditor->GetPriorHTMLNode(selNode, selOffset, true);
if (nearNode && (TextEditUtils::IsBreak(nearNode) ||
- nsEditor::IsTextNode(nearNode) ||
+ EditorBase::IsTextNode(nearNode) ||
HTMLEditUtils::IsImage(nearNode) ||
nearNode->IsHTMLElement(nsGkAtoms::hr))) {
// this is a good place for the caret to be
return NS_OK;
}
NS_ENSURE_STATE(mHTMLEditor);
nearNode = mHTMLEditor->GetNextHTMLNode(selNode, selOffset, true);
if (nearNode && (TextEditUtils::IsBreak(nearNode) ||
- nsEditor::IsTextNode(nearNode) ||
+ EditorBase::IsTextNode(nearNode) ||
nearNode->IsAnyOfHTMLElements(nsGkAtoms::img,
nsGkAtoms::hr))) {
return NS_OK; // this is a good place for the caret to be
}
// look for a nearby text node.
// prefer the correct direction.
nsCOMPtr<nsIDOMNode> nearNodeDOM = GetAsDOMNode(nearNode);
@@ -7380,17 +7381,17 @@ HTMLEditRules::AdjustSelection(Selection
int32_t offset = 0;
// put selection in right place:
if (aAction == nsIEditor::ePrevious)
textNode->GetLength((uint32_t*)&offset);
res = aSelection->Collapse(nearNode,offset);
}
else // must be break or image
{
- selNode = nsEditor::GetNodeLocation(nearNode, &selOffset);
+ selNode = EditorBase::GetNodeLocation(nearNode, &selOffset);
if (aAction == nsIEditor::ePrevious) selOffset++; // want to be beyond it if we backed up to it
res = aSelection->Collapse(selNode, selOffset);
}
}
return res;
}
@@ -8060,17 +8061,17 @@ NS_IMETHODIMP
HTMLEditRules::WillJoinNodes(nsIDOMNode* aLeftNode,
nsIDOMNode* aRightNode,
nsIDOMNode* aParent)
{
if (!mListenerEnabled) {
return NS_OK;
}
// remember split point
- nsresult res = nsEditor::GetLengthOfDOMNode(aLeftNode, mJoinOffset);
+ nsresult res = EditorBase::GetLengthOfDOMNode(aLeftNode, mJoinOffset);
return res;
}
NS_IMETHODIMP
HTMLEditRules::DidJoinNodes(nsIDOMNode* aLeftNode,
nsIDOMNode* aRightNode,
nsIDOMNode* aParent,
nsresult aResult)
@@ -8212,17 +8213,17 @@ HTMLEditRules::RemoveAlignment(nsIDOMNod
{
tmp = nullptr;
}
bool isBlock;
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->NodeIsBlockStatic(child, &isBlock);
NS_ENSURE_SUCCESS(res, res);
- if (nsEditor::NodeIsType(child, nsGkAtoms::center)) {
+ if (EditorBase::NodeIsType(child, nsGkAtoms::center)) {
// the current node is a CENTER element
// first remove children's alignment
res = RemoveAlignment(child, aAlignType, true);
NS_ENSURE_SUCCESS(res, res);
// we may have to insert BRs in first and last position of element's children
// if the nodes before/after are not blocks and not BRs
res = MakeSureElemStartsOrEndsOnCR(child);
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -5,17 +5,16 @@
#ifndef HTMLEditRules_h
#define HTMLEditRules_h
#include "TypeInState.h"
#include "mozilla/SelectionState.h"
#include "mozilla/TextEditRules.h"
#include "nsCOMPtr.h"
-#include "nsEditor.h"
#include "nsIEditActionListener.h"
#include "nsIEditor.h"
#include "nsIHTMLEditor.h"
#include "nsISupportsImpl.h"
#include "nsTArray.h"
#include "nscore.h"
class nsIAtom;
--- a/editor/libeditor/HTMLEditUtils.cpp
+++ b/editor/libeditor/HTMLEditUtils.cpp
@@ -3,22 +3,22 @@
* 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/. */
#include "HTMLEditUtils.h"
#include "TextEditUtils.h" // for TextEditUtils
#include "mozilla/ArrayUtils.h" // for ArrayLength
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
+#include "mozilla/EditorBase.h" // for EditorBase
#include "mozilla/dom/Element.h" // for Element, nsINode
#include "nsAString.h" // for nsAString_internal::IsEmpty
#include "nsCOMPtr.h" // for nsCOMPtr, operator==, etc
#include "nsCaseTreatment.h"
#include "nsDebug.h" // for NS_PRECONDITION, etc
-#include "nsEditor.h" // for nsEditor
#include "nsError.h" // for NS_SUCCEEDED
#include "nsGkAtoms.h" // for nsGkAtoms, nsGkAtoms::a, etc
#include "nsHTMLTags.h"
#include "nsIAtom.h" // for nsIAtom
#include "nsIDOMHTMLAnchorElement.h" // for nsIDOMHTMLAnchorElement
#include "nsIDOMNode.h" // for nsIDOMNode
#include "nsNameSpaceManager.h" // for kNameSpaceID_None
#include "nsLiteralString.h" // for NS_LITERAL_STRING
@@ -83,17 +83,17 @@ HTMLEditUtils::IsFormatNode(nsINode* aNo
/**
* IsNodeThatCanOutdent() returns true if aNode is a list, list item or
* blockquote.
*/
bool
HTMLEditUtils::IsNodeThatCanOutdent(nsIDOMNode* aNode)
{
MOZ_ASSERT(aNode);
- nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(aNode);
+ nsCOMPtr<nsIAtom> nodeAtom = EditorBase::GetTag(aNode);
return (nodeAtom == nsGkAtoms::ul)
|| (nodeAtom == nsGkAtoms::ol)
|| (nodeAtom == nsGkAtoms::dl)
|| (nodeAtom == nsGkAtoms::li)
|| (nodeAtom == nsGkAtoms::dd)
|| (nodeAtom == nsGkAtoms::dt)
|| (nodeAtom == nsGkAtoms::blockquote);
}
@@ -122,26 +122,26 @@ HTMLEditUtils::IsHeader(nsIDOMNode* aNod
}
/**
* IsParagraph() returns true if aNode is an html paragraph.
*/
bool
HTMLEditUtils::IsParagraph(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::p);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::p);
}
/**
* IsHR() returns true if aNode is an horizontal rule.
*/
bool
HTMLEditUtils::IsHR(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::hr);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::hr);
}
/**
* IsListItem() returns true if aNode is an html list item.
*/
bool
HTMLEditUtils::IsListItem(nsIDOMNode* aNode)
{
@@ -210,32 +210,32 @@ HTMLEditUtils::IsTableElementButNotTable
}
/**
* IsTable() returns true if aNode is an html table.
*/
bool
HTMLEditUtils::IsTable(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::table);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::table);
}
bool
HTMLEditUtils::IsTable(nsINode* aNode)
{
return aNode && aNode->IsHTMLElement(nsGkAtoms::table);
}
/**
* IsTableRow() returns true if aNode is an html tr.
*/
bool
HTMLEditUtils::IsTableRow(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::tr);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::tr);
}
/**
* IsTableCell() returns true if aNode is an html td or th.
*/
bool
HTMLEditUtils::IsTableCell(nsIDOMNode* aNode)
{
@@ -282,60 +282,60 @@ HTMLEditUtils::IsList(nsINode* aNode)
}
/**
* IsOrderedList() returns true if aNode is an html ordered list.
*/
bool
HTMLEditUtils::IsOrderedList(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::ol);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::ol);
}
/**
* IsUnorderedList() returns true if aNode is an html unordered list.
*/
bool
HTMLEditUtils::IsUnorderedList(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::ul);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::ul);
}
/**
* IsBlockquote() returns true if aNode is an html blockquote node.
*/
bool
HTMLEditUtils::IsBlockquote(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::blockquote);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::blockquote);
}
/**
* IsPre() returns true if aNode is an html pre node.
*/
bool
HTMLEditUtils::IsPre(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::pre);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::pre);
}
/**
* IsImage() returns true if aNode is an html image node.
*/
bool
HTMLEditUtils::IsImage(nsINode* aNode)
{
return aNode && aNode->IsHTMLElement(nsGkAtoms::img);
}
bool
HTMLEditUtils::IsImage(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::img);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::img);
}
bool
HTMLEditUtils::IsLink(nsIDOMNode *aNode)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsLink(node);
}
@@ -377,17 +377,17 @@ HTMLEditUtils::IsNamedAnchor(nsINode* aN
}
/**
* IsDiv() returns true if aNode is an html div node.
*/
bool
HTMLEditUtils::IsDiv(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::div);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::div);
}
/**
* IsMozDiv() returns true if aNode is an html div node with |type = _moz|.
*/
bool
HTMLEditUtils::IsMozDiv(nsIDOMNode* aNode)
{
@@ -461,17 +461,17 @@ HTMLEditUtils::IsFormWidget(nsINode* aNo
nsGkAtoms::meter,
nsGkAtoms::input);
}
bool
HTMLEditUtils::SupportsAlignAttr(nsIDOMNode* aNode)
{
MOZ_ASSERT(aNode);
- nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(aNode);
+ nsCOMPtr<nsIAtom> nodeAtom = EditorBase::GetTag(aNode);
return (nodeAtom == nsGkAtoms::hr)
|| (nodeAtom == nsGkAtoms::table)
|| (nodeAtom == nsGkAtoms::tbody)
|| (nodeAtom == nsGkAtoms::tfoot)
|| (nodeAtom == nsGkAtoms::thead)
|| (nodeAtom == nsGkAtoms::tr)
|| (nodeAtom == nsGkAtoms::td)
|| (nodeAtom == nsGkAtoms::th)
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -229,18 +229,18 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAddColumnBeforeButton)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRemoveColumnButton)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAddColumnAfterButton)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAddRowBeforeButton)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRemoveRowButton)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAddRowAfterButton)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-NS_IMPL_ADDREF_INHERITED(HTMLEditor, nsEditor)
-NS_IMPL_RELEASE_INHERITED(HTMLEditor, nsEditor)
+NS_IMPL_ADDREF_INHERITED(HTMLEditor, EditorBase)
+NS_IMPL_RELEASE_INHERITED(HTMLEditor, EditorBase)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLEditor)
NS_INTERFACE_MAP_ENTRY(nsIHTMLEditor)
NS_INTERFACE_MAP_ENTRY(nsIHTMLObjectResizer)
NS_INTERFACE_MAP_ENTRY(nsIHTMLAbsPosEditor)
NS_INTERFACE_MAP_ENTRY(nsIHTMLInlineTableEditor)
NS_INTERFACE_MAP_ENTRY(nsITableEditor)
NS_INTERFACE_MAP_ENTRY(nsIEditorStyleSheets)
@@ -350,17 +350,17 @@ HTMLEditor::PreDestroy(bool aDestroyingF
}
NS_IMETHODIMP
HTMLEditor::GetRootElement(nsIDOMElement** aRootElement)
{
NS_ENSURE_ARG_POINTER(aRootElement);
if (mRootElement) {
- return nsEditor::GetRootElement(aRootElement);
+ return EditorBase::GetRootElement(aRootElement);
}
*aRootElement = nullptr;
// Use the HTML documents body element as the editor root if we didn't
// get a root element during initialization.
nsCOMPtr<nsIDOMElement> rootElement;
@@ -603,38 +603,38 @@ HTMLEditor::BeginningOfDocument()
nsresult
HTMLEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
{
// NOTE: When you change this method, you should also change:
// * editor/libeditor/tests/test_htmleditor_keyevent_handling.html
if (IsReadonly() || IsDisabled()) {
- // When we're not editable, the events are handled on nsEditor, so, we can
+ // When we're not editable, the events are handled on EditorBase, so, we can
// bypass TextEditor.
- return nsEditor::HandleKeyPressEvent(aKeyEvent);
+ return EditorBase::HandleKeyPressEvent(aKeyEvent);
}
WidgetKeyboardEvent* nativeKeyEvent =
aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
NS_ENSURE_TRUE(nativeKeyEvent, NS_ERROR_UNEXPECTED);
NS_ASSERTION(nativeKeyEvent->mMessage == eKeyPress,
"HandleKeyPressEvent gets non-keypress event");
switch (nativeKeyEvent->mKeyCode) {
case NS_VK_META:
case NS_VK_WIN:
case NS_VK_SHIFT:
case NS_VK_CONTROL:
case NS_VK_ALT:
case NS_VK_BACK:
case NS_VK_DELETE:
- // These keys are handled on nsEditor, so, we can bypass
+ // These keys are handled on EditorBase, so, we can bypass
// TextEditor.
- return nsEditor::HandleKeyPressEvent(aKeyEvent);
+ return EditorBase::HandleKeyPressEvent(aKeyEvent);
case NS_VK_TAB: {
if (IsPlaintextEditor()) {
// If this works as plain text editor, e.g., mail editor for plain
// text, should be handled on TextEditor.
return TextEditor::HandleKeyPressEvent(aKeyEvent);
}
if (IsTabbable()) {
@@ -825,17 +825,17 @@ HTMLEditor::SetDocumentTitle(const nsASt
new SetDocumentTitleTransaction();
NS_ENSURE_TRUE(transaction, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = transaction->Init(this, &aTitle);
NS_ENSURE_SUCCESS(rv, rv);
//Don't let Rules System change the selection
AutoTransactionsConserveSelection dontChangeSelection(this);
- return nsEditor::DoTransaction(transaction);
+ return EditorBase::DoTransaction(transaction);
}
/**
* GetBlockNodeParent returns enclosing block level ancestor, if any.
*/
Element*
HTMLEditor::GetBlockNodeParent(nsINode* aNode)
{
@@ -3104,17 +3104,17 @@ HTMLEditor::GetEmbeddedObjects(nsISuppor
}
NS_IMETHODIMP
HTMLEditor::DeleteSelectionImpl(EDirection aAction,
EStripWrappers aStripWrappers)
{
MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
- nsresult res = nsEditor::DeleteSelectionImpl(aAction, aStripWrappers);
+ nsresult res = EditorBase::DeleteSelectionImpl(aAction, aStripWrappers);
NS_ENSURE_SUCCESS(res, res);
// If we weren't asked to strip any wrappers, we're done.
if (aStripWrappers == eNoStrip) {
return NS_OK;
}
RefPtr<Selection> selection = GetSelection();
@@ -3169,45 +3169,45 @@ NS_IMETHODIMP
HTMLEditor::DeleteNode(nsIDOMNode* aNode)
{
// do nothing if the node is read-only
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
if (!IsModifiableNode(aNode) && !IsMozEditorBogusNode(content)) {
return NS_ERROR_FAILURE;
}
- return nsEditor::DeleteNode(aNode);
+ return EditorBase::DeleteNode(aNode);
}
nsresult
HTMLEditor::DeleteText(nsGenericDOMDataNode& aCharData,
uint32_t aOffset,
uint32_t aLength)
{
// Do nothing if the node is read-only
if (!IsModifiableNode(&aCharData)) {
return NS_ERROR_FAILURE;
}
- return nsEditor::DeleteText(aCharData, aOffset, aLength);
+ return EditorBase::DeleteText(aCharData, aOffset, aLength);
}
nsresult
HTMLEditor::InsertTextImpl(const nsAString& aStringToInsert,
nsCOMPtr<nsINode>* aInOutNode,
int32_t* aInOutOffset,
nsIDocument* aDoc)
{
// Do nothing if the node is read-only
if (!IsModifiableNode(*aInOutNode)) {
return NS_ERROR_FAILURE;
}
- return nsEditor::InsertTextImpl(aStringToInsert, aInOutNode, aInOutOffset,
- aDoc);
+ return EditorBase::InsertTextImpl(aStringToInsert, aInOutNode, aInOutOffset,
+ aDoc);
}
void
HTMLEditor::ContentAppended(nsIDocument* aDocument,
nsIContent* aContainer,
nsIContent* aFirstNewContent,
int32_t aIndexInContainer)
{
@@ -3467,17 +3467,17 @@ HTMLEditor::StyleSheetLoaded(StyleSheetH
*/
NS_IMETHODIMP
HTMLEditor::StartOperation(EditAction opID,
nsIEditor::EDirection aDirection)
{
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
- nsEditor::StartOperation(opID, aDirection); // will set mAction, mDirection
+ EditorBase::StartOperation(opID, aDirection); // will set mAction, mDirection
if (mRules) return mRules->BeforeEdit(mAction, mDirection);
return NS_OK;
}
/**
* All editor operations which alter the doc should be followed
* with a call to EndOperation.
*/
@@ -3485,17 +3485,17 @@ NS_IMETHODIMP
HTMLEditor::EndOperation()
{
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
// post processing
nsresult res = NS_OK;
if (mRules) res = mRules->AfterEdit(mAction, mDirection);
- nsEditor::EndOperation(); // will clear mAction, mDirection
+ EditorBase::EndOperation(); // will clear mAction, mDirection
return res;
}
bool
HTMLEditor::TagCanContainTag(nsIAtom& aParentTag,
nsIAtom& aChildTag)
{
nsIParserService* parserService = nsContentUtils::GetParserService();
@@ -3557,17 +3557,17 @@ HTMLEditor::SelectEntireDocument(Selecti
NS_ENSURE_SUCCESS(res, res);
if (bDocIsEmpty)
{
// if its empty dont select entire doc - that would select the bogus node
return aSelection->Collapse(rootElement, 0);
}
- return nsEditor::SelectEntireDocument(aSelection);
+ return EditorBase::SelectEntireDocument(aSelection);
}
NS_IMETHODIMP
HTMLEditor::SelectAll()
{
ForceCompositionEnd();
RefPtr<Selection> selection = GetSelection();
@@ -3736,17 +3736,17 @@ HTMLEditor::GetEnclosingTable(nsIDOMNode
return ret;
}
/**
* This method scans the selection for adjacent text nodes
* and collapses them into a single text node.
* "adjacent" means literally adjacent siblings of the same parent.
- * Uses nsEditor::JoinNodes so action is undoable.
+ * Uses EditorBase::JoinNodes so action is undoable.
* Should be called within the context of a batch transaction.
*/
nsresult
HTMLEditor::CollapseAdjacentTextNodes(nsRange* aInRange)
{
NS_ENSURE_TRUE(aInRange, NS_ERROR_NULL_POINTER);
AutoTransactionsConserveSelection dontSpazMySelection(this);
nsTArray<nsCOMPtr<nsIDOMNode> > textNodes;
@@ -4366,17 +4366,17 @@ HTMLEditor::IsEmptyNodeImpl(nsINode* aNo
HTMLEditUtils::IsTableCell(aNode);
// loop over children of node. if no children, or all children are either
// empty text nodes or non-editable, then node qualifies as empty
for (nsCOMPtr<nsIContent> child = aNode->GetFirstChild();
child;
child = child->GetNextSibling()) {
// Is the child editable and non-empty? if so, return false
- if (nsEditor::IsEditable(child)) {
+ if (EditorBase::IsEditable(child)) {
if (child->NodeType() == nsIDOMNode::TEXT_NODE) {
nsresult rv = IsVisTextNode(child, outIsEmptyNode, aSafeToAskFrames);
NS_ENSURE_SUCCESS(rv, rv);
// break out if we find we aren't emtpy
if (!*outIsEmptyNode) {
return NS_OK;
}
} else {
@@ -4821,17 +4821,17 @@ HTMLEditor::GetElementOrigin(nsIDOMEleme
aY = nsPresContext::AppUnitsToIntCSSPixels(off.y);
return NS_OK;
}
nsresult
HTMLEditor::EndUpdateViewBatch()
{
- nsresult res = nsEditor::EndUpdateViewBatch();
+ nsresult res = EditorBase::EndUpdateViewBatch();
NS_ENSURE_SUCCESS(res, res);
// We may need to show resizing handles or update existing ones after
// all transactions are done. This way of doing is preferred to DOM
// mutation events listeners because all the changes the user can apply
// to a document may result in multiple events, some of them quite hard
// to listen too (in particular when an ancestor of the selection is
// changed but the selection itself is not changed).
@@ -5173,17 +5173,17 @@ HTMLEditor::OurWindowHasFocus()
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocWeak);
nsPIDOMWindowOuter* ourWindow = doc->GetWindow();
return ourWindow == focusedWindow;
}
bool
HTMLEditor::IsAcceptableInputEvent(nsIDOMEvent* aEvent)
{
- if (!nsEditor::IsAcceptableInputEvent(aEvent)) {
+ if (!EditorBase::IsAcceptableInputEvent(aEvent)) {
return false;
}
// While there is composition, all composition events in its top level window
// are always fired on the composing editor. Therefore, if this editor has
// composition, the composition events should be handled in this editor.
if (mComposition && aEvent->WidgetEventPtr()->AsCompositionEvent()) {
return true;
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -113,17 +113,17 @@ public:
virtual bool IsActiveInDOMWindow() override;
virtual already_AddRefed<dom::EventTarget> GetDOMEventTarget() override;
virtual Element* GetEditorRoot() override;
virtual already_AddRefed<nsIContent> FindSelectionRoot(
nsINode *aNode) override;
virtual bool IsAcceptableInputEvent(nsIDOMEvent* aEvent) override;
virtual already_AddRefed<nsIContent> GetInputEventTargetContent() override;
virtual bool IsEditable(nsINode* aNode) override;
- using nsEditor::IsEditable;
+ using EditorBase::IsEditable;
// nsStubMutationObserver overrides
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
// nsIEditorIMESupport overrides
NS_IMETHOD GetPreferredIMEState(widget::IMEState* aState) override;
@@ -243,17 +243,17 @@ public:
/**
* This sets background on the appropriate container element (table, cell,)
* or calls into nsTextEditor to set the page background.
*/
nsresult SetCSSBackgroundColor(const nsAString& aColor);
nsresult SetHTMLBackgroundColor(const nsAString& aColor);
- // Block methods moved from nsEditor
+ // Block methods moved from EditorBase
static Element* GetBlockNodeParent(nsINode* aNode);
static nsIDOMNode* GetBlockNodeParent(nsIDOMNode* aNode);
static Element* GetBlock(nsINode& aNode);
void IsNextCharInNodeWhitespace(nsIContent* aContent,
int32_t aOffset,
bool* outIsSpace,
bool* outIsNBSP,
@@ -261,34 +261,34 @@ public:
int32_t* outOffset = 0);
void IsPrevCharInNodeWhitespace(nsIContent* aContent,
int32_t aOffset,
bool* outIsSpace,
bool* outIsNBSP,
nsIContent** outNode = nullptr,
int32_t* outOffset = 0);
- // Overrides of nsEditor interface methods
+ // Overrides of EditorBase interface methods
nsresult EndUpdateViewBatch() override;
NS_IMETHOD Init(nsIDOMDocument* aDoc, nsIContent* aRoot,
nsISelectionController* aSelCon, uint32_t aFlags,
const nsAString& aValue) override;
NS_IMETHOD PreDestroy(bool aDestroyingFrames) override;
/**
* @param aElement Must not be null.
*/
static bool NodeIsBlockStatic(const nsINode* aElement);
static nsresult NodeIsBlockStatic(nsIDOMNode *aNode, bool *aIsBlock);
protected:
virtual ~HTMLEditor();
- using nsEditor::IsBlockNode;
+ using EditorBase::IsBlockNode;
virtual bool IsBlockNode(nsINode *aNode) override;
public:
// XXX Why don't we move following methods above for grouping by the origins?
NS_IMETHOD SetFlags(uint32_t aFlags) override;
NS_IMETHOD Paste(int32_t aSelectionType) override;
NS_IMETHOD CanPaste(int32_t aSelectionType, bool* aCanPaste) override;
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -26,17 +26,16 @@
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsCRTGlue.h"
#include "nsComponentManagerUtils.h"
#include "nsIScriptError.h"
#include "nsContentUtils.h"
#include "nsDebug.h"
#include "nsDependentSubstring.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
#include "nsIClipboard.h"
#include "nsIContent.h"
#include "nsIContentFilter.h"
#include "nsIDOMComment.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentFragment.h"
--- a/editor/libeditor/HTMLEditorEventListener.cpp
+++ b/editor/libeditor/HTMLEditorEventListener.cpp
@@ -6,17 +6,16 @@
#include "HTMLEditorEventListener.h"
#include "HTMLEditUtils.h"
#include "mozilla/HTMLEditor.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/Selection.h"
#include "nsCOMPtr.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMNode.h"
#include "nsIEditor.h"
#include "nsIHTMLInlineTableEditor.h"
@@ -27,32 +26,32 @@
#include "nsRange.h"
namespace mozilla {
using namespace dom;
#ifdef DEBUG
nsresult
-HTMLEditorEventListener::Connect(nsEditor* aEditor)
+HTMLEditorEventListener::Connect(EditorBase* aEditorBase)
{
- nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryObject(aEditor);
+ nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryObject(aEditorBase);
nsCOMPtr<nsIHTMLInlineTableEditor> htmlInlineTableEditor =
- do_QueryObject(aEditor);
+ do_QueryObject(aEditorBase);
NS_PRECONDITION(htmlEditor && htmlInlineTableEditor,
"Set HTMLEditor or its sub class");
- return EditorEventListener::Connect(aEditor);
+ return EditorEventListener::Connect(aEditorBase);
}
#endif
HTMLEditor*
HTMLEditorEventListener::GetHTMLEditor()
{
// mEditor must be HTMLEditor or its subclass.
- return static_cast<HTMLEditor*>(mEditor);
+ return static_cast<HTMLEditor*>(mEditorBase);
}
nsresult
HTMLEditorEventListener::MouseUp(nsIDOMMouseEvent* aMouseEvent)
{
HTMLEditor* htmlEditor = GetHTMLEditor();
nsCOMPtr<nsIDOMEventTarget> target;
@@ -99,17 +98,17 @@ HTMLEditorEventListener::MouseDown(nsIDO
nsCOMPtr<nsIDOMEventTarget> target;
rv = aMouseEvent->AsEvent()->GetExplicitOriginalTarget(getter_AddRefs(target));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
if (isContextClick || (buttonNumber == 0 && clickCount == 2)) {
- RefPtr<Selection> selection = mEditor->GetSelection();
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
NS_ENSURE_TRUE(selection, NS_OK);
// Get location of mouse within target node
nsCOMPtr<nsIDOMNode> parent;
rv = aMouseEvent->GetRangeParent(getter_AddRefs(parent));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
--- a/editor/libeditor/HTMLEditorEventListener.h
+++ b/editor/libeditor/HTMLEditorEventListener.h
@@ -4,36 +4,35 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef HTMLEditorEventListener_h
#define HTMLEditorEventListener_h
#include "EditorEventListener.h"
#include "nscore.h"
-class nsEditor;
-
namespace mozilla {
+class EditorBase;
class HTMLEditor;
class HTMLEditorEventListener final : public EditorEventListener
{
public:
HTMLEditorEventListener()
{
}
virtual ~HTMLEditorEventListener()
{
}
#ifdef DEBUG
// WARNING: You must be use HTMLEditor or its sub class for this class.
- virtual nsresult Connect(nsEditor* aEditor) override;
+ virtual nsresult Connect(EditorBase* aEditorBase) override;
#endif
protected:
virtual nsresult MouseDown(nsIDOMMouseEvent* aMouseEvent) override;
virtual nsresult MouseUp(nsIDOMMouseEvent* aMouseEvent) override;
virtual nsresult MouseClick(nsIDOMMouseEvent* aMouseEvent) override;
inline HTMLEditor* GetHTMLEditor();
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -15,17 +15,16 @@
#include "mozilla/dom/Element.h"
#include "mozilla/mozalloc.h"
#include "nsAString.h"
#include "nsAttrName.h"
#include "nsCOMPtr.h"
#include "nsCaseTreatment.h"
#include "nsComponentManagerUtils.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
#include "nsIAtom.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsIDOMElement.h"
#include "nsIEditor.h"
#include "nsIEditorIMESupport.h"
@@ -47,17 +46,17 @@ class nsISupports;
namespace mozilla {
using namespace dom;
static bool
IsEmptyTextNode(HTMLEditor* aThis, nsINode* aNode)
{
bool isEmptyTextNode = false;
- return nsEditor::IsTextNode(aNode) &&
+ return EditorBase::IsTextNode(aNode) &&
NS_SUCCEEDED(aThis->IsEmptyNode(aNode, &isEmptyTextNode)) &&
isEmptyTextNode;
}
NS_IMETHODIMP
HTMLEditor::AddDefaultProperty(nsIAtom* aProperty,
const nsAString& aAttribute,
const nsAString& aValue)
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -11,17 +11,16 @@
#include "HTMLEditUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/Element.h"
#include "nsAString.h"
#include "nsAlgorithm.h"
#include "nsCOMPtr.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
#include "nsIAtom.h"
#include "nsIContent.h"
#include "nsIDOMElement.h"
#include "nsIDOMNode.h"
#include "nsIEditor.h"
#include "nsIFrame.h"
@@ -1973,23 +1972,23 @@ HTMLEditor::SwitchTableCellHeaderType(ns
// Save current selection to restore when done
// This is needed so ReplaceContainer can monitor selection
// when replacing nodes
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
AutoSelectionRestorer selectionRestorer(selection, this);
// Set to the opposite of current type
- nsCOMPtr<nsIAtom> atom = nsEditor::GetTag(aSourceCell);
+ nsCOMPtr<nsIAtom> atom = EditorBase::GetTag(aSourceCell);
nsIAtom* newCellType = atom == nsGkAtoms::td ? nsGkAtoms::th : nsGkAtoms::td;
// This creates new node, moves children, copies attributes (true)
// and manages the selection!
nsCOMPtr<Element> newNode = ReplaceContainer(sourceCell, newCellType,
- nullptr, nullptr, nsEditor::eCloneAttributes);
+ nullptr, nullptr, EditorBase::eCloneAttributes);
NS_ENSURE_TRUE(newNode, NS_ERROR_FAILURE);
// Return the new cell
if (aNewCell)
{
nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(newNode);
*aNewCell = newElement.get();
NS_ADDREF(*aNewCell);
@@ -3246,17 +3245,17 @@ HTMLEditor::GetSelectedOrParentTableElem
if (!selectedNode)
{
selectedNode = anchorNode;
// If anchor doesn't have a child, we can't be selecting a table element,
// so don't do the following:
}
else
{
- nsCOMPtr<nsIAtom> atom = nsEditor::GetTag(selectedNode);
+ nsCOMPtr<nsIAtom> atom = EditorBase::GetTag(selectedNode);
if (atom == nsGkAtoms::td) {
tableOrCellElement = do_QueryInterface(selectedNode);
aTagName = tdName;
// Each cell is in its own selection range,
// so count signals multiple-cell selection
res = selection->GetRangeCount(aSelectedCount);
NS_ENSURE_SUCCESS(res, res);
--- a/editor/libeditor/InsertNodeTransaction.cpp
+++ b/editor/libeditor/InsertNodeTransaction.cpp
@@ -1,38 +1,39 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "InsertNodeTransaction.h"
+#include "mozilla/EditorBase.h" // for EditorBase
+
#include "mozilla/dom/Selection.h" // for Selection
#include "nsAString.h"
#include "nsDebug.h" // for NS_ENSURE_TRUE, etc
-#include "nsEditor.h" // for nsEditor
#include "nsError.h" // for NS_ERROR_NULL_POINTER, etc
#include "nsIContent.h" // for nsIContent
#include "nsMemory.h" // for nsMemory
#include "nsReadableUtils.h" // for ToNewCString
#include "nsString.h" // for nsString
namespace mozilla {
using namespace dom;
InsertNodeTransaction::InsertNodeTransaction(nsIContent& aNode,
nsINode& aParent,
int32_t aOffset,
- nsEditor& aEditor)
+ EditorBase& aEditorBase)
: mNode(&aNode)
, mParent(&aParent)
, mOffset(aOffset)
- , mEditor(aEditor)
+ , mEditorBase(aEditorBase)
{
}
InsertNodeTransaction::~InsertNodeTransaction()
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(InsertNodeTransaction, EditTransactionBase,
@@ -53,25 +54,25 @@ InsertNodeTransaction::DoTransaction()
if (mOffset > static_cast<int32_t>(count) || mOffset == -1) {
// -1 is sentinel value meaning "append at end"
mOffset = count;
}
// Note, it's ok for ref to be null. That means append.
nsCOMPtr<nsIContent> ref = mParent->GetChildAt(mOffset);
- mEditor.MarkNodeDirty(GetAsDOMNode(mNode));
+ mEditorBase.MarkNodeDirty(GetAsDOMNode(mNode));
ErrorResult rv;
mParent->InsertBefore(*mNode, ref, rv);
NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
// Only set selection to insertion point if editor gives permission
- if (mEditor.GetShouldTxnSetSelection()) {
- RefPtr<Selection> selection = mEditor.GetSelection();
+ if (mEditorBase.GetShouldTxnSetSelection()) {
+ RefPtr<Selection> selection = mEditorBase.GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
// Place the selection just after the inserted element
selection->Collapse(mParent, mOffset + 1);
} else {
// Do nothing - DOM Range gravity will adjust selection
}
return NS_OK;
}
--- a/editor/libeditor/InsertNodeTransaction.h
+++ b/editor/libeditor/InsertNodeTransaction.h
@@ -7,34 +7,34 @@
#define InsertNodeTransaction_h
#include "EditTransactionBase.h" // for EditTransactionBase, etc
#include "nsCOMPtr.h" // for nsCOMPtr
#include "nsCycleCollectionParticipant.h"
#include "nsIContent.h" // for nsIContent
#include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED
-class nsEditor;
+namespace mozilla {
-namespace mozilla {
+class EditorBase;
/**
* A transaction that inserts a single element
*/
class InsertNodeTransaction final : public EditTransactionBase
{
public:
/**
* Initialize the transaction.
* @param aNode The node to insert.
* @param aParent The node to insert into.
* @param aOffset The offset in aParent to insert aNode.
*/
InsertNodeTransaction(nsIContent& aNode, nsINode& aParent, int32_t aOffset,
- nsEditor& aEditor);
+ EditorBase& aEditorBase);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InsertNodeTransaction,
EditTransactionBase)
NS_DECL_EDITTRANSACTIONBASE
protected:
@@ -45,14 +45,14 @@ protected:
// The node into which the new node will be inserted.
nsCOMPtr<nsINode> mParent;
// The index in mParent for the new node.
int32_t mOffset;
// The editor for this transaction.
- nsEditor& mEditor;
+ EditorBase& mEditorBase;
};
} // namespace mozilla
#endif // #ifndef InsertNodeTransaction_h
--- a/editor/libeditor/InsertTextTransaction.cpp
+++ b/editor/libeditor/InsertTextTransaction.cpp
@@ -1,35 +1,35 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "InsertTextTransaction.h"
+#include "mozilla/EditorBase.h" // mEditorBase
#include "mozilla/dom/Selection.h" // Selection local var
#include "mozilla/dom/Text.h" // mTextNode
#include "nsAString.h" // nsAString parameter
#include "nsDebug.h" // for NS_ASSERTION, etc
-#include "nsEditor.h" // mEditor
#include "nsError.h" // for NS_OK, etc
#include "nsQueryObject.h" // for do_QueryObject
namespace mozilla {
using namespace dom;
InsertTextTransaction::InsertTextTransaction(Text& aTextNode,
uint32_t aOffset,
const nsAString& aStringToInsert,
- nsEditor& aEditor)
+ EditorBase& aEditorBase)
: mTextNode(&aTextNode)
, mOffset(aOffset)
, mStringToInsert(aStringToInsert)
- , mEditor(aEditor)
+ , mEditorBase(aEditorBase)
{
}
InsertTextTransaction::~InsertTextTransaction()
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(InsertTextTransaction, EditTransactionBase,
@@ -46,18 +46,18 @@ NS_INTERFACE_MAP_END_INHERITING(EditTran
NS_IMETHODIMP
InsertTextTransaction::DoTransaction()
{
nsresult res = mTextNode->InsertData(mOffset, mStringToInsert);
NS_ENSURE_SUCCESS(res, res);
// Only set selection to insertion point if editor gives permission
- if (mEditor.GetShouldTxnSetSelection()) {
- RefPtr<Selection> selection = mEditor.GetSelection();
+ if (mEditorBase.GetShouldTxnSetSelection()) {
+ RefPtr<Selection> selection = mEditorBase.GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
res = selection->Collapse(mTextNode,
mOffset + mStringToInsert.Length());
NS_ASSERTION(NS_SUCCEEDED(res),
"Selection could not be collapsed after insert");
} else {
// Do nothing - DOM Range gravity will adjust selection
}
--- a/editor/libeditor/InsertTextTransaction.h
+++ b/editor/libeditor/InsertTextTransaction.h
@@ -8,25 +8,25 @@
#include "EditTransactionBase.h" // base class
#include "nsCycleCollectionParticipant.h" // various macros
#include "nsID.h" // NS_DECLARE_STATIC_IID_ACCESSOR
#include "nsISupportsImpl.h" // NS_DECL_ISUPPORTS_INHERITED
#include "nsString.h" // nsString members
#include "nscore.h" // NS_IMETHOD, nsAString
-class nsEditor;
class nsITransaction;
#define NS_INSERTTEXTTXN_IID \
{ 0x8c9ad77f, 0x22a7, 0x4d01, \
{ 0xb1, 0x59, 0x8a, 0x0f, 0xdb, 0x1d, 0x08, 0xe9 } }
namespace mozilla {
+class EditorBase;
namespace dom {
class Text;
} // namespace dom
/**
* A transaction that inserts text into a content node.
*/
class InsertTextTransaction final : public EditTransactionBase
@@ -36,17 +36,17 @@ public:
/**
* @param aElement The text content node.
* @param aOffset The location in aElement to do the insertion.
* @param aString The new text to insert.
* @param aPresShell Used to get and set the selection.
*/
InsertTextTransaction(dom::Text& aTextNode, uint32_t aOffset,
- const nsAString& aString, nsEditor& aEditor);
+ const nsAString& aString, EditorBase& aEditorBase);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InsertTextTransaction,
EditTransactionBase)
NS_DECL_EDITTRANSACTIONBASE
NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
@@ -67,16 +67,16 @@ private:
// The offset into mTextNode where the insertion is to take place.
uint32_t mOffset;
// The text to insert into mTextNode at mOffset.
nsString mStringToInsert;
// The editor, which we'll need to get the selection.
- nsEditor& mEditor;
+ EditorBase& mEditorBase;
};
NS_DEFINE_STATIC_IID_ACCESSOR(InsertTextTransaction, NS_INSERTTEXTTXN_IID)
} // namespace mozilla
#endif // #ifndef InsertTextTransaction_h
--- a/editor/libeditor/JoinNodeTransaction.cpp
+++ b/editor/libeditor/JoinNodeTransaction.cpp
@@ -1,31 +1,32 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "JoinNodeTransaction.h"
+
+#include "mozilla/EditorBase.h" // for EditorBase
#include "nsAString.h"
#include "nsDebug.h" // for NS_ASSERTION, etc
-#include "nsEditor.h" // for nsEditor
#include "nsError.h" // for NS_ERROR_NULL_POINTER, etc
#include "nsIContent.h" // for nsIContent
#include "nsIDOMCharacterData.h" // for nsIDOMCharacterData
-#include "nsIEditor.h" // for nsEditor::IsModifiableNode
+#include "nsIEditor.h" // for EditorBase::IsModifiableNode
#include "nsISupportsImpl.h" // for QueryInterface, etc
namespace mozilla {
using namespace dom;
-JoinNodeTransaction::JoinNodeTransaction(nsEditor& aEditor,
+JoinNodeTransaction::JoinNodeTransaction(EditorBase& aEditorBase,
nsINode& aLeftNode,
nsINode& aRightNode)
- : mEditor(aEditor)
+ : mEditorBase(aEditorBase)
, mLeftNode(&aLeftNode)
, mRightNode(&aRightNode)
, mOffset(0)
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(JoinNodeTransaction, EditTransactionBase,
mLeftNode,
@@ -33,17 +34,17 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(JoinN
mParent)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JoinNodeTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
nsresult
JoinNodeTransaction::CheckValidity()
{
- if (!mEditor.IsModifiableNode(mLeftNode->GetParentNode())) {
+ if (!mEditorBase.IsModifiableNode(mLeftNode->GetParentNode())) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
// After DoTransaction() and RedoTransaction(), the left node is removed from
// the content tree and right node remains.
NS_IMETHODIMP
@@ -59,17 +60,17 @@ JoinNodeTransaction::DoTransaction()
return NS_ERROR_INVALID_ARG;
}
// Set this instance's mParent. Other methods will see a non-null mParent
// and know all is well
mParent = leftParent;
mOffset = mLeftNode->Length();
- return mEditor.JoinNodesImpl(mRightNode, mLeftNode, mParent);
+ return mEditorBase.JoinNodesImpl(mRightNode, mLeftNode, mParent);
}
//XXX: What if instead of split, we just deleted the unneeded children of
// mRight and re-inserted mLeft?
NS_IMETHODIMP
JoinNodeTransaction::UndoTransaction()
{
MOZ_ASSERT(mParent);
--- a/editor/libeditor/JoinNodeTransaction.h
+++ b/editor/libeditor/JoinNodeTransaction.h
@@ -7,51 +7,52 @@
#define JoinNodeTransaction_h
#include "EditTransactionBase.h" // for EditTransactionBase, etc
#include "nsCOMPtr.h" // for nsCOMPtr
#include "nsCycleCollectionParticipant.h"
#include "nsID.h" // for REFNSIID
#include "nscore.h" // for NS_IMETHOD
-class nsEditor;
class nsINode;
namespace mozilla {
+class EditorBase;
+
/**
* A transaction that joins two nodes E1 (left node) and E2 (right node) into a
* single node E. The children of E are the children of E1 followed by the
* children of E2. After DoTransaction() and RedoTransaction(), E1 is removed
* from the content tree and E2 remains.
*/
class JoinNodeTransaction final : public EditTransactionBase
{
public:
/**
- * @param aEditor The provider of core editing operations.
+ * @param aEditorBase The provider of core editing operations.
* @param aLeftNode The first of two nodes to join.
* @param aRightNode The second of two nodes to join.
*/
- JoinNodeTransaction(nsEditor& aEditor,
+ JoinNodeTransaction(EditorBase& aEditorBase,
nsINode& aLeftNode, nsINode& aRightNode);
/**
* Call this after constructing to ensure the inputs are correct.
*/
nsresult CheckValidity();
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(JoinNodeTransaction,
EditTransactionBase)
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
NS_DECL_EDITTRANSACTIONBASE
protected:
- nsEditor& mEditor;
+ EditorBase& mEditorBase;
// The nodes to operate upon. After the merge, mRightNode remains and
// mLeftNode is removed from the content tree.
nsCOMPtr<nsINode> mLeftNode;
nsCOMPtr<nsINode> mRightNode;
// The offset into mNode where the children of mElement are split (for
// undo). mOffset is the index of the first child in the right node. -1
--- a/editor/libeditor/PlaceholderTransaction.cpp
+++ b/editor/libeditor/PlaceholderTransaction.cpp
@@ -1,31 +1,31 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "PlaceholderTransaction.h"
#include "CompositionTransaction.h"
+#include "mozilla/EditorBase.h"
#include "mozilla/dom/Selection.h"
-#include "nsEditor.h"
#include "nsGkAtoms.h"
#include "nsQueryObject.h"
namespace mozilla {
using namespace dom;
PlaceholderTransaction::PlaceholderTransaction()
: mAbsorb(true)
, mForwarding(nullptr)
, mCompositionTransaction(nullptr)
, mCommitted(false)
- , mEditor(nullptr)
+ , mEditorBase(nullptr)
{
}
PlaceholderTransaction::~PlaceholderTransaction()
{
}
NS_IMPL_CYCLE_COLLECTION_CLASS(PlaceholderTransaction)
@@ -52,23 +52,23 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
NS_INTERFACE_MAP_END_INHERITING(EditAggregateTransaction)
NS_IMPL_ADDREF_INHERITED(PlaceholderTransaction, EditAggregateTransaction)
NS_IMPL_RELEASE_INHERITED(PlaceholderTransaction, EditAggregateTransaction)
NS_IMETHODIMP
PlaceholderTransaction::Init(nsIAtom* aName,
SelectionState* aSelState,
- nsEditor* aEditor)
+ EditorBase* aEditorBase)
{
- NS_ENSURE_TRUE(aEditor && aSelState, NS_ERROR_NULL_POINTER);
+ NS_ENSURE_TRUE(aEditorBase && aSelState, NS_ERROR_NULL_POINTER);
mName = aName;
mStartSel = aSelState;
- mEditor = aEditor;
+ mEditorBase = aEditorBase;
return NS_OK;
}
NS_IMETHODIMP
PlaceholderTransaction::DoTransaction()
{
return NS_OK;
}
@@ -78,30 +78,30 @@ PlaceholderTransaction::UndoTransaction(
{
// Undo transactions.
nsresult rv = EditAggregateTransaction::UndoTransaction();
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(mStartSel, NS_ERROR_NULL_POINTER);
// now restore selection
- RefPtr<Selection> selection = mEditor->GetSelection();
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
return mStartSel->RestoreSelection(selection);
}
NS_IMETHODIMP
PlaceholderTransaction::RedoTransaction()
{
// Redo transactions.
nsresult rv = EditAggregateTransaction::RedoTransaction();
NS_ENSURE_SUCCESS(rv, rv);
// now restore selection
- RefPtr<Selection> selection = mEditor->GetSelection();
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
return mEndSel.RestoreSelection(selection);
}
NS_IMETHODIMP
PlaceholderTransaction::Merge(nsITransaction* aTransaction,
bool* aDidMerge)
@@ -260,15 +260,15 @@ PlaceholderTransaction::Commit()
{
mCommitted = true;
return NS_OK;
}
nsresult
PlaceholderTransaction::RememberEndingSelection()
{
- RefPtr<Selection> selection = mEditor->GetSelection();
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
mEndSel.SaveSelection(selection);
return NS_OK;
}
} // namespace mozilla
--- a/editor/libeditor/PlaceholderTransaction.h
+++ b/editor/libeditor/PlaceholderTransaction.h
@@ -42,17 +42,17 @@ public:
NS_DECL_EDITTRANSACTIONBASE
NS_IMETHOD RedoTransaction() override;
NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
// ------------ nsIAbsorbingTransaction -----------------------
NS_IMETHOD Init(nsIAtom* aName, SelectionState* aSelState,
- nsEditor* aEditor) override;
+ EditorBase* aEditorBase) override;
NS_IMETHOD GetTxnName(nsIAtom** aName) override;
NS_IMETHOD StartSelectionEquals(SelectionState* aSelState,
bool* aResult) override;
NS_IMETHOD EndPlaceHolderBatch() override;
@@ -79,14 +79,14 @@ protected:
// at the end. This is so that UndoTransaction() and RedoTransaction() can
// restore the selection properly.
// Use a pointer because this is constructed before we exist.
nsAutoPtr<SelectionState> mStartSel;
SelectionState mEndSel;
// The editor for this transaction.
- nsEditor* mEditor;
+ EditorBase* mEditorBase;
};
} // namespace mozilla
#endif // #ifndef PlaceholderTransaction_h
--- a/editor/libeditor/SelectionState.cpp
+++ b/editor/libeditor/SelectionState.cpp
@@ -6,17 +6,16 @@
#include "mozilla/SelectionState.h"
#include "EditorUtils.h" // for EditorUtils
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/dom/Selection.h" // for Selection
#include "nsAString.h" // for nsAString_internal::Length
#include "nsCycleCollectionParticipant.h"
#include "nsDebug.h" // for NS_ENSURE_TRUE, etc
-#include "nsEditor.h" // for nsEditor
#include "nsError.h" // for NS_OK, etc
#include "nsIContent.h" // for nsIContent
#include "nsIDOMCharacterData.h" // for nsIDOMCharacterData
#include "nsIDOMNode.h" // for nsIDOMNode
#include "nsISupportsImpl.h" // for nsRange::Release
#include "nsRange.h" // for nsRange
namespace mozilla {
--- a/editor/libeditor/SplitNodeTransaction.cpp
+++ b/editor/libeditor/SplitNodeTransaction.cpp
@@ -1,30 +1,30 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "SplitNodeTransaction.h"
+#include "mozilla/EditorBase.h" // for EditorBase
#include "mozilla/dom/Selection.h"
#include "nsAString.h"
#include "nsDebug.h" // for NS_ASSERTION, etc
-#include "nsEditor.h" // for nsEditor
#include "nsError.h" // for NS_ERROR_NOT_INITIALIZED, etc
#include "nsIContent.h" // for nsIContent
namespace mozilla {
using namespace dom;
-SplitNodeTransaction::SplitNodeTransaction(nsEditor& aEditor,
+SplitNodeTransaction::SplitNodeTransaction(EditorBase& aEditorBase,
nsIContent& aNode,
int32_t aOffset)
- : mEditor(aEditor)
+ : mEditorBase(aEditorBase)
, mExistingRightNode(&aNode)
, mOffset(aOffset)
{
}
SplitNodeTransaction::~SplitNodeTransaction()
{
}
@@ -43,39 +43,39 @@ SplitNodeTransaction::DoTransaction()
{
// Create a new node
ErrorResult rv;
// Don't use .downcast directly because AsContent has an assertion we want
nsCOMPtr<nsINode> clone = mExistingRightNode->CloneNode(false, rv);
NS_ASSERTION(!rv.Failed() && clone, "Could not create clone");
NS_ENSURE_TRUE(!rv.Failed() && clone, rv.StealNSResult());
mNewLeftNode = dont_AddRef(clone.forget().take()->AsContent());
- mEditor.MarkNodeDirty(mExistingRightNode->AsDOMNode());
+ mEditorBase.MarkNodeDirty(mExistingRightNode->AsDOMNode());
// Get the parent node
mParent = mExistingRightNode->GetParentNode();
NS_ENSURE_TRUE(mParent, NS_ERROR_NULL_POINTER);
// Insert the new node
- rv = mEditor.SplitNodeImpl(*mExistingRightNode, mOffset, *mNewLeftNode);
- if (mEditor.GetShouldTxnSetSelection()) {
- RefPtr<Selection> selection = mEditor.GetSelection();
+ rv = mEditorBase.SplitNodeImpl(*mExistingRightNode, mOffset, *mNewLeftNode);
+ if (mEditorBase.GetShouldTxnSetSelection()) {
+ RefPtr<Selection> selection = mEditorBase.GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
rv = selection->Collapse(mNewLeftNode, mOffset);
}
return rv.StealNSResult();
}
NS_IMETHODIMP
SplitNodeTransaction::UndoTransaction()
{
MOZ_ASSERT(mNewLeftNode && mParent);
// This assumes Do inserted the new node in front of the prior existing node
- return mEditor.JoinNodesImpl(mExistingRightNode, mNewLeftNode, mParent);
+ return mEditorBase.JoinNodesImpl(mExistingRightNode, mNewLeftNode, mParent);
}
/* Redo cannot simply resplit the right node, because subsequent transactions
* on the redo stack may depend on the left node existing in its previous
* state.
*/
NS_IMETHODIMP
SplitNodeTransaction::RedoTransaction()
--- a/editor/libeditor/SplitNodeTransaction.h
+++ b/editor/libeditor/SplitNodeTransaction.h
@@ -7,52 +7,54 @@
#define SplitNodeTransaction_h
#include "EditTransactionBase.h" // for EditTxn, etc
#include "nsCOMPtr.h" // for nsCOMPtr
#include "nsCycleCollectionParticipant.h"
#include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED
#include "nscore.h" // for NS_IMETHOD
-class nsEditor;
class nsIContent;
class nsINode;
namespace mozilla {
+class EditorBase;
+
/**
* A transaction that splits a node into two identical nodes, with the children
* divided between the new nodes.
*/
class SplitNodeTransaction final : public EditTransactionBase
{
public:
/**
- * @param aEditor The provider of core editing operations
- * @param aNode The node to split
- * @param aOffset The location within aNode to do the split. aOffset may
- * refer to children of aNode, or content of aNode. The left
- * node will have child|content 0..aOffset-1.
+ * @param aEditorBase The provider of core editing operations
+ * @param aNode The node to split
+ * @param aOffset The location within aNode to do the split. aOffset may
+ * refer to children of aNode, or content of aNode. The
+ * left node will have child|content 0..aOffset-1.
*/
- SplitNodeTransaction(nsEditor& aEditor, nsIContent& aNode, int32_t aOffset);
+ SplitNodeTransaction(EditorBase& aEditorBase, nsIContent& aNode,
+ int32_t aOffset);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitNodeTransaction,
EditTransactionBase)
NS_DECL_EDITTRANSACTIONBASE
NS_IMETHOD RedoTransaction() override;
nsIContent* GetNewNode();
protected:
virtual ~SplitNodeTransaction();
- nsEditor& mEditor;
+ EditorBase& mEditorBase;
// The node to operate upon.
nsCOMPtr<nsIContent> mExistingRightNode;
// The offset into mExistingRightNode where its children are split. mOffset
// is the index of the first child in the right node. -1 means the new node
// gets no children.
int32_t mOffset;
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -17,17 +17,16 @@
#include "mozilla/dom/Selection.h"
#include "nsAString.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsCRTGlue.h"
#include "nsComponentManagerUtils.h"
#include "nsContentUtils.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
#include "nsIContent.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMNode.h"
#include "nsIDOMNodeFilter.h"
@@ -456,34 +455,37 @@ TextEditRules::CollapseSelectionToTraili
res = nodeAsText->GetLength(&length);
NS_ENSURE_SUCCESS(res, res);
// nothing to do if we're not at the end of the text node
if (selOffset != int32_t(length))
return NS_OK;
int32_t parentOffset;
- nsCOMPtr<nsIDOMNode> parentNode = nsEditor::GetNodeLocation(selNode, &parentOffset);
+ nsCOMPtr<nsIDOMNode> parentNode =
+ EditorBase::GetNodeLocation(selNode, &parentOffset);
NS_ENSURE_STATE(mTextEditor);
nsCOMPtr<nsIDOMNode> root = do_QueryInterface(mTextEditor->GetRoot());
NS_ENSURE_TRUE(root, NS_ERROR_NULL_POINTER);
if (parentNode != root) return NS_OK;
nsCOMPtr<nsIDOMNode> nextNode = mTextEditor->GetChildAt(parentNode,
parentOffset + 1);
if (nextNode && TextEditUtils::IsMozBR(nextNode)) {
res = aSelection->Collapse(parentNode, parentOffset + 1);
NS_ENSURE_SUCCESS(res, res);
}
return res;
}
static inline already_AddRefed<nsIDOMNode>
-GetTextNode(Selection* selection, nsEditor* editor) {
+GetTextNode(Selection* selection,
+ EditorBase* editor)
+{
int32_t selOffset;
nsCOMPtr<nsIDOMNode> selNode;
nsresult res = editor->GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset);
NS_ENSURE_SUCCESS(res, nullptr);
if (!editor->IsTextNode(selNode)) {
// Get an nsINode from the nsIDOMNode
nsCOMPtr<nsINode> node = do_QueryInterface(selNode);
// if node is null, return it to indicate there's no text
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -1,19 +1,19 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef mozilla_TextEditRules_h
#define mozilla_TextEditRules_h
+#include "mozilla/EditorBase.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
-#include "nsEditor.h"
#include "nsIEditRules.h"
#include "nsIEditor.h"
#include "nsISupportsImpl.h"
#include "nsITimer.h"
#include "nsString.h"
#include "nscore.h"
class nsIDOMElement;
--- a/editor/libeditor/TextEditUtils.cpp
+++ b/editor/libeditor/TextEditUtils.cpp
@@ -7,17 +7,16 @@
#include "mozilla/Assertions.h"
#include "mozilla/TextEditor.h"
#include "mozilla/dom/Element.h"
#include "nsAString.h"
#include "nsCOMPtr.h"
#include "nsCaseTreatment.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
#include "nsIDOMElement.h"
#include "nsIDOMNode.h"
#include "nsNameSpaceManager.h"
#include "nsLiteralString.h"
#include "nsString.h"
@@ -28,26 +27,26 @@ namespace mozilla {
******************************************************************************/
/**
* IsBody() returns true if aNode is an html body node.
*/
bool
TextEditUtils::IsBody(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::body);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::body);
}
/**
* IsBreak() returns true if aNode is an html break node.
*/
bool
TextEditUtils::IsBreak(nsIDOMNode* aNode)
{
- return nsEditor::NodeIsType(aNode, nsGkAtoms::br);
+ return EditorBase::NodeIsType(aNode, nsGkAtoms::br);
}
bool
TextEditUtils::IsBreak(nsINode* aNode)
{
MOZ_ASSERT(aNode);
return aNode->IsHTMLElement(nsGkAtoms::br);
}
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -89,33 +89,33 @@ TextEditor::~TextEditor()
RemoveEventListeners();
if (mRules)
mRules->DetachEditor();
}
NS_IMPL_CYCLE_COLLECTION_CLASS(TextEditor)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TextEditor, nsEditor)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TextEditor, EditorBase)
if (tmp->mRules)
tmp->mRules->DetachEditor();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRules)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(TextEditor, nsEditor)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(TextEditor, EditorBase)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRules)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-NS_IMPL_ADDREF_INHERITED(TextEditor, nsEditor)
-NS_IMPL_RELEASE_INHERITED(TextEditor, nsEditor)
+NS_IMPL_ADDREF_INHERITED(TextEditor, EditorBase)
+NS_IMPL_RELEASE_INHERITED(TextEditor, EditorBase)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TextEditor)
NS_INTERFACE_MAP_ENTRY(nsIPlaintextEditor)
NS_INTERFACE_MAP_ENTRY(nsIEditorMailSupport)
-NS_INTERFACE_MAP_END_INHERITING(nsEditor)
+NS_INTERFACE_MAP_END_INHERITING(EditorBase)
NS_IMETHODIMP
TextEditor::Init(nsIDOMDocument* aDoc,
nsIContent* aRoot,
nsISelectionController* aSelCon,
uint32_t aFlags,
const nsAString& aInitialValue)
@@ -128,17 +128,17 @@ TextEditor::Init(nsIDOMDocument* aDoc,
mRules->DetachEditor();
}
{
// block to scope AutoEditInitRulesTrigger
AutoEditInitRulesTrigger rulesTrigger(this, rulesRes);
// Init the base editor
- res = nsEditor::Init(aDoc, aRoot, aSelCon, aFlags, aInitialValue);
+ res = EditorBase::Init(aDoc, aRoot, aSelCon, aFlags, aInitialValue);
}
NS_ENSURE_SUCCESS(rulesRes, rulesRes);
// mRules may not have been initialized yet, when this is called via
// HTMLEditor::Init.
if (mRules) {
mRules->SetInitialValue(aInitialValue);
@@ -210,17 +210,17 @@ TextEditor::EndEditorInit()
}
}
return res;
}
NS_IMETHODIMP
TextEditor::SetDocumentCharacterSet(const nsACString& characterSet)
{
- nsresult rv = nsEditor::SetDocumentCharacterSet(characterSet);
+ nsresult rv = EditorBase::SetDocumentCharacterSet(characterSet);
NS_ENSURE_SUCCESS(rv, rv);
// Update META charset element.
nsCOMPtr<nsIDOMDocument> domdoc = GetDOMDocument();
NS_ENSURE_TRUE(domdoc, NS_ERROR_NOT_INITIALIZED);
if (UpdateMetaCharset(domdoc, characterSet)) {
return NS_OK;
@@ -304,20 +304,20 @@ TextEditor::UpdateMetaCharset(nsIDOMDocu
if (!FindInReadable(charsetEquals, start, end,
nsCaseInsensitiveStringComparator())) {
continue;
}
// set attribute to <original prefix> charset=text/html
nsCOMPtr<nsIDOMElement> metaElement = do_QueryInterface(metaNode);
MOZ_ASSERT(metaElement);
- rv = nsEditor::SetAttribute(metaElement, NS_LITERAL_STRING("content"),
- Substring(originalStart, start) +
- charsetEquals +
- NS_ConvertASCIItoUTF16(aCharacterSet));
+ rv = EditorBase::SetAttribute(metaElement, NS_LITERAL_STRING("content"),
+ Substring(originalStart, start) +
+ charsetEquals +
+ NS_ConvertASCIItoUTF16(aCharacterSet));
return NS_SUCCEEDED(rv);
}
return false;
}
NS_IMETHODIMP
TextEditor::InitRules()
{
@@ -352,36 +352,36 @@ TextEditor::HandleKeyPressEvent(nsIDOMKe
// NOTE: When you change this method, you should also change:
// * editor/libeditor/tests/test_texteditor_keyevent_handling.html
// * editor/libeditor/tests/test_htmleditor_keyevent_handling.html
//
// And also when you add new key handling, you need to change the subclass's
// HandleKeyPressEvent()'s switch statement.
if (IsReadonly() || IsDisabled()) {
- // When we're not editable, the events handled on nsEditor.
- return nsEditor::HandleKeyPressEvent(aKeyEvent);
+ // When we're not editable, the events handled on EditorBase.
+ return EditorBase::HandleKeyPressEvent(aKeyEvent);
}
WidgetKeyboardEvent* nativeKeyEvent =
aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
NS_ENSURE_TRUE(nativeKeyEvent, NS_ERROR_UNEXPECTED);
NS_ASSERTION(nativeKeyEvent->mMessage == eKeyPress,
"HandleKeyPressEvent gets non-keypress event");
switch (nativeKeyEvent->mKeyCode) {
case NS_VK_META:
case NS_VK_WIN:
case NS_VK_SHIFT:
case NS_VK_CONTROL:
case NS_VK_ALT:
case NS_VK_BACK:
case NS_VK_DELETE:
- // These keys are handled on nsEditor
- return nsEditor::HandleKeyPressEvent(aKeyEvent);
+ // These keys are handled on EditorBase
+ return EditorBase::HandleKeyPressEvent(aKeyEvent);
case NS_VK_TAB: {
if (IsTabbable()) {
return NS_OK; // let it be used for focus switching
}
if (nativeKeyEvent->IsShift() || nativeKeyEvent->IsControl() ||
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() ||
nativeKeyEvent->IsOS()) {
@@ -839,17 +839,17 @@ TextEditor::BeginIMEComposition(WidgetCo
NS_ENSURE_TRUE(mRules, NS_ERROR_NULL_POINTER);
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
TextEditRules* textEditRules = static_cast<TextEditRules*>(mRules.get());
textEditRules->ResetIMETextPWBuf();
}
- return nsEditor::BeginIMEComposition(aEvent);
+ return EditorBase::BeginIMEComposition(aEvent);
}
nsresult
TextEditor::UpdateIMEComposition(nsIDOMEvent* aDOMTextEvent)
{
MOZ_ASSERT(aDOMTextEvent, "aDOMTextEvent must not be nullptr");
WidgetCompositionEvent* compositionChangeEvent =
@@ -1099,17 +1099,17 @@ TextEditor::Undo(uint32_t aCount)
TextRulesInfo ruleInfo(EditAction::undo);
RefPtr<Selection> selection = GetSelection();
bool cancel, handled;
nsresult result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (!cancel && NS_SUCCEEDED(result))
{
- result = nsEditor::Undo(aCount);
+ result = EditorBase::Undo(aCount);
result = mRules->DidDoAction(selection, &ruleInfo, result);
}
NotifyEditorObservers(eNotifyEditorObserversOfEnd);
return result;
}
NS_IMETHODIMP
@@ -1128,17 +1128,17 @@ TextEditor::Redo(uint32_t aCount)
TextRulesInfo ruleInfo(EditAction::redo);
RefPtr<Selection> selection = GetSelection();
bool cancel, handled;
nsresult result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (!cancel && NS_SUCCEEDED(result))
{
- result = nsEditor::Redo(aCount);
+ result = EditorBase::Redo(aCount);
result = mRules->DidDoAction(selection, &ruleInfo, result);
}
NotifyEditorObservers(eNotifyEditorObserversOfEnd);
return result;
}
bool
@@ -1547,17 +1547,17 @@ TextEditor::GetEmbeddedObjects(nsISuppor
*/
NS_IMETHODIMP
TextEditor::StartOperation(EditAction opID,
nsIEditor::EDirection aDirection)
{
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
- nsEditor::StartOperation(opID, aDirection); // will set mAction, mDirection
+ EditorBase::StartOperation(opID, aDirection); // will set mAction, mDirection
if (mRules) return mRules->BeforeEdit(mAction, mDirection);
return NS_OK;
}
/**
* All editor operations which alter the doc should be followed
* with a call to EndOperation.
*/
@@ -1565,17 +1565,17 @@ NS_IMETHODIMP
TextEditor::EndOperation()
{
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
// post processing
nsresult res = NS_OK;
if (mRules) res = mRules->AfterEdit(mAction, mDirection);
- nsEditor::EndOperation(); // will clear mAction, mDirection
+ EditorBase::EndOperation(); // will clear mAction, mDirection
return res;
}
nsresult
TextEditor::SelectEntireDocument(Selection* aSelection)
{
if (!aSelection || !mRules) { return NS_ERROR_NULL_POINTER; }
@@ -1590,17 +1590,17 @@ TextEditor::SelectEntireDocument(Selecti
nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(GetRoot());
NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
// if it's empty don't select entire doc - that would select the bogus node
return aSelection->Collapse(rootElement, 0);
}
SelectionBatcher selectionBatcher(aSelection);
- nsresult rv = nsEditor::SelectEntireDocument(aSelection);
+ nsresult rv = EditorBase::SelectEntireDocument(aSelection);
NS_ENSURE_SUCCESS(rv, rv);
// Don't select the trailing BR node if we have one
int32_t selOffset;
nsCOMPtr<nsIDOMNode> selNode;
rv = GetEndNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
NS_ENSURE_SUCCESS(rv, rv);
@@ -1625,20 +1625,20 @@ TextEditor::GetDOMEventTarget()
nsresult
TextEditor::SetAttributeOrEquivalent(nsIDOMElement* aElement,
const nsAString& aAttribute,
const nsAString& aValue,
bool aSuppressTransaction)
{
- return nsEditor::SetAttribute(aElement, aAttribute, aValue);
+ return EditorBase::SetAttribute(aElement, aAttribute, aValue);
}
nsresult
TextEditor::RemoveAttributeOrEquivalent(nsIDOMElement* aElement,
const nsAString& aAttribute,
bool aSuppressTransaction)
{
- return nsEditor::RemoveAttribute(aElement, aAttribute);
+ return EditorBase::RemoveAttribute(aElement, aAttribute);
}
} // namespace mozilla
--- a/editor/libeditor/TextEditor.h
+++ b/editor/libeditor/TextEditor.h
@@ -1,19 +1,19 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef mozilla_TextEditor_h
#define mozilla_TextEditor_h
+#include "mozilla/EditorBase.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
-#include "nsEditor.h"
#include "nsIEditor.h"
#include "nsIEditorMailSupport.h"
#include "nsIPlaintextEditor.h"
#include "nsISupportsImpl.h"
#include "nscore.h"
class nsIContent;
class nsIDOMDocument;
@@ -35,40 +35,40 @@ class TextEditRules;
namespace dom {
class Selection;
} // namespace dom
/**
* The text editor implementation.
* Use to edit text document represented as a DOM tree.
*/
-class TextEditor : public nsEditor
+class TextEditor : public EditorBase
, public nsIPlaintextEditor
, public nsIEditorMailSupport
{
public:
NS_DECL_ISUPPORTS_INHERITED
- NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextEditor, nsEditor)
+ NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextEditor, EditorBase)
enum ETypingAction
{
eTypedText, /* user typed text */
eTypedBR, /* user typed shift-enter to get a br */
eTypedBreak /* user typed enter */
};
TextEditor();
// nsIPlaintextEditor methods
NS_DECL_NSIPLAINTEXTEDITOR
// nsIEditorMailSupport overrides
NS_DECL_NSIEDITORMAILSUPPORT
- // Overrides of nsEditor interface methods
+ // Overrides of EditorBase interface methods
NS_IMETHOD SetAttributeOrEquivalent(nsIDOMElement* aElement,
const nsAString& aAttribute,
const nsAString& aValue,
bool aSuppressTransaction) override;
NS_IMETHOD RemoveAttributeOrEquivalent(nsIDOMElement* aElement,
const nsAString& aAttribute,
bool aSuppressTransaction) override;
--- a/editor/libeditor/TextEditorDataTransfer.cpp
+++ b/editor/libeditor/TextEditorDataTransfer.cpp
@@ -11,17 +11,16 @@
#include "mozilla/SelectionState.h"
#include "mozilla/dom/Selection.h"
#include "nsAString.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsComponentManagerUtils.h"
#include "nsContentUtils.h"
#include "nsDebug.h"
-#include "nsEditor.h"
#include "nsError.h"
#include "nsIClipboard.h"
#include "nsIContent.h"
#include "nsIDOMDataTransfer.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDragEvent.h"
#include "nsIDOMEvent.h"
#include "nsIDOMNode.h"
--- a/editor/libeditor/TypeInState.cpp
+++ b/editor/libeditor/TypeInState.cpp
@@ -2,22 +2,22 @@
/* 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/. */
#include "TypeInState.h"
#include <stddef.h>
+#include "nsError.h"
+#include "mozilla/EditorBase.h"
+#include "mozilla/mozalloc.h"
#include "mozilla/dom/Selection.h"
-#include "mozilla/mozalloc.h"
#include "nsAString.h"
#include "nsDebug.h"
-#include "nsEditor.h"
-#include "nsError.h"
#include "nsGkAtoms.h"
#include "nsIDOMNode.h"
#include "nsISupportsBase.h"
#include "nsISupportsImpl.h"
#include "nsReadableUtils.h"
#include "nsStringFwd.h"
class nsIAtom;
@@ -58,17 +58,19 @@ nsresult
TypeInState::UpdateSelState(Selection* aSelection)
{
NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
if (!aSelection->Collapsed()) {
return NS_OK;
}
- return nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(mLastSelectionContainer), &mLastSelectionOffset);
+ return EditorBase::GetStartNodeAndOffset(
+ aSelection, getter_AddRefs(mLastSelectionContainer),
+ &mLastSelectionOffset);
}
NS_IMETHODIMP
TypeInState::NotifySelectionChanged(nsIDOMDocument* aDOMDocument,
nsISelection* aSelection,
int16_t aReason)
{
@@ -87,18 +89,18 @@ TypeInState::NotifySelectionChanged(nsID
if (aSelection) {
int32_t rangeCount = selection->RangeCount();
if (selection->Collapsed() && rangeCount) {
nsCOMPtr<nsIDOMNode> selNode;
int32_t selOffset = 0;
nsresult result =
- nsEditor::GetStartNodeAndOffset(selection, getter_AddRefs(selNode),
- &selOffset);
+ EditorBase::GetStartNodeAndOffset(selection, getter_AddRefs(selNode),
+ &selOffset);
NS_ENSURE_SUCCESS(result, result);
if (selNode && selNode == mLastSelectionContainer && selOffset == mLastSelectionOffset)
{
// We got a bogus selection changed notification!
return NS_OK;
}
--- a/editor/libeditor/moz.build
+++ b/editor/libeditor/moz.build
@@ -9,21 +9,21 @@ MOCHITEST_MANIFESTS += [
'tests/mochitest.ini',
]
MOCHITEST_CHROME_MANIFESTS += ['tests/chrome.ini']
BROWSER_CHROME_MANIFESTS += ['tests/browser.ini']
EXPORTS += [
- 'nsEditor.h',
'nsIEditRules.h',
]
EXPORTS.mozilla += [
+ 'EditorBase.h',
'EditorController.h',
'HTMLEditor.h',
'SelectionState.h',
'TextEditor.h',
'TextEditRules.h',
]
UNIFIED_SOURCES += [
@@ -31,16 +31,17 @@ UNIFIED_SOURCES += [
'ChangeStyleTransaction.cpp',
'CompositionTransaction.cpp',
'CreateElementTransaction.cpp',
'CSSEditUtils.cpp',
'DeleteNodeTransaction.cpp',
'DeleteRangeTransaction.cpp',
'DeleteTextTransaction.cpp',
'EditAggregateTransaction.cpp',
+ 'EditorBase.cpp',
'EditorCommands.cpp',
'EditorController.cpp',
'EditorEventListener.cpp',
'EditorUtils.cpp',
'EditTransactionBase.cpp',
'HTMLAbsPositionEditor.cpp',
'HTMLAnonymousNodeEditor.cpp',
'HTMLEditor.cpp',
@@ -52,17 +53,16 @@ UNIFIED_SOURCES += [
'HTMLInlineTableEditor.cpp',
'HTMLStyleEditor.cpp',
'HTMLTableEditor.cpp',
'HTMLURIRefObject.cpp',
'InsertNodeTransaction.cpp',
'InsertTextTransaction.cpp',
'InternetCiter.cpp',
'JoinNodeTransaction.cpp',
- 'nsEditor.cpp',
'PlaceholderTransaction.cpp',
'SelectionState.cpp',
'SetDocumentTitleTransaction.cpp',
'SplitNodeTransaction.cpp',
'StyleSheetTransactions.cpp',
'TextEditor.cpp',
'TextEditorDataTransfer.cpp',
'TextEditorTest.cpp',
--- a/editor/libeditor/nsIAbsorbingTransaction.h
+++ b/editor/libeditor/nsIAbsorbingTransaction.h
@@ -17,30 +17,31 @@ Transaction interface to outside world
0xa6cf9116, \
0x15b3, \
0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
class nsIAtom;
namespace mozilla {
+class EditorBase;
class SelectionState;
} // namespace mozilla
/**
* A transaction interface mixin - for transactions that can support.
* the placeholder absorbtion idiom.
*/
class nsIAbsorbingTransaction : public nsISupports{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IABSORBINGTRANSACTION_IID)
NS_IMETHOD Init(nsIAtom* aName, mozilla::SelectionState* aSelState,
- nsEditor* aEditor) = 0;
+ mozilla::EditorBase* aEditorBase) = 0;
NS_IMETHOD EndPlaceHolderBatch()=0;
NS_IMETHOD GetTxnName(nsIAtom **aName)=0;
NS_IMETHOD StartSelectionEquals(mozilla::SelectionState* aSelState,
bool* aResult) = 0;
--- a/editor/libeditor/nsIEditRules.h
+++ b/editor/libeditor/nsIEditRules.h
@@ -5,17 +5,17 @@
#ifndef nsIEditRules_h
#define nsIEditRules_h
#define NS_IEDITRULES_IID \
{ 0x3836386d, 0x806a, 0x488d, \
{ 0x8b, 0xab, 0xaf, 0x42, 0xbb, 0x4c, 0x90, 0x66 } }
-#include "nsEditor.h" // for EditAction enum
+#include "mozilla/EditorBase.h" // for EditAction enum
namespace mozilla {
class TextEditor;
namespace dom {
class Selection;
} // namespace dom
--- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp
@@ -28,16 +28,17 @@
* something changed that we need to check on navigation. Navigation events
* tend to be a little tricky because we want to check the current word on
* exit if something has changed. If we navigate inside the word, we don't want
* to do anything. As a result, this flag is cleared in FinishNavigationEvent
* when we know that we are checking as a result of navigation.
*/
#include "EditorUtils.h"
+#include "mozilla/EditorBase.h"
#include "mozilla/Services.h"
#include "mozilla/dom/Selection.h"
#include "mozInlineSpellChecker.h"
#include "mozInlineSpellWordUtil.h"
#include "mozISpellI18NManager.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsIDOMNode.h"
@@ -61,17 +62,16 @@
#include "nsIServiceManager.h"
#include "nsITextServicesFilter.h"
#include "nsString.h"
#include "nsThreadUtils.h"
#include "nsUnicharUtils.h"
#include "nsIContent.h"
#include "nsRange.h"
#include "nsContentUtils.h"
-#include "nsEditor.h"
#include "nsIObserverService.h"
#include "nsITextControlElement.h"
#include "prtime.h"
using namespace mozilla;
using namespace mozilla::dom;
// Set to spew messages to the console about what is happening.
--- a/extensions/spellcheck/src/mozInlineSpellChecker.h
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.h
@@ -1,23 +1,23 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef __mozinlinespellchecker_h__
#define __mozinlinespellchecker_h__
+#include "mozilla/EditorBase.h"
#include "nsRange.h"
#include "nsIEditorSpellCheck.h"
#include "nsIEditActionListener.h"
#include "nsIInlineSpellChecker.h"
#include "nsIDOMTreeWalker.h"
#include "nsWeakReference.h"
-#include "nsEditor.h"
#include "nsIDOMEventListener.h"
#include "nsWeakReference.h"
#include "mozISpellI18NUtil.h"
#include "nsCycleCollectionParticipant.h"
// X.h defines KeyPress
#ifdef KeyPress
#undef KeyPress
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -7611,17 +7611,17 @@ nsLayoutUtils::GetEditableRootContentByC
// If the document is in designMode we should return nullptr.
if (!aDocument || aDocument->HasFlag(NODE_IS_EDITABLE)) {
return nullptr;
}
// contenteditable only works with HTML document.
// Note: Use nsIDOMHTMLDocument rather than nsIHTMLDocument for getting the
// body node because nsIDOMHTMLDocument::GetBody() does something
- // additional work for some cases and nsEditor uses them.
+ // additional work for some cases and EditorBase uses them.
nsCOMPtr<nsIDOMHTMLDocument> domHTMLDoc = do_QueryInterface(aDocument);
if (!domHTMLDoc) {
return nullptr;
}
Element* rootElement = aDocument->GetRootElement();
if (rootElement && rootElement->IsEditable()) {
return rootElement;
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -131,17 +131,16 @@ using mozilla::dom::PushNotifier;
{ 0x2fc2d3e3, 0x020f, 0x404e, { 0xb0, 0x6a, 0x6e, 0xcf, 0x3e, 0xa2, 0x33, 0x4a } }
#endif
#include "AudioChannelAgent.h"
using mozilla::dom::AudioChannelAgent;
// Editor stuff
#include "nsEditorCID.h"
-#include "nsEditor.h"
#include "mozilla/EditorController.h" //CID
#include "mozilla/HTMLEditor.h"
#include "nsTextServicesDocument.h"
#include "nsTextServicesCID.h"
#include "nsScriptSecurityManager.h"
#include "nsPrincipal.h"
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -252,18 +252,18 @@ ModifierKeyState::Update()
EnsureAltGr();
}
void
ModifierKeyState::Unset(Modifiers aRemovingModifiers)
{
mModifiers &= ~aRemovingModifiers;
// Note that we don't need to unset AltGr flag here automatically.
- // For nsEditor, we need to remove Alt and Control flags but AltGr isn't
- // checked in nsEditor, so, it can be kept.
+ // For EditorBase, we need to remove Alt and Control flags but AltGr isn't
+ // checked in EditorBase, so, it can be kept.
}
void
ModifierKeyState::Set(Modifiers aAddingModifiers)
{
mModifiers |= aAddingModifiers;
EnsureAltGr();
}
@@ -578,17 +578,17 @@ VirtualKey::GetUniChars(ShiftState aShif
result.FillModifiers(ShiftStateToModifiers(aShiftState));
return result;
}
if ((aShiftState & STATE_ALT_CONTROL) == STATE_ALT_CONTROL) {
// Even if the shifted chars and the unshifted chars are same, we
// should consume the Alt key state and the Ctrl key state when
// AltGr key is pressed. Because if we don't consume them, the input
- // events are ignored on nsEditor. (I.e., Users cannot input the
+ // events are ignored on EditorBase. (I.e., Users cannot input the
// characters with this key combination.)
Modifiers finalModifiers = ShiftStateToModifiers(aShiftState);
finalModifiers &= ~(MODIFIER_ALT | MODIFIER_CONTROL);
result.FillModifiers(finalModifiers);
return result;
}
UniCharsAndModifiers unmodifiedReslt =
@@ -1694,17 +1694,17 @@ NativeKey::HandleCharMessage(const MSG&
keypressEvent.mKeyCode = mDOMKeyCode;
}
nsresult rv = mDispatcher->BeginNativeInputTransaction();
if (NS_WARN_IF(NS_FAILED(rv))) {
return true;
}
// When AltGr (Alt+Ctrl) is pressed, that causes normal text input.
- // At this time, if either alt or ctrl flag is set, nsEditor ignores the
+ // At this time, if either alt or ctrl flag is set, EditorBase ignores the
// keypress event. For avoiding this issue, we should remove ctrl and alt
// flags.
ModifierKeyState modKeyState(mModKeyState);
modKeyState.Unset(MODIFIER_ALT | MODIFIER_CONTROL);
nsEventStatus status = InitKeyEvent(keypressEvent, modKeyState, &aCharMsg);
bool dispatched =
mDispatcher->MaybeDispatchKeypressEvents(keypressEvent, status,
const_cast<NativeKey*>(this));