Implement @formmethod, @formenctype

RESOLVED FIXED in mozilla2.0b5

Status

()

Core
Layout: Form Controls
RESOLVED FIXED
7 years ago
5 years ago

People

(Reporter: dzbarsky, Assigned: mounir)

Tracking

(Blocks: 1 bug, {dev-doc-complete, html5})

Trunk
mozilla2.0b5
dev-doc-complete, html5
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(blocking2.0 beta5+)

Details

Attachments

(1 attachment, 7 obsolete attachments)

Comment hidden (empty)
(Reporter)

Updated

7 years ago
Assignee: nobody → dzbarsky
(Reporter)

Updated

7 years ago
Depends on: 582303
(Reporter)

Comment 1

7 years ago
Created attachment 460689 [details] [diff] [review]
Part 1: Implement the attributes and use them
Attachment #460689 - Flags: review?(Olli.Pettay)
(Reporter)

Comment 2

7 years ago
Created attachment 460690 [details] [diff] [review]
Part 1: Implement the attributes and use them

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

7 years ago
Created attachment 460700 [details] [diff] [review]
Part 2: Define IDL attributed and implement them
Attachment #460700 - Flags: review?(Olli.Pettay)
(Reporter)

Comment 4

7 years ago
Of course I forgot to bump the IID. Consider that done.
(Assignee)

Comment 5

7 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

7 years ago
Blocks: 583288

Comment 6

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

Updated

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

Comment 7

7 years ago
Created attachment 463048 [details] [diff] [review]
Implement only @formmethod and @formenctype
Attachment #460690 - Attachment is obsolete: true
Attachment #463048 - Flags: review?(Olli.Pettay)
(Assignee)

Comment 8

7 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

7 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

7 years ago
Status: NEW → ASSIGNED
(Assignee)

Comment 11

7 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

7 years ago
Created attachment 467228 [details] [diff] [review]
Patch v2

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

7 years ago
blocking2.0: --- → ?
(Assignee)

Comment 13

7 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

7 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

7 years ago
Created attachment 467645 [details] [diff] [review]
Patch v2.1

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

7 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

7 years ago
Created attachment 467694 [details] [diff] [review]
Patch v2.2

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)

Updated

7 years ago
Attachment #467694 - Flags: review?(Olli.Pettay) → review+
(Assignee)

Comment 21

7 years ago
Created attachment 467861 [details] [diff] [review]
Patch v2.3

Patch ready to be landed.
Attachment #467694 - Attachment is obsolete: true
blocking2.0: ? → final+
blocking2.0: final+ → beta5+
(Assignee)

Comment 22

7 years ago
In the tree:
http://hg.mozilla.org/mozilla-central/rev/7a5dfaf19c26
Status: ASSIGNED → RESOLVED
Last Resolved: 7 years ago
Flags: in-testsuite+
Keywords: dev-doc-needed, html5
Resolution: --- → FIXED
Target Milestone: --- → mozilla2.0b5

Updated

7 years ago
Keywords: dev-doc-needed → dev-doc-complete
(Assignee)

Updated

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