зеркало из https://github.com/mozilla/gecko-dev.git
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 : 40eaab3f8a13fdb7709d165f8374f96084121950
This commit is contained in:
Родитель
540f7d2d63
Коммит
6c4ca071b5
|
@ -17,6 +17,7 @@
|
|||
#include "mozilla/HTMLEditor.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "mozilla/dom/Selection.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/OwningNonNull.h"
|
||||
|
@ -3431,7 +3432,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)) {
|
||||
|
@ -4151,8 +4152,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;
|
||||
}
|
||||
|
@ -4233,8 +4233,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
|
||||
|
@ -4942,12 +4941,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);
|
||||
|
@ -4959,7 +4954,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
|
||||
|
@ -6547,10 +6542,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);
|
||||
|
@ -7877,23 +7869,24 @@ 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);
|
||||
Unused << kungFuDeathGrip;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -7902,24 +7895,20 @@ 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);
|
||||
mHTMLEditor->SplitNode(*curParent->AsContent(), offset, rv);
|
||||
if (NS_WARN_IF(rv.Failed())) {
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
}
|
||||
|
||||
if (!bIsFirstListItem) {
|
||||
|
@ -7927,16 +7916,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;
|
||||
}
|
||||
|
@ -7953,7 +7944,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);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче