Bug 63029: Japanese input in text area in forms confuses subsequent input

The fix is to
- maintain the index of PasswordBuf at the start of IME
- maintain the old IME text
- remove the old IME text from PasswordBuf
/r=jfrancis, /sr=kin, /a=blizzard
This commit is contained in:
yokoyama%netscape.com 2001-06-06 01:21:05 +00:00
Родитель af53a2e023
Коммит f2b48ea628
8 изменённых файлов: 120 добавлений и 0 удалений

Просмотреть файл

@ -1073,6 +1073,22 @@ NS_IMETHODIMP nsPlaintextEditor::InsertLineBreak()
return res;
}
NS_IMETHODIMP
nsPlaintextEditor::BeginComposition(nsTextEventReply* aReply)
{
if(mFlags & nsIPlaintextEditor::eEditorPasswordMask) {
if (mRules) {
nsIEditRules *p = mRules.get();
nsTextEditRules *textEditRules = NS_STATIC_CAST(nsTextEditRules *, p);
textEditRules->ResetIMETextPWBuf();
}
else {
return NS_ERROR_NULL_POINTER;
}
}
return nsEditor::BeginComposition(aReply);
}
NS_IMETHODIMP
nsPlaintextEditor::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)

Просмотреть файл

@ -89,6 +89,7 @@ public:
NS_IMETHOD GetReconversionString(nsReconversionEventReply* aReply);
/* ------------ Overrides of nsEditor interface methods -------------- */
NS_IMETHOD BeginComposition(nsTextEventReply* aReply);
/** prepare the editor for use */
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, nsIContent *aRoot, nsISelectionController *aSelCon, PRUint32 aFlags);

Просмотреть файл

@ -75,6 +75,8 @@ NS_NewTextEditRules(nsIEditRules** aInstancePtrResult)
nsTextEditRules::nsTextEditRules()
: mEditor(nsnull)
, mPasswordText()
, mPasswordIMEText()
, mPasswordIMEIndex(0)
, mBogusNode(nsnull)
, mBody(nsnull)
, mFlags(0) // initialized to 0 ("no flags set"). Real initial value is given in Init()
@ -504,6 +506,11 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
// to the replacement character
if (mFlags & nsIPlaintextEditor::eEditorPasswordMask)
{
if (aAction == kInsertTextIME) {
res = RemoveIMETextFromPWBuf(start, outString);
if (NS_FAILED(res)) return res;
}
res = EchoInsertionToPWBuff(start, end, outString);
if (NS_FAILED(res)) return res;
}
@ -1257,6 +1264,34 @@ nsTextEditRules::TruncateInsertionIfNeeded(nsISelection *aSelection,
return res;
}
nsresult
nsTextEditRules::ResetIMETextPWBuf()
{
mPasswordIMEText.SetLength(0);
return NS_OK;
}
nsresult
nsTextEditRules::RemoveIMETextFromPWBuf(PRInt32 &aStart, nsAWritableString *aIMEString)
{
if (!aIMEString) {
return NS_ERROR_NULL_POINTER;
}
// initialize PasswordIME
if (!mPasswordIMEText.Length()) {
mPasswordIMEIndex = aStart;
mPasswordIMEText.Assign(*aIMEString);
return NS_OK;
}
// manage the password buffer
mPasswordText.Cut(mPasswordIMEIndex, mPasswordIMEText.Length());
aStart = mPasswordIMEIndex;
mPasswordIMEText.Assign(*aIMEString);
return NS_OK;
}
nsresult
nsTextEditRules::EchoInsertionToPWBuff(PRInt32 aStart, PRInt32 aEnd, nsAWritableString *aOutString)

Просмотреть файл

@ -85,6 +85,9 @@ public:
kInsertElement = 3008
};
public:
nsresult ResetIMETextPWBuf();
protected:
// nsTextEditRules implementation methods
@ -159,6 +162,9 @@ protected:
insertion text to '*'s */
nsresult EchoInsertionToPWBuff(PRInt32 aStart, PRInt32 aEnd, nsAWritableString *aOutString);
/** Remove IME composition text from password buffer */
nsresult RemoveIMETextFromPWBuf(PRInt32 &aStart, nsAWritableString *aIMEString);
nsresult CreateMozBR(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outBRNode);
PRBool DeleteEmptyTextNode(nsIDOMNode *aNode);
@ -173,6 +179,8 @@ protected:
// data members
nsPlaintextEditor *mEditor; // note that we do not refcount the editor
nsString mPasswordText; // a buffer we use to store the real value of password editors
nsString mPasswordIMEText; // a buffer we use to track the IME composition string
PRInt32 mPasswordIMEIndex;
nsCOMPtr<nsIDOMNode> mBogusNode; // magic node acts as placeholder in empty doc
nsCOMPtr<nsIDOMNode> mBody; // cached root node
PRUint32 mFlags;

Просмотреть файл

@ -1073,6 +1073,22 @@ NS_IMETHODIMP nsPlaintextEditor::InsertLineBreak()
return res;
}
NS_IMETHODIMP
nsPlaintextEditor::BeginComposition(nsTextEventReply* aReply)
{
if(mFlags & nsIPlaintextEditor::eEditorPasswordMask) {
if (mRules) {
nsIEditRules *p = mRules.get();
nsTextEditRules *textEditRules = NS_STATIC_CAST(nsTextEditRules *, p);
textEditRules->ResetIMETextPWBuf();
}
else {
return NS_ERROR_NULL_POINTER;
}
}
return nsEditor::BeginComposition(aReply);
}
NS_IMETHODIMP
nsPlaintextEditor::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)

Просмотреть файл

@ -89,6 +89,7 @@ public:
NS_IMETHOD GetReconversionString(nsReconversionEventReply* aReply);
/* ------------ Overrides of nsEditor interface methods -------------- */
NS_IMETHOD BeginComposition(nsTextEventReply* aReply);
/** prepare the editor for use */
NS_IMETHOD Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell, nsIContent *aRoot, nsISelectionController *aSelCon, PRUint32 aFlags);

Просмотреть файл

@ -75,6 +75,8 @@ NS_NewTextEditRules(nsIEditRules** aInstancePtrResult)
nsTextEditRules::nsTextEditRules()
: mEditor(nsnull)
, mPasswordText()
, mPasswordIMEText()
, mPasswordIMEIndex(0)
, mBogusNode(nsnull)
, mBody(nsnull)
, mFlags(0) // initialized to 0 ("no flags set"). Real initial value is given in Init()
@ -504,6 +506,11 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
// to the replacement character
if (mFlags & nsIPlaintextEditor::eEditorPasswordMask)
{
if (aAction == kInsertTextIME) {
res = RemoveIMETextFromPWBuf(start, outString);
if (NS_FAILED(res)) return res;
}
res = EchoInsertionToPWBuff(start, end, outString);
if (NS_FAILED(res)) return res;
}
@ -1257,6 +1264,34 @@ nsTextEditRules::TruncateInsertionIfNeeded(nsISelection *aSelection,
return res;
}
nsresult
nsTextEditRules::ResetIMETextPWBuf()
{
mPasswordIMEText.SetLength(0);
return NS_OK;
}
nsresult
nsTextEditRules::RemoveIMETextFromPWBuf(PRInt32 &aStart, nsAWritableString *aIMEString)
{
if (!aIMEString) {
return NS_ERROR_NULL_POINTER;
}
// initialize PasswordIME
if (!mPasswordIMEText.Length()) {
mPasswordIMEIndex = aStart;
mPasswordIMEText.Assign(*aIMEString);
return NS_OK;
}
// manage the password buffer
mPasswordText.Cut(mPasswordIMEIndex, mPasswordIMEText.Length());
aStart = mPasswordIMEIndex;
mPasswordIMEText.Assign(*aIMEString);
return NS_OK;
}
nsresult
nsTextEditRules::EchoInsertionToPWBuff(PRInt32 aStart, PRInt32 aEnd, nsAWritableString *aOutString)

Просмотреть файл

@ -85,6 +85,9 @@ public:
kInsertElement = 3008
};
public:
nsresult ResetIMETextPWBuf();
protected:
// nsTextEditRules implementation methods
@ -159,6 +162,9 @@ protected:
insertion text to '*'s */
nsresult EchoInsertionToPWBuff(PRInt32 aStart, PRInt32 aEnd, nsAWritableString *aOutString);
/** Remove IME composition text from password buffer */
nsresult RemoveIMETextFromPWBuf(PRInt32 &aStart, nsAWritableString *aIMEString);
nsresult CreateMozBR(nsIDOMNode *inParent, PRInt32 inOffset, nsCOMPtr<nsIDOMNode> *outBRNode);
PRBool DeleteEmptyTextNode(nsIDOMNode *aNode);
@ -173,6 +179,8 @@ protected:
// data members
nsPlaintextEditor *mEditor; // note that we do not refcount the editor
nsString mPasswordText; // a buffer we use to store the real value of password editors
nsString mPasswordIMEText; // a buffer we use to track the IME composition string
PRInt32 mPasswordIMEIndex;
nsCOMPtr<nsIDOMNode> mBogusNode; // magic node acts as placeholder in empty doc
nsCOMPtr<nsIDOMNode> mBody; // cached root node
PRUint32 mFlags;