1# Event Distribution
2
3## Overview
4
5ArkUI touch events are primarily categorized into touch and mouse types based on the input source.
6
7The touch input sources include: finger, pen
8
9The mouse input sources include: mouse, touchpad, joystick
10
11Events triggered by these two types of input sources are as follows.
12
13| Touch | Mouse |
14|:-----:| ----- |
15| Touch event | Touch event |
16| Click event | Mouse event |
17| Drag event | Click event |
18| Gesture event | Drag event |
19|       | Gesture event |
20
21Both touch and mouse events in ArkUI are initiated by touch testing, which directly determines the generation of the ArkUI event response chain and the distribution of events.
22
23## Touch Testing
24
25Several factors significantly affect the results of touch testing:
26
27- **TouchTest**: The entry method for touch testing, without external APIs
28
29- **hitTestBehavior**: control on touch testing
30
31- **interceptTouch**: custom interception of events
32
33- **responseRegion**: touch target settings
34
35- **enabled**: enable/disable control, which means control on the component's interactivity
36
37- Security components
38
39- Other attribute settings: such as opacity and component availability
40
41### TouchTest
42
43- Touch testing is initiated by each press action, with the root node's **TouchTest** API as the default entry point.
44
45- **hitTestBehavior** can be modified by the **InterceptTouch** event.
46
47- If touch targets, enable/disable control, opacity, or other settings do not meet the component's interaction requirements, the event will immediately bubble up to the parent node.
48
49  ![TouchTest](figures/TouchTest.png)
50
51### Touch Test Control
52
53For details, see [Hit Test Control](../reference/apis-arkui/arkui-ts/ts-universal-attributes-hit-test-behavior.md).
54
55- Hit: The touch test successfully captures events for the current component or its child components.
56
57- The impact of child components on the parent component's touch test depends on the last child component that does not block the touch test.
58
59- **HitTestMode.Default**: the default mode when the **hitTestBehavior** attribute is not specified. If the component itself is hit, it will block other siblings but not children.
60
61  ![hitTestModeDefault](figures/hitTestModeDefault.png)
62
63- **HitTestMode.None**: The component does not receive events and does not prevent siblings or children from continuing the touch test.
64
65  ![hitTestModeNone](figures/hitTestModeNone.png)
66
67- **HitTestMode.Block**: This mode blocks touch tests of the children. If the component itself is hit, it will block the touch test for siblings and the parent.
68
69  ![hitTestModeBlock](figures/hitTestModeBlock.png)
70
71- **HitTestMode.Transparent**: The component participates in the touch test without blocking siblings or the parent.
72
73  ![hitTestModeTransparent](figures/hitTestModeTransparent.png)
74
75### Custom Event Interception
76
77[Custom event interception](../reference/apis-arkui/arkui-ts/ts-universal-attributes-on-touch-intercept.md) allows you to dynamically change a component's **hitTestBehavior** attribute based on service needs when a touch is initiated.
78
79### Enable/Disable Control
80
81[Disabled](../reference/apis-arkui/arkui-ts/ts-universal-attributes-enable.md) components, including their children, do not initiate the touch testing process; instead, they pass the event back to the parent for handling.
82
83### Touch Target Settings
84
85[Touch target settings](../reference/apis-arkui/arkui-ts/ts-universal-attributes-touch-target.md) affect touch testing for touch and mouse inputs. If the component area is set to zero or designated as a non-touchable area, the event will directly propagate to the parent node for continued touch testing.
86
87### Security Components
88
89ArkUI provides a range of security components, including [LocationButton](../security/AccessToken/locationbutton.md), [PasteButton](../security/AccessToken/pastebutton.md), and [SaveButton](../security/AccessToken/savebutton.md).
90
91If a component has a higher [z-order](../reference/apis-arkui/arkui-ts/ts-universal-attributes-z-order.md) than a security component and covers it, the security component's touch events are sent directly to the parent node for further touch testing.
92
93## Event Response Chain Collection
94
95In ArkUI, the event response chain is collected based on a right subtree priority, which follows a post-order traversal process according to the layout hierarchy of components. The process is as follows:
96
97```
98foreach(item=>(node.rbegin(),node.rend(){
99    item.TouchTest()
100}
101node.collectEvent()
102```
103
104In the example of response chain collection below, with all **hitTestBehavior** attributes set to **Default** in the component tree, if a user touches component 5, the response chain that is ultimately collected, in order, is 5, 3, 1.
105
106This is because component 3 has **hitTestBehavior** set to **Default**, which, upon capturing the event, blocks the collection from its sibling nodes, thereby preventing the collection of component 1's left subtree.
107
108  ![EventResponseChain](figures/EventResponseChain.png)
109