123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License.
523b3eb3cSopenharmony_ci * You may obtain a copy of the License at
623b3eb3cSopenharmony_ci *
723b3eb3cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
823b3eb3cSopenharmony_ci *
923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and
1323b3eb3cSopenharmony_ci * limitations under the License.
1423b3eb3cSopenharmony_ci */
1523b3eb3cSopenharmony_ci
1623b3eb3cSopenharmony_ci#ifndef FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_SAMPLES_EVENT_ADAPTER_H
1723b3eb3cSopenharmony_ci#define FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_SAMPLES_EVENT_ADAPTER_H
1823b3eb3cSopenharmony_ci
1923b3eb3cSopenharmony_ci#include <mutex>
2023b3eb3cSopenharmony_ci
2123b3eb3cSopenharmony_ci#include "glfw_render_context.h"
2223b3eb3cSopenharmony_ci
2323b3eb3cSopenharmony_ci#include "adapter/preview/external/multimodalinput/key_event.h"
2423b3eb3cSopenharmony_ci#include "adapter/preview/external/multimodalinput/pointer_event.h"
2523b3eb3cSopenharmony_ci#include "frameworks/base/utils/singleton.h"
2623b3eb3cSopenharmony_ci
2723b3eb3cSopenharmony_ciusing OHOS::MMI::KeyAction;
2823b3eb3cSopenharmony_ciusing OHOS::MMI::KeyCode;
2923b3eb3cSopenharmony_ciusing OHOS::MMI::KeyEvent;
3023b3eb3cSopenharmony_ciusing OHOS::MMI::PointerEvent;
3123b3eb3cSopenharmony_ciusing OHOS::MMI::SourceTool;
3223b3eb3cSopenharmony_ciusing OHOS::MMI::SourceType;
3323b3eb3cSopenharmony_ciusing OHOS::MMI::TouchPoint;
3423b3eb3cSopenharmony_ciusing OHOS::MMI::TouchType;
3523b3eb3cSopenharmony_ciusing OHOS::Rosen::GlfwRenderContext;
3623b3eb3cSopenharmony_ci
3723b3eb3cSopenharmony_ciusing MMIKeyEventCallback = std::function<void(const std::shared_ptr<KeyEvent>&)>;
3823b3eb3cSopenharmony_ciusing MMIPointerEventCallback = std::function<void(const std::shared_ptr<PointerEvent>&)>;
3923b3eb3cSopenharmony_ciusing InspectorCallback = std::function<void(void)>;
4023b3eb3cSopenharmony_ci
4123b3eb3cSopenharmony_cinamespace OHOS::Ace::Sample {
4223b3eb3cSopenharmony_ci
4323b3eb3cSopenharmony_ciclass EventAdapter : public Singleton<EventAdapter> {
4423b3eb3cSopenharmony_ci    DECLARE_SINGLETON(EventAdapter);
4523b3eb3cSopenharmony_ci
4623b3eb3cSopenharmony_cipublic:
4723b3eb3cSopenharmony_ci    void Initialize(std::shared_ptr<GlfwRenderContext>& glfwRenderContext);
4823b3eb3cSopenharmony_ci    bool RecognizeKeyEvent(int key, int action, int mods);
4923b3eb3cSopenharmony_ci    void RecognizePointerEvent(const TouchType type);
5023b3eb3cSopenharmony_ci    void RegisterKeyEventCallback(MMIKeyEventCallback&& callback);
5123b3eb3cSopenharmony_ci    void RegisterPointerEventCallback(MMIPointerEventCallback&& callback);
5223b3eb3cSopenharmony_ci    // Register the callback for inspector
5323b3eb3cSopenharmony_ci    void RegisterInspectorCallback(InspectorCallback&& callback);
5423b3eb3cSopenharmony_ci    // This function is used to perform specific operations, by recognize some special shortcut keys.
5523b3eb3cSopenharmony_ci    bool RunSpecialOperations(int key, int action, int mods);
5623b3eb3cSopenharmony_ci
5723b3eb3cSopenharmony_ciprivate:
5823b3eb3cSopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent_;
5923b3eb3cSopenharmony_ci    std::shared_ptr<PointerEvent> pointerEvent_;
6023b3eb3cSopenharmony_ci    MMIKeyEventCallback keyEventCallback_;
6123b3eb3cSopenharmony_ci    MMIPointerEventCallback pointerEventCallback_;
6223b3eb3cSopenharmony_ci    InspectorCallback inspectorCallback_;
6323b3eb3cSopenharmony_ci
6423b3eb3cSopenharmony_ci    // for mouse event
6523b3eb3cSopenharmony_ci    std::mutex mouseMutex_;
6623b3eb3cSopenharmony_ci    bool isMousePressed_ = false;
6723b3eb3cSopenharmony_ci    double posX_ = 0;
6823b3eb3cSopenharmony_ci    double posY_ = 0;
6923b3eb3cSopenharmony_ci};
7023b3eb3cSopenharmony_ci
7123b3eb3cSopenharmony_ci} // namespace OHOS::Ace::Sample
7223b3eb3cSopenharmony_ci
7323b3eb3cSopenharmony_ci#endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_SAMPLES_EVENT_ADAPTER_H
74