From 9513b53050196f98abba51b1db631ead7285da9d Mon Sep 17 00:00:00 2001 From: "mrbkap@gmail.com" Date: Sat, 22 Sep 2007 14:06:58 -0700 Subject: [PATCH] Restore the right caret in all cases. bug 395888, r+sr+a=roc --- .../libeditor/text/nsEditorEventListeners.cpp | 29 +++++++------------ .../libeditor/text/nsEditorEventListeners.h | 1 - layout/base/nsIPresShell.h | 16 ++++++---- layout/base/nsPresShell.cpp | 15 ++++++---- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/editor/libeditor/text/nsEditorEventListeners.cpp b/editor/libeditor/text/nsEditorEventListeners.cpp index b9bfdeefff22..681bf85290d1 100644 --- a/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/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/editor/libeditor/text/nsEditorEventListeners.h b/editor/libeditor/text/nsEditorEventListeners.h index 63accc648ca0..8b4c1d95a8c1 100644 --- a/editor/libeditor/text/nsEditorEventListeners.h +++ b/editor/libeditor/text/nsEditorEventListeners.h @@ -237,7 +237,6 @@ protected: nsWeakPtr mPresShell; nsCOMPtr mCaret; - nsCOMPtr mOtherCaret; PRBool mCaretDrawn; }; diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index 2068157f3b28..72011ea894de 100644 --- a/layout/base/nsIPresShell.h +++ b/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/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index a54235c6cc2f..28ffbc77b24b 100644 --- a/layout/base/nsPresShell.cpp +++ b/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)