From 394b6ebb90a8311dd0b6ed9318c246bc15e01812 Mon Sep 17 00:00:00 2001 From: "mats.palmgren%bredband.net" Date: Fri, 5 Jan 2007 16:31:07 +0000 Subject: [PATCH] OnChange is sometimes triggered for scripted changes. b=265047 r+sr=jst git-svn-id: svn://10.0.0.236/trunk@217827 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/forms/nsFileControlFrame.cpp | 12 ++++----- mozilla/layout/forms/nsTextControlFrame.cpp | 30 ++++++++++----------- mozilla/layout/forms/nsTextControlFrame.h | 12 +++++---- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index 74a9bb10e83..90f6785dca4 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -334,13 +334,13 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent) nsAutoString unicodePath; result = localFile->GetPath(unicodePath); if (!unicodePath.IsEmpty()) { - // Tell mTextFrame that it doesn't have focus while we're setting the - // value. Otherwise it'll think that the value is being set by a script - // while it has focus and not fire onchange when it should. - PRBool hasFocus = mTextFrame->GetHasFocus(); - mTextFrame->SetHasFocus(PR_FALSE); + // Tell mTextFrame that this update of the value is a user initiated + // change. Otherwise it'll think that the value is being set by a script + // and not fire onchange when it should. + PRBool oldState = mTextFrame->GetFireChangeEventState(); + mTextFrame->SetFireChangeEventState(PR_TRUE); mTextFrame->SetFormProperty(nsGkAtoms::value, unicodePath); - mTextFrame->SetHasFocus(hasFocus); + mTextFrame->SetFireChangeEventState(oldState); nsCOMPtr fileControl = do_QueryInterface(mContent); if (fileControl) { fileControl->SetFileName(unicodePath); diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp index a241d41c983..980e912a494 100644 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ b/mozilla/layout/forms/nsTextControlFrame.cpp @@ -352,8 +352,6 @@ nsTextInputListener::Focus(nsIDOMEvent* aEvent) editor->AddEditorObserver(this); } - mFrame->SetHasFocus(PR_TRUE); - return mFrame->InitFocusedValue(); } @@ -369,8 +367,6 @@ nsTextInputListener::Blur(nsIDOMEvent* aEvent) editor->RemoveEditorObserver(this); } - mFrame->SetHasFocus(PR_FALSE); - return NS_OK; } @@ -1033,17 +1029,17 @@ NS_IMETHODIMP nsTextControlFrame::GetAccessible(nsIAccessible** aAccessible) nsTextControlFrame::nsTextControlFrame(nsIPresShell* aShell, nsStyleContext* aContext) : nsStackFrame(aShell, aContext) -{ - mUseEditor = PR_FALSE; - mIsProcessing = PR_FALSE; - mNotifyOnInput = PR_TRUE; - mScrollableView = nsnull; - mDidPreDestroy = PR_FALSE; - mHasFocus = PR_FALSE; - + , mUseEditor(PR_FALSE) + , mIsProcessing(PR_FALSE) + , mNotifyOnInput(PR_TRUE) + , mDidPreDestroy(PR_FALSE) + , mFireChangeEventState(PR_FALSE) + , mTextListener(nsnull) + , mScrollableView(nsnull) #ifdef DEBUG - mCreateFrameForCalled = PR_FALSE; + , mCreateFrameForCalled(PR_FALSE) #endif +{ } nsTextControlFrame::~nsTextControlFrame() @@ -2732,9 +2728,11 @@ 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. + // This method isn't used for user-generated changes, except for calls + // from nsFileControlFrame which sets mFireChangeEventState==true and + // restores it afterwards (ie. we want onchange events for those changes). + if (!mFireChangeEventState) { + // Reset mFocusedValue so the onchange event doesn't fire incorrectly. InitFocusedValue(); } } diff --git a/mozilla/layout/forms/nsTextControlFrame.h b/mozilla/layout/forms/nsTextControlFrame.h index ec7bd6f5b07..508b48775ee 100644 --- a/mozilla/layout/forms/nsTextControlFrame.h +++ b/mozilla/layout/forms/nsTextControlFrame.h @@ -190,14 +190,14 @@ 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) + void SetFireChangeEventState(PRBool aNewState) { - mHasFocus = aHasFocus; + mFireChangeEventState = aNewState; }; - PRBool GetHasFocus() const + PRBool GetFireChangeEventState() const { - return mHasFocus; + return mFireChangeEventState; } /* called to free up native keybinding services */ @@ -280,7 +280,9 @@ private: PRPackedBool mIsProcessing; PRPackedBool mNotifyOnInput;//default this to off to stop any notifications until setup is complete PRPackedBool mDidPreDestroy; // has PreDestroy been called - PRPackedBool mHasFocus; + // Calls to SetValue will be treated as user values (i.e. trigger onChange + // eventually) when mFireChangeEventState==true, this is used by nsFileControlFrame. + PRPackedBool mFireChangeEventState; nsCOMPtr mSelCon; nsCOMPtr mFrameSel;