Bug 80110 - [Forms] HTMLFieldSetElement.idl doesn't have elements attribute.
Summary: [Forms] HTMLFieldSetElement.idl doesn't have elements attribute.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Rakesh
URL: http://jsfiddle.net/2yYDD/
Keywords:
Depends on: 81854 86602 87371
Blocks: HTML5Forms
  Show dependency treegraph
 
Reported: 2012-03-01 23:46 PST by yosin
Modified: 2012-05-28 20:57 PDT (History)
6 users (show)

See Also:


Attachments
proposed patch (27.06 KB, patch)
2012-05-22 03:56 PDT, Rakesh
no flags Details | Formatted Diff | Diff
proposed patch (28.15 KB, patch)
2012-05-23 05:02 PDT, Rakesh
no flags Details | Formatted Diff | Diff
patch (27.94 KB, patch)
2012-05-25 03:58 PDT, Rakesh
no flags Details | Formatted Diff | Diff
updated patch (29.09 KB, patch)
2012-05-28 12:29 PDT, Rakesh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description yosin 2012-03-01 23:46:27 PST
See http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#the-fieldset-element

elements attribute returns list of following elements as same as forms.elements:
 * button 
 * fieldset 
 * input 
 * keygen 
 * object 
 * output 
 * select 
 * textarea
Comment 1 Rakesh 2012-03-21 05:53:51 PDT
I am planning to take up this implementation. Few thoughts:

Presently HTMLFormCollection is tightly coupled with HTMLFormElement. So first step would be to decouple these.

Can we have a class like FormControlsContainer and make both HTMLFormElement and HTMLFieldSetElement derive from it?
We can have separate implementations for eg. of length() for Form and FieldSet.

As HTMLFieldSetElement is set of form controls, can we have list of elements by  traversing all the children and checking if each element is a form control? AFAIK each form control is associated with its form element if any. Is there any mechanism to associate a form control with FieldSet?

Please do let me know if you have suggestions/better approach.

Thanks.
Comment 2 Kent Tamura 2012-03-21 17:59:43 PDT
(In reply to comment #1)
Before implementing HTMLFieldSetElement::elements, we need to consider how to realize RadioNodeList [1].  HTMLFormControlsCollection needs to support it, but our HTMLFormElement::elements doesn't support it for now.

Can we add RadioNodeList support to HTMLFormCollection.*?  Can we add RadioNodeList support to HTMLCollection.*?


[1]: http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#radionodelist
Comment 3 Rakesh 2012-03-21 22:53:38 PDT
(In reply to comment #2)
> (In reply to comment #1)

Thanks for replying.

> Before implementing HTMLFieldSetElement::elements, we need to consider how to realize RadioNodeList [1].  HTMLFormControlsCollection needs to support it, but our HTMLFormElement::elements doesn't support it for now.
> 
> Can we add RadioNodeList support to HTMLFormCollection.*?  Can we add RadioNodeList support to HTMLCollection.*?

Yes surely, will check RadioNodeList and add support for that.

> 
> 
> [1]: http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#radionodelist
Comment 4 Rakesh 2012-04-24 07:16:43 PDT
(In reply to comment #2)
> Can we add RadioNodeList support to HTMLFormCollection.*?  Can we add RadioNodeList support to HTMLCollection.*?

As RadioNodeList support has landed, can we now think of refactoring HTMLFormCollection to be independent of HTMLFormElement?
Comment 5 Rakesh 2012-05-22 03:56:43 PDT
Created attachment 143262 [details]
proposed patch

Added support for elements attribute in HTMLFieldSetElement.
Comment 6 Kent Tamura 2012-05-22 21:43:12 PDT
Comment on attachment 143262 [details]
proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=143262&action=review

> Source/WebCore/html/HTMLFieldSetElement.cpp:96
> +    uint64_t docversion = document()->domTreeVersion();

should be docVersion, documentVersion, or domTreeVersion.

> Source/WebCore/html/HTMLFieldSetElement.cpp:105
> +    for (Element* node = firstElementChild(); node; node = node->nextElementSibling()) {

We need a test to confirm that fieldset.elements contains listed-elements in deeper places like
  <fieldset>
    <div>
       <input>
    </div>
  </fieldset>

> Source/WebCore/html/HTMLFieldSetElement.cpp:117
> +        if (node->hasTagName(imgTag)) {
> +            m_imageElements.append(static_cast<HTMLImageElement*>(node));
> +            continue;
> +        }

Why do you need to collect img elements?

> Source/WebCore/html/HTMLFieldSetElement.cpp:129
> +const Vector<HTMLImageElement*>& HTMLFieldSetElement::imageElements() const

ditto.

> Source/WebCore/html/HTMLFieldSetElement.h:45
> +    const Vector<HTMLImageElement*>& imageElements() const;

ditto.

> Source/WebCore/html/HTMLFieldSetElement.h:65
> +    mutable Vector<HTMLImageElement*> m_imageElements;

ditto.

> Source/WebCore/html/HTMLFieldSetElement.idl:29
>  
> +        readonly attribute HTMLCollection elements;
> +
>          readonly attribute DOMString type;

Please put 'elements' after 'type' in order to follow the IDL in the specification.

> Source/WebCore/html/RadioNodeList.cpp:87
> +    return equalIgnoringCase(testElement->getIdAttribute(), m_name) || equalIgnoringCase(testElement->getNameAttribute(), m_name);

This is not a new code, but equalIgnoringCase() looks wrong.  ID matching and name matching should be case-sensitive.
Comment 7 Rakesh 2012-05-23 00:38:17 PDT
(In reply to comment #6)
Thanks for reviewing this patch.

> should be docVersion, documentVersion, or domTreeVersion.
I missed that, will do it.

> We need a test to confirm that fieldset.elements contains listed-elements in deeper places like
>   <fieldset>
>     <div>
>        <input>
>     </div>
>   </fieldset>
Will add the test, I think we need to traverse all children, only sibling traversing is not enough?

> 
> Why do you need to collect img elements?
Code in FormCollection uses image elements.
http://trac.webkit.org/browser/trunk/Source/WebCore/html/HTMLFormCollection.cpp#L137

> Please put 'elements' after 'type' in order to follow the IDL in the specification.
Will do this change.

> This is not a new code, but equalIgnoringCase() looks wrong.  ID matching and name matching should be case-sensitive.
Yes will make it case sensitive.
Comment 8 Kent Tamura 2012-05-23 00:52:54 PDT
(In reply to comment #7)
> > Why do you need to collect img elements?
> Code in FormCollection uses image elements.
> http://trac.webkit.org/browser/trunk/Source/WebCore/html/HTMLFormCollection.cpp#L137

It seems the specification doesn't ask to support img elements in HTMLFieldSetElement::elements.  How other browsers work for img elemnents in a form/fieldset element?


> > This is not a new code, but equalIgnoringCase() looks wrong.  ID matching and name matching should be case-sensitive.
> Yes will make it case sensitive.

It's better to make another bug and patch.
Comment 9 Rakesh 2012-05-23 02:31:33 PDT
(In reply to comment #8)
http://trac.webkit.org/browser/trunk/Source/WebCore/html/HTMLFormCollection.cpp#L137
> 
> It seems the specification doesn't ask to support img elements in HTMLFieldSetElement::elements.  How other browsers work for img elemnents in a form/fieldset element?
> 
Specs says excluding image buttons(http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#the-form-element). I am not sure if that means image elements also. In any case the form.elements behavior is inconsistent for image elements in webkit: 
1. form.elements[some number] does not give image element.
2. form.elements["imageElem"] or form.elements.namedItem("imageElem") gives the image element.
3. form.length does not include the image elements count.

Other browsers, firefox and opera do not consider image elements in form.elements.

> It's better to make another bug and patch.
ok
Comment 10 Rakesh 2012-05-23 02:57:06 PDT
(In reply to comment #9)
> (In reply to comment #8)

Also listed elements(http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#category-listed) does not have image element specified, Do you think image elements support needs be removed from FormCollection?
Comment 11 Kent Tamura 2012-05-23 03:28:52 PDT
(In reply to comment #10)
> Also listed elements(http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#category-listed) does not have image element specified, Do you think image elements support needs be removed from FormCollection?

We might want to remove the img element support in the future.  But it's not the scope of this bug, and we don't need to hurry.

As for HTMLFieldSetElement::elements, we don't need to support img elements at all.  So HTMLFormCollection::getNamedFormItem() may have

 if (base()->hasTagName(fieldsetTag))
     return 0;

before getting imageElementsArray?
Comment 12 Rakesh 2012-05-23 05:02:03 PDT
Created attachment 143537 [details]
proposed patch

Modified as per comments
Comment 13 Kent Tamura 2012-05-24 01:50:46 PDT
Comment on attachment 143537 [details]
proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=143537&action=review

> Source/WebCore/html/HTMLFieldSetElement.h:64
> +    OwnPtr<HTMLFormCollection> m_elementsCollection;
> +
> +    mutable Vector<FormAssociatedElement*> m_associatedElements;
> +
> +    mutable uint64_t m_documentVersion;

nit: these blank lines are not needed.

m_documentVersion should be renamed to m_documentVersionForAssociatedElements, or we should add a comment about the purpose.

> Source/WebCore/html/RadioNodeList.cpp:87
> +    return equalIgnoringCase(testElement->getIdAttribute(), m_name) || equalIgnoringCase(testElement->getNameAttribute(), m_name);

Please add a FIXME comment about the incorrectness, or fix the problem before this bug.

> Source/WebCore/html/RadioNodeList.cpp:95
>  {
> +    if (testElement->hasTagName(objectTag))
> +        return checkIfNameOrIdMatches(testElement);
> +
>      if (!testElement->isFormControlElement())

This change affects HTMLFormElement::elements too, right?
So, we should add <object> support before this bug.
Comment 14 Rakesh 2012-05-24 04:47:41 PDT
(In reply to comment #13)
> Please add a FIXME comment about the incorrectness, or fix the problem before this bug.

Created https://bugs.webkit.org/show_bug.cgi?id=87369 for this problem.

> This change affects HTMLFormElement::elements too, right?
> So, we should add <object> support before this bug.

Created https://bugs.webkit.org/show_bug.cgi?id=87371 for this issue.
Comment 15 Rakesh 2012-05-25 03:58:33 PDT
Created attachment 144037 [details]
patch

Updated patch
Comment 16 Kent Tamura 2012-05-25 06:08:12 PDT
Comment on attachment 144037 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=144037&action=review

r- because of test coverage

> LayoutTests/fast/forms/fieldset/fieldset-elements.html:86
> +

Please test:
  owner.parentNode.removeChild(owner);
  then, adding/removing some form controls to/from 'owner' and owner.elements is correctly updated.

Also, we need a test to check if changing input type from/to 'image' updates HTMLFieldSetElement::elements correctly.
Comment 17 Rakesh 2012-05-28 12:29:34 PDT
Created attachment 144387 [details]
updated patch

Added more test converage.
Comment 18 Kent Tamura 2012-05-28 19:58:46 PDT
Comment on attachment 144387 [details]
updated patch

Looks good.  Thank you!
Comment 19 WebKit Review Bot 2012-05-28 20:57:32 PDT
Comment on attachment 144387 [details]
updated patch

Clearing flags on attachment: 144387

Committed r118720: <http://trac.webkit.org/changeset/118720>
Comment 20 WebKit Review Bot 2012-05-28 20:57:38 PDT
All reviewed patches have been landed.  Closing bug.