Bug 747346 - Cleanup nsTextEditRules::CreateTrailingBRIfNeeded(); r=ehsan

This commit is contained in:
Ms2ger 2012-05-05 11:00:05 +02:00
parent de7a9c7e64
commit ccd3cd30f5

View File

@ -1089,37 +1089,35 @@ nsresult
nsTextEditRules::CreateTrailingBRIfNeeded()
{
// but only if we aren't a single line edit field
if (IsSingleLineEditor())
if (IsSingleLineEditor()) {
return NS_OK;
nsCOMPtr<nsIDOMNode> body = do_QueryInterface(mEditor->GetRoot());
}
dom::Element* body = mEditor->GetRoot();
NS_ENSURE_TRUE(body, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMNode> lastChild;
nsresult res = body->GetLastChild(getter_AddRefs(lastChild));
nsIContent* lastChild = body->GetLastChild();
// assuming CreateBogusNodeIfNeeded() has been called first
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(lastChild, NS_ERROR_NULL_POINTER);
if (!nsTextEditUtils::IsBreak(lastChild))
{
if (!lastChild->IsHTML(nsGkAtoms::br)) {
nsAutoTxnsConserveSelection dontSpazMySelection(mEditor);
PRUint32 rootLen;
res = mEditor->GetLengthOfDOMNode(body, rootLen);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> domBody = do_QueryInterface(body);
nsCOMPtr<nsIDOMNode> unused;
res = CreateMozBR(body, rootLen, address_of(unused));
} else {
// Check to see if the trailing BR is a former bogus node - this will have stuck
// around if we previously morphed a trailing node into a bogus node
nsCOMPtr<nsIContent> lastBR = do_QueryInterface(lastChild);
if (!mEditor->IsMozEditorBogusNode(lastBR))
return NS_OK;
// Morph it back to a mozBR
dom::Element* elem = lastBR->AsElement();
elem->UnsetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom, false);
elem->SetAttr(kNameSpaceID_None, nsGkAtoms::type, NS_LITERAL_STRING("_moz"), true);
return CreateMozBR(domBody, body->Length(), address_of(unused));
}
return res;
// Check to see if the trailing BR is a former bogus node - this will have
// stuck around if we previously morphed a trailing node into a bogus node.
if (!mEditor->IsMozEditorBogusNode(lastChild)) {
return NS_OK;
}
// Morph it back to a mozBR
lastChild->UnsetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom, false);
lastChild->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
NS_LITERAL_STRING("_moz"), true);
return NS_OK;
}
nsresult