From b5d751e9330eb132effbd2d993e5f74a3027e1bd Mon Sep 17 00:00:00 2001 From: "mrbkap%gmail.com" Date: Sat, 22 Sep 2007 21:06:58 +0000 Subject: [PATCH] Restore the right caret in all cases. bug 395888, r+sr+a=roc git-svn-id: svn://10.0.0.236/trunk@236507 18797224-902f-48f8-a5cc-f745e15eee43 --- .../libeditor/text/nsEditorEventListeners.cpp | 29 +++++++------------ .../libeditor/text/nsEditorEventListeners.h | 1 - mozilla/layout/base/nsIPresShell.h | 16 ++++++---- mozilla/layout/base/nsPresShell.cpp | 15 ++++++---- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp index b9bfdeefff2..681bf85290d 100644 --- a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp @@ -524,25 +524,21 @@ nsresult nsTextEditorDragListener::DragEnter(nsIDOMEvent* aDragEvent) { nsCOMPtr presShell = do_QueryReferent(mPresShell); + if (!presShell) + return NS_OK; + if (!mCaret) { - if (presShell) + mCaret = do_CreateInstance("@mozilla.org/layout/caret;1"); + if (mCaret) { - mCaret = do_CreateInstance("@mozilla.org/layout/caret;1"); - if (mCaret) - { - mCaret->Init(presShell); - mCaret->SetCaretReadOnly(PR_TRUE); - - mOtherCaret = presShell->SetCaret(mCaret); - } - mCaretDrawn = PR_FALSE; + mCaret->Init(presShell); + mCaret->SetCaretReadOnly(PR_TRUE); } + mCaretDrawn = PR_FALSE; } - else if (presShell) - { - presShell->SetCaret(mCaret); - } + + presShell->SetCaret(mCaret); return DragOver(aDragEvent); } @@ -644,11 +640,8 @@ nsTextEditorDragListener::DragDrop(nsIDOMEvent* aMouseEvent) nsCOMPtr presShell = do_QueryReferent(mPresShell); if (presShell) { - NS_ASSERTION(mOtherCaret, "Where'd my other caret go?"); - mCaret = presShell->SetCaret(mOtherCaret); + presShell->RestoreCaret(); } - - mOtherCaret = mCaret = nsnull; } if (!mEditor) diff --git a/mozilla/editor/libeditor/text/nsEditorEventListeners.h b/mozilla/editor/libeditor/text/nsEditorEventListeners.h index 63accc648ca..8b4c1d95a8c 100644 --- a/mozilla/editor/libeditor/text/nsEditorEventListeners.h +++ b/mozilla/editor/libeditor/text/nsEditorEventListeners.h @@ -237,7 +237,6 @@ protected: nsWeakPtr mPresShell; nsCOMPtr mCaret; - nsCOMPtr mOtherCaret; PRBool mCaretDrawn; }; diff --git a/mozilla/layout/base/nsIPresShell.h b/mozilla/layout/base/nsIPresShell.h index 2068157f3b2..72011ea894d 100644 --- a/mozilla/layout/base/nsIPresShell.h +++ b/mozilla/layout/base/nsIPresShell.h @@ -102,10 +102,10 @@ class gfxContext; typedef short SelectionType; typedef PRUint32 nsFrameState; -// D93B931B-D5EF-4D3C-AB99-444176963464 +// 4BE324F2-FB22-47CD-A653-19C70EE55E3F #define NS_IPRESSHELL_IID \ -{ 0xd93b931b, 0xd5ef, 0x4d3c, \ - { 0xab, 0x99, 0x44, 0x41, 0x76, 0x96, 0x34, 0x64 } } +{ 0x4BE324F2, 0xFB22, 0x47CD, \ + { 0xA6, 0x53, 0x19, 0xC7, 0x0E, 0xE5, 0x5E, 0x3F } } // Constants for ScrollContentIntoView() function #define NS_PRESSHELL_SCROLL_TOP 0 @@ -495,9 +495,15 @@ public: NS_IMETHOD_(void) MaybeInvalidateCaretPosition() = 0; /** - * Set the current caret to a new caret. Returns the old caret. + * Set the current caret to a new caret. To undo this, call RestoreCaret. */ - virtual already_AddRefed SetCaret(nsICaret *aNewCaret) = 0; + virtual void SetCaret(nsICaret *aNewCaret) = 0; + + /** + * Restore the caret to the original caret that this pres shell was created + * with. + */ + virtual void RestoreCaret() = 0; /** * Should the images have borders etc. Actual visual effects are determined diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index a54235c6cc2..28ffbc77b24 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -917,7 +917,8 @@ public: NS_IMETHOD SetCaretReadOnly(PRBool aReadOnly); NS_IMETHOD GetCaretEnabled(PRBool *aOutEnabled); NS_IMETHOD SetCaretVisibilityDuringSelection(PRBool aVisibility); - virtual already_AddRefed SetCaret(nsICaret *aNewCaret); + virtual void SetCaret(nsICaret *aNewCaret); + virtual void RestoreCaret(); NS_IMETHOD SetSelectionFlags(PRInt16 aInEnable); NS_IMETHOD GetSelectionFlags(PRInt16 *aOutEnable); @@ -1130,6 +1131,7 @@ protected: nsCOMArray mCurrentEventContentStack; nsCOMPtr mCaret; + nsCOMPtr mOriginalCaret; PRInt16 mSelectionFlags; FrameArena mFrameArena; StackArena mStackArena; @@ -1498,6 +1500,7 @@ PresShell::Init(nsIDocument* aDocument, if (NS_SUCCEEDED(err)) { mCaret->Init(this); + mOriginalCaret = mCaret; } //SetCaretEnabled(PR_TRUE); // make it show in browser windows @@ -2616,12 +2619,14 @@ NS_IMETHODIMP_(void) PresShell::MaybeInvalidateCaretPosition() } } -already_AddRefed PresShell::SetCaret(nsICaret *aNewCaret) +void PresShell::SetCaret(nsICaret *aNewCaret) { - nsICaret *oldCaret = nsnull; - mCaret.swap(oldCaret); mCaret = aNewCaret; - return oldCaret; +} + +void PresShell::RestoreCaret() +{ + mCaret = mOriginalCaret; } NS_IMETHODIMP PresShell::SetCaretEnabled(PRBool aInEnable)