зеркало из https://github.com/mozilla/gecko-dev.git
Fix for bug 101599: onChange fires when hitting return in text widgets
Modified nsTextInputListener::KeyPress() so that the return key fires and onChange event if the contents of the text control has changed, and it is a single line text control. mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h r=glazman@netscape.com sr=sfraser@netscape.com
This commit is contained in:
Родитель
4b6b331717
Коммит
29d7d2190b
|
@ -312,19 +312,32 @@ nsTextInputListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
|||
if(dispatchStopped)
|
||||
return NS_OK;
|
||||
}
|
||||
PRUint32 keyCode;
|
||||
keyEvent->GetKeyCode(&keyCode);
|
||||
if (nsIDOMKeyEvent::DOM_VK_RETURN==keyCode
|
||||
|| nsIDOMKeyEvent::DOM_VK_ENTER==keyCode)
|
||||
|
||||
if (mFrame && mFrame->IsSingleLineTextControl())
|
||||
{
|
||||
if (mFrame)
|
||||
mFrame->CallOnChange();
|
||||
if (mFrame)//we must recheck frame since callonchange may cause a deletion of this frame!
|
||||
PRUint32 keyCode;
|
||||
keyEvent->GetKeyCode(&keyCode);
|
||||
|
||||
if (nsIDOMKeyEvent::DOM_VK_RETURN==keyCode ||
|
||||
nsIDOMKeyEvent::DOM_VK_ENTER==keyCode)
|
||||
{
|
||||
nsAutoString blurValue;
|
||||
mFrame->GetText(&blurValue,PR_FALSE);
|
||||
mFocusedValue = blurValue;
|
||||
mFrame->SubmitAttempt();
|
||||
nsAutoString curValue;
|
||||
mFrame->GetText(&curValue,PR_FALSE);
|
||||
|
||||
// If the text control's contents have changed, fire
|
||||
// off an onChange().
|
||||
|
||||
if (!mFocusedValue.Equals(curValue))
|
||||
{
|
||||
mFocusedValue = curValue;
|
||||
mFrame->CallOnChange();
|
||||
}
|
||||
|
||||
// Now try to submit the form. Be sure to check mFrame again
|
||||
// since CallOnChange() may have caused the deletion of mFrame.
|
||||
|
||||
if (mFrame)
|
||||
mFrame->SubmitAttempt();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
|
|
@ -180,6 +180,9 @@ public: //for methods who access nsGfxTextControlFrame2 directly
|
|||
void SubmitAttempt();
|
||||
NS_IMETHOD InternalContentChanged();//notify that we have some kind of change.
|
||||
NS_IMETHOD CallOnChange();
|
||||
virtual PRBool IsSingleLineTextControl() const;
|
||||
virtual PRBool IsPlainTextControl() const;
|
||||
virtual PRBool IsPasswordTextControl() const;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -192,9 +195,6 @@ protected:
|
|||
NS_IMETHOD DoesAttributeExist(nsIAtom *aAtt);
|
||||
|
||||
//helper methods
|
||||
virtual PRBool IsSingleLineTextControl() const;
|
||||
virtual PRBool IsPlainTextControl() const;
|
||||
virtual PRBool IsPasswordTextControl() const;
|
||||
nsresult GetSizeFromContent(PRInt32* aSize) const;
|
||||
PRInt32 GetDefaultColumnWidth() const { return (PRInt32)(20); } // this was DEFAULT_PIXEL_WIDTH
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче