Bug 572618 - Make debugging the editor easier - Part 1: Replace all if(NS_FAILED) checks with NS_ENSURE_SUCCESS; r=roc

This commit is contained in:
Ehsan Akhgari 2010-06-17 15:27:24 -04:00
Родитель c3b8ed0a41
Коммит dbee1fa3ae
36 изменённых файлов: 1566 добавлений и 1566 удалений

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

@ -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<nsIAtom> bigAtom = do_GetAtom("big");
rv = htmlEditor->RemoveInlineProperty(bigAtom, EmptyString());
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAtom> 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<nsIDOMElement> 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);
}

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

@ -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;

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

@ -76,7 +76,7 @@ GetPresContextFromEditor(nsIEditor *aEditor, nsPresContext **aResult)
nsCOMPtr<nsISelectionController> 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<nsIPresShell> presShell = do_QueryInterface(selCon);
@ -116,7 +116,7 @@ nsSetDocumentOptionsCommand::DoCommandParams(const char *aCommandName,
nsRefPtr<nsPresContext> 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<nsIDocShell> 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<nsPresContext> 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<nsIDocShell> 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;

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

@ -126,19 +126,19 @@ CreateControllerWithSingletonCommandTable(const nsCID& inCommandTableCID, nsICon
{
nsresult rv;
nsCOMPtr<nsIController> controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIControllerCommandTable> 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<nsIControllerContext> 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<nsIController> 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<nsIController> 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<nsIControllerCommandTable> 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<nsIControllerCommandTable> 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

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

@ -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<nsIEditorDocShell> 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<nsIEditingSession*>(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<nsIEditingSession*>(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<nsIEditorDocShell> 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<nsIEditorDocShell> editorDocShell = do_QueryInterface(docShell, &rv);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIEditor> 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<nsIContentViewer> 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<nsIDOMDocument> 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<nsIPresShell> 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<nsISelectionController> 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<nsISelection> 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<nsITransactionManager> 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<nsIEditorDocShell> 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<nsIDOMWindow> domWindow;
nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMDocument> domDoc;
rv = domWindow->GetDocument(getter_AddRefs(domDoc));
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocument> 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<nsIDOMWindowInternal> domWindowInt =
do_QueryInterface(aWindow, &rv);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIControllers> 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<nsIController> 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<nsIDOMWindowInternal> domWindowInt =
do_QueryInterface(aWindow, &rv);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIControllers> controllers;
rv = domWindowInt->GetControllers(getter_AddRefs(controllers));
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupports> 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)

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

@ -180,7 +180,7 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::DoTransaction(void)
nsCOMPtr<nsIDOMCSSStyleDeclaration> 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<nsIDOMCSSStyleDeclaration> 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);
}
}

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

@ -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);
nsCOMPtr<nsIDOMElement>newElement = 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<nsISelection> 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.");

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

@ -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<nsISelection> 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<nsIDOMNodeList> 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<nsIDOMNode> 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<DeleteElementTxn> 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))
{

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

@ -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<nsISelection> 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.");

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

@ -109,7 +109,7 @@ NS_IMETHODIMP InsertElementTxn::DoTransaction(void)
nsCOMPtr<nsIDOMNodeList> childNodes;
nsresult result = mParent->GetChildNodes(getter_AddRefs(childNodes));
if (NS_FAILED(result)) return result;
NS_ENSURE_SUCCESS(result, result);
nsCOMPtr<nsIDOMNode>refNode;
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<nsIDOMNode> 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<nsISelection> 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);

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

@ -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<nsISelection> 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.");

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

@ -76,7 +76,7 @@ NS_IMETHODIMP JoinElementTxn::Init(nsEditor *aEditor,
mLeftNode = do_QueryInterface(aLeftNode);
nsCOMPtr<nsIDOMNode>leftParent;
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
nsCOMPtr<nsIDOMNode>leftParent;
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
nsCOMPtr<nsIDOMNode>rightParent;
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<nsIDOMNodeList> childNodes;
result = mLeftNode->GetChildNodes(getter_AddRefs(childNodes));
if (NS_FAILED(result)) return result;
NS_ENSURE_SUCCESS(result, result);
if (childNodes)
{
childNodes->GetLength(&mOffset);

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

@ -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<nsISelection> 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<nsISelection> 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<nsISelection> 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);
}

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

@ -91,7 +91,7 @@ nsresult SetDocTitleTxn::SetDomTitle(const nsAString& aTitle)
nsCOMPtr<nsIDOMNodeList> 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 <HEAD> node, create a <TITLE> 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)

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

@ -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);
}

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

@ -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();
}

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

@ -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++)
{

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

@ -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)

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

@ -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;

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

@ -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)
{

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

@ -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)

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

@ -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;

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

@ -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 !");

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

@ -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.

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

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

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

@ -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);

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

@ -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)
{

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

@ -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;
}

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

@ -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

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

@ -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;
}

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

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

@ -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);

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

@ -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();

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

@ -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;
}

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

@ -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);
}