From 6e3a97f5c5d2287805f5c201fa99bc309cd00f33 Mon Sep 17 00:00:00 2001 From: "jfrancis%netscape.com" Date: Fri, 30 Jun 2000 04:58:34 +0000 Subject: [PATCH] fix for undo in ender-lite (text fields, url bar, etc) git-svn-id: svn://10.0.0.236/trunk@73575 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/PlaceholderTxn.cpp | 25 ++++++------------- mozilla/editor/base/PlaceholderTxn.h | 6 ++--- mozilla/editor/base/nsEditor.cpp | 2 +- mozilla/editor/base/nsIAbsorbingTransaction.h | 8 +++--- .../editor/libeditor/base/PlaceholderTxn.cpp | 25 ++++++------------- .../editor/libeditor/base/PlaceholderTxn.h | 6 ++--- mozilla/editor/libeditor/base/nsEditor.cpp | 2 +- .../libeditor/base/nsIAbsorbingTransaction.h | 8 +++--- 8 files changed, 30 insertions(+), 52 deletions(-) diff --git a/mozilla/editor/base/PlaceholderTxn.cpp b/mozilla/editor/base/PlaceholderTxn.cpp index 9188958e7b5..55a8a4916a3 100644 --- a/mozilla/editor/base/PlaceholderTxn.cpp +++ b/mozilla/editor/base/PlaceholderTxn.cpp @@ -35,13 +35,13 @@ static const PRBool gNoisy = PR_FALSE; PlaceholderTxn::PlaceholderTxn() : EditAggregateTxn(), - mPresShellWeak(nsnull), mAbsorb(PR_TRUE), mForwarding(nsnull), mIMETextTxn(nsnull), mCommitted(PR_FALSE), mStartSel(nsnull), - mEndSel() + mEndSel(), + mEditor(nsnull) { SetTransactionDescriptionID( kTransactionID ); /* log description initialized in parent constructor */ @@ -74,16 +74,13 @@ NS_IMETHODIMP PlaceholderTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr) return EditAggregateTxn::QueryInterface(aIID, aInstancePtr); } -NS_IMETHODIMP PlaceholderTxn::Init(nsWeakPtr aPresShellWeak, nsIAtom *aName, - nsSelectionState *aSelState) +NS_IMETHODIMP PlaceholderTxn::Init(nsIAtom *aName, nsSelectionState *aSelState, nsIEditor *aEditor) { - NS_ASSERTION(aPresShellWeak, "bad args"); - if (!aPresShellWeak || !aSelState) return NS_ERROR_NULL_POINTER; + if (!aEditor || !aSelState) return NS_ERROR_NULL_POINTER; - mPresShellWeak = aPresShellWeak; mName = aName; mStartSel = aSelState; - + mEditor = aEditor; return NS_OK; } @@ -100,10 +97,8 @@ NS_IMETHODIMP PlaceholderTxn::Undo(void) if (NS_FAILED(res)) return res; // now restore selection - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); - if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); + res = mEditor->GetSelection(getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; if (!mStartSel) return NS_ERROR_NULL_POINTER; @@ -119,10 +114,8 @@ NS_IMETHODIMP PlaceholderTxn::Redo(void) if (NS_FAILED(res)) return res; // now restore selection - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); - if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); + res = mEditor->GetSelection(getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; res = mEndSel.RestoreSelection(selection); @@ -272,10 +265,8 @@ NS_IMETHODIMP PlaceholderTxn::Commit() NS_IMETHODIMP PlaceholderTxn::RememberEndingSelection() { - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); - if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - nsresult res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); + nsresult res = mEditor->GetSelection(getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; res = mEndSel.SaveSelection(selection); diff --git a/mozilla/editor/base/PlaceholderTxn.h b/mozilla/editor/base/PlaceholderTxn.h index 80ed51a88f9..d3c792d5cd7 100644 --- a/mozilla/editor/base/PlaceholderTxn.h +++ b/mozilla/editor/base/PlaceholderTxn.h @@ -75,7 +75,7 @@ public: // ------------ nsIAbsorbingTransaction ----------------------- - NS_IMETHOD Init(nsWeakPtr aPresShellWeak, nsIAtom *aName, nsSelectionState *aSelState); + NS_IMETHOD Init(nsIAtom *aName, nsSelectionState *aSelState, nsIEditor *aEditor); NS_IMETHOD GetTxnName(nsIAtom **aName); @@ -96,7 +96,6 @@ public: protected: /** the presentation shell, which we'll need to get the selection */ - nsWeakPtr mPresShellWeak; // weak reference to the nsIPresShell PRBool mAbsorb; // do we auto absorb any and all transaction? nsWeakPtr mForwarding; IMETextTxn *mIMETextTxn; // first IME txn in this placeholder - used for IME merging @@ -105,8 +104,9 @@ protected: // these next two members store the state of the selection in a safe way. // selection at the start of the txn is stored, as is the selection at the end. // This is so that Undo() and Redo() can restore the selection properly. - nsSelectionState *mStartSel; // use a pointer because this is constructed before we exist + nsSelectionState *mStartSel; // use a pointer because this is constructed before we exist nsSelectionState mEndSel; + nsIEditor* mEditor; /** the editor for this transaction */ }; diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index 32118743863..fa5a79afaf7 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -990,7 +990,7 @@ nsEditor::Do(nsITransaction *aTxn) // save off weak reference to placeholder txn mPlaceHolderTxn = getter_AddRefs( NS_GetWeakReference(plcTxn) ); - plcTxn->Init(mPresShellWeak, mPlaceHolderName, mSelState); + plcTxn->Init(mPlaceHolderName, mSelState, this); mSelState = nsnull; // placeholder txn took ownership of this pointer // finally we QI to an nsITransaction since that's what Do() expects diff --git a/mozilla/editor/base/nsIAbsorbingTransaction.h b/mozilla/editor/base/nsIAbsorbingTransaction.h index 48c915c2acc..a88f82f7b53 100644 --- a/mozilla/editor/base/nsIAbsorbingTransaction.h +++ b/mozilla/editor/base/nsIAbsorbingTransaction.h @@ -35,12 +35,10 @@ Transaction interface to outside world 0x15b3, \ 0x11d2, \ {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } -#include "nsCOMPtr.h" -#include "nsWeakPtr.h" -#include "nsIAtom.h" -#include "nsIDOMNode.h" class nsSelectionState; +class nsIEditor; +class nsIAtom; /** * A transaction interface mixin - for transactions that can support. @@ -51,7 +49,7 @@ public: static const nsIID& GetIID() { static nsIID iid = NS_IABSORBINGTRANSACTION_IID; return iid; } - NS_IMETHOD Init(nsWeakPtr aPresShellWeak, nsIAtom *aName, nsSelectionState *aSelState)=0; + NS_IMETHOD Init(nsIAtom *aName, nsSelectionState *aSelState, nsIEditor *aEditor)=0; NS_IMETHOD EndPlaceHolderBatch()=0; diff --git a/mozilla/editor/libeditor/base/PlaceholderTxn.cpp b/mozilla/editor/libeditor/base/PlaceholderTxn.cpp index 9188958e7b5..55a8a4916a3 100644 --- a/mozilla/editor/libeditor/base/PlaceholderTxn.cpp +++ b/mozilla/editor/libeditor/base/PlaceholderTxn.cpp @@ -35,13 +35,13 @@ static const PRBool gNoisy = PR_FALSE; PlaceholderTxn::PlaceholderTxn() : EditAggregateTxn(), - mPresShellWeak(nsnull), mAbsorb(PR_TRUE), mForwarding(nsnull), mIMETextTxn(nsnull), mCommitted(PR_FALSE), mStartSel(nsnull), - mEndSel() + mEndSel(), + mEditor(nsnull) { SetTransactionDescriptionID( kTransactionID ); /* log description initialized in parent constructor */ @@ -74,16 +74,13 @@ NS_IMETHODIMP PlaceholderTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr) return EditAggregateTxn::QueryInterface(aIID, aInstancePtr); } -NS_IMETHODIMP PlaceholderTxn::Init(nsWeakPtr aPresShellWeak, nsIAtom *aName, - nsSelectionState *aSelState) +NS_IMETHODIMP PlaceholderTxn::Init(nsIAtom *aName, nsSelectionState *aSelState, nsIEditor *aEditor) { - NS_ASSERTION(aPresShellWeak, "bad args"); - if (!aPresShellWeak || !aSelState) return NS_ERROR_NULL_POINTER; + if (!aEditor || !aSelState) return NS_ERROR_NULL_POINTER; - mPresShellWeak = aPresShellWeak; mName = aName; mStartSel = aSelState; - + mEditor = aEditor; return NS_OK; } @@ -100,10 +97,8 @@ NS_IMETHODIMP PlaceholderTxn::Undo(void) if (NS_FAILED(res)) return res; // now restore selection - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); - if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); + res = mEditor->GetSelection(getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; if (!mStartSel) return NS_ERROR_NULL_POINTER; @@ -119,10 +114,8 @@ NS_IMETHODIMP PlaceholderTxn::Redo(void) if (NS_FAILED(res)) return res; // now restore selection - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); - if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); + res = mEditor->GetSelection(getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; res = mEndSel.RestoreSelection(selection); @@ -272,10 +265,8 @@ NS_IMETHODIMP PlaceholderTxn::Commit() NS_IMETHODIMP PlaceholderTxn::RememberEndingSelection() { - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); - if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - nsresult res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); + nsresult res = mEditor->GetSelection(getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; res = mEndSel.SaveSelection(selection); diff --git a/mozilla/editor/libeditor/base/PlaceholderTxn.h b/mozilla/editor/libeditor/base/PlaceholderTxn.h index 80ed51a88f9..d3c792d5cd7 100644 --- a/mozilla/editor/libeditor/base/PlaceholderTxn.h +++ b/mozilla/editor/libeditor/base/PlaceholderTxn.h @@ -75,7 +75,7 @@ public: // ------------ nsIAbsorbingTransaction ----------------------- - NS_IMETHOD Init(nsWeakPtr aPresShellWeak, nsIAtom *aName, nsSelectionState *aSelState); + NS_IMETHOD Init(nsIAtom *aName, nsSelectionState *aSelState, nsIEditor *aEditor); NS_IMETHOD GetTxnName(nsIAtom **aName); @@ -96,7 +96,6 @@ public: protected: /** the presentation shell, which we'll need to get the selection */ - nsWeakPtr mPresShellWeak; // weak reference to the nsIPresShell PRBool mAbsorb; // do we auto absorb any and all transaction? nsWeakPtr mForwarding; IMETextTxn *mIMETextTxn; // first IME txn in this placeholder - used for IME merging @@ -105,8 +104,9 @@ protected: // these next two members store the state of the selection in a safe way. // selection at the start of the txn is stored, as is the selection at the end. // This is so that Undo() and Redo() can restore the selection properly. - nsSelectionState *mStartSel; // use a pointer because this is constructed before we exist + nsSelectionState *mStartSel; // use a pointer because this is constructed before we exist nsSelectionState mEndSel; + nsIEditor* mEditor; /** the editor for this transaction */ }; diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index 32118743863..fa5a79afaf7 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -990,7 +990,7 @@ nsEditor::Do(nsITransaction *aTxn) // save off weak reference to placeholder txn mPlaceHolderTxn = getter_AddRefs( NS_GetWeakReference(plcTxn) ); - plcTxn->Init(mPresShellWeak, mPlaceHolderName, mSelState); + plcTxn->Init(mPlaceHolderName, mSelState, this); mSelState = nsnull; // placeholder txn took ownership of this pointer // finally we QI to an nsITransaction since that's what Do() expects diff --git a/mozilla/editor/libeditor/base/nsIAbsorbingTransaction.h b/mozilla/editor/libeditor/base/nsIAbsorbingTransaction.h index 48c915c2acc..a88f82f7b53 100644 --- a/mozilla/editor/libeditor/base/nsIAbsorbingTransaction.h +++ b/mozilla/editor/libeditor/base/nsIAbsorbingTransaction.h @@ -35,12 +35,10 @@ Transaction interface to outside world 0x15b3, \ 0x11d2, \ {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } -#include "nsCOMPtr.h" -#include "nsWeakPtr.h" -#include "nsIAtom.h" -#include "nsIDOMNode.h" class nsSelectionState; +class nsIEditor; +class nsIAtom; /** * A transaction interface mixin - for transactions that can support. @@ -51,7 +49,7 @@ public: static const nsIID& GetIID() { static nsIID iid = NS_IABSORBINGTRANSACTION_IID; return iid; } - NS_IMETHOD Init(nsWeakPtr aPresShellWeak, nsIAtom *aName, nsSelectionState *aSelState)=0; + NS_IMETHOD Init(nsIAtom *aName, nsSelectionState *aSelState, nsIEditor *aEditor)=0; NS_IMETHOD EndPlaceHolderBatch()=0;