diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index 137ddbece9ee..bcdd93d66559 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -665,6 +665,7 @@ protected: PRInt32 aEndOffset); nsresult RelativeFontChangeOnNode( PRInt32 aSizeChange, nsIDOMNode *aNode); + nsresult RelativeFontChangeHelper(PRInt32 aSizeChange, nsINode* aNode); nsresult RelativeFontChangeHelper( PRInt32 aSizeChange, nsIDOMNode *aNode); diff --git a/editor/libeditor/html/nsHTMLEditorStyle.cpp b/editor/libeditor/html/nsHTMLEditorStyle.cpp index ce95a4a258d7..8fb31bb6125f 100644 --- a/editor/libeditor/html/nsHTMLEditorStyle.cpp +++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp @@ -1667,9 +1667,21 @@ nsHTMLEditor::RelativeFontChangeOnTextNode( PRInt32 aSizeChange, nsresult -nsHTMLEditor::RelativeFontChangeHelper( PRInt32 aSizeChange, - nsIDOMNode *aNode) +nsHTMLEditor::RelativeFontChangeHelper(PRInt32 aSizeChange, nsIDOMNode* aNode) { + NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER); + + nsCOMPtr node = do_QueryInterface(aNode); + NS_ENSURE_STATE(node); + + return RelativeFontChangeHelper(aSizeChange, node); +} + +nsresult +nsHTMLEditor::RelativeFontChangeHelper(PRInt32 aSizeChange, nsINode* aNode) +{ + MOZ_ASSERT(aNode); + /* This routine looks for all the font nodes in the tree rooted by aNode, including aNode itself, looking for font nodes that have the size attr set. Any such nodes need to have big or small put inside them, since @@ -1677,60 +1689,31 @@ nsHTMLEditor::RelativeFontChangeHelper( PRInt32 aSizeChange, */ // Can only change font size by + or - 1 - if ( !( (aSizeChange==1) || (aSizeChange==-1) ) ) + if (aSizeChange != 1 && aSizeChange != -1) { return NS_ERROR_ILLEGAL_VALUE; - NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER); + } - nsresult res = NS_OK; - nsAutoString tag; - if (aSizeChange == 1) tag.AssignLiteral("big"); - else tag.AssignLiteral("small"); - nsCOMPtr childNodes; - PRInt32 j; - PRUint32 childCount; - nsCOMPtr childNode; - - // if this is a font node with size, put big/small inside it - NS_NAMED_LITERAL_STRING(attr, "size"); - if (NodeIsType(aNode, nsEditProperty::font) && HasAttr(aNode, &attr)) - { - // cycle through children and adjust relative font size - res = aNode->GetChildNodes(getter_AddRefs(childNodes)); - NS_ENSURE_SUCCESS(res, res); - if (childNodes) - { - childNodes->GetLength(&childCount); - for (j=childCount-1; j>=0; j--) - { - res = childNodes->Item(j, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(res)) && (childNode)) - { - res = RelativeFontChangeOnNode(aSizeChange, childNode); - NS_ENSURE_SUCCESS(res, res); - } - } + // If this is a font node with size, put big/small inside it. + if (aNode->IsElement() && aNode->AsElement()->IsHTML(nsGkAtoms::font) && + aNode->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::size)) { + // Cycle through children and adjust relative font size. + for (nsIContent* child = aNode->GetLastChild(); + child; + child = child->GetPreviousSibling()) { + nsresult rv = RelativeFontChangeOnNode(aSizeChange, child->AsDOMNode()); + NS_ENSURE_SUCCESS(rv, rv); } } - childNodes = nsnull; - // now cycle through the children. - res = aNode->GetChildNodes(getter_AddRefs(childNodes)); - NS_ENSURE_SUCCESS(res, res); - if (childNodes) - { - childNodes->GetLength(&childCount); - for (j=childCount-1; j>=0; j--) - { - res = childNodes->Item(j, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(res)) && (childNode)) - { - res = RelativeFontChangeHelper(aSizeChange, childNode); - NS_ENSURE_SUCCESS(res, res); - } - } + // Now cycle through the children. + for (nsIContent* child = aNode->GetLastChild(); + child; + child = child->GetPreviousSibling()) { + nsresult rv = RelativeFontChangeHelper(aSizeChange, child); + NS_ENSURE_SUCCESS(rv, rv); } - return res; + return NS_OK; }