Bug 1500862 - part 2: Create AutoTransactionBatchExternal class which calls XPCOM methods instead of non-virtual internal methods r=m_kato

Unfortunately, TextServicesDocument::InsertText() is too complicated to
do it with both editor class and TextServicesDocument separately.
Therefore, this patch adds AutoTransactionBatchExternal class which is
almost same as AutoTransactionBatch but uses XPCOM methods to begin/end
transaction.  This change helps editor to manage whether it starts to
handle new edit action or not when BeginTransaction() is called explicitly.

Differential Revision: https://phabricator.services.mozilla.com/D9478

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2018-10-24 05:18:40 +00:00
Родитель 25b5b80801
Коммит 87499ae61c
2 изменённых файлов: 31 добавлений и 6 удалений

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

@ -451,6 +451,34 @@ private:
SplitRangeOffFromNodeResult() = delete;
};
/***************************************************************************
* stack based helper class for calling EditorBase::EndTransaction() after
* EditorBase::BeginTransaction(). This shouldn't be used in editor classes
* or helper classes while an edit action is being handled. Use
* AutoTransactionBatch in such cases since it uses non-virtual internal
* methods.
***************************************************************************/
class MOZ_RAII AutoTransactionBatchExternal final
{
private:
OwningNonNull<EditorBase> mEditorBase;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
public:
explicit AutoTransactionBatchExternal(EditorBase& aEditorBase
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mEditorBase(aEditorBase)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
mEditorBase->BeginTransaction();
}
~AutoTransactionBatchExternal()
{
mEditorBase->EndTransaction();
}
};
/***************************************************************************
* stack based helper class for calling EditorBase::EndTransaction() after
* EditorBase::BeginTransaction().

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

@ -1148,12 +1148,9 @@ TextServicesDocument::InsertText(const nsString* aText)
NS_ENSURE_SUCCESS(rv, rv);
}
// AutoTransactionBatch grabs mTextEditor, so, we don't need to grab the
// instance with local variable here.
// XXX Well, do we really need to create AutoTransactionBatch here?
// Looks like that after InsertTextAsAction(), this does nothing
// from a point of view of editor.
AutoTransactionBatch bundleAllTransactions(*mTextEditor);
// AutoTransactionBatchExternal grabs mTextEditor, so, we don't need to grab
// the instance with local variable here.
AutoTransactionBatchExternal treatAsOneTransaction(*mTextEditor);
nsresult rv = mTextEditor->InsertTextAsAction(*aText);
if (NS_FAILED(rv)) {