--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -2642,18 +2642,18 @@ EditorBase::FindBetterInsertionPoint(con
if (aPoint.IsInTextNode()) {
// There is no "better" insertion point.
return aPoint;
}
if (!IsPlaintextEditor()) {
// We cannot find "better" insertion point in HTML editor.
// WARNING: When you add some code to find better node in HTML editor,
- // you need to call this before calling InsertTextImpl() in
- // HTMLEditRules.
+ // you need to call this before calling InsertTextWithTransaction()
+ // in HTMLEditRules.
return aPoint;
}
nsCOMPtr<nsINode> root = GetRoot();
if (aPoint.GetContainer() == root) {
// In some cases, aNode is the anonymous DIV, and offset is 0. To avoid
// injecting unneeded text nodes, we first look to see if we have one
// available. In that case, we'll just adjust node and offset accordingly.
@@ -2713,20 +2713,21 @@ EditorBase::FindBetterInsertionPoint(con
aPoint.GetContainerAsContent(), 0);
}
}
return aPoint;
}
nsresult
-EditorBase::InsertTextImpl(nsIDocument& aDocument,
- const nsAString& aStringToInsert,
- const EditorRawDOMPoint& aPointToInsert,
- EditorRawDOMPoint* aPointAfterInsertedString)
+EditorBase::InsertTextWithTransaction(
+ nsIDocument& aDocument,
+ const nsAString& aStringToInsert,
+ const EditorRawDOMPoint& aPointToInsert,
+ EditorRawDOMPoint* aPointAfterInsertedString)
{
// NOTE: caller *must* have already used AutoTransactionsConserveSelection
// stack-based class to turn off txn selection updating. Caller also turned
// on rules sniffing if desired.
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
return NS_ERROR_INVALID_ARG;
}
@@ -2779,35 +2780,35 @@ EditorBase::InsertTextImpl(nsIDocument&
}
pointToInsert.Set(newNode, 0);
newOffset = lengthToInsert;
} else {
newOffset = lengthToInsert + pointToInsert.Offset();
NS_ENSURE_TRUE(newOffset.isValid(), NS_ERROR_FAILURE);
}
nsresult rv =
- InsertTextIntoTextNodeImpl(aStringToInsert,
- *pointToInsert.GetContainerAsText(),
- pointToInsert.Offset());
+ InsertTextIntoTextNodeWithTransaction(aStringToInsert,
+ *pointToInsert.GetContainerAsText(),
+ pointToInsert.Offset());
NS_ENSURE_SUCCESS(rv, rv);
if (aPointAfterInsertedString) {
aPointAfterInsertedString->Set(pointToInsert.GetContainer(),
newOffset.value());
}
return NS_OK;
}
if (pointToInsert.IsInTextNode()) {
CheckedInt<int32_t> newOffset = lengthToInsert + pointToInsert.Offset();
NS_ENSURE_TRUE(newOffset.isValid(), NS_ERROR_FAILURE);
// we are inserting text into an existing text node.
nsresult rv =
- InsertTextIntoTextNodeImpl(aStringToInsert,
- *pointToInsert.GetContainerAsText(),
- pointToInsert.Offset());
+ InsertTextIntoTextNodeWithTransaction(aStringToInsert,
+ *pointToInsert.GetContainerAsText(),
+ pointToInsert.Offset());
NS_ENSURE_SUCCESS(rv, rv);
if (aPointAfterInsertedString) {
aPointAfterInsertedString->Set(pointToInsert.GetContainer(),
newOffset.value());
}
return NS_OK;
}
@@ -2822,20 +2823,21 @@ EditorBase::InsertTextImpl(nsIDocument&
}
if (aPointAfterInsertedString) {
aPointAfterInsertedString->Set(newNode, lengthToInsert.value());
}
return NS_OK;
}
nsresult
-EditorBase::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
- Text& aTextNode,
- int32_t aOffset,
- bool aSuppressIME)
+EditorBase::InsertTextIntoTextNodeWithTransaction(
+ const nsAString& aStringToInsert,
+ Text& aTextNode,
+ int32_t aOffset,
+ bool aSuppressIME)
{
RefPtr<EditTransactionBase> transaction;
bool isIMETransaction = false;
RefPtr<Text> insertedTextNode = &aTextNode;
int32_t insertedOffset = aOffset;
// aSuppressIME is used when editor must insert text, yet this text is not
// part of the current IME operation. Example: adjusting whitespace around an
// IME insertion.
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -291,18 +291,18 @@ public:
* already has an IMEContentObserver, this will crash in debug build.
*/
void SetIMEContentObserver(IMEContentObserver* aIMEContentObserver);
public:
virtual bool IsModifiableNode(nsINode* aNode);
/**
- * InsertTextImpl() inserts aStringToInsert to aPointToInsert or better
- * insertion point around it. If aPointToInsert isn't in a text node,
+ * InsertTextWithTransaction() inserts aStringToInsert to aPointToInsert or
+ * better insertion point around it. If aPointToInsert isn't in a text node,
* this method looks for the nearest point in a text node with
* FindBetterInsertionPoint(). If there is no text node, this creates
* new text node and put aStringToInsert to it.
*
* @param aDocument The document of this editor.
* @param aStringToInsert The string to insert.
* @param aPointToInser The point to insert aStringToInsert.
* Must be valid DOM point.
@@ -311,24 +311,37 @@ public:
* So, when this method actually inserts string,
* this is set to a point in the text node.
* Otherwise, this may be set to aPointToInsert.
* @return When this succeeds to insert the string or
* does nothing during composition, returns NS_OK.
* Otherwise, an error code.
*/
virtual nsresult
- InsertTextImpl(nsIDocument& aDocument,
- const nsAString& aStringToInsert,
- const EditorRawDOMPoint& aPointToInsert,
- EditorRawDOMPoint* aPointAfterInsertedString = nullptr);
+ InsertTextWithTransaction(nsIDocument& aDocument,
+ const nsAString& aStringToInsert,
+ const EditorRawDOMPoint& aPointToInsert,
+ EditorRawDOMPoint* aPointAfterInsertedString =
+ nullptr);
- nsresult InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
- Text& aTextNode, int32_t aOffset,
- bool aSuppressIME = false);
+ /**
+ * InsertTextIntoTextNodeWithTransaction() inserts aStringToInsert into
+ * aOffset of aTextNode with transaction.
+ *
+ * @param aStringToInsert String to be inserted.
+ * @param aTextNode Text node to contain aStringToInsert.
+ * @param aOffset Offset at insertion point in aTextNode.
+ * @param aSuppressIME true if it's not a part of IME composition.
+ * E.g., adjusting whitespaces during composition.
+ * false, otherwise.
+ */
+ nsresult
+ InsertTextIntoTextNodeWithTransaction(const nsAString& aStringToInsert,
+ Text& aTextNode, int32_t aOffset,
+ bool aSuppressIME = false);
nsresult SetTextImpl(Selection& aSelection,
const nsAString& aString,
Text& aTextNode);
/**
* DeleteNodeWithTransaction() removes aNode from the DOM tree.
*
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -1345,28 +1345,29 @@ HTMLEditRules::WillInsertText(EditAction
if (!EditorBase::IsTextNode(pointToInsert.GetContainer()) &&
!htmlEditor->CanContainTag(*pointToInsert.GetContainer(),
*nsGkAtoms::textTagName)) {
return NS_ERROR_FAILURE;
}
if (aAction == EditAction::insertIMEText) {
// Right now the WSRunObject code bails on empty strings, but IME needs
- // the InsertTextImpl() call to still happen since empty strings are meaningful there.
+ // the InsertTextWithTransaction() call to still happen since empty strings
+ // are meaningful there.
// If there is one or more IME selections, its minimum offset should be
// the insertion point.
int32_t IMESelectionOffset =
htmlEditor->GetIMESelectionStartOffsetIn(pointToInsert.GetContainer());
if (IMESelectionOffset >= 0) {
pointToInsert.Set(pointToInsert.GetContainer(), IMESelectionOffset);
}
if (inString->IsEmpty()) {
- rv = htmlEditor->InsertTextImpl(*doc, *inString,
- EditorRawDOMPoint(pointToInsert));
+ rv = htmlEditor->InsertTextWithTransaction(
+ *doc, *inString, EditorRawDOMPoint(pointToInsert));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
WSRunObject wsObj(htmlEditor, pointToInsert);
rv = wsObj.InsertText(*doc, *inString, pointToInsert);
@@ -1445,19 +1446,20 @@ HTMLEditRules::WillInsertText(EditAction
DebugOnly<bool> advanced = currentPoint.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset after the new <br> element");
NS_WARNING_ASSERTION(currentPoint == pointToInsert,
"Perhaps, <br> element position has been moved to different point "
"by mutation observer");
} else {
EditorRawDOMPoint pointAfterInsertedString;
- rv = htmlEditor->InsertTextImpl(*doc, subStr,
- EditorRawDOMPoint(currentPoint),
- &pointAfterInsertedString);
+ rv = htmlEditor->InsertTextWithTransaction(
+ *doc, subStr,
+ EditorRawDOMPoint(currentPoint),
+ &pointAfterInsertedString);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
currentPoint = pointAfterInsertedString;
pointToInsert = pointAfterInsertedString;
}
}
} else {
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -3269,32 +3269,34 @@ HTMLEditor::DeleteTextWithTransaction(Ch
if (!IsModifiableNode(&aCharData)) {
return NS_ERROR_FAILURE;
}
return EditorBase::DeleteTextWithTransaction(aCharData, aOffset, aLength);
}
nsresult
-HTMLEditor::InsertTextImpl(nsIDocument& aDocument,
- const nsAString& aStringToInsert,
- const EditorRawDOMPoint& aPointToInsert,
- EditorRawDOMPoint* aPointAfterInsertedString)
+HTMLEditor::InsertTextWithTransaction(
+ nsIDocument& aDocument,
+ const nsAString& aStringToInsert,
+ const EditorRawDOMPoint& aPointToInsert,
+ EditorRawDOMPoint* aPointAfterInsertedString)
{
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
return NS_ERROR_INVALID_ARG;
}
// Do nothing if the node is read-only
if (!IsModifiableNode(aPointToInsert.GetContainer())) {
return NS_ERROR_FAILURE;
}
- return EditorBase::InsertTextImpl(aDocument, aStringToInsert, aPointToInsert,
- aPointAfterInsertedString);
+ return EditorBase::InsertTextWithTransaction(aDocument, aStringToInsert,
+ aPointToInsert,
+ aPointAfterInsertedString);
}
void
HTMLEditor::ContentAppended(nsIContent* aFirstNewContent)
{
DoContentInserted(aFirstNewContent, eAppended);
}
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -413,22 +413,26 @@ public:
*
* @param aCharData The data node which should be modified.
* @param aOffset Start offset of removing text in aCharData.
* @param aLength Length of removing text.
*/
nsresult DeleteTextWithTransaction(dom::CharacterData& aTextNode,
uint32_t aOffset, uint32_t aLength);
+ /**
+ * InsertTextWithTransaction() inserts aStringToInsert at aPointToInsert.
+ */
virtual nsresult
- InsertTextImpl(nsIDocument& aDocument,
- const nsAString& aStringToInsert,
- const EditorRawDOMPoint& aPointToInsert,
- EditorRawDOMPoint* aPointAfterInsertedString =
- nullptr) override;
+ InsertTextWithTransaction(nsIDocument& aDocument,
+ const nsAString& aStringToInsert,
+ const EditorRawDOMPoint& aPointToInsert,
+ EditorRawDOMPoint* aPointAfterInsertedString =
+ nullptr) override;
+
virtual bool IsModifiableNode(nsINode* aNode) override;
NS_IMETHOD SelectAll() override;
// nsICSSLoaderObserver
NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet,
bool aWasAlternate, nsresult aStatus) override;
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -773,29 +773,33 @@ TextEditRules::WillInsertText(EditAction
// the insertion point.
int32_t IMESelectionOffset =
mTextEditor->GetIMESelectionStartOffsetIn(
betterInsertionPoint.GetContainer());
if (IMESelectionOffset >= 0) {
betterInsertionPoint.Set(betterInsertionPoint.GetContainer(),
IMESelectionOffset);
}
- rv = mTextEditor->InsertTextImpl(*doc, *outString, betterInsertionPoint);
+ rv = mTextEditor->InsertTextWithTransaction(*doc, *outString,
+ betterInsertionPoint);
NS_ENSURE_SUCCESS(rv, rv);
} else {
// aAction == EditAction::insertText
// don't change my selection in subtransactions
NS_ENSURE_STATE(mTextEditor);
AutoTransactionsConserveSelection dontChangeMySelection(mTextEditor);
EditorRawDOMPoint pointAfterStringInserted;
- rv = mTextEditor->InsertTextImpl(*doc, *outString, atStartOfSelection,
- &pointAfterStringInserted);
- NS_ENSURE_SUCCESS(rv, rv);
+ rv = mTextEditor->InsertTextWithTransaction(*doc, *outString,
+ atStartOfSelection,
+ &pointAfterStringInserted);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
if (pointAfterStringInserted.IsSet()) {
// Make the caret attach to the inserted text, unless this text ends with a LF,
// in which case make the caret attach to the next line.
bool endsWithLF =
!outString->IsEmpty() && outString->Last() == nsCRT::LF;
aSelection->SetInterlinePosition(endsWithLF);
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -1019,18 +1019,18 @@ TextEditor::InsertLineBreak()
nsCOMPtr<nsIDocument> doc = GetDocument();
NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED);
// don't change my selection in subtransactions
AutoTransactionsConserveSelection dontChangeMySelection(this);
// insert a linefeed character
EditorRawDOMPoint pointAfterInsertedLineBreak;
- rv = InsertTextImpl(*doc, NS_LITERAL_STRING("\n"), pointToInsert,
- &pointAfterInsertedLineBreak);
+ rv = InsertTextWithTransaction(*doc, NS_LITERAL_STRING("\n"), pointToInsert,
+ &pointAfterInsertedLineBreak);
if (NS_WARN_IF(!pointAfterInsertedLineBreak.IsSet())) {
rv = NS_ERROR_NULL_POINTER; // don't return here, so DidDoAction is called
}
if (NS_SUCCEEDED(rv)) {
// set the selection to the correct location
MOZ_ASSERT(!pointAfterInsertedLineBreak.GetChild(),
"After inserting text into a text node, pointAfterInsertedLineBreak."
"GetChild() should be nullptr");
--- a/editor/libeditor/WSRunObject.cpp
+++ b/editor/libeditor/WSRunObject.cpp
@@ -405,18 +405,18 @@ WSRunObject::InsertText(nsIDocument& aDo
}
} else {
prevWS = false;
}
}
// Ready, aim, fire!
nsresult rv =
- mHTMLEditor->InsertTextImpl(aDocument, theString, pointToInsert,
- aPointAfterInsertedString);
+ mHTMLEditor->InsertTextWithTransaction(aDocument, theString, pointToInsert,
+ aPointAfterInsertedString);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_OK;
}
return NS_OK;
}
nsresult
WSRunObject::DeleteWSBackward()
@@ -1543,19 +1543,19 @@ WSRunObject::InsertNBSPAndRemoveFollowin
// wsFragment info.
if (NS_WARN_IF(!aPoint.mTextNode)) {
return NS_ERROR_NULL_POINTER;
}
// First, insert an NBSP.
AutoTransactionsConserveSelection dontChangeMySelection(mHTMLEditor);
nsresult rv =
- mHTMLEditor->InsertTextIntoTextNodeImpl(nsDependentSubstring(&kNBSP, 1),
- *aPoint.mTextNode, aPoint.mOffset,
- true);
+ mHTMLEditor->InsertTextIntoTextNodeWithTransaction(
+ nsDependentSubstring(&kNBSP, 1),
+ *aPoint.mTextNode, aPoint.mOffset, true);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Now, the text node may have been modified by mutation observer.
// So, the NBSP may have gone.
if (aPoint.mTextNode->TextDataLength() <= aPoint.mOffset ||
aPoint.mTextNode->GetText()->CharAt(aPoint.mOffset) != kNBSP) {
@@ -1880,18 +1880,20 @@ WSRunObject::CheckTrailingNBSPOfRun(WSFr
rightCheck = true;
}
}
if (leftCheck && rightCheck) {
// Now replace nbsp with space. First, insert a space
AutoTransactionsConserveSelection dontChangeMySelection(htmlEditor);
nsAutoString spaceStr(char16_t(32));
nsresult rv =
- htmlEditor->InsertTextIntoTextNodeImpl(spaceStr, *thePoint.mTextNode,
- thePoint.mOffset, true);
+ htmlEditor->InsertTextIntoTextNodeWithTransaction(spaceStr,
+ *thePoint.mTextNode,
+ thePoint.mOffset,
+ true);
NS_ENSURE_SUCCESS(rv, rv);
// Finally, delete that nbsp
rv = DeleteRange(EditorRawDOMPoint(thePoint.mTextNode,
thePoint.mOffset + 1),
EditorRawDOMPoint(thePoint.mTextNode,
thePoint.mOffset + 2));
if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -1919,18 +1921,19 @@ WSRunObject::CheckTrailingNBSPOfRun(WSFr
thePoint.mOffset + 1));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Finally, insert that nbsp before the ASCII ws run
AutoTransactionsConserveSelection dontChangeMySelection(htmlEditor);
rv =
- htmlEditor->InsertTextIntoTextNodeImpl(nsDependentSubstring(&kNBSP, 1),
- *startNode, startOffset, true);
+ htmlEditor->InsertTextIntoTextNodeWithTransaction(
+ nsDependentSubstring(&kNBSP, 1),
+ *startNode, startOffset, true);
NS_ENSURE_SUCCESS(rv, rv);
}
}
return NS_OK;
}
template<typename PT, typename CT>
nsresult
@@ -1972,18 +1975,19 @@ WSRunObject::ReplacePreviousNBSPIfUnnces
if (!canConvert) {
return NS_OK;
}
// First, insert a space before the previous NBSP.
AutoTransactionsConserveSelection dontChangeMySelection(mHTMLEditor);
nsAutoString spaceStr(char16_t(32));
nsresult rv =
- mHTMLEditor->InsertTextIntoTextNodeImpl(spaceStr, *thePoint.mTextNode,
- thePoint.mOffset, true);
+ mHTMLEditor->InsertTextIntoTextNodeWithTransaction(spaceStr,
+ *thePoint.mTextNode,
+ thePoint.mOffset, true);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Finally, delete the previous NBSP.
rv = DeleteRange(EditorRawDOMPoint(thePoint.mTextNode,
thePoint.mOffset + 1),
EditorRawDOMPoint(thePoint.mTextNode,
@@ -2020,18 +2024,20 @@ WSRunObject::CheckLeadingNBSP(WSFragment
canConvert = true;
}
}
if (canConvert) {
// First, insert a space
AutoTransactionsConserveSelection dontChangeMySelection(mHTMLEditor);
nsAutoString spaceStr(char16_t(32));
nsresult rv =
- mHTMLEditor->InsertTextIntoTextNodeImpl(spaceStr, *thePoint.mTextNode,
- thePoint.mOffset, true);
+ mHTMLEditor->InsertTextIntoTextNodeWithTransaction(spaceStr,
+ *thePoint.mTextNode,
+ thePoint.mOffset,
+ true);
NS_ENSURE_SUCCESS(rv, rv);
// Finally, delete that nbsp
rv = DeleteRange(EditorRawDOMPoint(thePoint.mTextNode,
thePoint.mOffset + 1),
EditorRawDOMPoint(thePoint.mTextNode,
thePoint.mOffset + 2));
if (NS_WARN_IF(NS_FAILED(rv))) {
--- a/editor/libeditor/WSRunObject.h
+++ b/editor/libeditor/WSRunObject.h
@@ -232,22 +232,22 @@ public:
*/
template<typename PT, typename CT>
already_AddRefed<dom::Element>
InsertBreak(Selection& aSelection,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
nsIEditor::EDirection aSelect);
/**
- * InsertTextImpl() inserts aStringToInsert to aPointToInsert and makes any
+ * InsertText() inserts aStringToInsert to aPointToInsert and makes any
* needed adjustments to white spaces around that point. E.g., trailing white
* spaces before aPointToInsert needs to be removed.
- * This calls EditorBase::InsertTextImpl() after adjusting white spaces.
- * So, please refer the method's explanation to know what this method exactly
- * does.
+ * This calls EditorBase::InsertTextWithTransaction() after adjusting white
+ * spaces. So, please refer the method's explanation to know what this
+ * method exactly does.
*
* @param aDocument The document of this editor.
* @param aStringToInsert The string to insert.
* @param aPointToInser The point to insert aStringToInsert.
* Must be valid DOM point.
* @param aPointAfterInsertedString
* The point after inserted aStringToInsert.
* So, when this method actually inserts string,