Bug 1324505 - Part 3. Clean up HTMLEditRules::PopListItem. r=masayuki

PopListItem still uses nsIDOM*.  We should new binding API instead and it is unnecessary to use QI and refcounting if possible.

MozReview-Commit-ID: DJL105hNt6z

--HG--
extra : rebase_source : ca3944abde042aac769c64ad5caf8903e715b31d
This commit is contained in:
Makoto Kato 2017-01-11 19:07:33 +09:00
Родитель 7aef46317d
Коммит 4306cf9aa6
4 изменённых файлов: 52 добавлений и 76 удалений

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

@ -3407,7 +3407,7 @@ HTMLEditRules::WillRemoveList(Selection* aSelection,
// unlist this listitem
bool bOutOfList;
do {
rv = PopListItem(GetAsDOMNode(curNode), &bOutOfList);
rv = PopListItem(*curNode->AsContent(), &bOutOfList);
NS_ENSURE_SUCCESS(rv, rv);
} while (!bOutOfList); // keep popping it out until it's not in a list anymore
} else if (HTMLEditUtils::IsList(curNode)) {
@ -4127,8 +4127,7 @@ HTMLEditRules::WillOutdent(Selection& aSelection,
lastBQChild = nullptr;
curBlockQuoteIsIndentedWithCSS = false;
}
bool unused;
rv = PopListItem(GetAsDOMNode(curNode), &unused);
rv = PopListItem(*curNode->AsContent());
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
@ -4209,8 +4208,7 @@ HTMLEditRules::WillOutdent(Selection& aSelection,
nsCOMPtr<nsIContent> child = curNode->GetLastChild();
while (child) {
if (HTMLEditUtils::IsListItem(child)) {
bool unused;
rv = PopListItem(GetAsDOMNode(child), &unused);
rv = PopListItem(*child);
NS_ENSURE_SUCCESS(rv, rv);
} else if (HTMLEditUtils::IsList(child)) {
// We have an embedded list, so move it out from under the parent
@ -4918,12 +4916,8 @@ HTMLEditRules::CheckForEmptyBlock(nsINode* aStartNode,
if (HTMLEditUtils::IsListItem(emptyBlock)) {
// Are we the first list item in the list?
bool bIsFirst;
NS_ENSURE_STATE(htmlEditor);
nsresult rv =
htmlEditor->IsFirstEditableChild(GetAsDOMNode(emptyBlock), &bIsFirst);
NS_ENSURE_SUCCESS(rv, rv);
if (bIsFirst) {
if (htmlEditor->IsFirstEditableChild(emptyBlock)) {
nsCOMPtr<nsINode> listParent = blockParent->GetParentNode();
NS_ENSURE_TRUE(listParent, NS_ERROR_FAILURE);
int32_t listOffset = listParent->IndexOf(blockParent);
@ -4935,7 +4929,7 @@ HTMLEditRules::CheckForEmptyBlock(nsINode* aStartNode,
htmlEditor->CreateBR(listParent, listOffset);
NS_ENSURE_STATE(br);
// Adjust selection to be right before it
rv = aSelection->Collapse(listParent, listOffset);
nsresult rv = aSelection->Collapse(listParent, listOffset);
NS_ENSURE_SUCCESS(rv, rv);
}
// Else just let selection percolate up. We'll adjust it in
@ -6523,10 +6517,7 @@ HTMLEditRules::ReturnInListItem(Selection& aSelection,
int32_t offset = listParent ? listParent->IndexOf(list) : -1;
// Are we the last list item in the list?
bool isLast;
rv = htmlEditor->IsLastEditableChild(aListItem.AsDOMNode(), &isLast);
NS_ENSURE_SUCCESS(rv, rv);
if (!isLast) {
if (!htmlEditor->IsLastEditableChild(&aListItem)) {
// We need to split the list!
ErrorResult rv;
htmlEditor->SplitNode(*list, itemOffset, rv);
@ -7853,23 +7844,23 @@ HTMLEditRules::ListIsEmptyLine(nsTArray<OwningNonNull<nsINode>>& aArrayOfNodes)
nsresult
HTMLEditRules::PopListItem(nsIDOMNode* aListItem,
HTMLEditRules::PopListItem(nsIContent& aListItem,
bool* aOutOfList)
{
nsCOMPtr<Element> listItem = do_QueryInterface(aListItem);
// check parms
NS_ENSURE_TRUE(listItem && aOutOfList, NS_ERROR_NULL_POINTER);
// init out params
*aOutOfList = false;
if (aOutOfList) {
*aOutOfList = false;
}
nsCOMPtr<nsINode> curParent = listItem->GetParentNode();
nsCOMPtr<nsIContent> kungFuDeathGrip(&aListItem);
nsCOMPtr<nsINode> curParent = aListItem.GetParentNode();
if (NS_WARN_IF(!curParent)) {
return NS_ERROR_FAILURE;
}
int32_t offset = curParent->IndexOf(listItem);
int32_t offset = curParent->IndexOf(&aListItem);
if (!HTMLEditUtils::IsListItem(listItem)) {
if (!HTMLEditUtils::IsListItem(&aListItem)) {
return NS_ERROR_FAILURE;
}
@ -7878,24 +7869,21 @@ HTMLEditRules::PopListItem(nsIDOMNode* aListItem,
nsCOMPtr<nsINode> curParPar = curParent->GetParentNode();
int32_t parOffset = curParPar ? curParPar->IndexOf(curParent) : -1;
bool bIsFirstListItem;
NS_ENSURE_STATE(mHTMLEditor);
nsresult rv =
mHTMLEditor->IsFirstEditableChild(aListItem, &bIsFirstListItem);
NS_ENSURE_SUCCESS(rv, rv);
bool bIsFirstListItem = mHTMLEditor->IsFirstEditableChild(&aListItem);
bool bIsLastListItem;
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->IsLastEditableChild(aListItem, &bIsLastListItem);
NS_ENSURE_SUCCESS(rv, rv);
bool bIsLastListItem = mHTMLEditor->IsLastEditableChild(&aListItem);
if (!bIsFirstListItem && !bIsLastListItem) {
// split the list
nsCOMPtr<nsIDOMNode> newBlock;
ErrorResult rv;
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->SplitNode(GetAsDOMNode(curParent), offset,
getter_AddRefs(newBlock));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIContent> newBlock =
mHTMLEditor->SplitNode(*curParent->AsContent(), offset, rv);
if (NS_WARN_IF(rv.Failed())) {
return rv.StealNSResult();
}
}
if (!bIsFirstListItem) {
@ -7903,16 +7891,18 @@ HTMLEditRules::PopListItem(nsIDOMNode* aListItem,
}
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->MoveNode(listItem, curParPar, parOffset);
nsresult rv = mHTMLEditor->MoveNode(&aListItem, curParPar, parOffset);
NS_ENSURE_SUCCESS(rv, rv);
// unwrap list item contents if they are no longer in a list
if (!HTMLEditUtils::IsList(curParPar) &&
HTMLEditUtils::IsListItem(listItem)) {
HTMLEditUtils::IsListItem(&aListItem)) {
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->RemoveBlockContainer(*listItem);
rv = mHTMLEditor->RemoveBlockContainer(*aListItem.AsElement());
NS_ENSURE_SUCCESS(rv, rv);
*aOutOfList = true;
if (aOutOfList) {
*aOutOfList = true;
}
}
return NS_OK;
}
@ -7929,7 +7919,7 @@ HTMLEditRules::RemoveListStructure(Element& aList)
bool isOutOfList;
// Keep popping it out until it's not in a list anymore
do {
nsresult rv = PopListItem(child->AsDOMNode(), &isOutOfList);
nsresult rv = PopListItem(child, &isOutOfList);
NS_ENSURE_SUCCESS(rv, rv);
} while (!isOutOfList);
} else if (HTMLEditUtils::IsList(child)) {

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

@ -372,7 +372,7 @@ protected:
EditorDOMPoint JoinNodesSmart(nsIContent& aNodeLeft,
nsIContent& aNodeRight);
Element* GetTopEnclosingMailCite(nsINode& aNode);
nsresult PopListItem(nsIDOMNode* aListItem, bool* aOutOfList);
nsresult PopListItem(nsIContent& aListItem, bool* aOutOfList = nullptr);
nsresult RemoveListStructure(Element& aList);
nsresult CacheInlineStyles(nsIDOMNode* aNode);
nsresult ReapplyCachedStyles();

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

@ -1572,12 +1572,10 @@ HTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement,
rv = SetCaretAfterElement(aElement);
NS_ENSURE_SUCCESS(rv, rv);
}
// check for inserting a whole table at the end of a block. If so insert a br after it.
// check for inserting a whole table at the end of a block. If so insert
// a br after it.
if (HTMLEditUtils::IsTable(node)) {
bool isLast;
rv = IsLastEditableChild(node, &isLast);
NS_ENSURE_SUCCESS(rv, rv);
if (isLast) {
if (IsLastEditableChild(element)) {
nsCOMPtr<nsIDOMNode> brNode;
rv = CreateBR(parentSelectedNode, offsetForInsert + 1,
address_of(brNode));
@ -4152,40 +4150,28 @@ HTMLEditor::GetNextHTMLNode(nsIDOMNode* aNode,
return NS_OK;
}
nsresult
HTMLEditor::IsFirstEditableChild(nsIDOMNode* aNode,
bool* aOutIsFirst)
bool
HTMLEditor::IsFirstEditableChild(nsINode* aNode)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_ENSURE_TRUE(aOutIsFirst && node, NS_ERROR_NULL_POINTER);
// init out parms
*aOutIsFirst = false;
MOZ_ASSERT(aNode);
// find first editable child and compare it to aNode
nsCOMPtr<nsINode> parent = node->GetParentNode();
NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
*aOutIsFirst = (GetFirstEditableChild(*parent) == node);
return NS_OK;
nsCOMPtr<nsINode> parent = aNode->GetParentNode();
if (NS_WARN_IF(!parent)) {
return false;
}
return (GetFirstEditableChild(*parent) == aNode);
}
nsresult
HTMLEditor::IsLastEditableChild(nsIDOMNode* aNode,
bool* aOutIsLast)
bool
HTMLEditor::IsLastEditableChild(nsINode* aNode)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_ENSURE_TRUE(aOutIsLast && node, NS_ERROR_NULL_POINTER);
// init out parms
*aOutIsLast = false;
MOZ_ASSERT(aNode);
// find last editable child and compare it to aNode
nsCOMPtr<nsINode> parent = node->GetParentNode();
NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
*aOutIsLast = (GetLastEditableChild(*parent) == node);
return NS_OK;
nsCOMPtr<nsINode> parent = aNode->GetParentNode();
if (NS_WARN_IF(!parent)) {
return false;
}
return (GetLastEditableChild(*parent) == aNode);
}
nsIContent*

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

@ -840,8 +840,8 @@ protected:
nsCOMPtr<nsIDOMNode>* outNode,
bool bNoBlockCrossing = false);
nsresult IsFirstEditableChild(nsIDOMNode* aNode, bool* aOutIsFirst);
nsresult IsLastEditableChild(nsIDOMNode* aNode, bool* aOutIsLast);
bool IsFirstEditableChild(nsINode* aNode);
bool IsLastEditableChild(nsINode* aNode);
nsIContent* GetFirstEditableChild(nsINode& aNode);
nsIContent* GetLastEditableChild(nsINode& aNode);