diff --git a/editor/composer/src/nsComposerCommands.cpp b/editor/composer/src/nsComposerCommands.cpp index ba8813f44f7..3ecb300fe2b 100644 --- a/editor/composer/src/nsComposerCommands.cpp +++ b/editor/composer/src/nsComposerCommands.cpp @@ -317,7 +317,7 @@ nsListCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, PRBool bMixed; PRUnichar *tagStr; nsresult rv = GetListState(aEditor,&bMixed, &tagStr); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Need to use mTagName???? PRBool inList = (0 == nsCRT::strcmp(tagStr, @@ -380,7 +380,7 @@ nsListItemCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, PRBool bMixed, bLI, bDT, bDD; nsresult rv = htmlEditor->GetListItemState(&bMixed, &bLI, &bDT, &bDD); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); PRBool inList = PR_FALSE; if (!bMixed) @@ -414,7 +414,7 @@ nsListItemCommand::ToggleState(nsIEditor *aEditor, const char* aTagName) rv = params->GetBooleanValue(STATE_ALL,&inList); if (NS_FAILED(rv)) return rv; - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (inList) { @@ -422,7 +422,7 @@ nsListItemCommand::ToggleState(nsIEditor *aEditor, const char* aTagName) PRBool bMixed; PRUnichar *tagStr; rv = GetListState(aEditor,&bMixed, &tagStr); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (tagStr) { if (!bMixed) @@ -461,7 +461,7 @@ nsRemoveListCommand::IsCommandEnabled(const char * aCommandName, PRBool bMixed; PRUnichar *tagStr; nsresult rv = GetListState(editor, &bMixed, &tagStr); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); *outCmdEnabled = bMixed ? PR_TRUE : (tagStr && *tagStr); @@ -816,7 +816,7 @@ nsFontSizeStateCommand::GetCurrentState(nsIEditor *aEditor, EmptyString(), &firstHas, &anyHas, &allHas, outStateString); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCAutoString tOutStateString; tOutStateString.AssignWithConversion(outStateString); @@ -851,15 +851,15 @@ nsFontSizeStateCommand::SetState(nsIEditor *aEditor, nsString& newState) newState.EqualsLiteral("medium")) { // remove any existing font size, big or small rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("size")); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr bigAtom = do_GetAtom("big"); rv = htmlEditor->RemoveInlineProperty(bigAtom, EmptyString()); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr smallAtom = do_GetAtom("small"); rv = htmlEditor->RemoveInlineProperty(smallAtom, EmptyString()); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } else { // set the size rv = htmlEditor->SetInlineProperty(fontAtom, NS_LITERAL_STRING("size"), @@ -1150,7 +1150,7 @@ nsAbsolutePositioningCommand::ToggleState(nsIEditor *aEditor, const char* aTagNa nsCOMPtr elt; nsresult rv = htmlEditor->GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(elt)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (elt) { // we have to remove positioning on an element @@ -1185,7 +1185,7 @@ nsDecreaseZIndexCommand::IsCommandEnabled(const char * aCommandName, if (positionedElement) { PRInt32 z; nsresult res = htmlEditor->GetElementZIndex(positionedElement, &z); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *outCmdEnabled = (z > 0); } diff --git a/editor/composer/src/nsComposerCommandsUpdater.cpp b/editor/composer/src/nsComposerCommandsUpdater.cpp index 5f814d1e05f..b034083e259 100644 --- a/editor/composer/src/nsComposerCommandsUpdater.cpp +++ b/editor/composer/src/nsComposerCommandsUpdater.cpp @@ -262,7 +262,7 @@ nsComposerCommandsUpdater::PrimeUpdateTimer() { nsresult rv = NS_OK; mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1", &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } const PRUint32 kUpdateTimerDelay = 150; diff --git a/editor/composer/src/nsComposerDocumentCommands.cpp b/editor/composer/src/nsComposerDocumentCommands.cpp index 6d301d758af..bab1c06079d 100644 --- a/editor/composer/src/nsComposerDocumentCommands.cpp +++ b/editor/composer/src/nsComposerDocumentCommands.cpp @@ -76,7 +76,7 @@ GetPresContextFromEditor(nsIEditor *aEditor, nsPresContext **aResult) nsCOMPtr selCon; nsresult rv = aEditor->GetSelectionController(getter_AddRefs(selCon)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!selCon) return NS_ERROR_FAILURE; nsCOMPtr presShell = do_QueryInterface(selCon); @@ -116,7 +116,7 @@ nsSetDocumentOptionsCommand::DoCommandParams(const char *aCommandName, nsRefPtr presContext; nsresult rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!presContext) return NS_ERROR_FAILURE; PRInt32 animationMode; @@ -136,11 +136,11 @@ nsSetDocumentOptionsCommand::DoCommandParams(const char *aCommandName, if (!container) return NS_ERROR_FAILURE; nsCOMPtr docShell(do_QueryInterface(container, &rv)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!docShell) return NS_ERROR_FAILURE; rv = docShell->SetAllowPlugins(allowPlugins); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; @@ -167,7 +167,7 @@ nsSetDocumentOptionsCommand::GetCommandStateParams(const char *aCommandName, // get pres context nsRefPtr presContext; rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!presContext) return NS_ERROR_FAILURE; PRInt32 animationMode; @@ -178,7 +178,7 @@ nsSetDocumentOptionsCommand::GetCommandStateParams(const char *aCommandName, // http://lxr.mozilla.org/seamonkey/source/modules/libpr0n/public/imgIContainer.idl rv = aParams->SetLongValue("imageAnimation", presContext->ImageAnimationMode()); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } PRBool allowPlugins; @@ -189,14 +189,14 @@ nsSetDocumentOptionsCommand::GetCommandStateParams(const char *aCommandName, if (!container) return NS_ERROR_FAILURE; nsCOMPtr docShell(do_QueryInterface(container, &rv)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!docShell) return NS_ERROR_FAILURE; rv = docShell->GetAllowPlugins(&allowPlugins); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = aParams->SetBooleanValue("plugins", allowPlugins); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; diff --git a/editor/composer/src/nsComposerRegistration.cpp b/editor/composer/src/nsComposerRegistration.cpp index 3b5c2b311e9..f9c9378f08a 100644 --- a/editor/composer/src/nsComposerRegistration.cpp +++ b/editor/composer/src/nsComposerRegistration.cpp @@ -126,19 +126,19 @@ CreateControllerWithSingletonCommandTable(const nsCID& inCommandTableCID, nsICon { nsresult rv; nsCOMPtr controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr composerCommandTable = do_GetService(inCommandTableCID, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // this guy is a singleton, so make it immutable composerCommandTable->MakeImmutable(); nsCOMPtr controllerContext = do_QueryInterface(controller, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = controllerContext->Init(composerCommandTable); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); *aResult = controller; NS_ADDREF(*aResult); @@ -154,7 +154,7 @@ nsHTMLEditorDocStateControllerConstructor(nsISupports *aOuter, REFNSIID aIID, { nsCOMPtr controller; nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorDocStateCommandTableCID, getter_AddRefs(controller)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); return controller->QueryInterface(aIID, aResult); } @@ -166,7 +166,7 @@ nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aRe { nsCOMPtr controller; nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorCommandTableCID, getter_AddRefs(controller)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); return controller->QueryInterface(aIID, aResult); } @@ -179,10 +179,10 @@ nsHTMLEditorCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, nsresult rv; nsCOMPtr commandTable = do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = nsComposerController::RegisterHTMLEditorCommands(commandTable); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // we don't know here whether we're being created as an instance, // or a service, so we can't become immutable @@ -199,10 +199,10 @@ nsHTMLEditorDocStateCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, nsresult rv; nsCOMPtr commandTable = do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = nsComposerController::RegisterEditorDocStateCommands(commandTable); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // we don't know here whether we're being created as an instance, // or a service, so we can't become immutable diff --git a/editor/composer/src/nsEditingSession.cpp b/editor/composer/src/nsEditingSession.cpp index 977ed979c41..5fe19c907d3 100644 --- a/editor/composer/src/nsEditingSession.cpp +++ b/editor/composer/src/nsEditingSession.cpp @@ -174,15 +174,15 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, // if all this does is setup listeners and I don't need listeners, // can't this step be ignored?? (based on aDoAfterURILoad) rv = PrepareForEditing(aWindow); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr editorDocShell; rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // set the flag on the docShell to say that it's editable rv = editorDocShell->MakeEditable(aDoAfterUriLoad); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Setup commands common to plaintext and html editors, // including the document creation observers @@ -191,7 +191,7 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, aWindow, static_cast(this), &mBaseCommandControllerId); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // The second is a controller to monitor doc state, // such as creation and "dirty flag" @@ -199,7 +199,7 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, aWindow, static_cast(this), &mDocStateControllerId); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // aDoAfterUriLoad can be false only when making an existing window editable if (!aDoAfterUriLoad) @@ -274,7 +274,7 @@ nsEditingSession::WindowIsEditable(nsIDOMWindow *aWindow, PRBool *outIsEditable) nsCOMPtr editorDocShell; nsresult rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); return editorDocShell->GetEditable(outIsEditable); } @@ -418,7 +418,7 @@ nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow) // This allows notification of error state // even if we don't create an editor rv = mStateMaintainer->Init(aWindow); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (mEditorStatus != eEditorCreationInProgress) { @@ -437,19 +437,19 @@ nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow) if (!utils) return NS_ERROR_FAILURE; rv = utils->GetImageAnimationMode(&mImageAnimationMode); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); utils->SetImageAnimationMode(imgIContainer::kDontAnimMode); } // create and set editor nsCOMPtr editorDocShell = do_QueryInterface(docShell, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr editor = do_CreateInstance(classString, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // set the editor on the docShell. The docShell now owns it. rv = editorDocShell->SetEditor(editor); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // setup the HTML editor command controller if (needHTMLController) @@ -458,38 +458,38 @@ nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow) rv = SetupEditorCommandController("@mozilla.org/editor/htmleditorcontroller;1", aWindow, editor, &mHTMLCommandControllerId); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } // Set mimetype on editor rv = editor->SetContentsMIMEType(mimeCType.get()); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr contentViewer; rv = docShell->GetContentViewer(getter_AddRefs(contentViewer)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!contentViewer) return NS_ERROR_FAILURE; nsCOMPtr domDoc; rv = contentViewer->GetDOMDocument(getter_AddRefs(domDoc)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!domDoc) return NS_ERROR_FAILURE; // Set up as a doc state listener // Important! We must have this to broadcast the "obs_documentCreated" message rv = editor->AddDocumentStateListener(mStateMaintainer); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // XXXbz we really shouldn't need a presShell here! nsCOMPtr presShell; rv = docShell->GetPresShell(getter_AddRefs(presShell)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!presShell) return NS_ERROR_FAILURE; nsCOMPtr selCon = do_QueryInterface(presShell); rv = editor->Init(domDoc, presShell, nsnull /* root content */, selCon, mEditorFlags); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr selection; editor->GetSelection(getter_AddRefs(selection)); @@ -497,7 +497,7 @@ nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow) if (!selPriv) return NS_ERROR_FAILURE; rv = selPriv->AddSelectionListener(mStateMaintainer); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // and as a transaction listener nsCOMPtr txnMgr; @@ -507,7 +507,7 @@ nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow) // Set context on all controllers to be the editor rv = SetEditorOnControllers(aWindow, editor); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Everything went fine! mEditorStatus = eEditorOK; @@ -632,7 +632,7 @@ nsEditingSession::GetEditorForWindow(nsIDOMWindow *aWindow, nsCOMPtr editorDocShell; nsresult rv = GetEditorDocShellFromWindow(aWindow, getter_AddRefs(editorDocShell)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); return editorDocShell->GetEditor(outEditor); } @@ -837,11 +837,11 @@ nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress, { nsCOMPtr domWindow; nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr domDoc; rv = domWindow->GetDocument(getter_AddRefs(domDoc)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr doc = do_QueryInterface(domDoc); if (!doc) return NS_ERROR_FAILURE; @@ -1054,7 +1054,7 @@ nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress, } mLoadBlankDocTimer = do_CreateInstance("@mozilla.org/timer;1", &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); mEditorStatus = eEditorCreationInProgress; mDocShell = do_GetWeakReference(docShell); @@ -1241,11 +1241,11 @@ nsEditingSession::SetupEditorCommandController( nsresult rv; nsCOMPtr domWindowInt = do_QueryInterface(aWindow, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr controllers; rv = domWindowInt->GetControllers(getter_AddRefs(controllers)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // We only have to create each singleton controller once // We know this has happened once we have a controllerId value @@ -1254,17 +1254,17 @@ nsEditingSession::SetupEditorCommandController( nsresult rv; nsCOMPtr controller; controller = do_CreateInstance(aControllerClassName, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // We must insert at head of the list to be sure our // controller is found before other implementations // (e.g., not-implemented versions by browser) rv = controllers->InsertControllerAt(0, controller); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Remember the ID for the controller rv = controllers->GetControllerId(controller, aControllerId); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } // Set the context @@ -1286,25 +1286,25 @@ nsEditingSession::SetEditorOnControllers(nsIDOMWindow *aWindow, // set the editor on the controller nsCOMPtr domWindowInt = do_QueryInterface(aWindow, &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr controllers; rv = domWindowInt->GetControllers(getter_AddRefs(controllers)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr editorAsISupports = do_QueryInterface(aEditor); if (mBaseCommandControllerId) { rv = SetContextOnControllerById(controllers, editorAsISupports, mBaseCommandControllerId); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } if (mDocStateControllerId) { rv = SetContextOnControllerById(controllers, editorAsISupports, mDocStateControllerId); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } if (mHTMLCommandControllerId) diff --git a/editor/libeditor/base/ChangeCSSInlineStyleTxn.cpp b/editor/libeditor/base/ChangeCSSInlineStyleTxn.cpp index 91ae1c9a532..3807d0ac039 100644 --- a/editor/libeditor/base/ChangeCSSInlineStyleTxn.cpp +++ b/editor/libeditor/base/ChangeCSSInlineStyleTxn.cpp @@ -180,7 +180,7 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::DoTransaction(void) nsCOMPtr cssDecl; nsresult result = inlineStyles->GetStyle(getter_AddRefs(cssDecl)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!cssDecl) return NS_ERROR_NULL_POINTER; nsAutoString propertyNameString; @@ -188,11 +188,11 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::DoTransaction(void) NS_NAMED_LITERAL_STRING(styleAttr, "style"); result = mElement->HasAttribute(styleAttr, &mUndoAttributeWasSet); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); nsAutoString values; result = cssDecl->GetPropertyValue(propertyNameString, values); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); mUndoValue.Assign(values); // does this property accept more than 1 value ? @@ -211,26 +211,26 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::DoTransaction(void) RemoveValueFromListOfValues(values, mValue); if (values.IsEmpty()) { result = cssDecl->RemoveProperty(propertyNameString, returnString); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); } else { nsAutoString priority; result = cssDecl->GetPropertyPriority(propertyNameString, priority); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); result = cssDecl->SetProperty(propertyNameString, values, priority); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); } } else { result = cssDecl->RemoveProperty(propertyNameString, returnString); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); } } else { nsAutoString priority; result = cssDecl->GetPropertyPriority(propertyNameString, priority); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (multiple) { // the property can have more than one value, let's add // the value we have to add to the others @@ -243,16 +243,16 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::DoTransaction(void) values.Assign(mValue); result = cssDecl->SetProperty(propertyNameString, values, priority); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); } // let's be sure we don't keep an empty style attribute PRUint32 length; result = cssDecl->GetLength(&length); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!length) { result = mElement->RemoveAttribute(styleAttr); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); } else mRedoAttributeWasSet = PR_TRUE; @@ -276,7 +276,7 @@ nsresult ChangeCSSInlineStyleTxn::SetStyle(PRBool aAttributeWasSet, if (!inlineStyles) return NS_ERROR_NULL_POINTER; nsCOMPtr cssDecl; result = inlineStyles->GetStyle(getter_AddRefs(cssDecl)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!cssDecl) return NS_ERROR_NULL_POINTER; if (aValue.IsEmpty()) { @@ -288,7 +288,7 @@ nsresult ChangeCSSInlineStyleTxn::SetStyle(PRBool aAttributeWasSet, // let's recreate the declaration as it was nsAutoString priority; result = cssDecl->GetPropertyPriority(propertyNameString, priority); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); result = cssDecl->SetProperty(propertyNameString, aValue, priority); } } diff --git a/editor/libeditor/base/CreateElementTxn.cpp b/editor/libeditor/base/CreateElementTxn.cpp index 0a4cb3e4068..5253d19f53b 100644 --- a/editor/libeditor/base/CreateElementTxn.cpp +++ b/editor/libeditor/base/CreateElementTxn.cpp @@ -115,7 +115,7 @@ NS_IMETHODIMP CreateElementTxn::DoTransaction(void) //new call to use instead to get proper HTML element, bug# 39919 nsresult result = mEditor->CreateHTMLContent(mTag, getter_AddRefs(newContent)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); nsCOMPtrnewElement = do_QueryInterface(newContent); if (!newElement) return NS_ERROR_NULL_POINTER; mNewNode = do_QueryInterface(newElement); @@ -149,10 +149,10 @@ NS_IMETHODIMP CreateElementTxn::DoTransaction(void) if (mOffsetInParent>count) mOffsetInParent = count; result = childNodes->Item(mOffsetInParent, getter_AddRefs(mRefNode)); - if (NS_FAILED(result)) return result; // note, it's ok for mRefNode to be null. that means append + NS_ENSURE_SUCCESS(result, result); // note, it's ok for mRefNode to be null. that means append result = mParent->InsertBefore(mNewNode, mRefNode, getter_AddRefs(resultNode)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); // only set selection to insertion point if editor gives permission PRBool bAdjustSelection; @@ -161,12 +161,12 @@ NS_IMETHODIMP CreateElementTxn::DoTransaction(void) { nsCOMPtr selection; result = mEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; PRInt32 offset=0; result = nsEditor::GetChildOffset(mNewNode, mParent, offset); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); result = selection->Collapse(mParent, offset+1); NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert."); diff --git a/editor/libeditor/base/DeleteRangeTxn.cpp b/editor/libeditor/base/DeleteRangeTxn.cpp index 81a55c16f5a..2d0056b0799 100644 --- a/editor/libeditor/base/DeleteRangeTxn.cpp +++ b/editor/libeditor/base/DeleteRangeTxn.cpp @@ -196,7 +196,7 @@ NS_IMETHODIMP DeleteRangeTxn::DoTransaction(void) result = EditAggregateTxn::DoTransaction(); } - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); // only set selection to deletion point if editor gives permission PRBool bAdjustSelection; @@ -205,7 +205,7 @@ NS_IMETHODIMP DeleteRangeTxn::DoTransaction(void) { nsCOMPtr selection; result = mEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; result = selection->Collapse(mStartParent, mStartOffset); } @@ -274,7 +274,7 @@ DeleteRangeTxn::CreateTxnsToDeleteBetween(nsIDOMNode *aStartParent, { nsCOMPtr children; result = aStartParent->GetChildNodes(getter_AddRefs(children)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!children) return NS_ERROR_NULL_POINTER; #ifdef DEBUG @@ -287,7 +287,7 @@ DeleteRangeTxn::CreateTxnsToDeleteBetween(nsIDOMNode *aStartParent, { nsCOMPtr child; result = children->Item(i, getter_AddRefs(child)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!child) return NS_ERROR_NULL_POINTER; nsRefPtr txn = new DeleteElementTxn(); @@ -345,7 +345,7 @@ NS_IMETHODIMP DeleteRangeTxn::CreateTxnsToDeleteNodesBetween() if (!iter) return NS_ERROR_NULL_POINTER; nsresult result = iter->Init(mRange); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); while (!iter->IsDone() && NS_SUCCEEDED(result)) { diff --git a/editor/libeditor/base/DeleteTextTxn.cpp b/editor/libeditor/base/DeleteTextTxn.cpp index 13bcf17b223..69e3e8acaa3 100644 --- a/editor/libeditor/base/DeleteTextTxn.cpp +++ b/editor/libeditor/base/DeleteTextTxn.cpp @@ -107,7 +107,7 @@ NS_IMETHODIMP DeleteTextTxn::DoTransaction(void) nsresult result = mElement->SubstringData(mOffset, mNumCharsToDelete, mDeletedText); NS_ASSERTION(NS_SUCCEEDED(result), "could not get text to delete."); result = mElement->DeleteData(mOffset, mNumCharsToDelete); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (mRangeUpdater) mRangeUpdater->SelAdjDeleteText(mElement, mOffset, mNumCharsToDelete); @@ -119,7 +119,7 @@ NS_IMETHODIMP DeleteTextTxn::DoTransaction(void) { nsCOMPtr selection; result = mEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; result = selection->Collapse(mElement, mOffset); NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of deletetext."); diff --git a/editor/libeditor/base/InsertElementTxn.cpp b/editor/libeditor/base/InsertElementTxn.cpp index c333a1ea90e..860303b8225 100644 --- a/editor/libeditor/base/InsertElementTxn.cpp +++ b/editor/libeditor/base/InsertElementTxn.cpp @@ -109,7 +109,7 @@ NS_IMETHODIMP InsertElementTxn::DoTransaction(void) nsCOMPtr childNodes; nsresult result = mParent->GetChildNodes(getter_AddRefs(childNodes)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); nsCOMPtrrefNode; if (childNodes) { @@ -119,7 +119,7 @@ NS_IMETHODIMP InsertElementTxn::DoTransaction(void) // -1 is sentinel value meaning "append at end" if (mOffset == -1) mOffset = count; result = childNodes->Item(mOffset, getter_AddRefs(refNode)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); // note, it's ok for mRefNode to be null. that means append } @@ -127,7 +127,7 @@ NS_IMETHODIMP InsertElementTxn::DoTransaction(void) nsCOMPtr resultNode; result = mParent->InsertBefore(mNode, refNode, getter_AddRefs(resultNode)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!resultNode) return NS_ERROR_NULL_POINTER; // only set selection to insertion point if editor gives permission @@ -137,7 +137,7 @@ NS_IMETHODIMP InsertElementTxn::DoTransaction(void) { nsCOMPtr selection; result = mEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; // place the selection just after the inserted element selection->Collapse(mParent, mOffset+1); diff --git a/editor/libeditor/base/InsertTextTxn.cpp b/editor/libeditor/base/InsertTextTxn.cpp index e2e55212ae3..ce3bc50b821 100644 --- a/editor/libeditor/base/InsertTextTxn.cpp +++ b/editor/libeditor/base/InsertTextTxn.cpp @@ -104,7 +104,7 @@ NS_IMETHODIMP InsertTextTxn::DoTransaction(void) if (!mElement || !mEditor) { return NS_ERROR_NOT_INITIALIZED; } nsresult result = mElement->InsertData(mOffset, mStringToInsert); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); // only set selection to insertion point if editor gives permission PRBool bAdjustSelection; @@ -113,7 +113,7 @@ NS_IMETHODIMP InsertTextTxn::DoTransaction(void) { nsCOMPtr selection; result = mEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; result = selection->Collapse(mElement, mOffset+mStringToInsert.Length()); NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after insert."); diff --git a/editor/libeditor/base/JoinElementTxn.cpp b/editor/libeditor/base/JoinElementTxn.cpp index 97eb41327cc..02f625c666f 100644 --- a/editor/libeditor/base/JoinElementTxn.cpp +++ b/editor/libeditor/base/JoinElementTxn.cpp @@ -76,7 +76,7 @@ NS_IMETHODIMP JoinElementTxn::Init(nsEditor *aEditor, mLeftNode = do_QueryInterface(aLeftNode); nsCOMPtrleftParent; nsresult result = mLeftNode->GetParentNode(getter_AddRefs(leftParent)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!mEditor->IsModifiableNode(leftParent)) { return NS_ERROR_FAILURE; } @@ -104,13 +104,13 @@ NS_IMETHODIMP JoinElementTxn::DoTransaction(void) // get the parent node nsCOMPtrleftParent; nsresult result = mLeftNode->GetParentNode(getter_AddRefs(leftParent)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!leftParent) return NS_ERROR_NULL_POINTER; // verify that mLeftNode and mRightNode have the same parent nsCOMPtrrightParent; result = mRightNode->GetParentNode(getter_AddRefs(rightParent)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!rightParent) return NS_ERROR_NULL_POINTER; if (leftParent==rightParent) @@ -126,7 +126,7 @@ NS_IMETHODIMP JoinElementTxn::DoTransaction(void) { nsCOMPtr childNodes; result = mLeftNode->GetChildNodes(getter_AddRefs(childNodes)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (childNodes) { childNodes->GetLength(&mOffset); diff --git a/editor/libeditor/base/PlaceholderTxn.cpp b/editor/libeditor/base/PlaceholderTxn.cpp index 6a0d9cc692b..c691be40db0 100644 --- a/editor/libeditor/base/PlaceholderTxn.cpp +++ b/editor/libeditor/base/PlaceholderTxn.cpp @@ -93,14 +93,14 @@ NS_IMETHODIMP PlaceholderTxn::UndoTransaction(void) { // undo txns nsresult res = EditAggregateTxn::UndoTransaction(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!mStartSel) return NS_ERROR_NULL_POINTER; // now restore selection nsCOMPtr selection; res = mEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; return mStartSel->RestoreSelection(selection); } @@ -110,12 +110,12 @@ NS_IMETHODIMP PlaceholderTxn::RedoTransaction(void) { // redo txns nsresult res = EditAggregateTxn::RedoTransaction(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // now restore selection nsCOMPtr selection; res = mEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; return mEndSel.RestoreSelection(selection); } @@ -290,7 +290,7 @@ NS_IMETHODIMP PlaceholderTxn::RememberEndingSelection() { nsCOMPtr selection; nsresult res = mEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; return mEndSel.SaveSelection(selection); } diff --git a/editor/libeditor/base/SetDocTitleTxn.cpp b/editor/libeditor/base/SetDocTitleTxn.cpp index 97bb08cdbb9..c49b2cf1e66 100644 --- a/editor/libeditor/base/SetDocTitleTxn.cpp +++ b/editor/libeditor/base/SetDocTitleTxn.cpp @@ -91,7 +91,7 @@ nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle) nsCOMPtr titleList; res = domDoc->GetElementsByTagName(NS_LITERAL_STRING("title"), getter_AddRefs(titleList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // First assume we will NOT really do anything // (transaction will not be pushed on stack) @@ -101,7 +101,7 @@ nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle) if(titleList) { res = titleList->Item(0, getter_AddRefs(titleNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (titleNode) { // Delete existing child textnode of title node @@ -134,7 +134,7 @@ nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle) // Get the node, create a and insert it under the HEAD nsCOMPtr<nsIDOMNodeList> headList; res = domDoc->GetElementsByTagName(NS_LITERAL_STRING("head"),getter_AddRefs(headList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!headList) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMNode>headNode; @@ -149,7 +149,7 @@ nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle) // Didn't find one above: Create a new one nsCOMPtr<nsIDOMElement>titleElement; res = domDoc->CreateElement(NS_LITERAL_STRING("title"), getter_AddRefs(titleElement)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!titleElement) return NS_ERROR_FAILURE; titleNode = do_QueryInterface(titleElement); @@ -159,7 +159,7 @@ nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle) // after all existing HEAD children nsCOMPtr<nsIDOMNodeList> children; res = headNode->GetChildNodes(getter_AddRefs(children)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (children) children->GetLength(&newTitleIndex); } @@ -170,7 +170,7 @@ nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle) { nsCOMPtr<nsIDOMText> textNode; res = domDoc->CreateTextNode(aTitle, getter_AddRefs(textNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(textNode); if (!newNode) return NS_ERROR_FAILURE; @@ -185,7 +185,7 @@ nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle) // This is an undoable transaction res = editor->InsertNode(newNode, titleNode, 0); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (newTitleNode) diff --git a/editor/libeditor/base/SplitElementTxn.cpp b/editor/libeditor/base/SplitElementTxn.cpp index 27c14dd8b4d..8e1a3973fcd 100644 --- a/editor/libeditor/base/SplitElementTxn.cpp +++ b/editor/libeditor/base/SplitElementTxn.cpp @@ -98,7 +98,7 @@ NS_IMETHODIMP SplitElementTxn::DoTransaction(void) // create a new node nsresult result = mExistingRightNode->CloneNode(PR_FALSE, getter_AddRefs(mNewLeftNode)); NS_ASSERTION(((NS_SUCCEEDED(result)) && (mNewLeftNode)), "could not create element."); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!mNewLeftNode) return NS_ERROR_NULL_POINTER; mEditor->MarkNodeDirty(mExistingRightNode); @@ -112,7 +112,7 @@ NS_IMETHODIMP SplitElementTxn::DoTransaction(void) // get the parent node result = mExistingRightNode->GetParentNode(getter_AddRefs(mParent)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!mParent) return NS_ERROR_NULL_POINTER; // insert the new node @@ -121,7 +121,7 @@ NS_IMETHODIMP SplitElementTxn::DoTransaction(void) { nsCOMPtr<nsISelection>selection; mEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; result = selection->Collapse(mNewLeftNode, mOffset); } diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 6ef9cd72e5d..ed761b03d5d 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -596,7 +596,7 @@ nsEditor::DoTransaction(nsITransaction *aTxn) { nsCOMPtr<nsITransaction> topTxn; result = mTxnMgr->PeekUndoStack(getter_AddRefs(topTxn)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (topTxn) { plcTxn = do_QueryInterface(topTxn); @@ -868,7 +868,7 @@ nsEditor::BeginPlaceHolderTransaction(nsIAtom *aName) mPlaceHolderName = aName; nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); mSelState = new nsSelectionState(); if (!mSelState) return NS_ERROR_OUT_OF_MEMORY; @@ -1028,7 +1028,7 @@ NS_IMETHODIMP nsEditor::BeginningOfDocument() if (!parentNode) { return NS_ERROR_NULL_POINTER; } PRInt32 offsetInParent; result = nsEditor::GetChildOffset(firstNode, parentNode, offsetInParent); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); result = selection->Collapse(parentNode, offsetInParent); } } @@ -1049,7 +1049,7 @@ nsEditor::EndOfDocument() // get selection nsCOMPtr<nsISelection> selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; // get the root element @@ -1060,7 +1060,7 @@ nsEditor::EndOfDocument() // get the length of the rot element PRUint32 len; res = GetLengthOfDOMNode(rootElement, len); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // set the selection to after the last child of the root element return selection->Collapse(rootElement, (PRInt32)len); @@ -1409,11 +1409,11 @@ nsEditor::JoinNodes(nsIDOMNode * aLeftNode, // remember some values; later used for saved selection updating. // find the offset between the nodes to be joined. nsresult result = GetChildOffset(aRightNode, aParent, offset); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); // find the number of children of the lefthand node PRUint32 oldLeftNodeLen; result = GetLengthOfDOMNode(aLeftNode, oldLeftNodeLen); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); for (i = 0; i < mActionListeners.Count(); i++) mActionListeners[i]->WillJoinNodes(aLeftNode, aRightNode, aParent); @@ -1441,7 +1441,7 @@ NS_IMETHODIMP nsEditor::DeleteNode(nsIDOMNode * aElement) // save node location for selection updating code. nsresult result = GetNodeLocation(aElement, address_of(parent), &offset); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); for (i = 0; i < mActionListeners.Count(); i++) mActionListeners[i]->WillDeleteNode(aElement); @@ -1476,7 +1476,7 @@ nsEditor::ReplaceContainer(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> parent; PRInt32 offset; nsresult res = GetNodeLocation(inNode, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // create new container nsCOMPtr<nsIContent> newContent; @@ -1484,20 +1484,20 @@ nsEditor::ReplaceContainer(nsIDOMNode *inNode, //new call to use instead to get proper HTML element, bug# 39919 res = CreateHTMLContent(aNodeType, getter_AddRefs(newContent)); nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(newContent); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *outNode = do_QueryInterface(elem); // set attribute if needed if (aAttribute && aValue && !aAttribute->IsEmpty()) { res = elem->SetAttribute(*aAttribute, *aValue); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (aCloneAttributes) { nsCOMPtr<nsIDOMNode>newNode = do_QueryInterface(elem); res = CloneAttributes(newNode, inNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // notify our internal selection state listener @@ -1513,16 +1513,16 @@ nsEditor::ReplaceContainer(nsIDOMNode *inNode, { inNode->GetFirstChild(getter_AddRefs(child)); res = DeleteNode(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = InsertNode(child, *outNode, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); inNode->HasChildNodes(&bHasMoreChildren); } } // insert new container into tree res = InsertNode( *outNode, parent, offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // delete old container return DeleteNode(inNode); @@ -1541,7 +1541,7 @@ nsEditor::RemoveContainer(nsIDOMNode *inNode) PRInt32 offset; nsresult res = GetNodeLocation(inNode, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // loop through the child nodes of inNode and promote them // into inNode's parent. @@ -1549,7 +1549,7 @@ nsEditor::RemoveContainer(nsIDOMNode *inNode) inNode->HasChildNodes(&bHasMoreChildren); nsCOMPtr<nsIDOMNodeList> nodeList; res = inNode->GetChildNodes(getter_AddRefs(nodeList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!nodeList) return NS_ERROR_NULL_POINTER; PRUint32 nodeOrigLen; nodeList->GetLength(&nodeOrigLen); @@ -1562,9 +1562,9 @@ nsEditor::RemoveContainer(nsIDOMNode *inNode) { inNode->GetLastChild(getter_AddRefs(child)); res = DeleteNode(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = InsertNode(child, parent, offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); inNode->HasChildNodes(&bHasMoreChildren); } return DeleteNode(inNode); @@ -1589,7 +1589,7 @@ nsEditor::InsertContainerAbove( nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> parent; PRInt32 offset; nsresult res = GetNodeLocation(inNode, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // create new container nsCOMPtr<nsIContent> newContent; @@ -1597,14 +1597,14 @@ nsEditor::InsertContainerAbove( nsIDOMNode *inNode, //new call to use instead to get proper HTML element, bug# 39919 res = CreateHTMLContent(aNodeType, getter_AddRefs(newContent)); nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(newContent); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *outNode = do_QueryInterface(elem); // set attribute if needed if (aAttribute && aValue && !aAttribute->IsEmpty()) { res = elem->SetAttribute(*aAttribute, *aValue); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // notify our internal selection state listener @@ -1612,12 +1612,12 @@ nsEditor::InsertContainerAbove( nsIDOMNode *inNode, // put inNode in new parent, outNode res = DeleteNode(inNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); { nsAutoTxnsConserveSelection conserveSelection(this); res = InsertNode(inNode, *outNode, 0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // put new parent in doc @@ -1641,7 +1641,7 @@ nsEditor::MoveNode(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aOffset) PRUint32 unsignedOffset; // magic value meaning "move to end of aParent" res = GetLengthOfDOMNode(aParent, unsignedOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aOffset = (PRInt32)unsignedOffset; } @@ -1659,7 +1659,7 @@ nsEditor::MoveNode(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aOffset) // put aNode in new parent res = DeleteNode(aNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return InsertNode(aNode, aParent, aOffset); } @@ -2311,16 +2311,16 @@ NS_IMETHODIMP nsEditor::InsertTextImpl(const nsAString& aStringToInsert, { // create a text node res = aDoc->CreateTextNode(EmptyString(), getter_AddRefs(nodeAsText)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!nodeAsText) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(nodeAsText); // then we insert it into the dom tree res = InsertNode(newNode, *aInOutNode, offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); offset = 0; } res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { @@ -2328,7 +2328,7 @@ NS_IMETHODIMP nsEditor::InsertTextImpl(const nsAString& aStringToInsert, { // we are inserting text into an existing text node. res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *aInOutOffset += aStringToInsert.Length(); } else @@ -2336,12 +2336,12 @@ NS_IMETHODIMP nsEditor::InsertTextImpl(const nsAString& aStringToInsert, // we are inserting text into a non-text node // first we have to create a textnode (this also populates it with the text) res = aDoc->CreateTextNode(aStringToInsert, getter_AddRefs(nodeAsText)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!nodeAsText) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(nodeAsText); // then we insert it into the dom tree res = InsertNode(newNode, *aInOutNode, offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *aInOutNode = newNode; *aInOutOffset = aStringToInsert.Length(); } @@ -2417,7 +2417,7 @@ nsresult nsEditor::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert, getter_AddRefs(insertTxn)); txn = insertTxn; } - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); // let listeners know what's up PRInt32 i; @@ -2551,7 +2551,7 @@ nsEditor::NotifyDocumentListeners(TDocumentListenerNotification aNotificationTyp { PRBool docIsDirty; rv = GetDocumentModified(&docIsDirty); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (docIsDirty == mDocDirtyState) return NS_OK; @@ -2697,7 +2697,7 @@ nsEditor::SplitNodeImpl(nsIDOMNode * aExistingRightNode, // get selection nsCOMPtr<nsISelection> selection; result = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; // remember some selection points @@ -2838,12 +2838,12 @@ nsEditor::JoinNodesImpl(nsIDOMNode * aNodeToKeep, PRUint32 firstNodeLength; result = GetLengthOfDOMNode(leftNode, firstNodeLength); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); nsCOMPtr<nsIDOMNode> parent; result = GetNodeLocation(aNodeToJoin, address_of(parent), &joinOffset); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); result = GetNodeLocation(aNodeToKeep, address_of(parent), &keepOffset); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); // if selection endpoint is between the nodes, remember it as being // in the one that is going away instead. This simplifies later selection @@ -3199,7 +3199,7 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode, nsCOMPtr<nsIDOMNode> candidate; result = GetPriorNodeImpl(aCurrentNode, aEditableNode, address_of(candidate), bNoBlockCrossing); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!candidate) { @@ -3310,7 +3310,7 @@ nsEditor::GetNextNode(nsIDOMNode *aCurrentNode, nsCOMPtr<nsIDOMNode> candidate; nsresult result = GetNextNodeImpl(aCurrentNode, aEditableNode, address_of(candidate), bNoBlockCrossing); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!candidate) { @@ -3960,19 +3960,19 @@ nsEditor::SplitNodeDeep(nsIDOMNode *aNode, PRUint32 len; PRBool bDoSplit = PR_FALSE; res = GetLengthOfDOMNode(nodeToSplit, len); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!(aNoEmptyContainers || nodeAsText) || (offset && (offset != (PRInt32)len))) { bDoSplit = PR_TRUE; res = SplitNode(nodeToSplit, offset, getter_AddRefs(tempNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (outRightNode) *outRightNode = nodeToSplit; if (outLeftNode) *outLeftNode = tempNode; } res = nodeToSplit->GetParentNode(getter_AddRefs(parentNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!parentNode) return NS_ERROR_FAILURE; if (!bDoSplit && offset) // must be "end of text node" case, we didn't split it, just move past it @@ -4040,7 +4040,7 @@ nsEditor::JoinNodeDeep(nsIDOMNode *aLeftNode, else { res = GetLengthOfDOMNode(leftNodeToJoin, length); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } *aOutJoinNode = rightNodeToJoin; @@ -4048,7 +4048,7 @@ nsEditor::JoinNodeDeep(nsIDOMNode *aLeftNode, // do the join res = JoinNodes(leftNodeToJoin, rightNodeToJoin, parentNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (IsTextNode(parentNode)) // we've joined all the way down to text nodes, we're done! return NS_OK; @@ -4201,7 +4201,7 @@ nsEditor::DeleteSelectionImpl(nsIEditor::EDirection aAction) { nsCOMPtr<nsISelection>selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsRefPtr<EditAggregateTxn> txn; nsCOMPtr<nsIDOMNode> deleteNode; PRInt32 deleteCharOffset = 0, deleteCharLength = 0; @@ -4265,7 +4265,7 @@ nsEditor::DeleteSelectionAndCreateNode(const nsAString& aTag, // we want the selection to be just after the new node nsCOMPtr<nsISelection> selection; result = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; return selection->Collapse(parentSelectedNode, offsetOfNewNode+1); } @@ -4321,7 +4321,7 @@ nsEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtr<nsIDOMNode> &parentSele nsresult result=NS_ERROR_NOT_INITIALIZED; nsCOMPtr<nsISelection> selection; result = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; PRBool collapsed; @@ -4905,21 +4905,21 @@ nsEditor::AppendNodeToSelectionAsRange(nsIDOMNode *aNode) if (!aNode) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if(!selection) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMNode> parentNode; res = aNode->GetParentNode(getter_AddRefs(parentNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!parentNode) return NS_ERROR_NULL_POINTER; PRInt32 offset; res = GetChildOffset(aNode, parentNode, offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMRange> range; res = CreateRange(parentNode, offset, parentNode, offset+1, getter_AddRefs(range)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!range) return NS_ERROR_NULL_POINTER; return selection->AddRange(range); @@ -4929,7 +4929,7 @@ nsresult nsEditor::ClearSelection() { nsCOMPtr<nsISelection> selection; nsresult res = nsEditor::GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; return selection->RemoveAllRanges(); } diff --git a/editor/libeditor/base/nsEditorEventListener.cpp b/editor/libeditor/base/nsEditorEventListener.cpp index b3cb5752a0a..fc53a6cc0d6 100644 --- a/editor/libeditor/base/nsEditorEventListener.cpp +++ b/editor/libeditor/base/nsEditorEventListener.cpp @@ -572,7 +572,7 @@ nsEditorEventListener::DragOver(nsIDOMDragEvent* aDragEvent) { PRInt32 offset = 0; nsresult rv = nsuiEvent->GetRangeOffset(&offset); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // to avoid flicker, we could track the node and offset to see if we moved if (mCaretDrawn) @@ -721,11 +721,11 @@ nsEditorEventListener::CanDrop(nsIDOMDragEvent* aEvent) nsCOMPtr<nsIDOMDocument> domdoc; nsresult rv = mEditor->GetDocument(getter_AddRefs(domdoc)); - if (NS_FAILED(rv)) return PR_FALSE; + NS_ENSURE_SUCCESS(rv, PR_FALSE); nsCOMPtr<nsIDOMDocument> sourceDoc; rv = sourceNode->GetOwnerDocument(getter_AddRefs(sourceDoc)); - if (NS_FAILED(rv)) return PR_FALSE; + NS_ENSURE_SUCCESS(rv, PR_FALSE); if (domdoc == sourceDoc) // source and dest are the same document; disallow drops within the selection { nsCOMPtr<nsISelection> selection; @@ -735,7 +735,7 @@ nsEditorEventListener::CanDrop(nsIDOMDragEvent* aEvent) PRBool isCollapsed; rv = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(rv)) return PR_FALSE; + NS_ENSURE_SUCCESS(rv, PR_FALSE); // Don't bother if collapsed - can always drop if (!isCollapsed) @@ -749,11 +749,11 @@ nsEditorEventListener::CanDrop(nsIDOMDragEvent* aEvent) PRInt32 offset = 0; rv = nsuiEvent->GetRangeOffset(&offset); - if (NS_FAILED(rv)) return PR_FALSE; + NS_ENSURE_SUCCESS(rv, PR_FALSE); PRInt32 rangeCount; rv = selection->GetRangeCount(&rangeCount); - if (NS_FAILED(rv)) return PR_FALSE; + NS_ENSURE_SUCCESS(rv, PR_FALSE); for (PRInt32 i = 0; i < rangeCount; i++) { diff --git a/editor/libeditor/base/nsEditorUtils.cpp b/editor/libeditor/base/nsEditorUtils.cpp index af7182685f8..fc17ed0e735 100644 --- a/editor/libeditor/base/nsEditorUtils.cpp +++ b/editor/libeditor/base/nsEditorUtils.cpp @@ -105,7 +105,7 @@ nsDOMIterator::Init(nsIDOMRange* aRange) { nsresult res; mIter = do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!mIter) return NS_ERROR_FAILURE; return mIter->Init(aRange); } @@ -115,7 +115,7 @@ nsDOMIterator::Init(nsIDOMNode* aNode) { nsresult res; mIter = do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!mIter) return NS_ERROR_FAILURE; nsCOMPtr<nsIContent> content = do_QueryInterface(aNode); return mIter->Init(content); @@ -173,7 +173,7 @@ nsDOMSubtreeIterator::Init(nsIDOMRange* aRange) { nsresult res; mIter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!mIter) return NS_ERROR_FAILURE; return mIter->Init(aRange); } @@ -183,7 +183,7 @@ nsDOMSubtreeIterator::Init(nsIDOMNode* aNode) { nsresult res; mIter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!mIter) return NS_ERROR_FAILURE; nsCOMPtr<nsIContent> content = do_QueryInterface(aNode); return mIter->Init(content); @@ -205,7 +205,7 @@ nsEditorUtils::IsDescendantOf(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 *a do { res = node->GetParentNode(getter_AddRefs(parent)); - if (NS_FAILED(res)) return PR_FALSE; + NS_ENSURE_SUCCESS(res, PR_FALSE); if (parent == aParent) { if (aOffset) diff --git a/editor/libeditor/base/nsSelectionState.cpp b/editor/libeditor/base/nsSelectionState.cpp index 3f93c0c0703..ed82a2cbfa9 100644 --- a/editor/libeditor/base/nsSelectionState.cpp +++ b/editor/libeditor/base/nsSelectionState.cpp @@ -342,11 +342,11 @@ nsRangeUpdater::SelAdjSplitNode(nsIDOMNode *aOldRightNode, PRInt32 aOffset, nsID nsCOMPtr<nsIDOMNode> parent; PRInt32 offset; nsresult result = nsEditor::GetNodeLocation(aOldRightNode, address_of(parent), &offset); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); // first part is same as inserting aNewLeftnode result = SelAdjInsertNode(parent,offset-1); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); // next step is to check for range enpoints inside aOldRightNode nsRangeStore *item; diff --git a/editor/libeditor/html/TypeInState.cpp b/editor/libeditor/html/TypeInState.cpp index c6ebe6ff427..516b99aeda3 100644 --- a/editor/libeditor/html/TypeInState.cpp +++ b/editor/libeditor/html/TypeInState.cpp @@ -74,7 +74,7 @@ nsresult TypeInState::UpdateSelState(nsISelection *aSelection) PRBool isCollapsed = PR_FALSE; nsresult result = aSelection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (isCollapsed) { @@ -101,7 +101,7 @@ NS_IMETHODIMP TypeInState::NotifySelectionChanged(nsIDOMDocument *, nsISelection PRBool isCollapsed = PR_FALSE; nsresult result = aSelection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (isCollapsed) { @@ -110,7 +110,7 @@ NS_IMETHODIMP TypeInState::NotifySelectionChanged(nsIDOMDocument *, nsISelection result = nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (selNode && selNode == mLastSelectionContainer && selOffset == mLastSelectionOffset) { diff --git a/editor/libeditor/html/nsHTMLAbsPosition.cpp b/editor/libeditor/html/nsHTMLAbsPosition.cpp index fc6dcdd4571..412185649f6 100644 --- a/editor/libeditor/html/nsHTMLAbsPosition.cpp +++ b/editor/libeditor/html/nsHTMLAbsPosition.cpp @@ -81,7 +81,7 @@ nsHTMLEditor::AbsolutePositionSelection(PRBool aEnabled) // Find out if the selection is collapsed: nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsTextRulesInfo ruleInfo(aEnabled ? @@ -100,7 +100,7 @@ nsHTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement **_retval) { nsCOMPtr<nsIDOMElement> element; nsresult res = GetSelectionContainer(getter_AddRefs(element)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoString positionStr; nsCOMPtr<nsIDOMNode> node = do_QueryInterface(element); @@ -109,13 +109,13 @@ nsHTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement **_retval) while (!resultNode && !nsEditor::NodeIsType(node, nsEditProperty::html)) { res = mHTMLCSSUtils->GetComputedProperty(node, nsEditProperty::cssPosition, positionStr); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (positionStr.EqualsLiteral("absolute")) resultNode = node; else { nsCOMPtr<nsIDOMNode> parentNode; res = node->GetParentNode(getter_AddRefs(parentNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); node.swap(parentNode); } } @@ -159,7 +159,7 @@ nsHTMLEditor::RelativeChangeElementZIndex(nsIDOMElement * aElement, PRInt32 zIndex; nsresult res = GetElementZIndex(aElement, &zIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); zIndex = NS_MAX(zIndex + aChange, 0); SetElementZIndex(aElement, zIndex); @@ -197,7 +197,7 @@ nsHTMLEditor::RelativeChangeZIndex(PRInt32 aChange) // Find out if the selection is collapsed: nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsTextRulesInfo ruleInfo((aChange < 0) ? nsTextEditRules::kDecreaseZIndex: nsTextEditRules::kIncreaseZIndex); @@ -219,13 +219,13 @@ nsHTMLEditor::GetElementZIndex(nsIDOMElement * aElement, nsresult res = mHTMLCSSUtils->GetSpecifiedProperty(aElement, nsEditProperty::cssZIndex, zIndexStr); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (zIndexStr.EqualsLiteral("auto")) { // we have to look at the positioned ancestors // cf. CSS 2 spec section 9.9.1 nsCOMPtr<nsIDOMNode> parentNode; res = aElement->GetParentNode(getter_AddRefs(parentNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> node = parentNode; nsAutoString positionStr; while (node && @@ -234,17 +234,17 @@ nsHTMLEditor::GetElementZIndex(nsIDOMElement * aElement, res = mHTMLCSSUtils->GetComputedProperty(node, nsEditProperty::cssPosition, positionStr); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (positionStr.EqualsLiteral("absolute")) { // ah, we found one, what's its z-index ? If its z-index is auto, // we have to continue climbing the document's tree res = mHTMLCSSUtils->GetComputedProperty(node, nsEditProperty::cssZIndex, zIndexStr); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } res = node->GetParentNode(getter_AddRefs(parentNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); node = parentNode; } } @@ -293,7 +293,7 @@ nsHTMLEditor::RefreshGrabber() mPositionedObjectMarginLeft, mPositionedObjectMarginTop); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); SetAnonymousElementPosition(mPositionedObjectX+12, mPositionedObjectY-14, @@ -306,7 +306,7 @@ nsHTMLEditor::HideGrabber() { nsresult res = mAbsolutelyPositionedObject->RemoveAttribute(NS_LITERAL_STRING("_moz_abspos")); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); mAbsolutelyPositionedObject = nsnull; NS_ENSURE_TRUE(mGrabber, NS_ERROR_NULL_POINTER); @@ -344,11 +344,11 @@ nsHTMLEditor::ShowGrabberOnElement(nsIDOMElement * aElement) nsAutoString classValue; nsresult res = CheckPositionedElementBGandFG(aElement, classValue); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = aElement->SetAttribute(NS_LITERAL_STRING("_moz_abspos"), classValue); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // first, let's keep track of that element... mAbsolutelyPositionedObject = aElement; @@ -467,7 +467,7 @@ nsresult nsHTMLEditor::SetFinalPosition(PRInt32 aX, PRInt32 aY) { nsresult res = EndMoving(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // we have now to set the new width and height of the resized object // we don't set the x and y position because we don't control that in @@ -552,15 +552,15 @@ nsHTMLEditor::AbsolutelyPositionElement(nsIDOMElement * aElement, // container nsCOMPtr<nsIDOMNode> parentNode; res = aElement->GetParentNode(getter_AddRefs(parentNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNodeList> childNodes; res = parentNode->GetChildNodes(getter_AddRefs(childNodes)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!childNodes) return NS_ERROR_NULL_POINTER; PRUint32 childCount; res = childNodes->GetLength(&childCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (childCount == 1) { nsCOMPtr<nsIDOMNode> brNode; @@ -592,12 +592,12 @@ nsHTMLEditor::AbsolutelyPositionElement(nsIDOMElement * aElement, PRBool hasStyleOrIdOrClass; res = HasStyleOrIdOrClass(aElement, &hasStyleOrIdOrClass); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!hasStyleOrIdOrClass && nsHTMLEditUtils::IsDiv(aElement)) { nsCOMPtr<nsIHTMLEditRules> htmlRules = do_QueryInterface(mRules); if (!htmlRules) return NS_ERROR_FAILURE; res = htmlRules->MakeSureElemStartsOrEndsOnCR(aElement); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = RemoveContainer(aElement); } } @@ -680,52 +680,52 @@ nsHTMLEditor::CheckPositionedElementBGandFG(nsIDOMElement * aElement, mHTMLCSSUtils->GetComputedProperty(aElement, nsEditProperty::cssBackgroundImage, bgImageStr); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bgImageStr.EqualsLiteral("none")) { nsAutoString bgColorStr; res = mHTMLCSSUtils->GetComputedProperty(aElement, nsEditProperty::cssBackgroundColor, bgColorStr); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bgColorStr.EqualsLiteral("transparent")) { nsCOMPtr<nsIDOMViewCSS> viewCSS; res = mHTMLCSSUtils->GetDefaultViewCSS(aElement, getter_AddRefs(viewCSS)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl; res = viewCSS->GetComputedStyle(aElement, EmptyString(), getter_AddRefs(cssDecl)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // from these declarations, get the one we want and that one only nsCOMPtr<nsIDOMCSSValue> colorCssValue; res = cssDecl->GetPropertyCSSValue(NS_LITERAL_STRING("color"), getter_AddRefs(colorCssValue)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRUint16 type; res = colorCssValue->GetCssValueType(&type); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nsIDOMCSSValue::CSS_PRIMITIVE_VALUE == type) { nsCOMPtr<nsIDOMCSSPrimitiveValue> val = do_QueryInterface(colorCssValue); res = val->GetPrimitiveType(&type); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nsIDOMCSSPrimitiveValue::CSS_RGBCOLOR == type) { nsCOMPtr<nsIDOMRGBColor> rgbColor; res = val->GetRGBColorValue(getter_AddRefs(rgbColor)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMCSSPrimitiveValue> red, green, blue; float r, g, b; res = rgbColor->GetRed(getter_AddRefs(red)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = rgbColor->GetGreen(getter_AddRefs(green)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = rgbColor->GetBlue(getter_AddRefs(blue)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = red->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_NUMBER, &r); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = green->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_NUMBER, &g); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = blue->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_NUMBER, &b); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (r >= BLACK_BG_RGB_TRIGGER && g >= BLACK_BG_RGB_TRIGGER && b >= BLACK_BG_RGB_TRIGGER) diff --git a/editor/libeditor/html/nsHTMLAnonymousUtils.cpp b/editor/libeditor/html/nsHTMLAnonymousUtils.cpp index 2ce426515e7..c7a07b073f0 100644 --- a/editor/libeditor/html/nsHTMLAnonymousUtils.cpp +++ b/editor/libeditor/html/nsHTMLAnonymousUtils.cpp @@ -83,7 +83,7 @@ static PRInt32 GetCSSFloatValue(nsIDOMCSSStyleDeclaration * aDecl, case nsIDOMCSSPrimitiveValue::CSS_PX: // the value is in pixels, just get it res = val->GetFloatValue(nsIDOMCSSPrimitiveValue::CSS_PX, &f); - if (NS_FAILED(res)) return 0; + NS_ENSURE_SUCCESS(res, 0); break; case nsIDOMCSSPrimitiveValue::CSS_IDENT: { // the value is keyword, we have to map these keywords into @@ -163,7 +163,7 @@ nsHTMLEditor::CreateAnonymousElement(const nsAString & aTag, nsIDOMNode * aPare // Create a new node through the element factory nsCOMPtr<nsIContent> newContent; nsresult res = CreateHTMLContent(aTag, getter_AddRefs(newContent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(newContent); if (!newElement) @@ -173,14 +173,14 @@ nsHTMLEditor::CreateAnonymousElement(const nsAString & aTag, nsIDOMNode * aPare if (aIsCreatedHidden) { res = newElement->SetAttribute(NS_LITERAL_STRING("class"), NS_LITERAL_STRING("hidden")); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // add an _moz_anonclass attribute if needed if (!aAnonClass.IsEmpty()) { res = newElement->SetAttribute(NS_LITERAL_STRING("_moz_anonclass"), aAnonClass); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } { @@ -293,12 +293,12 @@ nsHTMLEditor::CheckSelectionStateForAnonymousButtons(nsISelection * aSelection) // let's get the containing element of the selection nsresult res = GetSelectionContainer(getter_AddRefs(focusElement)); if (!focusElement) return NS_OK; - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // what's its tag? nsAutoString focusTagName; res = focusElement->GetTagName(focusTagName); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); ToLowerCase(focusTagName); nsCOMPtr<nsIAtom> focusTagAtom = do_GetAtom(focusTagName); @@ -307,7 +307,7 @@ nsHTMLEditor::CheckSelectionStateForAnonymousButtons(nsISelection * aSelection) // Absolute Positioning support is enabled, is the selection contained // in an absolutely positioned element ? res = GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(absPosElement)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } nsCOMPtr<nsIDOMElement> cellElement; @@ -317,7 +317,7 @@ nsHTMLEditor::CheckSelectionStateForAnonymousButtons(nsISelection * aSelection) res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cellElement)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (mIsObjectResizingEnabled && cellElement) { @@ -351,21 +351,21 @@ nsHTMLEditor::CheckSelectionStateForAnonymousButtons(nsISelection * aSelection) if (mIsAbsolutelyPositioningEnabled && mAbsolutelyPositionedObject && absPosElement != mAbsolutelyPositionedObject) { res = HideGrabber(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); NS_ASSERTION(!mAbsolutelyPositionedObject, "HideGrabber failed"); } if (mIsObjectResizingEnabled && mResizedObject && mResizedObject != focusElement) { res = HideResizers(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); NS_ASSERTION(!mResizedObject, "HideResizers failed"); } if (mIsInlineTableEditingEnabled && mInlineEditedCell && mInlineEditedCell != cellElement) { res = HideInlineTableEditingUI(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); NS_ASSERTION(!mInlineEditedCell, "HideInlineTableEditingUI failed"); } @@ -379,7 +379,7 @@ nsHTMLEditor::CheckSelectionStateForAnonymousButtons(nsISelection * aSelection) res = RefreshResizers(); else res = ShowResizers(focusElement); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (mIsAbsolutelyPositioningEnabled && absPosElement && @@ -388,7 +388,7 @@ nsHTMLEditor::CheckSelectionStateForAnonymousButtons(nsISelection * aSelection) res = RefreshGrabber(); else res = ShowGrabberOnElement(absPosElement); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (mIsInlineTableEditingEnabled && cellElement && @@ -418,7 +418,7 @@ nsHTMLEditor::GetPositionAndDimensions(nsIDOMElement * aElement, // Is the element positioned ? let's check the cheap way first... PRBool isPositioned = PR_FALSE; nsresult res = aElement->HasAttribute(NS_LITERAL_STRING("_moz_abspos"), &isPositioned); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!isPositioned) { // hmmm... the expensive way now... nsAutoString positionStr; @@ -438,7 +438,7 @@ nsHTMLEditor::GetPositionAndDimensions(nsIDOMElement * aElement, nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl; // Get the all the computed css styles attached to the element node res = viewCSS->GetComputedStyle(aElement, EmptyString(), getter_AddRefs(cssDecl)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aBorderLeft = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-left-width")); aBorderTop = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-top-width")); @@ -460,7 +460,7 @@ nsHTMLEditor::GetPositionAndDimensions(nsIDOMElement * aElement, GetElementOrigin(aElement, aX, aY); res = nsElement->GetOffsetWidth(&aW); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = nsElement->GetOffsetHeight(&aH); aBorderLeft = 0; diff --git a/editor/libeditor/html/nsHTMLCSSUtils.cpp b/editor/libeditor/html/nsHTMLCSSUtils.cpp index b93bb67e4c9..565ae9cc14c 100644 --- a/editor/libeditor/html/nsHTMLCSSUtils.cpp +++ b/editor/libeditor/html/nsHTMLCSSUtils.cpp @@ -317,7 +317,7 @@ nsHTMLCSSUtils::Init(nsHTMLEditor *aEditor) do_GetService(NS_PREFSERVICE_CONTRACTID, &result); if (NS_SUCCEEDED(result) && prefBranch) { result = prefBranch->GetBoolPref("editor.use_css", &mIsCSSPrefChecked); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); } return result; } @@ -542,7 +542,7 @@ nsHTMLCSSUtils::GetComputedProperty(nsIDOMNode *aNode, nsIAtom *aProperty, { nsCOMPtr<nsIDOMViewCSS> viewCSS = nsnull; nsresult res = GetDefaultViewCSS(aNode, getter_AddRefs(viewCSS)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return GetCSSInlinePropertyBase(aNode, aProperty, aValue, viewCSS, COMPUTED_STYLE_TYPE); } @@ -558,7 +558,7 @@ nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode *aNode, nsIAtom *aProperty, nsCOMPtr<nsIDOMElement>element; nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(element)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); switch (aStyleType) { case COMPUTED_STYLE_TYPE: @@ -571,7 +571,7 @@ nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode *aNode, nsIAtom *aProperty, if (NS_FAILED(res) || !cssDecl) return res; // from these declarations, get the one we want and that one only res = cssDecl->GetPropertyValue(propString, value); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aValue.Assign(value); } break; @@ -584,7 +584,7 @@ nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode *aNode, nsIAtom *aProperty, nsAutoString value, propString; aProperty->ToString(propString); res = cssDecl->GetPropertyValue(propString, value); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aValue.Assign(value); } break; @@ -597,7 +597,7 @@ nsHTMLCSSUtils::GetDefaultViewCSS(nsIDOMNode *aNode, nsIDOMViewCSS **aViewCSS) { nsCOMPtr<nsIDOMElement>element; nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(element)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if we have an element node if (element) { @@ -605,13 +605,13 @@ nsHTMLCSSUtils::GetDefaultViewCSS(nsIDOMNode *aNode, nsIDOMViewCSS **aViewCSS) nsCOMPtr<nsIDOMDocument> doc; nsCOMPtr<nsIDOMNode> node = do_QueryInterface(element); res = node->GetOwnerDocument(getter_AddRefs(doc)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (doc) { nsCOMPtr<nsIDOMDocumentView> documentView = do_QueryInterface(doc); nsCOMPtr<nsIDOMAbstractView> abstractView; // from the document, get the abtractView res = documentView->GetDefaultView(getter_AddRefs(abstractView)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (abstractView) { // from the abstractView, get the CSS view CallQueryInterface(abstractView, aViewCSS); @@ -645,7 +645,7 @@ nsHTMLCSSUtils::RemoveCSSInlineStyle(nsIDOMNode *aNode, nsIAtom *aProperty, cons // remove the property from the style attribute nsresult res = RemoveCSSProperty(elem, aProperty, aPropertyValue, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nsEditor::NodeIsType(aNode, nsEditProperty::span)) { nsCOMPtr<nsIContent> content = do_QueryInterface(aNode); @@ -654,13 +654,13 @@ nsHTMLCSSUtils::RemoveCSSInlineStyle(nsIDOMNode *aNode, nsIAtom *aProperty, cons if (0 == attrCount) { // no more attributes on this span, let's remove the element res = mHTMLEditor->RemoveContainer(aNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else if (1 == attrCount) { // incredible hack in case the only remaining attribute is a _moz_dirty... if (content->GetAttrNameAt(0)->Equals(nsEditProperty::mozdirty)) { res = mHTMLEditor->RemoveContainer(aNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -682,26 +682,26 @@ nsHTMLCSSUtils::GetDefaultBackgroundColor(nsAString & aColor) nsresult result; nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &result); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); aColor.AssignLiteral("#ffffff"); nsXPIDLCString returnColor; if (prefBranch) { PRBool useCustomColors; result = prefBranch->GetBoolPref("editor.use_custom_colors", &useCustomColors); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (useCustomColors) { result = prefBranch->GetCharPref("editor.background_color", getter_Copies(returnColor)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); } else { PRBool useSystemColors; result = prefBranch->GetBoolPref("browser.display.use_system_colors", &useSystemColors); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!useSystemColors) { result = prefBranch->GetCharPref("browser.display.background_color", getter_Copies(returnColor)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); } } } @@ -718,13 +718,13 @@ nsHTMLCSSUtils::GetDefaultLengthUnit(nsAString & aLengthUnit) nsresult result; nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &result); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); aLengthUnit.AssignLiteral("px"); if (NS_SUCCEEDED(result) && prefBranch) { nsXPIDLCString returnLengthUnit; result = prefBranch->GetCharPref("editor.css.default_length_unit", getter_Copies(returnLengthUnit)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (returnLengthUnit) { CopyASCIItoUTF16(returnLengthUnit, aLengthUnit); } @@ -1009,7 +1009,7 @@ nsHTMLCSSUtils::SetCSSEquivalentToHTMLStyle(nsIDOMNode * aNode, nsCOMPtr<nsIDOMElement> theElement = do_QueryInterface(aNode); res = SetCSSProperty(theElement, cssPropertyArray[index], cssValueArray[index], aSuppressTransaction); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } return NS_OK; @@ -1044,7 +1044,7 @@ nsHTMLCSSUtils::RemoveCSSEquivalentToHTMLStyle(nsIDOMNode * aNode, cssPropertyArray[index], cssValueArray[index], aSuppressTransaction); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } return NS_OK; @@ -1059,9 +1059,9 @@ nsHTMLCSSUtils::HasClassOrID(nsIDOMElement * aElement, PRBool & aReturn) aReturn = PR_FALSE; nsresult res = mHTMLEditor->GetAttributeValue(aElement, NS_LITERAL_STRING("class"), classVal, &isClassSet); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->GetAttributeValue(aElement, NS_LITERAL_STRING("id"), idVal, &isIdSet); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // we need to make sure that if the element has an id or a class attribute, // the attribute is not the empty string @@ -1084,7 +1084,7 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode, aValueString.Truncate(); nsCOMPtr<nsIDOMElement> theElement; nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(theElement)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (theElement && IsCSSEditableProperty(theElement, aHTMLProperty, aAttribute)) { // Yes, the requested HTML style has a CSS equivalence in this implementation @@ -1092,7 +1092,7 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode, nsCOMPtr<nsIDOMViewCSS> viewCSS = nsnull; if (COMPUTED_STYLE_TYPE == aStyleType) { res = GetDefaultViewCSS(theElement, getter_AddRefs(viewCSS)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } nsTArray<nsIAtom*> cssPropertyArray; nsTArray<nsString> cssValueArray; @@ -1107,7 +1107,7 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode, // retrieve the specified/computed value of the property res = GetCSSInlinePropertyBase(theElement, cssPropertyArray[index], valueString, viewCSS, aStyleType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // append the value to aValueString (possibly with a leading whitespace) if (index) aValueString.Append(PRUnichar(' ')); aValueString.Append(valueString); @@ -1140,7 +1140,7 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode, // get the value of the CSS equivalent styles nsresult res = GetCSSEquivalentToHTMLInlineStyleSet(node, aHTMLProperty, aHTMLAttribute, valueString, aStyleType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // early way out if we can if (valueString.IsEmpty()) return NS_OK; @@ -1274,7 +1274,7 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode, // that means that we have to look at ancestors of node to see if they are underlined nsCOMPtr<nsIDOMNode> tmp; res = node->GetParentNode(getter_AddRefs(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMElement> element = do_QueryInterface(tmp); node = element; // set to null if it's not a dom element } @@ -1402,7 +1402,7 @@ nsHTMLCSSUtils::GetElementContainerOrSelf(nsIDOMNode * aNode, nsIDOMElement ** a PRUint16 type; nsresult res; res = node->GetNodeType(&type); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nsIDOMNode::DOCUMENT_NODE == type) { return NS_ERROR_NULL_POINTER; @@ -1412,10 +1412,10 @@ nsHTMLCSSUtils::GetElementContainerOrSelf(nsIDOMNode * aNode, nsIDOMElement ** a while (node && nsIDOMNode::ELEMENT_NODE != type) { parentNode = node; res = parentNode->GetParentNode(getter_AddRefs(node)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (node) { res = node->GetNodeType(&type); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } NS_ASSERTION(node, "we reached a null node ancestor !"); diff --git a/editor/libeditor/html/nsHTMLDataTransfer.cpp b/editor/libeditor/html/nsHTMLDataTransfer.cpp index 054d2f0fdfb..b6016106584 100644 --- a/editor/libeditor/html/nsHTMLDataTransfer.cpp +++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp @@ -184,24 +184,24 @@ NS_IMETHODIMP nsHTMLEditor::LoadHTML(const nsAString & aInputString) // Get selection nsCOMPtr<nsISelection>selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsTextRulesInfo ruleInfo(nsTextEditRules::kLoadHTML); PRBool cancel, handled; res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (cancel) return NS_OK; // rules canceled the operation if (!handled) { PRBool isCollapsed; res = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Delete Selection, but only if it isn't collapsed, see bug #106269 if (!isCollapsed) { res = DeleteSelection(eNone); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // Get the first range in the selection, for context: @@ -274,7 +274,7 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, nsresult res; nsCOMPtr<nsISelection>selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // create a dom document fragment that represents the structure to paste nsCOMPtr<nsIDOMNode> fragmentAsNode, streamStartParent, streamEndParent; @@ -297,7 +297,7 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, // fetch the paste insertion point from our selection res = GetStartNodeAndOffset(selection, getter_AddRefs(targetNode), &targetOffset); if (!targetNode) res = NS_ERROR_FAILURE; - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { @@ -411,7 +411,7 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement); PRBool cancel, handled; res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (cancel) return NS_OK; // rules canceled the operation if (!handled) { @@ -419,7 +419,7 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, // refresh our memory... res = GetStartNodeAndOffset(selection, getter_AddRefs(parentNode), &offsetOfNewNode); if (!parentNode) res = NS_ERROR_FAILURE; - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Adjust position based on the first node we are going to insert. NormalizeEOLInsertPosition(nodeList[0], address_of(parentNode), &offsetOfNewNode); @@ -432,7 +432,7 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, !IsVisBreak(wsObj.mEndReasonNode) ) { res = DeleteNode(wsObj.mEndReasonNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // remeber if we are in a link. @@ -443,9 +443,9 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, { nsCOMPtr<nsIDOMNode> temp; res = SplitNodeDeep(parentNode, parentNode, offsetOfNewNode, &offsetOfNewNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = parentNode->GetParentNode(getter_AddRefs(temp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); parentNode = temp; } @@ -654,7 +654,7 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, if (!nsHTMLEditUtils::IsTable(lastInsertNode)) { res = GetLastEditableLeaf(lastInsertNode, address_of(selNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); tmp = selNode; while (tmp && (tmp != lastInsertNode)) { @@ -672,14 +672,14 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, if (IsTextNode(selNode) || (IsContainer(selNode) && !nsHTMLEditUtils::IsTable(selNode))) { res = GetLengthOfDOMNode(selNode, (PRUint32&)selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else // we need to find a container for selection. Look up. { tmp = selNode; res = GetNodeLocation(tmp, address_of(selNode), &selOffset); ++selOffset; // want to be *after* last leaf node in paste - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // make sure we don't end up with selection collapsed after an invisible break node @@ -687,7 +687,7 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, PRInt32 outVisOffset=0; PRInt16 visType=0; res = wsRunObj.PriorVisibleNode(selNode, selOffset, address_of(visNode), &outVisOffset, &visType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (visType == nsWSRunObject::eBreak) { // we are after a break. Is it visible? Despite the name, @@ -702,7 +702,7 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, // we want to be inside any inline style prior to break nsWSRunObject wsRunObj(this, selNode, selOffset); res = wsRunObj.PriorVisibleNode(selNode, selOffset, address_of(visNode), &outVisOffset, &visType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (visType == nsWSRunObject::eText || visType == nsWSRunObject::eNormalWS) { @@ -731,9 +731,9 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, nsCOMPtr<nsIDOMNode> leftLink; PRInt32 linkOffset; res = SplitNodeDeep(link, selNode, selOffset, &linkOffset, PR_TRUE, address_of(leftLink)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = GetNodeLocation(leftLink, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); selection->Collapse(selNode, selOffset+1); } } @@ -1485,7 +1485,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) nsresult rv; nsCOMPtr<nsIDragService> dragService = do_GetService("@mozilla.org/widget/dragservice;1", &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIDragSession> dragSession; dragService->GetCurrentSession(getter_AddRefs(dragSession)); @@ -1499,17 +1499,17 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) // around with cfhtml if we do. PRBool bHavePrivateHTMLFlavor = PR_FALSE; rv = dragSession->IsDataFlavorSupported(kHTMLContext, &bHavePrivateHTMLFlavor); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Get the nsITransferable interface for getting the data from the drop nsCOMPtr<nsITransferable> trans; rv = PrepareHTMLTransferable(getter_AddRefs(trans), bHavePrivateHTMLFlavor); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!trans) return NS_OK; // NS_ERROR_FAILURE; SHOULD WE FAIL? PRUint32 numItems = 0; rv = dragSession->GetNumDropItems(&numItems); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Combine any deletion and drop insertion into one transaction nsAutoEditBatch beginBatching(this); @@ -1522,14 +1522,14 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) // Source doc is null if source is *not* the current editor document nsCOMPtr<nsIDOMDocument> srcdomdoc; rv = dragSession->GetSourceDocument(getter_AddRefs(srcdomdoc)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); PRUint32 i; PRBool doPlaceCaret = PR_TRUE; for (i = 0; i < numItems; ++i) { rv = dragSession->GetData(trans, i); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!trans) return NS_OK; // NS_ERROR_FAILURE; Should we fail? // get additional html copy hints, if present @@ -1591,24 +1591,24 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) // Current doc is destination nsCOMPtr<nsIDOMDocument>destdomdoc; rv = GetDocument(getter_AddRefs(destdomdoc)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISelection> selection; rv = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!selection) return NS_ERROR_FAILURE; PRBool isCollapsed; rv = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Parent and offset under the mouse cursor rv = nsuiEvent->GetRangeParent(getter_AddRefs(newSelectionParent)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!newSelectionParent) return NS_ERROR_FAILURE; rv = nsuiEvent->GetRangeOffset(&newSelectionOffset); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // XXX: This userSelectNode code is a workaround for bug 195957. // @@ -1631,7 +1631,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) rv = GetNodeLocation(userSelectNode, address_of(newSelectionParent), &newSelectionOffset); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!newSelectionParent) return NS_ERROR_FAILURE; } @@ -1720,7 +1720,7 @@ nsHTMLEditor::PutDragDataInTransferable(nsITransferable **aTransferable) *aTransferable = nsnull; nsCOMPtr<nsIDocumentEncoder> docEncoder; nsresult rv = SetupDocEncoder(getter_AddRefs(docEncoder)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(docEncoder, NS_ERROR_FAILURE); // grab a string @@ -1731,13 +1731,13 @@ nsHTMLEditor::PutDragDataInTransferable(nsITransferable **aTransferable) { // encode the selection as html with contextual info rv = docEncoder->EncodeToStringWithContext(parents, info, buffer); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } else { // encode the selection rv = docEncoder->EncodeToString(buffer); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } // if we have an empty string, we're done; otherwise continue @@ -1749,7 +1749,7 @@ nsHTMLEditor::PutDragDataInTransferable(nsITransferable **aTransferable) dataWrapper = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); rv = dataWrapper->SetData(buffer); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); /* create html flavor transferable */ nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1"); @@ -1759,14 +1759,14 @@ nsHTMLEditor::PutDragDataInTransferable(nsITransferable **aTransferable) { // Add the unicode flavor to the transferable rv = trans->AddDataFlavor(kUnicodeMime); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // QI the data object an |nsISupports| so that when the transferable holds // onto it, it will addref the correct interface. nsCOMPtr<nsISupports> genericDataObj(do_QueryInterface(dataWrapper)); rv = trans->SetTransferData(kUnicodeMime, genericDataObj, buffer.Length() * sizeof(PRUnichar)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } else { @@ -1779,19 +1779,19 @@ nsHTMLEditor::PutDragDataInTransferable(nsITransferable **aTransferable) infoWrapper->SetData(info); rv = trans->AddDataFlavor(kHTMLMime); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIFormatConverter> htmlConverter = do_CreateInstance("@mozilla.org/widget/htmlformatconverter;1"); NS_ENSURE_TRUE(htmlConverter, NS_ERROR_FAILURE); rv = trans->SetConverter(htmlConverter); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISupports> genericDataObj(do_QueryInterface(dataWrapper)); rv = trans->SetTransferData(kHTMLMime, genericDataObj, buffer.Length() * sizeof(PRUnichar)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!parents.IsEmpty()) { @@ -1993,7 +1993,7 @@ NS_IMETHODIMP nsHTMLEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste) nsresult rv; nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); PRBool haveFlavors; @@ -2007,7 +2007,7 @@ NS_IMETHODIMP nsHTMLEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste) NS_ARRAY_LENGTH(textHtmlEditorFlavors), aSelectionType, &haveFlavors); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); *aCanPaste = haveFlavors; return NS_OK; @@ -2080,20 +2080,20 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(const nsAString & aCitation, // get selection nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; // give rules a chance to handle or cancel nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement); PRBool cancel, handled; res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (cancel) return NS_OK; // rules canceled the operation if (!handled) { nsCOMPtr<nsIDOMNode> newNode; res = DeleteSelectionAndCreateNode(NS_LITERAL_STRING("blockquote"), getter_AddRefs(newNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!newNode) return NS_ERROR_NULL_POINTER; // Try to set type=cite. Ignore it if this fails. @@ -2126,7 +2126,7 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsPlaintextQuotation(PRInt32 aSelectionType) // Get Clipboard Service nsresult rv; nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Create generic Transferable for getting the data nsCOMPtr<nsITransferable> trans = @@ -2304,7 +2304,7 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAString & aQuotedText, // get selection nsCOMPtr<nsISelection> selection; rv = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!selection) return NS_ERROR_NULL_POINTER; else { @@ -2315,7 +2315,7 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAString & aQuotedText, nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement); PRBool cancel, handled; rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (cancel) return NS_OK; // rules canceled the operation if (!handled) { @@ -2417,7 +2417,7 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsAString & aQuotedText, // get selection nsCOMPtr<nsISelection> selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; else { @@ -2428,12 +2428,12 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsAString & aQuotedText, nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement); PRBool cancel, handled; res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (cancel) return NS_OK; // rules canceled the operation if (!handled) { res = DeleteSelectionAndCreateNode(NS_LITERAL_STRING("blockquote"), getter_AddRefs(newNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!newNode) return NS_ERROR_NULL_POINTER; // Try to set type=cite. Ignore it if this fails. diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index 337c05ed59e..e8602d9efe0 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -147,7 +147,7 @@ class nsEmptyEditableFunctor : public nsBoolDomIterFunctor { PRBool bIsEmptyNode; nsresult res = mHTMLEditor->IsEmptyNode(aNode, &bIsEmptyNode, PR_FALSE, PR_FALSE); - if (NS_FAILED(res)) return PR_FALSE; + NS_ENSURE_SUCCESS(res, PR_FALSE); if (bIsEmptyNode) return PR_TRUE; } @@ -255,12 +255,12 @@ nsHTMLEditRules::Init(nsPlaintextEditor *aEditor) // call through to base class Init res = nsTextEditRules::Init(aEditor); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // cache any prefs we care about nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); char *returnInEmptyLIKillsList = 0; res = prefBranch->GetCharPref("editor.html.typing.returnInEmptyListItemClosesList", @@ -295,7 +295,7 @@ nsHTMLEditRules::Init(nsPlaintextEditor *aEditor) } mDocChangeRange->SelectNode(rootElem); res = AdjustSpecialBreaks(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // add ourselves as a listener to edit actions @@ -329,19 +329,19 @@ nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection) // get selection nsCOMPtr<nsISelection>selection; nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // get the selection start location nsCOMPtr<nsIDOMNode> selStartNode, selEndNode; PRInt32 selOffset; res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(selStartNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); mRangeItem.startNode = selStartNode; mRangeItem.startOffset = selOffset; // get the selection end location res = mHTMLEditor->GetEndNodeAndOffset(selection, getter_AddRefs(selEndNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); mRangeItem.endNode = selEndNode; mRangeItem.endOffset = selOffset; @@ -375,7 +375,7 @@ nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection) if (aDirection == nsIEditor::eNext) selNode = selEndNode; res = CacheInlineStyles(selNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // check that selection is in subtree defined by body node @@ -416,7 +416,7 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection) nsCOMPtr<nsISelection> selection; nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(selection)); nsCOMPtr<nsFrameSelection> frameSelection; privateSelection->GetFrameSelection(getter_AddRefs(frameSelection)); @@ -438,7 +438,7 @@ nsHTMLEditRules::AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection nsCOMPtr<nsISelection>selection; nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> rangeStartParent, rangeEndParent; PRInt32 rangeStartOffset = 0, rangeEndOffset = 0; @@ -462,7 +462,7 @@ nsHTMLEditRules::AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection // expand the "changed doc range" as needed res = PromoteRange(mDocChangeRange, action); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if we did a ranged deletion, make sure we have a place to put caret. // Note we only want to do this if the overall operation was deletion, @@ -471,19 +471,19 @@ nsHTMLEditRules::AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection if ((action == nsEditor::kOpDeleteSelection) && mDidRangedDelete) { res = InsertBRIfNeeded(selection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // add in any needed <br>s, and remove any unneeded ones. res = AdjustSpecialBreaks(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // merge any adjacent text nodes if ( (action != nsEditor::kOpInsertText && action != nsEditor::kOpInsertIMEText) ) { res = mHTMLEditor->CollapseAdjacentTextNodes(mDocChangeRange); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // replace newlines with breaks. @@ -498,12 +498,12 @@ nsHTMLEditRules::AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection (action == nsHTMLEditor::kOpLoadHTML))) { res = ReplaceNewlines(mDocChangeRange); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // clean up any empty nodes in the selection res = RemoveEmptyNodes(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // attempt to transform any unneeded nbsp's into spaces after doing various operations if ((action == nsEditor::kOpInsertText) || @@ -514,7 +514,7 @@ nsHTMLEditRules::AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection (action == nsHTMLEditor::kOpLoadHTML))) { res = AdjustWhitespace(selection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // also do this for original selection endpoints. nsWSRunObject(mHTMLEditor, mRangeItem.startNode, mRangeItem.startOffset).AdjustWhitespace(); @@ -541,7 +541,7 @@ nsHTMLEditRules::AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection (action == nsHTMLEditor::kOpLoadHTML))) { res = AdjustSelection(selection, aDirection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // check for any styles which were removed inappropriately @@ -552,9 +552,9 @@ nsHTMLEditRules::AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection { mHTMLEditor->mTypeInState->UpdateSelState(selection); res = ReapplyCachedStyles(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = ClearCachedStyles(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -711,7 +711,7 @@ nsHTMLEditRules::DidDoAction(nsISelection *aSelection, return DidMakeBasicBlock(aSelection, aInfo, aResult); case kSetAbsolutePosition: { nsresult rv = DidMakeBasicBlock(aSelection, aInfo, aResult); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); return DidAbsolutePosition(); } } @@ -737,7 +737,7 @@ nsHTMLEditRules::GetListState(PRBool *aMixed, PRBool *aOL, PRBool *aUL, PRBool * nsCOMArray<nsIDOMNode> arrayOfNodes; nsresult res = GetListActionNodes(arrayOfNodes, PR_FALSE, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // examine list type for nodes in selection PRInt32 listCount = arrayOfNodes.Count(); @@ -755,7 +755,7 @@ nsHTMLEditRules::GetListState(PRBool *aMixed, PRBool *aOL, PRBool *aUL, PRBool * nsCOMPtr<nsIDOMNode> parent; PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nsHTMLEditUtils::IsUnorderedList(parent)) *aUL = PR_TRUE; else if (nsHTMLEditUtils::IsOrderedList(parent)) @@ -789,7 +789,7 @@ nsHTMLEditRules::GetListItemState(PRBool *aMixed, PRBool *aLI, PRBool *aDT, PRBo nsCOMArray<nsIDOMNode> arrayOfNodes; nsresult res = GetListActionNodes(arrayOfNodes, PR_FALSE, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // examine list type for nodes in selection PRInt32 listCount = arrayOfNodes.Count(); @@ -817,7 +817,7 @@ nsHTMLEditRules::GetListItemState(PRBool *aMixed, PRBool *aLI, PRBool *aDT, PRBo // need to look inside dl and see which types of items it has PRBool bDT, bDD; res = GetDefinitionListItemTypes(curNode, bDT, bDD); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *aDT |= bDT; *aDD |= bDD; } @@ -850,7 +850,7 @@ nsHTMLEditRules::GetAlignment(PRBool *aMixed, nsIHTMLEditor::EAlignment *aAlign) // get selection nsCOMPtr<nsISelection>selection; nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // get selection location nsCOMPtr<nsIDOMNode> parent; @@ -860,14 +860,14 @@ nsHTMLEditRules::GetAlignment(PRBool *aMixed, nsIHTMLEditor::EAlignment *aAlign) PRInt32 offset, rootOffset; res = nsEditor::GetNodeLocation(rootElem, address_of(parent), &rootOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // is the selection collapsed? PRBool bCollapsed; res = selection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> nodeToExamine; nsCOMPtr<nsISupports> isupports; if (bCollapsed) @@ -891,12 +891,12 @@ nsHTMLEditRules::GetAlignment(PRBool *aMixed, nsIHTMLEditor::EAlignment *aAlign) { nsCOMArray<nsIDOMRange> arrayOfRanges; res = GetPromotedRanges(selection, arrayOfRanges, kAlign); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // use these ranges to construct a list of nodes to act on. nsCOMArray<nsIDOMNode> arrayOfNodes; res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, kAlign, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nodeToExamine = arrayOfNodes.SafeObjectAt(0); } @@ -1013,7 +1013,7 @@ nsHTMLEditRules::GetIndentState(PRBool *aCanIndent, PRBool *aCanOutdent) // get selection nsCOMPtr<nsISelection>selection; nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); if (!selPriv) return NS_ERROR_FAILURE; @@ -1021,7 +1021,7 @@ nsHTMLEditRules::GetIndentState(PRBool *aCanIndent, PRBool *aCanOutdent) // contruct a list of nodes to act on. nsCOMArray<nsIDOMNode> arrayOfNodes; res = GetNodesFromSelection(selection, kIndent, arrayOfNodes, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // examine nodes in selection for blockquotes or list elements; // these we can outdent. Note that we return true for canOutdent @@ -1072,12 +1072,12 @@ nsHTMLEditRules::GetIndentState(PRBool *aCanIndent, PRBool *aCanOutdent) root = do_QueryInterface(rootElem); if (!root) return NS_ERROR_NO_INTERFACE; res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; // test start parent hierarchy res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(parent), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); while (parent && (parent!=root)) { if (nsHTMLEditUtils::IsNodeThatCanOutdent(parent)) @@ -1091,7 +1091,7 @@ nsHTMLEditRules::GetIndentState(PRBool *aCanIndent, PRBool *aCanOutdent) // test end parent hierarchy res = mHTMLEditor->GetEndNodeAndOffset(selection, getter_AddRefs(parent), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); while (parent && (parent!=root)) { if (nsHTMLEditUtils::IsNodeThatCanOutdent(parent)) @@ -1123,7 +1123,7 @@ nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat) nsCOMArray<nsIDOMNode> arrayOfNodes; nsresult res = GetParagraphFormatNodes(arrayOfNodes, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // post process list. We need to replace any block nodes that are not format // nodes with their content. This is so we only have to look "up" the hierarchy @@ -1139,7 +1139,7 @@ nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat) { // arrayOfNodes.RemoveObject(curNode); res = AppendInnerFormatNodes(arrayOfNodes, curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -1152,9 +1152,9 @@ nsHTMLEditRules::GetParagraphState(PRBool *aMixed, nsAString &outFormat) PRInt32 selOffset; nsCOMPtr<nsISelection>selection; res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selNode) return NS_ERROR_NULL_POINTER; arrayOfNodes.AppendObject(selNode); listCount = 1; @@ -1282,7 +1282,7 @@ nsresult nsHTMLEditRules::WillInsert(nsISelection *aSelection, PRBool *aCancel) { nsresult res = nsTextEditRules::WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Adjust selection to prevent insertion after a moz-BR. // this next only works for collapsed selections right now, @@ -1290,7 +1290,7 @@ nsHTMLEditRules::WillInsert(nsISelection *aSelection, PRBool *aCancel) // (no good way to extend start or end of selection) PRBool bCollapsed; res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bCollapsed) return NS_OK; // if we are after a mozBR in the same block, then move selection @@ -1300,7 +1300,7 @@ nsHTMLEditRules::WillInsert(nsISelection *aSelection, PRBool *aCancel) // get the (collapsed) selection location res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // get prior node res = mHTMLEditor->GetPriorHTMLNode(selNode, selOffset, address_of(priorNode)); @@ -1317,16 +1317,16 @@ nsHTMLEditRules::WillInsert(nsISelection *aSelection, PRBool *aCancel) // that is in the same block as the selection. We need to move // the selection start to be before the mozBR. res = nsEditor::GetNodeLocation(priorNode, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = aSelection->Collapse(selNode,selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } // we need to get the doc nsCOMPtr<nsIDOMDocument>doc; res = mHTMLEditor->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!doc) return NS_ERROR_NULL_POINTER; // for every property that is set, insert a new inline style node @@ -1376,22 +1376,22 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, // if the selection isn't collapsed, delete it. PRBool bCollapsed; res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bCollapsed) { res = mHTMLEditor->DeleteSelection(nsIEditor::eNone); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() *aCancel = PR_FALSE; // get the (collapsed) selection location res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // dont put text in places that can't have it if (!mHTMLEditor->IsTextNode(selNode) && @@ -1401,7 +1401,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, // we need to get the doc nsCOMPtr<nsIDOMDocument>doc; res = mHTMLEditor->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!doc) return NS_ERROR_NULL_POINTER; if (aAction == kInsertTextIME) @@ -1417,7 +1417,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, nsWSRunObject wsObj(mHTMLEditor, selNode, selOffset); res = wsObj.InsertText(*inString, address_of(selNode), &selOffset, doc); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else // aAction == kInsertText { @@ -1429,7 +1429,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, // We remember this so that we know how to handle tabs. PRBool isPRE; res = mHTMLEditor->IsPreformatted(selNode, &isPRE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // turn off the edit listener: we know how to // build the "doc changed range" ourselves, and it's @@ -1481,7 +1481,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, { res = mHTMLEditor->InsertTextImpl(subStr, address_of(curNode), &curOffset, doc); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } else @@ -1515,22 +1515,22 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, if (subStr.Equals(tabStr)) { res = wsObj.InsertText(spacesStr, address_of(curNode), &curOffset, doc); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); pos++; } // is it a return? else if (subStr.Equals(newlineStr)) { res = wsObj.InsertBreak(address_of(curNode), &curOffset, address_of(unused), nsIEditor::eNone); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); pos++; } else { res = wsObj.InsertText(subStr, address_of(curNode), &curOffset, doc); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } nsCOMPtr<nsISelection> selection(aSelection); @@ -1545,12 +1545,12 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, if (!mDocChangeRange) return NS_ERROR_NULL_POINTER; } res = mDocChangeRange->SetStart(selNode, selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (curNode) res = mDocChangeRange->SetEnd(curNode, curOffset); else res = mDocChangeRange->SetEnd(selNode, selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return res; } @@ -1585,15 +1585,15 @@ nsHTMLEditRules::WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBo // if the selection isn't collapsed, delete it. PRBool bCollapsed; nsresult res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bCollapsed) { res = mHTMLEditor->DeleteSelection(nsIEditor::eNone); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() @@ -1604,7 +1604,7 @@ nsHTMLEditRules::WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBo if (IsMailEditor()) { res = SplitMailCites(aSelection, IsPlaintextEditor(), aHandled); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (*aHandled) return NS_OK; } @@ -1613,7 +1613,7 @@ nsHTMLEditRules::WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBo PRInt32 offset; res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!node) return NS_ERROR_FAILURE; // identify the block @@ -1644,10 +1644,10 @@ nsHTMLEditRules::WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBo { PRUint32 blockLen; res = mHTMLEditor->GetLengthOfDOMNode(blockParent, blockLen); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> brNode; res = mHTMLEditor->CreateBR(blockParent, blockLen, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } nsCOMPtr<nsIDOMNode> listItem = IsInListItem(blockParent); @@ -1670,7 +1670,7 @@ nsHTMLEditRules::WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBo else if (nsHTMLEditUtils::IsParagraph(blockParent)) { res = ReturnInParagraph(aSelection, blockParent, node, offset, aCancel, aHandled); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // fall through, we may not have handled it in ReturnInParagraph() } @@ -1704,11 +1704,11 @@ nsHTMLEditRules::StandardBreakImpl(nsIDOMNode *aNode, PRInt32 aOffset, nsISelect PRInt32 visOffset=0, newOffset; PRInt16 wsType; res = wsObj.PriorVisibleNode(node, aOffset, address_of(visNode), &visOffset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (wsType & nsWSRunObject::eBlock) bAfterBlock = PR_TRUE; res = wsObj.NextVisibleNode(node, aOffset, address_of(visNode), &visOffset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (wsType & nsWSRunObject::eBlock) bBeforeBlock = PR_TRUE; if (mHTMLEditor->IsInLink(node, address_of(linkNode))) @@ -1716,18 +1716,18 @@ nsHTMLEditRules::StandardBreakImpl(nsIDOMNode *aNode, PRInt32 aOffset, nsISelect // split the link nsCOMPtr<nsIDOMNode> linkParent; res = linkNode->GetParentNode(getter_AddRefs(linkParent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->SplitNodeDeep(linkNode, node, aOffset, &newOffset, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // reset {node,aOffset} to the point where link was split node = linkParent; aOffset = newOffset; } res = wsObj.InsertBreak(address_of(node), &aOffset, address_of(brNode), nsIEditor::eNone); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = nsEditor::GetNodeLocation(brNode, address_of(node), &aOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bAfterBlock && bBeforeBlock) { // we just placed a br between block boundaries. @@ -1744,7 +1744,7 @@ nsHTMLEditRules::StandardBreakImpl(nsIDOMNode *aNode, PRInt32 aOffset, nsISelect PRInt32 visOffset=0; PRInt16 wsType; res = wsObj.NextVisibleNode(node, aOffset+1, address_of(secondBR), &visOffset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (wsType==nsWSRunObject::eBreak) { // the next thing after the break we inserted is another break. Move the 2nd @@ -1755,11 +1755,11 @@ nsHTMLEditRules::StandardBreakImpl(nsIDOMNode *aNode, PRInt32 aOffset, nsISelect nsCOMPtr<nsIDOMNode> brParent; PRInt32 brOffset; res = nsEditor::GetNodeLocation(secondBR, address_of(brParent), &brOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ((brParent != node) || (brOffset != (aOffset+1))) { res = mHTMLEditor->MoveNode(secondBR, node, aOffset+1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } // SetInterlinePosition(PR_TRUE) means we want the caret to stick to the content on the "right". @@ -1796,9 +1796,9 @@ nsHTMLEditRules::SplitMailCites(nsISelection *aSelection, PRBool aPlaintext, PRB nsCOMPtr<nsIDOMNode> citeNode, selNode, leftCite, rightCite; PRInt32 selOffset, newOffset; nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = GetTopEnclosingMailCite(selNode, address_of(citeNode), aPlaintext); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (citeNode) { // If our selection is just before a break, nudge it to be @@ -1814,7 +1814,7 @@ nsHTMLEditRules::SplitMailCites(nsISelection *aSelection, PRBool aPlaintext, PRB PRInt32 visOffset=0; PRInt16 wsType; res = wsObj.NextVisibleNode(selNode, selOffset, address_of(visNode), &visOffset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (wsType==nsWSRunObject::eBreak) { // ok, we are just before a break. is it inside the mailquote? @@ -1823,7 +1823,7 @@ nsHTMLEditRules::SplitMailCites(nsISelection *aSelection, PRBool aPlaintext, PRB { // it is. so lets reset our selection to be just after it. res = mHTMLEditor->GetNodeLocation(visNode, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); ++selOffset; } } @@ -1831,15 +1831,15 @@ nsHTMLEditRules::SplitMailCites(nsISelection *aSelection, PRBool aPlaintext, PRB nsCOMPtr<nsIDOMNode> brNode; res = mHTMLEditor->SplitNodeDeep(citeNode, selNode, selOffset, &newOffset, PR_TRUE, address_of(leftCite), address_of(rightCite)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = citeNode->GetParentNode(getter_AddRefs(selNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateBR(selNode, newOffset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // want selection before the break, and on same line selPriv->SetInterlinePosition(PR_TRUE); res = aSelection->Collapse(selNode, newOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if citeNode wasn't a block, we might also want another break before it. // We need to examine the content both before the br we just added and also // just after it. If we don't have another br or block boundary adjacent, @@ -1851,20 +1851,20 @@ nsHTMLEditRules::SplitMailCites(nsISelection *aSelection, PRBool aPlaintext, PRB PRInt32 visOffset=0; PRInt16 wsType; res = wsObj.PriorVisibleNode(selNode, newOffset, address_of(visNode), &visOffset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ((wsType==nsWSRunObject::eNormalWS) || (wsType==nsWSRunObject::eText) || (wsType==nsWSRunObject::eSpecial)) { nsWSRunObject wsObjAfterBR(mHTMLEditor, selNode, newOffset+1); res = wsObjAfterBR.NextVisibleNode(selNode, newOffset+1, address_of(visNode), &visOffset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ((wsType==nsWSRunObject::eNormalWS) || (wsType==nsWSRunObject::eText) || (wsType==nsWSRunObject::eSpecial)) { res = mHTMLEditor->CreateBR(selNode, newOffset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -1875,14 +1875,14 @@ nsHTMLEditRules::SplitMailCites(nsISelection *aSelection, PRBool aPlaintext, PRB res = mHTMLEditor->IsEmptyNode(leftCite, &bEmptyCite, PR_TRUE, PR_FALSE); if (NS_SUCCEEDED(res) && bEmptyCite) res = mHTMLEditor->DeleteNode(leftCite); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (rightCite) { res = mHTMLEditor->IsEmptyNode(rightCite, &bEmptyCite, PR_TRUE, PR_FALSE); if (NS_SUCCEEDED(res) && bEmptyCite) res = mHTMLEditor->DeleteNode(rightCite); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } *aHandled = PR_TRUE; } @@ -1915,7 +1915,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, nsresult res = NS_OK; PRBool bCollapsed, join = PR_FALSE; res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // origCollapsed is used later to determine whether we should join // blocks. We don't really care about bCollapsed because it will be @@ -1941,7 +1941,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, } res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!startNode) return NS_ERROR_FAILURE; // get the root element @@ -1952,12 +1952,12 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, { // if we are inside an empty block, delete it. res = CheckForEmptyBlock(startNode, rootNode, aSelection, aHandled); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (*aHandled) return NS_OK; // Test for distance between caret and text that will be deleted res = CheckBidiLevelForDeletion(aSelection, startNode, startOffset, aAction, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (*aCancel) return NS_OK; res = mHTMLEditor->ExtendSelectionForDelete(aSelection, &aAction); @@ -1969,11 +1969,11 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, // ExtendSelectionForDelete() may have changed the selection, update it res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!startNode) return NS_ERROR_FAILURE; res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (bCollapsed) @@ -1989,7 +1989,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, res = wsObj.NextVisibleNode(startNode, startOffset, address_of(visNode), &visOffset, &wsType); else res = wsObj.PriorVisibleNode(startNode, startOffset, address_of(visNode), &visOffset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!visNode) // can't find anything to delete! { @@ -2005,7 +2005,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, else res = wsObj.DeleteWSBackward(); *aHandled = PR_TRUE; - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = InsertBRIfNeeded(aSelection); return res; } @@ -2044,11 +2044,11 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, NS_ENSURE_SUCCESS(res, res); } res = nsWSRunObject::PrepareToDeleteRange(mHTMLEditor, address_of(visNode), &so, address_of(visNode), &eo); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMCharacterData> nodeAsText(do_QueryInterface(visNode)); res = mHTMLEditor->DeleteText(nodeAsText, NS_MIN(so, eo), PR_ABS(eo - so)); *aHandled = PR_TRUE; - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = InsertBRIfNeeded(aSelection); return res; } @@ -2060,7 +2060,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, if (nsTextEditUtils::IsBreak(visNode) && !mHTMLEditor->IsVisBreak(visNode)) { res = mHTMLEditor->DeleteNode(visNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return WillDeleteSelection(aSelection, aAction, aCancel, aHandled); } @@ -2091,12 +2091,12 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, PRBool moveOnly = PR_TRUE; res = nsEditor::GetNodeLocation(visNode, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool interLineIsRight; nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(aSelection)); res = selPriv->GetInterlinePosition(&interLineIsRight); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (startNode == selNode && startOffset -1 == selOffset && @@ -2123,16 +2123,16 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, PRInt32 otherOffset; res = wsObj.NextVisibleNode(startNode, startOffset, address_of(otherNode), &otherOffset, &otherWSType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (otherWSType == nsWSRunObject::eBreak) { // Delete the <br> res = nsWSRunObject::PrepareToDeleteNode(mHTMLEditor, otherNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->DeleteNode(otherNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return NS_OK; @@ -2142,13 +2142,13 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, // found break or image, or hr. res = nsWSRunObject::PrepareToDeleteNode(mHTMLEditor, visNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember sibling to visnode, if any nsCOMPtr<nsIDOMNode> sibling, stepbrother; mHTMLEditor->GetPriorHTMLSibling(visNode, address_of(sibling)); // delete the node, and join like nodes if appropriate res = mHTMLEditor->DeleteNode(visNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // we did something, so lets say so. *aHandled = PR_TRUE; // is there a prior node and are they siblings? @@ -2161,12 +2161,12 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, { // if so, join them! res = JoinNodesSmart(sibling, startNode, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // fix up selection res = aSelection->Collapse(selNode, selOffset); } } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = InsertBRIfNeeded(aSelection); return res; } @@ -2193,21 +2193,21 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, res = wsObj.PriorVisibleNode(startNode, startOffset, address_of(otherNode), &otherOffset, &otherWSType); else res = wsObj.NextVisibleNode(startNode, startOffset, address_of(otherNode), &otherOffset, &otherWSType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // first find the adjacent node in the block nsCOMPtr<nsIDOMNode> leafNode, leftNode, rightNode, leftParent, rightParent; if (aAction == nsIEditor::ePrevious) { res = mHTMLEditor->GetLastEditableLeaf( visNode, address_of(leafNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); leftNode = leafNode; rightNode = startNode; } else { res = mHTMLEditor->GetFirstEditableLeaf( visNode, address_of(leafNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); leftNode = startNode; rightNode = leafNode; } @@ -2215,7 +2215,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, if (nsTextEditUtils::IsBreak(otherNode)) { res = mHTMLEditor->DeleteNode(otherNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *aHandled = PR_TRUE; bDeletedBR = PR_TRUE; } @@ -2234,7 +2234,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> newSelNode; PRInt32 newSelOffset; res = GetGoodSelPointForNode(leafNode, aAction, address_of(newSelNode), &newSelOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aSelection->Collapse(newSelNode, newSelOffset); return res; } @@ -2285,13 +2285,13 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, if (aAction == nsIEditor::ePrevious) { res = mHTMLEditor->GetPriorHTMLNode(visNode, address_of(leftNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); rightNode = startNode; } else { res = mHTMLEditor->GetNextHTMLNode( visNode, address_of(rightNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); leftNode = startNode; } @@ -2340,19 +2340,19 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, // else we have a non collapsed selection // first adjust the selection res = ExpandSelectionForDeletion(aSelection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember that we did a ranged delete for the benefit of AfterEditInner(). mDidRangedDelete = PR_TRUE; // refresh start and end points res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!startNode) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMNode> endNode; PRInt32 endOffset; res = mHTMLEditor->GetEndNodeAndOffset(aSelection, getter_AddRefs(endNode), &endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!endNode) return NS_ERROR_FAILURE; // figure out if the endpoints are in nodes that can be merged @@ -2363,7 +2363,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, res = nsWSRunObject::PrepareToDeleteRange(mHTMLEditor, address_of(startNode), &startOffset, address_of(endNode), &endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } { @@ -2375,7 +2375,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, if (endNode == startNode) { res = mHTMLEditor->DeleteSelectionImpl(aAction); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { @@ -2383,10 +2383,10 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> endCiteNode, startCiteNode; res = GetTopEnclosingMailCite(startNode, address_of(startCiteNode), IsPlaintextEditor()); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = GetTopEnclosingMailCite(endNode, address_of(endCiteNode), IsPlaintextEditor()); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if we only have a mailcite at one of the two endpoints, set the directionality // of the deletion so that the selection will end up outside the mailcite. @@ -2436,10 +2436,10 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, { // first delete the selection res = mHTMLEditor->DeleteSelectionImpl(aAction); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // then join para's, insert break res = mHTMLEditor->JoinNodeDeep(leftParent,rightParent,address_of(selNode),&selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // fix up selection res = aSelection->Collapse(selNode,selOffset); return res; @@ -2449,10 +2449,10 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, { // first delete the selection res = mHTMLEditor->DeleteSelectionImpl(aAction); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // join blocks res = mHTMLEditor->JoinNodeDeep(leftParent,rightParent,address_of(selNode),&selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // fix up selection res = aSelection->Collapse(selNode,selOffset); return res; @@ -2464,7 +2464,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, nsCOMPtr<nsIEnumerator> enumerator; nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(aSelection)); res = selPriv->GetEnumerator(getter_AddRefs(enumerator)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!enumerator) return NS_ERROR_UNEXPECTED; join = PR_TRUE; @@ -2473,7 +2473,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, { nsCOMPtr<nsISupports> currentItem; res = enumerator->CurrentItem(getter_AddRefs(currentItem)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!currentItem) return NS_ERROR_UNEXPECTED; // build a list of nodes in the range @@ -2482,9 +2482,9 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, nsTrivialFunctor functor; nsDOMSubtreeIterator iter; res = iter.Init(range); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = iter.AppendList(functor, arrayOfNodes); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // now that we have the list, delete non table elements PRInt32 listCount = arrayOfNodes.Count(); @@ -2524,7 +2524,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, if (len > (PRUint32)startOffset) { res = mHTMLEditor->DeleteText(nodeAsText,startOffset,len-startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } if ( mHTMLEditor->IsTextNode(endNode) ) @@ -2535,14 +2535,14 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection, if (endOffset) { res = mHTMLEditor->DeleteText(nodeAsText,0,endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } if (join) { res = JoinBlocks(address_of(leftParent), address_of(rightParent), aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -2582,7 +2582,7 @@ nsHTMLEditRules::InsertBRIfNeeded(nsISelection *aSelection) nsCOMPtr<nsIDOMNode> node; PRInt32 offset; nsresult res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!node) return NS_ERROR_FAILURE; // examine selection @@ -2629,13 +2629,13 @@ nsHTMLEditRules::GetGoodSelPointForNode(nsIDOMNode *aNode, nsIEditor::EDirection PRUint32 len; res = mHTMLEditor->GetLengthOfDOMNode(aNode, len); *outSelOffset = PRInt32(len); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } else { res = nsEditor::GetNodeLocation(aNode, outSelNode, outSelOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!nsTextEditUtils::IsBreak(aNode) || mHTMLEditor->IsVisBreak(aNode)) { if (aAction == nsIEditor::ePrevious) @@ -2739,13 +2739,13 @@ nsHTMLEditRules::JoinBlocks(nsCOMPtr<nsIDOMNode> *aLeftBlock, // Do ws adjustment. This just destroys non-visible ws at boundaries we will be joining. rightOffset++; res = nsWSRunObject::ScrubBlockBoundary(mHTMLEditor, aLeftBlock, nsWSRunObject::kBlockEnd); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = nsWSRunObject::ScrubBlockBoundary(mHTMLEditor, aRightBlock, nsWSRunObject::kAfterBlock, &rightOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Do br adjustment. nsCOMPtr<nsIDOMNode> brNode; res = CheckForInvisibleBR(*aLeftBlock, kBlockEnd, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bMergeLists) { // idea here is to take all children in rightList that are past @@ -2779,13 +2779,13 @@ nsHTMLEditRules::JoinBlocks(nsCOMPtr<nsIDOMNode> *aLeftBlock, // tricky case. right block is inside left block. // Do ws adjustment. This just destroys non-visible ws at boundaries we will be joining. res = nsWSRunObject::ScrubBlockBoundary(mHTMLEditor, aRightBlock, nsWSRunObject::kBlockStart); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = nsWSRunObject::ScrubBlockBoundary(mHTMLEditor, aLeftBlock, nsWSRunObject::kBeforeBlock, &leftOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Do br adjustment. nsCOMPtr<nsIDOMNode> brNode; res = CheckForInvisibleBR(*aLeftBlock, kBeforeBlock, address_of(brNode), leftOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bMergeLists) { res = MoveContents(rightList, leftList, &leftOffset); @@ -2805,11 +2805,11 @@ nsHTMLEditRules::JoinBlocks(nsCOMPtr<nsIDOMNode> *aLeftBlock, // adjust whitespace at block boundaries res = nsWSRunObject::PrepareToJoinBlocks(mHTMLEditor, *aLeftBlock, *aRightBlock); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Do br adjustment. nsCOMPtr<nsIDOMNode> brNode; res = CheckForInvisibleBR(*aLeftBlock, kBlockEnd, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bMergeLists || mHTMLEditor->NodesSameType(*aLeftBlock, *aRightBlock)) { // nodes are same type. merge them. @@ -2852,7 +2852,7 @@ nsHTMLEditRules::MoveBlock(nsIDOMNode *aLeftBlock, nsIDOMNode *aRightBlock, PRIn nsCOMPtr<nsISupports> isupports; // GetNodesFromPoint is the workhorse that figures out what we wnat to move. nsresult res = GetNodesFromPoint(DOMPoint(aRightBlock,aRightOffset), kMakeList, arrayOfNodes, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 listCount = arrayOfNodes.Count(); PRInt32 i; for (i=0; i<listCount; i++) @@ -2863,7 +2863,7 @@ nsHTMLEditRules::MoveBlock(nsIDOMNode *aLeftBlock, nsIDOMNode *aRightBlock, PRIn { // For block nodes, move their contents only, then delete block. res = MoveContents(curNode, aLeftBlock, &aLeftOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->DeleteNode(curNode); } else @@ -2891,23 +2891,23 @@ nsHTMLEditRules::MoveNodeSmart(nsIDOMNode *aSource, nsIDOMNode *aDest, PRInt32 * nsAutoString tag; nsresult res; res = mHTMLEditor->GetTagString(aSource, tag); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); ToLowerCase(tag); // check if this node can go into the destination node if (mHTMLEditor->CanContainTag(aDest, tag)) { // if it can, move it there res = mHTMLEditor->MoveNode(aSource, aDest, *aOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (*aOffset != -1) ++(*aOffset); } else { // if it can't, move it's children, and then delete it. res = MoveContents(aSource, aDest, aOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->DeleteNode(aSource); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return NS_OK; } @@ -2934,7 +2934,7 @@ nsHTMLEditRules::MoveContents(nsIDOMNode *aSource, nsIDOMNode *aDest, PRInt32 *a while (child) { res = MoveNodeSmart(child, aDest, aOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aSource->GetFirstChild(getter_AddRefs(child)); } return NS_OK; @@ -2961,7 +2961,7 @@ nsHTMLEditRules::DeleteNonTableElements(nsIDOMNode *aNode) nsCOMPtr<nsIDOMNode> node; children->Item(j,getter_AddRefs(node)); res = DeleteNonTableElements(node); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -2969,7 +2969,7 @@ nsHTMLEditRules::DeleteNonTableElements(nsIDOMNode *aNode) else { res = mHTMLEditor->DeleteNode(aNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return res; } @@ -2985,14 +2985,14 @@ nsHTMLEditRules::DidDeleteSelection(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> startNode; PRInt32 startOffset; nsresult res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!startNode) return NS_ERROR_FAILURE; // find any enclosing mailcite nsCOMPtr<nsIDOMNode> citeNode; res = GetTopEnclosingMailCite(startNode, address_of(citeNode), IsPlaintextEditor()); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (citeNode) { PRBool isEmpty = PR_TRUE, seenBR = PR_FALSE; @@ -3003,11 +3003,11 @@ nsHTMLEditRules::DidDeleteSelection(nsISelection *aSelection, PRInt32 offset; nsEditor::GetNodeLocation(citeNode, address_of(parent), &offset); res = mHTMLEditor->DeleteNode(citeNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (parent && seenBR) { res = mHTMLEditor->CreateBR(parent, offset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aSelection->Collapse(parent, offset); } } @@ -3029,7 +3029,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, if (!aSelection || !aListType || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } nsresult res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() @@ -3053,12 +3053,12 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, *aHandled = PR_TRUE; res = NormalizeSelection(aSelection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); nsCOMArray<nsIDOMNode> arrayOfNodes; res = GetListActionNodes(arrayOfNodes, aEntireList); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 listCount = arrayOfNodes.Count(); @@ -3088,21 +3088,21 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, for (j=0; j<(PRInt32)listCount; j++) { res = mHTMLEditor->DeleteNode(arrayOfNodes[j]); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } // get selection location res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // make sure we can put a list here res = SplitAsNeeded(aListType, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(*aListType, parent, offset, getter_AddRefs(theList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(itemType, theList, 0, getter_AddRefs(theListItem)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = theListItem; // put selection in new list item @@ -3116,7 +3116,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, // then look inside of it until we find inner list or content. res = LookInsideDivBQandList(arrayOfNodes); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Ok, now go through all the nodes and put then in the list, // or whatever is approriate. Wohoo! @@ -3134,7 +3134,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> curNode = arrayOfNodes[i]; PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // make sure we don't assemble content that is in different table cells into the same list. // respect table cell boundaries when listifying. @@ -3142,7 +3142,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, { PRBool bInDifTblElems; res = InDifferentTableElements(curList, curNode, &bInDifTblElems); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bInDifTblElems) curList = nsnull; } @@ -3151,7 +3151,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, if (nsTextEditUtils::IsBreak(curNode)) { res = mHTMLEditor->DeleteNode(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); prevListItem = 0; continue; } @@ -3159,7 +3159,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, else if (IsEmptyInline(curNode)) { res = mHTMLEditor->DeleteNode(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); continue; } @@ -3177,17 +3177,17 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, // ConvertListType first: that routine // handles converting the list item types, if needed res = mHTMLEditor->MoveNode(curNode, curList, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = ConvertListType(curNode, address_of(newBlock), *aListType, itemType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->RemoveBlockContainer(newBlock); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { // replace list with new list type res = ConvertListType(curNode, address_of(newBlock), *aListType, itemType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); curList = newBlock; } prevListItem = 0; @@ -3207,22 +3207,22 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, if (!curList || nsEditorUtils::IsDescendantOf(curNode, curList)) { res = mHTMLEditor->SplitNode(curParent, offset, getter_AddRefs(newBlock)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> p; PRInt32 o; res = nsEditor::GetNodeLocation(curParent, address_of(p), &o); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(*aListType, p, o, getter_AddRefs(curList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // move list item to new list res = mHTMLEditor->MoveNode(curNode, curList, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // convert list item type if needed if (!mHTMLEditor->NodeIsTypeString(curNode,itemType)) { res = mHTMLEditor->ReplaceContainer(curNode, address_of(newBlock), itemType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } else @@ -3237,13 +3237,13 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, { // move list item to new list res = mHTMLEditor->MoveNode(curNode, curList, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } if (!mHTMLEditor->NodeIsTypeString(curNode,itemType)) { res = mHTMLEditor->ReplaceContainer(curNode, address_of(newBlock), itemType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } nsCOMPtr<nsIDOMElement> curElement = do_QueryInterface(curNode); @@ -3254,7 +3254,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, else { res = mHTMLEditor->RemoveAttribute(curElement, typestr); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); continue; } @@ -3265,9 +3265,9 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, prevListItem = nsnull; PRInt32 j=i+1; res = GetInnerContent(curNode, arrayOfNodes, &j); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->RemoveContainer(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); listCount = arrayOfNodes.Count(); continue; } @@ -3276,9 +3276,9 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, if (!curList) { res = SplitAsNeeded(aListType, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(*aListType, curParent, offset, getter_AddRefs(curList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = curList; // curList is now the correct thing to put curNode in @@ -3294,7 +3294,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, // this is a continuation of some inline nodes that belong together in // the same list item. use prevListItem res = mHTMLEditor->MoveNode(curNode, prevListItem, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { @@ -3307,7 +3307,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, { res = mHTMLEditor->InsertContainerAbove(curNode, address_of(listItem), itemType); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (IsInlineNode(curNode)) prevListItem = listItem; else @@ -3323,7 +3323,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection, { // tuck the listItem into the end of the active list res = mHTMLEditor->MoveNode(listItem, curList, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -3343,17 +3343,17 @@ nsHTMLEditRules::WillRemoveList(nsISelection *aSelection, *aHandled = PR_TRUE; nsresult res = NormalizeSelection(aSelection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); nsCOMArray<nsIDOMRange> arrayOfRanges; res = GetPromotedRanges(aSelection, arrayOfRanges, kMakeList); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // use these ranges to contruct a list of nodes to act on. nsCOMArray<nsIDOMNode> arrayOfNodes; res = GetListActionNodes(arrayOfNodes, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Remove all non-editable nodes. Leave them be. PRInt32 listCount = arrayOfNodes.Count(); @@ -3378,7 +3378,7 @@ nsHTMLEditRules::WillRemoveList(nsISelection *aSelection, nsIDOMNode* curNode = arrayOfNodes[i]; PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nsHTMLEditUtils::IsListItem(curNode)) // unlist this listitem { @@ -3386,13 +3386,13 @@ nsHTMLEditRules::WillRemoveList(nsISelection *aSelection, do { res = PopListItem(curNode, &bOutOfList); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } while (!bOutOfList); // keep popping it out until it's not in a list anymore } else if (nsHTMLEditUtils::IsList(curNode)) // node is a list, move list items out { res = RemoveListStructure(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } return res; @@ -3423,12 +3423,12 @@ nsHTMLEditRules::WillMakeBasicBlock(nsISelection *aSelection, *aHandled = PR_FALSE; nsresult res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() *aCancel = PR_FALSE; res = NormalizeSelection(aSelection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor); *aHandled = PR_TRUE; @@ -3437,7 +3437,7 @@ nsHTMLEditRules::WillMakeBasicBlock(nsISelection *aSelection, // contruct a list of nodes to act on. nsCOMArray<nsIDOMNode> arrayOfNodes; res = GetNodesFromSelection(aSelection, kMakeBasicBlock, arrayOfNodes); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Remove all non-editable nodes. Leave them be. PRInt32 listCount = arrayOfNodes.Count(); @@ -3461,7 +3461,7 @@ nsHTMLEditRules::WillMakeBasicBlock(nsISelection *aSelection, // get selection location res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (tString.EqualsLiteral("normal") || tString.IsEmpty() ) // we are removing blocks (going to "body text") { @@ -3477,18 +3477,18 @@ nsHTMLEditRules::WillMakeBasicBlock(nsISelection *aSelection, // it gets pushed into a following block after the split, which is visually bad. nsCOMPtr<nsIDOMNode> brNode; res = mHTMLEditor->GetNextHTMLNode(parent, offset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (brNode && nsTextEditUtils::IsBreak(brNode)) { res = mHTMLEditor->DeleteNode(brNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // do the splits! res = mHTMLEditor->SplitNodeDeep(curBlock, parent, offset, &offset, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // put a br at the split point res = mHTMLEditor->CreateBR(curBlockPar, offset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // put selection at the split point res = aSelection->Collapse(curBlockPar, offset); selectionResetter.Abort(); // to prevent selection reseter from overriding us. @@ -3501,19 +3501,19 @@ nsHTMLEditRules::WillMakeBasicBlock(nsISelection *aSelection, // consume a br, if needed nsCOMPtr<nsIDOMNode> brNode; res = mHTMLEditor->GetNextHTMLNode(parent, offset, address_of(brNode), PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (brNode && nsTextEditUtils::IsBreak(brNode)) { res = mHTMLEditor->DeleteNode(brNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // we don't need to act on this node any more arrayOfNodes.RemoveObject(brNode); } // make sure we can put a block here res = SplitAsNeeded(aBlockType, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(*aBlockType, parent, offset, getter_AddRefs(theBlock)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = theBlock; // delete anything that was in the list of nodes @@ -3521,9 +3521,9 @@ nsHTMLEditRules::WillMakeBasicBlock(nsISelection *aSelection, { nsCOMPtr<nsIDOMNode> curNode = arrayOfNodes[0]; res = mHTMLEditor->DeleteNode(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = arrayOfNodes.RemoveObjectAt(0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // put selection in new block res = aSelection->Collapse(theBlock,0); @@ -3557,13 +3557,13 @@ nsHTMLEditRules::DidMakeBasicBlock(nsISelection *aSelection, // check for empty block. if so, put a moz br in it. PRBool isCollapsed; nsresult res = aSelection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!isCollapsed) return NS_OK; nsCOMPtr<nsIDOMNode> parent; PRInt32 offset; res = nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = InsertMozBRIfNeeded(parent); return res; } @@ -3590,7 +3590,7 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } nsresult res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() @@ -3598,7 +3598,7 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool *aHandled = PR_TRUE; res = NormalizeSelection(aSelection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); nsCOMArray<nsIDOMRange> arrayOfRanges; nsCOMArray<nsIDOMNode> arrayOfNodes; @@ -3609,13 +3609,13 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool PRBool bCollapsed; nsCOMPtr<nsIDOMNode> liNode; res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bCollapsed) { nsCOMPtr<nsIDOMNode> node, block; PRInt32 offset; nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (IsBlockNode(node)) block = node; else @@ -3635,7 +3635,7 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool // block parent, and then further expands to include any ancestors // whose children are all in the range res = GetNodesFromSelection(aSelection, kIndent, arrayOfNodes); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } NS_NAMED_LITERAL_STRING(quoteType, "blockquote"); @@ -3647,12 +3647,12 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool nsAutoString quoteType(NS_LITERAL_STRING("div")); // get selection location res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // make sure we can put a block here res = SplitAsNeeded("eType, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(quoteType, parent, offset, getter_AddRefs(theBlock)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = theBlock; RelativeChangeIndentationOfElementNode(theBlock, +1); @@ -3661,9 +3661,9 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool { nsCOMPtr<nsIDOMNode> curNode = arrayOfNodes[0]; res = mHTMLEditor->DeleteNode(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = arrayOfNodes.RemoveObjectAt(0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // put selection in new block res = aSelection->Collapse(theBlock,0); @@ -3690,7 +3690,7 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // some logic for putting list items into nested lists... if (nsHTMLEditUtils::IsList(curParent)) @@ -3709,7 +3709,7 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool if (curListTag == siblingListTag) { res = mHTMLEditor->MoveNode(curNode, sibling, 0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); continue; } } @@ -3725,7 +3725,7 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool if (curListTag == siblingListTag) { res = mHTMLEditor->MoveNode(curNode, sibling, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); continue; } } @@ -3743,9 +3743,9 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool ToLowerCase(listTag); // create a new nested list of correct type res = SplitAsNeeded(&listTag, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(listTag, curParent, offset, getter_AddRefs(curList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // curList is now the correct thing to put curNode in // remember our new block for postprocessing mNewBlock = curList; @@ -3753,9 +3753,9 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool // tuck the node into the end of the active list PRUint32 listLen; res = mHTMLEditor->GetLengthOfDOMNode(curList, listLen); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->MoveNode(curNode, curList, listLen); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else // not a list item @@ -3769,9 +3769,9 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool { NS_NAMED_LITERAL_STRING(divquoteType, "div"); res = SplitAsNeeded(&divquoteType, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(divquoteType, curParent, offset, getter_AddRefs(curQuote)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); RelativeChangeIndentationOfElementNode(curQuote, +1); // remember our new block for postprocessing mNewBlock = curQuote; @@ -3781,9 +3781,9 @@ nsHTMLEditRules::WillCSSIndent(nsISelection *aSelection, PRBool *aCancel, PRBool // tuck the node into the end of the active blockquote PRUint32 quoteLen; res = mHTMLEditor->GetLengthOfDOMNode(curQuote, quoteLen); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->MoveNode(curNode, curQuote, quoteLen); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -3795,7 +3795,7 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo { if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } nsresult res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() @@ -3803,7 +3803,7 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo *aHandled = PR_TRUE; res = NormalizeSelection(aSelection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); // convert the selection ranges into "promoted" selection ranges: @@ -3813,12 +3813,12 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo nsCOMArray<nsIDOMRange> arrayOfRanges; res = GetPromotedRanges(aSelection, arrayOfRanges, kIndent); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // use these ranges to contruct a list of nodes to act on. nsCOMArray<nsIDOMNode> arrayOfNodes; res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, kIndent); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); NS_NAMED_LITERAL_STRING(quoteType, "blockquote"); @@ -3830,12 +3830,12 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo // get selection location res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // make sure we can put a block here res = SplitAsNeeded("eType, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(quoteType, parent, offset, getter_AddRefs(theBlock)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = theBlock; // delete anything that was in the list of nodes @@ -3843,9 +3843,9 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo { nsCOMPtr<nsIDOMNode> curNode = arrayOfNodes[0]; res = mHTMLEditor->DeleteNode(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = arrayOfNodes.RemoveObjectAt(0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // put selection in new block res = aSelection->Collapse(theBlock,0); @@ -3869,7 +3869,7 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // some logic for putting list items into nested lists... if (nsHTMLEditUtils::IsList(curParent)) @@ -3888,7 +3888,7 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo if (curListTag == siblingListTag) { res = mHTMLEditor->MoveNode(curNode, sibling, 0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); continue; } } @@ -3905,7 +3905,7 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo if (curListTag == siblingListTag) { res = mHTMLEditor->MoveNode(curNode, sibling, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); continue; } } @@ -3924,16 +3924,16 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo ToLowerCase(listTag); // create a new nested list of correct type res = SplitAsNeeded(&listTag, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(listTag, curParent, offset, getter_AddRefs(curList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // curList is now the correct thing to put curNode in // remember our new block for postprocessing mNewBlock = curList; } // tuck the node into the end of the active list res = mHTMLEditor->MoveNode(curNode, curList, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // forget curQuote, if any curQuote = nsnull; } @@ -3951,7 +3951,7 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo { if (indentedLI == listitem) continue; // already indented this list item res = nsEditor::GetNodeLocation(listitem, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // check to see if curList is still appropriate. Which it is if // curNode is still right after it in the same list. if (curList) @@ -3967,12 +3967,12 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo ToLowerCase(listTag); // create a new nested list of correct type res = SplitAsNeeded(&listTag, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(listTag, curParent, offset, getter_AddRefs(curList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } res = mHTMLEditor->MoveNode(listitem, curList, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember we indented this li indentedLI = listitem; } @@ -3987,7 +3987,7 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo { PRBool bInDifTblElems; res = InDifferentTableElements(curQuote, curNode, &bInDifTblElems); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bInDifTblElems) curQuote = nsnull; } @@ -3995,9 +3995,9 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo if (!curQuote) { res = SplitAsNeeded("eType, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(quoteType, curParent, offset, getter_AddRefs(curQuote)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = curQuote; // curQuote is now the correct thing to put curNode in @@ -4005,7 +4005,7 @@ nsHTMLEditRules::WillHTMLIndent(nsISelection *aSelection, PRBool *aCancel, PRBoo // tuck the node into the end of the active blockquote res = mHTMLEditor->MoveNode(curNode, curQuote, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // forget curList, if any curList = nsnull; } @@ -4028,7 +4028,7 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, PRBool *aCancel, PRBool * mHTMLEditor->GetIsCSSEnabled(&useCSS); res = NormalizeSelection(aSelection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // some scoping for selection resetting - we may need to tweak it { nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); @@ -4039,7 +4039,7 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, PRBool *aCancel, PRBool * // whose children are all in the range nsCOMArray<nsIDOMNode> arrayOfNodes; res = GetNodesFromSelection(aSelection, kOutdent, arrayOfNodes); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Ok, now go through all the nodes and remove a level of blockquoting, // or whatever is appropriate. Wohoo! @@ -4055,7 +4055,7 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, PRBool *aCancel, PRBool * nsCOMPtr<nsIDOMNode> curNode = arrayOfNodes[i]; PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // is it a blockquote? if (nsHTMLEditUtils::IsBlockquote(curNode)) @@ -4068,12 +4068,12 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, PRBool *aCancel, PRBool * curBlockQuoteIsIndentedWithCSS, address_of(rememberedLeftBQ), address_of(rememberedRightBQ)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); curBlockQuote = 0; firstBQChild = 0; lastBQChild = 0; curBlockQuoteIsIndentedWithCSS = PR_FALSE; } res = mHTMLEditor->RemoveBlockContainer(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); continue; } // is it a list item? @@ -4088,13 +4088,13 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, PRBool *aCancel, PRBool * curBlockQuoteIsIndentedWithCSS, address_of(rememberedLeftBQ), address_of(rememberedRightBQ)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); curBlockQuote = 0; firstBQChild = 0; lastBQChild = 0; curBlockQuoteIsIndentedWithCSS = PR_FALSE; } PRBool bOutOfList; res = PopListItem(curNode, &bOutOfList); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); continue; } // do we have a blockquote that we are already committed to removing? @@ -4115,7 +4115,7 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, PRBool *aCancel, PRBool * curBlockQuoteIsIndentedWithCSS, address_of(rememberedLeftBQ), address_of(rememberedRightBQ)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); curBlockQuote = 0; firstBQChild = 0; lastBQChild = 0; curBlockQuoteIsIndentedWithCSS = PR_FALSE; // fall out and handle curNode @@ -4171,7 +4171,7 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, PRBool *aCancel, PRBool * if (nsHTMLEditUtils::IsList(curNode)) // just unwrap this sublist { res = mHTMLEditor->RemoveBlockContainer(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // handled list item case above } @@ -4185,7 +4185,7 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, PRBool *aCancel, PRBool * { PRBool bOutOfList; res = PopListItem(child, &bOutOfList); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else if (nsHTMLEditUtils::IsList(child)) { @@ -4195,19 +4195,19 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, PRBool *aCancel, PRBool * // list of children. res = mHTMLEditor->MoveNode(child, curParent, offset + 1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { // delete any non- list items for now res = mHTMLEditor->DeleteNode(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } curNode->GetLastChild(getter_AddRefs(child)); } // delete the now-empty list res = mHTMLEditor->RemoveBlockContainer(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else if (useCSS) { nsCOMPtr<nsIDOMElement> element; @@ -4233,7 +4233,7 @@ nsHTMLEditRules::WillOutdent(nsISelection *aSelection, PRBool *aCancel, PRBool * curBlockQuoteIsIndentedWithCSS, address_of(rememberedLeftBQ), address_of(rememberedRightBQ)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } // make sure selection didn't stick to last piece of content in old bq @@ -4288,7 +4288,7 @@ nsHTMLEditRules::RemovePartOfBlock(nsIDOMNode *aBlock, nsresult res = SplitBlock(aBlock, aStartChild, aEndChild, aLeftNode, aRightNode, address_of(middleNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // get rid of part of blockquote we are outdenting return mHTMLEditor->RemoveBlockContainer(aBlock); @@ -4311,12 +4311,12 @@ nsHTMLEditRules::SplitBlock(nsIDOMNode *aBlock, // get split point location res = nsEditor::GetNodeLocation(aStartChild, address_of(startParent), &startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // do the splits! res = mHTMLEditor->SplitNodeDeep(aBlock, startParent, startOffset, &offset, PR_TRUE, address_of(leftNode), address_of(rightNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (rightNode) aBlock = rightNode; // remember left portion of block if caller requested @@ -4325,13 +4325,13 @@ nsHTMLEditRules::SplitBlock(nsIDOMNode *aBlock, // get split point location res = nsEditor::GetNodeLocation(aEndChild, address_of(endParent), &endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); endOffset++; // want to be after lastBQChild // do the splits! res = mHTMLEditor->SplitNodeDeep(aBlock, endParent, endOffset, &offset, PR_TRUE, address_of(leftNode), address_of(rightNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (leftNode) aBlock = leftNode; // remember right portion of block if caller requested @@ -4357,7 +4357,7 @@ nsHTMLEditRules::OutdentPartOfBlock(nsIDOMNode *aBlock, aLeftNode, aRightNode, address_of(middleNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (aIsBlockIndentedWithCSS) res = RelativeChangeIndentationOfElementNode(middleNode, -1); else @@ -4385,13 +4385,13 @@ nsHTMLEditRules::ConvertListType(nsIDOMNode *aList, if (nsHTMLEditUtils::IsListItem(child) && !nsEditor::NodeIsTypeString(child, aItemType)) { res = mHTMLEditor->ReplaceContainer(child, address_of(temp), aItemType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); child = temp; } else if (nsHTMLEditUtils::IsList(child) && !nsEditor::NodeIsTypeString(child, aListType)) { res = ConvertListType(child, address_of(temp), aListType, aItemType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); child = temp; } child->GetNextSibling(getter_AddRefs(temp)); @@ -4632,7 +4632,7 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } nsresult res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() @@ -4640,7 +4640,7 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, *aHandled = PR_FALSE; res = NormalizeSelection(aSelection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); // convert the selection ranges into "promoted" selection ranges: @@ -4650,7 +4650,7 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, *aHandled = PR_TRUE; nsCOMArray<nsIDOMNode> arrayOfNodes; res = GetNodesFromSelection(aSelection, kAlign, arrayOfNodes); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if we don't have any nodes, or we have only a single br, then we are // creating an empty alignment div. We have to do some different things for these. @@ -4669,7 +4669,7 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, // all the work is done in AlignBlock nsCOMPtr<nsIDOMElement> theElem = do_QueryInterface(theNode); res = AlignBlock(theElem, alignType, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return NS_OK; } @@ -4702,38 +4702,38 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> brNode, parent, theDiv, sib; NS_NAMED_LITERAL_STRING(divType, "div"); res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = SplitAsNeeded(&divType, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // consume a trailing br, if any. This is to keep an alignment from // creating extra lines, if possible. res = mHTMLEditor->GetNextHTMLNode(parent, offset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (brNode && nsTextEditUtils::IsBreak(brNode)) { // making use of html structure... if next node after where // we are putting our div is not a block, then the br we // found is in same block we are, so its safe to consume it. res = mHTMLEditor->GetNextHTMLSibling(parent, offset, address_of(sib)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!IsBlockNode(sib)) { res = mHTMLEditor->DeleteNode(brNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } res = mHTMLEditor->CreateNode(divType, parent, offset, getter_AddRefs(theDiv)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = theDiv; // set up the alignment on the div, using HTML or CSS nsCOMPtr<nsIDOMElement> divElem = do_QueryInterface(theDiv); res = AlignBlock(divElem, alignType, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *aHandled = PR_TRUE; // put in a moz-br so that it won't get deleted res = CreateMozBR(theDiv, 0, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = aSelection->Collapse(theDiv, 0); selectionResetter.Abort(); // don't reset our selection in this case. return res; @@ -4744,7 +4744,7 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, nsTArray<PRPackedBool> transitionList; res = MakeTransitionList(arrayOfNodes, transitionList); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Ok, now go through all the nodes and give them an align attrib or put them in a div, // or whatever is appropriate. Wohoo! @@ -4760,7 +4760,7 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> curNode = arrayOfNodes[i]; PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // the node is a table element, an horiz rule, a paragraph, a div // or a section header; in HTML 4, it can directly carry the ALIGN @@ -4770,7 +4770,7 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, { nsCOMPtr<nsIDOMElement> curElem = do_QueryInterface(curNode); res = AlignBlock(curElem, alignType, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // clear out curDiv so that we don't put nodes after this one into it curDiv = 0; continue; @@ -4790,7 +4790,7 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, || nsHTMLEditUtils::IsList(curNode)) { res = RemoveAlignment(curNode, *alignType, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (useCSS) { nsCOMPtr<nsIDOMElement> curElem = do_QueryInterface(curNode); NS_NAMED_LITERAL_STRING(attrName, "align"); @@ -4805,7 +4805,7 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, // if we don't use CSS, add a contraint to list element : they have // to be inside another list, ie >= second level of nesting res = AlignInnerBlocks(curNode, alignType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); curDiv = 0; continue; } @@ -4818,9 +4818,9 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, { NS_NAMED_LITERAL_STRING(divType, "div"); res = SplitAsNeeded(&divType, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(divType, curParent, offset, getter_AddRefs(curDiv)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = curDiv; // set up the alignment on the div @@ -4828,13 +4828,13 @@ nsHTMLEditRules::WillAlign(nsISelection *aSelection, res = AlignBlock(divElem, alignType, PR_TRUE); // nsAutoString attr(NS_LITERAL_STRING("align")); // res = mHTMLEditor->SetAttribute(divElem, attr, *alignType); -// if (NS_FAILED(res)) return res; +// NS_ENSURE_SUCCESS(res, res); // curDiv is now the correct thing to put curNode in } // tuck the node into the end of the active div res = mHTMLEditor->MoveNode(curNode, curDiv, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return res; @@ -4855,9 +4855,9 @@ nsHTMLEditRules::AlignInnerBlocks(nsIDOMNode *aNode, const nsAString *alignType) nsTableCellAndListItemFunctor functor; nsDOMIterator iter; res = iter.Init(aNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = iter.AppendList(functor, arrayOfNodes); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // now that we have the list, align their contents as requested PRInt32 listCount = arrayOfNodes.Count(); @@ -4867,7 +4867,7 @@ nsHTMLEditRules::AlignInnerBlocks(nsIDOMNode *aNode, const nsAString *alignType) { nsIDOMNode* node = arrayOfNodes[0]; res = AlignBlockContents(node, alignType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); arrayOfNodes.RemoveObjectAt(0); } @@ -4889,9 +4889,9 @@ nsHTMLEditRules::AlignBlockContents(nsIDOMNode *aNode, const nsAString *alignTyp mHTMLEditor->GetIsCSSEnabled(&useCSS); res = mHTMLEditor->GetFirstEditableChild(aNode, address_of(firstChild)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->GetLastEditableChild(aNode, address_of(lastChild)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); NS_NAMED_LITERAL_STRING(attr, "align"); if (!firstChild) { @@ -4908,13 +4908,13 @@ nsHTMLEditRules::AlignBlockContents(nsIDOMNode *aNode, const nsAString *alignTyp else { res = mHTMLEditor->SetAttribute(divElem, attr, *alignType); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { // else we need to put in a div, set the alignment, and toss in all the children res = mHTMLEditor->CreateNode(NS_LITERAL_STRING("div"), aNode, 0, getter_AddRefs(divNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // set up the alignment on the div nsCOMPtr<nsIDOMElement> divElem = do_QueryInterface(divNode); if (useCSS) { @@ -4923,14 +4923,14 @@ nsHTMLEditRules::AlignBlockContents(nsIDOMNode *aNode, const nsAString *alignTyp else { res = mHTMLEditor->SetAttribute(divElem, attr, *alignType); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // tuck the children into the end of the active div while (lastChild && (lastChild != divNode)) { res = mHTMLEditor->MoveNode(lastChild, divNode, 0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->GetLastEditableChild(aNode, address_of(lastChild)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } return res; @@ -4958,13 +4958,13 @@ nsHTMLEditRules::CheckForEmptyBlock(nsIDOMNode *aStartNode, if (block != aBodyNode) // efficiency hack. avoiding IsEmptyNode() call when in body { res = mHTMLEditor->IsEmptyNode(block, &bIsEmptyNode, PR_TRUE, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); while (bIsEmptyNode && !nsHTMLEditUtils::IsTableElement(block) && (block != aBodyNode)) { emptyBlock = block; block = mHTMLEditor->GetBlockNodeParent(emptyBlock); res = mHTMLEditor->IsEmptyNode(block, &bIsEmptyNode, PR_TRUE, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -4973,7 +4973,7 @@ nsHTMLEditRules::CheckForEmptyBlock(nsIDOMNode *aStartNode, nsCOMPtr<nsIDOMNode> blockParent; PRInt32 offset; res = nsEditor::GetNodeLocation(emptyBlock, address_of(blockParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!blockParent || offset < 0) return NS_ERROR_FAILURE; if (nsHTMLEditUtils::IsListItem(emptyBlock)) @@ -4981,13 +4981,13 @@ nsHTMLEditRules::CheckForEmptyBlock(nsIDOMNode *aStartNode, // are we the first list item in the list? PRBool bIsFirst; res = mHTMLEditor->IsFirstEditableChild(emptyBlock, &bIsFirst); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bIsFirst) { nsCOMPtr<nsIDOMNode> listParent; PRInt32 listOffset; res = nsEditor::GetNodeLocation(blockParent, address_of(listParent), &listOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!listParent || listOffset < 0) return NS_ERROR_FAILURE; // if we are a sublist, skip the br creation if (!nsHTMLEditUtils::IsList(listParent)) @@ -4995,10 +4995,10 @@ nsHTMLEditRules::CheckForEmptyBlock(nsIDOMNode *aStartNode, // create a br before list nsCOMPtr<nsIDOMNode> brNode; res = mHTMLEditor->CreateBR(listParent, listOffset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // adjust selection to be right before it res = aSelection->Collapse(listParent, listOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // else just let selection perculate up. We'll adjust it in AfterEdit() } @@ -5007,7 +5007,7 @@ nsHTMLEditRules::CheckForEmptyBlock(nsIDOMNode *aStartNode, { // adjust selection to be right after it res = aSelection->Collapse(blockParent, offset+1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } res = mHTMLEditor->DeleteNode(emptyBlock); *aHandled = PR_TRUE; @@ -5094,7 +5094,7 @@ nsHTMLEditRules::GetInnerContent(nsIDOMNode *aNode, nsCOMArray<nsIDOMNode> &outA || ( aTbl && nsHTMLEditUtils::IsTableElement(node) ) ) { res = GetInnerContent(node, outArrayOfNodes, aIndex, aList, aTbl); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { @@ -5122,12 +5122,12 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection) // don't need to touch collapsed selections PRBool bCollapsed; nsresult res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bCollapsed) return res; PRInt32 rangeCount; res = aSelection->GetRangeCount(&rangeCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // we don't need to mess with cell selections, and we assume multirange selections are those. if (rangeCount != 1) return NS_OK; @@ -5135,23 +5135,23 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection) // find current sel start and end nsCOMPtr<nsIDOMRange> range; res = aSelection->GetRangeAt(0, getter_AddRefs(range)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!range) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode> selStartNode, selEndNode, selCommon; PRInt32 selStartOffset, selEndOffset; res = range->GetStartContainer(getter_AddRefs(selStartNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetStartOffset(&selStartOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndContainer(getter_AddRefs(selEndNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndOffset(&selEndOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // find current selection common block parent res = range->GetCommonAncestorContainer(getter_AddRefs(selCommon)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!IsBlockNode(selCommon)) selCommon = nsHTMLEditor::GetBlockNodeParent(selCommon); @@ -5171,7 +5171,7 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection) { nsWSRunObject wsObj(mHTMLEditor, selStartNode, selStartOffset); res = wsObj.PriorVisibleNode(selStartNode, selStartOffset, address_of(visNode), &visOffset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (wsType == nsWSRunObject::eThisBlock) { // we want to keep looking up. But stop if we are crossing table element @@ -5202,7 +5202,7 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection) { nsWSRunObject wsObj(mHTMLEditor, selEndNode, selEndOffset); res = wsObj.NextVisibleNode(selEndNode, selEndOffset, address_of(visNode), &visOffset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (wsType == nsWSRunObject::eBreak) { if (mHTMLEditor->IsVisBreak(wsObj.mEndReasonNode)) @@ -5261,9 +5261,9 @@ nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection) nsCOMPtr<nsIDOMRange> range = do_CreateInstance("@mozilla.org/content/range;1"); if (!range) return NS_ERROR_NULL_POINTER; res = range->SetStart(selStartNode, selStartOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->SetEnd(selEndNode, selEndOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // check if block is entirely inside range nsCOMPtr<nsIContent> brContentBlock = do_QueryInterface(brBlock); @@ -5298,7 +5298,7 @@ nsHTMLEditRules::AtStartOfBlock(nsIDOMNode *aNode, PRInt32 aOffset, nsIDOMNode * nsCOMPtr<nsIDOMNode> priorNode; nsresult res = mHTMLEditor->GetPriorHTMLNode(aNode, aOffset, address_of(priorNode)); - if (NS_FAILED(res)) return PR_TRUE; + NS_ENSURE_SUCCESS(res, PR_TRUE); if (!priorNode) return PR_TRUE; nsCOMPtr<nsIDOMNode> blockParent = mHTMLEditor->GetBlockNodeParent(priorNode); if (blockParent && (blockParent == aBlock)) return PR_FALSE; @@ -5321,7 +5321,7 @@ nsHTMLEditRules::AtEndOfBlock(nsIDOMNode *aNode, PRInt32 aOffset, nsIDOMNode *aB } nsCOMPtr<nsIDOMNode> nextNode; nsresult res = mHTMLEditor->GetNextHTMLNode(aNode, aOffset, address_of(nextNode)); - if (NS_FAILED(res)) return PR_TRUE; + NS_ENSURE_SUCCESS(res, PR_TRUE); if (!nextNode) return PR_TRUE; nsCOMPtr<nsIDOMNode> blockParent = mHTMLEditor->GetBlockNodeParent(nextNode); if (blockParent && (blockParent == aBlock)) return PR_FALSE; @@ -5339,11 +5339,11 @@ nsHTMLEditRules::CreateMozDiv(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<n nsAutoString divType= "div"; *outDiv = nsnull; nsresult res = mHTMLEditor->CreateNode(divType, inParent, inOffset, getter_AddRefs(*outDiv)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // give it special moz attr nsCOMPtr<nsIDOMElement> mozDivElem = do_QueryInterface(*outDiv); res = mHTMLEditor->SetAttribute(mozDivElem, "type", "_moz"); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = AddTrailerBR(*outDiv); return res; } @@ -5365,19 +5365,19 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection) // don't need to touch collapsed selections PRBool bCollapsed; nsresult res = inSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bCollapsed) return res; PRInt32 rangeCount; res = inSelection->GetRangeCount(&rangeCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // we don't need to mess with cell selections, and we assume multirange selections are those. if (rangeCount != 1) return NS_OK; nsCOMPtr<nsIDOMRange> range; res = inSelection->GetRangeAt(0, getter_AddRefs(range)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!range) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode> startNode, endNode; PRInt32 startOffset, endOffset; @@ -5385,13 +5385,13 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection) PRInt32 newStartOffset, newEndOffset; res = range->GetStartContainer(getter_AddRefs(startNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetStartOffset(&startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndContainer(getter_AddRefs(endNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndOffset(&endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // adjusted values default to original values newStartNode = startNode; @@ -5409,7 +5409,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection) // is there any intervening visible whitespace? if so we can't push selection past that, // it would visibly change maening of users selection res = wsEndObj.PriorVisibleNode(endNode, endOffset, address_of(someNode), &offset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ((wsType != nsWSRunObject::eText) && (wsType != nsWSRunObject::eNormalWS)) { // eThisBlock and eOtherBlock conveniently distinquish cases @@ -5421,7 +5421,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection) if (child) { res = nsEditor::GetNodeLocation(child, address_of(newEndNode), &newEndOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); ++newEndOffset; // offset *after* child } // else block is empty - we can leave selection alone here, i think. @@ -5434,7 +5434,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection) if (child) { res = nsEditor::GetNodeLocation(child, address_of(newEndNode), &newEndOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); ++newEndOffset; // offset *after* child } // else block is empty - we can leave selection alone here, i think. @@ -5443,7 +5443,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection) { // endpoint is just after break. lets adjust it to before it. res = nsEditor::GetNodeLocation(wsEndObj.mStartReasonNode, address_of(newEndNode), &newEndOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -5453,7 +5453,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection) // is there any intervening visible whitespace? if so we can't push selection past that, // it would visibly change maening of users selection res = wsStartObj.NextVisibleNode(startNode, startOffset, address_of(someNode), &offset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ((wsType != nsWSRunObject::eText) && (wsType != nsWSRunObject::eNormalWS)) { // eThisBlock and eOtherBlock conveniently distinquish cases @@ -5465,7 +5465,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection) if (child) { res = nsEditor::GetNodeLocation(child, address_of(newStartNode), &newStartOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // else block is empty - we can leave selection alone here, i think. } @@ -5477,7 +5477,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection) if (child) { res = nsEditor::GetNodeLocation(child, address_of(newStartNode), &newStartOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // else block is empty - we can leave selection alone here, i think. } @@ -5485,7 +5485,7 @@ nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection) { // startpoint is just before a break. lets adjust it to after it. res = nsEditor::GetNodeLocation(wsStartObj.mEndReasonNode, address_of(newStartNode), &newStartOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); ++newStartOffset; // offset *after* break } } @@ -5540,7 +5540,7 @@ nsHTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt do { res = mHTMLEditor->IsPrevCharWhitespace(node, offset, &isSpace, &isNBSP, address_of(temp), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isSpace || isNBSP) node = temp; else break; } while (node); @@ -5553,7 +5553,7 @@ nsHTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt do { res = mHTMLEditor->IsNextCharWhitespace(node, offset, &isSpace, &isNBSP, address_of(temp), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isSpace || isNBSP) node = temp; else break; } while (node); @@ -5572,7 +5572,7 @@ nsHTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt if (nsEditor::IsTextNode(aNode)) { res = nsEditor::GetNodeLocation(aNode, address_of(node), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // look back through any further inline nodes that @@ -5587,16 +5587,16 @@ nsHTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt if (IsBlockNode(priorNode)) break; res = nsEditor::GetNodeLocation(priorNode, address_of(node), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->GetPriorHTMLNode(node, offset, address_of(priorNode), PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // finding the real start for this point. look up the tree for as long as we are the // first node in the container, and as long as we haven't hit the body node. res = mHTMLEditor->GetPriorHTMLNode(node, offset, address_of(nearNode), PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); while (!nearNode && !nsTextEditUtils::IsBody(node)) { // some cutoffs are here: we don't need to also include them in the aWhere == kEnd case. @@ -5607,11 +5607,11 @@ nsHTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt break; res = nsEditor::GetNodeLocation(node, address_of(parent), &pOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); node = parent; offset = pOffset; res = mHTMLEditor->GetPriorHTMLNode(node, offset, address_of(nearNode), PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } *outNode = node; *outOffset = offset; @@ -5624,7 +5624,7 @@ nsHTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt if (nsEditor::IsTextNode(aNode)) { res = nsEditor::GetNodeLocation(aNode, address_of(node), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); offset++; // want to be after the text node } @@ -5638,26 +5638,26 @@ nsHTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode *aNode, PRInt if (IsBlockNode(nextNode)) break; res = nsEditor::GetNodeLocation(nextNode, address_of(node), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); offset++; if (mHTMLEditor->IsVisBreak(nextNode)) break; res = mHTMLEditor->GetNextHTMLNode(node, offset, address_of(nextNode), PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // finding the real end for this point. look up the tree for as long as we are the // last node in the container, and as long as we haven't hit the body node. res = mHTMLEditor->GetNextHTMLNode(node, offset, address_of(nearNode), PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); while (!nearNode && !nsTextEditUtils::IsBody(node)) { res = nsEditor::GetNodeLocation(node, address_of(parent), &pOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); node = parent; offset = pOffset+1; // we want to be AFTER nearNode res = mHTMLEditor->GetNextHTMLNode(node, offset, address_of(nearNode), PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } *outNode = node; *outOffset = offset; @@ -5681,7 +5681,7 @@ nsHTMLEditRules::GetPromotedRanges(nsISelection *inSelection, PRInt32 rangeCount; nsresult res = inSelection->GetRangeCount(&rangeCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 i; nsCOMPtr<nsIDOMRange> selectionRange; @@ -5690,18 +5690,18 @@ nsHTMLEditRules::GetPromotedRanges(nsISelection *inSelection, for (i = 0; i < rangeCount; i++) { res = inSelection->GetRangeAt(i, getter_AddRefs(selectionRange)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // clone range so we don't muck with actual selection ranges res = selectionRange->CloneRange(getter_AddRefs(opRange)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // make a new adjusted range to represent the appropriate block content. // The basic idea is to push out the range endpoints // to truly enclose the blocks that we will affect. // This call alters opRange. res = PromoteRange(opRange, inOperationType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // stuff new opRange into array outArrayOfRanges.AppendObject(opRange); @@ -5724,13 +5724,13 @@ nsHTMLEditRules::PromoteRange(nsIDOMRange *inRange, PRInt32 startOffset, endOffset; res = inRange->GetStartContainer(getter_AddRefs(startNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetStartOffset(&startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetEndContainer(getter_AddRefs(endNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetEndOffset(&endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // MOOSE major hack: // GetPromotedPoint doesn't really do the right thing for collapsed ranges @@ -5777,11 +5777,11 @@ nsHTMLEditRules::PromoteRange(nsIDOMRange *inRange, nsCOMPtr<nsIDOMRange> opRange; res = GetPromotedPoint( kStart, startNode, startOffset, inOperationType, address_of(opStartNode), &opStartOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = GetPromotedPoint( kEnd, endNode, endOffset, inOperationType, address_of(opEndNode), &opEndOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->SetStart(opStartNode, opStartOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->SetEnd(opEndNode, opEndOffset); return res; } @@ -5861,7 +5861,7 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges, } inArrayOfRanges.AppendObject(opRange); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // gather up a list of all the nodes for (i = 0; i < rangeCount; i++) @@ -5870,11 +5870,11 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges, nsDOMSubtreeIterator iter; res = iter.Init(opRange); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (outArrayOfNodes.Count() == 0) { nsTrivialFunctor functor; res = iter.AppendList(functor, outArrayOfNodes); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { // We don't want duplicates in outArrayOfNodes, so we use an @@ -5883,7 +5883,7 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges, nsCOMArray<nsIDOMNode> nodes; nsUniqueFunctor functor(outArrayOfNodes); res = iter.AppendList(functor, nodes); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!outArrayOfNodes.AppendObjects(nodes)) return NS_ERROR_OUT_OF_MEMORY; } @@ -5902,7 +5902,7 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges, PRInt32 j=i; outArrayOfNodes.RemoveObjectAt(i); res = GetInnerContent(node, outArrayOfNodes, &j); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -5921,7 +5921,7 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges, PRInt32 j=i; outArrayOfNodes.RemoveObjectAt(i); res = GetInnerContent(node, outArrayOfNodes, &j); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -5937,7 +5937,7 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges, PRInt32 j=i; outArrayOfNodes.RemoveObjectAt(i); res = GetInnerContent(node, outArrayOfNodes, &j, PR_FALSE, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -5961,7 +5961,7 @@ nsHTMLEditRules::GetNodesForOperation(nsCOMArray<nsIDOMRange>& inArrayOfRanges, { nsCOMArray<nsIDOMNode> arrayOfInlines; res = BustUpInlinesAtBRs(node, arrayOfInlines); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // put these nodes in outArrayOfNodes, replacing the current node outArrayOfNodes.RemoveObjectAt(i); outArrayOfNodes.InsertObjectsAt(arrayOfInlines, i); @@ -5984,11 +5984,11 @@ nsHTMLEditRules::GetChildNodesForOperation(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNodeList> childNodes; nsresult res = inNode->GetChildNodes(getter_AddRefs(childNodes)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!childNodes) return NS_ERROR_NULL_POINTER; PRUint32 childCount; res = childNodes->GetLength(&childCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRUint32 i; nsCOMPtr<nsIDOMNode> node; @@ -6016,7 +6016,7 @@ nsHTMLEditRules::GetListActionNodes(nsCOMArray<nsIDOMNode> &outArrayOfNodes, nsCOMPtr<nsISelection>selection; res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); if (!selPriv) return NS_ERROR_FAILURE; @@ -6026,14 +6026,14 @@ nsHTMLEditRules::GetListActionNodes(nsCOMArray<nsIDOMNode> &outArrayOfNodes, { nsCOMPtr<nsIEnumerator> enumerator; res = selPriv->GetEnumerator(getter_AddRefs(enumerator)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!enumerator) return NS_ERROR_UNEXPECTED; for (enumerator->First(); NS_OK!=enumerator->IsDone(); enumerator->Next()) { nsCOMPtr<nsISupports> currentItem; res = enumerator->CurrentItem(getter_AddRefs(currentItem)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!currentItem) return NS_ERROR_UNEXPECTED; nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) ); @@ -6061,7 +6061,7 @@ nsHTMLEditRules::GetListActionNodes(nsCOMArray<nsIDOMNode> &outArrayOfNodes, // contruct a list of nodes to act on. res = GetNodesFromSelection(selection, kMakeList, outArrayOfNodes, aDontTouchContent); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // pre process our list of nodes... PRInt32 listCount = outArrayOfNodes.Count(); @@ -6083,7 +6083,7 @@ nsHTMLEditRules::GetListActionNodes(nsCOMArray<nsIDOMNode> &outArrayOfNodes, PRInt32 j=i; outArrayOfNodes.RemoveObjectAt(i); res = GetInnerContent(testNode, outArrayOfNodes, &j, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -6115,7 +6115,7 @@ nsHTMLEditRules::LookInsideDivBQandList(nsCOMArray<nsIDOMNode>& aNodeArray) // dive as long as there is only one child, and it is a list, div, blockquote PRUint32 numChildren; res = mHTMLEditor->CountEditableChildren(curNode, numChildren); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (numChildren == 1) { @@ -6179,11 +6179,11 @@ nsHTMLEditRules::GetParagraphFormatNodes(nsCOMArray<nsIDOMNode>& outArrayOfNodes { nsCOMPtr<nsISelection>selection; nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // contruct a list of nodes to act on. res = GetNodesFromSelection(selection, kMakeBasicBlock, outArrayOfNodes, aDontTouchContent); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // pre process our list of nodes... PRInt32 listCount = outArrayOfNodes.Count(); @@ -6207,7 +6207,7 @@ nsHTMLEditRules::GetParagraphFormatNodes(nsCOMArray<nsIDOMNode>& outArrayOfNodes PRInt32 j=i; outArrayOfNodes.RemoveObjectAt(i); res = GetInnerContent(testNode, outArrayOfNodes, &j); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } return res; @@ -6233,7 +6233,7 @@ nsHTMLEditRules::BustUpInlinesAtRangeEndpoints(nsRangeStore &item) endInline->GetParentNode(getter_AddRefs(resultEndNode)); res = mHTMLEditor->SplitNodeDeep(endInline, item.endNode, item.endOffset, &resultEndOffset, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // reset range item.endNode = resultEndNode; item.endOffset = resultEndOffset; } @@ -6247,7 +6247,7 @@ nsHTMLEditRules::BustUpInlinesAtRangeEndpoints(nsRangeStore &item) startInline->GetParentNode(getter_AddRefs(resultStartNode)); res = mHTMLEditor->SplitNodeDeep(startInline, item.startNode, item.startOffset, &resultStartOffset, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // reset range item.startNode = resultStartNode; item.startOffset = resultStartOffset; } @@ -6272,9 +6272,9 @@ nsHTMLEditRules::BustUpInlinesAtBRs(nsIDOMNode *inNode, nsBRNodeFunctor functor; nsDOMIterator iter; nsresult res = iter.Init(inNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = iter.AppendList(functor, arrayOfBreaks); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if there aren't any breaks, just put inNode itself in the array PRInt32 listCount = arrayOfBreaks.Count(); @@ -6301,10 +6301,10 @@ nsHTMLEditRules::BustUpInlinesAtBRs(nsIDOMNode *inNode, if (!breakNode) return NS_ERROR_NULL_POINTER; if (!splitDeepNode) return NS_ERROR_NULL_POINTER; res = nsEditor::GetNodeLocation(breakNode, address_of(splitParentNode), &splitOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->SplitNodeDeep(splitDeepNode, splitParentNode, splitOffset, &resultOffset, PR_FALSE, address_of(leftNode), address_of(rightNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // put left node in node list if (leftNode) { @@ -6316,7 +6316,7 @@ nsHTMLEditRules::BustUpInlinesAtBRs(nsIDOMNode *inNode, } // move break outside of container and also put in node list res = mHTMLEditor->MoveNode(breakNode, inlineParentNode, resultOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!outArrayOfNodes.AppendObject(breakNode)) return NS_ERROR_FAILURE; // now rightNode becomes the new node to split @@ -6369,14 +6369,14 @@ nsHTMLEditRules::GetNodesFromPoint(DOMPoint point, // use it to make a range nsCOMPtr<nsIDOMRange> range = do_CreateInstance("@mozilla.org/content/range;1"); res = range->SetStart(node, offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); /* SetStart() will also set the end for this new range res = range->SetEnd(node, offset); - if (NS_FAILED(res)) return res; */ + NS_ENSURE_SUCCESS(res, res); */ // expand the range to include adjacent inlines res = PromoteRange(range, operation); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // make array of ranges nsCOMArray<nsIDOMRange> arrayOfRanges; @@ -6406,7 +6406,7 @@ nsHTMLEditRules::GetNodesFromSelection(nsISelection *selection, // promote selection ranges nsCOMArray<nsIDOMRange> arrayOfRanges; res = GetPromotedRanges(selection, arrayOfRanges, operation); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // use these ranges to contruct a list of nodes to act on. res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, operation, dontTouchContent); @@ -6493,17 +6493,17 @@ nsHTMLEditRules::ReturnInHeader(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> headerParent; PRInt32 offset; nsresult res = nsEditor::GetNodeLocation(aHeader, address_of(headerParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // get ws code to adjust any ws nsCOMPtr<nsIDOMNode> selNode = aNode; res = nsWSRunObject::PrepareToSplitAcrossBlocks(mHTMLEditor, address_of(selNode), &aOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // split the header PRInt32 newOffset; res = mHTMLEditor->SplitNodeDeep( aHeader, selNode, aOffset, &newOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if the leftand heading is empty, put a mozbr in it nsCOMPtr<nsIDOMNode> prevItem; @@ -6512,35 +6512,35 @@ nsHTMLEditRules::ReturnInHeader(nsISelection *aSelection, { PRBool bIsEmptyNode; res = mHTMLEditor->IsEmptyNode(prevItem, &bIsEmptyNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bIsEmptyNode) { nsCOMPtr<nsIDOMNode> brNode; res = CreateMozBR(prevItem, 0, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } // if the new (righthand) header node is empty, delete it PRBool isEmpty; res = IsEmptyBlock(aHeader, &isEmpty, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isEmpty) { res = mHTMLEditor->DeleteNode(aHeader); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // layout tells the caret to blink in a weird place // if we don't place a break after the header. nsCOMPtr<nsIDOMNode> sibling; res = mHTMLEditor->GetNextHTMLSibling(headerParent, offset+1, address_of(sibling)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!sibling || !nsTextEditUtils::IsBreak(sibling)) { res = CreateMozBR(headerParent, offset+1, address_of(sibling)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } res = nsEditor::GetNodeLocation(sibling, address_of(headerParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // put selection after break res = aSelection->Collapse(headerParent,offset+1); } @@ -6571,11 +6571,11 @@ nsHTMLEditRules::ReturnInParagraph(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> parent; PRInt32 offset; nsresult res = nsEditor::GetNodeLocation(aNode, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool doesCRCreateNewP; res = mHTMLEditor->GetReturnInParagraphCreatesNewParagraph(&doesCRCreateNewP); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool newBRneeded = PR_FALSE; nsCOMPtr<nsIDOMNode> sibling; @@ -6589,7 +6589,7 @@ nsHTMLEditRules::ReturnInParagraph(nsISelection *aSelection, nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(aNode); PRUint32 strLength; res = textNode->GetLength(&strLength); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // at beginning of text node? if (!aOffset) @@ -6620,7 +6620,7 @@ nsHTMLEditRules::ReturnInParagraph(nsISelection *aSelection, { nsCOMPtr<nsIDOMNode> tmp; res = mEditor->SplitNode(aNode, aOffset, getter_AddRefs(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aNode = tmp; } @@ -6634,12 +6634,12 @@ nsHTMLEditRules::ReturnInParagraph(nsISelection *aSelection, // is there a BR prior to it? nsCOMPtr<nsIDOMNode> nearNode, selNode = aNode; res = mHTMLEditor->GetPriorHTMLNode(aNode, aOffset, address_of(nearNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!nearNode || !mHTMLEditor->IsVisBreak(nearNode) || nsTextEditUtils::HasMozAttr(nearNode)) { // is there a BR after it? res = mHTMLEditor->GetNextHTMLNode(aNode, aOffset, address_of(nearNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!nearNode || !mHTMLEditor->IsVisBreak(nearNode) || nsTextEditUtils::HasMozAttr(nearNode)) { newBRneeded = PR_TRUE; @@ -6682,23 +6682,23 @@ nsHTMLEditRules::SplitParagraph(nsIDOMNode *aPara, // get ws code to adjust any ws nsCOMPtr<nsIDOMNode> leftPara, rightPara; res = nsWSRunObject::PrepareToSplitAcrossBlocks(mHTMLEditor, aSelNode, aOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // split the paragraph res = mHTMLEditor->SplitNodeDeep(aPara, *aSelNode, *aOffset, &newOffset, PR_FALSE, address_of(leftPara), address_of(rightPara)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // get rid of the break, if it is visible (otherwise it may be needed to prevent an empty p) if (mHTMLEditor->IsVisBreak(aBRNode)) { res = mHTMLEditor->DeleteNode(aBRNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // check both halves of para to see if we need mozBR res = InsertMozBRIfNeeded(leftPara); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = InsertMozBRIfNeeded(rightPara); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // selection to beginning of right hand para; // look inside any containers that are up front. @@ -6741,45 +6741,45 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection, // if we are in an empty listitem, then we want to pop up out of the list PRBool isEmpty; res = IsEmptyBlock(aListItem, &isEmpty, PR_TRUE, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isEmpty && mReturnInEmptyLIKillsList) // but only if prefs says it's ok { nsCOMPtr<nsIDOMNode> list, listparent; PRInt32 offset, itemOffset; res = nsEditor::GetNodeLocation(aListItem, address_of(list), &itemOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = nsEditor::GetNodeLocation(list, address_of(listparent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // are we the last list item in the list? PRBool bIsLast; res = mHTMLEditor->IsLastEditableChild(aListItem, &bIsLast); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bIsLast) { // we need to split the list! nsCOMPtr<nsIDOMNode> tempNode; res = mHTMLEditor->SplitNode(list, itemOffset, getter_AddRefs(tempNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // are we in a sublist? if (nsHTMLEditUtils::IsList(listparent)) //in a sublist { // if so, move this list item out of this list and into the grandparent list res = mHTMLEditor->MoveNode(aListItem,listparent,offset+1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = aSelection->Collapse(aListItem,0); } else { // otherwise kill this listitem res = mHTMLEditor->DeleteNode(aListItem); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // time to insert a break nsCOMPtr<nsIDOMNode> brNode; res = CreateMozBR(listparent, offset+1, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // set selection to before the moz br selPriv->SetInterlinePosition(PR_TRUE); @@ -6792,11 +6792,11 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection, // get ws code to adjust any ws nsCOMPtr<nsIDOMNode> selNode = aNode; res = nsWSRunObject::PrepareToSplitAcrossBlocks(mHTMLEditor, address_of(selNode), &aOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // now split list item PRInt32 newOffset; res = mHTMLEditor->SplitNodeDeep( aListItem, selNode, aOffset, &newOffset, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // hack: until I can change the damaged doc range code back to being // extra inclusive, I have to manually detect certain list items that // may be left empty. @@ -6807,17 +6807,17 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection, { PRBool bIsEmptyNode; res = mHTMLEditor->IsEmptyNode(prevItem, &bIsEmptyNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bIsEmptyNode) { nsCOMPtr<nsIDOMNode> brNode; res = CreateMozBR(prevItem, 0, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { res = mHTMLEditor->IsEmptyNode(aListItem, &bIsEmptyNode, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bIsEmptyNode) { nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(aListItem); @@ -6826,20 +6826,20 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> list; PRInt32 itemOffset; res = nsEditor::GetNodeLocation(aListItem, address_of(list), &itemOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoString listTag((nodeAtom == nsEditProperty::dt) ? NS_LITERAL_STRING("dd") : NS_LITERAL_STRING("dt")); nsCOMPtr<nsIDOMNode> newListItem; res = mHTMLEditor->CreateNode(listTag, list, itemOffset+1, getter_AddRefs(newListItem)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mEditor->DeleteNode(aListItem); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return aSelection->Collapse(newListItem, 0); } nsCOMPtr<nsIDOMNode> brNode; res = mHTMLEditor->CopyLastEditableChildStyles(prevItem, aListItem, getter_AddRefs(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (brNode) { nsCOMPtr<nsIDOMNode> brParent; @@ -6855,7 +6855,7 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection, PRInt32 visOffset = 0; PRInt16 wsType; res = wsObj.NextVisibleNode(aListItem, 0, address_of(visNode), &visOffset, &wsType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ( (wsType==nsWSRunObject::eSpecial) || (wsType==nsWSRunObject::eBreak) || nsHTMLEditUtils::IsHR(visNode) ) @@ -6863,7 +6863,7 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> parent; PRInt32 offset; res = nsEditor::GetNodeLocation(visNode, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return aSelection->Collapse(parent, offset); } else @@ -6903,7 +6903,7 @@ nsHTMLEditRules::MakeBlockquote(nsCOMArray<nsIDOMNode>& arrayOfNodes) // get the node to act on, and it's location curNode = arrayOfNodes[i]; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if the node is a table element or list item, dive inside if (nsHTMLEditUtils::IsTableElementButNotTable(curNode) || @@ -6913,9 +6913,9 @@ nsHTMLEditRules::MakeBlockquote(nsCOMArray<nsIDOMNode>& arrayOfNodes) // recursion time nsCOMArray<nsIDOMNode> childArray; res = GetChildNodesForOperation(curNode, childArray); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = MakeBlockquote(childArray); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // if the node has different parent than previous node, @@ -6941,16 +6941,16 @@ nsHTMLEditRules::MakeBlockquote(nsCOMArray<nsIDOMNode>& arrayOfNodes) { NS_NAMED_LITERAL_STRING(quoteType, "blockquote"); res = SplitAsNeeded("eType, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(quoteType, curParent, offset, getter_AddRefs(curBlock)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = curBlock; // note: doesn't matter if we set mNewBlock multiple times. } res = mHTMLEditor->MoveNode(curNode, curBlock, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return res; } @@ -6979,7 +6979,7 @@ nsHTMLEditRules::RemoveBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes) // get the node to act on, and it's location curNode = arrayOfNodes[i]; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoString curNodeTag, curBlockTag; nsEditor::GetTagString(curNode, curNodeTag); ToLowerCase(curNodeTag); @@ -6991,12 +6991,12 @@ nsHTMLEditRules::RemoveBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes) if (curBlock) { res = RemovePartOfBlock(curBlock, firstNode, lastNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); curBlock = 0; firstNode = 0; lastNode = 0; } // remove curent block res = mHTMLEditor->RemoveBlockContainer(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else if (nsHTMLEditUtils::IsTable(curNode) || nsHTMLEditUtils::IsTableRow(curNode) || @@ -7011,15 +7011,15 @@ nsHTMLEditRules::RemoveBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes) if (curBlock) { res = RemovePartOfBlock(curBlock, firstNode, lastNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); curBlock = 0; firstNode = 0; lastNode = 0; } // recursion time nsCOMArray<nsIDOMNode> childArray; res = GetChildNodesForOperation(curNode, childArray); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = RemoveBlockStyle(childArray); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else if (IsInlineNode(curNode)) { @@ -7037,7 +7037,7 @@ nsHTMLEditRules::RemoveBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes) // so lets handle it now. We need to remove the portion of // curBlock that contains [firstNode - lastNode]. res = RemovePartOfBlock(curBlock, firstNode, lastNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); curBlock = 0; firstNode = 0; lastNode = 0; // fall out and handle curNode } @@ -7057,7 +7057,7 @@ nsHTMLEditRules::RemoveBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes) if (curBlock) { res = RemovePartOfBlock(curBlock, firstNode, lastNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); curBlock = 0; firstNode = 0; lastNode = 0; } } @@ -7066,7 +7066,7 @@ nsHTMLEditRules::RemoveBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes) if (curBlock) { res = RemovePartOfBlock(curBlock, firstNode, lastNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); curBlock = 0; firstNode = 0; lastNode = 0; } return res; @@ -7111,7 +7111,7 @@ nsHTMLEditRules::ApplyBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes, const nsA // get the node to act on, and it's location curNode = arrayOfNodes[i]; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoString curNodeTag; nsEditor::GetTagString(curNode, curNodeTag); ToLowerCase(curNodeTag); @@ -7132,7 +7132,7 @@ nsHTMLEditRules::ApplyBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes, const nsA curBlock = 0; // forget any previous block used for previous inline nodes res = mHTMLEditor->ReplaceContainer(curNode, address_of(newBlock), *aBlockTag, nsnull, nsnull, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else if (nsHTMLEditUtils::IsTable(curNode) || (curNodeTag.EqualsLiteral("tbody")) || @@ -7147,21 +7147,21 @@ nsHTMLEditRules::ApplyBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes, const nsA // recursion time nsCOMArray<nsIDOMNode> childArray; res = GetChildNodesForOperation(curNode, childArray); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 childCount = childArray.Count(); if (childCount) { res = ApplyBlockStyle(childArray, aBlockTag); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { // make sure we can put a block here res = SplitAsNeeded(aBlockTag, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> theBlock; res = mHTMLEditor->CreateNode(*aBlockTag, curParent, offset, getter_AddRefs(theBlock)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = theBlock; } @@ -7174,21 +7174,21 @@ nsHTMLEditRules::ApplyBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes, const nsA { curBlock = 0; // forget any previous block used for previous inline nodes res = mHTMLEditor->DeleteNode(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { // the break is the first (or even only) node we encountered. Create a // block for it. res = SplitAsNeeded(aBlockTag, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(*aBlockTag, curParent, offset, getter_AddRefs(curBlock)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = curBlock; // note: doesn't matter if we set mNewBlock multiple times. res = mHTMLEditor->MoveNode(curNode, curBlock, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -7211,9 +7211,9 @@ nsHTMLEditRules::ApplyBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes, const nsA if (!curBlock) { res = SplitAsNeeded(aBlockTag, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(*aBlockTag, curParent, offset, getter_AddRefs(curBlock)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = curBlock; // note: doesn't matter if we set mNewBlock multiple times. @@ -7225,7 +7225,7 @@ nsHTMLEditRules::ApplyBlockStyle(nsCOMArray<nsIDOMNode>& arrayOfNodes, const nsA // this is a continuation of some inline nodes that belong together in // the same block item. use curBlock res = mHTMLEditor->MoveNode(curNode, curBlock, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } return res; @@ -7270,7 +7270,7 @@ nsHTMLEditRules::SplitAsNeeded(const nsAString *aTag, { // we found a place for block, but above inOutParent. We need to split nodes. res = mHTMLEditor->SplitNodeDeep(splitNode, *inOutParent, *inOutOffset, inOutOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *inOutParent = tagParent; } return res; @@ -7299,7 +7299,7 @@ nsHTMLEditRules::JoinNodesSmart( nsIDOMNode *aNodeLeft, PRInt32 parOffset; nsCOMPtr<nsIDOMNode> parent, rightParent; res = nsEditor::GetNodeLocation(aNodeLeft, address_of(parent), &parOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aNodeRight->GetParentNode(getter_AddRefs(rightParent)); // if they don't have the same parent, first move the 'right' node @@ -7307,13 +7307,13 @@ nsHTMLEditRules::JoinNodesSmart( nsIDOMNode *aNodeLeft, if (parent != rightParent) { res = mHTMLEditor->MoveNode(aNodeRight, parent, parOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // defaults for outParams *aOutMergeParent = aNodeRight; res = mHTMLEditor->GetLengthOfDOMNode(aNodeLeft, *((PRUint32*)aOutMergeOffset)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // separate join rules for differing blocks if (nsHTMLEditUtils::IsList(aNodeLeft) || @@ -7321,7 +7321,7 @@ nsHTMLEditRules::JoinNodesSmart( nsIDOMNode *aNodeLeft, { // for list's, merge shallow (wouldn't want to combine list items) res = mHTMLEditor->JoinNodes(aNodeLeft, aNodeRight, parent); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return res; } else @@ -7329,13 +7329,13 @@ nsHTMLEditRules::JoinNodesSmart( nsIDOMNode *aNodeLeft, // remember the last left child, and firt right child nsCOMPtr<nsIDOMNode> lastLeft, firstRight; res = mHTMLEditor->GetLastEditableChild(aNodeLeft, address_of(lastLeft)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->GetFirstEditableChild(aNodeRight, address_of(firstRight)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // for list items, divs, etc, merge smart res = mHTMLEditor->JoinNodes(aNodeLeft, aNodeRight, parent); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (lastLeft && firstRight && mHTMLEditor->NodesSameType(lastLeft, firstRight) && @@ -7368,7 +7368,7 @@ nsHTMLEditRules::GetTopEnclosingMailCite(nsIDOMNode *aNode, if (nsTextEditUtils::IsBody(node)) break; res = node->GetParentNode(getter_AddRefs(parentNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); node = parentNode; } @@ -7429,11 +7429,11 @@ nsHTMLEditRules::ReapplyCachedStyles() // get selection point nsCOMPtr<nsISelection>selection; nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> selNode; PRInt32 selOffset; res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = NS_OK; PRInt32 j; @@ -7454,7 +7454,7 @@ nsHTMLEditRules::ReapplyCachedStyles() { res = mHTMLEditor->GetInlinePropertyBase(mCachedStyles[j].tag, &(mCachedStyles[j].attr), &(mCachedStyles[j].value), &bFirst, &bAny, &bAll, &curValue, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // this style has disappeared through deletion. Add it onto our typeinstate: if (!bAny) @@ -7493,9 +7493,9 @@ nsHTMLEditRules::AdjustSpecialBreaks(PRBool aSafeToAskFrames) nsEmptyEditableFunctor functor(mHTMLEditor); nsDOMIterator iter; nsresult res = iter.Init(mDocChangeRange); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = iter.AppendList(functor, arrayOfNodes); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // put moz-br's into these empty li's and td's nodeCount = arrayOfNodes.Count(); @@ -7509,9 +7509,9 @@ nsHTMLEditRules::AdjustSpecialBreaks(PRBool aSafeToAskFrames) nsCOMPtr<nsIDOMNode> brNode, theNode = arrayOfNodes[0]; arrayOfNodes.RemoveObjectAt(0); res = nsEditor::GetLengthOfDOMNode(theNode, len); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = CreateMozBR(theNode, (PRInt32)len, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return res; @@ -7524,7 +7524,7 @@ nsHTMLEditRules::AdjustWhitespace(nsISelection *aSelection) nsCOMPtr<nsIDOMNode> selNode; PRInt32 selOffset; nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // ask whitespace object to tweak nbsp's return nsWSRunObject(mHTMLEditor, selNode, selOffset).AdjustWhitespace(); @@ -7536,27 +7536,27 @@ nsHTMLEditRules::PinSelectionToNewBlock(nsISelection *aSelection) if (!aSelection) return NS_ERROR_NULL_POINTER; PRBool bCollapsed; nsresult res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bCollapsed) return res; // get the (collapsed) selection location nsCOMPtr<nsIDOMNode> selNode, temp; PRInt32 selOffset; res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); temp = selNode; // use ranges and sRangeHelper to compare sel point to new block nsCOMPtr<nsIDOMRange> range = do_CreateInstance("@mozilla.org/content/range;1"); res = range->SetStart(selNode, selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->SetEnd(selNode, selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIContent> block (do_QueryInterface(mNewBlock)); if (!block) return NS_ERROR_NO_INTERFACE; PRBool nodeBefore, nodeAfter; res = mHTMLEditor->sRangeHelper->CompareNodeToRange(block, range, &nodeBefore, &nodeAfter); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nodeBefore && nodeAfter) return NS_OK; // selection is inside block @@ -7569,13 +7569,13 @@ nsHTMLEditRules::PinSelectionToNewBlock(nsISelection *aSelection) if (mHTMLEditor->IsTextNode(tmp) || mHTMLEditor->IsContainer(tmp)) { res = nsEditor::GetLengthOfDOMNode(tmp, endPoint); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { nsCOMPtr<nsIDOMNode> tmp2; res = nsEditor::GetNodeLocation(tmp, address_of(tmp2), (PRInt32*)&endPoint); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); tmp = tmp2; endPoint++; // want to be after this node } @@ -7591,7 +7591,7 @@ nsHTMLEditRules::PinSelectionToNewBlock(nsISelection *aSelection) { nsCOMPtr<nsIDOMNode> tmp2; res = nsEditor::GetNodeLocation(tmp, address_of(tmp2), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); tmp = tmp2; } return aSelection->Collapse(tmp, 0); @@ -7608,14 +7608,14 @@ nsHTMLEditRules::CheckInterlinePosition(nsISelection *aSelection) // if the selection isn't collapsed, do nothing. PRBool bCollapsed; nsresult res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bCollapsed) return res; // get the (collapsed) selection location nsCOMPtr<nsIDOMNode> selNode, node; PRInt32 selOffset; res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // are we after a block? If so try set caret to following content mHTMLEditor->GetPriorHTMLSibling(selNode, selOffset, address_of(node)); @@ -7652,14 +7652,14 @@ nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection // only a single break selected, and collapse it. Good thing? Beats me. PRBool bCollapsed; nsresult res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bCollapsed) return res; // get the (collapsed) selection location nsCOMPtr<nsIDOMNode> selNode, temp; PRInt32 selOffset; res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); temp = selNode; // are we in an editable node? @@ -7667,7 +7667,7 @@ nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection { // scan up the tree until we find an editable place to be res = nsEditor::GetNodeLocation(temp, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selNode) return NS_ERROR_FAILURE; temp = selNode; } @@ -7680,7 +7680,7 @@ nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection if (theblock && mHTMLEditor->IsEditable(theblock)) { PRBool bIsEmptyNode; res = mHTMLEditor->IsEmptyNode(theblock, &bIsEmptyNode, PR_FALSE, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // check if br can go into the destination node if (bIsEmptyNode && mHTMLEditor->CanContainTag(selNode, NS_LITERAL_STRING("br"))) { @@ -7713,7 +7713,7 @@ nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection nsCOMPtr<nsIDOMNode> nearNode; res = mHTMLEditor->GetPriorHTMLNode(selNode, selOffset, address_of(nearNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nearNode) { // is nearNode also a descendant of same block? @@ -7732,13 +7732,13 @@ nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection // like table cells won't grow in height. nsCOMPtr<nsIDOMNode> brNode; res = CreateMozBR(selNode, selOffset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = nsEditor::GetNodeLocation(brNode, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // selection stays *before* moz-br, sticking to it selPriv->SetInterlinePosition(PR_TRUE); res = aSelection->Collapse(selNode,selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { @@ -7757,14 +7757,14 @@ nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection // we aren't in a textnode: are we adjacent to text or a break or an image? res = mHTMLEditor->GetPriorHTMLNode(selNode, selOffset, address_of(nearNode), PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nearNode && (nsTextEditUtils::IsBreak(nearNode) || nsEditor::IsTextNode(nearNode) || nsHTMLEditUtils::IsImage(nearNode) || nsHTMLEditUtils::IsHR(nearNode))) return NS_OK; // this is a good place for the caret to be res = mHTMLEditor->GetNextHTMLNode(selNode, selOffset, address_of(nearNode), PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nearNode && (nsTextEditUtils::IsBreak(nearNode) || nsEditor::IsTextNode(nearNode) || nsHTMLEditUtils::IsImage(nearNode) @@ -7774,7 +7774,7 @@ nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection // look for a nearby text node. // prefer the correct direction. res = FindNearSelectableNode(selNode, selOffset, aAction, address_of(nearNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nearNode) { @@ -7791,7 +7791,7 @@ nsHTMLEditRules::AdjustSelection(nsISelection *aSelection, nsIEditor::EDirection else // must be break or image { res = nsEditor::GetNodeLocation(nearNode, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (aAction == nsIEditor::ePrevious) selOffset++; // want to be beyond it if we backed up to it res = aSelection->Collapse(selNode, selOffset); } @@ -7815,7 +7815,7 @@ nsHTMLEditRules::FindNearSelectableNode(nsIDOMNode *aSelNode, res = mHTMLEditor->GetPriorHTMLNode(aSelNode, aSelOffset, address_of(nearNode)); else res = mHTMLEditor->GetNextHTMLNode(aSelNode, aSelOffset, address_of(nearNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!nearNode) // try the other direction then { @@ -7828,7 +7828,7 @@ nsHTMLEditRules::FindNearSelectableNode(nsIDOMNode *aSelNode, res = mHTMLEditor->GetPriorHTMLNode(aSelNode, aSelOffset, address_of(nearNode)); else res = mHTMLEditor->GetNextHTMLNode(aSelNode, aSelOffset, address_of(nearNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // scan in the right direction until we find an eligible text node, @@ -7842,7 +7842,7 @@ nsHTMLEditRules::FindNearSelectableNode(nsIDOMNode *aSelNode, res = mHTMLEditor->GetPriorHTMLNode(curNode, address_of(nearNode)); else res = mHTMLEditor->GetNextHTMLNode(curNode, address_of(nearNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (nearNode) @@ -7850,7 +7850,7 @@ nsHTMLEditRules::FindNearSelectableNode(nsIDOMNode *aSelNode, // don't cross any table elements PRBool bInDifTblElems; res = InDifferentTableElements(nearNode, aSelNode, &bInDifTblElems); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bInDifTblElems) return NS_OK; // otherwise, ok, we have found a good spot to put the selection @@ -7925,7 +7925,7 @@ nsHTMLEditRules::RemoveEmptyNodes() if (!iter) return NS_ERROR_NULL_POINTER; nsresult res = iter->Init(mDocChangeRange); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsTArray<nsIDOMNode*> skipList; @@ -7975,7 +7975,7 @@ nsHTMLEditRules::RemoveEmptyNodes() // user to type into. PRBool bIsSelInNode; res = SelectionEndpointInNode(node, &bIsSelInNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bIsSelInNode) { bIsCandidate = PR_TRUE; @@ -7989,7 +7989,7 @@ nsHTMLEditRules::RemoveEmptyNodes() res = mHTMLEditor->IsEmptyNode(node, &bIsEmptyNode, PR_TRUE, PR_TRUE); else // other nodes we require to be empty res = mHTMLEditor->IsEmptyNode(node, &bIsEmptyNode, PR_FALSE, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bIsEmptyNode) { if (bIsMailCite) // mailcites go on a separate list from other empty nodes @@ -8034,7 +8034,7 @@ nsHTMLEditRules::RemoveEmptyNodes() arrayOfEmptyCites.RemoveObjectAt(0); PRBool bIsEmptyNode; res = mHTMLEditor->IsEmptyNode(delNode, &bIsEmptyNode, PR_FALSE, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bIsEmptyNode) { // we are deleting a cite that has just a br. We want to delete cite, @@ -8042,12 +8042,12 @@ nsHTMLEditRules::RemoveEmptyNodes() nsCOMPtr<nsIDOMNode> parent, brNode; PRInt32 offset; res = nsEditor::GetNodeLocation(delNode, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateBR(parent, offset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } res = mHTMLEditor->DeleteNode(delNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return res; @@ -8062,19 +8062,19 @@ nsHTMLEditRules::SelectionEndpointInNode(nsIDOMNode *aNode, PRBool *aResult) nsCOMPtr<nsISelection>selection; nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsISelectionPrivate>selPriv(do_QueryInterface(selection)); nsCOMPtr<nsIEnumerator> enumerator; res = selPriv->GetEnumerator(getter_AddRefs(enumerator)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!enumerator) return NS_ERROR_UNEXPECTED; for (enumerator->First(); NS_OK!=enumerator->IsDone(); enumerator->Next()) { nsCOMPtr<nsISupports> currentItem; res = enumerator->CurrentItem(getter_AddRefs(currentItem)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!currentItem) return NS_ERROR_UNEXPECTED; nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) ); @@ -8175,7 +8175,7 @@ nsHTMLEditRules::PopListItem(nsIDOMNode *aListItem, PRBool *aOutOfList) nsCOMPtr<nsIDOMNode> curNode( do_QueryInterface(aListItem)); PRInt32 offset; nsresult res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!nsHTMLEditUtils::IsListItem(curNode)) return NS_ERROR_FAILURE; @@ -8185,35 +8185,35 @@ nsHTMLEditRules::PopListItem(nsIDOMNode *aListItem, PRBool *aOutOfList) nsCOMPtr<nsIDOMNode> curParPar; PRInt32 parOffset; res = nsEditor::GetNodeLocation(curParent, address_of(curParPar), &parOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool bIsFirstListItem; res = mHTMLEditor->IsFirstEditableChild(curNode, &bIsFirstListItem); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool bIsLastListItem; res = mHTMLEditor->IsLastEditableChild(curNode, &bIsLastListItem); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bIsFirstListItem && !bIsLastListItem) { // split the list nsCOMPtr<nsIDOMNode> newBlock; res = mHTMLEditor->SplitNode(curParent, offset, getter_AddRefs(newBlock)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (!bIsFirstListItem) parOffset++; res = mHTMLEditor->MoveNode(curNode, curParPar, parOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // unwrap list item contents if they are no longer in a list if (!nsHTMLEditUtils::IsList(curParPar) && nsHTMLEditUtils::IsListItem(curNode)) { res = mHTMLEditor->RemoveBlockContainer(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *aOutOfList = PR_TRUE; } return res; @@ -8237,25 +8237,25 @@ nsHTMLEditRules::RemoveListStructure(nsIDOMNode *aList) do { res = PopListItem(child, &bOutOfList); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } while (!bOutOfList); // keep popping it out until it's not in a list anymore } else if (nsHTMLEditUtils::IsList(child)) { res = RemoveListStructure(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { // delete any non- list items for now res = mHTMLEditor->DeleteNode(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } aList->GetFirstChild(getter_AddRefs(child)); } // delete the now-empty list res = mHTMLEditor->RemoveBlockContainer(aList); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return res; } @@ -8273,13 +8273,13 @@ nsHTMLEditRules::ConfirmSelectionInBody() // get the selection nsCOMPtr<nsISelection>selection; res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // get the selection start location nsCOMPtr<nsIDOMNode> selNode, temp, parent; PRInt32 selOffset; res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); temp = selNode; // check that selNode is inside body @@ -8299,7 +8299,7 @@ nsHTMLEditRules::ConfirmSelectionInBody() // get the selection end location res = mHTMLEditor->GetEndNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); temp = selNode; // check that selNode is inside body @@ -8332,7 +8332,7 @@ nsHTMLEditRules::UpdateDocChangeRange(nsIDOMRange *aRange) // before placing it in it's list) nsCOMPtr<nsIDOMNode> startNode; res = aRange->GetStartContainer(getter_AddRefs(startNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!mHTMLEditor->IsDescendantOfBody(startNode)) { // just return - we don't need to adjust mDocChangeRange in this case @@ -8359,29 +8359,29 @@ nsHTMLEditRules::UpdateDocChangeRange(nsIDOMRange *aRange) result = 1; res = NS_OK; } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (result > 0) // positive result means mDocChangeRange start is after aRange start { PRInt32 startOffset; res = aRange->GetStartOffset(&startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mDocChangeRange->SetStart(startNode, startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // compare ends of ranges res = mDocChangeRange->CompareBoundaryPoints(nsIDOMRange::END_TO_END, aRange, &result); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (result < 0) // negative result means mDocChangeRange end is before aRange end { nsCOMPtr<nsIDOMNode> endNode; PRInt32 endOffset; res = aRange->GetEndContainer(getter_AddRefs(endNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = aRange->GetEndOffset(&endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mDocChangeRange->SetEnd(endNode, endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } return res; @@ -8396,7 +8396,7 @@ nsHTMLEditRules::InsertMozBRIfNeeded(nsIDOMNode *aNode) PRBool isEmpty; nsCOMPtr<nsIDOMNode> brNode; nsresult res = mHTMLEditor->IsEmptyNode(aNode, &isEmpty); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isEmpty) { res = CreateMozBR(aNode, 0, address_of(brNode)); @@ -8426,7 +8426,7 @@ nsHTMLEditRules::DidCreateNode(const nsAString& aTag, if (!mListenerEnabled) return NS_OK; // assumption that Join keeps the righthand node nsresult res = mUtilRange->SelectNode(aNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); return res; } @@ -8447,7 +8447,7 @@ nsHTMLEditRules::DidInsertNode(nsIDOMNode *aNode, { if (!mListenerEnabled) return NS_OK; nsresult res = mUtilRange->SelectNode(aNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); return res; } @@ -8458,7 +8458,7 @@ nsHTMLEditRules::WillDeleteNode(nsIDOMNode *aChild) { if (!mListenerEnabled) return NS_OK; nsresult res = mUtilRange->SelectNode(aChild); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); return res; } @@ -8486,9 +8486,9 @@ nsHTMLEditRules::DidSplitNode(nsIDOMNode *aExistingRightNode, { if (!mListenerEnabled) return NS_OK; nsresult res = mUtilRange->SetStart(aNewLeftNode, 0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mUtilRange->SetEnd(aExistingRightNode, 0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); return res; } @@ -8513,9 +8513,9 @@ nsHTMLEditRules::DidJoinNodes(nsIDOMNode *aLeftNode, if (!mListenerEnabled) return NS_OK; // assumption that Join keeps the righthand node nsresult res = mUtilRange->SetStart(aRightNode, mJoinOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mUtilRange->SetEnd(aRightNode, mJoinOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); return res; } @@ -8538,9 +8538,9 @@ nsHTMLEditRules::DidInsertText(nsIDOMCharacterData *aTextNode, PRInt32 length = aString.Length(); nsCOMPtr<nsIDOMNode> theNode = do_QueryInterface(aTextNode); nsresult res = mUtilRange->SetStart(theNode, aOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mUtilRange->SetEnd(theNode, aOffset+length); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); return res; } @@ -8562,9 +8562,9 @@ nsHTMLEditRules::DidDeleteText(nsIDOMCharacterData *aTextNode, if (!mListenerEnabled) return NS_OK; nsCOMPtr<nsIDOMNode> theNode = do_QueryInterface(aTextNode); nsresult res = mUtilRange->SetStart(theNode, aOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mUtilRange->SetEnd(theNode, aOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); return res; } @@ -8592,13 +8592,13 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection) PRInt32 selOffset; nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mUtilRange->SetStart(selNode, selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->GetEndNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mUtilRange->SetEnd(selNode, selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); return res; } @@ -8641,7 +8641,7 @@ nsHTMLEditRules::RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignTyp } PRBool isBlock; res = mHTMLEditor->NodeIsBlockStatic(child, &isBlock); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ((isBlock && !nsHTMLEditUtils::IsDiv(child)) || nsHTMLEditUtils::IsHR(child)) { @@ -8651,7 +8651,7 @@ nsHTMLEditRules::RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignTyp { // remove the ALIGN attribute if this element can have it res = mHTMLEditor->RemoveAttribute(curElem, NS_LITERAL_STRING("align")); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (useCSS) { @@ -8664,13 +8664,13 @@ nsHTMLEditRules::RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignTyp nsAutoString dummyCssValue; res = mHTMLEditor->mHTMLCSSUtils->RemoveCSSInlineStyle(child, nsEditProperty::cssTextAlign, dummyCssValue); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (!nsHTMLEditUtils::IsTable(child)) { // unless this is a table, look at children res = RemoveAlignment(child, aAlignType, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } else if (nsEditor::NodeIsType(child, nsEditProperty::center) @@ -8679,7 +8679,7 @@ nsHTMLEditRules::RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignTyp // this is a CENTER or a DIV element and we have to remove it // first remove children's alignment res = RemoveAlignment(child, aAlignType, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (useCSS && nsHTMLEditUtils::IsDiv(child)) { @@ -8687,19 +8687,19 @@ nsHTMLEditRules::RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignTyp // if it does not carry any style hint (style attr, class or ID) nsAutoString dummyCssValue; res = mHTMLEditor->mHTMLCSSUtils->RemoveCSSInlineStyle(child, nsEditProperty::cssTextAlign, dummyCssValue); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMElement> childElt = do_QueryInterface(child); PRBool hasStyleOrIdOrClass; res = mHTMLEditor->HasStyleOrIdOrClass(childElt, &hasStyleOrIdOrClass); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!hasStyleOrIdOrClass) { // we may have to insert BRs in first and last position of DIV's children // if the nodes before/after are not blocks and not BRs res = MakeSureElemStartsOrEndsOnCR(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->RemoveContainer(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } else @@ -8707,11 +8707,11 @@ nsHTMLEditRules::RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignTyp // we may have to insert BRs in first and last position of element's children // if the nodes before/after are not blocks and not BRs res = MakeSureElemStartsOrEndsOnCR(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // in HTML mode, let's remove the element res = mHTMLEditor->RemoveContainer(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } child = tmp; @@ -8737,11 +8737,11 @@ nsHTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsIDOMNode *aNode, PRBool aStarts) { res = mHTMLEditor->GetLastEditableChild(aNode, address_of(child)); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!child) return NS_OK; PRBool isChildBlock; res = mHTMLEditor->NodeIsBlockStatic(child, &isChildBlock); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool foundCR = PR_FALSE; if (isChildBlock || nsTextEditUtils::IsBreak(child)) { @@ -8758,12 +8758,12 @@ nsHTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsIDOMNode *aNode, PRBool aStarts) { res = mHTMLEditor->GetNextHTMLSibling(aNode, address_of(sibling)); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (sibling) { PRBool isBlock; res = mHTMLEditor->NodeIsBlockStatic(sibling, &isBlock); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isBlock || nsTextEditUtils::IsBreak(sibling)) { foundCR = PR_TRUE; @@ -8782,15 +8782,15 @@ nsHTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsIDOMNode *aNode, PRBool aStarts) { nsCOMPtr<nsIDOMNodeList> childNodes; res = aNode->GetChildNodes(getter_AddRefs(childNodes)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!childNodes) return NS_ERROR_NULL_POINTER; PRUint32 childCount; res = childNodes->GetLength(&childCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); offset = childCount; } res = mHTMLEditor->CreateBR(aNode, offset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return NS_OK; } @@ -8799,7 +8799,7 @@ NS_IMETHODIMP nsHTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsIDOMNode *aNode) { nsresult res = MakeSureElemStartsOrEndsOnCR(aNode, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = MakeSureElemStartsOrEndsOnCR(aNode, PR_TRUE); return res; } @@ -8817,7 +8817,7 @@ nsHTMLEditRules::AlignBlock(nsIDOMElement * aElement, const nsAString * aAlignTy } nsresult res = RemoveAlignment(node, *aAlignType, aContentsOnly); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); NS_NAMED_LITERAL_STRING(attr, "align"); PRBool useCSS; mHTMLEditor->GetIsCSSEnabled(&useCSS); @@ -8825,14 +8825,14 @@ nsHTMLEditRules::AlignBlock(nsIDOMElement * aElement, const nsAString * aAlignTy // let's use CSS alignment; we use margin-left and margin-right for tables // and text-align for other block-level elements res = mHTMLEditor->SetAttributeOrEquivalent(aElement, attr, *aAlignType, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { // HTML case; this code is supposed to be called ONLY if the element // supports the align attribute but we'll never know... if (nsHTMLEditUtils::SupportsAlignAttr(node)) { res = mHTMLEditor->SetAttribute(aElement, attr, *aAlignType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } return NS_OK; @@ -8898,13 +8898,13 @@ nsHTMLEditRules::RelativeChangeIndentationOfElementNode(nsIDOMNode *aNode, PRInt // we deal with a DIV ; let's see if it is useless and if we can remove it nsCOMPtr<nsIDOMNamedNodeMap> attributeList; res = element->GetAttributes(getter_AddRefs(attributeList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRUint32 count; attributeList->GetLength(&count); if (!count) { // the DIV has no attribute at all, let's remove it res = mHTMLEditor->RemoveContainer(element); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else if (1 == count) { nsCOMPtr<nsIDOMNode> styleAttributeNode; @@ -8912,7 +8912,7 @@ nsHTMLEditRules::RelativeChangeIndentationOfElementNode(nsIDOMNode *aNode, PRInt getter_AddRefs(styleAttributeNode)); if (!styleAttributeNode) { res = mHTMLEditor->RemoveContainer(element); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -8930,7 +8930,7 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, { if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } nsresult res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() @@ -8948,7 +8948,7 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, } res = NormalizeSelection(aSelection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); // convert the selection ranges into "promoted" selection ranges: @@ -8958,12 +8958,12 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, nsCOMArray<nsIDOMRange> arrayOfRanges; res = GetPromotedRanges(aSelection, arrayOfRanges, kSetAbsolutePosition); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // use these ranges to contruct a list of nodes to act on. nsCOMArray<nsIDOMNode> arrayOfNodes; res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, kSetAbsolutePosition); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); NS_NAMED_LITERAL_STRING(divType, "div"); @@ -8976,12 +8976,12 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, // get selection location res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // make sure we can put a block here res = SplitAsNeeded(&divType, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(divType, parent, offset, getter_AddRefs(thePositionedDiv)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = thePositionedDiv; // delete anything that was in the list of nodes @@ -8989,9 +8989,9 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, { nsCOMPtr<nsIDOMNode> curNode = arrayOfNodes[0]; res = mHTMLEditor->DeleteNode(curNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = arrayOfNodes.RemoveObjectAt(0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // put selection in new block res = aSelection->Collapse(thePositionedDiv,0); @@ -9015,7 +9015,7 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, PRInt32 offset; res = nsEditor::GetNodeLocation(curNode, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // some logic for putting list items into nested lists... if (nsHTMLEditUtils::IsList(curParent)) @@ -9035,7 +9035,7 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, ToLowerCase(listTag); // create a new nested list of correct type res = SplitAsNeeded(&listTag, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!curPositionedDiv) { PRInt32 parentOffset; nsCOMPtr<nsIDOMNode> curParentParent; @@ -9044,14 +9044,14 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, mNewBlock = curPositionedDiv; } res = mHTMLEditor->CreateNode(listTag, curPositionedDiv, -1, getter_AddRefs(curList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // curList is now the correct thing to put curNode in // remember our new block for postprocessing // mNewBlock = curList; } // tuck the node into the end of the active list res = mHTMLEditor->MoveNode(curNode, curList, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // forget curPositionedDiv, if any // curPositionedDiv = nsnull; } @@ -9069,7 +9069,7 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, { if (indentedLI == listitem) continue; // already indented this list item res = nsEditor::GetNodeLocation(listitem, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // check to see if curList is still appropriate. Which it is if // curNode is still right after it in the same list. if (curList) @@ -9085,7 +9085,7 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, ToLowerCase(listTag); // create a new nested list of correct type res = SplitAsNeeded(&listTag, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!curPositionedDiv) { PRInt32 parentOffset; nsCOMPtr<nsIDOMNode> curParentParent; @@ -9094,10 +9094,10 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, mNewBlock = curPositionedDiv; } res = mHTMLEditor->CreateNode(listTag, curPositionedDiv, -1, getter_AddRefs(curList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } res = mHTMLEditor->MoveNode(listitem, curList, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember we indented this li indentedLI = listitem; } @@ -9116,9 +9116,9 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, continue; } res = SplitAsNeeded(&divType, address_of(curParent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mHTMLEditor->CreateNode(divType, curParent, offset, getter_AddRefs(curPositionedDiv)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remember our new block for postprocessing mNewBlock = curPositionedDiv; // curPositionedDiv is now the correct thing to put curNode in @@ -9126,7 +9126,7 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel, // tuck the node into the end of the active blockquote res = mHTMLEditor->MoveNode(curNode, curPositionedDiv, -1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // forget curList, if any curList = nsnull; } @@ -9148,7 +9148,7 @@ nsHTMLEditRules::WillRemoveAbsolutePosition(nsISelection *aSelection, PRBool *aC { if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } nsresult res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore aCancel from WillInsert() @@ -9157,7 +9157,7 @@ nsHTMLEditRules::WillRemoveAbsolutePosition(nsISelection *aSelection, PRBool *aC nsCOMPtr<nsIDOMElement> elt; res = mHTMLEditor->GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(elt)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); @@ -9173,7 +9173,7 @@ nsHTMLEditRules::WillRelativeChangeZIndex(nsISelection *aSelection, { if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } nsresult res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore aCancel from WillInsert() @@ -9182,7 +9182,7 @@ nsHTMLEditRules::WillRelativeChangeZIndex(nsISelection *aSelection, nsCOMPtr<nsIDOMElement> elt; res = mHTMLEditor->GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(elt)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 9b0ba33cf92..3a675a56c1f 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -335,7 +335,7 @@ nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, } } - if (NS_FAILED(rulesRes)) return rulesRes; + NS_ENSURE_SUCCESS(rulesRes, rulesRes); return result; } @@ -521,7 +521,7 @@ nsHTMLEditor::InitRules() { // instantiate the rules for the html editor nsresult res = NS_NewHTMLEditRules(getter_AddRefs(mRules)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!mRules) return NS_ERROR_UNEXPECTED; res = mRules->Init(static_cast<nsPlaintextEditor*>(this)); @@ -567,7 +567,7 @@ nsHTMLEditor::BeginningOfDocument() (visType==nsWSRunObject::eSpecial)) { res = GetNodeLocation(visNode, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); done = PR_TRUE; } else if (visType==nsWSRunObject::eOtherBlock) @@ -588,7 +588,7 @@ nsHTMLEditor::BeginningOfDocument() // We want to place the caret in front of that block. res = GetNodeLocation(visNode, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); done = PR_TRUE; } else @@ -599,7 +599,7 @@ nsHTMLEditor::BeginningOfDocument() { // skip the empty block res = GetNodeLocation(visNode, address_of(curNode), &curOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); ++curOffset; } else @@ -827,7 +827,7 @@ nsHTMLEditor::NodeIsBlockStatic(nsIDOMNode *aNode, PRBool *aIsBlock) nsAutoString tagName; rv = element->GetTagName(tagName); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); assertmsg.Append(tagName); char* assertstr = ToNewCString(assertmsg); @@ -1459,7 +1459,7 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled) nsCOMPtr<nsIDOMElement> cellElement; // can't use |NS_LITERAL_STRING| here until |GetElementOrParentByTagName| is fixed to accept readables nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cellElement)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Do nothing -- we didn't find a table cell if (!cellElement) return NS_OK; @@ -1471,15 +1471,15 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled) // first create an iterator over the table nsCOMPtr<nsIContentIterator> iter = do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!iter) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIContent> cTbl = do_QueryInterface(tbl); nsCOMPtr<nsIContent> cBlock = do_QueryInterface(cellElement); res = iter->Init(cTbl); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // position iter at block res = iter->PositionAt(cBlock); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> node; do @@ -1495,7 +1495,7 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled) GetEnclosingTable(node) == tbl) { res = CollapseSelectionToDeepestNonTableFirstChild(nsnull, node); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *outHandled = PR_TRUE; return NS_OK; } @@ -1506,7 +1506,7 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled) // if we havent handled it yet then we must have run off the end of // the table. Insert a new row. res = InsertTableRow(1, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *outHandled = PR_TRUE; // put selection in right place // Use table code to get selection and index to new row... @@ -1519,10 +1519,10 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled) getter_AddRefs(cell), nsnull, nsnull, &row, nsnull); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // ...so that we can ask for first cell in that row... res = GetCellAt(tblElement, row, 0, getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // ...and then set selection there. // (Note that normally you should use CollapseSelectionToDeepestNonTableFirstChild(), // but we know cell is an empty new cell, so this works fine) @@ -1570,20 +1570,20 @@ NS_IMETHODIMP nsHTMLEditor::CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent, { // split the text node res = SplitNode(node, theOffset, getter_AddRefs(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = GetNodeLocation(node, address_of(tmp), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // create br res = CreateNode(brType, tmp, offset, getter_AddRefs(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *aInOutParent = tmp; *aInOutOffset = offset+1; } else { res = CreateNode(brType, node, theOffset, getter_AddRefs(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); (*aInOutOffset)++; } @@ -1594,10 +1594,10 @@ NS_IMETHODIMP nsHTMLEditor::CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent, nsCOMPtr<nsIDOMNode> parent; PRInt32 offset; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); res = GetNodeLocation(*outBRNode, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (aSelect == eNext) { // position selection after br @@ -1634,26 +1634,26 @@ NS_IMETHODIMP nsHTMLEditor::InsertBR(nsCOMPtr<nsIDOMNode> *outBRNode) nsAutoRules beginRulesSniffing(this, kOpInsertText, nsIEditor::eNext); nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); res = selection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bCollapsed) { res = DeleteSelection(nsIEditor::eNone); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } nsCOMPtr<nsIDOMNode> selNode; PRInt32 selOffset; res = GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = CreateBR(selNode, selOffset, outBRNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // position selection after br res = GetNodeLocation(*outBRNode, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); selPriv->SetInterlinePosition(PR_TRUE); res = selection->Collapse(selNode, selOffset+1); @@ -1672,7 +1672,7 @@ nsHTMLEditor::CollapseSelectionToDeepestNonTableFirstChild(nsISelection *aSelect selection = aSelection; } else { res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; } nsCOMPtr<nsIDOMNode> node = aNode; @@ -1707,7 +1707,7 @@ nsHTMLEditor::ReplaceHeadContentsWithHTML(const nsAString& aSourceToInsert) nsAutoRules beginRulesSniffing(this, kOpIgnore, nsIEditor::eNone); // don't do any post processing, rules get confused nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; ForceCompositionEnd(); @@ -1719,7 +1719,7 @@ nsHTMLEditor::ReplaceHeadContentsWithHTML(const nsAString& aSourceToInsert) nsCOMPtr<nsIDOMNodeList>nodeList; res = doc->GetElementsByTagName(NS_LITERAL_STRING("head"), getter_AddRefs(nodeList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!nodeList) return NS_ERROR_NULL_POINTER; PRUint32 count; @@ -1728,7 +1728,7 @@ nsHTMLEditor::ReplaceHeadContentsWithHTML(const nsAString& aSourceToInsert) nsCOMPtr<nsIDOMNode> headNode; res = nodeList->Item(0, getter_AddRefs(headNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!headNode) return NS_ERROR_NULL_POINTER; // First, make sure there are no return chars in the source. @@ -1747,7 +1747,7 @@ nsHTMLEditor::ReplaceHeadContentsWithHTML(const nsAString& aSourceToInsert) nsAutoEditBatch beginBatching(this); res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; // Get the first range in the selection, for context: @@ -1780,11 +1780,11 @@ nsHTMLEditor::ReplaceHeadContentsWithHTML(const nsAString& aSourceToInsert) // First delete all children in head do { res = headNode->GetFirstChild(getter_AddRefs(child)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (child) { res = DeleteNode(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } while (child); @@ -1795,11 +1795,11 @@ nsHTMLEditor::ReplaceHeadContentsWithHTML(const nsAString& aSourceToInsert) // Loop over the contents of the fragment and move into the document do { res = fragmentAsNode->GetFirstChild(getter_AddRefs(child)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (child) { res = InsertNode(child, headNode, offsetOfNewNode++); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } while (child); @@ -1813,10 +1813,10 @@ nsHTMLEditor::RebuildDocumentFromSource(const nsAString& aSourceString) nsCOMPtr<nsISelection>selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsIDOMElement *bodyElement = GetRoot(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bodyElement) return NS_ERROR_NULL_POINTER; // Find where the <body> tag starts. @@ -1873,10 +1873,10 @@ nsHTMLEditor::RebuildDocumentFromSource(const nsAString& aSourceString) // so we assume that there is no head res = ReplaceHeadContentsWithHTML(head); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = SelectAll(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!foundbody) { NS_NAMED_LITERAL_STRING(body, "<body>"); @@ -1904,7 +1904,7 @@ nsHTMLEditor::RebuildDocumentFromSource(const nsAString& aSourceString) } res = LoadHTML(Substring(beginbody, endtotal)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Now we must copy attributes user might have edited on the <body> tag // because InsertHTML (actually, CreateContextualFragment()) @@ -1925,26 +1925,26 @@ nsHTMLEditor::RebuildDocumentFromSource(const nsAString& aSourceString) nsCOMPtr<nsIDOMRange> range; res = selection->GetRangeAt(0, getter_AddRefs(range)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNSRange> nsrange (do_QueryInterface(range)); if (!nsrange) return NS_ERROR_NO_INTERFACE; nsCOMPtr<nsIDOMDocumentFragment> docfrag; res = nsrange->CreateContextualFragment(bodyTag, getter_AddRefs(docfrag)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> fragmentAsNode (do_QueryInterface(docfrag)); if (!fragmentAsNode) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode> child; res = fragmentAsNode->GetFirstChild(getter_AddRefs(child)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!child) return NS_ERROR_NULL_POINTER; // Copy all attributes from the div child to current body element res = CloneAttributes(bodyElement, child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // place selection at first editable content return BeginningOfDocument(); @@ -2103,19 +2103,19 @@ nsHTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement, PRBool aDeleteSe if (!SetCaretInTableCell(aElement)) { res = SetCaretAfterElement(aElement); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // check for inserting a whole table at the end of a block. If so insert a br after it. if (nsHTMLEditUtils::IsTable(node)) { PRBool isLast; res = IsLastEditableChild(node, &isLast); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isLast) { nsCOMPtr<nsIDOMNode> brNode; res = CreateBR(parentSelectedNode, offsetForInsert+1, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); selection->Collapse(parentSelectedNode, offsetForInsert+1); } } @@ -2196,7 +2196,7 @@ nsHTMLEditor::SelectElement(nsIDOMElement* aElement) { nsCOMPtr<nsISelection> selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode>parent; res = aElement->GetParentNode(getter_AddRefs(parent)); @@ -2229,11 +2229,11 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) { nsCOMPtr<nsISelection> selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode>parent; res = aElement->GetParentNode(getter_AddRefs(parent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!parent) return NS_ERROR_NULL_POINTER; PRInt32 offsetInParent; res = GetChildOffset(aElement, parent, offsetInParent); @@ -2327,19 +2327,19 @@ nsHTMLEditor::GetCSSBackgroundColorState(PRBool *aMixed, nsAString &aOutColor, P // get selection nsCOMPtr<nsISelection>selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // get selection location nsCOMPtr<nsIDOMNode> parent; PRInt32 offset; res = GetStartNodeAndOffset(selection, getter_AddRefs(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!parent) return NS_ERROR_NULL_POINTER; // is the selection collapsed? PRBool bCollapsed; res = selection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> nodeToExamine; if (bCollapsed || IsTextNode(parent)) { @@ -2359,7 +2359,7 @@ nsHTMLEditor::GetCSSBackgroundColorState(PRBool *aMixed, nsAString &aOutColor, P // is the node to examine a block ? PRBool isBlock; res = NodeIsBlockStatic(nodeToExamine, &isBlock); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> tmp; @@ -2398,13 +2398,13 @@ nsHTMLEditor::GetCSSBackgroundColorState(PRBool *aMixed, nsAString &aOutColor, P if (IsTextNode(nodeToExamine)) { // if the node of interest is a text node, let's climb a level res = nodeToExamine->GetParentNode(getter_AddRefs(parent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nodeToExamine = parent; } do { // is the node to examine a block ? res = NodeIsBlockStatic(nodeToExamine, &isBlock); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isBlock) { // yes it is a block; in that case, the text background color is transparent aOutColor.AssignLiteral("transparent"); @@ -2421,7 +2421,7 @@ nsHTMLEditor::GetCSSBackgroundColorState(PRBool *aMixed, nsAString &aOutColor, P } tmp.swap(nodeToExamine); res = tmp->GetParentNode(getter_AddRefs(nodeToExamine)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } while ( aOutColor.EqualsLiteral("transparent") && nodeToExamine ); } return NS_OK; @@ -2441,7 +2441,7 @@ nsHTMLEditor::GetHTMLBackgroundColorState(PRBool *aMixed, nsAString &aOutColor) nsresult res = GetSelectedOrParentTableElement(tagName, &selectedCount, getter_AddRefs(element)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); NS_NAMED_LITERAL_STRING(styleName, "bgcolor"); @@ -2449,7 +2449,7 @@ nsHTMLEditor::GetHTMLBackgroundColorState(PRBool *aMixed, nsAString &aOutColor) { // We are in a cell or selected table res = element->GetAttribute(styleName, aOutColor); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Done if we have a color explicitly set if (!aOutColor.IsEmpty()) @@ -2462,7 +2462,7 @@ nsHTMLEditor::GetHTMLBackgroundColorState(PRBool *aMixed, nsAString &aOutColor) // from nested cells/tables, so search up parent chain nsCOMPtr<nsIDOMNode> parentNode; res = element->GetParentNode(getter_AddRefs(parentNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); element = do_QueryInterface(parentNode); } @@ -2537,7 +2537,7 @@ nsHTMLEditor::MakeOrChangeList(const nsAString& aListType, PRBool entireList, co // pre-process res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsTextRulesInfo ruleInfo(nsTextEditRules::kMakeList); @@ -2552,14 +2552,14 @@ nsHTMLEditor::MakeOrChangeList(const nsAString& aListType, PRBool entireList, co // Find out if the selection is collapsed: PRBool isCollapsed; res = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> node; PRInt32 offset; res = GetStartNodeAndOffset(selection, getter_AddRefs(node), &offset); if (!node) res = NS_ERROR_FAILURE; - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isCollapsed) { @@ -2580,19 +2580,19 @@ nsHTMLEditor::MakeOrChangeList(const nsAString& aListType, PRBool entireList, co { // we need to split up to the child of parent res = SplitNodeDeep(topChild, node, offset, &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // make a list nsCOMPtr<nsIDOMNode> newList; res = CreateNode(aListType, parent, offset, getter_AddRefs(newList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // make a list item nsCOMPtr<nsIDOMNode> newItem; res = CreateNode(NS_LITERAL_STRING("li"), newList, 0, getter_AddRefs(newItem)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = selection->Collapse(newItem,0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -2618,7 +2618,7 @@ nsHTMLEditor::RemoveList(const nsAString& aListType) // pre-process res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsTextRulesInfo ruleInfo(nsTextEditRules::kRemoveList); @@ -2651,7 +2651,7 @@ nsHTMLEditor::MakeDefinitionItem(const nsAString& aItemType) // pre-process res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsTextRulesInfo ruleInfo(nsTextEditRules::kMakeDefListItem); ruleInfo.blockType = &aItemType; @@ -2684,7 +2684,7 @@ nsHTMLEditor::InsertBasicBlock(const nsAString& aBlockType) // pre-process res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsTextRulesInfo ruleInfo(nsTextEditRules::kMakeBasicBlock); ruleInfo.blockType = &aBlockType; @@ -2696,14 +2696,14 @@ nsHTMLEditor::InsertBasicBlock(const nsAString& aBlockType) // Find out if the selection is collapsed: PRBool isCollapsed; res = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> node; PRInt32 offset; res = GetStartNodeAndOffset(selection, getter_AddRefs(node), &offset); if (!node) res = NS_ERROR_FAILURE; - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isCollapsed) { @@ -2724,17 +2724,17 @@ nsHTMLEditor::InsertBasicBlock(const nsAString& aBlockType) { // we need to split up to the child of parent res = SplitNodeDeep(topChild, node, offset, &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // make a block nsCOMPtr<nsIDOMNode> newBlock; res = CreateNode(aBlockType, parent, offset, getter_AddRefs(newBlock)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // reposition selection to inside the block res = selection->Collapse(newBlock,0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -2765,7 +2765,7 @@ nsHTMLEditor::Indent(const nsAString& aIndent) // pre-process nsCOMPtr<nsISelection> selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsTextRulesInfo ruleInfo(theAction); @@ -2779,11 +2779,11 @@ nsHTMLEditor::Indent(const nsAString& aIndent) PRInt32 offset; PRBool isCollapsed; res = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = GetStartNodeAndOffset(selection, getter_AddRefs(node), &offset); if (!node) res = NS_ERROR_FAILURE; - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (aIndent.EqualsLiteral("indent")) { @@ -2806,23 +2806,23 @@ nsHTMLEditor::Indent(const nsAString& aIndent) { // we need to split up to the child of parent res = SplitNodeDeep(topChild, node, offset, &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // make a blockquote nsCOMPtr<nsIDOMNode> newBQ; res = CreateNode(bq, parent, offset, getter_AddRefs(newBQ)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // put a space in it so layout will draw the list item res = selection->Collapse(newBQ,0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = InsertText(NS_LITERAL_STRING(" ")); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // reposition selection to before the space character res = GetStartNodeAndOffset(selection, getter_AddRefs(node), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = selection->Collapse(node,0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -2847,7 +2847,7 @@ nsHTMLEditor::Align(const nsAString& aAlignType) // Find out if the selection is collapsed: nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsTextRulesInfo ruleInfo(nsTextEditRules::kAlign); ruleInfo.alignType = &aAlignType; @@ -2875,7 +2875,7 @@ nsHTMLEditor::GetElementOrParentByTagName(const nsAString& aTagName, nsIDOMNode // If no node supplied, get it from anchor node of current selection nsCOMPtr<nsISelection>selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode> anchorNode; @@ -2993,7 +2993,7 @@ nsHTMLEditor::GetSelectedElement(const nsAString& aTagName, nsIDOMElement** aRet // First look for a single element in selection nsCOMPtr<nsISelection>selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); @@ -3013,26 +3013,26 @@ nsHTMLEditor::GetSelectedElement(const nsAString& aTagName, nsIDOMElement** aRet nsCOMPtr<nsIDOMElement> selectedElement; nsCOMPtr<nsIDOMRange> range; res = selection->GetRangeAt(0, getter_AddRefs(range)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> startParent; PRInt32 startOffset, endOffset; res = range->GetStartContainer(getter_AddRefs(startParent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetStartOffset(&startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> endParent; res = range->GetEndContainer(getter_AddRefs(endParent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndOffset(&endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Optimization for a single selected element if (startParent && startParent == endParent && (endOffset-startOffset) == 1) { nsCOMPtr<nsIDOMNode> selectedNode = GetChildAt(startParent, startOffset); - if (NS_FAILED(res)) return NS_OK; + NS_ENSURE_SUCCESS(res, NS_OK); if (selectedNode) { selectedNode->GetNodeName(domTagName); @@ -3058,14 +3058,14 @@ nsHTMLEditor::GetSelectedElement(const nsAString& aTagName, nsIDOMElement** aRet // included a collapsed selection (just a caret in a link) nsCOMPtr<nsIDOMNode> anchorNode; res = selection->GetAnchorNode(getter_AddRefs(anchorNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 anchorOffset = -1; if (anchorNode) selection->GetAnchorOffset(&anchorOffset); nsCOMPtr<nsIDOMNode> focusNode; res = selection->GetFocusNode(getter_AddRefs(focusNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 focusOffset = -1; if (focusNode) selection->GetFocusOffset(&focusOffset); @@ -3142,7 +3142,7 @@ nsHTMLEditor::GetSelectedElement(const nsAString& aTagName, nsIDOMElement** aRet nsCOMPtr<nsIDOMRange> currange( do_QueryInterface(currentItem) ); nsCOMPtr<nsIContentIterator> iter = do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); iter->Init(currange); // loop through the content iterator for each content node @@ -3260,15 +3260,15 @@ nsHTMLEditor::CreateElementWithDefaults(const nsAString& aTagName, nsIDOMElement // Note that we read the user's attributes for these from prefs (in InsertHLine JS) res = SetAttributeOrEquivalent(newElement, NS_LITERAL_STRING("width"), NS_LITERAL_STRING("100%"), PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = SetAttributeOrEquivalent(newElement, NS_LITERAL_STRING("size"), NS_LITERAL_STRING("2"), PR_TRUE); } else if (TagName.EqualsLiteral("table")) { res = newElement->SetAttribute(NS_LITERAL_STRING("cellpadding"),NS_LITERAL_STRING("2")); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = newElement->SetAttribute(NS_LITERAL_STRING("cellspacing"),NS_LITERAL_STRING("2")); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = newElement->SetAttribute(NS_LITERAL_STRING("border"),NS_LITERAL_STRING("1")); } else if (TagName.EqualsLiteral("td")) { @@ -3302,7 +3302,7 @@ nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { res = NS_ERROR_NULL_POINTER; } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; PRBool isCollapsed; @@ -3321,7 +3321,7 @@ nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { nsAutoString href; res = anchor->GetHref(href); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!href.IsEmpty()) { nsAutoEditBatch beginBatching(this); @@ -3340,7 +3340,7 @@ nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { nsCOMPtr<nsIDOMNode> attrNode; res = attrMap->Item(i, getter_AddRefs(attrNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (attrNode) { @@ -3353,13 +3353,13 @@ nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) value.Truncate(); res = attribute->GetName(name); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = attribute->GetValue(value); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = SetInlineProperty(nsEditProperty::a, name, value); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -3380,7 +3380,7 @@ nsHTMLEditor::SetHTMLBackgroundColor(const nsAString& aColor) nsAutoString tagName; nsresult res = GetSelectedOrParentTableElement(tagName, &selectedCount, getter_AddRefs(element)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool setColor = !aColor.IsEmpty(); @@ -3447,7 +3447,7 @@ nsHTMLEditor::GetLinkedObjects(nsISupportsArray** aNodeList) nsresult res; res = NS_NewISupportsArray(aNodeList); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!*aNodeList) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIContentIterator> iter = @@ -3769,7 +3769,7 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList) nsresult res; res = NS_NewISupportsArray(aNodeList); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!*aNodeList) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIContentIterator> iter = @@ -3968,7 +3968,7 @@ static nsresult SetSelectionAroundHeadChildren(nsCOMPtr<nsISelection> aSelection nsCOMPtr<nsIDOMNodeList>nodeList; res = doc->GetElementsByTagName(NS_LITERAL_STRING("head"), getter_AddRefs(nodeList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!nodeList) return NS_ERROR_NULL_POINTER; PRUint32 count; @@ -3977,17 +3977,17 @@ static nsresult SetSelectionAroundHeadChildren(nsCOMPtr<nsISelection> aSelection nsCOMPtr<nsIDOMNode> headNode; res = nodeList->Item(0, getter_AddRefs(headNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!headNode) return NS_ERROR_NULL_POINTER; // Collapse selection to before first child of the head, res = aSelection->Collapse(headNode, 0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // then extend it to just after nsCOMPtr<nsIDOMNodeList> childNodes; res = headNode->GetChildNodes(getter_AddRefs(childNodes)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!childNodes) return NS_ERROR_NULL_POINTER; PRUint32 childCount; childNodes->GetLength(&childCount); @@ -4000,14 +4000,14 @@ nsHTMLEditor::GetHeadContentsAsHTML(nsAString& aOutputString) { nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; // Save current selection nsAutoSelectionReset selectionResetter(selection, this); res = SetSelectionAroundHeadChildren(selection, mDocWeak); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = OutputToString(NS_LITERAL_STRING("text/html"), nsIDocumentEncoder::OutputSelectionOnly, @@ -4201,7 +4201,7 @@ nsHTMLEditor::SelectEntireDocument(nsISelection *aSelection) // is doc empty? PRBool bDocIsEmpty; nsresult res = mRules->DocumentIsEmpty(&bDocIsEmpty); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (bDocIsEmpty) { @@ -4481,7 +4481,7 @@ nsHTMLEditor::CollapseAdjacentTextNodes(nsIDOMRange *aInRange) nsresult result; nsCOMPtr<nsIContentIterator> iter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &result); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); iter->Init(aInRange); @@ -4509,15 +4509,15 @@ nsHTMLEditor::CollapseAdjacentTextNodes(nsIDOMRange *aInRange) nsCOMPtr<nsIDOMNode> prevSibOfRightNode; result = rightTextNode->GetPreviousSibling(getter_AddRefs(prevSibOfRightNode)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (prevSibOfRightNode && (prevSibOfRightNode == leftTextNode)) { nsCOMPtr<nsIDOMNode> parent; result = rightTextNode->GetParentNode(getter_AddRefs(parent)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!parent) return NS_ERROR_NULL_POINTER; result = JoinNodes(leftTextNode, rightTextNode, parent); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); } textNodes.RemoveElementAt(0); // remove the leftmost text node from the list @@ -4562,7 +4562,7 @@ nsHTMLEditor::RemoveBlockContainer(nsIDOMNode *inNode) // trailing br. res = GetFirstEditableChild(inNode, address_of(child)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (child) // the case of inNode not being empty { @@ -4573,16 +4573,16 @@ nsHTMLEditor::RemoveBlockContainer(nsIDOMNode *inNode) // 4) either is null res = GetPriorHTMLSibling(inNode, address_of(sibling)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (sibling && !IsBlockNode(sibling) && !nsTextEditUtils::IsBreak(sibling)) { res = GetFirstEditableChild(inNode, address_of(child)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (child && !IsBlockNode(child)) { // insert br node res = CreateBR(inNode, 0, address_of(unused)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -4593,19 +4593,19 @@ nsHTMLEditor::RemoveBlockContainer(nsIDOMNode *inNode) // 4) either is null res = GetNextHTMLSibling(inNode, address_of(sibling)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (sibling && !IsBlockNode(sibling)) { res = GetLastEditableChild(inNode, address_of(child)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (child && !IsBlockNode(child) && !nsTextEditUtils::IsBreak(child)) { // insert br node PRUint32 len; res = GetLengthOfDOMNode(inNode, len); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = CreateBR(inNode, (PRInt32)len, address_of(unused)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -4618,16 +4618,16 @@ nsHTMLEditor::RemoveBlockContainer(nsIDOMNode *inNode) // 4) following sibling of inNode is a br OR // 5) either is null res = GetPriorHTMLSibling(inNode, address_of(sibling)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (sibling && !IsBlockNode(sibling) && !nsTextEditUtils::IsBreak(sibling)) { res = GetNextHTMLSibling(inNode, address_of(sibling)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (sibling && !IsBlockNode(sibling) && !nsTextEditUtils::IsBreak(sibling)) { // insert br node res = CreateBR(inNode, 0, address_of(unused)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -4652,7 +4652,7 @@ nsHTMLEditor::GetPriorHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outN while (1) { res = node->GetPreviousSibling(getter_AddRefs(temp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!temp) return NS_OK; // return null sibling // if it's editable, we're done if (IsEditable(temp)) break; @@ -4704,7 +4704,7 @@ nsHTMLEditor::GetNextHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNo while (1) { res = node->GetNextSibling(getter_AddRefs(temp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!temp) return NS_OK; // return null sibling // if it's editable, we're done if (IsEditable(temp)) break; @@ -4750,7 +4750,7 @@ nsHTMLEditor::GetPriorHTMLNode(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode { if (!outNode) return NS_ERROR_NULL_POINTER; nsresult res = GetPriorNode(inNode, PR_TRUE, address_of(*outNode), bNoBlockCrossing); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if it's not in the body, then zero it out if (*outNode && !nsTextEditUtils::InBody(*outNode, this)) @@ -4769,7 +4769,7 @@ nsHTMLEditor::GetPriorHTMLNode(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr< { if (!outNode) return NS_ERROR_NULL_POINTER; nsresult res = GetPriorNode(inParent, inOffset, PR_TRUE, address_of(*outNode), bNoBlockCrossing); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if it's not in the body, then zero it out if (*outNode && !nsTextEditUtils::InBody(*outNode, this)) @@ -4789,7 +4789,7 @@ nsHTMLEditor::GetNextHTMLNode(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode, { if (!outNode) return NS_ERROR_NULL_POINTER; nsresult res = GetNextNode(inNode, PR_TRUE, address_of(*outNode), bNoBlockCrossing); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if it's not in the body, then zero it out if (*outNode && !nsTextEditUtils::InBody(*outNode, this)) @@ -4808,7 +4808,7 @@ nsHTMLEditor::GetNextHTMLNode(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<n { if (!outNode) return NS_ERROR_NULL_POINTER; nsresult res = GetNextNode(inParent, inOffset, PR_TRUE, address_of(*outNode), bNoBlockCrossing); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if it's not in the body, then zero it out if (*outNode && !nsTextEditUtils::InBody(*outNode, this)) @@ -4831,10 +4831,10 @@ nsHTMLEditor::IsFirstEditableChild( nsIDOMNode *aNode, PRBool *aOutIsFirst) // find first editable child and compare it to aNode nsCOMPtr<nsIDOMNode> parent, firstChild; nsresult res = aNode->GetParentNode(getter_AddRefs(parent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!parent) return NS_ERROR_FAILURE; res = GetFirstEditableChild(parent, address_of(firstChild)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *aOutIsFirst = (firstChild.get() == aNode); return res; @@ -4853,10 +4853,10 @@ nsHTMLEditor::IsLastEditableChild( nsIDOMNode *aNode, PRBool *aOutIsLast) // find last editable child and compare it to aNode nsCOMPtr<nsIDOMNode> parent, lastChild; nsresult res = aNode->GetParentNode(getter_AddRefs(parent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!parent) return NS_ERROR_FAILURE; res = GetLastEditableChild(parent, address_of(lastChild)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *aOutIsLast = (lastChild.get() == aNode); return res; @@ -4875,13 +4875,13 @@ nsHTMLEditor::GetFirstEditableChild( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aO // find first editable child nsCOMPtr<nsIDOMNode> child; nsresult res = aNode->GetFirstChild(getter_AddRefs(child)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); while (child && !IsEditable(child)) { nsCOMPtr<nsIDOMNode> tmp; res = child->GetNextSibling(getter_AddRefs(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!tmp) return NS_ERROR_FAILURE; child = tmp; } @@ -4903,13 +4903,13 @@ nsHTMLEditor::GetLastEditableChild( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOu // find last editable child nsCOMPtr<nsIDOMNode> child; nsresult res = aNode->GetLastChild(getter_AddRefs(child)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); while (child && !IsEditable(child)) { nsCOMPtr<nsIDOMNode> tmp; res = child->GetPreviousSibling(getter_AddRefs(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!tmp) return NS_ERROR_FAILURE; child = tmp; } @@ -4935,7 +4935,7 @@ nsHTMLEditor::GetFirstEditableLeaf( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOu { nsCOMPtr<nsIDOMNode> tmp; res = GetNextHTMLNode(child, address_of(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!tmp) return NS_ERROR_FAILURE; // only accept nodes that are descendants of aNode @@ -4969,7 +4969,7 @@ nsHTMLEditor::GetLastEditableLeaf( nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *aOut { nsCOMPtr<nsIDOMNode> tmp; res = GetPriorHTMLNode(child, address_of(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!tmp) return NS_ERROR_FAILURE; // only accept nodes that are descendants of aNode @@ -5024,7 +5024,7 @@ nsHTMLEditor::IsVisTextNode( nsIDOMNode *aNode, { nsCOMPtr<nsISelectionController> selCon; res = GetSelectionController(getter_AddRefs(selCon)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selCon) return NS_ERROR_FAILURE; PRBool isVisible = PR_FALSE; // ask the selection controller for information about whether any @@ -5034,7 +5034,7 @@ nsHTMLEditor::IsVisTextNode( nsIDOMNode *aNode, // in bed with frames anyway. (this is a fix for bug 22227, and a // partial fix for bug 46209) res = selCon->CheckVisibility(aNode, 0, length, &isVisible); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isVisible) { *outIsEmptyNode = PR_FALSE; @@ -5049,7 +5049,7 @@ nsHTMLEditor::IsVisTextNode( nsIDOMNode *aNode, PRInt32 outVisOffset=0; PRInt16 visType=0; res = wsRunObj.NextVisibleNode(aNode, 0, address_of(visNode), &outVisOffset, &visType); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ( (visType == nsWSRunObject::eNormalWS) || (visType == nsWSRunObject::eText) ) { @@ -5137,7 +5137,7 @@ nsHTMLEditor::IsEmptyNodeImpl( nsIDOMNode *aNode, if (nsEditor::IsTextNode(node)) { res = IsVisTextNode(node, outIsEmptyNode, aSafeToAskFrames); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!*outIsEmptyNode) return NS_OK; // break out if we find we aren't emtpy } else // an editable, non-text node. we need to check it's content. @@ -5172,7 +5172,7 @@ nsHTMLEditor::IsEmptyNodeImpl( nsIDOMNode *aNode, PRBool isEmptyNode = PR_TRUE; res = IsEmptyNodeImpl(node, &isEmptyNode, aSingleBRDoesntCount, aListOrCellNotEmpty, aSafeToAskFrames, aSeenBR); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!isEmptyNode) { // otherwise it ain't empty @@ -5203,13 +5203,13 @@ nsHTMLEditor::SetAttributeOrEquivalent(nsIDOMElement * aElement, PRInt32 count; res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(aElement, nsnull, &aAttribute, &aValue, &count, aSuppressTransaction); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (count) { // we found an equivalence ; let's remove the HTML attribute itself if it is set nsAutoString existingValue; PRBool wasSet = PR_FALSE; res = GetAttributeValue(aElement, aAttribute, existingValue, &wasSet); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (wasSet) { if (aSuppressTransaction) res = aElement->RemoveAttribute(aAttribute); @@ -5227,7 +5227,7 @@ nsHTMLEditor::SetAttributeOrEquivalent(nsIDOMElement * aElement, nsAutoString existingValue; PRBool wasSet = PR_FALSE; res = GetAttributeValue(aElement, NS_LITERAL_STRING("style"), existingValue, &wasSet); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); existingValue.AppendLiteral(" "); existingValue.Append(aValue); if (aSuppressTransaction) @@ -5266,13 +5266,13 @@ nsHTMLEditor::RemoveAttributeOrEquivalent(nsIDOMElement * aElement, if (useCSS && mHTMLCSSUtils) { res = mHTMLCSSUtils->RemoveCSSEquivalentToHTMLStyle(aElement, nsnull, &aAttribute, nsnull, aSuppressTransaction); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } nsAutoString existingValue; PRBool wasSet = PR_FALSE; res = GetAttributeValue(aElement, aAttribute, existingValue, &wasSet); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (wasSet) { if (aSuppressTransaction) res = aElement->RemoveAttribute(aAttribute); @@ -5320,7 +5320,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) nsresult res; nsCOMPtr<nsISelection>selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); @@ -5335,13 +5335,13 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) PRBool cancel, handled; nsTextRulesInfo ruleInfo(nsTextEditRules::kSetTextProperty); res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cancel && !handled) { // get selection range enumerator nsCOMPtr<nsIEnumerator> enumerator; res = selPriv->GetEnumerator(getter_AddRefs(enumerator)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!enumerator) return NS_ERROR_FAILURE; // loop thru the ranges in the selection @@ -5352,7 +5352,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) while ((NS_ENUMERATOR_FALSE == enumerator->IsDone())) { res = enumerator->CurrentItem(getter_AddRefs(currentItem)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!currentItem) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) ); @@ -5361,13 +5361,13 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) nsCOMPtr<nsIDOMNode> startNode, endNode; PRInt32 startOffset, endOffset; res = range->GetStartContainer(getter_AddRefs(startNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndContainer(getter_AddRefs(endNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetStartOffset(&startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndOffset(&endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ((startNode == endNode) && IsTextNode(startNode)) { // let's find the block container of the text node @@ -5380,7 +5380,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) nsCOMPtr<nsIDOMElement> element = do_QueryInterface(blockParent); PRInt32 count; res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(element, nsnull, &bgcolor, &aColor, &count, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } else if ((startNode == endNode) && nsTextEditUtils::IsBody(startNode) && isCollapsed) @@ -5389,7 +5389,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) nsCOMPtr<nsIDOMElement> element = do_QueryInterface(startNode); PRInt32 count; res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(element, nsnull, &bgcolor, &aColor, &count, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else if ((startNode == endNode) && (((endOffset-startOffset) == 1) || (!startOffset && !endOffset))) { @@ -5398,7 +5398,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) nsCOMPtr<nsIDOMNode> selectedNode = GetChildAt(startNode, startOffset); PRBool isBlock =PR_FALSE; res = NodeIsBlockStatic(selectedNode, &isBlock); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> blockParent = selectedNode; if (!isBlock) { blockParent = GetBlockNodeParent(selectedNode); @@ -5409,7 +5409,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) nsCOMPtr<nsIDOMElement> element = do_QueryInterface(blockParent); PRInt32 count; res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(element, nsnull, &bgcolor, &aColor, &count, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } else @@ -5427,7 +5427,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) nsCOMPtr<nsIContentIterator> iter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!iter) return NS_ERROR_FAILURE; nsCOMArray<nsIDOMNode> arrayOfNodes; @@ -5468,7 +5468,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) nsCOMPtr<nsIDOMElement> element = do_QueryInterface(blockParent); PRInt32 count; res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(element, nsnull, &bgcolor, &aColor, &count, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -5481,7 +5481,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) // do we have a block here ? PRBool isBlock =PR_FALSE; res = NodeIsBlockStatic(node, &isBlock); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> blockParent = node; if (!isBlock) { // no we don't, let's find the block ancestor @@ -5494,7 +5494,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) PRInt32 count; // and set the property on it res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(element, nsnull, &bgcolor, &aColor, &count, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } arrayOfNodes.Clear(); @@ -5512,7 +5512,7 @@ nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor) nsCOMPtr<nsIDOMElement> element = do_QueryInterface(blockParent); PRInt32 count; res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(element, nsnull, &bgcolor, &aColor, &count, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -5588,7 +5588,7 @@ nsHTMLEditor::CopyLastEditableChildStyles(nsIDOMNode * aPreviousBlock, nsIDOMNod while (NS_SUCCEEDED(res) && child) { res = DeleteNode(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = aNewBlock->GetFirstChild(getter_AddRefs(child)); } // now find and clone the styles @@ -5597,12 +5597,12 @@ nsHTMLEditor::CopyLastEditableChildStyles(nsIDOMNode * aPreviousBlock, nsIDOMNod while (tmp) { child = tmp; res = GetLastEditableChild(child, address_of(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } while (child && nsTextEditUtils::IsBreak(child)) { nsCOMPtr<nsIDOMNode> priorNode; res = GetPriorHTMLNode(child, address_of(priorNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); child = priorNode; } nsCOMPtr<nsIDOMNode> newStyles = nsnull, deepestStyle = nsnull; @@ -5615,26 +5615,26 @@ nsHTMLEditor::CopyLastEditableChildStyles(nsIDOMNode * aPreviousBlock, nsIDOMNod if (newStyles) { nsCOMPtr<nsIDOMNode> newContainer; res = InsertContainerAbove(newStyles, address_of(newContainer), domTagName); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); newStyles = newContainer; } else { res = CreateNode(domTagName, aNewBlock, 0, getter_AddRefs(newStyles)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); deepestStyle = newStyles; } res = CloneAttributes(newStyles, child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } nsCOMPtr<nsIDOMNode> tmp; res = child->GetParentNode(getter_AddRefs(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); child = tmp; } if (deepestStyle) { nsCOMPtr<nsIDOMNode> outBRNode; res = CreateBR(deepestStyle, 0, address_of(outBRNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Getters must addref *aOutBrNode = outBRNode; NS_ADDREF(*aOutBrNode); @@ -5668,7 +5668,7 @@ nsresult nsHTMLEditor::EndUpdateViewBatch() { nsresult res = nsEditor::EndUpdateViewBatch(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // We may need to show resizing handles or update existing ones after // all transactions are done. This way of doing is preferred to DOM @@ -5679,7 +5679,7 @@ nsHTMLEditor::EndUpdateViewBatch() if (mUpdateCount == 0) { nsCOMPtr<nsISelection> selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NOT_INITIALIZED; res = CheckSelectionStateForAnonymousButtons(selection); } @@ -5703,48 +5703,48 @@ nsHTMLEditor::GetSelectionContainer(nsIDOMElement ** aReturn) PRBool bCollapsed; res = selection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> focusNode; if (bCollapsed) { res = selection->GetFocusNode(getter_AddRefs(focusNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { PRInt32 rangeCount; res = selection->GetRangeCount(&rangeCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (rangeCount == 1) { nsCOMPtr<nsIDOMRange> range; res = selection->GetRangeAt(0, getter_AddRefs(range)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!range) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode> startContainer, endContainer; res = range->GetStartContainer(getter_AddRefs(startContainer)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndContainer(getter_AddRefs(endContainer)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 startOffset, endOffset; res = range->GetStartOffset(&startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndOffset(&endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMElement> focusElement; if (startContainer == endContainer && startOffset + 1 == endOffset) { res = GetSelectedElement(EmptyString(), getter_AddRefs(focusElement)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (focusElement) focusNode = do_QueryInterface(focusElement); } if (!focusNode) { res = range->GetCommonAncestorContainer(getter_AddRefs(focusNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } else { @@ -5753,7 +5753,7 @@ nsHTMLEditor::GetSelectionContainer(nsIDOMElement ** aReturn) for (i = 0; i < rangeCount; i++) { res = selection->GetRangeAt(i, getter_AddRefs(range)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> startContainer; res = range->GetStartContainer(getter_AddRefs(startContainer)); if (NS_FAILED(res)) continue; @@ -5761,7 +5761,7 @@ nsHTMLEditor::GetSelectionContainer(nsIDOMElement ** aReturn) focusNode = startContainer; else if (focusNode != startContainer) { res = startContainer->GetParentNode(getter_AddRefs(focusNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); break; } } @@ -5774,7 +5774,7 @@ nsHTMLEditor::GetSelectionContainer(nsIDOMElement ** aReturn) if (nsIDOMNode::TEXT_NODE == nodeType) { nsCOMPtr<nsIDOMNode> parent; res = focusNode->GetParentNode(getter_AddRefs(parent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); focusNode = parent; } } diff --git a/editor/libeditor/html/nsHTMLEditorEventListener.cpp b/editor/libeditor/html/nsHTMLEditorEventListener.cpp index 40fcce7e9a6..7c1b56f95b4 100644 --- a/editor/libeditor/html/nsHTMLEditorEventListener.cpp +++ b/editor/libeditor/html/nsHTMLEditorEventListener.cpp @@ -102,7 +102,7 @@ nsHTMLEditorEventListener::MouseUp(nsIDOMEvent* aMouseEvent) nsCOMPtr<nsIDOMEventTarget> target; nsresult res = aMouseEvent->GetTarget(getter_AddRefs(target)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!target) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target); @@ -132,14 +132,14 @@ nsHTMLEditorEventListener::MouseDown(nsIDOMEvent* aMouseEvent) // But eDOMEvents_contextmenu and NS_CONTEXTMENU is not exposed in any event interface :-( PRUint16 buttonNumber; nsresult res = mouseEvent->GetButton(&buttonNumber); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool isContextClick; #if defined(XP_MAC) || defined(XP_MACOSX) // Ctrl+Click for context menu res = mouseEvent->GetCtrlKey(&isContextClick); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); #else // Right mouse button for Windows, UNIX isContextClick = buttonNumber == 2; @@ -147,12 +147,12 @@ nsHTMLEditorEventListener::MouseDown(nsIDOMEvent* aMouseEvent) PRInt32 clickCount; res = mouseEvent->GetDetail(&clickCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMEventTarget> target; nsCOMPtr<nsIDOMNSEvent> internalEvent = do_QueryInterface(aMouseEvent); res = internalEvent->GetExplicitOriginalTarget(getter_AddRefs(target)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!target) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target); @@ -170,11 +170,11 @@ nsHTMLEditorEventListener::MouseDown(nsIDOMEvent* aMouseEvent) PRInt32 offset = 0; res = uiEvent->GetRangeParent(getter_AddRefs(parent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!parent) return NS_ERROR_FAILURE; res = uiEvent->GetRangeOffset(&offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Detect if mouse point is within current selection for context click PRBool nodeIsInSelection = PR_FALSE; @@ -186,7 +186,7 @@ nsHTMLEditorEventListener::MouseDown(nsIDOMEvent* aMouseEvent) { PRInt32 rangeCount; res = selection->GetRangeCount(&rangeCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); for (PRInt32 i = 0; i < rangeCount; i++) { @@ -223,7 +223,7 @@ nsHTMLEditorEventListener::MouseDown(nsIDOMEvent* aMouseEvent) // Get enclosing link if in text so we can select the link nsCOMPtr<nsIDOMElement> linkElement; res = htmlEditor->GetElementOrParentByTagName(NS_LITERAL_STRING("href"), node, getter_AddRefs(linkElement)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (linkElement) element = linkElement; } @@ -300,7 +300,7 @@ nsHTMLEditorEventListener::MouseClick(nsIDOMEvent* aMouseEvent) nsCOMPtr<nsIDOMEventTarget> target; nsresult res = aMouseEvent->GetTarget(getter_AddRefs(target)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!target) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target); diff --git a/editor/libeditor/html/nsHTMLEditorLog.cpp b/editor/libeditor/html/nsHTMLEditorLog.cpp index f922529718a..6b4643ef834 100644 --- a/editor/libeditor/html/nsHTMLEditorLog.cpp +++ b/editor/libeditor/html/nsHTMLEditorLog.cpp @@ -845,7 +845,7 @@ nsHTMLEditorLog::StartLogging(nsIFile *aLogFile) } result = NS_NewLocalFileOutputStream(getter_AddRefs(mFileStream), aLogFile); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (mTxnMgr) { diff --git a/editor/libeditor/html/nsHTMLEditorStyle.cpp b/editor/libeditor/html/nsHTMLEditorStyle.cpp index 62ae6d5bc4f..b946b011a49 100644 --- a/editor/libeditor/html/nsHTMLEditorStyle.cpp +++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp @@ -132,7 +132,7 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, nsCOMPtr<nsISelection>selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); @@ -154,13 +154,13 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, PRBool cancel, handled; nsTextRulesInfo ruleInfo(nsTextEditRules::kSetTextProperty); res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cancel && !handled) { // get selection range enumerator nsCOMPtr<nsIEnumerator> enumerator; res = selPriv->GetEnumerator(getter_AddRefs(enumerator)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!enumerator) return NS_ERROR_FAILURE; // loop thru the ranges in the selection @@ -169,21 +169,21 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, while ((NS_ENUMERATOR_FALSE == enumerator->IsDone())) { res = enumerator->CurrentItem(getter_AddRefs(currentItem)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!currentItem) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) ); // adjust range to include any ancestors who's children are entirely selected res = PromoteInlineRange(range); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // check for easy case: both range endpoints in same text node nsCOMPtr<nsIDOMNode> startNode, endNode; res = range->GetStartContainer(getter_AddRefs(startNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndContainer(getter_AddRefs(endNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ((startNode == endNode) && IsTextNode(startNode)) { PRInt32 startOffset, endOffset; @@ -191,7 +191,7 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, range->GetEndOffset(&endOffset); nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(startNode); res = SetInlinePropertyOnTextNode(nodeAsText, startOffset, endOffset, aProperty, &aAttribute, &aValue); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { @@ -208,7 +208,7 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, nsCOMPtr<nsIContentIterator> iter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!iter) return NS_ERROR_FAILURE; nsCOMArray<nsIDOMNode> arrayOfNodes; @@ -247,7 +247,7 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, range->GetStartOffset(&startOffset); nodeAsText->GetLength(&textLen); res = SetInlinePropertyOnTextNode(nodeAsText, startOffset, textLen, aProperty, &aAttribute, &aValue); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // then loop through the list, set the property on each node @@ -257,7 +257,7 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, { node = arrayOfNodes[j]; res = SetInlinePropertyOnNode(node, aProperty, &aAttribute, &aValue); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } arrayOfNodes.Clear(); @@ -270,7 +270,7 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, PRInt32 endOffset; range->GetEndOffset(&endOffset); res = SetInlinePropertyOnTextNode(nodeAsText, 0, endOffset, aProperty, &aAttribute, &aValue); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } enumerator->Next(); @@ -297,7 +297,7 @@ nsHTMLEditor::SetInlinePropertyOnTextNode( nsIDOMCharacterData *aTextNode, if (!aTextNode) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode> parent; nsresult res = aTextNode->GetParentNode(getter_AddRefs(parent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoString tagString; aProperty->ToString(tagString); @@ -340,14 +340,14 @@ nsHTMLEditor::SetInlinePropertyOnTextNode( nsIDOMCharacterData *aTextNode, { // we need to split off back of text node res = SplitNode(node, aEndOffset, getter_AddRefs(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); node = tmp; // remember left node } if ( aStartOffset ) { // we need to split off front of text node res = SplitNode(node, aStartOffset, getter_AddRefs(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // look for siblings that are correct type of node @@ -417,11 +417,11 @@ nsHTMLEditor::SetInlinePropertyOnNode( nsIDOMNode *aNode, // first we have to remove occurences of the same style hint in the // children of the aNode res = RemoveStyleInside(tmp, aProperty, aAttribute, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 count; // then we add the css styles corresponding to the HTML style request res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(element, aProperty, aAttribute, aValue, &count, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> nextSibling, previousSibling; GetNextHTMLSibling(tmp, address_of(nextSibling)); @@ -430,13 +430,13 @@ nsHTMLEditor::SetInlinePropertyOnNode( nsIDOMNode *aNode, { nsCOMPtr<nsIDOMNode> mergeParent; res = tmp->GetParentNode(getter_AddRefs(mergeParent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (previousSibling && nsEditor::NodeIsType(previousSibling, nsEditProperty::span) && NodesSameType(tmp, previousSibling)) { res = JoinNodes(previousSibling, tmp, mergeParent); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (nextSibling && nsEditor::NodeIsType(nextSibling, nsEditProperty::span) && @@ -461,7 +461,7 @@ nsHTMLEditor::SetInlinePropertyOnNode( nsIDOMNode *aNode, // just set the attribute on it. // but first remove any contrary style in it's children. res = RemoveStyleInside(aNode, aProperty, aAttribute, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(aNode); return SetAttribute(elem, *aAttribute, *aValue); } @@ -492,13 +492,13 @@ nsHTMLEditor::SetInlinePropertyOnNode( nsIDOMNode *aNode, // ok, chuck it in it's very own container res = InsertContainerAbove(aNode, address_of(tmp), tag, aAttribute, aValue); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return RemoveStyleInside(aNode, aProperty, aAttribute); } // none of the above? then cycle through the children. nsCOMPtr<nsIDOMNodeList> childNodes; res = aNode->GetChildNodes(getter_AddRefs(childNodes)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (childNodes) { PRInt32 j; @@ -526,7 +526,7 @@ nsHTMLEditor::SetInlinePropertyOnNode( nsIDOMNode *aNode, { node = arrayOfNodes[j]; res = SetInlinePropertyOnNode(node, aProperty, aAttribute, aValue); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } arrayOfNodes.Clear(); } @@ -545,13 +545,13 @@ nsresult nsHTMLEditor::SplitStyleAboveRange(nsIDOMRange *inRange, PRInt32 startOffset, endOffset, origStartOffset; res = inRange->GetStartContainer(getter_AddRefs(startNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetStartOffset(&startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetEndContainer(getter_AddRefs(endNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetEndOffset(&endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); origStartNode = startNode; origStartOffset = startOffset; @@ -560,16 +560,16 @@ nsresult nsHTMLEditor::SplitStyleAboveRange(nsIDOMRange *inRange, { nsAutoTrackDOMPoint tracker(mRangeUpdater, address_of(endNode), &endOffset); res = SplitStyleAbovePoint(address_of(startNode), &startOffset, aProperty, aAttribute); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // second verse, same as the first... res = SplitStyleAbovePoint(address_of(endNode), &endOffset, aProperty, aAttribute); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // reset the range res = inRange->SetStart(startNode, startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->SetEnd(endNode, endOffset); return res; } @@ -643,7 +643,7 @@ nsresult nsHTMLEditor::ApplyDefaultProperties() if (!propItem) return NS_ERROR_NULL_POINTER; res = SetInlineProperty(propItem->tag, propItem->attr, propItem->value); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return res; } @@ -665,7 +665,7 @@ nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode, // cache next sibling since we might remove child child->GetNextSibling(getter_AddRefs(tmp)); res = RemoveStyleInside(child, aProperty, aAttribute); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); child = tmp; } @@ -859,13 +859,13 @@ nsresult nsHTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor(nsIDOMRange *inRa PRInt32 startOffset, endOffset, tmpOffset; res = inRange->GetStartContainer(getter_AddRefs(startNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetStartOffset(&startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetEndContainer(getter_AddRefs(endNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetEndOffset(&endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); tmp = startNode; while ( tmp && @@ -873,14 +873,14 @@ nsresult nsHTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor(nsIDOMRange *inRa !nsHTMLEditUtils::IsNamedAnchor(tmp)) { res = GetNodeLocation(tmp, address_of(parent), &tmpOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); tmp = parent; } if (!tmp) return NS_ERROR_NULL_POINTER; if (nsHTMLEditUtils::IsNamedAnchor(tmp)) { res = GetNodeLocation(tmp, address_of(parent), &tmpOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); startNode = parent; startOffset = tmpOffset; } @@ -891,20 +891,20 @@ nsresult nsHTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor(nsIDOMRange *inRa !nsHTMLEditUtils::IsNamedAnchor(tmp)) { res = GetNodeLocation(tmp, address_of(parent), &tmpOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); tmp = parent; } if (!tmp) return NS_ERROR_NULL_POINTER; if (nsHTMLEditUtils::IsNamedAnchor(tmp)) { res = GetNodeLocation(tmp, address_of(parent), &tmpOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); endNode = parent; endOffset = tmpOffset + 1; } res = inRange->SetStart(startNode, startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->SetEnd(endNode, endOffset); return res; } @@ -917,13 +917,13 @@ nsresult nsHTMLEditor::PromoteInlineRange(nsIDOMRange *inRange) PRInt32 startOffset, endOffset; res = inRange->GetStartContainer(getter_AddRefs(startNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetStartOffset(&startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetEndContainer(getter_AddRefs(endNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->GetEndOffset(&endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); while ( startNode && !nsTextEditUtils::IsBody(startNode) && @@ -931,7 +931,7 @@ nsresult nsHTMLEditor::PromoteInlineRange(nsIDOMRange *inRange) IsAtFrontOfNode(startNode, startOffset) ) { res = GetNodeLocation(startNode, address_of(parent), &startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); startNode = parent; } if (!startNode) return NS_ERROR_NULL_POINTER; @@ -942,14 +942,14 @@ nsresult nsHTMLEditor::PromoteInlineRange(nsIDOMRange *inRange) IsAtEndOfNode(endNode, endOffset) ) { res = GetNodeLocation(endNode, address_of(parent), &endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); endNode = parent; endOffset++; // we are AFTER this node } if (!endNode) return NS_ERROR_NULL_POINTER; res = inRange->SetStart(startNode, startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = inRange->SetEnd(endNode, endOffset); return res; } @@ -1023,7 +1023,7 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty, nsCOMPtr<nsISelection>selection; result = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); @@ -1032,7 +1032,7 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty, nsCOMPtr<nsIDOMNode> collapsedNode; nsCOMPtr<nsIEnumerator> enumerator; result = selPriv->GetEnumerator(getter_AddRefs(enumerator)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!enumerator) return NS_ERROR_NULL_POINTER; enumerator->First(); @@ -1101,9 +1101,9 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty, nsCOMPtr<nsIDOMNode> endNode; PRInt32 endOffset; result = range->GetEndContainer(getter_AddRefs(endNode)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); result = range->GetEndOffset(&endOffset); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); while (!iter->IsDone()) { nsCOMPtr<nsIContent> content = do_QueryInterface(iter->GetCurrentNode()); @@ -1255,7 +1255,7 @@ NS_IMETHODIMP nsHTMLEditor::RemoveAllInlineProperties() nsAutoRules beginRulesSniffing(this, kOpResetTextProperties, nsIEditor::eNext); nsresult res = RemoveInlinePropertyImpl(nsnull, nsnull); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return ApplyDefaultProperties(); } @@ -1272,7 +1272,7 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr nsresult res; nsCOMPtr<nsISelection>selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); @@ -1302,13 +1302,13 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr PRBool cancel, handled; nsTextRulesInfo ruleInfo(nsTextEditRules::kRemoveTextProperty); res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cancel && !handled) { // get selection range enumerator nsCOMPtr<nsIEnumerator> enumerator; res = selPriv->GetEnumerator(getter_AddRefs(enumerator)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!enumerator) return NS_ERROR_FAILURE; // loop thru the ranges in the selection @@ -1317,7 +1317,7 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr while ((NS_ENUMERATOR_FALSE == enumerator->IsDone())) { res = enumerator->CurrentItem(getter_AddRefs(currentItem)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!currentItem) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) ); @@ -1332,19 +1332,19 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr // adjust range to include any ancestors who's children are entirely selected res = PromoteInlineRange(range); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // remove this style from ancestors of our range endpoints, // splitting them as appropriate res = SplitStyleAboveRange(range, aProperty, aAttribute); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // check for easy case: both range endpoints in same text node nsCOMPtr<nsIDOMNode> startNode, endNode; res = range->GetStartContainer(getter_AddRefs(startNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndContainer(getter_AddRefs(endNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ((startNode == endNode) && IsTextNode(startNode)) { // we're done with this range! @@ -1380,7 +1380,7 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr // not the easy case. range not contained in single text node. nsCOMPtr<nsIContentIterator> iter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!iter) return NS_ERROR_FAILURE; nsCOMArray<nsIDOMNode> arrayOfNodes; @@ -1409,7 +1409,7 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr { node = arrayOfNodes[j]; res = RemoveStyleInside(node, aProperty, aAttribute); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (useCSS && mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)) { // the HTML style defined by aProperty/aAttribute has a CSS equivalence // in this implementation for node @@ -1468,13 +1468,13 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) // Get the selection nsCOMPtr<nsISelection>selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); // Is the selection collapsed? PRBool bCollapsed; res = selection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if it's collapsed set typing state if (bCollapsed) @@ -1490,7 +1490,7 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) if (IsTextNode(selectedNode)) { nsCOMPtr<nsIDOMNode> parent; res = selectedNode->GetParentNode(getter_AddRefs(parent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); selectedNode = parent; } nsAutoString tag; @@ -1510,7 +1510,7 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) // get selection range enumerator nsCOMPtr<nsIEnumerator> enumerator; res = selPriv->GetEnumerator(getter_AddRefs(enumerator)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!enumerator) return NS_ERROR_FAILURE; // loop thru the ranges in the selection @@ -1519,21 +1519,21 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) while ((NS_ENUMERATOR_FALSE == enumerator->IsDone())) { res = enumerator->CurrentItem(getter_AddRefs(currentItem)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!currentItem) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) ); // adjust range to include any ancestors who's children are entirely selected res = PromoteInlineRange(range); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // check for easy case: both range endpoints in same text node nsCOMPtr<nsIDOMNode> startNode, endNode; res = range->GetStartContainer(getter_AddRefs(startNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = range->GetEndContainer(getter_AddRefs(endNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if ((startNode == endNode) && IsTextNode(startNode)) { PRInt32 startOffset, endOffset; @@ -1541,7 +1541,7 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) range->GetEndOffset(&endOffset); nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(startNode); res = RelativeFontChangeOnTextNode(aSizeChange, nodeAsText, startOffset, endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { @@ -1558,7 +1558,7 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) nsCOMPtr<nsIContentIterator> iter = do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!iter) return NS_ERROR_FAILURE; nsCOMArray<nsIDOMNode> arrayOfNodes; @@ -1589,7 +1589,7 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) { node = arrayOfNodes[j]; res = RelativeFontChangeOnNode(aSizeChange, node); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } arrayOfNodes.Clear(); } @@ -1604,7 +1604,7 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) range->GetStartOffset(&startOffset); nodeAsText->GetLength(&textLen); res = RelativeFontChangeOnTextNode(aSizeChange, nodeAsText, startOffset, textLen); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (IsTextNode(endNode) && IsEditable(endNode)) { @@ -1612,7 +1612,7 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange) PRInt32 endOffset; range->GetEndOffset(&endOffset); res = RelativeFontChangeOnTextNode(aSizeChange, nodeAsText, 0, endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } enumerator->Next(); @@ -1638,7 +1638,7 @@ nsHTMLEditor::RelativeFontChangeOnTextNode( PRInt32 aSizeChange, nsresult res = NS_OK; nsCOMPtr<nsIDOMNode> parent; res = aTextNode->GetParentNode(getter_AddRefs(parent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!CanContainTag(parent, NS_LITERAL_STRING("big"))) return NS_OK; nsCOMPtr<nsIDOMNode> tmp, node = do_QueryInterface(aTextNode); @@ -1654,14 +1654,14 @@ nsHTMLEditor::RelativeFontChangeOnTextNode( PRInt32 aSizeChange, { // we need to split off back of text node res = SplitNode(node, aEndOffset, getter_AddRefs(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); node = tmp; // remember left node } if ( aStartOffset ) { // we need to split off front of text node res = SplitNode(node, aStartOffset, getter_AddRefs(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } NS_NAMED_LITERAL_STRING(bigSize, "big"); @@ -1721,7 +1721,7 @@ nsHTMLEditor::RelativeFontChangeHelper( PRInt32 aSizeChange, { // cycle through children and adjust relative font size res = aNode->GetChildNodes(getter_AddRefs(childNodes)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (childNodes) { childNodes->GetLength(&childCount); @@ -1731,7 +1731,7 @@ nsHTMLEditor::RelativeFontChangeHelper( PRInt32 aSizeChange, if ((NS_SUCCEEDED(res)) && (childNode)) { res = RelativeFontChangeOnNode(aSizeChange, childNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -1740,7 +1740,7 @@ nsHTMLEditor::RelativeFontChangeHelper( PRInt32 aSizeChange, childNodes = nsnull; // now cycle through the children. res = aNode->GetChildNodes(getter_AddRefs(childNodes)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (childNodes) { childNodes->GetLength(&childCount); @@ -1750,7 +1750,7 @@ nsHTMLEditor::RelativeFontChangeHelper( PRInt32 aSizeChange, if ((NS_SUCCEEDED(res)) && (childNode)) { res = RelativeFontChangeHelper(aSizeChange, childNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -1780,7 +1780,7 @@ nsHTMLEditor::RelativeFontChangeOnNode( PRInt32 aSizeChange, { // first populate any nested font tags that have the size attr set res = RelativeFontChangeHelper(aSizeChange, aNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // in that case, just remove this node and pull up the children res = RemoveContainer(aNode); return res; @@ -1790,7 +1790,7 @@ nsHTMLEditor::RelativeFontChangeOnNode( PRInt32 aSizeChange, { // first populate any nested font tags that have the size attr set res = RelativeFontChangeHelper(aSizeChange, aNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // ok, chuck it in. // first look at siblings of aNode for matching bigs or smalls. // if we find one, move aNode into it. @@ -1820,7 +1820,7 @@ nsHTMLEditor::RelativeFontChangeOnNode( PRInt32 aSizeChange, // each getting their own. nsCOMPtr<nsIDOMNodeList> childNodes; res = aNode->GetChildNodes(getter_AddRefs(childNodes)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (childNodes) { PRInt32 j; @@ -1833,7 +1833,7 @@ nsHTMLEditor::RelativeFontChangeOnNode( PRInt32 aSizeChange, if ((NS_SUCCEEDED(res)) && (childNode)) { res = RelativeFontChangeOnNode(aSizeChange, childNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -1853,7 +1853,7 @@ nsHTMLEditor::GetFontFaceState(PRBool *aMixed, nsAString &outFace) NS_NAMED_LITERAL_STRING(attr, "face"); res = GetInlinePropertyBase(nsEditProperty::font, &attr, nsnull, &first, &any, &all, &outFace); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (any && !all) return res; // mixed if (all) { @@ -1863,7 +1863,7 @@ nsHTMLEditor::GetFontFaceState(PRBool *aMixed, nsAString &outFace) // if there is no font face, check for tt res = GetInlinePropertyBase(nsEditProperty::tt, nsnull, nsnull, &first, &any, &all,nsnull); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (any && !all) return res; // mixed if (all) { @@ -1893,7 +1893,7 @@ nsHTMLEditor::GetFontColorState(PRBool *aMixed, nsAString &aOutColor) PRBool first, any, all; res = GetInlinePropertyBase(nsEditProperty::font, &colorStr, nsnull, &first, &any, &all, &aOutColor); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (any && !all) return res; // mixed if (all) { @@ -1939,10 +1939,10 @@ nsHTMLEditor::HasStyleOrIdOrClass(nsIDOMElement * aElement, PRBool *aHasStyleOrI PRBool isStyleSet; *aHasStyleOrIdOrClass = PR_TRUE; nsresult res = GetAttributeValue(aElement, NS_LITERAL_STRING("style"), styleVal, &isStyleSet); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!isStyleSet || styleVal.IsEmpty()) { res = mHTMLCSSUtils->HasClassOrID(aElement, *aHasStyleOrIdOrClass); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return res; } diff --git a/editor/libeditor/html/nsHTMLInlineTableEditor.cpp b/editor/libeditor/html/nsHTMLInlineTableEditor.cpp index 1f1bc374b44..b57e4945f0d 100644 --- a/editor/libeditor/html/nsHTMLInlineTableEditor.cpp +++ b/editor/libeditor/html/nsHTMLInlineTableEditor.cpp @@ -162,7 +162,7 @@ nsHTMLEditor::DoInlineTableEditingAction(nsIDOMElement * aElement) anonElement) { nsAutoString anonclass; nsresult res = aElement->GetAttribute(NS_LITERAL_STRING("_moz_anonclass"), anonclass); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!StringBeginsWith(anonclass, NS_LITERAL_STRING("mozTable"))) return NS_OK; @@ -171,7 +171,7 @@ nsHTMLEditor::DoInlineTableEditingAction(nsIDOMElement * aElement) nsCOMPtr<nsIDOMElement> tableElement = do_QueryInterface(tableNode); PRInt32 rowCount, colCount; res = GetTableSize(tableElement, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool hideUI = PR_FALSE; PRBool hideResizersWithInlineTableUI = (mResizedObject == tableElement); @@ -239,9 +239,9 @@ nsHTMLEditor::RefreshInlineTableEditingUI() GetElementOrigin(mInlineEditedCell, xCell, yCell); nsresult res = nsElement->GetOffsetWidth(&wCell); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = nsElement->GetOffsetHeight(&hCell); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 xHoriz = xCell + wCell/2; PRInt32 yVert = yCell + hCell/2; @@ -250,7 +250,7 @@ nsHTMLEditor::RefreshInlineTableEditingUI() nsCOMPtr<nsIDOMElement> tableElement = do_QueryInterface(tableNode); PRInt32 rowCount, colCount; res = GetTableSize(tableElement, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); SetAnonymousElementPosition(xHoriz-10, yCell-7, mAddColumnBeforeButton); #ifdef DISABLE_TABLE_DELETION diff --git a/editor/libeditor/html/nsHTMLObjectResizer.cpp b/editor/libeditor/html/nsHTMLObjectResizer.cpp index 74c3a1de894..93c64074971 100644 --- a/editor/libeditor/html/nsHTMLObjectResizer.cpp +++ b/editor/libeditor/html/nsHTMLObjectResizer.cpp @@ -187,7 +187,7 @@ nsHTMLEditor::CreateResizer(nsIDOMElement ** aReturn, PRInt16 aLocation, nsIDOMN PR_FALSE, aReturn); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!*aReturn) return NS_ERROR_FAILURE; @@ -325,9 +325,9 @@ nsHTMLEditor::RefreshResizers() mResizedObjectMarginLeft, mResizedObjectMarginTop); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = SetAllResizersPosition(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return SetShadowPosition(mResizingShadow, mResizedObject, mResizedObjectX, mResizedObjectY); } @@ -360,30 +360,30 @@ nsHTMLEditor::ShowResizersInner(nsIDOMElement *aResizedElement) // The resizers and the shadow will be anonymous siblings of the element. res = CreateResizer(getter_AddRefs(mTopLeftHandle), nsIHTMLObjectResizer::eTopLeft, parentNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = CreateResizer(getter_AddRefs(mTopHandle), nsIHTMLObjectResizer::eTop, parentNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = CreateResizer(getter_AddRefs(mTopRightHandle), nsIHTMLObjectResizer::eTopRight, parentNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = CreateResizer(getter_AddRefs(mLeftHandle), nsIHTMLObjectResizer::eLeft, parentNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = CreateResizer(getter_AddRefs(mRightHandle), nsIHTMLObjectResizer::eRight, parentNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = CreateResizer(getter_AddRefs(mBottomLeftHandle), nsIHTMLObjectResizer::eBottomLeft, parentNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = CreateResizer(getter_AddRefs(mBottomHandle), nsIHTMLObjectResizer::eBottom, parentNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = CreateResizer(getter_AddRefs(mBottomRightHandle), nsIHTMLObjectResizer::eBottomRight, parentNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = GetPositionAndDimensions(aResizedElement, mResizedObjectX, @@ -394,24 +394,24 @@ nsHTMLEditor::ShowResizersInner(nsIDOMElement *aResizedElement) mResizedObjectBorderTop, mResizedObjectMarginLeft, mResizedObjectMarginTop); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // and let's set their absolute positions in the document res = SetAllResizersPosition(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // now, let's create the resizing shadow res = CreateShadow(getter_AddRefs(mResizingShadow), parentNode, aResizedElement); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // and set its position res = SetShadowPosition(mResizingShadow, mResizedObject, mResizedObjectX, mResizedObjectY); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // and then the resizing info tooltip res = CreateResizingInfo(getter_AddRefs(mResizingInfo), parentNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // and listen to the "resize" event on the window first, get the // window from the document... @@ -644,7 +644,7 @@ nsHTMLEditor::MouseDown(PRInt32 aClientX, PRInt32 aClientY, if (anonElement) { nsAutoString anonclass; nsresult res = aTarget->GetAttribute(NS_LITERAL_STRING("_moz_anonclass"), anonclass); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (anonclass.EqualsLiteral("mozResizer")) { // and that element is a resizer, let's start resizing! aEvent->PreventDefault(); @@ -749,11 +749,11 @@ nsHTMLEditor::SetResizingInfoPosition(PRInt32 aX, PRInt32 aY, PRInt32 aW, PRInt3 nsCOMPtr<nsIDOMNode> textInfo; nsresult res = mResizingInfo->GetFirstChild(getter_AddRefs(textInfo)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> junk; if (textInfo) { res = mResizingInfo->RemoveChild(textInfo, getter_AddRefs(junk)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); textInfo = nsnull; junk = nsnull; } @@ -777,10 +777,10 @@ nsHTMLEditor::SetResizingInfoPosition(PRInt32 aX, PRInt32 aY, PRInt32 aW, PRInt3 nsCOMPtr<nsIDOMText> nodeAsText; res = domdoc->CreateTextNode(info, getter_AddRefs(nodeAsText)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); textInfo = do_QueryInterface(nodeAsText); res = mResizingInfo->AppendChild(textInfo, getter_AddRefs(junk)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool hasClass = PR_FALSE; if (NS_SUCCEEDED(mResizingInfo->HasAttribute(NS_LITERAL_STRING("class"), &hasClass )) && hasClass) @@ -801,9 +801,9 @@ nsHTMLEditor::SetShadowPosition(nsIDOMElement * aShadow, nsAutoString imageSource; nsresult res = aOriginalObject->GetAttribute(NS_LITERAL_STRING("src"), imageSource); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = aShadow->SetAttribute(NS_LITERAL_STRING("src"), imageSource); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return NS_OK; } diff --git a/editor/libeditor/html/nsTableEditor.cpp b/editor/libeditor/html/nsTableEditor.cpp index 3feac934eaf..86099c0173c 100644 --- a/editor/libeditor/html/nsTableEditor.cpp +++ b/editor/libeditor/html/nsTableEditor.cpp @@ -130,13 +130,13 @@ nsHTMLEditor::InsertCell(nsIDOMElement *aCell, PRInt32 aRowSpan, PRInt32 aColSpa // And the parent and offsets needed to do an insert nsCOMPtr<nsIDOMNode> cellParent; nsresult res = aCell->GetParentNode(getter_AddRefs(cellParent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cellParent) return NS_ERROR_NULL_POINTER; PRInt32 cellOffset; res = GetChildOffset(aCell, cellParent, cellOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMElement> newCell; if (aIsHeader) @@ -207,7 +207,7 @@ nsHTMLEditor::InsertTableCell(PRInt32 aNumber, PRBool aAfter) getter_AddRefs(curCell), getter_AddRefs(cellParent), &cellOffset, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if no cell found if (!curCell) return NS_EDITOR_ELEMENT_NOT_FOUND; @@ -218,7 +218,7 @@ nsHTMLEditor::InsertTableCell(PRInt32 aNumber, PRBool aAfter) getter_AddRefs(curCell), &curStartRowIndex, &curStartColIndex, &rowSpan, &colSpan, &actualRowSpan, &actualColSpan, &isSelected); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!curCell) return NS_ERROR_FAILURE; PRInt32 newCellIndex = aAfter ? (startColIndex+colSpan) : startColIndex; //We control selection resetting after the insert... @@ -253,12 +253,12 @@ nsHTMLEditor::GetFirstRow(nsIDOMElement* aTableElement, nsIDOMNode** aRowNode) nsCOMPtr<nsIDOMElement> tableElement; nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), aTableElement, getter_AddRefs(tableElement)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!tableElement) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode> tableChild; res = tableElement->GetFirstChild(getter_AddRefs(tableChild)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); while (tableChild) { @@ -281,14 +281,14 @@ nsHTMLEditor::GetFirstRow(nsIDOMElement* aTableElement, nsIDOMNode** aRowNode) { nsCOMPtr<nsIDOMNode> rowNode; res = tableChild->GetFirstChild(getter_AddRefs(rowNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // We can encounter textnodes here -- must find a row while (rowNode && !nsHTMLEditUtils::IsTableRow(rowNode)) { nsCOMPtr<nsIDOMNode> nextNode; res = rowNode->GetNextSibling(getter_AddRefs(nextNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); rowNode = nextNode; } @@ -306,7 +306,7 @@ nsHTMLEditor::GetFirstRow(nsIDOMElement* aTableElement, nsIDOMNode** aRowNode) // Look in next table child nsCOMPtr<nsIDOMNode> nextChild; res = tableChild->GetNextSibling(getter_AddRefs(nextChild)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); tableChild = nextChild; }; @@ -328,7 +328,7 @@ nsHTMLEditor::GetNextRow(nsIDOMNode* aCurrentRowNode, nsIDOMNode **aRowNode) nsCOMPtr<nsIDOMNode> nextRow; nsresult res = aCurrentRowNode->GetNextSibling(getter_AddRefs(nextRow)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> nextNode; @@ -336,7 +336,7 @@ nsHTMLEditor::GetNextRow(nsIDOMNode* aCurrentRowNode, nsIDOMNode **aRowNode) while (nextRow && !nsHTMLEditUtils::IsTableRow(nextRow)) { res = nextRow->GetNextSibling(getter_AddRefs(nextNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nextRow = nextNode; } @@ -350,23 +350,23 @@ nsHTMLEditor::GetNextRow(nsIDOMNode* aCurrentRowNode, nsIDOMNode **aRowNode) // No row found, search for rows in other table sections nsCOMPtr<nsIDOMNode> rowParent; res = aCurrentRowNode->GetParentNode(getter_AddRefs(rowParent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!rowParent) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIDOMNode> parentSibling; res = rowParent->GetNextSibling(getter_AddRefs(parentSibling)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); while (parentSibling) { res = parentSibling->GetFirstChild(getter_AddRefs(nextRow)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // We can encounter textnodes here -- must find a row while (nextRow && !nsHTMLEditUtils::IsTableRow(nextRow)) { res = nextRow->GetNextSibling(getter_AddRefs(nextNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nextRow = nextNode; } @@ -383,7 +383,7 @@ nsHTMLEditor::GetNextRow(nsIDOMNode* aCurrentRowNode, nsIDOMNode **aRowNode) // or first child of section is not a row (bad HTML or more "_moz_text" nodes!) // So look for another section sibling res = parentSibling->GetNextSibling(getter_AddRefs(nextNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); parentSibling = nextNode; } @@ -402,14 +402,14 @@ nsHTMLEditor::GetLastCellInRow(nsIDOMNode* aRowNode, nsIDOMNode** aCellNode) nsCOMPtr<nsIDOMNode> rowChild; nsresult res = aRowNode->GetLastChild(getter_AddRefs(rowChild)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); while (rowChild && !nsHTMLEditUtils::IsTableCell(rowChild)) { // Skip over textnodes nsCOMPtr<nsIDOMNode> previousChild; res = rowChild->GetPreviousSibling(getter_AddRefs(previousChild)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); rowChild = previousChild; }; @@ -435,7 +435,7 @@ nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) getter_AddRefs(curCell), nsnull, nsnull, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if no cell found if (!curCell) return NS_EDITOR_ELEMENT_NOT_FOUND; @@ -447,7 +447,7 @@ nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) &curStartRowIndex, &curStartColIndex, &rowSpan, &colSpan, &actualRowSpan, &actualColSpan, &isSelected); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!curCell) return NS_ERROR_FAILURE; nsAutoEditBatch beginBatching(this); @@ -468,7 +468,7 @@ nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) PRInt32 rowCount, colCount, rowIndex; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); //We reset caret in destructor... nsSetSelectionAfterTableEdit setCaret(this, table, startRowIndex, startColIndex, ePreviousRow, PR_FALSE); @@ -497,7 +497,7 @@ nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) &curStartRowIndex, &curStartColIndex, &rowSpan, &colSpan, &actualRowSpan, &actualColSpan, &isSelected); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail entire process if we fail to find a cell // (may fail just in particular rows with < adequate cells per row) @@ -529,13 +529,13 @@ nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) res = GetNextRow(rowNode.get(), getter_AddRefs(nextRow)); rowNode = nextRow; } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (rowNode) { nsCOMPtr<nsIDOMNode> lastCell; res = GetLastCellInRow(rowNode, getter_AddRefs(lastCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!lastCell) return NS_ERROR_FAILURE; curCell = do_QueryInterface(lastCell); @@ -568,7 +568,7 @@ nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter) getter_AddRefs(curCell), nsnull, nsnull, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if no cell found if (!curCell) return NS_EDITOR_ELEMENT_NOT_FOUND; @@ -580,12 +580,12 @@ nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter) &curStartRowIndex, &curStartColIndex, &rowSpan, &colSpan, &actualRowSpan, &actualColSpan, &isSelected); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!curCell) return NS_ERROR_FAILURE; PRInt32 rowCount, colCount; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoEditBatch beginBatching(this); // Prevent auto insertion of BR in new cell until we're done @@ -690,14 +690,14 @@ nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter) { nsCOMPtr<nsIDOMElement> parentRow; res = GetElementOrParentByTagName(trStr, cellForRowParent, getter_AddRefs(parentRow)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!parentRow) return NS_ERROR_NULL_POINTER; parentRow->GetParentNode(getter_AddRefs(parentOfRow)); if (!parentOfRow) return NS_ERROR_NULL_POINTER; res = GetChildOffset(parentRow, parentOfRow, newRowOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Adjust for when adding past the end if (aAfter && startRowIndex >= rowCount) @@ -719,18 +719,18 @@ nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter) { nsCOMPtr<nsIDOMElement> newCell; res = CreateElementWithDefaults(NS_LITERAL_STRING("td"), getter_AddRefs(newCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!newCell) return NS_ERROR_FAILURE; // Don't use transaction system yet! (not until entire row is inserted) nsCOMPtr<nsIDOMNode>resultNode; res = newRow->AppendChild(newCell, getter_AddRefs(resultNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // Use transaction system to insert the entire row+cells // (Note that rows are inserted at same childoffset each time) res = InsertNode(newRow, parentOfRow, newRowOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -749,7 +749,7 @@ nsHTMLEditor::DeleteTable2(nsIDOMElement *aTable, nsISelection *aSelection) nsresult res = ClearSelection(); if (NS_SUCCEEDED(res)) res = AppendNodeToSelectionAsRange(aTable); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); return DeleteSelection(nsIEditor::eNext); } @@ -763,7 +763,7 @@ nsHTMLEditor::DeleteTable() getter_AddRefs(table), nsnull, nsnull, nsnull, nsnull, nsnull); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsAutoEditBatch beginBatching(this); return DeleteTable2(table, selection); @@ -784,7 +784,7 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) nsnull, nsnull, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if we didn't find a table or cell if (!table || !cell) return NS_EDITOR_ELEMENT_NOT_FOUND; @@ -795,11 +795,11 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) nsCOMPtr<nsIDOMElement> firstCell; nsCOMPtr<nsIDOMRange> range; res = GetFirstSelectedCell(getter_AddRefs(range), getter_AddRefs(firstCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 rangeCount; res = selection->GetRangeCount(&rangeCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (firstCell && rangeCount > 1) { @@ -809,11 +809,11 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) PRInt32 rowCount, colCount; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Get indexes -- may be different than original cell res = GetCellIndexes(cell, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // The setCaret object will call SetSelectionAfterTableEdit in it's destructor nsSetSelectionAfterTableEdit setCaret(this, table, startRowIndex, startColIndex, ePreviousColumn, PR_FALSE); @@ -841,14 +841,14 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) while (nextRow == startRowIndex) { res = GetNextSelectedCell(nsnull, getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cell) break; res = GetCellIndexes(cell, &nextRow, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // Delete entire row res = DeleteRow(table, startRowIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (cell) { @@ -876,14 +876,14 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) while (nextCol == startColIndex) { res = GetNextSelectedCell(nsnull, getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cell) break; res = GetCellIndexes(cell, &startRowIndex, &nextCol); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // Delete entire Col res = DeleteColumn(table, startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (cell) { // For the next cell, subtract 1 for col. deleted @@ -898,18 +898,18 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) // First get the next cell to delete nsCOMPtr<nsIDOMElement> nextCell; res = GetNextSelectedCell(getter_AddRefs(range), getter_AddRefs(nextCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Then delete the cell res = DeleteNode(cell); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // The next cell to delete cell = nextCell; if (cell) { res = GetCellIndexes(cell, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -922,7 +922,7 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) getter_AddRefs(cell), nsnull, nsnull, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if no cell found if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND; @@ -930,7 +930,7 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) { nsCOMPtr<nsIDOMElement> parentRow; res = GetElementOrParentByTagName(NS_LITERAL_STRING("tr"), cell, getter_AddRefs(parentRow)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!parentRow) return NS_ERROR_NULL_POINTER; // We should delete the row instead, @@ -938,14 +938,14 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) // so we can delete the entire table PRInt32 rowCount, colCount; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (rowCount == 1) return DeleteTable2(table, selection); // We need to call DeleteTableRow to handle cells with rowspan res = DeleteTableRow(1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else { @@ -957,7 +957,7 @@ nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) res = DeleteNode(cell); // If we fail, don't try to delete any more cells??? - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } return NS_OK; @@ -976,7 +976,7 @@ nsHTMLEditor::DeleteTableCellContents() getter_AddRefs(cell), nsnull, nsnull, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if no cell found if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND; @@ -991,14 +991,14 @@ nsHTMLEditor::DeleteTableCellContents() nsCOMPtr<nsIDOMElement> firstCell; nsCOMPtr<nsIDOMRange> range; res = GetFirstSelectedCell(getter_AddRefs(range), getter_AddRefs(firstCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (firstCell) { cell = firstCell; res = GetCellIndexes(cell, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } nsSetSelectionAfterTableEdit setCaret(this, table, startRowIndex, startColIndex, ePreviousColumn, PR_FALSE); @@ -1010,7 +1010,7 @@ nsHTMLEditor::DeleteTableCellContents() { // We doing a selected cells, so do all of them res = GetNextSelectedCell(nsnull, getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else cell = nsnull; @@ -1034,7 +1034,7 @@ nsHTMLEditor::DeleteCellContents(nsIDOMElement *aCell) { aCell->GetLastChild(getter_AddRefs(child)); nsresult res = DeleteNode(child); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aCell->HasChildNodes(&hasChild); } return NS_OK; @@ -1052,12 +1052,12 @@ nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber) getter_AddRefs(cell), nsnull, nsnull, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if no cell found if (!table || !cell) return NS_EDITOR_ELEMENT_NOT_FOUND; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Shortcut the case of deleting all columns in table if(startColIndex == 0 && aNumber >= colCount) @@ -1074,17 +1074,17 @@ nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber) nsCOMPtr<nsIDOMElement> firstCell; nsCOMPtr<nsIDOMRange> range; res = GetFirstSelectedCell(getter_AddRefs(range), getter_AddRefs(firstCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 rangeCount; res = selection->GetRangeCount(&rangeCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (firstCell && rangeCount > 1) { // Fetch indexes again - may be different for selected cells res = GetCellIndexes(firstCell, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } //We control selection resetting after the insert... nsSetSelectionAfterTableEdit setCaret(this, table, startRowIndex, startColIndex, ePreviousRow, PR_FALSE); @@ -1099,7 +1099,7 @@ nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber) if (cell != firstCell) { res = GetCellIndexes(cell, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // Find the next cell in a different column // to continue after we delete this column @@ -1107,19 +1107,19 @@ nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber) while (nextCol == startColIndex) { res = GetNextSelectedCell(getter_AddRefs(range), getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cell) break; res = GetCellIndexes(cell, &startRowIndex, &nextCol); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } res = DeleteColumn(table, startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } else for (PRInt32 i = 0; i < aNumber; i++) { res = DeleteColumn(table, startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return NS_OK; } @@ -1141,7 +1141,7 @@ nsHTMLEditor::DeleteColumn(nsIDOMElement *aTable, PRInt32 aColIndex) &startRowIndex, &startColIndex, &rowSpan, &colSpan, &actualRowSpan, &actualColSpan, &isSelected); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (cell) { @@ -1174,7 +1174,7 @@ nsHTMLEditor::DeleteColumn(nsIDOMElement *aTable, PRInt32 aColIndex) // Only 1 cell in row - delete the row nsCOMPtr<nsIDOMElement> parentRow; res = GetElementOrParentByTagName(NS_LITERAL_STRING("tr"), cell, getter_AddRefs(parentRow)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if(!parentRow) return NS_ERROR_NULL_POINTER; // But first check if its the only row left @@ -1182,13 +1182,13 @@ nsHTMLEditor::DeleteColumn(nsIDOMElement *aTable, PRInt32 aColIndex) // (This should never happen but it's the safe thing to do) PRInt32 rowCount, colCount; res = GetTableSize(aTable, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (rowCount == 1) { nsCOMPtr<nsISelection> selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; return DeleteTable2(aTable, selection); } @@ -1196,7 +1196,7 @@ nsHTMLEditor::DeleteColumn(nsIDOMElement *aTable, PRInt32 aColIndex) // Delete the row by placing caret in cell we were to delete // We need to call DeleteTableRow to handle cells with rowspan res = DeleteRow(aTable, startRowIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Note that we don't incremenet rowIndex // since a row was deleted and "next" @@ -1206,7 +1206,7 @@ nsHTMLEditor::DeleteColumn(nsIDOMElement *aTable, PRInt32 aColIndex) { // A more "normal" deletion res = DeleteNode(cell); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); //Skip over any rows spanned by this cell rowIndex += actualRowSpan; @@ -1231,12 +1231,12 @@ nsHTMLEditor::DeleteTableRow(PRInt32 aNumber) getter_AddRefs(cell), nsnull, nsnull, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if no cell found if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Shortcut the case of deleting all rows in table if(startRowIndex == 0 && aNumber >= rowCount) @@ -1249,17 +1249,17 @@ nsHTMLEditor::DeleteTableRow(PRInt32 aNumber) nsCOMPtr<nsIDOMElement> firstCell; nsCOMPtr<nsIDOMRange> range; res = GetFirstSelectedCell(getter_AddRefs(range), getter_AddRefs(firstCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 rangeCount; res = selection->GetRangeCount(&rangeCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (firstCell && rangeCount > 1) { // Fetch indexes again - may be different for selected cells res = GetCellIndexes(firstCell, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } //We control selection resetting after the insert... @@ -1277,7 +1277,7 @@ nsHTMLEditor::DeleteTableRow(PRInt32 aNumber) if (cell != firstCell) { res = GetCellIndexes(cell, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // Find the next cell in a different row // to continue after we delete this row @@ -1285,14 +1285,14 @@ nsHTMLEditor::DeleteTableRow(PRInt32 aNumber) while (nextRow == startRowIndex) { res = GetNextSelectedCell(getter_AddRefs(range), getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cell) break; res = GetCellIndexes(cell, &nextRow, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // Delete entire row res = DeleteRow(table, startRowIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } else @@ -1309,7 +1309,7 @@ nsHTMLEditor::DeleteTableRow(PRInt32 aNumber) // Check if there's a cell in the "next" row res = GetCellAt(table, startRowIndex, startColIndex, getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if(!cell) break; } @@ -1377,7 +1377,7 @@ nsHTMLEditor::DeleteRow(nsIDOMElement *aTable, PRInt32 aRowIndex) res = SplitCellIntoRows(aTable, startRowIndex, startColIndex, aRowIndex - startRowIndex + 1, // The row above the row to insert new cell into actualRowSpan - 1, nsnull); // Span remaining below - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (!cellInDeleteRow) cellInDeleteRow = cell; // Reference cell to find row to delete @@ -1394,12 +1394,12 @@ nsHTMLEditor::DeleteRow(nsIDOMElement *aTable, PRInt32 aRowIndex) // Delete the entire row nsCOMPtr<nsIDOMElement> parentRow; res = GetElementOrParentByTagName(NS_LITERAL_STRING("tr"), cellInDeleteRow, getter_AddRefs(parentRow)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (parentRow) { res = DeleteNode(parentRow); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // Now we can set new rowspans for cells stored above @@ -1409,7 +1409,7 @@ nsHTMLEditor::DeleteRow(nsIDOMElement *aTable, PRInt32 aRowIndex) if (cellPtr) { res = SetRowSpan(cellPtr, newSpanList[i]); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } return NS_OK; @@ -1422,7 +1422,7 @@ nsHTMLEditor::SelectTable() nsCOMPtr<nsIDOMElement> table; nsresult res = NS_ERROR_FAILURE; res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), nsnull, getter_AddRefs(table)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if we didn't find a table if (!table) return NS_OK; @@ -1438,7 +1438,7 @@ nsHTMLEditor::SelectTableCell() { nsCOMPtr<nsIDOMElement> cell; nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND; res = ClearSelection(); @@ -1455,18 +1455,18 @@ nsHTMLEditor::SelectBlockOfCells(nsIDOMElement *aStartCell, nsIDOMElement *aEndC nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; NS_NAMED_LITERAL_STRING(tableStr, "table"); nsCOMPtr<nsIDOMElement> table; res = GetElementOrParentByTagName(tableStr, aStartCell, getter_AddRefs(table)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!table) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMElement> endTable; res = GetElementOrParentByTagName(tableStr, aEndCell, getter_AddRefs(endTable)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!endTable) return NS_ERROR_FAILURE; // We can only select a block if within the same table, @@ -1497,13 +1497,13 @@ nsHTMLEditor::SelectBlockOfCells(nsIDOMElement *aStartCell, nsIDOMElement *aEndC PRInt32 currentRowIndex, currentColIndex; nsCOMPtr<nsIDOMRange> range; res = GetFirstSelectedCell(getter_AddRefs(range), getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (res == NS_EDITOR_ELEMENT_NOT_FOUND) return NS_OK; while (cell) { res = GetCellIndexes(cell, ¤tRowIndex, ¤tColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (currentRowIndex < maxRow || currentRowIndex > maxRow || currentColIndex < maxColumn || currentColIndex > maxColumn) @@ -1513,7 +1513,7 @@ nsHTMLEditor::SelectBlockOfCells(nsIDOMElement *aStartCell, nsIDOMElement *aEndC mSelectedCellIndex--; } res = GetNextSelectedCell(getter_AddRefs(range), getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } PRInt32 rowSpan, colSpan, actualRowSpan, actualColSpan; @@ -1543,7 +1543,7 @@ nsHTMLEditor::SelectAllTableCells() { nsCOMPtr<nsIDOMElement> cell; nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if we didn't find a cell if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND; @@ -1553,16 +1553,16 @@ nsHTMLEditor::SelectAllTableCells() // Get parent table nsCOMPtr<nsIDOMElement> table; res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), cell, getter_AddRefs(table)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if(!table) return NS_ERROR_NULL_POINTER; PRInt32 rowCount, colCount; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsISelection> selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; // Suppress nsISelectionListener notification @@ -1608,7 +1608,7 @@ nsHTMLEditor::SelectTableRow() { nsCOMPtr<nsIDOMElement> cell; nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if we didn't find a cell if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND; @@ -1624,12 +1624,12 @@ nsHTMLEditor::SelectTableRow() getter_AddRefs(cell), nsnull, nsnull, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!table) return NS_ERROR_FAILURE; PRInt32 rowCount, colCount; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); //Note: At this point, we could get first and last cells in row, // then call SelectBlockOfCells, but that would take just @@ -1674,7 +1674,7 @@ nsHTMLEditor::SelectTableColumn() { nsCOMPtr<nsIDOMElement> cell; nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("td"), nsnull, getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if we didn't find a cell if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND; @@ -1691,12 +1691,12 @@ nsHTMLEditor::SelectTableColumn() getter_AddRefs(cell), nsnull, nsnull, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!table) return NS_ERROR_FAILURE; PRInt32 rowCount, colCount; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Suppress nsISelectionListener notification // until all selection changes are finished @@ -1744,12 +1744,12 @@ nsHTMLEditor::SplitTableCell() getter_AddRefs(cell), nsnull, nsnull, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if(!table || !cell) return NS_EDITOR_ELEMENT_NOT_FOUND; // We need rowspan and colspan data res = GetCellSpansAt(table, startRowIndex, startColIndex, actualRowSpan, actualColSpan); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Must have some span to split if (actualRowSpan <= 1 && actualColSpan <= 1) @@ -1776,7 +1776,7 @@ nsHTMLEditor::SplitTableCell() if (rowSpanBelow > 0) { res = SplitCellIntoRows(table, rowIndex, startColIndex, 1, rowSpanBelow, getter_AddRefs(newCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); CopyCellBackgroundColor(newCell, cell); } PRInt32 colIndex = startColIndex; @@ -1784,7 +1784,7 @@ nsHTMLEditor::SplitTableCell() for (colSpanAfter = actualColSpan-1; colSpanAfter > 0; colSpanAfter--) { res = SplitCellIntoColumns(table, rowIndex, colIndex, 1, colSpanAfter, getter_AddRefs(newCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); CopyCellBackgroundColor(newCell, cell); colIndex++; } @@ -1826,7 +1826,7 @@ nsHTMLEditor::SplitCellIntoColumns(nsIDOMElement *aTable, PRInt32 aRowIndex, PRI &startRowIndex, &startColIndex, &rowSpan, &colSpan, &actualRowSpan, &actualColSpan, &isSelected); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cell) return NS_ERROR_NULL_POINTER; // We can't split! @@ -1835,13 +1835,13 @@ nsHTMLEditor::SplitCellIntoColumns(nsIDOMElement *aTable, PRInt32 aRowIndex, PRI // Reduce colspan of cell to split res = SetColSpan(cell, aColSpanLeft); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Insert new cell after using the remaining span // and always get the new cell so we can copy the background color; nsCOMPtr<nsIDOMElement> newCell; res = InsertCell(cell, actualRowSpan, aColSpanRight, PR_TRUE, PR_FALSE, getter_AddRefs(newCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (newCell) { if (aNewCell) @@ -1869,7 +1869,7 @@ nsHTMLEditor::SplitCellIntoRows(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt3 &startRowIndex, &startColIndex, &rowSpan, &colSpan, &actualRowSpan, &actualColSpan, &isSelected); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cell) return NS_ERROR_NULL_POINTER; // We can't split! @@ -1878,7 +1878,7 @@ nsHTMLEditor::SplitCellIntoRows(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt3 PRInt32 rowCount, colCount; res = GetTableSize(aTable, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMElement> cell2; nsCOMPtr<nsIDOMElement> lastCellFound; @@ -1948,14 +1948,14 @@ nsHTMLEditor::SplitCellIntoRows(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt3 // Reduce rowspan of cell to split res = SetRowSpan(cell, aRowSpanAbove); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Insert new cell after using the remaining span // and always get the new cell so we can copy the background color; nsCOMPtr<nsIDOMElement> newCell; res = InsertCell(cell2, aRowSpanBelow, actualColSpan, insertAfter, PR_FALSE, getter_AddRefs(newCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (newCell) { if (aNewCell) @@ -1984,7 +1984,7 @@ nsHTMLEditor::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElemen // when replacing nodes nsCOMPtr<nsISelection>selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; nsAutoSelectionReset selectionResetter(selection, this); @@ -1995,7 +1995,7 @@ nsHTMLEditor::SwitchTableCellHeaderType(nsIDOMElement *aSourceCell, nsIDOMElemen // This creates new node, moves children, copies attributes (PR_TRUE) // and manages the selection! res = ReplaceContainer(aSourceCell, address_of(newNode), newCellType, nsnull, nsnull, PR_TRUE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!newNode) return NS_ERROR_FAILURE; // Return the new cell @@ -2026,7 +2026,7 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) getter_AddRefs(targetCell), nsnull, nsnull, &startRowIndex, &startColIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if(!table || !targetCell) return NS_EDITOR_ELEMENT_NOT_FOUND; nsAutoEditBatch beginBatching(this); @@ -2040,14 +2040,14 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) nsCOMPtr<nsIDOMElement> firstCell; PRInt32 firstRowIndex, firstColIndex; res = GetFirstSelectedCellInTable(&firstRowIndex, &firstColIndex, getter_AddRefs(firstCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool joinSelectedCells = PR_FALSE; if (firstCell) { nsCOMPtr<nsIDOMElement> secondCell; res = GetNextSelectedCell(nsnull, getter_AddRefs(secondCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // If only one cell is selected, join with cell to the right joinSelectedCells = (secondCell != nsnull); @@ -2060,12 +2060,12 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) PRInt32 rowCount, colCount; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Get spans for cell we will merge into PRInt32 firstRowSpan, firstColSpan; res = GetCellSpansAt( table, firstRowIndex, firstColIndex, firstRowSpan, firstColSpan); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // This defines the last indexes along the "edges" // of the contiguous block of cells, telling us @@ -2084,7 +2084,7 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) PRInt32 currentRowCount = rowCount; // Be sure each row doesn't have rowspan errors res = FixBadRowSpan(table, rowIndex, rowCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Adjust rowcount by number of rows we removed lastRowIndex -= (currentRowCount-rowCount); @@ -2098,7 +2098,7 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) &startRowIndex2, &startColIndex2, &rowSpan2, &colSpan2, &actualRowSpan2, &actualColSpan2, &isSelected2); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isSelected2) { @@ -2186,7 +2186,7 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) &startRowIndex2, &startColIndex2, &rowSpan2, &colSpan2, &actualRowSpan2, &actualColSpan2, &isSelected2); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // If this is 0, we are past last cell in row, so exit the loop if (actualColSpan2 == 0) @@ -2213,12 +2213,12 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) { res = SplitCellIntoColumns(table, startRowIndex2, startColIndex2, actualColSpan2-extraColSpan, extraColSpan, nsnull); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } res = MergeCells(firstCell, cell2, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Add cell to list to delete deleteList.AppendElement(cell2.get()); @@ -2227,7 +2227,7 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) { // Cell is outside join region -- just merge the contents res = MergeCells(firstCell, cell2, PR_FALSE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } } @@ -2244,25 +2244,25 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) { nsCOMPtr<nsIDOMNode> node = do_QueryInterface(elementPtr); res = DeleteNode(node); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } // Cleanup selection: remove ranges where cells were deleted nsCOMPtr<nsISelection> selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; PRInt32 rangeCount; res = selection->GetRangeCount(&rangeCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMRange> range; PRInt32 i; for (i = 0; i < rangeCount; i++) { res = selection->GetRangeAt(i, getter_AddRefs(range)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!range) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMElement> deletedCell; @@ -2277,9 +2277,9 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) // Set spans for the cell everthing merged into res = SetRowSpan(firstCell, lastRowIndex-firstRowIndex+1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = SetColSpan(firstCell, lastColIndex-firstColIndex+1); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Fixup disturbances in table layout @@ -2291,14 +2291,14 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) res = GetCellDataAt(table, startRowIndex, startColIndex, getter_AddRefs(targetCell), &startRowIndex, &startColIndex, &rowSpan, &colSpan, &actualRowSpan, &actualColSpan, &isSelected); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!targetCell) return NS_ERROR_NULL_POINTER; // Get data for cell to the right res = GetCellDataAt(table, startRowIndex, startColIndex+actualColSpan, getter_AddRefs(cell2), &startRowIndex2, &startColIndex2, &rowSpan2, &colSpan2, &actualRowSpan2, &actualColSpan2, &isSelected2); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if(!cell2) return NS_OK; // Don't fail if there's no cell // sanity check @@ -2316,7 +2316,7 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) res = SplitCellIntoRows(table, startRowIndex2, startColIndex2, spanAboveMergedCell+actualRowSpan, effectiveRowSpan2-actualRowSpan, nsnull); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // Move contents from cell to the right @@ -2325,7 +2325,7 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) res = MergeCells(targetCell, cell2, (startRowIndex2 == startRowIndex) && (effectiveRowSpan2 >= actualRowSpan)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (effectiveRowSpan2 < actualRowSpan) { @@ -2341,12 +2341,12 @@ nsHTMLEditor::JoinTableCells(PRBool aMergeNonContiguousContents) // Cell we merged started in a row above the target cell // Reduce rowspan to give room where target cell will extend it's colspan res = SetRowSpan(cell2, spanAboveMergedCell); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // Reset target cell's colspan to encompass cell to the right res = SetColSpan(targetCell, actualColSpan+actualColSpan2); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return res; } @@ -2379,15 +2379,15 @@ nsHTMLEditor::MergeCells(nsCOMPtr<nsIDOMElement> aTargetCell, // Start inserting just after last child PRUint32 len; res = childNodes->GetLength(&len); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (len == 1 && IsEmptyCell(aTargetCell)) { // Delete the empty node nsCOMPtr<nsIDOMNode> tempNode; res = childNodes->Item(0, getter_AddRefs(cellChild)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = DeleteNode(cellChild); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); insertIndex = 0; } else @@ -2401,10 +2401,10 @@ nsHTMLEditor::MergeCells(nsCOMPtr<nsIDOMElement> aTargetCell, { aCellToMerge->GetLastChild(getter_AddRefs(cellChild)); res = DeleteNode(cellChild); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = InsertNode(cellChild, aTargetCell, insertIndex); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aCellToMerge->HasChildNodes(&hasChild); } @@ -2425,7 +2425,7 @@ nsHTMLEditor::FixBadRowSpan(nsIDOMElement *aTable, PRInt32 aRowIndex, PRInt32& a PRInt32 rowCount, colCount; nsresult res = GetTableSize(aTable, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMElement>cell; PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan; @@ -2483,7 +2483,7 @@ nsHTMLEditor::FixBadColSpan(nsIDOMElement *aTable, PRInt32 aColIndex, PRInt32& a PRInt32 rowCount, colCount; nsresult res = GetTableSize(aTable, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMElement> cell; PRInt32 startRowIndex, startColIndex, rowSpan, colSpan, actualRowSpan, actualColSpan; @@ -2539,18 +2539,18 @@ nsHTMLEditor::NormalizeTable(nsIDOMElement *aTable) { nsCOMPtr<nsISelection>selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMElement> table; res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), aTable, getter_AddRefs(table)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't fail if we didn't find a table if (!table) return NS_OK; PRInt32 rowCount, colCount, rowIndex, colIndex; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Save current selection nsAutoSelectionReset selectionResetter(selection, this); @@ -2567,13 +2567,13 @@ nsHTMLEditor::NormalizeTable(nsIDOMElement *aTable) for(rowIndex = 0; rowIndex < rowCount; rowIndex++) { res = FixBadRowSpan(table, rowIndex, rowCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // and same for colspans for(colIndex = 0; colIndex < colCount; colIndex++) { res = FixBadColSpan(table, colIndex, colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // Fill in missing cellmap locations with empty cells @@ -2600,7 +2600,7 @@ nsHTMLEditor::NormalizeTable(nsIDOMElement *aTable) { // Insert a new cell after (PR_TRUE), and return the new cell to us res = InsertCell(previousCellInRow, 1, 1, PR_TRUE, PR_FALSE, getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Set this so we use returned new "cell" to set previousCellInRow below if(cell) @@ -2690,7 +2690,7 @@ PRBool nsHTMLEditor::GetNumberOfCellsInRow(nsIDOMElement* aTable, PRInt32 rowInd res = GetCellDataAt(aTable, rowIndex, colIndex, getter_AddRefs(cell), &startRowIndex, &startColIndex, &rowSpan, &colSpan, &actualRowSpan, &actualColSpan, &isSelected); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (cell) { // Only count cells that start in row we are working with @@ -2723,13 +2723,13 @@ nsHTMLEditor::GetTableSize(nsIDOMElement *aTable, nsCOMPtr<nsIDOMElement> table; // Get the selected talbe or the table enclosing the selection anchor res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), aTable, getter_AddRefs(table)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!table) return NS_ERROR_FAILURE; // frames are not ref counted, so don't use an nsCOMPtr nsITableLayout *tableLayoutObject; res = GetTableLayoutObject(table.get(), &tableLayoutObject); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!tableLayoutObject) return NS_ERROR_FAILURE; @@ -2769,7 +2769,7 @@ nsHTMLEditor::GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, // Get the selected table or the table enclosing the selection anchor nsCOMPtr<nsIDOMElement> table; res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), nsnull, getter_AddRefs(table)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (table) aTable = table; else @@ -2779,7 +2779,7 @@ nsHTMLEditor::GetCellDataAt(nsIDOMElement* aTable, PRInt32 aRowIndex, // frames are not ref counted, so don't use an nsCOMPtr nsITableLayout *tableLayoutObject; res = GetTableLayoutObject(aTable, &tableLayoutObject); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!tableLayoutObject) return NS_ERROR_FAILURE; // Note that this returns NS_TABLELAYOUT_CELL_NOT_FOUND when @@ -2843,7 +2843,7 @@ nsHTMLEditor::GetCellContext(nsISelection **aSelection, nsCOMPtr <nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; if (aSelection) @@ -2869,7 +2869,7 @@ nsHTMLEditor::GetCellContext(nsISelection **aSelection, nsAutoString tagName; res = GetSelectedOrParentTableElement(tagName, &selectedCount, getter_AddRefs(cellOrTableElement)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (tagName.EqualsLiteral("table")) { // We have a selected table, not a cell @@ -2894,7 +2894,7 @@ nsHTMLEditor::GetCellContext(nsISelection **aSelection, // Get containing table res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), cell, getter_AddRefs(table)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Cell must be in a table, so fail if not found if (!table) return NS_ERROR_FAILURE; if (aTable) @@ -2918,7 +2918,7 @@ nsHTMLEditor::GetCellContext(nsISelection **aSelection, nsCOMPtr <nsIDOMNode> cellParent; // Get the immediate parent of the cell res = cell->GetParentNode(getter_AddRefs(cellParent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Cell has to have a parent, so fail if not found if (!cellParent) return NS_ERROR_FAILURE; @@ -2943,12 +2943,12 @@ nsHTMLEditor::GetCellFromRange(nsIDOMRange *aRange, nsIDOMElement **aCell) nsCOMPtr<nsIDOMNode> startParent; nsresult res = aRange->GetStartContainer(getter_AddRefs(startParent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!startParent) return NS_ERROR_FAILURE; PRInt32 startOffset; res = aRange->GetStartOffset(&startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> childNode = GetChildAt(startParent, startOffset); // This means selection is probably at a text node (or end of doc?) @@ -2956,12 +2956,12 @@ nsHTMLEditor::GetCellFromRange(nsIDOMRange *aRange, nsIDOMElement **aCell) nsCOMPtr<nsIDOMNode> endParent; res = aRange->GetEndContainer(getter_AddRefs(endParent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!startParent) return NS_ERROR_FAILURE; PRInt32 endOffset; res = aRange->GetEndOffset(&endOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // If a cell is deleted, the range is collapse // (startOffset == endOffset) @@ -2989,12 +2989,12 @@ nsHTMLEditor::GetFirstSelectedCell(nsIDOMRange **aRange, nsIDOMElement **aCell) nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMRange> range; res = selection->GetRangeAt(0, getter_AddRefs(range)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!range) return NS_ERROR_FAILURE; mSelectedCellIndex = 0; @@ -3002,7 +3002,7 @@ nsHTMLEditor::GetFirstSelectedCell(nsIDOMRange **aRange, nsIDOMElement **aCell) res = GetCellFromRange(range, aCell); // Failure here probably means selection is in a text node, // so there's no selected cell - if (NS_FAILED(res)) return NS_EDITOR_ELEMENT_NOT_FOUND; + NS_ENSURE_SUCCESS(res, NS_EDITOR_ELEMENT_NOT_FOUND); // No cell means range was collapsed (cell was deleted) if (!*aCell) return NS_EDITOR_ELEMENT_NOT_FOUND; @@ -3027,12 +3027,12 @@ nsHTMLEditor::GetNextSelectedCell(nsIDOMRange **aRange, nsIDOMElement **aCell) nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; PRInt32 rangeCount; res = selection->GetRangeCount(&rangeCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Don't even try if index exceeds range count if (mSelectedCellIndex >= rangeCount) @@ -3043,12 +3043,12 @@ nsHTMLEditor::GetNextSelectedCell(nsIDOMRange **aRange, nsIDOMElement **aCell) for (; mSelectedCellIndex < rangeCount; mSelectedCellIndex++) { res = selection->GetRangeAt(mSelectedCellIndex, getter_AddRefs(range)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!range) return NS_ERROR_FAILURE; res = GetCellFromRange(range, aCell); // Failure here means the range doesn't contain a cell - if (NS_FAILED(res)) return NS_EDITOR_ELEMENT_NOT_FOUND; + NS_ENSURE_SUCCESS(res, NS_EDITOR_ELEMENT_NOT_FOUND); // We found a selected cell if (*aCell) break; @@ -3086,7 +3086,7 @@ nsHTMLEditor::GetFirstSelectedCellInTable(PRInt32 *aRowIndex, PRInt32 *aColIndex nsCOMPtr<nsIDOMElement> cell; nsresult res = GetFirstSelectedCell(nsnull, getter_AddRefs(cell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cell) return NS_EDITOR_ELEMENT_NOT_FOUND; *aCell = cell.get(); @@ -3117,7 +3117,7 @@ nsHTMLEditor::SetSelectionAfterTableEdit(nsIDOMElement* aTable, PRInt32 aRow, PR nsCOMPtr<nsISelection>selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) { @@ -3213,13 +3213,13 @@ nsHTMLEditor::GetSelectedOrParentTableElement(nsAString& aTagName, nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_FAILURE; // Try to get the first selected cell nsCOMPtr<nsIDOMElement> tableOrCellElement; res = GetFirstSelectedCell(nsnull, getter_AddRefs(tableOrCellElement)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); NS_NAMED_LITERAL_STRING(tdName, "td"); @@ -3228,7 +3228,7 @@ nsHTMLEditor::GetSelectedOrParentTableElement(nsAString& aTagName, // Each cell is in its own selection range, // so count signals multiple-cell selection res = selection->GetRangeCount(aSelectedCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); aTagName = tdName; } else @@ -3248,7 +3248,7 @@ nsHTMLEditor::GetSelectedOrParentTableElement(nsAString& aTagName, { PRInt32 anchorOffset; res = selection->GetAnchorOffset(&anchorOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); selectedNode = GetChildAt(anchorNode, anchorOffset); if (!selectedNode) { @@ -3267,7 +3267,7 @@ nsHTMLEditor::GetSelectedOrParentTableElement(nsAString& aTagName, // Each cell is in its own selection range, // so count signals multiple-cell selection res = selection->GetRangeCount(aSelectedCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else if (atom == nsEditProperty::table) { @@ -3311,16 +3311,16 @@ nsHTMLEditor::GetSelectedCellsType(nsIDOMElement *aElement, PRUint32 *aSelection nsCOMPtr<nsIDOMElement> table; nsresult res = GetElementOrParentByTagName(NS_LITERAL_STRING("table"), aElement, getter_AddRefs(table)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRInt32 rowCount, colCount; res = GetTableSize(table, &rowCount, &colCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // Traverse all selected cells nsCOMPtr<nsIDOMElement> selectedCell; res = GetFirstSelectedCell(nsnull, getter_AddRefs(selectedCell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (res == NS_EDITOR_ELEMENT_NOT_FOUND) return NS_OK; // We have at least one selected cell, so set return value @@ -3398,7 +3398,7 @@ nsHTMLEditor::AllCellsInRowSelected(nsIDOMElement *aTable, PRInt32 aRowIndex, PR &rowSpan, &colSpan, &actualRowSpan, &actualColSpan, &isSelected); - if (NS_FAILED(res)) return PR_FALSE; + NS_ENSURE_SUCCESS(res, PR_FALSE); // If no cell, we may have a "ragged" right edge, // so return TRUE only if we already found a cell in the row if (!cell) return (col > 0) ? PR_TRUE : PR_FALSE; @@ -3428,7 +3428,7 @@ nsHTMLEditor::AllCellsInColumnSelected(nsIDOMElement *aTable, PRInt32 aColIndex, &rowSpan, &colSpan, &actualRowSpan, &actualColSpan, &isSelected); - if (NS_FAILED(res)) return PR_FALSE; + NS_ENSURE_SUCCESS(res, PR_FALSE); // If no cell, we must have a "ragged" right edge on the last column // so return TRUE only if we already found a cell in the row if (!cell) return (row > 0) ? PR_TRUE : PR_FALSE; @@ -3447,13 +3447,13 @@ nsHTMLEditor::IsEmptyCell(nsIDOMElement *aCell) // Check if target only contains empty text node or <br> nsresult res = aCell->GetFirstChild(getter_AddRefs(cellChild)); - if (NS_FAILED(res)) return PR_FALSE; + NS_ENSURE_SUCCESS(res, PR_FALSE); if (cellChild) { nsCOMPtr<nsIDOMNode> nextChild; res = cellChild->GetNextSibling(getter_AddRefs(nextChild)); - if (NS_FAILED(res)) return PR_FALSE; + NS_ENSURE_SUCCESS(res, PR_FALSE); if (!nextChild) { // We insert a single break into a cell by default @@ -3463,7 +3463,7 @@ nsHTMLEditor::IsEmptyCell(nsIDOMElement *aCell) if (!isEmpty) { res = IsEmptyNode(cellChild, &isEmpty, PR_FALSE, PR_FALSE); - if (NS_FAILED(res)) return PR_FALSE; + NS_ENSURE_SUCCESS(res, PR_FALSE); } return isEmpty; diff --git a/editor/libeditor/text/nsPlaintextDataTransfer.cpp b/editor/libeditor/text/nsPlaintextDataTransfer.cpp index bff9bef8e04..08988b721ff 100644 --- a/editor/libeditor/text/nsPlaintextDataTransfer.cpp +++ b/editor/libeditor/text/nsPlaintextDataTransfer.cpp @@ -158,7 +158,7 @@ NS_IMETHODIMP nsPlaintextEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) nsresult rv; nsCOMPtr<nsIDragService> dragService = do_GetService("@mozilla.org/widget/dragservice;1", &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIDragSession> dragSession; dragService->GetCurrentSession(getter_AddRefs(dragSession)); @@ -167,17 +167,17 @@ NS_IMETHODIMP nsPlaintextEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) // Current doc is destination nsCOMPtr<nsIDOMDocument> destdomdoc; rv = GetDocument(getter_AddRefs(destdomdoc)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Get the nsITransferable interface for getting the data from the drop nsCOMPtr<nsITransferable> trans; rv = PrepareTransferable(getter_AddRefs(trans)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!trans) return NS_OK; // NS_ERROR_FAILURE; SHOULD WE FAIL? PRUint32 numItems = 0; rv = dragSession->GetNumDropItems(&numItems); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (numItems < 1) return NS_ERROR_FAILURE; // nothing to drop? // Combine any deletion and drop insertion into one transaction @@ -192,21 +192,21 @@ NS_IMETHODIMP nsPlaintextEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) nsCOMPtr<nsIDOMNode> newSelectionParent; rv = nsuiEvent->GetRangeParent(getter_AddRefs(newSelectionParent)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!newSelectionParent) return NS_ERROR_FAILURE; PRInt32 newSelectionOffset; rv = nsuiEvent->GetRangeOffset(&newSelectionOffset); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISelection> selection; rv = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!selection) return NS_ERROR_FAILURE; PRBool isCollapsed; rv = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Check if mouse is in the selection // if so, jump through some hoops to determine if mouse is over selection (bail) @@ -218,7 +218,7 @@ NS_IMETHODIMP nsPlaintextEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) PRInt32 rangeCount; rv = selection->GetRangeCount(&rangeCount); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); for (PRInt32 j = 0; j < rangeCount; j++) { @@ -237,7 +237,7 @@ NS_IMETHODIMP nsPlaintextEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) // Current doc is destination (set earlier) nsCOMPtr<nsIDOMDocument> srcdomdoc; rv = dragSession->GetSourceDocument(getter_AddRefs(srcdomdoc)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (cursorIsInSelection) { @@ -289,7 +289,7 @@ NS_IMETHODIMP nsPlaintextEditor::InsertFromDrop(nsIDOMEvent* aDropEvent) for (i = 0; i < numItems; ++i) { rv = dragSession->GetData(trans, i); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!trans) return NS_OK; // NS_ERROR_FAILURE; Should we fail? // Beware! This may flush notifications via synchronous @@ -320,11 +320,11 @@ NS_IMETHODIMP nsPlaintextEditor::CanDrag(nsIDOMEvent *aDragEvent, PRBool *aCanDr nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool isCollapsed; res = selection->GetIsCollapsed(&isCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // if we are collapsed, we have no selection so nothing to drag if ( isCollapsed ) @@ -335,7 +335,7 @@ NS_IMETHODIMP nsPlaintextEditor::CanDrag(nsIDOMEvent *aDragEvent, PRBool *aCanDr nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aDragEvent)); if (nsevent) { res = nsevent->GetTmpRealOriginalTarget(getter_AddRefs(eventTarget)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (eventTarget) @@ -345,7 +345,7 @@ NS_IMETHODIMP nsPlaintextEditor::CanDrag(nsIDOMEvent *aDragEvent, PRBool *aCanDr { PRBool isTargetedCorrectly = PR_FALSE; res = selection->ContainsNode(eventTargetDomNode, PR_FALSE, &isTargetedCorrectly); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *aCanDrag = isTargetedCorrectly; } @@ -360,13 +360,13 @@ NS_IMETHODIMP nsPlaintextEditor::DoDrag(nsIDOMEvent *aDragEvent) nsCOMPtr<nsITransferable> trans; rv = PutDragDataInTransferable(getter_AddRefs(trans)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!trans) return NS_OK; // maybe there was nothing to copy? /* get the drag service */ nsCOMPtr<nsIDragService> dragService = do_GetService("@mozilla.org/widget/dragservice;1", &rv); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); /* create an array of transferables */ nsCOMPtr<nsISupportsArray> transferableArray; @@ -376,7 +376,7 @@ NS_IMETHODIMP nsPlaintextEditor::DoDrag(nsIDOMEvent *aDragEvent) /* add the transferable to the array */ rv = transferableArray->AppendElement(trans); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // check our transferable hooks (if any) nsCOMPtr<nsIDOMDocument> domdoc; @@ -385,13 +385,13 @@ NS_IMETHODIMP nsPlaintextEditor::DoDrag(nsIDOMEvent *aDragEvent) /* invoke drag */ nsCOMPtr<nsIDOMEventTarget> eventTarget; rv = aDragEvent->GetTarget(getter_AddRefs(eventTarget)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIDOMNode> domnode = do_QueryInterface(eventTarget); nsCOMPtr<nsIScriptableRegion> selRegion; nsCOMPtr<nsISelection> selection; rv = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); unsigned int flags; // in some cases we'll want to cut rather than copy... hmmmmm... @@ -400,7 +400,7 @@ NS_IMETHODIMP nsPlaintextEditor::DoDrag(nsIDOMEvent *aDragEvent) nsCOMPtr<nsIDOMDragEvent> dragEvent(do_QueryInterface(aDragEvent)); rv = dragService->InvokeDragSessionWithSelection(selection, transferableArray, flags, dragEvent, nsnull); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); aDragEvent->StopPropagation(); aDragEvent->PreventDefault(); @@ -472,7 +472,7 @@ NS_IMETHODIMP nsPlaintextEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPa nsresult rv; nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // the flavors that we can deal with const char* textEditorFlavors[] = { kUnicodeMime }; @@ -481,7 +481,7 @@ NS_IMETHODIMP nsPlaintextEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPa rv = clipboard->HasDataMatchingFlavors(textEditorFlavors, NS_ARRAY_LENGTH(textEditorFlavors), aSelectionType, &haveFlavors); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); *aCanPaste = haveFlavors; return NS_OK; @@ -523,7 +523,7 @@ nsPlaintextEditor::SetupDocEncoder(nsIDocumentEncoder **aDocEncoder) { nsCOMPtr<nsIDOMDocument> domDoc; nsresult rv = GetDocument(getter_AddRefs(domDoc)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // find out if we're a plaintext control or not // get correct mimeType and document encoder flags set @@ -543,15 +543,15 @@ nsPlaintextEditor::SetupDocEncoder(nsIDocumentEncoder **aDocEncoder) return NS_ERROR_OUT_OF_MEMORY; rv = encoder->Init(domDoc, mimeType, docEncoderFlags); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); /* get the selection to be dragged */ nsCOMPtr<nsISelection> selection; rv = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); rv = encoder->SetSelection(selection); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); *aDocEncoder = encoder; NS_ADDREF(*aDocEncoder); @@ -564,12 +564,12 @@ nsPlaintextEditor::PutDragDataInTransferable(nsITransferable **aTransferable) *aTransferable = nsnull; nsCOMPtr<nsIDocumentEncoder> docEncoder; nsresult rv = SetupDocEncoder(getter_AddRefs(docEncoder)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // grab a string nsAutoString buffer; rv = docEncoder->EncodeToString(buffer); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // if we have an empty string, we're done; otherwise continue if (buffer.IsEmpty()) @@ -580,7 +580,7 @@ nsPlaintextEditor::PutDragDataInTransferable(nsITransferable **aTransferable) NS_ENSURE_SUCCESS(rv, rv); rv = dataWrapper->SetData(buffer); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); /* create html flavor transferable */ nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv); @@ -591,18 +591,18 @@ nsPlaintextEditor::PutDragDataInTransferable(nsITransferable **aTransferable) { // Add the unicode flavor to the transferable rv = trans->AddDataFlavor(kUnicodeMime); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } else { rv = trans->AddDataFlavor(kHTMLMime); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIFormatConverter> htmlConverter = do_CreateInstance("@mozilla.org/widget/htmlformatconverter;1"); NS_ENSURE_TRUE(htmlConverter, NS_ERROR_FAILURE); rv = trans->SetConverter(htmlConverter); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } // QI the data object an |nsISupports| so that when the transferable holds @@ -610,7 +610,7 @@ nsPlaintextEditor::PutDragDataInTransferable(nsITransferable **aTransferable) nsCOMPtr<nsISupports> nsisupportsDataWrapper = do_QueryInterface(dataWrapper); rv = trans->SetTransferData(IsPlaintextEditor() ? kUnicodeMime : kHTMLMime, nsisupportsDataWrapper, buffer.Length() * sizeof(PRUnichar)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); *aTransferable = trans; NS_ADDREF(*aTransferable); diff --git a/editor/libeditor/text/nsPlaintextEditor.cpp b/editor/libeditor/text/nsPlaintextEditor.cpp index 74769c61046..6b7a254e836 100644 --- a/editor/libeditor/text/nsPlaintextEditor.cpp +++ b/editor/libeditor/text/nsPlaintextEditor.cpp @@ -167,7 +167,7 @@ NS_IMETHODIMP nsPlaintextEditor::Init(nsIDOMDocument *aDoc, // and "caret behaviour in selection" prefs GetDefaultEditorPrefs(mNewlineHandling, mCaretStyle); - if (NS_FAILED(rulesRes)) return rulesRes; + NS_ENSURE_SUCCESS(rulesRes, rulesRes); return res; } @@ -331,7 +331,7 @@ NS_IMETHODIMP nsPlaintextEditor::InitRules() { // instantiate the rules for this text editor nsresult res = NS_NewTextEditRules(getter_AddRefs(mRules)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!mRules) return NS_ERROR_UNEXPECTED; return mRules->Init(this); } @@ -483,20 +483,20 @@ NS_IMETHODIMP nsPlaintextEditor::CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent { // split the text node res = SplitNode(node, theOffset, getter_AddRefs(tmp)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = GetNodeLocation(node, address_of(tmp), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // create br res = CreateNode(brType, tmp, offset, getter_AddRefs(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); *aInOutParent = tmp; *aInOutOffset = offset+1; } else { res = CreateNode(brType, node, theOffset, getter_AddRefs(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); (*aInOutOffset)++; } @@ -506,11 +506,11 @@ NS_IMETHODIMP nsPlaintextEditor::CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent nsCOMPtr<nsIDOMNode> parent; PRInt32 offset; res = GetNodeLocation(*outBRNode, address_of(parent), &offset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsISelection> selection; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); if (aSelect == eNext) { @@ -546,26 +546,26 @@ NS_IMETHODIMP nsPlaintextEditor::InsertBR(nsCOMPtr<nsIDOMNode> *outBRNode) nsCOMPtr<nsISelection> selection; nsresult res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRBool bCollapsed; res = selection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bCollapsed) { res = DeleteSelection(nsIEditor::eNone); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } nsCOMPtr<nsIDOMNode> selNode; PRInt32 selOffset; res = GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = CreateBR(selNode, selOffset, outBRNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // position selection after br res = GetNodeLocation(*outBRNode, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection)); selPriv->SetInterlinePosition(PR_TRUE); return selection->Collapse(selNode, selOffset+1); @@ -661,7 +661,7 @@ nsPlaintextEditor::ExtendSelectionForDelete(nsISelection *aSelection, PRBool bCollapsed; result = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (*aAction == eNextWord || *aAction == ePreviousWord || (*aAction == eNext && bCollapsed) @@ -748,7 +748,7 @@ NS_IMETHODIMP nsPlaintextEditor::DeleteSelection(nsIEditor::EDirection aAction) // pre-process nsCOMPtr<nsISelection> selection; result = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; // If there is an existing selection when an extended delete is requested, @@ -758,7 +758,7 @@ NS_IMETHODIMP nsPlaintextEditor::DeleteSelection(nsIEditor::EDirection aAction) // existing selection without extending it. PRBool bCollapsed; result = selection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!bCollapsed && (aAction == eNextWord || aAction == ePreviousWord || aAction == eToBeginningOfLine || aAction == eToEndOfLine)) @@ -766,7 +766,7 @@ NS_IMETHODIMP nsPlaintextEditor::DeleteSelection(nsIEditor::EDirection aAction) if (mCaretStyle == 1) { result = selection->CollapseToStart(); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); } else { @@ -778,7 +778,7 @@ NS_IMETHODIMP nsPlaintextEditor::DeleteSelection(nsIEditor::EDirection aAction) ruleInfo.collapsedAction = aAction; PRBool cancel, handled; result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!cancel && !handled) { result = DeleteSelectionImpl(aAction); @@ -812,7 +812,7 @@ NS_IMETHODIMP nsPlaintextEditor::InsertText(const nsAString &aStringToInsert) // pre-process nsCOMPtr<nsISelection> selection; nsresult result = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!selection) return NS_ERROR_NULL_POINTER; nsAutoString resultString; // XXX can we trust instring to outlive ruleInfo, @@ -825,7 +825,7 @@ NS_IMETHODIMP nsPlaintextEditor::InsertText(const nsAString &aStringToInsert) PRBool cancel, handled; result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); if (!cancel && !handled) { // we rely on rules code for now - no default implementation @@ -852,20 +852,20 @@ NS_IMETHODIMP nsPlaintextEditor::InsertLineBreak() nsCOMPtr<nsISelection> selection; nsresult res; res = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!selection) return NS_ERROR_NULL_POINTER; // Batching the selection and moving nodes out from under the caret causes // caret turds. Ask the shell to invalidate the caret now to avoid the turds. nsCOMPtr<nsIPresShell> shell; res = GetPresShell(getter_AddRefs(shell)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); shell->MaybeInvalidateCaretPosition(); nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertBreak); PRBool cancel, handled; res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!cancel && !handled) { // create the new BR node @@ -1073,7 +1073,7 @@ nsPlaintextEditor::SetWrapWidth(PRInt32 aWrapColumn) NS_NAMED_LITERAL_STRING(styleName, "style"); nsAutoString styleValue; nsresult res = rootElement->GetAttribute(styleName, styleValue); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // We'll replace styles for these values: CutStyle("white-space", styleValue); @@ -1282,7 +1282,7 @@ nsPlaintextEditor::GetAndInitDocEncoder(const nsAString& aFormatType, { nsCOMPtr<nsIPresShell> presShell; nsresult rv = GetPresShell(getter_AddRefs(presShell)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!presShell) return NS_ERROR_FAILURE; nsCAutoString formatType(NS_DOC_ENCODER_CONTRACTID_BASE); @@ -1385,7 +1385,7 @@ nsPlaintextEditor::OutputToStream(nsIOutputStream* aOutputStream, { PRBool docEmpty; rv = GetDocumentIsEmpty(&docEmpty); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (docEmpty) return NS_OK; // output nothing @@ -1420,7 +1420,7 @@ nsPlaintextEditor::PasteAsQuotation(PRInt32 aSelectionType) // Get Clipboard Service nsresult rv; nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); // Create generic Transferable for getting the data nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv); @@ -1491,7 +1491,7 @@ nsPlaintextEditor::InsertAsQuotation(const nsAString& aQuotedText, // get selection nsCOMPtr<nsISelection> selection; rv = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!selection) return NS_ERROR_NULL_POINTER; nsAutoEditBatch beginBatching(this); @@ -1501,7 +1501,7 @@ nsPlaintextEditor::InsertAsQuotation(const nsAString& aQuotedText, nsTextRulesInfo ruleInfo(nsTextEditRules::kInsertElement); PRBool cancel, handled; rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (cancel) return NS_OK; // rules canceled the operation if (!handled) { @@ -1575,17 +1575,17 @@ nsPlaintextEditor::Rewrap(PRBool aRespectNewlines) rv = SharedOutputString(nsIDocumentEncoder::OutputFormatted | nsIDocumentEncoder::OutputLFLineBreak, &isCollapsed, current); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsICiter> citer = new nsInternetCiter(); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (!citer) return NS_ERROR_UNEXPECTED; nsString wrapped; PRUint32 firstLineOffset = 0; // XXX need to reset this if there is a selection rv = citer->Rewrap(current, wrapCol, firstLineOffset, aRespectNewlines, wrapped); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (isCollapsed) // rewrap the whole document SelectAll(); @@ -1604,19 +1604,19 @@ nsPlaintextEditor::StripCites() PRBool isCollapsed; nsresult rv = SharedOutputString(nsIDocumentEncoder::OutputFormatted, &isCollapsed, current); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsICiter> citer = new nsInternetCiter(); if (!citer) return NS_ERROR_UNEXPECTED; nsString stripped; rv = citer->StripCites(current, stripped); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); if (isCollapsed) // rewrap the whole document { rv = SelectAll(); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); } return InsertText(stripped); @@ -1652,7 +1652,7 @@ nsPlaintextEditor::SetCompositionString(const nsAString& aCompositionString, nsCOMPtr<nsISelection> selection; nsresult result = GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(result)) return result; + NS_ENSURE_SUCCESS(result, result); nsRefPtr<nsCaret> caretP = ps->GetCaret(); diff --git a/editor/libeditor/text/nsTextEditRules.cpp b/editor/libeditor/text/nsTextEditRules.cpp index 4f878865094..4d0f2b86617 100644 --- a/editor/libeditor/text/nsTextEditRules.cpp +++ b/editor/libeditor/text/nsTextEditRules.cpp @@ -151,7 +151,7 @@ nsTextEditRules::Init(nsPlaintextEditor *aEditor) // Put in a magic br if needed. This method handles null selection, // which should never happen anyway nsresult res = CreateBogusNodeIfNeeded(selection); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // If the selection hasn't been set up yet, set it up collapsed to the end of // our editable content. @@ -167,7 +167,7 @@ nsTextEditRules::Init(nsPlaintextEditor *aEditor) { // ensure trailing br node res = CreateTrailingBRIfNeeded(); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } if (body) @@ -179,15 +179,15 @@ nsTextEditRules::Init(nsPlaintextEditor *aEditor) wholeDoc->SetStart(body,0); nsCOMPtr<nsIDOMNodeList> list; res = body->GetChildNodes(getter_AddRefs(list)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!list) return NS_ERROR_FAILURE; PRUint32 listCount; res = list->GetLength(&listCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = wholeDoc->SetEnd(body, listCount); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // replace newlines in that range with breaks res = ReplaceNewlines(wholeDoc); @@ -254,7 +254,7 @@ nsTextEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection) { nsCOMPtr<nsISelection>selection; res = mEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mEditor->HandleInlineSpellCheck(action, selection, mCachedSelectionNode, mCachedSelectionOffset, @@ -443,15 +443,15 @@ nsTextEditRules::WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBo // if the selection isn't collapsed, delete it. PRBool bCollapsed; nsresult res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bCollapsed) { res = mEditor->DeleteSelection(nsIEditor::eNone); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() *aCancel = PR_FALSE; @@ -477,7 +477,7 @@ nsTextEditRules::DidInsertBreak(nsISelection *aSelection, nsresult aResult) nsCOMPtr<nsIDOMNode> selNode; nsresult res; res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // confirm we are at end of document if (selOffset == 0) return NS_OK; // can't be after a br if we are at offset 0 nsIDOMElement *rootElem = mEditor->GetRoot(); @@ -498,13 +498,13 @@ nsTextEditRules::DidInsertBreak(nsISelection *aSelection, nsresult aResult) // like table cells won't grow in height. nsCOMPtr<nsIDOMNode> brNode; res = CreateMozBR(selNode, selOffset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = nsEditor::GetNodeLocation(brNode, address_of(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); selPrivate->SetInterlinePosition(PR_TRUE); res = aSelection->Collapse(selNode, selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return res; } @@ -514,7 +514,7 @@ GetTextNode(nsISelection *selection, nsEditor *editor) { PRInt32 selOffset; nsCOMPtr<nsIDOMNode> selNode; nsresult res = editor->GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return nsnull; + NS_ENSURE_SUCCESS(res, nsnull); if (!editor->IsTextNode(selNode)) { // Get an nsINode from the nsIDOMNode nsCOMPtr<nsINode> node = do_QueryInterface(selNode); @@ -641,7 +641,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, // handle docs with a max length // NOTE, this function copies inString into outString for us. nsresult res = TruncateInsertionIfNeeded(aSelection, inString, outString, aMaxLength); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); PRUint32 start = 0; PRUint32 end = 0; @@ -651,21 +651,21 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, { res = mEditor->GetTextSelectionOffsets(aSelection, start, end); NS_ASSERTION((NS_SUCCEEDED(res)), "getTextSelectionOffsets failed!"); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } // if the selection isn't collapsed, delete it. PRBool bCollapsed; res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bCollapsed) { res = mEditor->DeleteSelection(nsIEditor::eNone); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } res = WillInsert(aSelection, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() *aCancel = PR_FALSE; @@ -677,7 +677,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, { if (aAction == kInsertTextIME) { res = RemoveIMETextFromPWBuf(start, outString); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -717,14 +717,14 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, else { mTimer = do_CreateInstance("@mozilla.org/timer;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } mTimer->InitWithCallback(this, 600, nsITimer::TYPE_ONE_SHOT); } else { res = FillBufWithPWChars(outString, outString->Length()); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } @@ -732,7 +732,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, nsCOMPtr<nsIDOMNode> selNode; PRInt32 selOffset; res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // don't put text in places that can't have it if (!mEditor->IsTextNode(selNode) && !mEditor->CanContainTag(selNode, NS_LITERAL_STRING("#text"))) @@ -741,13 +741,13 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, // we need to get the doc nsCOMPtr<nsIDOMDocument>doc; res = mEditor->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!doc) return NS_ERROR_NULL_POINTER; if (aAction == kInsertTextIME) { res = mEditor->InsertTextImpl(*outString, address_of(selNode), &selOffset, doc); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } else // aAction == kInsertText { @@ -759,7 +759,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, // We remember this so that we know how to handle tabs. PRBool isPRE; res = mEditor->IsPreformatted(selNode, &isPRE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // don't spaz my selection in subtransactions nsAutoTxnsConserveSelection dontSpazMySelection(mEditor); @@ -835,7 +835,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, { res = mEditor->InsertTextImpl(subStr, address_of(curNode), &curOffset, doc); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } else @@ -878,7 +878,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, { res = mEditor->InsertTextImpl(subStr, address_of(curNode), &curOffset, doc); } - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } outString->Assign(tString); @@ -1006,18 +1006,18 @@ nsTextEditRules::WillDeleteSelection(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> startNode; PRInt32 startOffset; res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!startNode) return NS_ERROR_FAILURE; PRBool bCollapsed; res = aSelection->GetIsCollapsed(&bCollapsed); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!bCollapsed) return NS_OK; // Test for distance between caret and text that will be deleted res = CheckBidiLevelForDeletion(aSelection, startNode, startOffset, aCollapsedAction, aCancel); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (*aCancel) return NS_OK; res = mEditor->ExtendSelectionForDelete(aSelection, &aCollapsedAction); @@ -1040,7 +1040,7 @@ nsTextEditRules::DidDeleteSelection(nsISelection *aSelection, nsCOMPtr<nsIDOMNode> startNode; PRInt32 startOffset; nsresult res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!startNode) return NS_ERROR_FAILURE; // delete empty text nodes at selection @@ -1049,13 +1049,13 @@ nsTextEditRules::DidDeleteSelection(nsISelection *aSelection, nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(startNode); PRUint32 strLength; res = textNode->GetLength(&strLength); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // are we in an empty text node? if (!strLength) { res = mEditor->DeleteNode(startNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } } if (!mDidExplicitlySetInterline) @@ -1135,7 +1135,7 @@ nsTextEditRules::DidRedo(nsISelection *aSelection, nsresult aResult) nsCOMPtr<nsIDOMNodeList> nodeList; res = theRoot->GetElementsByTagName(NS_LITERAL_STRING("br"), getter_AddRefs(nodeList)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (nodeList) { PRUint32 len; @@ -1204,10 +1204,10 @@ nsTextEditRules::ReplaceNewlines(nsIDOMRange *aRange) nsresult res; nsCOMPtr<nsIContentIterator> iter = do_CreateInstance("@mozilla.org/content/post-content-iterator;1", &res); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = iter->Init(aRange); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMArray<nsIDOMCharacterData> arrayOfNodes; @@ -1222,7 +1222,7 @@ nsTextEditRules::ReplaceNewlines(nsIDOMRange *aRange) { PRBool isPRE; res = mEditor->IsPreformatted(node, &isPRE); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (isPRE) { nsCOMPtr<nsIDOMCharacterData> data = do_QueryInterface(node); @@ -1257,14 +1257,14 @@ nsTextEditRules::ReplaceNewlines(nsIDOMRange *aRange) // or, failing that, undo is disabled res = mEditor->CreateTxnForDeleteText(textNode, offset, 1, getter_AddRefs(txn)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!txn) return NS_ERROR_OUT_OF_MEMORY; res = mEditor->DoTransaction(txn); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // insert a break res = mEditor->CreateBR(textNode, offset, address_of(brNode)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } while (1); // break used to exit while loop } return res; @@ -1282,7 +1282,7 @@ nsTextEditRules::CreateTrailingBRIfNeeded() nsCOMPtr<nsIDOMNode> lastChild; nsresult res = body->GetLastChild(getter_AddRefs(lastChild)); // assuming CreateBogusNodeIfNeeded() has been called first - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); if (!lastChild) return NS_ERROR_NULL_POINTER; if (!nsTextEditUtils::IsBreak(lastChild)) @@ -1290,7 +1290,7 @@ nsTextEditRules::CreateTrailingBRIfNeeded() nsAutoTxnsConserveSelection dontSpazMySelection(mEditor); PRUint32 rootLen; res = mEditor->GetLengthOfDOMNode(body, rootLen); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> unused; res = CreateMozBR(body, rootLen, address_of(unused)); } @@ -1340,7 +1340,7 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsISelection *aSelection) // create a br nsCOMPtr<nsIContent> newContent; res = mEditor->CreateHTMLContent(NS_LITERAL_STRING("br"), getter_AddRefs(newContent)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMElement>brElement = do_QueryInterface(newContent); // set mBogusNode to be the newly created <br> @@ -1353,7 +1353,7 @@ nsTextEditRules::CreateBogusNodeIfNeeded(nsISelection *aSelection) // put the node in the document res = mEditor->InsertNode(mBogusNode, body, 0); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // set selection aSelection->Collapse(body, 0); @@ -1464,9 +1464,9 @@ nsresult nsTextEditRules::HideLastPWInput() { nsCOMPtr<nsISelection> selection; PRUint32 start, end; nsresult res = mEditor->GetSelection(getter_AddRefs(selection)); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); res = mEditor->GetTextSelectionOffsets(selection, start, end); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIDOMNode> selNode = GetTextNode(selection, mEditor); if (!selNode) @@ -1515,14 +1515,14 @@ nsTextEditRules::CreateMozBR(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<ns if (!inParent || !outBRNode) return NS_ERROR_NULL_POINTER; nsresult res = mEditor->CreateBR(inParent, inOffset, outBRNode); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); // give it special moz attr nsCOMPtr<nsIDOMElement> brElem = do_QueryInterface(*outBRNode); if (brElem) { res = mEditor->SetAttribute(brElem, NS_LITERAL_STRING("type"), NS_LITERAL_STRING("_moz")); - if (NS_FAILED(res)) return res; + NS_ENSURE_SUCCESS(res, res); } return res; } diff --git a/editor/txtsvc/src/nsFilteredContentIterator.cpp b/editor/txtsvc/src/nsFilteredContentIterator.cpp index e2406376615..d81090d938e 100644 --- a/editor/txtsvc/src/nsFilteredContentIterator.cpp +++ b/editor/txtsvc/src/nsFilteredContentIterator.cpp @@ -271,10 +271,10 @@ ContentIsInTraversalRange(nsIContent *aContent, PRBool aIsPreMode, PRInt32 startRes; PRInt32 endRes; nsresult rv = nsTextServicesDocument::ComparePoints(aStartNode, aStartOffset, parentNode, indx, &startRes); - if (NS_FAILED(rv)) return PR_FALSE; + NS_ENSURE_SUCCESS(rv, PR_FALSE); rv = nsTextServicesDocument::ComparePoints(aEndNode, aEndOffset, parentNode, indx, &endRes); - if (NS_FAILED(rv)) return PR_FALSE; + NS_ENSURE_SUCCESS(rv, PR_FALSE); return (startRes <= 0) && (endRes >= 0); }