1 /* 2 * Copyright (c) 2020-2021 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 GRAPHIC_LITE_POINTER_INPUT_DEVICE_H 17 #define GRAPHIC_LITE_POINTER_INPUT_DEVICE_H 18 19 #include "hal_tick.h" 20 #include "dock/input_device.h" 21 #include "components/ui_view_group.h" 22 23 namespace OHOS { 24 /** @brief A pointer input device. */ 25 class PointerInputDevice : public InputDevice { 26 public: PointerInputDevice()27 PointerInputDevice() 28 : touchableView_(nullptr), draggableView_(nullptr), targetView_(nullptr), lastPos_({0, 0}), 29 dragLastPos_({0, 0}), curPos_({ 0, 0 }), dragStep_({ 0, 0 }), dragLen_({ 0, 0 }), pressState_(false), 30 pressSent_(false), longPressSent_(false), cancelSent_(false), isDragging_(false), needClick_(true), 31 pressTimeStamp_(0) 32 {} ~PointerInputDevice()33 virtual ~PointerInputDevice() {} 34 35 protected: 36 void DispatchEvent(const DeviceData& data) override; 37 void OnViewLifeEvent() override; 38 39 private: 40 UIView* touchableView_; 41 UIView* draggableView_; 42 UIView* targetView_; 43 Point lastPos_; 44 Point dragLastPos_; 45 Point curPos_; 46 Point dragStep_; 47 Point dragLen_; 48 bool pressState_; 49 bool pressSent_; 50 bool longPressSent_; 51 bool cancelSent_; 52 bool isDragging_; 53 bool needClick_; 54 uint32_t pressTimeStamp_; 55 56 void DispatchPressEvent(UIViewGroup* rootView); 57 void DispatchReleaseEvent(UIViewGroup* rootView); 58 void DispatchDragStartEvent(); 59 void DispatchDragEndEvent(); 60 void DispatchDragEvent(); 61 void DispatchLongPressEvent(uint32_t elapse); 62 void DispatchCancelEvent(); 63 bool ProcessReleaseEvent(); 64 void UpdateEventViews(UIView* view); GetDraggableView(UIView * targetView)65 UIView* GetDraggableView(UIView* targetView) const 66 { 67 UIView* tempView = targetView; 68 while ((tempView != nullptr) && tempView->IsDragParentInstead()) { 69 tempView = tempView->GetParent(); 70 } 71 if ((tempView == nullptr) || !tempView->IsDraggable()) { 72 return nullptr; 73 } 74 return tempView; 75 } 76 }; 77 }; // namespace OHOS 78 #endif // GRAPHIC_LITE_POINTER_INPUT_DEVICE_H 79