From e2f9b9dd68cc2b732db424d71204267cdac12c1f Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Wed, 5 Jul 2006 22:15:01 +0000 Subject: [PATCH] Fixing bug 313337. Make input control onchange events only fire when the change is made by the user, not by script. r=bzbarsky@mit.edu, sr=bugmail@sicking.cc git-svn-id: svn://10.0.0.236/trunk@201614 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/forms/nsTextControlFrame.cpp | 11 +++++++++++ mozilla/layout/forms/nsTextControlFrame.h | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp index aa589b351fc..8598a95a8eb 100644 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ b/mozilla/layout/forms/nsTextControlFrame.cpp @@ -315,6 +315,8 @@ nsTextInputListener::Focus(nsIDOMEvent* aEvent) editor->AddEditorObserver(this); } + mFrame->SetHasFocus(PR_TRUE); + return mFrame->InitFocusedValue(); } @@ -330,6 +332,8 @@ nsTextInputListener::Blur(nsIDOMEvent* aEvent) editor->RemoveEditorObserver(this); } + mFrame->SetHasFocus(PR_FALSE); + return mFrame->CheckFireOnChange(); } @@ -988,6 +992,7 @@ nsTextControlFrame::nsTextControlFrame(nsIPresShell* aShell, nsStyleContext* aCo mNotifyOnInput = PR_TRUE; mScrollableView = nsnull; mDidPreDestroy = PR_FALSE; + mHasFocus = PR_FALSE; #ifdef DEBUG mCreateFrameForCalled = PR_FALSE; @@ -2795,6 +2800,12 @@ nsTextControlFrame::SetValue(const nsAString& aValue) if (outerTransaction) mNotifyOnInput = PR_TRUE; + + if (mHasFocus) { + // Since this code doesn't handle user-generated changes, reset + // mFocusedValue so the onchange event doesn't fire incorrectly. + InitFocusedValue(); + } } if (mScrollableView) diff --git a/mozilla/layout/forms/nsTextControlFrame.h b/mozilla/layout/forms/nsTextControlFrame.h index 8a9536ffaad..ce2377536ee 100644 --- a/mozilla/layout/forms/nsTextControlFrame.h +++ b/mozilla/layout/forms/nsTextControlFrame.h @@ -184,6 +184,11 @@ public: //for methods who access nsTextControlFrame directly nsresult DOMPointToOffset(nsIDOMNode* aNode, PRInt32 aNodeOffset, PRInt32 *aResult); nsresult OffsetToDOMPoint(PRInt32 aOffset, nsIDOMNode** aResult, PRInt32* aPosition); + void SetHasFocus(PRBool aHasFocus) + { + mHasFocus = aHasFocus; + }; + /* called to free up native keybinding services */ static NS_HIDDEN_(void) ShutDown(); @@ -280,7 +285,8 @@ private: PRPackedBool mUseEditor; PRPackedBool mIsProcessing; PRPackedBool mNotifyOnInput;//default this to off to stop any notifications until setup is complete - PRPackedBool mDidPreDestroy; // has PreDestroy been called + PRPackedBool mDidPreDestroy; // has PreDestroy been called + PRPackedBool mHasFocus; nsCOMPtr mSelCon; nsCOMPtr mFrameSel;