Bug 1413181 - part 5: HTMLEditRules::SplitParagraph() should take EditorRawDOMPoint instead of a set of container node and offset r?m_kato
Although, we need to make WSRunObject::PrepareToSplitAcrossBlocks() in
another bug, we should do it now for making HTMLEditRules::ReturnInParagraph()
implementation simpler.
MozReview-Commit-ID: AoMYqAEgCaV
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -6856,62 +6856,62 @@ HTMLEditRules::ReturnInParagraph(Selecti
// We split the parent after the br we've just inserted.
pointToSplitParentDivOrP.Set(brNode);
DebugOnly<bool> advanced = pointToSplitParentDivOrP.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset after the new <br>");
}
}
EditActionResult result(
- SplitParagraph(aSelection, aParentDivOrP, brNode,
- *pointToSplitParentDivOrP.Container(),
- pointToSplitParentDivOrP.Offset()));
+ SplitParagraph(aSelection, aParentDivOrP, pointToSplitParentDivOrP.AsRaw(),
+ brNode));
result.MarkAsHandled();
if (NS_WARN_IF(result.Failed())) {
return result;
}
return result;
}
nsresult
HTMLEditRules::SplitParagraph(Selection& aSelection,
- Element& aPara,
- nsIContent* aBRNode,
- nsINode& aSelNode,
- int32_t aOffset)
+ Element& aParentDivOrP,
+ const EditorRawDOMPoint& aStartOfRightNode,
+ nsIContent* aNextBRNode)
{
if (NS_WARN_IF(!mHTMLEditor)) {
return NS_ERROR_NOT_AVAILABLE;
}
RefPtr<HTMLEditor> htmlEditor = mHTMLEditor;
// split para
// get ws code to adjust any ws
nsCOMPtr<nsIContent> leftPara, rightPara;
- nsCOMPtr<nsINode> selNode = &aSelNode;
+ nsCOMPtr<nsINode> selNode = aStartOfRightNode.Container();
+ int32_t selOffset = aStartOfRightNode.Offset();
nsresult rv =
WSRunObject::PrepareToSplitAcrossBlocks(htmlEditor,
- address_of(selNode), &aOffset);
+ address_of(selNode), &selOffset);
// XXX When it fails, why do we need to return selection node? (Why can the
// caller trust the result even when it returns error?)
NS_ENSURE_SUCCESS(rv, rv);
// split the paragraph
NS_ENSURE_STATE(selNode->IsContent());
int32_t offset =
- htmlEditor->SplitNodeDeep(aPara, *selNode->AsContent(), aOffset,
+ htmlEditor->SplitNodeDeep(aParentDivOrP, *selNode->AsContent(), selOffset,
HTMLEditor::EmptyContainers::yes,
getter_AddRefs(leftPara),
getter_AddRefs(rightPara));
if (NS_WARN_IF(offset == -1)) {
return NS_ERROR_FAILURE;
}
- // get rid of the break, if it is visible (otherwise it may be needed to prevent an empty p)
- if (aBRNode && htmlEditor->IsVisibleBRElement(aBRNode)) {
- rv = htmlEditor->DeleteNode(aBRNode);
+ // Get rid of the break, if it is visible (otherwise it may be needed to
+ // prevent an empty p).
+ if (aNextBRNode && htmlEditor->IsVisibleBRElement(aNextBRNode)) {
+ rv = htmlEditor->DeleteNode(aNextBRNode);
NS_ENSURE_SUCCESS(rv, rv);
}
// remove ID attribute on the paragraph we just created
rv = htmlEditor->RemoveAttribute(rightPara->AsElement(), nsGkAtoms::id);
NS_ENSURE_SUCCESS(rv, rv);
// We need to ensure to both paragraphs visible even if they are empty.
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -309,28 +309,30 @@ protected:
* split the paragraph, marked as handled.
*/
EditActionResult ReturnInParagraph(Selection& aSelection,
Element& aParentDivOrP);
/**
* SplitParagraph() splits the parent block, aPara, at aSelNode - aOffset.
*
- * @param aSelection The selection.
- * @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 aSelNode Set the selection container to split aPara at.
- * @param aOffset Set the offset in the container.
+ * @param aSelection The selection.
+ * @param aParentDivOrP The parent block to be split. This must be <p>
+ * or <div> element.
+ * @param aStartOfRightNode The point to be start of right node after
+ * split. This must be descendant of
+ * aParentDivOrP.
+ * @param aNextBRNode Next <br> node if there is. Otherwise, nullptr.
+ * If this is not nullptr, the <br> node may be
+ * removed.
*/
nsresult SplitParagraph(Selection& aSelection,
- Element& aPara,
- nsIContent* aBRNode,
- nsINode& aSelNode,
- int32_t aOffset);
+ Element& aParentDivOrP,
+ const EditorRawDOMPoint& aStartOfRightNode,
+ nsIContent* aBRNode);
nsresult ReturnInListItem(Selection& aSelection, Element& aHeader,
nsINode& aNode, int32_t aOffset);
nsresult AfterEditInner(EditAction action,
nsIEditor::EDirection aDirection);
nsresult RemovePartOfBlock(Element& aBlock, nsIContent& aStartChild,
nsIContent& aEndChild);
void SplitBlock(Element& aBlock,