зеркало из https://github.com/mozilla/pjs.git
6276: Add wrapping support for mail.
This commit is contained in:
Родитель
e5a39e72e7
Коммит
74cc74130e
|
@ -63,6 +63,7 @@ CPPSRCS = \
|
|||
TypeInState.cpp \
|
||||
nsInternetCiter.cpp \
|
||||
nsAOLCiter.cpp \
|
||||
nsWrapUtils.cpp \
|
||||
nsInterfaceState.cpp \
|
||||
nsEditorShell.cpp \
|
||||
IMETextTxn.cpp \
|
||||
|
|
|
@ -58,6 +58,7 @@ CPPSRCS = \
|
|||
nsTableEditor.cpp \
|
||||
nsInternetCiter.cpp \
|
||||
nsAOLCiter.cpp \
|
||||
nsWrapUtils.cpp \
|
||||
nsInterfaceState.cpp \
|
||||
nsEditorShell.cpp \
|
||||
IMETextTxn.cpp \
|
||||
|
@ -97,6 +98,7 @@ CPP_OBJS = \
|
|||
.\$(OBJDIR)\nsTableEditor.obj \
|
||||
.\$(OBJDIR)\nsInternetCiter.obj \
|
||||
.\$(OBJDIR)\nsAOLCiter.obj \
|
||||
.\$(OBJDIR)\nsWrapUtils.obj \
|
||||
.\$(OBJDIR)\nsInterfaceState.obj \
|
||||
.\$(OBJDIR)\nsEditorShell.obj \
|
||||
.\$(OBJDIR)\IMETextTxn.obj \
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "nsAOLCiter.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsWrapUtils.h"
|
||||
|
||||
/** Mail citations using the AOL style >> This is a citation <<
|
||||
*/
|
||||
|
@ -85,14 +85,32 @@ nsAOLCiter::GetCiteString(const nsString& aInString, nsString& aOutString)
|
|||
NS_IMETHODIMP
|
||||
nsAOLCiter::StripCites(const nsString& aInString, nsString& aOutString)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
// Remove the beginning cites, if any:
|
||||
if (aInString.EqualsWithConversion(">>", PR_FALSE, 2))
|
||||
{
|
||||
PRInt32 i = 3;
|
||||
while (nsCRT::IsAsciiSpace(aInString[i]))
|
||||
++i;
|
||||
aOutString.Append(aInString, i);
|
||||
}
|
||||
else
|
||||
aOutString = aInString;
|
||||
|
||||
// Remove the end cites, if any:
|
||||
aOutString.Trim("<", PR_FALSE, PR_TRUE, PR_FALSE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAOLCiter::Rewrap(const nsString& aInString,
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
nsString& aOutString)
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
PRBool aRespectNewlines,
|
||||
nsString& aOutString)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
nsString citeString ("");
|
||||
return nsWrapUtils::Rewrap(aInString, aWrapCol, aFirstLineOffset,
|
||||
aRespectNewlines, citeString,
|
||||
aOutString);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
|
||||
NS_IMETHOD Rewrap(const nsString& aInString,
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
PRBool aRespectNewlines,
|
||||
nsString& aOutString);
|
||||
};
|
||||
|
||||
|
|
|
@ -2183,7 +2183,7 @@ static nsICiter* MakeACiter()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::Rewrap()
|
||||
nsEditorShell::Rewrap(PRBool aRespectNewlines)
|
||||
{
|
||||
PRInt32 wrapCol;
|
||||
nsresult rv = GetWrapColumn(&wrapCol);
|
||||
|
@ -2221,7 +2221,7 @@ nsEditorShell::Rewrap()
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
if (!citer) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
rv = citer->Rewrap(current, wrapCol, 0, wrapped);
|
||||
rv = citer->Rewrap(current, wrapCol, 0, aRespectNewlines, wrapped);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SelectAll();
|
||||
|
@ -2241,7 +2241,8 @@ nsEditorShell::Rewrap()
|
|||
if (!citer) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
PRUint32 firstLineOffset = 0; // XXX need to get this
|
||||
rv = citer->Rewrap(current, wrapCol, firstLineOffset, wrapped);
|
||||
rv = citer->Rewrap(current, wrapCol, firstLineOffset, aRespectNewlines,
|
||||
wrapped);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mEditor->InsertText(wrapped);
|
||||
|
|
|
@ -25,9 +25,20 @@
|
|||
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsWrapUtils.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
// Line breaker stuff
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsILineBreakerFactory.h"
|
||||
#include "nsLWBrkCIID.h"
|
||||
|
||||
/** Mail citations using the Internet style >> This is a citation <<
|
||||
*/
|
||||
|
||||
static NS_DEFINE_CID(kLWBrkCID, NS_LWBRK_CID);
|
||||
|
||||
nsInternetCiter::nsInternetCiter()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
@ -86,9 +97,15 @@ nsInternetCiter::GetCiteString(const nsString& aInString, nsString& aOutString)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInternetCiter::StripCites(const nsString& aInString, nsString& aOutString)
|
||||
nsresult
|
||||
nsInternetCiter::StripCitesAndLinebreaks(const nsString& aInString,
|
||||
nsString& aOutString,
|
||||
PRBool aLinebreaksToo,
|
||||
PRInt32* aCiteLevel)
|
||||
{
|
||||
if (aCiteLevel)
|
||||
*aCiteLevel = 0;
|
||||
|
||||
aOutString.SetLength(0);
|
||||
|
||||
PRInt32 length = aInString.Length();
|
||||
|
@ -96,27 +113,66 @@ nsInternetCiter::StripCites(const nsString& aInString, nsString& aOutString)
|
|||
PRUnichar gt ('>');
|
||||
while (i < length) // loop over lines
|
||||
{
|
||||
// Clear out cites first, at the beginning of the line:
|
||||
PRInt32 thisLineCiteLevel = 0;
|
||||
while (aInString[i] == gt || nsCRT::IsAsciiSpace(aInString[i]))
|
||||
{
|
||||
if (aInString[i] == gt) ++thisLineCiteLevel;
|
||||
++i;
|
||||
}
|
||||
|
||||
// Now copy characters until line end:
|
||||
PRInt32 nextNewline = aInString.FindCharInSet("\r\n", i);
|
||||
if (nextNewline > i)
|
||||
{
|
||||
while (i < nextNewline)
|
||||
aOutString += aInString[i++];
|
||||
aOutString += NS_LINEBREAK;
|
||||
aOutString.Append(aInString[i++]);
|
||||
if (aLinebreaksToo)
|
||||
aOutString.Append(' ');
|
||||
else
|
||||
aOutString.Append('\n'); // DOM linebreaks, not NS_LINEBREAK
|
||||
// Skip over any more consecutive linebreak-like characters:
|
||||
while (aOutString[i] == '\r' || aOutString[i] == '\n')
|
||||
++i;
|
||||
}
|
||||
else // no more newlines
|
||||
{
|
||||
while (i < length)
|
||||
aOutString.Append(aInString[i++]);
|
||||
}
|
||||
|
||||
// Done with this line -- update cite level
|
||||
if (aCiteLevel && (thisLineCiteLevel > *aCiteLevel))
|
||||
*aCiteLevel = thisLineCiteLevel;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInternetCiter::Rewrap(const nsString& aInString,
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
nsString& aOutString)
|
||||
nsInternetCiter::StripCites(const nsString& aInString, nsString& aOutString)
|
||||
{
|
||||
printf("nsInternetCiter::Rewrap not yet implemented\n");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return StripCitesAndLinebreaks(aInString, aOutString, PR_FALSE, 0);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInternetCiter::Rewrap(const nsString& aInString,
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
PRBool aRespectNewlines,
|
||||
nsString& aOutString)
|
||||
{
|
||||
PRInt32 i;
|
||||
|
||||
// First, clean up all the existing newlines/cite marks and save the cite level.
|
||||
nsAutoString inString;
|
||||
PRInt32 citeLevel;
|
||||
StripCitesAndLinebreaks(aInString, inString, !aRespectNewlines, &citeLevel);
|
||||
|
||||
nsAutoString citeString;
|
||||
for (i=0; i<citeLevel; ++i)
|
||||
citeString += "> ";
|
||||
|
||||
return nsWrapUtils::Rewrap(inString, aWrapCol, aFirstLineOffset,
|
||||
aRespectNewlines, citeString,
|
||||
aOutString);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include "nsString.h"
|
||||
|
||||
/** Mail citations using the AOL style >> This is a citation <<
|
||||
/** Mail citations using standard Internet style.
|
||||
*/
|
||||
class nsInternetCiter : public nsICiter
|
||||
{
|
||||
|
@ -44,7 +44,12 @@ public:
|
|||
|
||||
NS_IMETHOD Rewrap(const nsString& aInString,
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
PRBool aRespectNewlines,
|
||||
nsString& aOutString);
|
||||
|
||||
protected:
|
||||
nsresult StripCitesAndLinebreaks(const nsString& aInString, nsString& aOutString,
|
||||
PRBool aLinebreaksToo, PRInt32* aCiteLevel);
|
||||
};
|
||||
|
||||
#endif //nsInternetCiter_h__
|
||||
|
|
|
@ -2183,7 +2183,7 @@ static nsICiter* MakeACiter()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::Rewrap()
|
||||
nsEditorShell::Rewrap(PRBool aRespectNewlines)
|
||||
{
|
||||
PRInt32 wrapCol;
|
||||
nsresult rv = GetWrapColumn(&wrapCol);
|
||||
|
@ -2221,7 +2221,7 @@ nsEditorShell::Rewrap()
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
if (!citer) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
rv = citer->Rewrap(current, wrapCol, 0, wrapped);
|
||||
rv = citer->Rewrap(current, wrapCol, 0, aRespectNewlines, wrapped);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SelectAll();
|
||||
|
@ -2241,7 +2241,8 @@ nsEditorShell::Rewrap()
|
|||
if (!citer) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
PRUint32 firstLineOffset = 0; // XXX need to get this
|
||||
rv = citer->Rewrap(current, wrapCol, firstLineOffset, wrapped);
|
||||
rv = citer->Rewrap(current, wrapCol, firstLineOffset, aRespectNewlines,
|
||||
wrapped);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mEditor->InsertText(wrapped);
|
||||
|
|
|
@ -147,7 +147,7 @@ interface nsIEditorShell : nsISupports
|
|||
in boolean insertHTML, in wstring charset,
|
||||
out nsIDOMNode nodeInserted);
|
||||
|
||||
void Rewrap();
|
||||
void Rewrap(in boolean respectNewlines);
|
||||
void StripCites();
|
||||
|
||||
void SelectAll();
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "nsAOLCiter.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsWrapUtils.h"
|
||||
|
||||
/** Mail citations using the AOL style >> This is a citation <<
|
||||
*/
|
||||
|
@ -85,14 +85,32 @@ nsAOLCiter::GetCiteString(const nsString& aInString, nsString& aOutString)
|
|||
NS_IMETHODIMP
|
||||
nsAOLCiter::StripCites(const nsString& aInString, nsString& aOutString)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
// Remove the beginning cites, if any:
|
||||
if (aInString.EqualsWithConversion(">>", PR_FALSE, 2))
|
||||
{
|
||||
PRInt32 i = 3;
|
||||
while (nsCRT::IsAsciiSpace(aInString[i]))
|
||||
++i;
|
||||
aOutString.Append(aInString, i);
|
||||
}
|
||||
else
|
||||
aOutString = aInString;
|
||||
|
||||
// Remove the end cites, if any:
|
||||
aOutString.Trim("<", PR_FALSE, PR_TRUE, PR_FALSE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAOLCiter::Rewrap(const nsString& aInString,
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
nsString& aOutString)
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
PRBool aRespectNewlines,
|
||||
nsString& aOutString)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
nsString citeString ("");
|
||||
return nsWrapUtils::Rewrap(aInString, aWrapCol, aFirstLineOffset,
|
||||
aRespectNewlines, citeString,
|
||||
aOutString);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
|
||||
NS_IMETHOD Rewrap(const nsString& aInString,
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
PRBool aRespectNewlines,
|
||||
nsString& aOutString);
|
||||
};
|
||||
|
||||
|
|
|
@ -25,9 +25,20 @@
|
|||
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsWrapUtils.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
// Line breaker stuff
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsILineBreakerFactory.h"
|
||||
#include "nsLWBrkCIID.h"
|
||||
|
||||
/** Mail citations using the Internet style >> This is a citation <<
|
||||
*/
|
||||
|
||||
static NS_DEFINE_CID(kLWBrkCID, NS_LWBRK_CID);
|
||||
|
||||
nsInternetCiter::nsInternetCiter()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
@ -86,9 +97,15 @@ nsInternetCiter::GetCiteString(const nsString& aInString, nsString& aOutString)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInternetCiter::StripCites(const nsString& aInString, nsString& aOutString)
|
||||
nsresult
|
||||
nsInternetCiter::StripCitesAndLinebreaks(const nsString& aInString,
|
||||
nsString& aOutString,
|
||||
PRBool aLinebreaksToo,
|
||||
PRInt32* aCiteLevel)
|
||||
{
|
||||
if (aCiteLevel)
|
||||
*aCiteLevel = 0;
|
||||
|
||||
aOutString.SetLength(0);
|
||||
|
||||
PRInt32 length = aInString.Length();
|
||||
|
@ -96,27 +113,66 @@ nsInternetCiter::StripCites(const nsString& aInString, nsString& aOutString)
|
|||
PRUnichar gt ('>');
|
||||
while (i < length) // loop over lines
|
||||
{
|
||||
// Clear out cites first, at the beginning of the line:
|
||||
PRInt32 thisLineCiteLevel = 0;
|
||||
while (aInString[i] == gt || nsCRT::IsAsciiSpace(aInString[i]))
|
||||
{
|
||||
if (aInString[i] == gt) ++thisLineCiteLevel;
|
||||
++i;
|
||||
}
|
||||
|
||||
// Now copy characters until line end:
|
||||
PRInt32 nextNewline = aInString.FindCharInSet("\r\n", i);
|
||||
if (nextNewline > i)
|
||||
{
|
||||
while (i < nextNewline)
|
||||
aOutString += aInString[i++];
|
||||
aOutString += NS_LINEBREAK;
|
||||
aOutString.Append(aInString[i++]);
|
||||
if (aLinebreaksToo)
|
||||
aOutString.Append(' ');
|
||||
else
|
||||
aOutString.Append('\n'); // DOM linebreaks, not NS_LINEBREAK
|
||||
// Skip over any more consecutive linebreak-like characters:
|
||||
while (aOutString[i] == '\r' || aOutString[i] == '\n')
|
||||
++i;
|
||||
}
|
||||
else // no more newlines
|
||||
{
|
||||
while (i < length)
|
||||
aOutString.Append(aInString[i++]);
|
||||
}
|
||||
|
||||
// Done with this line -- update cite level
|
||||
if (aCiteLevel && (thisLineCiteLevel > *aCiteLevel))
|
||||
*aCiteLevel = thisLineCiteLevel;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInternetCiter::Rewrap(const nsString& aInString,
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
nsString& aOutString)
|
||||
nsInternetCiter::StripCites(const nsString& aInString, nsString& aOutString)
|
||||
{
|
||||
printf("nsInternetCiter::Rewrap not yet implemented\n");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return StripCitesAndLinebreaks(aInString, aOutString, PR_FALSE, 0);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInternetCiter::Rewrap(const nsString& aInString,
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
PRBool aRespectNewlines,
|
||||
nsString& aOutString)
|
||||
{
|
||||
PRInt32 i;
|
||||
|
||||
// First, clean up all the existing newlines/cite marks and save the cite level.
|
||||
nsAutoString inString;
|
||||
PRInt32 citeLevel;
|
||||
StripCitesAndLinebreaks(aInString, inString, !aRespectNewlines, &citeLevel);
|
||||
|
||||
nsAutoString citeString;
|
||||
for (i=0; i<citeLevel; ++i)
|
||||
citeString += "> ";
|
||||
|
||||
return nsWrapUtils::Rewrap(inString, aWrapCol, aFirstLineOffset,
|
||||
aRespectNewlines, citeString,
|
||||
aOutString);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include "nsString.h"
|
||||
|
||||
/** Mail citations using the AOL style >> This is a citation <<
|
||||
/** Mail citations using standard Internet style.
|
||||
*/
|
||||
class nsInternetCiter : public nsICiter
|
||||
{
|
||||
|
@ -44,7 +44,12 @@ public:
|
|||
|
||||
NS_IMETHOD Rewrap(const nsString& aInString,
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
PRBool aRespectNewlines,
|
||||
nsString& aOutString);
|
||||
|
||||
protected:
|
||||
nsresult StripCitesAndLinebreaks(const nsString& aInString, nsString& aOutString,
|
||||
PRBool aLinebreaksToo, PRInt32* aCiteLevel);
|
||||
};
|
||||
|
||||
#endif //nsInternetCiter_h__
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsICiter_h__
|
||||
#define nsICiter_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsString;
|
||||
|
||||
#define NS_ICITER_IID \
|
||||
{ /* a6cf9102-15b3-11d2-932e-00805f8add32 */ \
|
||||
0xa6cf9102, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
/** Handle plaintext citations, as in mail quoting.
|
||||
* Used by the editor but not dependant on it.
|
||||
*/
|
||||
class nsICiter : public nsISupports
|
||||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_ICITER_IID; return iid; }
|
||||
|
||||
NS_IMETHOD GetCiteString(const nsString& aInString, nsString& aOutString) = 0;
|
||||
|
||||
NS_IMETHOD StripCites(const nsString& aInString, nsString& aOutString) = 0;
|
||||
|
||||
NS_IMETHOD Rewrap(const nsString& aInString,
|
||||
PRUint32 aWrapCol, PRUint32 aFirstLineOffset,
|
||||
nsString& aOutString) = 0;
|
||||
};
|
||||
|
||||
#endif //nsICiter_h__
|
||||
|
|
@ -775,7 +775,7 @@ function EditorApplyStyleSheet(styleSheetURL)
|
|||
accesskey="&editpastequotation.accesskey;"
|
||||
oncommand="EditorPasteAsQuotation()"/>
|
||||
<menuitem value="&editRewrapCmd.label;"
|
||||
oncommand="editorShell.Rewrap()"/>
|
||||
oncommand="editorShell.Rewrap(false)"/>
|
||||
<menuitem value="&editStripQuotesCmd.label;"
|
||||
oncommand="editorShell.StripCites()"/>
|
||||
<menuitem value="&insertTextCmd.label;"
|
||||
|
|
Загрузка…
Ссылка в новой задаче