r=kin; Added in ctor/dtor counts

This commit is contained in:
kipp%netscape.com 1999-10-07 20:45:56 +00:00
parent 59df6ba2b7
commit 94df0dc557
4 changed files with 102 additions and 56 deletions

View File

@ -27,15 +27,19 @@ static NS_DEFINE_IID(kITransactionIID, NS_ITRANSACTION_IID);
NS_IMPL_ADDREF(EditTxn)
NS_IMPL_RELEASE(EditTxn)
MOZ_DECL_CTOR_COUNTER(EditTxn);
// note that aEditor is not refcounted
EditTxn::EditTxn()
: mTransactionID(-1)
{
MOZ_COUNT_CTOR(EditTxn);
NS_INIT_REFCNT();
}
EditTxn::~EditTxn()
{
MOZ_COUNT_DTOR(EditTxn);
}
NS_IMETHODIMP EditTxn::Do(void)

View File

@ -137,6 +137,8 @@ static const PRBool gNoisy = PR_FALSE;
PRInt32 nsEditor::gInstanceCount = 0;
MOZ_DECL_CTOR_COUNTER(nsEditor);
//class implementations are in order they are declared in nsEditor.h
@ -144,16 +146,18 @@ nsEditor::nsEditor()
: mPresShellWeak(nsnull)
, mViewManager(nsnull)
, mUpdateCount(0)
, mActionListeners(nsnull)
, mDocDirtyState(-1)
, mDocWeak(nsnull)
, mPlaceHolderTxn(nsnull)
, mPlaceHolderName(nsnull)
, mPlaceHolderBatch(0)
, mTxnStartNode(nsnull)
, mTxnStartOffset(0)
, mActionListeners(nsnull)
, mDocDirtyState(-1)
, mDocWeak(nsnull)
{
MOZ_COUNT_CTOR(nsEditor);
//initialize member variables here
NS_INIT_REFCNT();
PR_EnterMonitor(GetEditorMonitor());
@ -163,6 +167,8 @@ nsEditor::nsEditor()
nsEditor::~nsEditor()
{
MOZ_COUNT_DTOR(nsEditor);
// not sure if this needs to be called earlier.
NotifyDocumentListeners(eDocumentToBeDestroyed);
@ -353,9 +359,10 @@ nsEditor::Do(nsITransaction *aTxn)
{
// it's pretty darn amazing how many different types of pointers
// this transcation goes through here. I bet this is a record.
EditTxn *editTxn;
nsCOMPtr<EditTxn> editTxn;
nsCOMPtr<nsIAbsorbingTransaction> plcTxn;
result = TransactionFactory::GetNewTransaction(PlaceholderTxn::GetCID(), &editTxn);
result = TransactionFactory::GetNewTransaction(PlaceholderTxn::GetCID(),
getter_AddRefs(editTxn));
if (NS_FAILED(result)) { return result; }
if (!editTxn) { return NS_ERROR_NULL_POINTER; }
editTxn->QueryInterface(nsIAbsorbingTransaction::GetIID(), getter_AddRefs(plcTxn));
@ -368,6 +375,7 @@ nsEditor::Do(nsITransaction *aTxn)
// we will recurse, but will not hit this case in the nested call
nsCOMPtr<nsITransaction> theTxn = do_QueryInterface(plcTxn);
nsITransaction* txn = theTxn;
// we want to escape from this routine with a positive refcount
txn->AddRef();
Do(txn);
@ -844,8 +852,9 @@ nsEditor::GetProperties(nsVoidArray *aPropList)
NS_IMETHODIMP
nsEditor::SetAttribute(nsIDOMElement *aElement, const nsString& aAttribute, const nsString& aValue)
{
ChangeAttributeTxn *txn;
nsresult result = CreateTxnForSetAttribute(aElement, aAttribute, aValue, &txn);
nsCOMPtr<ChangeAttributeTxn> txn;
nsresult result = CreateTxnForSetAttribute(aElement, aAttribute, aValue,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = Do(txn);
}
@ -877,8 +886,9 @@ nsEditor::GetAttributeValue(nsIDOMElement *aElement,
NS_IMETHODIMP
nsEditor::RemoveAttribute(nsIDOMElement *aElement, const nsString& aAttribute)
{
ChangeAttributeTxn *txn;
nsresult result = CreateTxnForRemoveAttribute(aElement, aAttribute, &txn);
nsCOMPtr<ChangeAttributeTxn> txn;
nsresult result = CreateTxnForRemoveAttribute(aElement, aAttribute,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = Do(txn);
}
@ -891,8 +901,9 @@ NS_IMETHODIMP nsEditor::CreateNode(const nsString& aTag,
PRInt32 aPosition,
nsIDOMNode ** aNewNode)
{
CreateElementTxn *txn;
nsresult result = CreateTxnForCreateElement(aTag, aParent, aPosition, &txn);
nsCOMPtr<CreateElementTxn> txn;
nsresult result = CreateTxnForCreateElement(aTag, aParent, aPosition,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result))
{
result = Do(txn);
@ -1004,8 +1015,9 @@ nsEditor::InsertNoneditableTextNode(nsIDOMNode* parent, PRInt32 offset,
// Can't call CreateNode, because that will call us recursively.
// So duplicate what it does:
CreateElementTxn *txn;
res = CreateTxnForCreateElement(textNodeTag, parent, offset, &txn);
nsCOMPtr<CreateElementTxn> txn;
res = CreateTxnForCreateElement(textNodeTag, parent, offset,
getter_AddRefs(txn));
if (NS_FAILED(res))
return res;
@ -1137,8 +1149,8 @@ NS_IMETHODIMP nsEditor::DeleteNode(nsIDOMNode * aElement)
}
}
DeleteElementTxn *txn;
nsresult result = CreateTxnForDeleteElement(aElement, &txn);
nsCOMPtr<DeleteElementTxn> txn;
nsresult result = CreateTxnForDeleteElement(aElement, getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = Do(txn);
}
@ -1599,14 +1611,18 @@ nsresult nsEditor::GetTextNodeTag(nsString& aOutString)
NS_IMETHODIMP nsEditor::InsertTextImpl(const nsString& aStringToInsert)
{
EditAggregateTxn *aggTxn = nsnull;
nsCOMPtr<EditAggregateTxn> aggTxn;
// Create the "delete current selection" txn
nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName, &aggTxn);
if ((NS_FAILED(result)) || (nsnull==aggTxn)) {
nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName,
getter_AddRefs(aggTxn));
if (NS_FAILED(result) || !aggTxn) {
return NS_ERROR_OUT_OF_MEMORY;
}
InsertTextTxn *txn;
result = CreateTxnForInsertText(aStringToInsert, nsnull, &txn); // insert at the current selection
// insert at the current selection
nsCOMPtr<InsertTextTxn> txn;
result = CreateTxnForInsertText(aStringToInsert, nsnull,
getter_AddRefs(txn));
if ((NS_SUCCEEDED(result)) && txn) {
BeginUpdateViewBatch();
// aggTxn->AppendChild(txn);
@ -1981,11 +1997,12 @@ NS_IMETHODIMP nsEditor::DoInitialInsert(const nsString & aStringToInsert)
{ // now we've got the body tag.
// create transaction to insert the text node,
// and create a transaction to insert the text
CreateElementTxn *txn;
nsCOMPtr<CreateElementTxn> txn;
nsAutoString textNodeTag;
result = GetTextNodeTag(textNodeTag);
if (NS_FAILED(result)) { return result; }
result = CreateTxnForCreateElement(textNodeTag, node, 0, &txn);
result = CreateTxnForCreateElement(textNodeTag, node, 0,
getter_AddRefs(txn));
if ((NS_SUCCEEDED(result)) && txn)
{
result = Do(txn);
@ -2020,8 +2037,9 @@ NS_IMETHODIMP nsEditor::DeleteText(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
PRUint32 aLength)
{
DeleteTextTxn *txn;
nsresult result = CreateTxnForDeleteText(aElement, aOffset, aLength, &txn);
nsCOMPtr<DeleteTextTxn> txn;
nsresult result = CreateTxnForDeleteText(aElement, aOffset, aLength,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = Do(txn);
// HACKForceRedraw();
@ -3323,11 +3341,12 @@ NS_IMETHODIMP nsEditor::DoInitialInputMethodInsert(const nsString & aStringToIns
{ // now we've got the body tag.
// create transaction to insert the text node,
// and create a transaction to insert the text
CreateElementTxn *txn;
nsCOMPtr<CreateElementTxn> txn;
nsAutoString textNodeTag;
result = GetTextNodeTag(textNodeTag);
if (NS_FAILED(result)) { return result; }
result = CreateTxnForCreateElement(textNodeTag, node, 0, &txn);
result = CreateTxnForCreateElement(textNodeTag, node, 0,
getter_AddRefs(txn));
if ((NS_SUCCEEDED(result)) && txn)
{
result = Do(txn);
@ -4090,8 +4109,8 @@ nsEditor::DeleteSelectionImpl(ESelectionCollapseDirection aAction)
{
nsresult result;
EditAggregateTxn *txn;
result = CreateTxnForDeleteSelection(aAction, &txn);
nsCOMPtr<EditAggregateTxn> txn;
result = CreateTxnForDeleteSelection(aAction, getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = Do(txn);
}

View File

@ -27,15 +27,19 @@ static NS_DEFINE_IID(kITransactionIID, NS_ITRANSACTION_IID);
NS_IMPL_ADDREF(EditTxn)
NS_IMPL_RELEASE(EditTxn)
MOZ_DECL_CTOR_COUNTER(EditTxn);
// note that aEditor is not refcounted
EditTxn::EditTxn()
: mTransactionID(-1)
{
MOZ_COUNT_CTOR(EditTxn);
NS_INIT_REFCNT();
}
EditTxn::~EditTxn()
{
MOZ_COUNT_DTOR(EditTxn);
}
NS_IMETHODIMP EditTxn::Do(void)

View File

@ -137,6 +137,8 @@ static const PRBool gNoisy = PR_FALSE;
PRInt32 nsEditor::gInstanceCount = 0;
MOZ_DECL_CTOR_COUNTER(nsEditor);
//class implementations are in order they are declared in nsEditor.h
@ -144,16 +146,18 @@ nsEditor::nsEditor()
: mPresShellWeak(nsnull)
, mViewManager(nsnull)
, mUpdateCount(0)
, mActionListeners(nsnull)
, mDocDirtyState(-1)
, mDocWeak(nsnull)
, mPlaceHolderTxn(nsnull)
, mPlaceHolderName(nsnull)
, mPlaceHolderBatch(0)
, mTxnStartNode(nsnull)
, mTxnStartOffset(0)
, mActionListeners(nsnull)
, mDocDirtyState(-1)
, mDocWeak(nsnull)
{
MOZ_COUNT_CTOR(nsEditor);
//initialize member variables here
NS_INIT_REFCNT();
PR_EnterMonitor(GetEditorMonitor());
@ -163,6 +167,8 @@ nsEditor::nsEditor()
nsEditor::~nsEditor()
{
MOZ_COUNT_DTOR(nsEditor);
// not sure if this needs to be called earlier.
NotifyDocumentListeners(eDocumentToBeDestroyed);
@ -353,9 +359,10 @@ nsEditor::Do(nsITransaction *aTxn)
{
// it's pretty darn amazing how many different types of pointers
// this transcation goes through here. I bet this is a record.
EditTxn *editTxn;
nsCOMPtr<EditTxn> editTxn;
nsCOMPtr<nsIAbsorbingTransaction> plcTxn;
result = TransactionFactory::GetNewTransaction(PlaceholderTxn::GetCID(), &editTxn);
result = TransactionFactory::GetNewTransaction(PlaceholderTxn::GetCID(),
getter_AddRefs(editTxn));
if (NS_FAILED(result)) { return result; }
if (!editTxn) { return NS_ERROR_NULL_POINTER; }
editTxn->QueryInterface(nsIAbsorbingTransaction::GetIID(), getter_AddRefs(plcTxn));
@ -368,6 +375,7 @@ nsEditor::Do(nsITransaction *aTxn)
// we will recurse, but will not hit this case in the nested call
nsCOMPtr<nsITransaction> theTxn = do_QueryInterface(plcTxn);
nsITransaction* txn = theTxn;
// we want to escape from this routine with a positive refcount
txn->AddRef();
Do(txn);
@ -844,8 +852,9 @@ nsEditor::GetProperties(nsVoidArray *aPropList)
NS_IMETHODIMP
nsEditor::SetAttribute(nsIDOMElement *aElement, const nsString& aAttribute, const nsString& aValue)
{
ChangeAttributeTxn *txn;
nsresult result = CreateTxnForSetAttribute(aElement, aAttribute, aValue, &txn);
nsCOMPtr<ChangeAttributeTxn> txn;
nsresult result = CreateTxnForSetAttribute(aElement, aAttribute, aValue,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = Do(txn);
}
@ -877,8 +886,9 @@ nsEditor::GetAttributeValue(nsIDOMElement *aElement,
NS_IMETHODIMP
nsEditor::RemoveAttribute(nsIDOMElement *aElement, const nsString& aAttribute)
{
ChangeAttributeTxn *txn;
nsresult result = CreateTxnForRemoveAttribute(aElement, aAttribute, &txn);
nsCOMPtr<ChangeAttributeTxn> txn;
nsresult result = CreateTxnForRemoveAttribute(aElement, aAttribute,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = Do(txn);
}
@ -891,8 +901,9 @@ NS_IMETHODIMP nsEditor::CreateNode(const nsString& aTag,
PRInt32 aPosition,
nsIDOMNode ** aNewNode)
{
CreateElementTxn *txn;
nsresult result = CreateTxnForCreateElement(aTag, aParent, aPosition, &txn);
nsCOMPtr<CreateElementTxn> txn;
nsresult result = CreateTxnForCreateElement(aTag, aParent, aPosition,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result))
{
result = Do(txn);
@ -1004,8 +1015,9 @@ nsEditor::InsertNoneditableTextNode(nsIDOMNode* parent, PRInt32 offset,
// Can't call CreateNode, because that will call us recursively.
// So duplicate what it does:
CreateElementTxn *txn;
res = CreateTxnForCreateElement(textNodeTag, parent, offset, &txn);
nsCOMPtr<CreateElementTxn> txn;
res = CreateTxnForCreateElement(textNodeTag, parent, offset,
getter_AddRefs(txn));
if (NS_FAILED(res))
return res;
@ -1137,8 +1149,8 @@ NS_IMETHODIMP nsEditor::DeleteNode(nsIDOMNode * aElement)
}
}
DeleteElementTxn *txn;
nsresult result = CreateTxnForDeleteElement(aElement, &txn);
nsCOMPtr<DeleteElementTxn> txn;
nsresult result = CreateTxnForDeleteElement(aElement, getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = Do(txn);
}
@ -1599,14 +1611,18 @@ nsresult nsEditor::GetTextNodeTag(nsString& aOutString)
NS_IMETHODIMP nsEditor::InsertTextImpl(const nsString& aStringToInsert)
{
EditAggregateTxn *aggTxn = nsnull;
nsCOMPtr<EditAggregateTxn> aggTxn;
// Create the "delete current selection" txn
nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName, &aggTxn);
if ((NS_FAILED(result)) || (nsnull==aggTxn)) {
nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName,
getter_AddRefs(aggTxn));
if (NS_FAILED(result) || !aggTxn) {
return NS_ERROR_OUT_OF_MEMORY;
}
InsertTextTxn *txn;
result = CreateTxnForInsertText(aStringToInsert, nsnull, &txn); // insert at the current selection
// insert at the current selection
nsCOMPtr<InsertTextTxn> txn;
result = CreateTxnForInsertText(aStringToInsert, nsnull,
getter_AddRefs(txn));
if ((NS_SUCCEEDED(result)) && txn) {
BeginUpdateViewBatch();
// aggTxn->AppendChild(txn);
@ -1981,11 +1997,12 @@ NS_IMETHODIMP nsEditor::DoInitialInsert(const nsString & aStringToInsert)
{ // now we've got the body tag.
// create transaction to insert the text node,
// and create a transaction to insert the text
CreateElementTxn *txn;
nsCOMPtr<CreateElementTxn> txn;
nsAutoString textNodeTag;
result = GetTextNodeTag(textNodeTag);
if (NS_FAILED(result)) { return result; }
result = CreateTxnForCreateElement(textNodeTag, node, 0, &txn);
result = CreateTxnForCreateElement(textNodeTag, node, 0,
getter_AddRefs(txn));
if ((NS_SUCCEEDED(result)) && txn)
{
result = Do(txn);
@ -2020,8 +2037,9 @@ NS_IMETHODIMP nsEditor::DeleteText(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
PRUint32 aLength)
{
DeleteTextTxn *txn;
nsresult result = CreateTxnForDeleteText(aElement, aOffset, aLength, &txn);
nsCOMPtr<DeleteTextTxn> txn;
nsresult result = CreateTxnForDeleteText(aElement, aOffset, aLength,
getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = Do(txn);
// HACKForceRedraw();
@ -3323,11 +3341,12 @@ NS_IMETHODIMP nsEditor::DoInitialInputMethodInsert(const nsString & aStringToIns
{ // now we've got the body tag.
// create transaction to insert the text node,
// and create a transaction to insert the text
CreateElementTxn *txn;
nsCOMPtr<CreateElementTxn> txn;
nsAutoString textNodeTag;
result = GetTextNodeTag(textNodeTag);
if (NS_FAILED(result)) { return result; }
result = CreateTxnForCreateElement(textNodeTag, node, 0, &txn);
result = CreateTxnForCreateElement(textNodeTag, node, 0,
getter_AddRefs(txn));
if ((NS_SUCCEEDED(result)) && txn)
{
result = Do(txn);
@ -4090,8 +4109,8 @@ nsEditor::DeleteSelectionImpl(ESelectionCollapseDirection aAction)
{
nsresult result;
EditAggregateTxn *txn;
result = CreateTxnForDeleteSelection(aAction, &txn);
nsCOMPtr<EditAggregateTxn> txn;
result = CreateTxnForDeleteSelection(aAction, getter_AddRefs(txn));
if (NS_SUCCEEDED(result)) {
result = Do(txn);
}