gecko-dev/editor/txmgr/TransactionManager.h
Masayuki Nakano f882fa6959 Bug 1447924 - part 6: Implement EnableUndoRedo(), DisableUndoRedo() and ClearUndoRedo() in EditorBase and TransactionManager r=m_kato
nsIEditor::EnableUndo() and nsITransactionManager::Clear(),
nsITransactionManager::SetMaxTransactionCount() are called a lot but they are
virtual and some of or all of them are called once.  There should be each
non-virtual method to do what each root caller wants.  Therefore, this patch
adds EditorBase::EnableUndoRedo(), EditorBase::DisableUndoRedo(),
EditorBase::ClearUndoRedo(), TransactionManager::EnableUndoRedo(),
TransactionManager::DisableUndoRedo() and TransactionManager::ClearUndoRedo().

Note that this patch makes TransactionManager won't clear mUndoStack nor
mRedoStack if mDoStack is not empty.  This is checked only by
TransactionManager::SetMaxTransactionCount() but according to the comment,
TransactionManager::Clear(), TransactionManager::UndoStack() and
TransactionManager::RedoStack() should check it too.

MozReview-Commit-ID: 6qBZOQNwdhw

--HG--
extra : rebase_source : 3249137f7acca0b4698713ab732774140bcc27e8
2018-03-23 15:25:13 +09:00

107 lines
3.2 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();
}
bool EnableUndoRedo(int32_t aMaxTransactionCount = -1);
bool DisableUndoRedo()
{
return EnableUndoRedo(0);
}
bool ClearUndoRedo()
{
if (NS_WARN_IF(!mDoStack.IsEmpty())) {
return false;
}
mUndoStack.Clear();
mRedoStack.Clear();
return true;
}
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