In each algorithm in this section, the Window must be treated as if it were the parent node of the document — so that the Window can also receive events.
When an event is distributed into a shadow tree, its path either passes through shadow trees or ends at the shadow root. The only exception is change events (mutations). These types of events should never be distributed into a shadow tree.
5.1 Always stopped events
The following events should always be stopped at the lowest shadow root:
● abort
● error
● select
● change
● load
● reset
● resize
● scroll
● selectstart
The exact algorithm will be given below.
5.2 Ways of events
To determine the event path, it is necessary to use the event path calculation algorithm, which consists in performing the following actions:
Input
KNOT, node
EVENT, event (event)
Conclusion
PATH, event path, ordered list of event targets.
1. The PATH should be an empty ordered list.
2. THE CURRENT ITEM MUST BE A NODE
3. Repeat until CURRENT ELEMENT exists:
1. Add POWER ON POINT
2. If the final points of the CURRENT ELEMENT are not empty:
1. Add each switching point to the final switching points of the CURRENT ELEMENT, from the first, including, to the last, exclusive, to the PATH.
2 ... THE CURRENT ITEM must be the final destination of the CURRENT ITEM
3. Otherwise, if all the following conditions are met, stop this algorithm:
1. If the CURRENT ITEM is a shadow root:
2. If the CURRENT ITEM is the root node of the NODE
3. Installed scoped flag.
4. Otherwise: THE CURRENT ITEM must be a deep parent of the CURRENT ITEM.
5.3 Examples of event paths
This section is non-normative.
Suppose we have the following tree trees:
Fig. 5 Example of a tree. Nodes that are not participating in the event path in question, described below, are omitted.
● A is a document.
● E, J, N, Q, S are shadow roots.
● I, M, P, R, and U content inclusion points.
This tree of trees consists of the following six trees: one document tree and five shadow trees:
● Document tree 1. It consists of nodes A, B, C, and D.
● Shadow Tree 2 contained in B. It includes nodes E, F, G, H, and I.
● Shadow Tree 3 contained in H. It includes nodes J, K, L, and M.
● Shadow Tree 4 contained in K. It includes nodes N, O, and P.
● Shadow Tree 5 contained in O. It includes nodes Q and R.
● Shadow Tree 6 contained in F. It includes nodes S, T and U.
Let's assume that the result of the distribution of this tree is:
● Assignment of the switching points C is [I, M] (C is redistributed)
● Assignments of the switching points L is [P, R] (L is redistributed)
● The assignment points of the switch G is [U]
In this case, if the event is sent to node D, the event path will be as follows:
[D, C, I, M, L, P, R, Q, O, N, K, J, H, G, U, T, S, F, E, B, A] (Excluding Window)
Please note that the algorithm for calculating the event path is designed to achieve the following goals:
1. If there is a CENTRAL node in the event path and it has a PARENT in the node tree, the event path will also include the PARENT. PARENT always appears somewhere after a HELP in the event path.
2. Nodes along the way events form a linear chain of ancestors in each node tree. No node tree has branch points.
Fig. 6 In this figure, the number on the left of each node represents the initial position of each node in the event path. At the parent node, this figure is always greater than that of any of its descendants in each node tree.
This suggests that if we focus on one node tree and forget about all the others, the event path will look as if the event occurred only in the node tree in question. This is an important aspect in the sense that the presence of a shadow tree does not in any way affect the event path within the node tree containing the leading shadow element until the event is stopped in any of the descendant trees.
For example, from the point of view of the document tree 1, the event path should look like this: [D, C, B, A]. From the point of view of the shadow tree 2, the event path should look like [I, H, G, F, E]. Other node trees obey the same rules.
It is also worth noting that if we exclude all points of inclusion and shadow roots from the event path, the result would be equivalent to the containing ancestors of the node in the compiled tree on which the event occurs.
Fig. 7 The relationship between the event path and the constructed tree. The event path used in the example is shown in the figure on the left, and the composed tree is shown on the right. If we exclude all inclusion points and shadow roots from the event path, the result will correspond to the containing ancestors of node D in the constructed tree.
5.4 Event Forwarding
In cases where the event path passes through several node trees, the event information about its target can be adjusted depending on the order in which the encapsulation is processed. Event forwarding is the process of calculating the corresponding target elements for each ancestor of the node where the event occurs. A relative target element is the node that most accurately represents the target element of a given ancestor’s event while maintaining encapsulation.
The redirection algorithm should be used to determine relative goals and consist of the following steps:
Input
CURRENT WAY, event path
CURRENT GOAL, the node on which the event listener is triggered.
Conclusion
RELATIVE PURPOSE, adjusted target element
1. THE TREE OF THE CURRENT GOAL should be the node tree containing the CURRENT GOAL
2. THE ORIGINAL PURPOSE MUST BE THE FIRST ELEMENT IN THE WAY OF THE EVENT
3. TREE OF THE ORIGINAL PURPOSE should be the node tree containing the ORIGINAL PURPOSE
4. The TREE OF THE RELATIVE PURPOSE should be the closest common containing tree of the descendants of the TREE OF THE CURRENT GOAL and the TREE OF THE RELATIVE GOAL.
5. RELATIVE TARGET ELEMENT should be the first node in the EVENT WAY, satisfying the following conditions:
1. The node must be contained in the TREE OF THE RELATIVE TARGET ELEMENT
The redirection process must occur before the event is delivered to the element.
5.5 Redirect relatedTarget
Some events have a property relatedTarget
[DOM-Level-3-Events] , which contains a node that is not the purpose of the event, but related to it.
For example, for a mouseover event, relatedTarget may point to the node from which the mouse pointer moved to the current element. In the case when relatedTarget is in a shadow tree, the corresponding user agents should not allow leakage of its actual value beyond the limits of this tree. In cases where both the relatedTarget and the target belong to the same shadow tree, the corresponding user agents must stop the events in the shadow root to avoid the appearance of side mouseover and mouseout events from the same node at the same time.
Thus, if an event has a relatedTarget property, its value and the element that it must match must be adjusted.
The relatedTarget redirection process must occur before the event is delivered to the element.
5.6 Forwarding touch events
The Touch target attribute [TOUCH EVENTS] should be adjusted in the same way as an event with a relatedTarget. Each Touch target attribute in the TouchList list returned by a call to TouchEvent touches (), changedTouches (), and targetTouches () must be the result of executing the relative target calculation algorithm with the KNOT and Touch target as input data.
5.7 Redirect Focus Events
The focus, DOMFocusIn, blur, and DOMFocusOut events must be handled in the same way as events with relatedTarget, where a node loses focus as a result of receiving this focus by another node or event target element, which causes the node that has lost focus to become a relative target. with respect to the node that received it.
5.8 Event Transfer
At the time of the transfer event:
● The Event target and currentTarget attributes should return a relative target for the node on which the event listeners fired.
● The MouseOvent relatedTarget attribute of the event must return the corrected relative target
● The offsetX and offsetY attributes of the MouseEvent event should return the value of the origin point of the relative target, taking into account the internal indents.
● The Touch target attribute must return the adjusted relative target.
● If relatedTarget and target are the same element for a given node, event listeners should not work on it. TouchEvent does not obey this rule.
● If a node is its own relative goal, event listeners should not operate on it during the capture phase, which entails step 6 of the event transmission algorithm.
● If the node where the event listener was triggered is its own relative target, the eventPhase attribute of the event should return AT_TARGET during the ascent phase, which entails step 9 of the event transmission algorithm.
● If the value of the bubbles attribute of the event is false, the following should be done:
1. The event path must be sorted in reverse order.
2. The value of the eventPhase event attribute must be set to AT_TARGET
3. For each object in the event path, whose relative goal is equal to the object itself, the event listener must be called with the event itself as an argument until the event stop flag is disabled
After the event transfer is completed, the target and currentTarget event objects must indicate the relative target of the highest parent.
This step is necessary in order to avoid detection of nodes in the shadow tree, since it is possible for the script to transfer the event object beyond its scope.
5.9 Example of event redirection
This section is non-standard.
, , , . , , . :
1
, (#volume-slider-thumb), mouseover . relatedTarget.
, :
(Ancestor) (Relative Target)
mouseover , (#timeline-slider-thumb). mouseout mouseover .
, relatedTarget mouseout . , relatedTarget (#timeline-slider-thumb). , , :
(Ancestor) (Relative Target) (Adjusted related Target)
, #player, target relatedTarget (#player), , .