1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ACCESSIBILITY_ZOOM_GESTURE_H 17 #define ACCESSIBILITY_ZOOM_GESTURE_H 18 19 #include "accessibility_event_transmission.h" 20 #include "event_handler.h" 21 #include "pointer_event.h" 22 #include "dm_common.h" 23 #include "full_screen_magnification_manager.h" 24 #include "magnification_menu_manager.h" 25 26 namespace OHOS { 27 namespace Accessibility { 28 enum ACCESSIBILITY_ZOOM_STATE { 29 READY_STATE, 30 ZOOMIN_STATE, 31 SLIDING_STATE, 32 MENU_SLIDING_STATE, 33 DRAGGING_STATE 34 }; 35 36 enum ACCESSIBILITY_ZOOM_GESTURE_MSG : uint32_t { 37 MULTI_TAP_MSG, 38 }; 39 40 struct ZOOM_FOCUS_COORDINATE { 41 float centerX; 42 float centerY; 43 }; 44 45 class AccessibilityZoomGesture : public EventTransmission { 46 public: 47 AccessibilityZoomGesture(std::shared_ptr<FullScreenMagnificationManager> fullScreenManager, 48 std::shared_ptr<MagnificationMenuManager> menuManager); 49 ~AccessibilityZoomGesture() = default; 50 51 virtual bool OnPointerEvent(MMI::PointerEvent &event) override; 52 void DestroyEvents() override; 53 // flag = true shield zoom gesture | flag = false restore zoom gesture 54 void ShieldZoomGesture(bool state); 55 void GetWindowParam(bool needRefresh = false); 56 void StartMagnificationInteract(); 57 void DisableGesture(); GetZoomState()58 inline ACCESSIBILITY_ZOOM_STATE GetZoomState() 59 { 60 return state_; 61 } 62 63 private: 64 class ZoomGestureEventHandler : public AppExecFwk::EventHandler { 65 public: 66 ZoomGestureEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner, 67 AccessibilityZoomGesture &zoomGesture); 68 virtual ~ZoomGestureEventHandler() = default; 69 70 virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 71 private: 72 AccessibilityZoomGesture &zoomGesture_; 73 }; 74 75 void TransferState(ACCESSIBILITY_ZOOM_STATE state); 76 void CacheEvents(MMI::PointerEvent &event); 77 void SendCacheEventsToNext(); 78 void ClearCacheEventsAndMsg(); 79 void RecognizeInReadyState(MMI::PointerEvent &event); 80 void RecognizeInZoomStateDownEvent(MMI::PointerEvent &event); 81 void RecognizeInZoomStateMoveEvent(MMI::PointerEvent &event); 82 void RecognizeInZoomState(MMI::PointerEvent &event); 83 void RecognizeInSlidingState(MMI::PointerEvent &event); 84 void RecognizeInMenuSlidingState(MMI::PointerEvent &event); 85 void RecognizeInDraggingState(MMI::PointerEvent &event); 86 void RecognizeScroll(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE &coordinate); 87 void RecognizeScale(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE &coordinate); 88 void CalcFocusCoordinate(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE &coordinate); 89 float CalcScaleSpan(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE coordinate); 90 bool IsTapOnInputMethod(MMI::PointerEvent &event); 91 bool IsDownValid(); 92 bool IsUpValid(); 93 bool IsMoveValid(); 94 bool IsLongPress(); 95 bool IsKnuckles(MMI::PointerEvent &event); 96 bool IsTripleTaps(); 97 void OnTripleTap(MMI::PointerEvent &event); 98 int64_t CalcIntervalTime(std::shared_ptr<MMI::PointerEvent> firstEvent, 99 std::shared_ptr<MMI::PointerEvent> secondEvent); 100 float CalcSeparationDistance(std::shared_ptr<MMI::PointerEvent> firstEvent, 101 std::shared_ptr<MMI::PointerEvent> secondEvent); 102 void OnZoom(int32_t centerX, int32_t centerY, bool showMenu); 103 void OffZoom(); 104 void OnScroll(float offsetX, float offsetY); 105 void OnScale(float scaleSpan); 106 void Clear(); 107 void OnDrag(); 108 109 bool startScaling_ = false; 110 bool isLongPress_ = false; 111 float preSpan_ = 0.0f; 112 float lastSpan_ = 0.0f; 113 float screenSpan_ = 0.0f; 114 float lastScrollFocusX_ = 0.0f; 115 float lastScrollFocusY_ = 0.0f; 116 float tapDistance_ = 0.0f; 117 float multiTapDistance_ = 0.0f; 118 float scale_ = DEFAULT_SCALE; 119 bool isScale_ = false; 120 uint64_t screenId_ = -1; 121 uint32_t screenWidth_ = 0; 122 uint32_t screenHeight_ = 0; 123 float anchorPointX_ = 0.0f; 124 float anchorPointY_ = 0.0f; 125 int32_t centerX_ = 0; 126 int32_t centerY_ = 0; 127 float scaleRatio_ = 2.0f; 128 int32_t downPid_ = -1; 129 ACCESSIBILITY_ZOOM_STATE state_ = READY_STATE; 130 OHOS::Rosen::DisplayOrientation orientation_ = 131 OHOS::Rosen::DisplayOrientation::UNKNOWN; 132 std::shared_ptr<MMI::PointerEvent> preLastDownEvent_ = nullptr; 133 std::shared_ptr<MMI::PointerEvent> lastDownEvent_ = nullptr; 134 std::shared_ptr<MMI::PointerEvent> preLastUpEvent_ = nullptr; 135 std::shared_ptr<MMI::PointerEvent> lastUpEvent_ = nullptr; 136 std::shared_ptr<MMI::PointerEvent> currentMoveEvent_ = nullptr; 137 std::shared_ptr<MMI::PointerEvent> longPressDownEvent_ = nullptr; 138 std::shared_ptr<MMI::PointerEvent> lastSlidingEvent_ = nullptr; 139 std::shared_ptr<ZoomGestureEventHandler> zoomGestureEventHandler_ = nullptr; 140 std::vector<std::shared_ptr<MMI::PointerEvent>> cacheEvents_; 141 std::shared_ptr<FullScreenMagnificationManager> fullScreenManager_ = nullptr; 142 std::shared_ptr<MagnificationMenuManager> menuManager_ = nullptr; 143 144 std::atomic<bool> shieldZoomGestureFlag_ = false; 145 bool isTapOnMenu_ = false; 146 uint32_t gestureType_ = 0; 147 bool isTripleDown_ = false; 148 }; 149 } // namespace Accessibility 150 } // namespace OHOS 151 #endif // ACCESSIBILITY_ZOOM_GESTURE_H