diff --git a/services/aams/include/accessibility_input_interceptor.h b/services/aams/include/accessibility_input_interceptor.h index e4b82da50..06426002b 100644 --- a/services/aams/include/accessibility_input_interceptor.h +++ b/services/aams/include/accessibility_input_interceptor.h @@ -91,6 +91,8 @@ public: void StartMagnificationInteract(uint32_t mode); void EnableGesture(uint32_t mode); void DisableGesture(uint32_t mode); + void SetMagnificationMode(uint32_t mode); + void SetMagnificationTriggerMethod(int32_t screenMagnificationTriggerMethod); void InitInputManagerHandler(); void SetServiceOnKeyEventResult(int32_t connectionId, bool isHandled, uint32_t sequenceNum); @@ -112,8 +114,7 @@ private: void UpdateInterceptor(); void DestroyInterceptor(); void CreateMagnificationGesture(sptr &header, sptr ¤t); - void CreatZoomGesture(); - void CreatWindowMagnificationGesture(); + void CreateZoomGesture(); void ClearMagnificationGesture(); sptr pointerEventTransmitters_ = nullptr; @@ -129,7 +130,6 @@ private: ffrt::mutex eventHandlerMutex_; sptr zoomGesture_ = nullptr; - sptr windowMagnificationGesture_ = nullptr; bool needInteractMagnification_ = false; sptr keyEventFilter_ = nullptr; }; diff --git a/services/aams/include/accessibility_settings_config.h b/services/aams/include/accessibility_settings_config.h index 26938e939..5c0bb1eb7 100644 --- a/services/aams/include/accessibility_settings_config.h +++ b/services/aams/include/accessibility_settings_config.h @@ -23,6 +23,7 @@ #include "accessibility_caption.h" #include "accessibility_datashare_helper.h" +#include "magnification_def.h" namespace OHOS { namespace Accessibility { @@ -49,6 +50,7 @@ public: RetError SetScreenMagnificationType(const uint32_t type); RetError SetScreenMagnificationMode(const uint32_t mode); RetError SetScreenMagnificationScale(const float scale); + RetError SetScreenMagnificationTriggerMethod(const int32_t triggerMethod); RetError SetShortKeyState(const bool state); RetError SetShortKeyOnLockScreenState(const bool state); RetError SetShortKeyTimeout(const int32_t time); @@ -105,6 +107,7 @@ public: uint32_t GetScreenMagnificationType() const; uint32_t GetScreenMagnificationMode() const; float GetScreenMagnificationScale() const; + int32_t GetScreenMagnificationTriggerMethod() const; bool GetFlashReminderSwitch() const; bool GetSeniorModeState() const; @@ -158,6 +161,7 @@ private: std::atomic screenMagnificationType_ = 0; std::atomic screenMagnificationMode_ = 0; std::atomic screenMagnificationScale_ = 2.0f; + std::atomic screenMagnificationTriggerMethod_ = THREE_FINGER_DOUBLE_TAP_MODE; std::atomic isCaptionState_ = false; AccessibilityConfig::CaptionProperty captionProperty_; std::atomic isMouseKeyState_ = false; diff --git a/services/aams/include/accessibility_zoom_gesture.h b/services/aams/include/accessibility_zoom_gesture.h index 041a25131..8b003fbfa 100644 --- a/services/aams/include/accessibility_zoom_gesture.h +++ b/services/aams/include/accessibility_zoom_gesture.h @@ -21,20 +21,25 @@ #include "pointer_event.h" #include "dm_common.h" #include "full_screen_magnification_manager.h" +#include "window_magnification_manager.h" #include "magnification_menu_manager.h" +#include "magnification_def.h" +#include +#include namespace OHOS { namespace Accessibility { -enum ACCESSIBILITY_ZOOM_STATE { - READY_STATE, - ZOOMIN_STATE, - SLIDING_STATE, - MENU_SLIDING_STATE, - DRAGGING_STATE -}; + +#define BIND(func) [this](MMI::PointerEvent& event) { (func(event)); } enum ACCESSIBILITY_ZOOM_GESTURE_MSG : uint32_t { MULTI_TAP_MSG, + LONG_PRESS_MSG, + WAIT_ANOTHER_FINGER_DOWN_MSG, + HOLDING_MSG, + TWO_FINGER_SLIDING_MSG, + HOT_AREA_SLIDING_MSG, + MENU_SLIDING_MSG, }; struct ZOOM_FOCUS_COORDINATE { @@ -45,6 +50,7 @@ struct ZOOM_FOCUS_COORDINATE { class AccessibilityZoomGesture : public EventTransmission { public: AccessibilityZoomGesture(std::shared_ptr fullScreenManager, + std::shared_ptr windowMagnificationManager, std::shared_ptr menuManager); ~AccessibilityZoomGesture() = default; @@ -54,10 +60,12 @@ public: void ShieldZoomGesture(bool state); void GetWindowParam(bool needRefresh = false); void StartMagnificationInteract(); + void SetGestureMode(int32_t mode); + void SetMagnificationMode(uint32_t mode); void DisableGesture(); - inline ACCESSIBILITY_ZOOM_STATE GetZoomState() + inline int32_t GetZoomState() { - return state_; + return zoomState_; } private: @@ -72,77 +80,150 @@ private: AccessibilityZoomGesture &zoomGesture_; }; - void TransferState(ACCESSIBILITY_ZOOM_STATE state); + void TransferState(int32_t state); void CacheEvents(MMI::PointerEvent &event); void SendCacheEventsToNext(); + void SendEventToMultimodal(MMI::PointerEvent event); void ClearCacheEventsAndMsg(); - void RecognizeInReadyState(MMI::PointerEvent &event); + + void InitGestureFuncMap(); + void InitSingleFingerTripleTapFuncMap(); + void InitThreeFingerDoubleTapFuncMap(); + void OnPointerEventExecute(MMI::PointerEvent &event); + void RecognizeInZoomStateDownEvent(MMI::PointerEvent &event); void RecognizeInZoomStateMoveEvent(MMI::PointerEvent &event); - void RecognizeInZoomState(MMI::PointerEvent &event); - void RecognizeInSlidingState(MMI::PointerEvent &event); - void RecognizeInMenuSlidingState(MMI::PointerEvent &event); - void RecognizeInDraggingState(MMI::PointerEvent &event); - void RecognizeScroll(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE &coordinate); - void RecognizeScale(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE &coordinate); + void RecognizeScroll(ZOOM_FOCUS_COORDINATE &coordinate); + bool RecognizeScale(MMI::PointerEvent &event); void CalcFocusCoordinate(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE &coordinate); float CalcScaleSpan(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE coordinate); bool IsTapOnInputMethod(MMI::PointerEvent &event); - bool IsDownValid(); - bool IsUpValid(); - bool IsMoveValid(); + bool IsDownValid(std::shared_ptr curEvent, std::shared_ptr lastEvent); + bool IsMoveValid(std::shared_ptr curEvent, std::shared_ptr lastEvent); bool IsLongPress(); bool IsKnuckles(MMI::PointerEvent &event); - bool IsTripleTaps(); void OnTripleTap(MMI::PointerEvent &event); - int64_t CalcIntervalTime(std::shared_ptr firstEvent, - std::shared_ptr secondEvent); - float CalcSeparationDistance(std::shared_ptr firstEvent, - std::shared_ptr secondEvent); + bool IsThreeFingerMultiTap(MMI::PointerEvent &event); + float CalcSeparationDistance(MMI::PointerEvent &event); + float CalcSeparationDistance(MMI::PointerEvent &firstEvent, MMI::PointerEvent &secondEvent); void OnZoom(int32_t centerX, int32_t centerY, bool showMenu); void OffZoom(); void OnScroll(float offsetX, float offsetY); - void OnScale(float scaleSpan); void Clear(); - void OnDrag(); - bool startScaling_ = false; - bool isLongPress_ = false; - bool isMoveValid_ = true; - float preSpan_ = 0.0f; - float lastSpan_ = 0.0f; - float screenSpan_ = 0.0f; - float lastScrollFocusX_ = 0.0f; - float lastScrollFocusY_ = 0.0f; + void DoNothingHandler(MMI::PointerEvent &event); + void HandleSTReadyInitStateDown(MMI::PointerEvent &event); + void HandleSTReadyStateUp(MMI::PointerEvent &event); + void HandleSTReadyStateMove(MMI::PointerEvent &event); + void HandleSTReadyOneFingerTapStateDown(MMI::PointerEvent &event); + + void HandleSTZoomInitStateDown(MMI::PointerEvent &event); + void HandleSTZoomOneFingerDownStateDown(MMI::PointerEvent &event); + void HandleSTZoomOneFingerDownStateUp(MMI::PointerEvent &event); + void HandleSTZoomOneFingerDownStateMove(MMI::PointerEvent &event); + void HandleSTZoomTwoFingerDownStateMove(MMI::PointerEvent &event); + void HandleSTZoomOneFingerTapStateDown(MMI::PointerEvent &event); + void HandleZoomSlidingStateDown(MMI::PointerEvent &event); + void HandleZoomSlidingStateMove(MMI::PointerEvent &event); + void HandleZoomSlidingStateUp(MMI::PointerEvent &event); + + void HandleTDReadyInitStateDown(MMI::PointerEvent &event); + void HandleTDReadyOneFingerDownStateDown(MMI::PointerEvent &event); + void HandleTDReadyOneFingerDownStateMove(MMI::PointerEvent &event); + void HandleTDReadyTwoFingersDownStateDown(MMI::PointerEvent &event); + void HandleTDReadyTwoFingersDownStateMove(MMI::PointerEvent &event); + void HandleTDReadyThreeFingersDownStateUp(MMI::PointerEvent &event); + void HandleTDReadyThreeFingersDownStateMove(MMI::PointerEvent &event); + void HandleTDReadyThreeFingersTapStateDown(MMI::PointerEvent &event); + void HandleTDReadyThreeFingersTapStateMove(MMI::PointerEvent &event); + void HandleTDReadyThreeFingersContinueDownStateDown(MMI::PointerEvent &event); + void HandleTDReadyThreeFingersContinueDownStateUp(MMI::PointerEvent &event); + void HandleTDReadyThreeFingersContinueDownStateMove(MMI::PointerEvent &event); + void HandleHoldStateDown(MMI::PointerEvent &event); + void HandleHoldStateUp(MMI::PointerEvent &event); + void HandleHoldStateMove(MMI::PointerEvent &event); + void HandleMenuSlidingStateMove(MMI::PointerEvent &event); + void HandleMenuSlidingStateUp(MMI::PointerEvent &event); + void HandleHotAreaSlidingStateMove(MMI::PointerEvent &event); + void HandleHotAreaSlidingStateUp(MMI::PointerEvent &event); + + void HandleTDZoomInitStateDown(MMI::PointerEvent &event); + void HandleTDZoomOneFingerDownStateDown(MMI::PointerEvent &event); + void HandleTDZoomOneFingerDownStateMove(MMI::PointerEvent &event); + void HandleTDZoomOneFingerDownStateUp(MMI::PointerEvent &event); + void HandleTDZoomTwoFingersDownStateDown(MMI::PointerEvent &event); + void HandleTDZoomTwoFingersDownStateMove(MMI::PointerEvent &event); + void HandleTDZoomThreeFingersDownStateUp(MMI::PointerEvent &event); + void HandleTDZoomThreeFingersDownStateMove(MMI::PointerEvent &event); + void HandleTDZoomThreeFingersTapStateDown(MMI::PointerEvent &event); + void HandleTDZoomThreeFingersTapStateMove(MMI::PointerEvent &event); + void HandleTDZoomThreeFingersContinueDownStateUp(MMI::PointerEvent &event); + void HandleTDZoomThreeFingersContinueDownStateMove(MMI::PointerEvent &event); + float tapDistance_ = 0.0f; float multiTapDistance_ = 0.0f; - float scale_ = DEFAULT_SCALE; - bool isScale_ = false; + float baseDistance_ = 0.0f; + float lastDistance_ = 0.0f; uint64_t screenId_ = -1; uint32_t screenWidth_ = 0; uint32_t screenHeight_ = 0; - int32_t centerX_ = 0; - int32_t centerY_ = 0; - int32_t downPid_ = -1; - ACCESSIBILITY_ZOOM_STATE state_ = READY_STATE; + uint32_t gestureType_ = 0; + int32_t zoomState_ = READY; + int32_t zoomGestureState_ = INIT; + int32_t gestureMode_ = THREE_FINGER_DOUBLE_TAP_MODE; + uint32_t magnificationMode_ = FULL_SCREEN_MAGNIFICATION; + bool isTapOnMenu_ = false; + bool isTapOnWindowHotArea_ = false; + bool isTapOnWindow_ = false; + bool hasScaled_ = false; OHOS::Rosen::DisplayOrientation orientation_ = OHOS::Rosen::DisplayOrientation::UNKNOWN; - std::shared_ptr preLastDownEvent_ = nullptr; + ZOOM_FOCUS_COORDINATE lastCenter = {0.0f, 0.0f}; std::shared_ptr lastDownEvent_ = nullptr; - std::shared_ptr preLastUpEvent_ = nullptr; - std::shared_ptr lastUpEvent_ = nullptr; - std::shared_ptr currentMoveEvent_ = nullptr; - std::shared_ptr longPressDownEvent_ = nullptr; - std::shared_ptr lastSlidingEvent_ = nullptr; + std::shared_ptr lastTripleTapEvents_[3] = {nullptr, nullptr, nullptr}; std::shared_ptr zoomGestureEventHandler_ = nullptr; std::vector> cacheEvents_; std::shared_ptr fullScreenManager_ = nullptr; + std::shared_ptr windowMagnificationManager_ = nullptr; std::shared_ptr menuManager_ = nullptr; - + std::atomic shieldZoomGestureFlag_ = false; - bool isTapOnMenu_ = false; - uint32_t gestureType_ = 0; - bool isTripleDown_ = false; + int32_t singleFingerTapCount_ = 0; + + static constexpr int32_t POINTER_ID_0 = 0; + static constexpr int32_t POINTER_ID_1 = 1; + static constexpr int32_t POINTER_ID_2 = 2; + + static constexpr int32_t POINTER_COUNT_1 = 1; + static constexpr int32_t POINTER_COUNT_2 = 2; + static constexpr int32_t POINTER_COUNT_3 = 3; + + static constexpr int32_t READY = 0; + static constexpr int32_t ZOOM = 1; + + static constexpr int32_t PASSING_THROUGH = -2; + static constexpr int32_t INVALID = -1; + static constexpr int32_t INIT = 0; + static constexpr int32_t ONE_FINGER_DOWN = 1; + static constexpr int32_t ONE_FINGER_TAP = 2; + static constexpr int32_t ONE_FINGER_TAP_THEN_DOWN = 3; + static constexpr int32_t HOLD = 4; + static constexpr int32_t TWO_FINGER_DOWN = 5; + static constexpr int32_t THREE_FINGER_DOWN = 6; + static constexpr int32_t THREE_FINGER_TAP = 7; + static constexpr int32_t THREE_FINGER_TAP_THEN_DOWN = 8; + static constexpr int32_t SLIDING = 9; + static constexpr int32_t HOT_AREA_SLIDING = 10; + static constexpr int32_t MENU_SLIDING = 11; + + static constexpr int32_t GESTURE_MODE_COUNT = 2; + static constexpr int32_t MAGNIFICATION_STATE_COUNT = 2; + static constexpr int32_t GESTURE_STATE_COUNT = 12; + static constexpr int32_t POINTER_ACTION_MAX = 5; + + using GestureEventFunc = std::function; + GestureEventFunc handlerFuncMap_ + [GESTURE_MODE_COUNT][MAGNIFICATION_STATE_COUNT][GESTURE_STATE_COUNT][POINTER_ACTION_MAX] = {}; }; } // namespace Accessibility } // namespace OHOS diff --git a/services/aams/include/accessible_ability_manager_service.h b/services/aams/include/accessible_ability_manager_service.h index 837f7af04..1e0031200 100644 --- a/services/aams/include/accessible_ability_manager_service.h +++ b/services/aams/include/accessible_ability_manager_service.h @@ -277,6 +277,7 @@ public: bool GetMagnificationState(); uint32_t GetMagnificationType(); uint32_t GetMagnificationMode(); + int32_t GetMagnificationTriggerMethod(); void SetMagnificationMode(int32_t mode); float GetMagnificationScale(); void SetMagnificationScale(float scale); @@ -368,6 +369,8 @@ private: void RegisterScreenMagnificationState(); void OnScreenMagnificationTypeChanged(); void SetConfigScreenMagnificationScale(float scale); + void OnScreenMagnificationTriggerMethodChanged(); + void SetConfigScreenMagnificationTriggerMethod(int32_t triggerMethod); void OnScreenMagnificationScaleChanged(); void RegisterScreenMagnificationType(); void OnFlashReminderSwitchChanged(); diff --git a/services/aams/include/accessible_extend_manager_service_proxy.h b/services/aams/include/accessible_extend_manager_service_proxy.h index 19eb54445..c516c2e3d 100644 --- a/services/aams/include/accessible_extend_manager_service_proxy.h +++ b/services/aams/include/accessible_extend_manager_service_proxy.h @@ -53,6 +53,7 @@ enum class ExtMethod : int32_t { GET_CLICK_POSITION, FOLLOW_FOCUSE_ELEMENT, ON_SCREEN_MAGNIFICATION_TYPE_CHANGED, + ON_SCREEN_MAGNIFICATION_TRIGGER_METHOD_CHANGE, ON_SCREEN_MAGNIFICATION_STATE_CHANGED, OFF_ZOOM_GESTURE, SET_MAGNIFICATION_STATE @@ -83,6 +84,7 @@ public: void TransitionAnimationsCancelNotification(); int32_t TransitionAnimationsRegisterTimers(uint64_t beginTime); void TransitionAnimationsDestroyTimers(); + void OnScreenMagnificationTriggerMethodChanged(int32_t screenMagnificationTriggerMethod); void OnScreenMagnificationTypeChanged(uint32_t screenMagnificationType); void OnScreenMagnificationStateChanged(); void UnregisterDisplayListener(); @@ -103,6 +105,7 @@ public: bool SetSendPointerEventForHoverCallback(); bool SetGetDelayTimeCallback(); bool SetGetMagnificationStateCallback(); + bool ExtendGetMagnificationTriggerMethodCallback(); bool ExtendGetMagnificationModeCallback(); bool ExtendGetMagnificationScaleCallback(); bool ExtendUpdateInputFilterCallback(); diff --git a/services/aams/include/magnification_def.h b/services/aams/include/magnification_def.h index 77bc1aba4..5255c312e 100644 --- a/services/aams/include/magnification_def.h +++ b/services/aams/include/magnification_def.h @@ -63,6 +63,8 @@ constexpr uint32_t WINDOW_MAGNIFICATION = 2; constexpr uint32_t SWITCH_MAGNIFICATION = 3; constexpr uint32_t INPUT_METHOD_WINDOW_TYPE = 2105; constexpr uint32_t ORANGE_COLOR = 0xFFFFA500; +constexpr int32_t SINGLE_FINGER_TRIPLE_TAP_MODE = 0; +constexpr int32_t THREE_FINGER_DOUBLE_TAP_MODE = 1; constexpr uint32_t INVALID_GESTURE_TYPE = 0; constexpr uint32_t LEFT_BACK_GESTURE = 1; // Swipe from the left side of the screen inward diff --git a/services/aams/src/accessibility_account_data.cpp b/services/aams/src/accessibility_account_data.cpp index fffe91a6d..f59947c65 100644 --- a/services/aams/src/accessibility_account_data.cpp +++ b/services/aams/src/accessibility_account_data.cpp @@ -91,8 +91,6 @@ namespace { // Feature flag for window magnification. static constexpr uint32_t FEATURE_WINDOW_MAGNIFICATION = 0x00000100; - - static constexpr uint32_t WINDOW_MAGNIFICATION = 2; } // namespace AccessibilityAccountData::AccessibilityAccountData(int32_t accountId) diff --git a/services/aams/src/accessibility_element_operator_manager.cpp b/services/aams/src/accessibility_element_operator_manager.cpp index 9857fd7c9..51a85c72f 100644 --- a/services/aams/src/accessibility_element_operator_manager.cpp +++ b/services/aams/src/accessibility_element_operator_manager.cpp @@ -28,7 +28,6 @@ namespace OHOS { namespace Accessibility { namespace { constexpr int32_t SINGLE_TREE_ID = 0; - constexpr int32_t DIVISOR_TWO = 2; constexpr int64_t ELEMENT_ID_INVALID = -1; constexpr int32_t WINDOW_ID_INVALID = -1; constexpr uint32_t TIME_OUT_OPERATOR = 5000; diff --git a/services/aams/src/accessibility_settings_config.cpp b/services/aams/src/accessibility_settings_config.cpp index fa37b0f60..16e71cb5a 100644 --- a/services/aams/src/accessibility_settings_config.cpp +++ b/services/aams/src/accessibility_settings_config.cpp @@ -41,6 +41,7 @@ namespace { const char* SCREEN_MAGNIFICATION_TYPE = "accessibility_magnification_capability"; const char* SCREEN_MAGNIFICATION_MODE = "accessibility_magnification_mode"; const char* SCREEN_MAGNIFICATION_SCALE = "accessibility_display_magnification_scale"; + const char* SCREEN_MAGNIFICATION_TRIGGER_METHOD = "accessibility_display_magnification_trigger_method"; const char* MOUSEKEY = "mousekey"; const char* HIGH_CONTRAST_TEXT_KEY = "high_text_contrast_enabled"; const char* DALTONIZATION_STATE = "accessibility_display_daltonizer_enabled"; @@ -201,13 +202,11 @@ RetError AccessibilitySettingsConfig::SetScreenMagnificationState(const bool sta { HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); auto ret = SetConfigState(SCREEN_MAGNIFICATION_KEY, state); - // LCOV_EXCL_BR_START if (ret != RET_OK) { Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetScreenMagnificationState"); HILOG_ERROR("set SetScreenMagnificationState failed"); return ret; } - // LCOV_EXCL_BR_STOP SetMagnificationState(state); return ret; } @@ -246,6 +245,14 @@ RetError AccessibilitySettingsConfig::SetScreenMagnificationMode(const uint32_t return RET_OK; } + +RetError AccessibilitySettingsConfig::SetScreenMagnificationTriggerMethod(const int32_t triggerMethod) +{ + HILOG_DEBUG("screenMagnificationTriggerMethod = [%{public}d]", triggerMethod); + screenMagnificationTriggerMethod_.store(triggerMethod); + return RET_OK; +} + RetError AccessibilitySettingsConfig::SetScreenMagnificationScale(const float scale) { HILOG_DEBUG("screenMagnificationScale = [%{public}f]", scale); @@ -257,13 +264,11 @@ RetError AccessibilitySettingsConfig::SetShortKeyState(const bool state) { HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); auto ret = SetConfigState(SHORTCUT_ENABLED, state); - // LCOV_EXCL_BR_START if (ret != RET_OK) { Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetShortKeyState"); HILOG_ERROR("set isShortKeyState_ failed"); return ret; } - // LCOV_EXCL_BR_STOP isShortKeyState_.store(state); return ret; } @@ -318,13 +323,11 @@ RetError AccessibilitySettingsConfig::SetMouseKeyState(const bool state) { HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); auto ret = SetConfigState(MOUSEKEY, state); - // LCOV_EXCL_BR_START if (ret != RET_OK) { Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetMouseKeyState"); HILOG_ERROR("set isMouseKeyState_ failed"); return ret; } - // LCOV_EXCL_BR_STOP isMouseKeyState_.store(state); return ret; } @@ -356,13 +359,11 @@ RetError AccessibilitySettingsConfig::SetShortkeyTarget(const std::string &name) } auto ret = datashare_->PutStringValue("ShortkeyTarget", name); - // LCOV_EXCL_BR_START if (ret != RET_OK) { Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetShortkeyTarget"); HILOG_ERROR("set shortkeyTarget_ failed"); return ret; } - // LCOV_EXCL_BR_STOP shortkeyTarget_ = name; return ret; } @@ -889,6 +890,11 @@ float AccessibilitySettingsConfig::GetScreenMagnificationScale() const return screenMagnificationScale_.load(); } +int32_t AccessibilitySettingsConfig::GetScreenMagnificationTriggerMethod() const +{ + return screenMagnificationTriggerMethod_.load(); +} + bool AccessibilitySettingsConfig::GetIgnoreRepeatClickState() const { return ignoreRepeatClickState_.load(); @@ -1148,7 +1154,6 @@ void AccessibilitySettingsConfig::InitAnimationOffConfig() } } -// LCOV_EXCL_START void AccessibilitySettingsConfig::HandleIgnoreRepeatClickState() { int64_t recoveryDate = datashare_->GetLongValue(RECOVERY_IGNORE_REPEAT_CLICK_DATE, 0); @@ -1233,6 +1238,8 @@ void AccessibilitySettingsConfig::InitSetting() datashare_->GetIntValue(SCREEN_MAGNIFICATION_MODE, FULL_SCREEN_MAGNIFICATION))); screenMagnificationScale_.store(static_cast( datashare_->GetFloatValue(SCREEN_MAGNIFICATION_SCALE, DEFAULT_MAGNIFICATION_SCALE))); + screenMagnificationTriggerMethod_.store(static_cast( + datashare_->GetFloatValue(SCREEN_MAGNIFICATION_TRIGGER_METHOD, THREE_FINGER_DOUBLE_TAP_MODE))); clickResponseTime_.store(static_cast(datashare_->GetIntValue(CLICK_RESPONCE_TIME, 0))); SetClickResponseTime(clickResponseTime_.load()); ignoreRepeatClickTime_.store(static_cast(datashare_->GetIntValue(IGNORE_REPEAT_CLICK_TIME, 0))); @@ -1517,7 +1524,6 @@ void AccessibilitySettingsConfig::recoverAudioAdjustment() SetAudioBalance(audioBalance_.load()); } } -// LCOV_EXCL_STOP void AccessibilitySettingsConfig::OnDataClone() { @@ -1543,7 +1549,6 @@ void AccessibilitySettingsConfig::OnDataClone() } else { SetShortKeyOnLockScreenState(false); } - if (isShortkeyEnabled != GetShortKeyState()) { SetShortKeyState(isShortkeyEnabled); diff --git a/services/aams/src/accessible_ability_manager_service.cpp b/services/aams/src/accessible_ability_manager_service.cpp index 619957008..331083724 100644 --- a/services/aams/src/accessible_ability_manager_service.cpp +++ b/services/aams/src/accessible_ability_manager_service.cpp @@ -84,6 +84,7 @@ namespace { const char* SCREEN_MAGNIFICATION_MODE = "accessibility_magnification_mode"; const char* ELDER_CARE_ENABLED_KEY = "accessibility_elder_care_switch_enabled"; const char* SCREEN_MAGNIFICATION_SCALE = "accessibility_display_magnification_scale"; + const char* SCREEN_MAGNIFICATION_TRIGGER_METHOD = "accessibility_display_magnification_trigger_method"; const char* MAGNIFICATION_PARAM = "const.accessibility.magnification"; const char* VOICE_RECOGNITION_KEY = "accessibility_sound_recognition_switch"; const char* VOICE_RECOGNITION_TYPES = "accessibility_sound_recognition_enabled"; @@ -3019,6 +3020,43 @@ void AccessibleAbilityManagerService::OnScreenMagnificationScaleChanged() SetConfigScreenMagnificationScale(screenMagnificationScale); } +void AccessibleAbilityManagerService::SetConfigScreenMagnificationTriggerMethod(int32_t triggerMethod) +{ + HILOG_DEBUG(); + + sptr accountData = GetCurrentAccountData(); + if (accountData == nullptr) { + HILOG_ERROR("accountData is nullptr"); + return; + } + + std::shared_ptr config = accountData->GetConfig(); + if (config == nullptr) { + HILOG_ERROR("config is nullptr"); + return; + } + config->SetScreenMagnificationTriggerMethod(triggerMethod); +} + +void AccessibleAbilityManagerService::OnScreenMagnificationTriggerMethodChanged() +{ + HILOG_INFO(); + + shared_ptr helper = GetCurrentAcountDatashareHelper(); + if (helper == nullptr) { + HILOG_ERROR("datashareHelper is nullptr"); + return; + } + int32_t screenMagnificationTriggerMethod = helper->GetIntValue(SCREEN_MAGNIFICATION_TRIGGER_METHOD, + THREE_FINGER_DOUBLE_TAP_MODE); + + SetConfigScreenMagnificationTriggerMethod(screenMagnificationTriggerMethod); + if (Singleton::GetInstance().LoadExtProxy()) { + Singleton::GetInstance(). + OnScreenMagnificationTriggerMethodChanged(screenMagnificationTriggerMethod); + } +} + void AccessibleAbilityManagerService::RegisterScreenMagnificationState() { HILOG_DEBUG(); @@ -3040,9 +3078,14 @@ void AccessibleAbilityManagerService::RegisterScreenMagnificationState() AccessibilitySettingObserver::UpdateFunc scaleFunc = [ = ](const std::string &state) { Singleton::GetInstance().OnScreenMagnificationScaleChanged(); }; + AccessibilitySettingObserver::UpdateFunc triggerMethodFunc = [ = ](const std::string &state) { + Singleton::GetInstance().OnScreenMagnificationTriggerMethodChanged(); + }; if (accountData->GetConfig()->GetDbHandle()) { accountData->GetConfig()->GetDbHandle()->RegisterObserver(SCREEN_MAGNIFICATION_KEY, func); accountData->GetConfig()->GetDbHandle()->RegisterObserver(SCREEN_MAGNIFICATION_SCALE, scaleFunc); + accountData->GetConfig()->GetDbHandle()->RegisterObserver(SCREEN_MAGNIFICATION_TRIGGER_METHOD, + triggerMethodFunc); } }, "REGISTER_SCREEN_ZOOM_OBSERVER"); } @@ -3473,6 +3516,23 @@ uint32_t AccessibleAbilityManagerService::GetMagnificationMode() return config->GetScreenMagnificationMode(); } +int32_t AccessibleAbilityManagerService::GetMagnificationTriggerMethod() +{ + HILOG_DEBUG(); + sptr accountData = GetCurrentAccountData(); + if (accountData == nullptr) { + HILOG_ERROR("accountData is nullptr"); + return 0; + } + + std::shared_ptr config = accountData->GetConfig(); + if (config == nullptr) { + HILOG_ERROR("config is nullptr"); + return 0; + } + return config->GetScreenMagnificationTriggerMethod(); +} + void AccessibleAbilityManagerService::SetMagnificationMode(int32_t mode) { HILOG_DEBUG(); diff --git a/services/aams/src/accessible_extend_manager_service_proxy.cpp b/services/aams/src/accessible_extend_manager_service_proxy.cpp index ad4bb4a84..7e31d285b 100644 --- a/services/aams/src/accessible_extend_manager_service_proxy.cpp +++ b/services/aams/src/accessible_extend_manager_service_proxy.cpp @@ -78,6 +78,7 @@ bool ExtendManagerServiceProxy::LoadExtProxy() SetSendPointerEventForHoverCallback(); SetGetDelayTimeCallback(); SetGetMagnificationStateCallback(); + ExtendGetMagnificationTriggerMethodCallback(); ExtendGetMagnificationModeCallback(); ExtendGetMagnificationScaleCallback(); ExtendUpdateInputFilterCallback(); @@ -768,6 +769,27 @@ void ExtendManagerServiceProxy::TransitionAnimationsDestroyTimers() return func(); } +void ExtendManagerServiceProxy::OnScreenMagnificationTriggerMethodChanged(int32_t screenMagnificationTriggerMethod) +{ + using OnScreenMagnificationTriggerMethodChanged = void(*)(int32_t screenMagnificationTriggerMethod); + static OnScreenMagnificationTriggerMethodChanged func; + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + if (!func || readyFunc_.find(ExtMethod::ON_SCREEN_MAGNIFICATION_TRIGGER_METHOD_CHANGE) == readyFunc_.end()) { + func = (OnScreenMagnificationTriggerMethodChanged)GetFunc("OnScreenMagnificationTriggerMethodChanged"); + if (func) { + readyFunc_.insert(ExtMethod::ON_SCREEN_MAGNIFICATION_TRIGGER_METHOD_CHANGE); + return func(screenMagnificationTriggerMethod); + } else { + HILOG_ERROR("get OnScreenMagnificationTriggerMethodChanged func failed"); + return; + } + } + return func(screenMagnificationTriggerMethod); +} + void ExtendManagerServiceProxy::OnScreenMagnificationTypeChanged(uint32_t screenMagnificationType) { using OnScreenMagnificationTypeChanged = void(*)(uint32_t screenMagnificationType); @@ -864,6 +886,24 @@ bool ExtendManagerServiceProxy::CheckExtProxyStatus() return true; } +static int32_t GetMagnificationTriggerMethodCallback() +{ + return Singleton::GetInstance().GetMagnificationTriggerMethod(); +} + +bool ExtendManagerServiceProxy::ExtendGetMagnificationTriggerMethodCallback() +{ + using GetMagnificationTriggerMethod = int32_t(*)(); + using SetCallback = void(*)(GetMagnificationTriggerMethod cb); + SetCallback setCallbackFun = (SetCallback)GetFunc("ExtendGetMagnificationTriggerMethodCallback"); + if (!setCallbackFun) { + HILOG_ERROR("setCallbackFun is null"); + return false; + } + setCallbackFun(GetMagnificationTriggerMethodCallback); + return true; +} + static uint32_t GetMagnificationModeCallback() { return Singleton::GetInstance().GetMagnificationMode(); diff --git a/services/aams/test/mock/include/mock_accessibility_input_interceptor.h b/services/aams/test/mock/include/mock_accessibility_input_interceptor.h index 25d5b9968..8bfe6c26a 100644 --- a/services/aams/test/mock/include/mock_accessibility_input_interceptor.h +++ b/services/aams/test/mock/include/mock_accessibility_input_interceptor.h @@ -39,6 +39,8 @@ public: MOCK_METHOD1(OnKeyEvent, void(MMI::KeyEvent& event)); MOCK_METHOD1(OnPointerEvent, void(MMI::PointerEvent& event)); MOCK_METHOD1(SetAvailableFunctions, void(uint32_t availableFunctions)); + MOCK_METHOD1(SetMagnificationMode, void(uint32_t mode)); + MOCK_METHOD1(SetMagnificationTriggerMethod, void(int32_t screenMagnificationTriggerMethod)); }; } // namespace Accessibility } // namespace OHOS diff --git a/services/aams/test/mock/include/mock_accessibility_zoom_gesture.h b/services/aams/test/mock/include/mock_accessibility_zoom_gesture.h index 136522ade..73c800e7c 100644 --- a/services/aams/test/mock/include/mock_accessibility_zoom_gesture.h +++ b/services/aams/test/mock/include/mock_accessibility_zoom_gesture.h @@ -18,12 +18,16 @@ #include #include "accessibility_zoom_gesture.h" +#include "window_magnification_manager.h" namespace OHOS { namespace Accessibility { class MockAccessibilityZoomGesture : public AccessibilityZoomGesture { public: - MockAccessibilityZoomGesture(); + MockAccessibilityZoomGesture( + std::shared_ptr fullScreenManager = nullptr, + std::shared_ptr windowMagnificationManager = nullptr, + std::shared_ptr menuManager = nullptr); ~MockAccessibilityZoomGesture(); MOCK_METHOD1(Triple, bool(MMI::PointerEvent& event)); diff --git a/services/aams/test/mock/src/mock_accessibility_input_interceptor.cpp b/services/aams/test/mock/src/mock_accessibility_input_interceptor.cpp index 42cc8b050..7f6a4ce72 100644 --- a/services/aams/test/mock/src/mock_accessibility_input_interceptor.cpp +++ b/services/aams/test/mock/src/mock_accessibility_input_interceptor.cpp @@ -136,5 +136,15 @@ void AccessibilityInputInterceptor::EnableGesture(uint32_t mode) { (void)mode; } + +void AccessibilityInputInterceptor::SetMagnificationMode(uint32_t mode) +{ + (void)mode; +} + +void AccessibilityInputInterceptor::SetMagnificationTriggerMethod(int32_t screenMagnificationTriggerMethod) +{ + (void)screenMagnificationTriggerMethod; +} } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/services/aams/test/mock/src/mock_accessibility_settings_config.cpp b/services/aams/test/mock/src/mock_accessibility_settings_config.cpp index 347533ee0..3a1378b3d 100644 --- a/services/aams/test/mock/src/mock_accessibility_settings_config.cpp +++ b/services/aams/test/mock/src/mock_accessibility_settings_config.cpp @@ -108,6 +108,13 @@ RetError AccessibilitySettingsConfig::SetScreenMagnificationScale(const float sc return RET_OK; } +RetError AccessibilitySettingsConfig::SetScreenMagnificationTriggerMethod(const int32_t triggerMethod) +{ + HILOG_DEBUG("start."); + screenMagnificationTriggerMethod_ = triggerMethod; + return RET_OK; +} + RetError AccessibilitySettingsConfig::SetShortKeyState(const bool state) { HILOG_DEBUG("start."); @@ -287,6 +294,12 @@ float AccessibilitySettingsConfig::GetScreenMagnificationScale() const return screenMagnificationScale_; } +int32_t AccessibilitySettingsConfig::GetScreenMagnificationTriggerMethod() const +{ + HILOG_DEBUG("start."); + return screenMagnificationTriggerMethod_; +} + bool AccessibilitySettingsConfig::GetShortKeyState() const { HILOG_DEBUG("start."); diff --git a/services/aams/test/mock/src/mock_accessibility_zoom_gesture.cpp b/services/aams/test/mock/src/mock_accessibility_zoom_gesture.cpp new file mode 100644 index 000000000..d3b2bbd64 --- /dev/null +++ b/services/aams/test/mock/src/mock_accessibility_zoom_gesture.cpp @@ -0,0 +1,32 @@ +/* + * 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. + */ + +#include "mock_accessibility_zoom_gesture.h" + +namespace OHOS { +namespace Accessibility { +MockAccessibilityZoomGesture::MockAccessibilityZoomGesture( + std::shared_ptr fullScreenManager, + std::shared_ptr windowMagnificationManager, + std::shared_ptr menuManager) + : AccessibilityZoomGesture(fullScreenManager, windowMagnificationManager, menuManager) +{ +} + +MockAccessibilityZoomGesture::~MockAccessibilityZoomGesture() +{ +} +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp b/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp index 80a80199e..0bc9d302d 100644 --- a/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp +++ b/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp @@ -683,6 +683,11 @@ uint32_t AccessibleAbilityManagerService::GetMagnificationMode() return FULL_SCREEN_MAGNIFICATION; } +int32_t AccessibleAbilityManagerService::GetMagnificationTriggerMethod() +{ + return THREE_FINGER_DOUBLE_TAP_MODE; +} + void AccessibleAbilityManagerService::SetMagnificationMode(int32_t mode) { (void)mode; diff --git a/services/aams_ext/include/extend_service_manager.h b/services/aams_ext/include/extend_service_manager.h index f89cdfcd3..fbc2180c7 100644 --- a/services/aams_ext/include/extend_service_manager.h +++ b/services/aams_ext/include/extend_service_manager.h @@ -43,6 +43,7 @@ using SendPointerEventForHoverCallback = void (*)( using GetDelayTime = int64_t(*)(); using GetMagnificationState = bool(*)(); using GetMagnificationModeCallback = uint32_t(*)(); // get +using GetMagnificationTriggerMethodCallback = int32_t(*)(); using GetMagnificationScaleCallback = float(*)(); // get using UpdateInputFilterCallback = void(*)(); using MagnificationModeCallback = void(*)(int32_t mode); // set @@ -91,6 +92,7 @@ public: RetError SetMouseAutoClick(int32_t time); void SetServiceOnKeyEventResult(int32_t connectionId, bool isHandled, uint32_t sequenceNum); + void OnScreenMagnificationTriggerMethodChanged(int32_t screenMagnificationTriggerMethod); void OnScreenMagnificationTypeChanged(uint32_t screenMagnificationType); void OnScreenMagnificationStateChanged(); void UnregisterDisplayListener(); @@ -103,6 +105,7 @@ public: bool CheckDisplayId(uint64_t displayId); GetMagnificationModeCallback getMagnificationModeCallback = nullptr; + GetMagnificationTriggerMethodCallback getMagnificationTriggerMethodCallback = nullptr; GetMagnificationScaleCallback getMagnificationScaleCallback = nullptr; UpdateInputFilterCallback updateInputFilterCallback = nullptr; MagnificationModeCallback magnificationModeCallback = nullptr; diff --git a/services/aams_ext/include/magnification_window.h b/services/aams_ext/include/magnification_window.h index 5a463e422..b6c567716 100644 --- a/services/aams_ext/include/magnification_window.h +++ b/services/aams_ext/include/magnification_window.h @@ -38,7 +38,7 @@ public: static MagnificationWindow &GetInstance(); void EnableMagnification(uint32_t magnificationType, int32_t posX, int32_t posY); void DisableMagnification(uint32_t magnificationType, bool needClear); - void SetScale(uint32_t magnificationType, float scaleSpan); + void SetScale(uint32_t magnificationType, float ratio); void MoveMagnification(uint32_t magnificationType, int32_t deltaX, int32_t deltaY); PointerPos ConvertGesture(uint32_t type, PointerPos coordinates); PointerPos ConvertCoordinates(int32_t posX, int32_t posY); @@ -68,7 +68,7 @@ private: // full magnification void EnableMagnificationFull(int32_t centerX, int32_t centerY); void DisableMagnificationFull(bool needClear = false); - void SetScaleFull(float scaleSpan); + void SetScaleFull(float ratio); void MoveMagnificationFull(int32_t deltaX, int32_t deltaY); void FollowFocuseElementFull(int32_t centerX, int32_t centerY); @@ -79,7 +79,7 @@ private: // window magnification void EnableMagnificationPart(int32_t centerX, int32_t centerY); void DisableMagnificationPart(bool needClear = false); - void SetScalePart(float scaleSpan); + void SetScalePart(float ratio); void MoveMagnificationPart(int32_t deltaX, int32_t deltaY); void FollowFocuseElementPart(int32_t centerX, int32_t centerY); void ShowMagnificationPart(); diff --git a/services/aams_ext/src/accessibility_input_interceptor.cpp b/services/aams_ext/src/accessibility_input_interceptor.cpp index a40ef0d1c..83c503c4d 100644 --- a/services/aams_ext/src/accessibility_input_interceptor.cpp +++ b/services/aams_ext/src/accessibility_input_interceptor.cpp @@ -250,34 +250,27 @@ RetError AccessibilityInputInterceptor::InjectEvents(const std::shared_ptrSetGestureMode(screenMagnificationTriggerMethod); +} + void AccessibilityInputInterceptor::CreateMagnificationGesture(sptr &header, sptr ¤t) { - HILOG_INFO("CreatWindowMagnificationGesture start"); - + HILOG_INFO("CreateMagnificationGesture start"); + Singleton::GetInstance().InitMagnification(); - uint32_t magnificationMode = Singleton::GetInstance().getMagnificationModeCallback(); - if (magnificationMode == FULL_SCREEN_MAGNIFICATION) { - HILOG_INFO("create zoomGesture"); - CreatZoomGesture(); - if (zoomGesture_ == nullptr) { - HILOG_ERROR("zoomGesture create error."); - return; - } - SetNextEventTransmitter(header, current, zoomGesture_); - } else if (magnificationMode == WINDOW_MAGNIFICATION) { - HILOG_INFO("create windowMagnificationGesture"); - CreatWindowMagnificationGesture(); - if (windowMagnificationGesture_ == nullptr) { - HILOG_ERROR("windowMagnificationGesture create error."); - return; - } - SetNextEventTransmitter(header, current, windowMagnificationGesture_); - } else { - HILOG_WARN("invalid magnificationMode"); - ClearMagnificationGesture(); + CreateZoomGesture(); + if (zoomGesture_ == nullptr) { + HILOG_ERROR("zoomGesture create error."); + return; } + SetNextEventTransmitter(header, current, zoomGesture_); #ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER if (ExtUtils::IsWideFold() || ExtUtils::IsSmallFold()) { AccessibilityDisplayManager &displayMgr = Singleton::GetInstance(); @@ -288,12 +281,18 @@ void AccessibilityInputInterceptor::CreateMagnificationGesture(sptr windowMagnificationManager = + Singleton::GetInstance().GetWindowMagnificationManager(); std::shared_ptr fullScreenMagnificationManager = Singleton::GetInstance().GetFullScreenMagnificationManager(); std::shared_ptr menuManager = Singleton::GetInstance().GetMenuManager(); + if (windowMagnificationManager == nullptr) { + HILOG_ERROR("get windowMagnification manager failed."); + return; + } if (fullScreenMagnificationManager == nullptr) { HILOG_ERROR("get fullScreenMagnification manager failed."); return; @@ -304,7 +303,8 @@ void AccessibilityInputInterceptor::CreatZoomGesture() } if (zoomGesture_ == nullptr) { sptr zoomGesture = - new(std::nothrow) AccessibilityZoomGesture(fullScreenMagnificationManager, menuManager); + new(std::nothrow) AccessibilityZoomGesture(fullScreenMagnificationManager, + windowMagnificationManager, menuManager); if (zoomGesture == nullptr) { HILOG_ERROR("zoomGesture create error."); return; @@ -318,40 +318,10 @@ void AccessibilityInputInterceptor::CreatZoomGesture() } } -void AccessibilityInputInterceptor::CreatWindowMagnificationGesture() -{ - std::shared_ptr windowMagnificationManager = - Singleton::GetInstance().GetWindowMagnificationManager(); - std::shared_ptr menuManager = - Singleton::GetInstance().GetMenuManager(); - if (windowMagnificationManager == nullptr) { - HILOG_ERROR("get windowMagnification manager failed."); - return; - } - if (menuManager == nullptr) { - HILOG_ERROR("get menu manager failed."); - return; - } - if (windowMagnificationGesture_ == nullptr) { - sptr windowMagnificationGesture = - new(std::nothrow) WindowMagnificationGesture(windowMagnificationManager, menuManager); - if (windowMagnificationGesture == nullptr) { - HILOG_ERROR("windowMagnificationGesture create error."); - return; - } - windowMagnificationGesture_ = windowMagnificationGesture; - } - if (needInteractMagnification_) { - windowMagnificationGesture_->StartMagnificationInteract(); - needInteractMagnification_ = false; - } -} -// LCOV_EXCL_STOP void AccessibilityInputInterceptor::ClearMagnificationGesture() { zoomGesture_ = nullptr; - windowMagnificationGesture_ = nullptr; } void AccessibilityInputInterceptor::CreateKeyEventTransmitters() @@ -436,7 +406,6 @@ void AccessibilityInputInterceptor::DestroyTransmitters() Singleton::GetInstance().SetTouchEventInjector(nullptr); pointerEventTransmitters_= nullptr; zoomGesture_ = nullptr; - windowMagnificationGesture_ = nullptr; } if (keyEventTransmitters_ != nullptr) { keyEventTransmitters_->DestroyEvents(); @@ -498,16 +467,12 @@ void AccessibilityInputInterceptor::SetNextEventTransmitter(sptrShieldZoomGesture(flag); } - if (windowMagnificationGesture_) { - windowMagnificationGesture_->ShieldZoomGesture(flag); - } } void AccessibilityInputInterceptor::RefreshDisplayInfo() @@ -527,24 +492,24 @@ void AccessibilityInputInterceptor::StartMagnificationInteract(uint32_t mode) void AccessibilityInputInterceptor::DisableGesture(uint32_t mode) { HILOG_DEBUG("mode = %{public}d", mode); - if (mode == FULL_SCREEN_MAGNIFICATION && zoomGesture_ != nullptr) { + if (zoomGesture_ != nullptr) { zoomGesture_->DisableGesture(); - } else if (mode == WINDOW_MAGNIFICATION && windowMagnificationGesture_ != nullptr) { - windowMagnificationGesture_->DisableGesture(); - } else { - HILOG_WARN("invalid mode."); } } void AccessibilityInputInterceptor::EnableGesture(uint32_t mode) { HILOG_DEBUG("mode = %{public}d", mode); - if (mode == FULL_SCREEN_MAGNIFICATION && zoomGesture_ != nullptr) { + if (zoomGesture_ != nullptr) { zoomGesture_->StartMagnificationInteract(); - } else if (mode == WINDOW_MAGNIFICATION && windowMagnificationGesture_ != nullptr) { - windowMagnificationGesture_->StartMagnificationInteract(); - } else { - HILOG_WARN("invalid mode."); + } +} + +void AccessibilityInputInterceptor::SetMagnificationMode(uint32_t mode) +{ + HILOG_DEBUG("mode = %{public}d", mode); + if (zoomGesture_ != nullptr) { + zoomGesture_->SetMagnificationMode(mode); } } @@ -555,7 +520,6 @@ void AccessibilityInputInterceptor::SetServiceOnKeyEventResult( keyEventFilter_->SetServiceOnKeyEventResult(connectionId, isHandled, sequenceNum); } } -// LCOV_EXCL_STOP AccessibilityInputEventConsumer::AccessibilityInputEventConsumer() { diff --git a/services/aams_ext/src/accessibility_zoom_gesture.cpp b/services/aams_ext/src/accessibility_zoom_gesture.cpp index ca9308d49..f045c3d35 100644 --- a/services/aams_ext/src/accessibility_zoom_gesture.cpp +++ b/services/aams_ext/src/accessibility_zoom_gesture.cpp @@ -20,6 +20,7 @@ #include "ext_utils.h" #include "accessibility_input_interceptor.h" #include "extend_service_manager.h" +#include "accessibility_def.h" #ifdef OHOS_BUILD_ENABLE_POWER_MANAGER #include "accessibility_extend_power_manager.h" #endif @@ -30,12 +31,12 @@ namespace OHOS { namespace Accessibility { namespace { - constexpr size_t POINTER_COUNT_1 = 1; - constexpr size_t POINTER_COUNT_2 = 2; constexpr float TAP_MIN_DISTANCE = 8.0f; + constexpr int32_t MULTI_FINGER_TAP_INTERVAL_TIMER = 100; // ms constexpr int32_t MULTI_TAP_TIMER = 250; // ms constexpr int32_t LONG_PRESS_TIMER = 300; // ms constexpr float DOUBLE_TAP_SLOP = 100.0f; + constexpr uint32_t DOUBLE_TAP_COUNT = 2; constexpr uint32_t TRIPLE_TAP_COUNT = 3; constexpr float MIN_SCROLL_SPAN = 2.0f; constexpr float MIN_SCALE_SPAN = 2.0f; @@ -44,14 +45,17 @@ namespace { AccessibilityZoomGesture::AccessibilityZoomGesture( std::shared_ptr fullScreenManager, + std::shared_ptr windowMagnificationManager, std::shared_ptr menuManager) - : fullScreenManager_(fullScreenManager), menuManager_(menuManager) + : fullScreenManager_(fullScreenManager), + windowMagnificationManager_(windowMagnificationManager), + menuManager_(menuManager) { HILOG_DEBUG(); zoomGestureEventHandler_ = std::make_shared( AccessibilityInputInterceptor::GetInstance()->GetInputManagerRunner(), *this); - - tapDistance_ = TAP_MIN_DISTANCE; + magnificationMode_ = Singleton::GetInstance().getMagnificationModeCallback(); + gestureMode_ = Singleton::GetInstance().getMagnificationTriggerMethodCallback(); #ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER AccessibilityDisplayManager &displayMgr = Singleton::GetInstance(); @@ -62,13 +66,17 @@ AccessibilityZoomGesture::AccessibilityZoomGesture( } float densityPixels = display->GetVirtualPixelRatio(); + tapDistance_ = TAP_MIN_DISTANCE; multiTapDistance_ = densityPixels * DOUBLE_TAP_SLOP + 0.5f; #else HILOG_DEBUG("not support display manager"); multiTapDistance_ = 1 * DOUBLE_TAP_SLOP + 0.5f; #endif + + InitGestureFuncMap(); } + bool AccessibilityZoomGesture::IsTapOnInputMethod(MMI::PointerEvent &event) { size_t pointerCount = event.GetPointerIds().size(); @@ -103,9 +111,30 @@ bool AccessibilityZoomGesture::IsTapOnInputMethod(MMI::PointerEvent &event) return false; } +void AccessibilityZoomGesture::DisableGesture() +{ + OffZoom(); +} +void AccessibilityZoomGesture::StartMagnificationInteract() +{ + zoomState_ = ZOOM; +} + +bool AccessibilityZoomGesture::IsDownValid(std::shared_ptr curEvent, + std::shared_ptr lastEvent) +{ + return CalcSeparationDistance(*curEvent, *lastEvent) <= multiTapDistance_; +} + +bool AccessibilityZoomGesture::IsMoveValid(std::shared_ptr curEvent, + std::shared_ptr lastEvent) +{ + return CalcSeparationDistance(*curEvent, *lastEvent) <= tapDistance_; +} + bool AccessibilityZoomGesture::OnPointerEvent(MMI::PointerEvent &event) { - HILOG_DEBUG("state_ is %{public}d.", state_); + HILOG_DEBUG("zoomGestureState_ is %{public}d.", zoomGestureState_); if (shieldZoomGestureFlag_) { EventTransmission::OnPointerEvent(event); @@ -118,7 +147,7 @@ bool AccessibilityZoomGesture::OnPointerEvent(MMI::PointerEvent &event) } int32_t sourceType = event.GetSourceType(); - if (state_ == READY_STATE && sourceType != MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) { + if (zoomState_ == READY && sourceType != MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) { EventTransmission::OnPointerEvent(event); return false; } @@ -136,69 +165,223 @@ bool AccessibilityZoomGesture::OnPointerEvent(MMI::PointerEvent &event) return false; } - switch (state_) { - case READY_STATE: - CacheEvents(event); - RecognizeInReadyState(event); - break; - case ZOOMIN_STATE: - CacheEvents(event); - RecognizeInZoomState(event); - break; - case SLIDING_STATE: - RecognizeInSlidingState(event); - break; - case MENU_SLIDING_STATE: - RecognizeInMenuSlidingState(event); - break; - case DRAGGING_STATE: - RecognizeInDraggingState(event); - break; - default: - break; - } + OnPointerEventExecute(event); return true; } -void AccessibilityZoomGesture::TransferState(ACCESSIBILITY_ZOOM_STATE state) +void AccessibilityZoomGesture::OnPointerEventExecute(MMI::PointerEvent &event) { - HILOG_INFO("old state= %{public}d, new state= %{public}d", state_, state); - state_ = state; + int32_t action = event.GetPointerAction(); + if (action < 1 || action >= POINTER_ACTION_MAX) { + HILOG_ERROR("invalid action=%{public}d", action); + EventTransmission::OnPointerEvent(event); + return; + } + if (zoomGestureState_ == INVALID) { + if (action == MMI::PointerEvent::POINTER_ACTION_UP && event.GetPointerIds().size() == 1) { + TransferState(INIT); + } + return; + } + if (zoomGestureState_ == PASSING_THROUGH) { + if (action == MMI::PointerEvent::POINTER_ACTION_UP && event.GetPointerIds().size() == 1) { + TransferState(INIT); + } + SendEventToMultimodal(event); + return; + } + auto func = handlerFuncMap_[gestureMode_][zoomState_][zoomGestureState_][action]; + if (func != nullptr) { + func(event); + } else { + CacheEvents(event); + SendCacheEventsToNext(); + HILOG_ERROR("no handler for gestureMode=%{public}d, magState=%{public}d, state=%{public}d, action=%{public}d", + gestureMode_, zoomState_, zoomGestureState_, action); + if (action == MMI::PointerEvent::POINTER_ACTION_UP && event.GetPointerIds().size() == 1) { + return; + } + TransferState(PASSING_THROUGH); + } +} + +void AccessibilityZoomGesture::InitGestureFuncMap() +{ + HILOG_DEBUG(); + + InitSingleFingerTripleTapFuncMap(); + InitThreeFingerDoubleTapFuncMap(); +} + +void AccessibilityZoomGesture::InitSingleFingerTripleTapFuncMap() +{ + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][READY][INIT][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleSTReadyInitStateDown); + + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][READY][ONE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleSTReadyStateUp); + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][READY][ONE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleSTReadyStateMove); + + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][READY][ONE_FINGER_TAP][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleSTReadyOneFingerTapStateDown); + + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][HOLD][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleHoldStateDown); + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][HOLD][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleHoldStateUp); + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][HOLD][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleHoldStateMove); + + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][INIT][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleSTZoomInitStateDown); + + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][ONE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleSTZoomOneFingerDownStateDown); + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][ONE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleSTZoomOneFingerDownStateUp); + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][ONE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleSTZoomOneFingerDownStateMove); + + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][TWO_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleSTZoomTwoFingerDownStateMove); + + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][ONE_FINGER_TAP][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleSTZoomOneFingerTapStateDown); + + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][SLIDING][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleZoomSlidingStateDown); + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][SLIDING][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleZoomSlidingStateMove); + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][SLIDING][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleZoomSlidingStateUp); + + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][HOT_AREA_SLIDING][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(DoNothingHandler); + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][HOT_AREA_SLIDING][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleHotAreaSlidingStateMove); + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][HOT_AREA_SLIDING][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleHotAreaSlidingStateUp); + + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][MENU_SLIDING][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(DoNothingHandler); + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][MENU_SLIDING][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleMenuSlidingStateMove); + handlerFuncMap_[SINGLE_FINGER_TRIPLE_TAP_MODE][ZOOM][MENU_SLIDING][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleMenuSlidingStateUp); +} + +void AccessibilityZoomGesture::InitThreeFingerDoubleTapFuncMap() +{ + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][READY][INIT][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleTDReadyInitStateDown); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][READY][ONE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleTDReadyOneFingerDownStateDown); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][READY][ONE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleTDReadyOneFingerDownStateMove); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][READY][TWO_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleTDReadyTwoFingersDownStateDown); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][READY][TWO_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleTDReadyTwoFingersDownStateMove); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][READY][THREE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleTDReadyThreeFingersDownStateUp); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][READY][THREE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleTDReadyThreeFingersDownStateMove); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][READY][THREE_FINGER_TAP][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleTDReadyThreeFingersTapStateDown); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][READY][THREE_FINGER_TAP][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleTDReadyThreeFingersTapStateMove); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][READY][THREE_FINGER_TAP_THEN_DOWN] + [MMI::PointerEvent::POINTER_ACTION_UP] = BIND(HandleTDReadyThreeFingersContinueDownStateUp); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][READY][THREE_FINGER_TAP_THEN_DOWN] + [MMI::PointerEvent::POINTER_ACTION_MOVE] = BIND(HandleTDReadyThreeFingersContinueDownStateMove); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][HOLD][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleHoldStateDown); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][HOLD][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleHoldStateUp); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][HOLD][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleHoldStateMove); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][INIT][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleTDZoomInitStateDown); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][ONE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleTDZoomOneFingerDownStateDown); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][ONE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleTDZoomOneFingerDownStateMove); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][ONE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleTDZoomOneFingerDownStateUp); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][TWO_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleTDZoomTwoFingersDownStateDown); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][TWO_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleTDZoomTwoFingersDownStateMove); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][THREE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleTDZoomThreeFingersDownStateUp); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][THREE_FINGER_DOWN][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleTDZoomThreeFingersDownStateMove); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][THREE_FINGER_TAP][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleTDZoomThreeFingersTapStateDown); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][THREE_FINGER_TAP][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleTDZoomThreeFingersTapStateMove); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][THREE_FINGER_TAP_THEN_DOWN] + [MMI::PointerEvent::POINTER_ACTION_UP] = BIND(HandleTDZoomThreeFingersContinueDownStateUp); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][THREE_FINGER_TAP_THEN_DOWN] + [MMI::PointerEvent::POINTER_ACTION_MOVE] = BIND(HandleTDZoomThreeFingersContinueDownStateMove); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][SLIDING][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(HandleZoomSlidingStateDown); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][SLIDING][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleZoomSlidingStateMove); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][SLIDING][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleZoomSlidingStateUp); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][HOT_AREA_SLIDING][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(DoNothingHandler); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][HOT_AREA_SLIDING][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleHotAreaSlidingStateMove); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][HOT_AREA_SLIDING][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleHotAreaSlidingStateUp); + + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][MENU_SLIDING][MMI::PointerEvent::POINTER_ACTION_DOWN] = + BIND(DoNothingHandler); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][MENU_SLIDING][MMI::PointerEvent::POINTER_ACTION_MOVE] = + BIND(HandleMenuSlidingStateMove); + handlerFuncMap_[THREE_FINGER_DOUBLE_TAP_MODE][ZOOM][MENU_SLIDING][MMI::PointerEvent::POINTER_ACTION_UP] = + BIND(HandleMenuSlidingStateUp); +} + +void AccessibilityZoomGesture::SetMagnificationMode(uint32_t mode) +{ + magnificationMode_ = mode; +} + + +void AccessibilityZoomGesture::SetGestureMode(int32_t mode) +{ + HILOG_INFO("Set gesture mode: %{public}d", mode); + gestureMode_ = mode; +} + +void AccessibilityZoomGesture::TransferState(int32_t state) +{ + HILOG_INFO("old state= %{public}d, new state= %{public}d", zoomGestureState_, state); + zoomGestureState_ = state; } void AccessibilityZoomGesture::CacheEvents(MMI::PointerEvent &event) { HILOG_DEBUG(); - - int32_t action = event.GetPointerAction(); - size_t pointerCount = event.GetPointerIds().size(); std::shared_ptr pointerEvent = std::make_shared(event); - - switch (action) { - case MMI::PointerEvent::POINTER_ACTION_DOWN: - if (pointerCount == POINTER_COUNT_1) { - HILOG_DEBUG("Cache pointer down"); - preLastDownEvent_ = lastDownEvent_; - lastDownEvent_ = pointerEvent; - } - break; - case MMI::PointerEvent::POINTER_ACTION_UP: - if (pointerCount == POINTER_COUNT_1) { - HILOG_DEBUG("Cache pointer up"); - preLastUpEvent_ = lastUpEvent_; - lastUpEvent_ = pointerEvent; - } - break; - case MMI::PointerEvent::POINTER_ACTION_MOVE: - if (pointerCount == POINTER_COUNT_1) { - HILOG_DEBUG("Cache pointer move."); - currentMoveEvent_ = pointerEvent; - } - break; - default: - HILOG_DEBUG("Action is %{public}d", action); - break; - } cacheEvents_.emplace_back(pointerEvent); } @@ -206,52 +389,61 @@ void AccessibilityZoomGesture::SendCacheEventsToNext() { HILOG_DEBUG(); - bool isStartNewAction = false; - int32_t action = MMI::PointerEvent::POINTER_ACTION_UNKNOWN; - std::vector> cacheEventsTmp; - std::copy(cacheEvents_.begin(), cacheEvents_.end(), std::back_inserter(cacheEventsTmp)); - - ClearCacheEventsAndMsg(); - - size_t cacheEventsNum = 0; - size_t cacheEventsTotalNum = cacheEventsTmp.size(); - if (fullScreenManager_ == nullptr) { HILOG_ERROR("fullScreenManager_ is nullptr."); return; } - - for (auto &pointerEvent : cacheEventsTmp) { - cacheEventsNum++; - action = pointerEvent->GetPointerAction(); - if ((cacheEventsNum > 1) && - (cacheEventsNum == cacheEventsTotalNum) && - (action == MMI::PointerEvent::POINTER_ACTION_DOWN)) { - HILOG_DEBUG("The down event needs to be parsed again"); - isStartNewAction = true; - } - if (isStartNewAction) { - OnPointerEvent(*pointerEvent); - continue; - } - if (state_ != READY_STATE && fullScreenManager_->IsMagnificationWindowShow()) { - MMI::PointerEvent::PointerItem pointer {}; - pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointer); - PointerPos coordinates = fullScreenManager_->ConvertCoordinates(pointer.GetDisplayX(), - pointer.GetDisplayY()); - if (gestureType_ != INVALID_GESTURE_TYPE) { - coordinates = fullScreenManager_->ConvertGesture(gestureType_, coordinates); - } - pointer.SetDisplayX(coordinates.posX); - pointer.SetDisplayY(coordinates.posY); - pointer.SetTargetWindowId(-1); - pointerEvent->RemovePointerItem(pointerEvent->GetPointerId()); - pointerEvent->AddPointerItem(pointer); - pointerEvent->SetZOrder(10000); // 10000 is magnification window zorder - } - pointerEvent->SetActionTime(ExtUtils::GetSystemTime() * US_TO_MS); - EventTransmission::OnPointerEvent(*pointerEvent); + bool isMagnificationWindowShow = fullScreenManager_->IsMagnificationWindowShow(); + for (auto &pointerEvent : cacheEvents_) { + SendEventToMultimodal(*pointerEvent); } + ClearCacheEventsAndMsg(); +} + +void AccessibilityZoomGesture::SendEventToMultimodal(MMI::PointerEvent event) +{ + if (fullScreenManager_ == nullptr) { + HILOG_ERROR("fullScreenManager_ is nullptr."); + return; + } + + if (zoomState_ == ZOOM) { + if (magnificationMode_ == FULL_SCREEN_MAGNIFICATION && fullScreenManager_->IsMagnificationWindowShow()) { + MMI::PointerEvent::PointerItem pointer {}; + event.GetPointerItem(event.GetPointerId(), pointer); + + PointerPos coordinates = fullScreenManager_->ConvertCoordinates(pointer.GetDisplayX(), + pointer.GetDisplayY()); + if (gestureType_ != INVALID_GESTURE_TYPE) { + coordinates = fullScreenManager_->ConvertGesture(gestureType_, coordinates); + } + pointer.SetDisplayX(coordinates.posX); + pointer.SetDisplayY(coordinates.posY); + pointer.SetTargetWindowId(-1); + event.RemovePointerItem(event.GetPointerId()); + event.AddPointerItem(pointer); + event.SetZOrder(10000); // magnification zlevel is 10000 + } + if (magnificationMode_ != FULL_SCREEN_MAGNIFICATION && + windowMagnificationManager_->IsMagnificationWindowShow()) { + MMI::PointerEvent::PointerItem pointer {}; + event.GetPointerItem(event.GetPointerId(), pointer); + if (windowMagnificationManager_->IsTapOnMagnificationWindow(pointer.GetDisplayX(), pointer.GetDisplayY()) && + !windowMagnificationManager_->IsTapOnHotArea(pointer.GetDisplayX(), pointer.GetDisplayY())) { + HILOG_ERROR("need convert pos"); + PointerPos coordinates = windowMagnificationManager_->ConvertCoordinates(pointer.GetDisplayX(), + pointer.GetDisplayY()); + pointer.SetDisplayX(coordinates.posX); + pointer.SetDisplayY(coordinates.posY); + pointer.SetTargetWindowId(-1); + event.RemovePointerItem(event.GetPointerId()); + event.AddPointerItem(pointer); + event.SetZOrder(10000); // magnification zlevel is 10000 + } + } + } + event.SetActionTime(ExtUtils::GetSystemTime() * US_TO_MS); + EventTransmission::OnPointerEvent(event); } void AccessibilityZoomGesture::ClearCacheEventsAndMsg() @@ -259,374 +451,84 @@ void AccessibilityZoomGesture::ClearCacheEventsAndMsg() HILOG_DEBUG(); cacheEvents_.clear(); - preLastDownEvent_ = nullptr; lastDownEvent_ = nullptr; - preLastUpEvent_ = nullptr; - lastUpEvent_ = nullptr; -} - -void AccessibilityZoomGesture::RecognizeInReadyState(MMI::PointerEvent &event) -{ - HILOG_DEBUG(); - - int32_t action = event.GetPointerAction(); - size_t pointerCount = event.GetPointerIds().size(); - bool isTripleTaps = false; - - HILOG_DEBUG("action:%{public}d, pointerCount:%{public}zu", action, pointerCount); - switch (action) { - case MMI::PointerEvent::POINTER_ACTION_DOWN: - zoomGestureEventHandler_->RemoveEvent(MULTI_TAP_MSG); - if ((pointerCount == POINTER_COUNT_1) && IsDownValid()) { - zoomGestureEventHandler_->SendEvent(MULTI_TAP_MSG, 0, MULTI_TAP_TIMER); - IsTripleTaps(); - } else { - SendCacheEventsToNext(); - } - break; - case MMI::PointerEvent::POINTER_ACTION_UP: - if ((pointerCount == POINTER_COUNT_1) && IsUpValid() && !(IsTapOnInputMethod(event))) { - isTripleTaps = IsTripleTaps(); - } else { - SendCacheEventsToNext(); - HILOG_DEBUG("action:%{public}d, pointerCount:%{public}zu", action, pointerCount); - } - break; - case MMI::PointerEvent::POINTER_ACTION_MOVE: - if ((pointerCount == POINTER_COUNT_1) && IsMoveValid()) { - HILOG_DEBUG("move valid."); - } else { - SendCacheEventsToNext(); - HILOG_DEBUG("action:%{public}d, pointerCount:%{public}zu", action, pointerCount); - } - break; - case MMI::PointerEvent::POINTER_ACTION_CANCEL: - SendCacheEventsToNext(); - break; - default: - break; - } - - if (isTripleTaps) { - OnTripleTap(event); - zoomGestureEventHandler_->RemoveEvent(MULTI_TAP_MSG); - } -} - -void AccessibilityZoomGesture::RecognizeInZoomStateDownEvent(MMI::PointerEvent &event) -{ - if (fullScreenManager_ == nullptr) { - HILOG_ERROR("fullScreenManager_ is nullptr."); - return; - } - if (menuManager_ == nullptr) { - HILOG_ERROR("menuManager_ is nullptr."); - return; - } + lastTripleTapEvents_[POINTER_ID_0] = nullptr; + lastTripleTapEvents_[POINTER_ID_1] = nullptr; + lastTripleTapEvents_[POINTER_ID_2] = nullptr; gestureType_ = INVALID_GESTURE_TYPE; - std::vector pointerIdList = event.GetPointerIds(); - size_t pointerCount = pointerIdList.size(); + bool isTapOnMenu_ = false; + bool isTapOnWindowHotArea_ = false; + bool isTapOnWindow_ = false; + lastCenter = {0.0f, 0.0f}; + zoomGestureEventHandler_->RemoveEvent(MULTI_TAP_MSG); - if (pointerCount == POINTER_COUNT_1) { - isLongPress_ = false; - isMoveValid_ = true; - MMI::PointerEvent::PointerItem pointerItem; - event.GetPointerItem(event.GetPointerId(), pointerItem); - gestureType_ = fullScreenManager_->CheckTapOnHotArea(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); - isTapOnMenu_ = menuManager_->IsTapOnMenu(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); - std::shared_ptr pointerEvent = std::make_shared(event); - longPressDownEvent_ = pointerEvent; - downPid_ = event.GetPointerId(); - if (IsDownValid()) { - if (!isTapOnMenu_) { - zoomGestureEventHandler_->SendEvent(MULTI_TAP_MSG, 0, MULTI_TAP_TIMER); + zoomGestureEventHandler_->RemoveEvent(LONG_PRESS_MSG); + zoomGestureEventHandler_->RemoveEvent(HOLDING_MSG); + zoomGestureEventHandler_->RemoveEvent(TWO_FINGER_SLIDING_MSG); + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + zoomGestureEventHandler_->RemoveEvent(HOT_AREA_SLIDING_MSG); + zoomGestureEventHandler_->RemoveEvent(MENU_SLIDING_MSG); +} + + +void AccessibilityZoomGesture::RecognizeScroll(ZOOM_FOCUS_COORDINATE &coordinate) +{ + HILOG_DEBUG(); + if (abs(lastCenter.centerX) < EPS && abs(lastCenter.centerY) < EPS) { + lastCenter.centerX = coordinate.centerX; + lastCenter.centerY = coordinate.centerY; + return; + } + + float offsetX = coordinate.centerX - lastCenter.centerX; + float offsetY = coordinate.centerY - lastCenter.centerY; + if ((abs(offsetX) > MIN_SCROLL_SPAN) || (abs(offsetY) > MIN_SCROLL_SPAN)) { + lastCenter.centerX = coordinate.centerX; + lastCenter.centerY = coordinate.centerY; + OnScroll(offsetX, offsetY); + } +} + +bool AccessibilityZoomGesture::RecognizeScale(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + float curDistance = CalcSeparationDistance(event); + if (abs(lastDistance_) < EPS) { + HILOG_WARN("lastDistance_ is zero"); + lastDistance_ = curDistance; + return false; + } + if (magnificationMode_ == FULL_SCREEN_MAGNIFICATION) { + if (abs(lastDistance_ - curDistance) >= MIN_SCALE_SPAN) { + if (fullScreenManager_ == nullptr) { + HILOG_ERROR("fullScreenManager_ is nullptr."); + return false; } + fullScreenManager_->SetScale(curDistance / lastDistance_); + lastDistance_ = curDistance; + return true; + } + } else { + if (abs(baseDistance_ - curDistance) > MIN_SCALE_DISTANCE) { + hasScaled_ = true; + if (windowMagnificationManager_ == nullptr) { + HILOG_ERROR("fullScreenManager_ is nullptr."); + return false; + } + windowMagnificationManager_->FixSourceCenter(true); + windowMagnificationManager_->SetScale(curDistance - lastDistance_); + lastDistance_ = curDistance; + return true; } else { - SendCacheEventsToNext(); - } - } else if (pointerCount == POINTER_COUNT_2) { - gestureType_ = INVALID_GESTURE_TYPE; - if (isLongPress_ || IsKnuckles(event) || !isMoveValid_) { - HILOG_INFO("not transferState sliding."); - SendCacheEventsToNext(); - } else { - TransferState(SLIDING_STATE); - scale_ = fullScreenManager_->GetScale(); - isScale_ = false; - ClearCacheEventsAndMsg(); - ZOOM_FOCUS_COORDINATE focusXY = {0.0f, 0.0f}; - CalcFocusCoordinate(event, focusXY); - lastScrollFocusX_ = focusXY.centerX; - lastScrollFocusY_ = focusXY.centerY; - float span = CalcScaleSpan(event, focusXY); - preSpan_ = lastSpan_ = span; - } - } else { - HILOG_INFO("invalid pointer count."); - } -} - -void AccessibilityZoomGesture::RecognizeInZoomStateMoveEvent(MMI::PointerEvent &event) -{ - int32_t action = event.GetPointerAction(); - std::vector pointerIdList = event.GetPointerIds(); - size_t pointerCount = pointerIdList.size(); - HILOG_DEBUG(); - if ((pointerCount == POINTER_COUNT_1) && !IsLongPress() && IsMoveValid()) { - HILOG_DEBUG("move valid."); - } else if (isTapOnMenu_ && (!IsMoveValid() || IsLongPress())) { - TransferState(MENU_SLIDING_STATE); - ClearCacheEventsAndMsg(); - } else { - SendCacheEventsToNext(); - HILOG_DEBUG("action:%{public}d, pointerCount:%{public}zu", action, pointerCount); - } -} - -void AccessibilityZoomGesture::RecognizeInZoomState(MMI::PointerEvent &event) -{ - HILOG_DEBUG(); - - int32_t action = event.GetPointerAction(); - std::vector pointerIdList = event.GetPointerIds(); - size_t pointerCount = pointerIdList.size(); - bool isTripleTaps = false; - - HILOG_DEBUG("action:%{public}d, pointerCount:%{public}zu", action, pointerCount); - switch (action) { - case MMI::PointerEvent::POINTER_ACTION_DOWN: - RecognizeInZoomStateDownEvent(event); - break; - case MMI::PointerEvent::POINTER_ACTION_UP: - if (downPid_ == event.GetPointerId()) { - isLongPress_ = false; + if (hasScaled_) { + hasScaled_ = false; + CalcFocusCoordinate(event, lastCenter); } - if ((pointerCount == POINTER_COUNT_1) && IsUpValid()) { - if (isTapOnMenu_ && menuManager_ != nullptr) { - menuManager_->OnMenuTap(); - ClearCacheEventsAndMsg(); - } else { - isTripleTaps = IsTripleTaps(); - } - } else { - SendCacheEventsToNext(); - } - break; - case MMI::PointerEvent::POINTER_ACTION_MOVE: - RecognizeInZoomStateMoveEvent(event); - break; - case MMI::PointerEvent::POINTER_ACTION_CANCEL: - SendCacheEventsToNext(); - HILOG_DEBUG("action:%{public}d", action); - break; - default: - break; - } - - if (isTripleTaps) { - OnTripleTap(event); - } -} - -void AccessibilityZoomGesture::RecognizeInSlidingState(MMI::PointerEvent &event) -{ - HILOG_DEBUG(); - - int32_t action = event.GetPointerAction(); - size_t pointerCount = event.GetPointerIds().size(); - ZOOM_FOCUS_COORDINATE coordinate = {0.0f, 0.0f}; - CalcFocusCoordinate(event, coordinate); - - if (pointerCount == POINTER_COUNT_2) { - RecognizeScale(event, coordinate); - RecognizeScroll(event, coordinate); - } - - HILOG_DEBUG("action:%{public}d, pointerCount:%{public}zu", action, pointerCount); - - if (fullScreenManager_ == nullptr) { - HILOG_ERROR("fullScreenManager_ is nullptr."); - return; - } - - switch (action) { - case MMI::PointerEvent::POINTER_ACTION_UP: - if (pointerCount == POINTER_COUNT_1) { - TransferState(ZOOMIN_STATE); - if (isScale_ && (abs(scale_ - fullScreenManager_->GetScale()) > MIN_SCALE)) { - fullScreenManager_->PersistScale(); - isScale_ = false; - } - } - break; - case MMI::PointerEvent::POINTER_ACTION_CANCEL: - TransferState(ZOOMIN_STATE); - isScale_ = false; - break; - default: - break; - } -} - -void AccessibilityZoomGesture::RecognizeInMenuSlidingState(MMI::PointerEvent &event) -{ - HILOG_INFO(); - if (menuManager_ == nullptr) { - HILOG_ERROR("menuManager_ is nullptr."); - return; - } - int32_t action = event.GetPointerAction(); - switch (action) { - case MMI::PointerEvent::POINTER_ACTION_MOVE: - if (isTapOnMenu_) { - ClearCacheEventsAndMsg(); - if (lastSlidingEvent_ == nullptr) { - lastSlidingEvent_ = std::make_shared(event); - } - MMI::PointerEvent::PointerItem lastSlidingItem; - lastSlidingEvent_->GetPointerItem(lastSlidingEvent_->GetPointerId(), lastSlidingItem); - - MMI::PointerEvent::PointerItem currentItem; - event.GetPointerItem(event.GetPointerId(), currentItem); - - int32_t deltaX = currentItem.GetDisplayX() - lastSlidingItem.GetDisplayX(); - int32_t deltaY = currentItem.GetDisplayY() - lastSlidingItem.GetDisplayY(); - menuManager_->MoveMenuWindow(deltaX, deltaY); - - lastSlidingEvent_ = std::make_shared(event); - } else { - if (lastSlidingEvent_ != nullptr) { - lastSlidingEvent_ = nullptr; - } - } - break; - case MMI::PointerEvent::POINTER_ACTION_UP: - lastSlidingEvent_ = nullptr; - isTapOnMenu_ = false; - menuManager_->AttachToEdge(); - TransferState(ZOOMIN_STATE); - ClearCacheEventsAndMsg(); - break; - default: - break; - } -} - -void AccessibilityZoomGesture::RecognizeScroll(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE &coordinate) -{ - HILOG_DEBUG(); - - int32_t action = event.GetPointerAction(); - switch (action) { - case MMI::PointerEvent::POINTER_ACTION_DOWN: - case MMI::PointerEvent::POINTER_ACTION_UP: - lastScrollFocusX_ = coordinate.centerX; - lastScrollFocusY_ = coordinate.centerY; - break; - case MMI::PointerEvent::POINTER_ACTION_MOVE: { - float offsetX = coordinate.centerX - lastScrollFocusX_; - float offsetY = coordinate.centerY - lastScrollFocusY_; - if ((abs(offsetX) > MIN_SCROLL_SPAN) || (abs(offsetY) > MIN_SCROLL_SPAN)) { - lastScrollFocusX_ = coordinate.centerX; - lastScrollFocusY_ = coordinate.centerY; - OnScroll(offsetX, offsetY); - } - break; - } - default: - break; - } -} - -void AccessibilityZoomGesture::RecognizeScale(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE &coordinate) -{ - HILOG_DEBUG(); - - int32_t action = event.GetPointerAction(); - size_t pointerCount = event.GetPointerIds().size(); - if (((action == MMI::PointerEvent::POINTER_ACTION_UP) && (pointerCount != POINTER_COUNT_2)) || - (action == MMI::PointerEvent::POINTER_ACTION_CANCEL)) { - HILOG_DEBUG("Scaling is end"); - startScaling_ = false; - preSpan_ = lastSpan_ = 0; - return; - } - - float span = CalcScaleSpan(event, coordinate); - - if (action == MMI::PointerEvent::POINTER_ACTION_MOVE) { - if (abs(preSpan_ - span) >= MIN_SCALE_SPAN) { - startScaling_ = true; - HILOG_DEBUG("start scaling."); + windowMagnificationManager_->FixSourceCenter(false); + return false; } } - if (!startScaling_) { - // When the span is greater than or equal to MIN_SCALE_SPAN, start scaling. - if (abs(preSpan_ - span) >= MIN_SCALE_SPAN) { - startScaling_ = true; - HILOG_DEBUG("start scaling."); - } - } else { - // When the span is smaller than the MIN_SCALE_SPAN, - // the scale recognition will be restarted. - if (abs(lastSpan_ - span) < 1) { - startScaling_ = false; - preSpan_ = lastSpan_ = span; - } - if ((action == MMI::PointerEvent::POINTER_ACTION_UP) || - (action == MMI::PointerEvent::POINTER_ACTION_DOWN)) { - preSpan_ = lastSpan_ = span; - } - } - - if (!startScaling_) { - HILOG_DEBUG("Current is not scaling"); - return; - } - - if (action != MMI::PointerEvent::POINTER_ACTION_MOVE) { - HILOG_DEBUG("Action(%{public}d) is not move", action); - return; - } - - float scaleSpan = span - lastSpan_; - if (abs(scaleSpan) > EPS) { - OnScale(scaleSpan); - lastSpan_ = span; - isScale_ = true; - } -} - -void AccessibilityZoomGesture::RecognizeInDraggingState(MMI::PointerEvent &event) -{ - HILOG_DEBUG(); - int32_t action = event.GetPointerAction(); - if (event.GetPointerId() != DEFAULT_POINTER_ID) { - return; - } - switch (action) { - case MMI::PointerEvent::POINTER_ACTION_MOVE: { - int32_t pointerId = event.GetPointerId(); - MMI::PointerEvent::PointerItem item; - event.GetPointerItem(pointerId, item); - int32_t anchorX = item.GetDisplayX(); - int32_t anchorY = item.GetDisplayY(); - float offsetX = lastScrollFocusX_ - anchorX; - float offsetY = lastScrollFocusY_ - anchorY; - if ((abs(offsetX) > MIN_SCROLL_SPAN) || (abs(offsetY) > MIN_SCROLL_SPAN)) { - lastScrollFocusX_ = anchorX; - lastScrollFocusY_ = anchorY; - OnScroll(offsetX, offsetY); - } - break; - } - case MMI::PointerEvent::POINTER_ACTION_UP: - OffZoom(); - TransferState(READY_STATE); - break; - default: - break; - } + return false; } void AccessibilityZoomGesture::CalcFocusCoordinate(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE &coordinate) @@ -686,21 +588,7 @@ float AccessibilityZoomGesture::CalcScaleSpan(MMI::PointerEvent &event, ZOOM_FOC return span; } - if (action == MMI::PointerEvent::POINTER_ACTION_UP) { - upPointerId = event.GetPointerId(); - HILOG_DEBUG("The pointer id of up is %{public}d", upPointerId); - count--; - } - - if (!count) { - HILOG_DEBUG("The size of PointerIds(down) is invalid"); - return span; - } - for (int32_t pointerId : pointerIdList) { - if (pointerId == upPointerId) { - continue; - } MMI::PointerEvent::PointerItem item; event.GetPointerItem(pointerId, item); sumSpanX += static_cast(abs(item.GetRawDisplayX() - coordinate.centerX)); @@ -714,80 +602,6 @@ float AccessibilityZoomGesture::CalcScaleSpan(MMI::PointerEvent &event, ZOOM_FOC return span; } -bool AccessibilityZoomGesture::IsDownValid() -{ - HILOG_DEBUG(); - - if (!preLastDownEvent_) { - HILOG_DEBUG("This is the first down event"); - return true; - } - - if (CalcSeparationDistance(preLastDownEvent_, lastDownEvent_) >= multiTapDistance_) { - HILOG_DEBUG("The down event is vailid"); - return false; - } - return true; -} - -bool AccessibilityZoomGesture::IsUpValid() -{ - HILOG_DEBUG(); - - if (!lastDownEvent_) { - HILOG_DEBUG("The up event is invailid"); - return false; - } - - if (CalcIntervalTime(lastDownEvent_, lastUpEvent_) >= LONG_PRESS_TIMER) { - HILOG_DEBUG("The time has exceeded the long press time"); - return false; - } - - if (CalcSeparationDistance(lastDownEvent_, lastUpEvent_) >= tapDistance_) { - HILOG_DEBUG("The distance has exceeded the threshold"); - return false; - } - return true; -} - -bool AccessibilityZoomGesture::IsMoveValid() -{ - HILOG_DEBUG(); - - if (!lastDownEvent_) { - HILOG_DEBUG("The move event is invailid"); - isMoveValid_ = false; - return false; - } - - if (CalcIntervalTime(lastDownEvent_, currentMoveEvent_) >= LONG_PRESS_TIMER) { - HILOG_DEBUG("The time has exceeded the long press time"); - isMoveValid_ = false; - return false; - } - - if (CalcSeparationDistance(lastDownEvent_, currentMoveEvent_) >= tapDistance_) { - HILOG_DEBUG("The distance has exceeded the threshold"); - isMoveValid_ = false; - return false; - } - isMoveValid_ = true; - return true; -} - -bool AccessibilityZoomGesture::IsLongPress() -{ - HILOG_DEBUG(); - - if (CalcIntervalTime(longPressDownEvent_, currentMoveEvent_) >= LONG_PRESS_TIMER) { - HILOG_DEBUG("The time has exceeded the long press time"); - isLongPress_ = true; - return true; - } - return false; -} - bool AccessibilityZoomGesture::IsKnuckles(MMI::PointerEvent &event) { HILOG_DEBUG(); @@ -805,102 +619,42 @@ bool AccessibilityZoomGesture::IsKnuckles(MMI::PointerEvent &event) return false; } -bool AccessibilityZoomGesture::IsTripleTaps() +float AccessibilityZoomGesture::CalcSeparationDistance(MMI::PointerEvent &event) { - HILOG_DEBUG(); - - uint32_t upEventCount = 0; - uint32_t downEventCount = 0; - int32_t action = MMI::PointerEvent::POINTER_ACTION_UNKNOWN; - for (auto &pointerEvent : cacheEvents_) { - action = pointerEvent->GetPointerAction(); - if (action == MMI::PointerEvent::POINTER_ACTION_UP) { - upEventCount++; - } - if (action == MMI::PointerEvent::POINTER_ACTION_DOWN) { - downEventCount++; - } + std::vector pointerIdList = event.GetPointerIds(); + size_t count = pointerIdList.size(); + if (count != POINTER_COUNT_2) { + HILOG_ERROR("only two fingers can cal distance"); + return 0.0f; } - - if (downEventCount == TRIPLE_TAP_COUNT && upEventCount == TAP_COUNT_TWO) { - HILOG_INFO("Triple down detected"); - isTripleDown_ = true; - } - - if (upEventCount >= TRIPLE_TAP_COUNT) { - HILOG_DEBUG("Triple tap detected"); - isTripleDown_ = false; - return true; - } - - return false; -} - -int64_t AccessibilityZoomGesture::CalcIntervalTime(std::shared_ptr firstEvent, - std::shared_ptr secondEvent) -{ - HILOG_DEBUG(); - - if (!firstEvent || !secondEvent) { - HILOG_DEBUG("The event is null"); - return 0; - } - - int64_t firstTime = firstEvent->GetActionTime(); - int64_t secondTime = secondEvent->GetActionTime(); - int64_t intervalTime = (secondTime - firstTime) / US_TO_MS; - - return intervalTime; -} - -float AccessibilityZoomGesture::CalcSeparationDistance(std::shared_ptr firstEvent, - std::shared_ptr secondEvent) -{ - HILOG_DEBUG(); - - if (!firstEvent || !secondEvent) { - HILOG_DEBUG("The event is null"); - return 0; - } - MMI::PointerEvent::PointerItem firstItem; MMI::PointerEvent::PointerItem secondItem; - firstEvent->GetPointerItem(firstEvent->GetPointerId(), firstItem); - secondEvent->GetPointerItem(secondEvent->GetPointerId(), secondItem); + event.GetPointerItem(pointerIdList[POINTER_ID_0], firstItem); + event.GetPointerItem(pointerIdList[POINTER_ID_1], secondItem); int32_t durationX = secondItem.GetDisplayX() - firstItem.GetDisplayX(); int32_t durationY = secondItem.GetDisplayY() - firstItem.GetDisplayY(); float distance = static_cast(hypot(durationX, durationY)); - + HILOG_DEBUG("distance:%{public}f", distance); return distance; } -void AccessibilityZoomGesture::OnTripleTap(MMI::PointerEvent &event) +float AccessibilityZoomGesture::CalcSeparationDistance(MMI::PointerEvent &firstEvent, + MMI::PointerEvent &secondEvent) { - HILOG_INFO("state_ is %{public}d.", state_); + HILOG_DEBUG(); - switch (state_) { - case READY_STATE: { - TransferState(ZOOMIN_STATE); - int32_t pointerId = event.GetPointerId(); - MMI::PointerEvent::PointerItem item; - event.GetPointerItem(pointerId, item); - int32_t anchorX = item.GetDisplayX(); - int32_t anchorY = item.GetDisplayY(); - HILOG_DEBUG("anchorX:%{private}d, anchorY:%{private}d.", anchorX, anchorY); - OnZoom(anchorX, anchorY, true); - break; - } - case ZOOMIN_STATE: - TransferState(READY_STATE); - OffZoom(); - break; - default: - break; - } - - ClearCacheEventsAndMsg(); + MMI::PointerEvent::PointerItem firstItem; + MMI::PointerEvent::PointerItem secondItem; + firstEvent.GetPointerItem(firstEvent.GetPointerId(), firstItem); + secondEvent.GetPointerItem(secondEvent.GetPointerId(), secondItem); + int32_t durationX = secondItem.GetDisplayX() - firstItem.GetDisplayX(); + int32_t durationY = secondItem.GetDisplayY() - firstItem.GetDisplayY(); + float distance = static_cast(hypot(durationX, durationY)); + HILOG_DEBUG("distance:%{public}f", distance); + return distance; } + AccessibilityZoomGesture::ZoomGestureEventHandler::ZoomGestureEventHandler( const std::shared_ptr &runner, AccessibilityZoomGesture &zoomGesture): AppExecFwk::EventHandler(runner), zoomGesture_(zoomGesture) @@ -913,15 +667,54 @@ void AccessibilityZoomGesture::ZoomGestureEventHandler::ProcessEvent(const AppEx HILOG_DEBUG(); uint32_t eventId = event->GetInnerEventId(); - + switch (eventId) { case MULTI_TAP_MSG: HILOG_DEBUG("process multi tap msg."); - if (zoomGesture_.isTripleDown_) { - zoomGesture_.OnDrag(); + zoomGesture_.TransferState(INIT); + zoomGesture_.SendCacheEventsToNext(); + break; + case HOLDING_MSG: + { + zoomGesture_.TransferState(HOLD); + if (zoomGesture_.gestureMode_ == SINGLE_FINGER_TRIPLE_TAP_MODE) { + int32_t pointerId = zoomGesture_.lastDownEvent_->GetPointerId(); + MMI::PointerEvent::PointerItem item; + zoomGesture_.lastDownEvent_->GetPointerItem(pointerId, item); + int32_t anchorX = item.GetDisplayX(); + int32_t anchorY = item.GetDisplayY(); + HILOG_DEBUG("anchorX:%{private}d, anchorY:%{private}d.", anchorX, anchorY); + zoomGesture_.OnZoom(anchorX, anchorY, false); } else { - zoomGesture_.SendCacheEventsToNext(); + int32_t anchorX = 0; + int32_t anchorY = 0; + for (int i = 0; i < POINTER_COUNT_3; i++) { + MMI::PointerEvent::PointerItem pointerItem; + zoomGesture_.lastTripleTapEvents_[i]->GetPointerItem( + zoomGesture_.lastTripleTapEvents_[i]->GetPointerId(), pointerItem); + anchorX += pointerItem.GetDisplayX(); + anchorY += pointerItem.GetDisplayY(); + } + zoomGesture_.OnZoom(anchorX / POINTER_COUNT_3, anchorY / POINTER_COUNT_3, false); } + zoomGesture_.ClearCacheEventsAndMsg(); + break; + } + case WAIT_ANOTHER_FINGER_DOWN_MSG: + zoomGesture_.TransferState(PASSING_THROUGH); + zoomGesture_.SendCacheEventsToNext(); + break; + case TWO_FINGER_SLIDING_MSG: + zoomGesture_.TransferState(SLIDING); + zoomGesture_.ClearCacheEventsAndMsg(); + break; + case HOT_AREA_SLIDING_MSG: + zoomGesture_.TransferState(HOT_AREA_SLIDING); + zoomGesture_.ClearCacheEventsAndMsg(); + break; + case MENU_SLIDING: + zoomGesture_.TransferState(MENU_SLIDING); + zoomGesture_.ClearCacheEventsAndMsg(); break; default: break; @@ -948,94 +741,98 @@ void AccessibilityZoomGesture::GetWindowParam(bool needRefresh) screenHeight_ = static_cast(display->GetHeight()); HILOG_INFO("screenWidth_ = %{public}d, screenHeight_ = %{public}d.", screenWidth_, screenHeight_); } - screenSpan_ = hypot(screenWidth_, screenHeight_); #else HILOG_INFO("not support zoom"); #endif } -void AccessibilityZoomGesture::StartMagnificationInteract() -{ - HILOG_INFO(); - TransferState(ZOOMIN_STATE); -} - -void AccessibilityZoomGesture::DisableGesture() -{ - HILOG_INFO(); - TransferState(READY_STATE); -} - void AccessibilityZoomGesture::OnZoom(int32_t anchorX, int32_t anchorY, bool showMenu) { HILOG_INFO(); - centerX_ = anchorX; - centerY_ = anchorY; - if (fullScreenManager_ == nullptr) { - HILOG_ERROR("fullScreenManager_ is nullptr."); + zoomState_ = ZOOM; + if (menuManager_ == nullptr) { + HILOG_ERROR("menuManager_ is nullptr."); return; } - fullScreenManager_->EnableMagnification(anchorX, anchorY); - HILOG_INFO("announcedForMagnificationCallback start"); + + if (magnificationMode_ == FULL_SCREEN_MAGNIFICATION) { + if (fullScreenManager_ == nullptr) { + HILOG_ERROR("fullScreenManager_ is nullptr."); + return; + } + fullScreenManager_->EnableMagnification(anchorX, anchorY); + if (showMenu) { + menuManager_->ShowMenuWindow(FULL_SCREEN_MAGNIFICATION); + } + } else { + if (windowMagnificationManager_ == nullptr) { + HILOG_ERROR("windowMagnificationManager_ is nullptr."); + return; + } + windowMagnificationManager_->EnableWindowMagnification(anchorX, anchorY); + if (showMenu) { + menuManager_->ShowMenuWindow(WINDOW_MAGNIFICATION); + } + } Singleton::GetInstance().announcedForMagnificationCallback( AnnounceType::ANNOUNCE_MAGNIFICATION_SCALE); - if (showMenu && menuManager_ != nullptr) { - menuManager_->ShowMenuWindow(FULL_SCREEN_MAGNIFICATION); - } ExtUtils::RecordOnZoomGestureEvent("on", true); } void AccessibilityZoomGesture::OffZoom() { HILOG_INFO(); - if (fullScreenManager_ == nullptr) { - HILOG_ERROR("fullScreenManager_ is nullptr."); - return; - } + zoomState_ = READY; if (menuManager_ == nullptr) { HILOG_ERROR("menuManager_ is nullptr."); return; } - if (fullScreenManager_->IsMagnificationWindowShow()) { - HILOG_INFO("full magnification disable."); + if (magnificationMode_ == FULL_SCREEN_MAGNIFICATION) { + if (fullScreenManager_ == nullptr) { + HILOG_ERROR("fullScreenManager_ is nullptr."); + return; + } fullScreenManager_->DisableMagnification(false); - menuManager_->DisableMenuWindow(); - Singleton::GetInstance().announcedForMagnificationCallback( - AnnounceType::ANNOUNCE_MAGNIFICATION_DISABLE); + } else { + if (windowMagnificationManager_ == nullptr) { + HILOG_ERROR("windowMagnificationManager_ is nullptr."); + return; + } + windowMagnificationManager_->DisableWindowMagnification(); } + menuManager_->DisableMenuWindow(); + Singleton::GetInstance().announcedForMagnificationCallback( + AnnounceType::ANNOUNCE_MAGNIFICATION_DISABLE); ExtUtils::RecordOnZoomGestureEvent("off", true); } -// LCOV_EXCL_START void AccessibilityZoomGesture::OnScroll(float offsetX, float offsetY) { HILOG_DEBUG("offsetX:%{public}f, offsetY:%{public}f.", offsetX, offsetY); - - if (fullScreenManager_ == nullptr) { - HILOG_ERROR("fullScreenManager_ is nullptr."); - return; + if (magnificationMode_ == FULL_SCREEN_MAGNIFICATION) { + if (fullScreenManager_ == nullptr) { + HILOG_ERROR("fullScreenManager_ is nullptr."); + return; + } + fullScreenManager_->MoveMagnification(static_cast(offsetX), static_cast(offsetY)); + } else { + if (windowMagnificationManager_ == nullptr) { + HILOG_ERROR("fullScreenManager_ is nullptr."); + return; + } + windowMagnificationManager_->MoveMagnificationWindow(static_cast(offsetX), + static_cast(offsetY)); } - fullScreenManager_->MoveMagnification(static_cast(offsetX), static_cast(offsetY)); #ifdef OHOS_BUILD_ENABLE_POWER_MANAGER Singleton::GetInstance().RefreshActivity(); #endif } -void AccessibilityZoomGesture::OnScale(float scaleSpan) -{ - HILOG_DEBUG(); - if (fullScreenManager_ == nullptr) { - HILOG_ERROR("fullScreenManager_ is nullptr."); - return; - } - fullScreenManager_->SetScale(scaleSpan); -} - void AccessibilityZoomGesture::Clear() { HILOG_DEBUG(); SendCacheEventsToNext(); - TransferState(READY_STATE); + TransferState(INIT); } void AccessibilityZoomGesture::DestroyEvents() @@ -1073,25 +870,833 @@ void AccessibilityZoomGesture::ShieldZoomGesture(bool state) } } -void AccessibilityZoomGesture::OnDrag() +void AccessibilityZoomGesture::DoNothingHandler(MMI::PointerEvent &event) { - TransferState(DRAGGING_STATE); - if (lastDownEvent_ == nullptr) { - HILOG_ERROR("lastDownEvent_ is nullptr"); + HILOG_DEBUG(); +} + +void AccessibilityZoomGesture::HandleSTReadyInitStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + zoomGestureEventHandler_->RemoveEvent(MULTI_TAP_MSG); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != 1) { + SendCacheEventsToNext(); return; } - MMI::PointerEvent::PointerItem item; - lastDownEvent_->GetPointerItem(lastDownEvent_->GetPointerId(), item); - - int32_t anchorX = item.GetDisplayX(); - int32_t anchorY = item.GetDisplayY(); - OnZoom(anchorX, anchorY, false); - lastScrollFocusX_ = static_cast(anchorX); - lastScrollFocusY_ = static_cast(anchorY); - isTripleDown_ = false; - ClearCacheEventsAndMsg(); + lastDownEvent_ = std::make_shared(event); + singleFingerTapCount_ = 0; + zoomGestureEventHandler_->SendEvent(MULTI_TAP_MSG, 0, MULTI_TAP_TIMER); + TransferState(ONE_FINGER_DOWN); +} + +void AccessibilityZoomGesture::HandleSTReadyStateUp(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != 1 || IsTapOnInputMethod(event)) { + SendCacheEventsToNext(); + TransferState(INIT); + return; + } + + singleFingerTapCount_ += 1; + if (singleFingerTapCount_ == TRIPLE_TAP_COUNT) { + ClearCacheEventsAndMsg(); + TransferState(INIT); + int32_t pointerId = event.GetPointerId(); + MMI::PointerEvent::PointerItem item; + event.GetPointerItem(pointerId, item); + int32_t anchorX = item.GetDisplayX(); + int32_t anchorY = item.GetDisplayY(); + HILOG_DEBUG("anchorX:%{private}d, anchorY:%{private}d.", anchorX, anchorY); + OnZoom(anchorX, anchorY, true); + } else { + TransferState(ONE_FINGER_TAP); + } +} + +void AccessibilityZoomGesture::HandleSTReadyStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != 1 || !IsMoveValid(lastDownEvent_, std::make_shared(event))) { + SendCacheEventsToNext(); + TransferState(INIT); + return; + } +} + +void AccessibilityZoomGesture::HandleSTReadyOneFingerTapStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + zoomGestureEventHandler_->RemoveEvent(MULTI_TAP_MSG); + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != 1 || !IsDownValid(lastDownEvent_, std::make_shared(event))) { + SendCacheEventsToNext(); + TransferState(INIT); + return; + } + + lastDownEvent_ = std::make_shared(event); + TransferState(ONE_FINGER_DOWN); + if (singleFingerTapCount_ == DOUBLE_TAP_COUNT) { + zoomGestureEventHandler_->SendEvent(HOLDING_MSG, 0, LONG_PRESS_TIMER); + } else { + zoomGestureEventHandler_->SendEvent(MULTI_TAP_MSG, 0, MULTI_TAP_TIMER); + } +} + +void AccessibilityZoomGesture::HandleSTZoomInitStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != 1) { + SendCacheEventsToNext(); + return; + } + MMI::PointerEvent::PointerItem pointerItem; + event.GetPointerItem(event.GetPointerId(), pointerItem); + if (magnificationMode_ == FULL_SCREEN_MAGNIFICATION) { + gestureType_ = fullScreenManager_->CheckTapOnHotArea(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); + } else { + isTapOnWindowHotArea_ = windowMagnificationManager_->IsTapOnHotArea(pointerItem.GetDisplayX(), + pointerItem.GetDisplayY()); + isTapOnWindow_ = windowMagnificationManager_->IsTapOnMagnificationWindow(pointerItem.GetDisplayX(), + pointerItem.GetDisplayY()); + } + isTapOnMenu_ = menuManager_->IsTapOnMenu(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); + + lastDownEvent_ = std::make_shared(event); + lastTripleTapEvents_[event.GetPointerId()] = std::make_shared(event); + singleFingerTapCount_ = 0; + if (isTapOnWindowHotArea_) { + zoomGestureEventHandler_->SendEvent(HOT_AREA_SLIDING_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + } else if (isTapOnMenu_) { + zoomGestureEventHandler_->SendEvent(MENU_SLIDING_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + } else { + zoomGestureEventHandler_->SendEvent(WAIT_ANOTHER_FINGER_DOWN_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + } + zoomGestureEventHandler_->SendEvent(MULTI_TAP_MSG, 0, MULTI_TAP_TIMER); + TransferState(ONE_FINGER_DOWN); +} + +void AccessibilityZoomGesture::HandleSTZoomOneFingerDownStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + gestureType_ = INVALID_GESTURE_TYPE; + + zoomGestureEventHandler_->RemoveEvent(MULTI_TAP_MSG); + zoomGestureEventHandler_->RemoveEvent(HOT_AREA_SLIDING_MSG); + zoomGestureEventHandler_->RemoveEvent(MENU_SLIDING_MSG); + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + + MMI::PointerEvent::PointerItem pointerItem; + event.GetPointerItem(event.GetPointerId(), pointerItem); + isTapOnWindow_ = windowMagnificationManager_->IsTapOnMagnificationWindow(pointerItem.GetDisplayX(), + pointerItem.GetDisplayY()); + if (magnificationMode_ != FULL_SCREEN_MAGNIFICATION && !isTapOnWindow_) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + lastTripleTapEvents_[event.GetPointerId()] = std::make_shared(event); + if (magnificationMode_ == FULL_SCREEN_MAGNIFICATION || isTapOnWindow_) { + zoomGestureEventHandler_->SendEvent(TWO_FINGER_SLIDING_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + CalcFocusCoordinate(event, lastCenter); + baseDistance_ = lastDistance_ = CalcSeparationDistance(event); + } + TransferState(TWO_FINGER_DOWN); +} + +void AccessibilityZoomGesture::HandleSTZoomOneFingerDownStateUp(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + zoomGestureEventHandler_->RemoveEvent(HOT_AREA_SLIDING_MSG); + zoomGestureEventHandler_->RemoveEvent(MENU_SLIDING_MSG); + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != 1) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + if (menuManager_ != nullptr) { + MMI::PointerEvent::PointerItem pointerItem; + event.GetPointerItem(event.GetPointerId(), pointerItem); + if (isTapOnMenu_) { + menuManager_->OnMenuTap(); + TransferState(INIT); + ClearCacheEventsAndMsg(); + return; + } + } + + singleFingerTapCount_ += 1; + if (singleFingerTapCount_ == POINTER_COUNT_3) { + TransferState(INIT); + ClearCacheEventsAndMsg(); + OffZoom(); + } else { + TransferState(ONE_FINGER_TAP); + } +} + +void AccessibilityZoomGesture::HandleSTZoomOneFingerDownStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != 1 || !IsMoveValid(lastDownEvent_, std::make_shared(event))) { + if (isTapOnWindowHotArea_) { + ClearCacheEventsAndMsg(); + TransferState(HOT_AREA_SLIDING); + return; + } + if (isTapOnMenu_) { + ClearCacheEventsAndMsg(); + TransferState(MENU_SLIDING); + return; + } + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } +} + +void AccessibilityZoomGesture::HandleSTZoomTwoFingerDownStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + if (event.GetPointerIds().size() != POINTER_COUNT_2) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + int32_t pId = event.GetPointerId(); + if (IsMoveValid(lastTripleTapEvents_[pId], std::make_shared(event))) { + return; + } + zoomGestureEventHandler_->RemoveEvent(TWO_FINGER_SLIDING_MSG); + if (magnificationMode_ != FULL_SCREEN_MAGNIFICATION && !isTapOnWindow_) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + ClearCacheEventsAndMsg(); + TransferState(SLIDING); +} + +void AccessibilityZoomGesture::HandleSTZoomOneFingerTapStateDown(MMI::PointerEvent &event) +{ + zoomGestureEventHandler_->RemoveEvent(MULTI_TAP_MSG); + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != 1 || !IsDownValid(lastDownEvent_, std::make_shared(event))) { + SendCacheEventsToNext(); + TransferState(INIT); + return; + } + + lastDownEvent_ = std::make_shared(event); + TransferState(ONE_FINGER_DOWN); + zoomGestureEventHandler_->SendEvent(MULTI_TAP_MSG, 0, MULTI_TAP_TIMER); + zoomGestureEventHandler_->SendEvent(WAIT_ANOTHER_FINGER_DOWN_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); +} + +void AccessibilityZoomGesture::HandleZoomSlidingStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + size_t pointerCount = event.GetPointerIds().size(); + CalcFocusCoordinate(event, lastCenter); + if (pointerCount == POINTER_COUNT_2) { + baseDistance_ = lastDistance_ = CalcSeparationDistance(event); + } +} + +void AccessibilityZoomGesture::HandleZoomSlidingStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + size_t pointerCount = event.GetPointerIds().size(); + ZOOM_FOCUS_COORDINATE coordinate = {0.0f, 0.0f}; + CalcFocusCoordinate(event, coordinate); + if (pointerCount != POINTER_COUNT_2) { + RecognizeScroll(coordinate); + } else { + if (magnificationMode_ == FULL_SCREEN_MAGNIFICATION) { + RecognizeScroll(coordinate); + RecognizeScale(event); + } else { + if (!RecognizeScale(event)) { + RecognizeScroll(coordinate); + } + } + } +} + +void AccessibilityZoomGesture::HandleZoomSlidingStateUp(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount == POINTER_COUNT_1) { + TransferState(INIT); + } + if (pointerCount == POINTER_COUNT_3) { + baseDistance_ = lastDistance_ = CalcSeparationDistance(event); + } + CalcFocusCoordinate(event, lastCenter); +} + +void AccessibilityZoomGesture::HandleTDReadyInitStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != 1) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + + lastTripleTapEvents_[0] = std::make_shared(event); + zoomGestureEventHandler_->SendEvent(WAIT_ANOTHER_FINGER_DOWN_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + TransferState(ONE_FINGER_DOWN); +} + +void AccessibilityZoomGesture::HandleTDReadyOneFingerDownStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != POINTER_COUNT_2) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + + lastTripleTapEvents_[POINTER_COUNT_1] = std::make_shared(event); + zoomGestureEventHandler_->SendEvent(WAIT_ANOTHER_FINGER_DOWN_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + TransferState(TWO_FINGER_DOWN); +} + +void AccessibilityZoomGesture::HandleTDReadyOneFingerDownStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + int32_t pId = event.GetPointerId(); + if (pId > POINTER_COUNT_2 || !IsMoveValid(lastTripleTapEvents_[pId], std::make_shared(event))) { + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + } +} + +void AccessibilityZoomGesture::HandleTDReadyTwoFingersDownStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != POINTER_COUNT_3) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + + lastTripleTapEvents_[POINTER_COUNT_2] = std::make_shared(event); + zoomGestureEventHandler_->SendEvent(MULTI_TAP_MSG, 0, MULTI_TAP_TIMER); + TransferState(THREE_FINGER_DOWN); +} + +void AccessibilityZoomGesture::HandleTDReadyTwoFingersDownStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + int32_t pId = event.GetPointerId(); + if (pId > POINTER_COUNT_2 || !IsMoveValid(lastTripleTapEvents_[pId], std::make_shared(event))) { + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + } +} + +void AccessibilityZoomGesture::HandleTDReadyThreeFingersDownStateUp(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount == POINTER_COUNT_1) { + TransferState(THREE_FINGER_TAP); + } else if (pointerCount > POINTER_COUNT_3) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + } +} + +void AccessibilityZoomGesture::HandleTDReadyThreeFingersDownStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + int32_t pId = event.GetPointerId(); + if (pId > POINTER_COUNT_2 || !IsMoveValid(lastTripleTapEvents_[pId], std::make_shared(event))) { + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + } +} + +void AccessibilityZoomGesture::HandleTDReadyThreeFingersTapStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + zoomGestureEventHandler_->RemoveEvent(MULTI_TAP_MSG); + if (event.GetPointerId() < POINTER_COUNT_3) { + lastTripleTapEvents_[event.GetPointerId()] = std::make_shared(event); + } + uint32_t pointerSize = event.GetPointerIds().size(); + if (pointerSize < POINTER_COUNT_3) { + zoomGestureEventHandler_->SendEvent(WAIT_ANOTHER_FINGER_DOWN_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + } else if (pointerSize == POINTER_COUNT_3) { + zoomGestureEventHandler_->SendEvent(HOLDING_MSG, 0, LONG_PRESS_TIMER); + TransferState(THREE_FINGER_TAP_THEN_DOWN); + } else { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + } +} + +void AccessibilityZoomGesture::HandleTDReadyThreeFingersTapStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + int32_t pId = event.GetPointerId(); + if (pId > POINTER_COUNT_2 || !IsMoveValid(lastTripleTapEvents_[pId], std::make_shared(event))) { + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + } +} + +void AccessibilityZoomGesture::HandleTDReadyThreeFingersContinueDownStateUp(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + zoomGestureEventHandler_->RemoveEvent(HOLDING_MSG); + + uint32_t pointerSize = event.GetPointerIds().size(); + if (pointerSize == POINTER_COUNT_1) { + int32_t anchorX = 0; + int32_t anchorY = 0; + for (int i = 0; i < POINTER_COUNT_3; i++) { + MMI::PointerEvent::PointerItem pointerItem; + lastTripleTapEvents_[i]->GetPointerItem(lastTripleTapEvents_[i]->GetPointerId(), pointerItem); + anchorX += pointerItem.GetDisplayX(); + anchorY += pointerItem.GetDisplayY(); + } + OnZoom(anchorX / POINTER_COUNT_3, anchorY / POINTER_COUNT_3, true); + ClearCacheEventsAndMsg(); + TransferState(INIT); + } else if (pointerSize > POINTER_COUNT_3) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + } +} + +void AccessibilityZoomGesture::HandleTDReadyThreeFingersContinueDownStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + bool isMoveValid = false; + for (int i = 0; i < POINTER_COUNT_3; i++) { + isMoveValid |= IsMoveValid(lastTripleTapEvents_[i], std::make_shared(event)); + } + if (event.GetPointerIds().size() > POINTER_COUNT_3 || !isMoveValid) { + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + } +} + +void AccessibilityZoomGesture::HandleMenuSlidingStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + if (event.GetPointerId() == 0) { + if (!lastDownEvent_) { + lastDownEvent_ = std::make_shared(event); + } + MMI::PointerEvent::PointerItem lastDownItem; + lastDownEvent_->GetPointerItem(lastDownEvent_->GetPointerId(), lastDownItem); + MMI::PointerEvent::PointerItem currentItem; + event.GetPointerItem(event.GetPointerId(), currentItem); + int32_t deltaX = currentItem.GetDisplayX() - lastDownItem.GetDisplayX(); + int32_t deltaY = currentItem.GetDisplayY() - lastDownItem.GetDisplayY(); + menuManager_->MoveMenuWindow(deltaX, deltaY); + + lastDownEvent_ = std::make_shared(event); + } +} + +void AccessibilityZoomGesture::HandleMenuSlidingStateUp(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + if (event.GetPointerId() != 0) { + return; + } + if (menuManager_ != nullptr) { + menuManager_->AttachToEdge(); + } + if (event.GetPointerIds().size() > POINTER_COUNT_1) { + TransferState(INVALID); + } else { + TransferState(INIT); + } +} + +void AccessibilityZoomGesture::HandleHotAreaSlidingStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + if (event.GetPointerId() == 0) { + if (!lastDownEvent_) { + lastDownEvent_ = std::make_shared(event); + } + MMI::PointerEvent::PointerItem lastDownItem; + lastDownEvent_->GetPointerItem(lastDownEvent_->GetPointerId(), lastDownItem); + MMI::PointerEvent::PointerItem currentItem; + event.GetPointerItem(event.GetPointerId(), currentItem); + int32_t deltaX = currentItem.GetDisplayX() - lastDownItem.GetDisplayX(); + int32_t deltaY = currentItem.GetDisplayY() - lastDownItem.GetDisplayY(); + windowMagnificationManager_->MoveMagnificationWindow(deltaX, deltaY); + + lastDownEvent_ = std::make_shared(event); + } +} + +void AccessibilityZoomGesture::HandleHotAreaSlidingStateUp(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + if (event.GetPointerId() != 0) { + return; + } + if (event.GetPointerIds().size() > POINTER_COUNT_1) { + TransferState(INVALID); + } else { + TransferState(INIT); + } +} + +void AccessibilityZoomGesture::HandleHoldStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CalcFocusCoordinate(event, lastCenter); +} + +void AccessibilityZoomGesture::HandleHoldStateUp(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + if (event.GetPointerIds().size() == POINTER_COUNT_1) { + OffZoom(); + TransferState(INIT); + } + CalcFocusCoordinate(event, lastCenter); +} + +void AccessibilityZoomGesture::HandleHoldStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + ZOOM_FOCUS_COORDINATE coordinate = {0.0f, 0.0f}; + CalcFocusCoordinate(event, coordinate); + RecognizeScroll(coordinate); +} + +void AccessibilityZoomGesture::HandleTDZoomInitStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != POINTER_COUNT_1) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + MMI::PointerEvent::PointerItem pointerItem; + event.GetPointerItem(event.GetPointerId(), pointerItem); + if (magnificationMode_ == FULL_SCREEN_MAGNIFICATION) { + gestureType_ = fullScreenManager_->CheckTapOnHotArea(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); + } else { + isTapOnWindowHotArea_ = windowMagnificationManager_->IsTapOnHotArea(pointerItem.GetDisplayX(), + pointerItem.GetDisplayY()); + isTapOnWindow_ = windowMagnificationManager_->IsTapOnMagnificationWindow(pointerItem.GetDisplayX(), + pointerItem.GetDisplayY()); + } + isTapOnMenu_ = menuManager_->IsTapOnMenu(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); + + lastDownEvent_ = std::make_shared(event); + lastTripleTapEvents_[0] = std::make_shared(event); + if (isTapOnWindowHotArea_) { + zoomGestureEventHandler_->SendEvent(HOT_AREA_SLIDING_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + } else if (isTapOnMenu_) { + zoomGestureEventHandler_->SendEvent(MENU_SLIDING_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + } else { + zoomGestureEventHandler_->SendEvent(WAIT_ANOTHER_FINGER_DOWN_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + } + TransferState(ONE_FINGER_DOWN); +} + +void AccessibilityZoomGesture::HandleTDZoomOneFingerDownStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + gestureType_ = INVALID_GESTURE_TYPE; + + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + zoomGestureEventHandler_->RemoveEvent(HOT_AREA_SLIDING_MSG); + zoomGestureEventHandler_->RemoveEvent(MENU_SLIDING_MSG); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != POINTER_COUNT_2) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + MMI::PointerEvent::PointerItem pointerItem; + event.GetPointerItem(event.GetPointerId(), pointerItem); + isTapOnWindow_ = windowMagnificationManager_->IsTapOnMagnificationWindow(pointerItem.GetDisplayX(), + pointerItem.GetDisplayY()); + lastTripleTapEvents_[1] = std::make_shared(event); + TransferState(TWO_FINGER_DOWN); + if (magnificationMode_ != FULL_SCREEN_MAGNIFICATION && !isTapOnWindow_) { + zoomGestureEventHandler_->SendEvent(WAIT_ANOTHER_FINGER_DOWN_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + return; + } else { + zoomGestureEventHandler_->SendEvent(TWO_FINGER_SLIDING_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + CalcFocusCoordinate(event, lastCenter); + baseDistance_ = lastDistance_ = CalcSeparationDistance(event); + } +} + +void AccessibilityZoomGesture::HandleTDZoomOneFingerDownStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + int32_t pId = event.GetPointerId(); + if (pId > POINTER_ID_2) { + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + return; + } + if (!IsMoveValid(lastTripleTapEvents_[pId], std::make_shared(event))) { + if (isTapOnWindowHotArea_) { + ClearCacheEventsAndMsg(); + TransferState(HOT_AREA_SLIDING); + return; + } + if (isTapOnMenu_) { + ClearCacheEventsAndMsg(); + TransferState(MENU_SLIDING); + return; + } + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + } +} + +void AccessibilityZoomGesture::HandleTDZoomOneFingerDownStateUp(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != 1) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + if (menuManager_ != nullptr) { + MMI::PointerEvent::PointerItem pointerItem; + event.GetPointerItem(event.GetPointerId(), pointerItem); + if (menuManager_->IsTapOnMenu(pointerItem.GetDisplayX(), pointerItem.GetDisplayY())) { + menuManager_->OnMenuTap(); + TransferState(INIT); + ClearCacheEventsAndMsg(); + return; + } + } + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); +} + +void AccessibilityZoomGesture::HandleTDZoomTwoFingersDownStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + zoomGestureEventHandler_->RemoveEvent(TWO_FINGER_SLIDING_MSG); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount != POINTER_COUNT_3) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + + lastTripleTapEvents_[POINTER_COUNT_2] = std::make_shared(event); + zoomGestureEventHandler_->SendEvent(MULTI_TAP_MSG, 0, MULTI_TAP_TIMER); + TransferState(THREE_FINGER_DOWN); +} + +void AccessibilityZoomGesture::HandleTDZoomTwoFingersDownStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + if (event.GetPointerIds().size() != POINTER_COUNT_2) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + return; + } + int32_t pId = event.GetPointerId(); + if (IsMoveValid(lastTripleTapEvents_[pId], std::make_shared(event))) { + return; + } + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + zoomGestureEventHandler_->RemoveEvent(TWO_FINGER_SLIDING_MSG); + if (magnificationMode_ == FULL_SCREEN_MAGNIFICATION || isTapOnWindow_) { + ClearCacheEventsAndMsg(); + TransferState(SLIDING); + } else { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + } +} + + +void AccessibilityZoomGesture::HandleTDZoomThreeFingersDownStateUp(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + size_t pointerCount = event.GetPointerIds().size(); + if (pointerCount == POINTER_COUNT_1) { + TransferState(THREE_FINGER_TAP); + } else if (pointerCount > POINTER_COUNT_3) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + } +} + +void AccessibilityZoomGesture::HandleTDZoomThreeFingersDownStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + bool isMoveValid = false; + if (event.GetPointerIds().size() > POINTER_COUNT_3) { + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + return; + } + for (int i = 0; i < POINTER_COUNT_3; i++) { + isMoveValid |= IsMoveValid(lastTripleTapEvents_[i], std::make_shared(event)); + } + if (!isMoveValid) { + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + } +} + +void AccessibilityZoomGesture::HandleTDZoomThreeFingersTapStateDown(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + zoomGestureEventHandler_->RemoveEvent(WAIT_ANOTHER_FINGER_DOWN_MSG); + if (event.GetPointerId() < POINTER_COUNT_3) { + lastTripleTapEvents_[event.GetPointerId()] = std::make_shared(event); + } + uint32_t pointerSize = event.GetPointerIds().size(); + if (pointerSize < POINTER_COUNT_3) { + zoomGestureEventHandler_->SendEvent(WAIT_ANOTHER_FINGER_DOWN_MSG, 0, MULTI_FINGER_TAP_INTERVAL_TIMER); + } else if (pointerSize == POINTER_COUNT_3) { + zoomGestureEventHandler_->SendEvent(MULTI_TAP_MSG, 0, MULTI_TAP_TIMER); + TransferState(THREE_FINGER_TAP_THEN_DOWN); + } else { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + } +} + +void AccessibilityZoomGesture::HandleTDZoomThreeFingersTapStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + + int32_t pId = event.GetPointerId(); + if (pId > POINTER_ID_2) { + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + return; + } + if (!IsMoveValid(lastTripleTapEvents_[pId], std::make_shared(event))) { + uint32_t pointerSize = event.GetPointerIds().size(); + if (pointerSize == POINTER_COUNT_2 && (magnificationMode_ == FULL_SCREEN_MAGNIFICATION || isTapOnWindow_)) { + ClearCacheEventsAndMsg(); + TransferState(SLIDING); + return; + } + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + } +} + +void AccessibilityZoomGesture::HandleTDZoomThreeFingersContinueDownStateUp(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + zoomGestureEventHandler_->RemoveEvent(LONG_PRESS_MSG); + + uint32_t pointerSize = event.GetPointerIds().size(); + if (pointerSize == POINTER_COUNT_1) { + OffZoom(); + ClearCacheEventsAndMsg(); + TransferState(INIT); + } else if (pointerSize > POINTER_COUNT_3) { + SendCacheEventsToNext(); + TransferState(PASSING_THROUGH); + } +} + +void AccessibilityZoomGesture::HandleTDZoomThreeFingersContinueDownStateMove(MMI::PointerEvent &event) +{ + HILOG_DEBUG(); + CacheEvents(event); + bool isMoveValid = false; + for (int i = 0; i < POINTER_COUNT_3; i++) { + isMoveValid |= IsMoveValid(lastTripleTapEvents_[i], std::make_shared(event)); + } + if (event.GetPointerIds().size() > POINTER_COUNT_3 || !isMoveValid) { + TransferState(PASSING_THROUGH); + SendCacheEventsToNext(); + } } -// LCOV_EXCL_STOP } // namespace Accessibility } // namespace OHOS diff --git a/services/aams_ext/src/export_api.cpp b/services/aams_ext/src/export_api.cpp index 7d916f141..337c1a7e0 100644 --- a/services/aams_ext/src/export_api.cpp +++ b/services/aams_ext/src/export_api.cpp @@ -159,6 +159,11 @@ API_EXPORT OHOS::Accessibility::RetError InjectEvents( { return serviceManagerInstance.InjectEvents(gesturePath); } +API_EXPORT void OnScreenMagnificationTriggerMethodChanged(int32_t screenMagnificationTriggerMethod) +{ + HILOG_INFO(); + return serviceManagerInstance.OnScreenMagnificationTriggerMethodChanged(screenMagnificationTriggerMethod); +} API_EXPORT void OnScreenMagnificationTypeChanged(uint32_t screenMagnificationType) { HILOG_INFO(); @@ -179,6 +184,12 @@ API_EXPORT void ExtendGetMagnificationModeCallback(OHOS::Accessibility::GetMagni HILOG_INFO(); serviceManagerInstance.getMagnificationModeCallback = cb; } +API_EXPORT void ExtendGetMagnificationTriggerMethodCallback( + OHOS::Accessibility::GetMagnificationTriggerMethodCallback cb) +{ + HILOG_INFO(); + serviceManagerInstance.getMagnificationTriggerMethodCallback = cb; +} API_EXPORT void ExtendGetMagnificationScaleCallback(OHOS::Accessibility::GetMagnificationScaleCallback cb) { HILOG_INFO(); diff --git a/services/aams_ext/src/extend_service_manager.cpp b/services/aams_ext/src/extend_service_manager.cpp index 459f0f720..2f5bf31e5 100644 --- a/services/aams_ext/src/extend_service_manager.cpp +++ b/services/aams_ext/src/extend_service_manager.cpp @@ -187,6 +187,16 @@ uint64_t ExtendServiceManager::GetDefaultDisplayId() #endif } +void ExtendServiceManager::OnScreenMagnificationTriggerMethodChanged(int32_t screenMagnificationTriggerMethod) +{ + auto interceptor = AccessibilityInputInterceptor::GetInstance(); + if (!interceptor) { + HILOG_ERROR("interceptor is null."); + return; + } + interceptor->SetMagnificationTriggerMethod(screenMagnificationTriggerMethod); +} + void ExtendServiceManager::OnScreenMagnificationTypeChanged(uint32_t screenMagnificationType) { if (magnificationManager_ != nullptr) { diff --git a/services/aams_ext/src/magnification_manager.cpp b/services/aams_ext/src/magnification_manager.cpp index 64e527eb9..fcef75b38 100644 --- a/services/aams_ext/src/magnification_manager.cpp +++ b/services/aams_ext/src/magnification_manager.cpp @@ -150,10 +150,7 @@ void MagnificationManager::OnModeChanged(uint32_t mode) } Singleton::GetInstance().magnificationModeCallback(static_cast(mode)); currentMode_ = mode; - if (needShow) { - interceptor->StartMagnificationInteract(mode); - } - Singleton::GetInstance().updateInputFilterCallback(); + interceptor->SetMagnificationMode(mode); } void MagnificationManager::DisableMagnification() diff --git a/services/aams_ext/src/magnification_window.cpp b/services/aams_ext/src/magnification_window.cpp index 38780e136..f3cccc0bd 100644 --- a/services/aams_ext/src/magnification_window.cpp +++ b/services/aams_ext/src/magnification_window.cpp @@ -315,7 +315,7 @@ void MagnificationWindow::DisableMagnificationFull(bool needClear) isMagnificationShowFull_ = false; } -void MagnificationWindow::SetScaleFull(float scaleSpan) +void MagnificationWindow::SetScaleFull(float ratio) { HILOG_DEBUG(); if (window_ == nullptr) { @@ -326,9 +326,7 @@ void MagnificationWindow::SetScaleFull(float scaleSpan) HILOG_ERROR("screen param invalid."); return; } - - float ratio = scaleSpan / screenSpan_; - float tmpScale = scale_ + ratio * scale_; + float tmpScale = ratio * scale_; if (tmpScale > MAX_SCALE) { tmpScale = MAX_SCALE; @@ -821,14 +819,14 @@ void MagnificationWindow::DisableMagnification(uint32_t magnificationType, bool HILOG_DEBUG("invalid type = %{public}d", magnificationType); } -void MagnificationWindow::SetScale(uint32_t magnificationType, float scaleSpan) +void MagnificationWindow::SetScale(uint32_t magnificationType, float ratio) { if (magnificationType == FULL_SCREEN_MAGNIFICATION) { - SetScaleFull(scaleSpan); + SetScaleFull(ratio); return; } if (magnificationType == WINDOW_MAGNIFICATION) { - SetScalePart(scaleSpan); + SetScalePart(ratio); return; } HILOG_DEBUG("invalid type = %{public}d", magnificationType); diff --git a/services/aams_ext/test/BUILD.gn b/services/aams_ext/test/BUILD.gn index bb4a029b4..754f16de3 100644 --- a/services/aams_ext/test/BUILD.gn +++ b/services/aams_ext/test/BUILD.gn @@ -309,12 +309,12 @@ ohos_unittest("accessibility_zoom_gesture_test") { "../src/touch_exploration_multi_finger_gesture.cpp", "../src/touch_exploration_single_finger_gesture.cpp", "../src/window_magnification_gesture.cpp", - "../src/window_magnification_manager.cpp", "mock/src/mock_accessibility_display_manager.cpp", "mock/src/mock_accessibility_event_transmission.cpp", "mock/src/mock_accessibility_extend_power_manager.cpp", "mock/src/mock_extend_service_manager.cpp", "mock/src/mock_full_screen_magnification_manager.cpp", + "mock/src/mock_window_magnification_manager.cpp", "mock/src/mock_magnification_menu_manager.cpp", "mock/src/mock_system_ability.cpp", "unittest/accessibility_zoom_gesture_test.cpp", diff --git a/services/aams_ext/test/unittest/accessibility_zoom_gesture_test.cpp b/services/aams_ext/test/unittest/accessibility_zoom_gesture_test.cpp index 8a2e4533d..490eb2472 100644 --- a/services/aams_ext/test/unittest/accessibility_zoom_gesture_test.cpp +++ b/services/aams_ext/test/unittest/accessibility_zoom_gesture_test.cpp @@ -19,7 +19,9 @@ #include "accessibility_ut_helper.h" #include "accessibility_zoom_gesture.h" #include "full_screen_magnification_manager.h" +#include "window_magnification_manager.h" #include "magnification_menu_manager.h" +#include "magnification_def.h" using namespace testing; using namespace testing::ext; @@ -28,6 +30,14 @@ namespace OHOS { namespace Accessibility { namespace { constexpr uint32_t TRIPLE_TAP_COUNT = 3; + constexpr uint32_t DOUBLE_TAP_COUNT = 2; + constexpr int32_t SLEEP_MS_2 = 2; + constexpr int32_t POINT_ID_0 = 0; + constexpr int32_t POINT_ID_1 = 1; + constexpr int32_t POINT_ID_2 = 2; + constexpr int32_t INVALID_POINTER_ACTION = -1; + constexpr int32_t READY_STATE = 0; + constexpr int32_t ZOOM_STATE = 1; } // namespace class AccessibilityZoomGestureUnitTest : public ::testing::Test { public: @@ -41,9 +51,16 @@ public: void SetUp() override; void TearDown() override; std::shared_ptr CreatePointerEvent(int32_t sourceType, int32_t pointerAction); + std::shared_ptr CreatePointerEvent(int32_t pointerAction, + std::vector &points, int32_t pointerId); + void SetPointerItem(MMI::PointerEvent::PointerItem &point, int32_t id, int32_t x, int32_t y); void TripleTaps(); + void DoubleTapsWithThreeFingers(); std::shared_ptr zoomGesture_ = nullptr; + std::shared_ptr fullScreenManager_ = nullptr; + std::shared_ptr windowMagnificationManager_ = nullptr; + std::shared_ptr menuManager_ = nullptr; }; void AccessibilityZoomGestureUnitTest::SetUpTestCase() @@ -59,15 +76,23 @@ void AccessibilityZoomGestureUnitTest::TearDownTestCase() void AccessibilityZoomGestureUnitTest::SetUp() { GTEST_LOG_(INFO) << "SetUp"; - std::shared_ptr manager = std::make_shared(); - std::shared_ptr menuManager = std::make_shared(); - zoomGesture_ = std::make_shared(manager, menuManager); + fullScreenManager_ = std::make_shared(); + windowMagnificationManager_ = std::make_shared(); + menuManager_ = std::make_shared(); + zoomGesture_ = std::make_shared(fullScreenManager_, + windowMagnificationManager_, menuManager_); + AccessibilityAbilityHelper::GetInstance().ClearZoom(); } void AccessibilityZoomGestureUnitTest::TearDown() { GTEST_LOG_(INFO) << "TearDown"; + AccessibilityAbilityHelper::GetInstance().ClearZoom(); + AccessibilityAbilityHelper::GetInstance().ClearTouchEventActionVector(); zoomGesture_ = nullptr; + fullScreenManager_ = nullptr; + windowMagnificationManager_ = nullptr; + menuManager_ = nullptr; } std::shared_ptr AccessibilityZoomGestureUnitTest::CreatePointerEvent(int32_t sourceType, @@ -82,27 +107,79 @@ std::shared_ptr AccessibilityZoomGestureUnitTest::CreatePoint return event; } +std::shared_ptr AccessibilityZoomGestureUnitTest::CreatePointerEvent(int32_t pointerAction, + std::vector &points, int32_t pointerId) +{ + std::shared_ptr event = MMI::PointerEvent::Create(); + if (!event) { + return nullptr; + } + for (auto &point : points) { + event->AddPointerItem(point); + } + event->SetPointerId(pointerId); + event->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN); + event->SetPointerAction(pointerAction); + return event; +} + +void AccessibilityZoomGestureUnitTest::SetPointerItem(MMI::PointerEvent::PointerItem &point, + int32_t id, int32_t x, int32_t y) +{ + point.SetPointerId(id); + point.SetDisplayX(x); + point.SetDisplayY(y); +} + void AccessibilityZoomGestureUnitTest::TripleTaps() { EXPECT_TRUE(zoomGesture_ != nullptr); for (uint32_t count = 0; count < TRIPLE_TAP_COUNT; count++) { - // Pointer down std::shared_ptr eventDown = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, MMI::PointerEvent::POINTER_ACTION_DOWN); EXPECT_TRUE(eventDown != nullptr); MMI::PointerEvent::PointerItem item; + item.SetDisplayX(100); + item.SetDisplayY(100); eventDown->AddPointerItem(item); zoomGesture_->OnPointerEvent(*eventDown); - // Pointer up std::shared_ptr eventUp = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, MMI::PointerEvent::POINTER_ACTION_UP); EXPECT_TRUE(eventUp != nullptr); MMI::PointerEvent::PointerItem item1; + item1.SetDisplayX(100); + item1.SetDisplayY(100); eventUp->AddPointerItem(item1); zoomGesture_->OnPointerEvent(*eventUp); } } +void AccessibilityZoomGestureUnitTest::DoubleTapsWithThreeFingers() +{ + EXPECT_TRUE(zoomGesture_ != nullptr); + zoomGesture_->SetGestureMode(THREE_FINGER_DOUBLE_TAP_MODE); + for (uint32_t count = 0; count < DOUBLE_TAP_COUNT; count++) { + std::vector points = {}; + MMI::PointerEvent::PointerItem point1 = {}; + SetPointerItem(point1, POINT_ID_0, 10, 10); + MMI::PointerEvent::PointerItem point2 = {}; + SetPointerItem(point2, POINT_ID_1, 20, 20); + MMI::PointerEvent::PointerItem point3 = {}; + SetPointerItem(point3, POINT_ID_2, 30, 30); + points.emplace_back(point1); + points.emplace_back(point2); + points.emplace_back(point3); + std::shared_ptr eventDown = CreatePointerEvent( + MMI::PointerEvent::POINTER_ACTION_DOWN, points, POINT_ID_2); + EXPECT_TRUE(eventDown != nullptr); + zoomGesture_->OnPointerEvent(*eventDown); + std::shared_ptr eventUp = CreatePointerEvent( + MMI::PointerEvent::POINTER_ACTION_UP, points, POINT_ID_2); + EXPECT_TRUE(eventUp != nullptr); + zoomGesture_->OnPointerEvent(*eventUp); + } +} + /** * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_001 * @tc.name: OnPointerEvent @@ -467,5 +544,562 @@ HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnP GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_011 end"; } + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_012 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with invalid pointer action + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_012, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_012 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + std::shared_ptr event = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + INVALID_POINTER_ACTION); + EXPECT_TRUE(event != nullptr); + AccessibilityAbilityHelper::GetInstance().ClearTouchEventActionVector(); + zoomGesture_->OnPointerEvent(*event); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_012 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_013 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with levitate move action + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_013, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_013 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + std::shared_ptr event = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_LEVITATE_MOVE); + EXPECT_TRUE(event != nullptr); + AccessibilityAbilityHelper::GetInstance().ClearTouchEventActionVector(); + zoomGesture_->OnPointerEvent(*event); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_013 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_014 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with scrollshot pointer id + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_014, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_014 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + std::shared_ptr event = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_DOWN); + EXPECT_TRUE(event != nullptr); + event->SetPointerId(SCROLL_SHOT_POINTER_ID); + AccessibilityAbilityHelper::GetInstance().ClearTouchEventActionVector(); + zoomGesture_->OnPointerEvent(*event); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_014 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_DestroyEvents_001 + * @tc.name: DestroyEvents + * @tc.desc: Test function DestroyEvents + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_DestroyEvents_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_DestroyEvents_001 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + zoomGesture_->DestroyEvents(); + zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_FALSE(zoomState); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_DestroyEvents_001 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_ShieldZoomGesture_001 + * @tc.name: ShieldZoomGesture + * @tc.desc: Test function ShieldZoomGesture with true state + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_ShieldZoomGesture_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_ShieldZoomGesture_001 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + zoomGesture_->ShieldZoomGesture(true); + zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_FALSE(zoomState); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_ShieldZoomGesture_001 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_ShieldZoomGesture_002 + * @tc.name: ShieldZoomGesture + * @tc.desc: Test function ShieldZoomGesture with false state + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_ShieldZoomGesture_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_ShieldZoomGesture_002 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + zoomGesture_->ShieldZoomGesture(false); + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_ShieldZoomGesture_002 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_ShieldZoomGesture_003 + * @tc.name: ShieldZoomGesture + * @tc.desc: Test function ShieldZoomGesture called twice with same state + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_ShieldZoomGesture_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_ShieldZoomGesture_003 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + zoomGesture_->ShieldZoomGesture(true); + zoomGesture_->ShieldZoomGesture(true); + int32_t zoomState = zoomGesture_->GetZoomState(); + EXPECT_EQ(zoomState, READY_STATE); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_ShieldZoomGesture_003 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_GetWindowParam_001 + * @tc.name: GetWindowParam + * @tc.desc: Test function GetWindowParam with needRefresh true + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_GetWindowParam_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_GetWindowParam_001 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + zoomGesture_->GetWindowParam(true); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_GetWindowParam_001 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_GetWindowParam_002 + * @tc.name: GetWindowParam + * @tc.desc: Test function GetWindowParam with needRefresh false + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_GetWindowParam_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_GetWindowParam_002 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + zoomGesture_->GetWindowParam(false); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_GetWindowParam_002 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_StartMagnificationInteract_001 + * @tc.name: StartMagnificationInteract + * @tc.desc: Test function StartMagnificationInteract + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_StartMagnificationInteract_001, + TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_StartMagnificationInteract_001 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + zoomGesture_->StartMagnificationInteract(); + int32_t zoomState = zoomGesture_->GetZoomState(); + EXPECT_EQ(zoomState, ZOOM_STATE); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_StartMagnificationInteract_001 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_SetGestureMode_001 + * @tc.name: SetGestureMode + * @tc.desc: Test function SetGestureMode with SINGLE_FINGER_TRIPLE_TAP_MODE + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_SetGestureMode_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_SetGestureMode_001 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + zoomGesture_->SetGestureMode(SINGLE_FINGER_TRIPLE_TAP_MODE); + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_SetGestureMode_001 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_SetGestureMode_002 + * @tc.name: SetGestureMode + * @tc.desc: Test function SetGestureMode with THREE_FINGER_DOUBLE_TAP_MODE + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_SetGestureMode_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_SetGestureMode_002 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + zoomGesture_->SetGestureMode(THREE_FINGER_DOUBLE_TAP_MODE); + DoubleTapsWithThreeFingers(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_SetGestureMode_002 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_SetMagnificationMode_001 + * @tc.name: SetMagnificationMode + * @tc.desc: Test function SetMagnificationMode with FULL_SCREEN_MAGNIFICATION + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_SetMagnificationMode_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_SetMagnificationMode_001 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + zoomGesture_->SetMagnificationMode(FULL_SCREEN_MAGNIFICATION); + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_SetMagnificationMode_001 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_SetMagnificationMode_002 + * @tc.name: SetMagnificationMode + * @tc.desc: Test function SetMagnificationMode with WINDOW_MAGNIFICATION + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_SetMagnificationMode_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_SetMagnificationMode_002 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + zoomGesture_->SetMagnificationMode(WINDOW_MAGNIFICATION); + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_SetMagnificationMode_002 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_DisableGesture_001 + * @tc.name: DisableGesture + * @tc.desc: Test function DisableGesture + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_DisableGesture_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_DisableGesture_001 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + zoomGesture_->DisableGesture(); + zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_FALSE(zoomState); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_DisableGesture_001 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_GetZoomState_001 + * @tc.name: GetZoomState + * @tc.desc: Test function GetZoomState in ready state + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_GetZoomState_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_GetZoomState_001 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + int32_t zoomState = zoomGesture_->GetZoomState(); + EXPECT_EQ(zoomState, READY_STATE); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_GetZoomState_001 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_GetZoomState_002 + * @tc.name: GetZoomState + * @tc.desc: Test function GetZoomState in zoom state + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_GetZoomState_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_GetZoomState_002 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + TripleTaps(); + int32_t zoomState = zoomGesture_->GetZoomState(); + EXPECT_EQ(zoomState, ZOOM_STATE); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_GetZoomState_002 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_015 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with non-touchscreen source type in ready state + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_015, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_015 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + std::shared_ptr event = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_MOUSE, + MMI::PointerEvent::POINTER_ACTION_DOWN); + EXPECT_TRUE(event != nullptr); + AccessibilityAbilityHelper::GetInstance().ClearTouchEventActionVector(); + zoomGesture_->OnPointerEvent(*event); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_015 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_016 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with three finger double tap to start zoom + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_016, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_016 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + zoomGesture_->SetGestureMode(THREE_FINGER_DOUBLE_TAP_MODE); + DoubleTapsWithThreeFingers(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + DoubleTapsWithThreeFingers(); + zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_FALSE(zoomState); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_016 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_017 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with two finger move in sliding state + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_017, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_017 start"; + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + std::shared_ptr eventDown = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_DOWN); + EXPECT_TRUE(eventDown != nullptr); + MMI::PointerEvent::PointerItem item1; + item1.SetDisplayX(10); + item1.SetDisplayY(20); + item1.SetPointerId(POINT_ID_0); + eventDown->AddPointerItem(item1); + MMI::PointerEvent::PointerItem item2; + item2.SetDisplayX(40); + item2.SetDisplayY(20); + item2.SetPointerId(POINT_ID_1); + eventDown->AddPointerItem(item2); + zoomGesture_->OnPointerEvent(*eventDown); + std::shared_ptr eventMove = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_MOVE); + EXPECT_TRUE(eventMove != nullptr); + MMI::PointerEvent::PointerItem item3; + item3.SetDisplayX(0); + item3.SetDisplayY(50); + item3.SetPointerId(POINT_ID_0); + eventMove->AddPointerItem(item3); + MMI::PointerEvent::PointerItem item4; + item4.SetDisplayX(70); + item4.SetDisplayY(50); + item4.SetPointerId(POINT_ID_1); + eventMove->AddPointerItem(item4); + zoomGesture_->OnPointerEvent(*eventMove); + zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_017 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_018 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with hold state down and move + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_018, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_018 start"; + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + std::shared_ptr eventDown = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_DOWN); + EXPECT_TRUE(eventDown != nullptr); + MMI::PointerEvent::PointerItem item; + item.SetDisplayX(100); + item.SetDisplayY(100); + eventDown->AddPointerItem(item); + zoomGesture_->OnPointerEvent(*eventDown); + std::shared_ptr eventMove = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_MOVE); + EXPECT_TRUE(eventMove != nullptr); + MMI::PointerEvent::PointerItem itemMove; + itemMove.SetDisplayX(110); + itemMove.SetDisplayY(110); + eventMove->AddPointerItem(itemMove); + zoomGesture_->OnPointerEvent(*eventMove); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_018 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_019 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with hold state up to exit zoom + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_019, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_019 start"; + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + std::shared_ptr eventDown = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_DOWN); + EXPECT_TRUE(eventDown != nullptr); + MMI::PointerEvent::PointerItem item; + item.SetDisplayX(100); + item.SetDisplayY(100); + eventDown->AddPointerItem(item); + zoomGesture_->OnPointerEvent(*eventDown); + std::shared_ptr eventUp = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_UP); + EXPECT_TRUE(eventUp != nullptr); + MMI::PointerEvent::PointerItem itemUp; + itemUp.SetDisplayX(100); + itemUp.SetDisplayY(100); + eventUp->AddPointerItem(itemUp); + zoomGesture_->OnPointerEvent(*eventUp); + sleep(SLEEP_MS_2); + zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_FALSE(zoomState); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_019 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_020 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with passing through state + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_020, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_020 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + std::shared_ptr eventDown = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_DOWN); + EXPECT_TRUE(eventDown != nullptr); + MMI::PointerEvent::PointerItem item1; + item1.SetDisplayX(10); + item1.SetDisplayY(20); + eventDown->AddPointerItem(item1); + MMI::PointerEvent::PointerItem item2; + item2.SetDisplayX(40); + item2.SetDisplayY(20); + eventDown->AddPointerItem(item2); + zoomGesture_->OnPointerEvent(*eventDown); + AccessibilityAbilityHelper::GetInstance().ClearTouchEventActionVector(); + std::shared_ptr eventUp = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_UP); + EXPECT_TRUE(eventUp != nullptr); + zoomGesture_->OnPointerEvent(*eventUp); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_020 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_021 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with hot area sliding state + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_021, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_021 start"; + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + AccessibilityAbilityHelper::GetInstance().SetTapOnHotArea(true); + std::shared_ptr eventDown = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_DOWN); + EXPECT_TRUE(eventDown != nullptr); + MMI::PointerEvent::PointerItem item1; + item1.SetDisplayX(10); + item1.SetDisplayY(20); + eventDown->AddPointerItem(item1); + zoomGesture_->OnPointerEvent(*eventDown); + std::shared_ptr eventMove = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_MOVE); + EXPECT_TRUE(eventMove != nullptr); + MMI::PointerEvent::PointerItem itemMove; + itemMove.SetDisplayX(200); + itemMove.SetDisplayY(200); + eventMove->AddPointerItem(itemMove); + zoomGesture_->OnPointerEvent(*eventMove); + std::shared_ptr eventUp = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_UP); + EXPECT_TRUE(eventUp != nullptr); + MMI::PointerEvent::PointerItem itemUp; + itemUp.SetDisplayX(200); + itemUp.SetDisplayY(200); + eventUp->AddPointerItem(itemUp); + zoomGesture_->OnPointerEvent(*eventUp); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_021 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_022 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with menu sliding state + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_022, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_022 start"; + TripleTaps(); + bool zoomState = AccessibilityAbilityHelper::GetInstance().GetZoomState(); + EXPECT_TRUE(zoomState); + AccessibilityAbilityHelper::GetInstance().SetTapOnMenu(true); + std::shared_ptr eventDown = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_DOWN); + EXPECT_TRUE(eventDown != nullptr); + MMI::PointerEvent::PointerItem item1; + item1.SetDisplayX(10); + item1.SetDisplayY(20); + eventDown->AddPointerItem(item1); + zoomGesture_->OnPointerEvent(*eventDown); + std::shared_ptr eventMove = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_MOVE); + EXPECT_TRUE(eventMove != nullptr); + MMI::PointerEvent::PointerItem itemMove; + itemMove.SetDisplayX(200); + itemMove.SetDisplayY(200); + eventMove->AddPointerItem(itemMove); + zoomGesture_->OnPointerEvent(*eventMove); + std::shared_ptr eventUp = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_UP); + EXPECT_TRUE(eventUp != nullptr); + MMI::PointerEvent::PointerItem itemUp; + itemUp.SetDisplayX(200); + itemUp.SetDisplayY(200); + eventUp->AddPointerItem(itemUp); + zoomGesture_->OnPointerEvent(*eventUp); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_022 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_023 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with levitate in window action + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_023, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_023 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + std::shared_ptr event = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_LEVITATE_IN_WINDOW); + EXPECT_TRUE(event != nullptr); + AccessibilityAbilityHelper::GetInstance().ClearTouchEventActionVector(); + zoomGesture_->OnPointerEvent(*event); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_023 end"; +} + +/** + * @tc.number: AccessibilityZoomGesture_Unittest_OnPointerEvent_024 + * @tc.name: OnPointerEvent + * @tc.desc: Test function OnPointerEvent with levitate out window action + */ +HWTEST_F(AccessibilityZoomGestureUnitTest, AccessibilityZoomGesture_Unittest_OnPointerEvent_024, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_024 start"; + EXPECT_TRUE(zoomGesture_ != nullptr); + std::shared_ptr event = CreatePointerEvent(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, + MMI::PointerEvent::POINTER_ACTION_LEVITATE_OUT_WINDOW); + EXPECT_TRUE(event != nullptr); + AccessibilityAbilityHelper::GetInstance().ClearTouchEventActionVector(); + zoomGesture_->OnPointerEvent(*event); + GTEST_LOG_(INFO) << "AccessibilityZoomGesture_Unittest_OnPointerEvent_024 end"; +} } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/services/multiuser/test/mock/src/mock_accessible_ability_manager_service.cpp b/services/multiuser/test/mock/src/mock_accessible_ability_manager_service.cpp index 051131bca..734cbdc3f 100644 --- a/services/multiuser/test/mock/src/mock_accessible_ability_manager_service.cpp +++ b/services/multiuser/test/mock/src/mock_accessible_ability_manager_service.cpp @@ -3828,6 +3828,23 @@ uint32_t MockAccessibleAbilityManagerService::GetMagnificationType() return config->GetScreenMagnificationType(); } +int32_t AccessibleAbilityManagerService::GetMagnificationTriggerMethod() +{ + HILOG_DEBUG(); + sptr accountData = GetCurrentAccountData(); + if (accountData == nullptr) { + HILOG_ERROR("accountData is nullptr"); + return 0; + } + + std::shared_ptr config = accountData->GetConfig(); + if (config == nullptr) { + HILOG_ERROR("config is nullptr"); + return 0; + } + return config->GetScreenMagnificationTriggerMethod(); +} + uint32_t MockAccessibleAbilityManagerService::GetMagnificationMode() { HILOG_DEBUG(); diff --git a/services/test/mock/mock_accessible_extend_manager_service_proxy.cpp b/services/test/mock/mock_accessible_extend_manager_service_proxy.cpp index 63f0f5b5f..777f3458f 100644 --- a/services/test/mock/mock_accessible_extend_manager_service_proxy.cpp +++ b/services/test/mock/mock_accessible_extend_manager_service_proxy.cpp @@ -49,6 +49,11 @@ bool ExtendManagerServiceProxy::SetGetMagnificationStateCallback() return true; } +bool ExtendManagerServiceProxy::ExtendGetMagnificationTriggerMethodCallback() +{ + return true; +} + bool ExtendManagerServiceProxy::SetFindFocusedElementCallback() { return true; @@ -212,6 +217,12 @@ void ExtendManagerServiceProxy::OnScreenMagnificationTypeChanged(uint32_t screen return; } +void ExtendManagerServiceProxy::OnScreenMagnificationTriggerMethodChanged(int32_t screenMagnificationTriggerMethod) +{ + (void)screenMagnificationTriggerMethod; + return; +} + void ExtendManagerServiceProxy::OnScreenMagnificationStateChanged() { return; diff --git a/services/test/mock/mock_accessible_extend_manager_service_proxy.h b/services/test/mock/mock_accessible_extend_manager_service_proxy.h index 06d446f30..9de40cc1f 100644 --- a/services/test/mock/mock_accessible_extend_manager_service_proxy.h +++ b/services/test/mock/mock_accessible_extend_manager_service_proxy.h @@ -53,6 +53,7 @@ enum class ExtMethod : int32_t { GET_CLICK_POSITION, FOLLOW_FOCUSE_ELEMENT, ON_SCREEN_MAGNIFICATION_TYPE_CHANGED, + ON_SCREEN_MAGNIFICATION_TRIGGER_METHOD_CHANGE, ON_SCREEN_MAGNIFICATION_STATE_CHANGED, OFF_ZOOM_GESTURE, SET_MAGNIFICATION_STATE, @@ -86,6 +87,7 @@ public: void TransitionAnimationsCancelNotification(); int32_t TransitionAnimationsRegisterTimers(uint64_t beginTime); void TransitionAnimationsDestroyTimers(); + void OnScreenMagnificationTriggerMethodChanged(int32_t screenMagnificationTriggerMethod); void OnScreenMagnificationTypeChanged(uint32_t screenMagnificationType); void OnScreenMagnificationStateChanged(); void UnregisterDisplayListener(); @@ -107,6 +109,7 @@ public: bool SetSendPointerEventForHoverCallback(); bool SetGetDelayTimeCallback(); bool SetGetMagnificationStateCallback(); + bool ExtendGetMagnificationTriggerMethodCallback(); bool ExtendGetMagnificationModeCallback(); bool ExtendGetMagnificationScaleCallback(); bool ExtendUpdateInputFilterCallback();