• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
38 private:
39     UIView* touchableView_;
40     UIView* draggableView_;
41     UIView* targetView_;
42     Point lastPos_;
43     Point dragLastPos_;
44     Point curPos_;
45     Point dragStep_;
46     Point dragLen_;
47     bool pressState_;
48     bool pressSent_;
49     bool longPressSent_;
50     bool cancelSent_;
51     bool isDragging_;
52     bool needClick_;
53     uint32_t pressTimeStamp_;
54 
55     void DispatchPressEvent(UIViewGroup* rootView);
56     void DispatchReleaseEvent(UIViewGroup* rootView);
57     void DispatchDragStartEvent();
58     void DispatchDragEndEvent();
59     void DispatchDragEvent();
60     void DispatchLongPressEvent(uint32_t elapse);
61     void DispatchCancelEvent();
62     bool ProcessReleaseEvent();
GetDraggableView(UIView * targetView)63     UIView* GetDraggableView(UIView* targetView) const
64     {
65         UIView* tempView = targetView;
66         while ((tempView != nullptr) && tempView->IsDragParentInstead()) {
67             tempView = tempView->GetParent();
68         }
69         if ((tempView == nullptr) || !tempView->IsDraggable()) {
70             return nullptr;
71         }
72         return tempView;
73     }
74 };
75 }; // namespace OHOS
76 #endif // GRAPHIC_LITE_POINTER_INPUT_DEVICE_H
77