Implement @formmethod, @formenctype

RESOLVED FIXED in mozilla2.0b5

Status

()

defect
RESOLVED FIXED
9 years ago
7 years ago

People

(Reporter: dzbarsky, Assigned: mounir)

Tracking

({dev-doc-complete, html5})

Trunk
mozilla2.0b5
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(blocking2.0 beta5+)

Details

Attachments

(1 attachment, 7 obsolete attachments)

Reporter

Description

9 years ago
No description provided.
Reporter

Updated

9 years ago
Assignee: nobody → dzbarsky
Reporter

Updated

9 years ago
Depends on: 582303
Reporter

Comment 1

9 years ago
Attachment #460689 - Flags: review?(Olli.Pettay)
Reporter

Comment 2

9 years ago
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)
Reporter

Comment 3

9 years ago
Attachment #460700 - Flags: review?(Olli.Pettay)
Reporter

Comment 4

9 years ago
Of course I forgot to bump the IID. Consider that done.
Assignee

Comment 5

9 years ago
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
Assignee

Updated

9 years ago
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)
Reporter

Comment 7

9 years ago
Attachment #460690 - Attachment is obsolete: true
Attachment #463048 - Flags: review?(Olli.Pettay)
Assignee

Comment 8

9 years ago
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
Assignee

Comment 9

9 years ago
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-
Assignee

Updated

9 years ago
Status: NEW → ASSIGNED
Assignee

Comment 11

9 years ago
(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?
Assignee

Comment 12

9 years ago
Posted 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)
Assignee

Updated

9 years ago
blocking2.0: --- → ?
Assignee

Comment 13

9 years ago
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-
Assignee

Comment 16

9 years ago
(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)
Assignee

Comment 17

9 years ago
Posted 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)
Assignee

Comment 18

9 years ago
(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+
Assignee

Comment 20

9 years ago
Posted 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+
Assignee

Comment 21

9 years ago
Posted patch Patch v2.3Splinter Review
Patch ready to be landed.
Attachment #467694 - Attachment is obsolete: true
blocking2.0: final+ → beta5+
Assignee

Comment 22

9 years ago
In the tree:
http://hg.mozilla.org/mozilla-central/rev/7a5dfaf19c26
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla2.0b5
Assignee

Updated

7 years ago
Depends on: 787095
You need to log in before you can comment on or make changes to this bug.