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; }