Bug 1416099 - part 5: Rename |selNode|, |selOffset| and |newSelNode| in HTMLEditRules::ReturnInParagraph() to proper names r?m_kato
|selNode| and |selOffset| in HTMLEditRules::ReturnInParagraph() store the
point to split |aParentDivOrP|. So, they should be |containerAtSplitPoint|
and |offsetAtSplitPoint|.
Then, |newSelNode| can be renamed to |splitAfterNewBR|.
MozReview-Commit-ID: 1DcmLNx1Cff
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -6729,20 +6729,23 @@ HTMLEditRules::ReturnInParagraph(Selecti
if (!node) {
return EditActionResult(NS_ERROR_NULL_POINTER);
}
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor;
bool doesCRCreateNewP = htmlEditor->GetReturnInParagraphCreatesNewParagraph();
- bool newSelNode = false;
+ bool splitAfterNewBR = false;
nsCOMPtr<nsIContent> brNode;
- nsCOMPtr<nsIDOMNode> selNode = GetAsDOMNode(aNode);
- int32_t selOffset = aOffset;
+
+ // Point to split aParentDivOrP.
+ // XXX If we don't need to use nsIDOMNode here, we should use EditorDOMPoint.
+ nsCOMPtr<nsIDOMNode> containerAtSplitPoint = GetAsDOMNode(aNode);
+ int32_t offsetAtSplitPoint = aOffset;
EditorRawDOMPoint pointToInsertBR;
if (aNode == &aParentDivOrP && doesCRCreateNewP) {
// We are at the edges of the block, we don't need to create new <br>.
brNode = nullptr;
} else if (EditorBase::IsTextNode(aNode)) {
// at beginning of text node?
if (!aOffset) {
@@ -6768,21 +6771,22 @@ HTMLEditRules::ReturnInParagraph(Selecti
brNode = nullptr;
}
} else {
nsCOMPtr<nsINode> leftNode = node;
if (doesCRCreateNewP) {
nsCOMPtr<nsIDOMNode> leftDOMNode;
nsresult rv =
- htmlEditor->SplitNode(selNode, aOffset, getter_AddRefs(leftDOMNode));
+ htmlEditor->SplitNode(containerAtSplitPoint, offsetAtSplitPoint,
+ getter_AddRefs(leftDOMNode));
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditActionResult(rv);
}
- selNode = leftDOMNode;
+ containerAtSplitPoint = leftDOMNode;
leftNode = do_QueryInterface(leftDOMNode);
}
// We need to put new <br> after the left node if given node was split
// above.
pointToInsertBR.Set(leftNode);
DebugOnly<bool> advanced = pointToInsertBR.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
@@ -6800,17 +6804,17 @@ HTMLEditRules::ReturnInParagraph(Selecti
nearNode =
htmlEditor->GetNextEditableHTMLNode(
EditorRawDOMPoint(node, aChildAtOffset, aOffset));
if (!nearNode || !htmlEditor->IsVisibleBRElement(nearNode) ||
TextEditUtils::HasMozAttr(GetAsDOMNode(nearNode))) {
pointToInsertBR.Set(node, aOffset);
NS_WARNING_ASSERTION(pointToInsertBR.IsSetAndValid(),
"Failed to set point to insert <br> to given node");
- newSelNode = true;
+ splitAfterNewBR = true;
}
}
if (!pointToInsertBR.IsSet() && TextEditUtils::IsBreak(nearNode)) {
brNode = nearNode;
}
}
if (pointToInsertBR.IsSet()) {
// Don't modify the DOM tree if mHTMLEditor disappeared.
@@ -6820,25 +6824,25 @@ HTMLEditRules::ReturnInParagraph(Selecti
// if CR does not create a new P, default to BR creation
if (NS_WARN_IF(!doesCRCreateNewP)) {
return EditActionResult(NS_OK);
}
brNode = htmlEditor->CreateBR(pointToInsertBR.Container(),
pointToInsertBR.Offset());
- if (newSelNode) {
+ if (splitAfterNewBR) {
// We split the parent after the br we've just inserted.
- selNode = GetAsDOMNode(pointToInsertBR.Container());
- selOffset = pointToInsertBR.Offset() + 1;
+ containerAtSplitPoint = GetAsDOMNode(pointToInsertBR.Container());
+ offsetAtSplitPoint = pointToInsertBR.Offset() + 1;
}
}
EditActionResult result(
SplitParagraph(GetAsDOMNode(&aParentDivOrP), brNode, &aSelection,
- address_of(selNode), &selOffset));
+ address_of(containerAtSplitPoint), &offsetAtSplitPoint));
result.MarkAsHandled();
if (NS_WARN_IF(result.Failed())) {
return result;
}
return result;
}
nsresult