DOM/Web Forms 2.0

From MozillaWiki
< DOM
Jump to: navigation, search

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