| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 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> | 
| chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 21 | #include <ui/Transform.h> | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 22 | #include <utils/BitSet.h> | 
 | 23 | #include <utils/RefBase.h> | 
 | 24 |  | 
 | 25 | namespace android::inputdispatcher { | 
 | 26 |  | 
 | 27 | /* | 
 | 28 |  * An input target specifies how an input event is to be dispatched to a particular window | 
 | 29 |  * including the window's input channel, control flags, a timeout, and an X / Y offset to | 
 | 30 |  * be added to input event coordinates to compensate for the absolute position of the | 
 | 31 |  * window area. | 
 | 32 |  */ | 
 | 33 | struct InputTarget { | 
 | 34 |     enum { | 
 | 35 |         /* This flag indicates that the event is being delivered to a foreground application. */ | 
 | 36 |         FLAG_FOREGROUND = 1 << 0, | 
 | 37 |  | 
 | 38 |         /* This flag indicates that the MotionEvent falls within the area of the target | 
 | 39 |          * obscured by another visible window above it.  The motion event should be | 
 | 40 |          * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. */ | 
 | 41 |         FLAG_WINDOW_IS_OBSCURED = 1 << 1, | 
 | 42 |  | 
 | 43 |         /* This flag indicates that a motion event is being split across multiple windows. */ | 
 | 44 |         FLAG_SPLIT = 1 << 2, | 
 | 45 |  | 
 | 46 |         /* This flag indicates that the pointer coordinates dispatched to the application | 
 | 47 |          * will be zeroed out to avoid revealing information to an application. This is | 
 | 48 |          * used in conjunction with FLAG_DISPATCH_AS_OUTSIDE to prevent apps not sharing | 
 | 49 |          * the same UID from watching all touches. */ | 
 | 50 |         FLAG_ZERO_COORDS = 1 << 3, | 
 | 51 |  | 
 | 52 |         /* This flag indicates that the event should be sent as is. | 
 | 53 |          * Should always be set unless the event is to be transmuted. */ | 
 | 54 |         FLAG_DISPATCH_AS_IS = 1 << 8, | 
 | 55 |  | 
 | 56 |         /* This flag indicates that a MotionEvent with AMOTION_EVENT_ACTION_DOWN falls outside | 
 | 57 |          * of the area of this target and so should instead be delivered as an | 
 | 58 |          * AMOTION_EVENT_ACTION_OUTSIDE to this target. */ | 
 | 59 |         FLAG_DISPATCH_AS_OUTSIDE = 1 << 9, | 
 | 60 |  | 
 | 61 |         /* This flag indicates that a hover sequence is starting in the given window. | 
 | 62 |          * The event is transmuted into ACTION_HOVER_ENTER. */ | 
 | 63 |         FLAG_DISPATCH_AS_HOVER_ENTER = 1 << 10, | 
 | 64 |  | 
 | 65 |         /* This flag indicates that a hover event happened outside of a window which handled | 
 | 66 |          * previous hover events, signifying the end of the current hover sequence for that | 
 | 67 |          * window. | 
 | 68 |          * The event is transmuted into ACTION_HOVER_ENTER. */ | 
 | 69 |         FLAG_DISPATCH_AS_HOVER_EXIT = 1 << 11, | 
 | 70 |  | 
 | 71 |         /* This flag indicates that the event should be canceled. | 
 | 72 |          * It is used to transmute ACTION_MOVE into ACTION_CANCEL when a touch slips | 
 | 73 |          * outside of a window. */ | 
 | 74 |         FLAG_DISPATCH_AS_SLIPPERY_EXIT = 1 << 12, | 
 | 75 |  | 
 | 76 |         /* This flag indicates that the event should be dispatched as an initial down. | 
 | 77 |          * It is used to transmute ACTION_MOVE into ACTION_DOWN when a touch slips | 
 | 78 |          * into a new window. */ | 
 | 79 |         FLAG_DISPATCH_AS_SLIPPERY_ENTER = 1 << 13, | 
 | 80 |  | 
 | 81 |         /* Mask for all dispatch modes. */ | 
 | 82 |         FLAG_DISPATCH_MASK = FLAG_DISPATCH_AS_IS | FLAG_DISPATCH_AS_OUTSIDE | | 
 | 83 |                 FLAG_DISPATCH_AS_HOVER_ENTER | FLAG_DISPATCH_AS_HOVER_EXIT | | 
 | 84 |                 FLAG_DISPATCH_AS_SLIPPERY_EXIT | FLAG_DISPATCH_AS_SLIPPERY_ENTER, | 
 | 85 |  | 
 | 86 |         /* This flag indicates that the target of a MotionEvent is partly or wholly | 
 | 87 |          * obscured by another visible window above it.  The motion event should be | 
 | 88 |          * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED. */ | 
 | 89 |         FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 1 << 14, | 
 | 90 |  | 
 | 91 |     }; | 
 | 92 |  | 
 | 93 |     // The input channel to be targeted. | 
| Siarhei Vishniakou | ce5ab08 | 2020-07-09 17:03:21 -0500 | [diff] [blame] | 94 |     std::shared_ptr<InputChannel> inputChannel; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 95 |  | 
 | 96 |     // Flags for the input target. | 
| Siarhei Vishniakou | 240f831 | 2019-11-27 17:09:07 -0800 | [diff] [blame] | 97 |     int32_t flags = 0; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 98 |  | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 99 |     // Scaling factor to apply to MotionEvent as it is delivered. | 
 | 100 |     // (ignored for KeyEvents) | 
| Siarhei Vishniakou | 240f831 | 2019-11-27 17:09:07 -0800 | [diff] [blame] | 101 |     float globalScaleFactor = 1.0f; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 102 |  | 
| Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 103 |     // Display-size in its natural rotation. Used for compatibility transform of raw coordinates. | 
 | 104 |     vec2 displaySize = {AMOTION_EVENT_INVALID_DISPLAY_SIZE, AMOTION_EVENT_INVALID_DISPLAY_SIZE}; | 
 | 105 |  | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 106 |     // The subset of pointer ids to include in motion events dispatched to this input target | 
 | 107 |     // if FLAG_SPLIT is set. | 
| Siarhei Vishniakou | 5d6b661 | 2020-01-08 16:03:04 -0800 | [diff] [blame] | 108 |     BitSet32 pointerIds; | 
| Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 109 |     // The data is stored by the pointerId. Use the bit position of pointerIds to look up | 
| chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 110 |     // Transform per pointerId. | 
 | 111 |     ui::Transform pointerTransforms[MAX_POINTERS]; | 
| Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 112 |  | 
| chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 113 |     void addPointers(BitSet32 pointerIds, const ui::Transform& transform); | 
 | 114 |     void setDefaultPointerTransform(const ui::Transform& transform); | 
| Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 115 |  | 
 | 116 |     /** | 
 | 117 |      * Returns whether the default pointer information should be used. This will be true when the | 
 | 118 |      * InputTarget doesn't have any bits set in the pointerIds bitset. This can happen for monitors | 
 | 119 |      * and non splittable windows since we want all pointers for the EventEntry to go to this | 
 | 120 |      * target. | 
 | 121 |      */ | 
| chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 122 |     bool useDefaultPointerTransform() const; | 
| Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 123 |  | 
 | 124 |     /** | 
| chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 125 |      * Returns the default Transform object. This should be used when useDefaultPointerTransform is | 
| Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 126 |      * true. | 
 | 127 |      */ | 
| chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 128 |     const ui::Transform& getDefaultPointerTransform() const; | 
| Chavi Weingarten | 65f98b8 | 2020-01-16 18:56:50 +0000 | [diff] [blame] | 129 |  | 
 | 130 |     std::string getPointerInfoString() const; | 
| Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 131 | }; | 
 | 132 |  | 
 | 133 | std::string dispatchModeToString(int32_t dispatchMode); | 
 | 134 |  | 
 | 135 | } // namespace android::inputdispatcher | 
 | 136 |  | 
 | 137 | #endif // _UI_INPUT_INPUTDISPATCHER_INPUTTARGET_H |