Closed Bug 582412 Opened 11 years ago Closed 10 years ago

Implement @formmethod, @formenctype

Categories

(Core :: Layout: Form Controls, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla2.0b5
Tracking Status
blocking2.0 --- beta5+

People

(Reporter: dzbarsky, Assigned: mounir)

References

Details

(Keywords: dev-doc-complete, html5)

Attachments

(1 file, 7 obsolete files)

No description provided.
Assignee: nobody → dzbarsky
Depends on: 582303
Attachment #460689 - Flags: review?(Olli.Pettay)
Sorry, the other one simply defined GK_ATOMS.  That doesn't really do much =P
Attachment #460689 - Attachment is obsolete: true
Attachment #460690 - Flags: review?(Olli.Pettay)
Attachment #460689 - Flags: review?(Olli.Pettay)
Attachment #460700 - Flags: review?(Olli.Pettay)
Of course I forgot to bump the IID. Consider that done.
formaction and formtarget patches are in bug 566160 and bug 566064.
Please, implement only formmethod and formenctype in this bug.
Blocks: 344614
Summary: Implement @formmethod, @formaction, @formenctype, @formtarget → Implement @formmethod, @formenctype
Blocks: 583288
Comment on attachment 460690 [details] [diff] [review]
Part 1: Implement the attributes and use them

Based on comment 5, these patches need some tweaking (removing some parts).
Attachment #460690 - Flags: review?(Olli.Pettay)
Attachment #460700 - Flags: review?(Olli.Pettay)
Attachment #460690 - Attachment is obsolete: true
Attachment #463048 - Flags: review?(Olli.Pettay)
Be careful with NS_IMPL_ENUM_ATTR_DEFAULT_VALUE. It is assuming the enumerated value is limited to only known values like input.type. When I wrote this macro I was thinking all enumerated values would have to be limited to known values. However, this is clearly not the case [1]. I had to open a bug to have input.type limited to only known value [2] (for backward compatibility) and someone did that for button.type [3].
I hope most enumerated attributes will be limited to only known values. Anne looks to agree with this idea which lets me think it's not completely non sense.

For this bug, you can use the current macro thus not respecting the specifications. You can also create a new macro or add a new parameter to not limit to only known values like:
#define NS_IMPL_ENUM_ATTR_NOT_LIMITED(_class, _method, _atom) \
  NS_IMETHODIMP                                                           \
  _class::Get##_method(nsAString& aValue)                                 \
  {                                                                       \
    return GetEnumAttr(nsGkAtoms::_atom, nsnull, aValue);               \
  }   
[...]

and in nsGenericHTMLElement::GetEnumAttr, you change:
  if (attrVal && attrVal->Type() == nsAttrValue::eEnum) {
    attrVal->GetEnumString(aResult, PR_TRUE);
  } else {
    AppendASCIItoUTF16(nsDependentCString(aDefault), aResult);
  }
for:
  if (attrVal && attrVal->Type() == nsAttrValue::eEnum) {
    attrVal->GetEnumString(aResult, PR_TRUE);
  } else if (aDefault) {
    AppendASCIItoUTF16(nsDependentCString(aDefault), aResult);
  } else if (attrVal) { // when not limited to only known value, there is no default value
    attrVal->ToString(aResult);
  }


[1] http://www.w3.org/Bugs/Public/show_bug.cgi?id=9634
[2] http://www.w3.org/Bugs/Public/show_bug.cgi?id=9635
[3] http://www.w3.org/Bugs/Public/show_bug.cgi?id=10290
Good news, you can forget comment 8, the specs have changed and formmethod, formenctype, method and enctype are now limited to known values.
Comment on attachment 463048 [details] [diff] [review]
Implement only @formmethod and @formenctype

>diff --git a/content/html/content/public/nsFormSubmission.h b/content/html/content/public/nsFormSubmission.h
>--- a/content/html/content/public/nsFormSubmission.h
>+++ b/content/html/content/public/nsFormSubmission.h
>@@ -221,11 +221,12 @@ private:
> 
> /**
>  * Get a submission object based on attributes in the form (ENCTYPE and METHOD)
>  *
>  * @param aForm the form to get a submission object based on
>  * @param aFormSubmission the form submission object (out param)
Please document aOrigin param.
 
> nsresult
> GetSubmissionFromForm(nsGenericHTMLElement* aForm,
>+                      nsGenericHTMLElement* aOrigin,
>                       nsFormSubmission** aFormSubmission)
> {
>   // Get all the information necessary to encode the form data
>   NS_ASSERTION(aForm->GetCurrentDoc(),
>                "Should have doc if we're building submission!");
> 
>   // Get encoding type (default: urlencoded)
>   PRInt32 enctype = NS_FORM_ENCTYPE_URLENCODED;
>-  GetEnumAttr(aForm, nsGkAtoms::enctype, &enctype);
>+  bool hasEnctype = GetEnumAttr(aOrigin, nsGkAtoms::formenctype, &enctype);
>+  if (!hasEnctype)
>+    GetEnumAttr(aForm, nsGkAtoms::enctype, &enctype);
> 
>   // Get method (default: GET)
>   PRInt32 method = NS_FORM_METHOD_GET;
>-  GetEnumAttr(aForm, nsGkAtoms::method, &method);
>+  if (!GetEnumAttr(aOrigin, nsGkAtoms::formmethod, &method))
>+    GetEnumAttr(aForm, nsGkAtoms::method, &method);
You need to handle the case when aOrigin is null.
And also add testcases for that.

>-nsHTMLFormElement::BuildSubmission(nsFormSubmission** aFormSubmission, 
>+nsHTMLFormElement::BuildSubmission(nsFormSubmission** aFormSubmission,
>                                    nsEvent* aEvent)
> {
>   NS_ASSERTION(!mPendingSubmission, "tried to build two submissions!");
> 
>   // Get the originating frame (failure is non-fatal)
>-  nsIContent *originatingElement = nsnull;
>+  nsGenericHTMLElement *originatingElement = nsnull;
>   if (aEvent) {
>     if (NS_FORM_EVENT == aEvent->eventStructType) {
>-      originatingElement = ((nsFormEvent *)aEvent)->originator;
>+      originatingElement = static_cast<nsGenericHTMLElement*>(((nsFormEvent *)aEvent)->originator);
This is a bit evil. nsFormEvent has nsIContent* originator.
Could you just change that to nsGenericHTMLElement, and then there is no need 
for the extra static_cast

>@@ -1318,17 +1306,16 @@ nsHTMLFormElement::OnSubmitClickEnd()
> 
> void
> nsHTMLFormElement::FlushPendingSubmission()
> {
>   if (mPendingSubmission) {
>     // Transfer owning reference so that the submissioin doesn't get deleted
>     // if we reenter
>     nsAutoPtr<nsFormSubmission> submission = mPendingSubmission;
>-
No need for this
Attachment #463048 - Flags: review?(Olli.Pettay) → review-
Status: NEW → ASSIGNED
(In reply to comment #10)
> >-nsHTMLFormElement::BuildSubmission(nsFormSubmission** aFormSubmission, 
> >+nsHTMLFormElement::BuildSubmission(nsFormSubmission** aFormSubmission,
> >                                    nsEvent* aEvent)
> > {
> >   NS_ASSERTION(!mPendingSubmission, "tried to build two submissions!");
> > 
> >   // Get the originating frame (failure is non-fatal)
> >-  nsIContent *originatingElement = nsnull;
> >+  nsGenericHTMLElement *originatingElement = nsnull;
> >   if (aEvent) {
> >     if (NS_FORM_EVENT == aEvent->eventStructType) {
> >-      originatingElement = ((nsFormEvent *)aEvent)->originator;
> >+      originatingElement = static_cast<nsGenericHTMLElement*>(((nsFormEvent *)aEvent)->originator);
> This is a bit evil. nsFormEvent has nsIContent* originator.
> Could you just change that to nsGenericHTMLElement, and then there is no need 
> for the extra static_cast

I agree that originator will always be nsGenericHTMLElement* but I think making originator nsGenericHTMLElement* wouldn't be better because we will have to include nsGenericHTMLElement.h in widget/public/nsGUIEvent.h or force all cpp files including nsGUIEVent.h to include nsGenericHTMLELement.h. Both solutions are not doable, are they? Maybe we could create a nsFormEvent.h file which will need cpp files including it to include nsGenericHTMLElement.h but that may be a bit too much just to prevent a static_cast, right?
Attached patch Patch v2 (obsolete) — Splinter Review
I'm taking the ownership of this bug considering we want it for ff4 and David finished his internship and, according to jst, he may be on vacation now.
Assignee: dzbarsky → mounir.lamouri
Attachment #460700 - Attachment is obsolete: true
Attachment #463048 - Attachment is obsolete: true
Attachment #467228 - Flags: superreview?(jonas)
Attachment #467228 - Flags: review?(Olli.Pettay)
blocking2.0: --- → ?
Bug 566160 and bug 566064 may be landed before landing this one. There is no hard dependency but the patch may not apply easily.
You don't need to #include anything to be able to use it in nsGUIEvent.h
Just have class nsGenericHTMLElement; somewhere in the nsGUIEvent.h
Comment on attachment 467228 [details] [diff] [review]
Patch v2

Could you change the type of the originator.
static_cast from nsIContent without any checks is error prone.
What if some code later starts to use  .originator with non-html elements?
If we change its type, whoever needs it for non-html will have to
change the type and check also other usage.
Attachment #467228 - Flags: review?(Olli.Pettay) → review-
(In reply to comment #14)
> You don't need to #include anything to be able to use it in nsGUIEvent.h
> Just have class nsGenericHTMLElement; somewhere in the nsGUIEvent.h

This line can be changed only by adding 'class nsGenericHTMLElement':
  nsIContent *originator;\

But this one needs the class to be defined AFAIK:
  originator(nsnull)
Attached patch Patch v2.1 (obsolete) — Splinter Review
Jonas, just cancel the review if it seems not needed.
Attachment #467228 - Attachment is obsolete: true
Attachment #467645 - Flags: superreview?(jonas)
Attachment #467645 - Flags: review?(Olli.Pettay)
Attachment #467228 - Flags: superreview?(jonas)
(In reply to comment #17)
> Created attachment 467645 [details] [diff] [review]
> Patch v2.1
> 
> Jonas, just cancel the review if it seems not needed.

s/review/super-review/
Comment on attachment 467645 [details] [diff] [review]
Patch v2.1

sr=me
Attachment #467645 - Flags: superreview?(jonas) → superreview+
Attached patch Patch v2.2 (obsolete) — Splinter Review
sr=sicking

This should be more error-proof.
Attachment #467645 - Attachment is obsolete: true
Attachment #467694 - Flags: review?(Olli.Pettay)
Attachment #467645 - Flags: review?(Olli.Pettay)
Attachment #467694 - Flags: review?(Olli.Pettay) → review+
Attached patch Patch v2.3Splinter Review
Patch ready to be landed.
Attachment #467694 - Attachment is obsolete: true
blocking2.0: final+ → beta5+
In the tree:
http://hg.mozilla.org/mozilla-central/rev/7a5dfaf19c26
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla2.0b5
Depends on: 787095
You need to log in before you can comment on or make changes to this bug.