mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1086349 part 2 - Clean up SplitNodeTxn; r=ehsan
--HG-- rename : editor/libeditor/SplitElementTxn.cpp => editor/libeditor/SplitNodeTxn.cpp rename : editor/libeditor/SplitElementTxn.h => editor/libeditor/SplitNodeTxn.h
This commit is contained in:
parent
733493f6c6
commit
b30e151b26
@ -1,161 +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 "SplitElementTxn.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
|
||||
#include "nsIDOMCharacterData.h" // for nsIDOMCharacterData
|
||||
#include "nsIEditor.h" // for nsEditor::DebugDumpContent, etc
|
||||
#include "nsISelection.h" // for nsISelection
|
||||
#include "nsISupportsUtils.h" // for NS_ADDREF
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
// note that aEditor is not refcounted
|
||||
SplitElementTxn::SplitElementTxn()
|
||||
: EditTxn()
|
||||
{
|
||||
}
|
||||
|
||||
SplitElementTxn::~SplitElementTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(SplitElementTxn, EditTxn,
|
||||
mParent,
|
||||
mNewLeftNode)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(SplitElementTxn, EditTxn)
|
||||
NS_IMPL_RELEASE_INHERITED(SplitElementTxn, EditTxn)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SplitElementTxn)
|
||||
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::Init(nsEditor *aEditor,
|
||||
nsIDOMNode *aNode,
|
||||
int32_t aOffset)
|
||||
{
|
||||
NS_ASSERTION(aEditor && aNode, "bad args");
|
||||
if (!aEditor || !aNode) { return NS_ERROR_NOT_INITIALIZED; }
|
||||
|
||||
mEditor = aEditor;
|
||||
mExistingRightNode = do_QueryInterface(aNode);
|
||||
mOffset = aOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::DoTransaction(void)
|
||||
{
|
||||
NS_ASSERTION(mExistingRightNode && mEditor, "bad state");
|
||||
if (!mExistingRightNode || !mEditor) { return NS_ERROR_NOT_INITIALIZED; }
|
||||
|
||||
// create a new node
|
||||
nsresult result = mExistingRightNode->CloneNode(false, 1, getter_AddRefs(mNewLeftNode));
|
||||
NS_ASSERTION(((NS_SUCCEEDED(result)) && (mNewLeftNode)), "could not create element.");
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
mEditor->MarkNodeDirty(mExistingRightNode);
|
||||
|
||||
// get the parent node
|
||||
result = mExistingRightNode->GetParentNode(getter_AddRefs(mParent));
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
NS_ENSURE_TRUE(mParent, NS_ERROR_NULL_POINTER);
|
||||
|
||||
// insert the new node
|
||||
result = mEditor->SplitNodeImpl(mExistingRightNode, mOffset, mNewLeftNode, mParent);
|
||||
if (mNewLeftNode) {
|
||||
bool bAdjustSelection;
|
||||
mEditor->ShouldTxnSetSelection(&bAdjustSelection);
|
||||
if (bAdjustSelection)
|
||||
{
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||
result = selection->Collapse(mNewLeftNode, mOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
// do nothing - dom range gravity will adjust selection
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::UndoTransaction(void)
|
||||
{
|
||||
NS_ASSERTION(mEditor && mExistingRightNode && mNewLeftNode && mParent, "bad state");
|
||||
if (!mEditor || !mExistingRightNode || !mNewLeftNode || !mParent) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
// this assumes Do inserted the new node in front of the prior existing node
|
||||
nsCOMPtr<nsINode> right = do_QueryInterface(mExistingRightNode);
|
||||
nsCOMPtr<nsINode> left = do_QueryInterface(mNewLeftNode);
|
||||
nsCOMPtr<nsINode> parent = do_QueryInterface(mParent);
|
||||
return mEditor->JoinNodesImpl(right, left, parent);
|
||||
}
|
||||
|
||||
/* 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 SplitElementTxn::RedoTransaction(void)
|
||||
{
|
||||
NS_ASSERTION(mEditor && mExistingRightNode && mNewLeftNode && mParent, "bad state");
|
||||
if (!mEditor || !mExistingRightNode || !mNewLeftNode || !mParent) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIDOMNode>resultNode;
|
||||
// first, massage the existing node so it is in its post-split state
|
||||
nsCOMPtr<nsIDOMCharacterData>rightNodeAsText = do_QueryInterface(mExistingRightNode);
|
||||
if (rightNodeAsText)
|
||||
{
|
||||
nsresult result = rightNodeAsText->DeleteData(0, mOffset);
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode>child;
|
||||
nsCOMPtr<nsIDOMNode>nextSibling;
|
||||
result = mExistingRightNode->GetFirstChild(getter_AddRefs(child));
|
||||
int32_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 = mExistingRightNode->RemoveChild(child, getter_AddRefs(resultNode));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
result = mNewLeftNode->AppendChild(child, getter_AddRefs(resultNode));
|
||||
}
|
||||
child = do_QueryInterface(nextSibling);
|
||||
}
|
||||
}
|
||||
// second, re-insert the left node into the tree
|
||||
result = mParent->InsertBefore(mNewLeftNode, mExistingRightNode, getter_AddRefs(resultNode));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::GetTxnDescription(nsAString& aString)
|
||||
{
|
||||
aString.AssignLiteral("SplitElementTxn");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP SplitElementTxn::GetNewNode(nsIDOMNode **aNewNode)
|
||||
{
|
||||
NS_ENSURE_TRUE(aNewNode, NS_ERROR_NULL_POINTER);
|
||||
NS_ENSURE_TRUE(mNewLeftNode, NS_ERROR_NOT_INITIALIZED);
|
||||
*aNewNode = mNewLeftNode;
|
||||
NS_ADDREF(*aNewNode);
|
||||
return NS_OK;
|
||||
}
|
@ -1,67 +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 SplitElementTxn_h__
|
||||
#define SplitElementTxn_h__
|
||||
|
||||
#include "EditTxn.h" // for EditTxn, NS_DECL_EDITTXN
|
||||
#include "nsCOMPtr.h" // for nsCOMPtr
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIDOMNode.h" // for nsIDOMNode
|
||||
#include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED
|
||||
#include "nscore.h" // for NS_IMETHOD
|
||||
|
||||
class nsEditor;
|
||||
|
||||
/**
|
||||
* A transaction that splits an element E into two identical nodes, E1 and E2
|
||||
* with the children of E divided between E1 and E2.
|
||||
*/
|
||||
class SplitElementTxn : public EditTxn
|
||||
{
|
||||
public:
|
||||
/** initialize the transaction.
|
||||
* @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.
|
||||
*/
|
||||
NS_IMETHOD Init (nsEditor *aEditor,
|
||||
nsIDOMNode *aNode,
|
||||
int32_t aOffset);
|
||||
|
||||
SplitElementTxn();
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitElementTxn, EditTxn)
|
||||
|
||||
NS_DECL_EDITTXN
|
||||
|
||||
NS_IMETHOD RedoTransaction(void);
|
||||
|
||||
NS_IMETHOD GetNewNode(nsIDOMNode **aNewNode);
|
||||
|
||||
protected:
|
||||
virtual ~SplitElementTxn();
|
||||
|
||||
/** the element to operate upon */
|
||||
nsCOMPtr<nsIDOMNode> mExistingRightNode;
|
||||
|
||||
/** the offset into mElement where the children of mElement are split.<BR>
|
||||
* mOffset is the index of the first child in the right node.
|
||||
* -1 means the new node gets no children.
|
||||
*/
|
||||
int32_t mOffset;
|
||||
|
||||
/** the element we create when splitting mElement */
|
||||
nsCOMPtr<nsIDOMNode> mNewLeftNode;
|
||||
|
||||
/** the parent shared by mExistingRightNode and mNewLeftNode */
|
||||
nsCOMPtr<nsIDOMNode> mParent;
|
||||
nsEditor* mEditor;
|
||||
};
|
||||
|
||||
#endif
|
129
editor/libeditor/SplitNodeTxn.cpp
Normal file
129
editor/libeditor/SplitNodeTxn.cpp
Normal file
@ -0,0 +1,129 @@
|
||||
/* -*- 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 "mozilla/dom/Selection.h"
|
||||
#include "SplitNodeTxn.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
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
// note that aEditor is not refcounted
|
||||
SplitNodeTxn::SplitNodeTxn(nsEditor& aEditor, nsIContent& aNode,
|
||||
int32_t aOffset)
|
||||
: EditTxn()
|
||||
, mEditor(aEditor)
|
||||
, mExistingRightNode(&aNode)
|
||||
, mOffset(aOffset)
|
||||
, mNewLeftNode(nullptr)
|
||||
, mParent(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
SplitNodeTxn::~SplitNodeTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(SplitNodeTxn, EditTxn,
|
||||
mParent,
|
||||
mNewLeftNode)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(SplitNodeTxn, EditTxn)
|
||||
NS_IMPL_RELEASE_INHERITED(SplitNodeTxn, EditTxn)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SplitNodeTxn)
|
||||
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
|
||||
|
||||
NS_IMETHODIMP
|
||||
SplitNodeTxn::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.ErrorCode());
|
||||
mNewLeftNode = dont_AddRef(clone.forget().take()->AsContent());
|
||||
mEditor.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->AsDOMNode(), mOffset,
|
||||
mNewLeftNode->AsDOMNode(), mParent->AsDOMNode());
|
||||
if (mEditor.GetShouldTxnSetSelection()) {
|
||||
nsRefPtr<Selection> selection = mEditor.GetSelection();
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||
rv = selection->Collapse(mNewLeftNode, mOffset);
|
||||
}
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SplitNodeTxn::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);
|
||||
}
|
||||
|
||||
/* 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
|
||||
SplitNodeTxn::RedoTransaction()
|
||||
{
|
||||
MOZ_ASSERT(mNewLeftNode && mParent);
|
||||
|
||||
ErrorResult rv;
|
||||
// First, massage the existing node so it is in its post-split state
|
||||
if (mExistingRightNode->GetAsText()) {
|
||||
rv = mExistingRightNode->GetAsText()->DeleteData(0, mOffset);
|
||||
NS_ENSURE_SUCCESS(rv.ErrorCode(), rv.ErrorCode());
|
||||
} else {
|
||||
nsCOMPtr<nsIContent> child = mExistingRightNode->GetFirstChild();
|
||||
nsCOMPtr<nsIContent> nextSibling;
|
||||
for (int32_t i=0; i < mOffset; i++) {
|
||||
if (rv.Failed()) {
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
if (!child) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nextSibling = child->GetNextSibling();
|
||||
mExistingRightNode->RemoveChild(*child, rv);
|
||||
if (!rv.Failed()) {
|
||||
mNewLeftNode->AppendChild(*child, rv);
|
||||
}
|
||||
child = nextSibling;
|
||||
}
|
||||
}
|
||||
// Second, re-insert the left node into the tree
|
||||
mParent->InsertBefore(*mNewLeftNode, mExistingRightNode, rv);
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
SplitNodeTxn::GetTxnDescription(nsAString& aString)
|
||||
{
|
||||
aString.AssignLiteral("SplitNodeTxn");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIContent*
|
||||
SplitNodeTxn::GetNewNode()
|
||||
{
|
||||
return mNewLeftNode;
|
||||
}
|
69
editor/libeditor/SplitNodeTxn.h
Normal file
69
editor/libeditor/SplitNodeTxn.h
Normal file
@ -0,0 +1,69 @@
|
||||
/* -*- 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 SplitNodeTxn_h__
|
||||
#define SplitNodeTxn_h__
|
||||
|
||||
#include "EditTxn.h" // for EditTxn, NS_DECL_EDITTXN
|
||||
#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;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
/**
|
||||
* A transaction that splits a node into two identical nodes, with the children
|
||||
* divided between the new nodes.
|
||||
*/
|
||||
class SplitNodeTxn : public EditTxn
|
||||
{
|
||||
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.
|
||||
*/
|
||||
SplitNodeTxn(nsEditor& aEditor, nsIContent& aNode, int32_t aOffset);
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitNodeTxn, EditTxn)
|
||||
|
||||
NS_DECL_EDITTXN
|
||||
|
||||
NS_IMETHOD RedoTransaction();
|
||||
|
||||
nsIContent* GetNewNode();
|
||||
|
||||
protected:
|
||||
virtual ~SplitNodeTxn();
|
||||
|
||||
nsEditor& mEditor;
|
||||
|
||||
/** 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;
|
||||
|
||||
/** The node we create when splitting mExistingRightNode */
|
||||
nsCOMPtr<nsIContent> mNewLeftNode;
|
||||
|
||||
/** The parent shared by mExistingRightNode and mNewLeftNode */
|
||||
nsCOMPtr<nsINode> mParent;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -53,7 +53,7 @@ UNIFIED_SOURCES += [
|
||||
'nsWSRunObject.cpp',
|
||||
'PlaceholderTxn.cpp',
|
||||
'SetDocTitleTxn.cpp',
|
||||
'SplitElementTxn.cpp',
|
||||
'SplitNodeTxn.cpp',
|
||||
'TextEditorTest.cpp',
|
||||
'TypeInState.cpp',
|
||||
]
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "InsertTextTxn.h" // for InsertTextTxn
|
||||
#include "JoinNodeTxn.h" // for JoinNodeTxn
|
||||
#include "PlaceholderTxn.h" // for PlaceholderTxn
|
||||
#include "SplitElementTxn.h" // for SplitElementTxn
|
||||
#include "SplitNodeTxn.h" // for SplitNodeTxn
|
||||
#include "mozFlushType.h" // for mozFlushType::Flush_Frames
|
||||
#include "mozISpellCheckingEngine.h"
|
||||
#include "mozInlineSpellChecker.h" // for mozInlineSpellChecker
|
||||
@ -1421,38 +1421,44 @@ nsEditor::InsertNode(nsIContent& aNode, nsINode& aParent, int32_t aPosition)
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditor::SplitNode(nsIDOMNode * aNode,
|
||||
int32_t aOffset,
|
||||
nsIDOMNode **aNewLeftNode)
|
||||
NS_IMETHODIMP
|
||||
nsEditor::SplitNode(nsIDOMNode* aNode,
|
||||
int32_t aOffset,
|
||||
nsIDOMNode** aNewLeftNode)
|
||||
{
|
||||
int32_t i;
|
||||
nsAutoRules beginRulesSniffing(this, EditAction::splitNode, nsIEditor::eNext);
|
||||
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.ErrorCode();
|
||||
}
|
||||
|
||||
for (i = 0; i < mActionListeners.Count(); i++)
|
||||
mActionListeners[i]->WillSplitNode(aNode, aOffset);
|
||||
nsIContent*
|
||||
nsEditor::SplitNode(nsIContent& aNode, int32_t aOffset, ErrorResult& aResult)
|
||||
{
|
||||
nsAutoRules beginRulesSniffing(this, EditAction::splitNode,
|
||||
nsIEditor::eNext);
|
||||
|
||||
nsRefPtr<SplitElementTxn> txn;
|
||||
nsresult result = CreateTxnForSplitNode(aNode, aOffset, getter_AddRefs(txn));
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
result = DoTransaction(txn);
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
result = txn->GetNewNode(aNewLeftNode);
|
||||
NS_ASSERTION((NS_SUCCEEDED(result)), "result must succeeded for GetNewNode");
|
||||
}
|
||||
for (int32_t i = 0; i < mActionListeners.Count(); i++) {
|
||||
mActionListeners[i]->WillSplitNode(aNode.AsDOMNode(), aOffset);
|
||||
}
|
||||
|
||||
mRangeUpdater.SelAdjSplitNode(aNode, aOffset, *aNewLeftNode);
|
||||
nsRefPtr<SplitNodeTxn> txn = CreateTxnForSplitNode(aNode, aOffset);
|
||||
aResult = DoTransaction(txn);
|
||||
|
||||
for (i = 0; i < mActionListeners.Count(); i++)
|
||||
{
|
||||
nsIDOMNode *ptr = *aNewLeftNode;
|
||||
mActionListeners[i]->DidSplitNode(aNode, aOffset, ptr, result);
|
||||
nsCOMPtr<nsIContent> newNode = aResult.Failed() ? nullptr
|
||||
: txn->GetNewNode();
|
||||
|
||||
mRangeUpdater.SelAdjSplitNode(aNode, aOffset, newNode);
|
||||
|
||||
for (int32_t i = 0; i < mActionListeners.Count(); i++) {
|
||||
mActionListeners[i]->DidSplitNode(aNode.AsDOMNode(), aOffset,
|
||||
GetAsDOMNode(newNode),
|
||||
aResult.ErrorCode());
|
||||
}
|
||||
|
||||
return result;
|
||||
return newNode;
|
||||
}
|
||||
|
||||
|
||||
@ -2577,24 +2583,11 @@ nsEditor::CreateTxnForDeleteText(nsGenericDOMDataNode& aCharData,
|
||||
return txn.forget();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP nsEditor::CreateTxnForSplitNode(nsIDOMNode *aNode,
|
||||
uint32_t aOffset,
|
||||
SplitElementTxn **aTxn)
|
||||
already_AddRefed<SplitNodeTxn>
|
||||
nsEditor::CreateTxnForSplitNode(nsIContent& aNode, uint32_t aOffset)
|
||||
{
|
||||
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
|
||||
|
||||
nsRefPtr<SplitElementTxn> txn = new SplitElementTxn();
|
||||
|
||||
nsresult rv = txn->Init(this, aNode, aOffset);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
txn.forget(aTxn);
|
||||
}
|
||||
|
||||
return rv;
|
||||
nsRefPtr<SplitNodeTxn> txn = new SplitNodeTxn(*this, aNode, aOffset);
|
||||
return txn.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<JoinNodeTxn>
|
||||
|
@ -31,7 +31,6 @@ class AddStyleSheetTxn;
|
||||
class DeleteNodeTxn;
|
||||
class EditAggregateTxn;
|
||||
class RemoveStyleSheetTxn;
|
||||
class SplitElementTxn;
|
||||
class nsIAtom;
|
||||
class nsIContent;
|
||||
class nsIDOMCharacterData;
|
||||
@ -76,6 +75,7 @@ class InsertTextTxn;
|
||||
class InsertNodeTxn;
|
||||
class JoinNodeTxn;
|
||||
class Selection;
|
||||
class SplitNodeTxn;
|
||||
class Text;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
@ -234,6 +234,8 @@ public:
|
||||
nsIAtom* aNodeType,
|
||||
nsIAtom* aAttribute = nullptr,
|
||||
const nsAString* aValue = nullptr);
|
||||
nsIContent* SplitNode(nsIContent& aNode, int32_t aOffset,
|
||||
mozilla::ErrorResult& aResult);
|
||||
nsresult JoinNodes(nsINode& aLeftNode, nsINode& aRightNode);
|
||||
nsresult MoveNode(nsIContent* aNode, nsINode* aParent, int32_t aOffset);
|
||||
|
||||
@ -337,9 +339,8 @@ protected:
|
||||
CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData, uint32_t aOffset,
|
||||
EDirection aDirection);
|
||||
|
||||
NS_IMETHOD CreateTxnForSplitNode(nsIDOMNode *aNode,
|
||||
uint32_t aOffset,
|
||||
SplitElementTxn **aTxn);
|
||||
already_AddRefed<mozilla::dom::SplitNodeTxn>
|
||||
CreateTxnForSplitNode(nsIContent& aNode, uint32_t aOffset);
|
||||
|
||||
already_AddRefed<mozilla::dom::JoinNodeTxn>
|
||||
CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode);
|
||||
|
@ -320,21 +320,21 @@ nsRangeUpdater::SelAdjDeleteNode(nsIDOMNode *aNode)
|
||||
|
||||
|
||||
nsresult
|
||||
nsRangeUpdater::SelAdjSplitNode(nsINode* aOldRightNode, int32_t aOffset,
|
||||
nsINode* aNewLeftNode)
|
||||
nsRangeUpdater::SelAdjSplitNode(nsIContent& aOldRightNode, int32_t aOffset,
|
||||
nsIContent* aNewLeftNode)
|
||||
{
|
||||
if (mLock) {
|
||||
// lock set by Will/DidReplaceParent, etc...
|
||||
return NS_OK;
|
||||
}
|
||||
NS_ENSURE_TRUE(aOldRightNode && aNewLeftNode, NS_ERROR_NULL_POINTER);
|
||||
NS_ENSURE_TRUE(aNewLeftNode, NS_ERROR_NULL_POINTER);
|
||||
uint32_t count = mArray.Length();
|
||||
if (!count) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsINode> parent = aOldRightNode->GetParentNode();
|
||||
int32_t offset = parent ? parent->IndexOf(aOldRightNode) : -1;
|
||||
nsCOMPtr<nsINode> parent = aOldRightNode.GetParentNode();
|
||||
int32_t offset = parent ? parent->IndexOf(&aOldRightNode) : -1;
|
||||
|
||||
// first part is same as inserting aNewLeftnode
|
||||
nsresult result = SelAdjInsertNode(parent, offset - 1);
|
||||
@ -345,14 +345,14 @@ nsRangeUpdater::SelAdjSplitNode(nsINode* aOldRightNode, int32_t aOffset,
|
||||
nsRangeStore* item = mArray[i];
|
||||
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (item->startNode == aOldRightNode) {
|
||||
if (item->startNode == &aOldRightNode) {
|
||||
if (item->startOffset > aOffset) {
|
||||
item->startOffset -= aOffset;
|
||||
} else {
|
||||
item->startNode = aNewLeftNode;
|
||||
}
|
||||
}
|
||||
if (item->endNode == aOldRightNode) {
|
||||
if (item->endNode == &aOldRightNode) {
|
||||
if (item->endOffset > aOffset) {
|
||||
item->endOffset -= aOffset;
|
||||
} else {
|
||||
@ -363,16 +363,6 @@ nsRangeUpdater::SelAdjSplitNode(nsINode* aOldRightNode, int32_t aOffset,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsRangeUpdater::SelAdjSplitNode(nsIDOMNode* aOldRightNode, int32_t aOffset,
|
||||
nsIDOMNode* aNewLeftNode)
|
||||
{
|
||||
nsCOMPtr<nsINode> oldRightNode = do_QueryInterface(aOldRightNode);
|
||||
nsCOMPtr<nsINode> newLeftNode = do_QueryInterface(aNewLeftNode);
|
||||
return SelAdjSplitNode(oldRightNode, aOffset, newLeftNode);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsRangeUpdater::SelAdjJoinNodes(nsINode& aLeftNode,
|
||||
nsINode& aRightNode,
|
||||
|
@ -96,9 +96,8 @@ class nsRangeUpdater
|
||||
nsresult SelAdjInsertNode(nsIDOMNode *aParent, int32_t aPosition);
|
||||
void SelAdjDeleteNode(nsINode* aNode);
|
||||
void SelAdjDeleteNode(nsIDOMNode *aNode);
|
||||
nsresult SelAdjSplitNode(nsINode* aOldRightNode, int32_t aOffset,
|
||||
nsINode* aNewLeftNode);
|
||||
nsresult SelAdjSplitNode(nsIDOMNode *aOldRightNode, int32_t aOffset, nsIDOMNode *aNewLeftNode);
|
||||
nsresult SelAdjSplitNode(nsIContent& aOldRightNode, int32_t aOffset,
|
||||
nsIContent* aNewLeftNode);
|
||||
nsresult SelAdjJoinNodes(nsINode& aLeftNode,
|
||||
nsINode& aRightNode,
|
||||
nsINode& aParent,
|
||||
|
Loading…
Reference in New Issue
Block a user