From 48dcd3da7ae4520eca6973ca7735edfebd3043b1 Mon Sep 17 00:00:00 2001 From: "akkana%netscape.com" Date: Mon, 1 Mar 1999 19:21:01 +0000 Subject: [PATCH] Move bulk of DoCopy code from nsBrowserWindow.cpp into nsPresShell --- layout/base/nsIPresShell.h | 6 ++ layout/base/nsPresShell.cpp | 67 +++++++++++++++++++++++ layout/base/public/nsIPresShell.h | 6 ++ layout/html/base/src/nsPresShell.cpp | 67 +++++++++++++++++++++++ webshell/tests/viewer/nsBrowserWindow.cpp | 65 +--------------------- 5 files changed, 149 insertions(+), 62 deletions(-) diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index 2c92479d5801..34c44774bbcd 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -38,6 +38,7 @@ class nsString; class nsStringArray; class nsICaret; class nsIStyleContext; +class nsISelectionMgr; #define NS_IPRESSHELL_IID \ { 0x76e79c60, 0x944e, 0x11d1, \ @@ -255,6 +256,11 @@ public: PRInt32 aHOffsetPercent, PRUint32 aHFlags) const = 0; + /** + * Notify the SelectionMgr that we have something to copy. + */ + NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr) = 0; + /** * Get the caret, if it exists. AddRefs it. */ diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 02914cb899b3..ef2b559144e7 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -57,6 +57,11 @@ #include "nsIDOMHTMLDocument.h" #include "nsIScrollableView.h" #include "nsIDOMSelectionListener.h" +#include "nsISelectionMgr.h" +#include "nsIParser.h" +#include "nsParserCIID.h" +#include "nsHTMLContentSinkStream.h" +#include "nsXIFDTD.h" static PRBool gsNoisyRefs = PR_FALSE; @@ -292,6 +297,7 @@ public: PRUint32 aVFlags, PRInt32 aHOffsetPercent, PRUint32 aHFlags) const; + NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr); //nsIViewObserver interface @@ -1468,6 +1474,67 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame, return rv; } +NS_IMETHODIMP +PresShell::DoCopy(nsISelectionMgr* aSelectionMgr) +{ + nsCOMPtr doc; + GetDocument(getter_AddRefs(doc)); + if (doc) { + nsString buffer; + + nsIDOMSelection* sel = nsnull; + GetSelection(&sel); + + if (sel != nsnull) + doc->CreateXIF(buffer,sel); + NS_IF_RELEASE(sel); + + nsIParser* parser; + + static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); + static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); + + nsresult rv = nsRepository::CreateInstance(kCParserCID, + nsnull, + kCParserIID, + (void **)&parser); + + if (NS_OK != rv) + return rv; + + nsIHTMLContentSink* sink = nsnull; + + rv = NS_New_HTML_ContentSinkStream(&sink,PR_FALSE,PR_FALSE); + + ostream* copyStream; + rv = aSelectionMgr->GetCopyOStream(©Stream); + if (!NS_SUCCEEDED(rv)) + return rv; + + ((nsHTMLContentSinkStream*)sink)->SetOutputStream(*copyStream); + + if (NS_OK == rv) { + parser->SetContentSink(sink); + + nsIDTD* dtd = nsnull; + rv = NS_NewXIFDTD(&dtd); + if (NS_OK == rv) + { + parser->RegisterDTD(dtd); + //dtd->SetContentSink(sink); + //dtd->SetParser(parser); + parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE); + } + NS_IF_RELEASE(dtd); + NS_IF_RELEASE(sink); + + aSelectionMgr->CopyToClipboard(); + } + NS_RELEASE(parser); + } + return NS_OK; +} + NS_IMETHODIMP PresShell::ContentChanged(nsIDocument *aDocument, nsIContent* aContent, diff --git a/layout/base/public/nsIPresShell.h b/layout/base/public/nsIPresShell.h index 2c92479d5801..34c44774bbcd 100644 --- a/layout/base/public/nsIPresShell.h +++ b/layout/base/public/nsIPresShell.h @@ -38,6 +38,7 @@ class nsString; class nsStringArray; class nsICaret; class nsIStyleContext; +class nsISelectionMgr; #define NS_IPRESSHELL_IID \ { 0x76e79c60, 0x944e, 0x11d1, \ @@ -255,6 +256,11 @@ public: PRInt32 aHOffsetPercent, PRUint32 aHFlags) const = 0; + /** + * Notify the SelectionMgr that we have something to copy. + */ + NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr) = 0; + /** * Get the caret, if it exists. AddRefs it. */ diff --git a/layout/html/base/src/nsPresShell.cpp b/layout/html/base/src/nsPresShell.cpp index 02914cb899b3..ef2b559144e7 100644 --- a/layout/html/base/src/nsPresShell.cpp +++ b/layout/html/base/src/nsPresShell.cpp @@ -57,6 +57,11 @@ #include "nsIDOMHTMLDocument.h" #include "nsIScrollableView.h" #include "nsIDOMSelectionListener.h" +#include "nsISelectionMgr.h" +#include "nsIParser.h" +#include "nsParserCIID.h" +#include "nsHTMLContentSinkStream.h" +#include "nsXIFDTD.h" static PRBool gsNoisyRefs = PR_FALSE; @@ -292,6 +297,7 @@ public: PRUint32 aVFlags, PRInt32 aHOffsetPercent, PRUint32 aHFlags) const; + NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr); //nsIViewObserver interface @@ -1468,6 +1474,67 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame, return rv; } +NS_IMETHODIMP +PresShell::DoCopy(nsISelectionMgr* aSelectionMgr) +{ + nsCOMPtr doc; + GetDocument(getter_AddRefs(doc)); + if (doc) { + nsString buffer; + + nsIDOMSelection* sel = nsnull; + GetSelection(&sel); + + if (sel != nsnull) + doc->CreateXIF(buffer,sel); + NS_IF_RELEASE(sel); + + nsIParser* parser; + + static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); + static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); + + nsresult rv = nsRepository::CreateInstance(kCParserCID, + nsnull, + kCParserIID, + (void **)&parser); + + if (NS_OK != rv) + return rv; + + nsIHTMLContentSink* sink = nsnull; + + rv = NS_New_HTML_ContentSinkStream(&sink,PR_FALSE,PR_FALSE); + + ostream* copyStream; + rv = aSelectionMgr->GetCopyOStream(©Stream); + if (!NS_SUCCEEDED(rv)) + return rv; + + ((nsHTMLContentSinkStream*)sink)->SetOutputStream(*copyStream); + + if (NS_OK == rv) { + parser->SetContentSink(sink); + + nsIDTD* dtd = nsnull; + rv = NS_NewXIFDTD(&dtd); + if (NS_OK == rv) + { + parser->RegisterDTD(dtd); + //dtd->SetContentSink(sink); + //dtd->SetParser(parser); + parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE); + } + NS_IF_RELEASE(dtd); + NS_IF_RELEASE(sink); + + aSelectionMgr->CopyToClipboard(); + } + NS_RELEASE(parser); + } + return NS_OK; +} + NS_IMETHODIMP PresShell::ContentChanged(nsIDocument *aDocument, nsIContent* aContent, diff --git a/webshell/tests/viewer/nsBrowserWindow.cpp b/webshell/tests/viewer/nsBrowserWindow.cpp index 0ab0c9a7cab1..07762fdfd499 100644 --- a/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/webshell/tests/viewer/nsBrowserWindow.cpp @@ -2067,68 +2067,9 @@ nsBrowserWindow::DoCopy() { nsIPresShell* shell = GetPresShell(); if (nsnull != shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); - if (doc) { - nsString buffer; - - nsIDOMSelection* sel = nsnull; - shell->GetSelection(&sel); - - if (sel != nsnull) - doc->CreateXIF(buffer,sel); - NS_IF_RELEASE(sel); - - nsIParser* parser; - - static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); - static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); - - nsresult rv = nsRepository::CreateInstance(kCParserCID, - nsnull, - kCParserIID, - (void **)&parser); - - if (NS_OK == rv) { - nsIHTMLContentSink* sink = nsnull; - - rv = NS_New_HTML_ContentSinkStream(&sink,PR_FALSE,PR_FALSE); - - nsISelectionMgr* selectionMgr; - if (!NS_SUCCEEDED(mAppShell->GetSelectionMgr(&selectionMgr)) - || !selectionMgr) - return; - - ostream* copyStream; - if (!NS_SUCCEEDED(selectionMgr->GetCopyOStream(©Stream))) - { - NS_RELEASE(selectionMgr); - return; - } - ((nsHTMLContentSinkStream*)sink)->SetOutputStream(*copyStream); - - if (NS_OK == rv) { - parser->SetContentSink(sink); - - nsIDTD* dtd = nsnull; - rv = NS_NewXIFDTD(&dtd); - if (NS_OK == rv) - { - parser->RegisterDTD(dtd); - //dtd->SetContentSink(sink); - //dtd->SetParser(parser); - parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE); - } - NS_IF_RELEASE(dtd); - NS_IF_RELEASE(sink); - - selectionMgr->CopyToClipboard(); - NS_RELEASE(selectionMgr); - } - NS_RELEASE(parser); - } - } - + nsISelectionMgr* selectionMgr; + if (NS_SUCCEEDED(mAppShell->GetSelectionMgr(&selectionMgr))) + shell->DoCopy(selectionMgr); NS_RELEASE(shell); } }