33088: restructure editor output routines. r=kin,buster,adamlock sr=sfraser

This commit is contained in:
akkana%netscape.com 2001-01-08 21:01:29 +00:00
parent aa0c15578b
commit d53a276b40
26 changed files with 425 additions and 643 deletions

View File

@ -50,7 +50,7 @@ interface nsISelectionPrivate : nsISupports
void endBatchChanges();
nsIEnumerator getEnumerator();
wstring toStringWithFormat(in string formatType, in unsigned long flags, in PRInt32 wrapCount);
wstring toStringWithFormat(in string formatType, in unsigned long flags, in PRInt32 wrapColumn);
void addSelectionListener(in nsISelectionListener newListener);
void removeSelectionListener(in nsISelectionListener listenerToRemove);

View File

@ -3365,6 +3365,9 @@ NS_IMETHODIMP nsDocument::FindNext(const nsAReadableString& aSearchStr, PRBool a
return NS_ERROR_FAILURE;
}
/**
* nsIDiskDocument methods
*/
NS_IMETHODIMP
nsDocument::InitDiskDocument(nsFileSpec* aFileSpec)
@ -3390,7 +3393,8 @@ nsDocument::SaveFile(nsFileSpec* aFileSpec,
PRBool aSaveCopy,
const nsString& aFormatType,
const nsString& aSaveCharset,
PRUint32 aFlags)
PRUint32 aFlags,
PRUint32 aWrapColumn)
{
if (!aFileSpec)
return NS_ERROR_NULL_POINTER;
@ -3429,6 +3433,9 @@ nsDocument::SaveFile(nsFileSpec* aFileSpec,
if (NS_FAILED(rv))
return rv;
if (aFlags & nsIDocumentEncoder::OutputWrap)
encoder->SetWrapColumn(aWrapColumn);
nsAutoString charsetStr(aSaveCharset);
if (charsetStr.Length() == 0)
{

View File

@ -417,7 +417,8 @@ public:
PRBool aSaveCopy,
const nsString& aSaveFileType,
const nsString& aSaveCharset,
PRUint32 aFlags);
PRUint32 aFlags,
PRUint32 aWrapColumn);
NS_IMETHOD GetFileSpec(nsFileSpec& aFileSpec);
NS_IMETHOD GetModCount(PRInt32 *outModCount);

View File

@ -1583,6 +1583,24 @@ nsEditor::SetDocumentCharacterSet(const PRUnichar* characterSet)
return rv;
}
//
// Get an appropriate wrap width for saving this document.
// This class just uses a pref; subclasses are expected to
// override if they know more about the document.
//
NS_IMETHODIMP
nsEditor::GetWrapWidth(PRInt32 *aWrapColumn)
{
NS_ENSURE_ARG_POINTER(aWrapColumn);
*aWrapColumn = 72;
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && prefs)
(void) prefs->GetIntPref("editor.htmlWrapColumn", aWrapColumn);
return NS_OK;
}
NS_IMETHODIMP
nsEditor::SaveFile(nsFileSpec *aFileSpec, PRBool aReplaceExisting,
PRBool aSaveCopy, const nsString& aFormat)
@ -1613,10 +1631,11 @@ nsEditor::SaveFile(nsFileSpec *aFileSpec, PRBool aReplaceExisting,
flags |= nsIDocumentEncoder::OutputFormatted;
}
PRInt32 wrapColumn = 72;
GetWrapWidth(&wrapColumn);
nsAutoString useDocCharset;
rv = diskDoc->SaveFile(aFileSpec, aReplaceExisting, aSaveCopy,
aFormat, useDocCharset, flags);
aFormat, useDocCharset, flags, wrapColumn);
if (NS_SUCCEEDED(rv))
DoAfterDocumentSave();
@ -2328,10 +2347,11 @@ NS_IMETHODIMP nsEditor::OutputToString(nsAWritableString& aOutputString,
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsEditor::OutputToStream(nsIOutputStream* aOutputStream,
const nsString& aFormatType,
const nsString* aCharsetOverride,
PRUint32 aFlags)
NS_IMETHODIMP
nsEditor::OutputToStream(nsIOutputStream* aOutputStream,
const nsAReadableString& aFormatType,
const nsAReadableString* aCharsetOverride,
PRUint32 aFlags)
{
// these should be implemented by derived classes.
return NS_ERROR_NOT_IMPLEMENTED;

View File

@ -302,8 +302,8 @@ public:
PRUint32 aFlags);
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
const nsString& aFormatType,
const nsString* aCharsetOverride,
const nsAReadableString& aFormatType,
const nsAReadableString* aCharsetOverride,
PRUint32 aFlags);
/* Listeners */
@ -489,7 +489,10 @@ protected:
/** make the given selection span the entire document */
NS_IMETHOD SelectEntireDocument(nsISelection *aSelection);
/* Helper for output routines -- we expect subclasses to override this */
NS_IMETHOD GetWrapWidth(PRInt32* aWrapCol);
protected:
// XXXX: Horrible hack! We are doing this because
// of an error in Gecko which is not rendering the

View File

@ -3276,7 +3276,7 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
if (textEditor)
{
PRInt32 wc;
err = textEditor->GetBodyWrapWidth(&wc);
err = textEditor->GetWrapWidth(&wc);
if (NS_SUCCEEDED(err))
*aWrapColumn = (PRInt32)wc;
}
@ -3304,7 +3304,7 @@ nsEditorShell::SetWrapColumn(PRInt32 aWrapColumn)
{
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
err = textEditor->SetBodyWrapWidth(mWrapColumn);
err = textEditor->SetWrapWidth(mWrapColumn);
}
break;
default:

View File

@ -4933,10 +4933,10 @@ nsHTMLEditor::GetBodyStyleContext(nsIStyleContext** aStyleContext)
}
//
// Get the wrap width for the first PRE tag in the document.
// If no PRE tag, throw an error.
// Get an appropriate wrap width for saving this document.
//
NS_IMETHODIMP nsHTMLEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
NS_IMETHODIMP
nsHTMLEditor::GetWrapWidth(PRInt32 *aWrapColumn)
{
nsresult res;
@ -4945,33 +4945,46 @@ NS_IMETHODIMP nsHTMLEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
*aWrapColumn = -1; // default: no wrap
nsCOMPtr<nsIStyleContext> styleContext;
res = GetBodyStyleContext(getter_AddRefs(styleContext));
if (NS_FAILED(res)) return res;
// Don't wrap output of text fields
if (mFlags & eEditorSingleLineMask)
return NS_OK;
const nsStyleText* styleText =
(const nsStyleText*)styleContext->GetStyleData(eStyleStruct_Text);
if (NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace)
*aWrapColumn = 0; // wrap to window width
else if (NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace)
if (mFlags & eEditorPlaintextMask)
{
const nsStylePosition* stylePosition =
(const nsStylePosition*)styleContext->GetStyleData(eStyleStruct_Position);
if (stylePosition->mWidth.GetUnit() == eStyleUnit_Chars)
*aWrapColumn = stylePosition->mWidth.GetIntValue();
else {
nsCOMPtr<nsIStyleContext> styleContext;
res = GetBodyStyleContext(getter_AddRefs(styleContext));
if (NS_SUCCEEDED(res) && styleContext)
{
const nsStyleText* styleText =
(const nsStyleText*)styleContext->GetStyleData(eStyleStruct_Text);
if (NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace)
{
*aWrapColumn = 0; // wrap to window width
return NS_OK;
}
else if (NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace)
{
const nsStylePosition* stylePosition =
(const nsStylePosition*)styleContext->GetStyleData(eStyleStruct_Position);
if (stylePosition->mWidth.GetUnit() == eStyleUnit_Chars)
{
*aWrapColumn = stylePosition->mWidth.GetIntValue();
return NS_OK;
}
#ifdef DEBUG_akkana
printf("Can't get wrap column: style unit is %d\n",
stylePosition->mWidth.GetUnit());
else
printf("Can't get wrap column: style unit is %d\n",
stylePosition->mWidth.GetUnit());
#endif
*aWrapColumn = -1;
return NS_ERROR_UNEXPECTED;
}
}
}
else
*aWrapColumn = -1;
return NS_OK;
// If we get here, we weren't able to get the wrap column from style,
// or we aren't plaintext so we don't expect to.
// So fall back on nsEditor (which uses a pref).
return nsEditor::GetWrapWidth(aWrapColumn);
}
//
@ -4998,7 +5011,7 @@ static void CutStyle(const char* stylename, nsString& styleValue)
// interspersed quoted text blocks.)
// Alternately: Change the wrap width on the editor style sheet.
//
NS_IMETHODIMP nsHTMLEditor::SetBodyWrapWidth(PRInt32 aWrapColumn)
NS_IMETHODIMP nsHTMLEditor::SetWrapWidth(PRInt32 aWrapColumn)
{
nsresult res;
@ -6163,10 +6176,100 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText,
return res;
}
NS_IMETHODIMP nsHTMLEditor::OutputToString(nsAWritableString& aOutputString,
const nsAReadableString& aFormatType,
PRUint32 aFlags)
// Shared between OutputToString and OutputToStream
NS_IMETHODIMP
nsHTMLEditor::GetAndInitDocEncoder(const nsAReadableString& aFormatType,
PRUint32 aFlags,
const nsAReadableString* aCharset,
nsIDocumentEncoder** encoder)
{
nsCOMPtr<nsIPresShell> presShell;
nsresult rv = GetPresShell(getter_AddRefs(presShell));
if (NS_FAILED(rv)) return rv;
if (!presShell) return NS_ERROR_FAILURE;
nsCAutoString formatType(NS_DOC_ENCODER_CONTRACTID_BASE);
formatType.AppendWithConversion(aFormatType);
nsCOMPtr<nsIDocumentEncoder> docEncoder (do_CreateInstance(formatType, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocument> doc;
rv = presShell->GetDocument(getter_AddRefs(doc));
NS_ENSURE_SUCCESS(rv, rv);
rv = docEncoder->Init(doc, aFormatType, aFlags);
NS_ENSURE_SUCCESS(rv, rv);
if (aCharset && aCharset->Length() != 0
&& !(aCharset->Equals(NS_LITERAL_STRING("null"))))
docEncoder->SetCharset(*aCharset);
PRInt32 wc;
(void) GetWrapWidth(&wc);
if (wc >= 0)
(void) docEncoder->SetWrapColumn(wc);
// Set the selection, if appropriate.
// We do this either if the OutputSelectionOnly flag is set,
// in which case we use our existing selection ...
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
nsCOMPtr<nsISelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
rv = docEncoder->SetSelection(selection);
NS_ENSURE_SUCCESS(rv, rv);
}
// ... or if the root element is not a body,
// in which case we set the selection to encompass the root.
else
{
nsCOMPtr<nsIDOMElement> rootElement;
GetRootElement(getter_AddRefs(rootElement));
NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
if (!nsHTMLEditUtils::IsBody(rootElement))
{
// XXX Why does this use range rather than selection collapse/extend?
nsCOMPtr<nsIDOMRange> range (do_CreateInstance(kCRangeCID, &rv));
if (NS_FAILED(rv)) return rv;
if (!range) return NS_ERROR_FAILURE;
nsCOMPtr<nsISelection> selection (do_CreateInstance(kCDOMSelectionCID,
&rv));
if (NS_FAILED(rv)) return rv;
if (!selection) return NS_ERROR_FAILURE;
// get the independent selection interface
nsCOMPtr<nsIIndependentSelection> indSel = do_QueryInterface(selection);
if (indSel)
indSel->SetPresShell(presShell);
nsCOMPtr<nsIContent> content(do_QueryInterface(rootElement));
if (content)
{
range->SetStart(rootElement,0);
PRInt32 children;
if (NS_SUCCEEDED(content->ChildCount(children)))
range->SetEnd(rootElement,children);
// XXX else, should we return the error code?
if (NS_FAILED(selection->AddRange(range)))
return NS_ERROR_FAILURE;
}
rv = docEncoder->SetSelection(selection);
NS_ENSURE_SUCCESS(rv, rv);
}
}
NS_ADDREF(*encoder = docEncoder);
return rv;
}
NS_IMETHODIMP
nsHTMLEditor::OutputToString(nsAWritableString& aOutputString,
const nsAReadableString& aFormatType,
PRUint32 aFlags)
{
// XXX Why isn't this rules stuff also in OutputToStream?
PRBool cancel, handled;
nsString resultString;
nsTextRulesInfo ruleInfo(nsTextEditRules::kOutputText);
@ -6179,226 +6282,29 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsAWritableString& aOutputString,
if (handled)
{ // this case will get triggered by password fields
aOutputString.Assign(*(ruleInfo.outString));
}
else
{
nsCOMPtr<nsISelection> selection;
// 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.
PRInt32 wrapColumn;
PRUint32 wc =0;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
if (wrapColumn != 0)
{
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
}
}
nsCOMPtr<nsIDOMElement> rootElement;
GetRootElement(getter_AddRefs(rootElement));
NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
//is this a body?? do we want to output the whole doc?
// Set the selection, if appropriate:
nsCOMPtr<nsISelectionPrivate> selPriv;
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
rv = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(rv))
return rv;
selPriv = do_QueryInterface(selection);
}
else if (nsHTMLEditUtils::IsBody(rootElement))
{
nsCOMPtr<nsIDocumentEncoder> encoder;
nsCAutoString formatType(NS_DOC_ENCODER_CONTRACTID_BASE);
formatType.AppendWithConversion(aFormatType);
rv = nsComponentManager::CreateInstance((char*)formatType,
nsnull,
NS_GET_IID(nsIDocumentEncoder),
getter_AddRefs(encoder));
NS_ENSURE_SUCCESS(rv, rv);
if (!mPresShellWeak)
return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
if (!ps)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> doc;
rv = ps->GetDocument(getter_AddRefs(doc));
NS_ENSURE_SUCCESS(rv, rv);
rv = encoder->Init(doc, aFormatType, aFlags);
NS_ENSURE_SUCCESS(rv, rv);
if (wc != 0)
encoder->SetWrapColumn(wc);
return encoder->EncodeToString(aOutputString);
}
if (!selection)
{
nsCOMPtr<nsIDOMRange> range;
rv = nsComponentManager::CreateInstance(kCRangeCID,
nsnull,
NS_GET_IID(nsIDOMRange),
getter_AddRefs(range));
if (!range)
return NS_ERROR_FAILURE;
rv = nsComponentManager::CreateInstance(kCDOMSelectionCID,
nsnull,
NS_GET_IID(nsISelection),
getter_AddRefs(selection));
if (selection)
{
selPriv = do_QueryInterface(selection);
//get the independent selection interface
nsCOMPtr<nsIIndependentSelection> indSel = do_QueryInterface(selection);
if (indSel)
{
nsCOMPtr<nsIPresShell> presShell;
if (NS_SUCCEEDED(GetPresShell(getter_AddRefs(presShell))) && presShell)
indSel->SetPresShell(presShell);
}
nsCOMPtr<nsIContent> content(do_QueryInterface(rootElement));
if (content)
{
range->SetStart(rootElement,0);
PRInt32 children;
if (NS_SUCCEEDED(content->ChildCount(children)))
{
range->SetEnd(rootElement,children);
}
if (NS_FAILED(selection->AddRange(range)))
return NS_ERROR_FAILURE;
}
}
}
PRUnichar *tmp;
char *tmpformattype= ToNewCString(aFormatType);//crap copied string
if (!tmpformattype)
return NS_ERROR_NULL_POINTER;
rv = selPriv->ToStringWithFormat(tmpformattype, aFlags, wc, &tmp);
if (NS_SUCCEEDED(rv) && tmp)
{
nsMemory::Free(tmpformattype);
aOutputString.Assign(tmp);
nsMemory::Free(tmp);
}
return rv;
}
#if 0
PRBool cancel, handled;
nsString resultString;
nsTextRulesInfo ruleInfo(nsTextEditRules::kOutputText);
ruleInfo.outString = &resultString;
ruleInfo.outputFormat = &aFormatType;
nsresult rv = mRules->WillDoAction(nsnull, &ruleInfo, &cancel, &handled);
if (cancel || NS_FAILED(rv)) { return rv; }
if (handled)
{ // this case will get triggered by password fields
aOutputString = *(ruleInfo.outString);
}
else
{ // default processing
rv = NS_OK;
// special-case for empty document when requesting plain text,
// to account for the bogus text node
if (aFormatType.EqualsWithConversion("text/plain"))
{
PRBool docEmpty;
rv = GetDocumentIsEmpty(&docEmpty);
if (NS_FAILED(rv)) return rv;
if (docEmpty) {
aOutputString.SetLength(0);
return NS_OK;
}
else if (mFlags & eEditorPlaintextMask)
aFlags |= nsIDocumentEncoder::OutputPreformatted;
}
nsCOMPtr<nsIDocumentEncoder> encoder;
char* contractid = (char *)nsMemory::Alloc(strlen(NS_DOC_ENCODER_CONTRACTID_BASE) + aFormatType.Length() + 1);
if (! contractid)
return NS_ERROR_OUT_OF_MEMORY;
strcpy(contractid, NS_DOC_ENCODER_CONTRACTID_BASE);
char* type = aFormatType.ToNewCString();
strcat(contractid, type);
nsCRT::free(type);
rv = nsComponentManager::CreateInstance(contractid,
nsnull,
NS_GET_IID(nsIDocumentEncoder),
getter_AddRefs(encoder));
nsCRT::free(contractid);
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);
rv = encoder->Init(doc, aFormatType, aFlags);
if (NS_FAILED(rv))
return rv;
// Set the selection, if appropriate:
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
nsCOMPtr<nsISelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
encoder->SetSelection(selection);
}
// 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.
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
if (wrapColumn != 0)
{
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
}
rv = encoder->EncodeToString(aOutputString);
}
#endif
nsCOMPtr<nsIDocumentEncoder> encoder;
rv = GetAndInitDocEncoder(aFormatType, aFlags, 0, getter_AddRefs(encoder));
if (NS_FAILED(rv))
return rv;
rv = encoder->EncodeToString(aOutputString);
return rv;
}
NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
const nsString& aFormatType,
const nsString* aCharset,
PRUint32 aFlags)
NS_IMETHODIMP
nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
const nsAReadableString& aFormatType,
const nsAReadableString* aCharset,
PRUint32 aFlags)
{
nsresult rv;
// special-case for empty document when requesting plain text,
// to account for the bogus text node
if (aFormatType.EqualsWithConversion("text/plain"))
// to account for the bogus text node.
// XXX Should there be a similar test in OutputToString?
if (aFormatType == NS_LITERAL_STRING("text/plain"))
{
PRBool docEmpty;
rv = GetDocumentIsEmpty(&docEmpty);
@ -6409,65 +6315,11 @@ NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
}
nsCOMPtr<nsIDocumentEncoder> encoder;
char* contractid = (char *)nsMemory::Alloc(strlen(NS_DOC_ENCODER_CONTRACTID_BASE) + aFormatType.Length() + 1);
if (! contractid)
return NS_ERROR_OUT_OF_MEMORY;
rv = GetAndInitDocEncoder(aFormatType, aFlags, aCharset,
getter_AddRefs(encoder));
strcpy(contractid, NS_DOC_ENCODER_CONTRACTID_BASE);
char* type = aFormatType.ToNewCString();
strcat(contractid, type);
nsCRT::free(type);
rv = nsComponentManager::CreateInstance(contractid,
nsnull,
NS_GET_IID(nsIDocumentEncoder),
getter_AddRefs(encoder));
nsCRT::free(contractid);
if (NS_FAILED(rv))
{
printf("Couldn't get contractid %s\n", contractid);
return rv;
}
nsCOMPtr<nsIDOMDocument> domdoc;
rv = GetDocument(getter_AddRefs(domdoc));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
if (aCharset && aCharset->Length() != 0 && aCharset->EqualsWithConversion("null")==PR_FALSE)
encoder->SetCharset(*aCharset);
rv = encoder->Init(doc, aFormatType, aFlags);
if (NS_FAILED(rv))
return rv;
// Set the selection, if appropriate:
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
nsCOMPtr<nsISelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
encoder->SetSelection(selection);
}
// 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.
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
if (wrapColumn != 0)
{
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
}
return encoder->EncodeToStream(aOutputStream);
}

View File

@ -45,6 +45,7 @@ class nsIDOMKeyEvent;
class nsITransferable;
class nsIDOMEventReceiver;
class nsIDOMNSRange;
class nsIDocumentEncoder;
/**
* The HTML editor implementation.<br>
@ -270,8 +271,8 @@ public:
PRUint32 aFlags);
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
const nsString& aFormatType,
const nsString* aCharsetOverride,
const nsAReadableString& aFormatType,
const nsAReadableString* aCharsetOverride,
PRUint32 aFlags);
NS_IMETHOD GetHeadContentsAsHTML(nsString& aOutputString);
@ -490,6 +491,11 @@ protected:
PRInt32 aEndOffset,
nsISelection *aSelection);
// Helpers for output routines
NS_IMETHOD GetAndInitDocEncoder(const nsAReadableString& aFormatType,
PRUint32 aFlags,
const nsAReadableString* aCharset,
nsIDocumentEncoder** encoder);
// Methods for handling plaintext quotations
NS_IMETHOD PasteAsPlaintextQuotation(PRInt32 aSelectionType);

View File

@ -170,9 +170,10 @@ nsTextEditRules::SetFlags(PRUint32 aFlags)
if (!alreadyPlaintext && willBePlaintext)
{
// Call the editor's SetBodyWrapWidth(), which will
// Call the editor's SetWrapWidth(), which will
// set the styles appropriately for plaintext:
mEditor->SetBodyWrapWidth(72);
// XXX This shouldn't be hardcoded! Why is this here?
mEditor->SetWrapWidth(72);
}
return NS_OK;

View File

@ -3276,7 +3276,7 @@ nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
if (textEditor)
{
PRInt32 wc;
err = textEditor->GetBodyWrapWidth(&wc);
err = textEditor->GetWrapWidth(&wc);
if (NS_SUCCEEDED(err))
*aWrapColumn = (PRInt32)wc;
}
@ -3304,7 +3304,7 @@ nsEditorShell::SetWrapColumn(PRInt32 aWrapColumn)
{
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(mEditor);
if (textEditor)
err = textEditor->SetBodyWrapWidth(mWrapColumn);
err = textEditor->SetWrapWidth(mWrapColumn);
}
break;
default:

View File

@ -46,9 +46,8 @@ interface nsIPlaintextEditor : nsISupports
* Special values:
* 0 = wrap to window width
* -1 = no wrap at all
*
*/
attribute long bodyWrapWidth;
attribute long wrapWidth;
/**
* EditorKeyPress consumes a keyevent.

View File

@ -1583,6 +1583,24 @@ nsEditor::SetDocumentCharacterSet(const PRUnichar* characterSet)
return rv;
}
//
// Get an appropriate wrap width for saving this document.
// This class just uses a pref; subclasses are expected to
// override if they know more about the document.
//
NS_IMETHODIMP
nsEditor::GetWrapWidth(PRInt32 *aWrapColumn)
{
NS_ENSURE_ARG_POINTER(aWrapColumn);
*aWrapColumn = 72;
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && prefs)
(void) prefs->GetIntPref("editor.htmlWrapColumn", aWrapColumn);
return NS_OK;
}
NS_IMETHODIMP
nsEditor::SaveFile(nsFileSpec *aFileSpec, PRBool aReplaceExisting,
PRBool aSaveCopy, const nsString& aFormat)
@ -1613,10 +1631,11 @@ nsEditor::SaveFile(nsFileSpec *aFileSpec, PRBool aReplaceExisting,
flags |= nsIDocumentEncoder::OutputFormatted;
}
PRInt32 wrapColumn = 72;
GetWrapWidth(&wrapColumn);
nsAutoString useDocCharset;
rv = diskDoc->SaveFile(aFileSpec, aReplaceExisting, aSaveCopy,
aFormat, useDocCharset, flags);
aFormat, useDocCharset, flags, wrapColumn);
if (NS_SUCCEEDED(rv))
DoAfterDocumentSave();
@ -2328,10 +2347,11 @@ NS_IMETHODIMP nsEditor::OutputToString(nsAWritableString& aOutputString,
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsEditor::OutputToStream(nsIOutputStream* aOutputStream,
const nsString& aFormatType,
const nsString* aCharsetOverride,
PRUint32 aFlags)
NS_IMETHODIMP
nsEditor::OutputToStream(nsIOutputStream* aOutputStream,
const nsAReadableString& aFormatType,
const nsAReadableString* aCharsetOverride,
PRUint32 aFlags)
{
// these should be implemented by derived classes.
return NS_ERROR_NOT_IMPLEMENTED;

View File

@ -302,8 +302,8 @@ public:
PRUint32 aFlags);
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
const nsString& aFormatType,
const nsString* aCharsetOverride,
const nsAReadableString& aFormatType,
const nsAReadableString* aCharsetOverride,
PRUint32 aFlags);
/* Listeners */
@ -489,7 +489,10 @@ protected:
/** make the given selection span the entire document */
NS_IMETHOD SelectEntireDocument(nsISelection *aSelection);
/* Helper for output routines -- we expect subclasses to override this */
NS_IMETHOD GetWrapWidth(PRInt32* aWrapCol);
protected:
// XXXX: Horrible hack! We are doing this because
// of an error in Gecko which is not rendering the

View File

@ -4933,10 +4933,10 @@ nsHTMLEditor::GetBodyStyleContext(nsIStyleContext** aStyleContext)
}
//
// Get the wrap width for the first PRE tag in the document.
// If no PRE tag, throw an error.
// Get an appropriate wrap width for saving this document.
//
NS_IMETHODIMP nsHTMLEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
NS_IMETHODIMP
nsHTMLEditor::GetWrapWidth(PRInt32 *aWrapColumn)
{
nsresult res;
@ -4945,33 +4945,46 @@ NS_IMETHODIMP nsHTMLEditor::GetBodyWrapWidth(PRInt32 *aWrapColumn)
*aWrapColumn = -1; // default: no wrap
nsCOMPtr<nsIStyleContext> styleContext;
res = GetBodyStyleContext(getter_AddRefs(styleContext));
if (NS_FAILED(res)) return res;
// Don't wrap output of text fields
if (mFlags & eEditorSingleLineMask)
return NS_OK;
const nsStyleText* styleText =
(const nsStyleText*)styleContext->GetStyleData(eStyleStruct_Text);
if (NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace)
*aWrapColumn = 0; // wrap to window width
else if (NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace)
if (mFlags & eEditorPlaintextMask)
{
const nsStylePosition* stylePosition =
(const nsStylePosition*)styleContext->GetStyleData(eStyleStruct_Position);
if (stylePosition->mWidth.GetUnit() == eStyleUnit_Chars)
*aWrapColumn = stylePosition->mWidth.GetIntValue();
else {
nsCOMPtr<nsIStyleContext> styleContext;
res = GetBodyStyleContext(getter_AddRefs(styleContext));
if (NS_SUCCEEDED(res) && styleContext)
{
const nsStyleText* styleText =
(const nsStyleText*)styleContext->GetStyleData(eStyleStruct_Text);
if (NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace)
{
*aWrapColumn = 0; // wrap to window width
return NS_OK;
}
else if (NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace)
{
const nsStylePosition* stylePosition =
(const nsStylePosition*)styleContext->GetStyleData(eStyleStruct_Position);
if (stylePosition->mWidth.GetUnit() == eStyleUnit_Chars)
{
*aWrapColumn = stylePosition->mWidth.GetIntValue();
return NS_OK;
}
#ifdef DEBUG_akkana
printf("Can't get wrap column: style unit is %d\n",
stylePosition->mWidth.GetUnit());
else
printf("Can't get wrap column: style unit is %d\n",
stylePosition->mWidth.GetUnit());
#endif
*aWrapColumn = -1;
return NS_ERROR_UNEXPECTED;
}
}
}
else
*aWrapColumn = -1;
return NS_OK;
// If we get here, we weren't able to get the wrap column from style,
// or we aren't plaintext so we don't expect to.
// So fall back on nsEditor (which uses a pref).
return nsEditor::GetWrapWidth(aWrapColumn);
}
//
@ -4998,7 +5011,7 @@ static void CutStyle(const char* stylename, nsString& styleValue)
// interspersed quoted text blocks.)
// Alternately: Change the wrap width on the editor style sheet.
//
NS_IMETHODIMP nsHTMLEditor::SetBodyWrapWidth(PRInt32 aWrapColumn)
NS_IMETHODIMP nsHTMLEditor::SetWrapWidth(PRInt32 aWrapColumn)
{
nsresult res;
@ -6163,10 +6176,100 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsString& aQuotedText,
return res;
}
NS_IMETHODIMP nsHTMLEditor::OutputToString(nsAWritableString& aOutputString,
const nsAReadableString& aFormatType,
PRUint32 aFlags)
// Shared between OutputToString and OutputToStream
NS_IMETHODIMP
nsHTMLEditor::GetAndInitDocEncoder(const nsAReadableString& aFormatType,
PRUint32 aFlags,
const nsAReadableString* aCharset,
nsIDocumentEncoder** encoder)
{
nsCOMPtr<nsIPresShell> presShell;
nsresult rv = GetPresShell(getter_AddRefs(presShell));
if (NS_FAILED(rv)) return rv;
if (!presShell) return NS_ERROR_FAILURE;
nsCAutoString formatType(NS_DOC_ENCODER_CONTRACTID_BASE);
formatType.AppendWithConversion(aFormatType);
nsCOMPtr<nsIDocumentEncoder> docEncoder (do_CreateInstance(formatType, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocument> doc;
rv = presShell->GetDocument(getter_AddRefs(doc));
NS_ENSURE_SUCCESS(rv, rv);
rv = docEncoder->Init(doc, aFormatType, aFlags);
NS_ENSURE_SUCCESS(rv, rv);
if (aCharset && aCharset->Length() != 0
&& !(aCharset->Equals(NS_LITERAL_STRING("null"))))
docEncoder->SetCharset(*aCharset);
PRInt32 wc;
(void) GetWrapWidth(&wc);
if (wc >= 0)
(void) docEncoder->SetWrapColumn(wc);
// Set the selection, if appropriate.
// We do this either if the OutputSelectionOnly flag is set,
// in which case we use our existing selection ...
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
nsCOMPtr<nsISelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
rv = docEncoder->SetSelection(selection);
NS_ENSURE_SUCCESS(rv, rv);
}
// ... or if the root element is not a body,
// in which case we set the selection to encompass the root.
else
{
nsCOMPtr<nsIDOMElement> rootElement;
GetRootElement(getter_AddRefs(rootElement));
NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
if (!nsHTMLEditUtils::IsBody(rootElement))
{
// XXX Why does this use range rather than selection collapse/extend?
nsCOMPtr<nsIDOMRange> range (do_CreateInstance(kCRangeCID, &rv));
if (NS_FAILED(rv)) return rv;
if (!range) return NS_ERROR_FAILURE;
nsCOMPtr<nsISelection> selection (do_CreateInstance(kCDOMSelectionCID,
&rv));
if (NS_FAILED(rv)) return rv;
if (!selection) return NS_ERROR_FAILURE;
// get the independent selection interface
nsCOMPtr<nsIIndependentSelection> indSel = do_QueryInterface(selection);
if (indSel)
indSel->SetPresShell(presShell);
nsCOMPtr<nsIContent> content(do_QueryInterface(rootElement));
if (content)
{
range->SetStart(rootElement,0);
PRInt32 children;
if (NS_SUCCEEDED(content->ChildCount(children)))
range->SetEnd(rootElement,children);
// XXX else, should we return the error code?
if (NS_FAILED(selection->AddRange(range)))
return NS_ERROR_FAILURE;
}
rv = docEncoder->SetSelection(selection);
NS_ENSURE_SUCCESS(rv, rv);
}
}
NS_ADDREF(*encoder = docEncoder);
return rv;
}
NS_IMETHODIMP
nsHTMLEditor::OutputToString(nsAWritableString& aOutputString,
const nsAReadableString& aFormatType,
PRUint32 aFlags)
{
// XXX Why isn't this rules stuff also in OutputToStream?
PRBool cancel, handled;
nsString resultString;
nsTextRulesInfo ruleInfo(nsTextEditRules::kOutputText);
@ -6179,226 +6282,29 @@ NS_IMETHODIMP nsHTMLEditor::OutputToString(nsAWritableString& aOutputString,
if (handled)
{ // this case will get triggered by password fields
aOutputString.Assign(*(ruleInfo.outString));
}
else
{
nsCOMPtr<nsISelection> selection;
// 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.
PRInt32 wrapColumn;
PRUint32 wc =0;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
if (wrapColumn != 0)
{
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
}
}
nsCOMPtr<nsIDOMElement> rootElement;
GetRootElement(getter_AddRefs(rootElement));
NS_ENSURE_TRUE(rootElement, NS_ERROR_FAILURE);
//is this a body?? do we want to output the whole doc?
// Set the selection, if appropriate:
nsCOMPtr<nsISelectionPrivate> selPriv;
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
rv = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(rv))
return rv;
selPriv = do_QueryInterface(selection);
}
else if (nsHTMLEditUtils::IsBody(rootElement))
{
nsCOMPtr<nsIDocumentEncoder> encoder;
nsCAutoString formatType(NS_DOC_ENCODER_CONTRACTID_BASE);
formatType.AppendWithConversion(aFormatType);
rv = nsComponentManager::CreateInstance((char*)formatType,
nsnull,
NS_GET_IID(nsIDocumentEncoder),
getter_AddRefs(encoder));
NS_ENSURE_SUCCESS(rv, rv);
if (!mPresShellWeak)
return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
if (!ps)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> doc;
rv = ps->GetDocument(getter_AddRefs(doc));
NS_ENSURE_SUCCESS(rv, rv);
rv = encoder->Init(doc, aFormatType, aFlags);
NS_ENSURE_SUCCESS(rv, rv);
if (wc != 0)
encoder->SetWrapColumn(wc);
return encoder->EncodeToString(aOutputString);
}
if (!selection)
{
nsCOMPtr<nsIDOMRange> range;
rv = nsComponentManager::CreateInstance(kCRangeCID,
nsnull,
NS_GET_IID(nsIDOMRange),
getter_AddRefs(range));
if (!range)
return NS_ERROR_FAILURE;
rv = nsComponentManager::CreateInstance(kCDOMSelectionCID,
nsnull,
NS_GET_IID(nsISelection),
getter_AddRefs(selection));
if (selection)
{
selPriv = do_QueryInterface(selection);
//get the independent selection interface
nsCOMPtr<nsIIndependentSelection> indSel = do_QueryInterface(selection);
if (indSel)
{
nsCOMPtr<nsIPresShell> presShell;
if (NS_SUCCEEDED(GetPresShell(getter_AddRefs(presShell))) && presShell)
indSel->SetPresShell(presShell);
}
nsCOMPtr<nsIContent> content(do_QueryInterface(rootElement));
if (content)
{
range->SetStart(rootElement,0);
PRInt32 children;
if (NS_SUCCEEDED(content->ChildCount(children)))
{
range->SetEnd(rootElement,children);
}
if (NS_FAILED(selection->AddRange(range)))
return NS_ERROR_FAILURE;
}
}
}
PRUnichar *tmp;
char *tmpformattype= ToNewCString(aFormatType);//crap copied string
if (!tmpformattype)
return NS_ERROR_NULL_POINTER;
rv = selPriv->ToStringWithFormat(tmpformattype, aFlags, wc, &tmp);
if (NS_SUCCEEDED(rv) && tmp)
{
nsMemory::Free(tmpformattype);
aOutputString.Assign(tmp);
nsMemory::Free(tmp);
}
return rv;
}
#if 0
PRBool cancel, handled;
nsString resultString;
nsTextRulesInfo ruleInfo(nsTextEditRules::kOutputText);
ruleInfo.outString = &resultString;
ruleInfo.outputFormat = &aFormatType;
nsresult rv = mRules->WillDoAction(nsnull, &ruleInfo, &cancel, &handled);
if (cancel || NS_FAILED(rv)) { return rv; }
if (handled)
{ // this case will get triggered by password fields
aOutputString = *(ruleInfo.outString);
}
else
{ // default processing
rv = NS_OK;
// special-case for empty document when requesting plain text,
// to account for the bogus text node
if (aFormatType.EqualsWithConversion("text/plain"))
{
PRBool docEmpty;
rv = GetDocumentIsEmpty(&docEmpty);
if (NS_FAILED(rv)) return rv;
if (docEmpty) {
aOutputString.SetLength(0);
return NS_OK;
}
else if (mFlags & eEditorPlaintextMask)
aFlags |= nsIDocumentEncoder::OutputPreformatted;
}
nsCOMPtr<nsIDocumentEncoder> encoder;
char* contractid = (char *)nsMemory::Alloc(strlen(NS_DOC_ENCODER_CONTRACTID_BASE) + aFormatType.Length() + 1);
if (! contractid)
return NS_ERROR_OUT_OF_MEMORY;
strcpy(contractid, NS_DOC_ENCODER_CONTRACTID_BASE);
char* type = aFormatType.ToNewCString();
strcat(contractid, type);
nsCRT::free(type);
rv = nsComponentManager::CreateInstance(contractid,
nsnull,
NS_GET_IID(nsIDocumentEncoder),
getter_AddRefs(encoder));
nsCRT::free(contractid);
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);
rv = encoder->Init(doc, aFormatType, aFlags);
if (NS_FAILED(rv))
return rv;
// Set the selection, if appropriate:
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
nsCOMPtr<nsISelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
encoder->SetSelection(selection);
}
// 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.
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
if (wrapColumn != 0)
{
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
}
rv = encoder->EncodeToString(aOutputString);
}
#endif
nsCOMPtr<nsIDocumentEncoder> encoder;
rv = GetAndInitDocEncoder(aFormatType, aFlags, 0, getter_AddRefs(encoder));
if (NS_FAILED(rv))
return rv;
rv = encoder->EncodeToString(aOutputString);
return rv;
}
NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
const nsString& aFormatType,
const nsString* aCharset,
PRUint32 aFlags)
NS_IMETHODIMP
nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
const nsAReadableString& aFormatType,
const nsAReadableString* aCharset,
PRUint32 aFlags)
{
nsresult rv;
// special-case for empty document when requesting plain text,
// to account for the bogus text node
if (aFormatType.EqualsWithConversion("text/plain"))
// to account for the bogus text node.
// XXX Should there be a similar test in OutputToString?
if (aFormatType == NS_LITERAL_STRING("text/plain"))
{
PRBool docEmpty;
rv = GetDocumentIsEmpty(&docEmpty);
@ -6409,65 +6315,11 @@ NS_IMETHODIMP nsHTMLEditor::OutputToStream(nsIOutputStream* aOutputStream,
}
nsCOMPtr<nsIDocumentEncoder> encoder;
char* contractid = (char *)nsMemory::Alloc(strlen(NS_DOC_ENCODER_CONTRACTID_BASE) + aFormatType.Length() + 1);
if (! contractid)
return NS_ERROR_OUT_OF_MEMORY;
rv = GetAndInitDocEncoder(aFormatType, aFlags, aCharset,
getter_AddRefs(encoder));
strcpy(contractid, NS_DOC_ENCODER_CONTRACTID_BASE);
char* type = aFormatType.ToNewCString();
strcat(contractid, type);
nsCRT::free(type);
rv = nsComponentManager::CreateInstance(contractid,
nsnull,
NS_GET_IID(nsIDocumentEncoder),
getter_AddRefs(encoder));
nsCRT::free(contractid);
if (NS_FAILED(rv))
{
printf("Couldn't get contractid %s\n", contractid);
return rv;
}
nsCOMPtr<nsIDOMDocument> domdoc;
rv = GetDocument(getter_AddRefs(domdoc));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
if (aCharset && aCharset->Length() != 0 && aCharset->EqualsWithConversion("null")==PR_FALSE)
encoder->SetCharset(*aCharset);
rv = encoder->Init(doc, aFormatType, aFlags);
if (NS_FAILED(rv))
return rv;
// Set the selection, if appropriate:
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly)
{
nsCOMPtr<nsISelection> selection;
rv = GetSelection(getter_AddRefs(selection));
if (NS_SUCCEEDED(rv) && selection)
encoder->SetSelection(selection);
}
// 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.
PRInt32 wrapColumn;
if (NS_SUCCEEDED(GetBodyWrapWidth(&wrapColumn)))
{
if (wrapColumn != 0)
{
PRUint32 wc;
if (wrapColumn < 0)
wc = 0;
else
wc = (PRUint32)wrapColumn;
if (wrapColumn > 0)
(void)encoder->SetWrapColumn(wc);
}
}
return encoder->EncodeToStream(aOutputStream);
}

View File

@ -45,6 +45,7 @@ class nsIDOMKeyEvent;
class nsITransferable;
class nsIDOMEventReceiver;
class nsIDOMNSRange;
class nsIDocumentEncoder;
/**
* The HTML editor implementation.<br>
@ -270,8 +271,8 @@ public:
PRUint32 aFlags);
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
const nsString& aFormatType,
const nsString* aCharsetOverride,
const nsAReadableString& aFormatType,
const nsAReadableString* aCharsetOverride,
PRUint32 aFlags);
NS_IMETHOD GetHeadContentsAsHTML(nsString& aOutputString);
@ -490,6 +491,11 @@ protected:
PRInt32 aEndOffset,
nsISelection *aSelection);
// Helpers for output routines
NS_IMETHOD GetAndInitDocEncoder(const nsAReadableString& aFormatType,
PRUint32 aFlags,
const nsAReadableString* aCharset,
nsIDocumentEncoder** encoder);
// Methods for handling plaintext quotations
NS_IMETHOD PasteAsPlaintextQuotation(PRInt32 aSelectionType);

View File

@ -170,9 +170,10 @@ nsTextEditRules::SetFlags(PRUint32 aFlags)
if (!alreadyPlaintext && willBePlaintext)
{
// Call the editor's SetBodyWrapWidth(), which will
// Call the editor's SetWrapWidth(), which will
// set the styles appropriately for plaintext:
mEditor->SetBodyWrapWidth(72);
// XXX This shouldn't be hardcoded! Why is this here?
mEditor->SetWrapWidth(72);
}
return NS_OK;

View File

@ -428,8 +428,8 @@ public:
const nsAReadableString& aFormatType,
PRUint32 aFlags) = 0;
NS_IMETHOD OutputToStream(nsIOutputStream* aOutputStream,
const nsString& aFormatType,
const nsString* aCharsetOverride,
const nsAReadableString& aFormatType,
const nsAReadableString* aCharsetOverride,
PRUint32 aFlags) = 0;

View File

@ -43,6 +43,8 @@ pref("editor.table.delete_key", 0);
pref("editor.prettyprint", true);
pref("editor.htmlWrapColumn", 72);
pref("editor.throbber.url","chrome://editor/locale/editor.properties");
pref("editor.auto_save", false);

View File

@ -325,7 +325,7 @@ NS_IMETHODIMP nsWebBrowserPersist::SaveDocument(nsIDOMDocument *aDocument, const
PR_TRUE, /* save as a copy */
contentType,
charType,
0);
0, 72);
}
OnEndDownload();

View File

@ -34,11 +34,8 @@
/**
* This interface is used to save documents to disk (and other
* output devices, like network streams one day).
*
* It should be implemented by classes that need to save
* documents, like the editor and browser windows.
* This interface is used to associate a document with a disk file,
* and to save to that file.
*
*/
@ -75,15 +72,17 @@ public:
* referenced internally.
* @param inSaveFileType Mime type to save (text/plain or text/html)
* @param inSaveCharset Charset to save the document in. If this is an empty
* string, or "UCS2", then the doc will be saved as Unicode.
* string, or "UCS2", then the doc will be saved in the document's default charset.
* @param inSaveFlags Flags (see nsIDocumentEncoder). If unsure, use 0.
* @param inWrapColumn Wrap column, assuming that flags specify wrapping.
*/
NS_IMETHOD SaveFile( nsFileSpec* inFileSpec,
PRBool inReplaceExisting,
PRBool inSaveCopy,
const nsString& inSaveFileType,
const nsString& inSaveCharset,
PRUint32 inSaveFlags)=0;
PRUint32 inSaveFlags,
PRUint32 inWrapColumn)=0;
/** Return a file spec for the file. If the file has not been saved yet,
* and thus has no fileSpec, this will return NS_ERROR_NOT_INITIALIZED.

View File

@ -50,7 +50,7 @@ interface nsISelectionPrivate : nsISupports
void endBatchChanges();
nsIEnumerator getEnumerator();
wstring toStringWithFormat(in string formatType, in unsigned long flags, in PRInt32 wrapCount);
wstring toStringWithFormat(in string formatType, in unsigned long flags, in PRInt32 wrapColumn);
void addSelectionListener(in nsISelectionListener newListener);
void removeSelectionListener(in nsISelectionListener listenerToRemove);

View File

@ -3365,6 +3365,9 @@ NS_IMETHODIMP nsDocument::FindNext(const nsAReadableString& aSearchStr, PRBool a
return NS_ERROR_FAILURE;
}
/**
* nsIDiskDocument methods
*/
NS_IMETHODIMP
nsDocument::InitDiskDocument(nsFileSpec* aFileSpec)
@ -3390,7 +3393,8 @@ nsDocument::SaveFile(nsFileSpec* aFileSpec,
PRBool aSaveCopy,
const nsString& aFormatType,
const nsString& aSaveCharset,
PRUint32 aFlags)
PRUint32 aFlags,
PRUint32 aWrapColumn)
{
if (!aFileSpec)
return NS_ERROR_NULL_POINTER;
@ -3429,6 +3433,9 @@ nsDocument::SaveFile(nsFileSpec* aFileSpec,
if (NS_FAILED(rv))
return rv;
if (aFlags & nsIDocumentEncoder::OutputWrap)
encoder->SetWrapColumn(aWrapColumn);
nsAutoString charsetStr(aSaveCharset);
if (charsetStr.Length() == 0)
{

View File

@ -417,7 +417,8 @@ public:
PRBool aSaveCopy,
const nsString& aSaveFileType,
const nsString& aSaveCharset,
PRUint32 aFlags);
PRUint32 aFlags,
PRUint32 aWrapColumn);
NS_IMETHOD GetFileSpec(nsFileSpec& aFileSpec);
NS_IMETHOD GetModCount(PRInt32 *outModCount);

View File

@ -3351,7 +3351,7 @@ nsGfxTextControlFrame::InitializeTextControl(nsIPresShell *aPresShell, nsIDOMDoc
PRBool wrapToContainerWidth = PR_TRUE;
if (PR_TRUE==IsSingleLineTextControl())
{ // no wrapping for single line text controls
result = mailEditor->SetBodyWrapWidth(-1);
result = mailEditor->SetWrapWidth(-1);
wrapToContainerWidth = PR_FALSE;
}
else
@ -3362,25 +3362,25 @@ nsGfxTextControlFrame::InitializeTextControl(nsIPresShell *aPresShell, nsIDOMDoc
{
if (wrapProp == nsFormControlHelper::eHTMLTextWrap_Off)
{
result = mailEditor->SetBodyWrapWidth(-1);
result = mailEditor->SetWrapWidth(-1);
wrapToContainerWidth = PR_FALSE;
}
if (wrapProp == nsFormControlHelper::eHTMLTextWrap_Hard)
{
PRInt32 widthInCharacters = GetWidthInCharacters();
result = mailEditor->SetBodyWrapWidth(widthInCharacters);
result = mailEditor->SetWrapWidth(widthInCharacters);
wrapToContainerWidth = PR_FALSE;
}
} else {
result = mailEditor->SetBodyWrapWidth(-1);
result = mailEditor->SetWrapWidth(-1);
wrapToContainerWidth = PR_FALSE;
}
}
if (PR_TRUE==wrapToContainerWidth)
{ // if we didn't set wrapping explicitly, turn on default wrapping here
result = mailEditor->SetBodyWrapWidth(0);
result = mailEditor->SetWrapWidth(0);
}
NS_ASSERTION((NS_SUCCEEDED(result)), "error setting body wrap width");
NS_ASSERTION((NS_SUCCEEDED(result)), "error setting wrap width");
if (NS_FAILED(result)) { return result; }
}

View File

@ -1880,7 +1880,7 @@ nsGfxTextControlFrame2::CreateAnonymousContent(nsIPresContext* aPresContext,
col = ((colAttr.GetUnit() == eHTMLUnit_Pixel) ? colAttr.GetPixelValue() : colAttr.GetIntValue());
col = (col <= 0) ? 1 : col; // XXX why a default of 1 char, why hide it
}
textEditor->SetBodyWrapWidth(col);
textEditor->SetWrapWidth(col);
delete spec;
}

View File

@ -43,6 +43,8 @@ pref("editor.table.delete_key", 0);
pref("editor.prettyprint", true);
pref("editor.htmlWrapColumn", 72);
pref("editor.throbber.url","chrome://editor/locale/editor.properties");
pref("editor.auto_save", false);