Bug 1416099 - part 3: Rename aPara of HTMLEditRules::ReturnInParagraph() to aParentDivOrP and make it and aSelection as references r=m_kato

This cleans up |aSelection| and |aPara| of HTMLEditRules::ReturnInParagraph().

|aSelection| should be reference for avoiding nullptr check.

|aPara| is so too.  Additionally, the name is not clear.  We should rename it
to |aParentDivOrP| because it's a block parent of the point and has to be
<div> or <p> element.

MozReview-Commit-ID: 8LbKGlrvaIj

--HG--
extra : rebase_source : e0593c916791ec5b39b4138e21b6ce8c680dc4d8
This commit is contained in:
Masayuki Nakano 2017-11-10 14:58:53 +09:00
parent 77dd49f0f4
commit aee5a42ba9
2 changed files with 23 additions and 13 deletions

View File

@ -1789,7 +1789,7 @@ HTMLEditRules::WillInsertBreak(Selection& aSelection,
blockParent->IsAnyOfHTMLElements(nsGkAtoms::p, nsGkAtoms::div))) {
// Paragraphs: special rules to look for <br>s
EditActionResult result =
ReturnInParagraph(&aSelection, blockParent, node, offset, child);
ReturnInParagraph(aSelection, *blockParent, node, offset, child);
if (NS_WARN_IF(result.Failed())) {
return result.Rv();
}
@ -6714,15 +6714,9 @@ HTMLEditRules::ReturnInHeader(Selection& aSelection,
return NS_OK;
}
/**
* ReturnInParagraph() does the right thing for returns pressed in paragraphs.
* For our purposes, this means either <p> or <div>, which is not in keeping
* with the semantics of <div>, but is necessary for compatibility with other
* browsers.
*/
EditActionResult
HTMLEditRules::ReturnInParagraph(Selection* aSelection,
nsINode* aPara,
HTMLEditRules::ReturnInParagraph(Selection& aSelection,
nsINode& aParentDivOrP,
nsINode* aNode,
int32_t aOffset,
nsIContent* aChildAtOffset)
@ -6732,7 +6726,7 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
}
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
if (!aSelection || !aPara || !node) {
if (!node) {
return EditActionResult(NS_ERROR_NULL_POINTER);
}
@ -6749,7 +6743,7 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
nsCOMPtr<nsIDOMNode> selNode = GetAsDOMNode(aNode);
int32_t selOffset = aOffset;
if (aNode == aPara && doesCRCreateNewP) {
if (aNode == &aParentDivOrP && doesCRCreateNewP) {
// we are at the edges of the block, newBRneeded not needed!
brNode = nullptr;
} else if (EditorBase::IsTextNode(aNode)) {
@ -6831,7 +6825,7 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
}
}
EditActionResult result(
SplitParagraph(GetAsDOMNode(aPara), brNode, aSelection,
SplitParagraph(GetAsDOMNode(&aParentDivOrP), brNode, &aSelection,
address_of(selNode), &selOffset));
result.MarkAsHandled();
if (NS_WARN_IF(result.Failed())) {

View File

@ -294,7 +294,23 @@ protected:
nsAtom& DefaultParagraphSeparator();
nsresult ReturnInHeader(Selection& aSelection, Element& aHeader,
nsINode& aNode, int32_t aOffset);
EditActionResult ReturnInParagraph(Selection* aSelection, nsINode* aHeader,
/**
* ReturnInParagraph() does the right thing for Enter key press or
* 'insertParagraph' command in aParentDivOrP.
*
* @param aSelection The selection
* @param aParentDivOrP The parent block. This must be <p> or <div>
* element.
* @param aTextNode
* @param aOffset
* @param aChildAtOffset
* @return Returns with NS_OK if this doesn't meat any
* unexpected situation. If this method tries to
* split the paragraph, marked as handled.
*/
EditActionResult ReturnInParagraph(Selection& aSelection,
nsINode& aParentDivOrP,
nsINode* aTextNode, int32_t aOffset,
nsIContent* aChildAtOffset);