mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
made GetIsTransient return false by default, so most transactions don't need to implement GetIsTransient
made delete and backspace do the right thing (testing hacks removed)
This commit is contained in:
parent
1edca9201b
commit
d93ebdb1ac
@ -95,13 +95,6 @@ nsresult ChangeAttributeTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult ChangeAttributeTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult ChangeAttributeTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -54,8 +54,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -93,13 +93,6 @@ nsresult CreateElementTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult CreateElementTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult CreateElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -57,8 +57,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -113,13 +113,6 @@ nsresult DeleteElementTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult DeleteElementTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult DeleteElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -51,8 +51,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -153,13 +153,6 @@ nsresult DeleteRangeTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult DeleteRangeTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult DeleteRangeTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -55,8 +55,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -49,13 +49,6 @@ nsresult DeleteTextTxn::Undo(void)
|
||||
return (mElement->InsertData(mOffset, mDeletedText));
|
||||
}
|
||||
|
||||
nsresult DeleteTextTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult DeleteTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -49,7 +49,6 @@ public:
|
||||
|
||||
virtual nsresult Undo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
|
@ -100,7 +100,7 @@ nsresult EditAggregateTxn::Redo(void)
|
||||
nsresult EditAggregateTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_TRUE;
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ nsresult EditTxn::Redo(void)
|
||||
nsresult EditTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_TRUE;
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -49,13 +49,6 @@ nsresult InsertTextTxn::Undo(void)
|
||||
return (mElement->DeleteData(mOffset, length));
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
// set out param default value
|
||||
|
@ -50,8 +50,6 @@ public:
|
||||
|
||||
virtual nsresult Undo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -71,13 +71,6 @@ nsresult SplitElementTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult SplitElementTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult SplitElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -50,8 +50,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "TransactionFactory.h"
|
||||
// transactions this factory knows how to build
|
||||
#include "EditAggregateTxn.h"
|
||||
#include "InsertTextTxn.h"
|
||||
#include "DeleteTextTxn.h"
|
||||
#include "CreateElementTxn.h"
|
||||
@ -27,6 +28,7 @@
|
||||
#include "SplitElementTxn.h"
|
||||
#include "JoinElementTxn.h"
|
||||
|
||||
static NS_DEFINE_IID(kEditAggregateTxnIID, EDIT_AGGREGATE_TXN_IID);
|
||||
static NS_DEFINE_IID(kInsertTextTxnIID, INSERT_TEXT_TXN_IID);
|
||||
static NS_DEFINE_IID(kDeleteTextTxnIID, DELETE_TEXT_TXN_IID);
|
||||
static NS_DEFINE_IID(kCreateElementTxnIID, CREATE_ELEMENT_TXN_IID);
|
||||
@ -65,6 +67,8 @@ TransactionFactory::GetNewTransaction(REFNSIID aTxnType, EditTxn **aResult)
|
||||
*aResult = new SplitElementTxn();
|
||||
else if (aTxnType.Equals(kJoinElementTxnIID))
|
||||
*aResult = new JoinElementTxn();
|
||||
else if (aTxnType.Equals(kEditAggregateTxnIID))
|
||||
*aResult = new EditAggregateTxn();
|
||||
|
||||
if (nsnull==*aResult)
|
||||
result = NS_ERROR_INVALID_ARG;
|
||||
|
@ -826,17 +826,18 @@ nsresult nsEditor::CreateTxnForDeleteText(nsIDOMCharacterData *aElement,
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsEditor::DeleteSelection()
|
||||
nsEditor::DeleteSelection(nsIEditor::Direction aDir)
|
||||
{
|
||||
EditAggregateTxn *txn;
|
||||
nsresult result = CreateTxnForDeleteSelection(&txn);
|
||||
nsresult result = CreateTxnForDeleteSelection(aDir, &txn);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = Do(txn);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsEditor::CreateTxnForDeleteSelection(EditAggregateTxn ** aTxn)
|
||||
nsresult nsEditor::CreateTxnForDeleteSelection(nsIEditor::Direction aDir,
|
||||
EditAggregateTxn ** aTxn)
|
||||
{
|
||||
nsresult result;
|
||||
// allocate the out-param transaction
|
||||
@ -854,21 +855,52 @@ nsresult nsEditor::CreateTxnForDeleteSelection(EditAggregateTxn ** aTxn)
|
||||
enumerator->First();
|
||||
nsISupports *currentItem;
|
||||
result = enumerator->CurrentItem(¤tItem);
|
||||
while ((NS_SUCCEEDED(result)) && (nsnull!=currentItem))
|
||||
/*while */ if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem))
|
||||
{
|
||||
nsCOMPtr<nsIDOMRange> range(currentItem);
|
||||
DeleteRangeTxn *txn;
|
||||
result = TransactionFactory::GetNewTransaction(kDeleteRangeTxnIID, (EditTxn **)&txn);
|
||||
if (nsnull!=txn)
|
||||
PRBool isCollapsed;
|
||||
range->GetIsCollapsed(&isCollapsed);
|
||||
if (PR_FALSE==isCollapsed)
|
||||
{
|
||||
txn->Init(range);
|
||||
(*aTxn)->AppendChild(txn);
|
||||
DeleteRangeTxn *txn;
|
||||
result = TransactionFactory::GetNewTransaction(kDeleteRangeTxnIID, (EditTxn **)&txn);
|
||||
if (nsnull!=txn)
|
||||
{
|
||||
txn->Init(range);
|
||||
(*aTxn)->AppendChild(txn);
|
||||
}
|
||||
else
|
||||
result = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else
|
||||
result = NS_ERROR_OUT_OF_MEMORY;
|
||||
{ // we have an insertion point. delete the thing in front of it or behind it, depending on aDir
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
PRInt32 offset;
|
||||
PRInt32 length=1;
|
||||
result = range->GetStartParent(getter_AddRefs(node));
|
||||
result = range->GetStartOffset(&offset);
|
||||
nsCOMPtr<nsIDOMCharacterData> text = node.get();
|
||||
if (node)
|
||||
{ // we have text, so delete a char at the proper offset
|
||||
// XXX: doesn't handle beginning/end of text node, which needs to jump to next|prev node
|
||||
if (nsIEditor::eRTL==aDir)
|
||||
{
|
||||
if (0!=offset)
|
||||
offset --;
|
||||
}
|
||||
DeleteTextTxn *txn;
|
||||
result = CreateTxnForDeleteText(text, offset, length, &txn);
|
||||
(*aTxn)->AppendChild(txn);
|
||||
}
|
||||
}
|
||||
// XXX: should call IsDone -- waiting for fix from greg
|
||||
// when fixed, change if to while
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
nsresult nextResult = enumerator->Next();
|
||||
// XXX hack for now
|
||||
if (nextResult==NS_ERROR_FAILURE)
|
||||
return result;
|
||||
if (NS_SUCCEEDED(nextResult))
|
||||
{
|
||||
result = enumerator->CurrentItem(¤tItem);
|
||||
|
@ -162,7 +162,7 @@ public:
|
||||
nsresult DeleteElement(nsIDOMNode * aParent,
|
||||
nsIDOMNode * aElement);
|
||||
|
||||
nsresult DeleteSelection();
|
||||
nsresult DeleteSelection(nsIEditor::Direction aDir);
|
||||
|
||||
nsresult InsertText(const nsString& aStringToInsert);
|
||||
|
||||
@ -215,7 +215,8 @@ protected:
|
||||
PRUint32 aLength,
|
||||
DeleteTextTxn **aTxn);
|
||||
|
||||
nsresult CreateTxnForDeleteSelection(EditAggregateTxn ** aTxn);
|
||||
nsresult CreateTxnForDeleteSelection(nsIEditor::Direction aDir,
|
||||
EditAggregateTxn ** aTxn);
|
||||
|
||||
|
||||
};
|
||||
|
@ -136,58 +136,11 @@ nsEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
||||
{
|
||||
switch(keyCode) {
|
||||
case nsIDOMEvent::VK_BACK:
|
||||
{
|
||||
if (PR_FALSE==ctrlKey)
|
||||
{
|
||||
// XXX: for now, just grab the first text node
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMNode> textNode;
|
||||
nsCOMPtr<nsIDOMCharacterData> text;
|
||||
if (NS_SUCCEEDED(mEditor->GetCurrentNode(getter_AddRefs(currentNode))) &&
|
||||
NS_SUCCEEDED(mEditor->GetFirstTextNode(currentNode,getter_AddRefs(textNode))) &&
|
||||
NS_SUCCEEDED(textNode->QueryInterface(kIDOMCharacterDataIID, getter_AddRefs(text))))
|
||||
{
|
||||
// XXX: for now, just append the text
|
||||
PRUint32 offset;
|
||||
text->GetLength(&offset);
|
||||
nsresult result = mEditor->DeleteText(text, offset-1, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mEditor->DeleteSelection();
|
||||
}
|
||||
}
|
||||
mEditor->DeleteSelection(nsIEditor::eRTL);
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_DELETE:
|
||||
{
|
||||
if (PR_FALSE==ctrlKey)
|
||||
{
|
||||
// XXX: for now, just grab the first text node
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMNode> textNode;
|
||||
nsCOMPtr<nsIDOMCharacterData> text;
|
||||
if (NS_SUCCEEDED(mEditor->GetCurrentNode(getter_AddRefs(currentNode))) &&
|
||||
NS_SUCCEEDED(mEditor->GetFirstTextNode(currentNode,getter_AddRefs(textNode))) &&
|
||||
NS_SUCCEEDED(textNode->QueryInterface(kIDOMCharacterDataIID, getter_AddRefs(text))))
|
||||
{
|
||||
nsresult result = mEditor->DeleteText(text, 0, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // XXX: delete the first P we find
|
||||
nsAutoString pTag("P");
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, pTag, getter_AddRefs(currentNode))))
|
||||
{
|
||||
currentNode->GetParentNode(getter_AddRefs(parentNode));
|
||||
nsresult result = mEditor->DeleteElement(parentNode, currentNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
mEditor->DeleteSelection(nsIEditor::eLTR);
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_RETURN:
|
||||
|
@ -95,13 +95,6 @@ nsresult ChangeAttributeTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult ChangeAttributeTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult ChangeAttributeTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -54,8 +54,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -93,13 +93,6 @@ nsresult CreateElementTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult CreateElementTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult CreateElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -57,8 +57,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -113,13 +113,6 @@ nsresult DeleteElementTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult DeleteElementTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult DeleteElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -51,8 +51,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -153,13 +153,6 @@ nsresult DeleteRangeTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult DeleteRangeTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult DeleteRangeTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -55,8 +55,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -49,13 +49,6 @@ nsresult DeleteTextTxn::Undo(void)
|
||||
return (mElement->InsertData(mOffset, mDeletedText));
|
||||
}
|
||||
|
||||
nsresult DeleteTextTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult DeleteTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -49,7 +49,6 @@ public:
|
||||
|
||||
virtual nsresult Undo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
|
@ -100,7 +100,7 @@ nsresult EditAggregateTxn::Redo(void)
|
||||
nsresult EditAggregateTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_TRUE;
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ nsresult EditTxn::Redo(void)
|
||||
nsresult EditTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_TRUE;
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -49,13 +49,6 @@ nsresult InsertTextTxn::Undo(void)
|
||||
return (mElement->DeleteData(mOffset, length));
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
// set out param default value
|
||||
|
@ -50,8 +50,6 @@ public:
|
||||
|
||||
virtual nsresult Undo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -71,13 +71,6 @@ nsresult SplitElementTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult SplitElementTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult SplitElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -50,8 +50,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "TransactionFactory.h"
|
||||
// transactions this factory knows how to build
|
||||
#include "EditAggregateTxn.h"
|
||||
#include "InsertTextTxn.h"
|
||||
#include "DeleteTextTxn.h"
|
||||
#include "CreateElementTxn.h"
|
||||
@ -27,6 +28,7 @@
|
||||
#include "SplitElementTxn.h"
|
||||
#include "JoinElementTxn.h"
|
||||
|
||||
static NS_DEFINE_IID(kEditAggregateTxnIID, EDIT_AGGREGATE_TXN_IID);
|
||||
static NS_DEFINE_IID(kInsertTextTxnIID, INSERT_TEXT_TXN_IID);
|
||||
static NS_DEFINE_IID(kDeleteTextTxnIID, DELETE_TEXT_TXN_IID);
|
||||
static NS_DEFINE_IID(kCreateElementTxnIID, CREATE_ELEMENT_TXN_IID);
|
||||
@ -65,6 +67,8 @@ TransactionFactory::GetNewTransaction(REFNSIID aTxnType, EditTxn **aResult)
|
||||
*aResult = new SplitElementTxn();
|
||||
else if (aTxnType.Equals(kJoinElementTxnIID))
|
||||
*aResult = new JoinElementTxn();
|
||||
else if (aTxnType.Equals(kEditAggregateTxnIID))
|
||||
*aResult = new EditAggregateTxn();
|
||||
|
||||
if (nsnull==*aResult)
|
||||
result = NS_ERROR_INVALID_ARG;
|
||||
|
@ -826,17 +826,18 @@ nsresult nsEditor::CreateTxnForDeleteText(nsIDOMCharacterData *aElement,
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsEditor::DeleteSelection()
|
||||
nsEditor::DeleteSelection(nsIEditor::Direction aDir)
|
||||
{
|
||||
EditAggregateTxn *txn;
|
||||
nsresult result = CreateTxnForDeleteSelection(&txn);
|
||||
nsresult result = CreateTxnForDeleteSelection(aDir, &txn);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = Do(txn);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsEditor::CreateTxnForDeleteSelection(EditAggregateTxn ** aTxn)
|
||||
nsresult nsEditor::CreateTxnForDeleteSelection(nsIEditor::Direction aDir,
|
||||
EditAggregateTxn ** aTxn)
|
||||
{
|
||||
nsresult result;
|
||||
// allocate the out-param transaction
|
||||
@ -854,21 +855,52 @@ nsresult nsEditor::CreateTxnForDeleteSelection(EditAggregateTxn ** aTxn)
|
||||
enumerator->First();
|
||||
nsISupports *currentItem;
|
||||
result = enumerator->CurrentItem(¤tItem);
|
||||
while ((NS_SUCCEEDED(result)) && (nsnull!=currentItem))
|
||||
/*while */ if ((NS_SUCCEEDED(result)) && (nsnull!=currentItem))
|
||||
{
|
||||
nsCOMPtr<nsIDOMRange> range(currentItem);
|
||||
DeleteRangeTxn *txn;
|
||||
result = TransactionFactory::GetNewTransaction(kDeleteRangeTxnIID, (EditTxn **)&txn);
|
||||
if (nsnull!=txn)
|
||||
PRBool isCollapsed;
|
||||
range->GetIsCollapsed(&isCollapsed);
|
||||
if (PR_FALSE==isCollapsed)
|
||||
{
|
||||
txn->Init(range);
|
||||
(*aTxn)->AppendChild(txn);
|
||||
DeleteRangeTxn *txn;
|
||||
result = TransactionFactory::GetNewTransaction(kDeleteRangeTxnIID, (EditTxn **)&txn);
|
||||
if (nsnull!=txn)
|
||||
{
|
||||
txn->Init(range);
|
||||
(*aTxn)->AppendChild(txn);
|
||||
}
|
||||
else
|
||||
result = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else
|
||||
result = NS_ERROR_OUT_OF_MEMORY;
|
||||
{ // we have an insertion point. delete the thing in front of it or behind it, depending on aDir
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
PRInt32 offset;
|
||||
PRInt32 length=1;
|
||||
result = range->GetStartParent(getter_AddRefs(node));
|
||||
result = range->GetStartOffset(&offset);
|
||||
nsCOMPtr<nsIDOMCharacterData> text = node.get();
|
||||
if (node)
|
||||
{ // we have text, so delete a char at the proper offset
|
||||
// XXX: doesn't handle beginning/end of text node, which needs to jump to next|prev node
|
||||
if (nsIEditor::eRTL==aDir)
|
||||
{
|
||||
if (0!=offset)
|
||||
offset --;
|
||||
}
|
||||
DeleteTextTxn *txn;
|
||||
result = CreateTxnForDeleteText(text, offset, length, &txn);
|
||||
(*aTxn)->AppendChild(txn);
|
||||
}
|
||||
}
|
||||
// XXX: should call IsDone -- waiting for fix from greg
|
||||
// when fixed, change if to while
|
||||
if (NS_SUCCEEDED(result))
|
||||
{
|
||||
nsresult nextResult = enumerator->Next();
|
||||
// XXX hack for now
|
||||
if (nextResult==NS_ERROR_FAILURE)
|
||||
return result;
|
||||
if (NS_SUCCEEDED(nextResult))
|
||||
{
|
||||
result = enumerator->CurrentItem(¤tItem);
|
||||
|
@ -162,7 +162,7 @@ public:
|
||||
nsresult DeleteElement(nsIDOMNode * aParent,
|
||||
nsIDOMNode * aElement);
|
||||
|
||||
nsresult DeleteSelection();
|
||||
nsresult DeleteSelection(nsIEditor::Direction aDir);
|
||||
|
||||
nsresult InsertText(const nsString& aStringToInsert);
|
||||
|
||||
@ -215,7 +215,8 @@ protected:
|
||||
PRUint32 aLength,
|
||||
DeleteTextTxn **aTxn);
|
||||
|
||||
nsresult CreateTxnForDeleteSelection(EditAggregateTxn ** aTxn);
|
||||
nsresult CreateTxnForDeleteSelection(nsIEditor::Direction aDir,
|
||||
EditAggregateTxn ** aTxn);
|
||||
|
||||
|
||||
};
|
||||
|
@ -136,58 +136,11 @@ nsEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
||||
{
|
||||
switch(keyCode) {
|
||||
case nsIDOMEvent::VK_BACK:
|
||||
{
|
||||
if (PR_FALSE==ctrlKey)
|
||||
{
|
||||
// XXX: for now, just grab the first text node
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMNode> textNode;
|
||||
nsCOMPtr<nsIDOMCharacterData> text;
|
||||
if (NS_SUCCEEDED(mEditor->GetCurrentNode(getter_AddRefs(currentNode))) &&
|
||||
NS_SUCCEEDED(mEditor->GetFirstTextNode(currentNode,getter_AddRefs(textNode))) &&
|
||||
NS_SUCCEEDED(textNode->QueryInterface(kIDOMCharacterDataIID, getter_AddRefs(text))))
|
||||
{
|
||||
// XXX: for now, just append the text
|
||||
PRUint32 offset;
|
||||
text->GetLength(&offset);
|
||||
nsresult result = mEditor->DeleteText(text, offset-1, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mEditor->DeleteSelection();
|
||||
}
|
||||
}
|
||||
mEditor->DeleteSelection(nsIEditor::eRTL);
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_DELETE:
|
||||
{
|
||||
if (PR_FALSE==ctrlKey)
|
||||
{
|
||||
// XXX: for now, just grab the first text node
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMNode> textNode;
|
||||
nsCOMPtr<nsIDOMCharacterData> text;
|
||||
if (NS_SUCCEEDED(mEditor->GetCurrentNode(getter_AddRefs(currentNode))) &&
|
||||
NS_SUCCEEDED(mEditor->GetFirstTextNode(currentNode,getter_AddRefs(textNode))) &&
|
||||
NS_SUCCEEDED(textNode->QueryInterface(kIDOMCharacterDataIID, getter_AddRefs(text))))
|
||||
{
|
||||
nsresult result = mEditor->DeleteText(text, 0, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // XXX: delete the first P we find
|
||||
nsAutoString pTag("P");
|
||||
nsCOMPtr<nsIDOMNode> currentNode;
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
if (NS_SUCCEEDED(mEditor->GetFirstNodeOfType(nsnull, pTag, getter_AddRefs(currentNode))))
|
||||
{
|
||||
currentNode->GetParentNode(getter_AddRefs(parentNode));
|
||||
nsresult result = mEditor->DeleteElement(parentNode, currentNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
mEditor->DeleteSelection(nsIEditor::eLTR);
|
||||
break;
|
||||
|
||||
case nsIDOMEvent::VK_RETURN:
|
||||
|
@ -95,13 +95,6 @@ nsresult ChangeAttributeTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult ChangeAttributeTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult ChangeAttributeTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -54,8 +54,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -93,13 +93,6 @@ nsresult CreateElementTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult CreateElementTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult CreateElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -57,8 +57,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -113,13 +113,6 @@ nsresult DeleteElementTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult DeleteElementTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult DeleteElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -51,8 +51,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -153,13 +153,6 @@ nsresult DeleteRangeTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult DeleteRangeTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult DeleteRangeTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -55,8 +55,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -49,13 +49,6 @@ nsresult DeleteTextTxn::Undo(void)
|
||||
return (mElement->InsertData(mOffset, mDeletedText));
|
||||
}
|
||||
|
||||
nsresult DeleteTextTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult DeleteTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -49,7 +49,6 @@ public:
|
||||
|
||||
virtual nsresult Undo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
|
@ -100,7 +100,7 @@ nsresult EditAggregateTxn::Redo(void)
|
||||
nsresult EditAggregateTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_TRUE;
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ nsresult EditTxn::Redo(void)
|
||||
nsresult EditTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_TRUE;
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -49,13 +49,6 @@ nsresult InsertTextTxn::Undo(void)
|
||||
return (mElement->DeleteData(mOffset, length));
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult InsertTextTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
// set out param default value
|
||||
|
@ -50,8 +50,6 @@ public:
|
||||
|
||||
virtual nsresult Undo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -71,13 +71,6 @@ nsresult SplitElementTxn::Redo(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult SplitElementTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult SplitElementTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
if (nsnull!=aDidMerge)
|
||||
|
@ -50,8 +50,6 @@ public:
|
||||
|
||||
virtual nsresult Redo(void);
|
||||
|
||||
virtual nsresult GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
virtual nsresult Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
virtual nsresult Write(nsIOutputStream *aOutputStream);
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "TransactionFactory.h"
|
||||
// transactions this factory knows how to build
|
||||
#include "EditAggregateTxn.h"
|
||||
#include "InsertTextTxn.h"
|
||||
#include "DeleteTextTxn.h"
|
||||
#include "CreateElementTxn.h"
|
||||
@ -27,6 +28,7 @@
|
||||
#include "SplitElementTxn.h"
|
||||
#include "JoinElementTxn.h"
|
||||
|
||||
static NS_DEFINE_IID(kEditAggregateTxnIID, EDIT_AGGREGATE_TXN_IID);
|
||||
static NS_DEFINE_IID(kInsertTextTxnIID, INSERT_TEXT_TXN_IID);
|
||||
static NS_DEFINE_IID(kDeleteTextTxnIID, DELETE_TEXT_TXN_IID);
|
||||
static NS_DEFINE_IID(kCreateElementTxnIID, CREATE_ELEMENT_TXN_IID);
|
||||
@ -65,6 +67,8 @@ TransactionFactory::GetNewTransaction(REFNSIID aTxnType, EditTxn **aResult)
|
||||
*aResult = new SplitElementTxn();
|
||||
else if (aTxnType.Equals(kJoinElementTxnIID))
|
||||
*aResult = new JoinElementTxn();
|
||||
else if (aTxnType.Equals(kEditAggregateTxnIID))
|
||||
*aResult = new EditAggregateTxn();
|
||||
|
||||
if (nsnull==*aResult)
|
||||
result = NS_ERROR_INVALID_ARG;
|
||||
|
Loading…
Reference in New Issue
Block a user