mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Changed:
nsI*Editor::OutputText(nsString& aOutputString); nsI*Editor::OutputHTML(nsString& aOutputString); These methods always returns back a Unicode version of whatever is in the content model. It is the responsibility of the caller then to call whatever converter is required to convert to the appropriate charset. Added: nsI*Editor::OutputText(nsIOutputStream* aOutputStream, nsString* aCharsetOverride = nsnull) nsI*Editor::OutputHTML(nsIOutputStream* aOutputStream, nsString* aCharsetOverride = nsnull) These methods output the the current content model to aOutputStream. The document is encoded using the document defined charset or if the user passes in a non-null value for aCharsetOverride then this encoding overrides the encoding used by the document.
This commit is contained in:
parent
b9a1437db0
commit
860a8b9cfa
@ -62,6 +62,7 @@
|
||||
#include "SplitElementTxn.h"
|
||||
#include "JoinElementTxn.h"
|
||||
|
||||
#include "nsIStringStream.h"
|
||||
|
||||
#define HACK_FORCE_REDRAW 1
|
||||
|
||||
|
@ -350,6 +350,17 @@ NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsString& aOutputString)
|
||||
return nsTextEditor::OutputHTML(aOutputString);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::OutputText(nsIOutputStream* aOutputStream, nsString* aCharsetOverride)
|
||||
{
|
||||
return nsTextEditor::OutputText(aOutputStream,aCharsetOverride);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsIOutputStream* aOutputStream,nsString* aCharsetOverride)
|
||||
{
|
||||
return nsTextEditor::OutputHTML(aOutputStream,aCharsetOverride);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
|
||||
{
|
||||
|
@ -95,6 +95,8 @@ public:
|
||||
NS_IMETHOD Insert(nsString& aInputString);
|
||||
NS_IMETHOD OutputText(nsString& aOutputString);
|
||||
NS_IMETHOD OutputHTML(nsString& aOutputString);
|
||||
NS_IMETHOD OutputText(nsIOutputStream* aOutputStream,nsString* aCharsetOverride = nsnull);
|
||||
NS_IMETHOD OutputHTML(nsIOutputStream* aOutputStream,nsString* aCharsetOverride = nsnull);
|
||||
|
||||
// End of methods implemented in nsEditor
|
||||
//=============================================================
|
||||
@ -166,6 +168,8 @@ protected:
|
||||
// nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
|
||||
// nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //nsHTMLEditor_h__
|
||||
|
@ -58,21 +58,12 @@
|
||||
#include "PlaceholderTxn.h"
|
||||
#include "InsertTextTxn.h"
|
||||
|
||||
#include "nsIFileStream.h"
|
||||
#include "nsIStringStream.h"
|
||||
|
||||
|
||||
class nsIFrame;
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include <strstream.h>
|
||||
#endif
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
#ifdef XP_PC
|
||||
#include <strstrea.h>
|
||||
#endif
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
@ -100,6 +91,9 @@ static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
||||
static NS_DEFINE_IID(kIDOMRangeIID, NS_IDOMRANGE_IID);
|
||||
static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID);
|
||||
|
||||
static NS_DEFINE_IID(kIInputStreamIID, NS_IINPUTSTREAM_IID);
|
||||
static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gNoisy = PR_FALSE;
|
||||
#else
|
||||
@ -953,45 +947,19 @@ NS_IMETHODIMP nsTextEditor::Insert(nsString& aInputString)
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
#ifdef XP_MAC
|
||||
static void WriteFromStringstream(stringstream& aIn, nsString& aOutputString)
|
||||
{
|
||||
string theString = aIn.str();
|
||||
|
||||
aOutputString.SetLength(0); // empty the string
|
||||
aOutputString += theString.data();
|
||||
aOutputString.SetLength(theString.length()); // make sure it's terminated
|
||||
|
||||
/* relace LF with CR. Don't do this here, because strings passed out
|
||||
to JavaScript need LF termination.
|
||||
PRUnichar lineFeed = '\n';
|
||||
PRUnichar carriageReturn = '\r';
|
||||
aOutputString.ReplaceChar(lineFeed, carriageReturn);
|
||||
*/
|
||||
}
|
||||
#else
|
||||
static void WriteFromOstrstream(ostrstream& aIn, nsString& aOutputString)
|
||||
{
|
||||
char* strData = aIn.str(); // get a copy of the buffer (unterminated)
|
||||
|
||||
aOutputString.SetLength(0); // empty the string
|
||||
aOutputString += strData;
|
||||
aOutputString.SetLength(aIn.pcount()); // terminate
|
||||
|
||||
// in ostrstreams if you call the str() function
|
||||
// then you are responsible for deleting the string
|
||||
delete [] strData;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::OutputText(nsString& aOutputString)
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
stringstream outStream;
|
||||
#else
|
||||
ostrstream outStream;
|
||||
#endif
|
||||
return OutputText(nsnull,&aOutputString,nsnull);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::OutputText(nsIOutputStream* aOutputStream, nsString* aCharsetOverride)
|
||||
{
|
||||
return OutputText(aOutputStream,nsnull,aCharsetOverride);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::OutputText(nsIOutputStream* aOutputStream, nsString* aOutputString, nsString* aCharsetOverride)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
nsIPresShell* shell = nsnull;
|
||||
|
||||
@ -1019,53 +987,55 @@ NS_IMETHODIMP nsTextEditor::OutputText(nsString& aOutputString)
|
||||
kCParserIID,
|
||||
(void **)&parser);
|
||||
|
||||
if (NS_OK == rv) {
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsIHTMLContentSink* sink = nsnull;
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
|
||||
if (aOutputString != nsnull)
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink,aOutputString);
|
||||
else if (aOutputStream != nsnull)
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink,aOutputStream,aCharsetOverride);
|
||||
|
||||
rv = NS_New_HTMLToTXT_SinkStream(&sink);
|
||||
if (NS_OK == rv) {
|
||||
// what't this cast doing here, Greg?
|
||||
((nsHTMLContentSinkStream*)sink)->SetOutputStream(outStream);
|
||||
|
||||
if (NS_OK == rv) {
|
||||
parser->SetContentSink(sink);
|
||||
|
||||
parser->SetDocumentCharset(charset, kCharsetFromPreviousLoading);
|
||||
|
||||
nsIDTD* dtd = nsnull;
|
||||
if (sink && NS_SUCCEEDED(rv))
|
||||
{
|
||||
parser->SetContentSink(sink);
|
||||
parser->SetDocumentCharset(charset, kCharsetFromPreviousLoading);
|
||||
nsIDTD* dtd = nsnull;
|
||||
rv = NS_NewXIFDTD(&dtd);
|
||||
if (NS_OK == rv) {
|
||||
parser->RegisterDTD(dtd);
|
||||
parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE);
|
||||
}
|
||||
#ifdef XP_MAC
|
||||
WriteFromStringstream(outStream, aOutputString);
|
||||
#else
|
||||
WriteFromOstrstream(outStream, aOutputString);
|
||||
#endif
|
||||
|
||||
NS_IF_RELEASE(dtd);
|
||||
NS_IF_RELEASE(sink);
|
||||
NS_IF_RELEASE(parser);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(parser);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::OutputHTML(nsString& aOutputString)
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
stringstream outStream;
|
||||
#else
|
||||
ostrstream outStream;
|
||||
#endif
|
||||
return OutputHTML(nsnull,&aOutputString,nsnull);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::OutputHTML(nsIOutputStream* aOutputStream,nsString* aCharsetOverride)
|
||||
{
|
||||
return OutputHTML(aOutputStream,nsnull,aCharsetOverride);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsTextEditor::OutputHTML(nsIOutputStream* aOutputStream, nsString* aOutputString, nsString* aCharsetOverride)
|
||||
{
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
nsIPresShell* shell = nsnull;
|
||||
@ -1097,10 +1067,12 @@ NS_IMETHODIMP nsTextEditor::OutputHTML(nsString& aOutputString)
|
||||
if (NS_OK == rv) {
|
||||
nsIHTMLContentSink* sink = nsnull;
|
||||
|
||||
rv = NS_New_HTML_ContentSinkStream(&sink);
|
||||
if (aOutputStream)
|
||||
rv = NS_New_HTML_ContentSinkStream(&sink,aOutputStream,aCharsetOverride);
|
||||
else if (aOutputString)
|
||||
rv = NS_New_HTML_ContentSinkStream(&sink,aOutputString);
|
||||
|
||||
if (NS_OK == rv) {
|
||||
((nsHTMLContentSinkStream*)sink)->SetOutputStream(outStream);
|
||||
if (sink && NS_SUCCEEDED(rv)) {
|
||||
|
||||
if (NS_OK == rv) {
|
||||
parser->SetContentSink(sink);
|
||||
@ -1113,11 +1085,6 @@ NS_IMETHODIMP nsTextEditor::OutputHTML(nsString& aOutputString)
|
||||
parser->RegisterDTD(dtd);
|
||||
parser->Parse(buffer, 0, "text/xif",PR_FALSE,PR_TRUE);
|
||||
}
|
||||
#ifdef XP_MAC
|
||||
WriteFromStringstream(outStream, aOutputString);
|
||||
#else
|
||||
WriteFromOstrstream(outStream, aOutputString);
|
||||
#endif
|
||||
NS_IF_RELEASE(dtd);
|
||||
NS_IF_RELEASE(sink);
|
||||
}
|
||||
|
@ -98,6 +98,8 @@ public:
|
||||
NS_IMETHOD Insert(nsString& aInputString);
|
||||
NS_IMETHOD OutputText(nsString& aOutputString);
|
||||
NS_IMETHOD OutputHTML(nsString& aOutputString);
|
||||
NS_IMETHOD OutputText(nsIOutputStream* aOutputStream, nsString* aCharsetOverride);
|
||||
NS_IMETHOD OutputHTML(nsIOutputStream* aOutputStream, nsString* aCharsetOverride);
|
||||
|
||||
// End of methods implemented in nsEditor
|
||||
//=============================================================
|
||||
@ -268,7 +270,10 @@ protected:
|
||||
const nsString *aAttribute,
|
||||
const nsString *aValue);
|
||||
|
||||
|
||||
TypeInState *GetTypeInState();
|
||||
NS_IMETHOD OutputText(nsIOutputStream* aOutputStream, nsString* aOutputString, nsString* aCharsetOverride);
|
||||
NS_IMETHOD OutputHTML(nsIOutputStream* aOutputStream, nsString* aOutputString, nsString* aCharsetOverride);
|
||||
|
||||
|
||||
// Data members
|
||||
|
@ -62,6 +62,7 @@
|
||||
#include "SplitElementTxn.h"
|
||||
#include "JoinElementTxn.h"
|
||||
|
||||
#include "nsIStringStream.h"
|
||||
|
||||
#define HACK_FORCE_REDRAW 1
|
||||
|
||||
|
@ -350,6 +350,17 @@ NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsString& aOutputString)
|
||||
return nsTextEditor::OutputHTML(aOutputString);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::OutputText(nsIOutputStream* aOutputStream, nsString* aCharsetOverride)
|
||||
{
|
||||
return nsTextEditor::OutputText(aOutputStream,aCharsetOverride);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::OutputHTML(nsIOutputStream* aOutputStream,nsString* aCharsetOverride)
|
||||
{
|
||||
return nsTextEditor::OutputHTML(aOutputStream,aCharsetOverride);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::CopyAttributes(nsIDOMNode *aDestNode, nsIDOMNode *aSourceNode)
|
||||
{
|
||||
|
@ -95,6 +95,8 @@ public:
|
||||
NS_IMETHOD Insert(nsString& aInputString);
|
||||
NS_IMETHOD OutputText(nsString& aOutputString);
|
||||
NS_IMETHOD OutputHTML(nsString& aOutputString);
|
||||
NS_IMETHOD OutputText(nsIOutputStream* aOutputStream,nsString* aCharsetOverride = nsnull);
|
||||
NS_IMETHOD OutputHTML(nsIOutputStream* aOutputStream,nsString* aCharsetOverride = nsnull);
|
||||
|
||||
// End of methods implemented in nsEditor
|
||||
//=============================================================
|
||||
@ -166,6 +168,8 @@ protected:
|
||||
// nsCOMPtr<nsIDOMEventListener> mKeyListenerP;
|
||||
// nsCOMPtr<nsIDOMEventListener> mMouseListenerP;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //nsHTMLEditor_h__
|
||||
|
Loading…
Reference in New Issue
Block a user