Bug 1432186 part 10. Remove nsIDOMNode's lastChild attribute. r=mccr8

MozReview-Commit-ID: FhJs1MXAyeO
This commit is contained in:
Boris Zbarsky 2018-01-29 23:10:51 -05:00
parent baca310fed
commit 96697d35fe
7 changed files with 26 additions and 67 deletions

View File

@ -545,19 +545,6 @@ nsINode::GetFirstChild(nsIDOMNode** aNode)
return NS_OK;
}
nsresult
nsINode::GetLastChild(nsIDOMNode** aNode)
{
nsIContent* child = GetLastChild();
if (child) {
return CallQueryInterface(child, aNode);
}
*aNode = nullptr;
return NS_OK;
}
nsresult
nsINode::GetPreviousSibling(nsIDOMNode** aPrevSibling)
{

View File

@ -2079,7 +2079,6 @@ protected:
nsresult GetParentNode(nsIDOMNode** aParentNode);
nsresult GetChildNodes(nsIDOMNodeList** aChildNodes);
nsresult GetFirstChild(nsIDOMNode** aFirstChild);
nsresult GetLastChild(nsIDOMNode** aLastChild);
nsresult GetPreviousSibling(nsIDOMNode** aPrevSibling);
nsresult GetNextSibling(nsIDOMNode** aNextSibling);
nsresult GetOwnerDocument(nsIDOMDocument** aOwnerDocument);
@ -2281,10 +2280,6 @@ ToCanonicalSupports(nsINode* aPointer)
{ \
return nsINode::GetFirstChild(aFirstChild); \
} \
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild) __VA_ARGS__ override \
{ \
return nsINode::GetLastChild(aLastChild); \
} \
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling) __VA_ARGS__ override \
{ \
return nsINode::GetPreviousSibling(aPreviousSibling); \

View File

@ -35,7 +35,6 @@ interface nsIDOMNode : nsISupports
readonly attribute nsIDOMNode parentNode;
readonly attribute nsIDOMNodeList childNodes;
readonly attribute nsIDOMNode firstChild;
readonly attribute nsIDOMNode lastChild;
readonly attribute nsIDOMNode previousSibling;
readonly attribute nsIDOMNode nextSibling;
// Modified in DOM Level 2:

View File

@ -3088,8 +3088,7 @@ HTMLEditor::DeleteSelectionImpl(EDirection aAction,
nsresult
HTMLEditor::DeleteNode(nsINode* aNode)
{
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode);
return DeleteNode(node);
return DeleteNode(aNode->AsDOMNode());
}
NS_IMETHODIMP

View File

@ -731,9 +731,9 @@ protected:
nsresult CreateDOMFragmentFromPaste(const nsAString& aInputString,
const nsAString& aContextStr,
const nsAString& aInfoStr,
nsCOMPtr<nsIDOMNode>* outFragNode,
nsCOMPtr<nsIDOMNode>* outStartNode,
nsCOMPtr<nsIDOMNode>* outEndNode,
nsCOMPtr<nsINode>* outFragNode,
nsCOMPtr<nsINode>* outStartNode,
nsCOMPtr<nsINode>* outEndNode,
int32_t* outStartOffset,
int32_t* outEndOffset,
bool aTrustedInput);

View File

@ -217,7 +217,7 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
NS_ENSURE_STATE(selection);
// create a dom document fragment that represents the structure to paste
nsCOMPtr<nsIDOMNode> fragmentAsNode, streamStartParent, streamEndParent;
nsCOMPtr<nsINode> fragmentAsNode, streamStartParent, streamEndParent;
int32_t streamStartOffset = 0, streamEndOffset = 0;
nsresult rv = CreateDOMFragmentFromPaste(aInputString, aContextStr, aInfoStr,
@ -269,18 +269,10 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
// make a list of what nodes in docFrag we need to move
nsTArray<OwningNonNull<nsINode>> nodeList;
nsCOMPtr<nsINode> fragmentAsNodeNode = do_QueryInterface(fragmentAsNode);
NS_ENSURE_STATE(fragmentAsNodeNode || !fragmentAsNode);
nsCOMPtr<nsINode> streamStartParentNode =
do_QueryInterface(streamStartParent);
NS_ENSURE_STATE(streamStartParentNode || !streamStartParent);
nsCOMPtr<nsINode> streamEndParentNode =
do_QueryInterface(streamEndParent);
NS_ENSURE_STATE(streamEndParentNode || !streamEndParent);
CreateListOfNodesToPaste(*static_cast<DocumentFragment*>(fragmentAsNodeNode.get()),
CreateListOfNodesToPaste(*static_cast<DocumentFragment*>(fragmentAsNode.get()),
nodeList,
streamStartParentNode, streamStartOffset,
streamEndParentNode, streamEndOffset);
streamStartParent, streamStartOffset,
streamEndParent, streamEndOffset);
if (nodeList.IsEmpty()) {
// We aren't inserting anything, but if aDeleteSelection is set, we do want
@ -435,7 +427,7 @@ HTMLEditor::DoInsertHTMLWithContext(const nsAString& aInputString,
nsCOMPtr<nsIContent> lastInsertNode;
nsCOMPtr<nsINode> insertedContextParent;
for (OwningNonNull<nsINode>& curNode : nodeList) {
if (NS_WARN_IF(curNode == fragmentAsNodeNode) ||
if (NS_WARN_IF(curNode == fragmentAsNode) ||
NS_WARN_IF(TextEditUtils::IsBody(curNode))) {
return NS_ERROR_FAILURE;
}
@ -2050,9 +2042,9 @@ nsresult
HTMLEditor::CreateDOMFragmentFromPaste(const nsAString& aInputString,
const nsAString& aContextStr,
const nsAString& aInfoStr,
nsCOMPtr<nsIDOMNode>* outFragNode,
nsCOMPtr<nsIDOMNode>* outStartNode,
nsCOMPtr<nsIDOMNode>* outEndNode,
nsCOMPtr<nsINode>* outFragNode,
nsCOMPtr<nsINode>* outStartNode,
nsCOMPtr<nsINode>* outEndNode,
int32_t* outStartOffset,
int32_t* outEndOffset,
bool aTrustedInput)
@ -2118,7 +2110,7 @@ HTMLEditor::CreateDOMFragmentFromPaste(const nsAString& aInputString,
// If there was no context, then treat all of the data we did get as the
// pasted data.
if (contextLeaf) {
*outEndNode = *outStartNode = contextLeaf->AsDOMNode();
*outEndNode = *outStartNode = contextLeaf;
} else {
*outEndNode = *outStartNode = fragment;
}
@ -2135,24 +2127,21 @@ HTMLEditor::CreateDOMFragmentFromPaste(const nsAString& aInputString,
// Move the start and end children.
nsresult err;
int32_t num = numstr1.ToInteger(&err);
nsCOMPtr<nsIDOMNode> tmp;
while (num--) {
(*outStartNode)->GetFirstChild(getter_AddRefs(tmp));
nsINode* tmp = (*outStartNode)->GetFirstChild();
NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
tmp.swap(*outStartNode);
*outStartNode = tmp;
}
num = numstr2.ToInteger(&err);
while (num--) {
(*outEndNode)->GetLastChild(getter_AddRefs(tmp));
nsINode* tmp = (*outEndNode)->GetLastChild();
NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE);
tmp.swap(*outEndNode);
*outEndNode = tmp;
}
}
nsCOMPtr<nsINode> node = do_QueryInterface(*outEndNode);
*outEndOffset = node->Length();
*outEndOffset = (*outEndNode)->Length();
return NS_OK;
}

View File

@ -378,22 +378,17 @@ HTMLEditor::GetLastCellInRow(nsIDOMNode* aRowNode,
*aCellNode = nullptr;
NS_ENSURE_TRUE(aRowNode, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsINode> rowNode = do_QueryInterface(aRowNode);
NS_ENSURE_TRUE(rowNode, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMNode> rowChild;
nsresult rv = aRowNode->GetLastChild(getter_AddRefs(rowChild));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsINode> rowChild = rowNode->GetLastChild();
while (rowChild && !HTMLEditUtils::IsTableCell(rowChild)) {
// Skip over textnodes
nsCOMPtr<nsIDOMNode> previousChild;
rv = rowChild->GetPreviousSibling(getter_AddRefs(previousChild));
NS_ENSURE_SUCCESS(rv, rv);
rowChild = previousChild;
rowChild = rowChild->GetPreviousSibling();
}
if (rowChild) {
*aCellNode = rowChild.get();
*aCellNode = rowChild->AsDOMNode();
NS_ADDREF(*aCellNode);
return NS_OK;
}
@ -990,20 +985,15 @@ HTMLEditor::DeleteTableCellContents()
nsresult
HTMLEditor::DeleteCellContents(nsIDOMElement* aCell)
{
NS_ENSURE_TRUE(aCell, NS_ERROR_NULL_POINTER);
nsCOMPtr<Element> cell = do_QueryInterface(aCell);
NS_ENSURE_TRUE(cell, NS_ERROR_NULL_POINTER);
// Prevent rules testing until we're done
AutoRules beginRulesSniffing(this, EditAction::deleteNode, nsIEditor::eNext);
nsCOMPtr<nsIDOMNode> child;
bool hasChild;
aCell->HasChildNodes(&hasChild);
while (hasChild) {
aCell->GetLastChild(getter_AddRefs(child));
while (nsCOMPtr<nsINode> child = cell->GetLastChild()) {
nsresult rv = DeleteNode(child);
NS_ENSURE_SUCCESS(rv, rv);
aCell->HasChildNodes(&hasChild);
}
return NS_OK;
}