Bug 1086349 part 1 - Clean up JoinNodeTxn; r=ehsan

--HG--
rename : editor/libeditor/JoinElementTxn.cpp => editor/libeditor/JoinNodeTxn.cpp
rename : editor/libeditor/JoinElementTxn.h => editor/libeditor/JoinNodeTxn.h
This commit is contained in:
Aryeh Gregor 2014-11-02 14:04:12 +02:00
parent caba4af942
commit c496773550
11 changed files with 240 additions and 274 deletions

View File

@ -1,120 +0,0 @@
/* -*- 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 <stdio.h> // for printf
#include "JoinElementTxn.h"
#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 "nsISupportsImpl.h" // for EditTxn::QueryInterface, etc
using namespace mozilla;
JoinElementTxn::JoinElementTxn()
: EditTxn()
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(JoinElementTxn, EditTxn,
mLeftNode,
mRightNode,
mParent)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JoinElementTxn)
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
NS_IMETHODIMP JoinElementTxn::Init(nsEditor *aEditor,
nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode)
{
NS_PRECONDITION((aEditor && aLeftNode && aRightNode), "null arg");
if (!aEditor || !aLeftNode || !aRightNode) { return NS_ERROR_NULL_POINTER; }
mEditor = aEditor;
mLeftNode = do_QueryInterface(aLeftNode);
nsCOMPtr<nsIDOMNode>leftParent;
nsresult result = mLeftNode->GetParentNode(getter_AddRefs(leftParent));
NS_ENSURE_SUCCESS(result, result);
if (!mEditor->IsModifiableNode(leftParent)) {
return NS_ERROR_FAILURE;
}
mRightNode = do_QueryInterface(aRightNode);
mOffset = 0;
return NS_OK;
}
// After DoTransaction() and RedoTransaction(), the left node is removed from the content tree and right node remains.
NS_IMETHODIMP JoinElementTxn::DoTransaction(void)
{
NS_PRECONDITION((mEditor && mLeftNode && mRightNode), "null arg");
if (!mEditor || !mLeftNode || !mRightNode) { return NS_ERROR_NOT_INITIALIZED; }
// get the parent node
nsCOMPtr<nsINode> leftNode = do_QueryInterface(mLeftNode);
nsCOMPtr<nsINode> leftParent = leftNode->GetParentNode();
NS_ENSURE_TRUE(leftParent, NS_ERROR_NULL_POINTER);
// verify that mLeftNode and mRightNode have the same parent
nsCOMPtr<nsINode> rightNode = do_QueryInterface(mRightNode);
nsCOMPtr<nsINode> rightParent = rightNode->GetParentNode();
NS_ENSURE_TRUE(rightParent, NS_ERROR_NULL_POINTER);
if (leftParent != rightParent) {
NS_ASSERTION(false, "2 nodes do not have same parent");
return NS_ERROR_INVALID_ARG;
}
// set this instance mParent.
// Other methods will see a non-null mParent and know all is well
mParent = leftParent->AsDOMNode();
mOffset = leftNode->Length();
nsCOMPtr<nsINode> parent = do_QueryInterface(mParent);
return mEditor->JoinNodesImpl(rightNode, leftNode, parent);
}
//XXX: what if instead of split, we just deleted the unneeded children of mRight
// and re-inserted mLeft?
NS_IMETHODIMP JoinElementTxn::UndoTransaction(void)
{
NS_ASSERTION(mRightNode && mLeftNode && mParent, "bad state");
if (!mRightNode || !mLeftNode || !mParent) { return NS_ERROR_NOT_INITIALIZED; }
// first, massage the existing node so it is in its post-split state
nsresult result;
nsCOMPtr<nsIDOMNode>resultNode;
nsCOMPtr<nsIDOMCharacterData>rightNodeAsText = do_QueryInterface(mRightNode);
if (rightNodeAsText)
{
result = rightNodeAsText->DeleteData(0, mOffset);
}
else
{
nsCOMPtr<nsIDOMNode>child;
result = mRightNode->GetFirstChild(getter_AddRefs(child));
nsCOMPtr<nsIDOMNode>nextSibling;
uint32_t i;
for (i=0; i<mOffset; i++)
{
if (NS_FAILED(result)) {return result;}
if (!child) {return NS_ERROR_NULL_POINTER;}
child->GetNextSibling(getter_AddRefs(nextSibling));
result = mLeftNode->AppendChild(child, getter_AddRefs(resultNode));
child = do_QueryInterface(nextSibling);
}
}
// second, re-insert the left node into the tree
result = mParent->InsertBefore(mLeftNode, mRightNode, getter_AddRefs(resultNode));
return result;
}
NS_IMETHODIMP JoinElementTxn::GetTxnDescription(nsAString& aString)
{
aString.AssignLiteral("JoinElementTxn");
return NS_OK;
}

View File

@ -1,63 +0,0 @@
/* -*- 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 JoinElementTxn_h__
#define JoinElementTxn_h__
#include "EditTxn.h" // for EditTxn, NS_DECL_EDITTXN
#include "nsCOMPtr.h" // for nsCOMPtr
#include "nsCycleCollectionParticipant.h"
#include "nsID.h" // for REFNSIID
#include "nsIDOMNode.h" // for nsIDOMNode
#include "nscore.h" // for NS_IMETHOD
class nsEditor;
/**
* A transaction that joins two elements 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 JoinElementTxn : public EditTxn
{
public:
/** initialize the transaction
* @param aEditor the provider of core editing operations
* @param aLeftNode the first of two nodes to join
* @param aRightNode the second of two nodes to join
*/
NS_IMETHOD Init(nsEditor *aEditor,
nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode);
JoinElementTxn();
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(JoinElementTxn, EditTxn)
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_DECL_EDITTXN
protected:
/** the elements to operate upon.
* After the merge, mRightNode remains and mLeftNode is removed from the content tree.
*/
nsCOMPtr<nsIDOMNode> mLeftNode;
nsCOMPtr<nsIDOMNode> mRightNode;
/** the offset into mNode where the children of mElement are split (for undo).<BR>
* mOffset is the index of the first child in the right node.
* -1 means the left node had no children.
*/
uint32_t mOffset;
/** the parent node containing mLeftNode and mRightNode */
nsCOMPtr<nsIDOMNode> mParent;
nsEditor* mEditor;
};
#endif

View File

@ -0,0 +1,107 @@
/* -*- 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 <stdio.h> // for printf
#include "JoinNodeTxn.h"
#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 "nsISupportsImpl.h" // for EditTxn::QueryInterface, etc
using namespace mozilla;
using namespace mozilla::dom;
JoinNodeTxn::JoinNodeTxn(nsEditor& aEditor, nsINode& aLeftNode,
nsINode& aRightNode)
: EditTxn()
, mEditor(aEditor)
, mLeftNode(&aLeftNode)
, mRightNode(&aRightNode)
, mOffset(0)
, mParent(nullptr)
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(JoinNodeTxn, EditTxn,
mLeftNode,
mRightNode,
mParent)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JoinNodeTxn)
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
nsresult
JoinNodeTxn::CheckValidity()
{
if (!mEditor.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
JoinNodeTxn::DoTransaction()
{
// Get the parent node
nsCOMPtr<nsINode> leftParent = mLeftNode->GetParentNode();
NS_ENSURE_TRUE(leftParent, NS_ERROR_NULL_POINTER);
// Verify that mLeftNode and mRightNode have the same parent
if (leftParent != mRightNode->GetParentNode()) {
NS_ASSERTION(false, "Nodes do not have same parent");
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);
}
//XXX: What if instead of split, we just deleted the unneeded children of
// mRight and re-inserted mLeft?
NS_IMETHODIMP
JoinNodeTxn::UndoTransaction()
{
MOZ_ASSERT(mParent);
// First, massage the existing node so it is in its post-split state
ErrorResult rv;
if (mRightNode->GetAsText()) {
rv = mRightNode->GetAsText()->DeleteData(0, mOffset);
} else {
nsCOMPtr<nsIContent> child = mRightNode->GetFirstChild();
for (uint32_t i = 0; i < mOffset; i++) {
if (rv.Failed()) {
return rv.ErrorCode();
}
if (!child) {
return NS_ERROR_NULL_POINTER;
}
nsCOMPtr<nsIContent> nextSibling = child->GetNextSibling();
mLeftNode->AppendChild(*child, rv);
child = nextSibling;
}
}
// Second, re-insert the left node into the tree
mParent->InsertBefore(*mLeftNode, mRightNode, rv);
return rv.ErrorCode();
}
NS_IMETHODIMP
JoinNodeTxn::GetTxnDescription(nsAString& aString)
{
aString.AssignLiteral("JoinNodeTxn");
return NS_OK;
}

View File

@ -0,0 +1,66 @@
/* -*- 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 JoinNodeTxn_h__
#define JoinNodeTxn_h__
#include "EditTxn.h" // for EditTxn, NS_DECL_EDITTXN
#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 {
namespace dom {
/**
* 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 JoinNodeTxn : public EditTxn
{
public:
/** @param aEditor the provider of core editing operations
* @param aLeftNode the first of two nodes to join
* @param aRightNode the second of two nodes to join
*/
JoinNodeTxn(nsEditor& aEditor, nsINode& aLeftNode, nsINode& aRightNode);
/* Call this after constructing to ensure the inputs are correct */
nsresult CheckValidity();
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(JoinNodeTxn, EditTxn)
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_DECL_EDITTXN
protected:
nsEditor& mEditor;
/** 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
* means the left node had no children.
*/
uint32_t mOffset;
/** The parent node containing mLeftNode and mRightNode */
nsCOMPtr<nsINode> mParent;
};
}
}
#endif

View File

@ -23,7 +23,7 @@ UNIFIED_SOURCES += [
'IMETextTxn.cpp',
'InsertNodeTxn.cpp',
'InsertTextTxn.cpp',
'JoinElementTxn.cpp',
'JoinNodeTxn.cpp',
'nsEditor.cpp',
'nsEditorCommands.cpp',
'nsEditorController.cpp',

View File

@ -18,7 +18,7 @@
#include "IMETextTxn.h" // for IMETextTxn
#include "InsertNodeTxn.h" // for InsertNodeTxn
#include "InsertTextTxn.h" // for InsertTextTxn
#include "JoinElementTxn.h" // for JoinElementTxn
#include "JoinNodeTxn.h" // for JoinNodeTxn
#include "PlaceholderTxn.h" // for PlaceholderTxn
#include "SplitElementTxn.h" // for SplitElementTxn
#include "mozFlushType.h" // for mozFlushType::Flush_Frames
@ -1456,49 +1456,52 @@ nsEditor::SplitNode(nsIDOMNode * aNode,
}
nsresult
nsEditor::JoinNodes(nsINode* aNodeToKeep, nsIContent* aNodeToMove)
NS_IMETHODIMP
nsEditor::JoinNodes(nsIDOMNode* aLeftNode,
nsIDOMNode* aRightNode,
nsIDOMNode*)
{
// We don't really need aNodeToMove's parent to be non-null -- we could just
// skip adjusting any ranges in aNodeToMove's parent if there is none. But
// the current implementation requires it.
MOZ_ASSERT(aNodeToKeep && aNodeToMove && aNodeToMove->GetParentNode());
nsresult res = JoinNodes(aNodeToKeep->AsDOMNode(), aNodeToMove->AsDOMNode(),
aNodeToMove->GetParentNode()->AsDOMNode());
NS_ASSERTION(NS_SUCCEEDED(res), "JoinNodes failed");
NS_ENSURE_SUCCESS(res, res);
return NS_OK;
nsCOMPtr<nsINode> leftNode = do_QueryInterface(aLeftNode);
nsCOMPtr<nsINode> rightNode = do_QueryInterface(aRightNode);
NS_ENSURE_STATE(leftNode && rightNode && leftNode->GetParentNode());
return JoinNodes(*leftNode, *rightNode);
}
NS_IMETHODIMP
nsEditor::JoinNodes(nsIDOMNode * aLeftNode,
nsIDOMNode * aRightNode,
nsIDOMNode * aParent)
nsresult
nsEditor::JoinNodes(nsINode& aLeftNode, nsINode& aRightNode)
{
int32_t i;
nsAutoRules beginRulesSniffing(this, EditAction::joinNode, nsIEditor::ePrevious);
nsCOMPtr<nsINode> parent = aLeftNode.GetParentNode();
MOZ_ASSERT(parent);
// remember some values; later used for saved selection updating.
// find the offset between the nodes to be joined.
int32_t offset = GetChildOffset(aRightNode, aParent);
// find the number of children of the lefthand node
uint32_t oldLeftNodeLen;
nsresult result = GetLengthOfDOMNode(aLeftNode, oldLeftNodeLen);
NS_ENSURE_SUCCESS(result, result);
nsAutoRules beginRulesSniffing(this, EditAction::joinNode,
nsIEditor::ePrevious);
for (i = 0; i < mActionListeners.Count(); i++)
mActionListeners[i]->WillJoinNodes(aLeftNode, aRightNode, aParent);
// Remember some values; later used for saved selection updating.
// Find the offset between the nodes to be joined.
int32_t offset = parent->IndexOf(&aRightNode);
// Find the number of children of the lefthand node
uint32_t oldLeftNodeLen = aLeftNode.Length();
nsRefPtr<JoinElementTxn> txn;
result = CreateTxnForJoinNode(aLeftNode, aRightNode, getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = DoTransaction(txn);
for (int32_t i = 0; i < mActionListeners.Count(); i++) {
mActionListeners[i]->WillJoinNodes(aLeftNode.AsDOMNode(),
aRightNode.AsDOMNode(),
parent->AsDOMNode());
}
mRangeUpdater.SelAdjJoinNodes(aLeftNode, aRightNode, aParent, offset, (int32_t)oldLeftNodeLen);
for (i = 0; i < mActionListeners.Count(); i++)
mActionListeners[i]->DidJoinNodes(aLeftNode, aRightNode, aParent, result);
nsresult result;
nsRefPtr<JoinNodeTxn> txn = CreateTxnForJoinNode(aLeftNode, aRightNode);
if (txn) {
result = DoTransaction(txn);
}
mRangeUpdater.SelAdjJoinNodes(aLeftNode, aRightNode, *parent, offset,
(int32_t)oldLeftNodeLen);
for (int32_t i = 0; i < mActionListeners.Count(); i++) {
mActionListeners[i]->DidJoinNodes(aLeftNode.AsDOMNode(),
aRightNode.AsDOMNode(),
parent->AsDOMNode(), result);
}
return result;
}
@ -2594,21 +2597,14 @@ NS_IMETHODIMP nsEditor::CreateTxnForSplitNode(nsIDOMNode *aNode,
return rv;
}
NS_IMETHODIMP nsEditor::CreateTxnForJoinNode(nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode,
JoinElementTxn **aTxn)
already_AddRefed<JoinNodeTxn>
nsEditor::CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode)
{
NS_ENSURE_TRUE(aLeftNode && aRightNode, NS_ERROR_NULL_POINTER);
nsRefPtr<JoinNodeTxn> txn = new JoinNodeTxn(*this, aLeftNode, aRightNode);
nsRefPtr<JoinElementTxn> txn = new JoinElementTxn();
NS_ENSURE_SUCCESS(txn->CheckValidity(), nullptr);
nsresult rv = txn->Init(this, aLeftNode, aRightNode);
if (NS_SUCCEEDED(rv))
{
txn.forget(aTxn);
}
return rv;
return txn.forget();
}

View File

@ -30,7 +30,6 @@
class AddStyleSheetTxn;
class DeleteNodeTxn;
class EditAggregateTxn;
class JoinElementTxn;
class RemoveStyleSheetTxn;
class SplitElementTxn;
class nsIAtom;
@ -75,6 +74,7 @@ class EventTarget;
class IMETextTxn;
class InsertTextTxn;
class InsertNodeTxn;
class JoinNodeTxn;
class Selection;
class Text;
} // namespace dom
@ -234,7 +234,7 @@ public:
nsIAtom* aNodeType,
nsIAtom* aAttribute = nullptr,
const nsAString* aValue = nullptr);
nsresult JoinNodes(nsINode* aNodeToKeep, nsIContent* aNodeToMove);
nsresult JoinNodes(nsINode& aLeftNode, nsINode& aRightNode);
nsresult MoveNode(nsIContent* aNode, nsINode* aParent, int32_t aOffset);
/* Method to replace certain CreateElementNS() calls.
@ -341,9 +341,8 @@ protected:
uint32_t aOffset,
SplitElementTxn **aTxn);
NS_IMETHOD CreateTxnForJoinNode(nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode,
JoinElementTxn **aTxn);
already_AddRefed<mozilla::dom::JoinNodeTxn>
CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode);
/**
* This method first deletes the selection, if it's not collapsed. Then if

View File

@ -7544,7 +7544,7 @@ nsHTMLEditRules::JoinNodesSmart( nsIDOMNode *aNodeLeft,
{
// for list's, merge shallow (wouldn't want to combine list items)
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->JoinNodes(nodeLeft, nodeRight);
res = mHTMLEditor->JoinNodes(*nodeLeft, *nodeRight);
NS_ENSURE_SUCCESS(res, res);
return res;
}
@ -7561,7 +7561,7 @@ nsHTMLEditRules::JoinNodesSmart( nsIDOMNode *aNodeLeft,
// for list items, divs, etc, merge smart
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->JoinNodes(nodeLeft, nodeRight);
res = mHTMLEditor->JoinNodes(*nodeLeft, *nodeRight);
NS_ENSURE_SUCCESS(res, res);
if (lastLeft && firstRight && mHTMLEditor &&

View File

@ -446,7 +446,7 @@ nsHTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent* aNode,
res = MoveNode(aNode, previousSibling, -1);
NS_ENSURE_SUCCESS(res, res);
if (IsSimpleModifiableNode(nextSibling, aProperty, aAttribute, aValue)) {
res = JoinNodes(previousSibling, nextSibling);
res = JoinNodes(*previousSibling, *nextSibling);
NS_ENSURE_SUCCESS(res, res);
}
return NS_OK;

View File

@ -374,9 +374,9 @@ nsRangeUpdater::SelAdjSplitNode(nsIDOMNode* aOldRightNode, int32_t aOffset,
nsresult
nsRangeUpdater::SelAdjJoinNodes(nsINode* aLeftNode,
nsINode* aRightNode,
nsINode* aParent,
nsRangeUpdater::SelAdjJoinNodes(nsINode& aLeftNode,
nsINode& aRightNode,
nsINode& aParent,
int32_t aOffset,
int32_t aOldLeftNodeLength)
{
@ -384,7 +384,6 @@ nsRangeUpdater::SelAdjJoinNodes(nsINode* aLeftNode,
// lock set by Will/DidReplaceParent, etc...
return NS_OK;
}
NS_ENSURE_TRUE(aLeftNode && aRightNode && aParent, NS_ERROR_NULL_POINTER);
uint32_t count = mArray.Length();
if (!count) {
return NS_OK;
@ -394,57 +393,44 @@ nsRangeUpdater::SelAdjJoinNodes(nsINode* aLeftNode,
nsRangeStore* item = mArray[i];
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
if (item->startNode == aParent) {
if (item->startNode == &aParent) {
// adjust start point in aParent
if (item->startOffset > aOffset) {
item->startOffset--;
} else if (item->startOffset == aOffset) {
// join keeps right hand node
item->startNode = aRightNode;
item->startNode = &aRightNode;
item->startOffset = aOldLeftNodeLength;
}
} else if (item->startNode == aRightNode) {
} else if (item->startNode == &aRightNode) {
// adjust start point in aRightNode
item->startOffset += aOldLeftNodeLength;
} else if (item->startNode == aLeftNode) {
} else if (item->startNode == &aLeftNode) {
// adjust start point in aLeftNode
item->startNode = aRightNode;
item->startNode = &aRightNode;
}
if (item->endNode == aParent) {
if (item->endNode == &aParent) {
// adjust end point in aParent
if (item->endOffset > aOffset) {
item->endOffset--;
} else if (item->endOffset == aOffset) {
// join keeps right hand node
item->endNode = aRightNode;
item->endNode = &aRightNode;
item->endOffset = aOldLeftNodeLength;
}
} else if (item->endNode == aRightNode) {
} else if (item->endNode == &aRightNode) {
// adjust end point in aRightNode
item->endOffset += aOldLeftNodeLength;
} else if (item->endNode == aLeftNode) {
} else if (item->endNode == &aLeftNode) {
// adjust end point in aLeftNode
item->endNode = aRightNode;
item->endNode = &aRightNode;
}
}
return NS_OK;
}
nsresult
nsRangeUpdater::SelAdjJoinNodes(nsIDOMNode* aLeftNode,
nsIDOMNode* aRightNode,
nsIDOMNode* aParent,
int32_t aOffset,
int32_t aOldLeftNodeLength)
{
nsCOMPtr<nsINode> leftNode = do_QueryInterface(aLeftNode);
nsCOMPtr<nsINode> rightNode = do_QueryInterface(aRightNode);
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
return SelAdjJoinNodes(leftNode, rightNode, parent, aOffset, aOldLeftNodeLength);
}
void
nsRangeUpdater::SelAdjInsertText(Text& aTextNode, int32_t aOffset,

View File

@ -99,14 +99,9 @@ class nsRangeUpdater
nsresult SelAdjSplitNode(nsINode* aOldRightNode, int32_t aOffset,
nsINode* aNewLeftNode);
nsresult SelAdjSplitNode(nsIDOMNode *aOldRightNode, int32_t aOffset, nsIDOMNode *aNewLeftNode);
nsresult SelAdjJoinNodes(nsINode* aLeftNode,
nsINode* aRightNode,
nsINode* aParent,
int32_t aOffset,
int32_t aOldLeftNodeLength);
nsresult SelAdjJoinNodes(nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode,
nsIDOMNode *aParent,
nsresult SelAdjJoinNodes(nsINode& aLeftNode,
nsINode& aRightNode,
nsINode& aParent,
int32_t aOffset,
int32_t aOldLeftNodeLength);
void SelAdjInsertText(mozilla::dom::Text& aTextNode, int32_t aOffset,