Bug 744507 - Part b: Add nsINode versions in GetPriorHTMLSibling/GetNextHTMLSibling; r=ehsan

This commit is contained in:
Ms2ger 2012-04-14 15:09:38 +02:00
Родитель 64beece2b3
Коммит 7482a2122b
2 изменённых файлов: 85 добавлений и 64 удалений

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

@ -4209,29 +4209,30 @@ nsHTMLEditor::RemoveBlockContainer(nsIDOMNode *inNode)
// GetPriorHTMLSibling: returns the previous editable sibling, if there is
// one within the parent
//
nsINode*
nsHTMLEditor::GetPriorHTMLSibling(nsINode* aNode)
{
MOZ_ASSERT(aNode);
nsIContent* node = aNode->GetPreviousSibling();
while (node && !IsEditable(node)) {
node = node->GetPreviousSibling();
}
return node;
}
nsresult
nsHTMLEditor::GetPriorHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode)
{
NS_ENSURE_TRUE(outNode && inNode, NS_ERROR_NULL_POINTER);
nsresult res = NS_OK;
*outNode = nsnull;
nsCOMPtr<nsIDOMNode> temp, node = do_QueryInterface(inNode);
while (1)
{
res = node->GetPreviousSibling(getter_AddRefs(temp));
NS_ENSURE_SUCCESS(res, res);
if (!temp) {
// return null sibling
return NS_OK;
}
// if it's editable, we're done
if (IsEditable(temp)) break;
// otherwise try again
node = temp;
}
*outNode = temp;
return res;
NS_ENSURE_TRUE(outNode, NS_ERROR_NULL_POINTER);
*outNode = NULL;
nsCOMPtr<nsINode> node = do_QueryInterface(inNode);
NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
*outNode = do_QueryInterface(GetPriorHTMLSibling(node));
return NS_OK;
}
@ -4241,22 +4242,30 @@ nsHTMLEditor::GetPriorHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outN
// one within the parent. just like above routine but
// takes a parent/offset instead of a node.
//
nsINode*
nsHTMLEditor::GetPriorHTMLSibling(nsINode* aParent, PRInt32 aOffset)
{
MOZ_ASSERT(aParent);
nsIContent* node = aParent->GetChildAt(aOffset - 1);
if (!node || IsEditable(node)) {
return node;
}
return GetPriorHTMLSibling(node);
}
nsresult
nsHTMLEditor::GetPriorHTMLSibling(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outNode)
{
NS_ENSURE_TRUE(outNode && inParent, NS_ERROR_NULL_POINTER);
*outNode = nsnull;
nsCOMPtr<nsIDOMNode> node = nsEditor::GetChildAt(inParent,inOffset-1);
if (!node) {
// return null sibling if no sibling
return NS_OK;
}
if (IsEditable(node)) {
*outNode = node;
return NS_OK;
}
// else
return GetPriorHTMLSibling(node, outNode);
NS_ENSURE_TRUE(outNode, NS_ERROR_NULL_POINTER);
*outNode = NULL;
nsCOMPtr<nsINode> parent = do_QueryInterface(inParent);
NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
*outNode = do_QueryInterface(GetPriorHTMLSibling(parent, inOffset));
return NS_OK;
}
@ -4265,29 +4274,30 @@ nsHTMLEditor::GetPriorHTMLSibling(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMP
// GetNextHTMLSibling: returns the next editable sibling, if there is
// one within the parent
//
nsINode*
nsHTMLEditor::GetNextHTMLSibling(nsINode* aNode)
{
MOZ_ASSERT(aNode);
nsIContent* node = aNode->GetNextSibling();
while (node && !IsEditable(node)) {
node = node->GetNextSibling();
}
return node;
}
nsresult
nsHTMLEditor::GetNextHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode)
{
NS_ENSURE_TRUE(outNode, NS_ERROR_NULL_POINTER);
nsresult res = NS_OK;
*outNode = nsnull;
nsCOMPtr<nsIDOMNode> temp, node = do_QueryInterface(inNode);
nsCOMPtr<nsINode> node = do_QueryInterface(inNode);
NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
while (1)
{
res = node->GetNextSibling(getter_AddRefs(temp));
NS_ENSURE_SUCCESS(res, res);
if (!temp) {
// return null sibling
return NS_OK;
}
// if it's editable, we're done
if (IsEditable(temp)) break;
// otherwise try again
node = temp;
}
*outNode = temp;
return res;
*outNode = do_QueryInterface(GetNextHTMLSibling(node));
return NS_OK;
}
@ -4296,23 +4306,30 @@ nsHTMLEditor::GetNextHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNo
// GetNextHTMLSibling: returns the next editable sibling, if there is
// one within the parent. just like above routine but
// takes a parent/offset instead of a node.
//
nsINode*
nsHTMLEditor::GetNextHTMLSibling(nsINode* aParent, PRInt32 aOffset)
{
MOZ_ASSERT(aParent);
nsIContent* node = aParent->GetChildAt(aOffset + 1);
if (!node || IsEditable(node)) {
return node;
}
return GetNextHTMLSibling(node);
}
nsresult
nsHTMLEditor::GetNextHTMLSibling(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outNode)
{
NS_ENSURE_TRUE(outNode && inParent, NS_ERROR_NULL_POINTER);
*outNode = nsnull;
nsCOMPtr<nsIDOMNode> node = nsEditor::GetChildAt(inParent, inOffset + 1);
if (!node) {
// return null sibling if no sibling
return NS_OK;
}
if (IsEditable(node)) {
*outNode = node;
return NS_OK;
}
// else
return GetNextHTMLSibling(node, outNode);
NS_ENSURE_TRUE(outNode, NS_ERROR_NULL_POINTER);
*outNode = NULL;
nsCOMPtr<nsINode> parent = do_QueryInterface(inParent);
NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
*outNode = do_QueryInterface(GetNextHTMLSibling(parent, inOffset));
return NS_OK;
}

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

@ -720,9 +720,13 @@ protected:
bool IsOnlyAttribute(nsIDOMNode *aElement, const nsAString *aAttribute);
nsresult RemoveBlockContainer(nsIDOMNode *inNode);
nsINode* GetPriorHTMLSibling(nsINode* aNode);
nsresult GetPriorHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode);
nsINode* GetPriorHTMLSibling(nsINode* aParent, PRInt32 aOffset);
nsresult GetPriorHTMLSibling(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outNode);
nsINode* GetNextHTMLSibling(nsINode* aNode);
nsresult GetNextHTMLSibling(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode);
nsINode* GetNextHTMLSibling(nsINode* aParent, PRInt32 aOffset);
nsresult GetNextHTMLSibling(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outNode);
nsresult GetPriorHTMLNode(nsIDOMNode *inNode, nsCOMPtr<nsIDOMNode> *outNode, bool bNoBlockCrossing = false);
nsresult GetPriorHTMLNode(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outNode, bool bNoBlockCrossing = false);