Bug 812891 - Remove duplicated code from nsEditor::Get{Left,Right}mostChild; r=ehsan

This commit is contained in:
Ms2ger 2012-12-02 09:59:45 +01:00
Родитель a4bcef09e7
Коммит fe8dc575cd
2 изменённых файлов: 14 добавлений и 44 удалений

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

@ -3385,28 +3385,13 @@ nsEditor::FindNode(nsINode *aCurrentNode,
return FindNode(candidate, aGoForward, aEditableNode, bNoBlockCrossing);
}
already_AddRefed<nsIDOMNode>
nsEditor::GetRightmostChild(nsIDOMNode *aCurrentNode,
nsIDOMNode*
nsEditor::GetRightmostChild(nsIDOMNode* aCurrentNode,
bool bNoBlockCrossing)
{
NS_ENSURE_TRUE(aCurrentNode, nullptr);
nsCOMPtr<nsIDOMNode> resultNode, temp = aCurrentNode;
bool hasChildren;
aCurrentNode->HasChildNodes(&hasChildren);
while (hasChildren) {
temp->GetLastChild(getter_AddRefs(resultNode));
if (resultNode) {
if (bNoBlockCrossing && IsBlockNode(resultNode)) {
return resultNode.forget();
}
resultNode->HasChildNodes(&hasChildren);
temp = resultNode;
} else {
hasChildren = false;
}
}
return resultNode.forget();
nsCOMPtr<nsINode> currentNode = do_QueryInterface(aCurrentNode);
nsIContent* result = GetRightmostChild(currentNode, bNoBlockCrossing);
return result ? result->AsDOMNode() : nullptr;
}
nsIContent*
@ -3457,28 +3442,13 @@ nsEditor::GetLeftmostChild(nsINode *aCurrentNode,
return nullptr;
}
already_AddRefed<nsIDOMNode>
nsEditor::GetLeftmostChild(nsIDOMNode *aCurrentNode,
nsIDOMNode*
nsEditor::GetLeftmostChild(nsIDOMNode* aCurrentNode,
bool bNoBlockCrossing)
{
NS_ENSURE_TRUE(aCurrentNode, nullptr);
nsCOMPtr<nsIDOMNode> resultNode, temp = aCurrentNode;
bool hasChildren;
aCurrentNode->HasChildNodes(&hasChildren);
while (hasChildren) {
temp->GetFirstChild(getter_AddRefs(resultNode));
if (resultNode) {
if (bNoBlockCrossing && IsBlockNode(resultNode)) {
return resultNode.forget();
}
resultNode->HasChildNodes(&hasChildren);
temp = resultNode;
} else {
hasChildren = false;
}
}
return resultNode.forget();
nsCOMPtr<nsINode> currentNode = do_QueryInterface(aCurrentNode);
nsIContent* result = GetLeftmostChild(currentNode, bNoBlockCrossing);
return result ? result->AsDOMNode() : nullptr;
}
bool

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

@ -539,8 +539,8 @@ public:
* Get the rightmost child of aCurrentNode;
* return nullptr if aCurrentNode has no children.
*/
already_AddRefed<nsIDOMNode> GetRightmostChild(nsIDOMNode *aCurrentNode,
bool bNoBlockCrossing = false);
nsIDOMNode* GetRightmostChild(nsIDOMNode* aCurrentNode,
bool bNoBlockCrossing = false);
nsIContent* GetRightmostChild(nsINode *aCurrentNode,
bool bNoBlockCrossing = false);
@ -548,8 +548,8 @@ public:
* Get the leftmost child of aCurrentNode;
* return nullptr if aCurrentNode has no children.
*/
already_AddRefed<nsIDOMNode> GetLeftmostChild(nsIDOMNode *aCurrentNode,
bool bNoBlockCrossing = false);
nsIDOMNode* GetLeftmostChild(nsIDOMNode* aCurrentNode,
bool bNoBlockCrossing = false);
nsIContent* GetLeftmostChild(nsINode *aCurrentNode,
bool bNoBlockCrossing = false);