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;