Bug 1332977 - Move InsertBR into TextEditor to HTMLEditor. r?masayuki
TextEditor::InsertBR is called from HTMLEditor::TypedText only. So we should move it to HTMLEditor.
MozReview-Commit-ID: 4rPcayd9T5n
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1125,16 +1125,48 @@ HTMLEditor::CreateBR(nsIDOMNode* aNode,
nsCOMPtr<nsIDOMNode>* outBRNode,
EDirection aSelect)
{
nsCOMPtr<nsIDOMNode> parent = aNode;
int32_t offset = aOffset;
return CreateBRImpl(address_of(parent), &offset, outBRNode, aSelect);
}
+nsresult
+HTMLEditor::InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode)
+{
+ 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;
+ 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);
+
+ // position selection after br
+ selNode = GetNodeLocation(*outBRNode, &selOffset);
+ selection->SetInterlinePosition(true);
+ return selection->Collapse(selNode, selOffset+1);
+}
+
void
HTMLEditor::CollapseSelectionToDeepestNonTableFirstChild(Selection* aSelection,
nsINode* aNode)
{
MOZ_ASSERT(aNode);
RefPtr<Selection> selection = aSelection;
if (!selection) {
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -496,16 +496,18 @@ protected:
NS_IMETHOD 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);
+
// 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.
*/
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -524,48 +524,16 @@ TextEditor::CreateBR(nsIDOMNode* aNode,
EDirection aSelect)
{
nsCOMPtr<nsIDOMNode> parent = aNode;
int32_t offset = aOffset;
return CreateBRImpl(address_of(parent), &offset, outBRNode, aSelect);
}
nsresult
-TextEditor::InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode)
-{
- 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;
- 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);
-
- // position selection after br
- selNode = GetNodeLocation(*outBRNode, &selOffset);
- selection->SetInterlinePosition(true);
- return selection->Collapse(selNode, selOffset+1);
-}
-
-nsresult
TextEditor::ExtendSelectionForDelete(Selection* aSelection,
nsIEditor::EDirection* aAction)
{
bool bCollapsed = aSelection->Collapsed();
if (*aAction == eNextWord ||
*aAction == ePreviousWord ||
(*aAction == eNext && bCollapsed) ||
--- a/editor/libeditor/TextEditor.h
+++ b/editor/libeditor/TextEditor.h
@@ -189,17 +189,16 @@ protected:
EDirection aSelect = eNone);
already_AddRefed<Element> CreateBRImpl(nsCOMPtr<nsINode>* aInOutParent,
int32_t* aInOutOffset,
EDirection aSelect);
nsresult CreateBRImpl(nsCOMPtr<nsIDOMNode>* aInOutParent,
int32_t* aInOutOffset,
nsCOMPtr<nsIDOMNode>* outBRNode,
EDirection aSelect);
- nsresult InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode);
/**
* Factored methods for handling insertion of data from transferables
* (drag&drop or clipboard).
*/
NS_IMETHOD PrepareTransferable(nsITransferable** transferable);
NS_IMETHOD InsertTextFromTransferable(nsITransferable* transferable,
nsIDOMNode* aDestinationNode,