author | Ms2ger <ms2ger@gmail.com> |
Fri, 18 May 2012 10:29:39 +0200 | |
changeset 94310 | e0110ef139896b24b67eec02a2d4a93ed2f516b2 |
parent 94309 | 25025cc03fb3a1dc29dd49d52b556713c2fe9a94 |
child 94311 | c795f1a41daebc5eebb6eb706f62700ecea15ff0 |
push id | 22706 |
push user | Ms2ger@gmail.com |
push date | Fri, 18 May 2012 08:31:47 +0000 |
treeherder | mozilla-central@4b74c82dd5ab [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | ehsan |
bugs | 752210 |
milestone | 15.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
editor/libeditor/html/nsHTMLEditor.h | file | annotate | diff | comparison | revisions | |
editor/libeditor/html/nsHTMLEditorStyle.cpp | file | annotate | diff | comparison | revisions |
--- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -658,21 +658,20 @@ protected: /* increase/decrease the font size of selection */ nsresult RelativeFontChange( PRInt32 aSizeChange); /* helper routines for font size changing */ nsresult RelativeFontChangeOnTextNode( PRInt32 aSizeChange, nsIDOMCharacterData *aTextNode, PRInt32 aStartOffset, PRInt32 aEndOffset); + nsresult RelativeFontChangeOnNode(PRInt32 aSizeChange, nsINode* aNode); nsresult RelativeFontChangeOnNode( PRInt32 aSizeChange, nsIDOMNode *aNode); nsresult RelativeFontChangeHelper(PRInt32 aSizeChange, nsINode* aNode); - nsresult RelativeFontChangeHelper( PRInt32 aSizeChange, - nsIDOMNode *aNode); /* helper routines for inline style */ nsresult SetInlinePropertyOnTextNode( nsIDOMCharacterData *aTextNode, PRInt32 aStartOffset, PRInt32 aEndOffset, nsIAtom *aProperty, const nsAString *aAttribute, const nsAString *aValue);
--- a/editor/libeditor/html/nsHTMLEditorStyle.cpp +++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp @@ -1662,27 +1662,16 @@ nsHTMLEditor::RelativeFontChangeOnTextNo // else reparent the node inside font node with appropriate relative size res = InsertContainerAbove(node, address_of(tmp), nodeType); return res; } nsresult -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 they override any big/small that are above them. @@ -1695,17 +1684,17 @@ nsHTMLEditor::RelativeFontChangeHelper(P // 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()); + nsresult rv = RelativeFontChangeOnNode(aSizeChange, child); NS_ENSURE_SUCCESS(rv, rv); } } // Now cycle through the children. for (nsIContent* child = aNode->GetLastChild(); child; child = child->GetPreviousSibling()) { @@ -1713,96 +1702,91 @@ nsHTMLEditor::RelativeFontChangeHelper(P NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; } nsresult -nsHTMLEditor::RelativeFontChangeOnNode( PRInt32 aSizeChange, - nsIDOMNode *aNode) +nsHTMLEditor::RelativeFontChangeOnNode(PRInt32 aSizeChange, + nsIDOMNode* aNode) { + nsCOMPtr<nsINode> node = do_QueryInterface(aNode); + NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER); + + return RelativeFontChangeOnNode(aSizeChange, node); +} + +nsresult +nsHTMLEditor::RelativeFontChangeOnNode(PRInt32 aSizeChange, nsINode* aNode) +{ + MOZ_ASSERT(aNode); // 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; - nsCOMPtr<nsIDOMNode> tmp; nsIAtom* atom; if (aSizeChange == 1) { atom = nsGkAtoms::big; } else { atom = nsGkAtoms::small; } - // is it the opposite of what we want? - if ( ((aSizeChange == 1) && nsHTMLEditUtils::IsSmall(aNode)) || - ((aSizeChange == -1) && nsHTMLEditUtils::IsBig(aNode)) ) - { + // Is it the opposite of what we want? + if (aNode->IsElement() && + ((aSizeChange == 1 && aNode->AsElement()->IsHTML(nsGkAtoms::small)) || + (aSizeChange == -1 && aNode->AsElement()->IsHTML(nsGkAtoms::big)))) { // first populate any nested font tags that have the size attr set - res = RelativeFontChangeHelper(aSizeChange, aNode); - NS_ENSURE_SUCCESS(res, res); + nsresult rv = RelativeFontChangeHelper(aSizeChange, aNode); + NS_ENSURE_SUCCESS(rv, rv); // in that case, just remove this node and pull up the children - res = RemoveContainer(aNode); - return res; + return RemoveContainer(aNode); } + // can it be put inside a "big" or "small"? - if (TagCanContain(atom, aNode)) { + if (TagCanContain(atom, aNode->AsDOMNode())) { // first populate any nested font tags that have the size attr set - res = RelativeFontChangeHelper(aSizeChange, aNode); - NS_ENSURE_SUCCESS(res, res); + nsresult rv = RelativeFontChangeHelper(aSizeChange, aNode); + NS_ENSURE_SUCCESS(rv, rv); + // ok, chuck it in. // first look at siblings of aNode for matching bigs or smalls. // if we find one, move aNode into it. - nsCOMPtr<nsIDOMNode> sibling; - GetPriorHTMLSibling(aNode, address_of(sibling)); - if (sibling && nsEditor::NodeIsType(sibling, (aSizeChange==1 ? nsEditProperty::big : nsEditProperty::small))) - { + nsIContent* sibling = GetPriorHTMLSibling(aNode); + if (sibling && sibling->IsHTML(atom)) { // previous sib is already right kind of inline node; slide this over into it - res = MoveNode(aNode, sibling, -1); - return res; + return MoveNode(aNode->AsDOMNode(), sibling->AsDOMNode(), -1); } - sibling = nsnull; - GetNextHTMLSibling(aNode, address_of(sibling)); - if (sibling && nsEditor::NodeIsType(sibling, (aSizeChange==1 ? nsEditProperty::big : nsEditProperty::small))) - { + + sibling = GetNextHTMLSibling(aNode); + if (sibling && sibling->IsHTML(atom)) { // following sib is already right kind of inline node; slide this over into it - res = MoveNode(aNode, sibling, 0); - return res; + return MoveNode(aNode->AsDOMNode(), sibling->AsDOMNode(), 0); } + // else insert it above aNode - res = InsertContainerAbove(aNode, address_of(tmp), nsAtomString(atom)); - return res; + nsCOMPtr<nsIDOMNode> tmp; + return InsertContainerAbove(aNode->AsDOMNode(), address_of(tmp), + nsAtomString(atom)); } + // none of the above? then cycle through the children. // MOOSE: we should group the children together if possible // into a single "big" or "small". For the moment they are // each getting their own. - nsCOMPtr<nsIDOMNodeList> childNodes; - res = aNode->GetChildNodes(getter_AddRefs(childNodes)); - NS_ENSURE_SUCCESS(res, res); - if (childNodes) - { - PRInt32 j; - PRUint32 childCount; - childNodes->GetLength(&childCount); - for (j=childCount-1; j>=0; j--) - { - nsCOMPtr<nsIDOMNode> childNode; - res = childNodes->Item(j, getter_AddRefs(childNode)); - if ((NS_SUCCEEDED(res)) && (childNode)) - { - res = RelativeFontChangeOnNode(aSizeChange, childNode); - NS_ENSURE_SUCCESS(res, res); - } - } + for (nsIContent* child = aNode->GetLastChild(); + child; + child = child->GetPreviousSibling()) { + nsresult rv = RelativeFontChangeOnNode(aSizeChange, child); + NS_ENSURE_SUCCESS(rv, rv); } - return res; + + return NS_OK; } NS_IMETHODIMP nsHTMLEditor::GetFontFaceState(bool *aMixed, nsAString &outFace) { NS_ENSURE_TRUE(aMixed, NS_ERROR_FAILURE); *aMixed = true; outFace.Truncate();