diff --git a/mozilla/layout/forms/nsFormControlHelper.cpp b/mozilla/layout/forms/nsFormControlHelper.cpp index 4e38a9589ea..801d772b7e8 100644 --- a/mozilla/layout/forms/nsFormControlHelper.cpp +++ b/mozilla/layout/forms/nsFormControlHelper.cpp @@ -933,3 +933,67 @@ nsFormControlHelper::GetDisabled(nsIContent* aContent, PRBool* oIsDisabled) } return NS_OK; } + +// manual submission helper method +// aPresShell - If the PresShell is null then the PresContext will +// get its own and use itstatic nsresult +// aFormFrame - The HTML Form's frame +// aFormControlFrame - The form controls frame that is calling this +// it can be null +// aDoSubmit - Submit = TRUE, Reset = FALSE +// Indicates whether to do DOM Processing of the event or to do regular frame processing +nsresult +nsFormControlHelper::DoManualSubmitOrReset(nsIPresContext* aPresContext, + nsIPresShell* aPresShell, + nsIFrame* aFormFrame, + nsIFrame* aFormControlFrame, + PRBool aDoSubmit, + PRBool aDoDOMEvent) +{ + NS_ENSURE_ARG_POINTER(aPresContext); + NS_ENSURE_ARG_POINTER(aFormFrame); + + nsresult result = NS_OK; + + nsCOMPtr formContent; + aFormFrame->GetContent(getter_AddRefs(formContent)); + + 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 + if (aPresShell == nsnull) { + result = aPresContext->GetShell(getter_AddRefs(shell)); + aPresShell = shell.get(); // not AddRefing because shell will clean up + } + + // With a valid PreShell handle the event + if (NS_SUCCEEDED(result) && nsnull != aPresShell) { + nsEvent event; + event.eventStructType = NS_EVENT; + event.message = aDoSubmit?NS_FORM_SUBMIT:NS_FORM_RESET; + if (aDoDOMEvent) { + aPresShell->HandleDOMEventWithTarget(formContent, &event, &status); + } else { + aPresShell->HandleEventWithTarget(&event, nsnull, formContent, NS_EVENT_FLAG_INIT, &status); + } + } + } + + // Check status after handling event to make sure we should continue + if (nsEventStatus_eConsumeNoDefault != status) { + // get the form manager interface + nsIFormManager* formMan = nsnull; // weak reference, not refcounted + result = aFormFrame->QueryInterface(NS_GET_IID(nsIFormManager), (void**)&formMan); + if (NS_SUCCEEDED(result) && formMan) { + // now do the Submit or Reset + if (aDoSubmit) { + formMan->OnSubmit(aPresContext, aFormControlFrame); + } else { + formMan->OnReset(aPresContext); + } + } + } + return result; +} + diff --git a/mozilla/layout/forms/nsFormControlHelper.h b/mozilla/layout/forms/nsFormControlHelper.h index 4e5f3fd3d48..2e2cadade29 100644 --- a/mozilla/layout/forms/nsFormControlHelper.h +++ b/mozilla/layout/forms/nsFormControlHelper.h @@ -182,6 +182,15 @@ public: static const char * GetHTMLPropertiesFileName() { return FORM_PROPERTIES; } static nsresult GetDisabled(nsIContent* aContent, PRBool* oIsDisabled); + + // If the PresShell is null then the PresContext will get its own and use it + static nsresult DoManualSubmitOrReset(nsIPresContext* aPresContext, + nsIPresShell* aPresShell, + nsIFrame* aFormFrame, + nsIFrame* aFormControlFrame, + PRBool aDoSubmit, // Submit = TRUE, Reset = FALSE + PRBool aDoDOMEvent); + // //------------------------------------------------------------------------------------- // Utility methods for managing checkboxes and radiobuttons diff --git a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp index 88fc761030b..9663b44357f 100644 --- a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp @@ -331,36 +331,20 @@ void nsHTMLButtonControlFrame::MouseClicked(nsIPresContext* aPresContext) { if ((nsnull != mFormFrame) && !nsFormFrame::GetDisabled(this)) { - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - nsIContent *formContent = nsnull; - mFormFrame->GetContent(&formContent); + PRInt32 type; + GetType(&type); - nsCOMPtr presShell; - aPresContext->GetShell(getter_AddRefs(presShell)); - if (presShell) { - PRInt32 type; - GetType(&type); - if (IsReset(type) == PR_TRUE) { - event.message = NS_FORM_RESET; - presShell->HandleEventWithTarget(&event, nsnull, formContent, NS_EVENT_FLAG_INIT, &status); - if (nsEventStatus_eConsumeNoDefault != status && mFormFrame) { - mFormFrame->OnReset(aPresContext); - } - } - else if (IsSubmit(aPresContext, type) == PR_TRUE) { - event.message = NS_FORM_SUBMIT; - presShell->HandleEventWithTarget(&event, nsnull, formContent, NS_EVENT_FLAG_INIT, &status); - if (nsEventStatus_eConsumeNoDefault != status && mFormFrame) { - mFormFrame->OnSubmit(aPresContext, this); - } - } + if (IsReset(type) == PR_TRUE) { + // do Reset & Frame processing of event + nsFormControlHelper::DoManualSubmitOrReset(aPresContext, nsnull, mFormFrame, + this, PR_FALSE, PR_FALSE); + } + else if (IsSubmit(aPresContext, type) == PR_TRUE) { + // do Submit & Frame processing of event + nsFormControlHelper::DoManualSubmitOrReset(aPresContext, nsnull, mFormFrame, + this, PR_TRUE, PR_FALSE); } - - NS_IF_RELEASE(formContent); } - } void diff --git a/mozilla/layout/forms/nsImageControlFrame.cpp b/mozilla/layout/forms/nsImageControlFrame.cpp index 46ed317ee4a..d5f5dbcf1c4 100644 --- a/mozilla/layout/forms/nsImageControlFrame.cpp +++ b/mozilla/layout/forms/nsImageControlFrame.cpp @@ -435,28 +435,10 @@ nsImageControlFrame::GetCursor(nsIPresContext* aPresContext, void nsImageControlFrame::MouseClicked(nsIPresContext* aPresContext) { - PRInt32 type; - GetType(&type); - - if ((nsnull != mFormFrame) && !nsFormFrame::GetDisabled(this)) { - nsIContent *formContent = nsnull; - mFormFrame->GetContent(&formContent); - - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_FORM_SUBMIT; - if (nsnull != formContent) { - nsCOMPtr shell; - nsresult result = aPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(result) && shell) { - shell->HandleDOMEventWithTarget(formContent, &event, &status); - } - NS_RELEASE(formContent); - } - if (nsEventStatus_eConsumeNoDefault != status) { - mFormFrame->OnSubmit(aPresContext, this); - } + if (nsnull != mFormFrame && !nsFormFrame::GetDisabled(this)) { + // Do Submit & DOM Processing + nsFormControlHelper::DoManualSubmitOrReset(aPresContext, nsnull, + mFormFrame, this, PR_TRUE, PR_TRUE); } } diff --git a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp index 4e38a9589ea..801d772b7e8 100644 --- a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp @@ -933,3 +933,67 @@ nsFormControlHelper::GetDisabled(nsIContent* aContent, PRBool* oIsDisabled) } return NS_OK; } + +// manual submission helper method +// aPresShell - If the PresShell is null then the PresContext will +// get its own and use itstatic nsresult +// aFormFrame - The HTML Form's frame +// aFormControlFrame - The form controls frame that is calling this +// it can be null +// aDoSubmit - Submit = TRUE, Reset = FALSE +// Indicates whether to do DOM Processing of the event or to do regular frame processing +nsresult +nsFormControlHelper::DoManualSubmitOrReset(nsIPresContext* aPresContext, + nsIPresShell* aPresShell, + nsIFrame* aFormFrame, + nsIFrame* aFormControlFrame, + PRBool aDoSubmit, + PRBool aDoDOMEvent) +{ + NS_ENSURE_ARG_POINTER(aPresContext); + NS_ENSURE_ARG_POINTER(aFormFrame); + + nsresult result = NS_OK; + + nsCOMPtr formContent; + aFormFrame->GetContent(getter_AddRefs(formContent)); + + 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 + if (aPresShell == nsnull) { + result = aPresContext->GetShell(getter_AddRefs(shell)); + aPresShell = shell.get(); // not AddRefing because shell will clean up + } + + // With a valid PreShell handle the event + if (NS_SUCCEEDED(result) && nsnull != aPresShell) { + nsEvent event; + event.eventStructType = NS_EVENT; + event.message = aDoSubmit?NS_FORM_SUBMIT:NS_FORM_RESET; + if (aDoDOMEvent) { + aPresShell->HandleDOMEventWithTarget(formContent, &event, &status); + } else { + aPresShell->HandleEventWithTarget(&event, nsnull, formContent, NS_EVENT_FLAG_INIT, &status); + } + } + } + + // Check status after handling event to make sure we should continue + if (nsEventStatus_eConsumeNoDefault != status) { + // get the form manager interface + nsIFormManager* formMan = nsnull; // weak reference, not refcounted + result = aFormFrame->QueryInterface(NS_GET_IID(nsIFormManager), (void**)&formMan); + if (NS_SUCCEEDED(result) && formMan) { + // now do the Submit or Reset + if (aDoSubmit) { + formMan->OnSubmit(aPresContext, aFormControlFrame); + } else { + formMan->OnReset(aPresContext); + } + } + } + return result; +} + diff --git a/mozilla/layout/html/forms/src/nsFormControlHelper.h b/mozilla/layout/html/forms/src/nsFormControlHelper.h index 4e5f3fd3d48..2e2cadade29 100644 --- a/mozilla/layout/html/forms/src/nsFormControlHelper.h +++ b/mozilla/layout/html/forms/src/nsFormControlHelper.h @@ -182,6 +182,15 @@ public: static const char * GetHTMLPropertiesFileName() { return FORM_PROPERTIES; } static nsresult GetDisabled(nsIContent* aContent, PRBool* oIsDisabled); + + // If the PresShell is null then the PresContext will get its own and use it + static nsresult DoManualSubmitOrReset(nsIPresContext* aPresContext, + nsIPresShell* aPresShell, + nsIFrame* aFormFrame, + nsIFrame* aFormControlFrame, + PRBool aDoSubmit, // Submit = TRUE, Reset = FALSE + PRBool aDoDOMEvent); + // //------------------------------------------------------------------------------------- // Utility methods for managing checkboxes and radiobuttons diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp index e987ef60b9d..cd030264d73 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp @@ -2861,19 +2861,9 @@ nsGfxTextControlFrame2::SubmitAttempt() nsCOMPtr context; if (NS_SUCCEEDED(presShell->GetPresContext(getter_AddRefs(context))) && context) { - mFormFrame->GetContent(&formContent); - if (nsnull != formContent) { - nsEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_FORM_SUBMIT; - - formContent->HandleDOMEvent(context, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - NS_RELEASE(formContent); - } - - if (nsEventStatus_eConsumeNoDefault != status) { - mFormFrame->OnSubmit(context, this); - } + // do Submit & Frame processing of event + nsFormControlHelper::DoManualSubmitOrReset(context, presShell, mFormFrame, + this, PR_TRUE, PR_FALSE); } } } diff --git a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp index 88fc761030b..9663b44357f 100644 --- a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp @@ -331,36 +331,20 @@ void nsHTMLButtonControlFrame::MouseClicked(nsIPresContext* aPresContext) { if ((nsnull != mFormFrame) && !nsFormFrame::GetDisabled(this)) { - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - nsIContent *formContent = nsnull; - mFormFrame->GetContent(&formContent); + PRInt32 type; + GetType(&type); - nsCOMPtr presShell; - aPresContext->GetShell(getter_AddRefs(presShell)); - if (presShell) { - PRInt32 type; - GetType(&type); - if (IsReset(type) == PR_TRUE) { - event.message = NS_FORM_RESET; - presShell->HandleEventWithTarget(&event, nsnull, formContent, NS_EVENT_FLAG_INIT, &status); - if (nsEventStatus_eConsumeNoDefault != status && mFormFrame) { - mFormFrame->OnReset(aPresContext); - } - } - else if (IsSubmit(aPresContext, type) == PR_TRUE) { - event.message = NS_FORM_SUBMIT; - presShell->HandleEventWithTarget(&event, nsnull, formContent, NS_EVENT_FLAG_INIT, &status); - if (nsEventStatus_eConsumeNoDefault != status && mFormFrame) { - mFormFrame->OnSubmit(aPresContext, this); - } - } + if (IsReset(type) == PR_TRUE) { + // do Reset & Frame processing of event + nsFormControlHelper::DoManualSubmitOrReset(aPresContext, nsnull, mFormFrame, + this, PR_FALSE, PR_FALSE); + } + else if (IsSubmit(aPresContext, type) == PR_TRUE) { + // do Submit & Frame processing of event + nsFormControlHelper::DoManualSubmitOrReset(aPresContext, nsnull, mFormFrame, + this, PR_TRUE, PR_FALSE); } - - NS_IF_RELEASE(formContent); } - } void diff --git a/mozilla/layout/html/forms/src/nsImageControlFrame.cpp b/mozilla/layout/html/forms/src/nsImageControlFrame.cpp index 46ed317ee4a..d5f5dbcf1c4 100644 --- a/mozilla/layout/html/forms/src/nsImageControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsImageControlFrame.cpp @@ -435,28 +435,10 @@ nsImageControlFrame::GetCursor(nsIPresContext* aPresContext, void nsImageControlFrame::MouseClicked(nsIPresContext* aPresContext) { - PRInt32 type; - GetType(&type); - - if ((nsnull != mFormFrame) && !nsFormFrame::GetDisabled(this)) { - nsIContent *formContent = nsnull; - mFormFrame->GetContent(&formContent); - - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - event.eventStructType = NS_EVENT; - event.message = NS_FORM_SUBMIT; - if (nsnull != formContent) { - nsCOMPtr shell; - nsresult result = aPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(result) && shell) { - shell->HandleDOMEventWithTarget(formContent, &event, &status); - } - NS_RELEASE(formContent); - } - if (nsEventStatus_eConsumeNoDefault != status) { - mFormFrame->OnSubmit(aPresContext, this); - } + if (nsnull != mFormFrame && !nsFormFrame::GetDisabled(this)) { + // Do Submit & DOM Processing + nsFormControlHelper::DoManualSubmitOrReset(aPresContext, nsnull, + mFormFrame, this, PR_TRUE, PR_TRUE); } }