gecko-dev/editor/txmgr/TransactionManager.h
Masayuki Nakano a1f13e5b38 Bug 1447924 - part 5: Merge TextEditor::Undo()/Redo() with EditorBase::Undo()/Redo() r=m_kato
EditorBase::Undo() and EditorBase::Redo() implement only undo/redo function.
TextEditor::Undo() and TextEditor::Redo() call them with calling some
notification methods.  However, this causes redundant AutoRules instance
creation and doesn't make sense to separate them under current design.

Therefore this patch merges them into TextEditor.  Unfortunately, they are
XPCOM methods but we cannot implement proper overloads of non-virtual since
they are already minimized design.  Fortunately, reducing only one virtual
call per undo/redo isn't so effective.  So, let's keep simpler design.

Additionally, this patch makes them stop committing composition because
Chrome does not commit composition even if "undo"/"redo" is requested with
execCommand() during composition and it doesn't make sense to try to
undo/redo after committing composition since first undoable transaction
becomes the committing composition and committing composition causes
removing all transactions from redo transaction queue.

MozReview-Commit-ID: 78qlV2I9Lzk

--HG--
extra : rebase_source : 545c787d47fe02bf7e085be9d3ae028816750e69
2018-03-23 01:21:17 +09:00

92 lines
2.9 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_TransactionManager_h
#define mozilla_TransactionManager_h
#include "mozilla/TransactionStack.h"
#include "nsCOMArray.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsISupportsImpl.h"
#include "nsITransactionManager.h"
#include "nsWeakReference.h"
#include "nscore.h"
class nsITransaction;
class nsITransactionListener;
namespace mozilla {
class TransactionManager final : public nsITransactionManager
, public nsSupportsWeakReference
{
public:
explicit TransactionManager(int32_t aMaxTransactionCount = -1);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(TransactionManager,
nsITransactionManager)
NS_DECL_NSITRANSACTIONMANAGER
already_AddRefed<nsITransaction> PeekUndoStack();
already_AddRefed<nsITransaction> PeekRedoStack();
nsresult Undo();
nsresult Redo();
size_t NumberOfUndoItems() const
{
return mUndoStack.GetSize();
}
size_t NumberOfRedoItems() const
{
return mRedoStack.GetSize();
}
nsresult WillDoNotify(nsITransaction* aTransaction, bool* aInterrupt);
nsresult DidDoNotify(nsITransaction* aTransaction, nsresult aExecuteResult);
nsresult WillUndoNotify(nsITransaction* aTransaction, bool* aInterrupt);
nsresult DidUndoNotify(nsITransaction* aTransaction, nsresult aUndoResult);
nsresult WillRedoNotify(nsITransaction* aTransaction, bool *aInterrupt);
nsresult DidRedoNotify(nsITransaction* aTransaction, nsresult aRedoResult);
nsresult WillBeginBatchNotify(bool* aInterrupt);
nsresult DidBeginBatchNotify(nsresult aResult);
nsresult WillEndBatchNotify(bool* aInterrupt);
nsresult DidEndBatchNotify(nsresult aResult);
nsresult WillMergeNotify(nsITransaction* aTop,
nsITransaction* aTransaction,
bool* aInterrupt);
nsresult DidMergeNotify(nsITransaction* aTop,
nsITransaction* aTransaction,
bool aDidMerge,
nsresult aMergeResult);
private:
virtual ~TransactionManager() = default;
nsresult BeginTransaction(nsITransaction* aTransaction,
nsISupports* aData);
nsresult EndTransaction(bool aAllowEmpty);
int32_t mMaxTransactionCount;
TransactionStack mDoStack;
TransactionStack mUndoStack;
TransactionStack mRedoStack;
nsCOMArray<nsITransactionListener> mListeners;
};
} // namespace mozilla
mozilla::TransactionManager*
nsITransactionManager::AsTransactionManager()
{
return static_cast<mozilla::TransactionManager*>(this);
}
#endif // #ifndef mozilla_TransactionManager_h