зеркало из https://github.com/mozilla/pjs.git
Changed editor classes to inherited model. Fixed lots of destructor warnings.
This commit is contained in:
Родитель
632d7ed2ea
Коммит
06356ad73a
|
@ -25,6 +25,10 @@ ChangeAttributeTxn::ChangeAttributeTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChangeAttributeTxn::~ChangeAttributeTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor,
|
NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor,
|
||||||
nsIDOMElement *aElement,
|
nsIDOMElement *aElement,
|
||||||
const nsString& aAttribute,
|
const nsString& aAttribute,
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
class ChangeAttributeTxn : public EditTxn
|
class ChangeAttributeTxn : public EditTxn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~ChangeAttributeTxn();
|
||||||
|
|
||||||
/** Initialize the transaction.
|
/** Initialize the transaction.
|
||||||
* @param aEditor the object providing core editing operations
|
* @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");
|
NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad start child list");
|
||||||
children->GetLength(&count);
|
children->GetLength(&count);
|
||||||
}
|
}
|
||||||
NS_ASSERTION(mStartOffset<=count, "bad start offset");
|
NS_ASSERTION(mStartOffset<=(PRInt32)count, "bad start offset");
|
||||||
|
|
||||||
textNode = do_QueryInterface(mEndParent, &result);
|
textNode = do_QueryInterface(mEndParent, &result);
|
||||||
if (textNode)
|
if (textNode)
|
||||||
|
@ -87,7 +87,7 @@ NS_IMETHODIMP DeleteRangeTxn::Init(nsIEditor *aEditor, nsIDOMRange *aRange)
|
||||||
NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad end child list");
|
NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad end child list");
|
||||||
children->GetLength(&count);
|
children->GetLength(&count);
|
||||||
}
|
}
|
||||||
NS_ASSERTION(mEndOffset<=count, "bad end offset");
|
NS_ASSERTION(mEndOffset<=(PRInt32)count, "bad end offset");
|
||||||
if (gNoisy)
|
if (gNoisy)
|
||||||
printf ("DeleteRange: %d of %p to %d of %p\n",
|
printf ("DeleteRange: %d of %p to %d of %p\n",
|
||||||
mStartOffset, (void *)mStartParent, mEndOffset, (void *)mEndParent);
|
mStartOffset, (void *)mStartParent, mEndOffset, (void *)mEndParent);
|
||||||
|
|
|
@ -40,6 +40,10 @@ DeleteTableCellTxn::DeleteTableCellTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteTableCellTxn::~DeleteTableCellTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP DeleteTableCellTxn::Init(nsIDOMCharacterData *aElement,
|
NS_IMETHODIMP DeleteTableCellTxn::Init(nsIDOMCharacterData *aElement,
|
||||||
nsIDOMNode *aNode,
|
nsIDOMNode *aNode,
|
||||||
nsIPresShell* aPresShell)
|
nsIPresShell* aPresShell)
|
||||||
|
|
|
@ -58,7 +58,8 @@ private:
|
||||||
DeleteTableCellTxn();
|
DeleteTableCellTxn();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual ~DeleteTableCellTxn();
|
||||||
|
|
||||||
NS_IMETHOD Do(void);
|
NS_IMETHOD Do(void);
|
||||||
|
|
||||||
NS_IMETHOD Undo(void);
|
NS_IMETHOD Undo(void);
|
||||||
|
|
|
@ -40,6 +40,10 @@ DeleteTableColumnTxn::DeleteTableColumnTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteTableColumnTxn::~DeleteTableColumnTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP DeleteTableColumnTxn::Init(nsIDOMCharacterData *aElement,
|
NS_IMETHODIMP DeleteTableColumnTxn::Init(nsIDOMCharacterData *aElement,
|
||||||
nsIDOMNode *aNode,
|
nsIDOMNode *aNode,
|
||||||
nsIPresShell* aPresShell)
|
nsIPresShell* aPresShell)
|
||||||
|
|
|
@ -58,6 +58,7 @@ private:
|
||||||
DeleteTableColumnTxn();
|
DeleteTableColumnTxn();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual ~DeleteTableColumnTxn();
|
||||||
|
|
||||||
NS_IMETHOD Do(void);
|
NS_IMETHOD Do(void);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,10 @@ DeleteTableRowTxn::DeleteTableRowTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteTableRowTxn::~DeleteTableRowTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP DeleteTableRowTxn::Init(nsIDOMCharacterData *aElement,
|
NS_IMETHODIMP DeleteTableRowTxn::Init(nsIDOMCharacterData *aElement,
|
||||||
nsIDOMNode *aNode,
|
nsIDOMNode *aNode,
|
||||||
nsIPresShell* aPresShell)
|
nsIPresShell* aPresShell)
|
||||||
|
|
|
@ -59,6 +59,7 @@ private:
|
||||||
DeleteTableRowTxn();
|
DeleteTableRowTxn();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual ~DeleteTableRowTxn();
|
||||||
|
|
||||||
NS_IMETHOD Do(void);
|
NS_IMETHOD Do(void);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,10 @@ DeleteTableTxn::DeleteTableTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteTableTxn::~DeleteTableTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP DeleteTableTxn::Init(nsIDOMCharacterData *aElement,
|
NS_IMETHODIMP DeleteTableTxn::Init(nsIDOMCharacterData *aElement,
|
||||||
nsIDOMNode *aNode,
|
nsIDOMNode *aNode,
|
||||||
nsIPresShell* aPresShell)
|
nsIPresShell* aPresShell)
|
||||||
|
|
|
@ -58,7 +58,8 @@ private:
|
||||||
DeleteTableTxn();
|
DeleteTableTxn();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual ~DeleteTableTxn();
|
||||||
|
|
||||||
NS_IMETHOD Do(void);
|
NS_IMETHOD Do(void);
|
||||||
|
|
||||||
NS_IMETHOD Undo(void);
|
NS_IMETHOD Undo(void);
|
||||||
|
|
|
@ -26,6 +26,10 @@ DeleteTextTxn::DeleteTextTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteTextTxn::~DeleteTextTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP DeleteTextTxn::Init(nsIEditor *aEditor,
|
NS_IMETHODIMP DeleteTextTxn::Init(nsIEditor *aEditor,
|
||||||
nsIDOMCharacterData *aElement,
|
nsIDOMCharacterData *aElement,
|
||||||
PRUint32 aOffset,
|
PRUint32 aOffset,
|
||||||
|
|
|
@ -51,7 +51,8 @@ private:
|
||||||
DeleteTextTxn();
|
DeleteTextTxn();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual ~DeleteTextTxn();
|
||||||
|
|
||||||
NS_IMETHOD Do(void);
|
NS_IMETHOD Do(void);
|
||||||
|
|
||||||
NS_IMETHOD Undo(void);
|
NS_IMETHOD Undo(void);
|
||||||
|
|
|
@ -79,65 +79,32 @@ static NS_DEFINE_IID(kJoinTableCellsTxnIID, JOIN_CELLS_TXN_IID);
|
||||||
NS_IMETHODIMP nsHTMLEditor::InsertTable()
|
NS_IMETHODIMP nsHTMLEditor::InsertTable()
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||||
#if 0
|
//#if 0
|
||||||
if (mEditor)
|
result = nsEditor::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
|
|
||||||
result = mEditor->BeginTransaction();
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> newNode;
|
nsCOMPtr<nsIDOMNode> newNode;
|
||||||
nsAutoString tag("td");
|
nsAutoString tag("table");
|
||||||
result = mEditor->DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
|
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))
|
if( NS_SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
nsAutoString tag("tr");
|
nsAutoString tag("td");
|
||||||
nsCOMPtr<nsIDOMNode> ParentNode;
|
|
||||||
ParentNode = newNode;
|
ParentNode = newNode;
|
||||||
result = mEditor->CreateNode(tag, ParentNode, 0, getter_AddRefs(newNode));
|
result = nsEditor::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::EndTransaction();
|
||||||
|
//#endif
|
||||||
return result;
|
return result;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn)
|
NS_IMETHODIMP nsHTMLEditor::CreateTxnForInsertTable(const nsIDOMElement *aTableNode, InsertTableTxn ** aTxn)
|
||||||
{
|
{
|
||||||
if (mEditor==nsnull)
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
}
|
|
||||||
if( aTableNode == nsnull || aTxn == nsnull )
|
if( aTableNode == nsnull || aTxn == nsnull )
|
||||||
{
|
{
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
@ -193,103 +160,61 @@ NS_IMETHODIMP nsHTMLEditor::CreateTxnForInsertTable(const nsIDOMElement *aTableN
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::InsertTableCell(PRInt32 aNumber, PRBool aAfter)
|
NS_IMETHODIMP nsHTMLEditor::InsertTableCell(PRInt32 aNumber, PRBool aAfter)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter)
|
NS_IMETHODIMP nsHTMLEditor::InsertTableColumn(PRInt32 aNumber, PRBool aAfter)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter)
|
NS_IMETHODIMP nsHTMLEditor::InsertTableRow(PRInt32 aNumber, PRBool aAfter)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::DeleteTable()
|
NS_IMETHODIMP nsHTMLEditor::DeleteTable()
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::DeleteTableCell(PRInt32 aNumber)
|
NS_IMETHODIMP nsHTMLEditor::DeleteTableCell(PRInt32 aNumber)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber)
|
NS_IMETHODIMP nsHTMLEditor::DeleteTableColumn(PRInt32 aNumber)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::DeleteTableRow(PRInt32 aNumber)
|
NS_IMETHODIMP nsHTMLEditor::DeleteTableRow(PRInt32 aNumber)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||||
if (mEditor)
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::JoinTableCells(PRBool aCellToRight)
|
NS_IMETHODIMP nsHTMLEditor::JoinTableCells(PRBool aCellToRight)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex)
|
NS_IMETHODIMP nsHTMLEditor::GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
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
|
||||||
aCellIndex=0; // initialize out param
|
nsISupports *layoutObject=nsnull; // frames are not ref counted, so don't use an nsCOMPtr
|
||||||
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))
|
if ((NS_SUCCEEDED(result)) && (nsnull!=layoutObject))
|
||||||
{ // get the table cell interface from the frame
|
{ // get the table cell interface from the frame
|
||||||
nsITableCellLayout *cellLayoutObject=nsnull; // again, frames are not ref-counted
|
nsITableCellLayout *cellLayoutObject=nsnull; // again, frames are not ref-counted
|
||||||
result = layoutObject->QueryInterface(nsITableCellLayout::GetIID(), (void**)(&cellLayoutObject));
|
result = layoutObject->QueryInterface(nsITableCellLayout::GetIID(), (void**)(&cellLayoutObject));
|
||||||
if ((NS_SUCCEEDED(result)) && (nsnull!=cellLayoutObject))
|
if ((NS_SUCCEEDED(result)) && (nsnull!=cellLayoutObject))
|
||||||
{ // get the index
|
{ // get the index
|
||||||
result = cellLayoutObject->GetColIndex(aCellIndex);
|
result = cellLayoutObject->GetColIndex(aCellIndex);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -297,55 +222,30 @@ NS_IMETHODIMP nsHTMLEditor::GetColIndexForCell(nsIDOMNode *aCellNode, PRInt32 &a
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::GetRowIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex)
|
NS_IMETHODIMP nsHTMLEditor::GetRowIndexForCell(nsIDOMNode *aCellNode, PRInt32 &aCellIndex)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode)
|
NS_IMETHODIMP nsHTMLEditor::GetFirstCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aFirstCellNode)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::GetNextCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode)
|
NS_IMETHODIMP nsHTMLEditor::GetNextCellInColumn(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::GetFirstCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aCellNode)
|
NS_IMETHODIMP nsHTMLEditor::GetFirstCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aCellNode)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::GetNextCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode)
|
NS_IMETHODIMP nsHTMLEditor::GetNextCellInRow(nsIDOMNode *aCurrentCellNode, nsIDOMNode* &aNextCellNode)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,10 @@ EditTxn::EditTxn()
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EditTxn::~EditTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP EditTxn::Do(void)
|
NS_IMETHODIMP EditTxn::Do(void)
|
||||||
{
|
{
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
@ -39,6 +39,8 @@ public:
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
EditTxn();
|
EditTxn();
|
||||||
|
virtual ~EditTxn();
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHOD Do(void);
|
NS_IMETHOD Do(void);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,10 @@ InsertTableCellTxn::InsertTableCellTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InsertTableCellTxn::~InsertTableCellTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP InsertTableCellTxn::Init(nsIDOMCharacterData *aElement,
|
NS_IMETHODIMP InsertTableCellTxn::Init(nsIDOMCharacterData *aElement,
|
||||||
PRUint32 aOffset,
|
PRUint32 aOffset,
|
||||||
nsIDOMNode *aNode,
|
nsIDOMNode *aNode,
|
||||||
|
|
|
@ -38,6 +38,7 @@ class nsIPresShell;
|
||||||
class InsertTableCellTxn : public EditTxn
|
class InsertTableCellTxn : public EditTxn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~InsertTableCellTxn();
|
||||||
|
|
||||||
/** used to name aggregate transactions that consist only of a single InsertTableCellTxn,
|
/** used to name aggregate transactions that consist only of a single InsertTableCellTxn,
|
||||||
* or a DeleteSelection followed by an InsertTableCellTxn.
|
* or a DeleteSelection followed by an InsertTableCellTxn.
|
||||||
|
|
|
@ -40,6 +40,10 @@ InsertTableColumnTxn::InsertTableColumnTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InsertTableColumnTxn::~InsertTableColumnTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP InsertTableColumnTxn::Init(nsIDOMCharacterData *aElement,
|
NS_IMETHODIMP InsertTableColumnTxn::Init(nsIDOMCharacterData *aElement,
|
||||||
PRUint32 aOffset,
|
PRUint32 aOffset,
|
||||||
nsIDOMNode *aNode,
|
nsIDOMNode *aNode,
|
||||||
|
|
|
@ -39,6 +39,7 @@ class nsIPresShell;
|
||||||
class InsertTableColumnTxn : public EditTxn
|
class InsertTableColumnTxn : public EditTxn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~InsertTableColumnTxn();
|
||||||
|
|
||||||
/** used to name aggregate transactions that consist only of a single InsertTableColumnTxn,
|
/** used to name aggregate transactions that consist only of a single InsertTableColumnTxn,
|
||||||
* or a DeleteSelection followed by an InsertTableColumnTxn.
|
* or a DeleteSelection followed by an InsertTableColumnTxn.
|
||||||
|
|
|
@ -40,6 +40,10 @@ InsertTableRowTxn::InsertTableRowTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InsertTableRowTxn::~InsertTableRowTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP InsertTableRowTxn::Init(nsIDOMCharacterData *aElement,
|
NS_IMETHODIMP InsertTableRowTxn::Init(nsIDOMCharacterData *aElement,
|
||||||
PRUint32 aOffset,
|
PRUint32 aOffset,
|
||||||
nsIDOMNode *aNode,
|
nsIDOMNode *aNode,
|
||||||
|
|
|
@ -39,6 +39,7 @@ class nsIPresShell;
|
||||||
class InsertTableRowTxn : public EditTxn
|
class InsertTableRowTxn : public EditTxn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~InsertTableRowTxn();
|
||||||
|
|
||||||
/** used to name aggregate transactions that consist only of a single InsertTableRowTxn,
|
/** used to name aggregate transactions that consist only of a single InsertTableRowTxn,
|
||||||
* or a DeleteSelection followed by an InsertTableRowTxn.
|
* or a DeleteSelection followed by an InsertTableRowTxn.
|
||||||
|
|
|
@ -40,6 +40,10 @@ InsertTableTxn::InsertTableTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InsertTableTxn::~InsertTableTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP InsertTableTxn::Init(nsIDOMCharacterData *aElement,
|
NS_IMETHODIMP InsertTableTxn::Init(nsIDOMCharacterData *aElement,
|
||||||
PRUint32 aOffset,
|
PRUint32 aOffset,
|
||||||
nsIDOMNode *aNode,
|
nsIDOMNode *aNode,
|
||||||
|
|
|
@ -38,6 +38,7 @@ class nsIPresShell;
|
||||||
class InsertTableTxn : public EditTxn
|
class InsertTableTxn : public EditTxn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~InsertTableTxn();
|
||||||
|
|
||||||
/** used to name aggregate transactions that consist only of a single InsertTableTxn,
|
/** used to name aggregate transactions that consist only of a single InsertTableTxn,
|
||||||
* or a DeleteSelection followed by an InsertTableTxn.
|
* or a DeleteSelection followed by an InsertTableTxn.
|
||||||
|
|
|
@ -40,6 +40,10 @@ InsertTextTxn::InsertTextTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InsertTextTxn::~InsertTextTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement,
|
NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement,
|
||||||
PRUint32 aOffset,
|
PRUint32 aOffset,
|
||||||
const nsString& aStringToInsert,
|
const nsString& aStringToInsert,
|
||||||
|
|
|
@ -36,6 +36,7 @@ class nsIPresShell;
|
||||||
class InsertTextTxn : public EditTxn
|
class InsertTextTxn : public EditTxn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~InsertTextTxn();
|
||||||
|
|
||||||
/** used to name aggregate transactions that consist only of a single InsertTextTxn,
|
/** used to name aggregate transactions that consist only of a single InsertTextTxn,
|
||||||
* or a DeleteSelection followed by an InsertTextTxn.
|
* or a DeleteSelection followed by an InsertTextTxn.
|
||||||
|
|
|
@ -40,6 +40,10 @@ JoinTableCellsTxn::JoinTableCellsTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JoinTableCellsTxn::~JoinTableCellsTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP JoinTableCellsTxn::Init(nsIDOMCharacterData *aElement,
|
NS_IMETHODIMP JoinTableCellsTxn::Init(nsIDOMCharacterData *aElement,
|
||||||
nsIDOMNode *aNode,
|
nsIDOMNode *aNode,
|
||||||
nsIPresShell* aPresShell)
|
nsIPresShell* aPresShell)
|
||||||
|
|
|
@ -37,7 +37,7 @@ class nsIPresShell;
|
||||||
class JoinTableCellsTxn : public EditTxn
|
class JoinTableCellsTxn : public EditTxn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~JoinTableCellsTxn();
|
||||||
/** used to name aggregate transactions that consist only of a single JoinTableCellsTxn,
|
/** used to name aggregate transactions that consist only of a single JoinTableCellsTxn,
|
||||||
* or a DeleteSelection followed by an JoinTableCellsTxn.
|
* or a DeleteSelection followed by an JoinTableCellsTxn.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -811,32 +811,20 @@ NS_IMETHODIMP nsEditor::CreateTxnForDeleteElement(nsIDOMNode * aElement,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, nsISupports **aAggTxn)
|
NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, EditAggregateTxn **aAggTxn)
|
||||||
{
|
{
|
||||||
nsresult result = NS_ERROR_NULL_POINTER;
|
nsresult result = NS_ERROR_NULL_POINTER;
|
||||||
if (aAggTxn)
|
if (aAggTxn)
|
||||||
{
|
{
|
||||||
*aAggTxn = nsnull;
|
*aAggTxn = nsnull;
|
||||||
EditAggregateTxn *aTxn = nsnull;
|
result = TransactionFactory::GetNewTransaction(kEditAggregateTxnIID, (EditTxn**)aAggTxn);
|
||||||
|
|
||||||
result = TransactionFactory::GetNewTransaction(kEditAggregateTxnIID, (EditTxn**)&aTxn);
|
if (NS_FAILED(result) || !*aAggTxn) {
|
||||||
|
|
||||||
if ((NS_FAILED(result)) || !aTxn) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
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
|
// Set the name for the aggregate transaction
|
||||||
aTxn->SetName(aTxnName);
|
(*aAggTxn)->SetName(aTxnName);
|
||||||
|
|
||||||
// Get current selection and setup txn to delete it,
|
// Get current selection and setup txn to delete it,
|
||||||
// but only if selection exists (is not a collapsed "caret" state)
|
// but only if selection exists (is not a collapsed "caret" state)
|
||||||
|
@ -850,7 +838,7 @@ NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName,
|
||||||
EditAggregateTxn *delSelTxn;
|
EditAggregateTxn *delSelTxn;
|
||||||
result = CreateTxnForDeleteSelection(nsIEditor::eLTR, &delSelTxn);
|
result = CreateTxnForDeleteSelection(nsIEditor::eLTR, &delSelTxn);
|
||||||
if (NS_SUCCEEDED(result) && delSelTxn) {
|
if (NS_SUCCEEDED(result) && delSelTxn) {
|
||||||
aTxn->AppendChild(delSelTxn);
|
(*aAggTxn)->AppendChild(delSelTxn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -864,7 +852,7 @@ nsEditor::InsertText(const nsString& aStringToInsert)
|
||||||
{
|
{
|
||||||
EditAggregateTxn *aggTxn = nsnull;
|
EditAggregateTxn *aggTxn = nsnull;
|
||||||
// Create the "delete current selection" txn
|
// 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)) {
|
if ((NS_FAILED(result)) || (nsnull==aggTxn)) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,10 +79,11 @@ public:
|
||||||
|
|
||||||
/*BEGIN nsIEdieditor for more details*/
|
/*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_DECL_ISUPPORTS
|
||||||
|
|
||||||
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell);
|
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
|
||||||
|
|
||||||
NS_IMETHOD GetDocument(nsIDOMDocument **aDoc);
|
NS_IMETHOD GetDocument(nsIDOMDocument **aDoc);
|
||||||
|
|
||||||
|
@ -243,8 +244,6 @@ protected:
|
||||||
nsIDOMNode * aParent,
|
nsIDOMNode * aParent,
|
||||||
PRBool aNodeToKeepIsFirst);
|
PRBool aNodeToKeepIsFirst);
|
||||||
|
|
||||||
NS_IMETHOD CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, nsISupports **aAggTxn);
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
NS_IMETHOD CreateTxnToHandleEnterKey(EditAggregateTxn **aTxn);
|
NS_IMETHOD CreateTxnToHandleEnterKey(EditAggregateTxn **aTxn);
|
||||||
#endif
|
#endif
|
||||||
|
@ -257,6 +256,17 @@ protected:
|
||||||
|
|
||||||
NS_IMETHOD GetLeftmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
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))
|
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
|
//more class ids to support. here
|
||||||
|
|
||||||
if (obj && NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) )
|
if (obj && NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) )
|
||||||
|
|
|
@ -47,366 +47,180 @@ static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
|
||||||
|
|
||||||
nsHTMLEditor::nsHTMLEditor()
|
nsHTMLEditor::nsHTMLEditor()
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
// Done in nsEditor
|
||||||
|
// NS_INIT_REFCNT();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsHTMLEditor::~nsHTMLEditor()
|
nsHTMLEditor::~nsHTMLEditor()
|
||||||
{
|
{
|
||||||
//the autopointers will clear themselves up.
|
//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,
|
// Adds appropriate AddRef, Release, and QueryInterface methods for derived class
|
||||||
nsIPresShell *aPresShell,
|
//NS_IMPL_ISUPPORTS_INHERITED(nsHTMLEditor, nsTextEditor, nsIHTMLEditor)
|
||||||
nsIEditorCallback *aCallback)
|
|
||||||
|
//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");
|
NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg");
|
||||||
nsresult result=NS_ERROR_NULL_POINTER;
|
nsresult result=NS_ERROR_NULL_POINTER;
|
||||||
if ((nsnull!=aDoc) && (nsnull!=aPresShell))
|
if ((nsnull!=aDoc) && (nsnull!=aPresShell))
|
||||||
{
|
{
|
||||||
nsITextEditor *aTextEditor = nsnull;
|
return Inherited::Init(aDoc, aPresShell);
|
||||||
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 result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::SetTextProperty(nsIAtom *aProperty)
|
NS_IMETHODIMP nsHTMLEditor::SetTextProperty(nsIAtom *aProperty)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::SetTextProperty(aProperty);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->SetTextProperty(aProperty);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::GetTextProperty(nsIAtom *aProperty, PRBool &aAny, PRBool &aAll)
|
NS_IMETHODIMP nsHTMLEditor::GetTextProperty(nsIAtom *aProperty, PRBool &aAny, PRBool &aAll)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::GetTextProperty(aProperty, aAny, aAll);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->GetTextProperty(aProperty, aAny, aAll);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::RemoveTextProperty(nsIAtom *aProperty)
|
NS_IMETHODIMP nsHTMLEditor::RemoveTextProperty(nsIAtom *aProperty)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::RemoveTextProperty(aProperty);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->RemoveTextProperty(aProperty);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::DeleteSelection(nsIEditor::Direction aDir)
|
NS_IMETHODIMP nsHTMLEditor::DeleteSelection(nsIEditor::Direction aDir)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::DeleteSelection(aDir);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->DeleteSelection(aDir);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert)
|
NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::InsertText(aStringToInsert);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->InsertText(aStringToInsert);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::InsertBreak(PRBool aCtrlKey)
|
NS_IMETHODIMP nsHTMLEditor::InsertBreak(PRBool aCtrlKey)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::InsertBreak(aCtrlKey);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->InsertBreak(aCtrlKey);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methods shared with the base editor.
|
// Methods shared with the base editor.
|
||||||
// Note: We could call each of these via nsTextEditor -- is that better?
|
// Note: We could call each of these via nsTextEditor -- is that better?
|
||||||
NS_IMETHODIMP nsHTMLEditor::EnableUndo(PRBool aEnable)
|
NS_IMETHODIMP nsHTMLEditor::EnableUndo(PRBool aEnable)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::EnableUndo(aEnable);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->EnableUndo(aEnable);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::Undo(PRUint32 aCount)
|
NS_IMETHODIMP nsHTMLEditor::Undo(PRUint32 aCount)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::Undo(aCount);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->Undo(aCount);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo)
|
NS_IMETHODIMP nsHTMLEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::CanUndo(aIsEnabled, aCanUndo);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->CanUndo(aIsEnabled, aCanUndo);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::Redo(PRUint32 aCount)
|
NS_IMETHODIMP nsHTMLEditor::Redo(PRUint32 aCount)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::Redo(aCount);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->Redo(aCount);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo)
|
NS_IMETHODIMP nsHTMLEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::CanRedo(aIsEnabled, aCanRedo);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->CanRedo(aIsEnabled, aCanRedo);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::BeginTransaction()
|
NS_IMETHODIMP nsHTMLEditor::BeginTransaction()
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::BeginTransaction();
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->BeginTransaction();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::EndTransaction()
|
NS_IMETHODIMP nsHTMLEditor::EndTransaction()
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::EndTransaction();
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->EndTransaction();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::MoveSelectionUp(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->MoveSelectionUp(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::MoveSelectionDown(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->MoveSelectionDown(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::MoveSelectionNext(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->MoveSelectionNext(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::MoveSelectionPrevious(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->MoveSelectionPrevious(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::SelectNext(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->SelectNext(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::SelectPrevious(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->SelectPrevious(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::ScrollUp(nsIAtom *aIncrement)
|
NS_IMETHODIMP nsHTMLEditor::ScrollUp(nsIAtom *aIncrement)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::ScrollUp(aIncrement);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->ScrollUp(aIncrement);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::ScrollDown(nsIAtom *aIncrement)
|
NS_IMETHODIMP nsHTMLEditor::ScrollDown(nsIAtom *aIncrement)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::ScrollDown(aIncrement);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->ScrollDown(aIncrement);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin)
|
NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::ScrollIntoView(aScrollToBegin);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->ScrollIntoView(aScrollToBegin);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::Insert(nsIInputStream *aInputStream)
|
NS_IMETHODIMP nsHTMLEditor::Insert(nsIInputStream *aInputStream)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::Insert(aInputStream);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->Insert(aInputStream);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputText(nsIOutputStream *aOutputStream)
|
NS_IMETHODIMP nsHTMLEditor::OutputText(nsIOutputStream *aOutputStream)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::OutputText(aOutputStream);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->OutputText(aOutputStream);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsIOutputStream *aOutputStream)
|
NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsIOutputStream *aOutputStream)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::OutputHTML(aOutputStream);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//================================================================
|
//================================================================
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#define nsHTMLEditor_h__
|
#define nsHTMLEditor_h__
|
||||||
|
|
||||||
#include "nsITextEditor.h"
|
#include "nsITextEditor.h"
|
||||||
|
#include "nsTextEditor.h"
|
||||||
#include "nsIHTMLEditor.h"
|
#include "nsIHTMLEditor.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsIDOMEventListener.h"
|
#include "nsIDOMEventListener.h"
|
||||||
|
@ -29,20 +30,25 @@
|
||||||
* The HTML editor implementation.<br>
|
* The HTML editor implementation.<br>
|
||||||
* Use to edit HTML document represented as a DOM tree.
|
* 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:
|
public:
|
||||||
// see nsIHTMLEditor for documentation
|
// see nsIHTMLEditor for documentation
|
||||||
|
|
||||||
//Interfaces for addref and release and queryinterface
|
//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
|
//Initialization
|
||||||
nsHTMLEditor();
|
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
|
||||||
NS_IMETHOD InitHTMLEditor(nsIDOMDocument *aDoc,
|
|
||||||
nsIPresShell *aPresShell,
|
|
||||||
nsIEditorCallback *aCallback=nsnull);
|
|
||||||
virtual ~nsHTMLEditor();
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
// Methods that are duplicates of nsTextEditor -- exposed here for convenience
|
// Methods that are duplicates of nsTextEditor -- exposed here for convenience
|
||||||
|
@ -103,8 +109,6 @@ public:
|
||||||
|
|
||||||
// Data members
|
// Data members
|
||||||
protected:
|
protected:
|
||||||
nsCOMPtr<nsIEditor> mEditor;
|
|
||||||
nsCOMPtr<nsITextEditor> mTextEditor;
|
|
||||||
|
|
||||||
// EVENT LISTENERS AND COMMAND ROUTING NEEDS WORK
|
// EVENT LISTENERS AND COMMAND ROUTING NEEDS WORK
|
||||||
// For now, the listners are tied to the nsTextEditor class
|
// 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))
|
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
|
//more class ids to support. here
|
||||||
|
|
||||||
|
|
||||||
if (obj && NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) )
|
if (obj && NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) )
|
||||||
{
|
{
|
||||||
delete obj;
|
delete obj;
|
||||||
|
|
|
@ -85,55 +85,72 @@ static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
||||||
|
|
||||||
nsTextEditor::nsTextEditor()
|
nsTextEditor::nsTextEditor()
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
// Done in nsEditor
|
||||||
|
// NS_INIT_REFCNT();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsTextEditor::~nsTextEditor()
|
nsTextEditor::~nsTextEditor()
|
||||||
{
|
{
|
||||||
//the autopointers will clear themselves up.
|
//the autopointers will clear themselves up.
|
||||||
//but we need to also remove the listeners or we have a leak
|
//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;
|
nsCOMPtr<nsIDOMEventReceiver> erP;
|
||||||
mEditor->GetDocument(getter_AddRefs(doc));
|
nsresult result = doc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP));
|
||||||
if (doc)
|
if (NS_SUCCEEDED(result) && erP)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIDOMEventReceiver> erP;
|
if (mKeyListenerP) {
|
||||||
nsresult result = doc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP));
|
erP->RemoveEventListener(mKeyListenerP, kIDOMKeyListenerIID);
|
||||||
if (NS_SUCCEEDED(result) && erP)
|
}
|
||||||
{
|
if (mMouseListenerP) {
|
||||||
if (mKeyListenerP) {
|
erP->RemoveEventListener(mMouseListenerP, kIDOMMouseListenerIID);
|
||||||
erP->RemoveEventListener(mKeyListenerP, kIDOMKeyListenerIID);
|
|
||||||
}
|
|
||||||
if (mMouseListenerP) {
|
|
||||||
erP->RemoveEventListener(mMouseListenerP, kIDOMMouseListenerIID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
NS_NOTREACHED("~nsTextEditor");
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
NS_NOTREACHED("~nsTextEditor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::InitTextEditor(nsIDOMDocument *aDoc,
|
// Adds appropriate AddRef, Release, and QueryInterface methods for derived class
|
||||||
nsIPresShell *aPresShell,
|
//NS_IMPL_ISUPPORTS_INHERITED(nsTextEditor, nsEditor, nsITextEditor)
|
||||||
nsIEditorCallback *aCallback)
|
|
||||||
|
//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");
|
NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg");
|
||||||
nsresult result=NS_ERROR_NULL_POINTER;
|
nsresult result=NS_ERROR_NULL_POINTER;
|
||||||
if ((nsnull!=aDoc) && (nsnull!=aPresShell))
|
if ((nsnull!=aDoc) && (nsnull!=aPresShell))
|
||||||
{
|
{
|
||||||
// get the editor
|
// Init the base editor
|
||||||
nsIEditor *editor = nsnull;
|
result = Inherited::Init(aDoc, aPresShell);
|
||||||
result = nsRepository::CreateInstance(kEditorCID, nsnull,
|
if (NS_OK != result)
|
||||||
kIEditorIID, (void **)&editor);
|
return result;
|
||||||
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);
|
|
||||||
|
|
||||||
result = NS_NewEditorKeyListener(getter_AddRefs(mKeyListenerP), this);
|
result = NS_NewEditorKeyListener(getter_AddRefs(mKeyListenerP), this);
|
||||||
if (NS_OK != result) {
|
if (NS_OK != result) {
|
||||||
|
@ -145,6 +162,7 @@ NS_IMETHODIMP nsTextEditor::InitTextEditor(nsIDOMDocument *aDoc,
|
||||||
mKeyListenerP = do_QueryInterface(0);
|
mKeyListenerP = do_QueryInterface(0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMEventReceiver> erP;
|
nsCOMPtr<nsIDOMEventReceiver> erP;
|
||||||
result = aDoc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP));
|
result = aDoc->QueryInterface(kIDOMEventReceiverIID, getter_AddRefs(erP));
|
||||||
if (NS_OK != result)
|
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
|
mMouseListenerP = do_QueryInterface(0); //dont need these if we cant register them
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
//cmanske: Shouldn't we check result from this?
|
||||||
erP->AddEventListener(mKeyListenerP, kIDOMKeyListenerIID);
|
erP->AddEventListener(mKeyListenerP, kIDOMKeyListenerIID);
|
||||||
//erP->AddEventListener(mMouseListenerP, kIDOMMouseListenerIID);
|
//erP->AddEventListener(mMouseListenerP, kIDOMMouseListenerIID);
|
||||||
|
|
||||||
result = NS_OK;
|
result = NS_OK;
|
||||||
|
|
||||||
|
EnableUndo(PR_TRUE);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -169,80 +190,77 @@ NS_IMETHODIMP nsTextEditor::SetTextProperty(nsIAtom *aProperty)
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
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;
|
Inherited::BeginTransaction();
|
||||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
nsCOMPtr<nsIEnumerator> enumerator;
|
||||||
if ((NS_SUCCEEDED(result)) && selection)
|
enumerator = do_QueryInterface(selection, &result);
|
||||||
|
if ((NS_SUCCEEDED(result)) && enumerator)
|
||||||
{
|
{
|
||||||
mEditor->BeginTransaction();
|
enumerator->First();
|
||||||
nsCOMPtr<nsIEnumerator> enumerator;
|
nsISupports *currentItem;
|
||||||
enumerator = do_QueryInterface(selection, &result);
|
result = enumerator->CurrentItem(¤tItem);
|
||||||
if ((NS_SUCCEEDED(result)) && enumerator)
|
if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem))
|
||||||
{
|
{
|
||||||
enumerator->First();
|
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
|
||||||
nsISupports *currentItem;
|
nsCOMPtr<nsIDOMNode>commonParent;
|
||||||
result = enumerator->CurrentItem(¤tItem);
|
result = range->GetCommonParent(getter_AddRefs(commonParent));
|
||||||
if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem))
|
if ((NS_SUCCEEDED(result)) && commonParent)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
|
PRInt32 startOffset, endOffset;
|
||||||
nsCOMPtr<nsIDOMNode>commonParent;
|
range->GetStartOffset(&startOffset);
|
||||||
result = range->GetCommonParent(getter_AddRefs(commonParent));
|
range->GetEndOffset(&endOffset);
|
||||||
if ((NS_SUCCEEDED(result)) && commonParent)
|
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;
|
nsCOMPtr<nsIDOMNode> startGrandParent;
|
||||||
range->GetStartOffset(&startOffset);
|
startParent->GetParentNode(getter_AddRefs(startGrandParent));
|
||||||
range->GetEndOffset(&endOffset);
|
nsCOMPtr<nsIDOMNode> endGrandParent;
|
||||||
nsCOMPtr<nsIDOMNode> startParent; nsCOMPtr<nsIDOMNode> endParent;
|
endParent->GetParentNode(getter_AddRefs(endGrandParent));
|
||||||
range->GetStartParent(getter_AddRefs(startParent));
|
if (NS_SUCCEEDED(result))
|
||||||
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;
|
if (endGrandParent.get()==startGrandParent.get())
|
||||||
startParent->GetParentNode(getter_AddRefs(startGrandParent));
|
{ // the range is between 2 nodes that have a common (immediate) grandparent
|
||||||
nsCOMPtr<nsIDOMNode> endGrandParent;
|
result = SetTextPropertiesForNodesWithSameParent(startParent,startOffset,
|
||||||
endParent->GetParentNode(getter_AddRefs(endGrandParent));
|
endParent, endOffset,
|
||||||
if (NS_SUCCEEDED(result))
|
commonParent,
|
||||||
{
|
aProperty);
|
||||||
if (endGrandParent.get()==startGrandParent.get())
|
}
|
||||||
{ // the range is between 2 nodes that have a common (immediate) grandparent
|
else
|
||||||
result = SetTextPropertiesForNodesWithSameParent(startParent,startOffset,
|
{ // the range is between 2 nodes that have no simple relationship
|
||||||
endParent, endOffset,
|
result = SetTextPropertiesForNodeWithDifferentParents(range,
|
||||||
commonParent,
|
startParent,startOffset,
|
||||||
aProperty);
|
endParent, endOffset,
|
||||||
}
|
commonParent,
|
||||||
else
|
aProperty);
|
||||||
{ // 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
|
if (NS_SUCCEEDED(result))
|
||||||
// don't want to actually do anything with selection, because
|
{ // compute a range for the selection
|
||||||
// we are still iterating through it. Just want to create and remember
|
// don't want to actually do anything with selection, because
|
||||||
// an nsIDOMRange, and later add the range to the selection after clearing it.
|
// we are still iterating through it. Just want to create and remember
|
||||||
// XXX: I'm blocked here because nsIDOMSelection doesn't provide a mechanism
|
// an nsIDOMRange, and later add the range to the selection after clearing it.
|
||||||
// for setting a compound selection yet.
|
// XXX: I'm blocked here because nsIDOMSelection doesn't provide a mechanism
|
||||||
}
|
// for setting a compound selection yet.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mEditor->EndTransaction();
|
}
|
||||||
if (NS_SUCCEEDED(result))
|
Inherited::EndTransaction();
|
||||||
{ // set the selection
|
if (NS_SUCCEEDED(result))
|
||||||
// XXX: can't do anything until I can create ranges
|
{ // set the selection
|
||||||
}
|
// XXX: can't do anything until I can create ranges
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -256,71 +274,68 @@ NS_IMETHODIMP nsTextEditor::GetTextProperty(nsIAtom *aProperty, PRBool &aAny, PR
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||||
aAny=PR_FALSE;
|
aAny=PR_FALSE;
|
||||||
aAll=PR_TRUE;
|
aAll=PR_TRUE;
|
||||||
if (mEditor)
|
nsCOMPtr<nsIDOMSelection>selection;
|
||||||
|
result = Inherited::GetSelection(getter_AddRefs(selection));
|
||||||
|
if ((NS_SUCCEEDED(result)) && selection)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIDOMSelection>selection;
|
nsCOMPtr<nsIEnumerator> enumerator;
|
||||||
result = mEditor->GetSelection(getter_AddRefs(selection));
|
enumerator = do_QueryInterface(selection, &result);
|
||||||
if ((NS_SUCCEEDED(result)) && selection)
|
if ((NS_SUCCEEDED(result)) && enumerator)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIEnumerator> enumerator;
|
enumerator->First();
|
||||||
enumerator = do_QueryInterface(selection, &result);
|
nsISupports *currentItem;
|
||||||
if ((NS_SUCCEEDED(result)) && enumerator)
|
result = enumerator->CurrentItem(¤tItem);
|
||||||
|
if ((NS_SUCCEEDED(result)) && currentItem)
|
||||||
{
|
{
|
||||||
enumerator->First();
|
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
|
||||||
nsISupports *currentItem;
|
nsCOMPtr<nsIContentIterator> iter;
|
||||||
result = enumerator->CurrentItem(¤tItem);
|
result = nsRepository::CreateInstance(kCContentIteratorCID, nsnull,
|
||||||
if ((NS_SUCCEEDED(result)) && currentItem)
|
kIContentIteratorIID,
|
||||||
|
getter_AddRefs(iter));
|
||||||
|
if ((NS_SUCCEEDED(result)) && iter)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
|
iter->Init(range);
|
||||||
nsCOMPtr<nsIContentIterator> iter;
|
return 0;
|
||||||
result = nsRepository::CreateInstance(kCContentIteratorCID, nsnull,
|
// loop through the content iterator for each content node
|
||||||
kIContentIteratorIID,
|
// for each text node:
|
||||||
getter_AddRefs(iter));
|
// get the frame for the content, and from it the style context
|
||||||
if ((NS_SUCCEEDED(result)) && iter)
|
// 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);
|
nsCOMPtr<nsIDOMCharacterData>text;
|
||||||
return 0;
|
text = do_QueryInterface(content);
|
||||||
// loop through the content iterator for each content node
|
if (text)
|
||||||
// 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;
|
nsCOMPtr<nsIPresShell>presShell;
|
||||||
text = do_QueryInterface(content);
|
Inherited::GetPresShell(getter_AddRefs(presShell));
|
||||||
if (text)
|
NS_ASSERTION(presShell, "bad state, null pres shell");
|
||||||
|
if (presShell)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIPresShell>presShell;
|
nsIFrame *frame;
|
||||||
mEditor->GetPresShell(getter_AddRefs(presShell));
|
result = presShell->GetPrimaryFrameFor(content, &frame);
|
||||||
NS_ASSERTION(presShell, "bad state, null pres shell");
|
if ((NS_SUCCEEDED(result)) && frame)
|
||||||
if (presShell)
|
|
||||||
{
|
{
|
||||||
nsIFrame *frame;
|
nsCOMPtr<nsIStyleContext> sc;
|
||||||
result = presShell->GetPrimaryFrameFor(content, &frame);
|
result = presShell->GetStyleContextFor(frame, getter_AddRefs(sc));
|
||||||
if ((NS_SUCCEEDED(result)) && frame)
|
if ((NS_SUCCEEDED(result)) && sc)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIStyleContext> sc;
|
PRBool isSet;
|
||||||
result = presShell->GetStyleContextFor(frame, getter_AddRefs(sc));
|
IsTextStyleSet(sc, aProperty, isSet);
|
||||||
if ((NS_SUCCEEDED(result)) && sc)
|
if (PR_TRUE==isSet) {
|
||||||
{
|
aAny = PR_TRUE;
|
||||||
PRBool isSet;
|
}
|
||||||
IsTextStyleSet(sc, aProperty, isSet);
|
else {
|
||||||
if (PR_TRUE==isSet) {
|
aAll = PR_FALSE;
|
||||||
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)
|
NS_IMETHODIMP nsTextEditor::RemoveTextProperty(nsIAtom *aProperty)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
||||||
if (mEditor)
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::DeleteSelection(nsIEditor::Direction aDir)
|
NS_IMETHODIMP nsTextEditor::DeleteSelection(nsIEditor::Direction aDir)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::DeleteSelection(aDir);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->DeleteSelection(aDir);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::InsertText(const nsString& aStringToInsert)
|
NS_IMETHODIMP nsTextEditor::InsertText(const nsString& aStringToInsert)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::InsertText(aStringToInsert);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->InsertText(aStringToInsert);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::InsertBreak(PRBool aCtrlKey)
|
NS_IMETHODIMP nsTextEditor::InsertBreak(PRBool aCtrlKey)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
// Note: Code that does most of the deletion work was
|
||||||
if (mEditor)
|
// moved to nsEditor::DeleteSelectionAndCreateNode
|
||||||
{
|
// Only difference is we now do BeginTransaction()/EndTransaction()
|
||||||
// Note: Code that does most of the deletion work was
|
// even if we fail to get a selection
|
||||||
// moved to nsEditor::DeleteSelectionAndCreateNode
|
nsresult result = Inherited::BeginTransaction();
|
||||||
// Only difference is we now do BeginTransaction()/EndTransaction()
|
|
||||||
// even if we fail to get a selection
|
|
||||||
result = mEditor->BeginTransaction();
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> newNode;
|
nsCOMPtr<nsIDOMNode> newNode;
|
||||||
nsAutoString tag("BR");
|
nsAutoString tag("BR");
|
||||||
mEditor->DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
|
Inherited::DeleteSelectionAndCreateNode(tag, getter_AddRefs(newNode));
|
||||||
// Are we supposed to release newNode?
|
|
||||||
|
// Are we supposed to release newNode?
|
||||||
|
result = Inherited::EndTransaction();
|
||||||
|
|
||||||
result = mEditor->EndTransaction();
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::EnableUndo(PRBool aEnable)
|
NS_IMETHODIMP nsTextEditor::EnableUndo(PRBool aEnable)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::EnableUndo(aEnable);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->EnableUndo(aEnable);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::Undo(PRUint32 aCount)
|
NS_IMETHODIMP nsTextEditor::Undo(PRUint32 aCount)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::Undo(aCount);
|
||||||
if (mEditor) {
|
|
||||||
result = mEditor->Undo(aCount);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo)
|
NS_IMETHODIMP nsTextEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::CanUndo(aIsEnabled, aCanUndo);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->CanUndo(aIsEnabled, aCanUndo);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::Redo(PRUint32 aCount)
|
NS_IMETHODIMP nsTextEditor::Redo(PRUint32 aCount)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::Redo(aCount);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->Redo(aCount);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo)
|
NS_IMETHODIMP nsTextEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::CanRedo(aIsEnabled, aCanRedo);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->CanRedo(aIsEnabled, aCanRedo);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::BeginTransaction()
|
NS_IMETHODIMP nsTextEditor::BeginTransaction()
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::BeginTransaction();
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->BeginTransaction();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::EndTransaction()
|
NS_IMETHODIMP nsTextEditor::EndTransaction()
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::EndTransaction();
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->EndTransaction();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsTextEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsTextEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsTextEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsTextEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsTextEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsTextEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::ScrollUp(nsIAtom *aIncrement)
|
NS_IMETHODIMP nsTextEditor::ScrollUp(nsIAtom *aIncrement)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::ScrollDown(nsIAtom *aIncrement)
|
NS_IMETHODIMP nsTextEditor::ScrollDown(nsIAtom *aIncrement)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::ScrollIntoView(PRBool aScrollToBegin)
|
NS_IMETHODIMP nsTextEditor::ScrollIntoView(PRBool aScrollToBegin)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::ScrollIntoView(aScrollToBegin);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->ScrollIntoView(aScrollToBegin);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::Insert(nsIInputStream *aInputStream)
|
NS_IMETHODIMP nsTextEditor::Insert(nsIInputStream *aInputStream)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef XP_MAC
|
#ifdef XP_MAC
|
||||||
void WriteFromStringstream(stringstream& aIn, nsIOutputStream* aOut)
|
void WriteFromStringstream(stringstream& aIn, nsIOutputStream* aOut)
|
||||||
{
|
{
|
||||||
|
@ -619,60 +532,57 @@ NS_IMETHODIMP nsTextEditor::OutputText(nsIOutputStream *aOutputStream)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nsresult result=NS_ERROR_FAILURE;
|
nsresult result=NS_ERROR_FAILURE;
|
||||||
if (mEditor)
|
nsIPresShell* shell = nsnull;
|
||||||
{
|
Inherited::GetPresShell(&shell);
|
||||||
nsIPresShell* shell = nsnull;
|
|
||||||
|
|
||||||
mEditor->GetPresShell(&shell);
|
|
||||||
if (nsnull != shell) {
|
|
||||||
nsCOMPtr<nsIDocument> doc;
|
|
||||||
shell->GetDocument(getter_AddRefs(doc));
|
|
||||||
if (doc) {
|
|
||||||
nsString buffer;
|
|
||||||
|
|
||||||
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);
|
nsIParser* parser;
|
||||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
|
||||||
|
|
||||||
nsresult rv = nsRepository::CreateInstance(kCParserCID,
|
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||||
nsnull,
|
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
||||||
kCParserIID,
|
|
||||||
(void **)&parser);
|
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) {
|
if (NS_OK == rv) {
|
||||||
nsIHTMLContentSink* sink = nsnull;
|
parser->SetContentSink(sink);
|
||||||
|
|
||||||
rv = NS_New_HTMLToTXT_SinkStream(&sink);
|
|
||||||
|
|
||||||
if (aOutputStream != nsnull)
|
nsIDTD* dtd = nsnull;
|
||||||
((nsHTMLContentSinkStream*)sink)->SetOutputStream(out);
|
rv = NS_NewXIFDTD(&dtd);
|
||||||
|
|
||||||
if (NS_OK == rv) {
|
if (NS_OK == rv) {
|
||||||
parser->SetContentSink(sink);
|
parser->RegisterDTD(dtd);
|
||||||
|
parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -689,96 +599,61 @@ NS_IMETHODIMP nsTextEditor::OutputHTML(nsIOutputStream *aOutputStream)
|
||||||
|
|
||||||
|
|
||||||
nsresult result=NS_ERROR_FAILURE;
|
nsresult result=NS_ERROR_FAILURE;
|
||||||
if (mEditor)
|
nsIPresShell* shell = nsnull;
|
||||||
{
|
Inherited::GetPresShell(&shell);
|
||||||
nsIPresShell* shell = nsnull;
|
|
||||||
|
|
||||||
mEditor->GetPresShell(&shell);
|
|
||||||
if (nsnull != shell) {
|
|
||||||
nsCOMPtr<nsIDocument> doc;
|
|
||||||
shell->GetDocument(getter_AddRefs(doc));
|
|
||||||
if (doc) {
|
|
||||||
nsString buffer;
|
|
||||||
|
|
||||||
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);
|
nsIParser* parser;
|
||||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
|
||||||
|
|
||||||
nsresult rv = nsRepository::CreateInstance(kCParserCID,
|
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||||
nsnull,
|
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
||||||
kCParserIID,
|
|
||||||
(void **)&parser);
|
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) {
|
if (NS_OK == rv) {
|
||||||
nsIHTMLContentSink* sink = nsnull;
|
parser->SetContentSink(sink);
|
||||||
|
|
||||||
rv = NS_New_HTML_ContentSinkStream(&sink);
|
|
||||||
|
|
||||||
if (aOutputStream)
|
nsIDTD* dtd = nsnull;
|
||||||
((nsHTMLContentSinkStream*)sink)->SetOutputStream(out);
|
rv = NS_NewXIFDTD(&dtd);
|
||||||
|
|
||||||
if (NS_OK == rv) {
|
if (NS_OK == rv) {
|
||||||
parser->SetContentSink(sink);
|
parser->RegisterDTD(dtd);
|
||||||
|
parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
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;
|
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,
|
NS_IMETHODIMP nsTextEditor::SetTextPropertiesForNode(nsIDOMNode *aNode,
|
||||||
nsIDOMNode *aParent,
|
nsIDOMNode *aParent,
|
||||||
PRInt32 aStartOffset,
|
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
|
nsCOMPtr<nsIDOMNode>newTextNode; // this will be the text node we move into the new style node
|
||||||
if (aStartOffset!=0)
|
if (aStartOffset!=0)
|
||||||
{
|
{
|
||||||
result = mEditor->SplitNode(aNode, aStartOffset, getter_AddRefs(newTextNode));
|
result = Inherited::SplitNode(aNode, aStartOffset, getter_AddRefs(newTextNode));
|
||||||
}
|
}
|
||||||
if (NS_SUCCEEDED(result))
|
if (NS_SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
if (aEndOffset!=(PRInt32)count)
|
if (aEndOffset!=(PRInt32)count)
|
||||||
{
|
{
|
||||||
result = mEditor->SplitNode(aNode, aEndOffset-aStartOffset, getter_AddRefs(newTextNode));
|
result = Inherited::SplitNode(aNode, aEndOffset-aStartOffset, getter_AddRefs(newTextNode));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -819,12 +694,12 @@ NS_IMETHODIMP nsTextEditor::SetTextPropertiesForNode(nsIDOMNode *aNode,
|
||||||
if (NS_SUCCEEDED(result))
|
if (NS_SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIDOMNode>newStyleNode;
|
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))
|
if (NS_SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
result = mEditor->DeleteNode(newTextNode);
|
result = Inherited::DeleteNode(newTextNode);
|
||||||
if (NS_SUCCEEDED(result)) {
|
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;
|
nsresult result=NS_OK;
|
||||||
nsCOMPtr<nsIDOMNode>newLeftTextNode; // this will be the middle text node
|
nsCOMPtr<nsIDOMNode>newLeftTextNode; // this will be the middle text node
|
||||||
if (0!=aStartOffset) {
|
if (0!=aStartOffset) {
|
||||||
result = mEditor->SplitNode(aStartNode, aStartOffset, getter_AddRefs(newLeftTextNode));
|
result = Inherited::SplitNode(aStartNode, aStartOffset, getter_AddRefs(newLeftTextNode));
|
||||||
}
|
}
|
||||||
if (NS_SUCCEEDED(result))
|
if (NS_SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
|
@ -857,7 +732,7 @@ nsTextEditor::SetTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode,
|
||||||
endNodeAsChar->GetLength(&count);
|
endNodeAsChar->GetLength(&count);
|
||||||
nsCOMPtr<nsIDOMNode>newRightTextNode; // this will be the middle text node
|
nsCOMPtr<nsIDOMNode>newRightTextNode; // this will be the middle text node
|
||||||
if ((PRInt32)count!=aEndOffset) {
|
if ((PRInt32)count!=aEndOffset) {
|
||||||
result = mEditor->SplitNode(aEndNode, aEndOffset, getter_AddRefs(newRightTextNode));
|
result = Inherited::SplitNode(aEndNode, aEndOffset, getter_AddRefs(newRightTextNode));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
newRightTextNode = do_QueryInterface(aEndNode);
|
newRightTextNode = do_QueryInterface(aEndNode);
|
||||||
|
@ -878,18 +753,18 @@ nsTextEditor::SetTextPropertiesForNodesWithSameParent(nsIDOMNode *aStartNode,
|
||||||
if (NS_SUCCEEDED(result))
|
if (NS_SUCCEEDED(result))
|
||||||
{ // create the new style node, which will be the new parent for the selected nodes
|
{ // create the new style node, which will be the new parent for the selected nodes
|
||||||
nsCOMPtr<nsIDOMNode>newStyleNode;
|
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))
|
if (NS_SUCCEEDED(result))
|
||||||
{ // move the right half of the start node into the new style node
|
{ // move the right half of the start node into the new style node
|
||||||
nsCOMPtr<nsIDOMNode>intermediateNode;
|
nsCOMPtr<nsIDOMNode>intermediateNode;
|
||||||
result = aStartNode->GetNextSibling(getter_AddRefs(intermediateNode));
|
result = aStartNode->GetNextSibling(getter_AddRefs(intermediateNode));
|
||||||
if (NS_SUCCEEDED(result))
|
if (NS_SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
result = mEditor->DeleteNode(aStartNode);
|
result = Inherited::DeleteNode(aStartNode);
|
||||||
if (NS_SUCCEEDED(result))
|
if (NS_SUCCEEDED(result))
|
||||||
{
|
{
|
||||||
PRInt32 childIndex=0;
|
PRInt32 childIndex=0;
|
||||||
result = mEditor->InsertNode(aStartNode, newStyleNode, childIndex);
|
result = Inherited::InsertNode(aStartNode, newStyleNode, childIndex);
|
||||||
childIndex++;
|
childIndex++;
|
||||||
if (NS_SUCCEEDED(result))
|
if (NS_SUCCEEDED(result))
|
||||||
{ // move all the intermediate nodes into the new style node
|
{ // 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!!!
|
// get the next sibling before moving the current child!!!
|
||||||
intermediateNode->GetNextSibling(getter_AddRefs(nextSibling));
|
intermediateNode->GetNextSibling(getter_AddRefs(nextSibling));
|
||||||
result = mEditor->DeleteNode(intermediateNode);
|
result = Inherited::DeleteNode(intermediateNode);
|
||||||
if (NS_SUCCEEDED(result)) {
|
if (NS_SUCCEEDED(result)) {
|
||||||
result = mEditor->InsertNode(intermediateNode, newStyleNode, childIndex);
|
result = Inherited::InsertNode(intermediateNode, newStyleNode, childIndex);
|
||||||
childIndex++;
|
childIndex++;
|
||||||
}
|
}
|
||||||
intermediateNode = do_QueryInterface(nextSibling);
|
intermediateNode = do_QueryInterface(nextSibling);
|
||||||
}
|
}
|
||||||
if (NS_SUCCEEDED(result))
|
if (NS_SUCCEEDED(result))
|
||||||
{ // move the left half of the end node into the new style node
|
{ // 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))
|
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);
|
parentContent->IndexOf(content, offsetInParent);
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode>newStyleNode;
|
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) {
|
if (NS_SUCCEEDED(result) && newStyleNode) {
|
||||||
nsCOMPtr<nsIDOMNode>contentNode;
|
nsCOMPtr<nsIDOMNode>contentNode;
|
||||||
contentNode = do_QueryInterface(content);
|
contentNode = do_QueryInterface(content);
|
||||||
result = mEditor->DeleteNode(contentNode);
|
result = Inherited::DeleteNode(contentNode);
|
||||||
if (NS_SUCCEEDED(result)) {
|
if (NS_SUCCEEDED(result)) {
|
||||||
result = mEditor->InsertNode(contentNode, newStyleNode, 0);
|
result = Inherited::InsertNode(contentNode, newStyleNode, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "nsITextEditor.h"
|
#include "nsITextEditor.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsIDOMEventListener.h"
|
#include "nsIDOMEventListener.h"
|
||||||
|
#include "nsEditor.h"
|
||||||
|
|
||||||
class nsIStyleContext;
|
class nsIStyleContext;
|
||||||
class nsIDOMRange;
|
class nsIDOMRange;
|
||||||
|
@ -31,20 +32,25 @@ class nsIDOMRange;
|
||||||
* Use to edit text represented as a DOM tree.
|
* Use to edit text represented as a DOM tree.
|
||||||
* This class is used for editing both plain text and rich text (attributed text).
|
* 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:
|
public:
|
||||||
// see nsITextEditor for documentation
|
// see nsITextEditor for documentation
|
||||||
|
|
||||||
//Interfaces for addref and release and queryinterface
|
//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
|
//Initialization
|
||||||
nsTextEditor();
|
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
|
||||||
NS_IMETHOD InitTextEditor(nsIDOMDocument *aDoc,
|
|
||||||
nsIPresShell *aPresShell,
|
|
||||||
nsIEditorCallback *aCallback=nsnull);
|
|
||||||
virtual ~nsTextEditor();
|
|
||||||
|
|
||||||
// Editing Operations
|
// Editing Operations
|
||||||
NS_IMETHOD SetTextProperty(nsIAtom *aProperty);
|
NS_IMETHOD SetTextProperty(nsIAtom *aProperty);
|
||||||
|
@ -112,7 +118,6 @@ protected:
|
||||||
|
|
||||||
// Data members
|
// Data members
|
||||||
protected:
|
protected:
|
||||||
nsCOMPtr<nsIEditor> mEditor;
|
|
||||||
nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
|
nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
|
||||||
nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
|
nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,10 @@ ChangeAttributeTxn::ChangeAttributeTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChangeAttributeTxn::~ChangeAttributeTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor,
|
NS_IMETHODIMP ChangeAttributeTxn::Init(nsIEditor *aEditor,
|
||||||
nsIDOMElement *aElement,
|
nsIDOMElement *aElement,
|
||||||
const nsString& aAttribute,
|
const nsString& aAttribute,
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
class ChangeAttributeTxn : public EditTxn
|
class ChangeAttributeTxn : public EditTxn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~ChangeAttributeTxn();
|
||||||
|
|
||||||
/** Initialize the transaction.
|
/** Initialize the transaction.
|
||||||
* @param aEditor the object providing core editing operations
|
* @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");
|
NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad start child list");
|
||||||
children->GetLength(&count);
|
children->GetLength(&count);
|
||||||
}
|
}
|
||||||
NS_ASSERTION(mStartOffset<=count, "bad start offset");
|
NS_ASSERTION(mStartOffset<=(PRInt32)count, "bad start offset");
|
||||||
|
|
||||||
textNode = do_QueryInterface(mEndParent, &result);
|
textNode = do_QueryInterface(mEndParent, &result);
|
||||||
if (textNode)
|
if (textNode)
|
||||||
|
@ -87,7 +87,7 @@ NS_IMETHODIMP DeleteRangeTxn::Init(nsIEditor *aEditor, nsIDOMRange *aRange)
|
||||||
NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad end child list");
|
NS_ASSERTION(((NS_SUCCEEDED(result)) && children), "bad end child list");
|
||||||
children->GetLength(&count);
|
children->GetLength(&count);
|
||||||
}
|
}
|
||||||
NS_ASSERTION(mEndOffset<=count, "bad end offset");
|
NS_ASSERTION(mEndOffset<=(PRInt32)count, "bad end offset");
|
||||||
if (gNoisy)
|
if (gNoisy)
|
||||||
printf ("DeleteRange: %d of %p to %d of %p\n",
|
printf ("DeleteRange: %d of %p to %d of %p\n",
|
||||||
mStartOffset, (void *)mStartParent, mEndOffset, (void *)mEndParent);
|
mStartOffset, (void *)mStartParent, mEndOffset, (void *)mEndParent);
|
||||||
|
|
|
@ -26,6 +26,10 @@ DeleteTextTxn::DeleteTextTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeleteTextTxn::~DeleteTextTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP DeleteTextTxn::Init(nsIEditor *aEditor,
|
NS_IMETHODIMP DeleteTextTxn::Init(nsIEditor *aEditor,
|
||||||
nsIDOMCharacterData *aElement,
|
nsIDOMCharacterData *aElement,
|
||||||
PRUint32 aOffset,
|
PRUint32 aOffset,
|
||||||
|
|
|
@ -51,7 +51,8 @@ private:
|
||||||
DeleteTextTxn();
|
DeleteTextTxn();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual ~DeleteTextTxn();
|
||||||
|
|
||||||
NS_IMETHOD Do(void);
|
NS_IMETHOD Do(void);
|
||||||
|
|
||||||
NS_IMETHOD Undo(void);
|
NS_IMETHOD Undo(void);
|
||||||
|
|
|
@ -33,6 +33,10 @@ EditTxn::EditTxn()
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EditTxn::~EditTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP EditTxn::Do(void)
|
NS_IMETHODIMP EditTxn::Do(void)
|
||||||
{
|
{
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
@ -39,6 +39,8 @@ public:
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
EditTxn();
|
EditTxn();
|
||||||
|
virtual ~EditTxn();
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHOD Do(void);
|
NS_IMETHOD Do(void);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,10 @@ InsertTextTxn::InsertTextTxn()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InsertTextTxn::~InsertTextTxn()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement,
|
NS_IMETHODIMP InsertTextTxn::Init(nsIDOMCharacterData *aElement,
|
||||||
PRUint32 aOffset,
|
PRUint32 aOffset,
|
||||||
const nsString& aStringToInsert,
|
const nsString& aStringToInsert,
|
||||||
|
|
|
@ -36,6 +36,7 @@ class nsIPresShell;
|
||||||
class InsertTextTxn : public EditTxn
|
class InsertTextTxn : public EditTxn
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~InsertTextTxn();
|
||||||
|
|
||||||
/** used to name aggregate transactions that consist only of a single InsertTextTxn,
|
/** used to name aggregate transactions that consist only of a single InsertTextTxn,
|
||||||
* or a DeleteSelection followed by an InsertTextTxn.
|
* or a DeleteSelection followed by an InsertTextTxn.
|
||||||
|
|
|
@ -811,32 +811,20 @@ NS_IMETHODIMP nsEditor::CreateTxnForDeleteElement(nsIDOMNode * aElement,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, nsISupports **aAggTxn)
|
NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, EditAggregateTxn **aAggTxn)
|
||||||
{
|
{
|
||||||
nsresult result = NS_ERROR_NULL_POINTER;
|
nsresult result = NS_ERROR_NULL_POINTER;
|
||||||
if (aAggTxn)
|
if (aAggTxn)
|
||||||
{
|
{
|
||||||
*aAggTxn = nsnull;
|
*aAggTxn = nsnull;
|
||||||
EditAggregateTxn *aTxn = nsnull;
|
result = TransactionFactory::GetNewTransaction(kEditAggregateTxnIID, (EditTxn**)aAggTxn);
|
||||||
|
|
||||||
result = TransactionFactory::GetNewTransaction(kEditAggregateTxnIID, (EditTxn**)&aTxn);
|
if (NS_FAILED(result) || !*aAggTxn) {
|
||||||
|
|
||||||
if ((NS_FAILED(result)) || !aTxn) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
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
|
// Set the name for the aggregate transaction
|
||||||
aTxn->SetName(aTxnName);
|
(*aAggTxn)->SetName(aTxnName);
|
||||||
|
|
||||||
// Get current selection and setup txn to delete it,
|
// Get current selection and setup txn to delete it,
|
||||||
// but only if selection exists (is not a collapsed "caret" state)
|
// but only if selection exists (is not a collapsed "caret" state)
|
||||||
|
@ -850,7 +838,7 @@ NS_IMETHODIMP nsEditor::CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName,
|
||||||
EditAggregateTxn *delSelTxn;
|
EditAggregateTxn *delSelTxn;
|
||||||
result = CreateTxnForDeleteSelection(nsIEditor::eLTR, &delSelTxn);
|
result = CreateTxnForDeleteSelection(nsIEditor::eLTR, &delSelTxn);
|
||||||
if (NS_SUCCEEDED(result) && delSelTxn) {
|
if (NS_SUCCEEDED(result) && delSelTxn) {
|
||||||
aTxn->AppendChild(delSelTxn);
|
(*aAggTxn)->AppendChild(delSelTxn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -864,7 +852,7 @@ nsEditor::InsertText(const nsString& aStringToInsert)
|
||||||
{
|
{
|
||||||
EditAggregateTxn *aggTxn = nsnull;
|
EditAggregateTxn *aggTxn = nsnull;
|
||||||
// Create the "delete current selection" txn
|
// 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)) {
|
if ((NS_FAILED(result)) || (nsnull==aggTxn)) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,10 +79,11 @@ public:
|
||||||
|
|
||||||
/*BEGIN nsIEdieditor for more details*/
|
/*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_DECL_ISUPPORTS
|
||||||
|
|
||||||
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell);
|
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
|
||||||
|
|
||||||
NS_IMETHOD GetDocument(nsIDOMDocument **aDoc);
|
NS_IMETHOD GetDocument(nsIDOMDocument **aDoc);
|
||||||
|
|
||||||
|
@ -243,8 +244,6 @@ protected:
|
||||||
nsIDOMNode * aParent,
|
nsIDOMNode * aParent,
|
||||||
PRBool aNodeToKeepIsFirst);
|
PRBool aNodeToKeepIsFirst);
|
||||||
|
|
||||||
NS_IMETHOD CreateAggregateTxnForDeleteSelection(nsIAtom *aTxnName, nsISupports **aAggTxn);
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
NS_IMETHOD CreateTxnToHandleEnterKey(EditAggregateTxn **aTxn);
|
NS_IMETHOD CreateTxnToHandleEnterKey(EditAggregateTxn **aTxn);
|
||||||
#endif
|
#endif
|
||||||
|
@ -257,6 +256,17 @@ protected:
|
||||||
|
|
||||||
NS_IMETHOD GetLeftmostChild(nsIDOMNode *aCurrentNode, nsIDOMNode **aResultNode);
|
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()
|
nsHTMLEditor::nsHTMLEditor()
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
// Done in nsEditor
|
||||||
|
// NS_INIT_REFCNT();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsHTMLEditor::~nsHTMLEditor()
|
nsHTMLEditor::~nsHTMLEditor()
|
||||||
{
|
{
|
||||||
//the autopointers will clear themselves up.
|
//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,
|
// Adds appropriate AddRef, Release, and QueryInterface methods for derived class
|
||||||
nsIPresShell *aPresShell,
|
//NS_IMPL_ISUPPORTS_INHERITED(nsHTMLEditor, nsTextEditor, nsIHTMLEditor)
|
||||||
nsIEditorCallback *aCallback)
|
|
||||||
|
//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");
|
NS_PRECONDITION(nsnull!=aDoc && nsnull!=aPresShell, "bad arg");
|
||||||
nsresult result=NS_ERROR_NULL_POINTER;
|
nsresult result=NS_ERROR_NULL_POINTER;
|
||||||
if ((nsnull!=aDoc) && (nsnull!=aPresShell))
|
if ((nsnull!=aDoc) && (nsnull!=aPresShell))
|
||||||
{
|
{
|
||||||
nsITextEditor *aTextEditor = nsnull;
|
return Inherited::Init(aDoc, aPresShell);
|
||||||
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 result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::SetTextProperty(nsIAtom *aProperty)
|
NS_IMETHODIMP nsHTMLEditor::SetTextProperty(nsIAtom *aProperty)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::SetTextProperty(aProperty);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->SetTextProperty(aProperty);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::GetTextProperty(nsIAtom *aProperty, PRBool &aAny, PRBool &aAll)
|
NS_IMETHODIMP nsHTMLEditor::GetTextProperty(nsIAtom *aProperty, PRBool &aAny, PRBool &aAll)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::GetTextProperty(aProperty, aAny, aAll);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->GetTextProperty(aProperty, aAny, aAll);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::RemoveTextProperty(nsIAtom *aProperty)
|
NS_IMETHODIMP nsHTMLEditor::RemoveTextProperty(nsIAtom *aProperty)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::RemoveTextProperty(aProperty);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->RemoveTextProperty(aProperty);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::DeleteSelection(nsIEditor::Direction aDir)
|
NS_IMETHODIMP nsHTMLEditor::DeleteSelection(nsIEditor::Direction aDir)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::DeleteSelection(aDir);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->DeleteSelection(aDir);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert)
|
NS_IMETHODIMP nsHTMLEditor::InsertText(const nsString& aStringToInsert)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::InsertText(aStringToInsert);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->InsertText(aStringToInsert);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::InsertBreak(PRBool aCtrlKey)
|
NS_IMETHODIMP nsHTMLEditor::InsertBreak(PRBool aCtrlKey)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::InsertBreak(aCtrlKey);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->InsertBreak(aCtrlKey);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methods shared with the base editor.
|
// Methods shared with the base editor.
|
||||||
// Note: We could call each of these via nsTextEditor -- is that better?
|
// Note: We could call each of these via nsTextEditor -- is that better?
|
||||||
NS_IMETHODIMP nsHTMLEditor::EnableUndo(PRBool aEnable)
|
NS_IMETHODIMP nsHTMLEditor::EnableUndo(PRBool aEnable)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::EnableUndo(aEnable);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->EnableUndo(aEnable);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::Undo(PRUint32 aCount)
|
NS_IMETHODIMP nsHTMLEditor::Undo(PRUint32 aCount)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::Undo(aCount);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->Undo(aCount);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo)
|
NS_IMETHODIMP nsHTMLEditor::CanUndo(PRBool &aIsEnabled, PRBool &aCanUndo)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::CanUndo(aIsEnabled, aCanUndo);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->CanUndo(aIsEnabled, aCanUndo);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::Redo(PRUint32 aCount)
|
NS_IMETHODIMP nsHTMLEditor::Redo(PRUint32 aCount)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::Redo(aCount);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->Redo(aCount);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo)
|
NS_IMETHODIMP nsHTMLEditor::CanRedo(PRBool &aIsEnabled, PRBool &aCanRedo)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::CanRedo(aIsEnabled, aCanRedo);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->CanRedo(aIsEnabled, aCanRedo);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::BeginTransaction()
|
NS_IMETHODIMP nsHTMLEditor::BeginTransaction()
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::BeginTransaction();
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->BeginTransaction();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::EndTransaction()
|
NS_IMETHODIMP nsHTMLEditor::EndTransaction()
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::EndTransaction();
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mEditor->EndTransaction();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::MoveSelectionUp(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::MoveSelectionUp(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->MoveSelectionUp(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::MoveSelectionDown(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::MoveSelectionDown(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->MoveSelectionDown(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::MoveSelectionNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::MoveSelectionNext(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->MoveSelectionNext(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::MoveSelectionPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::MoveSelectionPrevious(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->MoveSelectionPrevious(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::SelectNext(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::SelectNext(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->SelectNext(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
NS_IMETHODIMP nsHTMLEditor::SelectPrevious(nsIAtom *aIncrement, PRBool aExtendSelection)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::SelectPrevious(aIncrement, aExtendSelection);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->SelectPrevious(aIncrement, aExtendSelection);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::ScrollUp(nsIAtom *aIncrement)
|
NS_IMETHODIMP nsHTMLEditor::ScrollUp(nsIAtom *aIncrement)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::ScrollUp(aIncrement);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->ScrollUp(aIncrement);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::ScrollDown(nsIAtom *aIncrement)
|
NS_IMETHODIMP nsHTMLEditor::ScrollDown(nsIAtom *aIncrement)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::ScrollDown(aIncrement);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->ScrollDown(aIncrement);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin)
|
NS_IMETHODIMP nsHTMLEditor::ScrollIntoView(PRBool aScrollToBegin)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::ScrollIntoView(aScrollToBegin);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->ScrollIntoView(aScrollToBegin);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::Insert(nsIInputStream *aInputStream)
|
NS_IMETHODIMP nsHTMLEditor::Insert(nsIInputStream *aInputStream)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::Insert(aInputStream);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->Insert(aInputStream);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputText(nsIOutputStream *aOutputStream)
|
NS_IMETHODIMP nsHTMLEditor::OutputText(nsIOutputStream *aOutputStream)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::OutputText(aOutputStream);
|
||||||
if (mEditor)
|
|
||||||
{
|
|
||||||
result = mTextEditor->OutputText(aOutputStream);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsIOutputStream *aOutputStream)
|
NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsIOutputStream *aOutputStream)
|
||||||
{
|
{
|
||||||
nsresult result=NS_ERROR_NOT_INITIALIZED;
|
return Inherited::OutputHTML(aOutputStream);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//================================================================
|
//================================================================
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#define nsHTMLEditor_h__
|
#define nsHTMLEditor_h__
|
||||||
|
|
||||||
#include "nsITextEditor.h"
|
#include "nsITextEditor.h"
|
||||||
|
#include "nsTextEditor.h"
|
||||||
#include "nsIHTMLEditor.h"
|
#include "nsIHTMLEditor.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsIDOMEventListener.h"
|
#include "nsIDOMEventListener.h"
|
||||||
|
@ -29,20 +30,25 @@
|
||||||
* The HTML editor implementation.<br>
|
* The HTML editor implementation.<br>
|
||||||
* Use to edit HTML document represented as a DOM tree.
|
* 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:
|
public:
|
||||||
// see nsIHTMLEditor for documentation
|
// see nsIHTMLEditor for documentation
|
||||||
|
|
||||||
//Interfaces for addref and release and queryinterface
|
//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
|
//Initialization
|
||||||
nsHTMLEditor();
|
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
|
||||||
NS_IMETHOD InitHTMLEditor(nsIDOMDocument *aDoc,
|
|
||||||
nsIPresShell *aPresShell,
|
|
||||||
nsIEditorCallback *aCallback=nsnull);
|
|
||||||
virtual ~nsHTMLEditor();
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
// Methods that are duplicates of nsTextEditor -- exposed here for convenience
|
// Methods that are duplicates of nsTextEditor -- exposed here for convenience
|
||||||
|
@ -103,8 +109,6 @@ public:
|
||||||
|
|
||||||
// Data members
|
// Data members
|
||||||
protected:
|
protected:
|
||||||
nsCOMPtr<nsIEditor> mEditor;
|
|
||||||
nsCOMPtr<nsITextEditor> mTextEditor;
|
|
||||||
|
|
||||||
// EVENT LISTENERS AND COMMAND ROUTING NEEDS WORK
|
// EVENT LISTENERS AND COMMAND ROUTING NEEDS WORK
|
||||||
// For now, the listners are tied to the nsTextEditor class
|
// 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
|
* 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
|
* @param aPresShell TEMP: The presentation shell displaying the document
|
||||||
* once events can tell us from what pres shell they originated,
|
* once events can tell us from what pres shell they originated,
|
||||||
* this will no longer be necessary and the editor will no longer be
|
* this will no longer be necessary and the editor will no longer be
|
||||||
* linked to a single pres shell.
|
* linked to a single pres shell.
|
||||||
*/
|
*/
|
||||||
NS_IMETHOD Init(nsIDOMDocument *aDomInterface,
|
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell )=0;
|
||||||
nsIPresShell *aPresShell) = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the DOM Document this editor is associated with
|
* return the DOM Document this editor is associated with
|
||||||
|
@ -303,15 +302,6 @@ public:
|
||||||
*/
|
*/
|
||||||
NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin)=0;
|
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__
|
#endif //nsIEditor_h__
|
||||||
|
|
|
@ -46,9 +46,7 @@ public:
|
||||||
/** Initialize the text editor
|
/** Initialize the text editor
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
NS_IMETHOD InitHTMLEditor(nsIDOMDocument *aDoc,
|
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell )=0;
|
||||||
nsIPresShell *aPresShell,
|
|
||||||
nsIEditorCallback *aCallback=nsnull)=0;
|
|
||||||
|
|
||||||
// Methods shared with nsITextEditor (see nsITextEditor.h for details)
|
// Methods shared with nsITextEditor (see nsITextEditor.h for details)
|
||||||
NS_IMETHOD SetTextProperty(nsIAtom *aProperty)=0;
|
NS_IMETHOD SetTextProperty(nsIAtom *aProperty)=0;
|
||||||
|
|
|
@ -53,9 +53,7 @@ public:
|
||||||
/** Initialize the text editor
|
/** Initialize the text editor
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
NS_IMETHOD InitTextEditor(nsIDOMDocument *aDoc,
|
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell)=0;
|
||||||
nsIPresShell *aPresShell,
|
|
||||||
nsIEditorCallback *aCallback=nsnull)=0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SetTextProperties() sets the aggregate properties on the current selection
|
* SetTextProperties() sets the aggregate properties on the current selection
|
||||||
|
|
Загрузка…
Ссылка в новой задаче