blob: 61b07feb3a691ffafcaf7cdd32a77d5f7cfc11d1 [file] [log] [blame]
Garfield Tane84e6f92019-08-29 17:28:41 -07001/*
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
Prabir Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Garfield Tane84e6f92019-08-29 17:28:41 -070018
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080019#include <ftl/flags.h>
chaviw3277faf2021-05-19 16:45:23 -050020#include <gui/constants.h>
Garfield Tane84e6f92019-08-29 17:28:41 -070021#include <input/InputTransport.h>
chaviw1ff3d1e2020-07-01 15:53:47 -070022#include <ui/Transform.h>
Garfield Tane84e6f92019-08-29 17:28:41 -070023#include <utils/BitSet.h>
Garfield Tane84e6f92019-08-29 17:28:41 -070024
25namespace 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 */
33struct InputTarget {
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080034 enum class Flags : uint32_t {
Garfield Tane84e6f92019-08-29 17:28:41 -070035 /* This flag indicates that the event is being delivered to a foreground application. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080036 FOREGROUND = 1 << 0,
Garfield Tane84e6f92019-08-29 17:28:41 -070037
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. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080041 WINDOW_IS_OBSCURED = 1 << 1,
Garfield Tane84e6f92019-08-29 17:28:41 -070042
43 /* This flag indicates that a motion event is being split across multiple windows. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080044 SPLIT = 1 << 2,
Garfield Tane84e6f92019-08-29 17:28:41 -070045
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. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080050 ZERO_COORDS = 1 << 3,
Garfield Tane84e6f92019-08-29 17:28:41 -070051
52 /* This flag indicates that the event should be sent as is.
53 * Should always be set unless the event is to be transmuted. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080054 DISPATCH_AS_IS = 1 << 8,
Garfield Tane84e6f92019-08-29 17:28:41 -070055
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. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080059 DISPATCH_AS_OUTSIDE = 1 << 9,
Garfield Tane84e6f92019-08-29 17:28:41 -070060
61 /* This flag indicates that a hover sequence is starting in the given window.
62 * The event is transmuted into ACTION_HOVER_ENTER. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080063 DISPATCH_AS_HOVER_ENTER = 1 << 10,
Garfield Tane84e6f92019-08-29 17:28:41 -070064
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. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080069 DISPATCH_AS_HOVER_EXIT = 1 << 11,
Garfield Tane84e6f92019-08-29 17:28:41 -070070
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. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080074 DISPATCH_AS_SLIPPERY_EXIT = 1 << 12,
Garfield Tane84e6f92019-08-29 17:28:41 -070075
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. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080079 DISPATCH_AS_SLIPPERY_ENTER = 1 << 13,
Garfield Tane84e6f92019-08-29 17:28:41 -070080
81 /* This flag indicates that the target of a MotionEvent is partly or wholly
82 * obscured by another visible window above it. The motion event should be
83 * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED. */
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080084 WINDOW_IS_PARTIALLY_OBSCURED = 1 << 14,
Garfield Tane84e6f92019-08-29 17:28:41 -070085 };
86
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080087 /* Mask for all dispatch modes. */
88 static constexpr const ftl::Flags<InputTarget::Flags> DISPATCH_MASK =
89 ftl::Flags<InputTarget::Flags>() | Flags::DISPATCH_AS_IS | Flags::DISPATCH_AS_OUTSIDE |
90 Flags::DISPATCH_AS_HOVER_ENTER | Flags::DISPATCH_AS_HOVER_EXIT |
91 Flags::DISPATCH_AS_SLIPPERY_EXIT | Flags::DISPATCH_AS_SLIPPERY_ENTER;
92
Garfield Tane84e6f92019-08-29 17:28:41 -070093 // The input channel to be targeted.
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -050094 std::shared_ptr<InputChannel> inputChannel;
Garfield Tane84e6f92019-08-29 17:28:41 -070095
96 // Flags for the input target.
Siarhei Vishniakou253f4642022-11-09 13:42:06 -080097 ftl::Flags<Flags> flags;
Garfield Tane84e6f92019-08-29 17:28:41 -070098
Garfield Tane84e6f92019-08-29 17:28:41 -070099 // Scaling factor to apply to MotionEvent as it is delivered.
100 // (ignored for KeyEvents)
Siarhei Vishniakou240f8312019-11-27 17:09:07 -0800101 float globalScaleFactor = 1.0f;
Garfield Tane84e6f92019-08-29 17:28:41 -0700102
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700103 // Current display transform. Used for compatibility for raw coordinates.
104 ui::Transform displayTransform;
Evan Rosky84f07f02021-04-16 10:42:42 -0700105
Garfield Tane84e6f92019-08-29 17:28:41 -0700106 // The subset of pointer ids to include in motion events dispatched to this input target
107 // if FLAG_SPLIT is set.
Siarhei Vishniakou5d6b6612020-01-08 16:03:04 -0800108 BitSet32 pointerIds;
Vaibhav Devmurari882bd9b2022-06-23 14:54:54 +0000109 // Event time for the first motion event (ACTION_DOWN) dispatched to this input target if
110 // FLAG_SPLIT is set.
111 std::optional<nsecs_t> firstDownTimeInTarget;
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000112 // The data is stored by the pointerId. Use the bit position of pointerIds to look up
chaviw1ff3d1e2020-07-01 15:53:47 -0700113 // Transform per pointerId.
114 ui::Transform pointerTransforms[MAX_POINTERS];
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000115
chaviw1ff3d1e2020-07-01 15:53:47 -0700116 void addPointers(BitSet32 pointerIds, const ui::Transform& transform);
117 void setDefaultPointerTransform(const ui::Transform& transform);
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000118
119 /**
120 * Returns whether the default pointer information should be used. This will be true when the
121 * InputTarget doesn't have any bits set in the pointerIds bitset. This can happen for monitors
122 * and non splittable windows since we want all pointers for the EventEntry to go to this
123 * target.
124 */
chaviw1ff3d1e2020-07-01 15:53:47 -0700125 bool useDefaultPointerTransform() const;
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000126
127 /**
chaviw1ff3d1e2020-07-01 15:53:47 -0700128 * Returns the default Transform object. This should be used when useDefaultPointerTransform is
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000129 * true.
130 */
chaviw1ff3d1e2020-07-01 15:53:47 -0700131 const ui::Transform& getDefaultPointerTransform() const;
Chavi Weingarten65f98b82020-01-16 18:56:50 +0000132
133 std::string getPointerInfoString() const;
Garfield Tane84e6f92019-08-29 17:28:41 -0700134};
135
136std::string dispatchModeToString(int32_t dispatchMode);
137
138} // namespace android::inputdispatcher