From a14fff24109b3367c358e06e4532e63bb9b4d4a4 Mon Sep 17 00:00:00 2001 From: "sfraser%netscape.com" Date: Thu, 28 Sep 2000 00:31:48 +0000 Subject: [PATCH] Fix for 52150; show caret in new composer/mail composer/AIM windows. If the editor is focussed on creation, show the caret instead of relying on a focus event. r, sr = kin,saari, hyatt git-svn-id: svn://10.0.0.236/trunk@80042 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsEditorShell.cpp | 40 +++++++++++++++++++ mozilla/editor/composer/src/nsEditorShell.cpp | 40 +++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 7c691805930..d0dc0ea5006 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -39,6 +39,7 @@ #include "nsIDiskDocument.h" #include "nsIDocument.h" #include "nsIDOMWindowInternal.h" +#include "nsPIDOMWindow.h" #include "nsIDOMNode.h" #include "nsIDOMNodeList.h" #include "nsICSSLoader.h" @@ -91,6 +92,8 @@ #include "nsIRefreshURI.h" #include "nsIPref.h" +#include "nsILookAndFeel.h" + /////////////////////////////////////// // Editor Includes /////////////////////////////////////// @@ -630,6 +633,43 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr // (this also turns on the caret) mEditor->SetCaretToDocumentStart(); } + + // show the caret, if our window is focussed already + nsCOMPtr contentInternal = do_QueryReferent(mContentWindow); + nsCOMPtr privContent(do_QueryInterface(contentInternal)); + + if (privContent) + { + nsCOMPtr commandDispatcher; + privContent->GetRootCommandDispatcher(getter_AddRefs(commandDispatcher)); + + if (commandDispatcher) + { + nsCOMPtr focussedWindow; + commandDispatcher->GetFocusedWindow(getter_AddRefs(focussedWindow)); + + if (focussedWindow.get() == contentInternal.get()) // now see if we are focussed + { + nsCOMPtr selCon; + editor->GetSelectionController(getter_AddRefs(selCon)); + + PRInt32 pixelWidth = 1; + + static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); + + nsCOMPtr lookNFeel = do_GetService(kLookAndFeelCID); + if (lookNFeel) + lookNFeel->GetMetric(nsILookAndFeel::eMetric_MultiLineCaretWidth, pixelWidth); + + selCon->SetCaretWidth(pixelWidth); + selCon->SetCaretEnabled(PR_FALSE); + selCon->SetCaretEnabled(PR_TRUE); // make damn sure it shows; the last SetVisible + // may have happened when we didn't have focus. + selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); + } + } + } + return NS_OK; } diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 7c691805930..d0dc0ea5006 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -39,6 +39,7 @@ #include "nsIDiskDocument.h" #include "nsIDocument.h" #include "nsIDOMWindowInternal.h" +#include "nsPIDOMWindow.h" #include "nsIDOMNode.h" #include "nsIDOMNodeList.h" #include "nsICSSLoader.h" @@ -91,6 +92,8 @@ #include "nsIRefreshURI.h" #include "nsIPref.h" +#include "nsILookAndFeel.h" + /////////////////////////////////////// // Editor Includes /////////////////////////////////////// @@ -630,6 +633,43 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr // (this also turns on the caret) mEditor->SetCaretToDocumentStart(); } + + // show the caret, if our window is focussed already + nsCOMPtr contentInternal = do_QueryReferent(mContentWindow); + nsCOMPtr privContent(do_QueryInterface(contentInternal)); + + if (privContent) + { + nsCOMPtr commandDispatcher; + privContent->GetRootCommandDispatcher(getter_AddRefs(commandDispatcher)); + + if (commandDispatcher) + { + nsCOMPtr focussedWindow; + commandDispatcher->GetFocusedWindow(getter_AddRefs(focussedWindow)); + + if (focussedWindow.get() == contentInternal.get()) // now see if we are focussed + { + nsCOMPtr selCon; + editor->GetSelectionController(getter_AddRefs(selCon)); + + PRInt32 pixelWidth = 1; + + static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); + + nsCOMPtr lookNFeel = do_GetService(kLookAndFeelCID); + if (lookNFeel) + lookNFeel->GetMetric(nsILookAndFeel::eMetric_MultiLineCaretWidth, pixelWidth); + + selCon->SetCaretWidth(pixelWidth); + selCon->SetCaretEnabled(PR_FALSE); + selCon->SetCaretEnabled(PR_TRUE); // make damn sure it shows; the last SetVisible + // may have happened when we didn't have focus. + selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); + } + } + } + return NS_OK; }