Backed out changeset e2a22ba1d1e4 (bug 1015433) for build bustages

This commit is contained in:
Carsten "Tomcat" Book 2014-05-31 17:06:29 +02:00
parent ebbde442da
commit d11f7b8a5e
12 changed files with 204 additions and 192 deletions

View File

@ -7,9 +7,11 @@
#include "nsAString.h"
#include "nsDebug.h" // for NS_ASSERTION
#include "nsError.h" // for NS_ERROR_NOT_INITIALIZED, etc
#include "nsIDOMElement.h" // for nsIDOMElement
#include "nsIEditor.h" // for nsIEditor
#include "nsEditor.h" // for nsEditor
#include "nsString.h" // for nsString
#include "mozilla/dom/Element.h"
using namespace mozilla;
ChangeAttributeTxn::ChangeAttributeTxn()
: EditTxn()
@ -24,8 +26,8 @@ NS_IMPL_RELEASE_INHERITED(ChangeAttributeTxn, EditTxn)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ChangeAttributeTxn)
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor,
nsIDOMElement *aElement,
NS_IMETHODIMP ChangeAttributeTxn::Init(nsEditor *aEditor,
dom::Element *aElement,
const nsAString& aAttribute,
const nsAString& aValue,
bool aRemoveAttribute)
@ -34,7 +36,7 @@ NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor,
if (!aEditor || !aElement) { return NS_ERROR_NULL_POINTER; }
mEditor = aEditor;
mElement = do_QueryInterface(aElement);
mElement = aElement;
mAttribute = aAttribute;
mValue = aValue;
mRemoveAttribute = aRemoveAttribute;
@ -48,20 +50,24 @@ NS_IMETHODIMP ChangeAttributeTxn::DoTransaction(void)
NS_ASSERTION(mEditor && mElement, "bad state");
if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(mElement);
// need to get the current value of the attribute and save it, and set mAttributeWasSet
nsresult result = mEditor->GetAttributeValue(mElement, mAttribute, mUndoValue, &mAttributeWasSet);
nsresult result = mEditor->GetAttributeValue(element, mAttribute, mUndoValue, &mAttributeWasSet);
NS_ENSURE_SUCCESS(result, result);
// XXX: hack until attribute-was-set code is implemented
if (!mUndoValue.IsEmpty())
mAttributeWasSet = true;
// XXX: end hack
ErrorResult rv;
// now set the attribute to the new value
if (!mRemoveAttribute)
result = mElement->SetAttribute(mAttribute, mValue);
mElement->SetAttribute(mAttribute, mValue, rv);
else
result = mElement->RemoveAttribute(mAttribute);
mElement->RemoveAttribute(mAttribute, rv);
return result;
return rv.ErrorCode();
}
NS_IMETHODIMP ChangeAttributeTxn::UndoTransaction(void)
@ -69,13 +75,13 @@ NS_IMETHODIMP ChangeAttributeTxn::UndoTransaction(void)
NS_ASSERTION(mEditor && mElement, "bad state");
if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }
nsresult result;
ErrorResult rv;
if (mAttributeWasSet)
result = mElement->SetAttribute(mAttribute, mUndoValue);
mElement->SetAttribute(mAttribute, mUndoValue, rv);
else
result = mElement->RemoveAttribute(mAttribute);
mElement->RemoveAttribute(mAttribute, rv);
return result;
return rv.ErrorCode();
}
NS_IMETHODIMP ChangeAttributeTxn::RedoTransaction(void)
@ -83,13 +89,13 @@ NS_IMETHODIMP ChangeAttributeTxn::RedoTransaction(void)
NS_ASSERTION(mEditor && mElement, "bad state");
if (!mEditor || !mElement) { return NS_ERROR_NOT_INITIALIZED; }
nsresult result;
ErrorResult rv;
if (!mRemoveAttribute)
result = mElement->SetAttribute(mAttribute, mValue);
mElement->SetAttribute(mAttribute, mValue, rv);
else
result = mElement->RemoveAttribute(mAttribute);
mElement->RemoveAttribute(mAttribute, rv);
return result;
return rv.ErrorCode();
}
NS_IMETHODIMP ChangeAttributeTxn::GetTxnDescription(nsAString& aString)

View File

@ -9,15 +9,20 @@
#include "EditTxn.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIDOMElement.h"
#include "nsISupportsImpl.h"
#include "nsString.h"
#include "nscore.h"
class nsIEditor;
class nsEditor;
namespace mozilla {
namespace dom {
class Element;
}
}
/**
* A transaction that changes an attribute of a content node.
* A transaction that changes an attribute of a content node.
* This transaction covers add, remove, and change attribute.
*/
class ChangeAttributeTxn : public EditTxn
@ -30,8 +35,8 @@ public:
* @param aValue the new value for aAttribute, if aRemoveAttribute is false
* @param aRemoveAttribute if true, remove aAttribute from aNode
*/
NS_IMETHOD Init(nsIEditor *aEditor,
nsIDOMElement *aNode,
NS_IMETHOD Init(nsEditor *aEditor,
mozilla::dom::Element *aNode,
const nsAString& aAttribute,
const nsAString& aValue,
bool aRemoveAttribute);
@ -48,11 +53,11 @@ public:
protected:
/** the editor that created this transaction */
nsIEditor* mEditor;
nsEditor* mEditor;
/** the element to operate upon */
nsCOMPtr<nsIDOMElement> mElement;
nsCOMPtr<mozilla::dom::Element> mElement;
/** the attribute to change */
nsString mAttribute;

View File

@ -13,7 +13,6 @@
#include "nsError.h"
#include "nsIContent.h"
#include "nsIDOMCharacterData.h"
#include "nsIEditor.h"
#include "nsINode.h"
#include "nsISelection.h"
#include "nsISupportsUtils.h"
@ -43,7 +42,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CreateElementTxn)
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
NS_IMETHODIMP CreateElementTxn::Init(nsEditor *aEditor,
const nsAString &aTag,
nsIDOMNode *aParent,
nsINode *aParent,
uint32_t aOffsetInParent)
{
NS_ASSERTION(aEditor&&aParent, "null args");
@ -67,28 +66,24 @@ NS_IMETHODIMP CreateElementTxn::DoTransaction(void)
NS_ENSURE_SUCCESS(rv.ErrorCode(), rv.ErrorCode());
NS_ENSURE_STATE(newContent);
mNewNode = newContent->AsDOMNode();
mNewNode = newContent;
// Try to insert formatting whitespace for the new node:
mEditor->MarkNodeDirty(mNewNode);
// insert the new node
if (CreateElementTxn::eAppend == int32_t(mOffsetInParent)) {
nsCOMPtr<nsIDOMNode> resultNode;
return mParent->AppendChild(mNewNode, getter_AddRefs(resultNode));
mParent->AppendChild(*mNewNode, rv);
return rv.ErrorCode();
}
nsCOMPtr<nsINode> parent = do_QueryInterface(mParent);
NS_ENSURE_STATE(parent);
mOffsetInParent = std::min(mOffsetInParent, parent->GetChildCount());
mOffsetInParent = std::min(mOffsetInParent, mParent->GetChildCount());
// note, it's ok for mRefNode to be null. that means append
nsIContent* refNode = parent->GetChildAt(mOffsetInParent);
mRefNode = refNode ? refNode->AsDOMNode() : nullptr;
mRefNode = mParent->GetChildAt(mOffsetInParent);
nsCOMPtr<nsIDOMNode> resultNode;
nsresult result = mParent->InsertBefore(mNewNode, mRefNode, getter_AddRefs(resultNode));
NS_ENSURE_SUCCESS(result, result);
mParent->InsertBefore(*mNewNode, mRefNode, rv);
NS_ENSURE_SUCCESS(rv.ErrorCode(), rv.ErrorCode());
// only set selection to insertion point if editor gives permission
bool bAdjustSelection;
@ -99,7 +94,7 @@ NS_IMETHODIMP CreateElementTxn::DoTransaction(void)
}
nsCOMPtr<nsISelection> selection;
result = mEditor->GetSelection(getter_AddRefs(selection));
nsresult result = mEditor->GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
@ -117,8 +112,9 @@ NS_IMETHODIMP CreateElementTxn::UndoTransaction(void)
NS_ASSERTION(mEditor && mParent, "bad state");
NS_ENSURE_TRUE(mEditor && mParent, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIDOMNode> resultNode;
return mParent->RemoveChild(mNewNode, getter_AddRefs(resultNode));
ErrorResult rv;
mParent->RemoveChild(*mNewNode, rv);
return rv.ErrorCode();
}
NS_IMETHODIMP CreateElementTxn::RedoTransaction(void)
@ -132,10 +128,11 @@ NS_IMETHODIMP CreateElementTxn::RedoTransaction(void)
{
nodeAsText->SetData(EmptyString());
}
// now, reinsert mNewNode
nsCOMPtr<nsIDOMNode> resultNode;
return mParent->InsertBefore(mNewNode, mRefNode, getter_AddRefs(resultNode));
ErrorResult rv;
mParent->InsertBefore(*mNewNode, mRefNode, rv);
return rv.ErrorCode();
}
NS_IMETHODIMP CreateElementTxn::GetTxnDescription(nsAString& aString)
@ -145,7 +142,7 @@ NS_IMETHODIMP CreateElementTxn::GetTxnDescription(nsAString& aString)
return NS_OK;
}
NS_IMETHODIMP CreateElementTxn::GetNewNode(nsIDOMNode **aNewNode)
NS_IMETHODIMP CreateElementTxn::GetNewNode(nsINode **aNewNode)
{
NS_ENSURE_TRUE(aNewNode, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(mNewNode, NS_ERROR_NOT_INITIALIZED);

View File

@ -9,12 +9,12 @@
#include "EditTxn.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIDOMNode.h"
#include "nsISupportsImpl.h"
#include "nsString.h"
#include "nscore.h"
class nsEditor;
class nsINode;
/**
* A transaction that creates a new node in the content tree.
@ -33,7 +33,7 @@ public:
*/
NS_IMETHOD Init(nsEditor *aEditor,
const nsAString& aTag,
nsIDOMNode *aParent,
nsINode *aParent,
uint32_t aOffsetInParent);
CreateElementTxn();
@ -45,27 +45,27 @@ public:
NS_IMETHOD RedoTransaction();
NS_IMETHOD GetNewNode(nsIDOMNode **aNewNode);
NS_IMETHOD GetNewNode(nsINode **aNewNode);
protected:
/** the document into which the new node will be inserted */
nsEditor* mEditor;
/** the tag (mapping to object type) for the new element */
nsString mTag;
/** the node into which the new node will be inserted */
nsCOMPtr<nsIDOMNode> mParent;
nsCOMPtr<nsINode> mParent;
/** the index in mParent for the new node */
uint32_t mOffsetInParent;
/** the new node to insert */
nsCOMPtr<nsIDOMNode> mNewNode;
nsCOMPtr<nsINode> mNewNode;
/** the node we will insert mNewNode before. We compute this ourselves. */
nsCOMPtr<nsIDOMNode> mRefNode;
nsCOMPtr<nsINode> mRefNode;
};
#endif

View File

@ -33,10 +33,10 @@ NS_IMPL_RELEASE_INHERITED(InsertElementTxn, EditTxn)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(InsertElementTxn)
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
NS_IMETHODIMP InsertElementTxn::Init(nsIDOMNode *aNode,
nsIDOMNode *aParent,
NS_IMETHODIMP InsertElementTxn::Init(nsINode *aNode,
nsINode *aParent,
int32_t aOffset,
nsIEditor *aEditor)
nsEditor *aEditor)
{
NS_ASSERTION(aNode && aParent && aEditor, "bad arg");
NS_ENSURE_TRUE(aNode && aParent && aEditor, NS_ERROR_NULL_POINTER);
@ -65,14 +65,12 @@ NS_IMETHODIMP InsertElementTxn::DoTransaction(void)
// note, it's ok for refContent to be null. that means append
nsCOMPtr<nsIContent> refContent = parent->GetChildAt(mOffset);
nsCOMPtr<nsIDOMNode> refNode = refContent ? refContent->AsDOMNode() : nullptr;
mEditor->MarkNodeDirty(mNode);
nsCOMPtr<nsIDOMNode> resultNode;
nsresult result = mParent->InsertBefore(mNode, refNode, getter_AddRefs(resultNode));
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_TRUE(resultNode, NS_ERROR_NULL_POINTER);
ErrorResult rv;
mParent->InsertBefore(*mNode, refContent, rv);
NS_ENSURE_SUCCESS(rv.ErrorCode(), rv.ErrorCode());
// only set selection to insertion point if editor gives permission
bool bAdjustSelection;
@ -80,25 +78,26 @@ NS_IMETHODIMP InsertElementTxn::DoTransaction(void)
if (bAdjustSelection)
{
nsCOMPtr<nsISelection> selection;
result = mEditor->GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(result, result);
rv = mEditor->GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(rv.ErrorCode(), rv.ErrorCode());
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
// place the selection just after the inserted element
selection->Collapse(mParent, mOffset+1);
selection->Collapse(mParent->AsDOMNode(), mOffset+1);
}
else
{
// do nothing - dom range gravity will adjust selection
}
return result;
return NS_OK;
}
NS_IMETHODIMP InsertElementTxn::UndoTransaction(void)
{
NS_ENSURE_TRUE(mNode && mParent, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIDOMNode> resultNode;
return mParent->RemoveChild(mNode, getter_AddRefs(resultNode));
ErrorResult rv;
mParent->RemoveChild(*mNode, rv);
return rv.ErrorCode();
}
NS_IMETHODIMP InsertElementTxn::GetTxnDescription(nsAString& aString)

View File

@ -9,11 +9,11 @@
#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 nsIEditor;
class nsEditor;
class nsINode;
/**
* A transaction that inserts a single element
@ -26,10 +26,10 @@ public:
* @param aParent the node to insert into
* @param aOffset the offset in aParent to insert aNode
*/
NS_IMETHOD Init(nsIDOMNode *aNode,
nsIDOMNode *aParent,
NS_IMETHOD Init(nsINode *aNode,
nsINode *aParent,
int32_t aOffset,
nsIEditor *aEditor);
nsEditor *aEditor);
InsertElementTxn();
@ -39,15 +39,15 @@ public:
NS_DECL_EDITTXN
protected:
/** the element to insert */
nsCOMPtr<nsIDOMNode> mNode;
nsCOMPtr<nsINode> mNode;
/** the node into which the new node will be inserted */
nsCOMPtr<nsIDOMNode> mParent;
nsCOMPtr<nsINode> mParent;
/** the editor for this transaction */
nsIEditor* mEditor;
nsEditor* mEditor;
/** the index in mParent for the new node */
int32_t mOffset;

View File

@ -31,20 +31,18 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JoinElementTxn)
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
NS_IMETHODIMP JoinElementTxn::Init(nsEditor *aEditor,
nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode)
nsINode *aLeftNode,
nsINode *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);
mLeftNode = aLeftNode;
nsCOMPtr<nsINode> leftParent = mLeftNode->GetParentNode();
if (!mEditor->IsModifiableNode(leftParent)) {
return NS_ERROR_FAILURE;
}
mRightNode = do_QueryInterface(aRightNode);
mRightNode = aRightNode;
mOffset = 0;
return NS_OK;
}
@ -56,13 +54,11 @@ NS_IMETHODIMP JoinElementTxn::DoTransaction(void)
if (!mEditor || !mLeftNode || !mRightNode) { return NS_ERROR_NOT_INITIALIZED; }
// get the parent node
nsCOMPtr<nsINode> leftNode = do_QueryInterface(mLeftNode);
nsCOMPtr<nsINode> leftParent = leftNode->GetParentNode();
nsCOMPtr<nsINode> leftParent = mLeftNode->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();
nsCOMPtr<nsINode> rightParent = mRightNode->GetParentNode();
NS_ENSURE_TRUE(rightParent, NS_ERROR_NULL_POINTER);
if (leftParent != rightParent) {
@ -72,11 +68,10 @@ NS_IMETHODIMP JoinElementTxn::DoTransaction(void)
// set this instance mParent.
// Other methods will see a non-null mParent and know all is well
mParent = leftParent->AsDOMNode();
mOffset = leftNode->Length();
mParent = leftParent;
mOffset = mLeftNode->Length();
nsCOMPtr<nsINode> parent = do_QueryInterface(mParent);
return mEditor->JoinNodesImpl(rightNode, leftNode, parent);
return mEditor->JoinNodesImpl(mRightNode, mLeftNode, mParent);
}
//XXX: what if instead of split, we just deleted the unneeded children of mRight
@ -86,31 +81,26 @@ 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);
ErrorResult rv;
if (rightNodeAsText)
{
result = rightNodeAsText->DeleteData(0, mOffset);
rv = rightNodeAsText->DeleteData(0, mOffset);
NS_ENSURE_SUCCESS(rv.ErrorCode(), rv.ErrorCode());
}
else
{
nsCOMPtr<nsIDOMNode>child;
result = mRightNode->GetFirstChild(getter_AddRefs(child));
nsCOMPtr<nsIDOMNode>nextSibling;
uint32_t i;
for (i=0; i<mOffset; i++)
for (nsCOMPtr<nsINode> child = mRightNode->GetFirstChild();
child;
child = child->GetNextSibling())
{
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);
mLeftNode->AppendChild(*child, rv);
NS_ENSURE_SUCCESS(rv.ErrorCode(), rv.ErrorCode());
}
}
// second, re-insert the left node into the tree
result = mParent->InsertBefore(mLeftNode, mRightNode, getter_AddRefs(resultNode));
return result;
mParent->InsertBefore(*mLeftNode, mRightNode, rv);
return rv.ErrorCode();
}
NS_IMETHODIMP JoinElementTxn::GetTxnDescription(nsAString& aString)

View File

@ -10,14 +10,14 @@
#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;
class nsINode;
/**
* A transaction that joins two elements E1 (left node) and E2 (right node)
* into a single node E.
* 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.
@ -31,8 +31,8 @@ public:
* @param aRightNode the second of two nodes to join
*/
NS_IMETHOD Init(nsEditor *aEditor,
nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode);
nsINode *aLeftNode,
nsINode *aRightNode);
JoinElementTxn();
@ -42,21 +42,21 @@ public:
NS_DECL_EDITTXN
protected:
/** the elements to operate upon.
/** the elements to operate upon.
* After the merge, mRightNode remains and mLeftNode is removed from the content tree.
*/
nsCOMPtr<nsIDOMNode> mLeftNode;
nsCOMPtr<nsIDOMNode> mRightNode;
nsCOMPtr<nsINode> mLeftNode;
nsCOMPtr<nsINode> 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.
* 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;
nsCOMPtr<nsINode> mParent;
nsEditor* mEditor;
};

View File

@ -34,7 +34,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SplitElementTxn)
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
NS_IMETHODIMP SplitElementTxn::Init(nsEditor *aEditor,
nsIDOMNode *aNode,
nsINode *aNode,
int32_t aOffset)
{
NS_ASSERTION(aEditor && aNode, "bad args");
@ -52,18 +52,23 @@ NS_IMETHODIMP SplitElementTxn::DoTransaction(void)
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);
ErrorResult rv;
mNewLeftNode = mExistingRightNode->CloneNode(false, rv);
NS_ENSURE_SUCCESS(rv.ErrorCode(), rv.ErrorCode());
NS_ASSERTION(mNewLeftNode, "could not create element.");
NS_ENSURE_TRUE(mNewLeftNode, NS_ERROR_NULL_POINTER);
mEditor->MarkNodeDirty(mExistingRightNode);
// get the parent node
result = mExistingRightNode->GetParentNode(getter_AddRefs(mParent));
NS_ENSURE_SUCCESS(result, result);
mParent = mExistingRightNode->GetParentNode();
NS_ENSURE_TRUE(mParent, NS_ERROR_NULL_POINTER);
// insert the new node
result = mEditor->SplitNodeImpl(mExistingRightNode, mOffset, mNewLeftNode, mParent);
nsresult result = mEditor->SplitNodeImpl(mExistingRightNode->AsDOMNode(),
mOffset,
mNewLeftNode->AsDOMNode(),
mParent->AsDOMNode());
NS_ENSURE_SUCCESS(result, result);
if (mNewLeftNode) {
bool bAdjustSelection;
mEditor->ShouldTxnSetSelection(&bAdjustSelection);
@ -73,7 +78,7 @@ NS_IMETHODIMP SplitElementTxn::DoTransaction(void)
result = mEditor->GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
result = selection->Collapse(mNewLeftNode, mOffset);
result = selection->Collapse(mNewLeftNode->AsDOMNode(), mOffset);
}
else
{
@ -91,10 +96,7 @@ NS_IMETHODIMP SplitElementTxn::UndoTransaction(void)
}
// 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);
return mEditor->JoinNodesImpl(mExistingRightNode, mNewLeftNode, mParent);
}
/* redo cannot simply resplit the right node, because subsequent transactions
@ -107,8 +109,6 @@ NS_IMETHODIMP SplitElementTxn::RedoTransaction(void)
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)
@ -118,26 +118,24 @@ NS_IMETHODIMP SplitElementTxn::RedoTransaction(void)
}
else
{
nsCOMPtr<nsIDOMNode>child;
nsCOMPtr<nsIDOMNode>nextSibling;
result = mExistingRightNode->GetFirstChild(getter_AddRefs(child));
int32_t i;
for (i=0; i<mOffset; i++)
nsCOMPtr<nsINode> child = mExistingRightNode->GetFirstChild();
for (int32_t 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))
ErrorResult rv;
mExistingRightNode->RemoveChild(*child, rv);
if (NS_SUCCEEDED(rv.ErrorCode()))
{
result = mNewLeftNode->AppendChild(child, getter_AddRefs(resultNode));
mNewLeftNode->AppendChild(*child, rv);
NS_ENSURE_SUCCESS(rv.ErrorCode(), rv.ErrorCode());
}
child = do_QueryInterface(nextSibling);
child = child->GetNextSibling();
}
}
// second, re-insert the left node into the tree
result = mParent->InsertBefore(mNewLeftNode, mExistingRightNode, getter_AddRefs(resultNode));
return result;
ErrorResult rv;
mParent->InsertBefore(*mNewLeftNode, mExistingRightNode, rv);
return rv.ErrorCode();
}
@ -147,7 +145,7 @@ NS_IMETHODIMP SplitElementTxn::GetTxnDescription(nsAString& aString)
return NS_OK;
}
NS_IMETHODIMP SplitElementTxn::GetNewNode(nsIDOMNode **aNewNode)
NS_IMETHODIMP SplitElementTxn::GetNewNode(nsINode **aNewNode)
{
NS_ENSURE_TRUE(aNewNode, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(mNewLeftNode, NS_ERROR_NOT_INITIALIZED);

View File

@ -9,11 +9,11 @@
#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;
class nsINode;
/**
* A transaction that splits an element E into two identical nodes, E1 and E2
@ -30,7 +30,7 @@ public:
* The left node will have child|content 0..aOffset-1.
*/
NS_IMETHOD Init (nsEditor *aEditor,
nsIDOMNode *aNode,
nsINode *aNode,
int32_t aOffset);
SplitElementTxn();
@ -42,12 +42,12 @@ public:
NS_IMETHOD RedoTransaction(void);
NS_IMETHOD GetNewNode(nsIDOMNode **aNewNode);
NS_IMETHOD GetNewNode(nsINode **aNewNode);
protected:
/** the element to operate upon */
nsCOMPtr<nsIDOMNode> mExistingRightNode;
nsCOMPtr<nsINode> 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.
@ -56,10 +56,10 @@ protected:
int32_t mOffset;
/** the element we create when splitting mElement */
nsCOMPtr<nsIDOMNode> mNewLeftNode;
nsCOMPtr<nsINode> mNewLeftNode;
/** the parent shared by mExistingRightNode and mNewLeftNode */
nsCOMPtr<nsIDOMNode> mParent;
nsCOMPtr<nsINode> mParent;
nsEditor* mEditor;
};

View File

@ -118,6 +118,7 @@ class nsITransferable;
#endif
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::widget;
// Defined in nsEditorRegistration.cpp
@ -1173,14 +1174,15 @@ nsEditor::CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
NS_IMETHODIMP
nsEditor::SetAttribute(nsIDOMElement *aElement, const nsAString & aAttribute, const nsAString & aValue)
{
nsRefPtr<ChangeAttributeTxn> txn;
nsresult result = CreateTxnForSetAttribute(aElement, aAttribute, aValue,
nsCOMPtr<Element> element = do_QueryInterface(aElement);
nsresult result = CreateTxnForSetAttribute(element, aAttribute, aValue,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = DoTransaction(txn);
result = DoTransaction(txn);
}
return result;
}
@ -1206,14 +1208,15 @@ nsEditor::GetAttributeValue(nsIDOMElement *aElement,
return rv;
}
NS_IMETHODIMP
NS_IMETHODIMP
nsEditor::RemoveAttribute(nsIDOMElement *aElement, const nsAString& aAttribute)
{
nsRefPtr<ChangeAttributeTxn> txn;
nsresult result = CreateTxnForRemoveAttribute(aElement, aAttribute,
nsCOMPtr<Element> element = do_QueryInterface(aElement);
nsresult result = CreateTxnForRemoveAttribute(element, aAttribute,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = DoTransaction(txn);
result = DoTransaction(txn);
}
return result;
}
@ -1231,15 +1234,21 @@ nsEditor::OutputsMozDirty()
NS_IMETHODIMP
nsEditor::MarkNodeDirty(nsIDOMNode* aNode)
{
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return MarkNodeDirty(node);
}
nsresult
nsEditor::MarkNodeDirty(nsINode* 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, nsEditProperty::mozdirty,
EmptyString(), false);
if (aNode->IsElement()) {
aNode->AsElement()->SetAttr(kNameSpaceID_None, nsEditProperty::mozdirty,
EmptyString(), false);
}
return NS_OK;
}
@ -1347,14 +1356,17 @@ NS_IMETHODIMP nsEditor::CreateNode(const nsAString& aTag,
mActionListeners[i]->WillCreateNode(aTag, aParent, aPosition);
nsRefPtr<CreateElementTxn> txn;
nsresult result = CreateTxnForCreateElement(aTag, aParent, aPosition,
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
nsresult result = CreateTxnForCreateElement(aTag, parent, aPosition,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result))
{
result = DoTransaction(txn);
if (NS_SUCCEEDED(result))
{
result = txn->GetNewNode(aNewNode);
nsCOMPtr<nsINode> newNode;
result = txn->GetNewNode(getter_AddRefs(newNode));
CallQueryInterface(newNode, aNewNode);
NS_ASSERTION((NS_SUCCEEDED(result)), "GetNewNode can't fail if txn::DoTransaction succeeded.");
}
}
@ -1388,8 +1400,8 @@ NS_IMETHODIMP nsEditor::InsertNode(nsIDOMNode * aNode,
nsRefPtr<InsertElementTxn> txn;
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
nsCOMPtr<nsINode> parent = do_QueryInterface(aParent);
nsresult result = CreateTxnForInsertElement(node->AsDOMNode(), parent->AsDOMNode(),
aPosition, getter_AddRefs(txn));
nsresult result = CreateTxnForInsertElement(node, parent, aPosition,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = DoTransaction(txn);
}
@ -1415,13 +1427,16 @@ nsEditor::SplitNode(nsIDOMNode * aNode,
mActionListeners[i]->WillSplitNode(aNode, aOffset);
nsRefPtr<SplitElementTxn> txn;
nsresult result = CreateTxnForSplitNode(aNode, aOffset, getter_AddRefs(txn));
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
nsresult result = CreateTxnForSplitNode(node, aOffset, getter_AddRefs(txn));
if (NS_SUCCEEDED(result))
{
result = DoTransaction(txn);
if (NS_SUCCEEDED(result))
{
result = txn->GetNewNode(aNewLeftNode);
nsCOMPtr<nsINode> leftNode;
result = txn->GetNewNode(getter_AddRefs(leftNode));
CallQueryInterface(leftNode, aNewLeftNode);
NS_ASSERTION((NS_SUCCEEDED(result)), "result must succeeded for GetNewNode");
}
}
@ -1472,13 +1487,15 @@ nsEditor::JoinNodes(nsIDOMNode * aLeftNode,
mActionListeners[i]->WillJoinNodes(aLeftNode, aRightNode, aParent);
nsRefPtr<JoinElementTxn> txn;
result = CreateTxnForJoinNode(aLeftNode, aRightNode, getter_AddRefs(txn));
nsCOMPtr<nsINode> leftNode = do_QueryInterface(aLeftNode);
nsCOMPtr<nsINode> rightNode = do_QueryInterface(aRightNode);
result = CreateTxnForJoinNode(leftNode, rightNode, getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = DoTransaction(txn);
result = DoTransaction(txn);
}
mRangeUpdater.SelAdjJoinNodes(aLeftNode, aRightNode, aParent, offset, (int32_t)oldLeftNodeLen);
for (i = 0; i < mActionListeners.Count(); i++)
mActionListeners[i]->DidJoinNodes(aLeftNode, aRightNode, aParent, result);
@ -2671,7 +2688,7 @@ nsEditor::CreateTxnForDeleteText(nsIDOMCharacterData* aElement,
NS_IMETHODIMP nsEditor::CreateTxnForSplitNode(nsIDOMNode *aNode,
NS_IMETHODIMP nsEditor::CreateTxnForSplitNode(nsINode *aNode,
uint32_t aOffset,
SplitElementTxn **aTxn)
{
@ -2688,8 +2705,8 @@ NS_IMETHODIMP nsEditor::CreateTxnForSplitNode(nsIDOMNode *aNode,
return rv;
}
NS_IMETHODIMP nsEditor::CreateTxnForJoinNode(nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode,
NS_IMETHODIMP nsEditor::CreateTxnForJoinNode(nsINode *aLeftNode,
nsINode *aRightNode,
JoinElementTxn **aTxn)
{
NS_ENSURE_TRUE(aLeftNode && aRightNode, NS_ERROR_NULL_POINTER);
@ -4312,9 +4329,9 @@ nsEditor::DoAfterRedoTransaction()
IncrementModificationCount(1)));
}
NS_IMETHODIMP
nsEditor::CreateTxnForSetAttribute(nsIDOMElement *aElement,
const nsAString& aAttribute,
NS_IMETHODIMP
nsEditor::CreateTxnForSetAttribute(Element *aElement,
const nsAString& aAttribute,
const nsAString& aValue,
ChangeAttributeTxn ** aTxn)
{
@ -4332,8 +4349,8 @@ nsEditor::CreateTxnForSetAttribute(nsIDOMElement *aElement,
}
NS_IMETHODIMP
nsEditor::CreateTxnForRemoveAttribute(nsIDOMElement *aElement,
NS_IMETHODIMP
nsEditor::CreateTxnForRemoveAttribute(Element *aElement,
const nsAString& aAttribute,
ChangeAttributeTxn ** aTxn)
{
@ -4352,7 +4369,7 @@ nsEditor::CreateTxnForRemoveAttribute(nsIDOMElement *aElement,
NS_IMETHODIMP nsEditor::CreateTxnForCreateElement(const nsAString& aTag,
nsIDOMNode *aParent,
nsINode *aParent,
int32_t aPosition,
CreateElementTxn ** aTxn)
{
@ -4370,8 +4387,8 @@ NS_IMETHODIMP nsEditor::CreateTxnForCreateElement(const nsAString& aTag,
}
NS_IMETHODIMP nsEditor::CreateTxnForInsertElement(nsIDOMNode * aNode,
nsIDOMNode * aParent,
NS_IMETHODIMP nsEditor::CreateTxnForInsertElement(nsINode * aNode,
nsINode * aParent,
int32_t aPosition,
InsertElementTxn ** aTxn)
{

View File

@ -264,28 +264,28 @@ protected:
/** create a transaction for setting aAttribute to aValue on aElement
*/
NS_IMETHOD CreateTxnForSetAttribute(nsIDOMElement *aElement,
NS_IMETHOD CreateTxnForSetAttribute(mozilla::dom::Element *aElement,
const nsAString & aAttribute,
const nsAString & aValue,
ChangeAttributeTxn ** aTxn);
/** create a transaction for removing aAttribute on aElement
*/
NS_IMETHOD CreateTxnForRemoveAttribute(nsIDOMElement *aElement,
NS_IMETHOD CreateTxnForRemoveAttribute(mozilla::dom::Element *aElement,
const nsAString & aAttribute,
ChangeAttributeTxn ** aTxn);
/** create a transaction for creating a new child node of aParent of type aTag.
*/
NS_IMETHOD CreateTxnForCreateElement(const nsAString & aTag,
nsIDOMNode *aParent,
nsINode *aParent,
int32_t aPosition,
CreateElementTxn ** aTxn);
/** create a transaction for inserting aNode as a child of aParent.
*/
NS_IMETHOD CreateTxnForInsertElement(nsIDOMNode * aNode,
nsIDOMNode * aParent,
NS_IMETHOD CreateTxnForInsertElement(nsINode * aNode,
nsINode * aParent,
int32_t aOffset,
InsertElementTxn ** aTxn);
@ -350,12 +350,12 @@ protected:
EDirection aDirection,
DeleteTextTxn** aTxn);
NS_IMETHOD CreateTxnForSplitNode(nsIDOMNode *aNode,
NS_IMETHOD CreateTxnForSplitNode(nsINode *aNode,
uint32_t aOffset,
SplitElementTxn **aTxn);
NS_IMETHOD CreateTxnForJoinNode(nsIDOMNode *aLeftNode,
nsIDOMNode *aRightNode,
NS_IMETHOD CreateTxnForJoinNode(nsINode *aLeftNode,
nsINode *aRightNode,
JoinElementTxn **aTxn);
/**