1. Introduction
1.1. Overview
UI Events is designed with two main goals. The first goal is the design of an event system which allows registration of event listeners and describes event flow through a tree structure. Additionally, the specification will provide standard modules of events for user interface control and document mutation notifications, including defined contextual information for each of these event modules.
The second goal of UI Events is to provide a common subset of the current event systems used in existing browsers. This is intended to foster interoperability of existing scripts and content. It is not expected that this goal will be met with full backwards compatibility. However, the specification attempts to achieve this when possible.
1.1.1. Mouse and Wheel Events
The Mouse Events and Wheel Events section of this specification have been moved to the Pointer Events specification [pointerevents4].
1.2. Conformance
This section is normative.
Within this specification, the key words MUST
, MUST NOT
,
REQUIRED
, SHALL
, SHALL NOT
, SHOULD
,
SHOULD NOT
, RECOMMENDED
, MAY
, and OPTIONAL
are to be interpreted as described in [RFC2119].
This specification is to be understood in the context of the DOM Level 3
Core specification [DOM-Level-3-Core] and the general considerations for DOM
implementations apply. For example, handling of namespace URIs is
discussed in
XML Namespaces.
For additional information about
conformance,
please see the DOM Level 3 Core specification [DOM-Level-3-Core]. A user
agent is not required to conform to the entirety of another
specification in order to conform to this specification, but it MUST conform
to the specific parts of any other specification which are called out in
this specification (e.g., a conforming UI Events user agent MUST
support the DOMString data type as defined in [WebIDL], but
need not support every method or data type defined in [WebIDL] in order
to conform to UI Events).
This specification defines several classes of conformance for different user agents, specifications, and content authors:
1.2.1. Web browsers and other dynamic or interactive user agents
A dynamic or interactive user agent, referred to here as a
browser
(be it a Web browser, AT (Accessibility Technology)
application, or other similar program), conforms to UI Events if it
supports:
-
the Core module defined in [DOM-Level-3-Core]
-
all the interfaces and events with their associated methods, attributes, and semantics defined in this specification with the exception of those marked as deprecated (a conforming user agent MAY implement the deprecated interfaces, events, or APIs for backwards compatibility, but is not required to do so in order to be conforming)
-
the complete set of
keyandcodevalues defined in [UIEvents-Key] and [UIEvents-Code] (subject to platform availability), and -
all other normative requirements defined in this specification.
A conforming browser MUST dispatch events appropriate to the
given EventTarget when the conditions defined for that event
type have been met.
A browser conforms specifically to UI Events if it implements the interfaces and related event types specified in this document.
A conforming browser MUST support scripting, declarative interactivity, or some other means of detecting and dispatching events in the manner described by this specification, and MUST support the APIs specified for that event type.
In addition to meeting all other conformance criteria, a conforming browser MAY implement features of this specification marked as deprecated, for backwards compatibility with existing content, but such implementation is discouraged.
A conforming browser MAY also support features not found in this specification, but which use the interfaces, events, or other features defined in this specification, and MAY implement additional interfaces and event types appropriate to that implementation. Such features can be later standardized in future specifications.
A browser which does not conform to all required portions of this specification MUST NOT claim conformance to UI Events. Such an implementation which does conform to portions of this specification MAY claim conformance to those specific portions.
A conforming browser MUST also be a conforming implementation of the IDL fragments in this specification, as described in the Web IDL specification [WebIDL].
1.2.2. Authoring tools
A content authoring tool conforms to UI Events if it produces content which uses the event types, consistent in a manner as defined in this specification.
A content authoring tool MUST NOT claim conformance to UI Events for content it produces which uses features of this specification marked as deprecated in this specification.
A conforming content authoring tool SHOULD provide to the content author a means to use all event types and interfaces appropriate to all host languages in the content document being produced.
1.2.3. Content authors and content
A content author creates conforming UI Events content if that content uses the event types consistent in a manner as defined in this specification.
A content author SHOULD NOT use features of this specification marked as deprecated, but SHOULD rely instead upon replacement mechanisms defined in this specification and elsewhere.
Conforming content MUST use the semantics of the interfaces and event types as described in this specification.
Content authors are advised to follow best practices as described in accessibility and internationalization guideline specifications.
1.2.4. Specifications and host languages
A specification or host language conforms to UI Events if it references and uses the event flow mechanism, interfaces, events, or other features defined in [DOM], and does not extend these features in incompatible ways.
A specification or host language conforms specifically to UI Events if it references and uses the interfaces and related event types specified in this document. A conforming specification MAY define additional interfaces and event types appropriate to that specification, or MAY extend the UI Events interfaces and event types in a manner that does not contradict or conflict with the definitions of those interfaces and event types in this specification.
Specifications or host languages which reference UI Events SHOULD NOT use or recommend features of this specification marked as deprecated, but SHOULD use or recommend the indicated replacement for that the feature (if available).
2. Stylistic Conventions
This specification follows the Proposed W3C Specification Conventions, with the following supplemental additions:
-
The key cap printed on a key is shown as
↓,=orQ. This is used to refer to a key from the user’s perspective without regard for thekeyandcodevalues in the generatedKeyboardEvent. -
Glyphs representing character are shown as:
"𣧂". -
Unicode character encodings are shown as:
U+003d. -
Names of key values generated by a key press (i.e., the value of
KeyboardEvent.key) are shown as:"ArrowDown","=","q"or"Q". -
Names of key codes associated with the physical keys (i.e., the value of
KeyboardEvent.code) are shown as:"ArrowDown","Equal"or"KeyQ".
In addition, certain terms are used in this specification with particular
meanings. The term implementation
applies to a browser, content
authoring tool, or other user agent that implements this specification,
while a content author is a person who writes script or code that takes
advantage of the interfaces, methods, attributes, events, and other features
described in this specification in order to make Web applications, and a user is
the person who uses those Web applications in an implementation.
And finally:
This is a note.
This is an open issue.
This is a warning.
interface Example {
// This is an IDL definition.
};
3. Basic Event Interfaces
The basic event interfaces defined in [DOM] are fundamental to UI Events. These basic event interfaces MUST always be supported by the implementation:
-
The
Eventinterface and its following constants, methods and attributes:-
NONEconstant -
CAPTURING_PHASEconstant -
AT_TARGETconstant -
BUBBLING_PHASEconstant -
typeattribute -
targetattribute -
currentTargetattribute -
eventPhaseattribute -
bubblesattribute -
cancelableattribute -
composedattribute -
timeStampattribute -
defaultPreventedattribute -
isTrustedattribute -
stopPropagation()method -
stopImmediatePropagation()method -
preventDefault()method -
initEvent()method
-
-
The
CustomEventinterface and its following method and attribute:-
initCustomEvent()method -
detailattribute
-
-
The
EventTargetinterface and its following methods:-
addEventListener()method -
removeEventListener()method -
dispatchEvent()method
-
-
The
EventListenerinterface and itshandleEvent()method -
The
Documentinterface’screateEvent()method
The event types defined in this specification derive from these basic interfaces, and MUST inherit all of the attributes, methods, and constants of the interfaces they derive from.
The following chart describes the inheritance structure of the interfaces described in this specification.
3.1. List of Event Types
Each event MUST be associated with a type, called event type and
available as the type attribute on the event object. The event
type MUST be of type DOMString.
Depending on the level of DOM support, or the devices used for display (e.g., screen) or interaction (e.g., mouse, keyboard, touch screen, or voice), these event types can be generated by the implementation. When used with an [XML] or [HTML5] application, the specifications of those languages MAY restrict the semantics and scope (in particular the possible event targets) associated with an event type. Refer to the specification defining the language used in order to find those restrictions or to find event types that are not defined in this document.
The following table provides an informative summary of the event types described in this specification.
| Event Type | Sync / Async | Bubbling Phase | Trusted event target types | DOM Interface | Cancelable | Default Action |
|---|---|---|---|---|---|---|
abort
| Sync | No | Window, Element | Event
| No | None |
beforeinput
| Sync | Yes | Element | InputEvent
| Yes | Update the DOM element |
blur
| Sync | No | Window, Element | FocusEvent
| No | None |
compositionstart
| Sync | Yes | Element | CompositionEvent
| Yes | Show a text composition system candidate window |
compositionupdate
| Sync | Yes | Element | CompositionEvent
| No | None |
compositionend
| Sync | Yes | Element | CompositionEvent
| No | None |
error
| Async | No | Window, Element | Event
| No | None |
focus
| Sync | No | Window, Element | FocusEvent
| No | None |
focusin
| Sync | Yes | Window, Element | FocusEvent
| No | None |
focusout
| Sync | Yes | Window, Element | FocusEvent
| No | None |
input
| Sync | Yes | Element | InputEvent
| No | None |
keydown
| Sync | Yes | Element | KeyboardEvent
| Yes | Varies: trigger beforeinput and input events; launch text composition system; blur and focus events; keypress event (if supported); activation behavior; other events
|
keyup
| Sync | Yes | Element | KeyboardEvent
| Yes | None |
load
| Async | No | Window, Document, Element | Event
| No | None |
select
| Sync | Yes | Element | Event
| No | None |
unload
| Sync | No | Window, Document, Element | Event
| No | None |
For a list of events which are deprecated in this specification, see the Legacy Event Types appendix at the end of this document.
The following is one way to interpret the above tables: the load
event will trigger event listeners attached on Element nodes
for that event and on the capture and target phases. This event is not
cancelable. If an event listener for the load event is attached to
a node other than Window, Document, or
Element nodes, or if it is attached to the bubbling phase
only, this event listener would not be triggered.
Don’t interpret the above tables as definitive for the listed event types.
For example, the load event is used in other specifications, for
example, in XMLHttpRequest. Similarly, dispatchEvent() can
be used to dispatch untrusted events to listeners on any
object that also implements EventTarget.
The event objects associated with the event types described above contain additional context information--refer to the description of the DOM interfaces for further information.
3.2. User Interface Events
The User Interface event module contains basic event types associated with user interfaces and document manipulation.
3.2.1. Interface UIEvent
Introduced in DOM Level 2
The UIEvent interface provides specific contextual information
associated with User Interface events.
To create an instance of the UIEvent interface, use the UIEvent
constructor, passing an optional UIEventInit dictionary.
For newly defined events, you don’t have to inherit UIEvent interface just
because they are related to user interface. Inherit only when members of
UIEventInit make sense to those events.
3.2.1.1. UIEvent
[Exposed =Window ]interface :UIEvent Event {(constructor DOMString ,type optional UIEventInit = {});eventInitDict readonly attribute Window ?;view readonly attribute long ; };detail
UIEvent . view-
The
viewattribute identifies theWindowfrom which the event was generated.The un-initialized value of this attribute MUST be
null. UIEvent . detail-
Specifies some detail information about the
Event, depending on the type of event.The un-initialized value of this attribute MUST be
0.
3.2.1.2. UIEventInit
dictionary :UIEventInit EventInit {Window ?=view null ;long = 0; };detail
UIEventInit . view-
Should be initialized to the Window object of the global
environment in which this event will be dispatched. If this
event will be dispatched to an element, the view property should
be set to the Window object containing the element’s
ownerDocument. UIEventInit . detail- This value is initialized to a number that is application-specific.
3.2.2. UIEvent Algorithms
3.2.2.1. initialize a UIEvent
- Input
-
event, the
UIEventto initializeeventType, a DOMString containing the event type
eventTarget, the
EventTargetof the eventbubbles, true if this event bubbles
cancelable, true if this event is cancelable
- Output
-
None
-
Initialize the base
Eventattributes:-
Initialize an Event with event, eventType, bubbles and cancelable
-
Set event.
target= eventTarget
-
-
Initialize the following public attributes:
-
Set event.
view= the eventTarget’s node document’sWindowobject -
Set event.
detail= 0
-
-
Initialize the following historical attributes:
-
Set event.
which= 0 (used by bothMouseEventandKeyboardEvent)
-
3.2.3. UIEvent Types
The User Interface event types are listed below. Some of these events
use the UIEvent interface if generated from a user interface, but
the Event interface otherwise, as detailed in each event.
3.2.3.1. load
| Type | load
|
|---|---|
| Interface | UIEvent if generated from a user interface, Event otherwise.
|
| Sync / Async | Async |
| Bubbles | No |
| Trusted Targets | Window, Document, Element
|
| Cancelable | No |
| Default action | None |
| Context (trusted events) |
A user agent MUST dispatch this event when the DOM
implementation finishes loading the resource (such as the document)
and any dependent resources (such as images, style sheets, or
scripts). Dependent resources that fail to load MUST NOT prevent
this event from firing if the resource that loaded them is still
accessible via the DOM. If this event type is dispatched,
implementations are REQUIRED to dispatch this event at least on the
Document node.
For legacy reasons, load events for resources inside the
document (e.g., images) do not include the Window in the
propagation path in HTML implementations. See [HTML5] for more
information.
3.2.3.2. unload
| Type | unload
|
|---|---|
| Interface | UIEvent if generated from a user interface, Event otherwise.
|
| Sync / Async | Sync |
| Bubbles | No |
| Trusted Targets | Window, Document, Element
|
| Cancelable | No |
| Default action | None |
| Context (trusted events) |
A user agent MUST dispatch this event when the DOM
Implementation removes from the environment the resource (such as
the document) or any dependent resources (such as images, style
sheets, scripts). The document MUST be unloaded after the dispatch
of this event type. If this event type is dispatched,
implementations are REQUIRED to dispatch this event at least on
the Document node.
3.2.3.3. abort
| Type | abort
|
|---|---|
| Interface | UIEvent if generated from a user interface, Event otherwise.
|
| Sync / Async | Sync |
| Bubbles | No |
| Trusted Targets | Window, Element
|
| Cancelable | No |
| Default action | None |
| Context (trusted events) |
A user agent MUST dispatch this event when the loading of a resource has been aborted, such as by a user canceling the load while it is still in progress.
3.2.3.4. error
| Type | error
|
|---|---|
| Interface | UIEvent if generated from a user interface, Event otherwise.
|
| Sync / Async | Async |
| Bubbles | No |
| Trusted Targets | Window, Element
|
| Cancelable | No |
| Default action | None |
| Context (trusted events) |
A user agent MUST dispatch this event when a resource failed to load, or has been loaded but cannot be interpreted according to its semantics, such as an invalid image, a script execution error, or non-well-formed XML.
3.2.3.5. select
| Type | select
|
|---|---|
| Interface | UIEvent if generated from a user interface, Event otherwise.
|
| Sync / Async | Sync |
| Bubbles | Yes |
| Trusted Targets | Element
|
| Cancelable | No |
| Default action | None |
| Context (trusted events) |
A user agent MUST dispatch this event when a user selects some text. This event is dispatched after the selection has occurred.
This specification does not provide contextual information to access
the selected text. Where applicable, a host language SHOULD
define rules for how a user MAY select content (with consideration
for international language conventions), at what point the
select event is dispatched, and how a content author MAY
access the user-selected content.
In order to access to user-selected content, content authors will
use native capabilities of the host languages, such as the
Document.getSelection() method of the HTML Editing APIs
[Editing].
The select event might not be available for all elements in
all languages. For example, in [HTML5], select events can
be dispatched only on form input and textarea elements.
Implementations can dispatch select events in any context
deemed appropriate, including text selections outside of form
controls, or image or markup selections such as in SVG.
3.3. Focus Events
This interface and its associated event types and § 3.3.2 Focus Event Order were designed in accordance to the concepts and guidelines defined in User Agent Accessibility Guidelines 2.0 [UAAG20], with particular attention on the focus mechanism and the terms defined in the glossary entry for focus.
3.3.1. Interface FocusEvent
Introduced in this specification
The FocusEvent interface provides specific contextual information
associated with Focus events.
To create an instance of the FocusEvent interface, use the
FocusEvent constructor, passing an optional FocusEventInit dictionary.
3.3.1.1. FocusEvent
[Exposed =Window ]interface :FocusEvent UIEvent {(constructor DOMString ,type optional FocusEventInit = {});eventInitDict readonly attribute EventTarget ?; };relatedTarget
FocusEvent . relatedTarget-
Used to identify a secondary
EventTargetrelated to a Focus event, depending on the type of event.For security reasons with nested browsing contexts, when tabbing into or out of a nested context, the relevant
EventTargetSHOULD benull.The un-initialized value of this attribute MUST be
null.
3.3.1.2. FocusEventInit
dictionary