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
This commit is contained in:
mats.palmgren%bredband.net
2007-01-05 16:31:07 +00:00
parent c37d6cc905
commit 394b6ebb90
3 changed files with 27 additions and 27 deletions

View File

@@ -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<nsIFileControlElement> fileControl = do_QueryInterface(mContent);
if (fileControl) {
fileControl->SetFileName(unicodePath);

View File

@@ -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();
}
}

View File

@@ -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<nsISelectionController> mSelCon;
nsCOMPtr<nsFrameSelection> mFrameSel;