1a3e0fd82Sopenharmony_ci/* 2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License. 5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at 6a3e0fd82Sopenharmony_ci * 7a3e0fd82Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a3e0fd82Sopenharmony_ci * 9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and 13a3e0fd82Sopenharmony_ci * limitations under the License. 14a3e0fd82Sopenharmony_ci */ 15a3e0fd82Sopenharmony_ci 16a3e0fd82Sopenharmony_ci/** 17a3e0fd82Sopenharmony_ci * @addtogroup UI_DFX 18a3e0fd82Sopenharmony_ci * @{ 19a3e0fd82Sopenharmony_ci * 20a3e0fd82Sopenharmony_ci * @brief Provides test and analysis capabilities, such as stimulating input events and viewing information about a 21a3e0fd82Sopenharmony_ci * Document Object Model (DOM) tree. 22a3e0fd82Sopenharmony_ci * 23a3e0fd82Sopenharmony_ci * @since 1.0 24a3e0fd82Sopenharmony_ci * @version 1.0 25a3e0fd82Sopenharmony_ci */ 26a3e0fd82Sopenharmony_ci 27a3e0fd82Sopenharmony_ci/** 28a3e0fd82Sopenharmony_ci * @file event_injector.h 29a3e0fd82Sopenharmony_ci * 30a3e0fd82Sopenharmony_ci * @brief Declares functions for simulating input events. 31a3e0fd82Sopenharmony_ci * 32a3e0fd82Sopenharmony_ci * @since 1.0 33a3e0fd82Sopenharmony_ci * @version 1.0 34a3e0fd82Sopenharmony_ci */ 35a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_EVENT_INJECTOR_H 36a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_EVENT_INJECTOR_H 37a3e0fd82Sopenharmony_ci 38a3e0fd82Sopenharmony_ci#include "graphic_config.h" 39a3e0fd82Sopenharmony_ci#if ENABLE_DEBUG 40a3e0fd82Sopenharmony_ci#include "gfx_utils/heap_base.h" 41a3e0fd82Sopenharmony_ci#include "gfx_utils/input_event_info.h" 42a3e0fd82Sopenharmony_cinamespace OHOS { 43a3e0fd82Sopenharmony_ci/** 44a3e0fd82Sopenharmony_ci * @ Enumerates the event types. 45a3e0fd82Sopenharmony_ci */ 46a3e0fd82Sopenharmony_cienum class EventDataType { 47a3e0fd82Sopenharmony_ci /** Point event */ 48a3e0fd82Sopenharmony_ci POINT_TYPE, 49a3e0fd82Sopenharmony_ci /** Key event */ 50a3e0fd82Sopenharmony_ci KEY_TYPE, 51a3e0fd82Sopenharmony_ci /** Other events */ 52a3e0fd82Sopenharmony_ci OTHERS 53a3e0fd82Sopenharmony_ci}; 54a3e0fd82Sopenharmony_ciclass PointEventInjector; 55a3e0fd82Sopenharmony_ciclass KeyEventInjector; 56a3e0fd82Sopenharmony_ci 57a3e0fd82Sopenharmony_ci/** 58a3e0fd82Sopenharmony_ci * @brief Manages all types of simulated input events, registers and unregisters event injectors, and simulates 59a3e0fd82Sopenharmony_ci * input events. 60a3e0fd82Sopenharmony_ci * 61a3e0fd82Sopenharmony_ci * @since 1.0 62a3e0fd82Sopenharmony_ci * @version 1.0 63a3e0fd82Sopenharmony_ci */ 64a3e0fd82Sopenharmony_ciclass EventInjector : public HeapBase { 65a3e0fd82Sopenharmony_cipublic: 66a3e0fd82Sopenharmony_ci /** 67a3e0fd82Sopenharmony_ci * @brief Obtains a singleton <b>EventInjector</b> instance. 68a3e0fd82Sopenharmony_ci * 69a3e0fd82Sopenharmony_ci * @return Returns the <b>EventInjector</b> instance. 70a3e0fd82Sopenharmony_ci * @since 1.0 71a3e0fd82Sopenharmony_ci * @version 1.0 72a3e0fd82Sopenharmony_ci */ 73a3e0fd82Sopenharmony_ci static EventInjector* GetInstance(); 74a3e0fd82Sopenharmony_ci 75a3e0fd82Sopenharmony_ci /** 76a3e0fd82Sopenharmony_ci * @brief Registers an event injector of a specified type. 77a3e0fd82Sopenharmony_ci * 78a3e0fd82Sopenharmony_ci * @param type Indicates the event type. For details, see {@link EventDataType}. 79a3e0fd82Sopenharmony_ci * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise. 80a3e0fd82Sopenharmony_ci * @since 1.0 81a3e0fd82Sopenharmony_ci * @version 1.0 82a3e0fd82Sopenharmony_ci */ 83a3e0fd82Sopenharmony_ci bool RegisterEventInjector(EventDataType type); 84a3e0fd82Sopenharmony_ci 85a3e0fd82Sopenharmony_ci /** 86a3e0fd82Sopenharmony_ci * @brief Unregisters an event injector of a specified type. 87a3e0fd82Sopenharmony_ci * 88a3e0fd82Sopenharmony_ci * @param type Indicates the event type. For details, see {@link EventDataType}. 89a3e0fd82Sopenharmony_ci * @since 1.0 90a3e0fd82Sopenharmony_ci * @version 1.0 91a3e0fd82Sopenharmony_ci */ 92a3e0fd82Sopenharmony_ci void UnregisterEventInjector(EventDataType type); 93a3e0fd82Sopenharmony_ci 94a3e0fd82Sopenharmony_ci /** 95a3e0fd82Sopenharmony_ci * @brief Checks whether the event injector of a specified type is registered. 96a3e0fd82Sopenharmony_ci * 97a3e0fd82Sopenharmony_ci * @param type Indicates the event type. For details, see {@link EventDataType}. 98a3e0fd82Sopenharmony_ci * @return Returns <b>true</b> if the device is registered; returns <b>false</b> otherwise. 99a3e0fd82Sopenharmony_ci * @since 1.0 100a3e0fd82Sopenharmony_ci * @version 1.0 101a3e0fd82Sopenharmony_ci */ 102a3e0fd82Sopenharmony_ci bool IsEventInjectorRegistered(EventDataType type) const; 103a3e0fd82Sopenharmony_ci 104a3e0fd82Sopenharmony_ci /** 105a3e0fd82Sopenharmony_ci * @brief Uses a data array of a specified length to simulate an input event of a specified type. 106a3e0fd82Sopenharmony_ci * 107a3e0fd82Sopenharmony_ci * @param dataArray Indicates the pointer to the data array used for simulating the event. 108a3e0fd82Sopenharmony_ci * @param arrayLength Indicates the length of the data array. 109a3e0fd82Sopenharmony_ci * @param type Indicates the event type. For details, see {@link EventDataType}. 110a3e0fd82Sopenharmony_ci * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise. 111a3e0fd82Sopenharmony_ci * @since 1.0 112a3e0fd82Sopenharmony_ci * @version 1.0 113a3e0fd82Sopenharmony_ci */ 114a3e0fd82Sopenharmony_ci bool SetInjectEvent(const DeviceData* dataArray, uint16_t arrayLength, EventDataType type); 115a3e0fd82Sopenharmony_ci 116a3e0fd82Sopenharmony_ci /** 117a3e0fd82Sopenharmony_ci * @brief Stimulates a click event. 118a3e0fd82Sopenharmony_ci * 119a3e0fd82Sopenharmony_ci * @param clickPoint Indicates the coordinates of the click point. 120a3e0fd82Sopenharmony_ci * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise. 121a3e0fd82Sopenharmony_ci * @since 3.0 122a3e0fd82Sopenharmony_ci * @version 5.0 123a3e0fd82Sopenharmony_ci */ 124a3e0fd82Sopenharmony_ci bool SetClickEvent(const Point& clickPoint); 125a3e0fd82Sopenharmony_ci 126a3e0fd82Sopenharmony_ci /** 127a3e0fd82Sopenharmony_ci * @brief Stimulates a long press event. 128a3e0fd82Sopenharmony_ci * 129a3e0fd82Sopenharmony_ci * @param longPressPoint Indicates the coordinates of the long press point. 130a3e0fd82Sopenharmony_ci * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise. 131a3e0fd82Sopenharmony_ci * @since 3.0 132a3e0fd82Sopenharmony_ci * @version 5.0 133a3e0fd82Sopenharmony_ci */ 134a3e0fd82Sopenharmony_ci bool SetLongPressEvent(const Point& longPressPoint); 135a3e0fd82Sopenharmony_ci 136a3e0fd82Sopenharmony_ci /** 137a3e0fd82Sopenharmony_ci * @brief Stimulates a drag event that occurs between two points. 138a3e0fd82Sopenharmony_ci * 139a3e0fd82Sopenharmony_ci * @param startPoint Indicates the coordinates of the start point. 140a3e0fd82Sopenharmony_ci * @param endPoint Indicates the coordinates of the end point. 141a3e0fd82Sopenharmony_ci * @param dragTime Indicates the duration of dragging from the start point to the end point, in milliseconds. 142a3e0fd82Sopenharmony_ci * The value range is [2, 499] x {@link INDEV_READ_PERIOD}. 143a3e0fd82Sopenharmony_ci * The shorter the duration is, the faster the sliding is. 144a3e0fd82Sopenharmony_ci * 145a3e0fd82Sopenharmony_ci * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise. 146a3e0fd82Sopenharmony_ci * @since 3.0 147a3e0fd82Sopenharmony_ci * @version 5.0 148a3e0fd82Sopenharmony_ci */ 149a3e0fd82Sopenharmony_ci bool SetDragEvent(const Point& startPoint, const Point& endPoint, uint32_t dragTime); 150a3e0fd82Sopenharmony_ci 151a3e0fd82Sopenharmony_ci /** 152a3e0fd82Sopenharmony_ci * @brief Simulates a key event. 153a3e0fd82Sopenharmony_ci * 154a3e0fd82Sopenharmony_ci * @param keyId Indicates the key ID. 155a3e0fd82Sopenharmony_ci * @param state Indicates the key state. For details, see {@link InputDevice}. 156a3e0fd82Sopenharmony_ci * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise. 157a3e0fd82Sopenharmony_ci * @since 3.0 158a3e0fd82Sopenharmony_ci * @version 5.0 159a3e0fd82Sopenharmony_ci */ 160a3e0fd82Sopenharmony_ci bool SetKeyEvent(uint16_t keyId, uint16_t state); 161a3e0fd82Sopenharmony_ci 162a3e0fd82Sopenharmony_ci#if ENABLE_WINDOW 163a3e0fd82Sopenharmony_ci /** 164a3e0fd82Sopenharmony_ci * @brief Set id of mock window. 165a3e0fd82Sopenharmony_ci * 166a3e0fd82Sopenharmony_ci * @param windowId id of mock window 167a3e0fd82Sopenharmony_ci * 168a3e0fd82Sopenharmony_ci * @since 3.0 169a3e0fd82Sopenharmony_ci * @version 5.0 170a3e0fd82Sopenharmony_ci */ 171a3e0fd82Sopenharmony_ci void SetWindowId(uint8_t windowId); 172a3e0fd82Sopenharmony_ci#endif 173a3e0fd82Sopenharmony_ci 174a3e0fd82Sopenharmony_ciprivate: 175a3e0fd82Sopenharmony_ci EventInjector() : pointEventInjector_(nullptr), keyEventInjector_(nullptr) {} 176a3e0fd82Sopenharmony_ci virtual ~EventInjector(); 177a3e0fd82Sopenharmony_ci 178a3e0fd82Sopenharmony_ci EventInjector(const EventInjector&) = delete; 179a3e0fd82Sopenharmony_ci EventInjector& operator=(const EventInjector&) = delete; 180a3e0fd82Sopenharmony_ci EventInjector(EventInjector&&) = delete; 181a3e0fd82Sopenharmony_ci EventInjector& operator=(EventInjector&&) = delete; 182a3e0fd82Sopenharmony_ci 183a3e0fd82Sopenharmony_ci PointEventInjector* pointEventInjector_; 184a3e0fd82Sopenharmony_ci KeyEventInjector* keyEventInjector_; 185a3e0fd82Sopenharmony_ci}; 186a3e0fd82Sopenharmony_ci} // namespace OHOS 187a3e0fd82Sopenharmony_ci#endif // ENABLE_DEBUG 188a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_EVENT_INJECTOR_H 189