Bug 1417344 - Clean up HTMLEditor::InsertBR. r?masayuki
No one uses out parameter of InsertBR, so we should remove it. Also, CreateBR
has direction parameter for selection, so we should use it.
MozReview-Commit-ID: 8heqaXpR9He
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -949,18 +949,17 @@ HTMLEditor::TypedText(const nsAString& a
ETypingAction aAction)
{
MOZ_ASSERT(!aString.IsEmpty() || aAction != eTypedText);
AutoPlaceholderBatch batch(this, nsGkAtoms::TypingTxnName);
if (aAction == eTypedBR) {
// only inserts a br node
- nsCOMPtr<nsIDOMNode> brNode;
- return InsertBR(address_of(brNode));
+ return InsertBR();
}
return TextEditor::TypedText(aString, aAction);
}
nsresult
HTMLEditor::TabInTable(bool inIsShift,
bool* outHandled)
@@ -1057,53 +1056,41 @@ HTMLEditor::CreateBR(nsIDOMNode* aNode,
EDirection aSelect)
{
nsCOMPtr<nsIDOMNode> parent = aNode;
int32_t offset = aOffset;
return CreateBRImpl(address_of(parent), &offset, outBRNode, aSelect);
}
nsresult
-HTMLEditor::InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode)
+HTMLEditor::InsertBR()
{
- NS_ENSURE_TRUE(outBRNode, NS_ERROR_NULL_POINTER);
- *outBRNode = nullptr;
-
// calling it text insertion to trigger moz br treatment by rules
AutoRules beginRulesSniffing(this, EditAction::insertText, nsIEditor::eNext);
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_STATE(selection);
if (!selection->Collapsed()) {
nsresult rv = DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
NS_ENSURE_SUCCESS(rv, rv);
}
- nsCOMPtr<nsIDOMNode> selNode;
+ nsCOMPtr<nsINode> selNode;
int32_t selOffset;
nsresult rv =
GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset);
NS_ENSURE_SUCCESS(rv, rv);
- rv = CreateBR(selNode, selOffset, outBRNode);
- NS_ENSURE_SUCCESS(rv, rv);
-
- selection->SetInterlinePosition(true);
-
// position selection after br
- nsCOMPtr<nsINode> brNode = do_QueryInterface(*outBRNode);
- if (NS_WARN_IF(!brNode)) {
+ RefPtr<Element> br = CreateBR(selNode, selOffset, nsIEditor::eNext);
+ if (NS_WARN_IF(!br)) {
return NS_ERROR_FAILURE;
}
- EditorRawDOMPoint afterBrNode(brNode);
- if (NS_WARN_IF(!afterBrNode.AdvanceOffset())) {
- return NS_ERROR_FAILURE;
- }
- return selection->Collapse(afterBrNode);
+ return NS_OK;
}
void
HTMLEditor::CollapseSelectionToDeepestNonTableFirstChild(Selection* aSelection,
nsINode* aNode)
{
MOZ_ASSERT(aNode);
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -472,17 +472,17 @@ protected:
nsresult TabInTable(bool inIsShift, bool* outHandled);
already_AddRefed<Element> CreateBR(nsINode* aNode, int32_t aOffset,
EDirection aSelect = eNone);
NS_IMETHOD CreateBR(
nsIDOMNode* aNode, int32_t aOffset,
nsCOMPtr<nsIDOMNode>* outBRNode,
nsIEditor::EDirection aSelect = nsIEditor::eNone) override;
- nsresult InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode);
+ nsresult InsertBR();
// Table Editing (implemented in nsTableEditor.cpp)
/**
* Insert a new cell after or before supplied aCell.
* Optional: If aNewCell supplied, returns the newly-created cell (addref'd,
* of course)
* This doesn't change or use the current selection.