From ba329b045105219a08268e47fb28ffe26b744f7e Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Tue, 23 Jan 2001 07:45:08 +0000 Subject: [PATCH] Fixing bug 57772. Hooking document.getSelection() into window.getSelection().toString() which does the right thing (i.e. doesn't produce pretty printed text). r=heikk@netscape.com, sr=rpotts@netscape.com git-svn-id: svn://10.0.0.236/trunk@85358 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/document/src/nsHTMLDocument.cpp | 58 ++++++++++--------- .../html/document/src/nsHTMLDocument.cpp | 58 ++++++++++--------- 2 files changed, 62 insertions(+), 54 deletions(-) diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index c028c707eb9..8dbb95949a0 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -2861,39 +2861,43 @@ nsHTMLDocument::GetSelection(nsAWritableString& aReturn) { aReturn.Truncate(); - 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 privSel(do_QueryInterface(domSelection)); - nsCOMPtr consoleService (do_GetService("@mozilla.org/consoleservice;1")); - + if (consoleService) { consoleService->LogStringMessage(NS_LITERAL_STRING("Deprecated method document.getSelection() called. Please use window.getSelection() instead.").get()); } - PRUnichar *tmp; - nsresult rv = privSel->ToStringWithFormat("text/plain", nsIDocumentEncoder::OutputFormatted |nsIDocumentEncoder::OutputSelectionOnly, 0, &tmp); - if (tmp) - { - aReturn.Assign(tmp); - nsMemory::Free(tmp); + + nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(0); + + if (!shell) { + return NS_OK; } + + nsCOMPtr cx; + + shell->GetPresContext(getter_AddRefs(cx)); + NS_ENSURE_TRUE(cx, NS_OK); + + nsCOMPtr container; + + cx->GetContainer(getter_AddRefs(container)); + NS_ENSURE_TRUE(container, NS_OK); + + nsCOMPtr window(do_GetInterface(container)); + NS_ENSURE_TRUE(window, NS_OK); + + nsCOMPtr selection; + + nsresult rv = window->GetSelection(getter_AddRefs(selection)); + NS_ENSURE_TRUE(selection && NS_SUCCEEDED(rv), rv); + + nsXPIDLString str; + + rv = selection->ToString(getter_Copies(str)); + + aReturn.Assign(str); + return rv; } diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp index c028c707eb9..8dbb95949a0 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp @@ -2861,39 +2861,43 @@ nsHTMLDocument::GetSelection(nsAWritableString& aReturn) { aReturn.Truncate(); - 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 privSel(do_QueryInterface(domSelection)); - nsCOMPtr consoleService (do_GetService("@mozilla.org/consoleservice;1")); - + if (consoleService) { consoleService->LogStringMessage(NS_LITERAL_STRING("Deprecated method document.getSelection() called. Please use window.getSelection() instead.").get()); } - PRUnichar *tmp; - nsresult rv = privSel->ToStringWithFormat("text/plain", nsIDocumentEncoder::OutputFormatted |nsIDocumentEncoder::OutputSelectionOnly, 0, &tmp); - if (tmp) - { - aReturn.Assign(tmp); - nsMemory::Free(tmp); + + nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(0); + + if (!shell) { + return NS_OK; } + + nsCOMPtr cx; + + shell->GetPresContext(getter_AddRefs(cx)); + NS_ENSURE_TRUE(cx, NS_OK); + + nsCOMPtr container; + + cx->GetContainer(getter_AddRefs(container)); + NS_ENSURE_TRUE(container, NS_OK); + + nsCOMPtr window(do_GetInterface(container)); + NS_ENSURE_TRUE(window, NS_OK); + + nsCOMPtr selection; + + nsresult rv = window->GetSelection(getter_AddRefs(selection)); + NS_ENSURE_TRUE(selection && NS_SUCCEEDED(rv), rv); + + nsXPIDLString str; + + rv = selection->ToString(getter_Copies(str)); + + aReturn.Assign(str); + return rv; }