1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _UI_INPUT_INPUTDISPATCHER_INPUTTARGET_H
18 #define _UI_INPUT_INPUTDISPATCHER_INPUTTARGET_H
19 
20 #include <input/InputTransport.h>
21 #include <utils/BitSet.h>
22 #include <utils/RefBase.h>
23 
24 namespace android::inputdispatcher {
25 
26 /*
27  * An input target specifies how an input event is to be dispatched to a particular window
28  * including the window's input channel, control flags, a timeout, and an X / Y offset to
29  * be added to input event coordinates to compensate for the absolute position of the
30  * window area.
31  */
32 struct InputTarget {
33     enum {
34         /* This flag indicates that the event is being delivered to a foreground application. */
35         FLAG_FOREGROUND = 1 << 0,
36 
37         /* This flag indicates that the MotionEvent falls within the area of the target
38          * obscured by another visible window above it.  The motion event should be
39          * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. */
40         FLAG_WINDOW_IS_OBSCURED = 1 << 1,
41 
42         /* This flag indicates that a motion event is being split across multiple windows. */
43         FLAG_SPLIT = 1 << 2,
44 
45         /* This flag indicates that the pointer coordinates dispatched to the application
46          * will be zeroed out to avoid revealing information to an application. This is
47          * used in conjunction with FLAG_DISPATCH_AS_OUTSIDE to prevent apps not sharing
48          * the same UID from watching all touches. */
49         FLAG_ZERO_COORDS = 1 << 3,
50 
51         /* This flag indicates that the event should be sent as is.
52          * Should always be set unless the event is to be transmuted. */
53         FLAG_DISPATCH_AS_IS = 1 << 8,
54 
55         /* This flag indicates that a MotionEvent with AMOTION_EVENT_ACTION_DOWN falls outside
56          * of the area of this target and so should instead be delivered as an
57          * AMOTION_EVENT_ACTION_OUTSIDE to this target. */
58         FLAG_DISPATCH_AS_OUTSIDE = 1 << 9,
59 
60         /* This flag indicates that a hover sequence is starting in the given window.
61          * The event is transmuted into ACTION_HOVER_ENTER. */
62         FLAG_DISPATCH_AS_HOVER_ENTER = 1 << 10,
63 
64         /* This flag indicates that a hover event happened outside of a window which handled
65          * previous hover events, signifying the end of the current hover sequence for that
66          * window.
67          * The event is transmuted into ACTION_HOVER_ENTER. */
68         FLAG_DISPATCH_AS_HOVER_EXIT = 1 << 11,
69 
70         /* This flag indicates that the event should be canceled.
71          * It is used to transmute ACTION_MOVE into ACTION_CANCEL when a touch slips
72          * outside of a window. */
73         FLAG_DISPATCH_AS_SLIPPERY_EXIT = 1 << 12,
74 
75         /* This flag indicates that the event should be dispatched as an initial down.
76          * It is used to transmute ACTION_MOVE into ACTION_DOWN when a touch slips
77          * into a new window. */
78         FLAG_DISPATCH_AS_SLIPPERY_ENTER = 1 << 13,
79 
80         /* Mask for all dispatch modes. */
81         FLAG_DISPATCH_MASK = FLAG_DISPATCH_AS_IS | FLAG_DISPATCH_AS_OUTSIDE |
82                 FLAG_DISPATCH_AS_HOVER_ENTER | FLAG_DISPATCH_AS_HOVER_EXIT |
83                 FLAG_DISPATCH_AS_SLIPPERY_EXIT | FLAG_DISPATCH_AS_SLIPPERY_ENTER,
84 
85         /* This flag indicates that the target of a MotionEvent is partly or wholly
86          * obscured by another visible window above it.  The motion event should be
87          * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED. */
88         FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 1 << 14,
89 
90     };
91 
92     // The input channel to be targeted.
93     sp<InputChannel> inputChannel;
94 
95     // Flags for the input target.
96     int32_t flags;
97 
98     // The x and y offset to add to a MotionEvent as it is delivered.
99     // (ignored for KeyEvents)
100     float xOffset, yOffset;
101 
102     // Scaling factor to apply to MotionEvent as it is delivered.
103     // (ignored for KeyEvents)
104     float globalScaleFactor;
105     float windowXScale = 1.0f;
106     float windowYScale = 1.0f;
107 
108     // The subset of pointer ids to include in motion events dispatched to this input target
109     // if FLAG_SPLIT is set.
110     BitSet32 pointerIds;
111 };
112 
113 std::string dispatchModeToString(int32_t dispatchMode);
114 
115 } // namespace android::inputdispatcher
116 
117 #endif // _UI_INPUT_INPUTDISPATCHER_INPUTTARGET_H
118