mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 730882 - Clean up nsTransactionStack; r=roc
This commit is contained in:
parent
147c013f99
commit
cf880062aa
@ -106,8 +106,7 @@ nsTransactionItem::AddChild(nsTransactionItem *aTransactionItem)
|
||||
NS_ENSURE_TRUE(aTransactionItem, NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (!mUndoStack) {
|
||||
mUndoStack = new nsTransactionStack();
|
||||
NS_ENSURE_TRUE(mUndoStack, NS_ERROR_OUT_OF_MEMORY);
|
||||
mUndoStack = new nsTransactionStack(nsTransactionStack::FOR_UNDO);
|
||||
}
|
||||
|
||||
mUndoStack->Push(aTransactionItem);
|
||||
@ -187,7 +186,9 @@ nsTransactionItem::GetChild(PRInt32 aIndex, nsTransactionItem **aChild)
|
||||
if (numItems > 0 && aIndex < numItems) {
|
||||
NS_ENSURE_TRUE(mUndoStack, NS_ERROR_FAILURE);
|
||||
|
||||
return mUndoStack->GetItem(aIndex, aChild);
|
||||
nsRefPtr<nsTransactionItem> child = mUndoStack->GetItem(aIndex);
|
||||
child.forget(aChild);
|
||||
return *aChild ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Adjust the index for the redo stack:
|
||||
@ -200,7 +201,9 @@ nsTransactionItem::GetChild(PRInt32 aIndex, nsTransactionItem **aChild)
|
||||
|
||||
NS_ENSURE_TRUE(mRedoStack && numItems != 0 && aIndex < numItems, NS_ERROR_FAILURE);
|
||||
|
||||
return mRedoStack->GetItem(numItems - aIndex - 1, aChild);
|
||||
nsRefPtr<nsTransactionItem> child = mRedoStack->GetItem(aIndex);
|
||||
child.forget(aChild);
|
||||
return *aChild ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -243,20 +246,17 @@ nsTransactionItem::UndoChildren(nsTransactionManager *aTxMgr)
|
||||
|
||||
if (mUndoStack) {
|
||||
if (!mRedoStack && mUndoStack) {
|
||||
mRedoStack = new nsTransactionRedoStack();
|
||||
NS_ENSURE_TRUE(mRedoStack, NS_ERROR_OUT_OF_MEMORY);
|
||||
mRedoStack = new nsTransactionStack(nsTransactionStack::FOR_REDO);
|
||||
}
|
||||
|
||||
/* Undo all of the transaction items children! */
|
||||
result = mUndoStack->GetSize(&sz);
|
||||
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
sz = mUndoStack->GetSize();
|
||||
|
||||
while (sz-- > 0) {
|
||||
result = mUndoStack->Peek(getter_AddRefs(item));
|
||||
item = mUndoStack->Peek();
|
||||
|
||||
if (NS_FAILED(result) || !item) {
|
||||
return result;
|
||||
if (!item) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITransaction> t;
|
||||
@ -282,15 +282,8 @@ nsTransactionItem::UndoChildren(nsTransactionManager *aTxMgr)
|
||||
result = item->UndoTransaction(aTxMgr);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = mUndoStack->Pop(getter_AddRefs(item));
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = mRedoStack->Push(item);
|
||||
|
||||
/* XXX: If we got an error here, I doubt we can recover!
|
||||
* XXX: Should we just push the item back on the undo stack?
|
||||
*/
|
||||
}
|
||||
item = mUndoStack->Pop();
|
||||
mRedoStack->Push(item);
|
||||
}
|
||||
|
||||
nsresult result2 = aTxMgr->DidUndoNotify(t, result);
|
||||
@ -331,22 +324,18 @@ nsTransactionItem::RedoChildren(nsTransactionManager *aTxMgr)
|
||||
{
|
||||
nsRefPtr<nsTransactionItem> item;
|
||||
nsresult result = NS_OK;
|
||||
PRInt32 sz = 0;
|
||||
|
||||
if (!mRedoStack)
|
||||
return NS_OK;
|
||||
|
||||
/* Redo all of the transaction items children! */
|
||||
result = mRedoStack->GetSize(&sz);
|
||||
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
|
||||
PRInt32 sz = mRedoStack->GetSize();
|
||||
|
||||
while (sz-- > 0) {
|
||||
result = mRedoStack->Peek(getter_AddRefs(item));
|
||||
item = mRedoStack->Peek();
|
||||
|
||||
if (NS_FAILED(result) || !item) {
|
||||
return result;
|
||||
if (!item) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITransaction> t;
|
||||
@ -372,14 +361,8 @@ nsTransactionItem::RedoChildren(nsTransactionManager *aTxMgr)
|
||||
result = item->RedoTransaction(aTxMgr);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = mRedoStack->Pop(getter_AddRefs(item));
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = mUndoStack->Push(item);
|
||||
|
||||
// XXX: If we got an error here, I doubt we can recover!
|
||||
// XXX: Should we just push the item back on the redo stack?
|
||||
}
|
||||
item = mRedoStack->Pop();
|
||||
mUndoStack->Push(item);
|
||||
}
|
||||
|
||||
nsresult result2 = aTxMgr->DidUndoNotify(t, result);
|
||||
@ -402,7 +385,8 @@ nsTransactionItem::GetNumberOfUndoItems(PRInt32 *aNumItems)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return mUndoStack->GetSize(aNumItems);
|
||||
*aNumItems = mUndoStack->GetSize();
|
||||
return *aNumItems ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -415,7 +399,8 @@ nsTransactionItem::GetNumberOfRedoItems(PRInt32 *aNumItems)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return mRedoStack->GetSize(aNumItems);
|
||||
*aNumItems = mRedoStack->GetSize();
|
||||
return *aNumItems ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -43,14 +43,13 @@
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
class nsTransactionStack;
|
||||
class nsTransactionRedoStack;
|
||||
class nsTransactionManager;
|
||||
|
||||
class nsTransactionItem
|
||||
{
|
||||
nsCOMPtr<nsITransaction> mTransaction;
|
||||
nsTransactionStack *mUndoStack;
|
||||
nsTransactionRedoStack *mRedoStack;
|
||||
nsTransactionStack *mRedoStack;
|
||||
nsAutoRefCnt mRefCnt;
|
||||
|
||||
public:
|
||||
|
@ -75,10 +75,10 @@ NS_IMETHODIMP nsTransactionList::GetNumItems(PRInt32 *aNumItems)
|
||||
|
||||
NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
|
||||
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
if (mTxnStack)
|
||||
result = mTxnStack->GetSize(aNumItems);
|
||||
*aNumItems = mTxnStack->GetSize();
|
||||
else if (mTxnItem)
|
||||
result = mTxnItem->GetNumberOfChildren(aNumItems);
|
||||
|
||||
@ -98,10 +98,10 @@ NS_IMETHODIMP nsTransactionList::ItemIsBatch(PRInt32 aIndex, bool *aIsBatch)
|
||||
|
||||
nsRefPtr<nsTransactionItem> item;
|
||||
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
if (mTxnStack)
|
||||
result = mTxnStack->GetItem(aIndex, getter_AddRefs(item));
|
||||
item = mTxnStack->GetItem(aIndex);
|
||||
else if (mTxnItem)
|
||||
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
|
||||
|
||||
@ -125,10 +125,10 @@ NS_IMETHODIMP nsTransactionList::GetItem(PRInt32 aIndex, nsITransaction **aItem)
|
||||
|
||||
nsRefPtr<nsTransactionItem> item;
|
||||
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
if (mTxnStack)
|
||||
result = mTxnStack->GetItem(aIndex, getter_AddRefs(item));
|
||||
item = mTxnStack->GetItem(aIndex);
|
||||
else if (mTxnItem)
|
||||
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
|
||||
|
||||
@ -152,10 +152,10 @@ NS_IMETHODIMP nsTransactionList::GetNumChildrenForItem(PRInt32 aIndex, PRInt32 *
|
||||
|
||||
nsRefPtr<nsTransactionItem> item;
|
||||
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
if (mTxnStack)
|
||||
result = mTxnStack->GetItem(aIndex, getter_AddRefs(item));
|
||||
item = mTxnStack->GetItem(aIndex);
|
||||
else if (mTxnItem)
|
||||
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
|
||||
|
||||
@ -179,10 +179,10 @@ NS_IMETHODIMP nsTransactionList::GetChildListForItem(PRInt32 aIndex, nsITransact
|
||||
|
||||
nsRefPtr<nsTransactionItem> item;
|
||||
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
if (mTxnStack)
|
||||
result = mTxnStack->GetItem(aIndex, getter_AddRefs(item));
|
||||
item = mTxnStack->GetItem(aIndex);
|
||||
else if (mTxnItem)
|
||||
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
|
||||
|
||||
|
@ -48,6 +48,9 @@
|
||||
|
||||
nsTransactionManager::nsTransactionManager(PRInt32 aMaxTransactionCount)
|
||||
: mMaxTransactionCount(aMaxTransactionCount)
|
||||
, mDoStack(nsTransactionStack::FOR_UNDO)
|
||||
, mUndoStack(nsTransactionStack::FOR_UNDO)
|
||||
, mRedoStack(nsTransactionStack::FOR_REDO)
|
||||
{
|
||||
}
|
||||
|
||||
@ -120,17 +123,12 @@ NS_IMETHODIMP
|
||||
nsTransactionManager::UndoTransaction()
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsRefPtr<nsTransactionItem> tx;
|
||||
|
||||
// It is illegal to call UndoTransaction() while the transaction manager is
|
||||
// executing a transaction's DoTransaction() method! If this happens,
|
||||
// the UndoTransaction() request is ignored, and we return NS_ERROR_FAILURE.
|
||||
|
||||
result = mDoStack.Peek(getter_AddRefs(tx));
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
nsRefPtr<nsTransactionItem> tx = mDoStack.Peek();
|
||||
|
||||
if (tx) {
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -138,11 +136,7 @@ nsTransactionManager::UndoTransaction()
|
||||
|
||||
// Peek at the top of the undo stack. Don't remove the transaction
|
||||
// until it has successfully completed.
|
||||
result = mUndoStack.Peek(getter_AddRefs(tx));
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
tx = mUndoStack.Peek();
|
||||
|
||||
// Bail if there's nothing on the stack.
|
||||
if (!tx) {
|
||||
@ -172,10 +166,8 @@ nsTransactionManager::UndoTransaction()
|
||||
result = tx->UndoTransaction(this);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = mUndoStack.Pop(getter_AddRefs(tx));
|
||||
|
||||
if (NS_SUCCEEDED(result))
|
||||
result = mRedoStack.Push(tx);
|
||||
tx = mUndoStack.Pop();
|
||||
mRedoStack.Push(tx);
|
||||
}
|
||||
|
||||
nsresult result2 = DidUndoNotify(t, result);
|
||||
@ -190,17 +182,12 @@ NS_IMETHODIMP
|
||||
nsTransactionManager::RedoTransaction()
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsRefPtr<nsTransactionItem> tx;
|
||||
|
||||
// It is illegal to call RedoTransaction() while the transaction manager is
|
||||
// executing a transaction's DoTransaction() method! If this happens,
|
||||
// the RedoTransaction() request is ignored, and we return NS_ERROR_FAILURE.
|
||||
|
||||
result = mDoStack.Peek(getter_AddRefs(tx));
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
nsRefPtr<nsTransactionItem> tx = mDoStack.Peek();
|
||||
|
||||
if (tx) {
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -208,11 +195,7 @@ nsTransactionManager::RedoTransaction()
|
||||
|
||||
// Peek at the top of the redo stack. Don't remove the transaction
|
||||
// until it has successfully completed.
|
||||
result = mRedoStack.Peek(getter_AddRefs(tx));
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
tx = mRedoStack.Peek();
|
||||
|
||||
// Bail if there's nothing on the stack.
|
||||
if (!tx) {
|
||||
@ -242,10 +225,8 @@ nsTransactionManager::RedoTransaction()
|
||||
result = tx->RedoTransaction(this);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = mRedoStack.Pop(getter_AddRefs(tx));
|
||||
|
||||
if (NS_SUCCEEDED(result))
|
||||
result = mUndoStack.Push(tx);
|
||||
tx = mRedoStack.Pop();
|
||||
mUndoStack.Push(tx);
|
||||
}
|
||||
|
||||
nsresult result2 = DidRedoNotify(t, result);
|
||||
@ -307,7 +288,6 @@ nsTransactionManager::BeginBatch()
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::EndBatch()
|
||||
{
|
||||
nsRefPtr<nsTransactionItem> tx;
|
||||
nsCOMPtr<nsITransaction> ti;
|
||||
nsresult result;
|
||||
|
||||
@ -322,11 +302,7 @@ nsTransactionManager::EndBatch()
|
||||
// future when we allow users to execute a transaction when beginning
|
||||
// a batch!!!!
|
||||
|
||||
result = mDoStack.Peek(getter_AddRefs(tx));
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
nsRefPtr<nsTransactionItem> tx = mDoStack.Peek();
|
||||
|
||||
if (tx)
|
||||
tx->GetTransaction(getter_AddRefs(ti));
|
||||
@ -360,13 +336,15 @@ nsTransactionManager::EndBatch()
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::GetNumberOfUndoItems(PRInt32 *aNumItems)
|
||||
{
|
||||
return mUndoStack.GetSize(aNumItems);
|
||||
*aNumItems = mUndoStack.GetSize();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::GetNumberOfRedoItems(PRInt32 *aNumItems)
|
||||
{
|
||||
return mRedoStack.GetSize(aNumItems);
|
||||
*aNumItems = mRedoStack.GetSize();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -383,8 +361,6 @@ NS_IMETHODIMP
|
||||
nsTransactionManager::SetMaxTransactionCount(PRInt32 aMaxCount)
|
||||
{
|
||||
PRInt32 numUndoItems = 0, numRedoItems = 0, total = 0;
|
||||
nsRefPtr<nsTransactionItem> tx;
|
||||
nsresult result;
|
||||
|
||||
// It is illegal to call SetMaxTransactionCount() while the transaction
|
||||
// manager is executing a transaction's DoTransaction() method because
|
||||
@ -392,11 +368,7 @@ nsTransactionManager::SetMaxTransactionCount(PRInt32 aMaxCount)
|
||||
// SetMaxTransactionCount() request is ignored, and we return
|
||||
// NS_ERROR_FAILURE.
|
||||
|
||||
result = mDoStack.Peek(getter_AddRefs(tx));
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
nsRefPtr<nsTransactionItem> tx = mDoStack.Peek();
|
||||
|
||||
if (tx) {
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -407,20 +379,12 @@ nsTransactionManager::SetMaxTransactionCount(PRInt32 aMaxCount)
|
||||
|
||||
if (aMaxCount < 0) {
|
||||
mMaxTransactionCount = -1;
|
||||
return result;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
result = mUndoStack.GetSize(&numUndoItems);
|
||||
numUndoItems = mUndoStack.GetSize();
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = mRedoStack.GetSize(&numRedoItems);
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
numRedoItems = mRedoStack.GetSize();
|
||||
|
||||
total = numUndoItems + numRedoItems;
|
||||
|
||||
@ -430,17 +394,17 @@ nsTransactionManager::SetMaxTransactionCount(PRInt32 aMaxCount)
|
||||
|
||||
if (aMaxCount > total ) {
|
||||
mMaxTransactionCount = aMaxCount;
|
||||
return result;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Try getting rid of some transactions on the undo stack! Start at
|
||||
// the bottom of the stack and pop towards the top.
|
||||
|
||||
while (numUndoItems > 0 && (numRedoItems + numUndoItems) > aMaxCount) {
|
||||
result = mUndoStack.PopBottom(getter_AddRefs(tx));
|
||||
tx = mUndoStack.PopBottom();
|
||||
|
||||
if (NS_FAILED(result) || !tx) {
|
||||
return result;
|
||||
if (!tx) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
--numUndoItems;
|
||||
@ -450,10 +414,10 @@ nsTransactionManager::SetMaxTransactionCount(PRInt32 aMaxCount)
|
||||
// the bottom of the stack and pop towards the top.
|
||||
|
||||
while (numRedoItems > 0 && (numRedoItems + numUndoItems) > aMaxCount) {
|
||||
result = mRedoStack.PopBottom(getter_AddRefs(tx));
|
||||
tx = mRedoStack.PopBottom();
|
||||
|
||||
if (NS_FAILED(result) || !tx) {
|
||||
return result;
|
||||
if (!tx) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
--numRedoItems;
|
||||
@ -461,23 +425,22 @@ nsTransactionManager::SetMaxTransactionCount(PRInt32 aMaxCount)
|
||||
|
||||
mMaxTransactionCount = aMaxCount;
|
||||
|
||||
return result;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::PeekUndoStack(nsITransaction **aTransaction)
|
||||
{
|
||||
nsRefPtr<nsTransactionItem> tx;
|
||||
nsresult result;
|
||||
|
||||
NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
|
||||
|
||||
*aTransaction = 0;
|
||||
|
||||
result = mUndoStack.Peek(getter_AddRefs(tx));
|
||||
nsRefPtr<nsTransactionItem> tx = mUndoStack.Peek();
|
||||
|
||||
if (NS_FAILED(result) || !tx) {
|
||||
return result;
|
||||
if (!tx) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
result = tx->GetTransaction(aTransaction);
|
||||
@ -488,17 +451,16 @@ nsTransactionManager::PeekUndoStack(nsITransaction **aTransaction)
|
||||
NS_IMETHODIMP
|
||||
nsTransactionManager::PeekRedoStack(nsITransaction **aTransaction)
|
||||
{
|
||||
nsRefPtr<nsTransactionItem> tx;
|
||||
nsresult result;
|
||||
|
||||
NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
|
||||
|
||||
*aTransaction = 0;
|
||||
|
||||
result = mRedoStack.Peek(getter_AddRefs(tx));
|
||||
nsRefPtr<nsTransactionItem> tx = mRedoStack.Peek();
|
||||
|
||||
if (NS_FAILED(result) || !tx) {
|
||||
return result;
|
||||
if (!tx) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
result = tx->GetTransaction(aTransaction);
|
||||
@ -549,13 +511,15 @@ nsTransactionManager::RemoveListener(nsITransactionListener *aListener)
|
||||
nsresult
|
||||
nsTransactionManager::ClearUndoStack()
|
||||
{
|
||||
return mUndoStack.Clear();
|
||||
mUndoStack.Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionManager::ClearRedoStack()
|
||||
{
|
||||
return mRedoStack.Clear();
|
||||
mRedoStack.Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -802,16 +766,12 @@ nsTransactionManager::BeginTransaction(nsITransaction *aTransaction)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
result = mDoStack.Push(tx);
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
mDoStack.Push(tx);
|
||||
|
||||
result = tx->DoTransaction();
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
mDoStack.Pop(getter_AddRefs(tx));
|
||||
tx = mDoStack.Pop();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -822,13 +782,12 @@ nsresult
|
||||
nsTransactionManager::EndTransaction()
|
||||
{
|
||||
nsCOMPtr<nsITransaction> tint;
|
||||
nsRefPtr<nsTransactionItem> tx;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
result = mDoStack.Pop(getter_AddRefs(tx));
|
||||
nsRefPtr<nsTransactionItem> tx = mDoStack.Pop();
|
||||
|
||||
if (NS_FAILED(result) || !tx)
|
||||
return result;
|
||||
if (!tx)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
result = tx->GetTransaction(getter_AddRefs(tint));
|
||||
|
||||
@ -864,13 +823,11 @@ nsTransactionManager::EndTransaction()
|
||||
return result;
|
||||
}
|
||||
|
||||
nsRefPtr<nsTransactionItem> top;
|
||||
|
||||
// Check if there is a transaction on the do stack. If there is,
|
||||
// the current transaction is a "sub" transaction, and should
|
||||
// be added to the transaction at the top of the do stack.
|
||||
|
||||
result = mDoStack.Peek(getter_AddRefs(top));
|
||||
nsRefPtr<nsTransactionItem> top = mDoStack.Peek();
|
||||
if (top) {
|
||||
result = top->AddChild(tx);
|
||||
|
||||
@ -890,8 +847,7 @@ nsTransactionManager::EndTransaction()
|
||||
// Check if we can coalesce this transaction with the one at the top
|
||||
// of the undo stack.
|
||||
|
||||
top = 0;
|
||||
result = mUndoStack.Peek(getter_AddRefs(top));
|
||||
top = mUndoStack.Peek();
|
||||
|
||||
if (tint && top) {
|
||||
bool didMerge = false;
|
||||
@ -929,27 +885,16 @@ nsTransactionManager::EndTransaction()
|
||||
// Check to see if we've hit the max level of undo. If so,
|
||||
// pop the bottom transaction off the undo stack and release it!
|
||||
|
||||
PRInt32 sz = 0;
|
||||
|
||||
result = mUndoStack.GetSize(&sz);
|
||||
PRInt32 sz = mUndoStack.GetSize();
|
||||
|
||||
if (mMaxTransactionCount > 0 && sz >= mMaxTransactionCount) {
|
||||
nsRefPtr<nsTransactionItem> overflow;
|
||||
|
||||
result = mUndoStack.PopBottom(getter_AddRefs(overflow));
|
||||
|
||||
// XXX: What do we do in the case where this fails?
|
||||
nsRefPtr<nsTransactionItem> overflow = mUndoStack.PopBottom();
|
||||
}
|
||||
|
||||
// Push the transaction on the undo stack:
|
||||
|
||||
result = mUndoStack.Push(tx);
|
||||
mUndoStack.Push(tx);
|
||||
|
||||
if (NS_FAILED(result)) {
|
||||
// XXX: What do we do in the case where a clear fails?
|
||||
// Remove the transaction from the stack, and release it?
|
||||
}
|
||||
|
||||
return result;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,6 @@ class nsITransaction;
|
||||
class nsITransactionListener;
|
||||
class nsTransactionItem;
|
||||
class nsTransactionStack;
|
||||
class nsTransactionRedoStack;
|
||||
|
||||
/** implementation of a transaction manager object.
|
||||
*
|
||||
@ -61,7 +60,7 @@ private:
|
||||
PRInt32 mMaxTransactionCount;
|
||||
nsTransactionStack mDoStack;
|
||||
nsTransactionStack mUndoStack;
|
||||
nsTransactionRedoStack mRedoStack;
|
||||
nsTransactionStack mRedoStack;
|
||||
nsCOMArray<nsITransactionListener> mListeners;
|
||||
|
||||
public:
|
||||
|
@ -41,115 +41,82 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "mozilla/Util.h"
|
||||
|
||||
nsTransactionStack::nsTransactionStack()
|
||||
nsTransactionStack::nsTransactionStack(nsTransactionStack::Type aType)
|
||||
: mQue(0)
|
||||
, mType(aType)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
nsTransactionStack::~nsTransactionStack()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
nsresult
|
||||
void
|
||||
nsTransactionStack::Push(nsTransactionItem *aTransaction)
|
||||
{
|
||||
NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
|
||||
if (!aTransaction) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* nsDeque's Push() method adds new items at the back
|
||||
* of the deque.
|
||||
*/
|
||||
NS_ADDREF(aTransaction);
|
||||
mQue.Push(aTransaction);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionStack::Pop(nsTransactionItem **aTransaction)
|
||||
already_AddRefed<nsTransactionItem>
|
||||
nsTransactionStack::Pop()
|
||||
{
|
||||
NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
|
||||
|
||||
/* nsDeque is a FIFO, so the top of our stack is actually
|
||||
* the back of the deque.
|
||||
*/
|
||||
*aTransaction = (nsTransactionItem *)mQue.Pop();
|
||||
|
||||
return NS_OK;
|
||||
return static_cast<nsTransactionItem*> (mQue.Pop());
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionStack::PopBottom(nsTransactionItem **aTransaction)
|
||||
already_AddRefed<nsTransactionItem>
|
||||
nsTransactionStack::PopBottom()
|
||||
{
|
||||
NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
|
||||
|
||||
/* nsDeque is a FIFO, so the bottom of our stack is actually
|
||||
* the front of the deque.
|
||||
*/
|
||||
*aTransaction = (nsTransactionItem *)mQue.PopFront();
|
||||
|
||||
return NS_OK;
|
||||
return static_cast<nsTransactionItem*> (mQue.PopFront());
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionStack::Peek(nsTransactionItem **aTransaction)
|
||||
already_AddRefed<nsTransactionItem>
|
||||
nsTransactionStack::Peek()
|
||||
{
|
||||
NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (!mQue.GetSize()) {
|
||||
*aTransaction = 0;
|
||||
return NS_OK;
|
||||
nsTransactionItem* transaction = nsnull;
|
||||
if (mQue.GetSize()) {
|
||||
NS_IF_ADDREF(transaction = static_cast<nsTransactionItem*>(mQue.Last()));
|
||||
}
|
||||
|
||||
NS_IF_ADDREF(*aTransaction = static_cast<nsTransactionItem*>(mQue.Last()));
|
||||
|
||||
return NS_OK;
|
||||
return transaction;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionStack::GetItem(PRInt32 aIndex, nsTransactionItem **aTransaction)
|
||||
already_AddRefed<nsTransactionItem>
|
||||
nsTransactionStack::GetItem(PRInt32 aIndex)
|
||||
{
|
||||
NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
|
||||
nsTransactionItem* transaction = nsnull;
|
||||
if (aIndex >= 0 && aIndex < mQue.GetSize()) {
|
||||
NS_IF_ADDREF(transaction =
|
||||
static_cast<nsTransactionItem*>(mQue.ObjectAt(aIndex)));
|
||||
}
|
||||
|
||||
if (aIndex < 0 || aIndex >= mQue.GetSize())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_IF_ADDREF(*aTransaction =
|
||||
static_cast<nsTransactionItem*>(mQue.ObjectAt(aIndex)));
|
||||
|
||||
return NS_OK;
|
||||
return transaction;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionStack::Clear(void)
|
||||
void
|
||||
nsTransactionStack::Clear()
|
||||
{
|
||||
nsRefPtr<nsTransactionItem> tx;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
/* Pop all transactions off the stack and release them. */
|
||||
|
||||
result = Pop(getter_AddRefs(tx));
|
||||
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
|
||||
while (tx) {
|
||||
result = Pop(getter_AddRefs(tx));
|
||||
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionStack::GetSize(PRInt32 *aStackSize)
|
||||
{
|
||||
NS_ENSURE_TRUE(aStackSize, NS_ERROR_NULL_POINTER);
|
||||
|
||||
*aStackSize = mQue.GetSize();
|
||||
|
||||
return NS_OK;
|
||||
do {
|
||||
tx = mType == FOR_UNDO ? Pop() : PopBottom();
|
||||
} while (tx);
|
||||
}
|
||||
|
||||
void
|
||||
@ -164,32 +131,3 @@ nsTransactionStack::DoTraverse(nsCycleCollectionTraversalCallback &cb)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsTransactionRedoStack::~nsTransactionRedoStack()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTransactionRedoStack::Clear(void)
|
||||
{
|
||||
nsRefPtr<nsTransactionItem> tx;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
/* When clearing a Redo stack, we have to clear from the
|
||||
* bottom of the stack towards the top!
|
||||
*/
|
||||
|
||||
result = PopBottom(getter_AddRefs(tx));
|
||||
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
|
||||
while (tx) {
|
||||
result = PopBottom(getter_AddRefs(tx));
|
||||
|
||||
NS_ENSURE_SUCCESS(result, result);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -39,36 +39,32 @@
|
||||
#define nsTransactionStack_h__
|
||||
|
||||
#include "nsDeque.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsTransactionItem;
|
||||
|
||||
class nsTransactionStack
|
||||
{
|
||||
nsDeque mQue;
|
||||
|
||||
public:
|
||||
enum Type { FOR_UNDO, FOR_REDO };
|
||||
|
||||
nsTransactionStack();
|
||||
virtual ~nsTransactionStack();
|
||||
explicit nsTransactionStack(Type aType);
|
||||
~nsTransactionStack();
|
||||
|
||||
virtual nsresult Push(nsTransactionItem *aTransactionItem);
|
||||
virtual nsresult Pop(nsTransactionItem **aTransactionItem);
|
||||
virtual nsresult PopBottom(nsTransactionItem **aTransactionItem);
|
||||
virtual nsresult Peek(nsTransactionItem **aTransactionItem);
|
||||
virtual nsresult GetItem(PRInt32 aIndex, nsTransactionItem **aTransactionItem);
|
||||
virtual nsresult Clear(void);
|
||||
virtual nsresult GetSize(PRInt32 *aStackSize);
|
||||
void Push(nsTransactionItem *aTransactionItem);
|
||||
already_AddRefed<nsTransactionItem> Pop();
|
||||
already_AddRefed<nsTransactionItem> PopBottom();
|
||||
already_AddRefed<nsTransactionItem> Peek();
|
||||
already_AddRefed<nsTransactionItem> GetItem(PRInt32 aIndex);
|
||||
void Clear();
|
||||
PRInt32 GetSize() { return mQue.GetSize(); }
|
||||
|
||||
void DoUnlink() { Clear(); }
|
||||
void DoTraverse(nsCycleCollectionTraversalCallback &cb);
|
||||
};
|
||||
|
||||
class nsTransactionRedoStack: public nsTransactionStack
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~nsTransactionRedoStack();
|
||||
virtual nsresult Clear(void);
|
||||
private:
|
||||
nsDeque mQue;
|
||||
const Type mType;
|
||||
};
|
||||
|
||||
#endif // nsTransactionStack_h__
|
||||
|
Loading…
Reference in New Issue
Block a user