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 23 namespace OHOS { 24 namespace Accessibility { 25 enum ACCESSIBILITY_ZOOM_STATE { 26 READY_STATE, 27 ZOOMIN_STATE, 28 SLIDING_STATE 29 }; 30 31 enum ACCESSIBILITY_ZOOM_GESTURE_MSG : uint32_t { 32 MULTI_TAP_MSG, 33 }; 34 35 struct ZOOM_FOCUS_COORDINATE { 36 float centerX; 37 float centerY; 38 }; 39 40 class AccessibilityZoomGesture : public EventTransmission { 41 public: 42 AccessibilityZoomGesture(); 43 ~AccessibilityZoomGesture() = default; 44 45 virtual bool OnPointerEvent(MMI::PointerEvent &event) override; 46 47 private: 48 class ZoomGestureEventHandler : public AppExecFwk::EventHandler { 49 public: 50 ZoomGestureEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner, 51 AccessibilityZoomGesture &zoomGesture); 52 virtual ~ZoomGestureEventHandler() = default; 53 54 virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 55 private: 56 AccessibilityZoomGesture &zoomGesture_; 57 }; 58 59 void TransferState(ACCESSIBILITY_ZOOM_STATE state); 60 void CacheEvents(MMI::PointerEvent &event); 61 void SendCacheEventsToNext(); 62 void ClearCacheEventsAndMsg(); 63 void RecognizeInReadyState(MMI::PointerEvent &event); 64 void RecognizeInZoomState(MMI::PointerEvent &event); 65 void RecognizeInSlidingState(MMI::PointerEvent &event); 66 void RecognizeScroll(MMI::PointerEvent &event); 67 void RecognizeScale(MMI::PointerEvent &event); 68 void CalcFocusCoordinate(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE &coordinate); 69 float CalcScaleSpan(MMI::PointerEvent &event, ZOOM_FOCUS_COORDINATE coordinate); 70 bool IsDownValid(); 71 bool IsUpValid(); 72 bool IsTripleTaps(); 73 void OnTripleTaps(MMI::PointerEvent &event); 74 int64_t CalcIntervalTime(std::shared_ptr<MMI::PointerEvent> firstEvent, 75 std::shared_ptr<MMI::PointerEvent> secondEvent); 76 float CalcSeparationDistance(std::shared_ptr<MMI::PointerEvent> firstEvent, 77 std::shared_ptr<MMI::PointerEvent> secondEvent); 78 void OnZoom(int32_t centerX, int32_t centerY); 79 void OffZoom(); 80 void OnScroll(float offsetX, float offsetY); 81 void OnScale(float scaleRatio, float focusX, float focusY); 82 83 bool startScaling_ = false; 84 float preSpan_ = 0; 85 float lastSpan_ = 0; 86 float lastScrollFocusX_ = 0.0f; 87 float lastScrollFocusY_ = 0.0f; 88 float tapDistance_ = 0.0f; 89 float multiTapDistance_ = 0.0f; 90 ACCESSIBILITY_ZOOM_STATE state_ = READY_STATE; 91 std::shared_ptr<MMI::PointerEvent> preLastDownEvent_ = nullptr; 92 std::shared_ptr<MMI::PointerEvent> lastDownEvent_ = nullptr; 93 std::shared_ptr<MMI::PointerEvent> preLastUpEvent_ = nullptr; 94 std::shared_ptr<MMI::PointerEvent> lastUpEvent_ = nullptr; 95 std::shared_ptr<ZoomGestureEventHandler> zoomGestureEventHandler_ = nullptr; 96 std::vector<std::shared_ptr<MMI::PointerEvent>> cacheEvents_; 97 }; 98 } // namespace Accessibility 99 } // namespace OHOS 100 #endif // ACCESSIBILITY_ZOOM_GESTURE_H