123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 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#include "adapter/ohos/entrance/ace_view_ohos.h"
1723b3eb3cSopenharmony_ci
1823b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_container.h"
1923b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/mmi_event_convertor.h"
2023b3eb3cSopenharmony_ci#include "base/log/dump_log.h"
2123b3eb3cSopenharmony_ci
2223b3eb3cSopenharmony_cinamespace OHOS::Ace::Platform {
2323b3eb3cSopenharmony_cinamespace {
2423b3eb3cSopenharmony_ci
2523b3eb3cSopenharmony_ciconstexpr int32_t ROTATION_DIVISOR = 64;
2623b3eb3cSopenharmony_ci
2723b3eb3cSopenharmony_cibool IsMMIMouseScrollBegin(const AxisEvent& event)
2823b3eb3cSopenharmony_ci{
2923b3eb3cSopenharmony_ci    if (event.action != AxisAction::BEGIN ||
3023b3eb3cSopenharmony_ci        event.sourceType != SourceType::MOUSE ||
3123b3eb3cSopenharmony_ci        event.sourceTool != SourceTool::MOUSE) {
3223b3eb3cSopenharmony_ci        return false;
3323b3eb3cSopenharmony_ci    }
3423b3eb3cSopenharmony_ci    return !(NearZero(event.horizontalAxis) && NearZero(event.verticalAxis));
3523b3eb3cSopenharmony_ci}
3623b3eb3cSopenharmony_ci} // namespace
3723b3eb3cSopenharmony_ci
3823b3eb3cSopenharmony_ciRefPtr<AceViewOhos> AceViewOhos::CreateView(int32_t instanceId, bool useCurrentEventRunner, bool usePlatformThread)
3923b3eb3cSopenharmony_ci{
4023b3eb3cSopenharmony_ci    return AceType::MakeRefPtr<AceViewOhos>(
4123b3eb3cSopenharmony_ci        instanceId, ThreadModelImpl::CreateThreadModel(
4223b3eb3cSopenharmony_ci                        useCurrentEventRunner, !usePlatformThread, !SystemProperties::GetRosenBackendEnabled()));
4323b3eb3cSopenharmony_ci}
4423b3eb3cSopenharmony_ci
4523b3eb3cSopenharmony_ciAceViewOhos::AceViewOhos(int32_t id, std::unique_ptr<ThreadModelImpl> threadModelImpl)
4623b3eb3cSopenharmony_ci    : instanceId_(id), threadModelImpl_(std::move(threadModelImpl))
4723b3eb3cSopenharmony_ci{}
4823b3eb3cSopenharmony_ci
4923b3eb3cSopenharmony_civoid AceViewOhos::SurfaceCreated(const RefPtr<AceViewOhos>& view, OHOS::sptr<OHOS::Rosen::Window> window)
5023b3eb3cSopenharmony_ci{
5123b3eb3cSopenharmony_ci    CHECK_NULL_VOID(window);
5223b3eb3cSopenharmony_ci    CHECK_NULL_VOID(view);
5323b3eb3cSopenharmony_ci}
5423b3eb3cSopenharmony_ci
5523b3eb3cSopenharmony_civoid AceViewOhos::ChangeViewSize(const RefPtr<AceViewOhos>& view, int32_t width, int32_t height)
5623b3eb3cSopenharmony_ci{
5723b3eb3cSopenharmony_ci    CHECK_NULL_VOID(view);
5823b3eb3cSopenharmony_ci    view->ChangeSize(width, height);
5923b3eb3cSopenharmony_ci}
6023b3eb3cSopenharmony_ci
6123b3eb3cSopenharmony_civoid AceViewOhos::SurfaceChanged(const RefPtr<AceViewOhos>& view, int32_t width, int32_t height, int32_t orientation,
6223b3eb3cSopenharmony_ci    WindowSizeChangeReason type, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)
6323b3eb3cSopenharmony_ci{
6423b3eb3cSopenharmony_ci    CHECK_NULL_VOID(view);
6523b3eb3cSopenharmony_ci
6623b3eb3cSopenharmony_ci    view->NotifySurfaceChanged(width, height, type, rsTransaction);
6723b3eb3cSopenharmony_ci
6823b3eb3cSopenharmony_ci    auto instanceId = view->GetInstanceId();
6923b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer(instanceId);
7023b3eb3cSopenharmony_ci    if (container) {
7123b3eb3cSopenharmony_ci        auto pipelineContext = container->GetPipelineContext();
7223b3eb3cSopenharmony_ci        CHECK_NULL_VOID(pipelineContext);
7323b3eb3cSopenharmony_ci        pipelineContext->HideOverlays();
7423b3eb3cSopenharmony_ci    }
7523b3eb3cSopenharmony_ci}
7623b3eb3cSopenharmony_ci
7723b3eb3cSopenharmony_civoid AceViewOhos::SurfacePositionChanged(const RefPtr<AceViewOhos>& view, int32_t posX, int32_t posY)
7823b3eb3cSopenharmony_ci{
7923b3eb3cSopenharmony_ci    CHECK_NULL_VOID(view);
8023b3eb3cSopenharmony_ci    view->NotifySurfacePositionChanged(posX, posY);
8123b3eb3cSopenharmony_ci}
8223b3eb3cSopenharmony_ci
8323b3eb3cSopenharmony_civoid AceViewOhos::SetViewportMetrics(const RefPtr<AceViewOhos>& view, const ViewportConfig& config)
8423b3eb3cSopenharmony_ci{
8523b3eb3cSopenharmony_ci    CHECK_NULL_VOID(view);
8623b3eb3cSopenharmony_ci    view->NotifyDensityChanged(config.Density());
8723b3eb3cSopenharmony_ci}
8823b3eb3cSopenharmony_ci
8923b3eb3cSopenharmony_civoid AceViewOhos::TransformHintChanged(const RefPtr<AceViewOhos>& view, uint32_t transform)
9023b3eb3cSopenharmony_ci{
9123b3eb3cSopenharmony_ci    CHECK_NULL_VOID(view);
9223b3eb3cSopenharmony_ci    view->NotifyTransformHintChanged(transform);
9323b3eb3cSopenharmony_ci}
9423b3eb3cSopenharmony_ci
9523b3eb3cSopenharmony_civoid AceViewOhos::DispatchTouchEvent(const RefPtr<AceViewOhos>& view,
9623b3eb3cSopenharmony_ci    const std::shared_ptr<MMI::PointerEvent>& pointerEvent, const RefPtr<OHOS::Ace::NG::FrameNode>& node,
9723b3eb3cSopenharmony_ci    const std::function<void()>& callback, bool isInjected)
9823b3eb3cSopenharmony_ci{
9923b3eb3cSopenharmony_ci    if (!pointerEvent) {
10023b3eb3cSopenharmony_ci        TAG_LOGE(AceLogTag::ACE_INPUTTRACKING, "DispatchTouchEvent pointerEvent is null return.");
10123b3eb3cSopenharmony_ci        return;
10223b3eb3cSopenharmony_ci    }
10323b3eb3cSopenharmony_ci    if (!view) {
10423b3eb3cSopenharmony_ci        MMI::InputManager::GetInstance()->MarkProcessed(
10523b3eb3cSopenharmony_ci            pointerEvent->GetId(), pointerEvent->GetActionTime(), pointerEvent->IsMarkEnabled());
10623b3eb3cSopenharmony_ci        TAG_LOGE(AceLogTag::ACE_INPUTTRACKING, "DispatchTouchEvent eventId:%{public}d aceView is null return.",
10723b3eb3cSopenharmony_ci            pointerEvent->GetId());
10823b3eb3cSopenharmony_ci        return;
10923b3eb3cSopenharmony_ci    }
11023b3eb3cSopenharmony_ci    auto instanceId = view->GetInstanceId();
11123b3eb3cSopenharmony_ci    LogPointInfo(pointerEvent, instanceId);
11223b3eb3cSopenharmony_ci    DispatchEventToPerf(pointerEvent);
11323b3eb3cSopenharmony_ci    int32_t pointerAction = pointerEvent->GetPointerAction();
11423b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer(instanceId);
11523b3eb3cSopenharmony_ci    if (!container) {
11623b3eb3cSopenharmony_ci        MMI::InputManager::GetInstance()->MarkProcessed(
11723b3eb3cSopenharmony_ci            pointerEvent->GetId(), pointerEvent->GetActionTime(), pointerEvent->IsMarkEnabled());
11823b3eb3cSopenharmony_ci        TAG_LOGE(AceLogTag::ACE_INPUTTRACKING, "DispatchTouchEvent eventId:%{public}d container is null return.",
11923b3eb3cSopenharmony_ci            pointerEvent->GetId());
12023b3eb3cSopenharmony_ci        return;
12123b3eb3cSopenharmony_ci    }
12223b3eb3cSopenharmony_ci    container->SetCurPointerEvent(pointerEvent);
12323b3eb3cSopenharmony_ci
12423b3eb3cSopenharmony_ci    if (pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
12523b3eb3cSopenharmony_ci        int32_t toolType = MMI::PointerEvent::TOOL_TYPE_MOUSE;
12623b3eb3cSopenharmony_ci        if (!GetPointerEventToolType(pointerEvent, toolType)) {
12723b3eb3cSopenharmony_ci            return;
12823b3eb3cSopenharmony_ci        }
12923b3eb3cSopenharmony_ci        // mouse event
13023b3eb3cSopenharmony_ci        if ((pointerAction >= MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN &&
13123b3eb3cSopenharmony_ci                pointerAction <= MMI::PointerEvent::POINTER_ACTION_AXIS_END) ||
13223b3eb3cSopenharmony_ci            (pointerAction >= MMI::PointerEvent::POINTER_ACTION_ROTATE_BEGIN &&
13323b3eb3cSopenharmony_ci                pointerAction <= MMI::PointerEvent::POINTER_ACTION_ROTATE_END) ||
13423b3eb3cSopenharmony_ci            (toolType == MMI::PointerEvent::TOOL_TYPE_TOUCHPAD &&
13523b3eb3cSopenharmony_ci                pointerAction == MMI::PointerEvent::POINTER_ACTION_CANCEL)) {
13623b3eb3cSopenharmony_ci            view->ProcessAxisEvent(pointerEvent, node, isInjected);
13723b3eb3cSopenharmony_ci        } else {
13823b3eb3cSopenharmony_ci            view->ProcessDragEvent(pointerEvent, node);
13923b3eb3cSopenharmony_ci            view->ProcessMouseEvent(pointerEvent, node, isInjected);
14023b3eb3cSopenharmony_ci        }
14123b3eb3cSopenharmony_ci    } else {
14223b3eb3cSopenharmony_ci        // touch event
14323b3eb3cSopenharmony_ci        view->ProcessDragEvent(pointerEvent, node);
14423b3eb3cSopenharmony_ci        view->ProcessTouchEvent(pointerEvent, node, callback, isInjected);
14523b3eb3cSopenharmony_ci    }
14623b3eb3cSopenharmony_ci}
14723b3eb3cSopenharmony_ci
14823b3eb3cSopenharmony_civoid AceViewOhos::DispatchEventToPerf(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
14923b3eb3cSopenharmony_ci{
15023b3eb3cSopenharmony_ci    CHECK_NULL_VOID(pointerEvent);
15123b3eb3cSopenharmony_ci    static bool isFirstMove = false;
15223b3eb3cSopenharmony_ci    PerfMonitor* pMonitor = PerfMonitor::GetPerfMonitor();
15323b3eb3cSopenharmony_ci    if (pMonitor == nullptr) {
15423b3eb3cSopenharmony_ci        return;
15523b3eb3cSopenharmony_ci    }
15623b3eb3cSopenharmony_ci    uint64_t inputTime = pointerEvent->GetSensorInputTime() * US_TO_MS;
15723b3eb3cSopenharmony_ci    if (inputTime <= 0) {
15823b3eb3cSopenharmony_ci        inputTime = pointerEvent->GetActionTime() * US_TO_MS;
15923b3eb3cSopenharmony_ci    }
16023b3eb3cSopenharmony_ci    if (inputTime <= 0) {
16123b3eb3cSopenharmony_ci        return;
16223b3eb3cSopenharmony_ci    }
16323b3eb3cSopenharmony_ci    PerfActionType inputType = UNKNOWN_ACTION;
16423b3eb3cSopenharmony_ci    PerfSourceType sourceType = UNKNOWN_SOURCE;
16523b3eb3cSopenharmony_ci    if (pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
16623b3eb3cSopenharmony_ci        sourceType = PERF_MOUSE_EVENT;
16723b3eb3cSopenharmony_ci    } else if (pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
16823b3eb3cSopenharmony_ci        sourceType = PERF_TOUCH_EVENT;
16923b3eb3cSopenharmony_ci    } else if (pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_TOUCHPAD) {
17023b3eb3cSopenharmony_ci        sourceType = PERF_TOUCH_PAD;
17123b3eb3cSopenharmony_ci    } else if (pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_JOYSTICK) {
17223b3eb3cSopenharmony_ci        sourceType = PERF_JOY_STICK;
17323b3eb3cSopenharmony_ci    }
17423b3eb3cSopenharmony_ci    int32_t pointerAction = pointerEvent->GetPointerAction();
17523b3eb3cSopenharmony_ci    if (pointerAction == MMI::PointerEvent::POINTER_ACTION_DOWN
17623b3eb3cSopenharmony_ci        || pointerAction == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN
17723b3eb3cSopenharmony_ci        || pointerAction == MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN
17823b3eb3cSopenharmony_ci        || pointerAction == MMI::PointerEvent::POINTER_ACTION_ROTATE_BEGIN) {
17923b3eb3cSopenharmony_ci        inputType = LAST_DOWN;
18023b3eb3cSopenharmony_ci        isFirstMove = true;
18123b3eb3cSopenharmony_ci    } else if (pointerAction == MMI::PointerEvent::POINTER_ACTION_UP
18223b3eb3cSopenharmony_ci        || pointerAction == MMI::PointerEvent::POINTER_ACTION_BUTTON_UP
18323b3eb3cSopenharmony_ci        || pointerAction == MMI::PointerEvent::POINTER_ACTION_AXIS_END
18423b3eb3cSopenharmony_ci        || pointerAction == MMI::PointerEvent::POINTER_ACTION_ROTATE_END) {
18523b3eb3cSopenharmony_ci        inputType = LAST_UP;
18623b3eb3cSopenharmony_ci        isFirstMove = false;
18723b3eb3cSopenharmony_ci    } else if (isFirstMove && (pointerAction == MMI::PointerEvent::POINTER_ACTION_MOVE
18823b3eb3cSopenharmony_ci        || pointerAction == MMI::PointerEvent::POINTER_ACTION_AXIS_UPDATE
18923b3eb3cSopenharmony_ci        || pointerAction == MMI::PointerEvent::POINTER_ACTION_ROTATE_UPDATE)) {
19023b3eb3cSopenharmony_ci        inputType = FIRST_MOVE;
19123b3eb3cSopenharmony_ci        isFirstMove = false;
19223b3eb3cSopenharmony_ci    }
19323b3eb3cSopenharmony_ci    pMonitor->RecordInputEvent(inputType, sourceType, inputTime);
19423b3eb3cSopenharmony_ci}
19523b3eb3cSopenharmony_ci
19623b3eb3cSopenharmony_civoid AceViewOhos::DispatchEventToPerf(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
19723b3eb3cSopenharmony_ci{
19823b3eb3cSopenharmony_ci    CHECK_NULL_VOID(keyEvent);
19923b3eb3cSopenharmony_ci    int32_t keyCode = keyEvent->GetKeyCode();
20023b3eb3cSopenharmony_ci    if (keyCode != MMI::KeyEvent::KEYCODE_VOLUME_DOWN
20123b3eb3cSopenharmony_ci        && keyCode != MMI::KeyEvent::KEYCODE_VOLUME_UP
20223b3eb3cSopenharmony_ci        && keyCode != MMI::KeyEvent::KEYCODE_POWER
20323b3eb3cSopenharmony_ci        && keyCode != MMI::KeyEvent::KEYCODE_META_LEFT
20423b3eb3cSopenharmony_ci        && keyCode != MMI::KeyEvent::KEYCODE_ESCAPE) {
20523b3eb3cSopenharmony_ci        return;
20623b3eb3cSopenharmony_ci    }
20723b3eb3cSopenharmony_ci    PerfMonitor* pMonitor = PerfMonitor::GetPerfMonitor();
20823b3eb3cSopenharmony_ci    if (pMonitor == nullptr) {
20923b3eb3cSopenharmony_ci        return;
21023b3eb3cSopenharmony_ci    }
21123b3eb3cSopenharmony_ci    PerfActionType inputType = UNKNOWN_ACTION;
21223b3eb3cSopenharmony_ci    int32_t action = keyEvent->GetKeyAction();
21323b3eb3cSopenharmony_ci    if (action == MMI::KeyEvent::KEY_ACTION_UP) {
21423b3eb3cSopenharmony_ci        inputType = LAST_UP;
21523b3eb3cSopenharmony_ci    } else if (action == MMI::KeyEvent::KEY_ACTION_DOWN) {
21623b3eb3cSopenharmony_ci        inputType = LAST_DOWN;
21723b3eb3cSopenharmony_ci    }
21823b3eb3cSopenharmony_ci    PerfSourceType sourceType = PERF_KEY_EVENT;
21923b3eb3cSopenharmony_ci    int64_t inputTime = (keyEvent->GetKeyItem())->GetDownTime() * US_TO_MS;
22023b3eb3cSopenharmony_ci    pMonitor->RecordInputEvent(inputType, sourceType, inputTime);
22123b3eb3cSopenharmony_ci}
22223b3eb3cSopenharmony_ci
22323b3eb3cSopenharmony_cibool AceViewOhos::DispatchKeyEvent(const RefPtr<AceViewOhos>& view,
22423b3eb3cSopenharmony_ci    const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool isPreIme)
22523b3eb3cSopenharmony_ci{
22623b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(view, false);
22723b3eb3cSopenharmony_ci    DispatchEventToPerf(keyEvent);
22823b3eb3cSopenharmony_ci    return view->ProcessKeyEvent(keyEvent, isPreIme);
22923b3eb3cSopenharmony_ci}
23023b3eb3cSopenharmony_ci
23123b3eb3cSopenharmony_cibool AceViewOhos::DispatchRotationEvent(const RefPtr<AceViewOhos>& view, float rotationValue)
23223b3eb3cSopenharmony_ci{
23323b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(view, false);
23423b3eb3cSopenharmony_ci    return view->ProcessRotationEvent(rotationValue);
23523b3eb3cSopenharmony_ci}
23623b3eb3cSopenharmony_ci
23723b3eb3cSopenharmony_civoid AceViewOhos::RegisterTouchEventCallback(TouchEventCallback&& callback)
23823b3eb3cSopenharmony_ci{
23923b3eb3cSopenharmony_ci    ACE_DCHECK(callback);
24023b3eb3cSopenharmony_ci    touchEventCallback_ = std::move(callback);
24123b3eb3cSopenharmony_ci}
24223b3eb3cSopenharmony_ci
24323b3eb3cSopenharmony_civoid AceViewOhos::RegisterDragEventCallback(DragEventCallBack&& callback)
24423b3eb3cSopenharmony_ci{
24523b3eb3cSopenharmony_ci    ACE_DCHECK(callback);
24623b3eb3cSopenharmony_ci    dragEventCallback_ = std::move(callback);
24723b3eb3cSopenharmony_ci}
24823b3eb3cSopenharmony_ci
24923b3eb3cSopenharmony_civoid AceViewOhos::RegisterKeyEventCallback(KeyEventCallback&& callback)
25023b3eb3cSopenharmony_ci{
25123b3eb3cSopenharmony_ci    ACE_DCHECK(callback);
25223b3eb3cSopenharmony_ci    keyEventCallback_ = std::move(callback);
25323b3eb3cSopenharmony_ci}
25423b3eb3cSopenharmony_ci
25523b3eb3cSopenharmony_civoid AceViewOhos::RegisterMouseEventCallback(MouseEventCallback&& callback)
25623b3eb3cSopenharmony_ci{
25723b3eb3cSopenharmony_ci    ACE_DCHECK(callback);
25823b3eb3cSopenharmony_ci    mouseEventCallback_ = std::move(callback);
25923b3eb3cSopenharmony_ci}
26023b3eb3cSopenharmony_ci
26123b3eb3cSopenharmony_civoid AceViewOhos::RegisterAxisEventCallback(AxisEventCallback&& callback)
26223b3eb3cSopenharmony_ci{
26323b3eb3cSopenharmony_ci    ACE_DCHECK(callback);
26423b3eb3cSopenharmony_ci    axisEventCallback_ = std::move(callback);
26523b3eb3cSopenharmony_ci}
26623b3eb3cSopenharmony_ci
26723b3eb3cSopenharmony_civoid AceViewOhos::RegisterRotationEventCallback(RotationEventCallBack&& callback)
26823b3eb3cSopenharmony_ci{
26923b3eb3cSopenharmony_ci    ACE_DCHECK(callback);
27023b3eb3cSopenharmony_ci    rotationEventCallBack_ = std::move(callback);
27123b3eb3cSopenharmony_ci}
27223b3eb3cSopenharmony_ci
27323b3eb3cSopenharmony_civoid AceViewOhos::Launch()
27423b3eb3cSopenharmony_ci{
27523b3eb3cSopenharmony_ci}
27623b3eb3cSopenharmony_ci
27723b3eb3cSopenharmony_civoid AceViewOhos::ProcessTouchEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
27823b3eb3cSopenharmony_ci    const RefPtr<OHOS::Ace::NG::FrameNode>& node, const std::function<void()>& callback, bool isInjected)
27923b3eb3cSopenharmony_ci{
28023b3eb3cSopenharmony_ci    if (!pointerEvent) {
28123b3eb3cSopenharmony_ci        TAG_LOGE(AceLogTag::ACE_INPUTTRACKING, "ProcessTouchEvent pointerEvent is null return.");
28223b3eb3cSopenharmony_ci        return;
28323b3eb3cSopenharmony_ci    }
28423b3eb3cSopenharmony_ci    TouchEvent touchPoint = ConvertTouchEvent(pointerEvent);
28523b3eb3cSopenharmony_ci    touchPoint.SetIsInjected(isInjected);
28623b3eb3cSopenharmony_ci    if (SystemProperties::GetDebugEnabled()) {
28723b3eb3cSopenharmony_ci        ACE_SCOPED_TRACE("ProcessTouchEvent pointX=%f pointY=%f type=%d timeStamp=%lld id=%d eventId=%d", touchPoint.x,
28823b3eb3cSopenharmony_ci            touchPoint.y, (int)touchPoint.type, touchPoint.time.time_since_epoch().count(), touchPoint.id,
28923b3eb3cSopenharmony_ci            touchPoint.touchEventId);
29023b3eb3cSopenharmony_ci    }
29123b3eb3cSopenharmony_ci    auto markProcess = [touchPoint, finallyCallback = callback, enabled = pointerEvent->IsMarkEnabled()]() {
29223b3eb3cSopenharmony_ci        MMI::InputManager::GetInstance()->MarkProcessed(touchPoint.touchEventId,
29323b3eb3cSopenharmony_ci            std::chrono::duration_cast<std::chrono::microseconds>(touchPoint.time.time_since_epoch()).count(),
29423b3eb3cSopenharmony_ci            enabled);
29523b3eb3cSopenharmony_ci        if (finallyCallback) {
29623b3eb3cSopenharmony_ci            finallyCallback();
29723b3eb3cSopenharmony_ci        }
29823b3eb3cSopenharmony_ci    };
29923b3eb3cSopenharmony_ci    if (touchPoint.type != TouchType::UNKNOWN) {
30023b3eb3cSopenharmony_ci        if (touchEventCallback_) {
30123b3eb3cSopenharmony_ci            touchEventCallback_(touchPoint, markProcess, node);
30223b3eb3cSopenharmony_ci        }
30323b3eb3cSopenharmony_ci    }
30423b3eb3cSopenharmony_ci}
30523b3eb3cSopenharmony_ci
30623b3eb3cSopenharmony_civoid AceViewOhos::ProcessDragEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
30723b3eb3cSopenharmony_ci    const RefPtr<OHOS::Ace::NG::FrameNode>& node)
30823b3eb3cSopenharmony_ci{
30923b3eb3cSopenharmony_ci    DragEventAction action;
31023b3eb3cSopenharmony_ci    PointerEvent event;
31123b3eb3cSopenharmony_ci    ConvertPointerEvent(pointerEvent, event);
31223b3eb3cSopenharmony_ci    CHECK_NULL_VOID(dragEventCallback_);
31323b3eb3cSopenharmony_ci    int32_t orgAction = pointerEvent->GetPointerAction();
31423b3eb3cSopenharmony_ci    switch (orgAction) {
31523b3eb3cSopenharmony_ci        case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_MOVE: {
31623b3eb3cSopenharmony_ci            action = DragEventAction::DRAG_EVENT_MOVE;
31723b3eb3cSopenharmony_ci            dragEventCallback_(event, action, node);
31823b3eb3cSopenharmony_ci            break;
31923b3eb3cSopenharmony_ci        }
32023b3eb3cSopenharmony_ci        case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_UP: {
32123b3eb3cSopenharmony_ci            action = DragEventAction::DRAG_EVENT_END;
32223b3eb3cSopenharmony_ci            dragEventCallback_(event, action, node);
32323b3eb3cSopenharmony_ci            break;
32423b3eb3cSopenharmony_ci        }
32523b3eb3cSopenharmony_ci        case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW: {
32623b3eb3cSopenharmony_ci            action = DragEventAction::DRAG_EVENT_START;
32723b3eb3cSopenharmony_ci            dragEventCallback_(event, action, node);
32823b3eb3cSopenharmony_ci            break;
32923b3eb3cSopenharmony_ci        }
33023b3eb3cSopenharmony_ci        case OHOS::MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW: {
33123b3eb3cSopenharmony_ci            action = DragEventAction::DRAG_EVENT_OUT;
33223b3eb3cSopenharmony_ci            dragEventCallback_(event, action, node);
33323b3eb3cSopenharmony_ci            break;
33423b3eb3cSopenharmony_ci        }
33523b3eb3cSopenharmony_ci        default:
33623b3eb3cSopenharmony_ci            break;
33723b3eb3cSopenharmony_ci    }
33823b3eb3cSopenharmony_ci}
33923b3eb3cSopenharmony_ci
34023b3eb3cSopenharmony_civoid AceViewOhos::ProcessDragEvent(int32_t x, int32_t y, const DragEventAction& action,
34123b3eb3cSopenharmony_ci    const RefPtr<OHOS::Ace::NG::FrameNode>& node)
34223b3eb3cSopenharmony_ci{
34323b3eb3cSopenharmony_ci    CHECK_NULL_VOID(dragEventCallback_);
34423b3eb3cSopenharmony_ci    dragEventCallback_(PointerEvent(x, y), action, node);
34523b3eb3cSopenharmony_ci}
34623b3eb3cSopenharmony_ci
34723b3eb3cSopenharmony_civoid AceViewOhos::ProcessMouseEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
34823b3eb3cSopenharmony_ci    const RefPtr<OHOS::Ace::NG::FrameNode>& node, bool isInjected)
34923b3eb3cSopenharmony_ci{
35023b3eb3cSopenharmony_ci    MouseEvent event;
35123b3eb3cSopenharmony_ci    bool markEnabled = true;
35223b3eb3cSopenharmony_ci    if (pointerEvent) {
35323b3eb3cSopenharmony_ci        auto container = Platform::AceContainer::GetContainer(instanceId_);
35423b3eb3cSopenharmony_ci        CHECK_NULL_VOID(container);
35523b3eb3cSopenharmony_ci        ConvertMouseEvent(pointerEvent, event, container->IsScenceBoardWindow());
35623b3eb3cSopenharmony_ci        markEnabled = pointerEvent->IsMarkEnabled();
35723b3eb3cSopenharmony_ci    }
35823b3eb3cSopenharmony_ci    event.isInjected = isInjected;
35923b3eb3cSopenharmony_ci    if (SystemProperties::GetDebugEnabled()) {
36023b3eb3cSopenharmony_ci        ACE_SCOPED_TRACE("ProcessMouseEvent pointX=%f pointY=%f type=%d timeStamp=%lld id=%d eventId=%d", event.x,
36123b3eb3cSopenharmony_ci            event.y, (int)event.action, event.time.time_since_epoch().count(), event.id, event.touchEventId);
36223b3eb3cSopenharmony_ci    }
36323b3eb3cSopenharmony_ci    auto markProcess = [event, markEnabled]() {
36423b3eb3cSopenharmony_ci        MMI::InputManager::GetInstance()->MarkProcessed(event.touchEventId,
36523b3eb3cSopenharmony_ci            std::chrono::duration_cast<std::chrono::microseconds>(event.time.time_since_epoch()).count(),
36623b3eb3cSopenharmony_ci            markEnabled);
36723b3eb3cSopenharmony_ci    };
36823b3eb3cSopenharmony_ci
36923b3eb3cSopenharmony_ci    CHECK_NULL_VOID(mouseEventCallback_);
37023b3eb3cSopenharmony_ci    mouseEventCallback_(event, markProcess, node);
37123b3eb3cSopenharmony_ci}
37223b3eb3cSopenharmony_ci
37323b3eb3cSopenharmony_civoid AceViewOhos::ProcessAxisEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
37423b3eb3cSopenharmony_ci    const RefPtr<OHOS::Ace::NG::FrameNode>& node, bool isInjected)
37523b3eb3cSopenharmony_ci{
37623b3eb3cSopenharmony_ci    CHECK_NULL_VOID(axisEventCallback_);
37723b3eb3cSopenharmony_ci    AxisEvent event;
37823b3eb3cSopenharmony_ci    event.isInjected = isInjected;
37923b3eb3cSopenharmony_ci    if (!pointerEvent) {
38023b3eb3cSopenharmony_ci        axisEventCallback_(event, nullptr, node);
38123b3eb3cSopenharmony_ci        return;
38223b3eb3cSopenharmony_ci    }
38323b3eb3cSopenharmony_ci
38423b3eb3cSopenharmony_ci    ConvertAxisEvent(pointerEvent, event);
38523b3eb3cSopenharmony_ci    auto markProcess = [event, enabled = pointerEvent->IsMarkEnabled()]() {
38623b3eb3cSopenharmony_ci        MMI::InputManager::GetInstance()->MarkProcessed(event.touchEventId,
38723b3eb3cSopenharmony_ci            std::chrono::duration_cast<std::chrono::microseconds>(event.time.time_since_epoch()).count(),
38823b3eb3cSopenharmony_ci            enabled);
38923b3eb3cSopenharmony_ci    };
39023b3eb3cSopenharmony_ci
39123b3eb3cSopenharmony_ci    /* The first step of axis event of mouse is equivalent to touch event START + UPDATE.
39223b3eb3cSopenharmony_ci     * Create a fake UPDATE event here to adapt to axis event of mouse.
39323b3eb3cSopenharmony_ci     * e.g {START, END} turns into {START, UPDATE, END}.
39423b3eb3cSopenharmony_ci     */
39523b3eb3cSopenharmony_ci    if (IsMMIMouseScrollBegin(event)) {
39623b3eb3cSopenharmony_ci        auto fakeAxisStart = std::make_shared<MMI::PointerEvent>(*pointerEvent);
39723b3eb3cSopenharmony_ci        fakeAxisStart->SetAxisValue(MMI::PointerEvent::AxisType::AXIS_TYPE_SCROLL_VERTICAL, 0.0);
39823b3eb3cSopenharmony_ci        fakeAxisStart->SetAxisValue(MMI::PointerEvent::AxisType::AXIS_TYPE_SCROLL_HORIZONTAL, 0.0);
39923b3eb3cSopenharmony_ci        ConvertAxisEvent(fakeAxisStart, event);
40023b3eb3cSopenharmony_ci        axisEventCallback_(event, nullptr, node);
40123b3eb3cSopenharmony_ci
40223b3eb3cSopenharmony_ci        auto fakeAxisUpdate = std::make_shared<MMI::PointerEvent>(*pointerEvent);
40323b3eb3cSopenharmony_ci        fakeAxisUpdate->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_AXIS_UPDATE);
40423b3eb3cSopenharmony_ci        ConvertAxisEvent(fakeAxisUpdate, event);
40523b3eb3cSopenharmony_ci    }
40623b3eb3cSopenharmony_ci    axisEventCallback_(event, markProcess, node);
40723b3eb3cSopenharmony_ci}
40823b3eb3cSopenharmony_ci
40923b3eb3cSopenharmony_cibool AceViewOhos::ProcessKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool isPreIme)
41023b3eb3cSopenharmony_ci{
41123b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(keyEventCallback_, false);
41223b3eb3cSopenharmony_ci    KeyEvent event;
41323b3eb3cSopenharmony_ci    ConvertKeyEvent(keyEvent, event);
41423b3eb3cSopenharmony_ci    event.isPreIme = isPreIme;
41523b3eb3cSopenharmony_ci    return keyEventCallback_(event);
41623b3eb3cSopenharmony_ci}
41723b3eb3cSopenharmony_ci
41823b3eb3cSopenharmony_ciconst void* AceViewOhos::GetNativeWindowById(uint64_t textureId)
41923b3eb3cSopenharmony_ci{
42023b3eb3cSopenharmony_ci    return nullptr;
42123b3eb3cSopenharmony_ci}
42223b3eb3cSopenharmony_ci
42323b3eb3cSopenharmony_cibool AceViewOhos::ProcessRotationEvent(float rotationValue)
42423b3eb3cSopenharmony_ci{
42523b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(rotationEventCallBack_, false);
42623b3eb3cSopenharmony_ci    RotationEvent event { .value = rotationValue * ROTATION_DIVISOR };
42723b3eb3cSopenharmony_ci    return rotationEventCallBack_(event);
42823b3eb3cSopenharmony_ci}
42923b3eb3cSopenharmony_ci
43023b3eb3cSopenharmony_cibool AceViewOhos::Dump(const std::vector<std::string>& params)
43123b3eb3cSopenharmony_ci{
43223b3eb3cSopenharmony_ci    if (params.empty() || params[0] != "-drawcmd") {
43323b3eb3cSopenharmony_ci        return false;
43423b3eb3cSopenharmony_ci    }
43523b3eb3cSopenharmony_ci    if (DumpLog::GetInstance().GetDumpFile()) {
43623b3eb3cSopenharmony_ci        DumpLog::GetInstance().AddDesc("Dump draw command not support on this version.");
43723b3eb3cSopenharmony_ci        DumpLog::GetInstance().Print(0, "Info:", 0);
43823b3eb3cSopenharmony_ci        return true;
43923b3eb3cSopenharmony_ci    }
44023b3eb3cSopenharmony_ci    return false;
44123b3eb3cSopenharmony_ci}
44223b3eb3cSopenharmony_ci
44323b3eb3cSopenharmony_ciuint32_t AceViewOhos::GetBackgroundColor()
44423b3eb3cSopenharmony_ci{
44523b3eb3cSopenharmony_ci    return Color::WHITE.GetValue();
44623b3eb3cSopenharmony_ci}
44723b3eb3cSopenharmony_ci
44823b3eb3cSopenharmony_ci} // namespace OHOS::Ace::Platform
449