EventAn Event object is simply named an event. It allows for
signaling that something has occurred, e.g., that an image has completed downloading.
Each event has the following associated flags that are all initially unset:
The stopPropagation() method steps are to set
this’s stop propagation flag.
The cancelBubble getter steps are to return true if
this’s stop propagation flag is set; otherwise false.
The cancelBubble setter steps are to set this’s stop propagation flag if
the given value is true; otherwise do nothing.
The stopImmediatePropagation() method steps are to set
this’s stop propagation flag and this’s
stop immediate propagation flag.
To initialize an event, with type, bubbles, and cancelable, run these steps:
Set event’s initialized flag.
Unset event’s stop propagation flag, stop immediate propagation flag, and canceled flag.
Set event’s isTrusted attribute to false.
Set event’s target to null.
Set event’s type attribute to type.
Set event’s bubbles attribute to bubbles.
Set event’s cancelable attribute to cancelable.
To dispatch an event event to an
EventTarget object target, with an optional legacy target override flag and
an optional legacyOutputDidListenersThrowFlag:
Set event’s dispatch flag.
Let targetOverride be target, if legacy target override flag
is not given, and target’s associated Document otherwise.
[HTML]
legacy target override flag is only used by HTML and only when
target is a Window object.
Let activationTarget be null.
Let relatedTarget be the result of retargeting event’s relatedTarget against target.
Let clearTargets be false.
If target is not relatedTarget or target is event’s relatedTarget:
Let touchTargets be a new list.
For each touchTarget of event’s touch target list: append the result of retargeting touchTarget against target to touchTargets.
Append to an event path with event, target, targetOverride, relatedTarget, touchTargets, and false.
Let isActivationEvent be true, if event is a MouseEvent object
and event’s type attribute is "click"; otherwise false.
If isActivationEvent is true and target has activation behavior, then set activationTarget to target.
Let slottable be target, if target is a slottable and is assigned, and null otherwise.
Let slotInClosedTree be false.
Let parent be the result of invoking target’s get the parent with event.
While parent is non-null:
If slottable is non-null:
Assert: parent is a slot.
Set slottable to null.
If parent’s root is a shadow root whose
mode is "closed", then set slotInClosedTree
to true.
If parent is a slottable and is assigned, then set slottable to parent.
Let relatedTarget be the result of retargeting event’s relatedTarget against parent.
Let touchTargets be a new list.
For each touchTarget of event’s touch target list: append the result of retargeting touchTarget against parent to touchTargets.
If parent is a Window object, or parent is a node
and target’s root is a shadow-including inclusive ancestor
of parent:
If isActivationEvent is true, event’s bubbles
attribute is true, activationTarget is null, and parent has
activation behavior, then set activationTarget to
parent.
Append to an event path with event, parent, null, relatedTarget, touchTargets, and slotInClosedTree.
Otherwise, if parent is relatedTarget, then set parent to null.
Otherwise:
Set target to parent.
If isActivationEvent is true, activationTarget is null, and target has activation behavior, then set activationTarget to target.
Append to an event path with event, parent, target, relatedTarget, touchTargets, and slotInClosedTree.
If parent is non-null, then set parent to the result of invoking parent’s get the parent with event.
Set slotInClosedTree to false.
Let clearTargetsItem be the last event path item in event’s path whose shadow-adjusted target is non-null.
If clearTargetsItem’s shadow-adjusted target,
clearTargetsItem’s relatedTarget, or an EventTarget object
in clearTargetsItem’s touch target list is a node
whose root is a shadow root: set clearTargets to true.
If activationTarget is non-null and activationTarget has legacy-pre-activation behavior, then run activationTarget’s legacy-pre-activation behavior.
For each item of event’s path, in reverse order:
If item’s shadow-adjusted target is non-null, then
set event’s eventPhase attribute to AT_TARGET.
Otherwise, set event’s eventPhase attribute to
CAPTURING_PHASE.
Invoke with item, event, "capturing", and
legacyOutputDidListenersThrowFlag if given.
For each item of event’s path:
If item’s shadow-adjusted target is non-null, then
set event’s eventPhase attribute to AT_TARGET.
Otherwise:
Set event’s eventPhase attribute to BUBBLING_PHASE.
Invoke with item, event, "bubbling", and
legacyOutputDidListenersThrowFlag if given.
Set event’s eventPhase attribute to NONE.
Set event’s currentTarget attribute to null.
Set event’s path to the empty list.
Unset event’s dispatch flag, stop propagation flag, and stop immediate propagation flag.
If clearTargets is true:
Set event’s target to null.
Set event’s relatedTarget to null.
Set event’s touch target list to the empty list.
If activationTarget is non-null:
If event’s canceled flag is unset, then run activationTarget’s activation behavior with event.
Otherwise, if activationTarget has legacy-canceled-activation behavior, then run activationTarget’s legacy-canceled-activation behavior.
Return false if event’s canceled flag is set; otherwise true.
Nodes are objects that implement Node.
Nodes participate in a tree, which is known as the
node tree.
NodeEach node has an associated node document, set upon creation, that is a document.
To create a node that implements an interface interface, given a document document:
Assert: interface is neither Document nor an interface that
inherits from Document. To create a document, use
create a document instead.
Return a new node that implements interface, in document’s relevant realm, with its node document set to document.
To clone a single node given a node node,
document document, and null or a CustomElementRegistry object
fallbackRegistry:
Let copy be null.
If node is an element:
Let registry be node’s custom element registry.
If registry is null, then set registry to fallbackRegistry.
If registry is a global custom element registry, then set registry to document’s custom element registry’s effective global custom element registry.
Set copy to the result of creating an element, given
document, node’s local name, node’s
namespace, node’s namespace prefix,
node’s is value, false, and registry.
For each attribute of node’s attribute list:
Let copyAttribute be the result of cloning a single node given attribute, document, and null.
Append copyAttribute to copy.
Otherwise, if node is a document, set copy to the result of creating a document that implements the same interfaces as node, given document’s relevant realm.
Otherwise, set copy to the result of creating a node that implements the same interfaces as node, given document.
Fulfill these additional requirements, switching on the interface node implements:
Document
Set copy’s encoding, content type, URL, origin, type, mode, and allow declarative shadow roots, to those of node.
If node’s custom element registry’s is scoped is true, then set copy’s custom element registry to node’s custom element registry.
DocumentType
Attr
Set copy’s namespace, namespace prefix, local name, and value to those of node.
Text
Comment
Set copy’s data to that of node.
ProcessingInstruction
Do nothing.
If node is a document, then set document to copy.
Set copy’s node document to document.
Return copy.
DocumentDocument nodes are simply
known as documents.
To adopt a node node into a document document:
Let oldDocument be node’s node document.
If document is not oldDocument, then for each inclusiveDescendant of node’s shadow-including inclusive descendants, in shadow-including tree order:
Set inclusiveDescendant’s node document to document.
If inclusiveDescendant is a shadow root and if any of the following are true:
inclusiveDescendant’s custom element registry is null and inclusiveDescendant’s keep custom element registry null is false; or
inclusiveDescendant’s custom element registry is a global custom element registry,
then set inclusiveDescendant’s custom element registry to document’s custom element registry’s effective global custom element registry.
Otherwise, if inclusiveDescendant is an element:
Set the node document of each attribute in inclusiveDescendant’s attribute list to document.
If inclusiveDescendant’s custom element registry is null or inclusiveDescendant’s custom element registry’s is scoped is false:
Let registry be null.
If inclusiveDescendant’s custom element registry is
non-null, inclusiveDescendant’s parent is null, or
inclusiveDescendant’s parent is an
exclusive DocumentFragment node, then set registry to
document’s custom element registry.
Otherwise, set registry to the result of looking up a custom element registry given inclusiveDescendant’s parent.
Set inclusiveDescendant’s custom element registry to registry’s effective global custom element registry.
If inclusiveDescendant is custom, then
enqueue a custom element callback reaction with inclusiveDescendant, callback
name "adoptedCallback", and « oldDocument, document ».
Run the adopting steps with inclusiveDescendant and oldDocument.
The
new DocumentFragment()
constructor steps are to set this’s node document to
current global object’s associated Document.
ElementElement nodes are simply known as
elements.
To append an attribute attribute to an element element:
Append attribute to element’s attribute list.
Set attribute’s element to element.
Set attribute’s node document to element’s node document.
Handle attribute changes for attribute with element, null, and attribute’s value.
To replace an attribute oldAttribute with an attribute newAttribute:
Let element be oldAttribute’s element.
Replace oldAttribute by newAttribute in element’s attribute list.
Set newAttribute’s element to element.
Set newAttribute’s node document to element’s node document.
Set oldAttribute’s element to null.
Handle attribute changes for oldAttribute with element, oldAttribute’s value, and newAttribute’s value.
The new Text(data)
constructor steps are to set this’s data to data and
this’s node document to current global object’s
associated Document.
The
new ProcessingInstruction(target, data)
constructor steps are:
Set this’s node document to current global object’s
associated Document.
Initialize this with target and data.
The new Comment(data)
constructor steps are to set this’s data to data and
this’s node document to current global object’s
associated Document.