зеркало из 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} \
|
||||
}
|
||||
|
||||
#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 \
|
||||
{ /* e7ba1480-1dea-11d3-830f-00104bed045e */ \
|
||||
0xe7ba1480, \
|
||||
|
@ -53,6 +45,7 @@ class nsIPresShell;
|
|||
{0x83, 0x0f, 0x00, 0x10, 0x4b, 0xed, 0x04, 0x5e} \
|
||||
}
|
||||
|
||||
#define NS_DOC_ENCODER_PROGID_BASE "component://netscape/layout/documentEncoder?type="
|
||||
|
||||
class nsIDocumentEncoder : public nsISupports
|
||||
{
|
||||
|
@ -64,7 +57,7 @@ public:
|
|||
* 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
|
||||
|
@ -98,24 +91,8 @@ public:
|
|||
NS_IMETHOD EncodeToString(nsString& aOutputString) = 0;
|
||||
};
|
||||
|
||||
// Example of a output service for a particular encoder
|
||||
class nsIHTMLEncoder : public nsIDocumentEncoder
|
||||
{
|
||||
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
|
||||
// Example of a output service for a particular encoder.
|
||||
// The text encoder handles XIF, HTML, and plaintext.
|
||||
class nsITextEncoder : public nsIDocumentEncoder
|
||||
{
|
||||
public:
|
||||
|
@ -125,6 +102,7 @@ public:
|
|||
// NOTE: we may want to use an enumerator
|
||||
NS_IMETHOD PrettyPrint(PRBool aYes) = 0;
|
||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
|
||||
NS_IMETHOD AddHeader(PRBool aYes) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -2849,6 +2849,11 @@ nsDocument::IncrementModCount(PRInt32 aNumMods)
|
|||
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,
|
||||
const nsIContent* aTest1,
|
||||
const nsIContent* aTest2) const
|
||||
|
@ -2892,7 +2897,16 @@ PRBool nsDocument::IsInRange(const nsIContent *aStartContent, const nsIContent*
|
|||
{
|
||||
result = IsBefore(aStartContent,aContent);
|
||||
if (result == PR_TRUE)
|
||||
{
|
||||
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;
|
||||
|
||||
|
|
|
@ -36,276 +36,8 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
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);
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
|
@ -314,7 +46,8 @@ public:
|
|||
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 */
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -325,8 +58,9 @@ public:
|
|||
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
|
||||
NS_IMETHOD EncodeToString(nsString& aOutputString);
|
||||
|
||||
NS_IMETHOD PrettyPrint(PRBool aYesNO);
|
||||
NS_IMETHOD PrettyPrint(PRBool aYes);
|
||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
|
||||
NS_IMETHOD AddHeader(PRBool aYes);
|
||||
|
||||
private:
|
||||
nsIDocument* mDocument;
|
||||
|
@ -336,6 +70,7 @@ private:
|
|||
nsString mCharset;
|
||||
PRBool mPrettyPrint;
|
||||
PRUint32 mWrapColumn;
|
||||
PRBool mAddHeader;
|
||||
};
|
||||
|
||||
|
||||
|
@ -357,7 +92,8 @@ nsTextEncoder::~nsTextEncoder()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument, nsString& aMimeType)
|
||||
nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
|
||||
const nsString& aMimeType)
|
||||
{
|
||||
if (!aDocument)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
@ -409,6 +145,13 @@ nsTextEncoder::SetWrapColumn(PRUint32 aWC)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEncoder::AddHeader(PRBool aYes)
|
||||
{
|
||||
mAddHeader = aYes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEncoder::SetSelection(nsIDOMSelection* aSelection)
|
||||
{
|
||||
|
@ -441,7 +184,14 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
|
|||
{
|
||||
nsString buffer;
|
||||
|
||||
mDocument->CreateXIF(buffer,mSelection);
|
||||
if (mMimeType == "text/xif")
|
||||
{
|
||||
mDocument->CreateXIF(aOutputString, mSelection);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mDocument->CreateXIF(buffer, mSelection);
|
||||
|
||||
nsIParser* parser;
|
||||
|
||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||
|
@ -456,19 +206,23 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
|
|||
{
|
||||
nsIHTMLContentSink* sink = nsnull;
|
||||
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
|
||||
mWrapColumn, mPrettyPrint);
|
||||
|
||||
if (sink && NS_SUCCEEDED(rv))
|
||||
if (mMimeType == "text/html")
|
||||
rv = NS_New_HTML_ContentSinkStream(&sink, &aOutputString,
|
||||
PR_FALSE, mAddHeader);
|
||||
|
||||
else // default to text/plain
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
|
||||
mWrapColumn, mPrettyPrint);
|
||||
|
||||
if (sink && NS_SUCCEEDED(rv))
|
||||
{
|
||||
parser->SetContentSink(sink);
|
||||
|
||||
nsIDTD* dtd = nsnull;
|
||||
rv = NS_NewXIFDTD(&dtd);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
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(sink);
|
||||
|
@ -516,8 +270,13 @@ nsTextEncoder::EncodeToStream(nsIOutputStream* aStream)
|
|||
if (NS_OK == rv) {
|
||||
nsIHTMLContentSink* sink = nsnull;
|
||||
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, aStream, charset,
|
||||
mWrapColumn, mPrettyPrint);
|
||||
if (mMimeType == "text/html")
|
||||
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))
|
||||
{
|
||||
|
@ -613,9 +372,7 @@ nsDocumentEncoderFactory::CreateInstance(nsISupports *aOuter,
|
|||
|
||||
*aResult = 0;
|
||||
|
||||
if (aIID.Equals(kCHTMLEncoderCID))
|
||||
*aResult = new nsHTMLEncoder;
|
||||
else if (aIID.Equals(kCTextEncoderCID))
|
||||
if (aIID.Equals(kCTextEncoderCID))
|
||||
*aResult = new nsTextEncoder;
|
||||
else
|
||||
return NS_NOINTERFACE;
|
||||
|
|
|
@ -193,12 +193,14 @@ void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter)
|
|||
nsICSSRule* rule = nsnull;
|
||||
|
||||
cssSheet->StyleRuleCount(ruleCount);
|
||||
aConverter.BeginCSSStyleSheet();
|
||||
for (ruleIndex = 0; ruleIndex < ruleCount; ruleIndex++)
|
||||
if (ruleCount > 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -218,10 +220,11 @@ void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter)
|
|||
NS_IF_RELEASE(rule);
|
||||
} // ruleAt
|
||||
|
||||
aConverter.EndCSSRule();
|
||||
} // for loop
|
||||
}
|
||||
aConverter.EndCSSStyleSheet();
|
||||
aConverter.EndCSSRule();
|
||||
} // for loop
|
||||
}
|
||||
aConverter.EndCSSStyleSheet();
|
||||
} // if ruleCount > 0
|
||||
NS_RELEASE(cssSheet);
|
||||
} // css_sheet
|
||||
NS_RELEASE(sheet);
|
||||
|
|
|
@ -1491,6 +1491,41 @@ NS_IMETHODIMP nsEditor::ApplyStyleSheet(const nsString& aURL)
|
|||
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
|
||||
nsEditor::AddEditActionListener(nsIEditActionListener *aListener)
|
||||
{
|
||||
|
|
|
@ -180,6 +180,15 @@ public:
|
|||
|
||||
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 DeleteSelection(nsIEditor::ECollapsedSelectionAction aAction);
|
||||
|
|
|
@ -290,11 +290,19 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
aProcessed=PR_TRUE;
|
||||
nsString output;
|
||||
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));
|
||||
if (htmlEditor)
|
||||
{
|
||||
if (isShift)
|
||||
res = htmlEditor->OutputTextToString(output, PR_FALSE);
|
||||
res = htmlEditor->OutputTextToString(output, PR_TRUE, PR_FALSE);
|
||||
else
|
||||
res = htmlEditor->OutputHTMLToString(output, PR_FALSE);
|
||||
}
|
||||
|
@ -304,11 +312,12 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
if (textEditor)
|
||||
{
|
||||
if (isShift)
|
||||
res = textEditor->OutputTextToString(output, PR_FALSE);
|
||||
res = textEditor->OutputTextToString(output, PR_TRUE, PR_FALSE);
|
||||
else
|
||||
res = textEditor->OutputHTMLToString(output, PR_FALSE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
|
|
|
@ -243,6 +243,7 @@ nsEditorShell::Init()
|
|||
nsAutoString editorType = "html"; // default to creating HTML editor
|
||||
mEditorTypeString = editorType;
|
||||
mEditorTypeString.ToLowerCase();
|
||||
mWrapColumn = 0;
|
||||
|
||||
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
|
||||
mEditorType = ePlainTextEditorType;
|
||||
|
||||
// and set the initial wrap column
|
||||
editor->SetBodyWrapWidth(mWrapColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1505,131 +1509,36 @@ nsEditorShell::FindNext()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::GetContentsAsText(PRUnichar * *contentsAsText)
|
||||
nsEditorShell::GetContentsAs(const PRUnichar *format, PRUint32 flags,
|
||||
PRUnichar **contentsAs)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::GetContentsAsHTML(PRUnichar * *contentsAsHTML)
|
||||
nsEditorShell::DumpContentTree()
|
||||
{
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
|
||||
nsString aContentsAsHTML;
|
||||
|
||||
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;
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return editor->DumpContentTree();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -1641,8 +1550,13 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
|
|||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// 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)
|
||||
{
|
||||
case ePlainTextEditorType:
|
||||
|
@ -1667,22 +1581,24 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
|
|||
NS_IMETHODIMP
|
||||
nsEditorShell::SetWrapColumn(PRInt32 aWrapColumn)
|
||||
{
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
|
||||
if (!aWrapColumn)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
switch (mEditorType)
|
||||
nsresult err = NS_OK;
|
||||
|
||||
mWrapColumn = aWrapColumn;
|
||||
|
||||
if (mEditor)
|
||||
{
|
||||
case ePlainTextEditorType:
|
||||
{
|
||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||
if (textEditor)
|
||||
err = textEditor->SetBodyWrapWidth(aWrapColumn);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
||||
switch (mEditorType)
|
||||
{
|
||||
case ePlainTextEditorType:
|
||||
{
|
||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||
if (textEditor)
|
||||
err = textEditor->SetBodyWrapWidth(mWrapColumn);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
|
|
|
@ -82,10 +82,6 @@ class nsEditorShell : public nsIEditorShell,
|
|||
|
||||
|
||||
/* 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 GetEditorSelection(nsIDOMSelection * *aEditorSelection);
|
||||
|
@ -163,6 +159,12 @@ class nsEditorShell : public nsIEditorShell,
|
|||
|
||||
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); */
|
||||
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> 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___
|
||||
|
|
|
@ -63,8 +63,6 @@ static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
|
|||
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
||||
static NS_DEFINE_CID(kCRangeCID, NS_RANGE_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
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
|
@ -661,45 +659,22 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTML(const nsString& aInputString)
|
|||
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)
|
||||
printf("============Content dump:===========\n");
|
||||
|
||||
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);
|
||||
return nsTextEditor::OutputToStream(aOutputStream, aFormatType,
|
||||
aCharset, aFlags);
|
||||
}
|
||||
|
||||
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
|
||||
nsHTMLEditor::CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
|
||||
{
|
||||
|
|
|
@ -108,10 +108,14 @@ public:
|
|||
NS_IMETHOD BeginComposition(void);
|
||||
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aTextRange);
|
||||
NS_IMETHOD EndComposition(void);
|
||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly);
|
||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly);
|
||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream,nsString* aCharsetOverride, PRBool aSelectionOnly);
|
||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream,nsString* aCharsetOverride, PRBool aSelectionOnly);
|
||||
|
||||
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||
const nsString& aFormatType,
|
||||
PRUint32 aFlags);
|
||||
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||
const nsString& aFormatType,
|
||||
const nsString* aCharsetOverride,
|
||||
PRUint32 aFlags);
|
||||
|
||||
// Miscellaneous
|
||||
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
|
||||
|
|
|
@ -512,25 +512,18 @@ nsJSEditorLog::InsertHTML(const nsString &aInputString)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSEditorLog::OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly)
|
||||
nsJSEditorLog::OutputToString(nsString& aOutputString,
|
||||
const nsString& aFormatType,
|
||||
PRUint32 aFlags)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSEditorLog::OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
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)
|
||||
nsJSEditorLog::OutputToStream(nsIOutputStream* aOutputStream,
|
||||
const nsString& aFormatType,
|
||||
const nsString* aCharsetOverride,
|
||||
PRUint32 aFlags)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -98,11 +98,13 @@ public:
|
|||
|
||||
NS_IMETHOD InsertHTML(const nsString &aInputString);
|
||||
|
||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly);
|
||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly);
|
||||
|
||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly);
|
||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly);
|
||||
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 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_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 "nsIServiceManager.h"
|
||||
|
||||
|
@ -266,9 +262,6 @@ NS_IMETHODIMP nsTextEditor::Init(nsIDOMDocument *aDoc,
|
|||
// get a mouse listener
|
||||
result = NS_NewEditorMouseListener(getter_AddRefs(mMouseListenerP), this);
|
||||
if (NS_OK != result) {
|
||||
#ifdef DEBUG_akkana
|
||||
printf("Couldn't get mouse listener\n");
|
||||
#endif
|
||||
HandleEventListenerError();
|
||||
return result;
|
||||
}
|
||||
|
@ -1322,10 +1315,6 @@ NS_IMETHODIMP nsTextEditor::PasteAsQuotation()
|
|||
mJSEditorLog->PasteAsQuotation();
|
||||
#endif // ENABLE_JS_EDITOR_LOG
|
||||
|
||||
#ifdef DEBUG_akkana
|
||||
printf("nsTextEditor::PasteAsQuotation\n");
|
||||
#endif
|
||||
|
||||
nsString stuffToPaste;
|
||||
|
||||
// Get Clipboard Service
|
||||
|
@ -1431,12 +1420,7 @@ NS_IMETHODIMP nsTextEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
|
|||
PRBool isSet;
|
||||
res = GetAttributeValue(preElement, colsStr, numCols, isSet);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("GetAttributeValue(cols) failed\n");
|
||||
#endif
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
if (isSet)
|
||||
{
|
||||
|
@ -1451,12 +1435,7 @@ NS_IMETHODIMP nsTextEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
|
|||
nsString wrapStr ("wrap");
|
||||
res = GetAttributeValue(preElement, colsStr, numCols, isSet);
|
||||
if (!NS_SUCCEEDED(res))
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("GetAttributeValue(cols) failed\n");
|
||||
#endif
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
if (isSet)
|
||||
*aWrapColumn = 0; // wrap to window width
|
||||
|
@ -1518,7 +1497,9 @@ NS_IMETHODIMP nsTextEditor::ApplyStyleSheet(const nsString& 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;
|
||||
nsString resultString;
|
||||
|
@ -1532,38 +1513,50 @@ NS_IMETHODIMP nsTextEditor::OutputTextToString(nsString& aOutputString, PRBool a
|
|||
else
|
||||
{ // default processing
|
||||
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,
|
||||
nsIDocumentEncoder::GetIID(),
|
||||
getter_AddRefs(encoder));
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("Couldn't get progid %s\n", progid);
|
||||
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/plain");
|
||||
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
|
||||
rv = GetPresShell(getter_AddRefs(shell));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = encoder->Init(shell, doc, mimetype);
|
||||
rv = encoder->Init(shell, doc, aFormatType);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (aSelectionOnly) {
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
if (aFlags & EditorOutputSelectionOnly)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
rv = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(rv) && selection)
|
||||
encoder->SetSelection(selection);
|
||||
}
|
||||
|
||||
// Try to turn on pretty printing, but don't panic if it doesn't work:
|
||||
(void)encoder->PrettyPrint(PR_TRUE);
|
||||
// Try to set pretty printing, but don't panic if it doesn't work:
|
||||
(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,
|
||||
// i.e. wrap to body width, then don't set it, let the
|
||||
// document encoder use its own default.
|
||||
|
@ -1583,76 +1576,33 @@ NS_IMETHODIMP nsTextEditor::OutputTextToString(nsString& aOutputString, PRBool a
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly)
|
||||
{
|
||||
#if defined(DEBUG_akkana)
|
||||
printf("============Content dump:===========\n");
|
||||
|
||||
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)
|
||||
NS_IMETHODIMP nsTextEditor::OutputToStream(nsIOutputStream* aOutputStream,
|
||||
const nsString& aFormatType,
|
||||
const nsString* aCharset,
|
||||
PRUint32 aFlags)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsITextEncoder> encoder;
|
||||
nsresult rv = nsComponentManager::CreateInstance(kTextEncoderCID,
|
||||
nsnull,
|
||||
nsIDocumentEncoder::GetIID(),
|
||||
getter_AddRefs(encoder));
|
||||
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,
|
||||
nsIDocumentEncoder::GetIID(),
|
||||
getter_AddRefs(encoder));
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
printf("Couldn't get progid %s\n", progid);
|
||||
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/plain");
|
||||
|
||||
if (aCharset && aCharset->Length() != 0 && aCharset->Equals("null")==PR_FALSE)
|
||||
encoder->SetCharset(*aCharset);
|
||||
|
@ -1661,59 +1611,37 @@ NS_IMETHODIMP nsTextEditor::OutputTextToStream(nsIOutputStream* aOutputStream, n
|
|||
|
||||
rv = GetPresShell(getter_AddRefs(shell));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = encoder->Init(shell,doc, mimetype);
|
||||
rv = encoder->Init(shell,doc, aFormatType);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (aSelectionOnly) {
|
||||
if (aFlags & EditorOutputSelectionOnly)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
rv = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_SUCCEEDED(rv) && selection)
|
||||
encoder->SetSelection(selection);
|
||||
}
|
||||
|
||||
// Try to turn on pretty printing, but don't panic if it doesn't work:
|
||||
(void)encoder->PrettyPrint(PR_TRUE);
|
||||
(void)encoder->SetWrapColumn(mWrapColumn);
|
||||
|
||||
return encoder->EncodeToStream(aOutputStream);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::OutputHTMLToStream(nsIOutputStream* aOutputStream,nsString* aCharset, PRBool aSelectionOnly)
|
||||
{
|
||||
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;
|
||||
|
||||
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);
|
||||
// Try to set pretty printing, but don't panic if it doesn't work:
|
||||
(void)encoder->PrettyPrint((aFlags & EditorOutputFormatted)
|
||||
? PR_TRUE : PR_FALSE);
|
||||
// Indicate whether we want the comment and doc type headers prepended:
|
||||
(void)encoder->AddHeader((aFlags & EditorOutputNoDoctype)
|
||||
? PR_FALSE : PR_TRUE);
|
||||
// Set the wrap column. If our wrap column is 0,
|
||||
// i.e. wrap to body width, then don't set it, let the
|
||||
// document encoder use its own default.
|
||||
if (mWrapColumn != 0)
|
||||
{
|
||||
PRUint32 wc;
|
||||
if (mWrapColumn < 0)
|
||||
wc = 0;
|
||||
else
|
||||
wc = (PRUint32)mWrapColumn;
|
||||
if (mWrapColumn > 0)
|
||||
(void)encoder->SetWrapColumn(wc);
|
||||
}
|
||||
|
||||
return encoder->EncodeToStream(aOutputStream);
|
||||
|
@ -1743,12 +1671,8 @@ nsTextEditor::FindPreElement()
|
|||
nsCOMPtr<nsIDOMNode> preNode;
|
||||
if (!NS_SUCCEEDED(nsEditor::GetFirstNodeOfType(rootNode, prestr,
|
||||
getter_AddRefs(preNode))))
|
||||
{
|
||||
#ifdef DEBUG_akkana
|
||||
printf("No PRE tag\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
return do_QueryInterface(preNode);
|
||||
}
|
||||
|
||||
|
|
|
@ -116,10 +116,14 @@ public:
|
|||
NS_IMETHOD BeginComposition(void);
|
||||
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aRangeList);
|
||||
NS_IMETHOD EndComposition(void);
|
||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly);
|
||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly);
|
||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly);
|
||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly);
|
||||
|
||||
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||
const nsString& aFormatType,
|
||||
PRUint32 aFlags);
|
||||
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||
const nsString& aFormatType,
|
||||
const nsString* aCharsetOverride,
|
||||
PRUint32 aFlags);
|
||||
|
||||
// Plain text wrapping control
|
||||
NS_IMETHOD GetBodyWrapWidth(PRInt32 *aWrapColumn);
|
||||
|
|
|
@ -243,6 +243,7 @@ nsEditorShell::Init()
|
|||
nsAutoString editorType = "html"; // default to creating HTML editor
|
||||
mEditorTypeString = editorType;
|
||||
mEditorTypeString.ToLowerCase();
|
||||
mWrapColumn = 0;
|
||||
|
||||
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
|
||||
mEditorType = ePlainTextEditorType;
|
||||
|
||||
// and set the initial wrap column
|
||||
editor->SetBodyWrapWidth(mWrapColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1505,131 +1509,36 @@ nsEditorShell::FindNext()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::GetContentsAsText(PRUnichar * *contentsAsText)
|
||||
nsEditorShell::GetContentsAs(const PRUnichar *format, PRUint32 flags,
|
||||
PRUnichar **contentsAs)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::GetContentsAsHTML(PRUnichar * *contentsAsHTML)
|
||||
nsEditorShell::DumpContentTree()
|
||||
{
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
|
||||
nsString aContentsAsHTML;
|
||||
|
||||
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;
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return editor->DumpContentTree();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -1641,8 +1550,13 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
|
|||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// 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)
|
||||
{
|
||||
case ePlainTextEditorType:
|
||||
|
@ -1667,22 +1581,24 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
|
|||
NS_IMETHODIMP
|
||||
nsEditorShell::SetWrapColumn(PRInt32 aWrapColumn)
|
||||
{
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
|
||||
if (!aWrapColumn)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
switch (mEditorType)
|
||||
nsresult err = NS_OK;
|
||||
|
||||
mWrapColumn = aWrapColumn;
|
||||
|
||||
if (mEditor)
|
||||
{
|
||||
case ePlainTextEditorType:
|
||||
{
|
||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||
if (textEditor)
|
||||
err = textEditor->SetBodyWrapWidth(aWrapColumn);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
||||
switch (mEditorType)
|
||||
{
|
||||
case ePlainTextEditorType:
|
||||
{
|
||||
nsCOMPtr<nsITextEditor> textEditor = do_QueryInterface(mEditor);
|
||||
if (textEditor)
|
||||
err = textEditor->SetBodyWrapWidth(mWrapColumn);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
|
|
|
@ -82,10 +82,6 @@ class nsEditorShell : public nsIEditorShell,
|
|||
|
||||
|
||||
/* 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 GetEditorSelection(nsIDOMSelection * *aEditorSelection);
|
||||
|
@ -163,6 +159,12 @@ class nsEditorShell : public nsIEditorShell,
|
|||
|
||||
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); */
|
||||
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> 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___
|
||||
|
|
|
@ -33,12 +33,6 @@ interface nsIFileSpec;
|
|||
[scriptable, uuid(9afff72b-ca9a-11d2-96c9-0060b0fb9956)]
|
||||
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 nsIDOMSelection editorSelection;
|
||||
|
||||
|
@ -110,6 +104,14 @@ interface nsIEditorShell : nsISupports
|
|||
|
||||
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 */
|
||||
wstring GetLocalFileURL(in nsIDOMWindow parent, in wstring filterType);
|
||||
|
||||
|
|
|
@ -1491,6 +1491,41 @@ NS_IMETHODIMP nsEditor::ApplyStyleSheet(const nsString& aURL)
|
|||
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
|
||||
nsEditor::AddEditActionListener(nsIEditActionListener *aListener)
|
||||
{
|
||||
|
|
|
@ -180,6 +180,15 @@ public:
|
|||
|
||||
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 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(kCRangeCID, NS_RANGE_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
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
|
@ -661,45 +659,22 @@ NS_IMETHODIMP nsHTMLEditor::InsertHTML(const nsString& aInputString)
|
|||
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)
|
||||
printf("============Content dump:===========\n");
|
||||
|
||||
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);
|
||||
return nsTextEditor::OutputToStream(aOutputStream, aFormatType,
|
||||
aCharset, aFlags);
|
||||
}
|
||||
|
||||
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
|
||||
nsHTMLEditor::CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
|
||||
{
|
||||
|
|
|
@ -108,10 +108,14 @@ public:
|
|||
NS_IMETHOD BeginComposition(void);
|
||||
NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIDOMTextRangeList* aTextRange);
|
||||
NS_IMETHOD EndComposition(void);
|
||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly);
|
||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly);
|
||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream,nsString* aCharsetOverride, PRBool aSelectionOnly);
|
||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream,nsString* aCharsetOverride, PRBool aSelectionOnly);
|
||||
|
||||
NS_IMETHOD OutputToString(nsString& aOutputString,
|
||||
const nsString& aFormatType,
|
||||
PRUint32 aFlags);
|
||||
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
|
||||
const nsString& aFormatType,
|
||||
const nsString* aCharsetOverride,
|
||||
PRUint32 aFlags);
|
||||
|
||||
// Miscellaneous
|
||||
NS_IMETHOD ApplyStyleSheet(const nsString& aURL);
|
||||
|
|
|
@ -290,11 +290,19 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
aProcessed=PR_TRUE;
|
||||
nsString output;
|
||||
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));
|
||||
if (htmlEditor)
|
||||
{
|
||||
if (isShift)
|
||||
res = htmlEditor->OutputTextToString(output, PR_FALSE);
|
||||
res = htmlEditor->OutputTextToString(output, PR_TRUE, PR_FALSE);
|
||||
else
|
||||
res = htmlEditor->OutputHTMLToString(output, PR_FALSE);
|
||||
}
|
||||
|
@ -304,11 +312,12 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
if (textEditor)
|
||||
{
|
||||
if (isShift)
|
||||
res = textEditor->OutputTextToString(output, PR_FALSE);
|
||||
res = textEditor->OutputTextToString(output, PR_TRUE, PR_FALSE);
|
||||
else
|
||||
res = textEditor->OutputHTMLToString(output, PR_FALSE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
|
|
|
@ -29,6 +29,7 @@ class nsIEditActionListener;
|
|||
class nsIFileSpec;
|
||||
class nsIDOMTextRangeList;
|
||||
class nsICSSStyleSheet;
|
||||
class nsIOutputStream;
|
||||
|
||||
/*
|
||||
Editor interface to outside world
|
||||
|
@ -204,7 +205,28 @@ public:
|
|||
|
||||
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.
|
||||
|
|
|
@ -102,11 +102,17 @@ public:
|
|||
|
||||
NS_IMETHOD InsertHTML(const nsString &aInputString)=0;
|
||||
|
||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly)=0;
|
||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly)=0;
|
||||
|
||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly)=0;
|
||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly)=0;
|
||||
/**
|
||||
* 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;
|
||||
|
||||
NS_IMETHOD ApplyStyleSheet(const nsString& aURL)=0;
|
||||
|
||||
|
|
|
@ -338,11 +338,17 @@ public:
|
|||
NS_IMETHOD ScrollIntoView(PRBool aScrollToBegin)=0;
|
||||
|
||||
// Input/Output
|
||||
NS_IMETHOD OutputTextToString(nsString& aOutputString, PRBool aSelectionOnly)=0;
|
||||
NS_IMETHOD OutputHTMLToString(nsString& aOutputString, PRBool aSelectionOnly)=0;
|
||||
|
||||
NS_IMETHOD OutputTextToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly)=0;
|
||||
NS_IMETHOD OutputHTMLToStream(nsIOutputStream* aOutputStream, nsString* aCharsetOverride, PRBool aSelectionOnly)=0;
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/** Get and set the body wrap width
|
||||
* @param aWrapColumn - the column to wrap at. This is set as a COLS attribute
|
||||
|
|
|
@ -187,8 +187,10 @@
|
|||
<!ENTITY debugMenu.label "Debug">
|
||||
<!ENTITY outputTextCmd.label "Output Text">
|
||||
<!ENTITY outputHTMLCmd.label "Output HTML">
|
||||
<!ENTITY outputXIFCmd.label "Output XIF">
|
||||
<!ENTITY insertTextCmd.label "Insert Text">
|
||||
<!ENTITY testSelectionCmd.label "Test Selection">
|
||||
<!ENTITY dumpContentCmd.label "Dump Content Tree">
|
||||
<!ENTITY testDocumentCmd.label "Test Document">
|
||||
<!ENTITY runUnitTestsCmd.label "Run Unit Tests">
|
||||
<!ENTITY startLogCmd.label "Start Log">
|
||||
|
@ -470,10 +472,12 @@
|
|||
<menu name="&debugMenu.label;">
|
||||
<menuitem name="&outputTextCmd.label;" onclick="EditorGetText()"/>
|
||||
<menuitem name="&outputHTMLCmd.label;" onclick="EditorGetHTML()"/>
|
||||
<menuitem name="&outputXIFCmd.label;" onclick="EditorGetXIF()"/>
|
||||
<separator />
|
||||
<menuitem name="&insertTextCmd.label;" onclick="EditorInsertText('All good things come to those who wait. ')"/>
|
||||
<separator />
|
||||
<menuitem name="&testSelectionCmd.label;" onclick="EditorTestSelection()"/>
|
||||
<menuitem name="&dumpContentCmd.label;" onclick="EditorDumpContent()"/>
|
||||
<menuitem name="&testDocumentCmd.label;" onclick="EditorTestDocument()"/>
|
||||
<menuitem name="&runUnitTestsCmd.label;" onclick="EditorUnitTests()"/>
|
||||
<separator />
|
||||
|
|
|
@ -326,7 +326,7 @@ function EditorGetText()
|
|||
{
|
||||
if (editorShell) {
|
||||
dump("Getting text\n");
|
||||
var outputText = editorShell.contentsAsText;
|
||||
var outputText = editorShell.GetContentsAs("text/plain", 2);
|
||||
dump(outputText + "\n");
|
||||
}
|
||||
}
|
||||
|
@ -335,8 +335,26 @@ function EditorGetHTML()
|
|||
{
|
||||
if (editorShell) {
|
||||
dump("Getting HTML\n");
|
||||
var outputText = editorShell.contentsAsHTML;
|
||||
dump(outputText + "\n");
|
||||
var outputHTML = editorShell.GetContentsAs("text/html", 2);
|
||||
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("Selection as text\n");
|
||||
dump(editorShell.selectionAsText + "\n\n");
|
||||
|
||||
dump("Selection as HTML\n");
|
||||
dump(editorShell.selectionAsHTML + "\n\n");
|
||||
var output;
|
||||
|
||||
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()
|
||||
|
|
|
@ -37,14 +37,6 @@ class nsIPresShell;
|
|||
{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 \
|
||||
{ /* e7ba1480-1dea-11d3-830f-00104bed045e */ \
|
||||
0xe7ba1480, \
|
||||
|
@ -53,6 +45,7 @@ class nsIPresShell;
|
|||
{0x83, 0x0f, 0x00, 0x10, 0x4b, 0xed, 0x04, 0x5e} \
|
||||
}
|
||||
|
||||
#define NS_DOC_ENCODER_PROGID_BASE "component://netscape/layout/documentEncoder?type="
|
||||
|
||||
class nsIDocumentEncoder : public nsISupports
|
||||
{
|
||||
|
@ -64,7 +57,7 @@ public:
|
|||
* 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
|
||||
|
@ -98,24 +91,8 @@ public:
|
|||
NS_IMETHOD EncodeToString(nsString& aOutputString) = 0;
|
||||
};
|
||||
|
||||
// Example of a output service for a particular encoder
|
||||
class nsIHTMLEncoder : public nsIDocumentEncoder
|
||||
{
|
||||
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
|
||||
// Example of a output service for a particular encoder.
|
||||
// The text encoder handles XIF, HTML, and plaintext.
|
||||
class nsITextEncoder : public nsIDocumentEncoder
|
||||
{
|
||||
public:
|
||||
|
@ -125,6 +102,7 @@ public:
|
|||
// NOTE: we may want to use an enumerator
|
||||
NS_IMETHOD PrettyPrint(PRBool aYes) = 0;
|
||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
|
||||
NS_IMETHOD AddHeader(PRBool aYes) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -2849,6 +2849,11 @@ nsDocument::IncrementModCount(PRInt32 aNumMods)
|
|||
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,
|
||||
const nsIContent* aTest1,
|
||||
const nsIContent* aTest2) const
|
||||
|
@ -2892,7 +2897,16 @@ PRBool nsDocument::IsInRange(const nsIContent *aStartContent, const nsIContent*
|
|||
{
|
||||
result = IsBefore(aStartContent,aContent);
|
||||
if (result == PR_TRUE)
|
||||
{
|
||||
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;
|
||||
|
||||
|
|
|
@ -36,276 +36,8 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
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);
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
|
@ -314,7 +46,8 @@ public:
|
|||
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 */
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -325,8 +58,9 @@ public:
|
|||
NS_IMETHOD EncodeToStream(nsIOutputStream* aStream);
|
||||
NS_IMETHOD EncodeToString(nsString& aOutputString);
|
||||
|
||||
NS_IMETHOD PrettyPrint(PRBool aYesNO);
|
||||
NS_IMETHOD PrettyPrint(PRBool aYes);
|
||||
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
|
||||
NS_IMETHOD AddHeader(PRBool aYes);
|
||||
|
||||
private:
|
||||
nsIDocument* mDocument;
|
||||
|
@ -336,6 +70,7 @@ private:
|
|||
nsString mCharset;
|
||||
PRBool mPrettyPrint;
|
||||
PRUint32 mWrapColumn;
|
||||
PRBool mAddHeader;
|
||||
};
|
||||
|
||||
|
||||
|
@ -357,7 +92,8 @@ nsTextEncoder::~nsTextEncoder()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument, nsString& aMimeType)
|
||||
nsTextEncoder::Init(nsIPresShell* aPresShell, nsIDocument* aDocument,
|
||||
const nsString& aMimeType)
|
||||
{
|
||||
if (!aDocument)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
@ -409,6 +145,13 @@ nsTextEncoder::SetWrapColumn(PRUint32 aWC)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEncoder::AddHeader(PRBool aYes)
|
||||
{
|
||||
mAddHeader = aYes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEncoder::SetSelection(nsIDOMSelection* aSelection)
|
||||
{
|
||||
|
@ -441,7 +184,14 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
|
|||
{
|
||||
nsString buffer;
|
||||
|
||||
mDocument->CreateXIF(buffer,mSelection);
|
||||
if (mMimeType == "text/xif")
|
||||
{
|
||||
mDocument->CreateXIF(aOutputString, mSelection);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mDocument->CreateXIF(buffer, mSelection);
|
||||
|
||||
nsIParser* parser;
|
||||
|
||||
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
|
||||
|
@ -456,19 +206,23 @@ nsTextEncoder::EncodeToString(nsString& aOutputString)
|
|||
{
|
||||
nsIHTMLContentSink* sink = nsnull;
|
||||
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
|
||||
mWrapColumn, mPrettyPrint);
|
||||
|
||||
if (sink && NS_SUCCEEDED(rv))
|
||||
if (mMimeType == "text/html")
|
||||
rv = NS_New_HTML_ContentSinkStream(&sink, &aOutputString,
|
||||
PR_FALSE, mAddHeader);
|
||||
|
||||
else // default to text/plain
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, &aOutputString,
|
||||
mWrapColumn, mPrettyPrint);
|
||||
|
||||
if (sink && NS_SUCCEEDED(rv))
|
||||
{
|
||||
parser->SetContentSink(sink);
|
||||
|
||||
nsIDTD* dtd = nsnull;
|
||||
rv = NS_NewXIFDTD(&dtd);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
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(sink);
|
||||
|
@ -516,8 +270,13 @@ nsTextEncoder::EncodeToStream(nsIOutputStream* aStream)
|
|||
if (NS_OK == rv) {
|
||||
nsIHTMLContentSink* sink = nsnull;
|
||||
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink, aStream, charset,
|
||||
mWrapColumn, mPrettyPrint);
|
||||
if (mMimeType == "text/html")
|
||||
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))
|
||||
{
|
||||
|
@ -613,9 +372,7 @@ nsDocumentEncoderFactory::CreateInstance(nsISupports *aOuter,
|
|||
|
||||
*aResult = 0;
|
||||
|
||||
if (aIID.Equals(kCHTMLEncoderCID))
|
||||
*aResult = new nsHTMLEncoder;
|
||||
else if (aIID.Equals(kCTextEncoderCID))
|
||||
if (aIID.Equals(kCTextEncoderCID))
|
||||
*aResult = new nsTextEncoder;
|
||||
else
|
||||
return NS_NOINTERFACE;
|
||||
|
|
|
@ -307,23 +307,25 @@ void nsXIFConverter::AddContent(const nsString& aContent)
|
|||
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)
|
||||
{
|
||||
// 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(aContent);
|
||||
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)
|
||||
{
|
||||
// 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);
|
||||
AddStartTag(tag, PR_FALSE);
|
||||
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(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_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);
|
||||
|
||||
extern nsresult NS_NewRangeList(nsIDOMSelection** aResult);
|
||||
|
@ -380,14 +379,6 @@ nsLayoutFactory::CreateInstance(nsISupports *aOuter,
|
|||
}
|
||||
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)) {
|
||||
res = NS_NewTextEncoder((nsIDocumentEncoder**) &inst);
|
||||
if (NS_FAILED(res)) {
|
||||
|
@ -709,20 +700,34 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
|
|||
LOG_REGISTER_FAILURE("kHTMLElementFactoryCID", rv);
|
||||
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);
|
||||
if (NS_FAILED(rv)) {
|
||||
LOG_REGISTER_FAILURE("kHTMLEncoderCID", rv);
|
||||
LOG_REGISTER_FAILURE(NS_DOC_ENCODER_PROGID_BASE "text/html", rv);
|
||||
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);
|
||||
if (NS_FAILED(rv)) {
|
||||
LOG_REGISTER_FAILURE("kTextEncoderCID", rv);
|
||||
LOG_REGISTER_FAILURE(NS_DOC_ENCODER_PROGID_BASE "text/plain", rv);
|
||||
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);
|
||||
|
||||
servMgr->ReleaseService(kComponentManagerCID, cm);
|
||||
|
@ -767,7 +772,7 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
|
|||
rv = cm->UnregisterComponent(kSubtreeIteratorCID, aPath);
|
||||
rv = cm->UnregisterComponent(kFrameUtilCID, aPath);
|
||||
rv = cm->UnregisterComponent(kLayoutDebuggerCID, aPath);
|
||||
rv = cm->UnregisterComponent(kHTMLEncoderCID, aPath);
|
||||
//rv = cm->UnregisterComponent(kHTMLEncoderCID, aPath);
|
||||
rv = cm->UnregisterComponent(kTextEncoderCID, aPath);
|
||||
|
||||
// XXX why the heck are these exported???? bad bad bad bad
|
||||
|
|
|
@ -193,12 +193,14 @@ void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter)
|
|||
nsICSSRule* rule = nsnull;
|
||||
|
||||
cssSheet->StyleRuleCount(ruleCount);
|
||||
aConverter.BeginCSSStyleSheet();
|
||||
for (ruleIndex = 0; ruleIndex < ruleCount; ruleIndex++)
|
||||
if (ruleCount > 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -218,10 +220,11 @@ void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter)
|
|||
NS_IF_RELEASE(rule);
|
||||
} // ruleAt
|
||||
|
||||
aConverter.EndCSSRule();
|
||||
} // for loop
|
||||
}
|
||||
aConverter.EndCSSStyleSheet();
|
||||
aConverter.EndCSSRule();
|
||||
} // for loop
|
||||
}
|
||||
aConverter.EndCSSStyleSheet();
|
||||
} // if ruleCount > 0
|
||||
NS_RELEASE(cssSheet);
|
||||
} // css_sheet
|
||||
NS_RELEASE(sheet);
|
||||
|
|
|
@ -271,7 +271,8 @@ nsGfxTextControlFrame::GetText(nsString* aText, PRBool aInitialValue)
|
|||
else
|
||||
{
|
||||
if (PR_TRUE==IsInitialized()) {
|
||||
result = mEditor->OutputTextToString(*aText, PR_FALSE);
|
||||
nsString format ("text/html");
|
||||
mEditor->OutputToString(*aText, format, 0);
|
||||
}
|
||||
else {
|
||||
result = nsFormControlHelper::GetInputElementValue(mContent, aText, aInitialValue);
|
||||
|
@ -533,7 +534,8 @@ void nsGfxTextControlFrame::GetTextControlFrameState(nsString& aValue)
|
|||
{
|
||||
aValue = ""; // initialize out param
|
||||
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())
|
||||
{
|
||||
nsAutoString currentValue;
|
||||
nsresult result = mEditor->OutputTextToString(currentValue, PR_FALSE);
|
||||
nsString format ("text/html");
|
||||
nsresult result = mEditor->OutputToString(currentValue, format, 0);
|
||||
if (PR_TRUE==IsSingleLineTextControl()) {
|
||||
RemoveNewlines(currentValue);
|
||||
}
|
||||
|
@ -1284,7 +1287,8 @@ nsGfxTextControlFrame::InternalContentChanged()
|
|||
if (!IsInitialized()) { return NS_ERROR_NOT_INITIALIZED; }
|
||||
nsAutoString textValue;
|
||||
// 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()) {
|
||||
RemoveNewlines(textValue);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "nsIMessage.h" //temporary!
|
||||
#include "nsMsgQuote.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIEditor.h" // for output flags
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsParserCIID.h"
|
||||
|
@ -380,10 +381,16 @@ nsresult nsMsgCompose::SendMsg(MSG_DeliverMode deliverMode,
|
|||
{
|
||||
nsAutoString msgBody;
|
||||
PRUnichar *bodyText = NULL;
|
||||
nsString format;
|
||||
PRUint32 flags = 0;
|
||||
if (m_composeHTML)
|
||||
m_editor->GetContentsAsHTML(&bodyText);
|
||||
format = "text/html";
|
||||
else
|
||||
m_editor->GetContentsAsText(&bodyText);
|
||||
{
|
||||
flags = nsIEditor::EditorOutputFormatted;
|
||||
format = "text/plain";
|
||||
}
|
||||
m_editor->GetContentsAs(format.GetUnicode(), flags, &bodyText);
|
||||
|
||||
msgBody = bodyText;
|
||||
delete [] bodyText;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "nsString.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIHTMLEditor.h"
|
||||
#include "nsITextEditor.h"
|
||||
#include "nsEditorCID.h"
|
||||
|
@ -83,16 +84,21 @@ nsresult NS_InitEditorMode(nsIDOMDocument *aDOMDocument, nsIPresShell* aPresShel
|
|||
static nsresult PrintEditorOutput(nsIHTMLEditor* editor, PRInt32 aCommandID)
|
||||
{
|
||||
nsString outString;
|
||||
char* cString;
|
||||
char* cString;
|
||||
nsString formatString;
|
||||
PRUint32 flags;
|
||||
|
||||
switch (aCommandID)
|
||||
{
|
||||
case VIEWER_DISPLAYTEXT:
|
||||
gEditor->OutputTextToString(outString, PR_FALSE);
|
||||
formatString = "text/plain";
|
||||
flags = nsIEditor::EditorOutputFormatted;
|
||||
gEditor->OutputToString(outString, formatString, flags);
|
||||
break;
|
||||
|
||||
case VIEWER_DISPLAYHTML:
|
||||
gEditor->OutputHTMLToString(outString, PR_FALSE);
|
||||
formatString = "text/html";
|
||||
gEditor->OutputToString(outString, formatString, flags);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче