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
This commit is contained in:
jst%netscape.com
2001-01-23 07:45:08 +00:00
parent 1e3e1cbc56
commit ba329b0451
2 changed files with 62 additions and 54 deletions

View File

@@ -2861,39 +2861,43 @@ nsHTMLDocument::GetSelection(nsAWritableString& aReturn)
{
aReturn.Truncate();
nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0);
if (!shell)
return NS_OK;
nsCOMPtr<nsIFrameSelection> selection;
shell->GetFrameSelection(getter_AddRefs(selection));
if (!selection)
return NS_OK;
nsCOMPtr<nsISelection> domSelection;
selection->GetSelection(nsISelectionController::SELECTION_NORMAL,
getter_AddRefs(domSelection));
if (!domSelection)
return NS_OK;
nsCOMPtr<nsISelectionPrivate> privSel(do_QueryInterface(domSelection));
nsCOMPtr<nsIConsoleService> 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<nsIPresContext> cx;
shell->GetPresContext(getter_AddRefs(cx));
NS_ENSURE_TRUE(cx, NS_OK);
nsCOMPtr<nsISupports> container;
cx->GetContainer(getter_AddRefs(container));
NS_ENSURE_TRUE(container, NS_OK);
nsCOMPtr<nsIDOMWindow> window(do_GetInterface(container));
NS_ENSURE_TRUE(window, NS_OK);
nsCOMPtr<nsISelection> 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;
}