Bug 1451672 - part 19: Remove TextEditor::CreateBR() and rename TextEditor::CreateBRImpl() to TextEditor::InsertBrElementWithTransaction() r=m_kato

TextEditor::CreateBR() is just a wrapper of TextEditor::CreateBRImpl() for
automatically retrieving Selection of the editor.

And TextEditor::CreateBRImpl() should be renamed to
TextEditor::InsertBrElementWithTransaction() for making it clearer what
it does.

MozReview-Commit-ID: D8sjVdLrVrd

--HG--
extra : rebase_source : f269f5c3ce598d221d7263c111475dab0dd5f19f
This commit is contained in:
Masayuki Nakano 2018-04-16 19:21:29 +09:00
Родитель 5af458988b
Коммит a409fc4d17
7 изменённых файлов: 177 добавлений и 127 удалений

Просмотреть файл

@ -491,9 +491,10 @@ HTMLEditor::SetPositionToAbsolute(Element& aElement)
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
RefPtr<Element> newBRElement =
CreateBRImpl(*selection, EditorRawDOMPoint(parentNode, 0), eNone);
if (NS_WARN_IF(!newBRElement)) {
RefPtr<Element> newBrElement =
InsertBrElementWithTransaction(*selection,
EditorRawDOMPoint(parentNode, 0));
if (NS_WARN_IF(!newBrElement)) {
return NS_ERROR_FAILURE;
}
}

Просмотреть файл

@ -1427,22 +1427,23 @@ HTMLEditRules::WillInsertText(EditAction aAction,
// is it a return?
if (subStr.Equals(newlineStr)) {
nsCOMPtr<Element> br =
htmlEditor->CreateBRImpl(*aSelection, currentPoint,
nsIEditor::eNone);
if (NS_WARN_IF(!br)) {
RefPtr<Element> brElement =
htmlEditor->InsertBrElementWithTransaction(*aSelection,
currentPoint,
nsIEditor::eNone);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
pos++;
if (br->GetNextSibling()) {
pointToInsert.Set(br->GetNextSibling());
if (brElement->GetNextSibling()) {
pointToInsert.Set(brElement->GetNextSibling());
} else {
pointToInsert.SetToEndOf(currentPoint.GetContainer());
}
// XXX In most cases, pointToInsert and currentPoint are same here.
// But if the <br> element has been moved to different point by
// mutation observer, those points become different.
currentPoint.Set(br);
currentPoint.Set(brElement);
DebugOnly<bool> advanced = currentPoint.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset after the new <br> element");
@ -1788,8 +1789,11 @@ HTMLEditRules::WillInsertBreak(Selection& aSelection,
AutoEditorDOMPointChildInvalidator lockOffset(atStartOfSelection);
EditorRawDOMPoint endOfBlockParent;
endOfBlockParent.SetToEndOf(blockParent);
RefPtr<Element> br = htmlEditor->CreateBR(endOfBlockParent);
NS_ENSURE_STATE(br);
RefPtr<Element> brElement =
htmlEditor->InsertBrElementWithTransaction(aSelection, endOfBlockParent);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
}
nsCOMPtr<Element> listItem = IsInListItem(blockParent);
@ -1869,7 +1873,8 @@ HTMLEditRules::InsertBRElement(Selection& aSelection,
// First, insert a <br> element.
RefPtr<Element> brElement;
if (IsPlaintextEditor()) {
brElement = htmlEditor->CreateBR(aPointToBreak);
brElement =
htmlEditor->InsertBrElementWithTransaction(aSelection, aPointToBreak);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -2071,8 +2076,12 @@ HTMLEditRules::SplitMailCites(Selection* aSelection,
// We ignore the result here.
EditorRawDOMPoint endOfPreviousNodeOfSplitPoint;
endOfPreviousNodeOfSplitPoint.SetToEndOf(previousNodeOfSplitPoint);
RefPtr<Element> invisBR =
htmlEditor->CreateBR(endOfPreviousNodeOfSplitPoint);
RefPtr<Element> invisibleBrElement =
htmlEditor->InsertBrElementWithTransaction(
*aSelection,
endOfPreviousNodeOfSplitPoint);
NS_WARNING_ASSERTION(invisibleBrElement,
"Failed to create an invisible <br> element");
}
}
@ -2080,15 +2089,17 @@ HTMLEditRules::SplitMailCites(Selection* aSelection,
// left cite hasn't been created because the split point was start of the
// cite node, <br> should be inserted before the current cite.
EditorRawDOMPoint pointToInsertBrNode(splitCiteNodeResult.SplitPoint());
RefPtr<Element> brNode = htmlEditor->CreateBR(pointToInsertBrNode);
if (NS_WARN_IF(!brNode)) {
RefPtr<Element> brElement =
htmlEditor->InsertBrElementWithTransaction(*aSelection,
pointToInsertBrNode);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
// Now, offset of pointToInsertBrNode is invalid. Let's clear it.
pointToInsertBrNode.Clear();
// Want selection before the break, and on same line.
EditorDOMPoint atBrNode(brNode);
EditorDOMPoint atBrNode(brElement);
Unused << atBrNode.Offset(); // Needs offset after collapsing the selection.
aSelection->SetInterlinePosition(true);
ErrorResult error;
@ -2125,8 +2136,10 @@ HTMLEditRules::SplitMailCites(Selection* aSelection,
wsType == WSType::special ||
// In case we're at the very end.
wsType == WSType::thisBlock) {
brNode = htmlEditor->CreateBR(pointToCreateNewBrNode);
if (NS_WARN_IF(!brNode)) {
brElement =
htmlEditor->InsertBrElementWithTransaction(*aSelection,
pointToCreateNewBrNode);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
// Now, those points may be invalid.
@ -2974,9 +2987,11 @@ HTMLEditRules::InsertBRIfNeeded(Selection* aSelection)
// first check that we are allowed to
if (htmlEditor->CanContainTag(*atStartOfSelection.GetContainer(),
*nsGkAtoms::br)) {
RefPtr<Element> br =
htmlEditor->CreateBR(atStartOfSelection, nsIEditor::ePrevious);
if (NS_WARN_IF(!br)) {
RefPtr<Element> brElement =
htmlEditor->InsertBrElementWithTransaction(*aSelection,
atStartOfSelection,
nsIEditor::ePrevious);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
@ -3556,12 +3571,13 @@ HTMLEditRules::DidDeleteSelection(Selection* aSelection,
}
}
if (atCiteNode.IsSet() && seenBR) {
RefPtr<Element> brNode = htmlEditor->CreateBR(atCiteNode);
if (NS_WARN_IF(!brNode)) {
RefPtr<Element> brElement =
htmlEditor->InsertBrElementWithTransaction(*aSelection, atCiteNode);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
IgnoredErrorResult error;
aSelection->Collapse(EditorRawDOMPoint(brNode), error);
aSelection->Collapse(EditorRawDOMPoint(brElement), error);
NS_WARNING_ASSERTION(!error.Failed(),
"Failed to collapse selection at the new <br> element");
}
@ -4059,11 +4075,11 @@ HTMLEditRules::MakeBasicBlock(Selection& aSelection, nsAtom& blockType)
// If the first editable node after selection is a br, consume it.
// Otherwise it gets pushed into a following block after the split,
// which is visually bad.
nsCOMPtr<nsIContent> brNode =
nsCOMPtr<nsIContent> brContent =
htmlEditor->GetNextEditableHTMLNode(pointToInsertBlock);
if (brNode && brNode->IsHTMLElement(nsGkAtoms::br)) {
if (brContent && brContent->IsHTMLElement(nsGkAtoms::br)) {
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsertBlock);
rv = htmlEditor->DeleteNodeWithTransaction(*brNode);
rv = htmlEditor->DeleteNodeWithTransaction(*brContent);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -4077,11 +4093,15 @@ HTMLEditRules::MakeBasicBlock(Selection& aSelection, nsAtom& blockType)
return splitNodeResult.Rv();
}
EditorRawDOMPoint pointToInsertBrNode(splitNodeResult.SplitPoint());
// Put a br at the split point
brNode = htmlEditor->CreateBR(pointToInsertBrNode);
NS_ENSURE_STATE(brNode);
// Put a <br> element at the split point
brContent =
htmlEditor->InsertBrElementWithTransaction(aSelection,
pointToInsertBrNode);
if (NS_WARN_IF(!brContent)) {
return NS_ERROR_FAILURE;
}
// Put selection at the split point
EditorRawDOMPoint atBrNode(brNode);
EditorRawDOMPoint atBrNode(brContent);
ErrorResult error;
aSelection.Collapse(atBrNode, error);
// Don't restore the selection
@ -5614,13 +5634,15 @@ HTMLEditRules::CheckForEmptyBlock(nsINode* aStartNode,
// If we are a sublist, skip the br creation
if (!HTMLEditUtils::IsList(atBlockParent.GetContainer())) {
// Create a br before list
RefPtr<Element> br = htmlEditor->CreateBR(atBlockParent);
if (NS_WARN_IF(!br)) {
RefPtr<Element> brElement =
htmlEditor->InsertBrElementWithTransaction(*aSelection,
atBlockParent);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
// Adjust selection to be right before it
ErrorResult error;
aSelection->Collapse(EditorRawDOMPoint(br), error);
aSelection->Collapse(EditorRawDOMPoint(brElement), error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
@ -7109,9 +7131,10 @@ HTMLEditRules::ReturnInHeader(Selection& aSelection,
}
// Append a <br> to it
RefPtr<Element> brNode =
htmlEditor->CreateBR(EditorRawDOMPoint(pNode, 0));
if (NS_WARN_IF(!brNode)) {
RefPtr<Element> brElement =
htmlEditor->InsertBrElementWithTransaction(aSelection,
EditorRawDOMPoint(pNode, 0));
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -7227,7 +7250,7 @@ HTMLEditRules::ReturnInParagraph(Selection& aSelection,
bool doesCRCreateNewP = htmlEditor->GetReturnInParagraphCreatesNewParagraph();
bool splitAfterNewBR = false;
nsCOMPtr<nsIContent> brNode;
nsCOMPtr<nsIContent> brContent;
EditorDOMPoint pointToSplitParentDivOrP(atStartOfSelection);
@ -7235,32 +7258,32 @@ HTMLEditRules::ReturnInParagraph(Selection& aSelection,
if (doesCRCreateNewP &&
atStartOfSelection.GetContainer() == &aParentDivOrP) {
// We are at the edges of the block, so, we don't need to create new <br>.
brNode = nullptr;
brContent = nullptr;
} else if (atStartOfSelection.IsInTextNode()) {
// at beginning of text node?
if (atStartOfSelection.IsStartOfContainer()) {
// is there a BR prior to it?
brNode =
brContent =
htmlEditor->GetPriorHTMLSibling(atStartOfSelection.GetContainer());
if (!brNode ||
!htmlEditor->IsVisibleBRElement(brNode) ||
TextEditUtils::HasMozAttr(brNode)) {
if (!brContent ||
!htmlEditor->IsVisibleBRElement(brContent) ||
TextEditUtils::HasMozAttr(brContent)) {
pointToInsertBR.Set(atStartOfSelection.GetContainer());
brNode = nullptr;
brContent = nullptr;
}
} else if (atStartOfSelection.IsEndOfContainer()) {
// we're at the end of text node...
// is there a BR after to it?
brNode =
brContent =
htmlEditor->GetNextHTMLSibling(atStartOfSelection.GetContainer());
if (!brNode ||
!htmlEditor->IsVisibleBRElement(brNode) ||
TextEditUtils::HasMozAttr(brNode)) {
if (!brContent ||
!htmlEditor->IsVisibleBRElement(brContent) ||
TextEditUtils::HasMozAttr(brContent)) {
pointToInsertBR.Set(atStartOfSelection.GetContainer());
DebugOnly<bool> advanced = pointToInsertBR.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset to after the container of selection start");
brNode = nullptr;
brContent = nullptr;
}
} else {
if (doesCRCreateNewP) {
@ -7298,7 +7321,7 @@ HTMLEditRules::ReturnInParagraph(Selection& aSelection,
}
}
if (!pointToInsertBR.IsSet() && TextEditUtils::IsBreak(nearNode)) {
brNode = nearNode;
brContent = nearNode;
}
}
if (pointToInsertBR.IsSet()) {
@ -7312,10 +7335,12 @@ HTMLEditRules::ReturnInParagraph(Selection& aSelection,
return EditActionResult(NS_OK);
}
brNode = htmlEditor->CreateBR(pointToInsertBR);
brContent =
htmlEditor->InsertBrElementWithTransaction(aSelection, pointToInsertBR);
NS_WARNING_ASSERTION(brContent, "Failed to create a <br> element");
if (splitAfterNewBR) {
// We split the parent after the br we've just inserted.
pointToSplitParentDivOrP.Set(brNode);
pointToSplitParentDivOrP.Set(brContent);
DebugOnly<bool> advanced = pointToSplitParentDivOrP.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset after the new <br>");
@ -7323,7 +7348,7 @@ HTMLEditRules::ReturnInParagraph(Selection& aSelection,
}
EditActionResult result(
SplitParagraph(aSelection, aParentDivOrP, pointToSplitParentDivOrP,
brNode));
brContent));
result.MarkAsHandled();
if (NS_WARN_IF(result.Failed())) {
return result;
@ -7487,10 +7512,16 @@ HTMLEditRules::ReturnInListItem(Selection& aSelection,
return NS_ERROR_FAILURE;
}
RefPtr<Selection> selection = htmlEditor->GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
// Append a <br> to it
RefPtr<Element> brNode =
htmlEditor->CreateBR(EditorRawDOMPoint(pNode, 0));
if (NS_WARN_IF(!brNode)) {
RefPtr<Element> brElement =
htmlEditor->InsertBrElementWithTransaction(*selection,
EditorRawDOMPoint(pNode, 0));
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -8782,10 +8813,16 @@ HTMLEditRules::RemoveEmptyNodes()
rv = htmlEditor->IsEmptyNode(delNode, &bIsEmptyNode, false, true);
NS_ENSURE_SUCCESS(rv, rv);
if (!bIsEmptyNode) {
RefPtr<Selection> selection = htmlEditor->GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
// We are deleting a cite that has just a br. We want to delete cite,
// but preserve br.
RefPtr<Element> br = htmlEditor->CreateBR(EditorRawDOMPoint(delNode));
if (NS_WARN_IF(!br)) {
RefPtr<Element> brElement =
htmlEditor->InsertBrElementWithTransaction(*selection,
EditorRawDOMPoint(delNode));
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
}
@ -9440,14 +9477,19 @@ HTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsINode& aNode,
}
}
if (!foundCR) {
RefPtr<Selection> selection = htmlEditor->GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
EditorRawDOMPoint pointToInsert;
if (!aStarts) {
pointToInsert.SetToEndOf(&aNode);
} else {
pointToInsert.Set(&aNode, 0);
}
RefPtr<Element> brNode = htmlEditor->CreateBR(pointToInsert);
if (NS_WARN_IF(!brNode)) {
RefPtr<Element> brElement =
htmlEditor->InsertBrElementWithTransaction(*selection, pointToInsert);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
}

Просмотреть файл

@ -1156,10 +1156,11 @@ HTMLEditor::InsertBR()
return NS_ERROR_FAILURE;
}
// CreateBRImpl() will set selection after the new <br> element.
RefPtr<Element> newBRElement =
CreateBRImpl(*selection, atStartOfSelection, nsIEditor::eNext);
if (NS_WARN_IF(!newBRElement)) {
// InsertBrElementWithTransaction() will set selection after the new <br>
// element.
RefPtr<Element> newBrElement =
InsertBrElementWithTransaction(*selection, atStartOfSelection, eNext);
if (NS_WARN_IF(!newBrElement)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
@ -1608,9 +1609,9 @@ HTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement,
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset from inserted point");
// Collapse selection to the new <br> element node after creating it.
RefPtr<Element> newBRElement =
CreateBRImpl(*selection, insertedPoint, ePrevious);
if (NS_WARN_IF(!newBRElement)) {
RefPtr<Element> newBrElement =
InsertBrElementWithTransaction(*selection, insertedPoint, ePrevious);
if (NS_WARN_IF(!newBrElement)) {
return NS_ERROR_FAILURE;
}
}
@ -3747,6 +3748,11 @@ HTMLEditor::SetSelectionAtDocumentStart(Selection* aSelection)
nsresult
HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement)
{
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
// Two possibilities: the container could be empty of editable content. If
// that is the case, we need to compare what is before and after aNode to
// determine if we need a br.
@ -3768,7 +3774,9 @@ HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement)
if (sibling && !IsBlockNode(sibling) &&
!sibling->IsHTMLElement(nsGkAtoms::br) && !IsBlockNode(child)) {
// Insert br node
RefPtr<Element> brElement = CreateBR(EditorRawDOMPoint(&aElement, 0));
RefPtr<Element> brElement =
InsertBrElementWithTransaction(*selection,
EditorRawDOMPoint(&aElement, 0));
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -3788,7 +3796,8 @@ HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement)
// Insert br node
EditorRawDOMPoint endOfNode;
endOfNode.SetToEndOf(&aElement);
RefPtr<Element> brElement = CreateBR(endOfNode);
RefPtr<Element> brElement =
InsertBrElementWithTransaction(*selection, endOfNode);
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -3808,7 +3817,9 @@ HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement)
if (sibling && !IsBlockNode(sibling) &&
!sibling->IsHTMLElement(nsGkAtoms::br)) {
// Insert br node
RefPtr<Element> brElement = CreateBR(EditorRawDOMPoint(&aElement, 0));
RefPtr<Element> brElement =
InsertBrElementWithTransaction(*selection,
EditorRawDOMPoint(&aElement, 0));
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -4570,9 +4581,17 @@ HTMLEditor::CopyLastEditableChildStyles(nsINode* aPreviousBlock,
childElement = childElement->GetParentElement();
}
if (deepestStyle) {
RefPtr<Element> retVal = CreateBR(EditorRawDOMPoint(deepestStyle, 0));
retVal.forget(aOutBrNode);
NS_ENSURE_STATE(*aOutBrNode);
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
RefPtr<Element> brElement =
InsertBrElementWithTransaction(*selection,
EditorRawDOMPoint(deepestStyle, 0));
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
brElement.forget(aOutBrNode);
}
return NS_OK;
}

Просмотреть файл

@ -1676,7 +1676,13 @@ TextEditRules::CreateBRInternal(const EditorRawDOMPoint& aPointToInsert,
}
RefPtr<TextEditor> textEditor = mTextEditor;
RefPtr<Element> brElement = textEditor->CreateBR(aPointToInsert);
RefPtr<Selection> selection = textEditor->GetSelection();
if (NS_WARN_IF(!selection)) {
return nullptr;
}
RefPtr<Element> brElement =
textEditor->InsertBrElementWithTransaction(*selection, aPointToInsert);
if (NS_WARN_IF(!brElement)) {
return nullptr;
}

Просмотреть файл

@ -65,11 +65,15 @@ namespace mozilla {
using namespace dom;
template already_AddRefed<Element>
TextEditor::CreateBR(const EditorDOMPoint& aPointToInsert,
EDirection aSelect);
TextEditor::InsertBrElementWithTransaction(
Selection& aSelection,
const EditorDOMPoint& aPointToInsert,
EDirection aSelect);
template already_AddRefed<Element>
TextEditor::CreateBR(const EditorRawDOMPoint& aPointToInsert,
EDirection aSelect);
TextEditor::InsertBrElementWithTransaction(
Selection& aSelection,
const EditorRawDOMPoint& aPointToInsert,
EDirection aSelect);
TextEditor::TextEditor()
: mWrapColumn(0)
@ -437,22 +441,10 @@ TextEditor::TypedText(const nsAString& aString, ETypingAction aAction)
template<typename PT, typename CT>
already_AddRefed<Element>
TextEditor::CreateBR(const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect /* = eNone */)
{
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return nullptr;
}
// We assume everything is fine if newBRElement is not null.
return CreateBRImpl(*selection, aPointToInsert, aSelect);
}
template<typename PT, typename CT>
already_AddRefed<Element>
TextEditor::CreateBRImpl(Selection& aSelection,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect)
TextEditor::InsertBrElementWithTransaction(
Selection& aSelection,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect /* = eNone */)
{
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
return nullptr;

Просмотреть файл

@ -226,28 +226,9 @@ protected:
const nsACString& aCharset);
/**
* CreateBR() creates new <br> element and inserts it before aPointToInsert,
* and collapse selection if it's necessary.
*
* @param aPointToInsert The point to insert new <br> element.
* @param aSelect If eNone, this won't change selection.
* If eNext, selection will be collapsed after the
* <br> element.
* If ePrevious, selection will be collapsed at the
* <br> element.
* @return The new <br> node. If failed to create new <br>
* node, returns nullptr.
*/
template<typename PT, typename CT>
already_AddRefed<Element>
CreateBR(const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect = eNone);
/**
* CreateBRImpl() creates a <br> element and inserts it before aPointToInsert.
* Then, tries to collapse selection at or after the new <br> node if
* aSelect is not eNone.
* XXX Perhaps, this should be merged with CreateBR().
* InsertBrElementWithTransaction() creates a <br> element and inserts it
* before aPointToInsert. Then, tries to collapse selection at or after the
* new <br> node if aSelect is not eNone.
*
* @param aSelection The selection of this editor.
* @param aPointToInsert The DOM point where should be <br> node inserted
@ -262,9 +243,10 @@ protected:
*/
template<typename PT, typename CT>
already_AddRefed<Element>
CreateBRImpl(Selection& aSelection,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect);
InsertBrElementWithTransaction(
Selection& aSelection,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect = eNone);
/**
* Factored methods for handling insertion of data from transferables

Просмотреть файл

@ -264,12 +264,13 @@ WSRunObject::InsertBreak(Selection& aSelection,
}
}
RefPtr<Element> newBRElement =
mHTMLEditor->CreateBRImpl(aSelection, pointToInsert, aSelect);
if (NS_WARN_IF(!newBRElement)) {
RefPtr<Element> newBrElement =
mHTMLEditor->InsertBrElementWithTransaction(aSelection, pointToInsert,
aSelect);
if (NS_WARN_IF(!newBrElement)) {
return nullptr;
}
return newBRElement.forget();
return newBrElement.forget();
}
template<typename PT, typename CT>
@ -1848,6 +1849,11 @@ WSRunObject::CheckTrailingNBSPOfRun(WSFragment *aRun)
}
if ((aRun->mRightType & WSType::block) &&
IsBlockNode(GetWSBoundingParent())) {
RefPtr<Selection> selection = htmlEditor->GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
// We are at a block boundary. Insert a <br>. Why? Well, first note
// that the br will have no visible effect since it is up against a
// block boundary. |foo<br><p>bar| renders like |foo<p>bar| and
@ -1869,8 +1875,10 @@ WSRunObject::CheckTrailingNBSPOfRun(WSFragment *aRun)
// beginning of soft wrapped lines, and lets the user see 2 spaces when
// they type 2 spaces.
RefPtr<Element> brNode = htmlEditor->CreateBR(aRun->EndPoint());
if (NS_WARN_IF(!brNode)) {
RefPtr<Element> brElement =
htmlEditor->InsertBrElementWithTransaction(*selection,
aRun->EndPoint());
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}