DOM/Web Forms 2.0: Difference between revisions

From MozillaWiki
< DOM
Jump to navigation Jump to search
m (GPHemsley moved page DOM:Web Forms 2.0 to DOM/Web Forms 2.0 without leaving a redirect)
 
(34 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This page is intended as a general design page (and to a smaller extent, a roadmap) for implementing the [http://www.whatwg.org/specs/web-forms/current-work/ Web Forms 2.0] specification (WF2).  The primary tracking bug for this is [https://bugzilla.mozilla.org/show_bug.cgi?id=344614 bug 344614].
This page is intended as a general design page (and to a smaller extent, a roadmap) for implementing the [http://www.whatwg.org/specs/web-forms/current-work/ Web Forms 2.0] specification (WF2).  The primary tracking bug for this is {{bug|344614}}.


Note this page is very, very incomplete at this time.  Web Forms 2.0 is a big specification, and implementation will take time.
Note this page is very, very incomplete at this time.  Web Forms 2.0 is a big specification, and implementation will take time.
 
== Current Status ==
 
The currently preferred implementation strategy is:
 
* [[DOM:Web_Forms_2.0#Phased_Implementation|Phased Implementation]]
* Implement new attributes and methods using [[DOM:Web_Forms_2.0#JavaScript_tearoffs|JavaScript tearoffs]]
* Implement visual component of new input controls using XBL/XUL
 
<strike>We are currently waiting to verify that JavaScript tearoffs can coexist with C++ objects. If this can be verified then work will start on implementing new attributes and methods as JavaScript/XPCOM objects.</strike>
 
<strike>{{bug|383776}} is blocking the development of the visual components of Web Forms 2.0.</strike>


== Key Personnel ==
== Key Personnel ==
Line 9: Line 21:
The following people are definitely committed to working on WF2.
The following people are definitely committed to working on WF2.


* [mailto:dean@edwards.name Dean Edwards], implementer
* [mailto:ajvincent@gmail.com Alex Vincent], implementer
* [mailto:ajvincent@gmail.com Alex Vincent], implementer
* Shawn Wilsher, implementer
* Shawn Wilsher, implementer
Line 15: Line 28:
The following people may be useful resources, but have not committed yet to working on WF2.
The following people may be useful resources, but have not committed yet to working on WF2.


* Jonas Sicking
* Aaron Leventhal, accessibility guru
* Aaron Leventhal, accessibility guru
* Alexander Surkov, XForms contact
* Alexander Surkov, XForms contact
Line 23: Line 37:
== Goals For Implementation ==
== Goals For Implementation ==


We'd like to try having Web Forms 2.0 in place for the Gecko 1.9 release.  However, we anticipate reviews being a large bottleneck for this, (not to mention the sheer amount of work required) and may not have a complete implementation until Gecko 1.10.
We doubt we'll have Web Forms 2.0 in place for the Gecko 1.9 release.  We anticipate reviews being a large bottleneck for this, (not to mention the sheer amount of work required) and may not have a complete implementation until Gecko 1.10.
 
If it is reasonable, we'd like WF2 implementation to be a Gecko 1.10 goal.


There has been no decision yet on whether or not to develop this code on a branch or not.  The implementers are currently progressing on the assumption that this work will proceed on trunk.
There has been no decision yet on whether or not to develop this code on a branch or not.  The implementers are currently progressing on the assumption that this work will proceed on trunk.


== Technologies ==
== Phased Implementation ==
=== IDL ===
 
Most of the interfaces WF2 extends are from DOM Level 2 HTML.  However, these interfaces are considered '''FROZEN''' by mozilla.org, so we cannot actually modify these interfaces.
 
On the other hand, we can define new interfaces to implement the extended properties and methods.  Therefore, by convention, we plan on doing this, with each new interface prefixed by the string: "nsIDOMWF2".  (Content peers suggested prefixing with at least "nsIDOM", and we include WF2 to indicate the source of these new interfaces.)


Common form control properties and methods will be included into a nsIDOMWF2FormControl interface, for ease of reuse.  Specific form control interfaces will extend this interface.
The development will proceed in three phases:


Note that web pages must not need to QueryInterface to these interfaces in order to use their capabilities.  The properties and methods these interfaces provide and define must be available by default.
* Phase 1
** implement new <input> types (except those defined by the repetition model)
** implement the new attributes and methods for <form>, <input>, <label> and <fieldset> elements
** redefine the elements attribute of a <form> element
** implement the <datalist> and <output> elements
* Phase 2
** implement the repetition model
* Phase 3
** implement the remainder of the Web Forms 2.0 specification


==== nsIDOMWF2FormElement ====
The remainder of this document will deal only with phase 1 of this implementation.
* Contributor: Alex Vincent


* Properties and methods:
=== Phase 1 ===
** attribute DOMString accept;
* <b>Form Validation</b>
** attribute DOMString replace;
** "invalid" event
** attribute DOMString data;
** ValidityState object
** readonly attribute HTMLCollection templateElements;
** visual feedback for invalidity
** bool checkValidity();
** :invalid CSS pseudo class
** void resetFromData(in Document data);
** affects form submission
** void dispatchFormInput();
* <b>Visual Components</b>
** void dispatchFormChange();
** Visual feedback for invalidity
** XBL extensions for numeric and date/time controls
** disabled state when parent <fieldset> is disabled
** XBL extension for <input> elements with an associated <datalist>
** The XBL stuff is mostly plug & play. Most of the work here will involve tweaking the new XUL elements to accommodate WF2.
** I need to raise a series of bugs to get XUL up to speed.
* <b>NodeLists</b>
** The forms/elements/labels/selectedOptions DOM properties return NodeLists. NodeLists are live. How do we fake these using JavaScript? Do we want to fake them with JavaScript? These properties will probably be slow if implemented in JavaScript.
* <b>Form Submission</b>
** The "elements" DOM property (elements can be bound to more than one form)
** validation - should not submit invalid forms. How do we hijack submission and yet allow user scripts to trap the "submit" event also?
** There are various new formats for form submission (phase 3)
** Trapping form submission - I'm not sure how to do this. Presumably I can just trap onsubmit?
** If we support multiple bindings of elements to forms then we will need to serialize the form ourselves prior to submission.


* Status: Initial implementation (checkValidity) under review ([https://bugzilla.mozilla.org/show_bug.cgi?id=345822 bug 345822]).
== Technologies ==


==== nsIDOMWF2FormControl ====
=== JavaScript tearoffs ===
* Contributor: Alex Vincent


* Properties and methods:
The properties added to existing objects, like <input> elements will be added using tearoffs. These tearoffs are instantiated from the C++ objects QueryInterface implementation, but are implemented in JavaScript. All communication between the tearoff and outside world is done using XPCOM interfaces.
** readonly attribute boolean willValidate;
** readonly attribute nsIDOMWF2ValidityState validity;
** boolean checkValidity();
** readonly attribute DOMString validationMessage;
** void setCustomValidity(in DOMString error);


* Status: Initial implementation (willValidate, validity, checkValidity) under review ([https://bugzilla.mozilla.org/show_bug.cgi?id=345822 bug 345822]).
New elements, such as <datalist> have stub implementations in C++ which simply instantiates javascript tearoffs to implement the WF2 functionality.


==== nsIDOMWF2InputElement ====
This is the first time we've implemented tearoffs using JavaScript, which means that it's not known if it'll work or not. In theory XPCOM supports aggregation which means that it should work, but there may be unknown bugs. In particular we need to make sure that QueryInterface on the tearoff can do the right thing and return the "outer" object for the interfaces the tearoff does not directly implement.
* Contributor: Alex Vincent
* Extends nsIDOMWF2FormControl
* Properties and methods:
** readonly attribute NodeList        forms;
** attribute DOMString min;
** attribute DOMString max;
** attribute DOMString step;
** attribute DOMString pattern;
** attribute boolean required;
** attribute boolean autocomplete;
** attribute boolean autofocus;
** attribute DOMString inputmode;
** attribute DOMString action;
** attribute DOMString enctype;
** attribute DOMString method;
** attribute DOMString target;
** attribute DOMString replace;
** readonly attribute HTMLElement list;
** readonly attribute HTMLOptionElement selectedOption;
** readonly attribute RepetitionElement htmlTemplate;
** readonly attribute HTMLCollection labels;
** attribute DOMTimeStamp valueAsDate;
** attribute float valueAsNumber;
** void stepUp(in int n);
** void stepDown(in int n);
** void dispatchChange();
** void dispatchFormChange();


* Status: Initial implementation (required) under review ([https://bugzilla.mozilla.org/show_bug.cgi?id=345822 bug 345822]).
Two things are needed for this to work. First of all the constructor for the tearoff must be able to receive a pointer to the outer object when it is initially constructed. This is known to work for C++ objects, but I'm not sure how it will work for JavaScript objects. Second, the QueryInterface implementation on the tearoff must be able to call QueryInterface on the outer object. This has been done plenty before so it should be fine.


==== nsIDOMWF2ValidityState ====
Make sure that the tearoff holding on to the original element and the original element holding on to the tearoff doesn't cause memory leaks. The cycle collector should take care of this, but it needs to be tested.
* Contributor: Alex Vincent


* Properties and methods:
<b>Initial testing suggests that this is a viable solution.</b>
** readonly attribute boolean typeMismatch;
** readonly attribute boolean stepMismatch;
** readonly attribute boolean rangeUnderflow;
** readonly attribute boolean rangeOverflow;
** readonly attribute boolean tooLong;
** readonly attribute boolean patternMismatch;
** readonly attribute boolean valueMissing;
** readonly attribute boolean customError;
** readonly attribute boolean valid;


* Status: Initial implementation (valueMissing, valid) under review ([https://bugzilla.mozilla.org/show_bug.cgi?id=345822 bug 345822]).
=== IDL ===


==== nsIDOMWF2OutputElement ====
Most of the interfaces WF2 extends are from DOM Level 2 HTML.  However, these interfaces are considered '''FROZEN''' by mozilla.org, so we cannot actually modify these interfaces.
* Contributor: Alex Vincent
* Extends nsIDOMWF2FormControl
* Properties and methods:
** attribute DOMString defaultValue;
** readonly attribute HTMLFormElement form;
** readonly attribute NodeList forms;
** attribute DOMString name;
** attribute DOMString value;


* Status: Waiting for a fix to [https://bugzilla.mozilla.org/show_bug.cgi?id=345822 bug 345822] before writing patches.
On the other hand, we can define new interfaces to implement the extended properties and methods.  Therefore, by convention, we plan on doing this, with each new interface prefixed by the string: "nsIDOMWF2". (Content peers suggested prefixing with at least "nsIDOM", and we include WF2 to indicate the source of these new interfaces.)


==== nsIDOMWF2RepetitionElement ====
Common form control properties and methods will be included into a nsIDOMWF2FormControl interface, for ease of reuse.  Specific form control interfaces will extend this interface.
* Contributor: Shawn Wilsher
* Constants
** const unsigned short REPETITION_NONE = 0
** const unsigned short REPETITION_TEMPLATE = 1
** const unsigned short REPETITION_BLOCK = 2
* Properties and Methods
** attribute unsigned short repetitionType
** attribute long repetitionIndex
** readonly attribute nsIDOMElement repetitionTemplate
** readonly attribute nsIDOMHTMLCollection repetitionBlocks
** attribute unsigned long repeatStart
** attribute unsigned long repeatMin
** attribute unsigned long repeatMax
** nsIDOMElement addRepetitionBlock(in nsIDOMNode refNode)
** nsIDOMElement addRepetitionBlockByIndex(in nsIDOMNode refNode, in long index)
** void moveRepetitionBlock(in long distance)
** void removeRepetitionBlock()


* Status - Initial implementation Posted, work in progress ([https://bugzilla.mozilla.org/show_bug.cgi?id=347070 Bug 347070]).
Note that web pages must not need to QueryInterface to these interfaces in order to use their capabilities. The properties and methods these interfaces provide and define must be available by default.


==== nsIDOMRepetitionEvent ====
The interface hierarchy might end up looking like this:
* Contributor: Shawn Wilsher
* Properties and Methods
** readonly attribute nsIDOMWF2RepetitionElement element
**  void initRepetitionEvent(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in nsIDOMWF2RepetitionElement elementArg)


* Status - Initial implementation posted, ready for review? Untested. ([https://bugzilla.mozilla.org/show_bug.cgi?id=347007 Bug 347007])
* nsIWF2FormElementTearoff
  * nsIWF2FormItem                    // anything bound to a form
** nsIWF2FieldsetElementTearoff
** nsIWF2FormControl                // implements validity
*** nsIWF2InputElementTearoff
*** nsIWF2OutputElementTearoff
** nsIWF2LabelElementTearoff
* nsIWF2ValidityState


=== <s>XTF</s> ===
These are the current unsolved (by Dean) problems:
* Returning a ValidityState object from a tearoff throws this error
<tt>Error: uncaught exception: Permission denied to create wrapper for object of class UnnamedClass</tt>
* the "valueAsDate" attribute should return a JavaScript Date object. How should the IDL define this type? I'm currently using DOMTimestamp but it returns a number.


Unfortunately, as XTF applies to new namespaces and Web Forms 2 lives exclusively in HTML and XHTML, XTF is not very useful for Web Forms 2.0.
=== XBL/XUL ===
{{bug|344614}} has been fixed. However there are still some rendering issues.
[picture]
There is also a potential problem with XUL using <html:input> elements under the hood to implement <xul:textbox>. This can lead to infinite recursion.


=== XBL ===
We will use the following XUL elements.


Everyone agrees as much of this implementation should be written in XBL as possible.  However, XBL 1 cannot always guarantee a binding will apply.  In particular, the display: none; style rule will disable a XBL 1 binding from applying.
==== <xul:datepicker> ====
This handles most of the functionality we need. It would be nice if it could handle ISO formats as that is what WF2 uses but it is not difficult to map between the XUL format and the ISO format.


As a general rule of thumb (from Jonas Sicking), anonymous content can be done in XBL 1, but not implementation or event handlers.
There are a number of other niggles which I'm sure are easy to fix:
* The <datepicker> does not look like regular O/S chrome
* Its spin buttons do not like the other XUL spin buttons
* There is no way to scroll by year
* There is no highlighting of days as you move the mouse over the control
* It is not accessible by keyboard
* There is an annoying popup of previously submitted values
* There is an occasional bug whereby it is sometimes impossible to click out of the datepicker.
* It would be nice if we could define a range of selection (day, week, month). We could then use it for <input type="week|month">.
* When using the spin controls, the field (day, month or year) that is being changed should be highlighted so that the user knows which field the spin control is affecting.


XBL 2 suffers from the same drawbacks.  CSS properties (binding) can be overridden.  HTML documents would have to include a processing instruction (&lt;?xbl ?&gt;) or the binding element. Most critically, any XBL2 binding can be undone via the removeBinding() method, and there is no apparent way in XBL2 to prevent the binding from falling off the bound element.
==== <xul:timepicker> ====
The spin controls suffer the same drawback as outlined in the last bullet point above. Otherwise, this control works very well.


Note we would reconsider in a heartbeat if there was some way to attach a binding in a way where it could not be detached, for any version of XBL.
==== <xul:textbox> ====
Particularly for <input type="number">.


=== DHTML Behaviors ===
==== <xul:spinbuttons> ====
These seem to work fine. We may need to implement <input type="month" with this or use a modified <xul:datepicker>.


* https://sourceforge.net/projects/wf2/
==== <xul:scale> ====
 
This works seamlessly.
This has not been actively explored yet.  It may be feasible, but for the same reasons XBL is not suitable, this may not be acceptable to content peers.
 
=== C++ ===
 
Extensions to current elements will require new DOM implementation code.  For instance, the pattern and required attributes of HTMLInputElement must be implemented in HTMLInputElement.cpp, in order for existing types (such as "text") to support them.
 
Objects which are properties of native elements (such as the validity state object) will also likely be implemented in C++.  There is no place for these to be defined in any other way, except possibly as XPCOM components, and that is probably not necessary or desirable for HTML DOM code.
 
For new elements, no irreversible decisions have been made yet (see the sections on XBL and DHTML Behaviors above).
 
=== XForms ===
 
Wherever it is practical, we'd like to share common code with the XForms extension ([https://bugzilla.mozilla.org/show_bug.cgi?id=344655 bug 344655]).  No one has yet done a formal analysis of where such code sharing might take place, or where it should be placed in our CVS repository.
 
Web Forms 2.0 cannot depend on XForms, however, as XForms is an extension, not built by default.  XForms also depends on schema-validation, another extension not built by default.  Neither are in core code, so they cannot be used as dependencies for core code.


== New objects ==
== New objects ==
=== DOMWF2ValidityState ===
=== DOMWF2ValidityState ===
* Contributor: Alex Vincent
This object will be implemented as a JavaScript XPCOM object. There is some initial difficulty returning this property as part of a tearoff.
 
We're starting with a basic implementation for [https://bugzilla.mozilla.org/show_bug.cgi?id=345822 bug 345822], and we'll build on it from there.


== New events ==
== New events ==
=== RepetitionEvent ===
=== RepetitionEvent ===
* Contributor: Shawn Wilsher
* Contributor: Shawn Wilsher
* Implementation: [https://bugzilla.mozilla.org/show_bug.cgi?id=347007 bug 347007]
* Implementation: {{bug|347007}}


== New elements ==
== New elements ==
=== &lt;html:repeat&gt; ===
=== <anyNS:anyELM repeat="template | #"> ===
* Contributor: Shawn Wilsher
This will be implemented in phase 2.
* Implementation: [https://bugzilla.mozilla.org/show_bug.cgi?id=347070 bug 347070]
* Accessibility
* Accessibility


=== &lt;html:output&gt; ===
=== <html:datalist> ===
* Contributor: Alex Vincent
This will be implemented in a similar way to <input> elements. A JavaScript tearoff will manage its DOM properties and methods. The element has no special attributes or methods.
* Implementation: [https://bugzilla.mozilla.org/show_bug.cgi?id=346485 bug 346485]
 
* Accessibility
* Accessibility
This element is not visible to the user.


== New input types ==
=== <html:output> ===
=== &lt;html:input type='number'&gt; ===
This will be implemented in a similar way to <input> elements. A JavaScript tearoff will manage its DOM properties and methods. The element has no special attributes or methods but *must* appear in its form's elements collection. This will mean messing with the elements attribute for a <form>.
* Implementation: [https://bugzilla.mozilla.org/show_bug.cgi?id=344616 bug 344616]
 
We can probably adopt an interface similar to the recently checked in &lt;xul:numberbox&gt;, or even use it via CSS for an anonymous layout.
 
It's not entirely clear how to make HTMLInputElement accept a custom binding for anonymous content (see [https://bugzilla.mozilla.org/show_bug.cgi?id=344615#c1 bug 344615 comment 1] for details).


* Accessibility
* Accessibility
This renders pretty much like a <span> element.


=== &lt;html:input type='uri'&gt; ===
== Changes to HTMLInputElement ==
* Contributor: Alex Vincent
* Implementation: [https://bugzilla.mozilla.org/show_bug.cgi?id=344615 bug 344615]


For this, we may just want to use NS_NewURI() to validate the value of the input.
=== Changes To Existing Properties ===
This has a disadvantage of not allowing for URI's which we don't support but WF2 allows.  The alternative, which I don't quite know how to do, is to validate the value by RFC 3987, as WF2 states.
{| border="1" cellpadding="5" cellspacing="0" align="left" width="100%"
|-
! style="background:#DDD;color:#000" | Property
! style="background:#DDD;color:#000" | Comments
|-
| form || <input> elements can now be bound to more than one form. The form property should refer to the first bound form. If we implement the "forms" property then we must override this property
|-
| type || we *must* override this property. The standard DOM property returns "text" for unknown types. All of the WF2 types are unknown to the underlying cpp implementation
|}
=== New Properties ===
{| border="1" cellpadding="5" cellspacing="0" align="left" width="100%"
|-
! style="background:#DDD;color:#000" | Property
! style="background:#DDD;color:#000" | Comments
|-
| forms || implementable as an array or "fake" NodeList
|-
| min || implementable
|-
| max || implementable
|-
| step || implementable
|-
| pattern || implementable
|-
| autocomplete || is this already implemented?
|-
| autofocus || implementable (by XBL)
|-
| inputmode || ?
|-
| action || ?
|-
| enctype || ?
|-
| method || ?
|-
| target || ?
|-
| replace || ?
|-
| list || implementable (in conjunction with <datalist>)
|-
| selectedOptions || implementable as an array or "fake" NodeList
|-
| htmlTemplate || implemented in phase 2
|-
| labels || implementable as an array or "fake" NodeList. We only need to implement this if we also implement the changes to the <label> element
|-
| valueAsDate || Not sure what to define this as in IDL. How do I return a JavaScript Date object?
|-
| valueAsNumber || implementable
|-
| willValidate || implementable
|-
| validity || implementable but I am having difficulty getting XPCOM to return the right interface
|-
| validationMessage || implementable, requires localization of default messages
|}
A "?" in the comments means that I have not investigated this attribute yet. They are potentially all "phase 3" developments.
{| border="1" cellpadding="5" cellspacing="0" align="left" width="100%"
|-
! style="background:#DDD;color:#000" | Method
! style="background:#DDD;color:#000" | Comments
|-
| checkValidity || implementable
|-
| dispatchChange || implementable
|-
| dispatchFormChange || implementable
|}
=== Comments ===


It may be best to allow both - default to NS_NewURI first, then validate by RFC 3987 if that fails.
Attributes that return NodeLists will have to return JavaScript NodeLists or these attributes will have to be defined in cpp.


It's not entirely clear how to make HTMLInputElement accept a custom binding for anonymous content (see bug 344615 comment 1 for details).
=== <html:input type="number"> ===
 
* Accessibility
** Suggested appearance: Perhaps a button to the side of the text input with a browser icon (globe with arrow?) and alternate text of "Web browser" or "Get URL", which opens up a miniature, stripped-down browser (not a tabbrowser).  The URL field of the dialog will then become the value of the input.


=== &lt;html:input type='range'&gt; ===
Maps to XUL element: <xul:textbox type="number">.
* Implementation: [https://bugzilla.mozilla.org/show_bug.cgi?id=344618 bug 344618]
This requires either a slight fix to numberbox.xml or a larger fix to textbox.xml.xml to prevent infinite recursion for <input type="number">. This is because XUL textboxes inherit the "type" attribute.


* Accessibility
* Accessibility


=== &lt;html:input&gt; date/time inputs ===
=== <html:input type="email|url"> ===
* Ideally, we'd like to reuse code the XForms contributors and [http://www.xulplanet.com/ndeakin/article/357 Neil Deakin's datepicker] have already done.


* Accessibility
For this, we may just want to use NS_NewURI() to validate the value of the input. This has a disadvantage of not allowing for URI's which we don't support but WF2 allows.  The alternative, which I don't quite know how to do, is to validate the value by RFC 3987, as WF2 states.


== New input attributes ==
It may be best to allow both - default to NS_NewURI first, then validate by RFC 3987 if that fails.
=== pattern ===
* Contributor: Alex Vincent
* Implementation: [https://bugzilla.mozilla.org/show_bug.cgi?id=345512 bug 345512]


This one depends on getting ECMAScript 3rd Ed. regular expressions exposed to C++ core code ([https://bugzilla.mozilla.org/show_bug.cgi?id=348642 bug 348642]).  Until that lands, there's not much that can be done for this.
We need a way to validate urls and email addresses.


* Accessibility
* Accessibility
** Suggested appearance (Alex): Perhaps a button to the side of the text input with a browser icon (globe with arrow?) and alternate text of "Web browser" or "Get URL", which opens up a miniature, stripped-down browser (not a tabbrowser).  The URL field of the dialog will then become the value of the input.


=== required ===
=== <html:input type="range"> ===
* Contributor: Alex Vincent
* Implementation: [https://bugzilla.mozilla.org/show_bug.cgi?id=345822 bug 345822]


This is the first aspect of Web Forms 2 I (ajvincent) am attempting to implement.  By this, I intend to lay the framework for most other extensions to the already-existing form controls.
Maps to XUL element: <xul:scale>.


I'm tying in the implementation of this along with the ValidityState object implementation; this attribute's implementation requires ValidityState's valueMissing implementation, and ValidityState will not get checked in without something that uses it.
=== <html:input type="date|time|datetime|datetime-local|week|month"> ===
For most of these controls we can map to the XUL elements <xul:datepicker> and/or <xul:timepicker>. <input type="week"> requires a change to <xul:datepicker> to allow range selection. <input type="month"> would probably be best implemented with a modified <xul:datepicker> but could be implemented using <xul:spinbuttons>.


* Accessibility
* Accessibility
** Suggested accessibility icon: A red asterisk, to the right of the upper right corner of the control. Done as an image, not actual text.


== Other styling and accessibility concerns ==
== Changes to HTMLFormElement ==
=== :invalid CSS pseudo-class ===
Implement as a JavaScript tearoff. The main change here is to intercept form submission to prevent the sending of invalid data.


* Suggested background color: #ff9999 (ajvincent)
=== Changes To Existing Properties ===
* Suggested accessibility icon: A red, bold exclamation point, to the right of the upper right corner of the control. Done as an image, not actual text.  (ajvincent)
{| border="1" cellpadding="5" cellspacing="0" align="left" width="100%"
|-
! style="background:#DDD;color:#000" | Property
! style="background:#DDD;color:#000" | Comments
|-
| elements || <input> elements can now be bound to more than one form. The elements collection should include all of the elements bound to it. It should also include any <output> elements. If we implement the <output> element, or the "forms" property of the <input> element, then we must override this property
|-
| length || see above
|}
=== New Properties ===
{| border="1" cellpadding="5" cellspacing="0" align="left" width="100%"
|-
! style="background:#DDD;color:#000" | Property
! style="background:#DDD;color:#000" | Comments
|-
| accept || ?
|-
| data || ?
|-
| replace || implementable (possibly phase 2 or 3)?
|}
   
A "?" in the comments means that I have not investigated this attribute yet. They are potentially all "phase 3" developments.
   
=== New Methods ===
{| border="1" cellpadding="5" cellspacing="0" align="left" width="100%"
|-
! style="background:#DDD;color:#000" | Method
! style="background:#DDD;color:#000" | Comments
|-
| checkValidity || implementable
|-
| dispatchFormChange || implementable
|-
| dispatchFormInput || implementable
|-
| resetFromData || implementable (possibly phase 2 or 3)?
|}
== Changes to HTMLFieldsetElement ==
Implement as a JavaScript tearoff.


=== Icon sizes and constraints ===
The Web Forms 2.0 specification adds a "disabled" property to <html:fieldset>. This will require an additional XBL binding for descendant <html:input> elements so that they can also be disabled.


With a combination of attributes and CSS pseudo-classes, we could end up with several icons for one control. Imagine:
== Changes to HTMLLabelElement ==
Implement as a JavaScript tearoff. If we implement these changes then we need to implement the "labels" property for the <input> element. Labels also have form/forms properties.


&lt;html:input type='uri' required='required' pattern='http://.*' value='foo'/&gt;
There is no visual component.


Already this implies ''four'' icons to the right of the control:  a URI search button, an asterisk icon for the required attribute, another icon for the pattern, and an exclamation point icon for the invalid value.  With more and more WF2 attributes implemented, this could get interesting.
== Security ==
 
Can someone who knows something about security write something here please? :-)
As a result, all icons should probably be square (suggest 12 px by 12 px for now).  When an icon isn't required, it should probably disappear and the space it occupied collapse.  (Is there an accessibility constraint against this? Will the box size change irritate end-users?)


== QA & Testing ==
== QA & Testing ==


=== http://webforms2.testsuite.org ===
http://webforms2.testsuite.org
 
== Bonus:  Extensions to XUL from WF2 ==
 
Because many XUL controls are largely derived from HTML form controls, we will be able to add new capabilities to XUL controls as they are added to baseline HTML form controls.

Latest revision as of 01:54, 12 May 2015

This page is intended as a general design page (and to a smaller extent, a roadmap) for implementing the Web Forms 2.0 specification (WF2). The primary tracking bug for this is bug 344614.

Note this page is very, very incomplete at this time. Web Forms 2.0 is a big specification, and implementation will take time.

Current Status

The currently preferred implementation strategy is:

We are currently waiting to verify that JavaScript tearoffs can coexist with C++ objects. If this can be verified then work will start on implementing new attributes and methods as JavaScript/XPCOM objects.

bug 383776 is blocking the development of the visual components of Web Forms 2.0.

Key Personnel

It takes a village...

The following people are definitely committed to working on WF2.

The following people may be useful resources, but have not committed yet to working on WF2.

  • Jonas Sicking
  • Aaron Leventhal, accessibility guru
  • Alexander Surkov, XForms contact
  • Neil Rashbrook, XUL guru

For review and module ownership purposes, Web Forms 2.0 work is currently considered a part of the Document Object Model module. The owners and peers of this module are also helpful references, but they have not actively committed to working on WF2.

Goals For Implementation

We doubt we'll have Web Forms 2.0 in place for the Gecko 1.9 release. We anticipate reviews being a large bottleneck for this, (not to mention the sheer amount of work required) and may not have a complete implementation until Gecko 1.10.

If it is reasonable, we'd like WF2 implementation to be a Gecko 1.10 goal.

There has been no decision yet on whether or not to develop this code on a branch or not. The implementers are currently progressing on the assumption that this work will proceed on trunk.

Phased Implementation

The development will proceed in three phases:

  • Phase 1
    • implement new <input> types (except those defined by the repetition model)
    • implement the new attributes and methods for <form>, <input>, <label> and <fieldset> elements
    • redefine the elements attribute of a <form> element
    • implement the <datalist> and <output> elements
  • Phase 2
    • implement the repetition model
  • Phase 3
    • implement the remainder of the Web Forms 2.0 specification

The remainder of this document will deal only with phase 1 of this implementation.

Phase 1

  • Form Validation
    • "invalid" event
    • ValidityState object
    • visual feedback for invalidity
    • :invalid CSS pseudo class
    • affects form submission
  • Visual Components
    • Visual feedback for invalidity
    • XBL extensions for numeric and date/time controls
    • disabled state when parent <fieldset> is disabled
    • XBL extension for <input> elements with an associated <datalist>
    • The XBL stuff is mostly plug & play. Most of the work here will involve tweaking the new XUL elements to accommodate WF2.
    • I need to raise a series of bugs to get XUL up to speed.
  • NodeLists
    • The forms/elements/labels/selectedOptions DOM properties return NodeLists. NodeLists are live. How do we fake these using JavaScript? Do we want to fake them with JavaScript? These properties will probably be slow if implemented in JavaScript.
  • Form Submission
    • The "elements" DOM property (elements can be bound to more than one form)
    • validation - should not submit invalid forms. How do we hijack submission and yet allow user scripts to trap the "submit" event also?
    • There are various new formats for form submission (phase 3)
    • Trapping form submission - I'm not sure how to do this. Presumably I can just trap onsubmit?
    • If we support multiple bindings of elements to forms then we will need to serialize the form ourselves prior to submission.

Technologies

JavaScript tearoffs

The properties added to existing objects, like <input> elements will be added using tearoffs. These tearoffs are instantiated from the C++ objects QueryInterface implementation, but are implemented in JavaScript. All communication between the tearoff and outside world is done using XPCOM interfaces.

New elements, such as <datalist> have stub implementations in C++ which simply instantiates javascript tearoffs to implement the WF2 functionality.

This is the first time we've implemented tearoffs using JavaScript, which means that it's not known if it'll work or not. In theory XPCOM supports aggregation which means that it should work, but there may be unknown bugs. In particular we need to make sure that QueryInterface on the tearoff can do the right thing and return the "outer" object for the interfaces the tearoff does not directly implement.

Two things are needed for this to work. First of all the constructor for the tearoff must be able to receive a pointer to the outer object when it is initially constructed. This is known to work for C++ objects, but I'm not sure how it will work for JavaScript objects. Second, the QueryInterface implementation on the tearoff must be able to call QueryInterface on the outer object. This has been done plenty before so it should be fine.

Make sure that the tearoff holding on to the original element and the original element holding on to the tearoff doesn't cause memory leaks. The cycle collector should take care of this, but it needs to be tested.

Initial testing suggests that this is a viable solution.

IDL

Most of the interfaces WF2 extends are from DOM Level 2 HTML. However, these interfaces are considered FROZEN by mozilla.org, so we cannot actually modify these interfaces.

On the other hand, we can define new interfaces to implement the extended properties and methods. Therefore, by convention, we plan on doing this, with each new interface prefixed by the string: "nsIDOMWF2". (Content peers suggested prefixing with at least "nsIDOM", and we include WF2 to indicate the source of these new interfaces.)

Common form control properties and methods will be included into a nsIDOMWF2FormControl interface, for ease of reuse. Specific form control interfaces will extend this interface.

Note that web pages must not need to QueryInterface to these interfaces in order to use their capabilities. The properties and methods these interfaces provide and define must be available by default.

The interface hierarchy might end up looking like this:

* nsIWF2FormElementTearoff
* nsIWF2FormItem                    // anything bound to a form
** nsIWF2FieldsetElementTearoff
** nsIWF2FormControl                // implements validity
*** nsIWF2InputElementTearoff
*** nsIWF2OutputElementTearoff
** nsIWF2LabelElementTearoff
* nsIWF2ValidityState

These are the current unsolved (by Dean) problems:

  • Returning a ValidityState object from a tearoff throws this error

Error: uncaught exception: Permission denied to create wrapper for object of class UnnamedClass

  • the "valueAsDate" attribute should return a JavaScript Date object. How should the IDL define this type? I'm currently using DOMTimestamp but it returns a number.

XBL/XUL

bug 344614 has been fixed. However there are still some rendering issues. [picture] There is also a potential problem with XUL using <html:input> elements under the hood to implement <xul:textbox>. This can lead to infinite recursion.

We will use the following XUL elements.

<xul:datepicker>

This handles most of the functionality we need. It would be nice if it could handle ISO formats as that is what WF2 uses but it is not difficult to map between the XUL format and the ISO format.

There are a number of other niggles which I'm sure are easy to fix:

  • The <datepicker> does not look like regular O/S chrome
  • Its spin buttons do not like the other XUL spin buttons
  • There is no way to scroll by year
  • There is no highlighting of days as you move the mouse over the control
  • It is not accessible by keyboard
  • There is an annoying popup of previously submitted values
  • There is an occasional bug whereby it is sometimes impossible to click out of the datepicker.
  • It would be nice if we could define a range of selection (day, week, month). We could then use it for <input type="week|month">.
  • When using the spin controls, the field (day, month or year) that is being changed should be highlighted so that the user knows which field the spin control is affecting.

<xul:timepicker>

The spin controls suffer the same drawback as outlined in the last bullet point above. Otherwise, this control works very well.

<xul:textbox>

Particularly for <input type="number">.

<xul:spinbuttons>

These seem to work fine. We may need to implement <input type="month" with this or use a modified <xul:datepicker>.

<xul:scale>

This works seamlessly.

New objects

DOMWF2ValidityState

This object will be implemented as a JavaScript XPCOM object. There is some initial difficulty returning this property as part of a tearoff.

New events

RepetitionEvent

  • Contributor: Shawn Wilsher
  • Implementation: bug 347007

New elements

<anyNS:anyELM repeat="template | #">

This will be implemented in phase 2.

  • Accessibility

<html:datalist>

This will be implemented in a similar way to <input> elements. A JavaScript tearoff will manage its DOM properties and methods. The element has no special attributes or methods.

  • Accessibility

This element is not visible to the user.

<html:output>

This will be implemented in a similar way to <input> elements. A JavaScript tearoff will manage its DOM properties and methods. The element has no special attributes or methods but *must* appear in its form's elements collection. This will mean messing with the elements attribute for a <form>.

  • Accessibility

This renders pretty much like a element.

Changes to HTMLInputElement

Changes To Existing Properties

Property Comments
form <input> elements can now be bound to more than one form. The form property should refer to the first bound form. If we implement the "forms" property then we must override this property
type we *must* override this property. The standard DOM property returns "text" for unknown types. All of the WF2 types are unknown to the underlying cpp implementation

New Properties

Property Comments
forms implementable as an array or "fake" NodeList
min implementable
max implementable
step implementable
pattern implementable
autocomplete is this already implemented?
autofocus implementable (by XBL)
inputmode ?
action ?
enctype ?
method ?
target ?
replace ?
list implementable (in conjunction with <datalist>)
selectedOptions implementable as an array or "fake" NodeList
htmlTemplate implemented in phase 2
labels implementable as an array or "fake" NodeList. We only need to implement this if we also implement the changes to the <label> element
valueAsDate Not sure what to define this as in IDL. How do I return a JavaScript Date object?
valueAsNumber implementable
willValidate implementable
validity implementable but I am having difficulty getting XPCOM to return the right interface
validationMessage implementable, requires localization of default messages

A "?" in the comments means that I have not investigated this attribute yet. They are potentially all "phase 3" developments.

Method Comments
checkValidity implementable
dispatchChange implementable
dispatchFormChange implementable

Comments

Attributes that return NodeLists will have to return JavaScript NodeLists or these attributes will have to be defined in cpp.

<html:input type="number">

Maps to XUL element: <xul:textbox type="number">. This requires either a slight fix to numberbox.xml or a larger fix to textbox.xml.xml to prevent infinite recursion for <input type="number">. This is because XUL textboxes inherit the "type" attribute.

  • Accessibility

<html:input type="email|url">

For this, we may just want to use NS_NewURI() to validate the value of the input. This has a disadvantage of not allowing for URI's which we don't support but WF2 allows. The alternative, which I don't quite know how to do, is to validate the value by RFC 3987, as WF2 states.

It may be best to allow both - default to NS_NewURI first, then validate by RFC 3987 if that fails.

We need a way to validate urls and email addresses.

  • Accessibility
    • Suggested appearance (Alex): Perhaps a button to the side of the text input with a browser icon (globe with arrow?) and alternate text of "Web browser" or "Get URL", which opens up a miniature, stripped-down browser (not a tabbrowser). The URL field of the dialog will then become the value of the input.

<html:input type="range">

Maps to XUL element: <xul:scale>.

<html:input type="date|time|datetime|datetime-local|week|month">

For most of these controls we can map to the XUL elements <xul:datepicker> and/or <xul:timepicker>. <input type="week"> requires a change to <xul:datepicker> to allow range selection. <input type="month"> would probably be best implemented with a modified <xul:datepicker> but could be implemented using <xul:spinbuttons>.

  • Accessibility

Changes to HTMLFormElement

Implement as a JavaScript tearoff. The main change here is to intercept form submission to prevent the sending of invalid data.

Changes To Existing Properties

Property Comments
elements <input> elements can now be bound to more than one form. The elements collection should include all of the elements bound to it. It should also include any <output> elements. If we implement the <output> element, or the "forms" property of the <input> element, then we must override this property
length see above

New Properties

Property Comments
accept ?
data ?
replace implementable (possibly phase 2 or 3)?

A "?" in the comments means that I have not investigated this attribute yet. They are potentially all "phase 3" developments.

New Methods

Method Comments
checkValidity implementable
dispatchFormChange implementable
dispatchFormInput implementable
resetFromData implementable (possibly phase 2 or 3)?

Changes to HTMLFieldsetElement

Implement as a JavaScript tearoff.

The Web Forms 2.0 specification adds a "disabled" property to <html:fieldset>. This will require an additional XBL binding for descendant <html:input> elements so that they can also be disabled.

Changes to HTMLLabelElement

Implement as a JavaScript tearoff. If we implement these changes then we need to implement the "labels" property for the <input> element. Labels also have form/forms properties.

There is no visual component.

Security

Can someone who knows something about security write something here please? :-)

QA & Testing

http://webforms2.testsuite.org