Bug 1416099 - part 2: Rename |sibling| in HTMLEditRules::ReturnInParagraph() to |brNode| r=m_kato

The local variable |sibling| in HTMLEditRules::ReturnInParagraph() is set to
aBRNode of SplitParagraph().  So, the name should be renamed to |brNode|.

Then, the |brNode| should be cleared if it's not a <br> node actually.  However,
SplitParagraph() doesn't allow aBRNode to be nullptr.  aBRNode is only used to
remove it from the document if it's not necessary.  So, it should be able to be
nullptr.  Therefore, this patch changes SplitParagraph() too.

Note that SplitParagrah() is called only by ReturnInParagraph().  So, we don't
need to worry about other callers.

MozReview-Commit-ID: 7Ynk9m5F8Mi

--HG--
extra : rebase_source : e2583c70ad274fe74f48df687796ed71a66bdf98
This commit is contained in:
Masayuki Nakano 2017-11-10 14:43:13 +09:00
parent 69c8b0b603
commit 77dd49f0f4
2 changed files with 37 additions and 20 deletions

View File

@ -6745,31 +6745,33 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
bool newBRneeded = false;
bool newSelNode = false;
nsCOMPtr<nsIContent> sibling;
nsCOMPtr<nsIContent> brNode;
nsCOMPtr<nsIDOMNode> selNode = GetAsDOMNode(aNode);
int32_t selOffset = aOffset;
if (aNode == aPara && doesCRCreateNewP) {
// we are at the edges of the block, newBRneeded not needed!
sibling = node->AsContent();
brNode = nullptr;
} else if (EditorBase::IsTextNode(aNode)) {
// at beginning of text node?
if (!aOffset) {
// is there a BR prior to it?
sibling = htmlEditor->GetPriorHTMLSibling(node);
if (!sibling ||
!htmlEditor->IsVisibleBRElement(sibling) ||
TextEditUtils::HasMozAttr(GetAsDOMNode(sibling))) {
brNode = htmlEditor->GetPriorHTMLSibling(node);
if (!brNode ||
!htmlEditor->IsVisibleBRElement(brNode) ||
TextEditUtils::HasMozAttr(GetAsDOMNode(brNode))) {
newBRneeded = true;
brNode = nullptr;
}
} else if (aOffset == static_cast<int32_t>(node->Length())) {
// we're at the end of text node...
// is there a BR after to it?
sibling = htmlEditor->GetNextHTMLSibling(node);
if (!sibling ||
!htmlEditor->IsVisibleBRElement(sibling) ||
TextEditUtils::HasMozAttr(GetAsDOMNode(sibling))) {
brNode = htmlEditor->GetNextHTMLSibling(node);
if (!brNode ||
!htmlEditor->IsVisibleBRElement(brNode) ||
TextEditUtils::HasMozAttr(GetAsDOMNode(brNode))) {
newBRneeded = true;
brNode = nullptr;
offset++;
}
} else {
@ -6806,8 +6808,8 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
newSelNode = true;
}
}
if (!newBRneeded) {
sibling = nearNode;
if (!newBRneeded && TextEditUtils::IsBreak(nearNode)) {
brNode = nearNode;
}
}
if (newBRneeded) {
@ -6821,7 +6823,7 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
return EditActionResult(NS_OK);
}
sibling = htmlEditor->CreateBR(parent, offset);
brNode = htmlEditor->CreateBR(parent, offset);
if (newSelNode) {
// We split the parent after the br we've just inserted.
selNode = GetAsDOMNode(parent);
@ -6829,7 +6831,7 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
}
}
EditActionResult result(
SplitParagraph(GetAsDOMNode(aPara), sibling, aSelection,
SplitParagraph(GetAsDOMNode(aPara), brNode, aSelection,
address_of(selNode), &selOffset));
result.MarkAsHandled();
if (NS_WARN_IF(result.Failed())) {
@ -6838,10 +6840,6 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
return result;
}
/**
* SplitParagraph() splits a paragraph at selection point, possibly deleting a
* br.
*/
nsresult
HTMLEditRules::SplitParagraph(nsIDOMNode *aPara,
nsIContent* aBRNode,
@ -6850,7 +6848,7 @@ HTMLEditRules::SplitParagraph(nsIDOMNode *aPara,
int32_t* aOffset)
{
nsCOMPtr<Element> para = do_QueryInterface(aPara);
NS_ENSURE_TRUE(para && aBRNode && aSelNode && *aSelNode && aOffset &&
NS_ENSURE_TRUE(para && aSelNode && *aSelNode && aOffset &&
aSelection, NS_ERROR_NULL_POINTER);
// split para
@ -6878,7 +6876,8 @@ HTMLEditRules::SplitParagraph(nsIDOMNode *aPara,
}
// get rid of the break, if it is visible (otherwise it may be needed to prevent an empty p)
NS_ENSURE_STATE(mHTMLEditor);
if (mHTMLEditor->IsVisibleBRElement(aBRNode)) {
if (aBRNode &&
mHTMLEditor->IsVisibleBRElement(aBRNode)) {
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->DeleteNode(aBRNode);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -297,11 +297,29 @@ protected:
EditActionResult ReturnInParagraph(Selection* aSelection, nsINode* aHeader,
nsINode* aTextNode, int32_t aOffset,
nsIContent* aChildAtOffset);
/**
* SplitParagraph() splits the parent block, aPara, at aSelNode - aOffset.
*
* @param aPara The parent block to be split.
* @param aBRNode Next <br> node if there is. Otherwise, nullptr.
* If this is not nullptr, the <br> node may be removed.
* @param aSelection The selection.
* @param aSelNode Set the selection container to split aPara at.
* Actual container node will be set by this method.
* XXX: The only caller ReturnInParagraph() doesn't need
* this result.
* @param aOffset Set the offset in the container.
* Actual offset will be set by this method.
* XXX: The only caller ReturnInParagraph() doesn't need
* this result.
*/
nsresult SplitParagraph(nsIDOMNode* aPara,
nsIContent* aBRNode,
Selection* aSelection,
nsCOMPtr<nsIDOMNode>* aSelNode,
int32_t* aOffset);
nsresult ReturnInListItem(Selection& aSelection, Element& aHeader,
nsINode& aNode, int32_t aOffset);
nsresult AfterEditInner(EditAction action,