!1514 触摸浏览手势重构

Merge pull request !1514 from 小发发/accessibility_241102
This commit is contained in:
openharmony_ci 2024-11-20 02:48:33 +00:00 committed by Gitee
commit 4636fadaa0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
37 changed files with 5755 additions and 13220 deletions

View File

@ -60,16 +60,14 @@ ohos_unittest("accessibility_parcel_test") {
"../../../../resources/config/build:coverage_flags",
]
deps = [
"../../../../../../../third_party/googletest:gmock_main",
"../../../../../../../third_party/googletest:gtest_main",
"../../../../interfaces/innerkits/common:accessibility_common",
]
deps = [ "../../../../interfaces/innerkits/common:accessibility_common" ]
external_deps = [
"access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk",
"c_utils:utils",
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"input:libmmi-client",
"ipc:ipc_single",

View File

@ -27,7 +27,6 @@ config("module_private_config") {
}
include_dirs = aams_mock_include_dirs
include_dirs += [
"${ability_runtime_inner_api_path}/ability_manager/include",
"../../../common/log/include",
"../include",
"./mock/include",
@ -73,8 +72,6 @@ ohos_unittest("accessibility_ui_test_ability_impl_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -92,6 +89,8 @@ ohos_unittest("accessibility_ui_test_ability_impl_test") {
"data_share:datashare_consumer",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"init:libbeget_proxy",
"init:libbegetutil",
@ -161,8 +160,6 @@ ohos_unittest("accessible_ability_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -180,6 +177,8 @@ ohos_unittest("accessible_ability_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
"hilog:libhilog",

View File

@ -12,7 +12,6 @@
# limitations under the License.
import("//build/test.gni")
import("../../../accessibility_aafwk.gni")
module_output_path = "accessibility/accessibility"
@ -25,11 +24,6 @@ config("module_private_config") {
}
include_dirs = [
"${ability_base_path}/interfaces/inner_api/base/include",
"${ability_base_path}/interfaces/kits/native/uri/include",
"${ability_base_path}/interfaces/kits/native/want/include",
"${ability_out_base_path}/notification/common_event_service/interfaces/inner_api",
"${ability_json_path}/notification/common_event_service/interfaces/inner_api",
"../../../services/interface/include",
"../include",
"../../../interfaces/innerkits/acfwk/include",
@ -61,8 +55,6 @@ ohos_unittest("ac_unit_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -80,6 +72,8 @@ ohos_unittest("ac_unit_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",

View File

@ -12,7 +12,6 @@
# limitations under the License.
import("//build/test.gni")
import("../../../accessibility_aafwk.gni")
module_output_path = "accessibility/accessibility"
@ -60,8 +59,6 @@ ohos_unittest("asac_unit_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -80,6 +77,8 @@ ohos_unittest("asac_unit_test") {
"data_share:datashare_consumer",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",

View File

@ -48,13 +48,13 @@ ohos_unittest("accessibility_common_test") {
"../../../resources/config/build:coverage_flags",
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../interfaces/innerkits/common:accessibility_common",
]
deps = [ "../../../interfaces/innerkits/common:accessibility_common" ]
external_deps = [ "hilog:libhilog" ]
external_deps = [
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
]
}
###############################################################################

View File

@ -12,7 +12,6 @@
# limitations under the License.
import("//build/ohos.gni")
import("../../../accessibility_aafwk.gni")
import("../../../accessibility_manager_service.gni")
aafwk_path = "../../../frameworks/aafwk"

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Copyright (C) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -380,6 +380,7 @@ constexpr int32_t DEFAULT_INT32 = 0;
constexpr int32_t CODE_SUCCESS = 0;
constexpr int32_t CODE_FAILED = -1;
constexpr int32_t CHAE_BUFFER_MAX = 1024;
constexpr int32_t US_TO_MS = 1000;
const std::string ERROR_MESSAGE_PARAMETER_ERROR = "Parameter error. Possible causes:"
"1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.";
const std::string ERROR_MESSAGE_NO_PERMISSION = "Permission verification failed."

View File

@ -12,7 +12,6 @@
# limitations under the License.
import("//build/ohos.gni")
import("../../../accessibility_aafwk.gni")
ohos_shared_library("accessibility_napi") {
branch_protector_ret = "pac_ret"

View File

@ -12,8 +12,7 @@
# limitations under the License.
import("//build/ohos.gni")
import(
"../../../../../../../arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/templates/abc/ohos_abc.gni")
es2abc_gen_abc("gen_accessibility_extension_abc") {
src_js = rebase_path("accessibility_extension.js")

View File

@ -12,8 +12,7 @@
# limitations under the License.
import("//build/ohos.gni")
import(
"../../../../../../../arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import("//build/templates/abc/ohos_abc.gni")
es2abc_gen_abc("gen_accessibility_extension_context_abc") {
src_js = rebase_path("accessibility_extension_context.js")

View File

@ -1,4 +1,4 @@
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Copyright (C) 2022-2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@ -55,17 +55,15 @@ accessibleabilityms_files = [
"${services_path}/src/accessibility_window_connection.cpp",
"${services_path}/src/accessibility_zoom_gesture.cpp",
"${services_path}/src/accessibility_common_event.cpp",
"${services_path}/src/accessibility_touch_guider.cpp",
"${services_path}/src/accessibility_gesture_recognizer.cpp",
"${services_path}/src/accessibility_event_transmission.cpp",
"${services_path}/src/accessibility_input_interceptor.cpp",
"${services_path}/src/accessibility_touchEvent_injector.cpp",
"${services_path}/src/accessibility_keyevent_filter.cpp",
"${services_path}/src/accessibility_mouse_autoclick.cpp",
"${services_path}/src/accessibility_multifinger_multitap.cpp",
"${services_path}/src/accessibility_mouse_key.cpp",
"${services_path}/src/accessibility_screen_touch.cpp",
"${services_path}/src/accessibility_short_key.cpp",
"${services_path}/src/accessibility_touchEvent_injector.cpp",
"${services_path}/src/accessibility_touch_exploration.cpp",
"${services_path}/src/accessibility_window_manager.cpp",
"${services_path}/src/utils.cpp",
"${services_path}/src/accessibility_dumper.cpp",

View File

@ -1,369 +0,0 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ACCESSIBILITY_GESTURE_RECOGNIZER_H
#define ACCESSIBILITY_GESTURE_RECOGNIZER_H
#include <cmath>
#include <vector>
#ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER
#include "accessibility_display_manager.h"
#endif
#include "accessibility_event_info.h"
#include "accessible_ability_manager_service.h"
#include "event_handler.h"
#include "event_runner.h"
#include "pointer_event.h"
#include "singleton.h"
namespace OHOS {
namespace Accessibility {
const int64_t GESTURE_STARTED_TIME_THRESHOLD = 300000; // microsecond
const int64_t GESTURE_NOT_STARTED_TIME_THRESHOLD = 200000; // microsecond
const float DOUBLE_TAP_SLOP = 100.0f;
const int64_t MIN_DOUBLE_TAP_TIME = 40000; // microsecond
const int64_t DOUBLE_TAP_TIMEOUT = 300000; // microsecond
const int64_t LONG_PRESS_TIMEOUT = 300000; // microsecond
const int64_t TAP_INTERVAL_TIMEOUT = 100000; // microsecond
const float DEGREES_THRESHOLD = 0.0f;
const int32_t DIRECTION_NUM = 4;
const int64_t US_TO_MS = 1000;
const int32_t MM_PER_CM = 10;
#define CALCULATION_DIMENSION(xdpi) ((xdpi) * 0.25f)
#define MIN_PIXELS(xyDpi) ((xyDpi) * 0.1f)
struct Pointer {
float px_;
float py_;
};
class AccessibilityGestureRecognizer;
class GestureHandler : public AppExecFwk::EventHandler {
public:
GestureHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner, AccessibilityGestureRecognizer &server);
virtual ~GestureHandler() = default;
/**
* @brief Process the event of install system bundles.
* @param event Indicates the event to be processed.
*/
virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
private:
AccessibilityGestureRecognizer &server_;
};
class AccessibilityGestureRecognizeListener {
public:
/**
* @brief A destructor used to delete the listener instance.
*/
virtual ~AccessibilityGestureRecognizeListener() = default;
/**
* @brief The callback function when lifted the finger on the second tap of a double tap.
*
* @param event the touch event received.
* @return true if the event is consumed, else false
*/
virtual bool OnDoubleTap(MMI::PointerEvent &event);
/**
* @brief The callback function when recognized an event stream as a gesture.
* @return true if the event is consumed, else false
*/
virtual bool OnStarted();
/**
* @brief The callback function when recognized an event stream as a multi finger gesture.
* @param isTwoFingerGesture whether the gesture is triggered by two finger.
*/
virtual void MultiFingerGestureOnStarted(bool isTwoFingerGesture);
/**
* @brief The callback function when decided the event stream is a gesture.
* @param gestureId the recognized gesture ID.
* @return true if the event is consumed, else false
*/
virtual bool OnCompleted(GestureType gestureId);
/**
* @brief The callback function when decided the event stream is a multi finger gesture.
* @param gestureId the recognized gesture ID.
*/
virtual void MultiFingerGestureOnCompleted(GestureType gestureId);
/**
* @brief The callback function when decided an event stream doesn't match any known gesture.
* @param event the touch event received.
* @return true if the event is consumed, else false
*/
virtual bool OnCancelled(MMI::PointerEvent &event);
/**
* @brief The callback function when decided an event stream doesn't match any known multi finger gesture.
* @param isNoDelayFlag whether the gesture recognize process is immediately canceled.
*/
virtual void MultiFingerGestureOnCancelled(const bool isNoDelayFlag);
};
class AccessibilityGestureRecognizer : public AppExecFwk::EventHandler {
public:
static constexpr uint32_t LONG_PRESS_MSG = 1;
static constexpr uint32_t SINGLE_TAP_MSG = 2;
/**
* @brief A constructor used to create a accessibilityGestureRecognizer instance.
*/
AccessibilityGestureRecognizer();
/**
* @brief A destructor used to delete the accessibilityGestureRecognizer instance.
*/
~AccessibilityGestureRecognizer() {}
/**
* @brief Register GestureRecognizeListener.
* @param listener the listener from touchguide
*/
void RegisterListener(AccessibilityGestureRecognizeListener& listener);
/**
* @brief Register GestureRecognizeListener.
* @param listener the listener from touchguide
*/
void UnregisterListener();
/**
* @brief Determine whether a single tap has occurred.
* @return true if a single tap has occurred, else false.
*/
bool IsfirstTap()
{
return isFirstTapUp_;
}
/**
* @brief Determine whether a double tap has occurred.
* @return true if a double tap has occurred, else false.
*/
bool GetIsDoubleTap()
{
return isDoubleTap_;
}
/**
* @brief Determine whether a longpress has occurred.
* @return true if longpress has occurred, else false.
*/
bool GetIsLongpress()
{
return isLongpress_;
}
/**
* @brief Handle a touch event. If an action is completed, the appropriate callback is called.
*
* @param event the touch event to be handled.
* @param rawEvent The raw touch event.
* @return true if the gesture be recognized, else false
*/
bool OnPointerEvent(MMI::PointerEvent &event);
/**
* @brief Clear state.
*/
void Clear();
/**
* @brief Judge whether the double click and long press gesture is recognized.
* @param event the touch event from touchguide
*/
void MaybeRecognizeLongPress(MMI::PointerEvent &event);
/**
* @brief If a single tap completed.
*/
void SingleTapDetected();
/**
* @brief Set isLongpress_ flag;
* @param value set isLongpress_ flag
*/
void SetIsLongpress (bool value)
{
isLongpress_ = value;
}
/**
* @brief Get pCurDown_ ptr.
*/
std::shared_ptr<MMI::PointerEvent> GetCurDown()
{
return pCurDown_;
}
/**
* @brief Get continueDown_ flag.
*/
bool GetContinueDown()
{
return continueDown_;
}
private:
/**
* @brief Recognize the standard gesture.
* @param event the touch event from touchguide
* @return true if the standard gesture be recognized, else false
*/
bool StandardGestureRecognizer(MMI::PointerEvent &event);
/**
* @brief A double tap has occurred, call OnDoubleTap callback.
* @param event the touch event from touchguide
* @return true if the DoubleTap be recognized, else false
*/
bool DoubleTapRecognized(MMI::PointerEvent &event);
/**
* @brief Recognize gestures based on the sequence of motions.
* @param event the touch event from touchguide
* @return true if the Direction be recognized, else false
*/
bool recognizeDirectionGesture(MMI::PointerEvent &event);
/**
* @brief Handle the down event from touchguide.
* @param event the touch event from touchguide
*/
void HandleTouchDownEvent(MMI::PointerEvent &event);
/**
* @brief Handle the move event from touchguide.
* @param event the touch event from touchguide
*/
bool HandleTouchMoveEvent(MMI::PointerEvent &event);
/**
* @brief Handle the up event from touchguide.
* @param event the touch event from touchguide
*/
bool HandleTouchUpEvent(MMI::PointerEvent &event);
/**
* @brief Check if it's double tap.
* @param event the touch event from touchguide
* @return true if it's double tap, else false
*/
bool isDoubleTap(MMI::PointerEvent &event);
/**
* @brief Cancel the gesture.
*/
void StandardGestureCanceled();
/**
* @brief Add position to pointer route.
* @param pointerIterm the touch item from touchguide
*/
void AddSwipePosition(MMI::PointerEvent::PointerItem &pointerIterm);
/**
* @brief Calculate the move threshold for the double tap gesture.
* @param densityDpi the physical density
*/
float GetDoubleTapMoveThreshold(float densityDpi);
/**
* @brief Get pointer path.
* @param route all pointer route
* @return the vector of PointerPath
*/
std::vector<Pointer> GetPointerPath(std::vector<Pointer> &route);
/**
* @brief Get swipe direction.
* @param firstP the start point
* @param secondP the endpoint
* @return the type of swipe direction
*/
int32_t GetSwipeDirection(Pointer firstP, Pointer secondP);
static constexpr int32_t SWIPE_UP = 0;
static constexpr int32_t SWIPE_DOWN = 1;
static constexpr int32_t SWIPE_LEFT = 2;
static constexpr int32_t SWIPE_RIGHT = 3;
static constexpr GestureType GESTURE_DIRECTION[DIRECTION_NUM] = {
GestureType::GESTURE_SWIPE_UP,
GestureType::GESTURE_SWIPE_DOWN,
GestureType::GESTURE_SWIPE_LEFT,
GestureType::GESTURE_SWIPE_RIGHT
};
static constexpr GestureType GESTURE_DIRECTION_TO_ID[DIRECTION_NUM][DIRECTION_NUM] = {
{
GestureType::GESTURE_SWIPE_UP,
GestureType::GESTURE_SWIPE_UP_THEN_DOWN,
GestureType::GESTURE_SWIPE_UP_THEN_LEFT,
GestureType::GESTURE_SWIPE_UP_THEN_RIGHT,
},
{
GestureType::GESTURE_SWIPE_DOWN_THEN_UP,
GestureType::GESTURE_SWIPE_DOWN,
GestureType::GESTURE_SWIPE_DOWN_THEN_LEFT,
GestureType::GESTURE_SWIPE_DOWN_THEN_RIGHT,
},
{
GestureType::GESTURE_SWIPE_LEFT_THEN_UP,
GestureType::GESTURE_SWIPE_LEFT_THEN_DOWN,
GestureType::GESTURE_SWIPE_LEFT,
GestureType::GESTURE_SWIPE_LEFT_THEN_RIGHT,
},
{
GestureType::GESTURE_SWIPE_RIGHT_THEN_UP,
GestureType::GESTURE_SWIPE_RIGHT_THEN_DOWN,
GestureType::GESTURE_SWIPE_RIGHT_THEN_LEFT,
GestureType::GESTURE_SWIPE_RIGHT
}
};
bool continueDown_ = false;
bool isLongpress_ = false;
bool isDoubleTapdetecting_ = false;
bool isTapDown_ = false;
bool isFirstTapUp_ = false;
bool isDoubleTap_ = false;
bool isRecognizingGesture_ = false;
bool isGestureStarted_ = false;
int64_t startTime_ = 0; // microsecond
float xMinPixels_ = 0;
float yMinPixels_ = 0;
float threshold_ = 0;
int32_t doubleTapScaledSlop_ = 0;
MMI::PointerEvent::PointerItem prePointer_ = {};
MMI::PointerEvent::PointerItem startPointer_ = {};
std::vector<Pointer> pointerRoute_ {};
AccessibilityGestureRecognizeListener *listener_ = nullptr;
std::unique_ptr<MMI::PointerEvent> pPreUp_ = nullptr;
std::shared_ptr<MMI::PointerEvent> pCurDown_ = nullptr;
std::shared_ptr<GestureHandler> handler_ = nullptr;
std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
};
} // namespace Accessibility
} // namespace OHOS
#endif // ACCESSIBILITY_GESTURE_RECOGNIZER_H

View File

@ -1,448 +0,0 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ACCESSIBILITY_MULTIFINGER_MULTITAP_H
#define ACCESSIBILITY_MULTIFINGER_MULTITAP_H
#include <cmath>
#include <vector>
#include "accessibility_gesture_recognizer.h"
#ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER
#include "accessibility_display_manager.h"
#endif
#include "accessibility_event_info.h"
#include "accessible_ability_manager_service.h"
#include "accessibility_def.h"
#include "event_handler.h"
#include "event_runner.h"
#include "pointer_event.h"
#include "singleton.h"
namespace OHOS {
namespace Accessibility {
namespace {
constexpr uint32_t MAX_TAP_NUM = 3;
constexpr uint32_t MAX_MULTI_FINGER_TYPE = 3;
} // namespace
enum MoveGirectionType : int32_t {
SWIPE_LEFT = 0,
SWIPE_RIGHT = 1,
SWIPE_UP = 2,
SWIPE_DOWN = 3
};
enum FingerTouchUpState : int32_t {
NOT_ALL_FINGER_TOUCH_UP = 0,
ALL_FINGER_TOUCH_UP = 1,
TOUCH_DOWN_AFTER_ALL_FINGER_TOUCH_UP = 2,
};
enum MultiFingerGestureState : int32_t {
GESTURE_NOT_START = 0,
GESTURE_START = 1,
GESTURE_CANCLE = 2,
GESTURE_COMPLETE = 3,
GESTURE_WAIT = 4,
};
class AccessibilityMultiTapGestureRecognizer;
class MultiFingerGestureHandler : public AppExecFwk::EventHandler {
public:
MultiFingerGestureHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
AccessibilityMultiTapGestureRecognizer &server);
virtual ~MultiFingerGestureHandler() = default;
/**
* @brief Process the event of install system bundles.
* @param event Indicates the event to be processed.
*/
virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
private:
/**
* @brief Process the multi finger gesture by Gesture type.
* @param gestureType Indicates the gesture type to be processed.
*/
void ProcessMultiFingerGestureTypeEvent(const GestureType gestureType);
/**
* @brief Process the multi finger gesture event.
* @param event Indicates the event to be processed.
* @return true if the gesture event is processed success, else false.
*/
bool ProcessMultiFingerGestureEvent(const AppExecFwk::InnerEvent::Pointer &event);
/**
* @brief check whether the gesture is a tap gesture.
* @param gestureType Indicates the gesture to be processed.
* @return true if the gesture is a tap gesture, else false.
*/
bool IsTapGesture(const GestureType gestureType);
AccessibilityMultiTapGestureRecognizer &server_;
};
class AccessibilityMultiTapGestureRecognizer : public AppExecFwk::EventHandler {
public:
static constexpr uint32_t TWO_FINGER_SINGLE_TAP_MSG = 3;
static constexpr uint32_t TWO_FINGER_LONG_PRESS_MSG = 4;
static constexpr uint32_t TWO_FINGER_DOUBLE_TAP_MSG = 5;
static constexpr uint32_t TWO_FINGER_DOUBLE_TAP_AND_HOLD_MSG = 6;
static constexpr uint32_t TWO_FINGER_TRIPLE_TAP_MSG = 7;
static constexpr uint32_t TWO_FINGER_TRIPLE_TAP_AND_HOLD_MSG = 8;
static constexpr uint32_t THREE_FINGER_SINGLE_TAP_MSG = 9;
static constexpr uint32_t THREE_FINGER_LONG_PRESS_MSG = 10;
static constexpr uint32_t THREE_FINGER_DOUBLE_TAP_MSG = 11;
static constexpr uint32_t THREE_FINGER_DOUBLE_TAP_AND_HOLD_MSG = 12;
static constexpr uint32_t THREE_FINGER_TRIPLE_TAP_MSG = 13;
static constexpr uint32_t THREE_FINGER_TRIPLE_TAP_AND_HOLD_MSG = 14;
static constexpr uint32_t FOUR_FINGER_SINGLE_TAP_MSG = 15;
static constexpr uint32_t FOUR_FINGER_LONG_PRESS_MSG = 16;
static constexpr uint32_t FOUR_FINGER_DOUBLE_TAP_MSG = 17;
static constexpr uint32_t FOUR_FINGER_DOUBLE_TAP_AND_HOLD_MSG = 18;
static constexpr uint32_t FOUR_FINGER_TRIPLE_TAP_MSG = 19;
static constexpr uint32_t FOUR_FINGER_TRIPLE_TAP_AND_HOLD_MSG = 20;
static constexpr uint32_t WAIT_ANOTHER_FINGER_DOWN_MSG = 21;
static constexpr uint32_t CANCEL_WAIT_FINGER_DOWN_MSG = 22;
static constexpr uint32_t CANCEL_GESTURE = 23;
static constexpr uint32_t COMPLETE_GESTURE = 24;
static constexpr uint32_t GESTURE_TAP_MSG[MAX_TAP_NUM][MAX_MULTI_FINGER_TYPE] = {
{
TWO_FINGER_SINGLE_TAP_MSG,
THREE_FINGER_SINGLE_TAP_MSG,
FOUR_FINGER_SINGLE_TAP_MSG,
},
{
TWO_FINGER_DOUBLE_TAP_MSG,
THREE_FINGER_DOUBLE_TAP_MSG,
FOUR_FINGER_DOUBLE_TAP_MSG,
},
{
TWO_FINGER_TRIPLE_TAP_MSG,
THREE_FINGER_TRIPLE_TAP_MSG,
FOUR_FINGER_TRIPLE_TAP_MSG,
}
};
static constexpr uint32_t GESTURE_HOLD_MSG[MAX_TAP_NUM][MAX_MULTI_FINGER_TYPE] = {
{
TWO_FINGER_LONG_PRESS_MSG,
THREE_FINGER_LONG_PRESS_MSG,
FOUR_FINGER_LONG_PRESS_MSG,
},
{
TWO_FINGER_DOUBLE_TAP_AND_HOLD_MSG,
THREE_FINGER_DOUBLE_TAP_AND_HOLD_MSG,
FOUR_FINGER_DOUBLE_TAP_AND_HOLD_MSG,
},
{
TWO_FINGER_TRIPLE_TAP_AND_HOLD_MSG,
THREE_FINGER_TRIPLE_TAP_AND_HOLD_MSG,
FOUR_FINGER_TRIPLE_TAP_AND_HOLD_MSG,
}
};
AccessibilityMultiTapGestureRecognizer();
~AccessibilityMultiTapGestureRecognizer() = default;
/**
* @brief Register GestureRecognizeListener.
* @param listener the listener from touchguide.
*/
void RegisterListener(AccessibilityGestureRecognizeListener &listener);
/**
* @brief Get the GestureRecognizeListener.
* @return AccessibilityGestureRecognizeListener ptr.
*/
AccessibilityGestureRecognizeListener *GetRecognizeListener() const
{
return listener_;
}
/**
* @brief Handle a touch event. If an action is completed, the appropriate callback is called.
*
* @param event the touch event to be handled.
*/
void OnPointerEvent(MMI::PointerEvent &event);
/**
* @brief Cancle multi finger gesture rocognize state, buffer etc.
*/
void Clear();
/**
* @brief Get the target fingers number touch down in first round.
* @return the finger numbers touch down in first round.
*/
int32_t GetTargetFingers() const
{
return targetFingers_;
}
/**
* @brief Get finger touch up state.
* @return the touch up state, indicates if fingers is still on the screen.
*/
int32_t GetFingerTouchUpState() const
{
return fingerTouchUpState_;
}
/**
* @brief Set the finger touch up state when touch up or finish touch down.
* @param touchUpState the touchUpState to be set.
*/
void SetFingerTouchUpState(const int32_t touchUpState)
{
fingerTouchUpState_ = touchUpState;
}
/**
* @brief Set multi finger gesture state, when gesture recognize start, cancel, complete etc.
* @param gestureState the multiFingerGestureState to be set.
*/
void SetMultiFingerGestureState(const int32_t gestureState)
{
multiFingerGestureState_ = gestureState;
}
/**
* @brief Determine whether multi finger gesture is started.
* @return true if gesture recognize is started, else false.
*/
bool IsMultiFingerGestureStarted() const
{
return multiFingerGestureState_ == MultiFingerGestureState::GESTURE_START;
}
/**
* @brief Determine whether multi finger gesture is started or finished.
* @return true if gesture recognize is started or finished, else false.
*/
bool IsMultiFingerRecognize() const
{
return (multiFingerGestureState_ == MultiFingerGestureState::GESTURE_START ||
multiFingerGestureState_ == MultiFingerGestureState::GESTURE_COMPLETE);
}
/**
* @brief Get the two finger move threshold.
* @return the two finger move threshold, indicates tap state to move state.
*/
float GetTouchSlop() const
{
return touchSlop_;
}
private:
/**
* @brief Cancle the pendding two finger gesture recognize event.
*/
void CancelTwoFingerEvent();
/**
* @brief Cancle the pendding three finger gesture recognize event.
*/
void CancelThreeFingerEvent();
/**
* @brief Cancle the pendding four finger gesture recognize event.
*/
void CancelFourFingerEvent();
/**
* @brief Cancle the pendding finger gesture recognize event by finger num.
* @param fingerNum which type gesture pendding event to be canceled.
*/
void CancelTapAndHoldGestureEvent(const int32_t fingerNum);
/**
* @brief Cancle the pendding multi finger hold gesture recognize event.
*/
void CancelHoldGestureEvent();
/**
* @brief Cancle All pendding inner event.
*/
void CancelAllPenddingEvent();
/**
* @brief Cancel the multi gesture recognize process.
* @param isNoDelayFlag if gesture cancel event is immediately processed.
*/
void CancelGesture(const bool isNoDelayFlag);
/**
* @brief param check for two finger Double tap recognize gesture.
* @param fingerNum the touch event from Multimodal.
* @return true if the used param is ok, else false.
*/
bool ParamCheck(const int32_t fingerNum);
/**
* @brief Get the last touch up time of the first finger.
* @param fingerNum total touch down finger nums, means the lastUpPoint_ size.
* @return the first finger's last touch up time.
*/
int64_t GetLastFirstPointUpTime(const int32_t fingerNum);
/**
* @brief Get the current and pre PointerItems with fingerNum, store in curPoints and prePoints.
* @param curPoints to store the cur touch event pointerItems rst, size is fingerNum.
* @param prePoints to store the pre touch event pointerItems rst, size is fingerNum.
* @param event current touch event, to get the curPoints.
* @param prePointsEventInfo pre touch Event storage, to get the prePoints.
* @return true if the get rst is ok, else false.
*/
bool GetPointerItemWithFingerNum(int32_t fingerNum, std::vector<MMI::PointerEvent::PointerItem> &curPoints,
std::vector<MMI::PointerEvent::PointerItem> &prePoints, MMI::PointerEvent &event,
std::map<int32_t, std::shared_ptr<MMI::PointerEvent>> &prePointsEventInfo);
/**
* @brief check whether the two taps offset is less than slop threshold.
* @param fingerNum touch down finger nums to be processed.
* @param curPoints current touch down pointer infos, size is fingerNum.
* @param prePoints first round touch down pointer infos, size is fingfingerNumerNums.
* @return true if the offset of two taps is less than slop threshold, else false.
*/
bool IsDoubelTapSlopConditionMatch(const int32_t fingerNum,
const std::vector<MMI::PointerEvent::PointerItem> &curPoints,
const std::vector<MMI::PointerEvent::PointerItem> &prePoints);
/**
* @brief Determine whether it is a multi finger double tap gesture.
* @param event the touch event from Multimodal.
* @param fingerNum the target fingerNum to be processed.
* @return true if the gesture is multi finger double tap, else false.
*/
bool IsMultiFingerDoubleTap(MMI::PointerEvent &event, const int32_t fingerNum);
/**
* @brief save touch down point event info.
*/
void storeBaseDownPoint();
/**
* @brief Get move direction by move distance.
* @param dx the x axis distance between base point and current point.
* @param dy the y axis distance between base point and current point.
* @return the move direction, value range is MoveGirectionType.
*/
int32_t GetSwipeDirection(const int32_t dx, const int32_t dy);
/**
* @brief Get the base point Item info by point Id.
* @param basePointerIterm to save th base pointItem info.
* @param pId the point Id to get the pointItem.
* @param pointInfo the touch down event point info storage.
* @return true if get base pointItem success, else false.
*/
bool GetBasePointItem(MMI::PointerEvent::PointerItem &basePointerIterm,
int32_t pId, std::map<int32_t, std::shared_ptr<MMI::PointerEvent>> &pointInfo);
/**
* @brief Save move gesture path info.
* @param event the touch event to be handled.
* @param pId the point Id to be handled.
* @param pointerIterm the point Item info to be saved.
* @param dx the x axis distance between base point and current point.
* @param dy the y axis distance between base point and current point.
*/
void SaveMoveGesturePointerInfo(MMI::PointerEvent &event,
const int32_t pId, const MMI::PointerEvent::PointerItem &pointerIterm, const int32_t dx, const int32_t dy);
/**
* @brief recognize the move path is correct and match a move gesture.
* @param path move path pointer info storage.
* @return true if the move path is correct and match a move gesture, else false.
*/
bool recognizeGesturePath(const std::vector<Pointer> &path);
/**
* @brief Get the matched move gesture by moveDirection and fingerNum.
* @return the matched gesture Id.
*/
GestureType GetMoveGestureId();
/**
* @brief whether the multi finger move event match a move gesture.
* @return true if multi finger move event match a move gesture, else false.
*/
bool IsMoveGestureRecognize();
/**
* @brief Save move gesture path info when finger up.
* @param event the touch event to be handled.
*/
void StoreUpPointInPointerRoute(MMI::PointerEvent &event);
/**
* @brief Handle the first touch down event.
* @param event the touch event to be handled.
*/
void HanleFirstTouchDownEvent(MMI::PointerEvent &event);
/**
* @brief Handle the continue touch down event.
* @param event the touch event to be handled.
*/
void HandleContinueTouchDownEvent(MMI::PointerEvent &event);
/**
* @brief Handle the multi finger touch move event.
* @param event the touch event to be handled.
*/
void HandleMultiFingerMoveEvent(MMI::PointerEvent &event);
/**
* @brief Handle the touch up event, not a move gesture.
* @param event the touch event to be handled.
*/
void HandleMultiFingerTouchUpEvent(MMI::PointerEvent &event);
/**
* @brief Handle the continue touch down event, decide whether it is a multi tap event.
* @param event the touch event to be handled.
* @param fingerNum the touch down fingerNum to be handled.
*/
void HandleMultiTapEvent(MMI::PointerEvent &event, const int32_t fingerNum);
float touchSlop_ = 0.0f;
int32_t doubleTapOffsetThresh_ = 0;
int32_t targetFingers_ = -1; // touch down finger numbers before first time the finger touch up
uint32_t addContinueTapNum_ = 0; // total number of touch down, except the first touch down
int32_t multiFingerGestureState_ = 0; // recognize state, value is MultiFingerGestureState
int32_t fingerTouchUpState_ = FingerTouchUpState::ALL_FINGER_TOUCH_UP;
bool isFirstUp_ = 0; // whether the first time finger touch up
bool isMoveGestureRecognizing = false; // in move gesture recognize process or not
int32_t moveDirection = -1;
float mMinPixelsBetweenSamplesX_ = 0;
float mMinPixelsBetweenSamplesY_ = 0;
std::map<int32_t, std::shared_ptr<MMI::PointerEvent>> firstDownPoint_; // first round touch down points
std::map<int32_t, std::shared_ptr<MMI::PointerEvent>> currentDownPoint_; // current round touch down points
std::map<int32_t, std::shared_ptr<MMI::PointerEvent>> preGesturePoint_; // pre move event points
std::map<int32_t, std::shared_ptr<MMI::PointerEvent>> lastUpPoint_; // last time finger touch up points
std::map<int32_t, std::vector<Pointer>> pointerRoute_;
AccessibilityGestureRecognizeListener *listener_ = nullptr;
std::shared_ptr<MultiFingerGestureHandler> handler_ = nullptr; // multi finger gesture recognize event handler
std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
};
} // namespace Accessibility
} // namespace OHOS
#endif // ACCESSIBILITY_MULTIFINGER_MULTITAP_H

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Copyright (C) 2023-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -20,7 +20,8 @@
#include <string>
#include <thread>
#include "accessibility_event_transmission.h"
#include "accessibility_gesture_recognizer.h"
#include "event_handler.h"
#include "event_runner.h"
namespace OHOS {
namespace Accessibility {
@ -123,4 +124,4 @@ private:
};
} // namespace Accessibility
} // namespace OHOS
#endif // ACCESSIBILITY_TOUCH_GUIDER_H
#endif // ACCESSIBILITY_SCREEN_TOUCH_H

View File

@ -0,0 +1,388 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ACCESSIBILITY_TOUCH_EXPLORATION_H
#define ACCESSIBILITY_TOUCH_EXPLORATION_H
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include "accessibility_element_info.h"
#include "accessibility_element_operator_callback_stub.h"
#include "accessibility_event_transmission.h"
#include "accessible_ability_manager_service.h"
#include "accessibility_def.h"
#include "event_handler.h"
namespace OHOS {
namespace Accessibility {
class TouchExploration;
const int32_t POINTER_COUNT_1 = 1;
const int32_t POINTER_COUNT_2 = 2;
const int32_t POINTER_COUNT_3 = 3;
const int32_t POINTER_COUNT_4 = 4;
const uint32_t MAX_MULTI_FINGER_TYPE = 3;
const int32_t LIMIT_SIZE_TWO = 2;
const int32_t LIMIT_SIZE_THREE = 3;
const int32_t DIRECTION_NUM = 4;
const int32_t TAP_COUNT_MAXIMUM = 3;
const int64_t LONG_PRESS_TIMEOUT = 200000; // microsecond
const int64_t DOUBLE_TAP_TIMEOUT = 300000; // microsecond
const int64_t MULTI_FINGER_TAP_INTERVAL_TIMEOUT = 100000; // microsecond
const int64_t SWIPE_COMPLETE_TIMEOUT = 300000; // microsecond
const int32_t MINI_POINTER_DISTANCE_DIP = 200;
const float DEGREES_THRESHOLD = 0.0f;
const uint32_t MIN_MULTI_FINGER_SWIPE_POINTER_NUM = 2;
const float TOUCH_SLOP = 8.0f;
const float MULTI_TAP_SLOP = 100.0f;
const float MULTI_TAP_SLOP_DELTA = 0.5f;
const int32_t SCREEN_AXIS_NUM = 2;
const double MAX_DRAG_GESTURE_COSINE = 0.525321989;
const int32_t MM_PER_CM = 10;
const double EPSINON = 0.01;
const float PIXEL_MULTIPLIER = 0.1f;
const int32_t DIVIDE_NUM = 2;
#define BIND(func) [this](MMI::PointerEvent& event) { (func(event)); }
/**
* @brief touch exploration state define
*/
enum class TouchExplorationState : int32_t {
TOUCH_INIT,
PASSING_THROUGH,
INVALID,
ONE_FINGER_DOWN,
ONE_FINGER_LONG_PRESS,
ONE_FINGER_SWIPE,
ONE_FINGER_SINGLE_TAP,
ONE_FINGER_SINGLE_TAP_THEN_DOWN,
TWO_FINGERS_DOWN,
TWO_FINGERS_DRAG,
TWO_FINGERS_TAP,
TWO_FINGERS_CONTINUE_DOWN,
TWO_FINGERS_UNKNOWN,
THREE_FINGERS_DOWN,
THREE_FINGERS_SWIPE,
THREE_FINGERS_TAP,
THREE_FINGERS_CONTINUE_DOWN,
FOUR_FINGERS_DOWN,
FOUR_FINGERS_SWIPE,
FOUR_FINGERS_TAP,
FOUR_FINGERS_CONTINUE_DOWN
};
enum class ChangeAction : int32_t {
NO_CHANGE,
HOVER_MOVE,
POINTER_DOWN,
POINTER_UP,
HOVER_ENTER,
HOVER_EXIT,
HOVER_CANCEL
};
struct Pointer {
float px_;
float py_;
};
class TouchExplorationEventHandler : public AppExecFwk::EventHandler {
public:
TouchExplorationEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
TouchExploration &tgServer);
virtual ~TouchExplorationEventHandler() = default;
/**
* @brief Process the event of install system bundles.
* @param event Indicates the event to be processed.
*/
virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
private:
TouchExploration &server_;
};
class TouchExploration : public EventTransmission {
public:
static constexpr uint32_t SEND_HOVER_MSG = 0;
static constexpr uint32_t LONG_PRESS_MSG = 1;
static constexpr uint32_t DOUBLE_TAP_MSG = 2;
static constexpr uint32_t SWIPE_COMPLETE_TIMEOUT_MSG = 3;
static constexpr uint32_t TWO_FINGER_SINGLE_TAP_MSG = 4;
static constexpr uint32_t TWO_FINGER_LONG_PRESS_MSG = 5;
static constexpr uint32_t TWO_FINGER_DOUBLE_TAP_MSG = 6;
static constexpr uint32_t TWO_FINGER_DOUBLE_TAP_AND_HOLD_MSG = 7;
static constexpr uint32_t TWO_FINGER_TRIPLE_TAP_MSG = 8;
static constexpr uint32_t TWO_FINGER_TRIPLE_TAP_AND_HOLD_MSG = 9;
static constexpr uint32_t THREE_FINGER_SINGLE_TAP_MSG = 10;
static constexpr uint32_t THREE_FINGER_LONG_PRESS_MSG = 11;
static constexpr uint32_t THREE_FINGER_DOUBLE_TAP_MSG = 12;
static constexpr uint32_t THREE_FINGER_DOUBLE_TAP_AND_HOLD_MSG = 13;
static constexpr uint32_t THREE_FINGER_TRIPLE_TAP_MSG = 14;
static constexpr uint32_t THREE_FINGER_TRIPLE_TAP_AND_HOLD_MSG = 15;
static constexpr uint32_t FOUR_FINGER_SINGLE_TAP_MSG = 16;
static constexpr uint32_t FOUR_FINGER_LONG_PRESS_MSG = 17;
static constexpr uint32_t FOUR_FINGER_DOUBLE_TAP_MSG = 18;
static constexpr uint32_t FOUR_FINGER_DOUBLE_TAP_AND_HOLD_MSG = 19;
static constexpr uint32_t FOUR_FINGER_TRIPLE_TAP_MSG = 20;
static constexpr uint32_t FOUR_FINGER_TRIPLE_TAP_AND_HOLD_MSG = 21;
static constexpr uint32_t WAIT_ANOTHER_FINGER_DOWN_MSG = 22;
static constexpr int32_t SWIPE_UP = 0;
static constexpr int32_t SWIPE_DOWN = 1;
static constexpr int32_t SWIPE_LEFT = 2;
static constexpr int32_t SWIPE_RIGHT = 3;
static constexpr GestureType GESTURE_DIRECTION[DIRECTION_NUM] = {
GestureType::GESTURE_SWIPE_UP,
GestureType::GESTURE_SWIPE_DOWN,
GestureType::GESTURE_SWIPE_LEFT,
GestureType::GESTURE_SWIPE_RIGHT
};
static constexpr GestureType GESTURE_DIRECTION_TO_ID[DIRECTION_NUM][DIRECTION_NUM] = {
{
GestureType::GESTURE_SWIPE_UP,
GestureType::GESTURE_SWIPE_UP_THEN_DOWN,
GestureType::GESTURE_SWIPE_UP_THEN_LEFT,
GestureType::GESTURE_SWIPE_UP_THEN_RIGHT,
},
{
GestureType::GESTURE_SWIPE_DOWN_THEN_UP,
GestureType::GESTURE_SWIPE_DOWN,
GestureType::GESTURE_SWIPE_DOWN_THEN_LEFT,
GestureType::GESTURE_SWIPE_DOWN_THEN_RIGHT,
},
{
GestureType::GESTURE_SWIPE_LEFT_THEN_UP,
GestureType::GESTURE_SWIPE_LEFT_THEN_DOWN,
GestureType::GESTURE_SWIPE_LEFT,
GestureType::GESTURE_SWIPE_LEFT_THEN_RIGHT,
},
{
GestureType::GESTURE_SWIPE_RIGHT_THEN_UP,
GestureType::GESTURE_SWIPE_RIGHT_THEN_DOWN,
GestureType::GESTURE_SWIPE_RIGHT_THEN_LEFT,
GestureType::GESTURE_SWIPE_RIGHT
}
};
static constexpr uint32_t GESTURE_TAP_MSG[TAP_COUNT_MAXIMUM][MAX_MULTI_FINGER_TYPE] = {
{
TWO_FINGER_SINGLE_TAP_MSG,
THREE_FINGER_SINGLE_TAP_MSG,
FOUR_FINGER_SINGLE_TAP_MSG,
},
{
TWO_FINGER_DOUBLE_TAP_MSG,
THREE_FINGER_DOUBLE_TAP_MSG,
FOUR_FINGER_DOUBLE_TAP_MSG,
},
{
TWO_FINGER_TRIPLE_TAP_MSG,
THREE_FINGER_TRIPLE_TAP_MSG,
FOUR_FINGER_TRIPLE_TAP_MSG,
}
};
static constexpr uint32_t GESTURE_HOLD_MSG[TAP_COUNT_MAXIMUM][MAX_MULTI_FINGER_TYPE] = {
{
TWO_FINGER_LONG_PRESS_MSG,
THREE_FINGER_LONG_PRESS_MSG,
FOUR_FINGER_LONG_PRESS_MSG,
},
{
TWO_FINGER_DOUBLE_TAP_AND_HOLD_MSG,
THREE_FINGER_DOUBLE_TAP_AND_HOLD_MSG,
FOUR_FINGER_DOUBLE_TAP_AND_HOLD_MSG,
},
{
TWO_FINGER_TRIPLE_TAP_AND_HOLD_MSG,
THREE_FINGER_TRIPLE_TAP_AND_HOLD_MSG,
FOUR_FINGER_TRIPLE_TAP_AND_HOLD_MSG,
}
};
TouchExploration();
~TouchExploration() {}
void StartUp();
void Clear();
void HoverEventRunner();
void SendAccessibilityEventToAA(EventType eventType);
void SendTouchEventToAA(MMI::PointerEvent &event);
void SendGestureEventToAA(GestureType gestureId);
void SendEventToMultimodal(MMI::PointerEvent &event, ChangeAction action);
void SendScreenWakeUpEvent(MMI::PointerEvent &event);
void SendUpForDraggingDownEvent();
void ProcessMultiFingerGesture(uint32_t eventId);
void CancelPostEvent(uint32_t innerEventID);
void CancelMultiFingerTapEvent();
void CancelMultiFingerTapAndHoldEvent();
/**
* @brief Handle pointer events from previous event stream node.
*
* @param event the pointer event to be handled.
* @return true: the event has been processed and does not need to be passed to the next node;
* false: the event is not processed.
*/
bool OnPointerEvent(MMI::PointerEvent &event) override;
/* Set current state */
inline void SetCurrentState(TouchExplorationState state)
{
currentState_ = state;
}
/* Get current state */
inline TouchExplorationState GetCurrentState()
{
return currentState_;
}
private:
// Processing Functions in the State Machine
void HandleInitStateDown(MMI::PointerEvent &event);
void HandleInitStateUp(MMI::PointerEvent &event);
void HandleInitStateMove(MMI::PointerEvent &event);
void HandlePassingThroughState(MMI::PointerEvent &event);
void HandleInvalidState(MMI::PointerEvent &event);
void HandleOneFingerDownStateDown(MMI::PointerEvent &event);
void HandleOneFingerDownStateUp(MMI::PointerEvent &event);
void HandleOneFingerDownStateMove(MMI::PointerEvent &event);
void HandleOneFingerLongPressStateDown(MMI::PointerEvent &event);
void HandleOneFingerLongPressStateUp(MMI::PointerEvent &event);
void HandleOneFingerLongPressStateMove(MMI::PointerEvent &event);
void HandleOneFingerSwipeStateDown(MMI::PointerEvent &event);
void HandleOneFingerSwipeStateUp(MMI::PointerEvent &event);
void HandleOneFingerSwipeStateMove(MMI::PointerEvent &event);
void HandleOneFingerSingleTapStateDown(MMI::PointerEvent &event);
void HandleOneFingerSingleTapThenDownStateDown(MMI::PointerEvent &event);
void HandleOneFingerSingleTapThenDownStateUp(MMI::PointerEvent &event);
void HandleOneFingerSingleTapThenDownStateMove(MMI::PointerEvent &event);
void HandleTwoFingersDownStateDown(MMI::PointerEvent &event);
void HandleTwoFingersDownStateUp(MMI::PointerEvent &event);
void HandleTwoFingersDownStateMove(MMI::PointerEvent &event);
void HandleTwoFingersDragStateDown(MMI::PointerEvent &event);
void HandleTwoFingersDragStateUp(MMI::PointerEvent &event);
void HandleTwoFingersDragStateMove(MMI::PointerEvent &event);
void HandleTwoFingersTapStateDown(MMI::PointerEvent &event);
void HandleMultiFingersTapStateUp(MMI::PointerEvent &event);
void HandleTwoFingersTapStateMove(MMI::PointerEvent &event);
void HandleMultiFingersContinueDownStateDown(MMI::PointerEvent &event);
void HandleTwoFingersContinueDownStateUp(MMI::PointerEvent &event);
void HandleTwoFingersContinueDownStateMove(MMI::PointerEvent &event);
void HandleTwoFingersUnknownStateDown(MMI::PointerEvent &event);
void HandleTwoFingersUnknownStateUp(MMI::PointerEvent &event);
void HandleTwoFingersUnknownStateMove(MMI::PointerEvent &event);
void HandleThreeFingersDownStateDown(MMI::PointerEvent &event);
void HandleThreeFingersDownStateUp(MMI::PointerEvent &event);
void HandleThreeFingersDownStateMove(MMI::PointerEvent &event);
void HandleThreeFingersSwipeStateDown(MMI::PointerEvent &event);
void HandleThreeFingersSwipeStateUp(MMI::PointerEvent &event);
void HandleThreeFingersSwipeStateMove(MMI::PointerEvent &event);
void HandleThreeFingersTapStateDown(MMI::PointerEvent &event);
void HandleThreeFingersTapStateMove(MMI::PointerEvent &event);
void HandleThreeFingersContinueDownStateUp(MMI::PointerEvent &event);
void HandleThreeFingersContinueDownStateMove(MMI::PointerEvent &event);
void HandleFourFingersDownStateDown(MMI::PointerEvent &event);
void HandleFourFingersDownStateUp(MMI::PointerEvent &event);
void HandleFourFingersDownStateMove(MMI::PointerEvent &event);
void HandleFourFingersSwipeStateDown(MMI::PointerEvent &event);
void HandleFourFingersSwipeStateUp(MMI::PointerEvent &event);
void HandleFourFingersSwipeStateMove(MMI::PointerEvent &event);
void HandleFourFingersTapStateDown(MMI::PointerEvent &event);
void HandleFourFingersTapStateMove(MMI::PointerEvent &event);
void HandleFourFingersContinueDownStateUp(MMI::PointerEvent &event);
void HandleFourFingersContinueDownStateMove(MMI::PointerEvent &event);
void HandleCancelEvent(MMI::PointerEvent &event);
void InitOneFingerGestureFuncMap();
void InitTwoFingerGestureFuncMap();
void InitThreeFingerGestureFuncMap();
void InitFourFingerGestureFuncMap();
void HandlePointerEvent(MMI::PointerEvent &event);
void AddOneFingerSwipeEvent(MMI::PointerEvent &event);
std::vector<Pointer> GetOneFingerSwipePath();
int32_t GetSwipeDirection(const int32_t dx, const int32_t dy);
void RecordFocusedLocation(MMI::PointerEvent &event);
void OffsetEvent(MMI::PointerEvent &event);
bool GetBasePointItem(MMI::PointerEvent::PointerItem &basePointerIterm, int32_t pId);
void GetPointOffset(MMI::PointerEvent &event, std::vector<float> &firstPointOffset,
std::vector<float> &secondPointOffset);
float GetAngleCos(float offsetX, float offsetY, bool isGetX);
bool IsDragGestureAccept(MMI::PointerEvent &event);
void SendDragDownEventToMultimodal(MMI::PointerEvent event);
bool GetPointerItemWithFingerNum(int32_t fingerNum, std::vector<MMI::PointerEvent::PointerItem> &curPoints,
std::vector<MMI::PointerEvent::PointerItem> &prePoints, MMI::PointerEvent &event);
bool IsMultiFingerMultiTap(MMI::PointerEvent &event, const int32_t fingerNum);
bool IsMultiFingerMultiTapGesture(MMI::PointerEvent &event, const int32_t fingerNum);
void HandleMultiFingersTapStateDown(MMI::PointerEvent &event, int32_t fingerNum);
void HandleMultiFingersTapStateMove(MMI::PointerEvent &event, int32_t fingerNum);
void HandleMultiFingersContinueDownStateUp(MMI::PointerEvent &event, int32_t fingerNum);
void HandleMultiFingersContinueDownStateMove(MMI::PointerEvent &event, int32_t fingerNum);
void StoreMultiFingerSwipeBaseDownPoint();
bool GetMultiFingerSwipeBasePointerItem(MMI::PointerEvent::PointerItem &basePointerIterm, int32_t pId);
bool SaveMultiFingerSwipeGesturePointerInfo(MMI::PointerEvent &event);
bool RecognizeMultiFingerSwipePath(const std::vector<Pointer> &path);
GestureType GetMultiFingerSwipeGestureId(int32_t fingerNum);
void HandleMultiFingersSwipeStateUp(MMI::PointerEvent &event, int32_t fingerNum);
std::map<uint32_t, GestureType> GetMultiFingerMsgToGestureMap();
inline float CalculateMoveThreshold(int dpi)
{
return dpi * (1.0f / 25.4f) * MM_PER_CM;
}
std::shared_ptr<TouchExplorationEventHandler> handler_ = nullptr;
std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
using HandleEventFunc = std::function<void(MMI::PointerEvent &)>;
std::map<TouchExplorationState, std::map<int32_t, HandleEventFunc>> handleEventFuncMap_ = {};
TouchExplorationState currentState_ = TouchExplorationState::TOUCH_INIT;
std::list<MMI::PointerEvent> receivedPointerEvents_ {};
std::list<MMI::PointerEvent> injectedPointerDownEvents_ {};
// single-finger gesture
int32_t offsetX_ = 0;
int32_t offsetY_ = 0;
float moveThreshold_ = 0;
float xMinPixels_ = 0;
float yMinPixels_ = 0;
std::vector<Pointer> oneFingerSwipeRoute_ {};
MMI::PointerEvent::PointerItem oneFingerSwipePrePointer_ {};
// multi-finger gesture
int32_t draggingPid_ = -1;
int32_t multiTapNum_ = 0;
int32_t multiTapOffsetThresh_ = 0;
int32_t multiFingerSwipeDirection_ = -1;
float mMinPixelsBetweenSamplesX_ = 0;
float mMinPixelsBetweenSamplesY_ = 0;
std::map<int32_t, std::vector<Pointer>> multiFingerSwipeRoute_ {};
std::map<int32_t, std::shared_ptr<MMI::PointerEvent>> multiFingerSwipePrePoint_ {};
};
} // namespace Accessibility
} // namespace OHOS
#endif // ACCESSIBILITY_TOUCH_EXPLORATION_H

View File

@ -1,532 +0,0 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ACCESSIBILITY_TOUCH_GUIDER_H
#define ACCESSIBILITY_TOUCH_GUIDER_H
#include <string>
#include "accessibility_element_info.h"
#include "accessibility_element_operator_callback_stub.h"
#include "accessibility_event_transmission.h"
#include "accessibility_gesture_recognizer.h"
#include "accessibility_multifinger_multitap.h"
#include "accessible_ability_manager_service.h"
namespace OHOS {
namespace Accessibility {
class TouchGuider;
const int64_t EXIT_GESTURE_REC_TIMEOUT = 400; // millisecond
const double MAX_DRAG_GESTURE_COSINE = 0.525321989;
const int32_t MINI_POINTER_DISTANCE_DIP = 200;
const int32_t INDEX_0 = 0;
const int32_t INDEX_1 = 1;
const int32_t INIT_POINT_ID = -1;
const float INIT_MMIPOINT = 0.0f;
const int32_t INIT_POINT_DISPLAY = 0;
#define DIVIDE_2(num) ((num) / 2)
#define EPSINON 0.01
/**
* @brief touch Guider state define
*/
enum class TouchGuideState : int32_t {
TOUCH_GUIDING,
DRAGGING,
TRANSMITTING,
GESTURE_RECOGNIZING,
PASSING_THROUGH
};
/**
* @brief Click location define
*/
enum ClickLocation : int32_t {
CLICK_NONE,
CLICK_ACCESSIBILITY_FOCUS,
CLICK_LAST_TOUCH_GUIDE
};
/**
* @brief struct to record injected pointers.
*/
struct InjectedEventRecorder {
std::set<int32_t> downPointers {};
int32_t downPointerNum;
int64_t lastDownTime;
std::shared_ptr<MMI::PointerEvent> lastHoverEvent;
};
/**
* @brief struct to record received pointers.
*/
struct ReceivedEventRecorder {
std::map<int32_t, int32_t> pointerDownX;
std::map<int32_t, int32_t> pointerDownY;
std::map<int32_t, int64_t> pointerActionTime;
std::shared_ptr<MMI::PointerEvent> lastEvent;
};
enum ChangeAction : int32_t {
NO_CHANGE,
HOVER_MOVE,
POINTER_DOWN,
POINTER_UP,
POINTER_MOVE,
HOVER_ENTER,
HOVER_EXIT,
};
class TGEventHandler : public AppExecFwk::EventHandler {
public:
TGEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
TouchGuider &tgServer);
virtual ~TGEventHandler() = default;
/**
* @brief Process the event of install system bundles.
* @param event Indicates the event to be processed.
*/
virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
private:
/**
* @brief Send HoverEnter and HoverMove to Multimodal.
*/
void HoverEnterAndMoveRunner();
/**
* @brief Send HoverExit to Multimodal.
*/
void HoverExitRunner();
TouchGuider &tgServer_;
};
class TouchGuider : public EventTransmission {
public:
static constexpr uint32_t EXIT_GESTURE_REC_MSG = 0;
static constexpr uint32_t SEND_HOVER_ENTER_MOVE_MSG = 1;
static constexpr uint32_t SEND_HOVER_EXIT_MSG = 2;
static constexpr uint32_t SEND_TOUCH_INTERACTION_END_MSG = 3;
static constexpr uint32_t SEND_TOUCH_GUIDE_END_MSG = 4;
/**
* @brief A constructor used to create a touchGuide instance.
*/
TouchGuider();
/**
* @brief A destructor used to delete the touchGuide instance.
*/
~TouchGuider() {}
/**
* @brief TouchGuide start up.
*/
void StartUp();
/**
* @brief Handle pointer events from previous event stream node.
*
* @param event the pointer event to be handled.
* @return true: the event has been processed and does not need to be passed to the next node;
* false: the event is not processed.
*/
bool OnPointerEvent(MMI::PointerEvent &event) override;
/**
* @brief Handle pointer events from previous event stream node.
*
* @param event the pointer event to be handled.
*/
void HandlePointerEvent(MMI::PointerEvent &event);
/**
* @brief Destroy event state.
*/
void DestroyEvents() override;
/**
* @brief Send pointer down event to multimodal input.
* @param event event the touch event from Multimodal, set the down point to the event and send.
* @param action point action send to multimode.
*/
void SendPointerDownEventToMultimodal(MMI::PointerEvent event, int32_t action);
/**
* @brief Send event to multimodal input.
* @param event the event prepared to send to Multimodal
* @param action the action of the event
*/
void SendEventToMultimodal(MMI::PointerEvent &event, int32_t action);
/**
* @brief Send accessibility event to specific AccessibleAbility.
* @param eventType the type of the event
*/
void SendAccessibilityEventToAA(EventType eventType);
/**
* @brief Send gesture event to specific AccessibleAbility.
* @param gestureId the gesture id of the event
*/
void SendGestureEventToAA(GestureType gestureId);
/**
* @brief Get hover enter and move event.
* @return Returns pointerEvents_ list.
*/
std::list<MMI::PointerEvent> getHoverEnterAndMoveEvent();
/**
* @brief Clear hover enter and move event.
*/
void ClearHoverEnterAndMoveEvent();
/**
* @brief Get last received event.
* @return Returns last event ptr.
*/
std::shared_ptr<MMI::PointerEvent> getLastReceivedEvent();
/* For TouchGuide */
inline void OnTouchInteractionStart()
{
isTouchStart_ = true;
}
inline void OnTouchInteractionEnd()
{
isTouchStart_ = false;
}
/**
* @brief whether touch guide end.
* @return true if touch guide end, else false.
*/
inline bool IsTouchInteractionEnd()
{
return isTouchStart_ == false;
}
/**
* @brief Perform action on Accessibility Focus.
* @param action the action of Accessibility node.
* @return Returns true if the action perform successfully; returns false code otherwise.
*/
bool ExecuteActionOnAccessibilityFocused(const ActionType &action);
static int64_t lastDoubleTapTime;
private:
class TouchGuideListener : public AccessibilityGestureRecognizeListener {
public:
/**
* @brief A constructor used to create a TouchGuideListener instance.
*/
explicit TouchGuideListener(TouchGuider &server) : server_(server) {};
/**
* @brief Prepare to send the event corresponding to the single tap to the Multimodal.
* @param event the touch event from Multimodal
*/
bool OnDoubleTap(MMI::PointerEvent &event) override;
/**
* @brief Send GESTURE_BEGIN to AccessibleAbility.
*/
bool OnStarted() override;
/**
* @brief Send GESTURE_BEGIN to AccessibleAbility when multi finger gesture start.
* @param isTwoFingerGesture whether the gesture is triggered by two finger.
*/
void MultiFingerGestureOnStarted(bool isTwoFingerGesture) override;
/**
* @brief Send GESTURE_END and TOUCH_END to AccessibleAbility.
* @param gestureId the id of gesture
*/
bool OnCompleted(GestureType gestureId) override;
/**
* @brief Send GESTURE_END and TOUCH_END to AccessibleAbility when multi finger gesture complete.
* @param gestureId the id of gesture.
*/
void MultiFingerGestureOnCompleted(GestureType gestureId) override;
/**
* @brief The gesture has been cancelled.
* @param event the touch event from Multimodal
*/
bool OnCancelled(MMI::PointerEvent &event) override;
/**
* @brief The gesture has been cancelled.
* @param isNoDelayFlag whether the gesture recognize process is immediately canceled.
*/
void MultiFingerGestureOnCancelled(const bool isNoDelayFlag) override;
private:
TouchGuider &server_;
};
class ElementOperatorCallbackImpl : public AccessibilityElementOperatorCallbackStub {
public:
ElementOperatorCallbackImpl() = default;
~ElementOperatorCallbackImpl() = default;
virtual void SetSearchElementInfoByAccessibilityIdResult(const std::vector<AccessibilityElementInfo> &infos,
const int32_t requestId) override;
virtual void SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> &infos,
const int32_t requestId) override;
virtual void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info,
const int32_t requestId) override;
virtual void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int32_t requestId) override;
virtual void SetExecuteActionResult(const bool succeeded, const int32_t requestId) override;
private:
ffrt::promise<void> promise_;
bool executeActionResult_ = false;
AccessibilityElementInfo accessibilityInfoResult_ = {};
std::vector<AccessibilityElementInfo> elementInfosResult_;
friend class TouchGuider;
};
/**
* @brief Determine whether to clear the touchguide.
*/
void Clear();
/**
* @brief clear the touchguide.
* @param event the last event from Multimodal
*/
void Clear(MMI::PointerEvent &event);
/**
* @brief Handle touch events on touchExploring state.
* @param event the touch event from Multimodal
*/
void HandleTouchGuidingState(MMI::PointerEvent &event);
/**
* @brief Handle touch events on dragging state.
* @param event the touch event from Multimodal
*/
void HandleDraggingState(MMI::PointerEvent &event);
/**
* @brief Handle touch events on transmitting state.
* @param event the touch event from Multimodal
*/
void HandleTransmitingState(MMI::PointerEvent &event);
/**
* @brief Handle touch events on passing through state.
* @param event the touch event from Multimodal
*/
void HandlePassingThroughState(MMI::PointerEvent &event);
/**
* @brief Determine whether it is a drag gesture.
* @param event the touch event from Multimodal
* @return whether the dragGesture is accepted.
*/
bool IsDragGestureAccept(MMI::PointerEvent &event);
/**
* @brief Get the offset of current points and touch down points.
* @param event the current touch event from Multimodal.
* @param firstPointOffset the first finger offset result, xAxis offset and yAxis offset.
* @param firstPointOffset the second finger offset result, xAxis offset and yAxis offset.
*/
void GetPointOffset(MMI::PointerEvent &event, std::vector<float> &firstPointOffset,
std::vector<float> &secondPointOffset) const;
/**
* @brief Determine whether it is a move gesture.
* @param event the touch event from Multimodal.
* @return whether this is a scolling.
*/
bool IsRealMoveState(MMI::PointerEvent &event) const;
/**
* @brief Get Angle Cos value.
* @param offsetX the X value
* @param offsetY the Y value
* @param isGetX whether is the Angle corresponding to the X axis
* @return Angle Cos value.
*/
float GetAngleCos(float offsetX, float offsetY, bool isGetX);
/**
* @brief Get the info of injected event.
* @param event the event prepared to send to Multimodal
*/
void RecordInjectedEvent(MMI::PointerEvent &event);
/**
* @brief Get the info of Received event.
* @param event event the touch event from Multimodal
*/
void RecordReceivedEvent(MMI::PointerEvent &event);
/**
* @brief Send touch event to specific AccessibleAbility.
* @param event the touch event from Multimodal
*/
void SendTouchEventToAA(MMI::PointerEvent &event);
/**
* @brief Clear received recorder info.
*/
void ClearReceivedEventRecorder();
/**
* @brief Clear Injected recorder info.
*/
void ClearInjectedEventRecorder();
/**
* @brief Send exit event to multimodal.
*/
void SendExitEvents();
/**
* @brief Send all down events to multimodal.
* @param event the event prepared to send to Multimodal
*/
void SendAllDownEvents(MMI::PointerEvent &event);
/**
* @brief Send all up events to multimodal.
* @param event the event prepared to send to Multimodal
*/
void SendAllUpEvents(MMI::PointerEvent &event);
/**
* @brief Send all up events to multimodal.
* @param event the event prepared to send to Multimodal
*/
void SendUpForAllInjectedEvent(MMI::PointerEvent &event);
/**
* @brief Send exit message.
*/
void PostGestureRecognizeExit();
/**
* @brief Send enter and move message.
* @param event event the touch event from Multimodal
*/
void PostHoverEnterAndMove(MMI::PointerEvent &event);
/**
* @brief Send exit message.
*/
void PostHoverExit();
/**
* @brief Send accessibility event message.
* @param innerEventID the id of inner event
*/
void PostAccessibilityEvent(uint32_t innerEventID);
/**
* @brief Cancel message.
* @param innerEventID the id of inner event
*/
void CancelPostEvent(uint32_t innerEventID);
/**
* @brief Cancel message if it has been sent.
* @param innerEventID the id of inner event
*/
void CancelPostEventIfNeed(uint32_t innerEventID);
/**
* @brief Check whether it has been sending.
* @param innerEventID the id of inner event
*/
bool HasEventPending(uint32_t innerEventID);
/**
* @brief Force send and remove event.
* @param innerEventID the id of inner event
* @param event event the touch event from Multimodal
*/
void ForceSendAndRemoveEvent(uint32_t innerEventID, MMI::PointerEvent &event);
/**
* @brief Handle down events on touchExploring state.
* @param event event the touch event from Multimodal
*/
void HandleTouchGuidingStateInnerDown(MMI::PointerEvent &event);
/**
* @brief Handle move events on touchExploring state.
* @param event event the touch event from Multimodal
*/
void HandleTouchGuidingStateInnerMove(MMI::PointerEvent &event);
/**
* @brief Handle move events on dragging state.
* @param event event the touch event from Multimodal
*/
void HandleDraggingStateInnerMove(MMI::PointerEvent &event);
/**
* @brief Ignore repeat execute action.
*/
bool IgnoreRepeatExecuteAction();
/**
* @brief Calculate Offset.
* @param event event the touch event from Multimodal
*/
void OffsetEvent(MMI::PointerEvent &event);
/**
* @brief Find Focused Element.
* @param elementInfo the focused element.
* @return Returns true if find focused flement successfully; returns false code otherwise.
*/
bool FindFocusedElement(AccessibilityElementInfo &elementInfo);
int32_t currentState_ = -1;
int32_t longPressPointId_ = INIT_POINT_ID;
float longPressOffsetX_ = INIT_MMIPOINT;
float longPressOffsetY_ = INIT_MMIPOINT;
bool isTouchStart_ = false;
bool isTouchGuiding_ = false;
ReceivedEventRecorder receivedRecorder_ = {};
InjectedEventRecorder injectedRecorder_ = {};
std::list<MMI::PointerEvent> pointerEvents_ {};
AccessibilityGestureRecognizer gestureRecognizer_;
AccessibilityMultiTapGestureRecognizer multiFingerGestureRecognizer_;
std::unique_ptr<TouchGuideListener> touchGuideListener_ = nullptr;
std::shared_ptr<TGEventHandler> handler_ = nullptr;
std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
std::shared_ptr<MMI::PointerEvent> doubleTapLongPressDownEvent_ = nullptr;
bool focusedElementExist_ = false;
int32_t leftTopX_ = INIT_POINT_DISPLAY;
int32_t leftTopY_ = INIT_POINT_DISPLAY;
int32_t rightBottomX_ = INIT_POINT_DISPLAY;
int32_t rightBottomY_ = INIT_POINT_DISPLAY;
int32_t currentPid_ = -1;
std::list<MMI::PointerEvent> cachedPointerEvents_ {};
};
} // namespace Accessibility
} // namespace OHOS
#endif // ACCESSIBILITY_TOUCH_GUIDER_H

View File

@ -1,480 +0,0 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed On an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "accessibility_gesture_recognizer.h"
#include "hilog_wrapper.h"
#include <cinttypes>
namespace OHOS {
namespace Accessibility {
namespace {
constexpr int32_t LIMIT_SIZE_TWO = 2;
constexpr int32_t LIMIT_SIZE_THREE = 3;
constexpr int32_t POINTER_COUNT_1 = 1;
constexpr float EPSINON = 0.0001f;
constexpr float TOUCH_SLOP = 8.0f;
} // namespace
GestureHandler::GestureHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
AccessibilityGestureRecognizer &server) : AppExecFwk::EventHandler(runner), server_(server)
{
}
void GestureHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
{
HILOG_DEBUG();
if (!event) {
HILOG_ERROR("event is null");
return;
}
switch (event->GetInnerEventId()) {
case AccessibilityGestureRecognizer::LONG_PRESS_MSG:
RemoveEvent(AccessibilityGestureRecognizer::SINGLE_TAP_MSG);
server_.SetIsLongpress(true);
server_.MaybeRecognizeLongPress(*server_.GetCurDown());
break;
case AccessibilityGestureRecognizer::SINGLE_TAP_MSG:
if (!server_.GetContinueDown()) {
server_.SingleTapDetected();
}
break;
default:
break;
}
}
float AccessibilityGestureRecognizer::GetDoubleTapMoveThreshold(float densityDpi)
{
return densityDpi * (1.0f / 25.4f) * MM_PER_CM;
}
AccessibilityGestureRecognizer::AccessibilityGestureRecognizer()
{
HILOG_DEBUG();
#ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER
AccessibilityDisplayManager &displayMgr = Singleton<AccessibilityDisplayManager>::GetInstance();
auto display = displayMgr.GetDefaultDisplay();
if (!display) {
HILOG_ERROR("get display is nullptr");
return;
}
threshold_ = GetDoubleTapMoveThreshold(display->GetDpi());
xMinPixels_ = MIN_PIXELS(display->GetWidth());
yMinPixels_ = MIN_PIXELS(display->GetHeight());
float densityPixels = display->GetVirtualPixelRatio();
int32_t slop = static_cast<int32_t>(densityPixels * DOUBLE_TAP_SLOP + 0.5f);
doubleTapScaledSlop_ = slop * slop;
#else
HILOG_DEBUG("not support display manager");
threshold_ = 1;
xMinPixels_ = 1;
yMinPixels_ = 1;
int32_t slop = static_cast<int32_t>(1 * DOUBLE_TAP_SLOP + 0.5f);
doubleTapScaledSlop_ = slop * slop;
#endif
runner_ = Singleton<AccessibleAbilityManagerService>::GetInstance().GetMainRunner();
if (!runner_) {
HILOG_ERROR("get runner failed");
return;
}
handler_ = std::make_shared<GestureHandler>(runner_, *this);
if (!handler_) {
HILOG_ERROR("create event handler failed");
return;
}
}
void AccessibilityGestureRecognizer::RegisterListener(AccessibilityGestureRecognizeListener& listener)
{
HILOG_DEBUG();
listener_ = &listener;
}
void AccessibilityGestureRecognizer::UnregisterListener()
{
HILOG_DEBUG();
listener_ = nullptr;
}
bool AccessibilityGestureRecognizer::OnPointerEvent(MMI::PointerEvent &event)
{
HILOG_DEBUG();
switch (event.GetPointerAction()) {
case MMI::PointerEvent::POINTER_ACTION_DOWN:
if (isDoubleTap_ && isLongpress_) {
HILOG_INFO("isDoubleTap and longpress, on down event");
return false;
}
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
HandleTouchDownEvent(event);
} else {
Clear();
isRecognizingGesture_ = false;
isGestureStarted_ = false;
pointerRoute_.clear();
}
break;
case MMI::PointerEvent::POINTER_ACTION_MOVE:
if (isDoubleTap_ && isLongpress_) {
HILOG_DEBUG("isDoubleTap and isLongpress, send move event to Multimodel.");
return false;
}
return HandleTouchMoveEvent(event);
case MMI::PointerEvent::POINTER_ACTION_UP:
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
return HandleTouchUpEvent(event);
}
break;
case MMI::PointerEvent::POINTER_ACTION_CANCEL:
Clear();
break;
default:
break;
}
if (!isRecognizingGesture_) {
return false;
}
return StandardGestureRecognizer(event);
}
void AccessibilityGestureRecognizer::Clear()
{
HILOG_DEBUG();
isFirstTapUp_ = false;
isDoubleTap_ = false;
isGestureStarted_ = false;
isRecognizingGesture_ = false;
pointerRoute_.clear();
continueDown_ = false;
StandardGestureCanceled();
}
void AccessibilityGestureRecognizer::HandleTouchDownEvent(MMI::PointerEvent &event)
{
HILOG_DEBUG();
Pointer mp;
MMI::PointerEvent::PointerItem pointerIterm;
if (!event.GetPointerItem(event.GetPointerId(), pointerIterm)) {
HILOG_WARN("get GetPointerItem(%{public}d) failed", event.GetPointerId());
}
mp.px_ = static_cast<float>(pointerIterm.GetDisplayX());
mp.py_ = static_cast<float>(pointerIterm.GetDisplayY());
isDoubleTap_ = false;
isRecognizingGesture_ = true;
isGestureStarted_ = false;
pointerRoute_.clear();
pointerRoute_.push_back(mp);
prePointer_ = pointerIterm;
startPointer_ = pointerIterm;
startTime_ = event.GetActionTime();
}
void AccessibilityGestureRecognizer::AddSwipePosition(MMI::PointerEvent::PointerItem &pointerIterm)
{
HILOG_DEBUG();
Pointer mp;
prePointer_ = pointerIterm;
mp.px_ = pointerIterm.GetDisplayX();
mp.py_ = pointerIterm.GetDisplayY();
pointerRoute_.push_back(mp);
}
bool AccessibilityGestureRecognizer::HandleTouchMoveEvent(MMI::PointerEvent &event)
{
HILOG_DEBUG();
MMI::PointerEvent::PointerItem pointerIterm;
if (!event.GetPointerItem(event.GetPointerId(), pointerIterm)) {
HILOG_ERROR("get GetPointerItem(%{public}d) failed", event.GetPointerId());
return false;
}
int64_t eventTime = event.GetActionTime();
float offsetX = startPointer_.GetDisplayX() - pointerIterm.GetDisplayX();
float offsetY = startPointer_.GetDisplayY() - pointerIterm.GetDisplayY();
double duration = hypot(offsetX, offsetY);
if (isRecognizingGesture_) {
if (isDoubleTap_ && duration > TOUCH_SLOP) {
HILOG_DEBUG("Cancel double tap event because the finger moves beyond preset slop.");
isRecognizingGesture_ = false;
isDoubleTap_ = false;
return listener_->OnCancelled(event);
} else if (duration > threshold_) {
startPointer_ = pointerIterm;
startTime_ = eventTime;
isFirstTapUp_ = false;
isDoubleTap_ = false;
if (!isGestureStarted_) {
isGestureStarted_ = true;
listener_->OnStarted();
return false;
}
} else if (!isFirstTapUp_) {
int64_t durationTime = eventTime - startTime_;
int64_t thresholdTime = isGestureStarted_ ?
GESTURE_STARTED_TIME_THRESHOLD : GESTURE_NOT_STARTED_TIME_THRESHOLD;
if (durationTime > thresholdTime) {
isRecognizingGesture_ = false;
isGestureStarted_ = false;
pointerRoute_.clear();
return listener_->OnCancelled(event);
}
}
if ((abs(pointerIterm.GetDisplayX() - prePointer_.GetDisplayX())) >= xMinPixels_ ||
(abs(pointerIterm.GetDisplayY() - prePointer_.GetDisplayY())) >= yMinPixels_) {
AddSwipePosition(pointerIterm);
}
}
if (!isRecognizingGesture_) {
return false;
}
return StandardGestureRecognizer(event);
}
bool AccessibilityGestureRecognizer::HandleTouchUpEvent(MMI::PointerEvent &event)
{
HILOG_DEBUG();
Pointer mp;
MMI::PointerEvent::PointerItem pointerIterm;
if (!event.GetPointerItem(event.GetPointerId(), pointerIterm)) {
HILOG_WARN("get GetPointerItem(%{public}d) failed", event.GetPointerId());
}
if (isDoubleTap_) {
if (isLongpress_) {
HILOG_DEBUG("up event, isDoubleTap and longpress.");
return false;
} else {
HILOG_DEBUG();
return DoubleTapRecognized(event);
}
}
if (isGestureStarted_) {
if ((abs(pointerIterm.GetDisplayX() - prePointer_.GetDisplayX())) >= xMinPixels_ ||
(abs(pointerIterm.GetDisplayY() - prePointer_.GetDisplayY())) >= yMinPixels_) {
HILOG_DEBUG("Add position to pointer route.");
mp.px_ = pointerIterm.GetDisplayX();
mp.py_ = pointerIterm.GetDisplayY();
pointerRoute_.push_back(mp);
}
return recognizeDirectionGesture(event);
}
if (!isRecognizingGesture_) {
return false;
}
return StandardGestureRecognizer(event);
}
bool AccessibilityGestureRecognizer::StandardGestureRecognizer(MMI::PointerEvent &event)
{
HILOG_DEBUG();
switch (event.GetPointerAction()) {
case MMI::PointerEvent::POINTER_ACTION_DOWN:
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
if (pCurDown_ && pPreUp_ && isDoubleTap(event)) {
HILOG_DEBUG("Double tap is recognized");
isDoubleTapdetecting_ = true;
isDoubleTap_ = true;
} else {
handler_->SendEvent(SINGLE_TAP_MSG, 0, DOUBLE_TAP_TIMEOUT / US_TO_MS);
}
pCurDown_ = std::make_shared<MMI::PointerEvent>(event);
isTapDown_ = true;
continueDown_ = true;
isLongpress_ = false;
handler_->RemoveEvent(LONG_PRESS_MSG);
handler_->SendEvent(LONG_PRESS_MSG, 0, LONG_PRESS_TIMEOUT / US_TO_MS);
} else {
StandardGestureCanceled();
}
break;
case MMI::PointerEvent::POINTER_ACTION_UP:
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
continueDown_ = false;
if (isLongpress_) {
handler_->RemoveEvent(SINGLE_TAP_MSG);
isLongpress_ = false;
} else if (!isDoubleTapdetecting_ && isTapDown_) {
isFirstTapUp_ = true;
}
pPreUp_ = std::make_unique<MMI::PointerEvent>(event);
isDoubleTapdetecting_ = false;
handler_->RemoveEvent(LONG_PRESS_MSG);
}
break;
default:
break;
}
return false;
}
void AccessibilityGestureRecognizer::StandardGestureCanceled()
{
HILOG_DEBUG();
handler_->RemoveEvent(LONG_PRESS_MSG);
handler_->RemoveEvent(SINGLE_TAP_MSG);
isLongpress_ = false;
isDoubleTapdetecting_ = false;
isTapDown_ = false;
isDoubleTap_ = false;
}
void AccessibilityGestureRecognizer::SingleTapDetected()
{
HILOG_DEBUG();
Clear();
}
void AccessibilityGestureRecognizer::MaybeRecognizeLongPress(MMI::PointerEvent &event)
{
HILOG_DEBUG();
}
bool AccessibilityGestureRecognizer::DoubleTapRecognized(MMI::PointerEvent &event)
{
HILOG_DEBUG();
Clear();
return listener_->OnDoubleTap(event);
}
bool AccessibilityGestureRecognizer::recognizeDirectionGesture(MMI::PointerEvent &event)
{
HILOG_DEBUG();
if (!listener_) {
HILOG_ERROR("listener_ is nullptr.");
return false;
}
if (pointerRoute_.size() < LIMIT_SIZE_TWO) {
return listener_->OnCancelled(event);
}
// Check the angle of the most recent motion vector versus the preceding motion vector,
// segment the line if the angle is about 90 degrees.
std::vector<Pointer> pointerPath = GetPointerPath(pointerRoute_);
if (pointerPath.size() == LIMIT_SIZE_TWO) {
int32_t swipeDirection = GetSwipeDirection(pointerPath[0], pointerPath[1]);
return listener_->OnCompleted(GESTURE_DIRECTION[swipeDirection]);
} else if (pointerPath.size() == LIMIT_SIZE_THREE) {
int32_t swipeDirectionH = GetSwipeDirection(pointerPath[0], pointerPath[1]);
int32_t swipeDirectionHV = GetSwipeDirection(pointerPath[1], pointerPath[2]);
return listener_->OnCompleted(GESTURE_DIRECTION_TO_ID[swipeDirectionH][swipeDirectionHV]);
}
return listener_->OnCancelled(event);
}
int32_t AccessibilityGestureRecognizer::GetSwipeDirection(Pointer firstP, Pointer secondP)
{
float offsetX = secondP.px_ - firstP.px_;
float offsetY = secondP.py_ - firstP.py_;
if (abs(offsetX) > abs(offsetY)) {
return offsetX > EPSINON ? SWIPE_RIGHT : SWIPE_LEFT;
} else {
return offsetY < EPSINON ? SWIPE_UP : SWIPE_DOWN;
}
}
std::vector<Pointer> AccessibilityGestureRecognizer::GetPointerPath(std::vector<Pointer> &route)
{
HILOG_DEBUG();
std::vector<Pointer> pointerPath;
Pointer firstSeparation = route[0];
Pointer nextPoint;
Pointer newSeparation;
float xUnitVector = 0;
float yUnitVector = 0;
float xVector = 0;
float yVector = 0;
float vectorLength = 0;
int32_t numSinceFirstSep = 0;
pointerPath.push_back(firstSeparation);
for (size_t i = 1; i < route.size(); i++) {
nextPoint = route[i];
if (numSinceFirstSep > 0) {
xVector = xUnitVector / numSinceFirstSep;
yVector = yUnitVector / numSinceFirstSep;
newSeparation.px_ = vectorLength * xVector + firstSeparation.px_;
newSeparation.py_ = vectorLength * yVector + firstSeparation.py_;
float xNextUnitVector = nextPoint.px_ - newSeparation.px_;
float yNextUnitVector = nextPoint.py_ - newSeparation.py_;
float nextVectorLength = hypot(xNextUnitVector, yNextUnitVector);
if (nextVectorLength > EPSINON) {
xNextUnitVector /= nextVectorLength;
yNextUnitVector /= nextVectorLength;
}
if ((xVector * xNextUnitVector + yVector * yNextUnitVector) < DEGREES_THRESHOLD) {
pointerPath.push_back(newSeparation);
firstSeparation = newSeparation;
xUnitVector = 0;
yUnitVector = 0;
numSinceFirstSep = 0;
}
}
xVector = nextPoint.px_ - firstSeparation.px_;
yVector = nextPoint.py_ - firstSeparation.py_;
vectorLength = hypot(xVector, yVector);
numSinceFirstSep += 1;
if (vectorLength > EPSINON) {
xUnitVector += xVector / vectorLength;
yUnitVector += yVector / vectorLength;
}
}
pointerPath.push_back(nextPoint);
return pointerPath;
}
bool AccessibilityGestureRecognizer::isDoubleTap(MMI::PointerEvent &event)
{
HILOG_DEBUG();
int64_t durationTime = event.GetActionTime() - pPreUp_->GetActionTime();
if (!(durationTime <= DOUBLE_TAP_TIMEOUT)) {
HILOG_WARN("durationTime[%{public}" PRId64 "] is wrong", durationTime);
return false;
}
MMI::PointerEvent::PointerItem curPI;
if (!event.GetPointerItem(event.GetPointerId(), curPI)) {
HILOG_WARN("get GetPointerItem(%{public}d) failed", event.GetPointerId());
}
MMI::PointerEvent::PointerItem firstPI;
pCurDown_->GetPointerItem(pCurDown_->GetPointerId(), firstPI);
int32_t durationX = firstPI.GetDisplayX() - curPI.GetDisplayX();
int32_t durationY = firstPI.GetDisplayY() - curPI.GetDisplayY();
return (durationX * durationX + durationY * durationY < doubleTapScaledSlop_);
}
} // namespace Accessibility
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Copyright (C) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -18,7 +18,7 @@
#include "accessibility_mouse_autoclick.h"
#include "accessibility_short_key.h"
#include "accessibility_screen_touch.h"
#include "accessibility_touch_guider.h"
#include "accessibility_touch_exploration.h"
#include "accessibility_touchEvent_injector.h"
#include "accessibility_zoom_gesture.h"
#include "accessible_ability_manager_service.h"
@ -79,8 +79,14 @@ bool AccessibilityInputInterceptor::OnKeyEvent(MMI::KeyEvent &event)
bool AccessibilityInputInterceptor::OnPointerEvent(MMI::PointerEvent &event)
{
HILOG_DEBUG("PointerAction:%{public}d, SourceType:%{public}d, PointerId:%{public}d",
event.GetPointerAction(), event.GetSourceType(), event.GetPointerId());
if (event.GetPointerAction() != MMI::PointerEvent::POINTER_ACTION_MOVE &&
event.GetPointerAction() != MMI::PointerEvent::POINTER_ACTION_HOVER_MOVE) {
HILOG_INFO("PointerAction:%{public}d, SourceType:%{public}d, PointerId:%{public}d",
event.GetPointerAction(), event.GetSourceType(), event.GetPointerId());
} else {
HILOG_DEBUG("PointerAction:%{public}d, SourceType:%{public}d, PointerId:%{public}d",
event.GetPointerAction(), event.GetSourceType(), event.GetPointerId());
}
event.AddFlag(MMI::InputEvent::EVENT_FLAG_NO_INTERCEPT);
std::shared_ptr<MMI::PointerEvent> pointerEvent = std::make_shared<MMI::PointerEvent>(event);
@ -180,13 +186,13 @@ void AccessibilityInputInterceptor::CreatePointerEventTransmitters()
}
if (availableFunctions_& FEATURE_TOUCH_EXPLORATION) {
sptr<TouchGuider> touchGuider = new(std::nothrow) TouchGuider();
if (!touchGuider) {
HILOG_ERROR("touchGuider is null");
sptr<TouchExploration> touchExploration = new(std::nothrow) TouchExploration();
if (!touchExploration) {
HILOG_ERROR("touchExploration is null");
return;
}
touchGuider->StartUp();
SetNextEventTransmitter(header, current, touchGuider);
touchExploration->StartUp();
SetNextEventTransmitter(header, current, touchExploration);
}
if ((availableFunctions_ & FEATURE_SCREEN_TOUCH) && ((availableFunctions_ & FEATURE_TOUCH_EXPLORATION) == 0)) {
@ -385,8 +391,14 @@ void AccessibilityInputEventConsumer::OnInputEvent(std::shared_ptr<MMI::PointerE
HILOG_WARN("pointerEvent is null.");
return;
}
HILOG_DEBUG("PointerAction:%{public}d, SourceType:%{public}d, PointerId:%{public}d.",
pointerEvent->GetPointerAction(), pointerEvent->GetSourceType(), pointerEvent->GetPointerId());
if (pointerEvent->GetPointerAction() != MMI::PointerEvent::POINTER_ACTION_MOVE) {
HILOG_INFO("PointerAction:%{public}d, SourceType:%{public}d, PointerId:%{public}d.",
pointerEvent->GetPointerAction(), pointerEvent->GetSourceType(), pointerEvent->GetPointerId());
} else {
HILOG_DEBUG("PointerAction:%{public}d, SourceType:%{public}d, PointerId:%{public}d.",
pointerEvent->GetPointerAction(), pointerEvent->GetSourceType(), pointerEvent->GetPointerId());
}
auto interceptor = AccessibilityInputInterceptor::GetInstance();
if (!interceptor) {

View File

@ -1,881 +0,0 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed On an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cfloat>
#include "accessibility_multifinger_multitap.h"
#include "hilog_wrapper.h"
#include <cinttypes>
namespace OHOS {
namespace Accessibility {
namespace {
constexpr float SLOP_DELTA = 0.5f;
constexpr int32_t POINTER_COUNT_1 = 1;
constexpr int32_t POINTER_COUNT_2 = 2;
constexpr int32_t POINTER_COUNT_3 = 3;
constexpr int32_t POINTER_COUNT_4 = 4;
constexpr int32_t MULTI_FINGER_MAX_CONTINUE_TAP_NUM = 3;
constexpr float TOUCH_SLOP = 8.0f;
constexpr uint32_t MIN_MOVE_POINTER_NUM = 2;
} // namespace
MultiFingerGestureHandler::MultiFingerGestureHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
AccessibilityMultiTapGestureRecognizer &server) : AppExecFwk::EventHandler(runner), server_(server)
{
}
bool MultiFingerGestureHandler::IsTapGesture(const GestureType gestureType)
{
if (gestureType == GestureType::GESTURE_TWO_FINGER_DOUBLE_TAP_AND_HOLD ||
gestureType == GestureType::GESTURE_THREE_FINGER_DOUBLE_TAP_AND_HOLD ||
gestureType == GestureType::GESTURE_FOUR_FINGER_DOUBLE_TAP_AND_HOLD ||
gestureType == GestureType::GESTURE_TWO_FINGER_TRIPLE_TAP_AND_HOLD ||
gestureType == GestureType::GESTURE_THREE_FINGER_TRIPLE_TAP_AND_HOLD ||
gestureType == GestureType::GESTURE_FOUR_FINGER_TRIPLE_TAP_AND_HOLD ||
gestureType == GestureType::GESTURE_INVALID) {
return false;
}
return true;
}
void MultiFingerGestureHandler::ProcessMultiFingerGestureTypeEvent(const GestureType gestureType)
{
HILOG_DEBUG("gesture id: %{public}d", static_cast<int32_t>(gestureType));
if (IsTapGesture(gestureType)) {
if (server_.GetFingerTouchUpState() == FingerTouchUpState::ALL_FINGER_TOUCH_UP) {
server_.GetRecognizeListener()->MultiFingerGestureOnCompleted(gestureType);
server_.SetMultiFingerGestureState(MultiFingerGestureState::GESTURE_COMPLETE);
server_.Clear();
}
} else {
if (server_.GetFingerTouchUpState() != FingerTouchUpState::NOT_ALL_FINGER_TOUCH_UP) {
if (gestureType != GestureType::GESTURE_INVALID) {
server_.GetRecognizeListener()->MultiFingerGestureOnCompleted(gestureType);
}
server_.SetMultiFingerGestureState(MultiFingerGestureState::GESTURE_COMPLETE);
}
server_.Clear();
}
}
bool MultiFingerGestureHandler::ProcessMultiFingerGestureEvent(const AppExecFwk::InnerEvent::Pointer &event)
{
HILOG_DEBUG("Inner Event Id id: %{public}u", static_cast<uint32_t>(event->GetInnerEventId()));
static std::map<uint32_t, GestureType> MULTI_GESTURE_TYPE = {
{AccessibilityMultiTapGestureRecognizer::TWO_FINGER_SINGLE_TAP_MSG,
GestureType::GESTURE_TWO_FINGER_SINGLE_TAP},
{AccessibilityMultiTapGestureRecognizer::TWO_FINGER_LONG_PRESS_MSG, GestureType::GESTURE_INVALID},
{AccessibilityMultiTapGestureRecognizer::TWO_FINGER_DOUBLE_TAP_MSG,
GestureType::GESTURE_TWO_FINGER_DOUBLE_TAP},
{AccessibilityMultiTapGestureRecognizer::TWO_FINGER_DOUBLE_TAP_AND_HOLD_MSG,
GestureType::GESTURE_TWO_FINGER_DOUBLE_TAP_AND_HOLD},
{AccessibilityMultiTapGestureRecognizer::TWO_FINGER_TRIPLE_TAP_MSG,
GestureType::GESTURE_TWO_FINGER_TRIPLE_TAP},
{AccessibilityMultiTapGestureRecognizer::TWO_FINGER_TRIPLE_TAP_AND_HOLD_MSG,
GestureType::GESTURE_TWO_FINGER_TRIPLE_TAP_AND_HOLD},
{AccessibilityMultiTapGestureRecognizer::THREE_FINGER_SINGLE_TAP_MSG,
GestureType::GESTURE_THREE_FINGER_SINGLE_TAP},
{AccessibilityMultiTapGestureRecognizer::THREE_FINGER_LONG_PRESS_MSG, GestureType::GESTURE_INVALID},
{AccessibilityMultiTapGestureRecognizer::THREE_FINGER_DOUBLE_TAP_MSG,
GestureType::GESTURE_THREE_FINGER_DOUBLE_TAP},
{AccessibilityMultiTapGestureRecognizer::THREE_FINGER_DOUBLE_TAP_AND_HOLD_MSG,
GestureType::GESTURE_THREE_FINGER_DOUBLE_TAP_AND_HOLD},
{AccessibilityMultiTapGestureRecognizer::THREE_FINGER_TRIPLE_TAP_MSG,
GestureType::GESTURE_THREE_FINGER_TRIPLE_TAP},
{AccessibilityMultiTapGestureRecognizer::THREE_FINGER_TRIPLE_TAP_AND_HOLD_MSG,
GestureType::GESTURE_THREE_FINGER_TRIPLE_TAP_AND_HOLD},
{AccessibilityMultiTapGestureRecognizer::FOUR_FINGER_SINGLE_TAP_MSG,
GestureType::GESTURE_FOUR_FINGER_SINGLE_TAP},
{AccessibilityMultiTapGestureRecognizer::FOUR_FINGER_LONG_PRESS_MSG, GestureType::GESTURE_INVALID},
{AccessibilityMultiTapGestureRecognizer::FOUR_FINGER_DOUBLE_TAP_MSG,
GestureType::GESTURE_FOUR_FINGER_DOUBLE_TAP},
{AccessibilityMultiTapGestureRecognizer::FOUR_FINGER_DOUBLE_TAP_AND_HOLD_MSG,
GestureType::GESTURE_FOUR_FINGER_DOUBLE_TAP_AND_HOLD},
{AccessibilityMultiTapGestureRecognizer::FOUR_FINGER_TRIPLE_TAP_MSG,
GestureType::GESTURE_FOUR_FINGER_TRIPLE_TAP},
{AccessibilityMultiTapGestureRecognizer::FOUR_FINGER_TRIPLE_TAP_AND_HOLD_MSG,
GestureType::GESTURE_FOUR_FINGER_TRIPLE_TAP_AND_HOLD}
};
uint32_t eventId = static_cast<uint32_t>(event->GetInnerEventId());
if (MULTI_GESTURE_TYPE.find(eventId) == MULTI_GESTURE_TYPE.end()) {
return false;
}
GestureType gestureType = MULTI_GESTURE_TYPE.at(eventId);
ProcessMultiFingerGestureTypeEvent(gestureType);
return true;
}
void MultiFingerGestureHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
{
HILOG_DEBUG();
if (!event) {
HILOG_ERROR("event is null");
return;
}
if (ProcessMultiFingerGestureEvent(event)) {
return;
}
switch (event->GetInnerEventId()) {
case AccessibilityMultiTapGestureRecognizer::WAIT_ANOTHER_FINGER_DOWN_MSG:
server_.SetFingerTouchUpState(FingerTouchUpState::NOT_ALL_FINGER_TOUCH_UP);
break;
case AccessibilityMultiTapGestureRecognizer::CANCEL_WAIT_FINGER_DOWN_MSG:
server_.SetMultiFingerGestureState(MultiFingerGestureState::GESTURE_NOT_START);
break;
case AccessibilityMultiTapGestureRecognizer::CANCEL_GESTURE:
if (server_.GetFingerTouchUpState() != FingerTouchUpState::ALL_FINGER_TOUCH_UP) {
server_.SetFingerTouchUpState(FingerTouchUpState::NOT_ALL_FINGER_TOUCH_UP);
}
server_.GetRecognizeListener()->MultiFingerGestureOnCancelled(true);
server_.SetMultiFingerGestureState(MultiFingerGestureState::GESTURE_CANCLE);
server_.Clear();
break;
default:
break;
}
}
AccessibilityMultiTapGestureRecognizer::AccessibilityMultiTapGestureRecognizer()
{
HILOG_DEBUG();
#ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER
AccessibilityDisplayManager &displayMgr = Singleton<AccessibilityDisplayManager>::GetInstance();
auto display = displayMgr.GetDefaultDisplay();
if (!display) {
HILOG_ERROR("get display is nullptr");
return;
}
float density = display->GetVirtualPixelRatio();
int32_t slop = static_cast<int32_t>(density * DOUBLE_TAP_SLOP + SLOP_DELTA);
doubleTapOffsetThresh_ = slop;
touchSlop_ = TOUCH_SLOP;
mMinPixelsBetweenSamplesX_ = MIN_PIXELS(display->GetWidth());
mMinPixelsBetweenSamplesY_ = MIN_PIXELS(display->GetHeight());
#else
HILOG_DEBUG("not support display manager");
doubleTapOffsetThresh_ = static_cast<int32_t>(1 * DOUBLE_TAP_SLOP + SLOP_DELTA);
touchSlop_ = TOUCH_SLOP;
mMinPixelsBetweenSamplesX_ = 1;
mMinPixelsBetweenSamplesY_ = 1;
#endif
runner_ = Singleton<AccessibleAbilityManagerService>::GetInstance().GetMainRunner();
if (!runner_) {
HILOG_ERROR("get runner failed");
return;
}
handler_ = std::make_shared<MultiFingerGestureHandler>(runner_, *this);
if (!handler_) {
HILOG_ERROR("create event handler failed");
return;
}
}
void AccessibilityMultiTapGestureRecognizer::RegisterListener(AccessibilityGestureRecognizeListener& listener)
{
HILOG_DEBUG();
listener_ = &listener;
}
void AccessibilityMultiTapGestureRecognizer::CancelTwoFingerEvent()
{
HILOG_DEBUG();
if (!handler_) {
HILOG_ERROR("handler_ is null ptr");
return;
}
handler_->RemoveEvent(TWO_FINGER_SINGLE_TAP_MSG);
handler_->RemoveEvent(TWO_FINGER_LONG_PRESS_MSG);
handler_->RemoveEvent(TWO_FINGER_DOUBLE_TAP_MSG);
handler_->RemoveEvent(TWO_FINGER_DOUBLE_TAP_AND_HOLD_MSG);
handler_->RemoveEvent(TWO_FINGER_TRIPLE_TAP_MSG);
handler_->RemoveEvent(TWO_FINGER_TRIPLE_TAP_AND_HOLD_MSG);
}
void AccessibilityMultiTapGestureRecognizer::CancelThreeFingerEvent()
{
HILOG_DEBUG();
if (!handler_) {
HILOG_ERROR("handler_ is null ptr");
return;
}
handler_->RemoveEvent(THREE_FINGER_SINGLE_TAP_MSG);
handler_->RemoveEvent(THREE_FINGER_LONG_PRESS_MSG);
handler_->RemoveEvent(THREE_FINGER_DOUBLE_TAP_MSG);
handler_->RemoveEvent(THREE_FINGER_DOUBLE_TAP_AND_HOLD_MSG);
handler_->RemoveEvent(THREE_FINGER_TRIPLE_TAP_MSG);
handler_->RemoveEvent(THREE_FINGER_TRIPLE_TAP_AND_HOLD_MSG);
}
void AccessibilityMultiTapGestureRecognizer::CancelFourFingerEvent()
{
HILOG_DEBUG();
if (!handler_) {
HILOG_ERROR("handler_ is null ptr");
return;
}
handler_->RemoveEvent(FOUR_FINGER_SINGLE_TAP_MSG);
handler_->RemoveEvent(FOUR_FINGER_LONG_PRESS_MSG);
handler_->RemoveEvent(FOUR_FINGER_DOUBLE_TAP_MSG);
handler_->RemoveEvent(FOUR_FINGER_DOUBLE_TAP_AND_HOLD_MSG);
handler_->RemoveEvent(FOUR_FINGER_TRIPLE_TAP_MSG);
handler_->RemoveEvent(FOUR_FINGER_TRIPLE_TAP_AND_HOLD_MSG);
}
void AccessibilityMultiTapGestureRecognizer::CancelTapAndHoldGestureEvent(const int32_t fingerNum)
{
HILOG_DEBUG();
switch (fingerNum) {
case POINTER_COUNT_2:
CancelTwoFingerEvent();
break;
case POINTER_COUNT_3:
CancelThreeFingerEvent();
break;
case POINTER_COUNT_4:
CancelFourFingerEvent();
break;
default:
break;
}
}
void AccessibilityMultiTapGestureRecognizer::CancelHoldGestureEvent()
{
HILOG_DEBUG();
if (!handler_) {
HILOG_ERROR("handler_ is null ptr");
return;
}
handler_->RemoveEvent(TWO_FINGER_LONG_PRESS_MSG);
handler_->RemoveEvent(TWO_FINGER_DOUBLE_TAP_AND_HOLD_MSG);
handler_->RemoveEvent(TWO_FINGER_TRIPLE_TAP_AND_HOLD_MSG);
handler_->RemoveEvent(THREE_FINGER_LONG_PRESS_MSG);
handler_->RemoveEvent(THREE_FINGER_DOUBLE_TAP_AND_HOLD_MSG);
handler_->RemoveEvent(THREE_FINGER_TRIPLE_TAP_AND_HOLD_MSG);
handler_->RemoveEvent(FOUR_FINGER_LONG_PRESS_MSG);
handler_->RemoveEvent(FOUR_FINGER_DOUBLE_TAP_AND_HOLD_MSG);
handler_->RemoveEvent(FOUR_FINGER_TRIPLE_TAP_AND_HOLD_MSG);
}
void AccessibilityMultiTapGestureRecognizer::CancelAllPenddingEvent()
{
HILOG_DEBUG();
if (!handler_) {
HILOG_ERROR("handler_ is null ptr");
return;
}
handler_->RemoveEvent(CANCEL_GESTURE);
handler_->RemoveEvent(CANCEL_WAIT_FINGER_DOWN_MSG);
CancelTwoFingerEvent();
CancelThreeFingerEvent();
CancelFourFingerEvent();
}
void AccessibilityMultiTapGestureRecognizer::Clear()
{
HILOG_DEBUG();
targetFingers_ = -1;
addContinueTapNum_ = 0;
isMoveGestureRecognizing = 0;
moveDirection = -1;
firstDownPoint_.clear();
lastUpPoint_.clear();
currentDownPoint_.clear();
preGesturePoint_.clear();
pointerRoute_.clear();
CancelAllPenddingEvent();
}
void AccessibilityMultiTapGestureRecognizer::CancelGesture(bool isNoDelayFlag)
{
HILOG_DEBUG();
SetMultiFingerGestureState(MultiFingerGestureState::GESTURE_CANCLE);
if (fingerTouchUpState_ != FingerTouchUpState::ALL_FINGER_TOUCH_UP) {
fingerTouchUpState_ = FingerTouchUpState::NOT_ALL_FINGER_TOUCH_UP;
}
if (!listener_) {
HILOG_ERROR("listener_ is null ptr");
return;
}
listener_->MultiFingerGestureOnCancelled(isNoDelayFlag);
Clear();
}
bool AccessibilityMultiTapGestureRecognizer::ParamCheck(const int32_t fingerNum)
{
if (static_cast<int32_t>(lastUpPoint_.size()) < fingerNum ||
static_cast<int32_t>(firstDownPoint_.size()) < fingerNum) {
HILOG_ERROR("last_up point or first_down point size is less than target fingerNum");
return false;
}
for (int pId = 0; pId < fingerNum; pId++) {
if (!lastUpPoint_.count(pId) || !lastUpPoint_[pId]) {
HILOG_ERROR("last_up point or first_down point container has wrong value and pId is: %{public}d", pId);
return false;
}
}
return true;
}
int64_t AccessibilityMultiTapGestureRecognizer::GetLastFirstPointUpTime(const int32_t fingerNum)
{
HILOG_DEBUG();
int64_t timeRst = lastUpPoint_[0]->GetActionTime();
for (int32_t pId = 1; pId < fingerNum; pId++) {
if (lastUpPoint_[pId]->GetActionTime() < timeRst) {
timeRst = lastUpPoint_[pId]->GetActionTime();
}
}
return timeRst;
}
bool AccessibilityMultiTapGestureRecognizer::IsDoubelTapSlopConditionMatch(const int32_t fingerNum,
const std::vector<MMI::PointerEvent::PointerItem> &curPoints,
const std::vector<MMI::PointerEvent::PointerItem> &prePoints)
{
HILOG_DEBUG("doubleTapOffsetThresh_, %{public}d", doubleTapOffsetThresh_);
std::vector<int32_t> excludePid(fingerNum, -1);
for (auto curPoint : curPoints) {
float moveDelta = FLT_MAX;
int32_t nearestPid = -1;
int32_t curX = curPoint.GetDisplayX();
int32_t curY = curPoint.GetDisplayY();
for (auto prePoint : prePoints) {
int32_t pId = prePoint.GetPointerId();
if (std::find(excludePid.begin(), excludePid.end(), pId) != excludePid.end()) {
continue;
}
int32_t preX = prePoint.GetDisplayX();
int32_t preY = prePoint.GetDisplayY();
int32_t offsetX = curX - preX;
int32_t offsetY = curY - preY;
if (offsetX == 0 && offsetY == 0) {
nearestPid = pId;
moveDelta = 0;
break;
}
float delta = hypot(offsetX, offsetY);
if (delta < moveDelta) {
moveDelta = delta;
nearestPid = pId;
}
}
HILOG_DEBUG("moveDelta = %{public}f, right = %{public}d", moveDelta, doubleTapOffsetThresh_ * fingerNum);
if (moveDelta < doubleTapOffsetThresh_ * fingerNum) {
excludePid.push_back(nearestPid);
} else {
return false;
}
}
return true;
}
bool AccessibilityMultiTapGestureRecognizer::GetPointerItemWithFingerNum(int32_t fingerNum,
std::vector<MMI::PointerEvent::PointerItem> &curPoints,
std::vector<MMI::PointerEvent::PointerItem> &prePoints, MMI::PointerEvent &event,
std::map<int32_t, std::shared_ptr<MMI::PointerEvent>> &prePointsEventInfo)
{
HILOG_DEBUG();
std::vector<int32_t> pIds = event.GetPointerIds();
for (int32_t pId = 0; pId < fingerNum; pId++) {
if (!event.GetPointerItem(pIds[pId], curPoints[pId])) {
HILOG_ERROR("curPoint GetPointerItem(%{public}d) failed", pIds[pId]);
return false;
}
if (!prePointsEventInfo[pId]->GetPointerItem(prePointsEventInfo[pId]->GetPointerId(), prePoints[pId])) {
HILOG_ERROR("prePoint GetPointerItem(%{public}d) failed", prePointsEventInfo[pId]->GetPointerId());
return false;
}
}
return true;
}
bool AccessibilityMultiTapGestureRecognizer::IsMultiFingerDoubleTap(MMI::PointerEvent &event,
const int32_t fingerNum)
{
HILOG_DEBUG("fingerNum is %{public}d", fingerNum);
if (!ParamCheck(fingerNum)) {
return false;
}
// first pointer up time to second pointer down time
int64_t firstUpTime = GetLastFirstPointUpTime(fingerNum);
int64_t durationTime = event.GetActionTime() - firstUpTime;
if (durationTime > DOUBLE_TAP_TIMEOUT || durationTime < MIN_DOUBLE_TAP_TIME) {
HILOG_WARN("durationTime[%{public}" PRId64 "] is wrong", durationTime);
return false;
}
std::vector<int32_t> pIds = event.GetPointerIds();
if (static_cast<int32_t>(pIds.size()) != fingerNum) {
return false;
}
std::vector<MMI::PointerEvent::PointerItem> curPoints(fingerNum);
std::vector<MMI::PointerEvent::PointerItem> prePoints(fingerNum);
if (!GetPointerItemWithFingerNum(fingerNum, curPoints, prePoints, event, firstDownPoint_)) {
return false;
}
return IsDoubelTapSlopConditionMatch(fingerNum, curPoints, prePoints);
}
void AccessibilityMultiTapGestureRecognizer::HanleFirstTouchDownEvent(MMI::PointerEvent &event)
{
HILOG_DEBUG("gestureState is %{public}d, touchUpState is %{public}d", multiFingerGestureState_,
fingerTouchUpState_);
if (multiFingerGestureState_ == MultiFingerGestureState::GESTURE_WAIT) {
if (event.GetPointerId() == 0) {
fingerTouchUpState_ = FingerTouchUpState::NOT_ALL_FINGER_TOUCH_UP;
Clear();
return;
} else if (!handler_->HasInnerEvent(WAIT_ANOTHER_FINGER_DOWN_MSG)) {
HILOG_DEBUG("do not have WAIT_ANOTHER_FINGER_DOWN_MSG");
SetMultiFingerGestureState(MultiFingerGestureState::GESTURE_NOT_START);
}
}
// NOT_ALL_FINGER_TOUCH_UP state can not revice touch down event
if (fingerTouchUpState_ == FingerTouchUpState::NOT_ALL_FINGER_TOUCH_UP) {
Clear();
return;
}
// start touch down, change fingerTouchUpState_ to TOUCH_DOWN_AFTER_ALL_FINGER_TOUCH_UP state
fingerTouchUpState_ = FingerTouchUpState::TOUCH_DOWN_AFTER_ALL_FINGER_TOUCH_UP;
firstDownPoint_[event.GetPointerId()] = std::make_shared<MMI::PointerEvent>(event);
handler_->SendEvent(WAIT_ANOTHER_FINGER_DOWN_MSG, 0, TAP_INTERVAL_TIMEOUT / US_TO_MS);
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
SetMultiFingerGestureState(MultiFingerGestureState::GESTURE_WAIT);
} else if (event.GetPointerIds().size() == POINTER_COUNT_2) {
listener_->MultiFingerGestureOnStarted(true);
SetMultiFingerGestureState(MultiFingerGestureState::GESTURE_START);
handler_->SendEvent(TWO_FINGER_SINGLE_TAP_MSG, 0, DOUBLE_TAP_TIMEOUT / US_TO_MS);
handler_->SendEvent(TWO_FINGER_LONG_PRESS_MSG, 0, LONG_PRESS_TIMEOUT / US_TO_MS);
} else if (event.GetPointerIds().size() == POINTER_COUNT_3) {
listener_->MultiFingerGestureOnStarted(false);
handler_->SendEvent(THREE_FINGER_SINGLE_TAP_MSG, 0, DOUBLE_TAP_TIMEOUT / US_TO_MS);
handler_->SendEvent(THREE_FINGER_LONG_PRESS_MSG, 0, LONG_PRESS_TIMEOUT / US_TO_MS);
} else if (event.GetPointerIds().size() == POINTER_COUNT_4) {
handler_->SendEvent(FOUR_FINGER_SINGLE_TAP_MSG, 0, DOUBLE_TAP_TIMEOUT / US_TO_MS);
handler_->SendEvent(FOUR_FINGER_LONG_PRESS_MSG, 0, LONG_PRESS_TIMEOUT / US_TO_MS);
} else {
CancelGesture(true);
}
}
void AccessibilityMultiTapGestureRecognizer::HandleMultiTapEvent(MMI::PointerEvent &event, const int32_t fingerNum)
{
HILOG_DEBUG("fingerNum is %{public}d", fingerNum);
// check is double tap
if (static_cast<int32_t>(firstDownPoint_.size()) == fingerNum &&
static_cast<int32_t>(lastUpPoint_.size()) == fingerNum &&
IsMultiFingerDoubleTap(event, fingerNum)) {
addContinueTapNum_ = addContinueTapNum_ + 1;
HILOG_DEBUG("two finger Double tap is recognized, addContinueTapNum %{public}d", addContinueTapNum_);
} else {
addContinueTapNum_ = 0;
}
if (fingerNum < POINTER_COUNT_2 || fingerNum > POINTER_COUNT_4) {
HILOG_ERROR("fingerNum: %{public}d is wrong", fingerNum);
return;
}
if (addContinueTapNum_ >= MULTI_FINGER_MAX_CONTINUE_TAP_NUM) {
HILOG_ERROR("continue tap times: %{public}u is wrong", addContinueTapNum_);
CancelGesture(true);
return;
}
uint32_t fingerNumIndex = static_cast<uint32_t>(fingerNum - 2);
handler_->SendEvent(GESTURE_TAP_MSG[addContinueTapNum_][fingerNumIndex], 0, DOUBLE_TAP_TIMEOUT / US_TO_MS);
handler_->SendEvent(GESTURE_HOLD_MSG[addContinueTapNum_][fingerNumIndex], 0, LONG_PRESS_TIMEOUT / US_TO_MS);
}
void AccessibilityMultiTapGestureRecognizer::HandleContinueTouchDownEvent(MMI::PointerEvent &event)
{
HILOG_DEBUG("fingerNum is %{public}d, gestureState is %{public}d, touchUpstate is %{public}d",
targetFingers_, multiFingerGestureState_, fingerTouchUpState_);
if (targetFingers_ == POINTER_COUNT_1) {
return;
}
if (multiFingerGestureState_ != MultiFingerGestureState::GESTURE_START) {
CancelGesture(true);
return;
}
if (fingerTouchUpState_ == FingerTouchUpState::NOT_ALL_FINGER_TOUCH_UP) {
CancelGesture(true);
return;
}
fingerTouchUpState_ = FingerTouchUpState::TOUCH_DOWN_AFTER_ALL_FINGER_TOUCH_UP;
int32_t pointerSize = static_cast<int32_t>(event.GetPointerIds().size());
if (pointerSize < targetFingers_) {
handler_->SendEvent(CANCEL_GESTURE, 0, TAP_INTERVAL_TIMEOUT / US_TO_MS);
} else if (pointerSize == targetFingers_) {
HandleMultiTapEvent(event, targetFingers_);
} else {
HILOG_DEBUG("current fingers is more than last touch down finger nums");
CancelGesture(true);
}
}
void AccessibilityMultiTapGestureRecognizer::storeBaseDownPoint()
{
HILOG_DEBUG();
for (auto iter : currentDownPoint_) {
Pointer mp;
MMI::PointerEvent::PointerItem pointerIterm;
std::vector<Pointer> mpVec;
int32_t pId = iter.first;
if (!iter.second->GetPointerItem(pId, pointerIterm)) {
HILOG_ERROR("get GetPointerItem(%{public}d) failed", pId);
return;
}
mp.px_ = static_cast<float>(pointerIterm.GetDisplayX());
mp.py_ = static_cast<float>(pointerIterm.GetDisplayY());
mpVec.push_back(mp);
pointerRoute_.insert(std::make_pair(pId, mpVec));
}
}
int32_t AccessibilityMultiTapGestureRecognizer::GetSwipeDirection(const int32_t dx, const int32_t dy)
{
HILOG_DEBUG();
if (abs(dx) > abs(dy)) {
return (dx < 0) ? MoveGirectionType::SWIPE_LEFT : MoveGirectionType::SWIPE_RIGHT;
} else {
return (dy < 0) ? MoveGirectionType::SWIPE_UP : MoveGirectionType::SWIPE_DOWN;
}
}
void AccessibilityMultiTapGestureRecognizer::SaveMoveGesturePointerInfo(MMI::PointerEvent &event,
const int32_t pId, const MMI::PointerEvent::PointerItem &pointerIterm, const int32_t dx, const int32_t dy)
{
HILOG_DEBUG();
int32_t currentDirection = GetSwipeDirection(dx, dy);
if (!isMoveGestureRecognizing) {
storeBaseDownPoint();
moveDirection = currentDirection;
isMoveGestureRecognizing = true;
return;
}
if (moveDirection != currentDirection) {
CancelGesture(true);
return;
}
Pointer mp;
mp.px_ = static_cast<float>(pointerIterm.GetDisplayX());
mp.py_ = static_cast<float>(pointerIterm.GetDisplayY());
pointerRoute_[pId].push_back(mp);
//update preGesturePoint_
preGesturePoint_[pId] = std::make_shared<MMI::PointerEvent>(event);
}
bool AccessibilityMultiTapGestureRecognizer::GetBasePointItem(MMI::PointerEvent::PointerItem &basePointerIterm,
int32_t pId, std::map<int32_t, std::shared_ptr<MMI::PointerEvent>> &pointInfo)
{
HILOG_DEBUG();
if (pointInfo.count(pId) == 0 || !pointInfo[pId]) {
return false;
}
if (!pointInfo[pId]->GetPointerItem(pointInfo[pId]->GetPointerId(), basePointerIterm)) {
HILOG_ERROR("base down point get GetPointerItem(%{public}d) failed", pId);
return false;
}
return true;
}
void AccessibilityMultiTapGestureRecognizer::HandleMultiFingerMoveEvent(MMI::PointerEvent &event)
{
int32_t pIdSize = static_cast<int32_t>(event.GetPointerIds().size());
int32_t downPointSize = static_cast<int32_t>(currentDownPoint_.size());
int32_t pId = event.GetPointerId();
HILOG_DEBUG("pointer num is %{public}d, down pointer size is %{public}d, pointId is %{public}d", pIdSize,
downPointSize, pId);
MMI::PointerEvent::PointerItem pointerIterm;
if (!event.GetPointerItem(pId, pointerIterm)) {
HILOG_ERROR("get GetPointerItem(%{public}d) failed", pId);
return;
}
MMI::PointerEvent::PointerItem basePointerIterm;
if (isMoveGestureRecognizing) {
if (!GetBasePointItem(basePointerIterm, pId, preGesturePoint_)) {
return;
}
} else {
if (!GetBasePointItem(basePointerIterm, pId, currentDownPoint_)) {
return;
}
}
int32_t offsetX = pointerIterm.GetDisplayX() - basePointerIterm.GetDisplayX();
int32_t offsetY = pointerIterm.GetDisplayY() - basePointerIterm.GetDisplayY();
HILOG_DEBUG("current point and first down point: pid %{public}d, %{public}d, %{public}d, %{public}d, %{public}d",
pId, pointerIterm.GetDisplayX(), pointerIterm.GetDisplayY(), basePointerIterm.GetDisplayX(),
basePointerIterm.GetDisplayY());
// two finger move will cancel gesture, but three or four finger move will enter move gesture recognize
if (!isMoveGestureRecognizing && hypot(offsetX, offsetY) > TOUCH_SLOP * downPointSize) {
if (downPointSize == POINTER_COUNT_2) {
HILOG_DEBUG("cancel gesture because finger move");
CancelGesture(false);
} else {
CancelThreeFingerEvent();
CancelFourFingerEvent();
SaveMoveGesturePointerInfo(event, pId, pointerIterm, offsetX, offsetY);
}
} else if (isMoveGestureRecognizing && (abs(offsetX) >= mMinPixelsBetweenSamplesX_ ||
abs(offsetY) >= mMinPixelsBetweenSamplesY_)) {
SaveMoveGesturePointerInfo(event, pId, pointerIterm, offsetX, offsetY);
}
}
void AccessibilityMultiTapGestureRecognizer::StoreUpPointInPointerRoute(MMI::PointerEvent &event)
{
HILOG_DEBUG();
if (!isMoveGestureRecognizing || multiFingerGestureState_ != MultiFingerGestureState::GESTURE_START) {
return;
}
MMI::PointerEvent::PointerItem pointerIterm;
int32_t pId = event.GetPointerId();
if (!event.GetPointerItem(pId, pointerIterm)) {
HILOG_ERROR("get GetPointerItem(%{public}d) failed", pId);
return;
}
MMI::PointerEvent::PointerItem basePointerIterm;
if (!GetBasePointItem(basePointerIterm, pId, preGesturePoint_)) {
return;
}
int32_t offsetX = pointerIterm.GetDisplayX() - basePointerIterm.GetDisplayX();
int32_t offsetY = pointerIterm.GetDisplayY() - basePointerIterm.GetDisplayY();
if (abs(offsetX) > mMinPixelsBetweenSamplesX_ || abs(offsetY) > mMinPixelsBetweenSamplesY_) {
SaveMoveGesturePointerInfo(event, pId, pointerIterm, offsetX, offsetY);
}
}
bool AccessibilityMultiTapGestureRecognizer::recognizeGesturePath(const std::vector<Pointer> &path)
{
HILOG_DEBUG();
if (path.size() < MIN_MOVE_POINTER_NUM) {
return false;
}
int pathSize = static_cast<int>(path.size() - 1);
for (int routerIndex = 0; routerIndex < pathSize; routerIndex++) {
int32_t dx = static_cast<int32_t>(path[routerIndex + 1].px_ - path[routerIndex].px_);
int32_t dy = static_cast<int32_t>(path[routerIndex + 1].py_ - path[routerIndex].py_);
if (GetSwipeDirection(dx, dy) != moveDirection) {
return false;
}
}
return true;
}
GestureType AccessibilityMultiTapGestureRecognizer::GetMoveGestureId()
{
HILOG_DEBUG();
int32_t downPointSize = static_cast<int32_t>(currentDownPoint_.size());
if (downPointSize == POINTER_COUNT_3) {
switch (moveDirection) {
case MoveGirectionType::SWIPE_LEFT:
return GestureType::GESTURE_THREE_FINGER_SWIPE_LEFT;
case MoveGirectionType::SWIPE_RIGHT:
return GestureType::GESTURE_THREE_FINGER_SWIPE_RIGHT;
case MoveGirectionType::SWIPE_UP:
return GestureType::GESTURE_THREE_FINGER_SWIPE_UP;
case MoveGirectionType::SWIPE_DOWN:
return GestureType::GESTURE_THREE_FINGER_SWIPE_DOWN;
default:
return GestureType::GESTURE_INVALID;
}
} else if (downPointSize == POINTER_COUNT_4) {
switch (moveDirection) {
case MoveGirectionType::SWIPE_LEFT:
return GestureType::GESTURE_FOUR_FINGER_SWIPE_LEFT;
case MoveGirectionType::SWIPE_RIGHT:
return GestureType::GESTURE_FOUR_FINGER_SWIPE_RIGHT;
case MoveGirectionType::SWIPE_UP:
return GestureType::GESTURE_FOUR_FINGER_SWIPE_UP;
case MoveGirectionType::SWIPE_DOWN:
return GestureType::GESTURE_FOUR_FINGER_SWIPE_DOWN;
default:
return GestureType::GESTURE_INVALID;
}
}
return GestureType::GESTURE_INVALID;
}
bool AccessibilityMultiTapGestureRecognizer::IsMoveGestureRecognize()
{
HILOG_DEBUG();
if (!isMoveGestureRecognizing || multiFingerGestureState_ != MultiFingerGestureState::GESTURE_START) {
return false;
}
int32_t downPointSize = static_cast<int32_t>(currentDownPoint_.size());
if (static_cast<int32_t>(pointerRoute_.size()) != downPointSize) {
return false;
}
for (int32_t pIndex = 0; pIndex < downPointSize; pIndex++) {
if (pointerRoute_.count(pIndex) == 0 || pointerRoute_[pIndex].size() < MIN_MOVE_POINTER_NUM) {
return false;
}
if (!recognizeGesturePath(pointerRoute_[pIndex])) {
return false;
}
}
GestureType gestureId = GetMoveGestureId();
listener_->MultiFingerGestureOnCompleted(gestureId);
return true;
}
void AccessibilityMultiTapGestureRecognizer::HandleMultiFingerTouchUpEvent(MMI::PointerEvent &event)
{
HILOG_DEBUG("gestureState is %{public}d, isFirstUp is %{public}d, target finger num is %{public}d",
multiFingerGestureState_, isFirstUp_, targetFingers_);
handler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG);
CancelHoldGestureEvent();
if (multiFingerGestureState_ == MultiFingerGestureState::GESTURE_WAIT) {
handler_->SendEvent(CANCEL_WAIT_FINGER_DOWN_MSG, event.GetPointerIds().size(), DOUBLE_TAP_TIMEOUT / US_TO_MS);
}
StoreUpPointInPointerRoute(event);
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
if (IsMoveGestureRecognize()) {
SetMultiFingerGestureState(MultiFingerGestureState::GESTURE_COMPLETE);
fingerTouchUpState_ = FingerTouchUpState::ALL_FINGER_TOUCH_UP;
Clear();
return;
}
fingerTouchUpState_ = FingerTouchUpState::ALL_FINGER_TOUCH_UP;
currentDownPoint_.clear();
preGesturePoint_.clear();
pointerRoute_.clear();
moveDirection = -1;
isMoveGestureRecognizing = false;
} else {
fingerTouchUpState_ = FingerTouchUpState::NOT_ALL_FINGER_TOUCH_UP;
}
if (isFirstUp_) {
isFirstUp_ = false;
if (targetFingers_ != -1 && static_cast<int32_t>(event.GetPointerIds().size()) != targetFingers_) {
CancelGesture(true);
return;
}
}
lastUpPoint_[event.GetPointerId()] = std::make_shared<MMI::PointerEvent>(event);
if (targetFingers_ == -1 && multiFingerGestureState_ == MultiFingerGestureState::GESTURE_START) {
targetFingers_ = static_cast<int32_t>(event.GetPointerIds().size());
}
}
void AccessibilityMultiTapGestureRecognizer::OnPointerEvent(MMI::PointerEvent &event)
{
HILOG_DEBUG("gestureState is %{public}d", multiFingerGestureState_);
switch (event.GetPointerAction()) {
case MMI::PointerEvent::POINTER_ACTION_DOWN:
// cancel last cancel event when recevie a new down event
CancelAllPenddingEvent();
isFirstUp_ = true;
currentDownPoint_[event.GetPointerId()] = std::make_shared<MMI::PointerEvent>(event);
preGesturePoint_[event.GetPointerId()] = std::make_shared<MMI::PointerEvent>(event);
if (targetFingers_ == -1) {
HanleFirstTouchDownEvent(event);
} else {
HandleContinueTouchDownEvent(event);
}
break;
case MMI::PointerEvent::POINTER_ACTION_MOVE:
if (multiFingerGestureState_ != MultiFingerGestureState::GESTURE_START) {
return;
}
HandleMultiFingerMoveEvent(event);
break;
case MMI::PointerEvent::POINTER_ACTION_UP:
HandleMultiFingerTouchUpEvent(event);
break;
default:
break;
}
return;
}
} // namespace Accessibility
} // namespace OHOS

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Copyright (C) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -31,7 +31,6 @@ namespace {
constexpr float TAP_MIN_DISTANCE = 8.0f;
constexpr int32_t MULTI_TAP_TIMER = 250; // ms
constexpr int32_t LONG_PRESS_TIMER = 300; // ms
constexpr int64_t US_TO_MS = 1000;
constexpr float DOUBLE_TAP_SLOP = 100.0f;
constexpr float HALF = 0.5f;
constexpr uint32_t DOUBLE = 2;

View File

@ -1,4 +1,4 @@
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Copyright (C) 2022-2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@ -37,22 +37,7 @@ config("module_private_config") {
"../../test/mock/common",
"../../../common/interface/include",
"../../../common/interface/include/parcel",
"${ability_base_path}/interfaces/inner_api/base/include",
"${ability_base_path}/interfaces/kits/native/uri/include",
"${ability_base_path}/interfaces/kits/native/want/include",
"${ability_runtime_path}/interfaces/kits/native/ability/native/",
"${ability_runtime_path}/interfaces/kits/native/appkit/app/",
"${ability_runtime_inner_api_path}/ability_manager/include",
"${ability_runtime_inner_api_path}/app_manager/include/appmgr/",
"${ability_runtime_services_path}/abilitymgr/include",
"mock",
"../../../../graphic/graphic_2d/rosen/modules/render_service_base/include",
"../../../../graphic/graphic_2d/rosen/modules/2d_graphics/include",
"../../../../multimedia/image_framework/interfaces/innerkits/include",
"../../../../multimedia/image_framework/interfaces/kits/native/include",
"../../../../window/window_manager/previewer/mock",
"../../../../multimodalinput/input/util/common/include",
"../../../../window/window_manager/utils/include",
]
defines = [
@ -75,12 +60,10 @@ ohos_unittest("accessibility_account_data_test") {
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_event_transmission.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_keyevent_filter.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -88,7 +71,7 @@ ohos_unittest("accessibility_account_data_test") {
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessibility_zoom_gesture.cpp",
@ -112,8 +95,6 @@ ohos_unittest("accessibility_account_data_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -132,6 +113,8 @@ ohos_unittest("accessibility_account_data_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -169,12 +152,10 @@ ohos_unittest("accessible_ability_manager_service_test") {
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_event_transmission.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_keyevent_filter.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -183,7 +164,7 @@ ohos_unittest("accessible_ability_manager_service_test") {
"../src/accessibility_settings_config.cpp",
"../src/accessibility_short_key.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_zoom_gesture.cpp",
"../src/accessible_ability_channel.cpp",
@ -209,8 +190,6 @@ ohos_unittest("accessible_ability_manager_service_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -229,6 +208,8 @@ ohos_unittest("accessible_ability_manager_service_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -249,7 +230,7 @@ ohos_unittest("accessible_ability_manager_service_test") {
}
################################################################################
ohos_unittest("accessibility_touch_guider_test") {
ohos_unittest("accessibility_touch_exploration_test") {
module_out_path = module_output_path
sources = [
"../../../common/interface/src/accessibility_element_operator_callback_stub.cpp",
@ -265,11 +246,9 @@ ohos_unittest("accessibility_touch_guider_test") {
"../../test/mock/mock_matching_skill.cpp",
"../src/accessibility_datashare_helper.cpp",
"../src/accessibility_display_manager.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_setting_observer.cpp",
"../src/accessibility_settings_config.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessible_ability_manager_service_event_handler.cpp",
"../src/utils.cpp",
@ -286,7 +265,7 @@ ohos_unittest("accessibility_touch_guider_test") {
"mock/src/mock_accessible_ability_manager_service_stub.cpp",
"mock/src/mock_display.cpp",
"mock/src/mock_system_ability.cpp",
"unittest/accessibility_touch_guider_test.cpp",
"unittest/accessibility_touch_exploration_test.cpp",
]
sources += aams_mock_distributeddatamgr_src
@ -295,11 +274,7 @@ ohos_unittest("accessibility_touch_guider_test") {
"../../../resources/config/build:coverage_flags",
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../interfaces/innerkits/common:accessibility_common",
]
deps = [ "../../../interfaces/innerkits/common:accessibility_common" ]
external_deps = [
"ability_base:want",
@ -316,6 +291,8 @@ ohos_unittest("accessibility_touch_guider_test") {
"data_share:datashare_consumer",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"hicollie:libhicollie",
"hilog:libhilog",
"hisysevent:libhisysevent",
@ -323,6 +300,7 @@ ohos_unittest("accessibility_touch_guider_test") {
"input:libmmi-client",
"ipc:ipc_core",
"os_account:os_account_innerkits",
"power_manager:powermgr_client",
"resource_management:global_resmgr",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
@ -348,12 +326,10 @@ ohos_unittest("accessibility_common_event_registry_test") {
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_event_transmission.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_keyevent_filter.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -363,7 +339,7 @@ ohos_unittest("accessibility_common_event_registry_test") {
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessibility_zoom_gesture.cpp",
@ -384,8 +360,6 @@ ohos_unittest("accessibility_common_event_registry_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -404,6 +378,8 @@ ohos_unittest("accessibility_common_event_registry_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -442,11 +418,9 @@ ohos_unittest("accessibility_input_interceptor_test") {
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_event_transmission.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -455,7 +429,7 @@ ohos_unittest("accessibility_input_interceptor_test") {
"../src/accessibility_settings_config.cpp",
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_zoom_gesture.cpp",
"../src/accessible_ability_channel.cpp",
@ -481,8 +455,6 @@ ohos_unittest("accessibility_input_interceptor_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -501,6 +473,8 @@ ohos_unittest("accessibility_input_interceptor_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -534,12 +508,10 @@ ohos_unittest("accessibility_window_manager_test") {
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_event_transmission.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_keyevent_filter.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -549,7 +521,7 @@ ohos_unittest("accessibility_window_manager_test") {
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessibility_zoom_gesture.cpp",
@ -574,8 +546,6 @@ ohos_unittest("accessibility_window_manager_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -594,6 +564,8 @@ ohos_unittest("accessibility_window_manager_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -622,12 +594,10 @@ ohos_unittest("accessibility_keyevent_filter_test") {
"../src/accessibility_datashare_helper.cpp",
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_keyevent_filter.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -637,7 +607,7 @@ ohos_unittest("accessibility_keyevent_filter_test") {
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessibility_zoom_gesture.cpp",
@ -658,8 +628,6 @@ ohos_unittest("accessibility_keyevent_filter_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -678,6 +646,8 @@ ohos_unittest("accessibility_keyevent_filter_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -716,11 +686,9 @@ ohos_unittest("accessible_ability_connection_test") {
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_event_transmission.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -728,7 +696,7 @@ ohos_unittest("accessible_ability_connection_test") {
"../src/accessibility_settings_config.cpp",
"../src/accessibility_short_key.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessibility_zoom_gesture.cpp",
@ -758,8 +726,6 @@ ohos_unittest("accessible_ability_connection_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -781,6 +747,8 @@ ohos_unittest("accessible_ability_connection_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -817,11 +785,7 @@ ohos_unittest("accessibility_display_manager_test") {
"../../../resources/config/build:coverage_flags",
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
]
deps = [ "../../../common/interface:accessibility_interface" ]
external_deps = [
"ability_base:zuri",
@ -835,6 +799,8 @@ ohos_unittest("accessibility_display_manager_test") {
"data_share:datashare_common",
"data_share:datashare_consumer",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hisysevent:libhisysevent",
"init:libbegetutil",
@ -887,11 +853,7 @@ ohos_unittest("accessibility_dumper_test") {
"../../../resources/config/build:coverage_flags",
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../interfaces/innerkits/common:accessibility_common",
]
deps = [ "../../../interfaces/innerkits/common:accessibility_common" ]
external_deps = [
"ability_base:want",
@ -908,12 +870,15 @@ ohos_unittest("accessibility_dumper_test") {
"data_share:datashare_consumer",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"hicollie:libhicollie",
"hilog:libhilog",
"hisysevent:libhisysevent",
"init:libbegetutil",
"ipc:ipc_core",
"os_account:os_account_innerkits",
"power_manager:powermgr_client",
"resource_management:global_resmgr",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
@ -936,12 +901,10 @@ ohos_unittest("accessibility_touchevent_injector_test") {
"../src/accessibility_datashare_helper.cpp",
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_keyevent_filter.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -951,7 +914,7 @@ ohos_unittest("accessibility_touchevent_injector_test") {
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessibility_zoom_gesture.cpp",
@ -974,8 +937,6 @@ ohos_unittest("accessibility_touchevent_injector_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -994,6 +955,8 @@ ohos_unittest("accessibility_touchevent_injector_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -1059,11 +1022,7 @@ ohos_unittest("accessible_ability_channel_test") {
"../../../resources/config/build:coverage_flags",
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../interfaces/innerkits/common:accessibility_common",
]
deps = [ "../../../interfaces/innerkits/common:accessibility_common" ]
external_deps = [
"ability_base:want",
@ -1080,6 +1039,8 @@ ohos_unittest("accessible_ability_channel_test") {
"data_share:datashare_consumer",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
"hilog:libhilog",
@ -1111,12 +1072,10 @@ ohos_unittest("accessibility_mouse_autoclick_test") {
"../src/accessibility_datashare_helper.cpp",
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_keyevent_filter.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -1125,7 +1084,7 @@ ohos_unittest("accessibility_mouse_autoclick_test") {
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessibility_zoom_gesture.cpp",
@ -1149,8 +1108,6 @@ ohos_unittest("accessibility_mouse_autoclick_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -1169,6 +1126,8 @@ ohos_unittest("accessibility_mouse_autoclick_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -1201,12 +1160,10 @@ ohos_unittest("accessibility_screen_touch_test") {
"../src/accessibility_datashare_helper.cpp",
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_keyevent_filter.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -1215,7 +1172,7 @@ ohos_unittest("accessibility_screen_touch_test") {
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessibility_zoom_gesture.cpp",
@ -1240,8 +1197,6 @@ ohos_unittest("accessibility_screen_touch_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -1260,6 +1215,8 @@ ohos_unittest("accessibility_screen_touch_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -1294,11 +1251,7 @@ ohos_unittest("accessibility_mouse_key_test") {
"../../../resources/config/build:coverage_flags",
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../interfaces/innerkits/common:accessibility_common",
]
deps = [ "../../../interfaces/innerkits/common:accessibility_common" ]
external_deps = [
"ability_base:zuri",
@ -1312,6 +1265,8 @@ ohos_unittest("accessibility_mouse_key_test") {
"data_share:datashare_common",
"data_share:datashare_consumer",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"hilog:libhilog",
"hisysevent:libhisysevent",
"init:libbegetutil",
@ -1339,12 +1294,10 @@ ohos_unittest("accessibility_short_key_test") {
"../src/accessibility_datashare_helper.cpp",
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_keyevent_filter.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -1354,7 +1307,7 @@ ohos_unittest("accessibility_short_key_test") {
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessibility_zoom_gesture.cpp",
@ -1377,8 +1330,6 @@ ohos_unittest("accessibility_short_key_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -1397,6 +1348,8 @@ ohos_unittest("accessibility_short_key_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -1459,8 +1412,6 @@ ohos_unittest("accessibility_short_key_dialog_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -1479,6 +1430,8 @@ ohos_unittest("accessibility_short_key_dialog_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -1509,12 +1462,10 @@ ohos_unittest("accessibility_settings_config_test") {
"../src/accessibility_display_manager.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_event_transmission.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_keyevent_filter.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -1524,7 +1475,7 @@ ohos_unittest("accessibility_settings_config_test") {
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessibility_zoom_gesture.cpp",
@ -1542,8 +1493,6 @@ ohos_unittest("accessibility_settings_config_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -1562,6 +1511,8 @@ ohos_unittest("accessibility_settings_config_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -1594,12 +1545,10 @@ ohos_unittest("accessibility_zoom_gesture_test") {
"../src/accessibility_circle_drawing_manager.cpp",
"../src/accessibility_datashare_helper.cpp",
"../src/accessibility_dumper.cpp",
"../src/accessibility_gesture_recognizer.cpp",
"../src/accessibility_input_interceptor.cpp",
"../src/accessibility_keyevent_filter.cpp",
"../src/accessibility_mouse_autoclick.cpp",
"../src/accessibility_mouse_key.cpp",
"../src/accessibility_multifinger_multitap.cpp",
"../src/accessibility_power_manager.cpp",
"../src/accessibility_screen_touch.cpp",
"../src/accessibility_setting_observer.cpp",
@ -1609,7 +1558,7 @@ ohos_unittest("accessibility_zoom_gesture_test") {
"../src/accessibility_short_key.cpp",
"../src/accessibility_short_key_dialog.cpp",
"../src/accessibility_touchEvent_injector.cpp",
"../src/accessibility_touch_guider.cpp",
"../src/accessibility_touch_exploration.cpp",
"../src/accessibility_window_connection.cpp",
"../src/accessibility_window_manager.cpp",
"../src/accessibility_zoom_gesture.cpp",
@ -1633,8 +1582,6 @@ ohos_unittest("accessibility_zoom_gesture_test") {
]
deps = [
"../../../../../../third_party/googletest:gmock_main",
"../../../../../../third_party/googletest:gtest_main",
"../../../common/interface:accessibility_interface",
"../../../interfaces/innerkits/common:accessibility_common",
]
@ -1653,6 +1600,8 @@ ohos_unittest("accessibility_zoom_gesture_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -1689,7 +1638,7 @@ group("unittest") {
":accessibility_screen_touch_test",
":accessibility_settings_config_test",
":accessibility_short_key_test",
":accessibility_touch_guider_test",
":accessibility_touch_exploration_test",
":accessibility_touchevent_injector_test",
":accessibility_window_manager_test",
":accessibility_zoom_gesture_test",

View File

@ -1,60 +0,0 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MOCK_ACCESSIBILITY_TOUCH_GUIDER_H
#define MOCK_ACCESSIBILITY_TOUCH_GUIDER_H
#include <gmock/gmock.h>
#include "accessibility_touch_guider.h"
namespace OHOS {
namespace Accessibility {
class MockTGEventHandler : public TGEventHandler {
public:
MockTGEventHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner, TouchGuider& tgServer);
virtual ~MockTGEventHandler() = default;
MOCK_METHOD1(ProcessEvent, void(const AppExecFwk::InnerEvent::Pointer& event));
};
class MockTouchGuider : public TouchGuider {
public:
MockTouchGuider();
~MockTouchGuider()
{}
MOCK_METHOD0(StartUp, void());
MOCK_METHOD1(OnPointerEvent, void(MMI::PointerEvent& event));
MOCK_METHOD0(DestroyEvents, void());
MOCK_METHOD2(SendEventToMultimodal, void(MMI::PointerEvent& event, int32_t action));
MOCK_METHOD1(SendAccessibilityEventToAA, void(EventType eventType));
MOCK_METHOD0(getHoverEnterAndMoveEvent, std::list<MMI::PointerEvent>());
MOCK_METHOD0(ClearHoverEnterAndMoveEvent, void());
MOCK_METHOD0(getLastReceivedEvent, std::shared_ptr<MMI::PointerEvent>());
/* For TouchGuide */
inline void OnTouchInteractionStart()
{
isTouchStart_ = true;
}
inline void OnTouchInteractionEnd()
{
isTouchStart_ = false;
}
};
} // namespace Accessibility
} // namespace OHOS
#endif // MOCK_ACCESSIBILITY_TOUCH_GUIDER_H

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -15,7 +15,7 @@
#include "accessibility_input_interceptor.h"
#include "accessibility_keyevent_filter.h"
#include "accessibility_touch_guider.h"
#include "accessibility_touch_exploration.h"
#include "accessibility_touchEvent_injector.h"
#include "accessible_ability_manager_service.h"
#include "hilog_wrapper.h"

View File

@ -1,790 +0,0 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed On an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "accessibility_touch_guider.h"
#include "accessibility_window_manager.h"
#include "hilog_wrapper.h"
#include "securec.h"
namespace OHOS {
namespace Accessibility {
namespace {
constexpr int32_t POINTER_COUNT_1 = 1;
constexpr int32_t POINTER_COUNT_2 = 2;
} // namespace
TGEventHandler::TGEventHandler(const std::shared_ptr<AppExecFwk::EventRunner>& runner, TouchGuider& tgServer)
: AppExecFwk::EventHandler(runner), tgServer_(tgServer)
{
}
TouchGuider::TouchGuider()
{
HILOG_DEBUG();
currentState_ = static_cast<int32_t>(TouchGuideState::TOUCH_GUIDING);
}
void TouchGuider::StartUp()
{
HILOG_DEBUG();
touchGuideListener_ = std::make_unique<TouchGuideListener>(*this);
gestureRecognizer_.RegisterListener(*touchGuideListener_.get());
runner_ = Singleton<AccessibleAbilityManagerService>::GetInstance().GetMainRunner();
if (!runner_) {
HILOG_ERROR("get runner failed");
return;
}
handler_ = std::make_shared<TGEventHandler>(runner_, *this);
if (!handler_) {
HILOG_ERROR("create event handler failed");
return;
}
}
void TGEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event)
{
HILOG_DEBUG();
switch (event->GetInnerEventId()) {
case TouchGuider::EXIT_GESTURE_REC_MSG:
tgServer_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_GESTURE_END);
break;
case TouchGuider::SEND_HOVER_ENTER_MOVE_MSG:
HoverEnterAndMoveRunner();
break;
case TouchGuider::SEND_HOVER_EXIT_MSG:
HoverExitRunner();
break;
case TouchGuider::SEND_TOUCH_INTERACTION_END_MSG:
tgServer_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END);
break;
case TouchGuider::SEND_TOUCH_GUIDE_END_MSG:
tgServer_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_END);
break;
default:
break;
}
}
bool TouchGuider::OnPointerEvent(MMI::PointerEvent& event)
{
HILOG_DEBUG();
if (event.GetSourceType() != MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
EventTransmission::OnPointerEvent(event);
return false;
}
if (event.GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_CANCEL) {
Clear(event);
return true;
}
RecordReceivedEvent(event);
if (gestureRecognizer_.OnPointerEvent(event)) {
return true;
}
switch (static_cast<TouchGuideState>(currentState_)) {
case TouchGuideState::TOUCH_GUIDING:
HandleTouchGuidingState(event);
break;
case TouchGuideState::DRAGGING:
HandleDraggingState(event);
break;
case TouchGuideState::TRANSMITTING:
HandleTransmitingState(event);
break;
default:
break;
}
return true;
}
void TouchGuider::DestroyEvents()
{
HILOG_DEBUG();
Clear();
EventTransmission::DestroyEvents();
}
void TouchGuider::SendAccessibilityEventToAA(EventType eventType)
{
HILOG_DEBUG("eventType is 0x%{public}x.", eventType);
AccessibilityEventInfo eventInfo {};
eventInfo.SetEventType(eventType);
int32_t windowsId = Singleton<AccessibilityWindowManager>::GetInstance().activeWindowId_;
eventInfo.SetWindowId(windowsId);
Singleton<AccessibleAbilityManagerService>::GetInstance().SendEvent(eventInfo);
if (eventType == EventType::TYPE_TOUCH_GUIDE_BEGIN) {
isTouchGuiding_ = true;
} else if (eventType == EventType::TYPE_TOUCH_GUIDE_END) {
isTouchGuiding_ = false;
}
}
void TouchGuider::SendEventToMultimodal(MMI::PointerEvent& event, int32_t action)
{
HILOG_DEBUG("action is %{public}d.", action);
HILOG_DEBUG("SourceType is %{public}d.", event.GetSourceType());
switch (action) {
case HOVER_MOVE:
if (event.GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
event.SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
event.SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
}
break;
case POINTER_DOWN:
if (event.GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
event.SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
}
break;
case POINTER_UP:
if (event.GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
event.SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
}
break;
default:
break;
}
EventTransmission::OnPointerEvent(event);
RecordInjectedEvent(event);
}
std::list<MMI::PointerEvent> TouchGuider::getHoverEnterAndMoveEvent()
{
HILOG_DEBUG();
return pointerEvents_;
}
void TouchGuider::ClearHoverEnterAndMoveEvent()
{
HILOG_DEBUG();
pointerEvents_.clear();
gestureRecognizer_.Clear();
}
std::shared_ptr<MMI::PointerEvent> TouchGuider::getLastReceivedEvent()
{
HILOG_DEBUG();
return receivedRecorder_.lastEvent;
}
bool TouchGuider::TouchGuideListener::OnDoubleTap(MMI::PointerEvent& event)
{
HILOG_DEBUG();
MMI::PointerEvent::PointerItem clickPoint = {};
if (server_.currentState_ != static_cast<int32_t>(TouchGuideState::TOUCH_GUIDING)) {
return false;
}
server_.OnTouchInteractionEnd();
server_.CancelPostEventIfNeed(server_.SEND_HOVER_ENTER_MOVE_MSG);
server_.CancelPostEventIfNeed(server_.SEND_HOVER_EXIT_MSG);
server_.ForceSendAndRemoveEvent(server_.SEND_TOUCH_GUIDE_END_MSG, event);
server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END);
return server_.ExecuteActionOnAccessibilityFocused(ActionType::ACCESSIBILITY_ACTION_CLICK);
}
bool TouchGuider::TouchGuideListener::OnStarted()
{
HILOG_DEBUG();
server_.currentState_ = static_cast<int32_t>(TouchGuideState::TRANSMITTING);
server_.CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG);
server_.CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG);
server_.PostGestureRecognizeExit();
server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_GESTURE_BEGIN);
return false;
}
bool TouchGuider::TouchGuideListener::OnCompleted(GestureType gestureId)
{
HILOG_DEBUG("OnCompleted, gestureId is %{public}d", gestureId);
if (server_.currentState_ != static_cast<int32_t>(TouchGuideState::TRANSMITTING)) {
HILOG_DEBUG("OnCompleted, state is not transmitting.");
return false;
}
server_.OnTouchInteractionEnd();
server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_GESTURE_END);
server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END);
server_.CancelPostEvent(EXIT_GESTURE_REC_MSG);
server_.currentState_ = static_cast<int32_t>(TouchGuideState::TOUCH_GUIDING);
AccessibilityEventInfo eventInfo {};
eventInfo.SetEventType(EventType::TYPE_GESTURE_EVENT);
eventInfo.SetGestureType(gestureId);
Singleton<AccessibleAbilityManagerService>::GetInstance().SendEvent(eventInfo);
return true;
}
bool TouchGuider::TouchGuideListener::OnCancelled(MMI::PointerEvent& event)
{
HILOG_DEBUG();
switch (static_cast<TouchGuideState>(server_.currentState_)) {
case TouchGuideState::TRANSMITTING:
server_.OnTouchInteractionEnd();
server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_GESTURE_END);
if (event.GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_UP &&
event.GetPointerIds().size() == POINTER_COUNT_1) {
server_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END);
}
server_.CancelPostEvent(EXIT_GESTURE_REC_MSG);
server_.currentState_ = static_cast<int32_t>(TouchGuideState::TOUCH_GUIDING);
break;
case TouchGuideState::TOUCH_GUIDING:
server_.pointerEvents_.push_back(event);
server_.ForceSendAndRemoveEvent(SEND_HOVER_ENTER_MOVE_MSG, event);
server_.CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG);
server_.SendEventToMultimodal(event, HOVER_MOVE);
break;
default:
return false;
}
return true;
}
void TouchGuider::HandleTouchGuidingState(MMI::PointerEvent& event)
{
HILOG_DEBUG();
switch (event.GetPointerAction()) {
case MMI::PointerEvent::POINTER_ACTION_DOWN:
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
HandleTouchGuidingStateInnerDown(event);
} else {
CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG);
CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG);
}
break;
case MMI::PointerEvent::POINTER_ACTION_MOVE:
HandleTouchGuidingStateInnerMove(event);
break;
case MMI::PointerEvent::POINTER_ACTION_UP:
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
OnTouchInteractionEnd();
if (HasEventPending(SEND_HOVER_ENTER_MOVE_MSG)) {
PostHoverExit();
} else {
SendExitEvents();
}
if (!HasEventPending(SEND_TOUCH_INTERACTION_END_MSG)) {
PostAccessibilityEvent(SEND_TOUCH_INTERACTION_END_MSG);
}
}
break;
default:
break;
}
}
void TouchGuider::HandleDraggingState(MMI::PointerEvent& event)
{
HILOG_DEBUG();
switch (event.GetPointerAction()) {
case MMI::PointerEvent::POINTER_ACTION_DOWN:
HILOG_DEBUG("MMI::PointerEvent::POINTER_ACTION_DOWN");
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
Clear(event);
} else {
currentState_ = static_cast<int32_t>(TouchGuideState::TRANSMITTING);
SendAllUpEvents(event);
}
break;
case MMI::PointerEvent::POINTER_ACTION_MOVE:
HILOG_DEBUG("MMI::PointerEvent::POINTER_ACTION_MOVE");
HandleDraggingStateInnerMove(event);
break;
case MMI::PointerEvent::POINTER_ACTION_UP:
HILOG_DEBUG("MMI::PointerEvent::POINTER_ACTION_UP");
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
OnTouchInteractionEnd();
SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END);
SendEventToMultimodal(event, NO_CHANGE);
currentState_ = static_cast<int32_t>(TouchGuideState::TOUCH_GUIDING);
} else {
SendEventToMultimodal(event, NO_CHANGE);
}
break;
default:
break;
}
}
void TouchGuider::HandleTransmitingState(MMI::PointerEvent& event)
{
HILOG_DEBUG();
switch (event.GetPointerAction()) {
case MMI::PointerEvent::POINTER_ACTION_DOWN:
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
Clear(event);
}
break;
case MMI::PointerEvent::POINTER_ACTION_UP:
if (event.GetPointerIds().size() == POINTER_COUNT_1) {
if (longPressPointId_ >= 0) {
// Adjust this event's location.
MMI::PointerEvent::PointerItem pointer = {};
event.GetPointerItem(event.GetPointerId(), pointer);
pointer.SetDisplayX(pointer.GetDisplayX() + longPressOffsetX_);
pointer.SetDisplayY(pointer.GetDisplayY() + longPressOffsetY_);
event.RemovePointerItem(event.GetPointerId());
event.AddPointerItem(pointer);
longPressPointId_ = INIT_POINT_ID;
longPressOffsetX_ = INIT_MMIPOINT;
longPressOffsetY_ = INIT_MMIPOINT;
}
SendEventToMultimodal(event, NO_CHANGE);
OnTouchInteractionEnd();
SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END);
currentState_ = static_cast<int32_t>(TouchGuideState::TOUCH_GUIDING);
}
break;
default:
SendEventToMultimodal(event, NO_CHANGE);
break;
}
}
void TouchGuider::Clear(MMI::PointerEvent& event)
{
HILOG_DEBUG();
if (currentState_ == static_cast<int32_t>(TouchGuideState::TOUCH_GUIDING)) {
SendExitEvents();
} else if (currentState_ == static_cast<int32_t>(TouchGuideState::DRAGGING) ||
currentState_ == static_cast<int32_t>(TouchGuideState::TRANSMITTING)) {
SendUpForAllInjectedEvent(event);
}
CancelPostEvent(EXIT_GESTURE_REC_MSG);
CancelPostEvent(SEND_TOUCH_INTERACTION_END_MSG);
CancelPostEvent(SEND_TOUCH_GUIDE_END_MSG);
CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG);
CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG);
ClearInjectedEventRecorder();
ClearReceivedEventRecorder();
pointerEvents_.clear();
currentState_ = static_cast<int32_t>(TouchGuideState::TOUCH_GUIDING);
isTouchGuiding_ = false;
gestureRecognizer_.Clear();
longPressPointId_ = INIT_POINT_ID;
longPressOffsetX_ = INIT_MMIPOINT;
longPressOffsetY_ = INIT_MMIPOINT;
OnTouchInteractionEnd();
}
void TouchGuider::Clear()
{
HILOG_DEBUG();
std::shared_ptr<MMI::PointerEvent> event = getLastReceivedEvent();
if (event) {
Clear(*event);
}
}
void TouchGuider::SendExitEvents()
{
HILOG_DEBUG();
if (!HasEventPending(SEND_TOUCH_GUIDE_END_MSG)) {
PostAccessibilityEvent(SEND_TOUCH_GUIDE_END_MSG);
}
}
void TouchGuider::HandleTouchGuidingStateInnerDown(MMI::PointerEvent& event)
{
(void)event;
}
void TouchGuider::HandleTouchGuidingStateInnerMove(MMI::PointerEvent& event)
{
HILOG_DEBUG();
switch (event.GetPointerIds().size()) {
case POINTER_COUNT_1:
HILOG_DEBUG("POINTER_COUNT_1 begin");
if (HasEventPending(SEND_HOVER_ENTER_MOVE_MSG)) {
pointerEvents_.push_back(event);
} else if (isTouchGuiding_) {
SendEventToMultimodal(event, HOVER_MOVE);
}
HILOG_DEBUG("POINTER_COUNT_1 end");
break;
case POINTER_COUNT_2:
HILOG_DEBUG("POINTER_COUNT_2 begin");
CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG);
CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG);
if (IsDragGestureAccept(event)) {
currentState_ = static_cast<int32_t>(TouchGuideState::DRAGGING);
SendEventToMultimodal(event, POINTER_DOWN);
} else {
currentState_ = static_cast<int32_t>(TouchGuideState::TRANSMITTING);
}
HILOG_DEBUG("POINTER_COUNT_2 end");
break;
default:
HILOG_DEBUG("default begin");
if (HasEventPending(SEND_HOVER_ENTER_MOVE_MSG)) {
CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG);
CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG);
} else {
SendExitEvents();
}
currentState_ = static_cast<int32_t>(TouchGuideState::TRANSMITTING);
HILOG_DEBUG("default end");
break;
}
}
void TouchGuider::HandleDraggingStateInnerMove(MMI::PointerEvent& event)
{
HILOG_DEBUG();
std::vector<int32_t> pIds = event.GetPointerIds();
int32_t pointCount = pIds.size();
if (pointCount == POINTER_COUNT_1) {
HILOG_INFO("Only two pointers can be received in the dragging state");
} else if (pointCount == POINTER_COUNT_2 && IsDragGestureAccept(event)) {
/* get densityPixels from WMS */
AccessibilityDisplayManager& displayMgr = Singleton<AccessibilityDisplayManager>::GetInstance();
auto display = displayMgr.GetDefaultDisplay();
float densityPixels = display->GetVirtualPixelRatio();
int32_t miniZoomPointerDistance = static_cast<int32_t>(MINI_POINTER_DISTANCE_DIP * densityPixels);
MMI::PointerEvent::PointerItem pointerF = {};
MMI::PointerEvent::PointerItem pointerS = {};
event.GetPointerItem(pIds[INDEX_0], pointerF);
event.GetPointerItem(pIds[INDEX_1], pointerS);
float xPointF = pointerF.GetDisplayX();
float xPointS = pointerS.GetDisplayX();
float yPointF = pointerF.GetDisplayY();
float yPointS = pointerS.GetDisplayY();
float offsetX = abs(xPointF - xPointS);
float offsetY = abs(yPointF - yPointS);
double duration = hypot(offsetX, offsetY);
if (duration > miniZoomPointerDistance) {
// Adjust this event's location.
MMI::PointerEvent::PointerItem pointer = {};
event.GetPointerItem(event.GetPointerId(), pointer);
pointer.SetDisplayX(pointer.GetDisplayX() + DIVIDE_2(offsetX));
pointer.SetDisplayY(pointer.GetDisplayY() + DIVIDE_2(offsetY));
event.RemovePointerItem(event.GetPointerId());
event.AddPointerItem(pointer);
}
SendEventToMultimodal(event, NO_CHANGE);
} else {
currentState_ = static_cast<int32_t>(TouchGuideState::TRANSMITTING);
SendAllUpEvents(event);
}
}
float TouchGuider::GetAngleCos(float offsetX, float offsetY, bool isGetX)
{
HILOG_DEBUG();
float ret = isGetX ? offsetX : offsetY;
double duration = hypot(offsetX, offsetY);
if (duration == 0) {
return ret;
}
ret = ret / duration;
return ret;
}
bool TouchGuider::IsDragGestureAccept(MMI::PointerEvent& event)
{
HILOG_DEBUG();
std::vector<int32_t> pIds = event.GetPointerIds();
MMI::PointerEvent::PointerItem pointerF = {};
MMI::PointerEvent::PointerItem pointerS = {};
if (!event.GetPointerItem(pIds[0], pointerF)) {
HILOG_ERROR("GetPointerItem(%{public}d) failed", pIds[0]);
}
if (!event.GetPointerItem(pIds[1], pointerS)) {
HILOG_ERROR("GetPointerItem(%{public}d) failed", pIds[1]);
}
float xPointF = pointerF.GetDisplayX();
float xPointS = pointerS.GetDisplayX();
float yPointF = pointerF.GetDisplayY();
float yPointS = pointerS.GetDisplayY();
float xPointDownF = 0;
float xPointDownS = 0;
float yPointDownF = 0;
float yPointDownS = 0;
if (receivedRecorder_.pointerDownX.find(INDEX_0) != receivedRecorder_.pointerDownX.end()) {
xPointDownF = receivedRecorder_.pointerDownX.find(INDEX_0)->second;
yPointDownF = receivedRecorder_.pointerDownY.find(INDEX_0)->second;
}
if (receivedRecorder_.pointerDownX.find(INDEX_1) != receivedRecorder_.pointerDownX.end()) {
xPointDownS = receivedRecorder_.pointerDownX.find(INDEX_1)->second;
yPointDownS = receivedRecorder_.pointerDownY.find(INDEX_1)->second;
}
float firstOffsetX = xPointF - xPointDownF;
float firstOffsetY = yPointF - yPointDownF;
float secondOffsetX = xPointS - xPointDownS;
float secondOffsetY = yPointS - yPointDownS;
if ((!firstOffsetX && !firstOffsetY) || (!secondOffsetX && !secondOffsetY)) {
return true;
}
float firstXCos = GetAngleCos(firstOffsetX, firstOffsetY, true);
float firstYCos = GetAngleCos(firstOffsetX, firstOffsetY, false);
float secondXCos = GetAngleCos(secondOffsetX, secondOffsetY, true);
float secondYCos = GetAngleCos(secondOffsetX, secondOffsetY, false);
if ((firstXCos * secondXCos + firstYCos * secondYCos) < MAX_DRAG_GESTURE_COSINE) {
return false;
}
return true;
}
void TouchGuider::RecordInjectedEvent(MMI::PointerEvent& event)
{
HILOG_DEBUG();
int32_t pointerId = event.GetPointerId();
switch (event.GetPointerAction()) {
case MMI::PointerEvent::POINTER_ACTION_DOWN:
injectedRecorder_.downPointerNum++;
injectedRecorder_.downPointers.insert(pointerId);
injectedRecorder_.lastDownTime = event.GetActionTime() / US_TO_MS;
break;
case MMI::PointerEvent::POINTER_ACTION_UP:
injectedRecorder_.downPointers.erase(pointerId);
if (injectedRecorder_.downPointerNum > 0) {
injectedRecorder_.downPointerNum--;
}
if (injectedRecorder_.downPointers.empty()) {
injectedRecorder_.lastDownTime = 0;
}
break;
case MMI::PointerEvent::POINTER_ACTION_MOVE:
injectedRecorder_.lastHoverEvent = std::make_shared<MMI::PointerEvent>(event);
break;
default:
break;
}
}
void TouchGuider::RecordReceivedEvent(MMI::PointerEvent& event)
{
HILOG_DEBUG();
int32_t pointId = event.GetPointerId();
MMI::PointerEvent::PointerItem pointer;
if (!event.GetPointerItem(pointId, pointer)) {
HILOG_ERROR("GetPointerItem(%{public}d) failed", pointId);
}
receivedRecorder_.lastEvent = std::make_shared<MMI::PointerEvent>(event);
switch (event.GetPointerAction()) {
case MMI::PointerEvent::POINTER_ACTION_DOWN:
receivedRecorder_.pointerDownX[pointId] = pointer.GetDisplayX();
receivedRecorder_.pointerDownY[pointId] = pointer.GetDisplayY();
break;
case MMI::PointerEvent::POINTER_ACTION_UP:
receivedRecorder_.pointerDownX.erase(pointId);
receivedRecorder_.pointerDownY.erase(pointId);
break;
default:
break;
}
}
void TouchGuider::ClearReceivedEventRecorder()
{
HILOG_DEBUG();
receivedRecorder_.pointerDownX.clear();
receivedRecorder_.pointerDownY.clear();
receivedRecorder_.lastEvent = nullptr;
}
void TouchGuider::ClearInjectedEventRecorder()
{
HILOG_DEBUG();
injectedRecorder_.downPointerNum = 0;
injectedRecorder_.downPointers.clear();
injectedRecorder_.lastHoverEvent = nullptr;
}
void TouchGuider::SendAllDownEvents(MMI::PointerEvent& event)
{
HILOG_DEBUG();
std::vector<int32_t> pIds = event.GetPointerIds();
for (auto& pId : pIds) {
if (injectedRecorder_.downPointers.find(pId) == injectedRecorder_.downPointers.end()) {
event.SetPointerId(pId);
SendEventToMultimodal(event, POINTER_DOWN);
}
}
}
void TouchGuider::SendAllUpEvents(MMI::PointerEvent &event)
{
HILOG_DEBUG();
std::vector<int32_t> pIds = event.GetPointerIds();
for (auto& pId : pIds) {
event.SetPointerId(pId);
SendEventToMultimodal(event, POINTER_UP);
}
}
void TouchGuider::SendUpForAllInjectedEvent(MMI::PointerEvent& event)
{
HILOG_DEBUG();
std::vector<int32_t> pIds = event.GetPointerIds();
for (const auto& pId : pIds) {
if (injectedRecorder_.downPointers.find(pId) == injectedRecorder_.downPointers.end()) {
continue;
}
SendEventToMultimodal(event, POINTER_UP);
}
}
void TouchGuider::PostGestureRecognizeExit()
{
HILOG_DEBUG();
handler_->SendEvent(EXIT_GESTURE_REC_MSG, 0, EXIT_GESTURE_REC_TIMEOUT);
}
void TouchGuider::PostHoverEnterAndMove(MMI::PointerEvent& event)
{
HILOG_DEBUG();
CancelPostEventIfNeed(SEND_HOVER_ENTER_MOVE_MSG);
pointerEvents_.push_back(event);
handler_->SendEvent(SEND_HOVER_ENTER_MOVE_MSG, 0, DOUBLE_TAP_TIMEOUT);
}
void TouchGuider::PostHoverExit()
{
HILOG_DEBUG();
CancelPostEventIfNeed(SEND_HOVER_EXIT_MSG);
handler_->SendEvent(SEND_HOVER_EXIT_MSG, 0, DOUBLE_TAP_TIMEOUT);
}
void TouchGuider::PostAccessibilityEvent(uint32_t innerEventID)
{
HILOG_DEBUG();
handler_->SendEvent(innerEventID, 0, EXIT_GESTURE_REC_TIMEOUT);
}
void TouchGuider::CancelPostEvent(uint32_t innerEventID)
{
HILOG_DEBUG();
handler_->RemoveEvent(innerEventID);
}
void TouchGuider::CancelPostEventIfNeed(uint32_t innerEventID)
{
HILOG_DEBUG();
if (HasEventPending(innerEventID)) {
handler_->RemoveEvent(innerEventID);
if (innerEventID == SEND_HOVER_ENTER_MOVE_MSG) {
pointerEvents_.clear();
}
}
}
bool TouchGuider::HasEventPending(uint32_t innerEventID)
{
HILOG_DEBUG();
return handler_->HasInnerEvent(innerEventID);
}
void TouchGuider::ForceSendAndRemoveEvent(uint32_t innerEventID, MMI::PointerEvent& event)
{
(void)event;
HILOG_DEBUG();
if (!HasEventPending(innerEventID)) {
HILOG_DEBUG("No pending event.");
return;
}
switch (innerEventID) {
case SEND_HOVER_ENTER_MOVE_MSG:
SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_BEGIN);
if (pointerEvents_.empty()) {
break;
}
for (auto iter = pointerEvents_.begin(); iter != pointerEvents_.end(); ++iter) {
SendEventToMultimodal(*iter, HOVER_MOVE);
}
pointerEvents_.clear();
break;
case SEND_TOUCH_INTERACTION_END_MSG:
SendAccessibilityEventToAA(EventType::TYPE_TOUCH_END);
break;
case SEND_TOUCH_GUIDE_END_MSG:
SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_END);
break;
default:
break;
}
CancelPostEvent(innerEventID);
}
void TGEventHandler::HoverEnterAndMoveRunner()
{
HILOG_DEBUG();
std::list<MMI::PointerEvent> motionEvent = tgServer_.getHoverEnterAndMoveEvent();
tgServer_.SendAccessibilityEventToAA(EventType::TYPE_TOUCH_GUIDE_BEGIN);
if (!motionEvent.empty()) {
for (auto iter = motionEvent.begin(); iter != motionEvent.end(); ++iter) {
tgServer_.SendEventToMultimodal(*iter, HOVER_MOVE);
}
}
tgServer_.ClearHoverEnterAndMoveEvent();
}
void TGEventHandler::HoverExitRunner()
{
HILOG_DEBUG();
std::shared_ptr<MMI::PointerEvent> pEvent = tgServer_.getLastReceivedEvent();
tgServer_.SendEventToMultimodal(*pEvent, HOVER_MOVE);
if (!HasInnerEvent(TouchGuider::SEND_TOUCH_GUIDE_END_MSG)) {
RemoveEvent(TouchGuider::SEND_TOUCH_GUIDE_END_MSG);
SendEvent(TouchGuider::SEND_TOUCH_GUIDE_END_MSG, 0, EXIT_GESTURE_REC_TIMEOUT);
}
if (HasInnerEvent(TouchGuider::SEND_TOUCH_INTERACTION_END_MSG)) {
RemoveEvent(TouchGuider::SEND_TOUCH_INTERACTION_END_MSG);
SendEvent(TouchGuider::SEND_TOUCH_INTERACTION_END_MSG, 0, EXIT_GESTURE_REC_TIMEOUT);
}
}
} // namespace Accessibility
} // namespace OHOS

View File

@ -15,7 +15,7 @@
#include <gtest/gtest.h>
#include "display.h"
#include "window/window_manager/utils/include/display_info.h"
#include "display_info.h"
namespace OHOS::Rosen {
namespace {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Copyright (C) 2022-2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@ -41,16 +41,7 @@ config("module_private_config") {
"../aams/include",
"mock",
"./mock/common",
"${ability_runtime_path}/interfaces/kits/native/ability/native/",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
"${ability_runtime_path}/interfaces/kits/native/appkit/app/",
"${ability_runtime_inner_api_path}/ability_manager/include",
"${ability_runtime_inner_api_path}/app_manager/include/appmgr",
"${ability_runtime_services_path}/abilitymgr/include",
"mock/aafwk/include",
"${AAMS_FOUNDATION_PATH}/window/window_manager/utils/include",
"../../../graphic/graphic_2d/rosen/modules/2d_graphics/include",
]
defines = [
@ -64,7 +55,7 @@ config("module_private_config") {
MockDistributedscheduleSrc = []
################################################################################
ohos_moduletest("aams_accessibility_touch_guider_test") {
ohos_moduletest("aams_accessibility_touch_exploration_test") {
module_out_path = module_output_path
sources = [
@ -76,12 +67,10 @@ ohos_moduletest("aams_accessibility_touch_guider_test") {
"../aams/src/accessibility_display_manager.cpp",
"../aams/src/accessibility_dumper.cpp",
"../aams/src/accessibility_event_transmission.cpp",
"../aams/src/accessibility_gesture_recognizer.cpp",
"../aams/src/accessibility_input_interceptor.cpp",
"../aams/src/accessibility_keyevent_filter.cpp",
"../aams/src/accessibility_mouse_autoclick.cpp",
"../aams/src/accessibility_mouse_key.cpp",
"../aams/src/accessibility_multifinger_multitap.cpp",
"../aams/src/accessibility_power_manager.cpp",
"../aams/src/accessibility_screen_touch.cpp",
"../aams/src/accessibility_setting_observer.cpp",
@ -89,7 +78,7 @@ ohos_moduletest("aams_accessibility_touch_guider_test") {
"../aams/src/accessibility_settings_config.cpp",
"../aams/src/accessibility_short_key.cpp",
"../aams/src/accessibility_touchEvent_injector.cpp",
"../aams/src/accessibility_touch_guider.cpp",
"../aams/src/accessibility_touch_exploration.cpp",
"../aams/src/accessibility_window_connection.cpp",
"../aams/src/accessibility_window_manager.cpp",
"../aams/src/accessibility_zoom_gesture.cpp",
@ -114,7 +103,7 @@ ohos_moduletest("aams_accessibility_touch_guider_test") {
"./mock/mock_parameter.c",
"./mock/mock_service_registry.cpp",
"./mock/mock_system_ability.cpp",
"moduletest/aamstest/aams_accessibility_touch_guider_test/aams_accessibility_touch_guider_test.cpp",
"moduletest/aamstest/aams_accessibility_touch_exploration_test/aams_accessibility_touch_exploration_test.cpp",
]
sources += aams_mock_distributeddatamgr_src
sources += aams_mock_multimodalinput_src
@ -127,8 +116,6 @@ ohos_moduletest("aams_accessibility_touch_guider_test") {
]
deps = [
"../../../../../third_party/googletest:gmock_main",
"../../../../../third_party/googletest:gtest_main",
"../../common/interface:accessibility_interface",
"../../interfaces/innerkits/common:accessibility_common",
]
@ -147,6 +134,8 @@ ohos_moduletest("aams_accessibility_touch_guider_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -176,12 +165,10 @@ ohos_moduletest("aams_accessibility_touchEvent_injector_test") {
"../aams/src/accessibility_display_manager.cpp",
"../aams/src/accessibility_dumper.cpp",
"../aams/src/accessibility_event_transmission.cpp",
"../aams/src/accessibility_gesture_recognizer.cpp",
"../aams/src/accessibility_input_interceptor.cpp",
"../aams/src/accessibility_keyevent_filter.cpp",
"../aams/src/accessibility_mouse_autoclick.cpp",
"../aams/src/accessibility_mouse_key.cpp",
"../aams/src/accessibility_multifinger_multitap.cpp",
"../aams/src/accessibility_power_manager.cpp",
"../aams/src/accessibility_screen_touch.cpp",
"../aams/src/accessibility_setting_observer.cpp",
@ -189,7 +176,7 @@ ohos_moduletest("aams_accessibility_touchEvent_injector_test") {
"../aams/src/accessibility_settings_config.cpp",
"../aams/src/accessibility_short_key.cpp",
"../aams/src/accessibility_touchEvent_injector.cpp",
"../aams/src/accessibility_touch_guider.cpp",
"../aams/src/accessibility_touch_exploration.cpp",
"../aams/src/accessibility_window_connection.cpp",
"../aams/src/accessibility_window_manager.cpp",
"../aams/src/accessibility_zoom_gesture.cpp",
@ -228,8 +215,6 @@ ohos_moduletest("aams_accessibility_touchEvent_injector_test") {
]
deps = [
"../../../../../third_party/googletest:gmock_main",
"../../../../../third_party/googletest:gtest_main",
"../../common/interface:accessibility_interface",
"../../interfaces/innerkits/common:accessibility_common",
]
@ -248,6 +233,8 @@ ohos_moduletest("aams_accessibility_touchEvent_injector_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -277,12 +264,10 @@ ohos_moduletest("aams_accessible_ability_channel_test") {
"../aams/src/accessibility_display_manager.cpp",
"../aams/src/accessibility_dumper.cpp",
"../aams/src/accessibility_event_transmission.cpp",
"../aams/src/accessibility_gesture_recognizer.cpp",
"../aams/src/accessibility_input_interceptor.cpp",
"../aams/src/accessibility_keyevent_filter.cpp",
"../aams/src/accessibility_mouse_autoclick.cpp",
"../aams/src/accessibility_mouse_key.cpp",
"../aams/src/accessibility_multifinger_multitap.cpp",
"../aams/src/accessibility_power_manager.cpp",
"../aams/src/accessibility_screen_touch.cpp",
"../aams/src/accessibility_setting_observer.cpp",
@ -290,7 +275,7 @@ ohos_moduletest("aams_accessible_ability_channel_test") {
"../aams/src/accessibility_settings_config.cpp",
"../aams/src/accessibility_short_key.cpp",
"../aams/src/accessibility_touchEvent_injector.cpp",
"../aams/src/accessibility_touch_guider.cpp",
"../aams/src/accessibility_touch_exploration.cpp",
"../aams/src/accessibility_window_connection.cpp",
"../aams/src/accessibility_window_manager.cpp",
"../aams/src/accessibility_zoom_gesture.cpp",
@ -335,8 +320,6 @@ ohos_moduletest("aams_accessible_ability_channel_test") {
]
deps = [
"../../../../../third_party/googletest:gmock_main",
"../../../../../third_party/googletest:gtest_main",
"../../common/interface:accessibility_interface",
"../../interfaces/innerkits/common:accessibility_common",
]
@ -354,6 +337,8 @@ ohos_moduletest("aams_accessible_ability_channel_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -383,12 +368,10 @@ ohos_moduletest("aams_server_test") {
"../aams/src/accessibility_display_manager.cpp",
"../aams/src/accessibility_dumper.cpp",
"../aams/src/accessibility_event_transmission.cpp",
"../aams/src/accessibility_gesture_recognizer.cpp",
"../aams/src/accessibility_input_interceptor.cpp",
"../aams/src/accessibility_keyevent_filter.cpp",
"../aams/src/accessibility_mouse_autoclick.cpp",
"../aams/src/accessibility_mouse_key.cpp",
"../aams/src/accessibility_multifinger_multitap.cpp",
"../aams/src/accessibility_power_manager.cpp",
"../aams/src/accessibility_screen_touch.cpp",
"../aams/src/accessibility_setting_observer.cpp",
@ -396,7 +379,7 @@ ohos_moduletest("aams_server_test") {
"../aams/src/accessibility_settings_config.cpp",
"../aams/src/accessibility_short_key.cpp",
"../aams/src/accessibility_touchEvent_injector.cpp",
"../aams/src/accessibility_touch_guider.cpp",
"../aams/src/accessibility_touch_exploration.cpp",
"../aams/src/accessibility_window_connection.cpp",
"../aams/src/accessibility_window_manager.cpp",
"../aams/src/accessibility_zoom_gesture.cpp",
@ -439,8 +422,6 @@ ohos_moduletest("aams_server_test") {
]
deps = [
"../../../../../third_party/googletest:gmock_main",
"../../../../../third_party/googletest:gtest_main",
"../../common/interface:accessibility_interface",
"../../interfaces/innerkits/common:accessibility_common",
]
@ -458,6 +439,8 @@ ohos_moduletest("aams_server_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -487,12 +470,10 @@ ohos_moduletest("aams_accessibility_keyevent_filter_test") {
"../aams/src/accessibility_display_manager.cpp",
"../aams/src/accessibility_dumper.cpp",
"../aams/src/accessibility_event_transmission.cpp",
"../aams/src/accessibility_gesture_recognizer.cpp",
"../aams/src/accessibility_input_interceptor.cpp",
"../aams/src/accessibility_keyevent_filter.cpp",
"../aams/src/accessibility_mouse_autoclick.cpp",
"../aams/src/accessibility_mouse_key.cpp",
"../aams/src/accessibility_multifinger_multitap.cpp",
"../aams/src/accessibility_power_manager.cpp",
"../aams/src/accessibility_screen_touch.cpp",
"../aams/src/accessibility_setting_observer.cpp",
@ -500,7 +481,7 @@ ohos_moduletest("aams_accessibility_keyevent_filter_test") {
"../aams/src/accessibility_settings_config.cpp",
"../aams/src/accessibility_short_key.cpp",
"../aams/src/accessibility_touchEvent_injector.cpp",
"../aams/src/accessibility_touch_guider.cpp",
"../aams/src/accessibility_touch_exploration.cpp",
"../aams/src/accessibility_window_connection.cpp",
"../aams/src/accessibility_window_manager.cpp",
"../aams/src/accessibility_zoom_gesture.cpp",
@ -537,8 +518,6 @@ ohos_moduletest("aams_accessibility_keyevent_filter_test") {
]
deps = [
"../../../../../third_party/googletest:gmock_main",
"../../../../../third_party/googletest:gtest_main",
"../../common/interface:accessibility_interface",
"../../interfaces/innerkits/common:accessibility_common",
]
@ -557,6 +536,8 @@ ohos_moduletest("aams_accessibility_keyevent_filter_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -586,12 +567,10 @@ ohos_moduletest("aams_common_event_registry_test") {
"../aams/src/accessibility_display_manager.cpp",
"../aams/src/accessibility_dumper.cpp",
"../aams/src/accessibility_event_transmission.cpp",
"../aams/src/accessibility_gesture_recognizer.cpp",
"../aams/src/accessibility_input_interceptor.cpp",
"../aams/src/accessibility_keyevent_filter.cpp",
"../aams/src/accessibility_mouse_autoclick.cpp",
"../aams/src/accessibility_mouse_key.cpp",
"../aams/src/accessibility_multifinger_multitap.cpp",
"../aams/src/accessibility_power_manager.cpp",
"../aams/src/accessibility_screen_touch.cpp",
"../aams/src/accessibility_setting_observer.cpp",
@ -599,7 +578,7 @@ ohos_moduletest("aams_common_event_registry_test") {
"../aams/src/accessibility_settings_config.cpp",
"../aams/src/accessibility_short_key.cpp",
"../aams/src/accessibility_touchEvent_injector.cpp",
"../aams/src/accessibility_touch_guider.cpp",
"../aams/src/accessibility_touch_exploration.cpp",
"../aams/src/accessibility_window_connection.cpp",
"../aams/src/accessibility_window_manager.cpp",
"../aams/src/accessibility_zoom_gesture.cpp",
@ -642,8 +621,6 @@ ohos_moduletest("aams_common_event_registry_test") {
]
deps = [
"../../../../../third_party/googletest:gmock_main",
"../../../../../third_party/googletest:gtest_main",
"../../common/interface:accessibility_interface",
"../../interfaces/innerkits/common:accessibility_common",
]
@ -661,6 +638,8 @@ ohos_moduletest("aams_common_event_registry_test") {
"display_manager:displaymgr",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"googletest:gmock_main",
"googletest:gtest_main",
"graphic_2d:2d_graphics",
"graphic_2d:librender_service_client",
"hicollie:libhicollie",
@ -686,7 +665,7 @@ group("moduletest") {
deps += [
":aams_accessibility_keyevent_filter_test",
":aams_accessibility_touchEvent_injector_test",
":aams_accessibility_touch_guider_test",
":aams_accessibility_touch_exploration_test",
":aams_accessible_ability_channel_test",
":aams_common_event_registry_test",
":aams_server_test",

View File

@ -11,11 +11,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
ability_base_path = "//foundation/ability/ability_base"
ability_runtime_path = "//foundation/ability/ability_runtime"
ability_runtime_inner_api_path = "${ability_runtime_path}/interfaces/inner_api"
ability_runtime_kits_path = "${ability_runtime_path}/frameworks/kits"
ability_runtime_services_path = "${ability_runtime_path}/services"
AAMS_MOCK_PATH = "//foundation/barrierfree/accessibility/services/test/mock"
AAMS_FRAMEWORKS_PATH = "//foundation/barrierfree/accessibility/frameworks"
AAMS_INTERFACES_PATH = "//foundation/barrierfree/accessibility/interfaces"
@ -27,39 +22,6 @@ aams_mock_include_dirs = [
"$AAMS_MOCK_PATH/distributeddatamgr/include",
"$AAMS_MOCK_PATH/multimodalinput/include",
"$AAMS_MOCK_PATH/powermanager/include",
"//base/account/os_account/interfaces/innerkits/common/include",
"//base/account/os_account/interfaces/innerkits/osaccount/native/include",
"//base/global/resource_management/interfaces/inner_api/include",
"//base/hiviewdfx/hiview/adapter/utility/include/extra/singleton.h",
"//base/notification/common_event_service/interfaces/inner_api",
"//base/notification/eventhandler/interfaces/inner_api",
"//base/powermgr/display_manager/utils/native/include",
"//foundation",
"//foundation/arkui/napi/native_engine",
"//foundation/distributeddatamgr/preferences/interfaces/inner_api/include",
"//foundation/multimodalinput/input/interfaces/native/innerkits/proxy/include",
"//foundation/distributeddatamgr/data_share/interfaces/inner_api/common/include",
"//foundation/multimodalinput/input/interfaces/native/innerkits/event/include",
"//base/powermgr/power_manager/interfaces/inner_api/native/include",
"//foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_base/include",
"//foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_core/include",
"//foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_core/include/bundlemgr",
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base/include",
"//foundation/multimedia/image_framework/interfaces/kits/native/include",
"//foundation/multimedia/image_framework/interfaces/innerkits/include",
"//foundation/multimodalinput/input/util/common/include",
"//foundation/window/window_manager/dm/include",
"//foundation/window/window_manager/interfaces/innerkits",
"//foundation/window/window_manager/interfaces/innerkits/dm",
"//foundation/window/window_manager/interfaces/innerkits/wm",
"//foundation/window/window_manager/utils/include",
"//third_party/jsoncpp/include",
"//third_party/jsoncpp/include/json",
"//commonlibrary/c_utils/base/include",
"//utils/system/safwk/native/include",
]
aams_mock_distributeddatamgr_src =

View File

@ -14,7 +14,7 @@
*/
#include "display.h"
#include "window/window_manager/utils/include/display_info.h"
#include "display_info.h"
namespace OHOS::Rosen {
namespace {

View File

@ -18,7 +18,7 @@
#include "display.h"
#include "dm_common.h"
#include "singleton_delegator.h"
#include "window/window_manager/utils/include/display_info.h"
#include "display_info.h"
namespace OHOS::Rosen {
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManager)