1a3e0fd82Sopenharmony_ci/*
2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License.
5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at
6a3e0fd82Sopenharmony_ci *
7a3e0fd82Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8a3e0fd82Sopenharmony_ci *
9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and
13a3e0fd82Sopenharmony_ci * limitations under the License.
14a3e0fd82Sopenharmony_ci */
15a3e0fd82Sopenharmony_ci
16a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_POINTER_INPUT_DEVICE_H
17a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_POINTER_INPUT_DEVICE_H
18a3e0fd82Sopenharmony_ci
19a3e0fd82Sopenharmony_ci#include "hal_tick.h"
20a3e0fd82Sopenharmony_ci#include "dock/input_device.h"
21a3e0fd82Sopenharmony_ci#include "components/ui_view_group.h"
22a3e0fd82Sopenharmony_ci
23a3e0fd82Sopenharmony_cinamespace OHOS {
24a3e0fd82Sopenharmony_ci/** @brief A pointer input device. */
25a3e0fd82Sopenharmony_ciclass PointerInputDevice : public InputDevice {
26a3e0fd82Sopenharmony_cipublic:
27a3e0fd82Sopenharmony_ci    PointerInputDevice()
28a3e0fd82Sopenharmony_ci        : touchableView_(nullptr), draggableView_(nullptr), targetView_(nullptr), lastPos_({0, 0}),
29a3e0fd82Sopenharmony_ci          dragLastPos_({0, 0}), curPos_({ 0, 0 }), dragStep_({ 0, 0 }), dragLen_({ 0, 0 }), pressState_(false),
30a3e0fd82Sopenharmony_ci          pressSent_(false), longPressSent_(false), cancelSent_(false), isDragging_(false), needClick_(true),
31a3e0fd82Sopenharmony_ci          pressTimeStamp_(0)
32a3e0fd82Sopenharmony_ci    {}
33a3e0fd82Sopenharmony_ci    virtual ~PointerInputDevice() {}
34a3e0fd82Sopenharmony_ci
35a3e0fd82Sopenharmony_ciprotected:
36a3e0fd82Sopenharmony_ci    void DispatchEvent(const DeviceData& data) override;
37a3e0fd82Sopenharmony_ci    void OnViewLifeEvent() override;
38a3e0fd82Sopenharmony_ci
39a3e0fd82Sopenharmony_ciprivate:
40a3e0fd82Sopenharmony_ci    UIView* touchableView_;
41a3e0fd82Sopenharmony_ci    UIView* draggableView_;
42a3e0fd82Sopenharmony_ci    UIView* targetView_;
43a3e0fd82Sopenharmony_ci    Point lastPos_;
44a3e0fd82Sopenharmony_ci    Point dragLastPos_;
45a3e0fd82Sopenharmony_ci    Point curPos_;
46a3e0fd82Sopenharmony_ci    Point dragStep_;
47a3e0fd82Sopenharmony_ci    Point dragLen_;
48a3e0fd82Sopenharmony_ci    bool pressState_;
49a3e0fd82Sopenharmony_ci    bool pressSent_;
50a3e0fd82Sopenharmony_ci    bool longPressSent_;
51a3e0fd82Sopenharmony_ci    bool cancelSent_;
52a3e0fd82Sopenharmony_ci    bool isDragging_;
53a3e0fd82Sopenharmony_ci    bool needClick_;
54a3e0fd82Sopenharmony_ci    uint32_t pressTimeStamp_;
55a3e0fd82Sopenharmony_ci
56a3e0fd82Sopenharmony_ci    void DispatchPressEvent(UIViewGroup* rootView);
57a3e0fd82Sopenharmony_ci    void DispatchReleaseEvent(UIViewGroup* rootView);
58a3e0fd82Sopenharmony_ci    void DispatchDragStartEvent();
59a3e0fd82Sopenharmony_ci    void DispatchDragEndEvent();
60a3e0fd82Sopenharmony_ci    void DispatchDragEvent();
61a3e0fd82Sopenharmony_ci    void DispatchLongPressEvent(uint32_t elapse);
62a3e0fd82Sopenharmony_ci    void DispatchCancelEvent();
63a3e0fd82Sopenharmony_ci    bool ProcessReleaseEvent();
64a3e0fd82Sopenharmony_ci    void UpdateEventViews(UIView* view);
65a3e0fd82Sopenharmony_ci    UIView* GetDraggableView(UIView* targetView) const
66a3e0fd82Sopenharmony_ci    {
67a3e0fd82Sopenharmony_ci        UIView* tempView = targetView;
68a3e0fd82Sopenharmony_ci        while ((tempView != nullptr) && tempView->IsDragParentInstead()) {
69a3e0fd82Sopenharmony_ci            tempView = tempView->GetParent();
70a3e0fd82Sopenharmony_ci        }
71a3e0fd82Sopenharmony_ci        if ((tempView == nullptr) || !tempView->IsDraggable()) {
72a3e0fd82Sopenharmony_ci            return nullptr;
73a3e0fd82Sopenharmony_ci        }
74a3e0fd82Sopenharmony_ci        return tempView;
75a3e0fd82Sopenharmony_ci    }
76a3e0fd82Sopenharmony_ci};
77a3e0fd82Sopenharmony_ci}; // namespace OHOS
78a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_POINTER_INPUT_DEVICE_H
79