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
Родитель e7a027d3f9
Коммит 3eef98bc2b
5 изменённых файлов: 149 добавлений и 62 удалений

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

@ -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.
*/

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

@ -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<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
PresShell::ContentChanged(nsIDocument *aDocument,
nsIContent* aContent,

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

@ -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.
*/

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

@ -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<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
PresShell::ContentChanged(nsIDocument *aDocument,
nsIContent* aContent,

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

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