mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 05:10:49 +00:00
Bug 1451672 - part 13: Rename EditorBase::InsertTextImpl() and EditorBase::InsertTextIntoTextNodeImpl() to EditorBase::InsertTextWithTransaction() and EditorBase::InsertTextIntoTextNodeWithTransaction() r=m_kato
MozReview-Commit-ID: DF3HBVyu4P2 --HG-- extra : rebase_source : 1ce6c2b005c06df340524d2d617673f4ce93df07
This commit is contained in:
parent
4131c9f033
commit
e31bcb6efe
@ -2647,8 +2647,8 @@ EditorBase::FindBetterInsertionPoint(const EditorRawDOMPoint& 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;
|
||||
}
|
||||
|
||||
@ -2718,10 +2718,11 @@ EditorBase::FindBetterInsertionPoint(const EditorRawDOMPoint& 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
|
||||
@ -2784,9 +2785,9 @@ EditorBase::InsertTextImpl(nsIDocument& aDocument,
|
||||
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(),
|
||||
@ -2800,9 +2801,9 @@ EditorBase::InsertTextImpl(nsIDocument& aDocument,
|
||||
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(),
|
||||
@ -2827,10 +2828,11 @@ EditorBase::InsertTextImpl(nsIDocument& aDocument,
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -296,8 +296,8 @@ 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.
|
||||
@ -316,14 +316,27 @@ public:
|
||||
* 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,
|
||||
|
@ -1350,7 +1350,8 @@ HTMLEditRules::WillInsertText(EditAction aAction,
|
||||
|
||||
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 =
|
||||
@ -1360,8 +1361,8 @@ HTMLEditRules::WillInsertText(EditAction aAction,
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@ -1450,9 +1451,10 @@ HTMLEditRules::WillInsertText(EditAction aAction,
|
||||
"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;
|
||||
}
|
||||
|
@ -3268,10 +3268,11 @@ HTMLEditor::DeleteTextWithTransaction(CharacterData& aCharData,
|
||||
}
|
||||
|
||||
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;
|
||||
@ -3282,8 +3283,9 @@ HTMLEditor::InsertTextImpl(nsIDocument& aDocument,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return EditorBase::InsertTextImpl(aDocument, aStringToInsert, aPointToInsert,
|
||||
aPointAfterInsertedString);
|
||||
return EditorBase::InsertTextWithTransaction(aDocument, aStringToInsert,
|
||||
aPointToInsert,
|
||||
aPointAfterInsertedString);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -418,12 +418,16 @@ public:
|
||||
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;
|
||||
|
@ -778,7 +778,8 @@ TextEditRules::WillInsertText(EditAction aAction,
|
||||
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
|
||||
@ -788,9 +789,12 @@ TextEditRules::WillInsertText(EditAction aAction,
|
||||
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,
|
||||
|
@ -1024,8 +1024,8 @@ TextEditor::InsertLineBreak()
|
||||
|
||||
// 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
|
||||
}
|
||||
|
@ -410,8 +410,8 @@ WSRunObject::InsertText(nsIDocument& aDocument,
|
||||
|
||||
// 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;
|
||||
}
|
||||
@ -1548,9 +1548,9 @@ WSRunObject::InsertNBSPAndRemoveFollowingASCIIWhitespaces(WSPoint aPoint)
|
||||
// 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;
|
||||
}
|
||||
@ -1885,8 +1885,10 @@ WSRunObject::CheckTrailingNBSPOfRun(WSFragment *aRun)
|
||||
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
|
||||
@ -1924,8 +1926,9 @@ WSRunObject::CheckTrailingNBSPOfRun(WSFragment *aRun)
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
@ -1977,8 +1980,9 @@ WSRunObject::ReplacePreviousNBSPIfUnncessary(
|
||||
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;
|
||||
}
|
||||
@ -2025,8 +2029,10 @@ WSRunObject::CheckLeadingNBSP(WSFragment* aRun,
|
||||
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
|
||||
|
@ -237,12 +237,12 @@ public:
|
||||
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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user