From 4482aee25ce8fbedd7e1aac1f7a918dca58ecf0a Mon Sep 17 00:00:00 2001 From: "kmcclusk%netscape.com" Date: Tue, 12 Oct 1999 22:44:23 +0000 Subject: [PATCH] Set state of checkbox and Radio button on MouseUp instead of MouseDown so JavaScript onclick event handlers can retreive the correct state of the form element. bug 15366; r=rods@netscape.com Submit the form when a text field is clicked on only if the JavaScript event handler has not consumed the event. bug 15949; r=rods@netscape.com --- layout/html/forms/src/nsCheckboxControlFrame.cpp | 7 ++++++- layout/html/forms/src/nsCheckboxControlFrame.h | 2 +- layout/html/forms/src/nsGfxTextControlFrame.cpp | 8 +++++--- layout/html/forms/src/nsRadioControlFrame.cpp | 7 ++++++- layout/html/forms/src/nsRadioControlFrame.h | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/layout/html/forms/src/nsCheckboxControlFrame.cpp b/layout/html/forms/src/nsCheckboxControlFrame.cpp index cd1e667a508e..78767e09d99a 100644 --- a/layout/html/forms/src/nsCheckboxControlFrame.cpp +++ b/layout/html/forms/src/nsCheckboxControlFrame.cpp @@ -189,7 +189,7 @@ nsCheckboxControlFrame::AttributeChanged(nsIPresContext* aPresContext, void -nsCheckboxControlFrame::MouseClicked(nsIPresContext* aPresContext) +nsCheckboxControlFrame::MouseUp(nsIPresContext* aPresContext) { if ( IsTristateCheckbox() ) { CheckState newState = eOn; @@ -272,9 +272,14 @@ NS_METHOD nsCheckboxControlFrame::HandleEvent(nsIPresContext& aPresContext, { if (nsEventStatus_eConsumeNoDefault == aEventStatus) return NS_OK; + if (nsFormFrame::GetDisabled(this)) return NS_OK; + if (NS_MOUSE_LEFT_BUTTON_UP == aEvent->message) { + MouseUp(&aPresContext); + } + return(nsNativeFormControlFrame::HandleEvent(aPresContext, aEvent, aEventStatus)); } diff --git a/layout/html/forms/src/nsCheckboxControlFrame.h b/layout/html/forms/src/nsCheckboxControlFrame.h index 6ef1c7f1bc51..3518887b9574 100644 --- a/layout/html/forms/src/nsCheckboxControlFrame.h +++ b/layout/html/forms/src/nsCheckboxControlFrame.h @@ -71,7 +71,7 @@ public: virtual PRInt32 GetMaxNumValues(); virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsString* aValues, nsString* aNames); - virtual void MouseClicked(nsIPresContext* aPresContext); + virtual void MouseUp(nsIPresContext* aPresContext); // nsFormControlFrame overrides nsresult RequiresWidget(PRBool &aHasWidget); diff --git a/layout/html/forms/src/nsGfxTextControlFrame.cpp b/layout/html/forms/src/nsGfxTextControlFrame.cpp index 327234436688..a7544d6fc778 100644 --- a/layout/html/forms/src/nsGfxTextControlFrame.cpp +++ b/layout/html/forms/src/nsGfxTextControlFrame.cpp @@ -315,18 +315,20 @@ nsGfxTextControlFrame::EnterPressed(nsIPresContext& aPresContext) if (mFormFrame && mFormFrame->CanSubmit(*this)) { nsIContent *formContent = nsnull; + nsEventStatus status = nsEventStatus_eIgnore; + mFormFrame->GetContent(&formContent); if (nsnull != formContent) { nsEvent event; - nsEventStatus status = nsEventStatus_eIgnore; - event.eventStructType = NS_EVENT; event.message = NS_FORM_SUBMIT; formContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status); NS_RELEASE(formContent); } - mFormFrame->OnSubmit(&aPresContext, this); + if (nsEventStatus_eConsumeNoDefault != status) { + mFormFrame->OnSubmit(&aPresContext, this); + } } } diff --git a/layout/html/forms/src/nsRadioControlFrame.cpp b/layout/html/forms/src/nsRadioControlFrame.cpp index 17dae2e5170e..3e796068feac 100644 --- a/layout/html/forms/src/nsRadioControlFrame.cpp +++ b/layout/html/forms/src/nsRadioControlFrame.cpp @@ -82,7 +82,7 @@ nsRadioControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWi } void -nsRadioControlFrame::MouseClicked(nsIPresContext* aPresContext) +nsRadioControlFrame::MouseUp(nsIPresContext* aPresContext) { SetRadioControlFrameState(NS_STRING_TRUE); @@ -201,6 +201,11 @@ nsRadioControlFrame::HandleEvent(nsIPresContext& aPresContext, } } break; + case NS_MOUSE_LEFT_BUTTON_UP: + MouseUp(&aPresContext); + break; + + default: break; } diff --git a/layout/html/forms/src/nsRadioControlFrame.h b/layout/html/forms/src/nsRadioControlFrame.h index 4f0c4610cdc4..2ef054322266 100644 --- a/layout/html/forms/src/nsRadioControlFrame.h +++ b/layout/html/forms/src/nsRadioControlFrame.h @@ -59,7 +59,7 @@ public: virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsString* aValues, nsString* aNames); - virtual void MouseClicked(nsIPresContext* aPresContext); + virtual void MouseUp(nsIPresContext* aPresContext); virtual void Reset(); virtual const nsIID& GetCID();