From b1edeeb86aaa02eaf803ac0eaf7b2fb154e04189 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Fri, 28 Apr 2000 14:05:45 +0000 Subject: [PATCH] Hooking up document.getSelection() for html documents to return a string so that we're compatible with 4.x. git-svn-id: svn://10.0.0.236/trunk@67533 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/document/src/nsHTMLDocument.cpp | 32 +++++++++++++++++-- .../html/document/src/nsHTMLDocument.cpp | 32 +++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 7ea2496dfa9..8ce7b03a27e 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -75,6 +75,7 @@ #include "nsICookieService.h" #include "nsIServiceManager.h" +#include "nsIConsoleService.h" #include "nsIFormManager.h" #include "nsIComponentManager.h" #include "nsParserCIID.h" @@ -89,6 +90,7 @@ #include "nsIFile.h" #include "nsIEventListenerManager.h" #include "nsISelectElement.h" +#include "nsIFrameSelection.h" #include "nsICharsetDetector.h" #include "nsICharsetDetectionAdaptor.h" @@ -2449,9 +2451,35 @@ nsHTMLDocument::GetPlugins(nsIDOMHTMLCollection** aPlugins) NS_IMETHODIMP nsHTMLDocument::GetSelection(nsString& aReturn) { - //XXX TBImplemented aReturn.Truncate(); - return NS_OK; + + nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0); + + if (!shell) + return NS_OK; + + nsCOMPtr selection; + shell->GetFrameSelection(getter_AddRefs(selection)); + + if (!selection) + return NS_OK; + + nsCOMPtr domSelection; + + selection->GetSelection(nsISelectionController::SELECTION_NORMAL, + getter_AddRefs(domSelection)); + + if (!domSelection) + return NS_OK; + + nsCOMPtr consoleService + (do_GetService("mozilla.consoleservice.1")); + + if (consoleService) { + consoleService->LogStringMessage(NS_ConvertASCIItoUCS2("Depricated method document.getSelection() called, use window.getSelection() in stead!").GetUnicode()); + } + + return domSelection->ToString(aReturn); } NS_IMETHODIMP diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp index 7ea2496dfa9..8ce7b03a27e 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp @@ -75,6 +75,7 @@ #include "nsICookieService.h" #include "nsIServiceManager.h" +#include "nsIConsoleService.h" #include "nsIFormManager.h" #include "nsIComponentManager.h" #include "nsParserCIID.h" @@ -89,6 +90,7 @@ #include "nsIFile.h" #include "nsIEventListenerManager.h" #include "nsISelectElement.h" +#include "nsIFrameSelection.h" #include "nsICharsetDetector.h" #include "nsICharsetDetectionAdaptor.h" @@ -2449,9 +2451,35 @@ nsHTMLDocument::GetPlugins(nsIDOMHTMLCollection** aPlugins) NS_IMETHODIMP nsHTMLDocument::GetSelection(nsString& aReturn) { - //XXX TBImplemented aReturn.Truncate(); - return NS_OK; + + nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0); + + if (!shell) + return NS_OK; + + nsCOMPtr selection; + shell->GetFrameSelection(getter_AddRefs(selection)); + + if (!selection) + return NS_OK; + + nsCOMPtr domSelection; + + selection->GetSelection(nsISelectionController::SELECTION_NORMAL, + getter_AddRefs(domSelection)); + + if (!domSelection) + return NS_OK; + + nsCOMPtr consoleService + (do_GetService("mozilla.consoleservice.1")); + + if (consoleService) { + consoleService->LogStringMessage(NS_ConvertASCIItoUCS2("Depricated method document.getSelection() called, use window.getSelection() in stead!").GetUnicode()); + } + + return domSelection->ToString(aReturn); } NS_IMETHODIMP