Bug 752210 - Part a: Use nsIContent in nsHTMLEditor::RelativeFontChangeHelper; r=ehsan

This commit is contained in:
Ms2ger 2012-05-18 10:29:39 +02:00
Родитель f62ee8eedc
Коммит 226f3d597f
2 изменённых файлов: 33 добавлений и 49 удалений

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

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

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

@ -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<nsINode> 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<nsIDOMNodeList> childNodes;
PRInt32 j;
PRUint32 childCount;
nsCOMPtr<nsIDOMNode> 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;
}