Changed editor classes to inherited model. Fixed lots of destructor warnings.

This commit is contained in:
cmanske%netscape.com 1999-03-05 21:05:35 +00:00
Родитель 632d7ed2ea
Коммит 06356ad73a
52 изменённых файлов: 629 добавлений и 1136 удалений

Просмотреть файл

@ -25,6 +25,10 @@ ChangeAttributeTxn::ChangeAttributeTxn()
{
}
ChangeAttributeTxn::~ChangeAttributeTxn()
{
}
NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor,
nsIDOMElement *aElement,
const nsString& aAttribute,

Просмотреть файл

@ -36,6 +36,7 @@
class ChangeAttributeTxn : public EditTxn
{
public:
virtual ~ChangeAttributeTxn();
/** Initialize the transaction.
* @param aEditor the object providing core editing operations

Просмотреть файл

@ -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);

Просмотреть файл

@ -40,6 +40,10 @@ DeleteTableCellTxn::DeleteTableCellTxn()
{
}
DeleteTableCellTxn::~DeleteTableCellTxn()
{
}
NS_IMETHODIMP DeleteTableCellTxn::Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)

Просмотреть файл

@ -58,7 +58,8 @@ private:
DeleteTableCellTxn();
public:
virtual ~DeleteTableCellTxn();
NS_IMETHOD Do(void);
NS_IMETHOD Undo(void);

Просмотреть файл

@ -40,6 +40,10 @@ DeleteTableColumnTxn::DeleteTableColumnTxn()
{
}
DeleteTableColumnTxn::~DeleteTableColumnTxn()
{
}
NS_IMETHODIMP DeleteTableColumnTxn::Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)

Просмотреть файл

@ -58,6 +58,7 @@ private:
DeleteTableColumnTxn();
public:
virtual ~DeleteTableColumnTxn();
NS_IMETHOD Do(void);

Просмотреть файл

@ -40,6 +40,10 @@ DeleteTableRowTxn::DeleteTableRowTxn()
{
}
DeleteTableRowTxn::~DeleteTableRowTxn()
{
}
NS_IMETHODIMP DeleteTableRowTxn::Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)

Просмотреть файл

@ -59,6 +59,7 @@ private:
DeleteTableRowTxn();
public:
virtual ~DeleteTableRowTxn();
NS_IMETHOD Do(void);

Просмотреть файл

@ -40,6 +40,10 @@ DeleteTableTxn::DeleteTableTxn()
{
}
DeleteTableTxn::~DeleteTableTxn()
{
}
NS_IMETHODIMP DeleteTableTxn::Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)

Просмотреть файл

@ -58,7 +58,8 @@ private:
DeleteTableTxn();
public:
virtual ~DeleteTableTxn();
NS_IMETHOD Do(void);
NS_IMETHOD Undo(void);

Просмотреть файл

@ -26,6 +26,10 @@ DeleteTextTxn::DeleteTextTxn()
{
}
DeleteTextTxn::~DeleteTextTxn()
{
}
NS_IMETHODIMP DeleteTextTxn::Init(nsIEditor *aEditor,
nsIDOMCharacterData *aElement,
PRUint32 aOffset,

Просмотреть файл

@ -51,7 +51,8 @@ private:
DeleteTextTxn();
public:
virtual ~DeleteTextTxn();
NS_IMETHOD Do(void);
NS_IMETHOD Undo(void);

Просмотреть файл

@ -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<nsIDOMNode> newNode;
nsAutoString tag("td");
result = mEditor->DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
nsCOMPtr<nsIDOMNode> newNode;
nsAutoString tag("table");
result = DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
if( NS_SUCCEEDED(result))
{
nsAutoString tag("tr");
nsCOMPtr<nsIDOMNode> ParentNode;
ParentNode = newNode;
result = nsEditor::CreateNode(tag, ParentNode, 0, getter_AddRefs(newNode));
if( NS_SUCCEEDED(result))
{
nsAutoString tag("tr");
nsCOMPtr<nsIDOMNode> 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;
}

Просмотреть файл

@ -33,6 +33,10 @@ EditTxn::EditTxn()
NS_INIT_REFCNT();
}
EditTxn::~EditTxn()
{
}
NS_IMETHODIMP EditTxn::Do(void)
{
return NS_OK;

Просмотреть файл

@ -39,6 +39,8 @@ public:
NS_DECL_ISUPPORTS
EditTxn();
virtual ~EditTxn();
NS_IMETHOD Do(void);

Просмотреть файл

@ -40,6 +40,10 @@ InsertTableCellTxn::InsertTableCellTxn()
{
}
InsertTableCellTxn::~InsertTableCellTxn()
{
}
NS_IMETHODIMP InsertTableCellTxn::Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,

Просмотреть файл

@ -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.

Просмотреть файл

@ -40,6 +40,10 @@ InsertTableColumnTxn::InsertTableColumnTxn()
{
}
InsertTableColumnTxn::~InsertTableColumnTxn()
{
}
NS_IMETHODIMP InsertTableColumnTxn::Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,

Просмотреть файл

@ -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.

Просмотреть файл

@ -40,6 +40,10 @@ InsertTableRowTxn::InsertTableRowTxn()
{
}
InsertTableRowTxn::~InsertTableRowTxn()
{
}
NS_IMETHODIMP InsertTableRowTxn::Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,

Просмотреть файл

@ -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.

Просмотреть файл

@ -40,6 +40,10 @@ InsertTableTxn::InsertTableTxn()
{
}
InsertTableTxn::~InsertTableTxn()
{
}
NS_IMETHODIMP InsertTableTxn::Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
nsIDOMNode *aNode,

Просмотреть файл

@ -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.

Просмотреть файл

@ -40,6 +40,10 @@ InsertTextTxn::InsertTextTxn()
{
}
InsertTextTxn::~InsertTextTxn()
{
}
NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
const nsString& aStringToInsert,

Просмотреть файл

@ -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.

Просмотреть файл

@ -40,6 +40,10 @@ JoinTableCellsTxn::JoinTableCellsTxn()
{
}
JoinTableCellsTxn::~JoinTableCellsTxn()
{
}
NS_IMETHODIMP JoinTableCellsTxn::Init(nsIDOMCharacterData *aElement,
nsIDOMNode *aNode,
nsIPresShell* aPresShell)

Просмотреть файл

@ -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.
*/

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -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)) )

Просмотреть файл

@ -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<nsIDOMDocument> doc;
mEditor->GetDocument(getter_AddRefs(doc));
if (doc)
{
nsCOMPtr<nsIDOMEventReceiver> 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<nsIEditor> 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<nsIEditor> 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);
}
//================================================================

Просмотреть файл

@ -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.<br>
* 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<nsIEditor> mEditor;
nsCOMPtr<nsITextEditor> mTextEditor;
// EVENT LISTENERS AND COMMAND ROUTING NEEDS WORK
// For now, the listners are tied to the nsTextEditor class

Просмотреть файл

@ -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;

Просмотреть файл

@ -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<nsIDOMDocument> doc;
Inherited::GetDocument(getter_AddRefs(doc));
if (doc)
{
nsCOMPtr<nsIDOMDocument> doc;
mEditor->GetDocument(getter_AddRefs(doc));
if (doc)
nsCOMPtr<nsIDOMEventReceiver> erP;
nsresult result = doc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP));
if (NS_SUCCEEDED(result) && erP)
{
nsCOMPtr<nsIDOMEventReceiver> 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<nsIDOMEventReceiver> 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)
nsCOMPtr<nsIDOMSelection>selection;
result = Inherited::GetSelection(getter_AddRefs(selection));
if ((NS_SUCCEEDED(result)) && selection)
{
nsCOMPtr<nsIDOMSelection>selection;
result = mEditor->GetSelection(getter_AddRefs(selection));
if ((NS_SUCCEEDED(result)) && selection)
Inherited::BeginTransaction();
nsCOMPtr<nsIEnumerator> enumerator;
enumerator = do_QueryInterface(selection, &result);
if ((NS_SUCCEEDED(result)) && enumerator)
{
mEditor->BeginTransaction();
nsCOMPtr<nsIEnumerator> enumerator;
enumerator = do_QueryInterface(selection, &result);
if ((NS_SUCCEEDED(result)) && enumerator)
enumerator->First();
nsISupports *currentItem;
result = enumerator->CurrentItem(&currentItem);
if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem))
{
enumerator->First();
nsISupports *currentItem;
result = enumerator->CurrentItem(&currentItem);
if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem))
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
nsCOMPtr<nsIDOMNode>commonParent;
result = range->GetCommonParent(getter_AddRefs(commonParent));
if ((NS_SUCCEEDED(result)) && commonParent)
{
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
nsCOMPtr<nsIDOMNode>commonParent;
result = range->GetCommonParent(getter_AddRefs(commonParent));
if ((NS_SUCCEEDED(result)) && commonParent)
PRInt32 startOffset, endOffset;
range->GetStartOffset(&startOffset);
range->GetEndOffset(&endOffset);
nsCOMPtr<nsIDOMNode> startParent; nsCOMPtr<nsIDOMNode> 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<nsIDOMNode> startParent; nsCOMPtr<nsIDOMNode> 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<nsIDOMNode> startGrandParent;
startParent->GetParentNode(getter_AddRefs(startGrandParent));
nsCOMPtr<nsIDOMNode> endGrandParent;
endParent->GetParentNode(getter_AddRefs(endGrandParent));
if (NS_SUCCEEDED(result))
{
nsCOMPtr<nsIDOMNode> startGrandParent;
startParent->GetParentNode(getter_AddRefs(startGrandParent));
nsCOMPtr<nsIDOMNode> 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)
nsCOMPtr<nsIDOMSelection>selection;
result = Inherited::GetSelection(getter_AddRefs(selection));
if ((NS_SUCCEEDED(result)) && selection)
{
nsCOMPtr<nsIDOMSelection>selection;
result = mEditor->GetSelection(getter_AddRefs(selection));
if ((NS_SUCCEEDED(result)) && selection)
nsCOMPtr<nsIEnumerator> enumerator;
enumerator = do_QueryInterface(selection, &result);
if ((NS_SUCCEEDED(result)) && enumerator)
{
nsCOMPtr<nsIEnumerator> enumerator;
enumerator = do_QueryInterface(selection, &result);
if ((NS_SUCCEEDED(result)) && enumerator)
enumerator->First();
nsISupports *currentItem;
result = enumerator->CurrentItem(&currentItem);
if ((NS_SUCCEEDED(result)) && currentItem)
{
enumerator->First();
nsISupports *currentItem;
result = enumerator->CurrentItem(&currentItem);
if ((NS_SUCCEEDED(result)) && currentItem)
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
nsCOMPtr<nsIContentIterator> iter;
result = nsRepository::CreateInstance(kCContentIteratorCID, nsnull,
kIContentIteratorIID,
getter_AddRefs(iter));
if ((NS_SUCCEEDED(result)) && iter)
{
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
nsCOMPtr<nsIContentIterator> 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<nsIContent> 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<nsIContent> content;
result = iter->CurrentNode(getter_AddRefs(content));
int i=0;
while (NS_COMFALSE == iter->IsDone())
nsCOMPtr<nsIDOMCharacterData>text;
text = do_QueryInterface(content);
if (text)
{
nsCOMPtr<nsIDOMCharacterData>text;
text = do_QueryInterface(content);
if (text)
nsCOMPtr<nsIPresShell>presShell;
Inherited::GetPresShell(getter_AddRefs(presShell));
NS_ASSERTION(presShell, "bad state, null pres shell");
if (presShell)
{
nsCOMPtr<nsIPresShell>presShell;
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<nsIStyleContext> sc;
result = presShell->GetStyleContextFor(frame, getter_AddRefs(sc));
if ((NS_SUCCEEDED(result)) && sc)
{
nsCOMPtr<nsIStyleContext> 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<nsIDOMNode> newNode;
nsAutoString tag("BR");
mEditor->DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
// Are we supposed to release newNode?
nsCOMPtr<nsIDOMNode> 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<nsIDocument> doc;
shell->GetDocument(getter_AddRefs(doc));
if (doc) {
nsString buffer;
nsIPresShell* shell = nsnull;
Inherited::GetPresShell(&shell);
doc->CreateXIF(buffer);
if (nsnull != shell) {
nsCOMPtr<nsIDocument> 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<nsIDocument> doc;
shell->GetDocument(getter_AddRefs(doc));
if (doc) {
nsString buffer;
nsIPresShell* shell = nsnull;
Inherited::GetPresShell(&shell);
doc->CreateXIF(buffer);
if (nsnull != shell) {
nsCOMPtr<nsIDocument> 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<nsIEditor> 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,
nsCOMPtr<nsIDOMNode>newTextNode; // 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))
{
nsCOMPtr<nsIDOMNode>newStyleNode;
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;
nsCOMPtr<nsIDOMNode>newLeftTextNode; // 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);
nsCOMPtr<nsIDOMNode>newRightTextNode; // 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
nsCOMPtr<nsIDOMNode>newStyleNode;
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
nsCOMPtr<nsIDOMNode>intermediateNode;
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);
nsCOMPtr<nsIDOMNode>newStyleNode;
result = mEditor->CreateNode(tag, parent, offsetInParent, getter_AddRefs(newStyleNode));
result = Inherited::CreateNode(tag, parent, offsetInParent, getter_AddRefs(newStyleNode));
if (NS_SUCCEEDED(result) && newStyleNode) {
nsCOMPtr<nsIDOMNode>contentNode;
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);
}
}
}

Просмотреть файл

@ -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<nsIEditor> mEditor;
nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
nsCOMPtr<nsIDOMEventListener> mMouseListenerP;

Просмотреть файл

@ -25,6 +25,10 @@ ChangeAttributeTxn::ChangeAttributeTxn()
{
}
ChangeAttributeTxn::~ChangeAttributeTxn()
{
}
NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor,
nsIDOMElement *aElement,
const nsString& aAttribute,

Просмотреть файл

@ -36,6 +36,7 @@
class ChangeAttributeTxn : public EditTxn
{
public:
virtual ~ChangeAttributeTxn();
/** Initialize the transaction.
* @param aEditor the object providing core editing operations

Просмотреть файл

@ -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);

Просмотреть файл

@ -26,6 +26,10 @@ DeleteTextTxn::DeleteTextTxn()
{
}
DeleteTextTxn::~DeleteTextTxn()
{
}
NS_IMETHODIMP DeleteTextTxn::Init(nsIEditor *aEditor,
nsIDOMCharacterData *aElement,
PRUint32 aOffset,

Просмотреть файл

@ -51,7 +51,8 @@ private:
DeleteTextTxn();
public:
virtual ~DeleteTextTxn();
NS_IMETHOD Do(void);
NS_IMETHOD Undo(void);

Просмотреть файл

@ -33,6 +33,10 @@ EditTxn::EditTxn()
NS_INIT_REFCNT();
}
EditTxn::~EditTxn()
{
}
NS_IMETHODIMP EditTxn::Do(void)
{
return NS_OK;

Просмотреть файл

@ -39,6 +39,8 @@ public:
NS_DECL_ISUPPORTS
EditTxn();
virtual ~EditTxn();
NS_IMETHOD Do(void);

Просмотреть файл

@ -40,6 +40,10 @@ InsertTextTxn::InsertTextTxn()
{
}
InsertTextTxn::~InsertTextTxn()
{
}
NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement,
PRUint32 aOffset,
const nsString& aStringToInsert,

Просмотреть файл

@ -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.

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -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<nsIDOMDocument> doc;
mEditor->GetDocument(getter_AddRefs(doc));
if (doc)
{
nsCOMPtr<nsIDOMEventReceiver> 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<nsIEditor> 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<nsIEditor> 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);
}
//================================================================

Просмотреть файл

@ -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.<br>
* 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<nsIEditor> mEditor;
nsCOMPtr<nsITextEditor> mTextEditor;
// EVENT LISTENERS AND COMMAND ROUTING NEEDS WORK
// For now, the listners are tied to the nsTextEditor class

Просмотреть файл

@ -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__

Просмотреть файл

@ -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;

Просмотреть файл

@ -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