Move bulk of DoCopy code from nsBrowserWindow.cpp into nsPresShell

This commit is contained in:
akkana%netscape.com 1999-03-01 19:21:01 +00:00
Родитель f9fd062256
Коммит 48dcd3da7a
5 изменённых файлов: 149 добавлений и 62 удалений

Просмотреть файл

@ -38,6 +38,7 @@ class nsString;
class nsStringArray; class nsStringArray;
class nsICaret; class nsICaret;
class nsIStyleContext; class nsIStyleContext;
class nsISelectionMgr;
#define NS_IPRESSHELL_IID \ #define NS_IPRESSHELL_IID \
{ 0x76e79c60, 0x944e, 0x11d1, \ { 0x76e79c60, 0x944e, 0x11d1, \
@ -255,6 +256,11 @@ public:
PRInt32 aHOffsetPercent, PRInt32 aHOffsetPercent,
PRUint32 aHFlags) const = 0; 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. * Get the caret, if it exists. AddRefs it.
*/ */

Просмотреть файл

@ -57,6 +57,11 @@
#include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLDocument.h"
#include "nsIScrollableView.h" #include "nsIScrollableView.h"
#include "nsIDOMSelectionListener.h" #include "nsIDOMSelectionListener.h"
#include "nsISelectionMgr.h"
#include "nsIParser.h"
#include "nsParserCIID.h"
#include "nsHTMLContentSinkStream.h"
#include "nsXIFDTD.h"
static PRBool gsNoisyRefs = PR_FALSE; static PRBool gsNoisyRefs = PR_FALSE;
@ -292,6 +297,7 @@ public:
PRUint32 aVFlags, PRUint32 aVFlags,
PRInt32 aHOffsetPercent, PRInt32 aHOffsetPercent,
PRUint32 aHFlags) const; PRUint32 aHFlags) const;
NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr);
//nsIViewObserver interface //nsIViewObserver interface
@ -1468,6 +1474,67 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame,
return rv; return rv;
} }
NS_IMETHODIMP
PresShell::DoCopy(nsISelectionMgr* aSelectionMgr)
{
nsCOMPtr<nsIDocument> 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(&copyStream);
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 NS_IMETHODIMP
PresShell::ContentChanged(nsIDocument *aDocument, PresShell::ContentChanged(nsIDocument *aDocument,
nsIContent* aContent, nsIContent* aContent,

Просмотреть файл

@ -38,6 +38,7 @@ class nsString;
class nsStringArray; class nsStringArray;
class nsICaret; class nsICaret;
class nsIStyleContext; class nsIStyleContext;
class nsISelectionMgr;
#define NS_IPRESSHELL_IID \ #define NS_IPRESSHELL_IID \
{ 0x76e79c60, 0x944e, 0x11d1, \ { 0x76e79c60, 0x944e, 0x11d1, \
@ -255,6 +256,11 @@ public:
PRInt32 aHOffsetPercent, PRInt32 aHOffsetPercent,
PRUint32 aHFlags) const = 0; 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. * Get the caret, if it exists. AddRefs it.
*/ */

Просмотреть файл

@ -57,6 +57,11 @@
#include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLDocument.h"
#include "nsIScrollableView.h" #include "nsIScrollableView.h"
#include "nsIDOMSelectionListener.h" #include "nsIDOMSelectionListener.h"
#include "nsISelectionMgr.h"
#include "nsIParser.h"
#include "nsParserCIID.h"
#include "nsHTMLContentSinkStream.h"
#include "nsXIFDTD.h"
static PRBool gsNoisyRefs = PR_FALSE; static PRBool gsNoisyRefs = PR_FALSE;
@ -292,6 +297,7 @@ public:
PRUint32 aVFlags, PRUint32 aVFlags,
PRInt32 aHOffsetPercent, PRInt32 aHOffsetPercent,
PRUint32 aHFlags) const; PRUint32 aHFlags) const;
NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr);
//nsIViewObserver interface //nsIViewObserver interface
@ -1468,6 +1474,67 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame,
return rv; return rv;
} }
NS_IMETHODIMP
PresShell::DoCopy(nsISelectionMgr* aSelectionMgr)
{
nsCOMPtr<nsIDocument> 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(&copyStream);
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 NS_IMETHODIMP
PresShell::ContentChanged(nsIDocument *aDocument, PresShell::ContentChanged(nsIDocument *aDocument,
nsIContent* aContent, nsIContent* aContent,

Просмотреть файл

@ -2067,68 +2067,9 @@ nsBrowserWindow::DoCopy()
{ {
nsIPresShell* shell = GetPresShell(); nsIPresShell* shell = GetPresShell();
if (nsnull != shell) { if (nsnull != shell) {
nsCOMPtr<nsIDocument> doc; nsISelectionMgr* selectionMgr;
shell->GetDocument(getter_AddRefs(doc)); if (NS_SUCCEEDED(mAppShell->GetSelectionMgr(&selectionMgr)))
if (doc) { shell->DoCopy(selectionMgr);
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(&copyStream)))
{
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);
}
}
NS_RELEASE(shell); NS_RELEASE(shell);
} }
} }