From 06356ad73a573e64d27251d82b57876cea2d7250 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Fri, 5 Mar 1999 21:05:35 +0000 Subject: [PATCH] Changed editor classes to inherited model. Fixed lots of destructor warnings. --- editor/base/ChangeAttributeTxn.cpp | 4 + editor/base/ChangeAttributeTxn.h | 1 + editor/base/DeleteRangeTxn.cpp | 4 +- editor/base/DeleteTableCellTxn.cpp | 4 + editor/base/DeleteTableCellTxn.h | 3 +- editor/base/DeleteTableColumnTxn.cpp | 4 + editor/base/DeleteTableColumnTxn.h | 1 + editor/base/DeleteTableRowTxn.cpp | 4 + editor/base/DeleteTableRowTxn.h | 1 + editor/base/DeleteTableTxn.cpp | 4 + editor/base/DeleteTableTxn.h | 3 +- editor/base/DeleteTextTxn.cpp | 4 + editor/base/DeleteTextTxn.h | 3 +- editor/base/EditTable.cpp | 178 ++--- editor/base/EditTxn.cpp | 4 + editor/base/EditTxn.h | 2 + editor/base/InsertTableCellTxn.cpp | 4 + editor/base/InsertTableCellTxn.h | 1 + editor/base/InsertTableColumnTxn.cpp | 4 + editor/base/InsertTableColumnTxn.h | 1 + editor/base/InsertTableRowTxn.cpp | 4 + editor/base/InsertTableRowTxn.h | 1 + editor/base/InsertTableTxn.cpp | 4 + editor/base/InsertTableTxn.h | 1 + editor/base/InsertTextTxn.cpp | 4 + editor/base/InsertTextTxn.h | 1 + editor/base/JoinTableCellsTxn.cpp | 4 + editor/base/JoinTableCellsTxn.h | 2 +- editor/base/nsEditor.cpp | 24 +- editor/base/nsEditor.h | 18 +- editor/base/nsHTMLEditFactory.cpp | 6 +- editor/base/nsHTMLEditor.cpp | 302 ++------ editor/base/nsHTMLEditor.h | 22 +- editor/base/nsTextEditFactory.cpp | 7 +- editor/base/nsTextEditor.cpp | 695 ++++++++----------- editor/base/nsTextEditor.h | 21 +- editor/libeditor/base/ChangeAttributeTxn.cpp | 4 + editor/libeditor/base/ChangeAttributeTxn.h | 1 + editor/libeditor/base/DeleteRangeTxn.cpp | 4 +- editor/libeditor/base/DeleteTextTxn.cpp | 4 + editor/libeditor/base/DeleteTextTxn.h | 3 +- editor/libeditor/base/EditTxn.cpp | 4 + editor/libeditor/base/EditTxn.h | 2 + editor/libeditor/base/InsertTextTxn.cpp | 4 + editor/libeditor/base/InsertTextTxn.h | 1 + editor/libeditor/base/nsEditor.cpp | 24 +- editor/libeditor/base/nsEditor.h | 18 +- editor/libeditor/html/nsHTMLEditor.cpp | 302 ++------ editor/libeditor/html/nsHTMLEditor.h | 22 +- editor/public/nsIEditor.h | 14 +- editor/public/nsIHTMLEditor.h | 4 +- editor/public/nsITextEditor.h | 4 +- 52 files changed, 629 insertions(+), 1136 deletions(-) diff --git a/editor/base/ChangeAttributeTxn.cpp b/editor/base/ChangeAttributeTxn.cpp index 2db140980ab..8f37b19645b 100644 --- a/editor/base/ChangeAttributeTxn.cpp +++ b/editor/base/ChangeAttributeTxn.cpp @@ -25,6 +25,10 @@ ChangeAttributeTxn::ChangeAttributeTxn() { } +ChangeAttributeTxn::~ChangeAttributeTxn() +{ +} + NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor, nsIDOMElement *aElement, const nsString& aAttribute, diff --git a/editor/base/ChangeAttributeTxn.h b/editor/base/ChangeAttributeTxn.h index 43cc18f534c..c97cf759df1 100644 --- a/editor/base/ChangeAttributeTxn.h +++ b/editor/base/ChangeAttributeTxn.h @@ -36,6 +36,7 @@ class ChangeAttributeTxn : public EditTxn { public: + virtual ~ChangeAttributeTxn(); /** Initialize the transaction. * @param aEditor the object providing core editing operations diff --git a/editor/base/DeleteRangeTxn.cpp b/editor/base/DeleteRangeTxn.cpp index 5c7bb8e8119..3661b2c5a09 100644 --- a/editor/base/DeleteRangeTxn.cpp +++ b/editor/base/DeleteRangeTxn.cpp @@ -75,7 +75,7 @@ NS_IMETHODIMP DeleteRangeTxn::Init(nsIEditor *aEditor, nsIDOMRange *aRange) NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad start child list"); children->GetLength(&count); } - NS_ASSERTION(mStartOffset<=count, "bad start offset"); + NS_ASSERTION(mStartOffset<=(PRInt32)count, "bad start offset"); textNode = do_QueryInterface(mEndParent, &result); if (textNode) @@ -87,7 +87,7 @@ NS_IMETHODIMP DeleteRangeTxn::Init(nsIEditor *aEditor, nsIDOMRange *aRange) NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad end child list"); children->GetLength(&count); } - NS_ASSERTION(mEndOffset<=count, "bad end offset"); + NS_ASSERTION(mEndOffset<=(PRInt32)count, "bad end offset"); if (gNoisy) printf ("DeleteRange: %d of %p to %d of %p\n", mStartOffset, (void *)mStartParent, mEndOffset, (void *)mEndParent); diff --git a/editor/base/DeleteTableCellTxn.cpp b/editor/base/DeleteTableCellTxn.cpp index 6503e45cfa6..fb855686998 100644 --- a/editor/base/DeleteTableCellTxn.cpp +++ b/editor/base/DeleteTableCellTxn.cpp @@ -40,6 +40,10 @@ DeleteTableCellTxn::DeleteTableCellTxn() { } +DeleteTableCellTxn::~DeleteTableCellTxn() +{ +} + NS_IMETHODIMP DeleteTableCellTxn::Init(nsIDOMCharacterData *aElement, nsIDOMNode *aNode, nsIPresShell* aPresShell) diff --git a/editor/base/DeleteTableCellTxn.h b/editor/base/DeleteTableCellTxn.h index 8d07de7b93e..4acf90b96fa 100644 --- a/editor/base/DeleteTableCellTxn.h +++ b/editor/base/DeleteTableCellTxn.h @@ -58,7 +58,8 @@ private: DeleteTableCellTxn(); public: - + virtual ~DeleteTableCellTxn(); + NS_IMETHOD Do(void); NS_IMETHOD Undo(void); diff --git a/editor/base/DeleteTableColumnTxn.cpp b/editor/base/DeleteTableColumnTxn.cpp index 2d835051b3d..1a0db852640 100644 --- a/editor/base/DeleteTableColumnTxn.cpp +++ b/editor/base/DeleteTableColumnTxn.cpp @@ -40,6 +40,10 @@ DeleteTableColumnTxn::DeleteTableColumnTxn() { } +DeleteTableColumnTxn::~DeleteTableColumnTxn() +{ +} + NS_IMETHODIMP DeleteTableColumnTxn::Init(nsIDOMCharacterData *aElement, nsIDOMNode *aNode, nsIPresShell* aPresShell) diff --git a/editor/base/DeleteTableColumnTxn.h b/editor/base/DeleteTableColumnTxn.h index 5ee91e8f9a7..405379ad152 100644 --- a/editor/base/DeleteTableColumnTxn.h +++ b/editor/base/DeleteTableColumnTxn.h @@ -58,6 +58,7 @@ private: DeleteTableColumnTxn(); public: + virtual ~DeleteTableColumnTxn(); NS_IMETHOD Do(void); diff --git a/editor/base/DeleteTableRowTxn.cpp b/editor/base/DeleteTableRowTxn.cpp index 200058b165d..539f22b06fb 100644 --- a/editor/base/DeleteTableRowTxn.cpp +++ b/editor/base/DeleteTableRowTxn.cpp @@ -40,6 +40,10 @@ DeleteTableRowTxn::DeleteTableRowTxn() { } +DeleteTableRowTxn::~DeleteTableRowTxn() +{ +} + NS_IMETHODIMP DeleteTableRowTxn::Init(nsIDOMCharacterData *aElement, nsIDOMNode *aNode, nsIPresShell* aPresShell) diff --git a/editor/base/DeleteTableRowTxn.h b/editor/base/DeleteTableRowTxn.h index 6afd3f95de8..517341ea5e4 100644 --- a/editor/base/DeleteTableRowTxn.h +++ b/editor/base/DeleteTableRowTxn.h @@ -59,6 +59,7 @@ private: DeleteTableRowTxn(); public: + virtual ~DeleteTableRowTxn(); NS_IMETHOD Do(void); diff --git a/editor/base/DeleteTableTxn.cpp b/editor/base/DeleteTableTxn.cpp index 88e86629237..f2cd8d1ff19 100644 --- a/editor/base/DeleteTableTxn.cpp +++ b/editor/base/DeleteTableTxn.cpp @@ -40,6 +40,10 @@ DeleteTableTxn::DeleteTableTxn() { } +DeleteTableTxn::~DeleteTableTxn() +{ +} + NS_IMETHODIMP DeleteTableTxn::Init(nsIDOMCharacterData *aElement, nsIDOMNode *aNode, nsIPresShell* aPresShell) diff --git a/editor/base/DeleteTableTxn.h b/editor/base/DeleteTableTxn.h index 59e50e30f02..415e4fc666c 100644 --- a/editor/base/DeleteTableTxn.h +++ b/editor/base/DeleteTableTxn.h @@ -58,7 +58,8 @@ private: DeleteTableTxn(); public: - + virtual ~DeleteTableTxn(); + NS_IMETHOD Do(void); NS_IMETHOD Undo(void); diff --git a/editor/base/DeleteTextTxn.cpp b/editor/base/DeleteTextTxn.cpp index b3a6ca7a864..b321d49b53b 100644 --- a/editor/base/DeleteTextTxn.cpp +++ b/editor/base/DeleteTextTxn.cpp @@ -26,6 +26,10 @@ DeleteTextTxn::DeleteTextTxn() { } +DeleteTextTxn::~DeleteTextTxn() +{ +} + NS_IMETHODIMP DeleteTextTxn::Init(nsIEditor *aEditor, nsIDOMCharacterData *aElement, PRUint32 aOffset, diff --git a/editor/base/DeleteTextTxn.h b/editor/base/DeleteTextTxn.h index 5be094eaebf..c0c4fca7f89 100644 --- a/editor/base/DeleteTextTxn.h +++ b/editor/base/DeleteTextTxn.h @@ -51,7 +51,8 @@ private: DeleteTextTxn(); public: - + virtual ~DeleteTextTxn(); + NS_IMETHOD Do(void); NS_IMETHOD Undo(void); diff --git a/editor/base/EditTable.cpp b/editor/base/EditTable.cpp index 57ee3350986..abf0ea0518e 100644 --- a/editor/base/EditTable.cpp +++ b/editor/base/EditTable.cpp @@ -79,65 +79,32 @@ static NS_DEFINE_IID(kJoinTableCellsTxnIID, JOIN_CELLS_TXN_IID); NS_IMETHODIMP nsHTMLEditor::InsertTable() { nsresult result=NS_ERROR_NOT_INITIALIZED; -#if 0 - if (mEditor) - { - // Note: Code that does most of the deletion work was - // moved to nsEditor::DeleteSelectionAndCreateNode - // Only difference is we now do BeginTransaction()/EndTransaction() - // even if we fail to get a selection - result = mEditor->BeginTransaction(); +//#if 0 + result = nsEditor::BeginTransaction(); - nsCOMPtr newNode; - nsAutoString tag("td"); - result = mEditor->DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); + nsCOMPtr newNode; + nsAutoString tag("table"); + result = DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); + if( NS_SUCCEEDED(result)) + { + nsAutoString tag("tr"); + nsCOMPtr ParentNode; + ParentNode = newNode; + result = nsEditor::CreateNode(tag, ParentNode, 0, getter_AddRefs(newNode)); if( NS_SUCCEEDED(result)) { - nsAutoString tag("tr"); - nsCOMPtr ParentNode; + nsAutoString tag("td"); ParentNode = newNode; - result = mEditor->CreateNode(tag, ParentNode, 0, getter_AddRefs(newNode)); - if( NS_SUCCEEDED(result)) - { - ParentNode = newNode; - nsAutoString tag("td"); - ParentNode = newNode; - result = mEditor->CreateNode(tag, ParentNode, 0, getter_AddRefs(newNode)); - } - } - result = mEditor->EndTransaction(); - } -#endif - return result; - -#if 0 - EditAggregateTxn *aggTxn; - result = mEditor->CreateAggregateTxnForDeleteSelection(InsertTableTxn::gInsertTableTxnName, (nsISupports**)&aggTxn); - if ((NS_FAILED(result)) || (nsnull==aggTxn)) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // CREATE A NEW TABLE HERE -- INCLUDE 1 ROW, CELL, AND DEFAULT PARAGRAPH WITH 1 SPACE - nsIDOMElement *aTableNode = nsnull; - - InsertTableTxn *txn; - result = CreateTxnForInsertTable(aTableNode, &txn); - if ((NS_SUCCEEDED(result)) && txn) { - aggTxn->AppendChild(txn); - result = mEditor->Do(aggTxn); + result = nsEditor::CreateNode(tag, ParentNode, 0, getter_AddRefs(newNode)); } } - + result = nsEditor::EndTransaction(); +//#endif return result; -#endif } NS_IMETHODIMP nsHTMLEditor::CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn) { - if (mEditor==nsnull) - { - return NS_ERROR_NOT_INITIALIZED; - } if( aTableNode == nsnull || aTxn == nsnull ) { return NS_ERROR_NULL_POINTER; @@ -193,103 +160,61 @@ NS_IMETHODIMP nsHTMLEditor::CreateTxnForInsertTable(const nsIDOMElement *aTableN NS_IMETHODIMP nsHTMLEditor::InsertTableCell(PRInt32 aNumber, PRBool aAfter) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::DeleteTable() { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::DeleteTableCell(PRInt32 aNumber) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::DeleteTableRow(PRInt32 aNumber) { nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::JoinTableCells(PRBool aCellToRight) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex) { nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - aCellIndex=0; // initialize out param - result = NS_ERROR_FAILURE; // we return an error unless we get the index - nsISupports *layoutObject=nsnull; // frames are not ref counted, so don't use an nsCOMPtr + aCellIndex=0; // initialize out param + result = NS_ERROR_FAILURE; // we return an error unless we get the index + nsISupports *layoutObject=nsnull; // frames are not ref counted, so don't use an nsCOMPtr - result = mEditor->GetLayoutObject(aCellNode, &layoutObject); + result = nsEditor::GetLayoutObject(aCellNode, &layoutObject); - if ((NS_SUCCEEDED(result)) && (nsnull!=layoutObject)) - { // get the table cell interface from the frame - nsITableCellLayout *cellLayoutObject=nsnull; // again, frames are not ref-counted - result = layoutObject->QueryInterface(nsITableCellLayout::GetIID(), (void**)(&cellLayoutObject)); - if ((NS_SUCCEEDED(result)) && (nsnull!=cellLayoutObject)) - { // get the index - result = cellLayoutObject->GetColIndex(aCellIndex); - } + if ((NS_SUCCEEDED(result)) && (nsnull!=layoutObject)) + { // get the table cell interface from the frame + nsITableCellLayout *cellLayoutObject=nsnull; // again, frames are not ref-counted + result = layoutObject->QueryInterface(nsITableCellLayout::GetIID(), (void**)(&cellLayoutObject)); + if ((NS_SUCCEEDED(result)) && (nsnull!=cellLayoutObject)) + { // get the index + result = cellLayoutObject->GetColIndex(aCellIndex); } } return result; @@ -297,55 +222,30 @@ NS_IMETHODIMP nsHTMLEditor::GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &a NS_IMETHODIMP nsHTMLEditor::GetRowIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::GetNextCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::GetFirstCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aCellNode) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsHTMLEditor::GetNextCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/editor/base/EditTxn.cpp b/editor/base/EditTxn.cpp index eb61c2ec0be..b0349a459c0 100644 --- a/editor/base/EditTxn.cpp +++ b/editor/base/EditTxn.cpp @@ -33,6 +33,10 @@ EditTxn::EditTxn() NS_INIT_REFCNT(); } +EditTxn::~EditTxn() +{ +} + NS_IMETHODIMP EditTxn::Do(void) { return NS_OK; diff --git a/editor/base/EditTxn.h b/editor/base/EditTxn.h index a4bc3462c7d..4323ef56bc5 100644 --- a/editor/base/EditTxn.h +++ b/editor/base/EditTxn.h @@ -39,6 +39,8 @@ public: NS_DECL_ISUPPORTS EditTxn(); + virtual ~EditTxn(); + NS_IMETHOD Do(void); diff --git a/editor/base/InsertTableCellTxn.cpp b/editor/base/InsertTableCellTxn.cpp index bebd355be6b..1a3b7f82cf2 100644 --- a/editor/base/InsertTableCellTxn.cpp +++ b/editor/base/InsertTableCellTxn.cpp @@ -40,6 +40,10 @@ InsertTableCellTxn::InsertTableCellTxn() { } +InsertTableCellTxn::~InsertTableCellTxn() +{ +} + NS_IMETHODIMP InsertTableCellTxn::Init(nsIDOMCharacterData *aElement, PRUint32 aOffset, nsIDOMNode *aNode, diff --git a/editor/base/InsertTableCellTxn.h b/editor/base/InsertTableCellTxn.h index c8055468e35..4533e57d57a 100644 --- a/editor/base/InsertTableCellTxn.h +++ b/editor/base/InsertTableCellTxn.h @@ -38,6 +38,7 @@ class nsIPresShell; class InsertTableCellTxn : public EditTxn { public: + virtual ~InsertTableCellTxn(); /** used to name aggregate transactions that consist only of a single InsertTableCellTxn, * or a DeleteSelection followed by an InsertTableCellTxn. diff --git a/editor/base/InsertTableColumnTxn.cpp b/editor/base/InsertTableColumnTxn.cpp index 39f1a83aa4a..5821e05137a 100644 --- a/editor/base/InsertTableColumnTxn.cpp +++ b/editor/base/InsertTableColumnTxn.cpp @@ -40,6 +40,10 @@ InsertTableColumnTxn::InsertTableColumnTxn() { } +InsertTableColumnTxn::~InsertTableColumnTxn() +{ +} + NS_IMETHODIMP InsertTableColumnTxn::Init(nsIDOMCharacterData *aElement, PRUint32 aOffset, nsIDOMNode *aNode, diff --git a/editor/base/InsertTableColumnTxn.h b/editor/base/InsertTableColumnTxn.h index 5fb712558e7..da6e618c0f3 100644 --- a/editor/base/InsertTableColumnTxn.h +++ b/editor/base/InsertTableColumnTxn.h @@ -39,6 +39,7 @@ class nsIPresShell; class InsertTableColumnTxn : public EditTxn { public: + virtual ~InsertTableColumnTxn(); /** used to name aggregate transactions that consist only of a single InsertTableColumnTxn, * or a DeleteSelection followed by an InsertTableColumnTxn. diff --git a/editor/base/InsertTableRowTxn.cpp b/editor/base/InsertTableRowTxn.cpp index 6591be6b52a..47cb3ee6c9a 100644 --- a/editor/base/InsertTableRowTxn.cpp +++ b/editor/base/InsertTableRowTxn.cpp @@ -40,6 +40,10 @@ InsertTableRowTxn::InsertTableRowTxn() { } +InsertTableRowTxn::~InsertTableRowTxn() +{ +} + NS_IMETHODIMP InsertTableRowTxn::Init(nsIDOMCharacterData *aElement, PRUint32 aOffset, nsIDOMNode *aNode, diff --git a/editor/base/InsertTableRowTxn.h b/editor/base/InsertTableRowTxn.h index d6c1ae6c672..7563d0133df 100644 --- a/editor/base/InsertTableRowTxn.h +++ b/editor/base/InsertTableRowTxn.h @@ -39,6 +39,7 @@ class nsIPresShell; class InsertTableRowTxn : public EditTxn { public: + virtual ~InsertTableRowTxn(); /** used to name aggregate transactions that consist only of a single InsertTableRowTxn, * or a DeleteSelection followed by an InsertTableRowTxn. diff --git a/editor/base/InsertTableTxn.cpp b/editor/base/InsertTableTxn.cpp index a9e7f684958..291b944f817 100644 --- a/editor/base/InsertTableTxn.cpp +++ b/editor/base/InsertTableTxn.cpp @@ -40,6 +40,10 @@ InsertTableTxn::InsertTableTxn() { } +InsertTableTxn::~InsertTableTxn() +{ +} + NS_IMETHODIMP InsertTableTxn::Init(nsIDOMCharacterData *aElement, PRUint32 aOffset, nsIDOMNode *aNode, diff --git a/editor/base/InsertTableTxn.h b/editor/base/InsertTableTxn.h index 62e07945ce4..df85caa468a 100644 --- a/editor/base/InsertTableTxn.h +++ b/editor/base/InsertTableTxn.h @@ -38,6 +38,7 @@ class nsIPresShell; class InsertTableTxn : public EditTxn { public: + virtual ~InsertTableTxn(); /** used to name aggregate transactions that consist only of a single InsertTableTxn, * or a DeleteSelection followed by an InsertTableTxn. diff --git a/editor/base/InsertTextTxn.cpp b/editor/base/InsertTextTxn.cpp index 7735afcad91..b7b718ae099 100644 --- a/editor/base/InsertTextTxn.cpp +++ b/editor/base/InsertTextTxn.cpp @@ -40,6 +40,10 @@ InsertTextTxn::InsertTextTxn() { } +InsertTextTxn::~InsertTextTxn() +{ +} + NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement, PRUint32 aOffset, const nsString& aStringToInsert, diff --git a/editor/base/InsertTextTxn.h b/editor/base/InsertTextTxn.h index ceb0f95d3f7..a7d482a5ce8 100644 --- a/editor/base/InsertTextTxn.h +++ b/editor/base/InsertTextTxn.h @@ -36,6 +36,7 @@ class nsIPresShell; class InsertTextTxn : public EditTxn { public: + virtual ~InsertTextTxn(); /** used to name aggregate transactions that consist only of a single InsertTextTxn, * or a DeleteSelection followed by an InsertTextTxn. diff --git a/editor/base/JoinTableCellsTxn.cpp b/editor/base/JoinTableCellsTxn.cpp index d81cc2fc44a..5ef822b3edd 100644 --- a/editor/base/JoinTableCellsTxn.cpp +++ b/editor/base/JoinTableCellsTxn.cpp @@ -40,6 +40,10 @@ JoinTableCellsTxn::JoinTableCellsTxn() { } +JoinTableCellsTxn::~JoinTableCellsTxn() +{ +} + NS_IMETHODIMP JoinTableCellsTxn::Init(nsIDOMCharacterData *aElement, nsIDOMNode *aNode, nsIPresShell* aPresShell) diff --git a/editor/base/JoinTableCellsTxn.h b/editor/base/JoinTableCellsTxn.h index f4e0291ee35..16ac5be63b4 100644 --- a/editor/base/JoinTableCellsTxn.h +++ b/editor/base/JoinTableCellsTxn.h @@ -37,7 +37,7 @@ class nsIPresShell; class JoinTableCellsTxn : public EditTxn { public: - + virtual ~JoinTableCellsTxn(); /** used to name aggregate transactions that consist only of a single JoinTableCellsTxn, * or a DeleteSelection followed by an JoinTableCellsTxn. */ diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index 44bd59c5d84..473abf53054 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -811,32 +811,20 @@ NS_IMETHODIMP nsEditor::CreateTxnForDeleteElement(nsIDOMNode * aElement, return result; } -NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, nsISupports **aAggTxn) +NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, EditAggregateTxn **aAggTxn) { nsresult result = NS_ERROR_NULL_POINTER; if (aAggTxn) { *aAggTxn = nsnull; - EditAggregateTxn *aTxn = nsnull; + result = TransactionFactory::GetNewTransaction(kEditAggregateTxnIID, (EditTxn**)aAggTxn); - result = TransactionFactory::GetNewTransaction(kEditAggregateTxnIID, (EditTxn**)&aTxn); - - if ((NS_FAILED(result)) || !aTxn) { + if (NS_FAILED(result) || !*aAggTxn) { return NS_ERROR_OUT_OF_MEMORY; } - // Return transaction pointer - *aAggTxn = (nsISupports*)aTxn; - -#if 0 - //Test to be sure the Return the transaction pointer as nsISupports* - result = aTxn->QueryInterface(kISupportsIID, (void**)aAggTxn); - if (!NS_SUCCEEDED(result)) - return NS_ERROR_UNEXPECTED; -#endif - // Set the name for the aggregate transaction - aTxn->SetName(aTxnName); + (*aAggTxn)->SetName(aTxnName); // Get current selection and setup txn to delete it, // but only if selection exists (is not a collapsed "caret" state) @@ -850,7 +838,7 @@ NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, EditAggregateTxn *delSelTxn; result = CreateTxnForDeleteSelection(nsIEditor::eLTR, &delSelTxn); if (NS_SUCCEEDED(result) && delSelTxn) { - aTxn->AppendChild(delSelTxn); + (*aAggTxn)->AppendChild(delSelTxn); } } } @@ -864,7 +852,7 @@ nsEditor::InsertText(const nsString& aStringToInsert) { EditAggregateTxn *aggTxn = nsnull; // Create the "delete current selection" txn - nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName, (nsISupports**)&aggTxn); + nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName, &aggTxn); if ((NS_FAILED(result)) || (nsnull==aggTxn)) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/editor/base/nsEditor.h b/editor/base/nsEditor.h index 30c7627ec73..8b786cf45ea 100644 --- a/editor/base/nsEditor.h +++ b/editor/base/nsEditor.h @@ -79,10 +79,11 @@ public: /*BEGIN nsIEdieditor for more details*/ - /*interfaces for addref and release and queryinterface*/ +//Interfaces for addref and release and queryinterface +//NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsText NS_DECL_ISUPPORTS - NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell); + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell); NS_IMETHOD GetDocument(nsIDOMDocument **aDoc); @@ -243,8 +244,6 @@ protected: nsIDOMNode * aParent, PRBool aNodeToKeepIsFirst); - NS_IMETHOD CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, nsISupports **aAggTxn); - #if 0 NS_IMETHOD CreateTxnToHandleEnterKey(EditAggregateTxn **aTxn); #endif @@ -257,6 +256,17 @@ protected: NS_IMETHOD GetLeftmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode); +//Methods not exposed in nsIEditor + + /** Create an aggregate transaction for deleting current selection + * Used by all methods that need to delete current selection, + * then insert something new to replace it + * @param nsString& aTxnName is the name of the aggregated transaction + * @param EditTxn **aAggTxn is the return location of the aggregate TXN, + * with the DeleteSelectionTxn as the first child ONLY + * if there was a selection to delete. + */ + NS_IMETHOD CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, EditAggregateTxn **aAggTxn); }; diff --git a/editor/base/nsHTMLEditFactory.cpp b/editor/base/nsHTMLEditFactory.cpp index 34d0cf82f23..a6cf453db5a 100644 --- a/editor/base/nsHTMLEditFactory.cpp +++ b/editor/base/nsHTMLEditFactory.cpp @@ -86,7 +86,11 @@ nsHTMLEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aRe if (mCID.Equals(kHTMLEditorCID)) - obj = (nsISupports *)new nsHTMLEditor(); + { + //Need to cast to interface first to avoid "ambiguous conversion..." error + // because of multiple nsISupports in the class hierarchy + obj = (nsISupports *)(nsIHTMLEditor*)new nsHTMLEditor(); + } //more class ids to support. here if (obj && NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) ) diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index fd7b0a5296e..a5ebbdbb70d 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -47,366 +47,180 @@ static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID); nsHTMLEditor::nsHTMLEditor() { - NS_INIT_REFCNT(); +// Done in nsEditor +// NS_INIT_REFCNT(); } nsHTMLEditor::~nsHTMLEditor() { //the autopointers will clear themselves up. -#if 0 -// NO EVENT LISTERNERS YET - //but we need to also remove the listeners or we have a leak - //(This is identical to nsTextEditor code - if (mEditor) - { - nsCOMPtr doc; - mEditor->GetDocument(getter_AddRefs(doc)); - if (doc) - { - nsCOMPtr erP; - nsresult result = doc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP)); - if (NS_SUCCEEDED(result) && erP) - { - if (mKeyListenerP) { - erP->RemoveEventListener(mKeyListenerP, kIDOMKeyListenerIID); - } - if (mMouseListenerP) { - erP->RemoveEventListener(mMouseListenerP, kIDOMMouseListenerIID); - } - } - else - NS_NOTREACHED("~nsHTMLEditor"); - } - } -#endif } -NS_IMETHODIMP nsHTMLEditor::InitHTMLEditor(nsIDOMDocument *aDoc, - nsIPresShell *aPresShell, - nsIEditorCallback *aCallback) +// Adds appropriate AddRef, Release, and QueryInterface methods for derived class +//NS_IMPL_ISUPPORTS_INHERITED(nsHTMLEditor, nsTextEditor, nsIHTMLEditor) + +//NS_IMPL_ADDREF_INHERITED(Class, Super) +NS_IMETHODIMP_(nsrefcnt) nsHTMLEditor::AddRef(void) +{ + return Inherited::AddRef(); +} + +//NS_IMPL_RELEASE_INHERITED(Class, Super) +NS_IMETHODIMP_(nsrefcnt) nsHTMLEditor::Release(void) +{ + return Inherited::Release(); +} + +//NS_IMPL_QUERY_INTERFACE_INHERITED(Class, Super, AdditionalInterface) +NS_IMETHODIMP nsHTMLEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if (!aInstancePtr) return NS_ERROR_NULL_POINTER; + + if (aIID.Equals(nsIHTMLEditor::GetIID())) { + *aInstancePtr = NS_STATIC_CAST(nsIHTMLEditor*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + return Inherited::QueryInterface(aIID, aInstancePtr); +} + + +NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell) { NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg"); nsresult result=NS_ERROR_NULL_POINTER; if ((nsnull!=aDoc) && (nsnull!=aPresShell)) { - nsITextEditor *aTextEditor = nsnull; - result = nsRepository::CreateInstance(kTextEditorCID, nsnull, - kITextEditorIID, (void **)&aTextEditor); - - if (NS_FAILED(result) || !aTextEditor) { - return NS_ERROR_OUT_OF_MEMORY; - } - mTextEditor = do_QueryInterface(aTextEditor); // CreateInstance did our addRef - - // Initialize nsTextEditor -- this will create and initialize the base nsEditor - // Note: nsTextEditor adds its own key, mouse, and DOM listners -- is that OK? - result = mTextEditor->InitTextEditor(aDoc, aPresShell); - if (NS_OK != result) { - return result; - } - mTextEditor->EnableUndo(PR_TRUE); - - // Get the pointer to the base editor for easier access - result = mTextEditor->QueryInterface(kIEditorIID, getter_AddRefs(mEditor)); - if (NS_OK != result) { - return result; - } - result = NS_OK; + return Inherited::Init(aDoc, aPresShell); } return result; } NS_IMETHODIMP nsHTMLEditor::SetTextProperty(nsIAtom *aProperty) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->SetTextProperty(aProperty); - } - return result; + return Inherited::SetTextProperty(aProperty); } NS_IMETHODIMP nsHTMLEditor::GetTextProperty(nsIAtom *aProperty, PRBool &aAny, PRBool &aAll) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->GetTextProperty(aProperty, aAny, aAll); - } - return result; + return Inherited::GetTextProperty(aProperty, aAny, aAll); } NS_IMETHODIMP nsHTMLEditor::RemoveTextProperty(nsIAtom *aProperty) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->RemoveTextProperty(aProperty); - } - return result; + return Inherited::RemoveTextProperty(aProperty); } NS_IMETHODIMP nsHTMLEditor::DeleteSelection(nsIEditor::Direction aDir) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->DeleteSelection(aDir); - } - return result; + return Inherited::DeleteSelection(aDir); } NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->InsertText(aStringToInsert); - } - return result; + return Inherited::InsertText(aStringToInsert); } NS_IMETHODIMP nsHTMLEditor::InsertBreak(PRBool aCtrlKey) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->InsertBreak(aCtrlKey); - } - return result; + return Inherited::InsertBreak(aCtrlKey); } // Methods shared with the base editor. // Note: We could call each of these via nsTextEditor -- is that better? NS_IMETHODIMP nsHTMLEditor::EnableUndo(PRBool aEnable) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->EnableUndo(aEnable); - } - return result; + return Inherited::EnableUndo(aEnable); } NS_IMETHODIMP nsHTMLEditor::Undo(PRUint32 aCount) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->Undo(aCount); - } - return result; + return Inherited::Undo(aCount); } NS_IMETHODIMP nsHTMLEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->CanUndo(aIsEnabled, aCanUndo); - } - return result; + return Inherited::CanUndo(aIsEnabled, aCanUndo); } NS_IMETHODIMP nsHTMLEditor::Redo(PRUint32 aCount) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->Redo(aCount); - } - return result; + return Inherited::Redo(aCount); } NS_IMETHODIMP nsHTMLEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->CanRedo(aIsEnabled, aCanRedo); - } - return result; + return Inherited::CanRedo(aIsEnabled, aCanRedo); } NS_IMETHODIMP nsHTMLEditor::BeginTransaction() { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->BeginTransaction(); - } - return result; + return Inherited::BeginTransaction(); } NS_IMETHODIMP nsHTMLEditor::EndTransaction() { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->EndTransaction(); - } - return result; + return Inherited::EndTransaction(); } NS_IMETHODIMP nsHTMLEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->MoveSelectionUp(aIncrement, aExtendSelection); - } - return result; + return Inherited::MoveSelectionUp(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->MoveSelectionDown(aIncrement, aExtendSelection); - } - return result; + return Inherited::MoveSelectionDown(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->MoveSelectionNext(aIncrement, aExtendSelection); - } - return result; + return Inherited::MoveSelectionNext(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->MoveSelectionPrevious(aIncrement, aExtendSelection); - } - return result; + return Inherited::MoveSelectionPrevious(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->SelectNext(aIncrement, aExtendSelection); - } - return result; + return Inherited::SelectNext(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->SelectPrevious(aIncrement, aExtendSelection); - } - return result; + return Inherited::SelectPrevious(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::ScrollUp(nsIAtom *aIncrement) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->ScrollUp(aIncrement); - } - return result; + return Inherited::ScrollUp(aIncrement); } NS_IMETHODIMP nsHTMLEditor::ScrollDown(nsIAtom *aIncrement) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->ScrollDown(aIncrement); - } - return result; + return Inherited::ScrollDown(aIncrement); } NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->ScrollIntoView(aScrollToBegin); - } - return result; + return Inherited::ScrollIntoView(aScrollToBegin); } NS_IMETHODIMP nsHTMLEditor::Insert(nsIInputStream *aInputStream) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->Insert(aInputStream); - } - return result; + return Inherited::Insert(aInputStream); } NS_IMETHODIMP nsHTMLEditor::OutputText(nsIOutputStream *aOutputStream) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->OutputText(aOutputStream); - } - return result; + return Inherited::OutputText(aOutputStream); } NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsIOutputStream *aOutputStream) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->OutputHTML(aOutputStream); - } - return result; -} - - -NS_IMPL_ADDREF(nsHTMLEditor) - -NS_IMPL_RELEASE(nsHTMLEditor) - -NS_IMETHODIMP -nsHTMLEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (nsnull == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*)(nsISupports*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(kIHTMLEditorIID)) { - *aInstancePtr = (void*)(nsIHTMLEditor*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - // If our pointer to nsTextEditor is null, don't bother querying? - if (aIID.Equals(kITextEditorIID) && (mTextEditor)) { - nsCOMPtr editor; - nsresult result = mTextEditor->QueryInterface(kITextEditorIID, getter_AddRefs(editor)); - if (NS_SUCCEEDED(result) && editor) { - *aInstancePtr = (void*)editor; - return NS_OK; - } - } - if (aIID.Equals(kIEditorIID) && (mEditor)) { - nsCOMPtr editor; - nsresult result = mEditor->QueryInterface(kIEditorIID, getter_AddRefs(editor)); - if (NS_SUCCEEDED(result) && editor) { - *aInstancePtr = (void*)editor; - return NS_OK; - } - } - return NS_NOINTERFACE; + return Inherited::OutputHTML(aOutputStream); } //================================================================ diff --git a/editor/base/nsHTMLEditor.h b/editor/base/nsHTMLEditor.h index fe6cc2dfb0f..fdfafe4b726 100644 --- a/editor/base/nsHTMLEditor.h +++ b/editor/base/nsHTMLEditor.h @@ -20,6 +20,7 @@ #define nsHTMLEditor_h__ #include "nsITextEditor.h" +#include "nsTextEditor.h" #include "nsIHTMLEditor.h" #include "nsCOMPtr.h" #include "nsIDOMEventListener.h" @@ -29,20 +30,25 @@ * The HTML editor implementation.
* Use to edit HTML document represented as a DOM tree. */ -class nsHTMLEditor : public nsIHTMLEditor +class nsHTMLEditor : public nsTextEditor, public nsIHTMLEditor { +private: + // So we can use "Inherited::foo()" instead of "nsTextEditor::foo()" + typedef nsTextEditor Inherited; + public: // see nsIHTMLEditor for documentation //Interfaces for addref and release and queryinterface - NS_DECL_ISUPPORTS +//NOTE macro used is for classes that inherit from +// another class. Only the base class should use NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED + + nsHTMLEditor(); + virtual ~nsHTMLEditor(); //Initialization - nsHTMLEditor(); - NS_IMETHOD InitHTMLEditor(nsIDOMDocument *aDoc, - nsIPresShell *aPresShell, - nsIEditorCallback *aCallback=nsnull); - virtual ~nsHTMLEditor(); + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell); //============================================================================ // Methods that are duplicates of nsTextEditor -- exposed here for convenience @@ -103,8 +109,6 @@ public: // Data members protected: - nsCOMPtr mEditor; - nsCOMPtr mTextEditor; // EVENT LISTENERS AND COMMAND ROUTING NEEDS WORK // For now, the listners are tied to the nsTextEditor class diff --git a/editor/base/nsTextEditFactory.cpp b/editor/base/nsTextEditFactory.cpp index acbd0689e4d..2a9242d3011 100644 --- a/editor/base/nsTextEditFactory.cpp +++ b/editor/base/nsTextEditFactory.cpp @@ -86,9 +86,14 @@ nsTextEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aRe if (mCID.Equals(kTextEditorCID)) - obj = (nsISupports *)new nsTextEditor(); + { + //Need to cast to interface first to avoid "ambiguous conversion..." error + // because of multiple nsISupports in the class hierarchy + obj = (nsISupports *)(nsITextEditor*)new nsTextEditor(); + } //more class ids to support. here + if (obj && NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) ) { delete obj; diff --git a/editor/base/nsTextEditor.cpp b/editor/base/nsTextEditor.cpp index 901c2fdf691..56e47ecd741 100644 --- a/editor/base/nsTextEditor.cpp +++ b/editor/base/nsTextEditor.cpp @@ -85,55 +85,72 @@ static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID); nsTextEditor::nsTextEditor() { - NS_INIT_REFCNT(); +// Done in nsEditor +// NS_INIT_REFCNT(); } nsTextEditor::~nsTextEditor() { //the autopointers will clear themselves up. //but we need to also remove the listeners or we have a leak - if (mEditor) + nsCOMPtr doc; + Inherited::GetDocument(getter_AddRefs(doc)); + if (doc) { - nsCOMPtr doc; - mEditor->GetDocument(getter_AddRefs(doc)); - if (doc) + nsCOMPtr erP; + nsresult result = doc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP)); + if (NS_SUCCEEDED(result) && erP) { - nsCOMPtr erP; - nsresult result = doc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP)); - if (NS_SUCCEEDED(result) && erP) - { - if (mKeyListenerP) { - erP->RemoveEventListener(mKeyListenerP, kIDOMKeyListenerIID); - } - if (mMouseListenerP) { - erP->RemoveEventListener(mMouseListenerP, kIDOMMouseListenerIID); - } + if (mKeyListenerP) { + erP->RemoveEventListener(mKeyListenerP, kIDOMKeyListenerIID); + } + if (mMouseListenerP) { + erP->RemoveEventListener(mMouseListenerP, kIDOMMouseListenerIID); } - else - NS_NOTREACHED("~nsTextEditor"); } + else + NS_NOTREACHED("~nsTextEditor"); } } -NS_IMETHODIMP nsTextEditor::InitTextEditor(nsIDOMDocument *aDoc, - nsIPresShell *aPresShell, - nsIEditorCallback *aCallback) +// Adds appropriate AddRef, Release, and QueryInterface methods for derived class +//NS_IMPL_ISUPPORTS_INHERITED(nsTextEditor, nsEditor, nsITextEditor) + +//NS_IMPL_ADDREF_INHERITED(Class, Super) +NS_IMETHODIMP_(nsrefcnt) nsTextEditor::AddRef(void) +{ + return Inherited::AddRef(); +} + +//NS_IMPL_RELEASE_INHERITED(Class, Super) +NS_IMETHODIMP_(nsrefcnt) nsTextEditor::Release(void) +{ + return Inherited::Release(); +} + +//NS_IMPL_QUERY_INTERFACE_INHERITED(Class, Super, AdditionalInterface) +NS_IMETHODIMP nsTextEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if (!aInstancePtr) return NS_ERROR_NULL_POINTER; + + if (aIID.Equals(nsITextEditor::GetIID())) { + *aInstancePtr = NS_STATIC_CAST(nsITextEditor*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + return Inherited::QueryInterface(aIID, aInstancePtr); +} + +NS_IMETHODIMP nsTextEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell) { NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg"); nsresult result=NS_ERROR_NULL_POINTER; if ((nsnull!=aDoc) && (nsnull!=aPresShell)) { - // get the editor - nsIEditor *editor = nsnull; - result = nsRepository::CreateInstance(kEditorCID, nsnull, - kIEditorIID, (void **)&editor); - if (NS_FAILED(result) || !editor) { - return NS_ERROR_OUT_OF_MEMORY; - } - mEditor = do_QueryInterface(editor); // CreateInstance did our addRef - - mEditor->Init(aDoc, aPresShell); - mEditor->EnableUndo(PR_TRUE); + // Init the base editor + result = Inherited::Init(aDoc, aPresShell); + if (NS_OK != result) + return result; result = NS_NewEditorKeyListener(getter_AddRefs(mKeyListenerP), this); if (NS_OK != result) { @@ -145,6 +162,7 @@ NS_IMETHODIMP nsTextEditor::InitTextEditor(nsIDOMDocument *aDoc, mKeyListenerP = do_QueryInterface(0); return result; } + nsCOMPtr erP; result = aDoc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP)); if (NS_OK != result) @@ -153,10 +171,13 @@ NS_IMETHODIMP nsTextEditor::InitTextEditor(nsIDOMDocument *aDoc, mMouseListenerP = do_QueryInterface(0); //dont need these if we cant register them return result; } + //cmanske: Shouldn't we check result from this? erP->AddEventListener(mKeyListenerP, kIDOMKeyListenerIID); //erP->AddEventListener(mMouseListenerP, kIDOMMouseListenerIID); result = NS_OK; + + EnableUndo(PR_TRUE); } return result; } @@ -169,80 +190,77 @@ NS_IMETHODIMP nsTextEditor::SetTextProperty(nsIAtom *aProperty) return NS_ERROR_NULL_POINTER; nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) + nsCOMPtrselection; + result = Inherited::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(result)) && selection) { - nsCOMPtrselection; - result = mEditor->GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + Inherited::BeginTransaction(); + nsCOMPtr enumerator; + enumerator = do_QueryInterface(selection, &result); + if ((NS_SUCCEEDED(result)) && enumerator) { - mEditor->BeginTransaction(); - nsCOMPtr enumerator; - enumerator = do_QueryInterface(selection, &result); - if ((NS_SUCCEEDED(result)) && enumerator) + enumerator->First(); + nsISupports *currentItem; + result = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) { - enumerator->First(); - nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem)) + nsCOMPtr range( do_QueryInterface(currentItem) ); + nsCOMPtrcommonParent; + result = range->GetCommonParent(getter_AddRefs(commonParent)); + if ((NS_SUCCEEDED(result)) && commonParent) { - nsCOMPtr range( do_QueryInterface(currentItem) ); - nsCOMPtrcommonParent; - result = range->GetCommonParent(getter_AddRefs(commonParent)); - if ((NS_SUCCEEDED(result)) && commonParent) + PRInt32 startOffset, endOffset; + range->GetStartOffset(&startOffset); + range->GetEndOffset(&endOffset); + nsCOMPtr startParent; nsCOMPtr endParent; + range->GetStartParent(getter_AddRefs(startParent)); + range->GetEndParent(getter_AddRefs(endParent)); + if (startParent.get()==endParent.get()) + { // the range is entirely contained within a single text node + result = SetTextPropertiesForNode(startParent, commonParent, + startOffset, endOffset, + aProperty); + } + else { - PRInt32 startOffset, endOffset; - range->GetStartOffset(&startOffset); - range->GetEndOffset(&endOffset); - nsCOMPtr startParent; nsCOMPtr endParent; - range->GetStartParent(getter_AddRefs(startParent)); - range->GetEndParent(getter_AddRefs(endParent)); - if (startParent.get()==endParent.get()) - { // the range is entirely contained within a single text node - result = SetTextPropertiesForNode(startParent, commonParent, - startOffset, endOffset, - aProperty); - } - else + nsCOMPtr startGrandParent; + startParent->GetParentNode(getter_AddRefs(startGrandParent)); + nsCOMPtr endGrandParent; + endParent->GetParentNode(getter_AddRefs(endGrandParent)); + if (NS_SUCCEEDED(result)) { - nsCOMPtr startGrandParent; - startParent->GetParentNode(getter_AddRefs(startGrandParent)); - nsCOMPtr endGrandParent; - endParent->GetParentNode(getter_AddRefs(endGrandParent)); - if (NS_SUCCEEDED(result)) - { - if (endGrandParent.get()==startGrandParent.get()) - { // the range is between 2 nodes that have a common (immediate) grandparent - result = SetTextPropertiesForNodesWithSameParent(startParent,startOffset, - endParent, endOffset, - commonParent, - aProperty); - } - else - { // the range is between 2 nodes that have no simple relationship - result = SetTextPropertiesForNodeWithDifferentParents(range, - startParent,startOffset, - endParent, endOffset, - commonParent, - aProperty); - } + if (endGrandParent.get()==startGrandParent.get()) + { // the range is between 2 nodes that have a common (immediate) grandparent + result = SetTextPropertiesForNodesWithSameParent(startParent,startOffset, + endParent, endOffset, + commonParent, + aProperty); + } + else + { // the range is between 2 nodes that have no simple relationship + result = SetTextPropertiesForNodeWithDifferentParents(range, + startParent,startOffset, + endParent, endOffset, + commonParent, + aProperty); } } - if (NS_SUCCEEDED(result)) - { // compute a range for the selection - // don't want to actually do anything with selection, because - // we are still iterating through it. Just want to create and remember - // an nsIDOMRange, and later add the range to the selection after clearing it. - // XXX: I'm blocked here because nsIDOMSelection doesn't provide a mechanism - // for setting a compound selection yet. - } + } + if (NS_SUCCEEDED(result)) + { // compute a range for the selection + // don't want to actually do anything with selection, because + // we are still iterating through it. Just want to create and remember + // an nsIDOMRange, and later add the range to the selection after clearing it. + // XXX: I'm blocked here because nsIDOMSelection doesn't provide a mechanism + // for setting a compound selection yet. } } } - mEditor->EndTransaction(); - if (NS_SUCCEEDED(result)) - { // set the selection - // XXX: can't do anything until I can create ranges - } + } + Inherited::EndTransaction(); + if (NS_SUCCEEDED(result)) + { // set the selection + // XXX: can't do anything until I can create ranges } } return result; @@ -256,71 +274,68 @@ NS_IMETHODIMP nsTextEditor::GetTextProperty(nsIAtom *aProperty, PRBool &aAny, PR nsresult result=NS_ERROR_NOT_INITIALIZED; aAny=PR_FALSE; aAll=PR_TRUE; - if (mEditor) + nsCOMPtrselection; + result = Inherited::GetSelection(getter_AddRefs(selection)); + if ((NS_SUCCEEDED(result)) && selection) { - nsCOMPtrselection; - result = mEditor->GetSelection(getter_AddRefs(selection)); - if ((NS_SUCCEEDED(result)) && selection) + nsCOMPtr enumerator; + enumerator = do_QueryInterface(selection, &result); + if ((NS_SUCCEEDED(result)) && enumerator) { - nsCOMPtr enumerator; - enumerator = do_QueryInterface(selection, &result); - if ((NS_SUCCEEDED(result)) && enumerator) + enumerator->First(); + nsISupports *currentItem; + result = enumerator->CurrentItem(¤tItem); + if ((NS_SUCCEEDED(result)) && currentItem) { - enumerator->First(); - nsISupports *currentItem; - result = enumerator->CurrentItem(¤tItem); - if ((NS_SUCCEEDED(result)) && currentItem) + nsCOMPtr range( do_QueryInterface(currentItem) ); + nsCOMPtr iter; + result = nsRepository::CreateInstance(kCContentIteratorCID, nsnull, + kIContentIteratorIID, + getter_AddRefs(iter)); + if ((NS_SUCCEEDED(result)) && iter) { - nsCOMPtr range( do_QueryInterface(currentItem) ); - nsCOMPtr iter; - result = nsRepository::CreateInstance(kCContentIteratorCID, nsnull, - kIContentIteratorIID, - getter_AddRefs(iter)); - if ((NS_SUCCEEDED(result)) && iter) + iter->Init(range); + return 0; + // loop through the content iterator for each content node + // for each text node: + // get the frame for the content, and from it the style context + // ask the style context about the property + nsCOMPtr content; + result = iter->CurrentNode(getter_AddRefs(content)); + int i=0; + while (NS_COMFALSE == iter->IsDone()) { - iter->Init(range); - return 0; - // loop through the content iterator for each content node - // for each text node: - // get the frame for the content, and from it the style context - // ask the style context about the property - nsCOMPtr content; - result = iter->CurrentNode(getter_AddRefs(content)); - int i=0; - while (NS_COMFALSE == iter->IsDone()) + nsCOMPtrtext; + text = do_QueryInterface(content); + if (text) { - nsCOMPtrtext; - text = do_QueryInterface(content); - if (text) + nsCOMPtrpresShell; + Inherited::GetPresShell(getter_AddRefs(presShell)); + NS_ASSERTION(presShell, "bad state, null pres shell"); + if (presShell) { - nsCOMPtrpresShell; - mEditor->GetPresShell(getter_AddRefs(presShell)); - NS_ASSERTION(presShell, "bad state, null pres shell"); - if (presShell) + nsIFrame *frame; + result = presShell->GetPrimaryFrameFor(content, &frame); + if ((NS_SUCCEEDED(result)) && frame) { - nsIFrame *frame; - result = presShell->GetPrimaryFrameFor(content, &frame); - if ((NS_SUCCEEDED(result)) && frame) + nsCOMPtr sc; + result = presShell->GetStyleContextFor(frame, getter_AddRefs(sc)); + if ((NS_SUCCEEDED(result)) && sc) { - nsCOMPtr sc; - result = presShell->GetStyleContextFor(frame, getter_AddRefs(sc)); - if ((NS_SUCCEEDED(result)) && sc) - { - PRBool isSet; - IsTextStyleSet(sc, aProperty, isSet); - if (PR_TRUE==isSet) { - aAny = PR_TRUE; - } - else { - aAll = PR_FALSE; - } + PRBool isSet; + IsTextStyleSet(sc, aProperty, isSet); + if (PR_TRUE==isSet) { + aAny = PR_TRUE; + } + else { + aAll = PR_FALSE; } } } } - iter->Next(); - result = iter->CurrentNode(getter_AddRefs(content)); } + iter->Next(); + result = iter->CurrentNode(getter_AddRefs(content)); } } } @@ -352,224 +367,122 @@ void nsTextEditor::IsTextStyleSet(nsIStyleContext *aSC, NS_IMETHODIMP nsTextEditor::RemoveTextProperty(nsIAtom *aProperty) { nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsTextEditor::DeleteSelection(nsIEditor::Direction aDir) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->DeleteSelection(aDir); - } - return result; + return Inherited::DeleteSelection(aDir); } NS_IMETHODIMP nsTextEditor::InsertText(const nsString& aStringToInsert) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->InsertText(aStringToInsert); - } - return result; + return Inherited::InsertText(aStringToInsert); } NS_IMETHODIMP nsTextEditor::InsertBreak(PRBool aCtrlKey) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - // Note: Code that does most of the deletion work was - // moved to nsEditor::DeleteSelectionAndCreateNode - // Only difference is we now do BeginTransaction()/EndTransaction() - // even if we fail to get a selection - result = mEditor->BeginTransaction(); + // Note: Code that does most of the deletion work was + // moved to nsEditor::DeleteSelectionAndCreateNode + // Only difference is we now do BeginTransaction()/EndTransaction() + // even if we fail to get a selection + nsresult result = Inherited::BeginTransaction(); - nsCOMPtr newNode; - nsAutoString tag("BR"); - mEditor->DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); - // Are we supposed to release newNode? + nsCOMPtr newNode; + nsAutoString tag("BR"); + Inherited::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode)); + + // Are we supposed to release newNode? + result = Inherited::EndTransaction(); - result = mEditor->EndTransaction(); - } return result; } NS_IMETHODIMP nsTextEditor::EnableUndo(PRBool aEnable) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->EnableUndo(aEnable); - } - return result; + return Inherited::EnableUndo(aEnable); } NS_IMETHODIMP nsTextEditor::Undo(PRUint32 aCount) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) { - result = mEditor->Undo(aCount); - } - return result; + return Inherited::Undo(aCount); } NS_IMETHODIMP nsTextEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->CanUndo(aIsEnabled, aCanUndo); - } - return result; + return Inherited::CanUndo(aIsEnabled, aCanUndo); } NS_IMETHODIMP nsTextEditor::Redo(PRUint32 aCount) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->Redo(aCount); - } - return result; + return Inherited::Redo(aCount); } NS_IMETHODIMP nsTextEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->CanRedo(aIsEnabled, aCanRedo); - } - return result; + return Inherited::CanRedo(aIsEnabled, aCanRedo); } NS_IMETHODIMP nsTextEditor::BeginTransaction() { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->BeginTransaction(); - } - return result; + return Inherited::BeginTransaction(); } NS_IMETHODIMP nsTextEditor::EndTransaction() { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->EndTransaction(); - } - return result; + return Inherited::EndTransaction(); } NS_IMETHODIMP nsTextEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsTextEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsTextEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsTextEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsTextEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsTextEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsTextEditor::ScrollUp(nsIAtom *aIncrement) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsTextEditor::ScrollDown(nsIAtom *aIncrement) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsTextEditor::ScrollIntoView(PRBool aScrollToBegin) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->ScrollIntoView(aScrollToBegin); - } - return result; + return Inherited::ScrollIntoView(aScrollToBegin); } NS_IMETHODIMP nsTextEditor::Insert(nsIInputStream *aInputStream) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; + return NS_ERROR_NOT_IMPLEMENTED; } - #ifdef XP_MAC void WriteFromStringstream(stringstream& aIn, nsIOutputStream* aOut) { @@ -619,60 +532,57 @@ NS_IMETHODIMP nsTextEditor::OutputText(nsIOutputStream *aOutputStream) #endif nsresult result=NS_ERROR_FAILURE; - if (mEditor) - { - nsIPresShell* shell = nsnull; - - mEditor->GetPresShell(&shell); - if (nsnull != shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); - if (doc) { - nsString buffer; + nsIPresShell* shell = nsnull; + Inherited::GetPresShell(&shell); - doc->CreateXIF(buffer); + if (nsnull != shell) { + nsCOMPtr doc; + shell->GetDocument(getter_AddRefs(doc)); + if (doc) { + nsString buffer; - nsIParser* parser; + doc->CreateXIF(buffer); - static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); - static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); + nsIParser* parser; - nsresult rv = nsRepository::CreateInstance(kCParserCID, - nsnull, - kCParserIID, - (void **)&parser); + static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); + static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); + + nsresult rv = nsRepository::CreateInstance(kCParserCID, + nsnull, + kCParserIID, + (void **)&parser); + + if (NS_OK == rv) { + nsIHTMLContentSink* sink = nsnull; + + rv = NS_New_HTMLToTXT_SinkStream(&sink); + + if (aOutputStream != nsnull) + ((nsHTMLContentSinkStream*)sink)->SetOutputStream(out); if (NS_OK == rv) { - nsIHTMLContentSink* sink = nsnull; - - rv = NS_New_HTMLToTXT_SinkStream(&sink); + parser->SetContentSink(sink); - if (aOutputStream != nsnull) - ((nsHTMLContentSinkStream*)sink)->SetOutputStream(out); - + nsIDTD* dtd = nsnull; + rv = NS_NewXIFDTD(&dtd); if (NS_OK == rv) { - parser->SetContentSink(sink); - - nsIDTD* dtd = nsnull; - rv = NS_NewXIFDTD(&dtd); - if (NS_OK == rv) { - parser->RegisterDTD(dtd); - parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE); - } - #ifdef XP_MAC - WriteFromStringstream(out,aOutputStream); - #else - WriteFromOstrstream(out,aOutputStream); - #endif - - NS_IF_RELEASE(dtd); - NS_IF_RELEASE(sink); + parser->RegisterDTD(dtd); + parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE); } - NS_RELEASE(parser); + #ifdef XP_MAC + WriteFromStringstream(out,aOutputStream); + #else + WriteFromOstrstream(out,aOutputStream); + #endif + + NS_IF_RELEASE(dtd); + NS_IF_RELEASE(sink); } + NS_RELEASE(parser); } - NS_RELEASE(shell); } + NS_RELEASE(shell); } return result; } @@ -689,96 +599,61 @@ NS_IMETHODIMP nsTextEditor::OutputHTML(nsIOutputStream *aOutputStream) nsresult result=NS_ERROR_FAILURE; - if (mEditor) - { - nsIPresShell* shell = nsnull; - - mEditor->GetPresShell(&shell); - if (nsnull != shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); - if (doc) { - nsString buffer; + nsIPresShell* shell = nsnull; + Inherited::GetPresShell(&shell); - doc->CreateXIF(buffer); + if (nsnull != shell) { + nsCOMPtr doc; + shell->GetDocument(getter_AddRefs(doc)); + if (doc) { + nsString buffer; - nsIParser* parser; + doc->CreateXIF(buffer); - static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); - static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); + nsIParser* parser; - nsresult rv = nsRepository::CreateInstance(kCParserCID, - nsnull, - kCParserIID, - (void **)&parser); + static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); + static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); + + nsresult rv = nsRepository::CreateInstance(kCParserCID, + nsnull, + kCParserIID, + (void **)&parser); + + if (NS_OK == rv) { + nsIHTMLContentSink* sink = nsnull; + + rv = NS_New_HTML_ContentSinkStream(&sink); + + if (aOutputStream) + ((nsHTMLContentSinkStream*)sink)->SetOutputStream(out); if (NS_OK == rv) { - nsIHTMLContentSink* sink = nsnull; - - rv = NS_New_HTML_ContentSinkStream(&sink); + parser->SetContentSink(sink); - if (aOutputStream) - ((nsHTMLContentSinkStream*)sink)->SetOutputStream(out); - + nsIDTD* dtd = nsnull; + rv = NS_NewXIFDTD(&dtd); if (NS_OK == rv) { - parser->SetContentSink(sink); - - nsIDTD* dtd = nsnull; - rv = NS_NewXIFDTD(&dtd); - if (NS_OK == rv) { - parser->RegisterDTD(dtd); - parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE); - } - #ifdef XP_MAC - WriteFromStringstream(out,aOutputStream); - #else - WriteFromOstrstream(out,aOutputStream); - #endif - NS_IF_RELEASE(dtd); - NS_IF_RELEASE(sink); + parser->RegisterDTD(dtd); + parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE); } - NS_RELEASE(parser); + #ifdef XP_MAC + WriteFromStringstream(out,aOutputStream); + #else + WriteFromOstrstream(out,aOutputStream); + #endif + NS_IF_RELEASE(dtd); + NS_IF_RELEASE(sink); } + NS_RELEASE(parser); } - NS_RELEASE(shell); } + NS_RELEASE(shell); } return result; } -NS_IMPL_ADDREF(nsTextEditor) - -NS_IMPL_RELEASE(nsTextEditor) - -NS_IMETHODIMP -nsTextEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (nsnull == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*)(nsISupports*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(kITextEditorIID)) { - *aInstancePtr = (void*)(nsITextEditor*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(kIEditorIID) && (mEditor)) { - nsCOMPtr editor; - nsresult result = mEditor->QueryInterface(kIEditorIID, getter_AddRefs(editor)); - if (NS_SUCCEEDED(result) && editor) { - *aInstancePtr = (void*)editor; - return NS_OK; - } - } - return NS_NOINTERFACE; -} - - NS_IMETHODIMP nsTextEditor::SetTextPropertiesForNode(nsIDOMNode *aNode, nsIDOMNode *aParent, PRInt32 aStartOffset, @@ -796,13 +671,13 @@ NS_IMETHODIMP nsTextEditor::SetTextPropertiesForNode(nsIDOMNode *aNode, nsCOMPtrnewTextNode; // this will be the text node we move into the new style node if (aStartOffset!=0) { - result = mEditor->SplitNode(aNode, aStartOffset, getter_AddRefs(newTextNode)); + result = Inherited::SplitNode(aNode, aStartOffset, getter_AddRefs(newTextNode)); } if (NS_SUCCEEDED(result)) { if (aEndOffset!=(PRInt32)count) { - result = mEditor->SplitNode(aNode, aEndOffset-aStartOffset, getter_AddRefs(newTextNode)); + result = Inherited::SplitNode(aNode, aEndOffset-aStartOffset, getter_AddRefs(newTextNode)); } else { @@ -819,12 +694,12 @@ NS_IMETHODIMP nsTextEditor::SetTextPropertiesForNode(nsIDOMNode *aNode, if (NS_SUCCEEDED(result)) { nsCOMPtrnewStyleNode; - result = mEditor->CreateNode(tag, aParent, offsetInParent, getter_AddRefs(newStyleNode)); + result = Inherited::CreateNode(tag, aParent, offsetInParent, getter_AddRefs(newStyleNode)); if (NS_SUCCEEDED(result)) { - result = mEditor->DeleteNode(newTextNode); + result = Inherited::DeleteNode(newTextNode); if (NS_SUCCEEDED(result)) { - result = mEditor->InsertNode(newTextNode, newStyleNode, 0); + result = Inherited::InsertNode(newTextNode, newStyleNode, 0); } } } @@ -845,7 +720,7 @@ nsTextEditor::SetTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode, nsresult result=NS_OK; nsCOMPtrnewLeftTextNode; // this will be the middle text node if (0!=aStartOffset) { - result = mEditor->SplitNode(aStartNode, aStartOffset, getter_AddRefs(newLeftTextNode)); + result = Inherited::SplitNode(aStartNode, aStartOffset, getter_AddRefs(newLeftTextNode)); } if (NS_SUCCEEDED(result)) { @@ -857,7 +732,7 @@ nsTextEditor::SetTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode, endNodeAsChar->GetLength(&count); nsCOMPtrnewRightTextNode; // this will be the middle text node if ((PRInt32)count!=aEndOffset) { - result = mEditor->SplitNode(aEndNode, aEndOffset, getter_AddRefs(newRightTextNode)); + result = Inherited::SplitNode(aEndNode, aEndOffset, getter_AddRefs(newRightTextNode)); } else { newRightTextNode = do_QueryInterface(aEndNode); @@ -878,18 +753,18 @@ nsTextEditor::SetTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode, if (NS_SUCCEEDED(result)) { // create the new style node, which will be the new parent for the selected nodes nsCOMPtrnewStyleNode; - result = mEditor->CreateNode(tag, aParent, offsetInParent+1, getter_AddRefs(newStyleNode)); + result = Inherited::CreateNode(tag, aParent, offsetInParent+1, getter_AddRefs(newStyleNode)); if (NS_SUCCEEDED(result)) { // move the right half of the start node into the new style node nsCOMPtrintermediateNode; result = aStartNode->GetNextSibling(getter_AddRefs(intermediateNode)); if (NS_SUCCEEDED(result)) { - result = mEditor->DeleteNode(aStartNode); + result = Inherited::DeleteNode(aStartNode); if (NS_SUCCEEDED(result)) { PRInt32 childIndex=0; - result = mEditor->InsertNode(aStartNode, newStyleNode, childIndex); + result = Inherited::InsertNode(aStartNode, newStyleNode, childIndex); childIndex++; if (NS_SUCCEEDED(result)) { // move all the intermediate nodes into the new style node @@ -903,19 +778,19 @@ nsTextEditor::SetTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode, } // get the next sibling before moving the current child!!! intermediateNode->GetNextSibling(getter_AddRefs(nextSibling)); - result = mEditor->DeleteNode(intermediateNode); + result = Inherited::DeleteNode(intermediateNode); if (NS_SUCCEEDED(result)) { - result = mEditor->InsertNode(intermediateNode, newStyleNode, childIndex); + result = Inherited::InsertNode(intermediateNode, newStyleNode, childIndex); childIndex++; } intermediateNode = do_QueryInterface(nextSibling); } if (NS_SUCCEEDED(result)) { // move the left half of the end node into the new style node - result = mEditor->DeleteNode(newRightTextNode); + result = Inherited::DeleteNode(newRightTextNode); if (NS_SUCCEEDED(result)) { - result = mEditor->InsertNode(newRightTextNode, newStyleNode, childIndex); + result = Inherited::InsertNode(newRightTextNode, newStyleNode, childIndex); } } } @@ -1008,13 +883,13 @@ nsTextEditor::SetTextPropertiesForNodeWithDifferentParents(nsIDOMRange *aRange, parentContent->IndexOf(content, offsetInParent); nsCOMPtrnewStyleNode; - result = mEditor->CreateNode(tag, parent, offsetInParent, getter_AddRefs(newStyleNode)); + result = Inherited::CreateNode(tag, parent, offsetInParent, getter_AddRefs(newStyleNode)); if (NS_SUCCEEDED(result) && newStyleNode) { nsCOMPtrcontentNode; contentNode = do_QueryInterface(content); - result = mEditor->DeleteNode(contentNode); + result = Inherited::DeleteNode(contentNode); if (NS_SUCCEEDED(result)) { - result = mEditor->InsertNode(contentNode, newStyleNode, 0); + result = Inherited::InsertNode(contentNode, newStyleNode, 0); } } } diff --git a/editor/base/nsTextEditor.h b/editor/base/nsTextEditor.h index 7cc58ecc1ae..136c0693327 100644 --- a/editor/base/nsTextEditor.h +++ b/editor/base/nsTextEditor.h @@ -22,6 +22,7 @@ #include "nsITextEditor.h" #include "nsCOMPtr.h" #include "nsIDOMEventListener.h" +#include "nsEditor.h" class nsIStyleContext; class nsIDOMRange; @@ -31,20 +32,25 @@ class nsIDOMRange; * Use to edit text represented as a DOM tree. * This class is used for editing both plain text and rich text (attributed text). */ -class nsTextEditor : public nsITextEditor +class nsTextEditor : public nsEditor, public nsITextEditor { +private: + // So we can use "Inherited::foo()" instead of "nsEditor::foo()" + typedef nsEditor Inherited; + public: // see nsITextEditor for documentation //Interfaces for addref and release and queryinterface - NS_DECL_ISUPPORTS +//NOTE macro used is for classes that inherit from +// another class. Only the base class should use NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED + + nsTextEditor(); + virtual ~nsTextEditor(); //Initialization - nsTextEditor(); - NS_IMETHOD InitTextEditor(nsIDOMDocument *aDoc, - nsIPresShell *aPresShell, - nsIEditorCallback *aCallback=nsnull); - virtual ~nsTextEditor(); + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell); // Editing Operations NS_IMETHOD SetTextProperty(nsIAtom *aProperty); @@ -112,7 +118,6 @@ protected: // Data members protected: - nsCOMPtr mEditor; nsCOMPtr mKeyListenerP; nsCOMPtr mMouseListenerP; diff --git a/editor/libeditor/base/ChangeAttributeTxn.cpp b/editor/libeditor/base/ChangeAttributeTxn.cpp index 2db140980ab..8f37b19645b 100644 --- a/editor/libeditor/base/ChangeAttributeTxn.cpp +++ b/editor/libeditor/base/ChangeAttributeTxn.cpp @@ -25,6 +25,10 @@ ChangeAttributeTxn::ChangeAttributeTxn() { } +ChangeAttributeTxn::~ChangeAttributeTxn() +{ +} + NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor, nsIDOMElement *aElement, const nsString& aAttribute, diff --git a/editor/libeditor/base/ChangeAttributeTxn.h b/editor/libeditor/base/ChangeAttributeTxn.h index 43cc18f534c..c97cf759df1 100644 --- a/editor/libeditor/base/ChangeAttributeTxn.h +++ b/editor/libeditor/base/ChangeAttributeTxn.h @@ -36,6 +36,7 @@ class ChangeAttributeTxn : public EditTxn { public: + virtual ~ChangeAttributeTxn(); /** Initialize the transaction. * @param aEditor the object providing core editing operations diff --git a/editor/libeditor/base/DeleteRangeTxn.cpp b/editor/libeditor/base/DeleteRangeTxn.cpp index 5c7bb8e8119..3661b2c5a09 100644 --- a/editor/libeditor/base/DeleteRangeTxn.cpp +++ b/editor/libeditor/base/DeleteRangeTxn.cpp @@ -75,7 +75,7 @@ NS_IMETHODIMP DeleteRangeTxn::Init(nsIEditor *aEditor, nsIDOMRange *aRange) NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad start child list"); children->GetLength(&count); } - NS_ASSERTION(mStartOffset<=count, "bad start offset"); + NS_ASSERTION(mStartOffset<=(PRInt32)count, "bad start offset"); textNode = do_QueryInterface(mEndParent, &result); if (textNode) @@ -87,7 +87,7 @@ NS_IMETHODIMP DeleteRangeTxn::Init(nsIEditor *aEditor, nsIDOMRange *aRange) NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad end child list"); children->GetLength(&count); } - NS_ASSERTION(mEndOffset<=count, "bad end offset"); + NS_ASSERTION(mEndOffset<=(PRInt32)count, "bad end offset"); if (gNoisy) printf ("DeleteRange: %d of %p to %d of %p\n", mStartOffset, (void *)mStartParent, mEndOffset, (void *)mEndParent); diff --git a/editor/libeditor/base/DeleteTextTxn.cpp b/editor/libeditor/base/DeleteTextTxn.cpp index b3a6ca7a864..b321d49b53b 100644 --- a/editor/libeditor/base/DeleteTextTxn.cpp +++ b/editor/libeditor/base/DeleteTextTxn.cpp @@ -26,6 +26,10 @@ DeleteTextTxn::DeleteTextTxn() { } +DeleteTextTxn::~DeleteTextTxn() +{ +} + NS_IMETHODIMP DeleteTextTxn::Init(nsIEditor *aEditor, nsIDOMCharacterData *aElement, PRUint32 aOffset, diff --git a/editor/libeditor/base/DeleteTextTxn.h b/editor/libeditor/base/DeleteTextTxn.h index 5be094eaebf..c0c4fca7f89 100644 --- a/editor/libeditor/base/DeleteTextTxn.h +++ b/editor/libeditor/base/DeleteTextTxn.h @@ -51,7 +51,8 @@ private: DeleteTextTxn(); public: - + virtual ~DeleteTextTxn(); + NS_IMETHOD Do(void); NS_IMETHOD Undo(void); diff --git a/editor/libeditor/base/EditTxn.cpp b/editor/libeditor/base/EditTxn.cpp index eb61c2ec0be..b0349a459c0 100644 --- a/editor/libeditor/base/EditTxn.cpp +++ b/editor/libeditor/base/EditTxn.cpp @@ -33,6 +33,10 @@ EditTxn::EditTxn() NS_INIT_REFCNT(); } +EditTxn::~EditTxn() +{ +} + NS_IMETHODIMP EditTxn::Do(void) { return NS_OK; diff --git a/editor/libeditor/base/EditTxn.h b/editor/libeditor/base/EditTxn.h index a4bc3462c7d..4323ef56bc5 100644 --- a/editor/libeditor/base/EditTxn.h +++ b/editor/libeditor/base/EditTxn.h @@ -39,6 +39,8 @@ public: NS_DECL_ISUPPORTS EditTxn(); + virtual ~EditTxn(); + NS_IMETHOD Do(void); diff --git a/editor/libeditor/base/InsertTextTxn.cpp b/editor/libeditor/base/InsertTextTxn.cpp index 7735afcad91..b7b718ae099 100644 --- a/editor/libeditor/base/InsertTextTxn.cpp +++ b/editor/libeditor/base/InsertTextTxn.cpp @@ -40,6 +40,10 @@ InsertTextTxn::InsertTextTxn() { } +InsertTextTxn::~InsertTextTxn() +{ +} + NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement, PRUint32 aOffset, const nsString& aStringToInsert, diff --git a/editor/libeditor/base/InsertTextTxn.h b/editor/libeditor/base/InsertTextTxn.h index ceb0f95d3f7..a7d482a5ce8 100644 --- a/editor/libeditor/base/InsertTextTxn.h +++ b/editor/libeditor/base/InsertTextTxn.h @@ -36,6 +36,7 @@ class nsIPresShell; class InsertTextTxn : public EditTxn { public: + virtual ~InsertTextTxn(); /** used to name aggregate transactions that consist only of a single InsertTextTxn, * or a DeleteSelection followed by an InsertTextTxn. diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 44bd59c5d84..473abf53054 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -811,32 +811,20 @@ NS_IMETHODIMP nsEditor::CreateTxnForDeleteElement(nsIDOMNode * aElement, return result; } -NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, nsISupports **aAggTxn) +NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, EditAggregateTxn **aAggTxn) { nsresult result = NS_ERROR_NULL_POINTER; if (aAggTxn) { *aAggTxn = nsnull; - EditAggregateTxn *aTxn = nsnull; + result = TransactionFactory::GetNewTransaction(kEditAggregateTxnIID, (EditTxn**)aAggTxn); - result = TransactionFactory::GetNewTransaction(kEditAggregateTxnIID, (EditTxn**)&aTxn); - - if ((NS_FAILED(result)) || !aTxn) { + if (NS_FAILED(result) || !*aAggTxn) { return NS_ERROR_OUT_OF_MEMORY; } - // Return transaction pointer - *aAggTxn = (nsISupports*)aTxn; - -#if 0 - //Test to be sure the Return the transaction pointer as nsISupports* - result = aTxn->QueryInterface(kISupportsIID, (void**)aAggTxn); - if (!NS_SUCCEEDED(result)) - return NS_ERROR_UNEXPECTED; -#endif - // Set the name for the aggregate transaction - aTxn->SetName(aTxnName); + (*aAggTxn)->SetName(aTxnName); // Get current selection and setup txn to delete it, // but only if selection exists (is not a collapsed "caret" state) @@ -850,7 +838,7 @@ NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, EditAggregateTxn *delSelTxn; result = CreateTxnForDeleteSelection(nsIEditor::eLTR, &delSelTxn); if (NS_SUCCEEDED(result) && delSelTxn) { - aTxn->AppendChild(delSelTxn); + (*aAggTxn)->AppendChild(delSelTxn); } } } @@ -864,7 +852,7 @@ nsEditor::InsertText(const nsString& aStringToInsert) { EditAggregateTxn *aggTxn = nsnull; // Create the "delete current selection" txn - nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName, (nsISupports**)&aggTxn); + nsresult result = CreateAggregateTxnForDeleteSelection(InsertTextTxn::gInsertTextTxnName, &aggTxn); if ((NS_FAILED(result)) || (nsnull==aggTxn)) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index 30c7627ec73..8b786cf45ea 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -79,10 +79,11 @@ public: /*BEGIN nsIEdieditor for more details*/ - /*interfaces for addref and release and queryinterface*/ +//Interfaces for addref and release and queryinterface +//NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsText NS_DECL_ISUPPORTS - NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell); + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell); NS_IMETHOD GetDocument(nsIDOMDocument **aDoc); @@ -243,8 +244,6 @@ protected: nsIDOMNode * aParent, PRBool aNodeToKeepIsFirst); - NS_IMETHOD CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, nsISupports **aAggTxn); - #if 0 NS_IMETHOD CreateTxnToHandleEnterKey(EditAggregateTxn **aTxn); #endif @@ -257,6 +256,17 @@ protected: NS_IMETHOD GetLeftmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode); +//Methods not exposed in nsIEditor + + /** Create an aggregate transaction for deleting current selection + * Used by all methods that need to delete current selection, + * then insert something new to replace it + * @param nsString& aTxnName is the name of the aggregated transaction + * @param EditTxn **aAggTxn is the return location of the aggregate TXN, + * with the DeleteSelectionTxn as the first child ONLY + * if there was a selection to delete. + */ + NS_IMETHOD CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, EditAggregateTxn **aAggTxn); }; diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index fd7b0a5296e..a5ebbdbb70d 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -47,366 +47,180 @@ static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID); nsHTMLEditor::nsHTMLEditor() { - NS_INIT_REFCNT(); +// Done in nsEditor +// NS_INIT_REFCNT(); } nsHTMLEditor::~nsHTMLEditor() { //the autopointers will clear themselves up. -#if 0 -// NO EVENT LISTERNERS YET - //but we need to also remove the listeners or we have a leak - //(This is identical to nsTextEditor code - if (mEditor) - { - nsCOMPtr doc; - mEditor->GetDocument(getter_AddRefs(doc)); - if (doc) - { - nsCOMPtr erP; - nsresult result = doc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP)); - if (NS_SUCCEEDED(result) && erP) - { - if (mKeyListenerP) { - erP->RemoveEventListener(mKeyListenerP, kIDOMKeyListenerIID); - } - if (mMouseListenerP) { - erP->RemoveEventListener(mMouseListenerP, kIDOMMouseListenerIID); - } - } - else - NS_NOTREACHED("~nsHTMLEditor"); - } - } -#endif } -NS_IMETHODIMP nsHTMLEditor::InitHTMLEditor(nsIDOMDocument *aDoc, - nsIPresShell *aPresShell, - nsIEditorCallback *aCallback) +// Adds appropriate AddRef, Release, and QueryInterface methods for derived class +//NS_IMPL_ISUPPORTS_INHERITED(nsHTMLEditor, nsTextEditor, nsIHTMLEditor) + +//NS_IMPL_ADDREF_INHERITED(Class, Super) +NS_IMETHODIMP_(nsrefcnt) nsHTMLEditor::AddRef(void) +{ + return Inherited::AddRef(); +} + +//NS_IMPL_RELEASE_INHERITED(Class, Super) +NS_IMETHODIMP_(nsrefcnt) nsHTMLEditor::Release(void) +{ + return Inherited::Release(); +} + +//NS_IMPL_QUERY_INTERFACE_INHERITED(Class, Super, AdditionalInterface) +NS_IMETHODIMP nsHTMLEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if (!aInstancePtr) return NS_ERROR_NULL_POINTER; + + if (aIID.Equals(nsIHTMLEditor::GetIID())) { + *aInstancePtr = NS_STATIC_CAST(nsIHTMLEditor*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + return Inherited::QueryInterface(aIID, aInstancePtr); +} + + +NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell) { NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg"); nsresult result=NS_ERROR_NULL_POINTER; if ((nsnull!=aDoc) && (nsnull!=aPresShell)) { - nsITextEditor *aTextEditor = nsnull; - result = nsRepository::CreateInstance(kTextEditorCID, nsnull, - kITextEditorIID, (void **)&aTextEditor); - - if (NS_FAILED(result) || !aTextEditor) { - return NS_ERROR_OUT_OF_MEMORY; - } - mTextEditor = do_QueryInterface(aTextEditor); // CreateInstance did our addRef - - // Initialize nsTextEditor -- this will create and initialize the base nsEditor - // Note: nsTextEditor adds its own key, mouse, and DOM listners -- is that OK? - result = mTextEditor->InitTextEditor(aDoc, aPresShell); - if (NS_OK != result) { - return result; - } - mTextEditor->EnableUndo(PR_TRUE); - - // Get the pointer to the base editor for easier access - result = mTextEditor->QueryInterface(kIEditorIID, getter_AddRefs(mEditor)); - if (NS_OK != result) { - return result; - } - result = NS_OK; + return Inherited::Init(aDoc, aPresShell); } return result; } NS_IMETHODIMP nsHTMLEditor::SetTextProperty(nsIAtom *aProperty) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->SetTextProperty(aProperty); - } - return result; + return Inherited::SetTextProperty(aProperty); } NS_IMETHODIMP nsHTMLEditor::GetTextProperty(nsIAtom *aProperty, PRBool &aAny, PRBool &aAll) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->GetTextProperty(aProperty, aAny, aAll); - } - return result; + return Inherited::GetTextProperty(aProperty, aAny, aAll); } NS_IMETHODIMP nsHTMLEditor::RemoveTextProperty(nsIAtom *aProperty) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->RemoveTextProperty(aProperty); - } - return result; + return Inherited::RemoveTextProperty(aProperty); } NS_IMETHODIMP nsHTMLEditor::DeleteSelection(nsIEditor::Direction aDir) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->DeleteSelection(aDir); - } - return result; + return Inherited::DeleteSelection(aDir); } NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->InsertText(aStringToInsert); - } - return result; + return Inherited::InsertText(aStringToInsert); } NS_IMETHODIMP nsHTMLEditor::InsertBreak(PRBool aCtrlKey) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->InsertBreak(aCtrlKey); - } - return result; + return Inherited::InsertBreak(aCtrlKey); } // Methods shared with the base editor. // Note: We could call each of these via nsTextEditor -- is that better? NS_IMETHODIMP nsHTMLEditor::EnableUndo(PRBool aEnable) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->EnableUndo(aEnable); - } - return result; + return Inherited::EnableUndo(aEnable); } NS_IMETHODIMP nsHTMLEditor::Undo(PRUint32 aCount) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->Undo(aCount); - } - return result; + return Inherited::Undo(aCount); } NS_IMETHODIMP nsHTMLEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->CanUndo(aIsEnabled, aCanUndo); - } - return result; + return Inherited::CanUndo(aIsEnabled, aCanUndo); } NS_IMETHODIMP nsHTMLEditor::Redo(PRUint32 aCount) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->Redo(aCount); - } - return result; + return Inherited::Redo(aCount); } NS_IMETHODIMP nsHTMLEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->CanRedo(aIsEnabled, aCanRedo); - } - return result; + return Inherited::CanRedo(aIsEnabled, aCanRedo); } NS_IMETHODIMP nsHTMLEditor::BeginTransaction() { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->BeginTransaction(); - } - return result; + return Inherited::BeginTransaction(); } NS_IMETHODIMP nsHTMLEditor::EndTransaction() { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mEditor->EndTransaction(); - } - return result; + return Inherited::EndTransaction(); } NS_IMETHODIMP nsHTMLEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->MoveSelectionUp(aIncrement, aExtendSelection); - } - return result; + return Inherited::MoveSelectionUp(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->MoveSelectionDown(aIncrement, aExtendSelection); - } - return result; + return Inherited::MoveSelectionDown(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->MoveSelectionNext(aIncrement, aExtendSelection); - } - return result; + return Inherited::MoveSelectionNext(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->MoveSelectionPrevious(aIncrement, aExtendSelection); - } - return result; + return Inherited::MoveSelectionPrevious(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->SelectNext(aIncrement, aExtendSelection); - } - return result; + return Inherited::SelectNext(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->SelectPrevious(aIncrement, aExtendSelection); - } - return result; + return Inherited::SelectPrevious(aIncrement, aExtendSelection); } NS_IMETHODIMP nsHTMLEditor::ScrollUp(nsIAtom *aIncrement) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->ScrollUp(aIncrement); - } - return result; + return Inherited::ScrollUp(aIncrement); } NS_IMETHODIMP nsHTMLEditor::ScrollDown(nsIAtom *aIncrement) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->ScrollDown(aIncrement); - } - return result; + return Inherited::ScrollDown(aIncrement); } NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->ScrollIntoView(aScrollToBegin); - } - return result; + return Inherited::ScrollIntoView(aScrollToBegin); } NS_IMETHODIMP nsHTMLEditor::Insert(nsIInputStream *aInputStream) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->Insert(aInputStream); - } - return result; + return Inherited::Insert(aInputStream); } NS_IMETHODIMP nsHTMLEditor::OutputText(nsIOutputStream *aOutputStream) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->OutputText(aOutputStream); - } - return result; + return Inherited::OutputText(aOutputStream); } NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsIOutputStream *aOutputStream) { - nsresult result=NS_ERROR_NOT_INITIALIZED; - if (mEditor) - { - result = mTextEditor->OutputHTML(aOutputStream); - } - return result; -} - - -NS_IMPL_ADDREF(nsHTMLEditor) - -NS_IMPL_RELEASE(nsHTMLEditor) - -NS_IMETHODIMP -nsHTMLEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (nsnull == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*)(nsISupports*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(kIHTMLEditorIID)) { - *aInstancePtr = (void*)(nsIHTMLEditor*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - // If our pointer to nsTextEditor is null, don't bother querying? - if (aIID.Equals(kITextEditorIID) && (mTextEditor)) { - nsCOMPtr editor; - nsresult result = mTextEditor->QueryInterface(kITextEditorIID, getter_AddRefs(editor)); - if (NS_SUCCEEDED(result) && editor) { - *aInstancePtr = (void*)editor; - return NS_OK; - } - } - if (aIID.Equals(kIEditorIID) && (mEditor)) { - nsCOMPtr editor; - nsresult result = mEditor->QueryInterface(kIEditorIID, getter_AddRefs(editor)); - if (NS_SUCCEEDED(result) && editor) { - *aInstancePtr = (void*)editor; - return NS_OK; - } - } - return NS_NOINTERFACE; + return Inherited::OutputHTML(aOutputStream); } //================================================================ diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index fe6cc2dfb0f..fdfafe4b726 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -20,6 +20,7 @@ #define nsHTMLEditor_h__ #include "nsITextEditor.h" +#include "nsTextEditor.h" #include "nsIHTMLEditor.h" #include "nsCOMPtr.h" #include "nsIDOMEventListener.h" @@ -29,20 +30,25 @@ * The HTML editor implementation.
* Use to edit HTML document represented as a DOM tree. */ -class nsHTMLEditor : public nsIHTMLEditor +class nsHTMLEditor : public nsTextEditor, public nsIHTMLEditor { +private: + // So we can use "Inherited::foo()" instead of "nsTextEditor::foo()" + typedef nsTextEditor Inherited; + public: // see nsIHTMLEditor for documentation //Interfaces for addref and release and queryinterface - NS_DECL_ISUPPORTS +//NOTE macro used is for classes that inherit from +// another class. Only the base class should use NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED + + nsHTMLEditor(); + virtual ~nsHTMLEditor(); //Initialization - nsHTMLEditor(); - NS_IMETHOD InitHTMLEditor(nsIDOMDocument *aDoc, - nsIPresShell *aPresShell, - nsIEditorCallback *aCallback=nsnull); - virtual ~nsHTMLEditor(); + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell); //============================================================================ // Methods that are duplicates of nsTextEditor -- exposed here for convenience @@ -103,8 +109,6 @@ public: // Data members protected: - nsCOMPtr mEditor; - nsCOMPtr mTextEditor; // EVENT LISTENERS AND COMMAND ROUTING NEEDS WORK // For now, the listners are tied to the nsTextEditor class diff --git a/editor/public/nsIEditor.h b/editor/public/nsIEditor.h index 443f7b83fb5..47b1a6a3eee 100644 --- a/editor/public/nsIEditor.h +++ b/editor/public/nsIEditor.h @@ -72,14 +72,13 @@ public: /** * Init tells is to tell the implementation of nsIEditor to begin its services - * @param aDomInterface The dom interface being observed + * @param aDoc The dom document interface being observed * @param aPresShell TEMP: The presentation shell displaying the document * once events can tell us from what pres shell they originated, * this will no longer be necessary and the editor will no longer be * linked to a single pres shell. */ - NS_IMETHOD Init(nsIDOMDocument *aDomInterface, - nsIPresShell *aPresShell) = 0; + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell )=0; /** * return the DOM Document this editor is associated with @@ -303,15 +302,6 @@ public: */ NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin)=0; - /** Create an aggregate transaction for deleting current selection - * Used by all methods that need to delete current selection, - * then insert something new to replace it - * @param nsString& aTxnName is the name of the aggregated transaction - * @param EditTxn **aAggTxn is the return location of the aggregate TXN, - * with the DeleteSelectionTxn as the first child ONLY - * if there was a selection to delete. - */ - NS_IMETHOD CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, nsISupports **aAggTxn)=0; }; #endif //nsIEditor_h__ diff --git a/editor/public/nsIHTMLEditor.h b/editor/public/nsIHTMLEditor.h index 9f085b267dd..8909084407f 100644 --- a/editor/public/nsIHTMLEditor.h +++ b/editor/public/nsIHTMLEditor.h @@ -46,9 +46,7 @@ public: /** Initialize the text editor * */ - NS_IMETHOD InitHTMLEditor(nsIDOMDocument *aDoc, - nsIPresShell *aPresShell, - nsIEditorCallback *aCallback=nsnull)=0; + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell )=0; // Methods shared with nsITextEditor (see nsITextEditor.h for details) NS_IMETHOD SetTextProperty(nsIAtom *aProperty)=0; diff --git a/editor/public/nsITextEditor.h b/editor/public/nsITextEditor.h index 657d9634f59..1daa84d6b8f 100644 --- a/editor/public/nsITextEditor.h +++ b/editor/public/nsITextEditor.h @@ -53,9 +53,7 @@ public: /** Initialize the text editor * */ - NS_IMETHOD InitTextEditor(nsIDOMDocument *aDoc, - nsIPresShell *aPresShell, - nsIEditorCallback *aCallback=nsnull)=0; + NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell)=0; /** * SetTextProperties() sets the aggregate properties on the current selection