Bug 1311606 Rename |result| of nsresult variants to |rv| in editor r=smaug

For conforming to our coding rules, |result| of nsresult variants should be renamed to |rv|.

MozReview-Commit-ID: Bk8CyLAnvXQ

--HG--
extra : rebase_source : dd3dc34a032f22abf3fd7f85556b47ffbeec55b2
This commit is contained in:
Masayuki Nakano 2016-10-25 00:43:49 +09:00
Родитель eeb042a75d
Коммит b83f17b535
13 изменённых файлов: 1975 добавлений и 2207 удалений

Просмотреть файл

@ -150,8 +150,8 @@ ChangeStyleTransaction::DoTransaction()
nsGkAtoms::style);
nsAutoString values;
nsresult result = cssDecl->GetPropertyValue(propertyNameString, values);
NS_ENSURE_SUCCESS(result, result);
nsresult rv = cssDecl->GetPropertyValue(propertyNameString, values);
NS_ENSURE_SUCCESS(rv, rv);
mUndoValue.Assign(values);
// Does this property accept more than one value? (bug 62682)
@ -168,18 +168,17 @@ ChangeStyleTransaction::DoTransaction()
RemoveValueFromListOfValues(values, NS_LITERAL_STRING("none"));
RemoveValueFromListOfValues(values, mValue);
if (values.IsEmpty()) {
result = cssDecl->RemoveProperty(propertyNameString, returnString);
NS_ENSURE_SUCCESS(result, result);
rv = cssDecl->RemoveProperty(propertyNameString, returnString);
NS_ENSURE_SUCCESS(rv, rv);
} else {
nsAutoString priority;
cssDecl->GetPropertyPriority(propertyNameString, priority);
result = cssDecl->SetProperty(propertyNameString, values,
priority);
NS_ENSURE_SUCCESS(result, result);
rv = cssDecl->SetProperty(propertyNameString, values, priority);
NS_ENSURE_SUCCESS(rv, rv);
}
} else {
result = cssDecl->RemoveProperty(propertyNameString, returnString);
NS_ENSURE_SUCCESS(result, result);
rv = cssDecl->RemoveProperty(propertyNameString, returnString);
NS_ENSURE_SUCCESS(rv, rv);
}
} else {
nsAutoString priority;
@ -194,18 +193,17 @@ ChangeStyleTransaction::DoTransaction()
} else {
values.Assign(mValue);
}
result = cssDecl->SetProperty(propertyNameString, values,
priority);
NS_ENSURE_SUCCESS(result, result);
rv = cssDecl->SetProperty(propertyNameString, values, priority);
NS_ENSURE_SUCCESS(rv, rv);
}
// Let's be sure we don't keep an empty style attribute
uint32_t length;
result = cssDecl->GetLength(&length);
NS_ENSURE_SUCCESS(result, result);
rv = cssDecl->GetLength(&length);
NS_ENSURE_SUCCESS(rv, rv);
if (!length) {
result = mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
NS_ENSURE_SUCCESS(result, result);
rv = mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
NS_ENSURE_SUCCESS(rv, rv);
} else {
mRedoAttributeWasSet = true;
}
@ -217,7 +215,6 @@ nsresult
ChangeStyleTransaction::SetStyle(bool aAttributeWasSet,
nsAString& aValue)
{
nsresult result = NS_OK;
if (aAttributeWasSet) {
// The style attribute was not empty, let's recreate the declaration
nsAutoString propertyNameString;
@ -230,18 +227,14 @@ ChangeStyleTransaction::SetStyle(bool aAttributeWasSet,
if (aValue.IsEmpty()) {
// An empty value means we have to remove the property
nsAutoString returnString;
result = cssDecl->RemoveProperty(propertyNameString, returnString);
} else {
// Let's recreate the declaration as it was
nsAutoString priority;
cssDecl->GetPropertyPriority(propertyNameString, priority);
result = cssDecl->SetProperty(propertyNameString, aValue, priority);
return cssDecl->RemoveProperty(propertyNameString, returnString);
}
} else {
result = mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
// Let's recreate the declaration as it was
nsAutoString priority;
cssDecl->GetPropertyPriority(propertyNameString, priority);
return cssDecl->SetProperty(propertyNameString, aValue, priority);
}
return result;
return mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
}
NS_IMETHODIMP

Просмотреть файл

@ -33,53 +33,53 @@ NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
NS_IMETHODIMP
EditAggregateTransaction::DoTransaction()
{
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
// FYI: It's legal (but not very useful) to have an empty child list.
for (uint32_t i = 0, length = mChildren.Length(); i < length; ++i) {
nsITransaction *txn = mChildren[i];
if (!txn) {
return NS_ERROR_NULL_POINTER;
}
result = txn->DoTransaction();
if (NS_FAILED(result)) {
break;
nsresult rv = txn->DoTransaction();
if (NS_FAILED(rv)) {
return rv;
}
}
return result;
return NS_OK;
}
NS_IMETHODIMP
EditAggregateTransaction::UndoTransaction()
{
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
// undo goes through children backwards
// FYI: It's legal (but not very useful) to have an empty child list.
// Undo goes through children backwards.
for (uint32_t i = mChildren.Length(); i--; ) {
nsITransaction *txn = mChildren[i];
if (!txn) {
return NS_ERROR_NULL_POINTER;
}
result = txn->UndoTransaction();
if (NS_FAILED(result)) {
break;
nsresult rv = txn->UndoTransaction();
if (NS_FAILED(rv)) {
return rv;
}
}
return result;
return NS_OK;
}
NS_IMETHODIMP
EditAggregateTransaction::RedoTransaction()
{
nsresult result=NS_OK; // it's legal (but not very useful) to have an empty child list
// It's legal (but not very useful) to have an empty child list.
for (uint32_t i = 0, length = mChildren.Length(); i < length; ++i) {
nsITransaction *txn = mChildren[i];
if (!txn) {
return NS_ERROR_NULL_POINTER;
}
result = txn->RedoTransaction();
if (NS_FAILED(result)) {
break;
nsresult rv = txn->RedoTransaction();
if (NS_FAILED(rv)) {
return rv;
}
}
return result;
return NS_OK;
}
NS_IMETHODIMP

Просмотреть файл

@ -1451,14 +1451,14 @@ EditorBase::SplitNode(nsIContent& aNode,
mRangeUpdater.SelAdjSplitNode(aNode, aOffset, newNode);
nsresult result = aResult.StealNSResult();
nsresult rv = aResult.StealNSResult();
for (auto& listener : mActionListeners) {
listener->DidSplitNode(aNode.AsDOMNode(), aOffset, GetAsDOMNode(newNode),
result);
rv);
}
// Note: result might be a success code, so we can't use Throw() to
// set it on aResult.
aResult = result;
aResult = rv;
return newNode;
}
@ -1495,11 +1495,11 @@ EditorBase::JoinNodes(nsINode& aLeftNode,
parent->AsDOMNode());
}
nsresult result = NS_OK;
nsresult rv = NS_OK;
RefPtr<JoinNodeTransaction> transaction =
CreateTxnForJoinNode(aLeftNode, aRightNode);
if (transaction) {
result = DoTransaction(transaction);
rv = DoTransaction(transaction);
}
mRangeUpdater.SelAdjJoinNodes(aLeftNode, aRightNode, *parent, offset,
@ -1507,10 +1507,10 @@ EditorBase::JoinNodes(nsINode& aLeftNode,
for (auto& listener : mActionListeners) {
listener->DidJoinNodes(aLeftNode.AsDOMNode(), aRightNode.AsDOMNode(),
parent->AsDOMNode(), result);
parent->AsDOMNode(), rv);
}
return result;
return rv;
}
NS_IMETHODIMP

Просмотреть файл

@ -258,16 +258,16 @@ HTMLEditor::Init(nsIDOMDocument* aDoc,
NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER);
MOZ_ASSERT(aInitialValue.IsEmpty(), "Non-empty initial values not supported");
nsresult result = NS_OK, rulesRes = NS_OK;
nsresult rulesRv = NS_OK;
{
// block to scope AutoEditInitRulesTrigger
AutoEditInitRulesTrigger rulesTrigger(this, rulesRes);
AutoEditInitRulesTrigger rulesTrigger(this, rulesRv);
// Init the plaintext editor
result = TextEditor::Init(aDoc, aRoot, nullptr, aFlags, aInitialValue);
if (NS_FAILED(result)) {
return result;
nsresult rv = TextEditor::Init(aDoc, aRoot, nullptr, aFlags, aInitialValue);
if (NS_FAILED(rv)) {
return rv;
}
// Init mutation observer
@ -317,9 +317,9 @@ HTMLEditor::Init(nsIDOMDocument* aDoc,
}
}
}
NS_ENSURE_SUCCESS(rulesRv, rulesRv);
NS_ENSURE_SUCCESS(rulesRes, rulesRes);
return result;
return NS_OK;
}
NS_IMETHODIMP
@ -1553,8 +1553,8 @@ HTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement,
NS_ENSURE_SUCCESS(rv, rv);
}
nsresult result = DeleteSelectionAndPrepareToCreateNode();
NS_ENSURE_SUCCESS(result, result);
nsresult rv = DeleteSelectionAndPrepareToCreateNode();
NS_ENSURE_SUCCESS(rv, rv);
}
// If deleting, selection will be collapsed.
@ -3637,7 +3637,6 @@ HTMLEditor::IsTextPropertySetByContent(nsIDOMNode* aNode,
bool& aIsSet,
nsAString* outValue)
{
nsresult result;
aIsSet = false; // must be initialized to false for code below to work
nsAutoString propName;
aProperty->ToString(propName);
@ -3680,8 +3679,7 @@ HTMLEditor::IsTextPropertySetByContent(nsIDOMNode* aNode,
}
}
nsCOMPtr<nsIDOMNode>temp;
result = node->GetParentNode(getter_AddRefs(temp));
if (NS_SUCCEEDED(result) && temp) {
if (NS_SUCCEEDED(node->GetParentNode(getter_AddRefs(temp))) && temp) {
node = temp;
} else {
node = nullptr;
@ -3760,10 +3758,10 @@ HTMLEditor::CollapseAdjacentTextNodes(nsRange* aInRange)
// build a list of editable text nodes
nsresult result;
nsresult rv = NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIContentIterator> iter =
do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &result);
NS_ENSURE_SUCCESS(result, result);
do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
iter->Init(aInRange);
@ -3788,22 +3786,21 @@ HTMLEditor::CollapseAdjacentTextNodes(nsRange* aInRange)
// get the prev sibling of the right node, and see if its leftTextNode
nsCOMPtr<nsIDOMNode> prevSibOfRightNode;
result =
rightTextNode->GetPreviousSibling(getter_AddRefs(prevSibOfRightNode));
NS_ENSURE_SUCCESS(result, result);
rv = rightTextNode->GetPreviousSibling(getter_AddRefs(prevSibOfRightNode));
NS_ENSURE_SUCCESS(rv, rv);
if (prevSibOfRightNode && prevSibOfRightNode == leftTextNode) {
nsCOMPtr<nsIDOMNode> parent;
result = rightTextNode->GetParentNode(getter_AddRefs(parent));
NS_ENSURE_SUCCESS(result, result);
rv = rightTextNode->GetParentNode(getter_AddRefs(parent));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
result = JoinNodes(leftTextNode, rightTextNode, parent);
NS_ENSURE_SUCCESS(result, result);
rv = JoinNodes(leftTextNode, rightTextNode, parent);
NS_ENSURE_SUCCESS(rv, rv);
}
textNodes.RemoveElementAt(0); // remove the leftmost text node from the list
}
return result;
return NS_OK;
}
nsresult

Просмотреть файл

@ -346,8 +346,8 @@ RangeUpdater::SelAdjSplitNode(nsIContent& aOldRightNode,
int32_t offset = parent ? parent->IndexOf(&aOldRightNode) : -1;
// first part is same as inserting aNewLeftnode
nsresult result = SelAdjInsertNode(parent, offset - 1);
NS_ENSURE_SUCCESS(result, result);
nsresult rv = SelAdjInsertNode(parent, offset - 1);
NS_ENSURE_SUCCESS(rv, rv);
// next step is to check for range enpoints inside aOldRightNode
for (size_t i = 0; i < count; i++) {

Просмотреть файл

@ -565,8 +565,6 @@ nsresult
TextEditor::ExtendSelectionForDelete(Selection* aSelection,
nsIEditor::EDirection* aAction)
{
nsresult result = NS_OK;
bool bCollapsed = aSelection->Collapsed();
if (*aAction == eNextWord ||
@ -579,19 +577,20 @@ TextEditor::ExtendSelectionForDelete(Selection* aSelection,
GetSelectionController(getter_AddRefs(selCont));
NS_ENSURE_TRUE(selCont, NS_ERROR_NO_INTERFACE);
nsresult rv;
switch (*aAction) {
case eNextWord:
result = selCont->WordExtendForDelete(true);
rv = selCont->WordExtendForDelete(true);
// DeleteSelectionImpl doesn't handle these actions
// because it's inside batching, so don't confuse it:
*aAction = eNone;
break;
case ePreviousWord:
result = selCont->WordExtendForDelete(false);
rv = selCont->WordExtendForDelete(false);
*aAction = eNone;
break;
case eNext:
result = selCont->CharacterExtendForDelete();
rv = selCont->CharacterExtendForDelete();
// Don't set aAction to eNone (see Bug 502259)
break;
case ePrevious: {
@ -602,8 +601,8 @@ TextEditor::ExtendSelectionForDelete(Selection* aSelection,
// typed character.
nsCOMPtr<nsIDOMNode> node;
int32_t offset;
result = GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
NS_ENSURE_SUCCESS(result, result);
rv = GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
// node might be anonymous DIV, so we find better text node
@ -613,15 +612,15 @@ TextEditor::ExtendSelectionForDelete(Selection* aSelection,
nsCOMPtr<nsIDOMCharacterData> charData = do_QueryInterface(node);
if (charData) {
nsAutoString data;
result = charData->GetData(data);
NS_ENSURE_SUCCESS(result, result);
rv = charData->GetData(data);
NS_ENSURE_SUCCESS(rv, rv);
if ((offset > 1 &&
NS_IS_LOW_SURROGATE(data[offset - 1]) &&
NS_IS_HIGH_SURROGATE(data[offset - 2])) ||
(offset > 0 &&
gfxFontUtils::IsVarSelector(data[offset - 1]))) {
result = selCont->CharacterExtendForBackspace();
rv = selCont->CharacterExtendForBackspace();
}
}
}
@ -629,19 +628,20 @@ TextEditor::ExtendSelectionForDelete(Selection* aSelection,
}
case eToBeginningOfLine:
selCont->IntraLineMove(true, false); // try to move to end
result = selCont->IntraLineMove(false, true); // select to beginning
rv = selCont->IntraLineMove(false, true); // select to beginning
*aAction = eNone;
break;
case eToEndOfLine:
result = selCont->IntraLineMove(true, true);
rv = selCont->IntraLineMove(true, true);
*aAction = eNext;
break;
default: // avoid several compiler warnings
result = NS_OK;
rv = NS_OK;
break;
}
return rv;
}
return result;
return NS_OK;
}
nsresult
@ -657,8 +657,6 @@ TextEditor::DeleteSelection(EDirection aAction,
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> rules(mRules);
nsresult result;
// delete placeholder txns merge.
AutoPlaceHolderBatch batch(this, nsGkAtoms::DeleteTxnName);
AutoRules beginRulesSniffing(this, EditAction::deleteSelection, aAction);
@ -676,8 +674,8 @@ TextEditor::DeleteSelection(EDirection aAction,
(aAction == eNextWord || aAction == ePreviousWord ||
aAction == eToBeginningOfLine || aAction == eToEndOfLine)) {
if (mCaretStyle == 1) {
result = selection->CollapseToStart();
NS_ENSURE_SUCCESS(result, result);
nsresult rv = selection->CollapseToStart();
NS_ENSURE_SUCCESS(rv, rv);
} else {
aAction = eNone;
}
@ -687,17 +685,16 @@ TextEditor::DeleteSelection(EDirection aAction,
ruleInfo.collapsedAction = aAction;
ruleInfo.stripWrappers = aStripWrappers;
bool cancel, handled;
result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(result, result);
nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(rv, rv);
if (!cancel && !handled) {
result = DeleteSelectionImpl(aAction, aStripWrappers);
rv = DeleteSelectionImpl(aAction, aStripWrappers);
}
if (!cancel) {
// post-process
result = rules->DidDoAction(selection, &ruleInfo, result);
rv = rules->DidDoAction(selection, &ruleInfo, rv);
}
return result;
return rv;
}
NS_IMETHODIMP
@ -1091,15 +1088,15 @@ TextEditor::Undo(uint32_t aCount)
TextRulesInfo ruleInfo(EditAction::undo);
RefPtr<Selection> selection = GetSelection();
bool cancel, handled;
nsresult result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (!cancel && NS_SUCCEEDED(result)) {
result = EditorBase::Undo(aCount);
result = rules->DidDoAction(selection, &ruleInfo, result);
if (!cancel && NS_SUCCEEDED(rv)) {
rv = EditorBase::Undo(aCount);
rv = rules->DidDoAction(selection, &ruleInfo, rv);
}
NotifyEditorObservers(eNotifyEditorObserversOfEnd);
return result;
return rv;
}
NS_IMETHODIMP
@ -1119,15 +1116,15 @@ TextEditor::Redo(uint32_t aCount)
TextRulesInfo ruleInfo(EditAction::redo);
RefPtr<Selection> selection = GetSelection();
bool cancel, handled;
nsresult result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (!cancel && NS_SUCCEEDED(result)) {
result = EditorBase::Redo(aCount);
result = rules->DidDoAction(selection, &ruleInfo, result);
if (!cancel && NS_SUCCEEDED(rv)) {
rv = EditorBase::Redo(aCount);
rv = rules->DidDoAction(selection, &ruleInfo, rv);
}
NotifyEditorObservers(eNotifyEditorObserversOfEnd);
return result;
return rv;
}
bool

Просмотреть файл

@ -48,110 +48,112 @@ void TextEditorTest::Run(nsIEditor *aEditor, int32_t *outNumTests, int32_t *outN
nsresult TextEditorTest::RunUnitTest(int32_t *outNumTests, int32_t *outNumTestsFailed)
{
nsresult result;
NS_ENSURE_TRUE(outNumTests && outNumTestsFailed, NS_ERROR_NULL_POINTER);
*outNumTests = 0;
*outNumTestsFailed = 0;
result = InitDoc();
TEST_RESULT(result);
nsresult rv = InitDoc();
TEST_RESULT(rv);
// shouldn't we just bail on error here?
// insert some simple text
result = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890"));
TEST_RESULT(result);
rv = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890"));
TEST_RESULT(rv);
(*outNumTests)++;
if (NS_FAILED(result))
if (NS_FAILED(rv)) {
++(*outNumTestsFailed);
}
// insert some more text
result = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states. I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham. Injustice anywhere is a threat to justice everywhere"));
TEST_RESULT(result);
rv = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states. I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham. Injustice anywhere is a threat to justice everywhere"));
TEST_RESULT(rv);
(*outNumTests)++;
if (NS_FAILED(result))
if (NS_FAILED(rv)) {
++(*outNumTestsFailed);
}
result = TestInsertBreak();
TEST_RESULT(result);
rv = TestInsertBreak();
TEST_RESULT(rv);
(*outNumTests)++;
if (NS_FAILED(result))
if (NS_FAILED(rv)) {
++(*outNumTestsFailed);
}
result = TestTextProperties();
TEST_RESULT(result);
rv = TestTextProperties();
TEST_RESULT(rv);
(*outNumTests)++;
if (NS_FAILED(result))
if (NS_FAILED(rv)) {
++(*outNumTestsFailed);
}
// get us back to the original document
result = mEditor->Undo(12);
TEST_RESULT(result);
rv = mEditor->Undo(12);
TEST_RESULT(rv);
return result;
return rv;
}
nsresult TextEditorTest::InitDoc()
{
nsresult result = mEditor->SelectAll();
TEST_RESULT(result);
result = mEditor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);
TEST_RESULT(result);
return result;
nsresult rv = mEditor->SelectAll();
TEST_RESULT(rv);
rv = mEditor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);
TEST_RESULT(rv);
return rv;
}
nsresult TextEditorTest::TestInsertBreak()
{
nsCOMPtr<nsISelection>selection;
nsresult result = mEditor->GetSelection(getter_AddRefs(selection));
TEST_RESULT(result);
nsresult rv = mEditor->GetSelection(getter_AddRefs(selection));
TEST_RESULT(rv);
TEST_POINTER(selection.get());
nsCOMPtr<nsIDOMNode>anchor;
result = selection->GetAnchorNode(getter_AddRefs(anchor));
TEST_RESULT(result);
rv = selection->GetAnchorNode(getter_AddRefs(anchor));
TEST_RESULT(rv);
TEST_POINTER(anchor.get());
selection->Collapse(anchor, 0);
// insert one break
printf("inserting a break\n");
result = mTextEditor->InsertLineBreak();
TEST_RESULT(result);
rv = mTextEditor->InsertLineBreak();
TEST_RESULT(rv);
mEditor->DebugDumpContent();
// insert a second break adjacent to the first
printf("inserting a second break\n");
result = mTextEditor->InsertLineBreak();
TEST_RESULT(result);
rv = mTextEditor->InsertLineBreak();
TEST_RESULT(rv);
mEditor->DebugDumpContent();
return result;
return rv;
}
nsresult TextEditorTest::TestTextProperties()
{
nsCOMPtr<nsIDOMDocument>doc;
nsresult result = mEditor->GetDocument(getter_AddRefs(doc));
TEST_RESULT(result);
nsresult rv = mEditor->GetDocument(getter_AddRefs(doc));
TEST_RESULT(rv);
TEST_POINTER(doc.get());
nsCOMPtr<nsIDOMNodeList>nodeList;
// XXX This is broken, text nodes are not elements.
nsAutoString textTag(NS_LITERAL_STRING("#text"));
result = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
TEST_RESULT(result);
rv = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
TEST_RESULT(rv);
TEST_POINTER(nodeList.get());
uint32_t count;
nodeList->GetLength(&count);
NS_ASSERTION(0!=count, "there are no text nodes in the document!");
nsCOMPtr<nsIDOMNode>textNode;
result = nodeList->Item(count-1, getter_AddRefs(textNode));
TEST_RESULT(result);
rv = nodeList->Item(count - 1, getter_AddRefs(textNode));
TEST_RESULT(rv);
TEST_POINTER(textNode.get());
// set the whole text node to bold
printf("set the whole first text node to bold\n");
nsCOMPtr<nsISelection>selection;
result = mEditor->GetSelection(getter_AddRefs(selection));
TEST_RESULT(result);
rv = mEditor->GetSelection(getter_AddRefs(selection));
TEST_RESULT(rv);
TEST_POINTER(selection.get());
nsCOMPtr<nsIDOMCharacterData>textData;
textData = do_QueryInterface(textNode);
@ -169,17 +171,17 @@ nsresult TextEditorTest::TestTextProperties()
const nsAFlatString& empty = EmptyString();
result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
&any, &all);
TEST_RESULT(result);
rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
&any, &all);
TEST_RESULT(rv);
NS_ASSERTION(false==first, "first should be false");
NS_ASSERTION(false==any, "any should be false");
NS_ASSERTION(false==all, "all should be false");
result = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
TEST_RESULT(result);
result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
&any, &all);
TEST_RESULT(result);
rv = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
TEST_RESULT(rv);
rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
&any, &all);
TEST_RESULT(rv);
NS_ASSERTION(true==first, "first should be true");
NS_ASSERTION(true==any, "any should be true");
NS_ASSERTION(true==all, "all should be true");
@ -187,11 +189,11 @@ nsresult TextEditorTest::TestTextProperties()
// remove the bold we just set
printf("set the whole first text node to not bold\n");
result = htmlEditor->RemoveInlineProperty(nsGkAtoms::b, empty);
TEST_RESULT(result);
result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
&any, &all);
TEST_RESULT(result);
rv = htmlEditor->RemoveInlineProperty(nsGkAtoms::b, empty);
TEST_RESULT(rv);
rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
&any, &all);
TEST_RESULT(rv);
NS_ASSERTION(false==first, "first should be false");
NS_ASSERTION(false==any, "any should be false");
NS_ASSERTION(false==all, "all should be false");
@ -201,61 +203,57 @@ nsresult TextEditorTest::TestTextProperties()
printf("set the first text node (1, length-1) to bold and italic, and (2, length-1) to underline.\n");
selection->Collapse(textNode, 1);
selection->Extend(textNode, length-1);
result = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
TEST_RESULT(result);
result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
&any, &all);
TEST_RESULT(result);
rv = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
TEST_RESULT(rv);
rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
&any, &all);
TEST_RESULT(rv);
NS_ASSERTION(true==first, "first should be true");
NS_ASSERTION(true==any, "any should be true");
NS_ASSERTION(true==all, "all should be true");
mEditor->DebugDumpContent();
// make all that same text italic
result = htmlEditor->SetInlineProperty(nsGkAtoms::i, empty, empty);
TEST_RESULT(result);
result = htmlEditor->GetInlineProperty(nsGkAtoms::i, empty, empty, &first,
&any, &all);
TEST_RESULT(result);
rv = htmlEditor->SetInlineProperty(nsGkAtoms::i, empty, empty);
TEST_RESULT(rv);
rv = htmlEditor->GetInlineProperty(nsGkAtoms::i, empty, empty, &first,
&any, &all);
TEST_RESULT(rv);
NS_ASSERTION(true==first, "first should be true");
NS_ASSERTION(true==any, "any should be true");
NS_ASSERTION(true==all, "all should be true");
result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
&any, &all);
TEST_RESULT(result);
rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
&any, &all);
TEST_RESULT(rv);
NS_ASSERTION(true==first, "first should be true");
NS_ASSERTION(true==any, "any should be true");
NS_ASSERTION(true==all, "all should be true");
mEditor->DebugDumpContent();
// make all the text underlined, except for the first 2 and last 2 characters
result = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
TEST_RESULT(result);
rv = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
TEST_RESULT(rv);
TEST_POINTER(nodeList.get());
nodeList->GetLength(&count);
NS_ASSERTION(0!=count, "there are no text nodes in the document!");
result = nodeList->Item(count-2, getter_AddRefs(textNode));
TEST_RESULT(result);
rv = nodeList->Item(count-2, getter_AddRefs(textNode));
TEST_RESULT(rv);
TEST_POINTER(textNode.get());
textData = do_QueryInterface(textNode);
textData->GetLength(&length);
NS_ASSERTION(length==915, "wrong text node");
selection->Collapse(textNode, 1);
selection->Extend(textNode, length-2);
result = htmlEditor->SetInlineProperty(nsGkAtoms::u, empty, empty);
TEST_RESULT(result);
result = htmlEditor->GetInlineProperty(nsGkAtoms::u, empty, empty, &first,
&any, &all);
TEST_RESULT(result);
rv = htmlEditor->SetInlineProperty(nsGkAtoms::u, empty, empty);
TEST_RESULT(rv);
rv = htmlEditor->GetInlineProperty(nsGkAtoms::u, empty, empty, &first,
&any, &all);
TEST_RESULT(rv);
NS_ASSERTION(true==first, "first should be true");
NS_ASSERTION(true==any, "any should be true");
NS_ASSERTION(true==all, "all should be true");
mEditor->DebugDumpContent();
return result;
return rv;
}
#endif

Просмотреть файл

@ -93,11 +93,11 @@ TypeInState::NotifySelectionChanged(nsIDOMDocument* aDOMDocument,
nsCOMPtr<nsIDOMNode> selNode;
int32_t selOffset = 0;
nsresult result =
nsresult rv =
EditorBase::GetStartNodeAndOffset(selection, getter_AddRefs(selNode),
&selOffset);
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_SUCCESS(rv, rv);
if (selNode &&
selNode == mLastSelectionContainer &&

Просмотреть файл

@ -96,8 +96,6 @@ nsTransactionItem::GetIsBatch(bool *aIsBatch)
nsresult
nsTransactionItem::GetNumberOfChildren(int32_t *aNumChildren)
{
nsresult result;
NS_ENSURE_TRUE(aNumChildren, NS_ERROR_NULL_POINTER);
*aNumChildren = 0;
@ -105,13 +103,13 @@ nsTransactionItem::GetNumberOfChildren(int32_t *aNumChildren)
int32_t ui = 0;
int32_t ri = 0;
result = GetNumberOfUndoItems(&ui);
nsresult rv = GetNumberOfUndoItems(&ui);
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_SUCCESS(rv, rv);
result = GetNumberOfRedoItems(&ri);
rv = GetNumberOfRedoItems(&ri);
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_SUCCESS(rv, rv);
*aNumChildren = ui + ri;
@ -126,21 +124,22 @@ nsTransactionItem::GetChild(int32_t aIndex, nsTransactionItem **aChild)
*aChild = 0;
int32_t numItems = 0;
nsresult result = GetNumberOfChildren(&numItems);
nsresult rv = GetNumberOfChildren(&numItems);
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_SUCCESS(rv, rv);
if (aIndex < 0 || aIndex >= numItems)
if (aIndex < 0 || aIndex >= numItems) {
return NS_ERROR_FAILURE;
}
// Children are expected to be in the order they were added,
// so the child first added would be at the bottom of the undo
// stack, or if there are no items on the undo stack, it would
// be at the top of the redo stack.
result = GetNumberOfUndoItems(&numItems);
rv = GetNumberOfUndoItems(&numItems);
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_SUCCESS(rv, rv);
if (numItems > 0 && aIndex < numItems) {
NS_ENSURE_TRUE(mUndoStack, NS_ERROR_FAILURE);
@ -154,9 +153,9 @@ nsTransactionItem::GetChild(int32_t aIndex, nsTransactionItem **aChild)
aIndex -= numItems;
result = GetNumberOfRedoItems(&numItems);
rv = GetNumberOfRedoItems(&numItems);
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(mRedoStack && numItems != 0 && aIndex < numItems, NS_ERROR_FAILURE);
@ -168,29 +167,31 @@ nsTransactionItem::GetChild(int32_t aIndex, nsTransactionItem **aChild)
nsresult
nsTransactionItem::DoTransaction()
{
if (mTransaction)
if (mTransaction) {
return mTransaction->DoTransaction();
}
return NS_OK;
}
nsresult
nsTransactionItem::UndoTransaction(nsTransactionManager *aTxMgr)
{
nsresult result = UndoChildren(aTxMgr);
nsresult rv = UndoChildren(aTxMgr);
if (NS_FAILED(result)) {
if (NS_FAILED(rv)) {
RecoverFromUndoError(aTxMgr);
return result;
return rv;
}
if (!mTransaction)
if (!mTransaction) {
return NS_OK;
}
result = mTransaction->UndoTransaction();
rv = mTransaction->UndoTransaction();
if (NS_FAILED(result)) {
if (NS_FAILED(rv)) {
RecoverFromUndoError(aTxMgr);
return result;
return rv;
}
return NS_OK;
@ -200,7 +201,6 @@ nsresult
nsTransactionItem::UndoChildren(nsTransactionManager *aTxMgr)
{
RefPtr<nsTransactionItem> item;
nsresult result = NS_OK;
int32_t sz = 0;
if (mUndoStack) {
@ -211,6 +211,7 @@ nsTransactionItem::UndoChildren(nsTransactionManager *aTxMgr)
/* Undo all of the transaction items children! */
sz = mUndoStack->GetSize();
nsresult rv = NS_OK;
while (sz-- > 0) {
item = mUndoStack->Peek();
@ -222,51 +223,53 @@ nsTransactionItem::UndoChildren(nsTransactionManager *aTxMgr)
bool doInterrupt = false;
result = aTxMgr->WillUndoNotify(t, &doInterrupt);
rv = aTxMgr->WillUndoNotify(t, &doInterrupt);
if (NS_FAILED(result)) {
return result;
if (NS_FAILED(rv)) {
return rv;
}
if (doInterrupt) {
return NS_OK;
}
result = item->UndoTransaction(aTxMgr);
rv = item->UndoTransaction(aTxMgr);
if (NS_SUCCEEDED(result)) {
if (NS_SUCCEEDED(rv)) {
item = mUndoStack->Pop();
mRedoStack->Push(item.forget());
}
nsresult result2 = aTxMgr->DidUndoNotify(t, result);
nsresult rv2 = aTxMgr->DidUndoNotify(t, rv);
if (NS_SUCCEEDED(result)) {
result = result2;
if (NS_SUCCEEDED(rv)) {
rv = rv2;
}
}
// XXX NS_OK if there is no Undo items or all methods work fine, otherwise,
// the result of the last item's UndoTransaction() or
// DidUndoNotify() if UndoTransaction() succeeded.
return rv;
}
return result;
return NS_OK;
}
nsresult
nsTransactionItem::RedoTransaction(nsTransactionManager *aTxMgr)
{
nsresult result;
nsCOMPtr<nsITransaction> transaction(mTransaction);
if (transaction) {
result = transaction->RedoTransaction();
nsresult rv = transaction->RedoTransaction();
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_SUCCESS(rv, rv);
}
result = RedoChildren(aTxMgr);
nsresult rv = RedoChildren(aTxMgr);
if (NS_FAILED(result)) {
if (NS_FAILED(rv)) {
RecoverFromRedoError(aTxMgr);
return result;
return rv;
}
return NS_OK;
@ -276,14 +279,15 @@ nsresult
nsTransactionItem::RedoChildren(nsTransactionManager *aTxMgr)
{
RefPtr<nsTransactionItem> item;
nsresult result = NS_OK;
if (!mRedoStack)
if (!mRedoStack) {
return NS_OK;
}
/* Redo all of the transaction items children! */
int32_t sz = mRedoStack->GetSize();
nsresult rv = NS_OK;
while (sz-- > 0) {
item = mRedoStack->Peek();
@ -295,31 +299,34 @@ nsTransactionItem::RedoChildren(nsTransactionManager *aTxMgr)
bool doInterrupt = false;
result = aTxMgr->WillRedoNotify(t, &doInterrupt);
rv = aTxMgr->WillRedoNotify(t, &doInterrupt);
if (NS_FAILED(result)) {
return result;
if (NS_FAILED(rv)) {
return rv;
}
if (doInterrupt) {
return NS_OK;
}
result = item->RedoTransaction(aTxMgr);
rv = item->RedoTransaction(aTxMgr);
if (NS_SUCCEEDED(result)) {
if (NS_SUCCEEDED(rv)) {
item = mRedoStack->Pop();
mUndoStack->Push(item.forget());
}
nsresult result2 = aTxMgr->DidUndoNotify(t, result);
// XXX Shouldn't this DidRedoNotify()? (bug 1311626)
nsresult rv2 = aTxMgr->DidUndoNotify(t, rv);
if (NS_SUCCEEDED(result)) {
result = result2;
if (NS_SUCCEEDED(rv)) {
rv = rv2;
}
}
return result;
// XXX NS_OK if there is no Redo items or all methods work fine, otherwise,
// the result of the last item's RedoTransaction() or
// DidUndoNotify() if UndoTransaction() succeeded.
return rv;
}
nsresult
@ -371,16 +378,15 @@ nsTransactionItem::RecoverFromRedoError(nsTransactionManager *aTxMgr)
// then undo the transaction item itself.
//
nsresult result;
nsresult rv = UndoChildren(aTxMgr);
result = UndoChildren(aTxMgr);
if (NS_FAILED(result)) {
return result;
if (NS_FAILED(rv)) {
return rv;
}
if (!mTransaction)
if (!mTransaction) {
return NS_OK;
}
return mTransaction->UndoTransaction();
}

Просмотреть файл

@ -49,14 +49,13 @@ NS_IMETHODIMP nsTransactionList::GetNumItems(int32_t *aNumItems)
NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
nsresult result = NS_OK;
if (mTxnStack)
if (mTxnStack) {
*aNumItems = mTxnStack->GetSize();
else if (mTxnItem)
result = mTxnItem->GetNumberOfChildren(aNumItems);
} else if (mTxnItem) {
return mTxnItem->GetNumberOfChildren(aNumItems);
}
return result;
return NS_OK;
}
NS_IMETHODIMP nsTransactionList::ItemIsBatch(int32_t aIndex, bool *aIsBatch)
@ -71,14 +70,12 @@ NS_IMETHODIMP nsTransactionList::ItemIsBatch(int32_t aIndex, bool *aIsBatch)
RefPtr<nsTransactionItem> item;
nsresult result = NS_OK;
if (mTxnStack)
if (mTxnStack) {
item = mTxnStack->GetItem(aIndex);
else if (mTxnItem)
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
NS_ENSURE_SUCCESS(result, result);
} else if (mTxnItem) {
nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
NS_ENSURE_SUCCESS(rv, rv);
}
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
@ -98,8 +95,8 @@ NS_IMETHODIMP nsTransactionList::GetData(int32_t aIndex,
if (mTxnStack) {
item = mTxnStack->GetItem(aIndex);
} else if (mTxnItem) {
nsresult result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
NS_ENSURE_SUCCESS(result, result);
nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMArray<nsISupports>& data = item->GetData();
@ -129,14 +126,12 @@ NS_IMETHODIMP nsTransactionList::GetItem(int32_t aIndex, nsITransaction **aItem)
RefPtr<nsTransactionItem> item;
nsresult result = NS_OK;
if (mTxnStack)
if (mTxnStack) {
item = mTxnStack->GetItem(aIndex);
else if (mTxnItem)
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
NS_ENSURE_SUCCESS(result, result);
} else if (mTxnItem) {
nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
NS_ENSURE_SUCCESS(rv, rv);
}
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
@ -157,14 +152,12 @@ NS_IMETHODIMP nsTransactionList::GetNumChildrenForItem(int32_t aIndex, int32_t *
RefPtr<nsTransactionItem> item;
nsresult result = NS_OK;
if (mTxnStack)
if (mTxnStack) {
item = mTxnStack->GetItem(aIndex);
else if (mTxnItem)
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
NS_ENSURE_SUCCESS(result, result);
} else if (mTxnItem) {
nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
NS_ENSURE_SUCCESS(rv, rv);
}
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
@ -183,14 +176,12 @@ NS_IMETHODIMP nsTransactionList::GetChildListForItem(int32_t aIndex, nsITransact
RefPtr<nsTransactionItem> item;
nsresult result = NS_OK;
if (mTxnStack)
if (mTxnStack) {
item = mTxnStack->GetItem(aIndex);
else if (mTxnItem)
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
NS_ENSURE_SUCCESS(result, result);
} else if (mTxnItem) {
nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
NS_ENSURE_SUCCESS(rv, rv);
}
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
@ -202,4 +193,3 @@ NS_IMETHODIMP nsTransactionList::GetChildListForItem(int32_t aIndex, nsITransact
return NS_OK;
}

Просмотреть файл

@ -59,45 +59,43 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTransactionManager)
NS_IMETHODIMP
nsTransactionManager::DoTransaction(nsITransaction *aTransaction)
{
nsresult result;
NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
bool doInterrupt = false;
result = WillDoNotify(aTransaction, &doInterrupt);
nsresult rv = WillDoNotify(aTransaction, &doInterrupt);
if (NS_FAILED(result)) {
return result;
if (NS_FAILED(rv)) {
return rv;
}
if (doInterrupt) {
return NS_OK;
}
result = BeginTransaction(aTransaction, nullptr);
rv = BeginTransaction(aTransaction, nullptr);
if (NS_FAILED(result)) {
DidDoNotify(aTransaction, result);
return result;
if (NS_FAILED(rv)) {
DidDoNotify(aTransaction, rv);
return rv;
}
result = EndTransaction(false);
rv = EndTransaction(false);
nsresult result2 = DidDoNotify(aTransaction, result);
nsresult rv2 = DidDoNotify(aTransaction, rv);
if (NS_SUCCEEDED(result)) {
result = result2;
if (NS_SUCCEEDED(rv)) {
rv = rv2;
}
return result;
// XXX The result of EndTransaction() or DidDoNotify() if EndTransaction()
// succeeded.
return rv;
}
NS_IMETHODIMP
nsTransactionManager::UndoTransaction()
{
nsresult result = NS_OK;
// It is illegal to call UndoTransaction() while the transaction manager is
// executing a transaction's DoTransaction() method! If this happens,
// the UndoTransaction() request is ignored, and we return NS_ERROR_FAILURE.
@ -119,37 +117,37 @@ nsTransactionManager::UndoTransaction()
bool doInterrupt = false;
result = WillUndoNotify(t, &doInterrupt);
nsresult rv = WillUndoNotify(t, &doInterrupt);
if (NS_FAILED(result)) {
return result;
if (NS_FAILED(rv)) {
return rv;
}
if (doInterrupt) {
return NS_OK;
}
result = tx->UndoTransaction(this);
rv = tx->UndoTransaction(this);
if (NS_SUCCEEDED(result)) {
if (NS_SUCCEEDED(rv)) {
tx = mUndoStack.Pop();
mRedoStack.Push(tx.forget());
}
nsresult result2 = DidUndoNotify(t, result);
nsresult rv2 = DidUndoNotify(t, rv);
if (NS_SUCCEEDED(result)) {
result = result2;
if (NS_SUCCEEDED(rv)) {
rv = rv2;
}
return result;
// XXX The result of UndoTransaction() or DidUndoNotify() if UndoTransaction()
// succeeded.
return rv;
}
NS_IMETHODIMP
nsTransactionManager::RedoTransaction()
{
nsresult result = NS_OK;
// It is illegal to call RedoTransaction() while the transaction manager is
// executing a transaction's DoTransaction() method! If this happens,
// the RedoTransaction() request is ignored, and we return NS_ERROR_FAILURE.
@ -171,53 +169,49 @@ nsTransactionManager::RedoTransaction()
bool doInterrupt = false;
result = WillRedoNotify(t, &doInterrupt);
nsresult rv = WillRedoNotify(t, &doInterrupt);
if (NS_FAILED(result)) {
return result;
if (NS_FAILED(rv)) {
return rv;
}
if (doInterrupt) {
return NS_OK;
}
result = tx->RedoTransaction(this);
rv = tx->RedoTransaction(this);
if (NS_SUCCEEDED(result)) {
if (NS_SUCCEEDED(rv)) {
tx = mRedoStack.Pop();
mUndoStack.Push(tx.forget());
}
nsresult result2 = DidRedoNotify(t, result);
nsresult rv2 = DidRedoNotify(t, rv);
if (NS_SUCCEEDED(result)) {
result = result2;
if (NS_SUCCEEDED(rv)) {
rv = rv2;
}
return result;
// XXX The result of RedoTransaction() or DidRedoNotify() if RedoTransaction()
// succeeded.
return rv;
}
NS_IMETHODIMP
nsTransactionManager::Clear()
{
nsresult result;
nsresult rv = ClearRedoStack();
result = ClearRedoStack();
if (NS_FAILED(result)) {
return result;
if (NS_FAILED(rv)) {
return rv;
}
result = ClearUndoStack();
return result;
return ClearUndoStack();
}
NS_IMETHODIMP
nsTransactionManager::BeginBatch(nsISupports* aData)
{
nsresult result;
// We can batch independent transactions together by simply pushing
// a dummy transaction item on the do stack. This dummy transaction item
// will be popped off the do stack, and then pushed on the undo stack
@ -225,33 +219,32 @@ nsTransactionManager::BeginBatch(nsISupports* aData)
bool doInterrupt = false;
result = WillBeginBatchNotify(&doInterrupt);
nsresult rv = WillBeginBatchNotify(&doInterrupt);
if (NS_FAILED(result)) {
return result;
if (NS_FAILED(rv)) {
return rv;
}
if (doInterrupt) {
return NS_OK;
}
result = BeginTransaction(0, aData);
rv = BeginTransaction(0, aData);
nsresult result2 = DidBeginBatchNotify(result);
nsresult rv2 = DidBeginBatchNotify(rv);
if (NS_SUCCEEDED(result)) {
result = result2;
if (NS_SUCCEEDED(rv)) {
rv = rv2;
}
return result;
// XXX The result of BeginTransaction() or DidBeginBatchNotify() if
// BeginTransaction() succeeded.
return rv;
}
NS_IMETHODIMP
nsTransactionManager::EndBatch(bool aAllowEmpty)
{
nsCOMPtr<nsITransaction> ti;
nsresult result;
// XXX: Need to add some mechanism to detect the case where the transaction
// at the top of the do stack isn't the dummy transaction, so we can
// throw an error!! This can happen if someone calls EndBatch() within
@ -265,6 +258,7 @@ nsTransactionManager::EndBatch(bool aAllowEmpty)
RefPtr<nsTransactionItem> tx = mDoStack.Peek();
nsCOMPtr<nsITransaction> ti;
if (tx) {
ti = tx->GetTransaction();
}
@ -275,25 +269,27 @@ nsTransactionManager::EndBatch(bool aAllowEmpty)
bool doInterrupt = false;
result = WillEndBatchNotify(&doInterrupt);
nsresult rv = WillEndBatchNotify(&doInterrupt);
if (NS_FAILED(result)) {
return result;
if (NS_FAILED(rv)) {
return rv;
}
if (doInterrupt) {
return NS_OK;
}
result = EndTransaction(aAllowEmpty);
rv = EndTransaction(aAllowEmpty);
nsresult result2 = DidEndBatchNotify(result);
nsresult rv2 = DidEndBatchNotify(rv);
if (NS_SUCCEEDED(result)) {
result = result2;
if (NS_SUCCEEDED(rv)) {
rv = rv2;
}
return result;
// XXX The result of EndTransaction() or DidEndBatchNotify() if
// EndTransaction() succeeded.
return rv;
}
NS_IMETHODIMP
@ -470,7 +466,7 @@ nsTransactionManager::BatchTopUndo()
previousUndo = mUndoStack.Peek();
MOZ_ASSERT(previousUndo, "There should be at least two transactions.");
nsresult result = previousUndo->AddChild(lastUndo);
nsresult rv = previousUndo->AddChild(lastUndo);
// Transfer data from the transactions that is going to be
// merged to the transaction that it is being merged with.
@ -479,7 +475,7 @@ nsTransactionManager::BatchTopUndo()
NS_ENSURE_TRUE(previousData.AppendObjects(lastData), NS_ERROR_UNEXPECTED);
lastData.Clear();
return result;
return rv;
}
nsresult
@ -526,210 +522,199 @@ nsTransactionManager::ClearRedoStack()
nsresult
nsTransactionManager::WillDoNotify(nsITransaction *aTransaction, bool *aInterrupt)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->WillDo(this, aTransaction, aInterrupt);
nsresult rv = listener->WillDo(this, aTransaction, aInterrupt);
if (NS_FAILED(result) || *aInterrupt) {
break;
if (NS_FAILED(rv) || *aInterrupt) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
nsTransactionManager::DidDoNotify(nsITransaction *aTransaction, nsresult aDoResult)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->DidDo(this, aTransaction, aDoResult);
nsresult rv = listener->DidDo(this, aTransaction, aDoResult);
if (NS_FAILED(result)) {
break;
if (NS_FAILED(rv)) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
nsTransactionManager::WillUndoNotify(nsITransaction *aTransaction, bool *aInterrupt)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->WillUndo(this, aTransaction, aInterrupt);
nsresult rv = listener->WillUndo(this, aTransaction, aInterrupt);
if (NS_FAILED(result) || *aInterrupt) {
break;
if (NS_FAILED(rv) || *aInterrupt) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
nsTransactionManager::DidUndoNotify(nsITransaction *aTransaction, nsresult aUndoResult)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->DidUndo(this, aTransaction, aUndoResult);
nsresult rv = listener->DidUndo(this, aTransaction, aUndoResult);
if (NS_FAILED(result)) {
break;
if (NS_FAILED(rv)) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
nsTransactionManager::WillRedoNotify(nsITransaction *aTransaction, bool *aInterrupt)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->WillRedo(this, aTransaction, aInterrupt);
nsresult rv = listener->WillRedo(this, aTransaction, aInterrupt);
if (NS_FAILED(result) || *aInterrupt) {
break;
if (NS_FAILED(rv) || *aInterrupt) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
nsTransactionManager::DidRedoNotify(nsITransaction *aTransaction, nsresult aRedoResult)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->DidRedo(this, aTransaction, aRedoResult);
nsresult rv = listener->DidRedo(this, aTransaction, aRedoResult);
if (NS_FAILED(result)) {
break;
if (NS_FAILED(rv)) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
nsTransactionManager::WillBeginBatchNotify(bool *aInterrupt)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->WillBeginBatch(this, aInterrupt);
nsresult rv = listener->WillBeginBatch(this, aInterrupt);
if (NS_FAILED(result) || *aInterrupt) {
break;
if (NS_FAILED(rv) || *aInterrupt) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
nsTransactionManager::DidBeginBatchNotify(nsresult aResult)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->DidBeginBatch(this, aResult);
nsresult rv = listener->DidBeginBatch(this, aResult);
if (NS_FAILED(result)) {
break;
if (NS_FAILED(rv)) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
nsTransactionManager::WillEndBatchNotify(bool *aInterrupt)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->WillEndBatch(this, aInterrupt);
nsresult rv = listener->WillEndBatch(this, aInterrupt);
if (NS_FAILED(result) || *aInterrupt) {
break;
if (NS_FAILED(rv) || *aInterrupt) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
nsTransactionManager::DidEndBatchNotify(nsresult aResult)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->DidEndBatch(this, aResult);
nsresult rv = listener->DidEndBatch(this, aResult);
if (NS_FAILED(result)) {
break;
if (NS_FAILED(rv)) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
nsTransactionManager::WillMergeNotify(nsITransaction *aTop, nsITransaction *aTransaction, bool *aInterrupt)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->WillMerge(this, aTop, aTransaction, aInterrupt);
nsresult rv = listener->WillMerge(this, aTop, aTransaction, aInterrupt);
if (NS_FAILED(result) || *aInterrupt) {
break;
if (NS_FAILED(rv) || *aInterrupt) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
@ -738,28 +723,26 @@ nsTransactionManager::DidMergeNotify(nsITransaction *aTop,
bool aDidMerge,
nsresult aMergeResult)
{
nsresult result = NS_OK;
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
nsITransactionListener *listener = mListeners[i];
nsITransactionListener* listener = mListeners[i];
NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
result = listener->DidMerge(this, aTop, aTransaction, aDidMerge, aMergeResult);
nsresult rv =
listener->DidMerge(this, aTop, aTransaction, aDidMerge, aMergeResult);
if (NS_FAILED(result)) {
break;
if (NS_FAILED(rv)) {
return rv;
}
}
return result;
return NS_OK;
}
nsresult
nsTransactionManager::BeginTransaction(nsITransaction *aTransaction,
nsISupports *aData)
{
nsresult result = NS_OK;
// XXX: POSSIBLE OPTIMIZATION
// We could use a factory that pre-allocates/recycles transaction items.
RefPtr<nsTransactionItem> tx = new nsTransactionItem(aTransaction);
@ -775,11 +758,11 @@ nsTransactionManager::BeginTransaction(nsITransaction *aTransaction,
mDoStack.Push(tx);
result = tx->DoTransaction();
nsresult rv = tx->DoTransaction();
if (NS_FAILED(result)) {
if (NS_FAILED(rv)) {
tx = mDoStack.Pop();
return result;
return rv;
}
return NS_OK;
@ -788,8 +771,6 @@ nsTransactionManager::BeginTransaction(nsITransaction *aTransaction,
nsresult
nsTransactionManager::EndTransaction(bool aAllowEmpty)
{
nsresult result = NS_OK;
RefPtr<nsTransactionItem> tx = mDoStack.Pop();
if (!tx) {
@ -807,7 +788,7 @@ nsTransactionManager::EndTransaction(bool aAllowEmpty)
tx->GetNumberOfChildren(&nc);
if (!nc) {
return result;
return NS_OK;
}
}
@ -815,15 +796,15 @@ nsTransactionManager::EndTransaction(bool aAllowEmpty)
// more to do, just return.
bool isTransient = false;
nsresult rv = NS_OK;
if (tint) {
result = tint->GetIsTransient(&isTransient);
rv = tint->GetIsTransient(&isTransient);
}
if (NS_FAILED(result) || isTransient || !mMaxTransactionCount) {
if (NS_FAILED(rv) || isTransient || !mMaxTransactionCount) {
// XXX: Should we be clearing the redo stack if the transaction
// is transient and there is nothing on the do stack?
return result;
return rv;
}
// Check if there is a transaction on the do stack. If there is,
@ -832,18 +813,14 @@ nsTransactionManager::EndTransaction(bool aAllowEmpty)
RefPtr<nsTransactionItem> top = mDoStack.Peek();
if (top) {
result = top->AddChild(tx);
// XXX: What do we do if this fails?
return result;
return top->AddChild(tx); // XXX: What do we do if this fails?
}
// The transaction succeeded, so clear the redo stack.
result = ClearRedoStack();
rv = ClearRedoStack();
if (NS_FAILED(result)) {
if (NS_FAILED(rv)) {
// XXX: What do we do if this fails?
}
@ -860,25 +837,25 @@ nsTransactionManager::EndTransaction(bool aAllowEmpty)
bool doInterrupt = false;
result = WillMergeNotify(topTransaction, tint, &doInterrupt);
rv = WillMergeNotify(topTransaction, tint, &doInterrupt);
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_SUCCESS(rv, rv);
if (!doInterrupt) {
result = topTransaction->Merge(tint, &didMerge);
rv = topTransaction->Merge(tint, &didMerge);
nsresult result2 = DidMergeNotify(topTransaction, tint, didMerge, result);
nsresult rv2 = DidMergeNotify(topTransaction, tint, didMerge, rv);
if (NS_SUCCEEDED(result)) {
result = result2;
if (NS_SUCCEEDED(rv)) {
rv = rv2;
}
if (NS_FAILED(result)) {
if (NS_FAILED(rv)) {
// XXX: What do we do if this fails?
}
if (didMerge) {
return result;
return rv;
}
}
}
@ -899,4 +876,3 @@ nsTransactionManager::EndTransaction(bool aAllowEmpty)
return NS_OK;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу