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); PRInt32 aEndOffset);
nsresult RelativeFontChangeOnNode( PRInt32 aSizeChange, nsresult RelativeFontChangeOnNode( PRInt32 aSizeChange,
nsIDOMNode *aNode); nsIDOMNode *aNode);
nsresult RelativeFontChangeHelper(PRInt32 aSizeChange, nsINode* aNode);
nsresult RelativeFontChangeHelper( PRInt32 aSizeChange, nsresult RelativeFontChangeHelper( PRInt32 aSizeChange,
nsIDOMNode *aNode); nsIDOMNode *aNode);

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

@ -1667,9 +1667,21 @@ nsHTMLEditor::RelativeFontChangeOnTextNode( PRInt32 aSizeChange,
nsresult nsresult
nsHTMLEditor::RelativeFontChangeHelper( PRInt32 aSizeChange, nsHTMLEditor::RelativeFontChangeHelper(PRInt32 aSizeChange, nsIDOMNode* aNode)
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, /* 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 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 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 // Can only change font size by + or - 1
if ( !( (aSizeChange==1) || (aSizeChange==-1) ) ) if (aSizeChange != 1 && aSizeChange != -1) {
return NS_ERROR_ILLEGAL_VALUE; return NS_ERROR_ILLEGAL_VALUE;
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER); }
nsresult res = NS_OK; // If this is a font node with size, put big/small inside it.
nsAutoString tag; if (aNode->IsElement() && aNode->AsElement()->IsHTML(nsGkAtoms::font) &&
if (aSizeChange == 1) tag.AssignLiteral("big"); aNode->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::size)) {
else tag.AssignLiteral("small"); // Cycle through children and adjust relative font size.
nsCOMPtr<nsIDOMNodeList> childNodes; for (nsIContent* child = aNode->GetLastChild();
PRInt32 j; child;
PRUint32 childCount; child = child->GetPreviousSibling()) {
nsCOMPtr<nsIDOMNode> childNode; nsresult rv = RelativeFontChangeOnNode(aSizeChange, child->AsDOMNode());
NS_ENSURE_SUCCESS(rv, rv);
// 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);
}
}
} }
} }
childNodes = nsnull; // Now cycle through the children.
// now cycle through the children. for (nsIContent* child = aNode->GetLastChild();
res = aNode->GetChildNodes(getter_AddRefs(childNodes)); child;
NS_ENSURE_SUCCESS(res, res); child = child->GetPreviousSibling()) {
if (childNodes) nsresult rv = RelativeFontChangeHelper(aSizeChange, child);
{ NS_ENSURE_SUCCESS(rv, rv);
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);
}
}
} }
return res; return NS_OK;
} }