diff --git a/mozilla/content/html/content/src/nsHTMLFormElement.cpp b/mozilla/content/html/content/src/nsHTMLFormElement.cpp index a74cfeda97c..625f5da8727 100644 --- a/mozilla/content/html/content/src/nsHTMLFormElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLFormElement.cpp @@ -40,6 +40,7 @@ #include "nsIDocument.h" #include "nsIPresShell.h" #include "nsIFrame.h" +#include "nsIFormControlFrame.h" #include "nsISizeOfHandler.h" #include "nsIScriptGlobalObject.h" #include "nsDOMError.h" @@ -331,10 +332,11 @@ nsHTMLFormElement::Submit() nsCOMPtr presContext; GetPresContext(this, getter_AddRefs(presContext)); if (presContext) { - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; + nsFormEvent event; + event.eventStructType = NS_FORM_EVENT; event.message = NS_FORM_SUBMIT; + event.originator = nsnull; + nsEventStatus status = nsEventStatus_eIgnore; rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } return rv; @@ -348,10 +350,11 @@ nsHTMLFormElement::Reset() nsCOMPtr presContext; GetPresContext(this, getter_AddRefs(presContext)); if (presContext) { + nsFormEvent event; + event.eventStructType = NS_FORM_EVENT; + event.message = NS_FORM_RESET; + event.originator = nsnull; nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_FORM_RESET; rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } return rv; @@ -450,7 +453,19 @@ nsHTMLFormElement::HandleDOMEvent(nsIPresContext* aPresContext, ret = formMan->OnReset(aPresContext); } else { - ret = formMan->OnSubmit(aPresContext, nsnull); + nsIFrame *originatingFrame = nsnull; + + // Get the originating frame (failure is non-fatal) + if (aEvent) { + if (NS_FORM_EVENT == aEvent->eventStructType) { + nsIContent *originator = ((nsFormEvent *)aEvent)->originator; + if (originator) { + shell->GetPrimaryFrameFor(originator, &originatingFrame); + } + } + } + + ret = formMan->OnSubmit(aPresContext, originatingFrame); } } } diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index 35f433d18ac..d701074c4ff 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -886,10 +886,13 @@ nsHTMLInputElement::MouseClickForAltText(nsIPresContext* aPresContext) nsCOMPtr shell; aPresContext->GetShell(getter_AddRefs(shell)); if (shell) { - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_FORM_SUBMIT; + nsCOMPtr formControl = this; // kungFuDeathGrip + + nsFormEvent event; + event.eventStructType = NS_FORM_EVENT; + event.message = NS_FORM_SUBMIT; + event.originator = formControl; + nsEventStatus status = nsEventStatus_eIgnore; shell->HandleDOMEventWithTarget(form, &event, &status); } } diff --git a/mozilla/layout/forms/nsFormControlHelper.cpp b/mozilla/layout/forms/nsFormControlHelper.cpp index 754e807188a..bdd7f724b26 100644 --- a/mozilla/layout/forms/nsFormControlHelper.cpp +++ b/mozilla/layout/forms/nsFormControlHelper.cpp @@ -971,7 +971,6 @@ nsFormControlHelper::DoManualSubmitOrReset(nsIPresContext* aPresContext, aFormControlFrame->GetContent(getter_AddRefs(controlContent)); } - nsEventStatus status = nsEventStatus_eIgnore; if (formContent) { //Either use the PresShell passed in or go get it from the PresContext nsCOMPtr shell; // this will do our clean up @@ -982,9 +981,16 @@ nsFormControlHelper::DoManualSubmitOrReset(nsIPresContext* aPresContext, // With a valid PreShell handle the event if (NS_SUCCEEDED(result) && nsnull != aPresShell) { - nsEvent event; - event.eventStructType = NS_EVENT; + + // Get originator for event (failure is non-fatal) + nsCOMPtr formControl; + aFormControlFrame->GetContent(getter_AddRefs(formControl)); + + nsFormEvent event; + event.eventStructType = NS_FORM_EVENT; event.message = aDoSubmit?NS_FORM_SUBMIT:NS_FORM_RESET; + event.originator = formControl; + nsEventStatus status = nsEventStatus_eIgnore; if (aDoDOMEvent) { aPresShell->HandleDOMEventWithTarget(formContent, &event, &status); } else { diff --git a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp index 754e807188a..bdd7f724b26 100644 --- a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp @@ -971,7 +971,6 @@ nsFormControlHelper::DoManualSubmitOrReset(nsIPresContext* aPresContext, aFormControlFrame->GetContent(getter_AddRefs(controlContent)); } - nsEventStatus status = nsEventStatus_eIgnore; if (formContent) { //Either use the PresShell passed in or go get it from the PresContext nsCOMPtr shell; // this will do our clean up @@ -982,9 +981,16 @@ nsFormControlHelper::DoManualSubmitOrReset(nsIPresContext* aPresContext, // With a valid PreShell handle the event if (NS_SUCCEEDED(result) && nsnull != aPresShell) { - nsEvent event; - event.eventStructType = NS_EVENT; + + // Get originator for event (failure is non-fatal) + nsCOMPtr formControl; + aFormControlFrame->GetContent(getter_AddRefs(formControl)); + + nsFormEvent event; + event.eventStructType = NS_FORM_EVENT; event.message = aDoSubmit?NS_FORM_SUBMIT:NS_FORM_RESET; + event.originator = formControl; + nsEventStatus status = nsEventStatus_eIgnore; if (aDoDOMEvent) { aPresShell->HandleDOMEventWithTarget(formContent, &event, &status); } else { diff --git a/mozilla/widget/public/nsGUIEvent.h b/mozilla/widget/public/nsGUIEvent.h index cc29608b10b..9540e97800c 100644 --- a/mozilla/widget/public/nsGUIEvent.h +++ b/mozilla/widget/public/nsGUIEvent.h @@ -40,6 +40,7 @@ class nsIRegion; class nsIWidget; class nsIMenuItem; class nsIAccessible; +class nsIContent; /** * Return status for event processors. @@ -290,6 +291,17 @@ struct nsMenuEvent : public nsGUIEvent { PRUint32 mCommand; }; +/** + * Form event + * + * We hold the originating form control for form submit and reset events. + * originator is a weak pointer (does not hold a strong reference). + */ + +struct nsFormEvent : public nsEvent { + nsIContent *originator; +}; + /** * Event status for D&D Event @@ -326,6 +338,7 @@ enum nsDragDropEventStatus { #define NS_SCROLLPORT_EVENT 18 #define NS_RECONVERSION_QUERY 19 #define NS_ACCESSIBLE_EVENT 20 +#define NS_FORM_EVENT 21 /** * GUI MESSAGES