mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
134439: Make plaintext compose wrap to window width instead of output
width, and don't wrap quotes in <pre> or <span>, to work around various editor bugs. Detect quoted blocks at output time, and continue our existing behavior of not wrapping quoted text. r=jfrancis,bratell, sr=alecf.
This commit is contained in:
parent
678b215e1d
commit
fdc4ae63df
@ -106,6 +106,7 @@ nsPlainTextSerializer::nsPlainTextSerializer()
|
||||
mStructs = PR_TRUE; // will be read from prefs later
|
||||
mHeaderStrategy = 1 /*indent increasingly*/; // ditto
|
||||
mQuotesPreformatted = PR_FALSE; // ditto
|
||||
mDontWrapAnyQuotes = PR_FALSE; // ditto
|
||||
mSpanLevel = 0;
|
||||
for (PRInt32 i = 0; i <= 6; i++) {
|
||||
mHeaderCounter[i] = 0;
|
||||
@ -202,6 +203,14 @@ nsPlainTextSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn,
|
||||
// The quotesPreformatted pref is a temporary measure. See bug 69638.
|
||||
prefs->GetBoolPref("editor.quotesPreformatted", &tempBool);
|
||||
mQuotesPreformatted = tempBool;
|
||||
// DontWrapAnyQuotes is set according to whether plaintext mail
|
||||
// is wrapping to window width -- see bug 134439.
|
||||
// We'll only want this if we're wrapping and formatted.
|
||||
if (mFlags & nsIDocumentEncoder::OutputWrap || mWrapColumn > 0)
|
||||
{
|
||||
prefs->GetBoolPref("mail.compose.wrap_to_window_width", &tempBool);
|
||||
mDontWrapAnyQuotes = tempBool;
|
||||
}
|
||||
}
|
||||
|
||||
// XXX We should let the caller pass this in.
|
||||
@ -1224,7 +1233,6 @@ nsPlainTextSerializer::AddToLine(const PRUnichar * aLineFragment,
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
linelength = mCurrentLine.Length();
|
||||
|
||||
// Wrap?
|
||||
@ -1509,9 +1517,8 @@ nsPlainTextSerializer::Write(const nsAString& aString)
|
||||
// that does normal formatted text. The one for preformatted text calls
|
||||
// Output directly while the other code path goes through AddToLine.
|
||||
if ((mPreFormatted && !mWrapColumn) || IsInPre()
|
||||
|| (!mQuotesPreformatted && mSpanLevel > 0
|
||||
//&& Substring(aString, 0, 1) == NS_LITERAL_STRING(">"))) {
|
||||
&& aString.First() == PRUnichar('>'))) {
|
||||
|| ((((!mQuotesPreformatted && mSpanLevel > 0) || mDontWrapAnyQuotes))
|
||||
&& mEmptyLines >= 0 && aString.First() == PRUnichar('>'))) {
|
||||
// No intelligent wrapping.
|
||||
|
||||
// This mustn't be mixed with intelligent wrapping without clearing
|
||||
|
@ -168,7 +168,18 @@ protected:
|
||||
|
||||
PRPackedBool mInHead;
|
||||
PRPackedBool mAtFirstColumn;
|
||||
PRPackedBool mQuotesPreformatted; // (pref)
|
||||
|
||||
// Handling of quoted text (for mail):
|
||||
// Quotes need to be wrapped differently from non-quoted text,
|
||||
// because quoted text has a few extra characters (e.g. ">> ")
|
||||
// which makes the line length longer.
|
||||
// Mail can represent quotes in different ways: it can wrap
|
||||
// quotes in a <pre> (if editor.quotesPreformatted is set),
|
||||
// or not wrapped in any special tag (if mail.compose.wrap_to_window_width)
|
||||
// or in a <span> (if neither of the above are set).
|
||||
PRPackedBool mQuotesPreformatted; // expect quotes wrapped in <pre>
|
||||
PRPackedBool mDontWrapAnyQuotes; // no special quote markers
|
||||
|
||||
PRPackedBool mStructs; // Output structs (pref)
|
||||
|
||||
PRInt32 mIndent;
|
||||
|
@ -1494,6 +1494,9 @@ NS_IMETHODIMP
|
||||
nsHTMLEditor::InsertAsPlaintextQuotation(const nsAString & aQuotedText,
|
||||
nsIDOMNode **aNodeInserted)
|
||||
{
|
||||
if (mWrapToWindow)
|
||||
return nsPlaintextEditor::InsertAsQuotation(aQuotedText, aNodeInserted);
|
||||
|
||||
nsresult rv;
|
||||
|
||||
// The quotesPreformatted pref is a temporary measure. See bug 69638.
|
||||
@ -1501,7 +1504,7 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAString & aQuotedText,
|
||||
PRBool quotesInPre;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(kPrefServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && prefs)
|
||||
rv = prefs->GetBoolPref("editor.quotesPreformatted", "esInPre);
|
||||
prefs->GetBoolPref("editor.quotesPreformatted", "esInPre);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> preNode;
|
||||
// get selection
|
||||
|
@ -135,6 +135,8 @@ nsPlaintextEditor::nsPlaintextEditor()
|
||||
, mIgnoreSpuriousDragEvent(PR_FALSE)
|
||||
, mRules(nsnull)
|
||||
, mIsComposing(PR_FALSE)
|
||||
, mWrapToWindow(PR_FALSE)
|
||||
, mWrapColumn(0)
|
||||
, mMaxTextLength(-1)
|
||||
, mInitTriggerCounter(0)
|
||||
{
|
||||
@ -1192,41 +1194,15 @@ nsPlaintextEditor::GetBodyStyleContext(nsIStyleContext** aStyleContext)
|
||||
}
|
||||
|
||||
//
|
||||
// Get the wrap width for the root of the document.
|
||||
// Get the wrap width
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsPlaintextEditor::GetWrapWidth(PRInt32 *aWrapColumn)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
if (! aWrapColumn)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aWrapColumn = -1; // default: no wrap
|
||||
|
||||
nsCOMPtr<nsIStyleContext> styleContext;
|
||||
res = GetBodyStyleContext(getter_AddRefs(styleContext));
|
||||
if (NS_FAILED(res)) return res;
|
||||
NS_ASSERTION(styleContext, "styleContext is null!");
|
||||
if (!styleContext) return NS_ERROR_FAILURE;
|
||||
|
||||
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)
|
||||
{
|
||||
const nsStylePosition* stylePosition =
|
||||
(const nsStylePosition*)styleContext->GetStyleData(eStyleStruct_Position);
|
||||
if (stylePosition->mWidth.GetUnit() == eStyleUnit_Chars)
|
||||
*aWrapColumn = stylePosition->mWidth.GetIntValue();
|
||||
else
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
*aWrapColumn = mWrapColumn;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1256,6 +1232,15 @@ nsPlaintextEditor::SetWrapWidth(PRInt32 aWrapColumn)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
mWrapColumn = aWrapColumn;
|
||||
|
||||
// Make sure we're a plaintext editor, otherwise we shouldn't
|
||||
// do the rest of this.
|
||||
PRUint32 flags = 0;
|
||||
GetFlags(&flags);
|
||||
if (!(flags & eEditorPlaintextMask))
|
||||
return NS_OK;
|
||||
|
||||
// Ought to set a style sheet here ...
|
||||
// Probably should keep around an mPlaintextStyleSheet for this purpose.
|
||||
nsCOMPtr<nsIDOMElement> bodyElement;
|
||||
@ -1285,19 +1270,29 @@ nsPlaintextEditor::SetWrapWidth(PRInt32 aWrapColumn)
|
||||
// Make sure we have fixed-width font. This should be done for us,
|
||||
// but it isn't, see bug 22502, so we have to add "font: -moz-fixed;".
|
||||
// Only do this if we're wrapping.
|
||||
PRUint32 flags = 0;
|
||||
GetFlags(&flags);
|
||||
if ((flags & eEditorEnableWrapHackMask) && aWrapColumn >= 0)
|
||||
styleValue.Append(NS_LITERAL_STRING("font-family: -moz-fixed; "));
|
||||
|
||||
// If "mail.compose.wrap_to_window_width" is set, and we're a mail editor,
|
||||
// then remember our wrap width (for output purposes) but set the visual
|
||||
// wrapping to window width.
|
||||
// We may reset mWrapToWindow here, based on the pref's current value.
|
||||
if (flags & eEditorMailMask)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID, &rv));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
prefs->GetBoolPref("mail.compose.wrap_to_window_width", &mWrapToWindow);
|
||||
}
|
||||
|
||||
// and now we're ready to set the new whitespace/wrapping style.
|
||||
if (aWrapColumn > 0) // Wrap to a fixed column
|
||||
if (aWrapColumn > 0 && !mWrapToWindow) // Wrap to a fixed column
|
||||
{
|
||||
styleValue.Append(NS_LITERAL_STRING("white-space: -moz-pre-wrap; width: "));
|
||||
styleValue.AppendInt(aWrapColumn);
|
||||
styleValue.Append(NS_LITERAL_STRING("ch;"));
|
||||
}
|
||||
else if (aWrapColumn == 0)
|
||||
else if (mWrapToWindow || aWrapColumn == 0)
|
||||
styleValue.Append(NS_LITERAL_STRING("white-space: -moz-pre-wrap;"));
|
||||
else
|
||||
styleValue.Append(NS_LITERAL_STRING("white-space: pre;"));
|
||||
|
@ -248,6 +248,8 @@ protected:
|
||||
nsCOMPtr<nsIDOMEventListener> mDragListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mFocusListenerP;
|
||||
PRBool mIsComposing;
|
||||
PRBool mWrapToWindow;
|
||||
PRInt32 mWrapColumn;
|
||||
PRInt32 mMaxTextLength;
|
||||
PRInt32 mInitTriggerCounter;
|
||||
|
||||
|
@ -144,6 +144,7 @@ pref("news.max_articles", 500);
|
||||
pref("news.mark_old_read", false);
|
||||
|
||||
pref("mailnews.wraplength", 72);
|
||||
pref("mail.compose.wrap_to_window_width", true);
|
||||
|
||||
pref("mailnews.reply_on_top", 0); // 0=bottom 1=top 2=select+bottom 3=select+top
|
||||
|
||||
|
@ -144,6 +144,7 @@ pref("news.max_articles", 500);
|
||||
pref("news.mark_old_read", false);
|
||||
|
||||
pref("mailnews.wraplength", 72);
|
||||
pref("mail.compose.wrap_to_window_width", true);
|
||||
|
||||
pref("mailnews.reply_on_top", 0); // 0=bottom 1=top 2=select+bottom 3=select+top
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user