mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 752210 - Part a: Use nsIContent in nsHTMLEditor::RelativeFontChangeHelper; r=ehsan
This commit is contained in:
parent
f62ee8eedc
commit
226f3d597f
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user