зеркало из https://github.com/mozilla/gecko-dev.git
Restructure the editor output routines to allow passing in
a mime type and a flag argument. Also fix the following bugs: 9746: get rid of bogus empty <style> in head. 8143: save wrap column in editor shell in case it's set before the editor is created. 9470, 9488: allow explicit specification of formatted output.
This commit is contained in:
Родитель
1b6f57843d
Коммит
a3fb11b98f
|
@ -37,14 +37,6 @@ class nsIPresShell;
|
||||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \
|
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NS_HTML_ENCODER_CID \
|
|
||||||
{ /* a6cf9104-15b3-11d2-932e-00805f8add32 */ \
|
|
||||||
0xa6cf9104, \
|
|
||||||
0x15b3, \
|
|
||||||
0x11d2, \
|
|
||||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define NS_TEXT_ENCODER_CID \
|
#define NS_TEXT_ENCODER_CID \
|
||||||
{ /* e7ba1480-1dea-11d3-830f-00104bed045e */ \
|
{ /* e7ba1480-1dea-11d3-830f-00104bed045e */ \
|
||||||
0xe7ba1480, \
|
0xe7ba1480, \
|
||||||
|
@ -53,6 +45,7 @@ class nsIPresShell;
|
||||||
{0x83, 0x0f, 0x00, 0x10, 0x4b, 0xed, 0x04, 0x5e} \
|
{0x83, 0x0f, 0x00, 0x10, 0x4b, 0xed, 0x04, 0x5e} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define NS_DOC_ENCODER_PROGID_BASE "component://netscape/layout/documentEncoder?type="
|
||||||
|
|
||||||
class nsIDocumentEncoder : public nsISupports
|
class nsIDocumentEncoder : public nsISupports
|
||||||
{
|
{
|
||||||
|
@ -64,7 +57,7 @@ public:
|
||||||
* Initialize with a pointer to the document and the mime type.
|
* Initialize with a pointer to the document and the mime type.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, nsString& aMimeType) = 0;
|
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, const nsString& aMimeType) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the selection is set to a non-null value, then the
|
* If the selection is set to a non-null value, then the
|
||||||
|
@ -98,24 +91,8 @@ public:
|
||||||
NS_IMETHOD EncodeToString(nsString& aOutputString) = 0;
|
NS_IMETHOD EncodeToString(nsString& aOutputString) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Example of a output service for a particular encoder
|
// Example of a output service for a particular encoder.
|
||||||
class nsIHTMLEncoder : public nsIDocumentEncoder
|
// The text encoder handles XIF, HTML, and plaintext.
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const nsIID& GetIID() { static nsIID iid = NS_HTML_ENCODER_CID; return iid; }
|
|
||||||
|
|
||||||
// Get embedded objects -- images, links, etc.
|
|
||||||
// NOTE: we may want to use an enumerator
|
|
||||||
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aObjects) = 0;
|
|
||||||
NS_IMETHOD SubstituteURL(const nsString& aOriginal,
|
|
||||||
const nsString& aReplacement) = 0;
|
|
||||||
NS_IMETHOD PrettyPrint(PRBool aYes) = 0;
|
|
||||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Example of a output service for a particular encoder
|
|
||||||
class nsITextEncoder : public nsIDocumentEncoder
|
class nsITextEncoder : public nsIDocumentEncoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -125,6 +102,7 @@ public:
|
||||||
// NOTE: we may want to use an enumerator
|
// NOTE: we may want to use an enumerator
|
||||||
NS_IMETHOD PrettyPrint(PRBool aYes) = 0;
|
NS_IMETHOD PrettyPrint(PRBool aYes) = 0;
|
||||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
|
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
|
||||||
|
NS_IMETHOD AddHeader(PRBool aYes) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2849,6 +2849,11 @@ nsDocument::IncrementModCount(PRInt32 aNumMods)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// FindContent does a depth-first search from aStartNode
|
||||||
|
// and returns the first of aTest1 or aTest2 which it finds.
|
||||||
|
// I think.
|
||||||
|
//
|
||||||
nsIContent* nsDocument::FindContent(const nsIContent* aStartNode,
|
nsIContent* nsDocument::FindContent(const nsIContent* aStartNode,
|
||||||
const nsIContent* aTest1,
|
const nsIContent* aTest1,
|
||||||
const nsIContent* aTest2) const
|
const nsIContent* aTest2) const
|
||||||
|
@ -2892,7 +2897,16 @@ PRBool nsDocument::IsInRange(const nsIContent *aStartContent, const nsIContent*
|
||||||
{
|
{
|
||||||
result = IsBefore(aStartContent,aContent);
|
result = IsBefore(aStartContent,aContent);
|
||||||
if (result == PR_TRUE)
|
if (result == PR_TRUE)
|
||||||
|
{
|
||||||
result = IsBefore(aContent,aEndContent);
|
result = IsBefore(aContent,aEndContent);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
// If aContent is a parent of aEndContent, then
|
||||||
|
// IsBefore returned false but IsInRange should be true.
|
||||||
|
if (FindContent(aContent, aEndContent, 0) == aEndContent)
|
||||||
|
result = PR_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|
|
@ -36,276 +36,8 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||||
|
|
||||||
static NS_DEFINE_CID(kCHTMLEncoderCID, NS_HTML_ENCODER_CID);
|
|
||||||
static NS_DEFINE_CID(kCTextEncoderCID, NS_TEXT_ENCODER_CID);
|
static NS_DEFINE_CID(kCTextEncoderCID, NS_TEXT_ENCODER_CID);
|
||||||
|
|
||||||
class nsHTMLEncoder : public nsIHTMLEncoder
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
|
|
||||||
|
|
||||||
nsHTMLEncoder();
|
|
||||||
virtual ~nsHTMLEncoder();
|
|
||||||
|
|
||||||
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, nsString& aMimeType);
|
|
||||||
|
|
||||||
/* Interfaces for addref and release and queryinterface */
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
|
|
||||||
// Inherited methods from nsIDocument
|
|
||||||
NS_IMETHOD SetSelection(nsIDOMSelection* aSelection);
|
|
||||||
NS_IMETHOD SetCharset(const nsString& aCharset);
|
|
||||||
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
|
|
||||||
NS_IMETHOD EncodeToString(nsString& aOutputString);
|
|
||||||
|
|
||||||
// Get embedded objects -- images, links, etc.
|
|
||||||
// NOTE: we may want to use an enumerator
|
|
||||||
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aObjects);
|
|
||||||
NS_IMETHOD SubstituteURL(const nsString& aOriginal,
|
|
||||||
const nsString& aReplacement);
|
|
||||||
NS_IMETHOD PrettyPrint(PRBool aYesNO);
|
|
||||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
|
|
||||||
|
|
||||||
private:
|
|
||||||
nsIDocument* mDocument;
|
|
||||||
nsIDOMSelection* mSelection;
|
|
||||||
nsIPresShell* mPresShell;
|
|
||||||
nsString mMimeType;
|
|
||||||
nsString mCharset;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF(nsHTMLEncoder)
|
|
||||||
// NS_IMPL_RELEASE(nsHTMLEncoder)
|
|
||||||
NS_IMETHODIMP_(nsrefcnt) nsHTMLEncoder::Release(void)
|
|
||||||
{
|
|
||||||
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
|
||||||
if (--mRefCnt == 0) {
|
|
||||||
NS_DELETEXPCOM(this);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return mRefCnt;
|
|
||||||
}
|
|
||||||
nsHTMLEncoder::nsHTMLEncoder() : mMimeType("text/html")
|
|
||||||
{
|
|
||||||
mDocument = 0;
|
|
||||||
mSelection = 0;
|
|
||||||
mPresShell = 0;
|
|
||||||
NS_INIT_REFCNT();
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLEncoder::~nsHTMLEncoder()
|
|
||||||
{
|
|
||||||
NS_IF_RELEASE(mDocument);
|
|
||||||
//NS_IF_RELEASE(mSelection); // no. we never addref'd it.
|
|
||||||
NS_IF_RELEASE(mPresShell);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
|
|
||||||
nsString& aMimeType)
|
|
||||||
{
|
|
||||||
if (!aDocument)
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
|
|
||||||
mDocument = aDocument;
|
|
||||||
NS_ADDREF(mDocument);
|
|
||||||
mPresShell = aPresShell;
|
|
||||||
NS_ADDREF(aPresShell);
|
|
||||||
mMimeType = aMimeType;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult nsHTMLEncoder::QueryInterface(REFNSIID aIID,
|
|
||||||
void **aInstancePtr)
|
|
||||||
{
|
|
||||||
if (nsnull == aInstancePtr)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
*aInstancePtr = 0;
|
|
||||||
|
|
||||||
if (aIID.Equals(kISupportsIID)) {
|
|
||||||
*aInstancePtr = (void *)(nsISupports*)this;
|
|
||||||
} else if (aIID.Equals(nsIDocumentEncoder::GetIID())) {
|
|
||||||
*aInstancePtr = (void *)(nsIDocumentEncoder*)this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nsnull == *aInstancePtr)
|
|
||||||
return NS_NOINTERFACE;
|
|
||||||
|
|
||||||
NS_ADDREF_THIS();
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::SetSelection(nsIDOMSelection* aSelection)
|
|
||||||
{
|
|
||||||
mSelection = aSelection;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::SetCharset(const nsString& aCharset)
|
|
||||||
{
|
|
||||||
mCharset = aCharset;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::EncodeToString(nsString& aOutputString)
|
|
||||||
{
|
|
||||||
nsresult rv;
|
|
||||||
|
|
||||||
if (!mDocument)
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
if (!mPresShell)
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
|
|
||||||
// xxx Also make sure mString is a mime type "text/html" or "text/plain"
|
|
||||||
|
|
||||||
if (mPresShell) {
|
|
||||||
if (mDocument) {
|
|
||||||
nsString buffer;
|
|
||||||
|
|
||||||
mDocument->CreateXIF(buffer,mSelection);
|
|
||||||
nsIParser* parser;
|
|
||||||
|
|
||||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
|
||||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
|
||||||
|
|
||||||
rv = nsComponentManager::CreateInstance(kCParserCID,
|
|
||||||
nsnull,
|
|
||||||
kCParserIID,
|
|
||||||
(void **)&parser);
|
|
||||||
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
nsIHTMLContentSink* sink = nsnull;
|
|
||||||
|
|
||||||
rv = NS_New_HTML_ContentSinkStream(&sink, &aOutputString,
|
|
||||||
PR_FALSE, PR_TRUE);
|
|
||||||
|
|
||||||
if (sink && NS_SUCCEEDED(rv)) {
|
|
||||||
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
parser->SetContentSink(sink);
|
|
||||||
|
|
||||||
nsIDTD* dtd = nsnull;
|
|
||||||
rv = NS_NewXIFDTD(&dtd);
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
parser->RegisterDTD(dtd);
|
|
||||||
parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE);
|
|
||||||
}
|
|
||||||
NS_IF_RELEASE(dtd);
|
|
||||||
NS_IF_RELEASE(sink);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NS_RELEASE(parser);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::EncodeToStream(nsIOutputStream* aStream)
|
|
||||||
{
|
|
||||||
nsresult rv;
|
|
||||||
|
|
||||||
if (!mDocument)
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
if (!mPresShell)
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
|
|
||||||
// xxx Also make sure mString is a mime type "text/html" or "text/plain"
|
|
||||||
|
|
||||||
if (mPresShell) {
|
|
||||||
if (mDocument) {
|
|
||||||
nsString buffer;
|
|
||||||
|
|
||||||
mDocument->CreateXIF(buffer,mSelection);
|
|
||||||
|
|
||||||
nsString* charset = nsnull;
|
|
||||||
nsAutoString defaultCharset("ISO-8859-1");
|
|
||||||
if (!mCharset.Equals("null") && !mCharset.Equals(""))
|
|
||||||
charset = &mCharset;
|
|
||||||
|
|
||||||
nsIParser* parser;
|
|
||||||
|
|
||||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
|
||||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
|
||||||
|
|
||||||
rv = nsComponentManager::CreateInstance(kCParserCID,
|
|
||||||
nsnull,
|
|
||||||
kCParserIID,
|
|
||||||
(void **)&parser);
|
|
||||||
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
nsIHTMLContentSink* sink = nsnull;
|
|
||||||
|
|
||||||
rv = NS_New_HTML_ContentSinkStream(&sink, aStream, charset,
|
|
||||||
PR_FALSE, PR_TRUE);
|
|
||||||
|
|
||||||
if (sink && NS_SUCCEEDED(rv)) {
|
|
||||||
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
parser->SetContentSink(sink);
|
|
||||||
|
|
||||||
nsIDTD* dtd = nsnull;
|
|
||||||
rv = NS_NewXIFDTD(&dtd);
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
parser->RegisterDTD(dtd);
|
|
||||||
parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE);
|
|
||||||
}
|
|
||||||
NS_IF_RELEASE(dtd);
|
|
||||||
NS_IF_RELEASE(sink);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NS_RELEASE(parser);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::GetEmbeddedObjects(nsISupportsArray* aObjects)
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::SubstituteURL(const nsString& aOriginal, const nsString& aReplacement)
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::PrettyPrint(PRBool)
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::SetWrapColumn(PRUint32)
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLEncoder(nsIDocumentEncoder** aResult)
|
|
||||||
{
|
|
||||||
*aResult = new nsHTMLEncoder;
|
|
||||||
if (!*aResult)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
NS_ADDREF(*aResult);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class nsTextEncoder : public nsITextEncoder
|
class nsTextEncoder : public nsITextEncoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -314,7 +46,8 @@ public:
|
||||||
nsTextEncoder();
|
nsTextEncoder();
|
||||||
virtual ~nsTextEncoder();
|
virtual ~nsTextEncoder();
|
||||||
|
|
||||||
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, nsString& aMimeType);
|
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
|
||||||
|
const nsString& aMimeType);
|
||||||
|
|
||||||
/* Interfaces for addref and release and queryinterface */
|
/* Interfaces for addref and release and queryinterface */
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
@ -325,8 +58,9 @@ public:
|
||||||
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
|
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
|
||||||
NS_IMETHOD EncodeToString(nsString& aOutputString);
|
NS_IMETHOD EncodeToString(nsString& aOutputString);
|
||||||
|
|
||||||
NS_IMETHOD PrettyPrint(PRBool aYesNO);
|
NS_IMETHOD PrettyPrint(PRBool aYes);
|
||||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
|
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
|
||||||
|
NS_IMETHOD AddHeader(PRBool aYes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsIDocument* mDocument;
|
nsIDocument* mDocument;
|
||||||
|
@ -336,6 +70,7 @@ private:
|
||||||
nsString mCharset;
|
nsString mCharset;
|
||||||
PRBool mPrettyPrint;
|
PRBool mPrettyPrint;
|
||||||
PRUint32 mWrapColumn;
|
PRUint32 mWrapColumn;
|
||||||
|
PRBool mAddHeader;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -357,7 +92,8 @@ nsTextEncoder::~nsTextEncoder()
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument, nsString& aMimeType)
|
nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
|
||||||
|
const nsString& aMimeType)
|
||||||
{
|
{
|
||||||
if (!aDocument)
|
if (!aDocument)
|
||||||
return NS_ERROR_INVALID_ARG;
|
return NS_ERROR_INVALID_ARG;
|
||||||
|
@ -409,6 +145,13 @@ nsTextEncoder::SetWrapColumn(PRUint32 aWC)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsTextEncoder::AddHeader(PRBool aYes)
|
||||||
|
{
|
||||||
|
mAddHeader = aYes;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsTextEncoder::SetSelection(nsIDOMSelection* aSelection)
|
nsTextEncoder::SetSelection(nsIDOMSelection* aSelection)
|
||||||
{
|
{
|
||||||
|
@ -441,7 +184,14 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
|
||||||
{
|
{
|
||||||
nsString buffer;
|
nsString buffer;
|
||||||
|
|
||||||
mDocument->CreateXIF(buffer,mSelection);
|
if (mMimeType == "text/xif")
|
||||||
|
{
|
||||||
|
mDocument->CreateXIF(aOutputString, mSelection);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
mDocument->CreateXIF(buffer, mSelection);
|
||||||
|
|
||||||
nsIParser* parser;
|
nsIParser* parser;
|
||||||
|
|
||||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||||
|
@ -456,19 +206,23 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
|
||||||
{
|
{
|
||||||
nsIHTMLContentSink* sink = nsnull;
|
nsIHTMLContentSink* sink = nsnull;
|
||||||
|
|
||||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
|
if (mMimeType == "text/html")
|
||||||
mWrapColumn, mPrettyPrint);
|
rv = NS_New_HTML_ContentSinkStream(&sink, &aOutputString,
|
||||||
|
PR_FALSE, mAddHeader);
|
||||||
if (sink && NS_SUCCEEDED(rv))
|
|
||||||
|
else // default to text/plain
|
||||||
|
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
|
||||||
|
mWrapColumn, mPrettyPrint);
|
||||||
|
|
||||||
|
if (sink && NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
parser->SetContentSink(sink);
|
parser->SetContentSink(sink);
|
||||||
|
|
||||||
nsIDTD* dtd = nsnull;
|
nsIDTD* dtd = nsnull;
|
||||||
rv = NS_NewXIFDTD(&dtd);
|
rv = NS_NewXIFDTD(&dtd);
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
parser->RegisterDTD(dtd);
|
parser->RegisterDTD(dtd);
|
||||||
parser->Parse(buffer, 0, "text/xif", PR_FALSE,PR_TRUE);
|
parser->Parse(buffer, 0, "text/xif", PR_FALSE, PR_TRUE);
|
||||||
}
|
}
|
||||||
NS_IF_RELEASE(dtd);
|
NS_IF_RELEASE(dtd);
|
||||||
NS_IF_RELEASE(sink);
|
NS_IF_RELEASE(sink);
|
||||||
|
@ -516,8 +270,13 @@ nsTextEncoder::EncodeToStream(nsIOutputStream* aStream)
|
||||||
if (NS_OK == rv) {
|
if (NS_OK == rv) {
|
||||||
nsIHTMLContentSink* sink = nsnull;
|
nsIHTMLContentSink* sink = nsnull;
|
||||||
|
|
||||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, aStream, charset,
|
if (mMimeType == "text/html")
|
||||||
mWrapColumn, mPrettyPrint);
|
rv = NS_New_HTML_ContentSinkStream(&sink, aStream, charset,
|
||||||
|
PR_FALSE, mAddHeader);
|
||||||
|
|
||||||
|
else
|
||||||
|
rv = NS_New_HTMLToTXT_SinkStream(&sink, aStream, charset,
|
||||||
|
mWrapColumn, mPrettyPrint);
|
||||||
|
|
||||||
if (sink && NS_SUCCEEDED(rv))
|
if (sink && NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
|
@ -613,9 +372,7 @@ nsDocumentEncoderFactory::CreateInstance(nsISupports *aOuter,
|
||||||
|
|
||||||
*aResult = 0;
|
*aResult = 0;
|
||||||
|
|
||||||
if (aIID.Equals(kCHTMLEncoderCID))
|
if (aIID.Equals(kCTextEncoderCID))
|
||||||
*aResult = new nsHTMLEncoder;
|
|
||||||
else if (aIID.Equals(kCTextEncoderCID))
|
|
||||||
*aResult = new nsTextEncoder;
|
*aResult = new nsTextEncoder;
|
||||||
else
|
else
|
||||||
return NS_NOINTERFACE;
|
return NS_NOINTERFACE;
|
||||||
|
|
|
@ -193,12 +193,14 @@ void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter)
|
||||||
nsICSSRule* rule = nsnull;
|
nsICSSRule* rule = nsnull;
|
||||||
|
|
||||||
cssSheet->StyleRuleCount(ruleCount);
|
cssSheet->StyleRuleCount(ruleCount);
|
||||||
aConverter.BeginCSSStyleSheet();
|
if (ruleCount > 0)
|
||||||
for (ruleIndex = 0; ruleIndex < ruleCount; ruleIndex++)
|
|
||||||
{
|
{
|
||||||
if (NS_OK == cssSheet->GetStyleRuleAt(ruleIndex, rule))
|
aConverter.BeginCSSStyleSheet();
|
||||||
|
for (ruleIndex = 0; ruleIndex < ruleCount; ruleIndex++)
|
||||||
{
|
{
|
||||||
aConverter.BeginCSSRule();
|
if (NS_OK == cssSheet->GetStyleRuleAt(ruleIndex, rule))
|
||||||
|
{
|
||||||
|
aConverter.BeginCSSRule();
|
||||||
|
|
||||||
if (nsnull != rule)
|
if (nsnull != rule)
|
||||||
{
|
{
|
||||||
|
@ -218,10 +220,11 @@ void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter)
|
||||||
NS_IF_RELEASE(rule);
|
NS_IF_RELEASE(rule);
|
||||||
} // ruleAt
|
} // ruleAt
|
||||||
|
|
||||||
aConverter.EndCSSRule();
|
aConverter.EndCSSRule();
|
||||||
} // for loop
|
} // for loop
|
||||||
}
|
}
|
||||||
aConverter.EndCSSStyleSheet();
|
aConverter.EndCSSStyleSheet();
|
||||||
|
} // if ruleCount > 0
|
||||||
NS_RELEASE(cssSheet);
|
NS_RELEASE(cssSheet);
|
||||||
} // css_sheet
|
} // css_sheet
|
||||||
NS_RELEASE(sheet);
|
NS_RELEASE(sheet);
|
||||||
|
|
|
@ -1491,6 +1491,41 @@ NS_IMETHODIMP nsEditor::ApplyStyleSheet(const nsString& aURL)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsEditor::OutputToString(nsString& aOutputString,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags)
|
||||||
|
{
|
||||||
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsEditor::OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharsetOverride,
|
||||||
|
PRUint32 aFlags)
|
||||||
|
{
|
||||||
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsEditor::DumpContentTree()
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIDocument> thedoc;
|
||||||
|
nsCOMPtr<nsIPresShell> presShell;
|
||||||
|
if (NS_SUCCEEDED(GetPresShell(getter_AddRefs(presShell))))
|
||||||
|
{
|
||||||
|
presShell->GetDocument(getter_AddRefs(thedoc));
|
||||||
|
if (thedoc) {
|
||||||
|
nsIContent* root = thedoc->GetRootContent();
|
||||||
|
if (nsnull != root) {
|
||||||
|
root->List(stdout);
|
||||||
|
NS_RELEASE(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsEditor::AddEditActionListener(nsIEditActionListener *aListener)
|
nsEditor::AddEditActionListener(nsIEditActionListener *aListener)
|
||||||
{
|
{
|
||||||
|
|
|
@ -180,6 +180,15 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD EndComposition(void);
|
NS_IMETHOD EndComposition(void);
|
||||||
|
|
||||||
|
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags);
|
||||||
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharsetOverride,
|
||||||
|
PRUint32 aFlags);
|
||||||
|
NS_IMETHOD DumpContentTree();
|
||||||
|
|
||||||
NS_IMETHOD DeleteNode(nsIDOMNode * aChild);
|
NS_IMETHOD DeleteNode(nsIDOMNode * aChild);
|
||||||
|
|
||||||
NS_IMETHOD DeleteSelection(nsIEditor::ECollapsedSelectionAction aAction);
|
NS_IMETHOD DeleteSelection(nsIEditor::ECollapsedSelectionAction aAction);
|
||||||
|
|
|
@ -290,11 +290,19 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
||||||
aProcessed=PR_TRUE;
|
aProcessed=PR_TRUE;
|
||||||
nsString output;
|
nsString output;
|
||||||
nsresult res = NS_ERROR_FAILURE;
|
nsresult res = NS_ERROR_FAILURE;
|
||||||
|
nsString format;
|
||||||
|
if (isShift)
|
||||||
|
format = "text/plain";
|
||||||
|
else
|
||||||
|
format = "text/html";
|
||||||
|
res = mEditor->OutputToString(output, format,
|
||||||
|
nsEditor::EditorOutputFormatted);
|
||||||
|
#if 0
|
||||||
nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mEditor));
|
nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mEditor));
|
||||||
if (htmlEditor)
|
if (htmlEditor)
|
||||||
{
|
{
|
||||||
if (isShift)
|
if (isShift)
|
||||||
res = htmlEditor->OutputTextToString(output, PR_FALSE);
|
res = htmlEditor->OutputTextToString(output, PR_TRUE, PR_FALSE);
|
||||||
else
|
else
|
||||||
res = htmlEditor->OutputHTMLToString(output, PR_FALSE);
|
res = htmlEditor->OutputHTMLToString(output, PR_FALSE);
|
||||||
}
|
}
|
||||||
|
@ -304,11 +312,12 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
||||||
if (textEditor)
|
if (textEditor)
|
||||||
{
|
{
|
||||||
if (isShift)
|
if (isShift)
|
||||||
res = textEditor->OutputTextToString(output, PR_FALSE);
|
res = textEditor->OutputTextToString(output, PR_TRUE, PR_FALSE);
|
||||||
else
|
else
|
||||||
res = textEditor->OutputHTMLToString(output, PR_FALSE);
|
res = textEditor->OutputHTMLToString(output, PR_FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (NS_SUCCEEDED(res))
|
if (NS_SUCCEEDED(res))
|
||||||
{
|
{
|
||||||
|
|
|
@ -243,6 +243,7 @@ nsEditorShell::Init()
|
||||||
nsAutoString editorType = "html"; // default to creating HTML editor
|
nsAutoString editorType = "html"; // default to creating HTML editor
|
||||||
mEditorTypeString = editorType;
|
mEditorTypeString = editorType;
|
||||||
mEditorTypeString.ToLowerCase();
|
mEditorTypeString.ToLowerCase();
|
||||||
|
mWrapColumn = 0;
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -328,6 +329,9 @@ nsEditorShell::InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell)
|
||||||
{
|
{
|
||||||
mEditor = do_QueryInterface(editor); // this does the addref that is the owning reference
|
mEditor = do_QueryInterface(editor); // this does the addref that is the owning reference
|
||||||
mEditorType = ePlainTextEditorType;
|
mEditorType = ePlainTextEditorType;
|
||||||
|
|
||||||
|
// and set the initial wrap column
|
||||||
|
editor->SetBodyWrapWidth(mWrapColumn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1505,131 +1509,36 @@ nsEditorShell::FindNext()
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsEditorShell::GetContentsAsText(PRUnichar * *contentsAsText)
|
nsEditorShell::GetContentsAs(const PRUnichar *format, PRUint32 flags,
|
||||||
|
PRUnichar **contentsAs)
|
||||||
{
|
{
|
||||||
nsresult err = NS_NOINTERFACE;
|
nsresult err = NS_NOINTERFACE;
|
||||||
|
|
||||||
nsString aContentsAsText;
|
|
||||||
|
|
||||||
switch (mEditorType)
|
|
||||||
{
|
|
||||||
case ePlainTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
|
||||||
if (textEditor)
|
|
||||||
err = textEditor->OutputTextToString(aContentsAsText, PR_FALSE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case eHTMLTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
||||||
if (htmlEditor)
|
|
||||||
err = htmlEditor->OutputTextToString(aContentsAsText, PR_FALSE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
*contentsAsText = aContentsAsText.ToNewUnicode();
|
nsString aFormat (format);
|
||||||
|
nsString aContentsAs;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||||
|
if (htmlEditor)
|
||||||
|
err = htmlEditor->OutputToString(aContentsAs, aFormat, flags);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||||
|
if (textEditor)
|
||||||
|
err = textEditor->OutputToString(aContentsAs, aFormat, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
*contentsAs = aContentsAs.ToNewUnicode();
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsEditorShell::GetContentsAsHTML(PRUnichar * *contentsAsHTML)
|
nsEditorShell::DumpContentTree()
|
||||||
{
|
{
|
||||||
nsresult err = NS_NOINTERFACE;
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||||
|
if (!editor)
|
||||||
nsString aContentsAsHTML;
|
return NS_ERROR_NOT_INITIALIZED;
|
||||||
|
return editor->DumpContentTree();
|
||||||
switch (mEditorType)
|
|
||||||
{
|
|
||||||
case ePlainTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
|
||||||
if (textEditor)
|
|
||||||
err = textEditor->OutputHTMLToString(aContentsAsHTML, PR_FALSE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case eHTMLTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
||||||
if (htmlEditor)
|
|
||||||
err = htmlEditor->OutputHTMLToString(aContentsAsHTML, PR_FALSE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
*contentsAsHTML = aContentsAsHTML.ToNewUnicode();
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsEditorShell::GetSelectionAsText(PRUnichar * *contentsAsText)
|
|
||||||
{
|
|
||||||
nsresult err = NS_NOINTERFACE;
|
|
||||||
|
|
||||||
nsString aContentsAsText;
|
|
||||||
|
|
||||||
switch (mEditorType)
|
|
||||||
{
|
|
||||||
case ePlainTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
|
||||||
if (textEditor)
|
|
||||||
err = textEditor->OutputTextToString(aContentsAsText, PR_TRUE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case eHTMLTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
||||||
if (htmlEditor)
|
|
||||||
err = htmlEditor->OutputTextToString(aContentsAsText, PR_TRUE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
*contentsAsText = aContentsAsText.ToNewUnicode();
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsEditorShell::GetSelectionAsHTML(PRUnichar * *contentsAsHTML)
|
|
||||||
{
|
|
||||||
nsresult err = NS_NOINTERFACE;
|
|
||||||
|
|
||||||
nsString aContentsAsHTML;
|
|
||||||
|
|
||||||
switch (mEditorType)
|
|
||||||
{
|
|
||||||
case ePlainTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
|
||||||
if (textEditor)
|
|
||||||
err = textEditor->OutputHTMLToString(aContentsAsHTML, PR_TRUE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case eHTMLTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
||||||
if (htmlEditor)
|
|
||||||
err = htmlEditor->OutputHTMLToString(aContentsAsHTML, PR_TRUE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
*contentsAsHTML = aContentsAsHTML.ToNewUnicode();
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1641,8 +1550,13 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
// fill result in case of failure
|
// fill result in case of failure
|
||||||
*aWrapColumn = 0;
|
*aWrapColumn = mWrapColumn;
|
||||||
|
|
||||||
|
// If we don't have an editor yet, say we're not initialized
|
||||||
|
// even though mWrapColumn may have a value.
|
||||||
|
if (!mEditor)
|
||||||
|
return NS_ERROR_NOT_INITIALIZED;
|
||||||
|
|
||||||
switch (mEditorType)
|
switch (mEditorType)
|
||||||
{
|
{
|
||||||
case ePlainTextEditorType:
|
case ePlainTextEditorType:
|
||||||
|
@ -1667,22 +1581,24 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsEditorShell::SetWrapColumn(PRInt32 aWrapColumn)
|
nsEditorShell::SetWrapColumn(PRInt32 aWrapColumn)
|
||||||
{
|
{
|
||||||
nsresult err = NS_NOINTERFACE;
|
nsresult err = NS_OK;
|
||||||
|
|
||||||
if (!aWrapColumn)
|
mWrapColumn = aWrapColumn;
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
if (mEditor)
|
||||||
switch (mEditorType)
|
|
||||||
{
|
{
|
||||||
case ePlainTextEditorType:
|
switch (mEditorType)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
case ePlainTextEditorType:
|
||||||
if (textEditor)
|
{
|
||||||
err = textEditor->SetBodyWrapWidth(aWrapColumn);
|
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||||
}
|
if (textEditor)
|
||||||
break;
|
err = textEditor->SetBodyWrapWidth(mWrapColumn);
|
||||||
default:
|
}
|
||||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
break;
|
||||||
|
default:
|
||||||
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -82,10 +82,6 @@ class nsEditorShell : public nsIEditorShell,
|
||||||
|
|
||||||
|
|
||||||
/* nsIEditorShell interface */
|
/* nsIEditorShell interface */
|
||||||
NS_IMETHOD GetContentsAsText(PRUnichar * *aContentsAsText);
|
|
||||||
NS_IMETHOD GetContentsAsHTML(PRUnichar * *aContentsAsHTML);
|
|
||||||
NS_IMETHOD GetSelectionAsHTML(PRUnichar * *aSelectionAsHTML);
|
|
||||||
NS_IMETHOD GetSelectionAsText(PRUnichar * *aSelectionAsText);
|
|
||||||
|
|
||||||
NS_IMETHOD GetEditorDocument(nsIDOMDocument * *aEditorDocument);
|
NS_IMETHOD GetEditorDocument(nsIDOMDocument * *aEditorDocument);
|
||||||
NS_IMETHOD GetEditorSelection(nsIDOMSelection * *aEditorSelection);
|
NS_IMETHOD GetEditorSelection(nsIDOMSelection * *aEditorSelection);
|
||||||
|
@ -163,6 +159,12 @@ class nsEditorShell : public nsIEditorShell,
|
||||||
|
|
||||||
NS_IMETHOD ApplyStyleSheet(const PRUnichar *url);
|
NS_IMETHOD ApplyStyleSheet(const PRUnichar *url);
|
||||||
|
|
||||||
|
/* Get the contents, for output or other uses */
|
||||||
|
NS_IMETHOD GetContentsAs(const PRUnichar *format, PRUint32 flags, PRUnichar **contentsAs);
|
||||||
|
|
||||||
|
/* Debugging: dump content tree to stdout */
|
||||||
|
NS_IMETHOD DumpContentTree();
|
||||||
|
|
||||||
/* string GetLocalFileURL (in nsIDOMWindow parent, in string filterType); */
|
/* string GetLocalFileURL (in nsIDOMWindow parent, in string filterType); */
|
||||||
NS_IMETHOD GetLocalFileURL(nsIDOMWindow *parent, const PRUnichar *filterType, PRUnichar **_retval);
|
NS_IMETHOD GetLocalFileURL(nsIDOMWindow *parent, const PRUnichar *filterType, PRUnichar **_retval);
|
||||||
|
|
||||||
|
@ -283,6 +285,8 @@ class nsEditorShell : public nsIEditorShell,
|
||||||
nsCOMPtr<nsISupports> mEditor; // this can be either an HTML or plain text (or other?) editor
|
nsCOMPtr<nsISupports> mEditor; // this can be either an HTML or plain text (or other?) editor
|
||||||
|
|
||||||
nsCOMPtr<nsISupports> mSearchContext; // context used for search and replace. Owned by the appshell.
|
nsCOMPtr<nsISupports> mSearchContext; // context used for search and replace. Owned by the appshell.
|
||||||
|
|
||||||
|
PRInt32 mWrapColumn; // can't actually set this 'til the editor is created, so we may have to hold on to it for a while
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // nsEditorAppCore_h___
|
#endif // nsEditorAppCore_h___
|
||||||
|
|
|
@ -63,8 +63,6 @@ static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
|
||||||
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
||||||
static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID);
|
static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID);
|
||||||
static NS_DEFINE_IID(kFileWidgetCID, NS_FILEWIDGET_CID);
|
static NS_DEFINE_IID(kFileWidgetCID, NS_FILEWIDGET_CID);
|
||||||
static NS_DEFINE_CID(kHTMLEncoderCID, NS_HTML_ENCODER_CID);
|
|
||||||
static NS_DEFINE_CID(kTextEncoderCID, NS_TEXT_ENCODER_CID);
|
|
||||||
|
|
||||||
#ifdef NS_DEBUG
|
#ifdef NS_DEBUG
|
||||||
static PRBool gNoisy = PR_FALSE;
|
static PRBool gNoisy = PR_FALSE;
|
||||||
|
@ -661,45 +659,22 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTML(const nsString& aInputString)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly)
|
NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags)
|
||||||
{
|
{
|
||||||
return nsTextEditor::OutputTextToString(aOutputString, aSelectionOnly);
|
return nsTextEditor::OutputToString(aOutputString, aFormatType, aFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly)
|
NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharset,
|
||||||
|
PRUint32 aFlags)
|
||||||
{
|
{
|
||||||
#if defined(DEBUG_akkana)
|
return nsTextEditor::OutputToStream(aOutputStream, aFormatType,
|
||||||
printf("============Content dump:===========\n");
|
aCharset, aFlags);
|
||||||
|
|
||||||
nsCOMPtr<nsIDocument> thedoc;
|
|
||||||
nsCOMPtr<nsIPresShell> presShell;
|
|
||||||
if (NS_SUCCEEDED(GetPresShell(getter_AddRefs(presShell))))
|
|
||||||
{
|
|
||||||
presShell->GetDocument(getter_AddRefs(thedoc));
|
|
||||||
if (thedoc) {
|
|
||||||
nsIContent* root = thedoc->GetRootContent();
|
|
||||||
if (nsnull != root) {
|
|
||||||
root->List(stdout);
|
|
||||||
NS_RELEASE(root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return nsTextEditor::OutputHTMLToString(aOutputString, aSelectionOnly);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharset, PRBool aSelectionOnly)
|
|
||||||
{
|
|
||||||
return nsTextEditor::OutputTextToStream(aOutputStream, aCharset, aSelectionOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputHTMLToStream(nsIOutputStream* aOutputStream,nsString* aCharset, PRBool aSelectionOnly)
|
|
||||||
{
|
|
||||||
return nsTextEditor::OutputHTMLToStream(aOutputStream, aCharset, aSelectionOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsHTMLEditor::CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
|
nsHTMLEditor::CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,10 +108,14 @@ public:
|
||||||
NS_IMETHOD BeginComposition(void);
|
NS_IMETHOD BeginComposition(void);
|
||||||
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aTextRange);
|
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aTextRange);
|
||||||
NS_IMETHOD EndComposition(void);
|
NS_IMETHOD EndComposition(void);
|
||||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly);
|
|
||||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly);
|
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream,nsString* aCharsetOverride, PRBool aSelectionOnly);
|
const nsString& aFormatType,
|
||||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream,nsString* aCharsetOverride, PRBool aSelectionOnly);
|
PRUint32 aFlags);
|
||||||
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharsetOverride,
|
||||||
|
PRUint32 aFlags);
|
||||||
|
|
||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
|
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
|
||||||
|
|
|
@ -512,25 +512,18 @@ nsJSEditorLog::InsertHTML(const nsString &aInputString)
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJSEditorLog::OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly)
|
nsJSEditorLog::OutputToString(nsString& aOutputString,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags)
|
||||||
{
|
{
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJSEditorLog::OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly)
|
nsJSEditorLog::OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
{
|
const nsString& aFormatType,
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
const nsString* aCharsetOverride,
|
||||||
}
|
PRUint32 aFlags)
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsJSEditorLog::OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly)
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsJSEditorLog::OutputHTMLToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly)
|
|
||||||
{
|
{
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,11 +98,13 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD InsertHTML(const nsString &aInputString);
|
NS_IMETHOD InsertHTML(const nsString &aInputString);
|
||||||
|
|
||||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly);
|
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly);
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags);
|
||||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly);
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly);
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharsetOverride,
|
||||||
|
PRUint32 aFlags);
|
||||||
|
|
||||||
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
|
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
|
||||||
|
|
||||||
|
|
|
@ -72,10 +72,6 @@ static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
|
||||||
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
|
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
|
||||||
//static NS_DEFINE_IID(kCXIFFormatConverterCID, NS_XIFFORMATCONVERTER_CID);
|
//static NS_DEFINE_IID(kCXIFFormatConverterCID, NS_XIFFORMATCONVERTER_CID);
|
||||||
|
|
||||||
// Document encoders
|
|
||||||
static NS_DEFINE_CID(kHTMLEncoderCID, NS_HTML_ENCODER_CID);
|
|
||||||
static NS_DEFINE_CID(kTextEncoderCID, NS_TEXT_ENCODER_CID);
|
|
||||||
|
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
|
|
||||||
|
@ -266,9 +262,6 @@ NS_IMETHODIMP nsTextEditor::Init(nsIDOMDocument *aDoc,
|
||||||
// get a mouse listener
|
// get a mouse listener
|
||||||
result = NS_NewEditorMouseListener(getter_AddRefs(mMouseListenerP), this);
|
result = NS_NewEditorMouseListener(getter_AddRefs(mMouseListenerP), this);
|
||||||
if (NS_OK != result) {
|
if (NS_OK != result) {
|
||||||
#ifdef DEBUG_akkana
|
|
||||||
printf("Couldn't get mouse listener\n");
|
|
||||||
#endif
|
|
||||||
HandleEventListenerError();
|
HandleEventListenerError();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1322,10 +1315,6 @@ NS_IMETHODIMP nsTextEditor::PasteAsQuotation()
|
||||||
mJSEditorLog->PasteAsQuotation();
|
mJSEditorLog->PasteAsQuotation();
|
||||||
#endif // ENABLE_JS_EDITOR_LOG
|
#endif // ENABLE_JS_EDITOR_LOG
|
||||||
|
|
||||||
#ifdef DEBUG_akkana
|
|
||||||
printf("nsTextEditor::PasteAsQuotation\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
nsString stuffToPaste;
|
nsString stuffToPaste;
|
||||||
|
|
||||||
// Get Clipboard Service
|
// Get Clipboard Service
|
||||||
|
@ -1431,12 +1420,7 @@ NS_IMETHODIMP nsTextEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
|
||||||
PRBool isSet;
|
PRBool isSet;
|
||||||
res = GetAttributeValue(preElement, colsStr, numCols, isSet);
|
res = GetAttributeValue(preElement, colsStr, numCols, isSet);
|
||||||
if (!NS_SUCCEEDED(res))
|
if (!NS_SUCCEEDED(res))
|
||||||
{
|
|
||||||
#ifdef DEBUG_akkana
|
|
||||||
printf("GetAttributeValue(cols) failed\n");
|
|
||||||
#endif
|
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
}
|
|
||||||
|
|
||||||
if (isSet)
|
if (isSet)
|
||||||
{
|
{
|
||||||
|
@ -1451,12 +1435,7 @@ NS_IMETHODIMP nsTextEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
|
||||||
nsString wrapStr ("wrap");
|
nsString wrapStr ("wrap");
|
||||||
res = GetAttributeValue(preElement, colsStr, numCols, isSet);
|
res = GetAttributeValue(preElement, colsStr, numCols, isSet);
|
||||||
if (!NS_SUCCEEDED(res))
|
if (!NS_SUCCEEDED(res))
|
||||||
{
|
|
||||||
#ifdef DEBUG_akkana
|
|
||||||
printf("GetAttributeValue(cols) failed\n");
|
|
||||||
#endif
|
|
||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
}
|
|
||||||
|
|
||||||
if (isSet)
|
if (isSet)
|
||||||
*aWrapColumn = 0; // wrap to window width
|
*aWrapColumn = 0; // wrap to window width
|
||||||
|
@ -1518,7 +1497,9 @@ NS_IMETHODIMP nsTextEditor::ApplyStyleSheet(const nsString& aURL)
|
||||||
return nsEditor::ApplyStyleSheet(aURL);
|
return nsEditor::ApplyStyleSheet(aURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly)
|
NS_IMETHODIMP nsTextEditor::OutputToString(nsString& aOutputString,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags)
|
||||||
{
|
{
|
||||||
PRBool cancel;
|
PRBool cancel;
|
||||||
nsString resultString;
|
nsString resultString;
|
||||||
|
@ -1532,38 +1513,50 @@ NS_IMETHODIMP nsTextEditor::OutputTextToString(nsString& aOutputString, PRBool a
|
||||||
else
|
else
|
||||||
{ // default processing
|
{ // default processing
|
||||||
nsCOMPtr<nsITextEncoder> encoder;
|
nsCOMPtr<nsITextEncoder> encoder;
|
||||||
rv = nsComponentManager::CreateInstance(kTextEncoderCID,
|
char progid[strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1];
|
||||||
|
strcpy(progid, NS_DOC_ENCODER_PROGID_BASE);
|
||||||
|
char* type = aFormatType.ToNewCString();
|
||||||
|
strcat(progid, type);
|
||||||
|
delete[] type;
|
||||||
|
rv = nsComponentManager::CreateInstance(progid,
|
||||||
nsnull,
|
nsnull,
|
||||||
nsIDocumentEncoder::GetIID(),
|
nsIDocumentEncoder::GetIID(),
|
||||||
getter_AddRefs(encoder));
|
getter_AddRefs(encoder));
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
|
{
|
||||||
|
printf("Couldn't get progid %s\n", progid);
|
||||||
return rv;
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMDocument> domdoc;
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
||||||
rv = GetDocument(getter_AddRefs(domdoc));
|
rv = GetDocument(getter_AddRefs(domdoc));
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return rv;
|
return rv;
|
||||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
||||||
nsString mimetype ("text/plain");
|
|
||||||
|
|
||||||
nsCOMPtr<nsIPresShell> shell;
|
nsCOMPtr<nsIPresShell> shell;
|
||||||
|
|
||||||
rv = GetPresShell(getter_AddRefs(shell));
|
rv = GetPresShell(getter_AddRefs(shell));
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return rv;
|
return rv;
|
||||||
rv = encoder->Init(shell, doc, mimetype);
|
rv = encoder->Init(shell, doc, aFormatType);
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
if (aSelectionOnly) {
|
if (aFlags & EditorOutputSelectionOnly)
|
||||||
nsCOMPtr<nsIDOMSelection> selection;
|
{
|
||||||
|
nsCOMPtr<nsIDOMSelection> selection;
|
||||||
rv = GetSelection(getter_AddRefs(selection));
|
rv = GetSelection(getter_AddRefs(selection));
|
||||||
if (NS_SUCCEEDED(rv) && selection)
|
if (NS_SUCCEEDED(rv) && selection)
|
||||||
encoder->SetSelection(selection);
|
encoder->SetSelection(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to turn on pretty printing, but don't panic if it doesn't work:
|
// Try to set pretty printing, but don't panic if it doesn't work:
|
||||||
(void)encoder->PrettyPrint(PR_TRUE);
|
(void)encoder->PrettyPrint((aFlags & EditorOutputFormatted)
|
||||||
|
? PR_TRUE : PR_FALSE);
|
||||||
|
// Indicate whether we want the comment and doctype headers prepended:
|
||||||
|
(void)encoder->AddHeader((aFlags & EditorOutputNoDoctype)
|
||||||
|
? PR_FALSE : PR_TRUE);
|
||||||
// Set the wrap column. If our wrap column is 0,
|
// Set the wrap column. If our wrap column is 0,
|
||||||
// i.e. wrap to body width, then don't set it, let the
|
// i.e. wrap to body width, then don't set it, let the
|
||||||
// document encoder use its own default.
|
// document encoder use its own default.
|
||||||
|
@ -1583,76 +1576,33 @@ NS_IMETHODIMP nsTextEditor::OutputTextToString(nsString& aOutputString, PRBool a
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly)
|
NS_IMETHODIMP nsTextEditor::OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
{
|
const nsString& aFormatType,
|
||||||
#if defined(DEBUG_akkana)
|
const nsString* aCharset,
|
||||||
printf("============Content dump:===========\n");
|
PRUint32 aFlags)
|
||||||
|
|
||||||
nsCOMPtr<nsIDocument> thedoc;
|
|
||||||
nsCOMPtr<nsIPresShell> presShell;
|
|
||||||
if (NS_SUCCEEDED(GetPresShell(getter_AddRefs(presShell))))
|
|
||||||
{
|
|
||||||
presShell->GetDocument(getter_AddRefs(thedoc));
|
|
||||||
if (thedoc) {
|
|
||||||
nsIContent* root = thedoc->GetRootContent();
|
|
||||||
if (nsnull != root) {
|
|
||||||
root->List(stdout);
|
|
||||||
NS_RELEASE(root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
nsCOMPtr<nsIHTMLEncoder> encoder;
|
|
||||||
nsresult rv = nsComponentManager::CreateInstance(kHTMLEncoderCID,
|
|
||||||
nsnull,
|
|
||||||
nsIDocumentEncoder::GetIID(),
|
|
||||||
getter_AddRefs(encoder));
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMDocument> domdoc;
|
|
||||||
rv = GetDocument(getter_AddRefs(domdoc));
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
|
||||||
nsString mimetype ("text/html");
|
|
||||||
|
|
||||||
nsCOMPtr<nsIPresShell> shell;
|
|
||||||
|
|
||||||
rv = GetPresShell(getter_AddRefs(shell));
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
rv = encoder->Init(shell,doc, mimetype);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aSelectionOnly) {
|
|
||||||
nsCOMPtr<nsIDOMSelection> selection;
|
|
||||||
rv = GetSelection(getter_AddRefs(selection));
|
|
||||||
if (NS_SUCCEEDED(rv) && selection)
|
|
||||||
encoder->SetSelection(selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
return encoder->EncodeToString(aOutputString);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsTextEditor::OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharset, PRBool aSelectionOnly)
|
|
||||||
{
|
{
|
||||||
|
nsresult rv;
|
||||||
nsCOMPtr<nsITextEncoder> encoder;
|
nsCOMPtr<nsITextEncoder> encoder;
|
||||||
nsresult rv = nsComponentManager::CreateInstance(kTextEncoderCID,
|
char progid[strlen(NS_DOC_ENCODER_PROGID_BASE) + aFormatType.Length() + 1];
|
||||||
nsnull,
|
strcpy(progid, NS_DOC_ENCODER_PROGID_BASE);
|
||||||
nsIDocumentEncoder::GetIID(),
|
char* type = aFormatType.ToNewCString();
|
||||||
getter_AddRefs(encoder));
|
strcat(progid, type);
|
||||||
|
delete[] type;
|
||||||
|
rv = nsComponentManager::CreateInstance(progid,
|
||||||
|
nsnull,
|
||||||
|
nsIDocumentEncoder::GetIID(),
|
||||||
|
getter_AddRefs(encoder));
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
|
{
|
||||||
|
printf("Couldn't get progid %s\n", progid);
|
||||||
return rv;
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMDocument> domdoc;
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
||||||
rv = GetDocument(getter_AddRefs(domdoc));
|
rv = GetDocument(getter_AddRefs(domdoc));
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return rv;
|
return rv;
|
||||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
||||||
nsString mimetype ("text/plain");
|
|
||||||
|
|
||||||
if (aCharset && aCharset->Length() != 0 && aCharset->Equals("null")==PR_FALSE)
|
if (aCharset && aCharset->Length() != 0 && aCharset->Equals("null")==PR_FALSE)
|
||||||
encoder->SetCharset(*aCharset);
|
encoder->SetCharset(*aCharset);
|
||||||
|
@ -1661,59 +1611,37 @@ NS_IMETHODIMP nsTextEditor::OutputTextToStream(nsIOutputStream* aOutputStream, n
|
||||||
|
|
||||||
rv = GetPresShell(getter_AddRefs(shell));
|
rv = GetPresShell(getter_AddRefs(shell));
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
rv = encoder->Init(shell,doc, mimetype);
|
rv = encoder->Init(shell,doc, aFormatType);
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aSelectionOnly) {
|
if (aFlags & EditorOutputSelectionOnly)
|
||||||
|
{
|
||||||
nsCOMPtr<nsIDOMSelection> selection;
|
nsCOMPtr<nsIDOMSelection> selection;
|
||||||
rv = GetSelection(getter_AddRefs(selection));
|
rv = GetSelection(getter_AddRefs(selection));
|
||||||
if (NS_SUCCEEDED(rv) && selection)
|
if (NS_SUCCEEDED(rv) && selection)
|
||||||
encoder->SetSelection(selection);
|
encoder->SetSelection(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to turn on pretty printing, but don't panic if it doesn't work:
|
// Try to set pretty printing, but don't panic if it doesn't work:
|
||||||
(void)encoder->PrettyPrint(PR_TRUE);
|
(void)encoder->PrettyPrint((aFlags & EditorOutputFormatted)
|
||||||
(void)encoder->SetWrapColumn(mWrapColumn);
|
? PR_TRUE : PR_FALSE);
|
||||||
|
// Indicate whether we want the comment and doc type headers prepended:
|
||||||
return encoder->EncodeToStream(aOutputStream);
|
(void)encoder->AddHeader((aFlags & EditorOutputNoDoctype)
|
||||||
}
|
? PR_FALSE : PR_TRUE);
|
||||||
|
// Set the wrap column. If our wrap column is 0,
|
||||||
NS_IMETHODIMP nsTextEditor::OutputHTMLToStream(nsIOutputStream* aOutputStream,nsString* aCharset, PRBool aSelectionOnly)
|
// i.e. wrap to body width, then don't set it, let the
|
||||||
{
|
// document encoder use its own default.
|
||||||
nsCOMPtr<nsIHTMLEncoder> encoder;
|
if (mWrapColumn != 0)
|
||||||
nsresult rv = nsComponentManager::CreateInstance(kHTMLEncoderCID,
|
{
|
||||||
nsnull,
|
PRUint32 wc;
|
||||||
nsIDocumentEncoder::GetIID(),
|
if (mWrapColumn < 0)
|
||||||
getter_AddRefs(encoder));
|
wc = 0;
|
||||||
if (NS_FAILED(rv))
|
else
|
||||||
return rv;
|
wc = (PRUint32)mWrapColumn;
|
||||||
|
if (mWrapColumn > 0)
|
||||||
nsCOMPtr<nsIDOMDocument> domdoc;
|
(void)encoder->SetWrapColumn(wc);
|
||||||
rv = GetDocument(getter_AddRefs(domdoc));
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
|
||||||
nsString mimetype ("text/html");
|
|
||||||
|
|
||||||
nsCOMPtr<nsIPresShell> shell;
|
|
||||||
|
|
||||||
if (aCharset && aCharset->Length() != 0 && aCharset->Equals("null")==PR_FALSE)
|
|
||||||
encoder->SetCharset(*aCharset);
|
|
||||||
|
|
||||||
rv = GetPresShell(getter_AddRefs(shell));
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
rv = encoder->Init(shell,doc, mimetype);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aSelectionOnly) {
|
|
||||||
nsCOMPtr<nsIDOMSelection> selection;
|
|
||||||
rv = GetSelection(getter_AddRefs(selection));
|
|
||||||
if (NS_SUCCEEDED(rv) && selection)
|
|
||||||
encoder->SetSelection(selection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return encoder->EncodeToStream(aOutputStream);
|
return encoder->EncodeToStream(aOutputStream);
|
||||||
|
@ -1743,12 +1671,8 @@ nsTextEditor::FindPreElement()
|
||||||
nsCOMPtr<nsIDOMNode> preNode;
|
nsCOMPtr<nsIDOMNode> preNode;
|
||||||
if (!NS_SUCCEEDED(nsEditor::GetFirstNodeOfType(rootNode, prestr,
|
if (!NS_SUCCEEDED(nsEditor::GetFirstNodeOfType(rootNode, prestr,
|
||||||
getter_AddRefs(preNode))))
|
getter_AddRefs(preNode))))
|
||||||
{
|
|
||||||
#ifdef DEBUG_akkana
|
|
||||||
printf("No PRE tag\n");
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
return do_QueryInterface(preNode);
|
return do_QueryInterface(preNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,10 +116,14 @@ public:
|
||||||
NS_IMETHOD BeginComposition(void);
|
NS_IMETHOD BeginComposition(void);
|
||||||
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aRangeList);
|
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aRangeList);
|
||||||
NS_IMETHOD EndComposition(void);
|
NS_IMETHOD EndComposition(void);
|
||||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly);
|
|
||||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly);
|
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly);
|
const nsString& aFormatType,
|
||||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly);
|
PRUint32 aFlags);
|
||||||
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharsetOverride,
|
||||||
|
PRUint32 aFlags);
|
||||||
|
|
||||||
// Plain text wrapping control
|
// Plain text wrapping control
|
||||||
NS_IMETHOD GetBodyWrapWidth(PRInt32 *aWrapColumn);
|
NS_IMETHOD GetBodyWrapWidth(PRInt32 *aWrapColumn);
|
||||||
|
|
|
@ -243,6 +243,7 @@ nsEditorShell::Init()
|
||||||
nsAutoString editorType = "html"; // default to creating HTML editor
|
nsAutoString editorType = "html"; // default to creating HTML editor
|
||||||
mEditorTypeString = editorType;
|
mEditorTypeString = editorType;
|
||||||
mEditorTypeString.ToLowerCase();
|
mEditorTypeString.ToLowerCase();
|
||||||
|
mWrapColumn = 0;
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -328,6 +329,9 @@ nsEditorShell::InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell)
|
||||||
{
|
{
|
||||||
mEditor = do_QueryInterface(editor); // this does the addref that is the owning reference
|
mEditor = do_QueryInterface(editor); // this does the addref that is the owning reference
|
||||||
mEditorType = ePlainTextEditorType;
|
mEditorType = ePlainTextEditorType;
|
||||||
|
|
||||||
|
// and set the initial wrap column
|
||||||
|
editor->SetBodyWrapWidth(mWrapColumn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1505,131 +1509,36 @@ nsEditorShell::FindNext()
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsEditorShell::GetContentsAsText(PRUnichar * *contentsAsText)
|
nsEditorShell::GetContentsAs(const PRUnichar *format, PRUint32 flags,
|
||||||
|
PRUnichar **contentsAs)
|
||||||
{
|
{
|
||||||
nsresult err = NS_NOINTERFACE;
|
nsresult err = NS_NOINTERFACE;
|
||||||
|
|
||||||
nsString aContentsAsText;
|
|
||||||
|
|
||||||
switch (mEditorType)
|
|
||||||
{
|
|
||||||
case ePlainTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
|
||||||
if (textEditor)
|
|
||||||
err = textEditor->OutputTextToString(aContentsAsText, PR_FALSE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case eHTMLTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
||||||
if (htmlEditor)
|
|
||||||
err = htmlEditor->OutputTextToString(aContentsAsText, PR_FALSE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
*contentsAsText = aContentsAsText.ToNewUnicode();
|
nsString aFormat (format);
|
||||||
|
nsString aContentsAs;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||||
|
if (htmlEditor)
|
||||||
|
err = htmlEditor->OutputToString(aContentsAs, aFormat, flags);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||||
|
if (textEditor)
|
||||||
|
err = textEditor->OutputToString(aContentsAs, aFormat, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
*contentsAs = aContentsAs.ToNewUnicode();
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsEditorShell::GetContentsAsHTML(PRUnichar * *contentsAsHTML)
|
nsEditorShell::DumpContentTree()
|
||||||
{
|
{
|
||||||
nsresult err = NS_NOINTERFACE;
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||||
|
if (!editor)
|
||||||
nsString aContentsAsHTML;
|
return NS_ERROR_NOT_INITIALIZED;
|
||||||
|
return editor->DumpContentTree();
|
||||||
switch (mEditorType)
|
|
||||||
{
|
|
||||||
case ePlainTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
|
||||||
if (textEditor)
|
|
||||||
err = textEditor->OutputHTMLToString(aContentsAsHTML, PR_FALSE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case eHTMLTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
||||||
if (htmlEditor)
|
|
||||||
err = htmlEditor->OutputHTMLToString(aContentsAsHTML, PR_FALSE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
*contentsAsHTML = aContentsAsHTML.ToNewUnicode();
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsEditorShell::GetSelectionAsText(PRUnichar * *contentsAsText)
|
|
||||||
{
|
|
||||||
nsresult err = NS_NOINTERFACE;
|
|
||||||
|
|
||||||
nsString aContentsAsText;
|
|
||||||
|
|
||||||
switch (mEditorType)
|
|
||||||
{
|
|
||||||
case ePlainTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
|
||||||
if (textEditor)
|
|
||||||
err = textEditor->OutputTextToString(aContentsAsText, PR_TRUE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case eHTMLTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
||||||
if (htmlEditor)
|
|
||||||
err = htmlEditor->OutputTextToString(aContentsAsText, PR_TRUE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
*contentsAsText = aContentsAsText.ToNewUnicode();
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsEditorShell::GetSelectionAsHTML(PRUnichar * *contentsAsHTML)
|
|
||||||
{
|
|
||||||
nsresult err = NS_NOINTERFACE;
|
|
||||||
|
|
||||||
nsString aContentsAsHTML;
|
|
||||||
|
|
||||||
switch (mEditorType)
|
|
||||||
{
|
|
||||||
case ePlainTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
|
||||||
if (textEditor)
|
|
||||||
err = textEditor->OutputHTMLToString(aContentsAsHTML, PR_TRUE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case eHTMLTextEditorType:
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
||||||
if (htmlEditor)
|
|
||||||
err = htmlEditor->OutputHTMLToString(aContentsAsHTML, PR_TRUE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
*contentsAsHTML = aContentsAsHTML.ToNewUnicode();
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -1641,8 +1550,13 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
// fill result in case of failure
|
// fill result in case of failure
|
||||||
*aWrapColumn = 0;
|
*aWrapColumn = mWrapColumn;
|
||||||
|
|
||||||
|
// If we don't have an editor yet, say we're not initialized
|
||||||
|
// even though mWrapColumn may have a value.
|
||||||
|
if (!mEditor)
|
||||||
|
return NS_ERROR_NOT_INITIALIZED;
|
||||||
|
|
||||||
switch (mEditorType)
|
switch (mEditorType)
|
||||||
{
|
{
|
||||||
case ePlainTextEditorType:
|
case ePlainTextEditorType:
|
||||||
|
@ -1667,22 +1581,24 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsEditorShell::SetWrapColumn(PRInt32 aWrapColumn)
|
nsEditorShell::SetWrapColumn(PRInt32 aWrapColumn)
|
||||||
{
|
{
|
||||||
nsresult err = NS_NOINTERFACE;
|
nsresult err = NS_OK;
|
||||||
|
|
||||||
if (!aWrapColumn)
|
mWrapColumn = aWrapColumn;
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
if (mEditor)
|
||||||
switch (mEditorType)
|
|
||||||
{
|
{
|
||||||
case ePlainTextEditorType:
|
switch (mEditorType)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
case ePlainTextEditorType:
|
||||||
if (textEditor)
|
{
|
||||||
err = textEditor->SetBodyWrapWidth(aWrapColumn);
|
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||||
}
|
if (textEditor)
|
||||||
break;
|
err = textEditor->SetBodyWrapWidth(mWrapColumn);
|
||||||
default:
|
}
|
||||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
break;
|
||||||
|
default:
|
||||||
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -82,10 +82,6 @@ class nsEditorShell : public nsIEditorShell,
|
||||||
|
|
||||||
|
|
||||||
/* nsIEditorShell interface */
|
/* nsIEditorShell interface */
|
||||||
NS_IMETHOD GetContentsAsText(PRUnichar * *aContentsAsText);
|
|
||||||
NS_IMETHOD GetContentsAsHTML(PRUnichar * *aContentsAsHTML);
|
|
||||||
NS_IMETHOD GetSelectionAsHTML(PRUnichar * *aSelectionAsHTML);
|
|
||||||
NS_IMETHOD GetSelectionAsText(PRUnichar * *aSelectionAsText);
|
|
||||||
|
|
||||||
NS_IMETHOD GetEditorDocument(nsIDOMDocument * *aEditorDocument);
|
NS_IMETHOD GetEditorDocument(nsIDOMDocument * *aEditorDocument);
|
||||||
NS_IMETHOD GetEditorSelection(nsIDOMSelection * *aEditorSelection);
|
NS_IMETHOD GetEditorSelection(nsIDOMSelection * *aEditorSelection);
|
||||||
|
@ -163,6 +159,12 @@ class nsEditorShell : public nsIEditorShell,
|
||||||
|
|
||||||
NS_IMETHOD ApplyStyleSheet(const PRUnichar *url);
|
NS_IMETHOD ApplyStyleSheet(const PRUnichar *url);
|
||||||
|
|
||||||
|
/* Get the contents, for output or other uses */
|
||||||
|
NS_IMETHOD GetContentsAs(const PRUnichar *format, PRUint32 flags, PRUnichar **contentsAs);
|
||||||
|
|
||||||
|
/* Debugging: dump content tree to stdout */
|
||||||
|
NS_IMETHOD DumpContentTree();
|
||||||
|
|
||||||
/* string GetLocalFileURL (in nsIDOMWindow parent, in string filterType); */
|
/* string GetLocalFileURL (in nsIDOMWindow parent, in string filterType); */
|
||||||
NS_IMETHOD GetLocalFileURL(nsIDOMWindow *parent, const PRUnichar *filterType, PRUnichar **_retval);
|
NS_IMETHOD GetLocalFileURL(nsIDOMWindow *parent, const PRUnichar *filterType, PRUnichar **_retval);
|
||||||
|
|
||||||
|
@ -283,6 +285,8 @@ class nsEditorShell : public nsIEditorShell,
|
||||||
nsCOMPtr<nsISupports> mEditor; // this can be either an HTML or plain text (or other?) editor
|
nsCOMPtr<nsISupports> mEditor; // this can be either an HTML or plain text (or other?) editor
|
||||||
|
|
||||||
nsCOMPtr<nsISupports> mSearchContext; // context used for search and replace. Owned by the appshell.
|
nsCOMPtr<nsISupports> mSearchContext; // context used for search and replace. Owned by the appshell.
|
||||||
|
|
||||||
|
PRInt32 mWrapColumn; // can't actually set this 'til the editor is created, so we may have to hold on to it for a while
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // nsEditorAppCore_h___
|
#endif // nsEditorAppCore_h___
|
||||||
|
|
|
@ -33,12 +33,6 @@ interface nsIFileSpec;
|
||||||
[scriptable, uuid(9afff72b-ca9a-11d2-96c9-0060b0fb9956)]
|
[scriptable, uuid(9afff72b-ca9a-11d2-96c9-0060b0fb9956)]
|
||||||
interface nsIEditorShell : nsISupports
|
interface nsIEditorShell : nsISupports
|
||||||
{
|
{
|
||||||
readonly attribute wstring contentsAsText;
|
|
||||||
readonly attribute wstring contentsAsHTML;
|
|
||||||
|
|
||||||
readonly attribute wstring selectionAsHTML;
|
|
||||||
readonly attribute wstring selectionAsText;
|
|
||||||
|
|
||||||
readonly attribute nsIDOMDocument editorDocument;
|
readonly attribute nsIDOMDocument editorDocument;
|
||||||
readonly attribute nsIDOMSelection editorSelection;
|
readonly attribute nsIDOMSelection editorSelection;
|
||||||
|
|
||||||
|
@ -110,6 +104,14 @@ interface nsIEditorShell : nsISupports
|
||||||
|
|
||||||
void ApplyStyleSheet(in wstring url);
|
void ApplyStyleSheet(in wstring url);
|
||||||
|
|
||||||
|
/* Output.
|
||||||
|
* format is mime type, e.g. text/html;
|
||||||
|
* See nsIEditor.h for legal flag values.
|
||||||
|
*/
|
||||||
|
wstring GetContentsAs(in wstring format, in PRUint32 flags);
|
||||||
|
/* For debugging, dump the content tree: */
|
||||||
|
void DumpContentTree();
|
||||||
|
|
||||||
/* Utility */
|
/* Utility */
|
||||||
wstring GetLocalFileURL(in nsIDOMWindow parent, in wstring filterType);
|
wstring GetLocalFileURL(in nsIDOMWindow parent, in wstring filterType);
|
||||||
|
|
||||||
|
|
|
@ -1491,6 +1491,41 @@ NS_IMETHODIMP nsEditor::ApplyStyleSheet(const nsString& aURL)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsEditor::OutputToString(nsString& aOutputString,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags)
|
||||||
|
{
|
||||||
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsEditor::OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharsetOverride,
|
||||||
|
PRUint32 aFlags)
|
||||||
|
{
|
||||||
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsEditor::DumpContentTree()
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIDocument> thedoc;
|
||||||
|
nsCOMPtr<nsIPresShell> presShell;
|
||||||
|
if (NS_SUCCEEDED(GetPresShell(getter_AddRefs(presShell))))
|
||||||
|
{
|
||||||
|
presShell->GetDocument(getter_AddRefs(thedoc));
|
||||||
|
if (thedoc) {
|
||||||
|
nsIContent* root = thedoc->GetRootContent();
|
||||||
|
if (nsnull != root) {
|
||||||
|
root->List(stdout);
|
||||||
|
NS_RELEASE(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsEditor::AddEditActionListener(nsIEditActionListener *aListener)
|
nsEditor::AddEditActionListener(nsIEditActionListener *aListener)
|
||||||
{
|
{
|
||||||
|
|
|
@ -180,6 +180,15 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD EndComposition(void);
|
NS_IMETHOD EndComposition(void);
|
||||||
|
|
||||||
|
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags);
|
||||||
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharsetOverride,
|
||||||
|
PRUint32 aFlags);
|
||||||
|
NS_IMETHOD DumpContentTree();
|
||||||
|
|
||||||
NS_IMETHOD DeleteNode(nsIDOMNode * aChild);
|
NS_IMETHOD DeleteNode(nsIDOMNode * aChild);
|
||||||
|
|
||||||
NS_IMETHOD DeleteSelection(nsIEditor::ECollapsedSelectionAction aAction);
|
NS_IMETHOD DeleteSelection(nsIEditor::ECollapsedSelectionAction aAction);
|
||||||
|
|
|
@ -63,8 +63,6 @@ static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
|
||||||
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
||||||
static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID);
|
static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID);
|
||||||
static NS_DEFINE_IID(kFileWidgetCID, NS_FILEWIDGET_CID);
|
static NS_DEFINE_IID(kFileWidgetCID, NS_FILEWIDGET_CID);
|
||||||
static NS_DEFINE_CID(kHTMLEncoderCID, NS_HTML_ENCODER_CID);
|
|
||||||
static NS_DEFINE_CID(kTextEncoderCID, NS_TEXT_ENCODER_CID);
|
|
||||||
|
|
||||||
#ifdef NS_DEBUG
|
#ifdef NS_DEBUG
|
||||||
static PRBool gNoisy = PR_FALSE;
|
static PRBool gNoisy = PR_FALSE;
|
||||||
|
@ -661,45 +659,22 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTML(const nsString& aInputString)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly)
|
NS_IMETHODIMP nsHTMLEditor::OutputToString(nsString& aOutputString,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags)
|
||||||
{
|
{
|
||||||
return nsTextEditor::OutputTextToString(aOutputString, aSelectionOnly);
|
return nsTextEditor::OutputToString(aOutputString, aFormatType, aFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly)
|
NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharset,
|
||||||
|
PRUint32 aFlags)
|
||||||
{
|
{
|
||||||
#if defined(DEBUG_akkana)
|
return nsTextEditor::OutputToStream(aOutputStream, aFormatType,
|
||||||
printf("============Content dump:===========\n");
|
aCharset, aFlags);
|
||||||
|
|
||||||
nsCOMPtr<nsIDocument> thedoc;
|
|
||||||
nsCOMPtr<nsIPresShell> presShell;
|
|
||||||
if (NS_SUCCEEDED(GetPresShell(getter_AddRefs(presShell))))
|
|
||||||
{
|
|
||||||
presShell->GetDocument(getter_AddRefs(thedoc));
|
|
||||||
if (thedoc) {
|
|
||||||
nsIContent* root = thedoc->GetRootContent();
|
|
||||||
if (nsnull != root) {
|
|
||||||
root->List(stdout);
|
|
||||||
NS_RELEASE(root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return nsTextEditor::OutputHTMLToString(aOutputString, aSelectionOnly);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharset, PRBool aSelectionOnly)
|
|
||||||
{
|
|
||||||
return nsTextEditor::OutputTextToStream(aOutputStream, aCharset, aSelectionOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP nsHTMLEditor::OutputHTMLToStream(nsIOutputStream* aOutputStream,nsString* aCharset, PRBool aSelectionOnly)
|
|
||||||
{
|
|
||||||
return nsTextEditor::OutputHTMLToStream(aOutputStream, aCharset, aSelectionOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsHTMLEditor::CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
|
nsHTMLEditor::CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,10 +108,14 @@ public:
|
||||||
NS_IMETHOD BeginComposition(void);
|
NS_IMETHOD BeginComposition(void);
|
||||||
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aTextRange);
|
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aTextRange);
|
||||||
NS_IMETHOD EndComposition(void);
|
NS_IMETHOD EndComposition(void);
|
||||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly);
|
|
||||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly);
|
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream,nsString* aCharsetOverride, PRBool aSelectionOnly);
|
const nsString& aFormatType,
|
||||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream,nsString* aCharsetOverride, PRBool aSelectionOnly);
|
PRUint32 aFlags);
|
||||||
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharsetOverride,
|
||||||
|
PRUint32 aFlags);
|
||||||
|
|
||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
|
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
|
||||||
|
|
|
@ -290,11 +290,19 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
||||||
aProcessed=PR_TRUE;
|
aProcessed=PR_TRUE;
|
||||||
nsString output;
|
nsString output;
|
||||||
nsresult res = NS_ERROR_FAILURE;
|
nsresult res = NS_ERROR_FAILURE;
|
||||||
|
nsString format;
|
||||||
|
if (isShift)
|
||||||
|
format = "text/plain";
|
||||||
|
else
|
||||||
|
format = "text/html";
|
||||||
|
res = mEditor->OutputToString(output, format,
|
||||||
|
nsEditor::EditorOutputFormatted);
|
||||||
|
#if 0
|
||||||
nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mEditor));
|
nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(mEditor));
|
||||||
if (htmlEditor)
|
if (htmlEditor)
|
||||||
{
|
{
|
||||||
if (isShift)
|
if (isShift)
|
||||||
res = htmlEditor->OutputTextToString(output, PR_FALSE);
|
res = htmlEditor->OutputTextToString(output, PR_TRUE, PR_FALSE);
|
||||||
else
|
else
|
||||||
res = htmlEditor->OutputHTMLToString(output, PR_FALSE);
|
res = htmlEditor->OutputHTMLToString(output, PR_FALSE);
|
||||||
}
|
}
|
||||||
|
@ -304,11 +312,12 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
||||||
if (textEditor)
|
if (textEditor)
|
||||||
{
|
{
|
||||||
if (isShift)
|
if (isShift)
|
||||||
res = textEditor->OutputTextToString(output, PR_FALSE);
|
res = textEditor->OutputTextToString(output, PR_TRUE, PR_FALSE);
|
||||||
else
|
else
|
||||||
res = textEditor->OutputHTMLToString(output, PR_FALSE);
|
res = textEditor->OutputHTMLToString(output, PR_FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (NS_SUCCEEDED(res))
|
if (NS_SUCCEEDED(res))
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,7 @@ class nsIEditActionListener;
|
||||||
class nsIFileSpec;
|
class nsIFileSpec;
|
||||||
class nsIDOMTextRangeList;
|
class nsIDOMTextRangeList;
|
||||||
class nsICSSStyleSheet;
|
class nsICSSStyleSheet;
|
||||||
|
class nsIOutputStream;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Editor interface to outside world
|
Editor interface to outside world
|
||||||
|
@ -204,7 +205,28 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD EndComposition(void) = 0;
|
NS_IMETHOD EndComposition(void) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output methods flags:
|
||||||
|
*/
|
||||||
|
const PRUint32 EditorOutputSelectionOnly = 1;
|
||||||
|
const PRUint32 EditorOutputFormatted = 2;
|
||||||
|
const PRUint32 EditorOutputNoDoctype = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output methods:
|
||||||
|
* aFormatType is a mime type, like text/plain.
|
||||||
|
*/
|
||||||
|
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags) = 0;
|
||||||
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharsetOverride,
|
||||||
|
PRUint32 aFlags) = 0;
|
||||||
|
/**
|
||||||
|
* And a debug method -- show us what the tree looks like right now
|
||||||
|
*/
|
||||||
|
NS_IMETHOD DumpContentTree() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DeleteNode removes aChild from aParent.
|
* DeleteNode removes aChild from aParent.
|
||||||
|
|
|
@ -102,11 +102,17 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD InsertHTML(const nsString &aInputString)=0;
|
NS_IMETHOD InsertHTML(const nsString &aInputString)=0;
|
||||||
|
|
||||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly)=0;
|
/**
|
||||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly)=0;
|
* Output methods:
|
||||||
|
* aFormatType is a mime type, like text/plain.
|
||||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly)=0;
|
*/
|
||||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly)=0;
|
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags) = 0;
|
||||||
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharsetOverride,
|
||||||
|
PRUint32 aFlags) = 0;
|
||||||
|
|
||||||
NS_IMETHOD ApplyStyleSheet(const nsString& aURL)=0;
|
NS_IMETHOD ApplyStyleSheet(const nsString& aURL)=0;
|
||||||
|
|
||||||
|
|
|
@ -338,11 +338,17 @@ public:
|
||||||
NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin)=0;
|
NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin)=0;
|
||||||
|
|
||||||
// Input/Output
|
// Input/Output
|
||||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly)=0;
|
/**
|
||||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly)=0;
|
* Output methods:
|
||||||
|
* aFormatType is a mime type, like text/plain.
|
||||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly)=0;
|
*/
|
||||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly)=0;
|
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
PRUint32 aFlags) = 0;
|
||||||
|
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||||
|
const nsString& aFormatType,
|
||||||
|
const nsString* aCharsetOverride,
|
||||||
|
PRUint32 aFlags) = 0;
|
||||||
|
|
||||||
/** Get and set the body wrap width
|
/** Get and set the body wrap width
|
||||||
* @param aWrapColumn - the column to wrap at. This is set as a COLS attribute
|
* @param aWrapColumn - the column to wrap at. This is set as a COLS attribute
|
||||||
|
|
|
@ -187,8 +187,10 @@
|
||||||
<!ENTITY debugMenu.label "Debug">
|
<!ENTITY debugMenu.label "Debug">
|
||||||
<!ENTITY outputTextCmd.label "Output Text">
|
<!ENTITY outputTextCmd.label "Output Text">
|
||||||
<!ENTITY outputHTMLCmd.label "Output HTML">
|
<!ENTITY outputHTMLCmd.label "Output HTML">
|
||||||
|
<!ENTITY outputXIFCmd.label "Output XIF">
|
||||||
<!ENTITY insertTextCmd.label "Insert Text">
|
<!ENTITY insertTextCmd.label "Insert Text">
|
||||||
<!ENTITY testSelectionCmd.label "Test Selection">
|
<!ENTITY testSelectionCmd.label "Test Selection">
|
||||||
|
<!ENTITY dumpContentCmd.label "Dump Content Tree">
|
||||||
<!ENTITY testDocumentCmd.label "Test Document">
|
<!ENTITY testDocumentCmd.label "Test Document">
|
||||||
<!ENTITY runUnitTestsCmd.label "Run Unit Tests">
|
<!ENTITY runUnitTestsCmd.label "Run Unit Tests">
|
||||||
<!ENTITY startLogCmd.label "Start Log">
|
<!ENTITY startLogCmd.label "Start Log">
|
||||||
|
@ -470,10 +472,12 @@
|
||||||
<menu name="&debugMenu.label;">
|
<menu name="&debugMenu.label;">
|
||||||
<menuitem name="&outputTextCmd.label;" onclick="EditorGetText()"/>
|
<menuitem name="&outputTextCmd.label;" onclick="EditorGetText()"/>
|
||||||
<menuitem name="&outputHTMLCmd.label;" onclick="EditorGetHTML()"/>
|
<menuitem name="&outputHTMLCmd.label;" onclick="EditorGetHTML()"/>
|
||||||
|
<menuitem name="&outputXIFCmd.label;" onclick="EditorGetXIF()"/>
|
||||||
<separator />
|
<separator />
|
||||||
<menuitem name="&insertTextCmd.label;" onclick="EditorInsertText('All good things come to those who wait. ')"/>
|
<menuitem name="&insertTextCmd.label;" onclick="EditorInsertText('All good things come to those who wait. ')"/>
|
||||||
<separator />
|
<separator />
|
||||||
<menuitem name="&testSelectionCmd.label;" onclick="EditorTestSelection()"/>
|
<menuitem name="&testSelectionCmd.label;" onclick="EditorTestSelection()"/>
|
||||||
|
<menuitem name="&dumpContentCmd.label;" onclick="EditorDumpContent()"/>
|
||||||
<menuitem name="&testDocumentCmd.label;" onclick="EditorTestDocument()"/>
|
<menuitem name="&testDocumentCmd.label;" onclick="EditorTestDocument()"/>
|
||||||
<menuitem name="&runUnitTestsCmd.label;" onclick="EditorUnitTests()"/>
|
<menuitem name="&runUnitTestsCmd.label;" onclick="EditorUnitTests()"/>
|
||||||
<separator />
|
<separator />
|
||||||
|
|
|
@ -326,7 +326,7 @@ function EditorGetText()
|
||||||
{
|
{
|
||||||
if (editorShell) {
|
if (editorShell) {
|
||||||
dump("Getting text\n");
|
dump("Getting text\n");
|
||||||
var outputText = editorShell.contentsAsText;
|
var outputText = editorShell.GetContentsAs("text/plain", 2);
|
||||||
dump(outputText + "\n");
|
dump(outputText + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,8 +335,26 @@ function EditorGetHTML()
|
||||||
{
|
{
|
||||||
if (editorShell) {
|
if (editorShell) {
|
||||||
dump("Getting HTML\n");
|
dump("Getting HTML\n");
|
||||||
var outputText = editorShell.contentsAsHTML;
|
var outputHTML = editorShell.GetContentsAs("text/html", 2);
|
||||||
dump(outputText + "\n");
|
dump(outputHTML + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function EditorGetXIF()
|
||||||
|
{
|
||||||
|
if (window.editorShell) {
|
||||||
|
dump("Getting XIF\n");
|
||||||
|
var outputHTML = editorShell.GetContentsAs("text/xif", 2);
|
||||||
|
dump(outputHTML + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function EditorDumpContent()
|
||||||
|
{
|
||||||
|
if (window.editorShell) {
|
||||||
|
dump("============== Content Tree: ================\n");
|
||||||
|
window.editorShell.DumpContentTree();
|
||||||
|
dump(outputHTML + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,12 +615,24 @@ function EditorTestSelection()
|
||||||
dump(firstRange.toString() + "\"\n");
|
dump(firstRange.toString() + "\"\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dump("Selection as text\n");
|
|
||||||
dump(editorShell.selectionAsText + "\n\n");
|
|
||||||
|
|
||||||
dump("Selection as HTML\n");
|
var output;
|
||||||
dump(editorShell.selectionAsHTML + "\n\n");
|
|
||||||
|
dump("\n====== Selection as XIF =======================\n");
|
||||||
|
output = editorShell.GetContentsAs("text/xif", 1);
|
||||||
|
dump(output + "\n\n");
|
||||||
|
|
||||||
|
dump("====== Selection as unformatted text ==========\n");
|
||||||
|
output = editorShell.GetContentsAs("text/plain", 1);
|
||||||
|
dump(output + "\n\n");
|
||||||
|
|
||||||
|
dump("====== Selection as formatted text ============\n");
|
||||||
|
output = editorShell.GetContentsAs("text/plain", 3);
|
||||||
|
dump(output + "\n\n");
|
||||||
|
|
||||||
|
dump("====== Selection as HTML ======================\n");
|
||||||
|
output = editorShell.GetContentsAs("text/html", 1);
|
||||||
|
dump(output + "\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
function EditorUnitTests()
|
function EditorUnitTests()
|
||||||
|
|
|
@ -37,14 +37,6 @@ class nsIPresShell;
|
||||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \
|
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NS_HTML_ENCODER_CID \
|
|
||||||
{ /* a6cf9104-15b3-11d2-932e-00805f8add32 */ \
|
|
||||||
0xa6cf9104, \
|
|
||||||
0x15b3, \
|
|
||||||
0x11d2, \
|
|
||||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define NS_TEXT_ENCODER_CID \
|
#define NS_TEXT_ENCODER_CID \
|
||||||
{ /* e7ba1480-1dea-11d3-830f-00104bed045e */ \
|
{ /* e7ba1480-1dea-11d3-830f-00104bed045e */ \
|
||||||
0xe7ba1480, \
|
0xe7ba1480, \
|
||||||
|
@ -53,6 +45,7 @@ class nsIPresShell;
|
||||||
{0x83, 0x0f, 0x00, 0x10, 0x4b, 0xed, 0x04, 0x5e} \
|
{0x83, 0x0f, 0x00, 0x10, 0x4b, 0xed, 0x04, 0x5e} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define NS_DOC_ENCODER_PROGID_BASE "component://netscape/layout/documentEncoder?type="
|
||||||
|
|
||||||
class nsIDocumentEncoder : public nsISupports
|
class nsIDocumentEncoder : public nsISupports
|
||||||
{
|
{
|
||||||
|
@ -64,7 +57,7 @@ public:
|
||||||
* Initialize with a pointer to the document and the mime type.
|
* Initialize with a pointer to the document and the mime type.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, nsString& aMimeType) = 0;
|
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, const nsString& aMimeType) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the selection is set to a non-null value, then the
|
* If the selection is set to a non-null value, then the
|
||||||
|
@ -98,24 +91,8 @@ public:
|
||||||
NS_IMETHOD EncodeToString(nsString& aOutputString) = 0;
|
NS_IMETHOD EncodeToString(nsString& aOutputString) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Example of a output service for a particular encoder
|
// Example of a output service for a particular encoder.
|
||||||
class nsIHTMLEncoder : public nsIDocumentEncoder
|
// The text encoder handles XIF, HTML, and plaintext.
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const nsIID& GetIID() { static nsIID iid = NS_HTML_ENCODER_CID; return iid; }
|
|
||||||
|
|
||||||
// Get embedded objects -- images, links, etc.
|
|
||||||
// NOTE: we may want to use an enumerator
|
|
||||||
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aObjects) = 0;
|
|
||||||
NS_IMETHOD SubstituteURL(const nsString& aOriginal,
|
|
||||||
const nsString& aReplacement) = 0;
|
|
||||||
NS_IMETHOD PrettyPrint(PRBool aYes) = 0;
|
|
||||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Example of a output service for a particular encoder
|
|
||||||
class nsITextEncoder : public nsIDocumentEncoder
|
class nsITextEncoder : public nsIDocumentEncoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -125,6 +102,7 @@ public:
|
||||||
// NOTE: we may want to use an enumerator
|
// NOTE: we may want to use an enumerator
|
||||||
NS_IMETHOD PrettyPrint(PRBool aYes) = 0;
|
NS_IMETHOD PrettyPrint(PRBool aYes) = 0;
|
||||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
|
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
|
||||||
|
NS_IMETHOD AddHeader(PRBool aYes) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2849,6 +2849,11 @@ nsDocument::IncrementModCount(PRInt32 aNumMods)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// FindContent does a depth-first search from aStartNode
|
||||||
|
// and returns the first of aTest1 or aTest2 which it finds.
|
||||||
|
// I think.
|
||||||
|
//
|
||||||
nsIContent* nsDocument::FindContent(const nsIContent* aStartNode,
|
nsIContent* nsDocument::FindContent(const nsIContent* aStartNode,
|
||||||
const nsIContent* aTest1,
|
const nsIContent* aTest1,
|
||||||
const nsIContent* aTest2) const
|
const nsIContent* aTest2) const
|
||||||
|
@ -2892,7 +2897,16 @@ PRBool nsDocument::IsInRange(const nsIContent *aStartContent, const nsIContent*
|
||||||
{
|
{
|
||||||
result = IsBefore(aStartContent,aContent);
|
result = IsBefore(aStartContent,aContent);
|
||||||
if (result == PR_TRUE)
|
if (result == PR_TRUE)
|
||||||
|
{
|
||||||
result = IsBefore(aContent,aEndContent);
|
result = IsBefore(aContent,aEndContent);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
// If aContent is a parent of aEndContent, then
|
||||||
|
// IsBefore returned false but IsInRange should be true.
|
||||||
|
if (FindContent(aContent, aEndContent, 0) == aEndContent)
|
||||||
|
result = PR_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|
|
@ -36,276 +36,8 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||||
|
|
||||||
static NS_DEFINE_CID(kCHTMLEncoderCID, NS_HTML_ENCODER_CID);
|
|
||||||
static NS_DEFINE_CID(kCTextEncoderCID, NS_TEXT_ENCODER_CID);
|
static NS_DEFINE_CID(kCTextEncoderCID, NS_TEXT_ENCODER_CID);
|
||||||
|
|
||||||
class nsHTMLEncoder : public nsIHTMLEncoder
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; }
|
|
||||||
|
|
||||||
nsHTMLEncoder();
|
|
||||||
virtual ~nsHTMLEncoder();
|
|
||||||
|
|
||||||
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, nsString& aMimeType);
|
|
||||||
|
|
||||||
/* Interfaces for addref and release and queryinterface */
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
|
|
||||||
// Inherited methods from nsIDocument
|
|
||||||
NS_IMETHOD SetSelection(nsIDOMSelection* aSelection);
|
|
||||||
NS_IMETHOD SetCharset(const nsString& aCharset);
|
|
||||||
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
|
|
||||||
NS_IMETHOD EncodeToString(nsString& aOutputString);
|
|
||||||
|
|
||||||
// Get embedded objects -- images, links, etc.
|
|
||||||
// NOTE: we may want to use an enumerator
|
|
||||||
NS_IMETHOD GetEmbeddedObjects(nsISupportsArray* aObjects);
|
|
||||||
NS_IMETHOD SubstituteURL(const nsString& aOriginal,
|
|
||||||
const nsString& aReplacement);
|
|
||||||
NS_IMETHOD PrettyPrint(PRBool aYesNO);
|
|
||||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
|
|
||||||
|
|
||||||
private:
|
|
||||||
nsIDocument* mDocument;
|
|
||||||
nsIDOMSelection* mSelection;
|
|
||||||
nsIPresShell* mPresShell;
|
|
||||||
nsString mMimeType;
|
|
||||||
nsString mCharset;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF(nsHTMLEncoder)
|
|
||||||
// NS_IMPL_RELEASE(nsHTMLEncoder)
|
|
||||||
NS_IMETHODIMP_(nsrefcnt) nsHTMLEncoder::Release(void)
|
|
||||||
{
|
|
||||||
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
|
||||||
if (--mRefCnt == 0) {
|
|
||||||
NS_DELETEXPCOM(this);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return mRefCnt;
|
|
||||||
}
|
|
||||||
nsHTMLEncoder::nsHTMLEncoder() : mMimeType("text/html")
|
|
||||||
{
|
|
||||||
mDocument = 0;
|
|
||||||
mSelection = 0;
|
|
||||||
mPresShell = 0;
|
|
||||||
NS_INIT_REFCNT();
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLEncoder::~nsHTMLEncoder()
|
|
||||||
{
|
|
||||||
NS_IF_RELEASE(mDocument);
|
|
||||||
//NS_IF_RELEASE(mSelection); // no. we never addref'd it.
|
|
||||||
NS_IF_RELEASE(mPresShell);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
|
|
||||||
nsString& aMimeType)
|
|
||||||
{
|
|
||||||
if (!aDocument)
|
|
||||||
return NS_ERROR_INVALID_ARG;
|
|
||||||
|
|
||||||
mDocument = aDocument;
|
|
||||||
NS_ADDREF(mDocument);
|
|
||||||
mPresShell = aPresShell;
|
|
||||||
NS_ADDREF(aPresShell);
|
|
||||||
mMimeType = aMimeType;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult nsHTMLEncoder::QueryInterface(REFNSIID aIID,
|
|
||||||
void **aInstancePtr)
|
|
||||||
{
|
|
||||||
if (nsnull == aInstancePtr)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
*aInstancePtr = 0;
|
|
||||||
|
|
||||||
if (aIID.Equals(kISupportsIID)) {
|
|
||||||
*aInstancePtr = (void *)(nsISupports*)this;
|
|
||||||
} else if (aIID.Equals(nsIDocumentEncoder::GetIID())) {
|
|
||||||
*aInstancePtr = (void *)(nsIDocumentEncoder*)this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nsnull == *aInstancePtr)
|
|
||||||
return NS_NOINTERFACE;
|
|
||||||
|
|
||||||
NS_ADDREF_THIS();
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::SetSelection(nsIDOMSelection* aSelection)
|
|
||||||
{
|
|
||||||
mSelection = aSelection;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::SetCharset(const nsString& aCharset)
|
|
||||||
{
|
|
||||||
mCharset = aCharset;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::EncodeToString(nsString& aOutputString)
|
|
||||||
{
|
|
||||||
nsresult rv;
|
|
||||||
|
|
||||||
if (!mDocument)
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
if (!mPresShell)
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
|
|
||||||
// xxx Also make sure mString is a mime type "text/html" or "text/plain"
|
|
||||||
|
|
||||||
if (mPresShell) {
|
|
||||||
if (mDocument) {
|
|
||||||
nsString buffer;
|
|
||||||
|
|
||||||
mDocument->CreateXIF(buffer,mSelection);
|
|
||||||
nsIParser* parser;
|
|
||||||
|
|
||||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
|
||||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
|
||||||
|
|
||||||
rv = nsComponentManager::CreateInstance(kCParserCID,
|
|
||||||
nsnull,
|
|
||||||
kCParserIID,
|
|
||||||
(void **)&parser);
|
|
||||||
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
nsIHTMLContentSink* sink = nsnull;
|
|
||||||
|
|
||||||
rv = NS_New_HTML_ContentSinkStream(&sink, &aOutputString,
|
|
||||||
PR_FALSE, PR_TRUE);
|
|
||||||
|
|
||||||
if (sink && NS_SUCCEEDED(rv)) {
|
|
||||||
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
parser->SetContentSink(sink);
|
|
||||||
|
|
||||||
nsIDTD* dtd = nsnull;
|
|
||||||
rv = NS_NewXIFDTD(&dtd);
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
parser->RegisterDTD(dtd);
|
|
||||||
parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE);
|
|
||||||
}
|
|
||||||
NS_IF_RELEASE(dtd);
|
|
||||||
NS_IF_RELEASE(sink);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NS_RELEASE(parser);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::EncodeToStream(nsIOutputStream* aStream)
|
|
||||||
{
|
|
||||||
nsresult rv;
|
|
||||||
|
|
||||||
if (!mDocument)
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
if (!mPresShell)
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
|
|
||||||
// xxx Also make sure mString is a mime type "text/html" or "text/plain"
|
|
||||||
|
|
||||||
if (mPresShell) {
|
|
||||||
if (mDocument) {
|
|
||||||
nsString buffer;
|
|
||||||
|
|
||||||
mDocument->CreateXIF(buffer,mSelection);
|
|
||||||
|
|
||||||
nsString* charset = nsnull;
|
|
||||||
nsAutoString defaultCharset("ISO-8859-1");
|
|
||||||
if (!mCharset.Equals("null") && !mCharset.Equals(""))
|
|
||||||
charset = &mCharset;
|
|
||||||
|
|
||||||
nsIParser* parser;
|
|
||||||
|
|
||||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
|
||||||
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
|
|
||||||
|
|
||||||
rv = nsComponentManager::CreateInstance(kCParserCID,
|
|
||||||
nsnull,
|
|
||||||
kCParserIID,
|
|
||||||
(void **)&parser);
|
|
||||||
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
nsIHTMLContentSink* sink = nsnull;
|
|
||||||
|
|
||||||
rv = NS_New_HTML_ContentSinkStream(&sink, aStream, charset,
|
|
||||||
PR_FALSE, PR_TRUE);
|
|
||||||
|
|
||||||
if (sink && NS_SUCCEEDED(rv)) {
|
|
||||||
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
parser->SetContentSink(sink);
|
|
||||||
|
|
||||||
nsIDTD* dtd = nsnull;
|
|
||||||
rv = NS_NewXIFDTD(&dtd);
|
|
||||||
if (NS_OK == rv) {
|
|
||||||
parser->RegisterDTD(dtd);
|
|
||||||
parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE);
|
|
||||||
}
|
|
||||||
NS_IF_RELEASE(dtd);
|
|
||||||
NS_IF_RELEASE(sink);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NS_RELEASE(parser);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::GetEmbeddedObjects(nsISupportsArray* aObjects)
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::SubstituteURL(const nsString& aOriginal, const nsString& aReplacement)
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::PrettyPrint(PRBool)
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLEncoder::SetWrapColumn(PRUint32)
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLEncoder(nsIDocumentEncoder** aResult)
|
|
||||||
{
|
|
||||||
*aResult = new nsHTMLEncoder;
|
|
||||||
if (!*aResult)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
NS_ADDREF(*aResult);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class nsTextEncoder : public nsITextEncoder
|
class nsTextEncoder : public nsITextEncoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -314,7 +46,8 @@ public:
|
||||||
nsTextEncoder();
|
nsTextEncoder();
|
||||||
virtual ~nsTextEncoder();
|
virtual ~nsTextEncoder();
|
||||||
|
|
||||||
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument, nsString& aMimeType);
|
NS_IMETHOD Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
|
||||||
|
const nsString& aMimeType);
|
||||||
|
|
||||||
/* Interfaces for addref and release and queryinterface */
|
/* Interfaces for addref and release and queryinterface */
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
@ -325,8 +58,9 @@ public:
|
||||||
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
|
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
|
||||||
NS_IMETHOD EncodeToString(nsString& aOutputString);
|
NS_IMETHOD EncodeToString(nsString& aOutputString);
|
||||||
|
|
||||||
NS_IMETHOD PrettyPrint(PRBool aYesNO);
|
NS_IMETHOD PrettyPrint(PRBool aYes);
|
||||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
|
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
|
||||||
|
NS_IMETHOD AddHeader(PRBool aYes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsIDocument* mDocument;
|
nsIDocument* mDocument;
|
||||||
|
@ -336,6 +70,7 @@ private:
|
||||||
nsString mCharset;
|
nsString mCharset;
|
||||||
PRBool mPrettyPrint;
|
PRBool mPrettyPrint;
|
||||||
PRUint32 mWrapColumn;
|
PRUint32 mWrapColumn;
|
||||||
|
PRBool mAddHeader;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -357,7 +92,8 @@ nsTextEncoder::~nsTextEncoder()
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument, nsString& aMimeType)
|
nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
|
||||||
|
const nsString& aMimeType)
|
||||||
{
|
{
|
||||||
if (!aDocument)
|
if (!aDocument)
|
||||||
return NS_ERROR_INVALID_ARG;
|
return NS_ERROR_INVALID_ARG;
|
||||||
|
@ -409,6 +145,13 @@ nsTextEncoder::SetWrapColumn(PRUint32 aWC)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsTextEncoder::AddHeader(PRBool aYes)
|
||||||
|
{
|
||||||
|
mAddHeader = aYes;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsTextEncoder::SetSelection(nsIDOMSelection* aSelection)
|
nsTextEncoder::SetSelection(nsIDOMSelection* aSelection)
|
||||||
{
|
{
|
||||||
|
@ -441,7 +184,14 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
|
||||||
{
|
{
|
||||||
nsString buffer;
|
nsString buffer;
|
||||||
|
|
||||||
mDocument->CreateXIF(buffer,mSelection);
|
if (mMimeType == "text/xif")
|
||||||
|
{
|
||||||
|
mDocument->CreateXIF(aOutputString, mSelection);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
mDocument->CreateXIF(buffer, mSelection);
|
||||||
|
|
||||||
nsIParser* parser;
|
nsIParser* parser;
|
||||||
|
|
||||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||||
|
@ -456,19 +206,23 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
|
||||||
{
|
{
|
||||||
nsIHTMLContentSink* sink = nsnull;
|
nsIHTMLContentSink* sink = nsnull;
|
||||||
|
|
||||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
|
if (mMimeType == "text/html")
|
||||||
mWrapColumn, mPrettyPrint);
|
rv = NS_New_HTML_ContentSinkStream(&sink, &aOutputString,
|
||||||
|
PR_FALSE, mAddHeader);
|
||||||
if (sink && NS_SUCCEEDED(rv))
|
|
||||||
|
else // default to text/plain
|
||||||
|
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
|
||||||
|
mWrapColumn, mPrettyPrint);
|
||||||
|
|
||||||
|
if (sink && NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
parser->SetContentSink(sink);
|
parser->SetContentSink(sink);
|
||||||
|
|
||||||
nsIDTD* dtd = nsnull;
|
nsIDTD* dtd = nsnull;
|
||||||
rv = NS_NewXIFDTD(&dtd);
|
rv = NS_NewXIFDTD(&dtd);
|
||||||
if (NS_SUCCEEDED(rv))
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
parser->RegisterDTD(dtd);
|
parser->RegisterDTD(dtd);
|
||||||
parser->Parse(buffer, 0, "text/xif", PR_FALSE,PR_TRUE);
|
parser->Parse(buffer, 0, "text/xif", PR_FALSE, PR_TRUE);
|
||||||
}
|
}
|
||||||
NS_IF_RELEASE(dtd);
|
NS_IF_RELEASE(dtd);
|
||||||
NS_IF_RELEASE(sink);
|
NS_IF_RELEASE(sink);
|
||||||
|
@ -516,8 +270,13 @@ nsTextEncoder::EncodeToStream(nsIOutputStream* aStream)
|
||||||
if (NS_OK == rv) {
|
if (NS_OK == rv) {
|
||||||
nsIHTMLContentSink* sink = nsnull;
|
nsIHTMLContentSink* sink = nsnull;
|
||||||
|
|
||||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, aStream, charset,
|
if (mMimeType == "text/html")
|
||||||
mWrapColumn, mPrettyPrint);
|
rv = NS_New_HTML_ContentSinkStream(&sink, aStream, charset,
|
||||||
|
PR_FALSE, mAddHeader);
|
||||||
|
|
||||||
|
else
|
||||||
|
rv = NS_New_HTMLToTXT_SinkStream(&sink, aStream, charset,
|
||||||
|
mWrapColumn, mPrettyPrint);
|
||||||
|
|
||||||
if (sink && NS_SUCCEEDED(rv))
|
if (sink && NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
|
@ -613,9 +372,7 @@ nsDocumentEncoderFactory::CreateInstance(nsISupports *aOuter,
|
||||||
|
|
||||||
*aResult = 0;
|
*aResult = 0;
|
||||||
|
|
||||||
if (aIID.Equals(kCHTMLEncoderCID))
|
if (aIID.Equals(kCTextEncoderCID))
|
||||||
*aResult = new nsHTMLEncoder;
|
|
||||||
else if (aIID.Equals(kCTextEncoderCID))
|
|
||||||
*aResult = new nsTextEncoder;
|
*aResult = new nsTextEncoder;
|
||||||
else
|
else
|
||||||
return NS_NOINTERFACE;
|
return NS_NOINTERFACE;
|
||||||
|
|
|
@ -307,23 +307,25 @@ void nsXIFConverter::AddContent(const nsString& aContent)
|
||||||
AddEndTag(tag,PR_FALSE);
|
AddEndTag(tag,PR_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// AddComment is used to add a XIF comment,
|
||||||
|
// not something that was a comment in the html;
|
||||||
|
// that would be a content comment.
|
||||||
|
//
|
||||||
void nsXIFConverter::AddComment(const nsString& aContent)
|
void nsXIFConverter::AddComment(const nsString& aContent)
|
||||||
{
|
{
|
||||||
// For actual comments, don't want to include the begin and
|
|
||||||
// end tags; but commenting them out caused bug
|
|
||||||
// http://bugzilla.mozilla.org/show_bug.cgi?id=7720
|
|
||||||
// so we'll have to look into this more deeply later.
|
|
||||||
mBuffer.Append(mBeginComment);
|
mBuffer.Append(mBeginComment);
|
||||||
mBuffer.Append(aContent);
|
mBuffer.Append(aContent);
|
||||||
mBuffer.Append(mEndComment);
|
mBuffer.Append(mEndComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// AddContentComment is used to add an HTML comment,
|
||||||
|
// which will be mapped back into the right thing
|
||||||
|
// in the content sink on the other end when this is parsed.
|
||||||
|
//
|
||||||
void nsXIFConverter::AddContentComment(const nsString& aContent)
|
void nsXIFConverter::AddContentComment(const nsString& aContent)
|
||||||
{
|
{
|
||||||
// For actual comments, don't want to include the begin and
|
|
||||||
// end tags; but commenting them out caused bug
|
|
||||||
// http://bugzilla.mozilla.org/show_bug.cgi?id=7720
|
|
||||||
// so we'll have to look into this more deeply later.
|
|
||||||
nsString tag(mComment);
|
nsString tag(mComment);
|
||||||
AddStartTag(tag, PR_FALSE);
|
AddStartTag(tag, PR_FALSE);
|
||||||
nsAutoString content;
|
nsAutoString content;
|
||||||
|
|
|
@ -78,7 +78,6 @@ static NS_DEFINE_CID(kPrintPreviewContextCID, NS_PRINT_PREVIEW_CONTEXT_CID);
|
||||||
static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID);
|
static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID);
|
||||||
static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID);
|
static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID);
|
||||||
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
|
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
|
||||||
static NS_DEFINE_CID(kHTMLEncoderCID, NS_HTML_ENCODER_CID);
|
|
||||||
static NS_DEFINE_CID(kTextEncoderCID, NS_TEXT_ENCODER_CID);
|
static NS_DEFINE_CID(kTextEncoderCID, NS_TEXT_ENCODER_CID);
|
||||||
|
|
||||||
extern nsresult NS_NewRangeList(nsIDOMSelection** aResult);
|
extern nsresult NS_NewRangeList(nsIDOMSelection** aResult);
|
||||||
|
@ -380,14 +379,6 @@ nsLayoutFactory::CreateInstance(nsISupports *aOuter,
|
||||||
}
|
}
|
||||||
refCounted = PR_TRUE;
|
refCounted = PR_TRUE;
|
||||||
}
|
}
|
||||||
else if (mClassID.Equals(kHTMLEncoderCID)) {
|
|
||||||
res = NS_NewHTMLEncoder((nsIDocumentEncoder**) &inst);
|
|
||||||
if (NS_FAILED(res)) {
|
|
||||||
LOG_NEW_FAILURE("NS_NewHTMLEncoder", res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
refCounted = PR_TRUE;
|
|
||||||
}
|
|
||||||
else if (mClassID.Equals(kTextEncoderCID)) {
|
else if (mClassID.Equals(kTextEncoderCID)) {
|
||||||
res = NS_NewTextEncoder((nsIDocumentEncoder**) &inst);
|
res = NS_NewTextEncoder((nsIDocumentEncoder**) &inst);
|
||||||
if (NS_FAILED(res)) {
|
if (NS_FAILED(res)) {
|
||||||
|
@ -709,20 +700,34 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
|
||||||
LOG_REGISTER_FAILURE("kHTMLElementFactoryCID", rv);
|
LOG_REGISTER_FAILURE("kHTMLElementFactoryCID", rv);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rv = cm->RegisterComponent(kHTMLEncoderCID, NULL, NULL, aPath,
|
rv = cm->RegisterComponent(kTextEncoderCID, "HTML document encoder",
|
||||||
|
NS_DOC_ENCODER_PROGID_BASE "text/html",
|
||||||
|
aPath,
|
||||||
PR_TRUE, PR_TRUE);
|
PR_TRUE, PR_TRUE);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
LOG_REGISTER_FAILURE("kHTMLEncoderCID", rv);
|
LOG_REGISTER_FAILURE(NS_DOC_ENCODER_PROGID_BASE "text/html", rv);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = cm->RegisterComponent(kTextEncoderCID, NULL, NULL, aPath,
|
rv = cm->RegisterComponent(kTextEncoderCID, "Plaintext document encoder",
|
||||||
|
NS_DOC_ENCODER_PROGID_BASE "text/plain",
|
||||||
|
aPath,
|
||||||
PR_TRUE, PR_TRUE);
|
PR_TRUE, PR_TRUE);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
LOG_REGISTER_FAILURE("kTextEncoderCID", rv);
|
LOG_REGISTER_FAILURE(NS_DOC_ENCODER_PROGID_BASE "text/plain", rv);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
rv = cm->RegisterComponent(kTextEncoderCID, "XIF document encoder",
|
||||||
|
NS_DOC_ENCODER_PROGID_BASE "text/xif",
|
||||||
|
aPath,
|
||||||
|
PR_TRUE, PR_TRUE);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
LOG_REGISTER_FAILURE(NS_DOC_ENCODER_PROGID_BASE "text/xif", rv);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
} while (PR_FALSE);
|
} while (PR_FALSE);
|
||||||
|
|
||||||
servMgr->ReleaseService(kComponentManagerCID, cm);
|
servMgr->ReleaseService(kComponentManagerCID, cm);
|
||||||
|
@ -767,7 +772,7 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
|
||||||
rv = cm->UnregisterComponent(kSubtreeIteratorCID, aPath);
|
rv = cm->UnregisterComponent(kSubtreeIteratorCID, aPath);
|
||||||
rv = cm->UnregisterComponent(kFrameUtilCID, aPath);
|
rv = cm->UnregisterComponent(kFrameUtilCID, aPath);
|
||||||
rv = cm->UnregisterComponent(kLayoutDebuggerCID, aPath);
|
rv = cm->UnregisterComponent(kLayoutDebuggerCID, aPath);
|
||||||
rv = cm->UnregisterComponent(kHTMLEncoderCID, aPath);
|
//rv = cm->UnregisterComponent(kHTMLEncoderCID, aPath);
|
||||||
rv = cm->UnregisterComponent(kTextEncoderCID, aPath);
|
rv = cm->UnregisterComponent(kTextEncoderCID, aPath);
|
||||||
|
|
||||||
// XXX why the heck are these exported???? bad bad bad bad
|
// XXX why the heck are these exported???? bad bad bad bad
|
||||||
|
|
|
@ -193,12 +193,14 @@ void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter)
|
||||||
nsICSSRule* rule = nsnull;
|
nsICSSRule* rule = nsnull;
|
||||||
|
|
||||||
cssSheet->StyleRuleCount(ruleCount);
|
cssSheet->StyleRuleCount(ruleCount);
|
||||||
aConverter.BeginCSSStyleSheet();
|
if (ruleCount > 0)
|
||||||
for (ruleIndex = 0; ruleIndex < ruleCount; ruleIndex++)
|
|
||||||
{
|
{
|
||||||
if (NS_OK == cssSheet->GetStyleRuleAt(ruleIndex, rule))
|
aConverter.BeginCSSStyleSheet();
|
||||||
|
for (ruleIndex = 0; ruleIndex < ruleCount; ruleIndex++)
|
||||||
{
|
{
|
||||||
aConverter.BeginCSSRule();
|
if (NS_OK == cssSheet->GetStyleRuleAt(ruleIndex, rule))
|
||||||
|
{
|
||||||
|
aConverter.BeginCSSRule();
|
||||||
|
|
||||||
if (nsnull != rule)
|
if (nsnull != rule)
|
||||||
{
|
{
|
||||||
|
@ -218,10 +220,11 @@ void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter)
|
||||||
NS_IF_RELEASE(rule);
|
NS_IF_RELEASE(rule);
|
||||||
} // ruleAt
|
} // ruleAt
|
||||||
|
|
||||||
aConverter.EndCSSRule();
|
aConverter.EndCSSRule();
|
||||||
} // for loop
|
} // for loop
|
||||||
}
|
}
|
||||||
aConverter.EndCSSStyleSheet();
|
aConverter.EndCSSStyleSheet();
|
||||||
|
} // if ruleCount > 0
|
||||||
NS_RELEASE(cssSheet);
|
NS_RELEASE(cssSheet);
|
||||||
} // css_sheet
|
} // css_sheet
|
||||||
NS_RELEASE(sheet);
|
NS_RELEASE(sheet);
|
||||||
|
|
|
@ -271,7 +271,8 @@ nsGfxTextControlFrame::GetText(nsString* aText, PRBool aInitialValue)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (PR_TRUE==IsInitialized()) {
|
if (PR_TRUE==IsInitialized()) {
|
||||||
result = mEditor->OutputTextToString(*aText, PR_FALSE);
|
nsString format ("text/html");
|
||||||
|
mEditor->OutputToString(*aText, format, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = nsFormControlHelper::GetInputElementValue(mContent, aText, aInitialValue);
|
result = nsFormControlHelper::GetInputElementValue(mContent, aText, aInitialValue);
|
||||||
|
@ -533,7 +534,8 @@ void nsGfxTextControlFrame::GetTextControlFrameState(nsString& aValue)
|
||||||
{
|
{
|
||||||
aValue = ""; // initialize out param
|
aValue = ""; // initialize out param
|
||||||
if (PR_TRUE==IsInitialized()) {
|
if (PR_TRUE==IsInitialized()) {
|
||||||
mEditor->OutputTextToString(aValue, PR_FALSE);
|
nsString format ("text/html");
|
||||||
|
mEditor->OutputToString(aValue, format, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +544,8 @@ void nsGfxTextControlFrame::SetTextControlFrameState(const nsString& aValue)
|
||||||
if (PR_TRUE==IsInitialized())
|
if (PR_TRUE==IsInitialized())
|
||||||
{
|
{
|
||||||
nsAutoString currentValue;
|
nsAutoString currentValue;
|
||||||
nsresult result = mEditor->OutputTextToString(currentValue, PR_FALSE);
|
nsString format ("text/html");
|
||||||
|
nsresult result = mEditor->OutputToString(currentValue, format, 0);
|
||||||
if (PR_TRUE==IsSingleLineTextControl()) {
|
if (PR_TRUE==IsSingleLineTextControl()) {
|
||||||
RemoveNewlines(currentValue);
|
RemoveNewlines(currentValue);
|
||||||
}
|
}
|
||||||
|
@ -1284,7 +1287,8 @@ nsGfxTextControlFrame::InternalContentChanged()
|
||||||
if (!IsInitialized()) { return NS_ERROR_NOT_INITIALIZED; }
|
if (!IsInitialized()) { return NS_ERROR_NOT_INITIALIZED; }
|
||||||
nsAutoString textValue;
|
nsAutoString textValue;
|
||||||
// XXX: need to check here if we're an HTML edit field or a text edit field
|
// XXX: need to check here if we're an HTML edit field or a text edit field
|
||||||
mEditor->OutputTextToString(textValue, PR_FALSE);
|
nsString format ("text/html");
|
||||||
|
mEditor->OutputToString(textValue, format, 0);
|
||||||
if (IsSingleLineTextControl()) {
|
if (IsSingleLineTextControl()) {
|
||||||
RemoveNewlines(textValue);
|
RemoveNewlines(textValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "nsIMessage.h" //temporary!
|
#include "nsIMessage.h" //temporary!
|
||||||
#include "nsMsgQuote.h"
|
#include "nsMsgQuote.h"
|
||||||
#include "nsIPref.h"
|
#include "nsIPref.h"
|
||||||
|
#include "nsIEditor.h" // for output flags
|
||||||
#include "nsXPIDLString.h"
|
#include "nsXPIDLString.h"
|
||||||
#include "nsIParser.h"
|
#include "nsIParser.h"
|
||||||
#include "nsParserCIID.h"
|
#include "nsParserCIID.h"
|
||||||
|
@ -380,10 +381,16 @@ nsresult nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode,
|
||||||
{
|
{
|
||||||
nsAutoString msgBody;
|
nsAutoString msgBody;
|
||||||
PRUnichar *bodyText = NULL;
|
PRUnichar *bodyText = NULL;
|
||||||
|
nsString format;
|
||||||
|
PRUint32 flags = 0;
|
||||||
if (m_composeHTML)
|
if (m_composeHTML)
|
||||||
m_editor->GetContentsAsHTML(&bodyText);
|
format = "text/html";
|
||||||
else
|
else
|
||||||
m_editor->GetContentsAsText(&bodyText);
|
{
|
||||||
|
flags = nsIEditor::EditorOutputFormatted;
|
||||||
|
format = "text/plain";
|
||||||
|
}
|
||||||
|
m_editor->GetContentsAs(format.GetUnicode(), flags, &bodyText);
|
||||||
|
|
||||||
msgBody = bodyText;
|
msgBody = bodyText;
|
||||||
delete [] bodyText;
|
delete [] bodyText;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsIDOMDocument.h"
|
#include "nsIDOMDocument.h"
|
||||||
|
|
||||||
|
#include "nsIEditor.h"
|
||||||
#include "nsIHTMLEditor.h"
|
#include "nsIHTMLEditor.h"
|
||||||
#include "nsITextEditor.h"
|
#include "nsITextEditor.h"
|
||||||
#include "nsEditorCID.h"
|
#include "nsEditorCID.h"
|
||||||
|
@ -83,16 +84,21 @@ nsresult NS_InitEditorMode(nsIDOMDocument *aDOMDocument, nsIPresShell* aPresShel
|
||||||
static nsresult PrintEditorOutput(nsIHTMLEditor* editor, PRInt32 aCommandID)
|
static nsresult PrintEditorOutput(nsIHTMLEditor* editor, PRInt32 aCommandID)
|
||||||
{
|
{
|
||||||
nsString outString;
|
nsString outString;
|
||||||
char* cString;
|
char* cString;
|
||||||
|
nsString formatString;
|
||||||
|
PRUint32 flags;
|
||||||
|
|
||||||
switch (aCommandID)
|
switch (aCommandID)
|
||||||
{
|
{
|
||||||
case VIEWER_DISPLAYTEXT:
|
case VIEWER_DISPLAYTEXT:
|
||||||
gEditor->OutputTextToString(outString, PR_FALSE);
|
formatString = "text/plain";
|
||||||
|
flags = nsIEditor::EditorOutputFormatted;
|
||||||
|
gEditor->OutputToString(outString, formatString, flags);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIEWER_DISPLAYHTML:
|
case VIEWER_DISPLAYHTML:
|
||||||
gEditor->OutputHTMLToString(outString, PR_FALSE);
|
formatString = "text/html";
|
||||||
|
gEditor->OutputToString(outString, formatString, flags);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче