diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index e7faf870666..c29b59b7e7b 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -59,7 +59,6 @@ static PRBool gNoisy = PR_FALSE; static const PRBool gNoisy = PR_FALSE; #endif - nsHTMLEditor::nsHTMLEditor() { // Done in nsEditor @@ -104,12 +103,12 @@ NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell) { NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg"); - nsresult result=NS_ERROR_NULL_POINTER; + nsresult res=NS_ERROR_NULL_POINTER; if ((nsnull!=aDoc) && (nsnull!=aPresShell)) { return nsTextEditor::Init(aDoc, aPresShell); } - return result; + return res; } void nsHTMLEditor::InitRules() @@ -152,7 +151,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert) NS_IMETHODIMP nsHTMLEditor::SetBackgroundColor(const nsString& aColor) { - nsresult result; + nsresult res; NS_ASSERTION(mDoc, "Missing Editor DOM Document"); // TODO: Check selection for Cell, Row, Column or table and do color on appropriate level @@ -160,20 +159,18 @@ NS_IMETHODIMP nsHTMLEditor::SetBackgroundColor(const nsString& aColor) // Set the background color attribute on the body tag nsCOMPtr bodyElement; - result = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); - if (NS_SUCCEEDED(result) && bodyElement) + res = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); + if (NS_SUCCEEDED(res) && bodyElement) { - result = nsEditor::BeginTransaction(); - if (NS_FAILED(result)) { return result; } + nsAutoEditBatch beginBatching(this); bodyElement->SetAttribute("bgcolor", aColor); - nsEditor::EndTransaction(); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::SetBodyAttribute(const nsString& aAttribute, const nsString& aValue) { - nsresult result; + nsresult res; // TODO: Check selection for Cell, Row, Column or table and do color on appropriate level NS_ASSERTION(mDoc, "Missing Editor DOM Document"); @@ -181,44 +178,41 @@ NS_IMETHODIMP nsHTMLEditor::SetBodyAttribute(const nsString& aAttribute, const n // Set the background color attribute on the body tag nsCOMPtr bodyElement; - result = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); - if (NS_SUCCEEDED(result) && bodyElement) + res = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); + if (NS_SUCCEEDED(res) && bodyElement) { - result = nsEditor::BeginTransaction(); - if (NS_FAILED(result)) { return result; } + nsAutoEditBatch beginBatching(this); bodyElement->SetAttribute(aAttribute, aValue); - nsEditor::EndTransaction(); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::InsertBreak() { - nsresult result; + nsresult res; if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } nsCOMPtr selection; PRBool cancel= PR_FALSE; - result = nsEditor::BeginTransaction(); - if (NS_FAILED(result)) { return result; } + nsAutoEditBatch beginBatching(this); // pre-process nsEditor::GetSelection(getter_AddRefs(selection)); nsTextRulesInfo ruleInfo(nsHTMLEditRules::kInsertBreak); - result = mRules->WillDoAction(selection, &ruleInfo, &cancel); - if ((PR_FALSE==cancel) && (NS_SUCCEEDED(result))) + res = mRules->WillDoAction(selection, &ruleInfo, &cancel); + if ((PR_FALSE==cancel) && (NS_SUCCEEDED(res))) { // create the new BR node nsCOMPtr newNode; nsAutoString tag("BR"); - result = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); - if (NS_SUCCEEDED(result) && newNode) + res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); + if (NS_SUCCEEDED(res) && newNode) { // set the selection to the new node nsCOMPtrparent; - result = newNode->GetParentNode(getter_AddRefs(parent)); - if (NS_SUCCEEDED(result) && parent) + res = newNode->GetParentNode(getter_AddRefs(parent)); + if (NS_SUCCEEDED(res) && parent) { PRInt32 offsetInParent=-1; // we use the -1 as a marker to see if we need to compute this or not nsCOMPtrnextNode; @@ -237,14 +231,14 @@ NS_IMETHODIMP nsHTMLEditor::InsertBreak() else { nextNode = do_QueryInterface(newNode); } - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if (NS_SUCCEEDED(result)) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if (NS_SUCCEEDED(res)) { if (-1==offsetInParent) { nextNode->GetParentNode(getter_AddRefs(parent)); - result = GetChildOffset(nextNode, parent, offsetInParent); - if (NS_SUCCEEDED(result)) { + res = GetChildOffset(nextNode, parent, offsetInParent); + if (NS_SUCCEEDED(res)) { selection->Collapse(parent, offsetInParent+1); // +1 to insert just after the break } } @@ -256,11 +250,8 @@ NS_IMETHODIMP nsHTMLEditor::InsertBreak() } } // post-process, always called if WillInsertBreak didn't return cancel==PR_TRUE - result = mRules->DidDoAction(selection, &ruleInfo, result); + res = mRules->DidDoAction(selection, &ruleInfo, res); } - nsresult endTxnResult = nsEditor::EndTransaction(); // don't return this result! - NS_ASSERTION ((NS_SUCCEEDED(endTxnResult)), "bad end transaction result"); - // XXXX: Horrible hack! We are doing this because // of an error in Gecko which is not rendering the // document after a change via the DOM - gpk 2/13/99 @@ -268,26 +259,26 @@ NS_IMETHODIMP nsHTMLEditor::InsertBreak() // HACKForceRedraw(); // END HACK - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::GetParagraphFormat(nsString& aParagraphFormat) { - nsresult result = NS_ERROR_NOT_INITIALIZED; + nsresult res = NS_ERROR_NOT_INITIALIZED; - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::SetParagraphFormat(const nsString& aParagraphFormat) { - nsresult result = NS_ERROR_NOT_INITIALIZED; + nsresult res = NS_ERROR_NOT_INITIALIZED; //Kinda sad to waste memory just to force lower case nsAutoString tag = aParagraphFormat; tag.ToLowerCase(); if (tag == "normal" || tag == "p") { - result = RemoveParagraphStyle(); + res = RemoveParagraphStyle(); } else { - result = ReplaceBlockParent(tag); + res = ReplaceBlockParent(tag); } // XXXX: Horrible hack! We are doing this because @@ -297,7 +288,7 @@ NS_IMETHODIMP nsHTMLEditor::SetParagraphFormat(const nsString& aParagraphFormat) // HACKForceRedraw(); // END HACK - return result; + return res; } @@ -426,11 +417,10 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(const nsString& aCitation) { printf("nsHTMLEditor::PasteAsQuotation\n"); - nsresult res = nsEditor::BeginTransaction(); - + nsAutoEditBatch beginBatching(this); nsCOMPtr newNode; nsAutoString tag("blockquote"); - res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); + nsresult res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); if (NS_FAILED(res) || !newNode) return res; @@ -462,9 +452,6 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(const nsString& aCitation) } res = Paste(); - - nsEditor::EndTransaction(); // don't return this result! - return res; } @@ -479,11 +466,10 @@ NS_IMETHODIMP nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText, { printf("nsHTMLEditor::InsertAsQuotation\n"); - nsresult res = nsEditor::BeginTransaction(); - + nsAutoEditBatch beginBatching(this); nsCOMPtr newNode; nsAutoString tag("blockquote"); - res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); + nsresult res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); if (NS_FAILED(res) || !newNode) return res; @@ -500,17 +486,13 @@ NS_IMETHODIMP nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText, } res = InsertHTML(aQuotedText); - - nsEditor::EndTransaction(); // don't return this result! - return res; } NS_IMETHODIMP nsHTMLEditor::InsertHTML(const nsString& aInputString) { nsresult res; - - nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsEditor::DeleteSelection(nsIEditor::eDoNothing); @@ -527,8 +509,6 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTML(const nsString& aInputString) // XXX How is it that we don't have to release the transaction? } - nsEditor::EndTransaction(); - if (NS_FAILED(res)) printf("Couldn't insert html: error was %d\n", res); @@ -575,10 +555,10 @@ nsHTMLEditor::GetParagraphStyle(nsStringArray *aTagList) if (gNoisy) { printf("---------- nsHTMLEditor::GetParagraphStyle ----------\n"); } if (!aTagList) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(res)) && selection) { nsCOMPtr enumerator; enumerator = do_QueryInterface(selection); @@ -586,30 +566,30 @@ nsHTMLEditor::GetParagraphStyle(nsStringArray *aTagList) { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && (nsnull!=currentItem)) { nsCOMPtr range( do_QueryInterface(currentItem) ); // scan the range for all the independent block content blockSections // and get the block parent of each nsISupportsArray *blockSections; - result = NS_NewISupportsArray(&blockSections); - if ((NS_SUCCEEDED(result)) && blockSections) + res = NS_NewISupportsArray(&blockSections); + if ((NS_SUCCEEDED(res)) && blockSections) { - result = GetBlockSectionsForRange(range, blockSections); - if (NS_SUCCEEDED(result)) + res = GetBlockSectionsForRange(range, blockSections); + if (NS_SUCCEEDED(res)) { nsIDOMRange *subRange; subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); - while (subRange && (NS_SUCCEEDED(result))) + while (subRange && (NS_SUCCEEDED(res))) { nsCOMPtrstartParent; - result = subRange->GetStartParent(getter_AddRefs(startParent)); - if (NS_SUCCEEDED(result) && startParent) + res = subRange->GetStartParent(getter_AddRefs(startParent)); + if (NS_SUCCEEDED(res) && startParent) { nsCOMPtr blockParent; - result = GetBlockParent(startParent, getter_AddRefs(blockParent)); - if (NS_SUCCEEDED(result) && blockParent) + res = GetBlockParent(startParent, getter_AddRefs(blockParent)); + if (NS_SUCCEEDED(res) && blockParent) { nsAutoString blockParentTag; blockParent->GetTagName(blockParentTag); @@ -631,7 +611,7 @@ nsHTMLEditor::GetParagraphStyle(nsStringArray *aTagList) } } - return result; + return res; } // use this when block parents are to be added regardless of current state @@ -645,37 +625,36 @@ nsHTMLEditor::AddBlockParent(nsString& aParentTag) delete [] tag; } - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(res)) && selection) { // set the block parent for all selected ranges - nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsCOMPtr enumerator; enumerator = do_QueryInterface(selection); if (enumerator) { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && (nsnull!=currentItem)) { nsCOMPtr range( do_QueryInterface(currentItem) ); // scan the range for all the independent block content blockSections // and apply the transformation to them - result = ReParentContentOfRange(range, aParentTag, eInsertParent); + res = ReParentContentOfRange(range, aParentTag, eInsertParent); } } - nsEditor::EndTransaction(); - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { // set the selection // XXX: can't do anything until I can create ranges } } if (gNoisy) {printf("Finished nsHTMLEditor::AddBlockParent with this content:\n"); DebugDumpContent(); } // DEBUG - return result; + return res; } // use this when a paragraph type is being transformed from one type to another @@ -690,33 +669,32 @@ nsHTMLEditor::ReplaceBlockParent(nsString& aParentTag) delete [] tag; } - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(res)) && selection) { // set the block parent for all selected ranges - nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsCOMPtr enumerator; enumerator = do_QueryInterface(selection); if (enumerator) { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && (nsnull!=currentItem)) { nsCOMPtr range( do_QueryInterface(currentItem) ); // scan the range for all the independent block content blockSections // and apply the transformation to them - result = ReParentContentOfRange(range, aParentTag, eReplaceParent); + res = ReParentContentOfRange(range, aParentTag, eReplaceParent); } } - nsEditor::EndTransaction(); } if (gNoisy) {printf("Finished nsHTMLEditor::AddBlockParent with this content:\n"); DebugDumpContent(); } // DEBUG - return result; + return res; } NS_IMETHODIMP @@ -734,7 +712,7 @@ nsHTMLEditor::ReParentContentOfNode(nsIDOMNode *aNode, // find the current block parent, or just use aNode if it is a block node nsCOMPtrblockParentElement; nsCOMPtrnodeToReParent; // this is the node we'll operate on, by default it's aNode - nsresult result = aNode->QueryInterface(nsIDOMNode::GetIID(), getter_AddRefs(nodeToReParent)); + nsresult res = aNode->QueryInterface(nsIDOMNode::GetIID(), getter_AddRefs(nodeToReParent)); PRBool nodeIsInline; PRBool nodeIsBlock=PR_FALSE; nsTextEditor::IsNodeInline(aNode, nodeIsInline); @@ -750,18 +728,18 @@ nsHTMLEditor::ReParentContentOfNode(nsIDOMNode *aNode, // if aNode is the block parent, then the node to reparent is one of its children if (PR_TRUE==nodeIsBlock) { - result = aNode->QueryInterface(nsIDOMNode::GetIID(), getter_AddRefs(blockParentElement)); - if (NS_SUCCEEDED(result) && blockParentElement) { - result = aNode->GetFirstChild(getter_AddRefs(nodeToReParent)); + res = aNode->QueryInterface(nsIDOMNode::GetIID(), getter_AddRefs(blockParentElement)); + if (NS_SUCCEEDED(res) && blockParentElement) { + res = aNode->GetFirstChild(getter_AddRefs(nodeToReParent)); } } else { // we just need to get the block parent of aNode - result = nsTextEditor::GetBlockParent(aNode, getter_AddRefs(blockParentElement)); + res = nsTextEditor::GetBlockParent(aNode, getter_AddRefs(blockParentElement)); } - // at this point, we must have a good result, a node to reparent, and a block parent + // at this point, we must have a good res, a node to reparent, and a block parent if (!nodeToReParent) { return NS_ERROR_UNEXPECTED;} if (!blockParentElement) { return NS_ERROR_NULL_POINTER;} - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { nsCOMPtr newParentNode; nsCOMPtr blockParentNode = do_QueryInterface(blockParentElement); @@ -779,17 +757,17 @@ nsHTMLEditor::ReParentContentOfNode(nsIDOMNode *aNode, nsCOMPtr nodeAsText = do_QueryInterface(nodeToReParent); if (nodeAsText) { - result = ReParentBlockContent(nodeToReParent, aParentTag, blockParentNode, parentTag, + res = ReParentBlockContent(nodeToReParent, aParentTag, blockParentNode, parentTag, aTransformation, getter_AddRefs(newParentNode)); } else { // this is the case of an insertion point between 2 non-text objects // XXX: how to you know it's an insertion point??? PRInt32 offsetInParent=0; - result = GetChildOffset(nodeToReParent, blockParentNode, offsetInParent); - NS_ASSERTION((NS_SUCCEEDED(result)), "bad result from GetChildOffset"); + res = GetChildOffset(nodeToReParent, blockParentNode, offsetInParent); + NS_ASSERTION((NS_SUCCEEDED(res)), "bad res from GetChildOffset"); // otherwise, just create the block parent at the selection - result = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, + res = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, getter_AddRefs(newParentNode)); // XXX: need to move some of the children of blockParentNode into the newParentNode? // XXX: need to create a bogus text node inside this new block? @@ -803,15 +781,15 @@ nsHTMLEditor::ReParentContentOfNode(nsIDOMNode *aNode, (eInsertParent==aTransformation)) { if (gNoisy) { DebugDumpContent(); } // DEBUG - result = ReParentBlockContent(nodeToReParent, aParentTag, blockParentNode, parentTag, + res = ReParentBlockContent(nodeToReParent, aParentTag, blockParentNode, parentTag, aTransformation, getter_AddRefs(newParentNode)); - if ((NS_SUCCEEDED(result)) && (newParentNode) && (eReplaceParent==aTransformation)) + if ((NS_SUCCEEDED(res)) && (newParentNode) && (eReplaceParent==aTransformation)) { PRBool hasChildren; blockParentNode->HasChildNodes(&hasChildren); if (PR_FALSE==hasChildren) { - result = nsEditor::DeleteNode(blockParentNode); + res = nsEditor::DeleteNode(blockParentNode); if (gNoisy) { printf("deleted old block parent node %p\n", blockParentNode.get()); @@ -825,7 +803,7 @@ nsHTMLEditor::ReParentContentOfNode(nsIDOMNode *aNode, } } } - return result; + return res; } @@ -843,9 +821,9 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, PRBool removeBreakBefore = PR_FALSE; PRBool removeBreakAfter = PR_FALSE; nsCOMPtrancestor; - nsresult result = aNode->GetParentNode(getter_AddRefs(ancestor)); + nsresult res = aNode->GetParentNode(getter_AddRefs(ancestor)); nsCOMPtrpreviousAncestor = do_QueryInterface(aNode); - while (NS_SUCCEEDED(result) && ancestor) + while (NS_SUCCEEDED(res) && ancestor) { nsCOMPtrancestorElement = do_QueryInterface(ancestor); nsAutoString ancestorTag; @@ -855,14 +833,14 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, break; // previousAncestor will contain the node to operate on } previousAncestor = do_QueryInterface(ancestor); - result = ancestorElement->GetParentNode(getter_AddRefs(ancestor)); + res = ancestorElement->GetParentNode(getter_AddRefs(ancestor)); } // now, previousAncestor is the node we are operating on nsCOMPtrleftNode, rightNode; - result = GetBlockSection(previousAncestor, + res = GetBlockSection(previousAncestor, getter_AddRefs(leftNode), getter_AddRefs(rightNode)); - if ((NS_SUCCEEDED(result)) && leftNode && rightNode) + if ((NS_SUCCEEDED(res)) && leftNode && rightNode) { // determine some state for managing
s around the new block PRBool isSubordinateBlock = PR_FALSE; // if true, the content is already in a subordinate block @@ -886,25 +864,25 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, PRInt32 offsetInParent=0; if (eInsertParent==aTransformation || PR_TRUE==isRootBlock) { - result = GetChildOffset(leftNode, blockParentNode, offsetInParent); - NS_ASSERTION((NS_SUCCEEDED(result)), "bad result from GetChildOffset"); - result = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, aNewParentNode); + res = GetChildOffset(leftNode, blockParentNode, offsetInParent); + NS_ASSERTION((NS_SUCCEEDED(res)), "bad res from GetChildOffset"); + res = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, aNewParentNode); if (gNoisy) { printf("created a node in blockParentNode at offset %d\n", offsetInParent); } } else { nsCOMPtr grandParent; - result = blockParentNode->GetParentNode(getter_AddRefs(grandParent)); - if ((NS_SUCCEEDED(result)) && grandParent) + res = blockParentNode->GetParentNode(getter_AddRefs(grandParent)); + if ((NS_SUCCEEDED(res)) && grandParent) { nsCOMPtrfirstChildNode, lastChildNode; blockParentNode->GetFirstChild(getter_AddRefs(firstChildNode)); blockParentNode->GetLastChild(getter_AddRefs(lastChildNode)); if (firstChildNode==leftNode && lastChildNode==rightNode) { - result = GetChildOffset(blockParentNode, grandParent, offsetInParent); - NS_ASSERTION((NS_SUCCEEDED(result)), "bad result from GetChildOffset"); - result = nsTextEditor::CreateNode(aParentTag, grandParent, offsetInParent, aNewParentNode); + res = GetChildOffset(blockParentNode, grandParent, offsetInParent); + NS_ASSERTION((NS_SUCCEEDED(res)), "bad res from GetChildOffset"); + res = nsTextEditor::CreateNode(aParentTag, grandParent, offsetInParent, aNewParentNode); if (gNoisy) { printf("created a node in grandParent at offset %d\n", offsetInParent); } } else @@ -916,41 +894,41 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, nsCOMPtr newLeftNode; if (firstChildNode!=leftNode) { - result = GetChildOffset(leftNode, blockParentNode, offsetInParent); + res = GetChildOffset(leftNode, blockParentNode, offsetInParent); if (gNoisy) { printf("splitting left at %d\n", offsetInParent); } - result = SplitNode(blockParentNode, offsetInParent, getter_AddRefs(newLeftNode)); + res = SplitNode(blockParentNode, offsetInParent, getter_AddRefs(newLeftNode)); // after this split, blockParentNode still contains leftNode and rightNode } if (lastChildNode!=rightNode) { - result = GetChildOffset(rightNode, blockParentNode, offsetInParent); + res = GetChildOffset(rightNode, blockParentNode, offsetInParent); offsetInParent++; if (gNoisy) { printf("splitting right at %d\n", offsetInParent); } - result = SplitNode(blockParentNode, offsetInParent, getter_AddRefs(newLeftNode)); + res = SplitNode(blockParentNode, offsetInParent, getter_AddRefs(newLeftNode)); blockParentNode = do_QueryInterface(newLeftNode); } - result = GetChildOffset(leftNode, blockParentNode, offsetInParent); - NS_ASSERTION((NS_SUCCEEDED(result)), "bad result from GetChildOffset"); - result = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, aNewParentNode); + res = GetChildOffset(leftNode, blockParentNode, offsetInParent); + NS_ASSERTION((NS_SUCCEEDED(res)), "bad res from GetChildOffset"); + res = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, aNewParentNode); if (gNoisy) { printf("created a node in blockParentNode at offset %d\n", offsetInParent); } // what we need to do here is remove the existing block parent when we're all done. removeBlockParent = PR_TRUE; } } } - if ((NS_SUCCEEDED(result)) && *aNewParentNode) + if ((NS_SUCCEEDED(res)) && *aNewParentNode) { // move all the children/contents of blockParentNode to aNewParentNode nsCOMPtrchildNode = do_QueryInterface(rightNode); nsCOMPtrpreviousSiblingNode; - while (NS_SUCCEEDED(result) && childNode) + while (NS_SUCCEEDED(res) && childNode) { childNode->GetPreviousSibling(getter_AddRefs(previousSiblingNode)); // explicitly delete of childNode from it's current parent // can't just rely on DOM semantics of InsertNode doing the delete implicitly, doesn't undo! - result = nsEditor::DeleteNode(childNode); - if (NS_SUCCEEDED(result)) + res = nsEditor::DeleteNode(childNode); + if (NS_SUCCEEDED(res)) { - result = nsEditor::InsertNode(childNode, *aNewParentNode, 0); + res = nsEditor::InsertNode(childNode, *aNewParentNode, 0); if (gNoisy) { printf("re-parented sibling node %p\n", childNode.get()); @@ -963,12 +941,12 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, } // end while loop } // clean up the surrounding content to maintain vertical whitespace - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { // if the prior node is a
and we did something to change vertical whitespacing, delete the
nsCOMPtr brNode; - result = GetPriorNode(leftNode, PR_TRUE, getter_AddRefs(brNode)); - if (NS_SUCCEEDED(result) && brNode) + res = GetPriorNode(leftNode, PR_TRUE, getter_AddRefs(brNode)); + if (NS_SUCCEEDED(res) && brNode) { nsCOMPtr brContent = do_QueryInterface(brNode); if (brContent) @@ -976,16 +954,16 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, nsCOMPtr brContentTag; brContent->GetTag(*getter_AddRefs(brContentTag)); if (nsIEditProperty::br==brContentTag.get()) { - result = DeleteNode(brNode); + res = DeleteNode(brNode); } } } // if the next node is a
and we did something to change vertical whitespacing, delete the
- if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { - result = GetNextNode(rightNode, PR_TRUE, getter_AddRefs(brNode)); - if (NS_SUCCEEDED(result) && brNode) + res = GetNextNode(rightNode, PR_TRUE, getter_AddRefs(brNode)); + if (NS_SUCCEEDED(res) && brNode) { nsCOMPtr brContent = do_QueryInterface(brNode); if (brContent) @@ -993,44 +971,44 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, nsCOMPtr brContentTag; brContent->GetTag(*getter_AddRefs(brContentTag)); if (nsIEditProperty::br==brContentTag.get()) { - result = DeleteNode(brNode); + res = DeleteNode(brNode); } } } } } - if ((NS_SUCCEEDED(result)) && (PR_TRUE==removeBlockParent)) + if ((NS_SUCCEEDED(res)) && (PR_TRUE==removeBlockParent)) { // we determined we need to remove the previous block parent. Do it! // go through list backwards so deletes don't interfere with the iteration nsCOMPtr childNodes; - result = blockParentNode->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) + res = blockParentNode->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(res)) && (childNodes)) { nsCOMPtrgrandParent; blockParentNode->GetParentNode(getter_AddRefs(grandParent)); PRInt32 offsetInParent; - result = GetChildOffset(blockParentNode, grandParent, offsetInParent); + res = GetChildOffset(blockParentNode, grandParent, offsetInParent); PRUint32 childCount; childNodes->GetLength(&childCount); PRInt32 i=childCount-1; - for ( ; ((NS_SUCCEEDED(result)) && (0<=i)); i--) + for ( ; ((NS_SUCCEEDED(res)) && (0<=i)); i--) { nsCOMPtr childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) + res = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(res)) && (childNode)) { - result = nsTextEditor::DeleteNode(childNode); - if (NS_SUCCEEDED(result)) { - result = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); + res = nsTextEditor::DeleteNode(childNode); + if (NS_SUCCEEDED(res)) { + res = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); } } } if (gNoisy) { printf("removing the old block parent %p\n", blockParentNode.get()); } - result = nsTextEditor::DeleteNode(blockParentNode); + res = nsTextEditor::DeleteNode(blockParentNode); } } } - return result; + return res; } NS_IMETHODIMP @@ -1039,24 +1017,24 @@ nsHTMLEditor::ReParentContentOfRange(nsIDOMRange *aRange, BlockTransformationType aTranformation) { if (!aRange) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsISupportsArray *blockSections; - result = NS_NewISupportsArray(&blockSections); - if ((NS_SUCCEEDED(result)) && blockSections) + res = NS_NewISupportsArray(&blockSections); + if ((NS_SUCCEEDED(res)) && blockSections) { - result = GetBlockSectionsForRange(aRange, blockSections); - if (NS_SUCCEEDED(result)) + res = GetBlockSectionsForRange(aRange, blockSections); + if (NS_SUCCEEDED(res)) { nsIDOMRange *subRange; subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); - while (subRange && (NS_SUCCEEDED(result))) + while (subRange && (NS_SUCCEEDED(res))) { nsCOMPtrstartParent; - result = subRange->GetStartParent(getter_AddRefs(startParent)); - if (NS_SUCCEEDED(result) && startParent) + res = subRange->GetStartParent(getter_AddRefs(startParent)); + if (NS_SUCCEEDED(res) && startParent) { if (gNoisy) { printf("ReParentContentOfRange calling ReParentContentOfNode\n"); } - result = ReParentContentOfNode(startParent, aParentTag, aTranformation); + res = ReParentContentOfNode(startParent, aParentTag, aTranformation); } NS_RELEASE(subRange); blockSections->RemoveElementAt(0); @@ -1065,7 +1043,7 @@ nsHTMLEditor::ReParentContentOfRange(nsIDOMRange *aRange, } NS_RELEASE(blockSections); } - return result; + return res; } NS_IMETHODIMP @@ -1075,47 +1053,46 @@ nsHTMLEditor::RemoveParagraphStyle() printf("---------- nsHTMLEditor::RemoveParagraphStyle ----------\n"); } - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(res)) && selection) { - nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsCOMPtr enumerator; enumerator = do_QueryInterface(selection); if (enumerator) { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && (nsnull!=currentItem)) { nsCOMPtr range( do_QueryInterface(currentItem) ); - result = RemoveParagraphStyleFromRange(range); + res = RemoveParagraphStyleFromRange(range); } } - nsEditor::EndTransaction(); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::RemoveParagraphStyleFromRange(nsIDOMRange *aRange) { if (!aRange) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsISupportsArray *blockSections; - result = NS_NewISupportsArray(&blockSections); - if ((NS_SUCCEEDED(result)) && blockSections) + res = NS_NewISupportsArray(&blockSections); + if ((NS_SUCCEEDED(res)) && blockSections) { - result = GetBlockSectionsForRange(aRange, blockSections); - if (NS_SUCCEEDED(result)) + res = GetBlockSectionsForRange(aRange, blockSections); + if (NS_SUCCEEDED(res)) { nsIDOMRange *subRange; subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); - while (subRange && (NS_SUCCEEDED(result))) + while (subRange && (NS_SUCCEEDED(res))) { - result = RemoveParagraphStyleFromBlockContent(subRange); + res = RemoveParagraphStyleFromBlockContent(subRange); NS_RELEASE(subRange); blockSections->RemoveElementAt(0); subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); @@ -1123,19 +1100,19 @@ nsHTMLEditor::RemoveParagraphStyleFromRange(nsIDOMRange *aRange) } NS_RELEASE(blockSections); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::RemoveParagraphStyleFromBlockContent(nsIDOMRange *aRange) { if (!aRange) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsCOMPtrstartParent; aRange->GetStartParent(getter_AddRefs(startParent)); nsCOMPtrblockParentElement; - result = nsTextEditor::GetBlockParent(startParent, getter_AddRefs(blockParentElement)); - while ((NS_SUCCEEDED(result)) && blockParentElement) + res = nsTextEditor::GetBlockParent(startParent, getter_AddRefs(blockParentElement)); + while ((NS_SUCCEEDED(res)) && blockParentElement) { nsAutoString blockParentTag; blockParentElement->GetTagName(blockParentTag); @@ -1148,36 +1125,36 @@ nsHTMLEditor::RemoveParagraphStyleFromBlockContent(nsIDOMRange *aRange) { // go through list backwards so deletes don't interfere with the iteration nsCOMPtr childNodes; - result = blockParentElement->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) + res = blockParentElement->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(res)) && (childNodes)) { nsCOMPtrgrandParent; blockParentElement->GetParentNode(getter_AddRefs(grandParent)); PRInt32 offsetInParent; - result = GetChildOffset(blockParentElement, grandParent, offsetInParent); + res = GetChildOffset(blockParentElement, grandParent, offsetInParent); PRUint32 childCount; childNodes->GetLength(&childCount); PRInt32 i=childCount-1; - for ( ; ((NS_SUCCEEDED(result)) && (0<=i)); i--) + for ( ; ((NS_SUCCEEDED(res)) && (0<=i)); i--) { nsCOMPtr childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) + res = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(res)) && (childNode)) { - result = nsTextEditor::DeleteNode(childNode); - if (NS_SUCCEEDED(result)) { - result = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); + res = nsTextEditor::DeleteNode(childNode); + if (NS_SUCCEEDED(res)) { + res = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); } } } - if (NS_SUCCEEDED(result)) { - result = nsTextEditor::DeleteNode(blockParentElement); + if (NS_SUCCEEDED(res)) { + res = nsTextEditor::DeleteNode(blockParentElement); } } } - result = nsTextEditor::GetBlockParent(startParent, getter_AddRefs(blockParentElement)); + res = nsTextEditor::GetBlockParent(startParent, getter_AddRefs(blockParentElement)); } - return result; + return res; } @@ -1188,47 +1165,46 @@ nsHTMLEditor::RemoveParent(const nsString &aParentTag) printf("---------- nsHTMLEditor::RemoveParent ----------\n"); } - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(res)) && selection) { - nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsCOMPtr enumerator; enumerator = do_QueryInterface(selection); if (enumerator) { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && (nsnull!=currentItem)) { nsCOMPtr range( do_QueryInterface(currentItem) ); - result = RemoveParentFromRange(aParentTag, range); + res = RemoveParentFromRange(aParentTag, range); } } - nsEditor::EndTransaction(); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::RemoveParentFromRange(const nsString &aParentTag, nsIDOMRange *aRange) { if (!aRange) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsISupportsArray *blockSections; - result = NS_NewISupportsArray(&blockSections); - if ((NS_SUCCEEDED(result)) && blockSections) + res = NS_NewISupportsArray(&blockSections); + if ((NS_SUCCEEDED(res)) && blockSections) { - result = GetBlockSectionsForRange(aRange, blockSections); - if (NS_SUCCEEDED(result)) + res = GetBlockSectionsForRange(aRange, blockSections); + if (NS_SUCCEEDED(res)) { nsIDOMRange *subRange; subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); - while (subRange && (NS_SUCCEEDED(result))) + while (subRange && (NS_SUCCEEDED(res))) { - result = RemoveParentFromBlockContent(aParentTag, subRange); + res = RemoveParentFromBlockContent(aParentTag, subRange); NS_RELEASE(subRange); blockSections->RemoveElementAt(0); subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); @@ -1236,22 +1212,22 @@ nsHTMLEditor::RemoveParentFromRange(const nsString &aParentTag, nsIDOMRange *aRa } NS_RELEASE(blockSections); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::RemoveParentFromBlockContent(const nsString &aParentTag, nsIDOMRange *aRange) { if (!aRange) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsCOMPtrstartParent; - result = aRange->GetStartParent(getter_AddRefs(startParent)); - if ((NS_SUCCEEDED(result)) && startParent) + res = aRange->GetStartParent(getter_AddRefs(startParent)); + if ((NS_SUCCEEDED(res)) && startParent) { nsCOMPtrparentNode; nsCOMPtrparentElement; - result = startParent->GetParentNode(getter_AddRefs(parentNode)); - while ((NS_SUCCEEDED(result)) && parentNode) + res = startParent->GetParentNode(getter_AddRefs(parentNode)); + while ((NS_SUCCEEDED(res)) && parentNode) { parentElement = do_QueryInterface(parentNode); nsAutoString parentTag; @@ -1262,30 +1238,30 @@ nsHTMLEditor::RemoveParentFromBlockContent(const nsString &aParentTag, nsIDOMRan { // go through list backwards so deletes don't interfere with the iteration nsCOMPtr childNodes; - result = parentElement->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) + res = parentElement->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(res)) && (childNodes)) { nsCOMPtrgrandParent; parentElement->GetParentNode(getter_AddRefs(grandParent)); PRInt32 offsetInParent; - result = GetChildOffset(parentElement, grandParent, offsetInParent); + res = GetChildOffset(parentElement, grandParent, offsetInParent); PRUint32 childCount; childNodes->GetLength(&childCount); PRInt32 i=childCount-1; - for ( ; ((NS_SUCCEEDED(result)) && (0<=i)); i--) + for ( ; ((NS_SUCCEEDED(res)) && (0<=i)); i--) { nsCOMPtr childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) + res = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(res)) && (childNode)) { - result = nsTextEditor::DeleteNode(childNode); - if (NS_SUCCEEDED(result)) { - result = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); + res = nsTextEditor::DeleteNode(childNode); + if (NS_SUCCEEDED(res)) { + res = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); } } } - if (NS_SUCCEEDED(result)) { - result = nsTextEditor::DeleteNode(parentElement); + if (NS_SUCCEEDED(res)) { + res = nsTextEditor::DeleteNode(parentElement); } } break; @@ -1293,10 +1269,10 @@ nsHTMLEditor::RemoveParentFromBlockContent(const nsString &aParentTag, nsIDOMRan else if (PR_TRUE==isRoot) { // hit a local root node, terminate loop break; } - result = parentElement->GetParentNode(getter_AddRefs(parentNode)); + res = parentElement->GetParentNode(getter_AddRefs(parentNode)); } } - return result; + return res; } @@ -1304,37 +1280,22 @@ nsHTMLEditor::RemoveParentFromBlockContent(const nsString &aParentTag, nsIDOMRan NS_IMETHODIMP nsHTMLEditor::Indent(const nsString& aIndent) { - nsresult res = nsEditor::BeginTransaction(); - if (NS_FAILED(res)) return res; - + nsAutoEditBatch beginBatching(this); nsCOMPtr node; PRInt32 offset; // Find out if the selection is collapsed: nsCOMPtr selection; - res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res) || !selection) - { - // my kingdom for exceptions - nsEditor::EndTransaction(); - return res; - } + nsresult res = GetSelection(getter_AddRefs(selection)); + if (NS_FAILED(res) || !selection) return res; PRBool isCollapsed; res = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; res = GetStartNodeAndOffset(selection, &node, &offset); if (!node) res = NS_ERROR_FAILURE; - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; nsAutoString inward("indent"); if (aIndent == inward) @@ -1350,11 +1311,7 @@ nsHTMLEditor::Indent(const nsString& aIndent) while ( !CanContainTag(parent, bq)) { parent->GetParentNode(getter_AddRefs(tmp)); - if (!tmp) - { - nsEditor::EndTransaction(); - return NS_ERROR_FAILURE; - } + if (!tmp) return NS_ERROR_FAILURE; topChild = parent; parent = tmp; } @@ -1363,11 +1320,7 @@ nsHTMLEditor::Indent(const nsString& aIndent) { // we need to split up to the child of parent res = SplitNodeDeep(topChild, node, offset); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // topChild already went to the right on the split // so we don't need to add one to offset when figuring // out where to plop list @@ -1377,43 +1330,21 @@ nsHTMLEditor::Indent(const nsString& aIndent) // make a blockquote nsCOMPtr newBQ; res = CreateNode(bq, parent, offset, getter_AddRefs(newBQ)); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // put a space in it so layout will draw the list item res = selection->Collapse(newBQ,0); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; nsAutoString theText(" "); res = InsertText(theText); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // reposition selection to before the space character res = GetStartNodeAndOffset(selection, &node, &offset); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; res = selection->Collapse(node,0); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; } } - nsEditor::EndTransaction(); // don't return this result! - return NS_OK; } @@ -1422,37 +1353,22 @@ nsHTMLEditor::Indent(const nsString& aIndent) NS_IMETHODIMP nsHTMLEditor::Align(const nsString& aAlignType) { - nsresult res = nsEditor::BeginTransaction(); - if (NS_FAILED(res)) return res; - + nsAutoEditBatch beginBatching(this); nsCOMPtr node; PRInt32 offset; // Find out if the selection is collapsed: nsCOMPtr selection; - res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res) || !selection) - { - // my kingdom for exceptions - nsEditor::EndTransaction(); - return res; - } + nsresult res = GetSelection(getter_AddRefs(selection)); + if (NS_FAILED(res) || !selection) return res; PRBool isCollapsed; res = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; res = GetStartNodeAndOffset(selection, &node, &offset); if (!node) res = NS_ERROR_FAILURE; - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; nsAutoString leftStr("left"); if (aAlignType == leftStr) @@ -1464,8 +1380,6 @@ nsHTMLEditor::Align(const nsString& aAlignType) } } - nsEditor::EndTransaction(); // don't return this result! - return NS_OK; } @@ -1473,37 +1387,33 @@ nsHTMLEditor::Align(const nsString& aAlignType) NS_IMETHODIMP nsHTMLEditor::InsertList(const nsString& aListType) { - nsresult res = nsEditor::BeginTransaction(); - if (NS_FAILED(res)) return res; + nsresult res; + if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } + + nsCOMPtr selection; + PRBool cancel= PR_FALSE; + + nsAutoEditBatch beginBatching(this); + + // pre-process + nsEditor::GetSelection(getter_AddRefs(selection)); + nsTextRulesInfo ruleInfo(nsHTMLEditRules::kMakeList); + res = mRules->WillDoAction(selection, &ruleInfo, &cancel); + if (cancel || (NS_FAILED(res))) return res; // Find out if the selection is collapsed: - nsCOMPtr selection; - res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res) || !selection) - { - // my kingdom for exceptions - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res) || !selection) return res; PRBool isCollapsed; res = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; nsCOMPtr node; PRInt32 offset; res = GetStartNodeAndOffset(selection, &node, &offset); if (!node) res = NS_ERROR_FAILURE; - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; if (isCollapsed) { @@ -1515,11 +1425,7 @@ nsHTMLEditor::InsertList(const nsString& aListType) while ( !CanContainTag(parent, aListType)) { parent->GetParentNode(getter_AddRefs(tmp)); - if (!tmp) - { - nsEditor::EndTransaction(); - return NS_ERROR_FAILURE; - } + if (!tmp) return NS_ERROR_FAILURE; topChild = parent; parent = tmp; } @@ -1528,11 +1434,7 @@ nsHTMLEditor::InsertList(const nsString& aListType) { // we need to split up to the child of parent res = SplitNodeDeep(topChild, node, offset); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // topChild already went to the right on the split // so we don't need to add one to offset when figuring // out where to plop list @@ -1542,49 +1444,24 @@ nsHTMLEditor::InsertList(const nsString& aListType) // make a list nsCOMPtr newList; res = CreateNode(aListType, parent, offset, getter_AddRefs(newList)); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // make a list item nsAutoString tag("li"); nsCOMPtr newItem; res = CreateNode(tag, newList, 0, getter_AddRefs(newItem)); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // put a space in it so layout will draw the list item res = selection->Collapse(newItem,0); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; nsAutoString theText(" "); res = InsertText(theText); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // reposition selection to before the space character res = GetStartNodeAndOffset(selection, &node, &offset); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; res = selection->Collapse(node,0); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; } - nsEditor::EndTransaction(); // don't return this result! return NS_OK; } @@ -1592,11 +1469,11 @@ nsHTMLEditor::InsertList(const nsString& aListType) NS_IMETHODIMP nsHTMLEditor::InsertLink(nsString& aURL) { - nsresult res = nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); // Find out if the selection is collapsed: nsCOMPtr selection; - res = GetSelection(getter_AddRefs(selection)); + nsresult res = GetSelection(getter_AddRefs(selection)); if (NS_FAILED(res) || !selection) { #ifdef DEBUG_akkana @@ -1673,8 +1550,6 @@ nsHTMLEditor::InsertLink(nsString& aURL) (void) InsertText(link); // ignore return value -- we don't care } - nsEditor::EndTransaction(); // don't return this result! - return NS_OK; } @@ -1729,7 +1604,7 @@ nsHTMLEditor::InsertImage(nsString& aURL, // Now we're ready to insert the new image node: // Starting now, don't return without ending the transaction! // - (void)nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsCOMPtr parentNode; PRInt32 offsetOfNewNode; @@ -1741,8 +1616,6 @@ nsHTMLEditor::InsertImage(nsString& aURL, res = InsertNode(newNode, parentNode, offsetOfNewNode); } - (void)nsEditor::EndTransaction(); // don't return this result! - return res; } @@ -1760,12 +1633,12 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu //Note that this doesn't need to go through the transaction system - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; PRBool first=PR_TRUE; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result) || !selection) - return result; + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if (NS_FAILED(res) || !selection) + return res; PRBool isCollapsed; selection->GetIsCollapsed(&isCollapsed); @@ -1781,20 +1654,20 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && currentItem) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && currentItem) { nsCOMPtr range( do_QueryInterface(currentItem) ); nsCOMPtr iter; - result = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull, + res = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull, nsIContentIterator::GetIID(), getter_AddRefs(iter)); - if ((NS_SUCCEEDED(result)) && iter) + if ((NS_SUCCEEDED(res)) && iter) { iter->Init(range); // loop through the content iterator for each content node nsCOMPtr content; - result = iter->CurrentNode(getter_AddRefs(content)); + res = iter->CurrentNode(getter_AddRefs(content)); PRBool bOtherNodeTypeFound = PR_FALSE; while (NS_COMFALSE == iter->IsDone()) @@ -1847,8 +1720,8 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu nsCOMPtr current = do_QueryInterface(selectedElement); PRBool notDone = PR_TRUE; do { - result = current->GetParentNode(getter_AddRefs(parent)); - notDone = NS_SUCCEEDED(result) && parent != nsnull; + res = current->GetParentNode(getter_AddRefs(parent)); + notDone = NS_SUCCEEDED(res) && parent != nsnull; if(notDone) { nsString tmpText; @@ -1894,13 +1767,13 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu *aReturn = selectedElement; } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn) { - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; if (aReturn) *aReturn = nsnull; @@ -1923,8 +1796,8 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* // go through the transaction system nsCOMPtrnewElement; - result = mDoc->CreateElement(realTagName, getter_AddRefs(newElement)); - if (NS_FAILED(result) || !newElement) + res = mDoc->CreateElement(realTagName, getter_AddRefs(newElement)); + if (NS_FAILED(res) || !newElement) return NS_ERROR_FAILURE; @@ -1938,27 +1811,25 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* } // ADD OTHER DEFAULT ATTRIBUTES HERE - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { *aReturn = newElement; } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn) { - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; if (aReturn) *aReturn = nsnull; if (!aElement || !aReturn) return NS_ERROR_NULL_POINTER; - result = nsEditor::BeginTransaction(); - if (NS_FAILED(result)) - return result; + nsAutoEditBatch beginBatching(this); nsCOMPtr parentSelectedNode; PRInt32 offsetOfNewNode; @@ -1976,22 +1847,21 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, ns } DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, offsetOfNewNode); - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { nsCOMPtr newNode = do_QueryInterface(aElement); - result = InsertNode(aElement, parentSelectedNode, offsetOfNewNode); + res = InsertNode(aElement, parentSelectedNode, offsetOfNewNode); } - (void)nsEditor::EndTransaction(); - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { - nsresult result=NS_ERROR_NULL_POINTER; + nsresult res=NS_ERROR_NULL_POINTER; nsCOMPtr selection; // DON'T RETURN EXCEPT AT THE END -- WE NEED TO RELEASE THE aAnchorElement @@ -1999,19 +1869,19 @@ nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) goto DELETE_ANCHOR; // We must have a real selection - result = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result) || !selection) + res = GetSelection(getter_AddRefs(selection)); + if (NS_FAILED(res) || !selection) goto DELETE_ANCHOR; PRBool isCollapsed; - result = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(result)) + res = selection->GetIsCollapsed(&isCollapsed); + if (NS_FAILED(res)) isCollapsed = PR_TRUE; if (isCollapsed) { printf("InsertLinkAroundSelection called but there is no selection!!!\n"); - result = NS_OK; + res = NS_OK; } else { // Be sure we were given an anchor element @@ -2021,16 +1891,12 @@ nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) nsAutoString href; if (NS_SUCCEEDED(anchor->GetHref(href)) && href.GetUnicode() && href.Length() > 0) { - result = nsEditor::BeginTransaction(); - if (NS_SUCCEEDED(result)) - { - const nsString attribute("href"); - SetTextProperty(nsIEditProperty::a, &attribute, &href); - //TODO: Enumerate through other properties of the anchor tag - // and set those as well. - // Optimization: Modify SetTextProperty to set all attributes at once? - } - (void)nsEditor::EndTransaction(); + nsAutoEditBatch beginBatching(this); + const nsString attribute("href"); + SetTextProperty(nsIEditProperty::a, &attribute, &href); + //TODO: Enumerate through other properties of the anchor tag + // and set those as well. + // Optimization: Modify SetTextProperty to set all attributes at once? } } } @@ -2040,7 +1906,7 @@ DELETE_ANCHOR: // so shouldn't we have to do this here? // It crashes in JavaScript if we do this! //NS_RELEASE(aAnchorElement); - return result; + return res; } PRBool nsHTMLEditor::IsElementInBody(nsIDOMElement* aElement) @@ -2048,8 +1914,8 @@ PRBool nsHTMLEditor::IsElementInBody(nsIDOMElement* aElement) if ( aElement ) { nsIDOMElement* bodyElement = nsnull; - nsresult result = nsEditor::GetBodyElement(&bodyElement); - if (NS_SUCCEEDED(result) && bodyElement) + nsresult res = nsEditor::GetBodyElement(&bodyElement); + if (NS_SUCCEEDED(res) && bodyElement) { nsCOMPtr parent; nsCOMPtr currentElement = do_QueryInterface(aElement); @@ -2074,23 +1940,23 @@ PRBool nsHTMLEditor::IsElementInBody(nsIDOMElement* aElement) NS_IMETHODIMP nsHTMLEditor::SelectElement(nsIDOMElement* aElement) { - nsresult result = NS_ERROR_NULL_POINTER; + nsresult res = NS_ERROR_NULL_POINTER; // Must be sure that element is contained in the document body if (IsElementInBody(aElement)) { nsCOMPtr selection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if (NS_SUCCEEDED(result) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if (NS_SUCCEEDED(res) && selection) { nsCOMPtrparent; - result = aElement->GetParentNode(getter_AddRefs(parent)); - if (NS_SUCCEEDED(result) && parent) + res = aElement->GetParentNode(getter_AddRefs(parent)); + if (NS_SUCCEEDED(res) && parent) { PRInt32 offsetInParent; - result = GetChildOffset(aElement, parent, offsetInParent); + res = GetChildOffset(aElement, parent, offsetInParent); - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { // Collapse selection to just before desired element, selection->Collapse(parent, offsetInParent); @@ -2100,29 +1966,29 @@ nsHTMLEditor::SelectElement(nsIDOMElement* aElement) } } } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) { - nsresult result = NS_ERROR_NULL_POINTER; + nsresult res = NS_ERROR_NULL_POINTER; // Must be sure that element is contained in the document body if (IsElementInBody(aElement)) { nsCOMPtr selection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if (NS_SUCCEEDED(result) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if (NS_SUCCEEDED(res) && selection) { nsCOMPtrparent; - result = aElement->GetParentNode(getter_AddRefs(parent)); - if (NS_SUCCEEDED(result) && parent) + res = aElement->GetParentNode(getter_AddRefs(parent)); + if (NS_SUCCEEDED(res) && parent) { PRInt32 offsetInParent; - result = GetChildOffset(aElement, parent, offsetInParent); + res = GetChildOffset(aElement, parent, offsetInParent); - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { // Collapse selection to just after desired element, selection->Collapse(parent, offsetInParent+1); @@ -2130,7 +1996,7 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) } } } - return result; + return res; } @@ -2274,12 +2140,12 @@ NS_IMETHODIMP nsHTMLEditor::GetLocalFileURL(nsIDOMWindow* aParent, const nsStrin // TODO: GET THE DEFAULT DIRECTORY FOR DIFFERENT TYPES FROM PREFERENCES nsFileSpec aDisplayDirectory; - nsresult result = nsComponentManager::CreateInstance(kFileWidgetCID, + nsresult res = nsComponentManager::CreateInstance(kFileWidgetCID, nsnull, nsIFileWidget::GetIID(), (void**)&fileWidget); - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { nsFileDlgResults dialogResult; if (htmlFilter) @@ -2310,7 +2176,7 @@ NS_IMETHODIMP nsHTMLEditor::GetLocalFileURL(nsIDOMWindow* aParent, const nsStrin fileWidget->GetDisplayDirectory(aDisplayDirectory); } - return result; + return res; } NS_IMETHODIMP diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index e7faf870666..c29b59b7e7b 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -59,7 +59,6 @@ static PRBool gNoisy = PR_FALSE; static const PRBool gNoisy = PR_FALSE; #endif - nsHTMLEditor::nsHTMLEditor() { // Done in nsEditor @@ -104,12 +103,12 @@ NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell) { NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg"); - nsresult result=NS_ERROR_NULL_POINTER; + nsresult res=NS_ERROR_NULL_POINTER; if ((nsnull!=aDoc) && (nsnull!=aPresShell)) { return nsTextEditor::Init(aDoc, aPresShell); } - return result; + return res; } void nsHTMLEditor::InitRules() @@ -152,7 +151,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert) NS_IMETHODIMP nsHTMLEditor::SetBackgroundColor(const nsString& aColor) { - nsresult result; + nsresult res; NS_ASSERTION(mDoc, "Missing Editor DOM Document"); // TODO: Check selection for Cell, Row, Column or table and do color on appropriate level @@ -160,20 +159,18 @@ NS_IMETHODIMP nsHTMLEditor::SetBackgroundColor(const nsString& aColor) // Set the background color attribute on the body tag nsCOMPtr bodyElement; - result = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); - if (NS_SUCCEEDED(result) && bodyElement) + res = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); + if (NS_SUCCEEDED(res) && bodyElement) { - result = nsEditor::BeginTransaction(); - if (NS_FAILED(result)) { return result; } + nsAutoEditBatch beginBatching(this); bodyElement->SetAttribute("bgcolor", aColor); - nsEditor::EndTransaction(); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::SetBodyAttribute(const nsString& aAttribute, const nsString& aValue) { - nsresult result; + nsresult res; // TODO: Check selection for Cell, Row, Column or table and do color on appropriate level NS_ASSERTION(mDoc, "Missing Editor DOM Document"); @@ -181,44 +178,41 @@ NS_IMETHODIMP nsHTMLEditor::SetBodyAttribute(const nsString& aAttribute, const n // Set the background color attribute on the body tag nsCOMPtr bodyElement; - result = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); - if (NS_SUCCEEDED(result) && bodyElement) + res = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); + if (NS_SUCCEEDED(res) && bodyElement) { - result = nsEditor::BeginTransaction(); - if (NS_FAILED(result)) { return result; } + nsAutoEditBatch beginBatching(this); bodyElement->SetAttribute(aAttribute, aValue); - nsEditor::EndTransaction(); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::InsertBreak() { - nsresult result; + nsresult res; if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } nsCOMPtr selection; PRBool cancel= PR_FALSE; - result = nsEditor::BeginTransaction(); - if (NS_FAILED(result)) { return result; } + nsAutoEditBatch beginBatching(this); // pre-process nsEditor::GetSelection(getter_AddRefs(selection)); nsTextRulesInfo ruleInfo(nsHTMLEditRules::kInsertBreak); - result = mRules->WillDoAction(selection, &ruleInfo, &cancel); - if ((PR_FALSE==cancel) && (NS_SUCCEEDED(result))) + res = mRules->WillDoAction(selection, &ruleInfo, &cancel); + if ((PR_FALSE==cancel) && (NS_SUCCEEDED(res))) { // create the new BR node nsCOMPtr newNode; nsAutoString tag("BR"); - result = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); - if (NS_SUCCEEDED(result) && newNode) + res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); + if (NS_SUCCEEDED(res) && newNode) { // set the selection to the new node nsCOMPtrparent; - result = newNode->GetParentNode(getter_AddRefs(parent)); - if (NS_SUCCEEDED(result) && parent) + res = newNode->GetParentNode(getter_AddRefs(parent)); + if (NS_SUCCEEDED(res) && parent) { PRInt32 offsetInParent=-1; // we use the -1 as a marker to see if we need to compute this or not nsCOMPtrnextNode; @@ -237,14 +231,14 @@ NS_IMETHODIMP nsHTMLEditor::InsertBreak() else { nextNode = do_QueryInterface(newNode); } - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if (NS_SUCCEEDED(result)) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if (NS_SUCCEEDED(res)) { if (-1==offsetInParent) { nextNode->GetParentNode(getter_AddRefs(parent)); - result = GetChildOffset(nextNode, parent, offsetInParent); - if (NS_SUCCEEDED(result)) { + res = GetChildOffset(nextNode, parent, offsetInParent); + if (NS_SUCCEEDED(res)) { selection->Collapse(parent, offsetInParent+1); // +1 to insert just after the break } } @@ -256,11 +250,8 @@ NS_IMETHODIMP nsHTMLEditor::InsertBreak() } } // post-process, always called if WillInsertBreak didn't return cancel==PR_TRUE - result = mRules->DidDoAction(selection, &ruleInfo, result); + res = mRules->DidDoAction(selection, &ruleInfo, res); } - nsresult endTxnResult = nsEditor::EndTransaction(); // don't return this result! - NS_ASSERTION ((NS_SUCCEEDED(endTxnResult)), "bad end transaction result"); - // XXXX: Horrible hack! We are doing this because // of an error in Gecko which is not rendering the // document after a change via the DOM - gpk 2/13/99 @@ -268,26 +259,26 @@ NS_IMETHODIMP nsHTMLEditor::InsertBreak() // HACKForceRedraw(); // END HACK - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::GetParagraphFormat(nsString& aParagraphFormat) { - nsresult result = NS_ERROR_NOT_INITIALIZED; + nsresult res = NS_ERROR_NOT_INITIALIZED; - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::SetParagraphFormat(const nsString& aParagraphFormat) { - nsresult result = NS_ERROR_NOT_INITIALIZED; + nsresult res = NS_ERROR_NOT_INITIALIZED; //Kinda sad to waste memory just to force lower case nsAutoString tag = aParagraphFormat; tag.ToLowerCase(); if (tag == "normal" || tag == "p") { - result = RemoveParagraphStyle(); + res = RemoveParagraphStyle(); } else { - result = ReplaceBlockParent(tag); + res = ReplaceBlockParent(tag); } // XXXX: Horrible hack! We are doing this because @@ -297,7 +288,7 @@ NS_IMETHODIMP nsHTMLEditor::SetParagraphFormat(const nsString& aParagraphFormat) // HACKForceRedraw(); // END HACK - return result; + return res; } @@ -426,11 +417,10 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(const nsString& aCitation) { printf("nsHTMLEditor::PasteAsQuotation\n"); - nsresult res = nsEditor::BeginTransaction(); - + nsAutoEditBatch beginBatching(this); nsCOMPtr newNode; nsAutoString tag("blockquote"); - res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); + nsresult res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); if (NS_FAILED(res) || !newNode) return res; @@ -462,9 +452,6 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(const nsString& aCitation) } res = Paste(); - - nsEditor::EndTransaction(); // don't return this result! - return res; } @@ -479,11 +466,10 @@ NS_IMETHODIMP nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText, { printf("nsHTMLEditor::InsertAsQuotation\n"); - nsresult res = nsEditor::BeginTransaction(); - + nsAutoEditBatch beginBatching(this); nsCOMPtr newNode; nsAutoString tag("blockquote"); - res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); + nsresult res = nsEditor::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); if (NS_FAILED(res) || !newNode) return res; @@ -500,17 +486,13 @@ NS_IMETHODIMP nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText, } res = InsertHTML(aQuotedText); - - nsEditor::EndTransaction(); // don't return this result! - return res; } NS_IMETHODIMP nsHTMLEditor::InsertHTML(const nsString& aInputString) { nsresult res; - - nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsEditor::DeleteSelection(nsIEditor::eDoNothing); @@ -527,8 +509,6 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTML(const nsString& aInputString) // XXX How is it that we don't have to release the transaction? } - nsEditor::EndTransaction(); - if (NS_FAILED(res)) printf("Couldn't insert html: error was %d\n", res); @@ -575,10 +555,10 @@ nsHTMLEditor::GetParagraphStyle(nsStringArray *aTagList) if (gNoisy) { printf("---------- nsHTMLEditor::GetParagraphStyle ----------\n"); } if (!aTagList) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(res)) && selection) { nsCOMPtr enumerator; enumerator = do_QueryInterface(selection); @@ -586,30 +566,30 @@ nsHTMLEditor::GetParagraphStyle(nsStringArray *aTagList) { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && (nsnull!=currentItem)) { nsCOMPtr range( do_QueryInterface(currentItem) ); // scan the range for all the independent block content blockSections // and get the block parent of each nsISupportsArray *blockSections; - result = NS_NewISupportsArray(&blockSections); - if ((NS_SUCCEEDED(result)) && blockSections) + res = NS_NewISupportsArray(&blockSections); + if ((NS_SUCCEEDED(res)) && blockSections) { - result = GetBlockSectionsForRange(range, blockSections); - if (NS_SUCCEEDED(result)) + res = GetBlockSectionsForRange(range, blockSections); + if (NS_SUCCEEDED(res)) { nsIDOMRange *subRange; subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); - while (subRange && (NS_SUCCEEDED(result))) + while (subRange && (NS_SUCCEEDED(res))) { nsCOMPtrstartParent; - result = subRange->GetStartParent(getter_AddRefs(startParent)); - if (NS_SUCCEEDED(result) && startParent) + res = subRange->GetStartParent(getter_AddRefs(startParent)); + if (NS_SUCCEEDED(res) && startParent) { nsCOMPtr blockParent; - result = GetBlockParent(startParent, getter_AddRefs(blockParent)); - if (NS_SUCCEEDED(result) && blockParent) + res = GetBlockParent(startParent, getter_AddRefs(blockParent)); + if (NS_SUCCEEDED(res) && blockParent) { nsAutoString blockParentTag; blockParent->GetTagName(blockParentTag); @@ -631,7 +611,7 @@ nsHTMLEditor::GetParagraphStyle(nsStringArray *aTagList) } } - return result; + return res; } // use this when block parents are to be added regardless of current state @@ -645,37 +625,36 @@ nsHTMLEditor::AddBlockParent(nsString& aParentTag) delete [] tag; } - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(res)) && selection) { // set the block parent for all selected ranges - nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsCOMPtr enumerator; enumerator = do_QueryInterface(selection); if (enumerator) { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && (nsnull!=currentItem)) { nsCOMPtr range( do_QueryInterface(currentItem) ); // scan the range for all the independent block content blockSections // and apply the transformation to them - result = ReParentContentOfRange(range, aParentTag, eInsertParent); + res = ReParentContentOfRange(range, aParentTag, eInsertParent); } } - nsEditor::EndTransaction(); - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { // set the selection // XXX: can't do anything until I can create ranges } } if (gNoisy) {printf("Finished nsHTMLEditor::AddBlockParent with this content:\n"); DebugDumpContent(); } // DEBUG - return result; + return res; } // use this when a paragraph type is being transformed from one type to another @@ -690,33 +669,32 @@ nsHTMLEditor::ReplaceBlockParent(nsString& aParentTag) delete [] tag; } - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(res)) && selection) { // set the block parent for all selected ranges - nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsCOMPtr enumerator; enumerator = do_QueryInterface(selection); if (enumerator) { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && (nsnull!=currentItem)) { nsCOMPtr range( do_QueryInterface(currentItem) ); // scan the range for all the independent block content blockSections // and apply the transformation to them - result = ReParentContentOfRange(range, aParentTag, eReplaceParent); + res = ReParentContentOfRange(range, aParentTag, eReplaceParent); } } - nsEditor::EndTransaction(); } if (gNoisy) {printf("Finished nsHTMLEditor::AddBlockParent with this content:\n"); DebugDumpContent(); } // DEBUG - return result; + return res; } NS_IMETHODIMP @@ -734,7 +712,7 @@ nsHTMLEditor::ReParentContentOfNode(nsIDOMNode *aNode, // find the current block parent, or just use aNode if it is a block node nsCOMPtrblockParentElement; nsCOMPtrnodeToReParent; // this is the node we'll operate on, by default it's aNode - nsresult result = aNode->QueryInterface(nsIDOMNode::GetIID(), getter_AddRefs(nodeToReParent)); + nsresult res = aNode->QueryInterface(nsIDOMNode::GetIID(), getter_AddRefs(nodeToReParent)); PRBool nodeIsInline; PRBool nodeIsBlock=PR_FALSE; nsTextEditor::IsNodeInline(aNode, nodeIsInline); @@ -750,18 +728,18 @@ nsHTMLEditor::ReParentContentOfNode(nsIDOMNode *aNode, // if aNode is the block parent, then the node to reparent is one of its children if (PR_TRUE==nodeIsBlock) { - result = aNode->QueryInterface(nsIDOMNode::GetIID(), getter_AddRefs(blockParentElement)); - if (NS_SUCCEEDED(result) && blockParentElement) { - result = aNode->GetFirstChild(getter_AddRefs(nodeToReParent)); + res = aNode->QueryInterface(nsIDOMNode::GetIID(), getter_AddRefs(blockParentElement)); + if (NS_SUCCEEDED(res) && blockParentElement) { + res = aNode->GetFirstChild(getter_AddRefs(nodeToReParent)); } } else { // we just need to get the block parent of aNode - result = nsTextEditor::GetBlockParent(aNode, getter_AddRefs(blockParentElement)); + res = nsTextEditor::GetBlockParent(aNode, getter_AddRefs(blockParentElement)); } - // at this point, we must have a good result, a node to reparent, and a block parent + // at this point, we must have a good res, a node to reparent, and a block parent if (!nodeToReParent) { return NS_ERROR_UNEXPECTED;} if (!blockParentElement) { return NS_ERROR_NULL_POINTER;} - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { nsCOMPtr newParentNode; nsCOMPtr blockParentNode = do_QueryInterface(blockParentElement); @@ -779,17 +757,17 @@ nsHTMLEditor::ReParentContentOfNode(nsIDOMNode *aNode, nsCOMPtr nodeAsText = do_QueryInterface(nodeToReParent); if (nodeAsText) { - result = ReParentBlockContent(nodeToReParent, aParentTag, blockParentNode, parentTag, + res = ReParentBlockContent(nodeToReParent, aParentTag, blockParentNode, parentTag, aTransformation, getter_AddRefs(newParentNode)); } else { // this is the case of an insertion point between 2 non-text objects // XXX: how to you know it's an insertion point??? PRInt32 offsetInParent=0; - result = GetChildOffset(nodeToReParent, blockParentNode, offsetInParent); - NS_ASSERTION((NS_SUCCEEDED(result)), "bad result from GetChildOffset"); + res = GetChildOffset(nodeToReParent, blockParentNode, offsetInParent); + NS_ASSERTION((NS_SUCCEEDED(res)), "bad res from GetChildOffset"); // otherwise, just create the block parent at the selection - result = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, + res = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, getter_AddRefs(newParentNode)); // XXX: need to move some of the children of blockParentNode into the newParentNode? // XXX: need to create a bogus text node inside this new block? @@ -803,15 +781,15 @@ nsHTMLEditor::ReParentContentOfNode(nsIDOMNode *aNode, (eInsertParent==aTransformation)) { if (gNoisy) { DebugDumpContent(); } // DEBUG - result = ReParentBlockContent(nodeToReParent, aParentTag, blockParentNode, parentTag, + res = ReParentBlockContent(nodeToReParent, aParentTag, blockParentNode, parentTag, aTransformation, getter_AddRefs(newParentNode)); - if ((NS_SUCCEEDED(result)) && (newParentNode) && (eReplaceParent==aTransformation)) + if ((NS_SUCCEEDED(res)) && (newParentNode) && (eReplaceParent==aTransformation)) { PRBool hasChildren; blockParentNode->HasChildNodes(&hasChildren); if (PR_FALSE==hasChildren) { - result = nsEditor::DeleteNode(blockParentNode); + res = nsEditor::DeleteNode(blockParentNode); if (gNoisy) { printf("deleted old block parent node %p\n", blockParentNode.get()); @@ -825,7 +803,7 @@ nsHTMLEditor::ReParentContentOfNode(nsIDOMNode *aNode, } } } - return result; + return res; } @@ -843,9 +821,9 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, PRBool removeBreakBefore = PR_FALSE; PRBool removeBreakAfter = PR_FALSE; nsCOMPtrancestor; - nsresult result = aNode->GetParentNode(getter_AddRefs(ancestor)); + nsresult res = aNode->GetParentNode(getter_AddRefs(ancestor)); nsCOMPtrpreviousAncestor = do_QueryInterface(aNode); - while (NS_SUCCEEDED(result) && ancestor) + while (NS_SUCCEEDED(res) && ancestor) { nsCOMPtrancestorElement = do_QueryInterface(ancestor); nsAutoString ancestorTag; @@ -855,14 +833,14 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, break; // previousAncestor will contain the node to operate on } previousAncestor = do_QueryInterface(ancestor); - result = ancestorElement->GetParentNode(getter_AddRefs(ancestor)); + res = ancestorElement->GetParentNode(getter_AddRefs(ancestor)); } // now, previousAncestor is the node we are operating on nsCOMPtrleftNode, rightNode; - result = GetBlockSection(previousAncestor, + res = GetBlockSection(previousAncestor, getter_AddRefs(leftNode), getter_AddRefs(rightNode)); - if ((NS_SUCCEEDED(result)) && leftNode && rightNode) + if ((NS_SUCCEEDED(res)) && leftNode && rightNode) { // determine some state for managing
s around the new block PRBool isSubordinateBlock = PR_FALSE; // if true, the content is already in a subordinate block @@ -886,25 +864,25 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, PRInt32 offsetInParent=0; if (eInsertParent==aTransformation || PR_TRUE==isRootBlock) { - result = GetChildOffset(leftNode, blockParentNode, offsetInParent); - NS_ASSERTION((NS_SUCCEEDED(result)), "bad result from GetChildOffset"); - result = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, aNewParentNode); + res = GetChildOffset(leftNode, blockParentNode, offsetInParent); + NS_ASSERTION((NS_SUCCEEDED(res)), "bad res from GetChildOffset"); + res = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, aNewParentNode); if (gNoisy) { printf("created a node in blockParentNode at offset %d\n", offsetInParent); } } else { nsCOMPtr grandParent; - result = blockParentNode->GetParentNode(getter_AddRefs(grandParent)); - if ((NS_SUCCEEDED(result)) && grandParent) + res = blockParentNode->GetParentNode(getter_AddRefs(grandParent)); + if ((NS_SUCCEEDED(res)) && grandParent) { nsCOMPtrfirstChildNode, lastChildNode; blockParentNode->GetFirstChild(getter_AddRefs(firstChildNode)); blockParentNode->GetLastChild(getter_AddRefs(lastChildNode)); if (firstChildNode==leftNode && lastChildNode==rightNode) { - result = GetChildOffset(blockParentNode, grandParent, offsetInParent); - NS_ASSERTION((NS_SUCCEEDED(result)), "bad result from GetChildOffset"); - result = nsTextEditor::CreateNode(aParentTag, grandParent, offsetInParent, aNewParentNode); + res = GetChildOffset(blockParentNode, grandParent, offsetInParent); + NS_ASSERTION((NS_SUCCEEDED(res)), "bad res from GetChildOffset"); + res = nsTextEditor::CreateNode(aParentTag, grandParent, offsetInParent, aNewParentNode); if (gNoisy) { printf("created a node in grandParent at offset %d\n", offsetInParent); } } else @@ -916,41 +894,41 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, nsCOMPtr newLeftNode; if (firstChildNode!=leftNode) { - result = GetChildOffset(leftNode, blockParentNode, offsetInParent); + res = GetChildOffset(leftNode, blockParentNode, offsetInParent); if (gNoisy) { printf("splitting left at %d\n", offsetInParent); } - result = SplitNode(blockParentNode, offsetInParent, getter_AddRefs(newLeftNode)); + res = SplitNode(blockParentNode, offsetInParent, getter_AddRefs(newLeftNode)); // after this split, blockParentNode still contains leftNode and rightNode } if (lastChildNode!=rightNode) { - result = GetChildOffset(rightNode, blockParentNode, offsetInParent); + res = GetChildOffset(rightNode, blockParentNode, offsetInParent); offsetInParent++; if (gNoisy) { printf("splitting right at %d\n", offsetInParent); } - result = SplitNode(blockParentNode, offsetInParent, getter_AddRefs(newLeftNode)); + res = SplitNode(blockParentNode, offsetInParent, getter_AddRefs(newLeftNode)); blockParentNode = do_QueryInterface(newLeftNode); } - result = GetChildOffset(leftNode, blockParentNode, offsetInParent); - NS_ASSERTION((NS_SUCCEEDED(result)), "bad result from GetChildOffset"); - result = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, aNewParentNode); + res = GetChildOffset(leftNode, blockParentNode, offsetInParent); + NS_ASSERTION((NS_SUCCEEDED(res)), "bad res from GetChildOffset"); + res = nsTextEditor::CreateNode(aParentTag, blockParentNode, offsetInParent, aNewParentNode); if (gNoisy) { printf("created a node in blockParentNode at offset %d\n", offsetInParent); } // what we need to do here is remove the existing block parent when we're all done. removeBlockParent = PR_TRUE; } } } - if ((NS_SUCCEEDED(result)) && *aNewParentNode) + if ((NS_SUCCEEDED(res)) && *aNewParentNode) { // move all the children/contents of blockParentNode to aNewParentNode nsCOMPtrchildNode = do_QueryInterface(rightNode); nsCOMPtrpreviousSiblingNode; - while (NS_SUCCEEDED(result) && childNode) + while (NS_SUCCEEDED(res) && childNode) { childNode->GetPreviousSibling(getter_AddRefs(previousSiblingNode)); // explicitly delete of childNode from it's current parent // can't just rely on DOM semantics of InsertNode doing the delete implicitly, doesn't undo! - result = nsEditor::DeleteNode(childNode); - if (NS_SUCCEEDED(result)) + res = nsEditor::DeleteNode(childNode); + if (NS_SUCCEEDED(res)) { - result = nsEditor::InsertNode(childNode, *aNewParentNode, 0); + res = nsEditor::InsertNode(childNode, *aNewParentNode, 0); if (gNoisy) { printf("re-parented sibling node %p\n", childNode.get()); @@ -963,12 +941,12 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, } // end while loop } // clean up the surrounding content to maintain vertical whitespace - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { // if the prior node is a
and we did something to change vertical whitespacing, delete the
nsCOMPtr brNode; - result = GetPriorNode(leftNode, PR_TRUE, getter_AddRefs(brNode)); - if (NS_SUCCEEDED(result) && brNode) + res = GetPriorNode(leftNode, PR_TRUE, getter_AddRefs(brNode)); + if (NS_SUCCEEDED(res) && brNode) { nsCOMPtr brContent = do_QueryInterface(brNode); if (brContent) @@ -976,16 +954,16 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, nsCOMPtr brContentTag; brContent->GetTag(*getter_AddRefs(brContentTag)); if (nsIEditProperty::br==brContentTag.get()) { - result = DeleteNode(brNode); + res = DeleteNode(brNode); } } } // if the next node is a
and we did something to change vertical whitespacing, delete the
- if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { - result = GetNextNode(rightNode, PR_TRUE, getter_AddRefs(brNode)); - if (NS_SUCCEEDED(result) && brNode) + res = GetNextNode(rightNode, PR_TRUE, getter_AddRefs(brNode)); + if (NS_SUCCEEDED(res) && brNode) { nsCOMPtr brContent = do_QueryInterface(brNode); if (brContent) @@ -993,44 +971,44 @@ nsHTMLEditor::ReParentBlockContent(nsIDOMNode *aNode, nsCOMPtr brContentTag; brContent->GetTag(*getter_AddRefs(brContentTag)); if (nsIEditProperty::br==brContentTag.get()) { - result = DeleteNode(brNode); + res = DeleteNode(brNode); } } } } } - if ((NS_SUCCEEDED(result)) && (PR_TRUE==removeBlockParent)) + if ((NS_SUCCEEDED(res)) && (PR_TRUE==removeBlockParent)) { // we determined we need to remove the previous block parent. Do it! // go through list backwards so deletes don't interfere with the iteration nsCOMPtr childNodes; - result = blockParentNode->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) + res = blockParentNode->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(res)) && (childNodes)) { nsCOMPtrgrandParent; blockParentNode->GetParentNode(getter_AddRefs(grandParent)); PRInt32 offsetInParent; - result = GetChildOffset(blockParentNode, grandParent, offsetInParent); + res = GetChildOffset(blockParentNode, grandParent, offsetInParent); PRUint32 childCount; childNodes->GetLength(&childCount); PRInt32 i=childCount-1; - for ( ; ((NS_SUCCEEDED(result)) && (0<=i)); i--) + for ( ; ((NS_SUCCEEDED(res)) && (0<=i)); i--) { nsCOMPtr childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) + res = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(res)) && (childNode)) { - result = nsTextEditor::DeleteNode(childNode); - if (NS_SUCCEEDED(result)) { - result = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); + res = nsTextEditor::DeleteNode(childNode); + if (NS_SUCCEEDED(res)) { + res = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); } } } if (gNoisy) { printf("removing the old block parent %p\n", blockParentNode.get()); } - result = nsTextEditor::DeleteNode(blockParentNode); + res = nsTextEditor::DeleteNode(blockParentNode); } } } - return result; + return res; } NS_IMETHODIMP @@ -1039,24 +1017,24 @@ nsHTMLEditor::ReParentContentOfRange(nsIDOMRange *aRange, BlockTransformationType aTranformation) { if (!aRange) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsISupportsArray *blockSections; - result = NS_NewISupportsArray(&blockSections); - if ((NS_SUCCEEDED(result)) && blockSections) + res = NS_NewISupportsArray(&blockSections); + if ((NS_SUCCEEDED(res)) && blockSections) { - result = GetBlockSectionsForRange(aRange, blockSections); - if (NS_SUCCEEDED(result)) + res = GetBlockSectionsForRange(aRange, blockSections); + if (NS_SUCCEEDED(res)) { nsIDOMRange *subRange; subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); - while (subRange && (NS_SUCCEEDED(result))) + while (subRange && (NS_SUCCEEDED(res))) { nsCOMPtrstartParent; - result = subRange->GetStartParent(getter_AddRefs(startParent)); - if (NS_SUCCEEDED(result) && startParent) + res = subRange->GetStartParent(getter_AddRefs(startParent)); + if (NS_SUCCEEDED(res) && startParent) { if (gNoisy) { printf("ReParentContentOfRange calling ReParentContentOfNode\n"); } - result = ReParentContentOfNode(startParent, aParentTag, aTranformation); + res = ReParentContentOfNode(startParent, aParentTag, aTranformation); } NS_RELEASE(subRange); blockSections->RemoveElementAt(0); @@ -1065,7 +1043,7 @@ nsHTMLEditor::ReParentContentOfRange(nsIDOMRange *aRange, } NS_RELEASE(blockSections); } - return result; + return res; } NS_IMETHODIMP @@ -1075,47 +1053,46 @@ nsHTMLEditor::RemoveParagraphStyle() printf("---------- nsHTMLEditor::RemoveParagraphStyle ----------\n"); } - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(res)) && selection) { - nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsCOMPtr enumerator; enumerator = do_QueryInterface(selection); if (enumerator) { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && (nsnull!=currentItem)) { nsCOMPtr range( do_QueryInterface(currentItem) ); - result = RemoveParagraphStyleFromRange(range); + res = RemoveParagraphStyleFromRange(range); } } - nsEditor::EndTransaction(); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::RemoveParagraphStyleFromRange(nsIDOMRange *aRange) { if (!aRange) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsISupportsArray *blockSections; - result = NS_NewISupportsArray(&blockSections); - if ((NS_SUCCEEDED(result)) && blockSections) + res = NS_NewISupportsArray(&blockSections); + if ((NS_SUCCEEDED(res)) && blockSections) { - result = GetBlockSectionsForRange(aRange, blockSections); - if (NS_SUCCEEDED(result)) + res = GetBlockSectionsForRange(aRange, blockSections); + if (NS_SUCCEEDED(res)) { nsIDOMRange *subRange; subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); - while (subRange && (NS_SUCCEEDED(result))) + while (subRange && (NS_SUCCEEDED(res))) { - result = RemoveParagraphStyleFromBlockContent(subRange); + res = RemoveParagraphStyleFromBlockContent(subRange); NS_RELEASE(subRange); blockSections->RemoveElementAt(0); subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); @@ -1123,19 +1100,19 @@ nsHTMLEditor::RemoveParagraphStyleFromRange(nsIDOMRange *aRange) } NS_RELEASE(blockSections); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::RemoveParagraphStyleFromBlockContent(nsIDOMRange *aRange) { if (!aRange) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsCOMPtrstartParent; aRange->GetStartParent(getter_AddRefs(startParent)); nsCOMPtrblockParentElement; - result = nsTextEditor::GetBlockParent(startParent, getter_AddRefs(blockParentElement)); - while ((NS_SUCCEEDED(result)) && blockParentElement) + res = nsTextEditor::GetBlockParent(startParent, getter_AddRefs(blockParentElement)); + while ((NS_SUCCEEDED(res)) && blockParentElement) { nsAutoString blockParentTag; blockParentElement->GetTagName(blockParentTag); @@ -1148,36 +1125,36 @@ nsHTMLEditor::RemoveParagraphStyleFromBlockContent(nsIDOMRange *aRange) { // go through list backwards so deletes don't interfere with the iteration nsCOMPtr childNodes; - result = blockParentElement->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) + res = blockParentElement->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(res)) && (childNodes)) { nsCOMPtrgrandParent; blockParentElement->GetParentNode(getter_AddRefs(grandParent)); PRInt32 offsetInParent; - result = GetChildOffset(blockParentElement, grandParent, offsetInParent); + res = GetChildOffset(blockParentElement, grandParent, offsetInParent); PRUint32 childCount; childNodes->GetLength(&childCount); PRInt32 i=childCount-1; - for ( ; ((NS_SUCCEEDED(result)) && (0<=i)); i--) + for ( ; ((NS_SUCCEEDED(res)) && (0<=i)); i--) { nsCOMPtr childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) + res = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(res)) && (childNode)) { - result = nsTextEditor::DeleteNode(childNode); - if (NS_SUCCEEDED(result)) { - result = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); + res = nsTextEditor::DeleteNode(childNode); + if (NS_SUCCEEDED(res)) { + res = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); } } } - if (NS_SUCCEEDED(result)) { - result = nsTextEditor::DeleteNode(blockParentElement); + if (NS_SUCCEEDED(res)) { + res = nsTextEditor::DeleteNode(blockParentElement); } } } - result = nsTextEditor::GetBlockParent(startParent, getter_AddRefs(blockParentElement)); + res = nsTextEditor::GetBlockParent(startParent, getter_AddRefs(blockParentElement)); } - return result; + return res; } @@ -1188,47 +1165,46 @@ nsHTMLEditor::RemoveParent(const nsString &aParentTag) printf("---------- nsHTMLEditor::RemoveParent ----------\n"); } - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(res)) && selection) { - nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsCOMPtr enumerator; enumerator = do_QueryInterface(selection); if (enumerator) { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && (nsnull!=currentItem)) { nsCOMPtr range( do_QueryInterface(currentItem) ); - result = RemoveParentFromRange(aParentTag, range); + res = RemoveParentFromRange(aParentTag, range); } } - nsEditor::EndTransaction(); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::RemoveParentFromRange(const nsString &aParentTag, nsIDOMRange *aRange) { if (!aRange) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsISupportsArray *blockSections; - result = NS_NewISupportsArray(&blockSections); - if ((NS_SUCCEEDED(result)) && blockSections) + res = NS_NewISupportsArray(&blockSections); + if ((NS_SUCCEEDED(res)) && blockSections) { - result = GetBlockSectionsForRange(aRange, blockSections); - if (NS_SUCCEEDED(result)) + res = GetBlockSectionsForRange(aRange, blockSections); + if (NS_SUCCEEDED(res)) { nsIDOMRange *subRange; subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); - while (subRange && (NS_SUCCEEDED(result))) + while (subRange && (NS_SUCCEEDED(res))) { - result = RemoveParentFromBlockContent(aParentTag, subRange); + res = RemoveParentFromBlockContent(aParentTag, subRange); NS_RELEASE(subRange); blockSections->RemoveElementAt(0); subRange = (nsIDOMRange *)(blockSections->ElementAt(0)); @@ -1236,22 +1212,22 @@ nsHTMLEditor::RemoveParentFromRange(const nsString &aParentTag, nsIDOMRange *aRa } NS_RELEASE(blockSections); } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::RemoveParentFromBlockContent(const nsString &aParentTag, nsIDOMRange *aRange) { if (!aRange) { return NS_ERROR_NULL_POINTER; } - nsresult result; + nsresult res; nsCOMPtrstartParent; - result = aRange->GetStartParent(getter_AddRefs(startParent)); - if ((NS_SUCCEEDED(result)) && startParent) + res = aRange->GetStartParent(getter_AddRefs(startParent)); + if ((NS_SUCCEEDED(res)) && startParent) { nsCOMPtrparentNode; nsCOMPtrparentElement; - result = startParent->GetParentNode(getter_AddRefs(parentNode)); - while ((NS_SUCCEEDED(result)) && parentNode) + res = startParent->GetParentNode(getter_AddRefs(parentNode)); + while ((NS_SUCCEEDED(res)) && parentNode) { parentElement = do_QueryInterface(parentNode); nsAutoString parentTag; @@ -1262,30 +1238,30 @@ nsHTMLEditor::RemoveParentFromBlockContent(const nsString &aParentTag, nsIDOMRan { // go through list backwards so deletes don't interfere with the iteration nsCOMPtr childNodes; - result = parentElement->GetChildNodes(getter_AddRefs(childNodes)); - if ((NS_SUCCEEDED(result)) && (childNodes)) + res = parentElement->GetChildNodes(getter_AddRefs(childNodes)); + if ((NS_SUCCEEDED(res)) && (childNodes)) { nsCOMPtrgrandParent; parentElement->GetParentNode(getter_AddRefs(grandParent)); PRInt32 offsetInParent; - result = GetChildOffset(parentElement, grandParent, offsetInParent); + res = GetChildOffset(parentElement, grandParent, offsetInParent); PRUint32 childCount; childNodes->GetLength(&childCount); PRInt32 i=childCount-1; - for ( ; ((NS_SUCCEEDED(result)) && (0<=i)); i--) + for ( ; ((NS_SUCCEEDED(res)) && (0<=i)); i--) { nsCOMPtr childNode; - result = childNodes->Item(i, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(result)) && (childNode)) + res = childNodes->Item(i, getter_AddRefs(childNode)); + if ((NS_SUCCEEDED(res)) && (childNode)) { - result = nsTextEditor::DeleteNode(childNode); - if (NS_SUCCEEDED(result)) { - result = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); + res = nsTextEditor::DeleteNode(childNode); + if (NS_SUCCEEDED(res)) { + res = nsTextEditor::InsertNode(childNode, grandParent, offsetInParent); } } } - if (NS_SUCCEEDED(result)) { - result = nsTextEditor::DeleteNode(parentElement); + if (NS_SUCCEEDED(res)) { + res = nsTextEditor::DeleteNode(parentElement); } } break; @@ -1293,10 +1269,10 @@ nsHTMLEditor::RemoveParentFromBlockContent(const nsString &aParentTag, nsIDOMRan else if (PR_TRUE==isRoot) { // hit a local root node, terminate loop break; } - result = parentElement->GetParentNode(getter_AddRefs(parentNode)); + res = parentElement->GetParentNode(getter_AddRefs(parentNode)); } } - return result; + return res; } @@ -1304,37 +1280,22 @@ nsHTMLEditor::RemoveParentFromBlockContent(const nsString &aParentTag, nsIDOMRan NS_IMETHODIMP nsHTMLEditor::Indent(const nsString& aIndent) { - nsresult res = nsEditor::BeginTransaction(); - if (NS_FAILED(res)) return res; - + nsAutoEditBatch beginBatching(this); nsCOMPtr node; PRInt32 offset; // Find out if the selection is collapsed: nsCOMPtr selection; - res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res) || !selection) - { - // my kingdom for exceptions - nsEditor::EndTransaction(); - return res; - } + nsresult res = GetSelection(getter_AddRefs(selection)); + if (NS_FAILED(res) || !selection) return res; PRBool isCollapsed; res = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; res = GetStartNodeAndOffset(selection, &node, &offset); if (!node) res = NS_ERROR_FAILURE; - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; nsAutoString inward("indent"); if (aIndent == inward) @@ -1350,11 +1311,7 @@ nsHTMLEditor::Indent(const nsString& aIndent) while ( !CanContainTag(parent, bq)) { parent->GetParentNode(getter_AddRefs(tmp)); - if (!tmp) - { - nsEditor::EndTransaction(); - return NS_ERROR_FAILURE; - } + if (!tmp) return NS_ERROR_FAILURE; topChild = parent; parent = tmp; } @@ -1363,11 +1320,7 @@ nsHTMLEditor::Indent(const nsString& aIndent) { // we need to split up to the child of parent res = SplitNodeDeep(topChild, node, offset); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // topChild already went to the right on the split // so we don't need to add one to offset when figuring // out where to plop list @@ -1377,43 +1330,21 @@ nsHTMLEditor::Indent(const nsString& aIndent) // make a blockquote nsCOMPtr newBQ; res = CreateNode(bq, parent, offset, getter_AddRefs(newBQ)); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // put a space in it so layout will draw the list item res = selection->Collapse(newBQ,0); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; nsAutoString theText(" "); res = InsertText(theText); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // reposition selection to before the space character res = GetStartNodeAndOffset(selection, &node, &offset); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; res = selection->Collapse(node,0); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; } } - nsEditor::EndTransaction(); // don't return this result! - return NS_OK; } @@ -1422,37 +1353,22 @@ nsHTMLEditor::Indent(const nsString& aIndent) NS_IMETHODIMP nsHTMLEditor::Align(const nsString& aAlignType) { - nsresult res = nsEditor::BeginTransaction(); - if (NS_FAILED(res)) return res; - + nsAutoEditBatch beginBatching(this); nsCOMPtr node; PRInt32 offset; // Find out if the selection is collapsed: nsCOMPtr selection; - res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res) || !selection) - { - // my kingdom for exceptions - nsEditor::EndTransaction(); - return res; - } + nsresult res = GetSelection(getter_AddRefs(selection)); + if (NS_FAILED(res) || !selection) return res; PRBool isCollapsed; res = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; res = GetStartNodeAndOffset(selection, &node, &offset); if (!node) res = NS_ERROR_FAILURE; - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; nsAutoString leftStr("left"); if (aAlignType == leftStr) @@ -1464,8 +1380,6 @@ nsHTMLEditor::Align(const nsString& aAlignType) } } - nsEditor::EndTransaction(); // don't return this result! - return NS_OK; } @@ -1473,37 +1387,33 @@ nsHTMLEditor::Align(const nsString& aAlignType) NS_IMETHODIMP nsHTMLEditor::InsertList(const nsString& aListType) { - nsresult res = nsEditor::BeginTransaction(); - if (NS_FAILED(res)) return res; + nsresult res; + if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } + + nsCOMPtr selection; + PRBool cancel= PR_FALSE; + + nsAutoEditBatch beginBatching(this); + + // pre-process + nsEditor::GetSelection(getter_AddRefs(selection)); + nsTextRulesInfo ruleInfo(nsHTMLEditRules::kMakeList); + res = mRules->WillDoAction(selection, &ruleInfo, &cancel); + if (cancel || (NS_FAILED(res))) return res; // Find out if the selection is collapsed: - nsCOMPtr selection; - res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res) || !selection) - { - // my kingdom for exceptions - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res) || !selection) return res; PRBool isCollapsed; res = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; nsCOMPtr node; PRInt32 offset; res = GetStartNodeAndOffset(selection, &node, &offset); if (!node) res = NS_ERROR_FAILURE; - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; if (isCollapsed) { @@ -1515,11 +1425,7 @@ nsHTMLEditor::InsertList(const nsString& aListType) while ( !CanContainTag(parent, aListType)) { parent->GetParentNode(getter_AddRefs(tmp)); - if (!tmp) - { - nsEditor::EndTransaction(); - return NS_ERROR_FAILURE; - } + if (!tmp) return NS_ERROR_FAILURE; topChild = parent; parent = tmp; } @@ -1528,11 +1434,7 @@ nsHTMLEditor::InsertList(const nsString& aListType) { // we need to split up to the child of parent res = SplitNodeDeep(topChild, node, offset); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // topChild already went to the right on the split // so we don't need to add one to offset when figuring // out where to plop list @@ -1542,49 +1444,24 @@ nsHTMLEditor::InsertList(const nsString& aListType) // make a list nsCOMPtr newList; res = CreateNode(aListType, parent, offset, getter_AddRefs(newList)); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // make a list item nsAutoString tag("li"); nsCOMPtr newItem; res = CreateNode(tag, newList, 0, getter_AddRefs(newItem)); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // put a space in it so layout will draw the list item res = selection->Collapse(newItem,0); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; nsAutoString theText(" "); res = InsertText(theText); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; // reposition selection to before the space character res = GetStartNodeAndOffset(selection, &node, &offset); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; res = selection->Collapse(node,0); - if (NS_FAILED(res)) - { - nsEditor::EndTransaction(); - return res; - } + if (NS_FAILED(res)) return res; } - nsEditor::EndTransaction(); // don't return this result! return NS_OK; } @@ -1592,11 +1469,11 @@ nsHTMLEditor::InsertList(const nsString& aListType) NS_IMETHODIMP nsHTMLEditor::InsertLink(nsString& aURL) { - nsresult res = nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); // Find out if the selection is collapsed: nsCOMPtr selection; - res = GetSelection(getter_AddRefs(selection)); + nsresult res = GetSelection(getter_AddRefs(selection)); if (NS_FAILED(res) || !selection) { #ifdef DEBUG_akkana @@ -1673,8 +1550,6 @@ nsHTMLEditor::InsertLink(nsString& aURL) (void) InsertText(link); // ignore return value -- we don't care } - nsEditor::EndTransaction(); // don't return this result! - return NS_OK; } @@ -1729,7 +1604,7 @@ nsHTMLEditor::InsertImage(nsString& aURL, // Now we're ready to insert the new image node: // Starting now, don't return without ending the transaction! // - (void)nsEditor::BeginTransaction(); + nsAutoEditBatch beginBatching(this); nsCOMPtr parentNode; PRInt32 offsetOfNewNode; @@ -1741,8 +1616,6 @@ nsHTMLEditor::InsertImage(nsString& aURL, res = InsertNode(newNode, parentNode, offsetOfNewNode); } - (void)nsEditor::EndTransaction(); // don't return this result! - return res; } @@ -1760,12 +1633,12 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu //Note that this doesn't need to go through the transaction system - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; PRBool first=PR_TRUE; nsCOMPtrselection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result) || !selection) - return result; + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if (NS_FAILED(res) || !selection) + return res; PRBool isCollapsed; selection->GetIsCollapsed(&isCollapsed); @@ -1781,20 +1654,20 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu { enumerator->First(); nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && currentItem) + res = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(res)) && currentItem) { nsCOMPtr range( do_QueryInterface(currentItem) ); nsCOMPtr iter; - result = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull, + res = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull, nsIContentIterator::GetIID(), getter_AddRefs(iter)); - if ((NS_SUCCEEDED(result)) && iter) + if ((NS_SUCCEEDED(res)) && iter) { iter->Init(range); // loop through the content iterator for each content node nsCOMPtr content; - result = iter->CurrentNode(getter_AddRefs(content)); + res = iter->CurrentNode(getter_AddRefs(content)); PRBool bOtherNodeTypeFound = PR_FALSE; while (NS_COMFALSE == iter->IsDone()) @@ -1847,8 +1720,8 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu nsCOMPtr current = do_QueryInterface(selectedElement); PRBool notDone = PR_TRUE; do { - result = current->GetParentNode(getter_AddRefs(parent)); - notDone = NS_SUCCEEDED(result) && parent != nsnull; + res = current->GetParentNode(getter_AddRefs(parent)); + notDone = NS_SUCCEEDED(res) && parent != nsnull; if(notDone) { nsString tmpText; @@ -1894,13 +1767,13 @@ nsHTMLEditor::GetSelectedElement(const nsString& aTagName, nsIDOMElement** aRetu *aReturn = selectedElement; } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn) { - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; if (aReturn) *aReturn = nsnull; @@ -1923,8 +1796,8 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* // go through the transaction system nsCOMPtrnewElement; - result = mDoc->CreateElement(realTagName, getter_AddRefs(newElement)); - if (NS_FAILED(result) || !newElement) + res = mDoc->CreateElement(realTagName, getter_AddRefs(newElement)); + if (NS_FAILED(res) || !newElement) return NS_ERROR_FAILURE; @@ -1938,27 +1811,25 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* } // ADD OTHER DEFAULT ATTRIBUTES HERE - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { *aReturn = newElement; } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn) { - nsresult result=NS_ERROR_NOT_INITIALIZED; + nsresult res=NS_ERROR_NOT_INITIALIZED; if (aReturn) *aReturn = nsnull; if (!aElement || !aReturn) return NS_ERROR_NULL_POINTER; - result = nsEditor::BeginTransaction(); - if (NS_FAILED(result)) - return result; + nsAutoEditBatch beginBatching(this); nsCOMPtr parentSelectedNode; PRInt32 offsetOfNewNode; @@ -1976,22 +1847,21 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, ns } DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, offsetOfNewNode); - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { nsCOMPtr newNode = do_QueryInterface(aElement); - result = InsertNode(aElement, parentSelectedNode, offsetOfNewNode); + res = InsertNode(aElement, parentSelectedNode, offsetOfNewNode); } - (void)nsEditor::EndTransaction(); - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { - nsresult result=NS_ERROR_NULL_POINTER; + nsresult res=NS_ERROR_NULL_POINTER; nsCOMPtr selection; // DON'T RETURN EXCEPT AT THE END -- WE NEED TO RELEASE THE aAnchorElement @@ -1999,19 +1869,19 @@ nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) goto DELETE_ANCHOR; // We must have a real selection - result = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result) || !selection) + res = GetSelection(getter_AddRefs(selection)); + if (NS_FAILED(res) || !selection) goto DELETE_ANCHOR; PRBool isCollapsed; - result = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(result)) + res = selection->GetIsCollapsed(&isCollapsed); + if (NS_FAILED(res)) isCollapsed = PR_TRUE; if (isCollapsed) { printf("InsertLinkAroundSelection called but there is no selection!!!\n"); - result = NS_OK; + res = NS_OK; } else { // Be sure we were given an anchor element @@ -2021,16 +1891,12 @@ nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) nsAutoString href; if (NS_SUCCEEDED(anchor->GetHref(href)) && href.GetUnicode() && href.Length() > 0) { - result = nsEditor::BeginTransaction(); - if (NS_SUCCEEDED(result)) - { - const nsString attribute("href"); - SetTextProperty(nsIEditProperty::a, &attribute, &href); - //TODO: Enumerate through other properties of the anchor tag - // and set those as well. - // Optimization: Modify SetTextProperty to set all attributes at once? - } - (void)nsEditor::EndTransaction(); + nsAutoEditBatch beginBatching(this); + const nsString attribute("href"); + SetTextProperty(nsIEditProperty::a, &attribute, &href); + //TODO: Enumerate through other properties of the anchor tag + // and set those as well. + // Optimization: Modify SetTextProperty to set all attributes at once? } } } @@ -2040,7 +1906,7 @@ DELETE_ANCHOR: // so shouldn't we have to do this here? // It crashes in JavaScript if we do this! //NS_RELEASE(aAnchorElement); - return result; + return res; } PRBool nsHTMLEditor::IsElementInBody(nsIDOMElement* aElement) @@ -2048,8 +1914,8 @@ PRBool nsHTMLEditor::IsElementInBody(nsIDOMElement* aElement) if ( aElement ) { nsIDOMElement* bodyElement = nsnull; - nsresult result = nsEditor::GetBodyElement(&bodyElement); - if (NS_SUCCEEDED(result) && bodyElement) + nsresult res = nsEditor::GetBodyElement(&bodyElement); + if (NS_SUCCEEDED(res) && bodyElement) { nsCOMPtr parent; nsCOMPtr currentElement = do_QueryInterface(aElement); @@ -2074,23 +1940,23 @@ PRBool nsHTMLEditor::IsElementInBody(nsIDOMElement* aElement) NS_IMETHODIMP nsHTMLEditor::SelectElement(nsIDOMElement* aElement) { - nsresult result = NS_ERROR_NULL_POINTER; + nsresult res = NS_ERROR_NULL_POINTER; // Must be sure that element is contained in the document body if (IsElementInBody(aElement)) { nsCOMPtr selection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if (NS_SUCCEEDED(result) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if (NS_SUCCEEDED(res) && selection) { nsCOMPtrparent; - result = aElement->GetParentNode(getter_AddRefs(parent)); - if (NS_SUCCEEDED(result) && parent) + res = aElement->GetParentNode(getter_AddRefs(parent)); + if (NS_SUCCEEDED(res) && parent) { PRInt32 offsetInParent; - result = GetChildOffset(aElement, parent, offsetInParent); + res = GetChildOffset(aElement, parent, offsetInParent); - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { // Collapse selection to just before desired element, selection->Collapse(parent, offsetInParent); @@ -2100,29 +1966,29 @@ nsHTMLEditor::SelectElement(nsIDOMElement* aElement) } } } - return result; + return res; } NS_IMETHODIMP nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) { - nsresult result = NS_ERROR_NULL_POINTER; + nsresult res = NS_ERROR_NULL_POINTER; // Must be sure that element is contained in the document body if (IsElementInBody(aElement)) { nsCOMPtr selection; - result = nsEditor::GetSelection(getter_AddRefs(selection)); - if (NS_SUCCEEDED(result) && selection) + res = nsEditor::GetSelection(getter_AddRefs(selection)); + if (NS_SUCCEEDED(res) && selection) { nsCOMPtrparent; - result = aElement->GetParentNode(getter_AddRefs(parent)); - if (NS_SUCCEEDED(result) && parent) + res = aElement->GetParentNode(getter_AddRefs(parent)); + if (NS_SUCCEEDED(res) && parent) { PRInt32 offsetInParent; - result = GetChildOffset(aElement, parent, offsetInParent); + res = GetChildOffset(aElement, parent, offsetInParent); - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { // Collapse selection to just after desired element, selection->Collapse(parent, offsetInParent+1); @@ -2130,7 +1996,7 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) } } } - return result; + return res; } @@ -2274,12 +2140,12 @@ NS_IMETHODIMP nsHTMLEditor::GetLocalFileURL(nsIDOMWindow* aParent, const nsStrin // TODO: GET THE DEFAULT DIRECTORY FOR DIFFERENT TYPES FROM PREFERENCES nsFileSpec aDisplayDirectory; - nsresult result = nsComponentManager::CreateInstance(kFileWidgetCID, + nsresult res = nsComponentManager::CreateInstance(kFileWidgetCID, nsnull, nsIFileWidget::GetIID(), (void**)&fileWidget); - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(res)) { nsFileDlgResults dialogResult; if (htmlFilter) @@ -2310,7 +2176,7 @@ NS_IMETHODIMP nsHTMLEditor::GetLocalFileURL(nsIDOMWindow* aParent, const nsStrin fileWidget->GetDisplayDirectory(aDisplayDirectory); } - return result; + return res; } NS_IMETHODIMP