mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 1447924 - part 1: Rename nsTransactionManager to mozilla::TransactionManager r=m_kato
We should rename nsTransactionManager to mozilla::TransactionManager before adding new non-virtual methods. MozReview-Commit-ID: JsivNVfDhex --HG-- rename : editor/txmgr/nsTransactionManager.cpp => editor/txmgr/TransactionManager.cpp rename : editor/txmgr/nsTransactionManager.h => editor/txmgr/TransactionManager.h rename : editor/txmgr/nsTransactionManagerFactory.cpp => editor/txmgr/TransactionManagerFactory.cpp extra : rebase_source : ff5bf76fec8be8f6a1202c17d488cf6c607d8f03
This commit is contained in:
parent
e9d257856b
commit
c525b695b9
@ -48,6 +48,7 @@
|
||||
#include "mozilla/TextInputListener.h" // for TextInputListener
|
||||
#include "mozilla/TextServicesDocument.h" // for TextServicesDocument
|
||||
#include "mozilla/TextEvents.h"
|
||||
#include "mozilla/TransactionManager.h" // for TransactionManager
|
||||
#include "mozilla/dom/CharacterData.h" // for CharacterData
|
||||
#include "mozilla/dom/Element.h" // for Element, nsINode::AsElement
|
||||
#include "mozilla/dom/HTMLBodyElement.h"
|
||||
@ -108,7 +109,6 @@
|
||||
#include "nsStyleStructFwd.h" // for nsIFrame::StyleUIReset, etc.
|
||||
#include "nsTextNode.h" // for nsTextNode
|
||||
#include "nsThreadUtils.h" // for nsRunnable
|
||||
#include "nsTransactionManager.h" // for nsTransactionManager
|
||||
#include "prtime.h" // for PR_Now
|
||||
|
||||
class nsIOutputStream;
|
||||
@ -180,7 +180,7 @@ EditorBase::~EditorBase()
|
||||
}
|
||||
// If this editor is still hiding the caret, we need to restore it.
|
||||
HideCaret(false);
|
||||
mTxnMgr = nullptr;
|
||||
mTransactionManager = nullptr;
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(EditorBase)
|
||||
@ -193,7 +193,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(EditorBase)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mInlineSpellChecker)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTextServicesDocument)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTextInputListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTxnMgr)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTransactionManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mActionListeners)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEditorObservers)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocStateListeners)
|
||||
@ -223,7 +223,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(EditorBase)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInlineSpellChecker)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTextServicesDocument)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTextInputListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTxnMgr)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTransactionManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mActionListeners)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEditorObservers)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocStateListeners)
|
||||
@ -525,9 +525,9 @@ EditorBase::PreDestroy(bool aDestroyingFrames)
|
||||
|
||||
// Transaction may grab this instance. Therefore, they should be released
|
||||
// here for stopping the circular reference with this instance.
|
||||
if (mTxnMgr) {
|
||||
mTxnMgr->Clear();
|
||||
mTxnMgr = nullptr;
|
||||
if (mTransactionManager) {
|
||||
mTransactionManager->Clear();
|
||||
mTransactionManager = nullptr;
|
||||
}
|
||||
|
||||
mDidPreDestroy = true;
|
||||
@ -746,8 +746,9 @@ EditorBase::DoTransaction(Selection* aSelection, nsITransaction* aTxn)
|
||||
// We will recurse, but will not hit this case in the nested call
|
||||
DoTransaction(mPlaceholderTransaction);
|
||||
|
||||
if (mTxnMgr) {
|
||||
nsCOMPtr<nsITransaction> topTransaction = mTxnMgr->PeekUndoStack();
|
||||
if (mTransactionManager) {
|
||||
nsCOMPtr<nsITransaction> topTransaction =
|
||||
mTransactionManager->PeekUndoStack();
|
||||
nsCOMPtr<nsIAbsorbingTransaction> topAbsorbingTransaction =
|
||||
do_QueryInterface(topTransaction);
|
||||
if (topAbsorbingTransaction) {
|
||||
@ -791,9 +792,9 @@ EditorBase::DoTransaction(Selection* aSelection, nsITransaction* aTxn)
|
||||
SelectionBatcher selectionBatcher(selection);
|
||||
|
||||
nsresult rv;
|
||||
if (mTxnMgr) {
|
||||
RefPtr<nsTransactionManager> txnMgr = mTxnMgr;
|
||||
rv = txnMgr->DoTransaction(aTxn);
|
||||
if (mTransactionManager) {
|
||||
RefPtr<TransactionManager> transactionManager(mTransactionManager);
|
||||
rv = transactionManager->DoTransaction(aTxn);
|
||||
} else {
|
||||
rv = aTxn->DoTransaction();
|
||||
}
|
||||
@ -811,14 +812,14 @@ NS_IMETHODIMP
|
||||
EditorBase::EnableUndo(bool aEnable)
|
||||
{
|
||||
if (aEnable) {
|
||||
if (!mTxnMgr) {
|
||||
mTxnMgr = new nsTransactionManager();
|
||||
if (!mTransactionManager) {
|
||||
mTransactionManager = new TransactionManager();
|
||||
}
|
||||
mTxnMgr->SetMaxTransactionCount(-1);
|
||||
} else if (mTxnMgr) {
|
||||
mTransactionManager->SetMaxTransactionCount(-1);
|
||||
} else if (mTransactionManager) {
|
||||
// disable the transaction manager if it is enabled
|
||||
mTxnMgr->Clear();
|
||||
mTxnMgr->SetMaxTransactionCount(0);
|
||||
mTransactionManager->Clear();
|
||||
mTransactionManager->SetMaxTransactionCount(0);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -834,11 +835,12 @@ EditorBase::GetNumberOfUndoItems(int32_t* aNumItems)
|
||||
int32_t
|
||||
EditorBase::NumberOfUndoItems() const
|
||||
{
|
||||
if (!mTxnMgr) {
|
||||
if (!mTransactionManager) {
|
||||
return 0;
|
||||
}
|
||||
int32_t numItems = 0;
|
||||
if (NS_WARN_IF(NS_FAILED(mTxnMgr->GetNumberOfUndoItems(&numItems)))) {
|
||||
nsresult rv = mTransactionManager->GetNumberOfUndoItems(&numItems);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return -1;
|
||||
}
|
||||
return numItems;
|
||||
@ -854,11 +856,12 @@ EditorBase::GetNumberOfRedoItems(int32_t* aNumItems)
|
||||
int32_t
|
||||
EditorBase::NumberOfRedoItems() const
|
||||
{
|
||||
if (!mTxnMgr) {
|
||||
if (!mTransactionManager) {
|
||||
return 0;
|
||||
}
|
||||
int32_t numItems = 0;
|
||||
if (NS_WARN_IF(NS_FAILED(mTxnMgr->GetNumberOfRedoItems(&numItems)))) {
|
||||
nsresult rv = mTransactionManager->GetNumberOfRedoItems(&numItems);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return -1;
|
||||
}
|
||||
return numItems;
|
||||
@ -882,7 +885,7 @@ EditorBase::GetTransactionManager(nsITransactionManager** aTxnManager)
|
||||
already_AddRefed<nsITransactionManager>
|
||||
EditorBase::GetTransactionManager() const
|
||||
{
|
||||
nsCOMPtr<nsITransactionManager> transactionManager = mTxnMgr.get();
|
||||
nsCOMPtr<nsITransactionManager> transactionManager(mTransactionManager);
|
||||
return transactionManager.forget();
|
||||
}
|
||||
|
||||
@ -891,19 +894,19 @@ EditorBase::Undo(uint32_t aCount)
|
||||
{
|
||||
ForceCompositionEnd();
|
||||
|
||||
bool hasTxnMgr, hasTransaction = false;
|
||||
CanUndo(&hasTxnMgr, &hasTransaction);
|
||||
bool hasTransactionManager, hasTransaction = false;
|
||||
CanUndo(&hasTransactionManager, &hasTransaction);
|
||||
NS_ENSURE_TRUE(hasTransaction, NS_OK);
|
||||
|
||||
AutoRules beginRulesSniffing(this, EditAction::undo, nsIEditor::eNone);
|
||||
|
||||
if (!mTxnMgr) {
|
||||
if (!mTransactionManager) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<nsTransactionManager> txnMgr = mTxnMgr;
|
||||
RefPtr<TransactionManager> transactionManager(mTransactionManager);
|
||||
for (uint32_t i = 0; i < aCount; ++i) {
|
||||
nsresult rv = txnMgr->UndoTransaction();
|
||||
nsresult rv = transactionManager->UndoTransaction();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
DoAfterUndoTransaction();
|
||||
@ -917,10 +920,10 @@ EditorBase::CanUndo(bool* aIsEnabled,
|
||||
bool* aCanUndo)
|
||||
{
|
||||
NS_ENSURE_TRUE(aIsEnabled && aCanUndo, NS_ERROR_NULL_POINTER);
|
||||
*aIsEnabled = !!mTxnMgr;
|
||||
*aIsEnabled = !!mTransactionManager;
|
||||
if (*aIsEnabled) {
|
||||
int32_t numTxns = 0;
|
||||
mTxnMgr->GetNumberOfUndoItems(&numTxns);
|
||||
mTransactionManager->GetNumberOfUndoItems(&numTxns);
|
||||
*aCanUndo = !!numTxns;
|
||||
} else {
|
||||
*aCanUndo = false;
|
||||
@ -931,19 +934,19 @@ EditorBase::CanUndo(bool* aIsEnabled,
|
||||
NS_IMETHODIMP
|
||||
EditorBase::Redo(uint32_t aCount)
|
||||
{
|
||||
bool hasTxnMgr, hasTransaction = false;
|
||||
CanRedo(&hasTxnMgr, &hasTransaction);
|
||||
bool hasTransactionManager, hasTransaction = false;
|
||||
CanRedo(&hasTransactionManager, &hasTransaction);
|
||||
NS_ENSURE_TRUE(hasTransaction, NS_OK);
|
||||
|
||||
AutoRules beginRulesSniffing(this, EditAction::redo, nsIEditor::eNone);
|
||||
|
||||
if (!mTxnMgr) {
|
||||
if (!mTransactionManager) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<nsTransactionManager> txnMgr = mTxnMgr;
|
||||
RefPtr<TransactionManager> transactionManager(mTransactionManager);
|
||||
for (uint32_t i = 0; i < aCount; ++i) {
|
||||
nsresult rv = txnMgr->RedoTransaction();
|
||||
nsresult rv = transactionManager->RedoTransaction();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
DoAfterRedoTransaction();
|
||||
@ -957,10 +960,10 @@ EditorBase::CanRedo(bool* aIsEnabled, bool* aCanRedo)
|
||||
{
|
||||
NS_ENSURE_TRUE(aIsEnabled && aCanRedo, NS_ERROR_NULL_POINTER);
|
||||
|
||||
*aIsEnabled = !!mTxnMgr;
|
||||
*aIsEnabled = !!mTransactionManager;
|
||||
if (*aIsEnabled) {
|
||||
int32_t numTxns = 0;
|
||||
mTxnMgr->GetNumberOfRedoItems(&numTxns);
|
||||
mTransactionManager->GetNumberOfRedoItems(&numTxns);
|
||||
*aCanRedo = !!numTxns;
|
||||
} else {
|
||||
*aCanRedo = false;
|
||||
@ -973,9 +976,9 @@ EditorBase::BeginTransaction()
|
||||
{
|
||||
BeginUpdateViewBatch();
|
||||
|
||||
if (mTxnMgr) {
|
||||
RefPtr<nsTransactionManager> txnMgr = mTxnMgr;
|
||||
txnMgr->BeginBatch(nullptr);
|
||||
if (mTransactionManager) {
|
||||
RefPtr<TransactionManager> transactionManager(mTransactionManager);
|
||||
transactionManager->BeginBatch(nullptr);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -984,9 +987,9 @@ EditorBase::BeginTransaction()
|
||||
NS_IMETHODIMP
|
||||
EditorBase::EndTransaction()
|
||||
{
|
||||
if (mTxnMgr) {
|
||||
RefPtr<nsTransactionManager> txnMgr = mTxnMgr;
|
||||
txnMgr->EndBatch(false);
|
||||
if (mTransactionManager) {
|
||||
RefPtr<TransactionManager> transactionManager(mTransactionManager);
|
||||
transactionManager->EndBatch(false);
|
||||
}
|
||||
|
||||
EndUpdateViewBatch();
|
||||
@ -2471,8 +2474,8 @@ EditorBase::EndIMEComposition()
|
||||
|
||||
// commit the IME transaction..we can get at it via the transaction mgr.
|
||||
// Note that this means IME won't work without an undo stack!
|
||||
if (mTxnMgr) {
|
||||
nsCOMPtr<nsITransaction> txn = mTxnMgr->PeekUndoStack();
|
||||
if (mTransactionManager) {
|
||||
nsCOMPtr<nsITransaction> txn = mTransactionManager->PeekUndoStack();
|
||||
nsCOMPtr<nsIAbsorbingTransaction> plcTxn = do_QueryInterface(txn);
|
||||
if (plcTxn) {
|
||||
DebugOnly<nsresult> rv = plcTxn->Commit();
|
||||
|
@ -51,7 +51,6 @@ class nsISupports;
|
||||
class nsITransaction;
|
||||
class nsIWidget;
|
||||
class nsRange;
|
||||
class nsTransactionManager;
|
||||
|
||||
namespace mozilla {
|
||||
class AddStyleSheetTransaction;
|
||||
@ -80,6 +79,7 @@ class TextComposition;
|
||||
class TextEditor;
|
||||
class TextInputListener;
|
||||
class TextServicesDocument;
|
||||
class TransactionManager;
|
||||
enum class EditAction : int32_t;
|
||||
|
||||
namespace dom {
|
||||
@ -1513,7 +1513,7 @@ protected:
|
||||
// Reference to text services document for mInlineSpellChecker.
|
||||
RefPtr<TextServicesDocument> mTextServicesDocument;
|
||||
|
||||
RefPtr<nsTransactionManager> mTxnMgr;
|
||||
RefPtr<TransactionManager> mTransactionManager;
|
||||
// Cached root node.
|
||||
nsCOMPtr<Element> mRootElement;
|
||||
// The form field as an event receiver.
|
||||
|
@ -3,6 +3,8 @@
|
||||
* 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/. */
|
||||
|
||||
#include "mozilla/TransactionManager.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/mozalloc.h"
|
||||
#include "nsCOMPtr.h"
|
||||
@ -14,10 +16,11 @@
|
||||
#include "nsITransactionListener.h"
|
||||
#include "nsIWeakReference.h"
|
||||
#include "nsTransactionItem.h"
|
||||
#include "nsTransactionManager.h"
|
||||
#include "nsTransactionStack.h"
|
||||
|
||||
nsTransactionManager::nsTransactionManager(int32_t aMaxTransactionCount)
|
||||
namespace mozilla {
|
||||
|
||||
TransactionManager::TransactionManager(int32_t aMaxTransactionCount)
|
||||
: mMaxTransactionCount(aMaxTransactionCount)
|
||||
, mDoStack(nsTransactionStack::FOR_UNDO)
|
||||
, mUndoStack(nsTransactionStack::FOR_UNDO)
|
||||
@ -25,37 +28,33 @@ nsTransactionManager::nsTransactionManager(int32_t aMaxTransactionCount)
|
||||
{
|
||||
}
|
||||
|
||||
nsTransactionManager::~nsTransactionManager()
|
||||
{
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(TransactionManager)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(nsTransactionManager)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsTransactionManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(TransactionManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mListeners)
|
||||
tmp->mDoStack.DoUnlink();
|
||||
tmp->mUndoStack.DoUnlink();
|
||||
tmp->mRedoStack.DoUnlink();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsTransactionManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(TransactionManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mListeners)
|
||||
tmp->mDoStack.DoTraverse(cb);
|
||||
tmp->mUndoStack.DoTraverse(cb);
|
||||
tmp->mRedoStack.DoTraverse(cb);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsTransactionManager)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TransactionManager)
|
||||
NS_INTERFACE_MAP_ENTRY(nsITransactionManager)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITransactionManager)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTransactionManager)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTransactionManager)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(TransactionManager)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(TransactionManager)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::DoTransaction(nsITransaction *aTransaction)
|
||||
TransactionManager::DoTransaction(nsITransaction* aTransaction)
|
||||
{
|
||||
NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
|
||||
|
||||
@ -88,7 +87,7 @@ nsTransactionManager::DoTransaction(nsITransaction *aTransaction)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::UndoTransaction()
|
||||
TransactionManager::UndoTransaction()
|
||||
{
|
||||
// It is illegal to call UndoTransaction() while the transaction manager is
|
||||
// executing a transaction's DoTransaction() method! If this happens,
|
||||
@ -132,7 +131,7 @@ nsTransactionManager::UndoTransaction()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::RedoTransaction()
|
||||
TransactionManager::RedoTransaction()
|
||||
{
|
||||
// It is illegal to call RedoTransaction() while the transaction manager is
|
||||
// executing a transaction's DoTransaction() method! If this happens,
|
||||
@ -176,7 +175,7 @@ nsTransactionManager::RedoTransaction()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::Clear()
|
||||
TransactionManager::Clear()
|
||||
{
|
||||
nsresult rv = ClearRedoStack();
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -186,7 +185,7 @@ nsTransactionManager::Clear()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::BeginBatch(nsISupports* aData)
|
||||
TransactionManager::BeginBatch(nsISupports* aData)
|
||||
{
|
||||
// We can batch independent transactions together by simply pushing
|
||||
// a dummy transaction item on the do stack. This dummy transaction item
|
||||
@ -214,7 +213,7 @@ nsTransactionManager::BeginBatch(nsISupports* aData)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::EndBatch(bool aAllowEmpty)
|
||||
TransactionManager::EndBatch(bool aAllowEmpty)
|
||||
{
|
||||
// XXX: Need to add some mechanism to detect the case where the transaction
|
||||
// at the top of the do stack isn't the dummy transaction, so we can
|
||||
@ -256,21 +255,21 @@ nsTransactionManager::EndBatch(bool aAllowEmpty)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::GetNumberOfUndoItems(int32_t *aNumItems)
|
||||
TransactionManager::GetNumberOfUndoItems(int32_t* aNumItems)
|
||||
{
|
||||
*aNumItems = mUndoStack.GetSize();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::GetNumberOfRedoItems(int32_t *aNumItems)
|
||||
TransactionManager::GetNumberOfRedoItems(int32_t* aNumItems)
|
||||
{
|
||||
*aNumItems = mRedoStack.GetSize();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::GetMaxTransactionCount(int32_t *aMaxCount)
|
||||
TransactionManager::GetMaxTransactionCount(int32_t* aMaxCount)
|
||||
{
|
||||
NS_ENSURE_TRUE(aMaxCount, NS_ERROR_NULL_POINTER);
|
||||
*aMaxCount = mMaxTransactionCount;
|
||||
@ -278,7 +277,7 @@ nsTransactionManager::GetMaxTransactionCount(int32_t *aMaxCount)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::SetMaxTransactionCount(int32_t aMaxCount)
|
||||
TransactionManager::SetMaxTransactionCount(int32_t aMaxCount)
|
||||
{
|
||||
// It is illegal to call SetMaxTransactionCount() while the transaction
|
||||
// manager is executing a transaction's DoTransaction() method because
|
||||
@ -332,7 +331,7 @@ nsTransactionManager::SetMaxTransactionCount(int32_t aMaxCount)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::PeekUndoStack(nsITransaction **aTransaction)
|
||||
TransactionManager::PeekUndoStack(nsITransaction** aTransaction)
|
||||
{
|
||||
MOZ_ASSERT(aTransaction);
|
||||
*aTransaction = PeekUndoStack().take();
|
||||
@ -340,7 +339,7 @@ nsTransactionManager::PeekUndoStack(nsITransaction **aTransaction)
|
||||
}
|
||||
|
||||
already_AddRefed<nsITransaction>
|
||||
nsTransactionManager::PeekUndoStack()
|
||||
TransactionManager::PeekUndoStack()
|
||||
{
|
||||
RefPtr<nsTransactionItem> tx = mUndoStack.Peek();
|
||||
if (!tx) {
|
||||
@ -350,7 +349,7 @@ nsTransactionManager::PeekUndoStack()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::PeekRedoStack(nsITransaction** aTransaction)
|
||||
TransactionManager::PeekRedoStack(nsITransaction** aTransaction)
|
||||
{
|
||||
MOZ_ASSERT(aTransaction);
|
||||
*aTransaction = PeekRedoStack().take();
|
||||
@ -358,7 +357,7 @@ nsTransactionManager::PeekRedoStack(nsITransaction** aTransaction)
|
||||
}
|
||||
|
||||
already_AddRefed<nsITransaction>
|
||||
nsTransactionManager::PeekRedoStack()
|
||||
TransactionManager::PeekRedoStack()
|
||||
{
|
||||
RefPtr<nsTransactionItem> tx = mRedoStack.Peek();
|
||||
if (!tx) {
|
||||
@ -368,7 +367,7 @@ nsTransactionManager::PeekRedoStack()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::BatchTopUndo()
|
||||
TransactionManager::BatchTopUndo()
|
||||
{
|
||||
if (mUndoStack.GetSize() < 2) {
|
||||
// Not enough transactions to merge into one batch.
|
||||
@ -396,7 +395,7 @@ nsTransactionManager::BatchTopUndo()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::RemoveTopUndo()
|
||||
TransactionManager::RemoveTopUndo()
|
||||
{
|
||||
if (mUndoStack.IsEmpty()) {
|
||||
return NS_OK;
|
||||
@ -407,35 +406,36 @@ nsTransactionManager::RemoveTopUndo()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::AddListener(nsITransactionListener *aListener)
|
||||
TransactionManager::AddListener(nsITransactionListener* aListener)
|
||||
{
|
||||
NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
|
||||
return mListeners.AppendObject(aListener) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::RemoveListener(nsITransactionListener *aListener)
|
||||
TransactionManager::RemoveListener(nsITransactionListener* aListener)
|
||||
{
|
||||
NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
|
||||
return mListeners.RemoveObject(aListener) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::ClearUndoStack()
|
||||
TransactionManager::ClearUndoStack()
|
||||
{
|
||||
mUndoStack.Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::ClearRedoStack()
|
||||
TransactionManager::ClearRedoStack()
|
||||
{
|
||||
mRedoStack.Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::WillDoNotify(nsITransaction *aTransaction, bool *aInterrupt)
|
||||
TransactionManager::WillDoNotify(nsITransaction* aTransaction,
|
||||
bool* aInterrupt)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -450,7 +450,8 @@ nsTransactionManager::WillDoNotify(nsITransaction *aTransaction, bool *aInterrup
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::DidDoNotify(nsITransaction *aTransaction, nsresult aDoResult)
|
||||
TransactionManager::DidDoNotify(nsITransaction* aTransaction,
|
||||
nsresult aDoResult)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -465,7 +466,8 @@ nsTransactionManager::DidDoNotify(nsITransaction *aTransaction, nsresult aDoResu
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::WillUndoNotify(nsITransaction *aTransaction, bool *aInterrupt)
|
||||
TransactionManager::WillUndoNotify(nsITransaction* aTransaction,
|
||||
bool* aInterrupt)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -480,7 +482,8 @@ nsTransactionManager::WillUndoNotify(nsITransaction *aTransaction, bool *aInterr
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::DidUndoNotify(nsITransaction *aTransaction, nsresult aUndoResult)
|
||||
TransactionManager::DidUndoNotify(nsITransaction* aTransaction,
|
||||
nsresult aUndoResult)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -495,7 +498,8 @@ nsTransactionManager::DidUndoNotify(nsITransaction *aTransaction, nsresult aUndo
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::WillRedoNotify(nsITransaction *aTransaction, bool *aInterrupt)
|
||||
TransactionManager::WillRedoNotify(nsITransaction* aTransaction,
|
||||
bool* aInterrupt)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -510,7 +514,8 @@ nsTransactionManager::WillRedoNotify(nsITransaction *aTransaction, bool *aInterr
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::DidRedoNotify(nsITransaction *aTransaction, nsresult aRedoResult)
|
||||
TransactionManager::DidRedoNotify(nsITransaction* aTransaction,
|
||||
nsresult aRedoResult)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -525,7 +530,7 @@ nsTransactionManager::DidRedoNotify(nsITransaction *aTransaction, nsresult aRedo
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::WillBeginBatchNotify(bool *aInterrupt)
|
||||
TransactionManager::WillBeginBatchNotify(bool* aInterrupt)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -540,7 +545,7 @@ nsTransactionManager::WillBeginBatchNotify(bool *aInterrupt)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::DidBeginBatchNotify(nsresult aResult)
|
||||
TransactionManager::DidBeginBatchNotify(nsresult aResult)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -555,7 +560,7 @@ nsTransactionManager::DidBeginBatchNotify(nsresult aResult)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::WillEndBatchNotify(bool *aInterrupt)
|
||||
TransactionManager::WillEndBatchNotify(bool* aInterrupt)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -570,7 +575,7 @@ nsTransactionManager::WillEndBatchNotify(bool *aInterrupt)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::DidEndBatchNotify(nsresult aResult)
|
||||
TransactionManager::DidEndBatchNotify(nsresult aResult)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -585,7 +590,9 @@ nsTransactionManager::DidEndBatchNotify(nsresult aResult)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::WillMergeNotify(nsITransaction *aTop, nsITransaction *aTransaction, bool *aInterrupt)
|
||||
TransactionManager::WillMergeNotify(nsITransaction* aTop,
|
||||
nsITransaction* aTransaction,
|
||||
bool* aInterrupt)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -600,10 +607,10 @@ nsTransactionManager::WillMergeNotify(nsITransaction *aTop, nsITransaction *aTra
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::DidMergeNotify(nsITransaction *aTop,
|
||||
nsITransaction *aTransaction,
|
||||
bool aDidMerge,
|
||||
nsresult aMergeResult)
|
||||
TransactionManager::DidMergeNotify(nsITransaction* aTop,
|
||||
nsITransaction* aTransaction,
|
||||
bool aDidMerge,
|
||||
nsresult aMergeResult)
|
||||
{
|
||||
for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
|
||||
nsITransactionListener* listener = mListeners[i];
|
||||
@ -619,8 +626,8 @@ nsTransactionManager::DidMergeNotify(nsITransaction *aTop,
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::BeginTransaction(nsITransaction *aTransaction,
|
||||
nsISupports *aData)
|
||||
TransactionManager::BeginTransaction(nsITransaction* aTransaction,
|
||||
nsISupports* aData)
|
||||
{
|
||||
// XXX: POSSIBLE OPTIMIZATION
|
||||
// We could use a factory that pre-allocates/recycles transaction items.
|
||||
@ -645,7 +652,7 @@ nsTransactionManager::BeginTransaction(nsITransaction *aTransaction,
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::EndTransaction(bool aAllowEmpty)
|
||||
TransactionManager::EndTransaction(bool aAllowEmpty)
|
||||
{
|
||||
RefPtr<nsTransactionItem> tx = mDoStack.Pop();
|
||||
if (!tx) {
|
||||
@ -728,3 +735,5 @@ nsTransactionManager::EndTransaction(bool aAllowEmpty)
|
||||
mUndoStack.Push(tx.forget());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
73
editor/txmgr/TransactionManager.h
Normal file
73
editor/txmgr/TransactionManager.h
Normal file
@ -0,0 +1,73 @@
|
||||
/* -*- 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 "nsCOMArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsTransactionStack.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsITransactionManager.h"
|
||||
#include "nsTransactionStack.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 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;
|
||||
nsTransactionStack mDoStack;
|
||||
nsTransactionStack mUndoStack;
|
||||
nsTransactionStack mRedoStack;
|
||||
nsCOMArray<nsITransactionListener> mListeners;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // #ifndef mozilla_TransactionManager_h
|
@ -7,32 +7,35 @@
|
||||
|
||||
#include "mozilla/Module.h"
|
||||
#include "mozilla/ModuleUtils.h"
|
||||
#include "mozilla/TransactionManager.h"
|
||||
#include "nsID.h"
|
||||
#include "nsITransactionManager.h"
|
||||
#include "nsTransactionManager.h"
|
||||
#include "nsTransactionManagerCID.h"
|
||||
|
||||
using mozilla::TransactionManager;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Define the contructor function for the objects
|
||||
//
|
||||
// NOTE: This creates an instance of objects by using the default constructor
|
||||
//
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransactionManager)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(TransactionManager)
|
||||
NS_DEFINE_NAMED_CID(NS_TRANSACTIONMANAGER_CID);
|
||||
|
||||
static const mozilla::Module::CIDEntry kTxMgrCIDs[] = {
|
||||
{ &kNS_TRANSACTIONMANAGER_CID, false, nullptr, nsTransactionManagerConstructor },
|
||||
{ nullptr }
|
||||
{ &kNS_TRANSACTIONMANAGER_CID, false, nullptr,
|
||||
TransactionManagerConstructor },
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
static const mozilla::Module::ContractIDEntry kTxMgrContracts[] = {
|
||||
{ NS_TRANSACTIONMANAGER_CONTRACTID, &kNS_TRANSACTIONMANAGER_CID },
|
||||
{ nullptr }
|
||||
{ NS_TRANSACTIONMANAGER_CONTRACTID, &kNS_TRANSACTIONMANAGER_CID },
|
||||
{ nullptr }
|
||||
};
|
||||
|
||||
static const mozilla::Module kTxMgrModule = {
|
||||
mozilla::Module::kVersion,
|
||||
kTxMgrCIDs,
|
||||
kTxMgrContracts
|
||||
mozilla::Module::kVersion,
|
||||
kTxMgrCIDs,
|
||||
kTxMgrContracts
|
||||
};
|
||||
|
||||
NSMODULE_DEFN(nsTransactionManagerModule) = &kTxMgrModule;
|
@ -18,11 +18,15 @@ EXPORTS += [
|
||||
'nsTransactionManagerCID.h',
|
||||
]
|
||||
|
||||
EXPORTS.mozilla += [
|
||||
'TransactionManager.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'nsTransactionItem.cpp',
|
||||
'nsTransactionManager.cpp',
|
||||
'nsTransactionManagerFactory.cpp',
|
||||
'nsTransactionStack.cpp',
|
||||
'TransactionManager.cpp',
|
||||
'TransactionManagerFactory.cpp',
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
@ -7,12 +7,6 @@
|
||||
#include "nsITransaction.idl"
|
||||
#include "nsITransactionListener.idl"
|
||||
|
||||
%{ C++
|
||||
|
||||
#define NS_TRANSACTIONMANAGER_CONTRACTID "@mozilla.org/transactionmanager;1"
|
||||
|
||||
%} C++
|
||||
|
||||
/**
|
||||
* The nsITransactionManager interface.
|
||||
* <P>
|
||||
@ -151,3 +145,13 @@ interface nsITransactionManager : nsISupports
|
||||
void RemoveListener(in nsITransactionListener aListener);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
|
||||
#define NS_TRANSACTIONMANAGER_CONTRACTID "@mozilla.org/transactionmanager;1"
|
||||
|
||||
// 9C8F9601-801A-11d2-98BA-00805F297D89
|
||||
#define NS_TRANSACTIONMANAGER_CID \
|
||||
{ 0x9c8f9601, 0x801a, 0x11d2, \
|
||||
{ 0x98, 0xba, 0x0, 0x80, 0x5f, 0x29, 0x7d, 0x89 } }
|
||||
|
||||
%} C++
|
||||
|
@ -3,16 +3,19 @@
|
||||
* 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/. */
|
||||
|
||||
#include "nsTransactionItem.h"
|
||||
|
||||
#include "mozilla/mozalloc.h"
|
||||
#include "mozilla/TransactionManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsError.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsITransaction.h"
|
||||
#include "nsTransactionItem.h"
|
||||
#include "nsTransactionManager.h"
|
||||
#include "nsTransactionStack.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
nsTransactionItem::nsTransactionItem(nsITransaction *aTransaction)
|
||||
: mTransaction(aTransaction), mUndoStack(0), mRedoStack(0)
|
||||
{
|
||||
@ -159,11 +162,11 @@ nsTransactionItem::DoTransaction()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionItem::UndoTransaction(nsTransactionManager *aTxMgr)
|
||||
nsTransactionItem::UndoTransaction(TransactionManager* aTransactionManager)
|
||||
{
|
||||
nsresult rv = UndoChildren(aTxMgr);
|
||||
nsresult rv = UndoChildren(aTransactionManager);
|
||||
if (NS_FAILED(rv)) {
|
||||
RecoverFromUndoError(aTxMgr);
|
||||
RecoverFromUndoError(aTransactionManager);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -173,7 +176,7 @@ nsTransactionItem::UndoTransaction(nsTransactionManager *aTxMgr)
|
||||
|
||||
rv = mTransaction->UndoTransaction();
|
||||
if (NS_FAILED(rv)) {
|
||||
RecoverFromUndoError(aTxMgr);
|
||||
RecoverFromUndoError(aTransactionManager);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -181,7 +184,7 @@ nsTransactionItem::UndoTransaction(nsTransactionManager *aTxMgr)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionItem::UndoChildren(nsTransactionManager *aTxMgr)
|
||||
nsTransactionItem::UndoChildren(TransactionManager* aTransactionManager)
|
||||
{
|
||||
if (mUndoStack) {
|
||||
if (!mRedoStack && mUndoStack) {
|
||||
@ -200,7 +203,7 @@ nsTransactionItem::UndoChildren(nsTransactionManager *aTxMgr)
|
||||
|
||||
nsCOMPtr<nsITransaction> t = item->GetTransaction();
|
||||
bool doInterrupt = false;
|
||||
rv = aTxMgr->WillUndoNotify(t, &doInterrupt);
|
||||
rv = aTransactionManager->WillUndoNotify(t, &doInterrupt);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
@ -208,13 +211,13 @@ nsTransactionItem::UndoChildren(nsTransactionManager *aTxMgr)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
rv = item->UndoTransaction(aTxMgr);
|
||||
rv = item->UndoTransaction(aTransactionManager);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
item = mUndoStack->Pop();
|
||||
mRedoStack->Push(item.forget());
|
||||
}
|
||||
|
||||
nsresult rv2 = aTxMgr->DidUndoNotify(t, rv);
|
||||
nsresult rv2 = aTransactionManager->DidUndoNotify(t, rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = rv2;
|
||||
}
|
||||
@ -229,7 +232,7 @@ nsTransactionItem::UndoChildren(nsTransactionManager *aTxMgr)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionItem::RedoTransaction(nsTransactionManager *aTxMgr)
|
||||
nsTransactionItem::RedoTransaction(TransactionManager* aTransactionManager)
|
||||
{
|
||||
nsCOMPtr<nsITransaction> transaction(mTransaction);
|
||||
if (transaction) {
|
||||
@ -237,9 +240,9 @@ nsTransactionItem::RedoTransaction(nsTransactionManager *aTxMgr)
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
nsresult rv = RedoChildren(aTxMgr);
|
||||
nsresult rv = RedoChildren(aTransactionManager);
|
||||
if (NS_FAILED(rv)) {
|
||||
RecoverFromRedoError(aTxMgr);
|
||||
RecoverFromRedoError(aTransactionManager);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -247,7 +250,7 @@ nsTransactionItem::RedoTransaction(nsTransactionManager *aTxMgr)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionItem::RedoChildren(nsTransactionManager *aTxMgr)
|
||||
nsTransactionItem::RedoChildren(TransactionManager* aTransactionManager)
|
||||
{
|
||||
if (!mRedoStack) {
|
||||
return NS_OK;
|
||||
@ -265,7 +268,7 @@ nsTransactionItem::RedoChildren(nsTransactionManager *aTxMgr)
|
||||
|
||||
nsCOMPtr<nsITransaction> t = item->GetTransaction();
|
||||
bool doInterrupt = false;
|
||||
rv = aTxMgr->WillRedoNotify(t, &doInterrupt);
|
||||
rv = aTransactionManager->WillRedoNotify(t, &doInterrupt);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
@ -273,14 +276,14 @@ nsTransactionItem::RedoChildren(nsTransactionManager *aTxMgr)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
rv = item->RedoTransaction(aTxMgr);
|
||||
rv = item->RedoTransaction(aTransactionManager);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
item = mRedoStack->Pop();
|
||||
mUndoStack->Push(item.forget());
|
||||
}
|
||||
|
||||
// XXX Shouldn't this DidRedoNotify()? (bug 1311626)
|
||||
nsresult rv2 = aTxMgr->DidUndoNotify(t, rv);
|
||||
nsresult rv2 = aTransactionManager->DidUndoNotify(t, rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = rv2;
|
||||
}
|
||||
@ -320,22 +323,22 @@ nsTransactionItem::GetNumberOfRedoItems(int32_t *aNumItems)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionItem::RecoverFromUndoError(nsTransactionManager *aTxMgr)
|
||||
nsTransactionItem::RecoverFromUndoError(TransactionManager* aTransactionManager)
|
||||
{
|
||||
// If this method gets called, we never got to the point where we
|
||||
// successfully called UndoTransaction() for the transaction item itself.
|
||||
// Just redo any children that successfully called undo!
|
||||
return RedoChildren(aTxMgr);
|
||||
return RedoChildren(aTransactionManager);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionItem::RecoverFromRedoError(nsTransactionManager *aTxMgr)
|
||||
nsTransactionItem::RecoverFromRedoError(TransactionManager* aTransactionManager)
|
||||
{
|
||||
// If this method gets called, we already successfully called
|
||||
// RedoTransaction() for the transaction item itself. Undo all
|
||||
// the children that successfully called RedoTransaction(),
|
||||
// then undo the transaction item itself.
|
||||
nsresult rv = UndoChildren(aTxMgr);
|
||||
nsresult rv = UndoChildren(aTransactionManager);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -13,9 +13,12 @@
|
||||
#include "nscore.h"
|
||||
|
||||
class nsITransaction;
|
||||
class nsTransactionManager;
|
||||
class nsTransactionStack;
|
||||
|
||||
namespace mozilla {
|
||||
class TransactionManager;
|
||||
} // namespace mozilla
|
||||
|
||||
class nsTransactionItem final
|
||||
{
|
||||
nsCOMArray<nsISupports> mData;
|
||||
@ -24,22 +27,21 @@ class nsTransactionItem final
|
||||
nsTransactionStack *mRedoStack;
|
||||
|
||||
public:
|
||||
|
||||
explicit nsTransactionItem(nsITransaction *aTransaction);
|
||||
explicit nsTransactionItem(nsITransaction* aTransaction);
|
||||
NS_METHOD_(MozExternalRefCountType) AddRef();
|
||||
NS_METHOD_(MozExternalRefCountType) Release();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsTransactionItem)
|
||||
|
||||
virtual nsresult AddChild(nsTransactionItem *aTransactionItem);
|
||||
nsresult AddChild(nsTransactionItem* aTransactionItem);
|
||||
already_AddRefed<nsITransaction> GetTransaction();
|
||||
virtual nsresult GetIsBatch(bool *aIsBatch);
|
||||
virtual nsresult GetNumberOfChildren(int32_t *aNumChildren);
|
||||
virtual nsresult GetChild(int32_t aIndex, nsTransactionItem **aChild);
|
||||
nsresult GetIsBatch(bool *aIsBatch);
|
||||
nsresult GetNumberOfChildren(int32_t *aNumChildren);
|
||||
nsresult GetChild(int32_t aIndex, nsTransactionItem** aChild);
|
||||
|
||||
virtual nsresult DoTransaction(void);
|
||||
virtual nsresult UndoTransaction(nsTransactionManager *aTxMgr);
|
||||
virtual nsresult RedoTransaction(nsTransactionManager *aTxMgr);
|
||||
nsresult DoTransaction();
|
||||
nsresult UndoTransaction(mozilla::TransactionManager* aTransactionManager);
|
||||
nsresult RedoTransaction(mozilla::TransactionManager* aTransactionManager);
|
||||
|
||||
nsCOMArray<nsISupports>& GetData()
|
||||
{
|
||||
@ -47,19 +49,21 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
nsresult UndoChildren(mozilla::TransactionManager* aTransactionManager);
|
||||
nsresult RedoChildren(mozilla::TransactionManager* aTransactionManager);
|
||||
|
||||
virtual nsresult UndoChildren(nsTransactionManager *aTxMgr);
|
||||
virtual nsresult RedoChildren(nsTransactionManager *aTxMgr);
|
||||
nsresult
|
||||
RecoverFromUndoError(mozilla::TransactionManager* aTransactionManager);
|
||||
nsresult
|
||||
RecoverFromRedoError(mozilla::TransactionManager* aTransactionManager);
|
||||
|
||||
virtual nsresult RecoverFromUndoError(nsTransactionManager *aTxMgr);
|
||||
virtual nsresult RecoverFromRedoError(nsTransactionManager *aTxMgr);
|
||||
|
||||
virtual nsresult GetNumberOfUndoItems(int32_t *aNumItems);
|
||||
virtual nsresult GetNumberOfRedoItems(int32_t *aNumItems);
|
||||
nsresult GetNumberOfUndoItems(int32_t* aNumItems);
|
||||
nsresult GetNumberOfRedoItems(int32_t* aNumItems);
|
||||
|
||||
void CleanUp();
|
||||
|
||||
protected:
|
||||
virtual ~nsTransactionItem();
|
||||
~nsTransactionItem();
|
||||
|
||||
nsCycleCollectingAutoRefCnt mRefCnt;
|
||||
NS_DECL_OWNINGTHREAD
|
||||
|
@ -1,83 +0,0 @@
|
||||
/* -*- 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 nsTransactionManager_h__
|
||||
#define nsTransactionManager_h__
|
||||
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsTransactionStack.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsITransactionManager.h"
|
||||
#include "nsTransactionStack.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nscore.h"
|
||||
|
||||
class nsITransaction;
|
||||
class nsITransactionListener;
|
||||
|
||||
/** implementation of a transaction manager object.
|
||||
*
|
||||
*/
|
||||
class nsTransactionManager final : public nsITransactionManager
|
||||
, public nsSupportsWeakReference
|
||||
{
|
||||
private:
|
||||
|
||||
int32_t mMaxTransactionCount;
|
||||
nsTransactionStack mDoStack;
|
||||
nsTransactionStack mUndoStack;
|
||||
nsTransactionStack mRedoStack;
|
||||
nsCOMArray<nsITransactionListener> mListeners;
|
||||
|
||||
/** The default destructor.
|
||||
*/
|
||||
virtual ~nsTransactionManager();
|
||||
|
||||
public:
|
||||
|
||||
/** The default constructor.
|
||||
*/
|
||||
explicit nsTransactionManager(int32_t aMaxTransactionCount=-1);
|
||||
|
||||
/* Macro for AddRef(), Release(), and QueryInterface() */
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTransactionManager,
|
||||
nsITransactionManager)
|
||||
|
||||
/* nsITransactionManager method implementations. */
|
||||
NS_DECL_NSITRANSACTIONMANAGER
|
||||
|
||||
already_AddRefed<nsITransaction> PeekUndoStack();
|
||||
already_AddRefed<nsITransaction> PeekRedoStack();
|
||||
|
||||
virtual nsresult WillDoNotify(nsITransaction *aTransaction, bool *aInterrupt);
|
||||
virtual nsresult DidDoNotify(nsITransaction *aTransaction, nsresult aExecuteResult);
|
||||
virtual nsresult WillUndoNotify(nsITransaction *aTransaction, bool *aInterrupt);
|
||||
virtual nsresult DidUndoNotify(nsITransaction *aTransaction, nsresult aUndoResult);
|
||||
virtual nsresult WillRedoNotify(nsITransaction *aTransaction, bool *aInterrupt);
|
||||
virtual nsresult DidRedoNotify(nsITransaction *aTransaction, nsresult aRedoResult);
|
||||
virtual nsresult WillBeginBatchNotify(bool *aInterrupt);
|
||||
virtual nsresult DidBeginBatchNotify(nsresult aResult);
|
||||
virtual nsresult WillEndBatchNotify(bool *aInterrupt);
|
||||
virtual nsresult DidEndBatchNotify(nsresult aResult);
|
||||
virtual nsresult WillMergeNotify(nsITransaction *aTop,
|
||||
nsITransaction *aTransaction,
|
||||
bool *aInterrupt);
|
||||
virtual nsresult DidMergeNotify(nsITransaction *aTop,
|
||||
nsITransaction *aTransaction,
|
||||
bool aDidMerge,
|
||||
nsresult aMergeResult);
|
||||
|
||||
private:
|
||||
|
||||
/* nsTransactionManager specific private methods. */
|
||||
virtual nsresult BeginTransaction(nsITransaction *aTransaction,
|
||||
nsISupports *aData);
|
||||
virtual nsresult EndTransaction(bool aAllowEmpty);
|
||||
};
|
||||
|
||||
#endif // nsTransactionManager_h__
|
@ -3,12 +3,7 @@
|
||||
* 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 nsTransactionManagerCID_h__
|
||||
#define nsTransactionManagerCID_h__
|
||||
// XXX Needs to modify mailnews/base/src/nsMsgWindow.cpp before removing this
|
||||
// header file.
|
||||
#include "nsITransactionManager.h"
|
||||
|
||||
#define NS_TRANSACTIONMANAGER_CID \
|
||||
{ /* 9C8F9601-801A-11d2-98BA-00805F297D89 */ \
|
||||
0x9c8f9601, 0x801a, 0x11d2, \
|
||||
{ 0x98, 0xba, 0x0, 0x80, 0x5f, 0x29, 0x7d, 0x89 } }
|
||||
|
||||
#endif /* nsTransactionManagerCID_h__ */
|
||||
|
Loading…
Reference in New Issue
Block a user