From 843108b4ad552f52e49d10fa7cdfe1be12999867 Mon Sep 17 00:00:00 2001 From: zhouchaobo Date: Sun, 8 Dec 2024 15:40:35 +0800 Subject: [PATCH] Joystick feature Signed-off-by: zhouchaobo Change-Id: Icadbc79193218fc5b2407a8433beedc266888852 --- adapter/ohos/entrance/ace_view_ohos.cpp | 10 +- adapter/ohos/entrance/ace_view_ohos.h | 2 +- adapter/ohos/entrance/mmi_event_convertor.cpp | 10 +- adapter/ohos/entrance/mmi_event_convertor.h | 5 +- .../ark_component/src/ArkComponent.ts | 20 +++ .../engine/arkComponent.js | 17 ++ .../engine/jsEnumStyle.js | 13 ++ .../arkts_native_api_impl_bridge.cpp | 4 + .../arkts_native_common_bridge.cpp | 71 ++++++++ .../nativeModule/arkts_native_common_bridge.h | 4 + .../jsview/js_view_abstract.cpp | 34 ++++ .../jsview/js_view_abstract.h | 1 + .../jsview/models/view_abstract_model_impl.h | 2 + frameworks/core/common/event_manager.cpp | 4 + frameworks/core/common/key_event_manager.cpp | 14 ++ frameworks/core/common/key_event_manager.h | 2 + .../core/components_ng/base/view_abstract.cpp | 28 ++++ .../core/components_ng/base/view_abstract.h | 4 + .../components_ng/base/view_abstract_model.h | 2 + .../base/view_abstract_model_ng.h | 17 ++ .../components_ng/event/event_constants.h | 13 +- .../event/focus_event_handler.cpp | 26 ++- .../components_ng/event/focus_event_handler.h | 4 + frameworks/core/event/ace_events.h | 3 +- ...ointer_axis_event.h => focus_axis_event.h} | 119 +++++++++++--- frameworks/core/event/key_event.h | 2 + .../core/interfaces/arkoala/arkoala_api.h | 25 +++ .../core/interfaces/native/node/node_api.cpp | 2 + .../native/node/node_common_modifier.cpp | 44 +++++ .../native/node/node_common_modifier.h | 2 + interfaces/native/event/ui_input_event.cpp | 153 ++++++++++++++++-- interfaces/native/event/ui_input_event_impl.h | 1 + interfaces/native/libace.ndk.json | 8 + interfaces/native/native_key_event.h | 6 + interfaces/native/native_node.h | 10 ++ interfaces/native/node/event_converter.cpp | 13 ++ interfaces/native/node/node_model.cpp | 12 +- interfaces/native/node/node_model.h | 1 + interfaces/native/ui_input_event.h | 46 ++++++ .../mock/mock_mmi_event_convertor.cpp | 2 +- 40 files changed, 703 insertions(+), 53 deletions(-) rename frameworks/core/event/{non_pointer_axis_event.h => focus_axis_event.h} (46%) diff --git a/adapter/ohos/entrance/ace_view_ohos.cpp b/adapter/ohos/entrance/ace_view_ohos.cpp index 5f7a9d0ab73..17617212c49 100644 --- a/adapter/ohos/entrance/ace_view_ohos.cpp +++ b/adapter/ohos/entrance/ace_view_ohos.cpp @@ -19,7 +19,7 @@ #include "adapter/ohos/entrance/ace_container.h" #include "adapter/ohos/entrance/mmi_event_convertor.h" #include "base/log/dump_log.h" -#include "core/event/non_pointer_axis_event.h" +#include "core/event/focus_axis_event.h" #include "core/event/non_pointer_event.h" namespace OHOS::Ace::Platform { @@ -124,7 +124,7 @@ void AceViewOhos::DispatchTouchEvent(const RefPtr& view, } container->SetCurPointerEvent(pointerEvent); if (pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_JOYSTICK) { - view->ProcessNonPointerAxisEvent(pointerEvent); + view->ProcessFocusAxisEvent(pointerEvent); } if (pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) { @@ -427,11 +427,11 @@ bool AceViewOhos::ProcessKeyEvent(const std::shared_ptr& keyEvent return nonPointerEventCallback_(event); } -bool AceViewOhos::ProcessNonPointerAxisEvent(const std::shared_ptr& pointerEvent) +bool AceViewOhos::ProcessFocusAxisEvent(const std::shared_ptr& pointerEvent) { CHECK_NULL_RETURN(nonPointerEventCallback_, false); - NG::NonPointerAxisEvent event; - ConvertNonPointerAxisEvent(pointerEvent, event); + NG::FocusAxisEvent event; + ConvertFocusAxisEvent(pointerEvent, event); return nonPointerEventCallback_(event); } diff --git a/adapter/ohos/entrance/ace_view_ohos.h b/adapter/ohos/entrance/ace_view_ohos.h index 9d986aa94c1..4d152681adf 100644 --- a/adapter/ohos/entrance/ace_view_ohos.h +++ b/adapter/ohos/entrance/ace_view_ohos.h @@ -89,7 +89,7 @@ public: bool ProcessKeyEvent(const std::shared_ptr& keyEvent, bool isPreIme); - bool ProcessNonPointerAxisEvent(const std::shared_ptr& pointerEvent); + bool ProcessFocusAxisEvent(const std::shared_ptr& pointerEvent); bool ProcessRotationEvent(float rotationValue); diff --git a/adapter/ohos/entrance/mmi_event_convertor.cpp b/adapter/ohos/entrance/mmi_event_convertor.cpp index cd9d198a410..1ce6deca3a4 100644 --- a/adapter/ohos/entrance/mmi_event_convertor.cpp +++ b/adapter/ohos/entrance/mmi_event_convertor.cpp @@ -382,7 +382,7 @@ void GetAxisEventAction(int32_t action, AxisEvent& event) } } -void GetNonPointerAxisEventAction(int32_t action, NG::NonPointerAxisEvent& event) +void GetNonPointerAxisEventAction(int32_t action, NG::FocusAxisEvent& event) { switch (action) { case OHOS::MMI::PointerEvent::POINTER_ACTION_AXIS_BEGIN: @@ -473,7 +473,9 @@ void ConvertKeyEvent(const std::shared_ptr& keyEvent, KeyEvent& e event.timeStamp = time; event.key = MMI::KeyEvent::KeyCodeToString(keyEvent->GetKeyCode()); event.deviceId = keyEvent->GetDeviceId(); - event.sourceType = SourceType::KEYBOARD; + int32_t orgDevice = keyEvent->GetSourceType(); + event.sourceType = + orgDevice == MMI::PointerEvent::SOURCE_TYPE_JOYSTICK ? SourceType::JOYSTICK : SourceType::KEYBOARD; #ifdef SECURITY_COMPONENT_ENABLE event.enhanceData = keyEvent->GetEnhanceData(); #endif @@ -485,7 +487,7 @@ void ConvertKeyEvent(const std::shared_ptr& keyEvent, KeyEvent& e event.numLock = keyEvent->GetFunctionKey(MMI::KeyEvent::NUM_LOCK_FUNCTION_KEY); } -void ConvertNonPointerAxisEvent(const std::shared_ptr& pointerEvent, NG::NonPointerAxisEvent& event) +void ConvertFocusAxisEvent(const std::shared_ptr& pointerEvent, NG::FocusAxisEvent& event) { int32_t pointerID = pointerEvent->GetPointerId(); MMI::PointerEvent::PointerItem item; @@ -508,7 +510,7 @@ void ConvertNonPointerAxisEvent(const std::shared_ptr& pointe GetNonPointerAxisEventAction(orgAction, event); int32_t orgDevice = pointerEvent->GetSourceType(); GetEventDevice(orgDevice, event); - event.sourceTool = GetSourceTool(item.GetToolType()); + event.sourceTool = SourceTool::JOYSTICK; event.pointerEvent = pointerEvent; event.originalId = item.GetOriginPointerId(); event.deviceId = pointerEvent->GetDeviceId(); diff --git a/adapter/ohos/entrance/mmi_event_convertor.h b/adapter/ohos/entrance/mmi_event_convertor.h index c4769c4226c..57aaef5abb7 100644 --- a/adapter/ohos/entrance/mmi_event_convertor.h +++ b/adapter/ohos/entrance/mmi_event_convertor.h @@ -27,7 +27,7 @@ #include "core/event/axis_event.h" #include "core/event/key_event.h" #include "core/event/mouse_event.h" -#include "core/event/non_pointer_axis_event.h" +#include "core/event/focus_axis_event.h" #include "core/event/touch_event.h" #include "core/event/pointer_event.h" @@ -63,6 +63,7 @@ void GetEventDevice(int32_t sourceType, E& event) event.sourceType = SourceType::TOUCH_PAD; break; case OHOS::MMI::PointerEvent::SOURCE_TYPE_MOUSE: + case OHOS::MMI::PointerEvent::SOURCE_TYPE_JOYSTICK: event.sourceType = SourceType::MOUSE; break; default: @@ -92,7 +93,7 @@ void ConvertAxisEvent(const std::shared_ptr& pointerEvent, Ax void ConvertKeyEvent(const std::shared_ptr& keyEvent, KeyEvent& event); -void ConvertNonPointerAxisEvent(const std::shared_ptr& pointerEvent, NG::NonPointerAxisEvent& event); +void ConvertFocusAxisEvent(const std::shared_ptr& pointerEvent, NG::FocusAxisEvent& event); void ConvertPointerEvent(const std::shared_ptr& pointerEvent, DragPointerEvent& event); diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts index 3fbc1155622..6169f987eaa 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts @@ -2094,6 +2094,21 @@ class ShouldBuiltInRecognizerParallelWithModifier extends ModifierWithKey void; +class OnFocusAxisEventModifier extends ModifierWithKey { + constructor(value: FocusAxisEventCallback) { + super(value); + } + static identity: Symbol = Symbol('onFocusAxisEvent'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnKeyEvent(node); + } else { + getUINativeModule().common.setOnKeyEvent(node, this.value); + } + } +} + class MotionPathModifier extends ModifierWithKey { constructor(value: MotionPathOptions) { super(value); @@ -3881,6 +3896,11 @@ class ArkComponent implements CommonMethod { return this; } + onFocusAxisEvent(event: (event?: FocusAxisEvent) => void): this { + modifierWithKey(this._modifiersWithKeys, OnFocusAxisEventModifier.identity, OnFocusAxisEventModifier, event); + return this; + } + focusable(value: boolean): this { if (typeof value === 'boolean') { modifierWithKey(this._modifiersWithKeys, FocusableModifier.identity, FocusableModifier, value); diff --git a/frameworks/bridge/declarative_frontend/engine/arkComponent.js b/frameworks/bridge/declarative_frontend/engine/arkComponent.js index cd74487ebc0..7a9572defa3 100644 --- a/frameworks/bridge/declarative_frontend/engine/arkComponent.js +++ b/frameworks/bridge/declarative_frontend/engine/arkComponent.js @@ -1831,6 +1831,19 @@ class OnKeyPreImeModifier extends ModifierWithKey { } } OnKeyPreImeModifier.identity = Symbol('onKeyPreIme'); +class OnFocusAxisEventModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnFocusAxisEvent(node); + } else { + getUINativeModule().common.setOnFocusAxisEvent(node, this.value); + } + } +} +OnFocusAxisEventModifier.identity = Symbol('onFocusAxisEvent'); class OnFocusModifier extends ModifierWithKey { constructor(value) { super(value); @@ -3708,6 +3721,10 @@ class ArkComponent { modifierWithKey(this._modifiersWithKeys, OnKeyPreImeModifier.identity, OnKeyPreImeModifier, event); return this; } + onFocusAxisEvent(event) { + modifierWithKey(this._modifiersWithKeys, OnFocusAxisEventModifier.identity, OnFocusAxisEventModifier, event); + return this; + } focusable(value) { if (typeof value === 'boolean') { modifierWithKey(this._modifiersWithKeys, FocusableModifier.identity, FocusableModifier, value); diff --git a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js index 162b4bc8bb8..aa9194465ec 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js +++ b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js @@ -1167,6 +1167,7 @@ let KeySource; (function (KeySource) { KeySource[KeySource.Unknown = 0] = 'Unknown'; KeySource[KeySource.Keyboard = 4] = 'Keyboard'; + KeySource[KeySource.JOYSTICK = 5] = "JOYSTICK"; })(KeySource || (KeySource = {})); let SeekMode; @@ -3529,3 +3530,15 @@ var WebNavigationType; WebNavigationType[WebNavigationType['NAVIGATION_TYPE_NEW_SUBFRAME'] = 4] = 'NAVIGATION_TYPE_NEW_SUBFRAME'; WebNavigationType[WebNavigationType['NAVIGATION_TYPE_AUTO_SUBFRAME'] = 5] = 'NAVIGATION_TYPE_AUTO_SUBFRAME'; })(WebNavigationType || (WebNavigationType = {})); + +var AxisModel; +(function (AxisModel) { + AxisModel[AxisModel.ABS_X = 0] = "ABS_X"; + AxisModel[AxisModel.ABS_Y = 1] = "ABS_Y"; + AxisModel[AxisModel.ABS_Z = 2] = "ABS_Z"; + AxisModel[AxisModel.ABS_RZ = 3] = "ABS_RZ"; + AxisModel[AxisModel.ABS_GAS = 4] = "ABS_GAS"; + AxisModel[AxisModel.ABS_BRAKE = 5] = "ABS_BRAKE"; + AxisModel[AxisModel.ABS_HAT0X = 6] = "ABS_HAT0X"; + AxisModel[AxisModel.ABS_HAT0Y = 7] = "ABS_HAT0Y"; +})(AxisModel || (AxisModel = {})); diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp index 00ef44b33ec..8d71cf77741 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp @@ -938,6 +938,10 @@ ArkUINativeModuleValue ArkUINativeModule::GetArkUINativeModule(ArkUIRuntimeCallI panda::FunctionRef::New(const_cast(vm), CommonBridge::SetOnKeyPreIme)); common->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnKeyPreIme"), panda::FunctionRef::New(const_cast(vm), CommonBridge::ResetOnKeyPreIme)); + common->Set(vm, panda::StringRef::NewFromUtf8(vm, "setOnFocusAxisEvent"), + panda::FunctionRef::New(const_cast(vm), CommonBridge::SetOnFocusAxisEvent)); + common->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnFocusAxisEvent"), + panda::FunctionRef::New(const_cast(vm), CommonBridge::ResetOnFocusAxisEvent)); common->Set(vm, panda::StringRef::NewFromUtf8(vm, "setOnFocus"), panda::FunctionRef::New(const_cast(vm), CommonBridge::SetOnFocus)); common->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnFocus"), diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp index 9a30fa9ffcc..a2dc50dd9ab 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp @@ -8182,4 +8182,75 @@ ArkUINativeModuleValue CommonBridge::ResetFocusBox(ArkUIRuntimeCallInfo* runtime GetArkUINodeModifiers()->getCommonModifier()->resetFocusBoxStyle(nativeNode); return panda::JSValueRef::Undefined(vm); } + +Local CommonBridge::CreateFocusAxisEventInfo(EcmaVM* vm, NG::FocusAxisEventInfo& info) +{ + auto axisMap = panda::MapRef::New(vm); + axisMap->Set(vm, panda::NumberRef::New(vm, static_cast(NG::AxisModel::ABS_X)), + panda::NumberRef::New(vm, info.GetAbsXValue())); + axisMap->Set(vm, panda::NumberRef::New(vm, static_cast(NG::AxisModel::ABS_Y)), + panda::NumberRef::New(vm, info.GetAbsYValue())); + axisMap->Set(vm, panda::NumberRef::New(vm, static_cast(NG::AxisModel::ABS_Z)), + panda::NumberRef::New(vm, info.GetAbsZValue())); + axisMap->Set(vm, panda::NumberRef::New(vm, static_cast(NG::AxisModel::ABS_RZ)), + panda::NumberRef::New(vm, info.GetAbsRzValue())); + axisMap->Set(vm, panda::NumberRef::New(vm, static_cast(NG::AxisModel::ABS_GAS)), + panda::NumberRef::New(vm, info.GetAbsGasValue())); + axisMap->Set(vm, panda::NumberRef::New(vm, static_cast(NG::AxisModel::ABS_BRAKE)), + panda::NumberRef::New(vm, info.GetAbsBrakeValue())); + axisMap->Set(vm, panda::NumberRef::New(vm, static_cast(NG::AxisModel::ABS_HAT0X)), + panda::NumberRef::New(vm, info.GetAbsHat0XValue())); + axisMap->Set(vm, panda::NumberRef::New(vm, static_cast(NG::AxisModel::ABS_HAT0Y)), + panda::NumberRef::New(vm, info.GetAbsHat0YValue())); + const char* keys[] = { "axisMap", "target", "timestamp", "source", "pressure", "tiltX", "tiltY", "sourceTool", + "deviceId", "getModifierKeyState", "stopPropagation" }; + Local values[] = { axisMap, FrameNodeBridge::CreateEventTargetObject(vm, info), + panda::NumberRef::New(vm, static_cast(info.GetTimeStamp().time_since_epoch().count())), + panda::NumberRef::New(vm, static_cast(info.GetSourceDevice())), + panda::NumberRef::New(vm, info.GetForce()), + panda::NumberRef::New(vm, static_cast(info.GetTiltX().value_or(0.0f))), + panda::NumberRef::New(vm, static_cast(info.GetTiltY().value_or(0.0f))), + panda::NumberRef::New(vm, static_cast(static_cast(info.GetSourceTool()))), + panda::NumberRef::New(vm, info.GetDeviceId()), panda::FunctionRef::New(vm, ArkTSUtils::JsGetModifierKeyState), + panda::FunctionRef::New(vm, Framework::JsStopPropagation) }; + auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values); + obj->SetNativePointerFieldCount(vm, 1); + obj->SetNativePointerField(vm, 0, static_cast(&info)); + return obj; +} + +ArkUINativeModuleValue CommonBridge::SetOnFocusAxisEvent(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); + auto* frameNode = GetFrameNode(runtimeCallInfo); + CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm)); + Local secondeArg = runtimeCallInfo->GetCallArgRef(1); + CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm)); + auto obj = secondeArg->ToObject(vm); + auto containerId = Container::CurrentId(); + panda::Local func = obj; + auto onFocusAxisEvent = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), + containerId](FocusAxisEventInfo& info) { + panda::LocalScope pandaScope(vm); + panda::TryCatch trycatch(vm); + ContainerScope scope(containerId); + PipelineContext::SetCallBackNode(node); + auto obj = CreateFocusAxisEventInfo(vm, info); + panda::Local params[] = { obj }; + func->Call(vm, func.ToLocal(), params, 1); + }; + NG::ViewAbstract::SetOnFocusAxisEvent(frameNode, std::move(onFocusAxisEvent)); + return panda::JSValueRef::Undefined(vm); +} + +ArkUINativeModuleValue CommonBridge::ResetOnFocusAxisEvent(ArkUIRuntimeCallInfo* runtimeCallInfo) +{ + EcmaVM* vm = runtimeCallInfo->GetVM(); + CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); + auto* frameNode = GetFrameNode(runtimeCallInfo); + CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm)); + ViewAbstract::DisableOnFocusAxisEvent(frameNode); + return panda::JSValueRef::Undefined(vm); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h index e3f9e5a1903..a2965fb6c49 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h @@ -18,6 +18,7 @@ #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_bridge.h" #include "core/components_ng/pattern/gesture/gesture_model.h" +#include "core/event/focus_axis_event.h" namespace OHOS::Ace::NG { class CommonBridge { @@ -373,6 +374,9 @@ public: static ArkUINativeModuleValue GetApiTargetVersion(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue SetFocusBox(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue ResetFocusBox(ArkUIRuntimeCallInfo* runtimeCallInfo); + static Local CreateFocusAxisEventInfo(EcmaVM* vm, NG::FocusAxisEventInfo& info); + static ArkUINativeModuleValue SetOnFocusAxisEvent(ArkUIRuntimeCallInfo* runtimeCallInfo); + static ArkUINativeModuleValue ResetOnFocusAxisEvent(ArkUIRuntimeCallInfo* runtimeCallInfo); }; } // namespace OHOS::Ace::NG diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp index b20fb86ec70..dc31b59ae80 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp @@ -51,6 +51,7 @@ #include "bridge/declarative_frontend/engine/functions/js_on_size_change_function.h" #include "bridge/declarative_frontend/engine/functions/js_should_built_in_recognizer_parallel_with_function.h" #include "bridge/declarative_frontend/engine/functions/js_touch_intercept_function.h" +#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h" #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_utils_bridge.h" #include "bridge/declarative_frontend/engine/jsi/js_ui_index.h" #include "bridge/declarative_frontend/engine/js_converter.h" @@ -59,6 +60,7 @@ #include "bridge/declarative_frontend/jsview/js_utils.h" #include "bridge/declarative_frontend/jsview/js_view_context.h" #include "bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h" +#include "core/event/focus_axis_event.h" #include "canvas_napi/js_canvas.h" #if !defined(PREVIEW) && defined(OHOS_PLATFORM) #include "interfaces/inner_api/ui_session/ui_session_manager.h" @@ -8833,6 +8835,7 @@ void JSViewAbstract::JSBind(BindingTarget globalObj) JSClass::StaticMethod("onSizeChange", &JSViewAbstract::JsOnSizeChange); JSClass::StaticMethod("touchable", &JSInteractableView::JsTouchable); JSClass::StaticMethod("monopolizeEvents", &JSInteractableView::JsMonopolizeEvents); + JSClass::StaticMethod("onFocusAxisEvent", &JSViewAbstract::JsOnFocusAxisEvent); JSClass::StaticMethod("accessibilityGroup", &JSViewAbstract::JsAccessibilityGroup); JSClass::StaticMethod("accessibilityText", &JSViewAbstract::JsAccessibilityText); @@ -10187,6 +10190,37 @@ void JSViewAbstract::JsKeyboardShortcut(const JSCallbackInfo& info) ViewAbstractModel::GetInstance()->SetKeyboardShortcut(value, keys, nullptr); } +void JSViewAbstract::JsOnFocusAxisEvent(const JSCallbackInfo& args) +{ + JSRef arg = args[0]; + if (arg->IsUndefined() && IsDisableEventVersion()) { + ViewAbstractModel::GetInstance()->DisableOnFocusAxisEvent(); + return; + } + if (!arg->IsFunction()) { + return; + } + EcmaVM* vm = args.GetVm(); + CHECK_NULL_VOID(vm); + auto jsOnFocusAxisEventFunc = JSRef::Cast(args[0]); + if (jsOnFocusAxisEventFunc->IsEmpty()) { + return; + } + auto jsOnFocusAxisFuncLocalHandle = jsOnFocusAxisEventFunc->GetLocalHandle(); + WeakPtr frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); + auto onFocusAxisEvent = [vm, execCtx = args.GetExecutionContext(), + func = panda::CopyableGlobal(vm, jsOnFocusAxisFuncLocalHandle), + node = frameNode](NG::FocusAxisEventInfo& info) { + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + ACE_SCORING_EVENT("onFocusAxis"); + PipelineContext::SetCallBackNode(node); + auto eventObj = NG::CommonBridge::CreateFocusAxisEventInfo(vm, info); + panda::Local params[1] = { eventObj }; + func->Call(vm, func.ToLocal(), params, 1); + }; + ViewAbstractModel::GetInstance()->SetOnFocusAxisEvent(std::move(onFocusAxisEvent)); +} + bool JSViewAbstract::CheckColor( const JSRef& jsValue, Color& result, const char* componentName, const char* propName) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h index e7a18977bdc..0772a06f6f5 100755 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h @@ -429,6 +429,7 @@ public: static void JsOpacityPassThrough(const JSCallbackInfo& info); static void JsTransitionPassThrough(const JSCallbackInfo& info); static void JsKeyboardShortcut(const JSCallbackInfo& info); + static void JsOnFocusAxisEvent(const JSCallbackInfo& args); static void JsObscured(const JSCallbackInfo& info); static void JsPrivacySensitive(const JSCallbackInfo& info); diff --git a/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h index 1799b1a0fae..5010d8d0284 100755 --- a/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h @@ -204,6 +204,7 @@ public: void SetOnFocusMove(std::function&& onFocusMoveCallback) override; void SetOnFocus(OnFocusFunc&& onFocusCallback) override; void SetOnBlur(OnBlurFunc&& onBlurCallback) override; + void SetOnFocusAxisEvent(OnFocusAxisEventFunc&& onFocusAxisCallback) override {} void SetDraggable(bool draggable) override {} void SetDragPreviewOptions(const NG::DragPreviewOption& previewOption) override {}; void SetOnDragStart(NG::OnDragStartFunc&& onDragStart) override; @@ -256,6 +257,7 @@ public: void DisableOnAreaChange() override {}; void DisableOnFocus() override {}; void DisableOnBlur() override {}; + void DisableOnFocusAxisEvent() override {}; void BindBackground(std::function&& buildFunc, const Alignment& align) override; void BindPopup(const RefPtr& param, const RefPtr& customNode) override; diff --git a/frameworks/core/common/event_manager.cpp b/frameworks/core/common/event_manager.cpp index 501a9afe503..4e830a8324e 100644 --- a/frameworks/core/common/event_manager.cpp +++ b/frameworks/core/common/event_manager.cpp @@ -22,6 +22,7 @@ #include "core/common/xcollie/xcollieInterface.h" #include "core/components_ng/manager/select_overlay/select_overlay_manager.h" #include "core/components_ng/pattern/window_scene/helper/window_scene_helper.h" +#include "core/event/focus_axis_event.h" namespace OHOS::Ace { constexpr int32_t DUMP_START_NUMBER = 4; @@ -2059,6 +2060,9 @@ bool EventManager::OnNonPointerEvent(const NonPointerEvent& event) if (event.eventType == UIInputEventType::KEY) { return OnKeyEvent(static_cast(event)); } + if (event.eventType == UIInputEventType::FOCUS_AXIS) { + return OnFocusAxisEvent(static_cast(event)); + } return false; } diff --git a/frameworks/core/common/key_event_manager.cpp b/frameworks/core/common/key_event_manager.cpp index 96d0f00cdf8..7d755cfdfcd 100644 --- a/frameworks/core/common/key_event_manager.cpp +++ b/frameworks/core/common/key_event_manager.cpp @@ -569,6 +569,20 @@ bool KeyEventManager::OnKeyEvent(const KeyEvent& event) return false; } +bool KeyEventManager::OnFocusAxisEvent(const FocusAxisEvent& event) +{ + auto container = Container::GetContainer(GetInstanceId()); + CHECK_NULL_RETURN(container, false); + auto pipeline = DynamicCast(container->GetPipelineContext()); + CHECK_NULL_RETURN(pipeline, false); + auto rootNode = pipeline->GetRootElement(); + CHECK_NULL_RETURN(rootNode, false); + auto focusNodeHub = rootNode->GetFocusHub(); + CHECK_NULL_RETURN(focusNodeHub, false); + focusNodeHub->HandleEvent(event); + return true; +} + bool KeyEventManager::TriggerKeyEventDispatch(const KeyEvent& event) { auto focusManager = GetFocusManager(GetInstanceId()); diff --git a/frameworks/core/common/key_event_manager.h b/frameworks/core/common/key_event_manager.h index 6fb1689f6a7..195e43bd90b 100644 --- a/frameworks/core/common/key_event_manager.h +++ b/frameworks/core/common/key_event_manager.h @@ -20,6 +20,7 @@ #include "core/components/common/layout/constants.h" #include "core/event/key_event.h" +#include "core/event/focus_axis_event.h" namespace OHOS::Ace { namespace NG { @@ -59,6 +60,7 @@ protected: virtual int32_t GetInstanceId() = 0; bool OnKeyEvent(const KeyEvent& event); + bool OnFocusAxisEvent(const FocusAxisEvent& event); private: // Distribute the key event to the corresponding root node. If the root node is not processed, return false and the diff --git a/frameworks/core/components_ng/base/view_abstract.cpp b/frameworks/core/components_ng/base/view_abstract.cpp index 71f75c0dcd0..908c7dd4e66 100644 --- a/frameworks/core/components_ng/base/view_abstract.cpp +++ b/frameworks/core/components_ng/base/view_abstract.cpp @@ -925,6 +925,20 @@ void ViewAbstract::DisableOnBlur() focusHub->ClearOnBlurCallback(); } +void ViewAbstract::DisableOnFocusAxisEvent() +{ + auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub(); + CHECK_NULL_VOID(focusHub); + focusHub->ClearOnFocusAxisCallback(); +} + +void ViewAbstract::DisableOnFocusAxisEvent(FrameNode* frameNode) +{ + auto focusHub = frameNode->GetOrCreateFocusHub(); + CHECK_NULL_VOID(focusHub); + focusHub->ClearOnFocusAxisCallback(); +} + void ViewAbstract::DisableOnClick(FrameNode* frameNode) { auto gestureHub = frameNode->GetOrCreateGestureEventHub(); @@ -1351,6 +1365,20 @@ void ViewAbstract::SetOnTouchTestFunc(NG::OnChildTouchTestFunc&& onChildTouchTes gestureHub->SetOnTouchTestFunc(std::move(onChildTouchTest)); } +void ViewAbstract::SetOnFocusAxisEvent(OnFocusAxisEventFunc&& onFocusAxisCallback) +{ + auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub(); + CHECK_NULL_VOID(focusHub); + focusHub->SetOnFocusAxisCallback(std::move(onFocusAxisCallback)); +} + +void ViewAbstract::SetOnFocusAxisEvent(FrameNode* frameNode, OnFocusAxisEventFunc &&onFocusAxisCallback) +{ + CHECK_NULL_VOID(frameNode); + auto focusHub = frameNode->GetOrCreateFocusHub(); + focusHub->SetOnFocusAxisCallback(std::move(onFocusAxisCallback)); +} + void ViewAbstract::AddDragFrameNodeToManager() { auto pipeline = PipelineContext::GetCurrentContext(); diff --git a/frameworks/core/components_ng/base/view_abstract.h b/frameworks/core/components_ng/base/view_abstract.h index bdc75c46bb7..44499d8c1c6 100644 --- a/frameworks/core/components_ng/base/view_abstract.h +++ b/frameworks/core/components_ng/base/view_abstract.h @@ -303,6 +303,7 @@ public: static void SetTouchable(bool touchable); static void SetHitTestMode(HitTestMode hitTestMode); static void SetOnTouchTestFunc(NG::OnChildTouchTestFunc&& onChildTouchTest); + static void SetOnFocusAxisEvent(OnFocusAxisEventFunc&& onFocusAxisCallback); static void SetDraggable(bool draggable); static void SetDragPreviewOptions(const DragPreviewOption& previewOption); static void SetOnDragStart( @@ -400,6 +401,8 @@ public: static void DisableOnAreaChange(); static void DisableOnFocus(); static void DisableOnBlur(); + static void DisableOnFocusAxisEvent(); + static void DisableOnFocusAxisEvent(FrameNode* frameNode); static void DisableOnClick(FrameNode* frameNode); static void DisableOnDragStart(FrameNode* frameNode); static void DisableOnDragEnter(FrameNode* frameNode); @@ -655,6 +658,7 @@ public: static void SetSystemFontChangeEvent(FrameNode* frameNode, std::function&& onFontChange); static void SetFocusBoxStyle(FrameNode* frameNode, const NG::FocusBoxStyle& style); static void SetClickDistance(FrameNode* frameNode, double clickDistance); + static void SetOnFocusAxisEvent(FrameNode* frameNode, OnFocusAxisEventFunc &&onFocusAxisCallback); static bool GetFocusable(FrameNode* frameNode); static bool GetTabStop(FrameNode* frameNode); diff --git a/frameworks/core/components_ng/base/view_abstract_model.h b/frameworks/core/components_ng/base/view_abstract_model.h index b339deaf842..b6fc4970d11 100755 --- a/frameworks/core/components_ng/base/view_abstract_model.h +++ b/frameworks/core/components_ng/base/view_abstract_model.h @@ -280,6 +280,7 @@ public: virtual void SetOnFocusMove(std::function&& onFocusMoveCallback) = 0; virtual void SetOnFocus(OnFocusFunc&& onFocusCallback) = 0; virtual void SetOnBlur(OnBlurFunc&& onBlurCallback) = 0; + virtual void SetOnFocusAxisEvent(OnFocusAxisEventFunc&& onFocusAxisCallback) = 0; virtual void SetDraggable(bool draggable) = 0; virtual void SetDragPreviewOptions(const NG::DragPreviewOption& previewOption) = 0; virtual void SetOnDragStart(NG::OnDragStartFunc&& onDragStart) = 0; @@ -316,6 +317,7 @@ public: virtual void DisableOnAreaChange() = 0; virtual void DisableOnFocus() = 0; virtual void DisableOnBlur() = 0; + virtual void DisableOnFocusAxisEvent() = 0; // interact virtual void SetResponseRegion(const std::vector& responseRegion) = 0; diff --git a/frameworks/core/components_ng/base/view_abstract_model_ng.h b/frameworks/core/components_ng/base/view_abstract_model_ng.h index c222faf7d92..8d799cf4565 100755 --- a/frameworks/core/components_ng/base/view_abstract_model_ng.h +++ b/frameworks/core/components_ng/base/view_abstract_model_ng.h @@ -1018,6 +1018,11 @@ public: ViewAbstract::SetOnBlur(std::move(onBlurCallback)); } + void SetOnFocusAxisEvent(OnFocusAxisEventFunc&& onFocusAxisCallback) override + { + ViewAbstract::SetOnFocusAxisEvent(std::move(onFocusAxisCallback)); + } + void SetDraggable(bool draggable) override { ViewAbstract::SetDraggable(draggable); @@ -1400,6 +1405,18 @@ public: ViewAbstract::DisableOnBlur(); } + void DisableOnFocusAxisEvent() override + { + ViewAbstract::DisableOnFocusAxisEvent(); + } + + static void DisableOnFocusAxisEvent(FrameNode* frameNode) + { + auto focusHub = frameNode->GetOrCreateFocusHub(); + CHECK_NULL_VOID(focusHub); + focusHub->ClearOnFocusAxisCallback(); + } + static void SetAccessibilityText(FrameNode* frameNode, const std::string& text); void SetLightPosition( diff --git a/frameworks/core/components_ng/event/event_constants.h b/frameworks/core/components_ng/event/event_constants.h index 150e5c76847..3f2de00fc16 100644 --- a/frameworks/core/components_ng/event/event_constants.h +++ b/frameworks/core/components_ng/event/event_constants.h @@ -90,6 +90,17 @@ enum class EventTreeType { POST_EVENT, }; +enum class AxisModel { + ABS_X = 0, + ABS_Y, + ABS_Z, + ABS_RZ, + ABS_GAS, + ABS_BRAKE, + ABS_HAT0X, + ABS_HAT0Y, +}; + } // namespace OHOS::Ace::NG namespace OHOS::Ace { @@ -120,7 +131,7 @@ enum class UIInputEventType { TOUCH, AXIS, KEY, - NON_POINTER_AXIS, + FOCUS_AXIS, }; enum class KeyIntention : int32_t { diff --git a/frameworks/core/components_ng/event/focus_event_handler.cpp b/frameworks/core/components_ng/event/focus_event_handler.cpp index 0b0716356e9..1da7f604e14 100644 --- a/frameworks/core/components_ng/event/focus_event_handler.cpp +++ b/frameworks/core/components_ng/event/focus_event_handler.cpp @@ -15,6 +15,7 @@ #include "focus_event_handler.h" #include "core/components_ng/base/frame_node.h" +#include "core/event/focus_axis_event.h" #include "core/pipeline_ng/pipeline_context.h" namespace OHOS::Ace::NG { @@ -105,9 +106,10 @@ bool FocusEventHandler::OnFocusEventNode(const FocusEvent& focusEvent) if (focusEvent.event.eventType == UIInputEventType::KEY) { const KeyEvent& keyEvent = static_cast(focusEvent.event); ret = HandleKeyEvent(keyEvent, focusEvent.intension); - } else { - LOGI("Handle NonPointerAxisEvent"); - return false; + } + if (focusEvent.event.eventType == UIInputEventType::FOCUS_AXIS) { + const FocusAxisEvent& focusAxisEvent = static_cast(focusEvent.event); + return HandleFocusAxisEvent(focusAxisEvent); } return ret ? true : HandleFocusTravel(focusEvent); } @@ -154,6 +156,24 @@ bool FocusEventHandler::HandleKeyEvent(const KeyEvent& event, FocusIntension int return ret; } +bool FocusEventHandler::HandleFocusAxisEvent(const FocusAxisEvent& event) +{ + auto node = GetFrameNode(); + CHECK_NULL_RETURN(node, false); + auto* pipeline = node->GetContext(); + CHECK_NULL_RETURN(pipeline, false); + auto onFocusAxisCallback = GetOnFocusAxisCallback(); + CHECK_NULL_RETURN(onFocusAxisCallback, false); + auto info = FocusAxisEventInfo(event); + auto eventHub = eventHub_.Upgrade(); + if (eventHub) { + auto targetImpl = eventHub->CreateGetEventTargetImpl(); + info.SetTarget(targetImpl().value_or(EventTarget())); + } + onFocusAxisCallback(info); + return info.IsStopPropagation(); +} + bool FocusEventHandler::OnKeyPreIme(KeyEventInfo& info, const KeyEvent& keyEvent) { TAG_LOGD(AceLogTag::ACE_FOCUS, diff --git a/frameworks/core/components_ng/event/focus_event_handler.h b/frameworks/core/components_ng/event/focus_event_handler.h index 7d32ad8b8ba..df85494aa22 100644 --- a/frameworks/core/components_ng/event/focus_event_handler.h +++ b/frameworks/core/components_ng/event/focus_event_handler.h @@ -17,6 +17,7 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_FOCUS_HANDLER_H #include "focus_state.h" +#include "core/event/focus_axis_event.h" #include "core/event/key_event.h" #include "core/gestures/gesture_event.h" namespace OHOS::Ace::NG { @@ -79,6 +80,7 @@ public: OnKeyCallbackFunc onJSFrameNodeKeyEventCallback_; OnKeyConsumeFunc onKeyPreImeCallback_; GestureEventFunc onClickEventCallback_; + OnFocusAxisEventFunc onFocusAxisEventCallback_; WeakPtr defaultFocusNode_; bool isDefaultFocus_ = { false }; @@ -123,6 +125,7 @@ protected: ACE_DEFINE_FOCUS_EVENT(OnKeyCallback, OnKeyConsumeFunc, onKeyEventCallback) ACE_DEFINE_FOCUS_EVENT(OnKeyPreIme, OnKeyConsumeFunc, onKeyPreImeCallback) ACE_DEFINE_FOCUS_EVENT(OnClickCallback, GestureEventFunc, onClickEventCallback) + ACE_DEFINE_FOCUS_EVENT(OnFocusAxisCallback, OnFocusAxisEventFunc, onFocusAxisEventCallback) std::unordered_map onKeyEventsInternal_; bool forceProcessOnKeyEventInternal_ { false }; // extension use only @@ -137,6 +140,7 @@ private: bool OnKeyEventNodeInternal(const KeyEvent& keyEvent); bool OnKeyEventNodeUser(KeyEventInfo& info, const KeyEvent& keyEvent); bool ProcessOnKeyEventInternal(const KeyEvent& event); + bool HandleFocusAxisEvent(const FocusAxisEvent& event); void PrintOnKeyEventUserInfo(const KeyEvent& keyEvent, bool retCallback); }; diff --git a/frameworks/core/event/ace_events.h b/frameworks/core/event/ace_events.h index 0521f579195..7eec96a4c49 100644 --- a/frameworks/core/event/ace_events.h +++ b/frameworks/core/event/ace_events.h @@ -35,7 +35,8 @@ enum class SourceType : int32_t { MOUSE = 1, TOUCH = 2, TOUCH_PAD = 3, - KEYBOARD = 4 + KEYBOARD = 4, + JOYSTICK = 5, }; enum class SourceTool : int32_t { diff --git a/frameworks/core/event/non_pointer_axis_event.h b/frameworks/core/event/focus_axis_event.h similarity index 46% rename from frameworks/core/event/non_pointer_axis_event.h rename to frameworks/core/event/focus_axis_event.h index 112e8a39676..f6f3f459c79 100644 --- a/frameworks/core/event/non_pointer_axis_event.h +++ b/frameworks/core/event/focus_axis_event.h @@ -13,15 +13,15 @@ * limitations under the License. */ -#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_NON_POINTER_AXIS_EVENT_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_NON_POINTER_AXIS_EVENT_H +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_FOCUS_AXIS_EVENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_FOCUS_AXIS_EVENT_H #include "core/event/non_pointer_event.h" #include "core/components_ng/event/event_constants.h" namespace OHOS::Ace::NG { -struct NonPointerAxisEvent final : public NonPointerEvent { +struct FocusAxisEvent final : public NonPointerEvent { int32_t id = 0; AxisAction action = AxisAction::NONE; SourceTool sourceTool = SourceTool::UNKNOWN; @@ -38,108 +38,181 @@ struct NonPointerAxisEvent final : public NonPointerEvent { float absHat0YValue = 0.0f; float absBrakeValue = 0.0f; float absGasValue = 0.0f; - ~NonPointerAxisEvent() = default; - NonPointerAxisEvent() + ~FocusAxisEvent() = default; + FocusAxisEvent() { - eventType = UIInputEventType::NON_POINTER_AXIS; + eventType = UIInputEventType::FOCUS_AXIS; } - NonPointerAxisEvent& SetId(int32_t id) + FocusAxisEvent& SetId(int32_t id) { this->id = id; return *this; } - NonPointerAxisEvent& SetAction(AxisAction action) + FocusAxisEvent& SetAction(AxisAction action) { this->action = action; return *this; } - NonPointerAxisEvent& SetSourceTool(SourceTool sourceTool) + FocusAxisEvent& SetSourceTool(SourceTool sourceTool) { this->sourceTool = sourceTool; return *this; } - NonPointerAxisEvent& SetPointerEvent(std::shared_ptr pointerEvent) + FocusAxisEvent& SetPointerEvent(std::shared_ptr pointerEvent) { this->pointerEvent = std::move(pointerEvent); return *this; } - NonPointerAxisEvent& SetTouchEventId(int32_t touchEventId) + FocusAxisEvent& SetTouchEventId(int32_t touchEventId) { this->touchEventId = touchEventId; return *this; } - NonPointerAxisEvent& SetPressedKeyCodes(const std::vector& pressedCodes) + FocusAxisEvent& SetPressedKeyCodes(const std::vector& pressedCodes) { this->pressedCodes = pressedCodes; return *this; } - NonPointerAxisEvent& SetTargetDisplayId(int32_t targetDisplayId) + FocusAxisEvent& SetTargetDisplayId(int32_t targetDisplayId) { this->targetDisplayId = targetDisplayId; return *this; } - NonPointerAxisEvent& SetOriginalId(int32_t originalId) + FocusAxisEvent& SetOriginalId(int32_t originalId) { this->originalId = originalId; return *this; } - NonPointerAxisEvent& SetAbsXValue(float absXValue) + FocusAxisEvent& SetAbsXValue(float absXValue) { this->absXValue = absXValue; return *this; } - NonPointerAxisEvent& SetAbsYValue(float absYValue) + FocusAxisEvent& SetAbsYValue(float absYValue) { this->absYValue = absYValue; return *this; } - NonPointerAxisEvent& SetAbsZValue(float absZValue) + FocusAxisEvent& SetAbsZValue(float absZValue) { this->absZValue = absZValue; return *this; } - NonPointerAxisEvent& SetAbsRzValue(float absRzValue) + FocusAxisEvent& SetAbsRzValue(float absRzValue) { this->absRzValue = absRzValue; return *this; } - NonPointerAxisEvent& SetAbsHat0XValue(float absHat0XValue) + FocusAxisEvent& SetAbsHat0XValue(float absHat0XValue) { this->absHat0XValue = absHat0XValue; return *this; } - NonPointerAxisEvent& SetAbsHat0YValue(float absHat0YValue) + FocusAxisEvent& SetAbsHat0YValue(float absHat0YValue) { this->absHat0YValue = absHat0YValue; return *this; } - NonPointerAxisEvent& SetAbsBrakeValue(float absBrakeValue) + FocusAxisEvent& SetAbsBrakeValue(float absBrakeValue) { this->absBrakeValue = absBrakeValue; return *this; } - NonPointerAxisEvent& SetAbsGasValue(float absGasValue) + FocusAxisEvent& SetAbsGasValue(float absGasValue) { this->absGasValue = absGasValue; return *this; } }; +class ACE_EXPORT FocusAxisEventInfo : public BaseEventInfo { + DECLARE_RELATIONSHIP_OF_CLASSES(FocusAxisEventInfo, BaseEventInfo) + +public: + explicit FocusAxisEventInfo(const FocusAxisEvent& event) : BaseEventInfo("focusAxisEvent") + { + absXValue = event.absXValue; + absYValue = event.absYValue; + absZValue = event.absZValue; + absRzValue = event.absRzValue; + absHat0XValue = event.absHat0XValue; + absHat0YValue = event.absHat0YValue; + absBrakeValue = event.absBrakeValue; + absGasValue = event.absGasValue; + timeStamp_ = event.time; + sourceTool_ = event.sourceTool; + deviceType_ = event.sourceType; + deviceId_ = event.deviceId; + pressedKeyCodes_ = event.pressedCodes; + }; + ~FocusAxisEventInfo() override = default; + + float GetAbsXValue() const + { + return absXValue; + } + + float GetAbsYValue() const + { + return absYValue; + } + + float GetAbsZValue() const + { + return absZValue; + } + + float GetAbsRzValue() const + { + return absRzValue; + } + + float GetAbsHat0XValue() const + { + return absHat0XValue; + } + + float GetAbsHat0YValue() const + { + return absHat0YValue; + } + + float GetAbsBrakeValue() const + { + return absBrakeValue; + } + + float GetAbsGasValue() const + { + return absGasValue; + } + +private: + float absXValue = 0.0f; + float absYValue = 0.0f; + float absZValue = 0.0f; + float absRzValue = 0.0f; + float absHat0XValue = 0.0f; + float absHat0YValue = 0.0f; + float absBrakeValue = 0.0f; + float absGasValue = 0.0f; +}; + } // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_NON_POINTER_AXIS_EVENT_H +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_FOCUS_AXIS_EVENT_H diff --git a/frameworks/core/event/key_event.h b/frameworks/core/event/key_event.h index 3d87eb3ddd3..522ef070f14 100644 --- a/frameworks/core/event/key_event.h +++ b/frameworks/core/event/key_event.h @@ -19,6 +19,7 @@ #include #include "core/event/ace_events.h" +#include "core/event/focus_axis_event.h" #include "core/event/non_pointer_event.h" namespace OHOS::MMI { @@ -672,5 +673,6 @@ using OnPaintFocusStateFunc = std::function; using OnBlurFunc = std::function; using OnBlurReasonFunc = std::function; using OnPreFocusFunc = std::function; +using OnFocusAxisEventFunc = std::function; } // namespace OHOS::Ace #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_KEY_EVENT_H diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index b7d973b9a59..b14d968ecc7 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -265,6 +265,28 @@ struct ArkUIDragEvent { ArkUI_Int32 dataTypesMaxStrLength; }; +struct ArkUIFocusAxisEvent { + ArkUI_Float64 absXValue; + ArkUI_Float64 absYValue; + ArkUI_Float64 absZValue; + ArkUI_Float64 absRzValue; + ArkUI_Float64 absHat0XValue; + ArkUI_Float64 absHat0YValue; + ArkUI_Float64 absBrakeValue; + ArkUI_Float64 absGasValue; + ArkUI_Float64 tiltX; + ArkUI_Float64 tiltY; + ArkUI_Float64 pressure; + ArkUI_Int32 toolType; + ArkUI_Int64 timeStamp; + ArkUI_Int32 subKind; + ArkUI_Int32 sourceType; + ArkUI_Int64 deviceId; + ArkUI_Int32* pressedKeyCodes; + ArkUI_Int32 keyCodesLength; + bool stopPropagation; +}; + struct ArkUIStringAndFloat { ArkUI_Float32 value; ArkUI_CharPtr valueStr; @@ -790,6 +812,7 @@ enum ArkUIEventCategory { MIXED_EVENT = 11, DRAG_EVENT = 12, KEY_INPUT_EVENT = 13, // KEY_EVENT is already defined as a macro in wincon.h + FOCUS_AXIS_EVENT = 14, }; #define ARKUI_MAX_EVENT_NUM 1000 @@ -820,6 +843,7 @@ enum ArkUIEventSubKind { ON_DRAG_END, ON_PRE_DRAG, ON_KEY_PREIME, + ON_FOCUS_AXIS, ON_DETECT_RESULT_UPDATE = ARKUI_MAX_EVENT_NUM * ARKUI_TEXT, ON_IMAGE_COMPLETE = ARKUI_MAX_EVENT_NUM * ARKUI_IMAGE, ON_IMAGE_ERROR, @@ -1144,6 +1168,7 @@ struct ArkUINodeEvent { ArkUIMixedEvent mixedEvent; ArkUIDragEvent dragEvent; ArkUIKeyEvent keyEvent; + ArkUIFocusAxisEvent focusAxisEvent; }; }; diff --git a/frameworks/core/interfaces/native/node/node_api.cpp b/frameworks/core/interfaces/native/node/node_api.cpp index d3857706cef..388cf930c91 100644 --- a/frameworks/core/interfaces/native/node/node_api.cpp +++ b/frameworks/core/interfaces/native/node/node_api.cpp @@ -323,6 +323,7 @@ const ComponentAsyncEventHandler commonNodeAsyncEventHandlers[] = { NodeModifier::SetOnDragEnd, NodeModifier::SetOnPreDrag, NodeModifier::SetOnKeyPreIme, + NodeModifier::SetOnFocusAxisEvent, }; const ComponentAsyncEventHandler scrollNodeAsyncEventHandlers[] = { @@ -524,6 +525,7 @@ const ResetComponentAsyncEventHandler COMMON_NODE_RESET_ASYNC_EVENT_HANDLERS[] = NodeModifier::ResetOnDragEnd, NodeModifier::ResetOnPreDrag, NodeModifier::ResetOnKeyPreIme, + NodeModifier::ResetOnFocusAxisEvent, }; const ResetComponentAsyncEventHandler SCROLL_NODE_RESET_ASYNC_EVENT_HANDLERS[] = { diff --git a/frameworks/core/interfaces/native/node/node_common_modifier.cpp b/frameworks/core/interfaces/native/node/node_common_modifier.cpp index d3911eb6c6a..838cf68d85c 100644 --- a/frameworks/core/interfaces/native/node/node_common_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_common_modifier.cpp @@ -6674,6 +6674,43 @@ void SetOnKeyPreIme(ArkUINodeHandle node, void* extraParam) NG::ViewAbstractModelNG::SetOnKeyPreIme(frameNode, std::move(onPreImeEvent)); } +void SetOnFocusAxisEvent(ArkUINodeHandle node, void* extraParam) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + int32_t nodeId = frameNode->GetId(); + auto onFocusAxisEvent = [frameNode, nodeId, extraParam](FocusAxisEventInfo& info) { + ArkUINodeEvent event; + event.kind = ArkUIEventCategory::FOCUS_AXIS_EVENT; + event.nodeId = nodeId; + event.extraParam = reinterpret_cast(extraParam); + event.focusAxisEvent.subKind = ArkUIEventSubKind::ON_FOCUS_AXIS; + event.focusAxisEvent.absXValue = info.GetAbsXValue(); + event.focusAxisEvent.absYValue = info.GetAbsYValue(); + event.focusAxisEvent.absZValue = info.GetAbsZValue(); + event.focusAxisEvent.absRzValue = info.GetAbsRzValue(); + event.focusAxisEvent.absGasValue = info.GetAbsGasValue(); + event.focusAxisEvent.absBrakeValue = info.GetAbsBrakeValue(); + event.focusAxisEvent.absHat0XValue = info.GetAbsHat0XValue(); + event.focusAxisEvent.absHat0YValue = info.GetAbsHat0YValue(); + event.focusAxisEvent.timeStamp = static_cast(info.GetTimeStamp().time_since_epoch().count()); + event.focusAxisEvent.toolType = static_cast(info.GetSourceTool()); + event.focusAxisEvent.sourceType = static_cast(info.GetSourceDevice()); + event.focusAxisEvent.deviceId = info.GetDeviceId(); + std::vector pressKeyCodeList; + auto pressedKeyCodes = info.GetPressedKeyCodes(); + event.focusAxisEvent.keyCodesLength = pressedKeyCodes.size(); + for (auto it = pressedKeyCodes.begin(); it != pressedKeyCodes.end(); it++) { + pressKeyCodeList.push_back(static_cast(*it)); + } + event.focusAxisEvent.pressedKeyCodes = pressKeyCodeList.data(); + PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode)); + SendArkUISyncEvent(&event); + info.SetStopPropagation(event.focusAxisEvent.stopPropagation); + }; + ViewAbstract::SetOnFocusAxisEvent(frameNode, onFocusAxisEvent); +} + void ResetOnKeyEvent(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); @@ -6688,6 +6725,13 @@ void ResetOnKeyPreIme(ArkUINodeHandle node) NG::ViewAbstractModelNG::DisableOnKeyPreIme(frameNode); } +void ResetOnFocusAxisEvent(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + NG::ViewAbstractModelNG::DisableOnFocusAxisEvent(frameNode); +} + void ConvertTouchLocationInfoToPoint(const TouchLocationInfo& locationInfo, ArkUITouchPoint& touchPoint, bool usePx) { const OHOS::Ace::Offset& globalLocation = locationInfo.GetGlobalLocation(); diff --git a/frameworks/core/interfaces/native/node/node_common_modifier.h b/frameworks/core/interfaces/native/node/node_common_modifier.h index c1a115e7c48..8f27d172e65 100644 --- a/frameworks/core/interfaces/native/node/node_common_modifier.h +++ b/frameworks/core/interfaces/native/node/node_common_modifier.h @@ -37,6 +37,7 @@ void SetOnMouse(ArkUINodeHandle node, void* extraParam); void SetOnAccessibilityActions(ArkUINodeHandle node, void* extraParam); void SetOnKeyEvent(ArkUINodeHandle node, void* extraParam); void SetOnKeyPreIme(ArkUINodeHandle node, void* extraParam); +void SetOnFocusAxisEvent(ArkUINodeHandle node, void* extraParam); void ResetOnAppear(ArkUINodeHandle node); void ResetOnDisappear(ArkUINodeHandle node); @@ -53,5 +54,6 @@ void ResetOnHover(ArkUINodeHandle node); void ResetOnMouse(ArkUINodeHandle node); void ResetOnKeyEvent(ArkUINodeHandle node); void ResetOnKeyPreIme(ArkUINodeHandle node); +void ResetOnFocusAxisEvent(ArkUINodeHandle node); } // namespace OHOS::Ace::NG::NodeModifier #endif // FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_COMMON_MODIFIER_H diff --git a/interfaces/native/event/ui_input_event.cpp b/interfaces/native/event/ui_input_event.cpp index c57fa40dae3..f469ad7fab4 100644 --- a/interfaces/native/event/ui_input_event.cpp +++ b/interfaces/native/event/ui_input_event.cpp @@ -111,6 +111,13 @@ int32_t OH_ArkUI_UIInputEvent_GetSourceType(const ArkUI_UIInputEvent* event) } return axisEvent->sourceType; } + case C_FOCUS_AXIS_EVENT_ID: { + const auto* focusAxisEvent = reinterpret_cast(event->inputEvent); + if (!focusAxisEvent) { + return static_cast(UI_INPUT_EVENT_SOURCE_TYPE_UNKNOWN); + } + return focusAxisEvent->sourceType; + } default: break; } @@ -144,6 +151,13 @@ int32_t OH_ArkUI_UIInputEvent_GetToolType(const ArkUI_UIInputEvent* event) } return OHOS::Ace::NodeModel::ConvertToCInputEventToolType(axisEvent->actionTouchPoint.toolType); } + case C_FOCUS_AXIS_EVENT_ID: { + const auto* focusAxisEvent = reinterpret_cast(event->inputEvent); + if (!focusAxisEvent) { + return static_cast(UI_INPUT_EVENT_TOOL_TYPE_UNKNOWN); + } + return OHOS::Ace::NodeModel::ConvertToCInputEventToolType(focusAxisEvent->toolType); + } default: break; } @@ -206,6 +220,15 @@ int64_t HandleCKeyEvent(ArkUI_UIInputEvent* event) return keyEvent->timestamp; } +int64_t HandleCFocusAxisEvent(ArkUI_UIInputEvent* event) +{ + const auto* focusAxisEvent = reinterpret_cast(event->inputEvent); + if (!focusAxisEvent) { + return 0; + } + return focusAxisEvent->timeStamp; +} + int64_t OH_ArkUI_UIInputEvent_GetEventTime(const ArkUI_UIInputEvent* event) { if (!event) { @@ -217,7 +240,8 @@ int64_t OH_ArkUI_UIInputEvent_GetEventTime(const ArkUI_UIInputEvent* event) {AXIS_EVENT_ID, HandleAxisEvent}, {C_MOUSE_EVENT_ID, HandleCMouseEvent}, {C_AXIS_EVENT_ID, HandleCAxisEvent}, - {C_KEY_EVENT_ID, HandleCKeyEvent} + {C_KEY_EVENT_ID, HandleCKeyEvent}, + {C_FOCUS_AXIS_EVENT_ID, HandleCFocusAxisEvent}, }; auto it = eventHandlers.find(event->eventTypeId); if (it != eventHandlers.end()) { @@ -227,40 +251,95 @@ int64_t OH_ArkUI_UIInputEvent_GetEventTime(const ArkUI_UIInputEvent* event) return 0; } +int32_t GetCKeyEventDeviceId(ArkUI_UIInputEvent* event) +{ + const auto* keyEvent = reinterpret_cast(event->inputEvent); + if (!keyEvent) { + return -1; + } + return static_cast(keyEvent->deviceId); +} + +int32_t GetCFocusAxisEventDeviceId(ArkUI_UIInputEvent* event) +{ + const auto* focusAxisEvent = reinterpret_cast(event->inputEvent); + if (!focusAxisEvent) { + return -1; + } + return static_cast(focusAxisEvent->deviceId); +} + int32_t OH_ArkUI_UIInputEvent_GetDeviceId(const ArkUI_UIInputEvent *event) { if (!event) { return -1; } - const auto* keyEvent = reinterpret_cast(event->inputEvent); - if (!keyEvent) { - return -1; + std::map> eventHandlers = { + {C_KEY_EVENT_ID, GetCKeyEventDeviceId}, + {C_FOCUS_AXIS_EVENT_ID, GetCFocusAxisEventDeviceId}, + }; + auto iter = eventHandlers.find(event->eventTypeId); + if (iter != eventHandlers.end()) { + ArkUI_UIInputEvent* inputEvent = const_cast(event); + return iter->second(inputEvent); } - auto result = static_cast(keyEvent->deviceId); - return result; + return -1; } -int32_t OH_ArkUI_UIInputEvent_GetPressedKeys( +int32_t GetCKeyEventPressedKeys( const ArkUI_UIInputEvent* event, int32_t* pressedKeyCodes, int32_t* length) { - if (!event || !pressedKeyCodes || !length) { - return ARKUI_ERROR_CODE_PARAM_INVALID; - } const auto* keyEvent = reinterpret_cast(event->inputEvent); if (!keyEvent) { return ARKUI_ERROR_CODE_PARAM_INVALID; } auto inputLength = *length; - *length = keyEvent->keyCodesLength; if (keyEvent->keyCodesLength > inputLength) { return ARKUI_ERROR_CODE_BUFFER_SIZE_NOT_ENOUGH; } + *length = keyEvent->keyCodesLength; for (int i = 0; i < keyEvent->keyCodesLength; i++) { pressedKeyCodes[i] = keyEvent->pressedKeyCodes[i]; } return ARKUI_ERROR_CODE_NO_ERROR; } +int32_t GetCFocusAxisEventPressedKeys( + const ArkUI_UIInputEvent* event, int32_t* pressedKeyCodes, int32_t* length) +{ + const auto* focusAxisEvent = reinterpret_cast(event->inputEvent); + if (!focusAxisEvent) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + auto inputLength = *length; + if (focusAxisEvent->keyCodesLength > inputLength) { + return ARKUI_ERROR_CODE_BUFFER_SIZE_NOT_ENOUGH; + } + *length = focusAxisEvent->keyCodesLength; + for (int i = 0; i < focusAxisEvent->keyCodesLength; i++) { + pressedKeyCodes[i] = focusAxisEvent->pressedKeyCodes[i]; + } + return ARKUI_ERROR_CODE_NO_ERROR; +} + +int32_t OH_ArkUI_UIInputEvent_GetPressedKeys( + const ArkUI_UIInputEvent* event, int32_t* pressedKeyCodes, int32_t* length) +{ + if (!event || !pressedKeyCodes || !length) { + return ARKUI_ERROR_CODE_PARAM_INVALID; + } + std::map> eventHandlers = { + {C_KEY_EVENT_ID, GetCKeyEventPressedKeys}, + {C_FOCUS_AXIS_EVENT_ID, GetCFocusAxisEventPressedKeys}, + }; + auto iter = eventHandlers.find(event->eventTypeId); + if (iter != eventHandlers.end()) { + ArkUI_UIInputEvent* inputEvent = const_cast(event); + return iter->second(inputEvent, pressedKeyCodes, length); + } + return ARKUI_ERROR_CODE_NO_ERROR; +} + uint32_t OH_ArkUI_PointerEvent_GetPointerCount(const ArkUI_UIInputEvent* event) { if (!event) { @@ -1361,6 +1440,58 @@ int32_t OH_ArkUI_MouseEvent_GetMouseAction(const ArkUI_UIInputEvent* event) return -1; } +double OH_ArkUI_FocusAxisEvent_GetAxisValue(const ArkUI_UIInputEvent* event, int32_t axis) +{ + if (!event) { + return 0.0; + } + if (event->eventTypeId != C_FOCUS_AXIS_EVENT_ID) { + return 0.0f; + } + const auto* focusAxisEvent = reinterpret_cast(event->inputEvent); + if (!focusAxisEvent) { + return 0.0; + } + switch (axis) { + case UI_FOCUS_AXIS_EVENT_ABS_X: + return focusAxisEvent->absXValue; + case UI_FOCUS_AXIS_EVENT_ABS_Y: + return focusAxisEvent->absYValue; + case UI_FOCUS_AXIS_EVENT_ABS_Z: + return focusAxisEvent->absZValue; + case UI_FOCUS_AXIS_EVENT_ABS_RZ: + return focusAxisEvent->absRzValue; + case UI_FOCUS_AXIS_EVENT_ABS_GAS: + return focusAxisEvent->absGasValue; + case UI_FOCUS_AXIS_EVENT_ABS_BRAKE: + return focusAxisEvent->absBrakeValue; + case UI_FOCUS_AXIS_EVENT_ABS_HAT0X: + return focusAxisEvent->absHat0XValue; + case UI_FOCUS_AXIS_EVENT_ABS_HAT0Y: + return focusAxisEvent->absHat0YValue; + default: + return 0.0; + } + return 0.0; +} + +int32_t OH_ArkUI_FocusAxisEvent_SetStopPropagation(const ArkUI_UIInputEvent* event, bool stopPropagation) +{ + if (!event) { + return OHOS::Ace::ERROR_CODE_PARAM_INVALID; + } + switch (event->eventTypeId) { + case C_FOCUS_AXIS_EVENT_ID: { + auto* focusAxisEvent = reinterpret_cast(event->inputEvent); + focusAxisEvent->stopPropagation = stopPropagation; + break; + } + default: + return OHOS::Ace::ERROR_CODE_PARAM_INVALID; + } + return OHOS::Ace::ERROR_CODE_NO_ERROR; +} + #ifdef __cplusplus }; #endif diff --git a/interfaces/native/event/ui_input_event_impl.h b/interfaces/native/event/ui_input_event_impl.h index 0ef6dc1512c..88e5b68d67a 100644 --- a/interfaces/native/event/ui_input_event_impl.h +++ b/interfaces/native/event/ui_input_event_impl.h @@ -29,6 +29,7 @@ typedef enum { C_MOUSE_EVENT_ID = 3, // defined in ace_engine/frameworks/core/interfaces/arkoala/arkoala_api.h C_AXIS_EVENT_ID = 4, // defined in ace_engine/frameworks/core/interfaces/arkoala/arkoala_api.h C_KEY_EVENT_ID = 5, // defined in ace_engine/frameworks/core/interfaces/arkoala/arkoala_api.h + C_FOCUS_AXIS_EVENT_ID = 6, // defined in ace_engine/frameworks/core/interfaces/arkoala/arkoala_api.h } ArkUIEventTypeId; struct ArkUI_UIInputEvent { diff --git a/interfaces/native/libace.ndk.json b/interfaces/native/libace.ndk.json index 9a6a30b7fb3..664bf63bebc 100644 --- a/interfaces/native/libace.ndk.json +++ b/interfaces/native/libace.ndk.json @@ -2474,5 +2474,13 @@ { "first_introduced": "14", "name": "OH_ArkUI_KeyEvent_SetConsumed" + }, + { + "first_introduced": "15", + "name": "OH_ArkUI_FocusAxisEvent_GetAxisValue" + }, + { + "first_introduced": "15", + "name": "OH_ArkUI_FocusAxisEvent_SetStopPropagation" } ] diff --git a/interfaces/native/native_key_event.h b/interfaces/native/native_key_event.h index 70958a81390..c9c2c4fb1d7 100644 --- a/interfaces/native/native_key_event.h +++ b/interfaces/native/native_key_event.h @@ -349,6 +349,12 @@ typedef enum { ARKUI_KEY_SOURCE_TYPE_MOUSE = 1, /** Keyboard **/ ARKUI_KEY_SOURCE_TYPE_KEYBOARD = 4, + /** + * @brief Joystick. + * + * @since 15 + */ + ARKUI_KEY_SOURCE_TYPE_JOYSTICK = 5, } ArkUI_KeySourceType; /** diff --git a/interfaces/native/native_node.h b/interfaces/native/native_node.h index 8246acc5805..72ad4fbe874 100644 --- a/interfaces/native/native_node.h +++ b/interfaces/native/native_node.h @@ -5506,6 +5506,16 @@ typedef enum { * @since 14 */ NODE_ON_KEY_PRE_IME = 22, + /** + * @brief Defines the event triggered when the bound component receives a focus axis event after gaining focus. + * + * The event callback is triggered by interactions with a joystick and a focused component. \n + * When the event callback occurs, the union type in the {@link ArkUI_NodeEvent} object is + * {@link ArkUI_UIInputEvent}. \n + * + * @since 15 + */ + NODE_ON_FOCUS_AXIS = 23, /** * @brief 文本设置TextDataDetectorConfig且识别成功时,触发onDetectResultUpdate回调。 * diff --git a/interfaces/native/node/event_converter.cpp b/interfaces/native/node/event_converter.cpp index befbb85ee66..e9599eb1c34 100644 --- a/interfaces/native/node/event_converter.cpp +++ b/interfaces/native/node/event_converter.cpp @@ -33,6 +33,7 @@ constexpr int32_t ORIGIN_INPUT_EVENT_TOOL_TYPE_FINGER = 1; constexpr int32_t ORIGIN_INPUT_EVENT_TOOL_TYPE_PEN = 2; constexpr int32_t ORIGIN_INPUT_EVENT_TOOL_TYPE_MOUSE = 7; constexpr int32_t ORIGIN_INPUT_EVENT_TOOL_TYPE_TOUCHPAD = 9; +constexpr int32_t ORIGIN_INPUT_EVENT_TOOL_TYPE_JOYSTICK = 10; constexpr int32_t ORIGIN_MOUSE_ACTION_PRESS = 1; constexpr int32_t ORIGIN_MOUSE_ACTION_RELEASE = 2; constexpr int32_t ORIGIN_MOUSE_ACTION_MOVE = 3; @@ -333,6 +334,8 @@ ArkUI_Int32 ConvertOriginEventType(ArkUI_NodeEventType type, int32_t nodeType) return ON_IMAGE_ANIMATOR_ON_REPEAT; case NODE_IMAGE_ANIMATOR_EVENT_ON_FINISH: return ON_IMAGE_ANIMATOR_ON_FINISH; + case NODE_ON_FOCUS_AXIS: + return ON_FOCUS_AXIS; default: return -1; } @@ -543,6 +546,8 @@ ArkUI_Int32 ConvertToNodeEventType(ArkUIEventSubKind type) return NODE_IMAGE_ANIMATOR_EVENT_ON_CANCEL; case ON_IMAGE_ANIMATOR_ON_FINISH: return NODE_IMAGE_ANIMATOR_EVENT_ON_FINISH; + case ON_FOCUS_AXIS: + return NODE_ON_FOCUS_AXIS; default: return -1; } @@ -619,6 +624,12 @@ bool ConvertEvent(ArkUINodeEvent* origin, ArkUI_NodeEvent* event) event->kind = ConvertToNodeEventType(subKind); return true; } + case FOCUS_AXIS_EVENT: { + event->category = static_cast(NODE_EVENT_CATEGORY_INPUT_EVENT); + ArkUIEventSubKind subKind = static_cast(origin->focusAxisEvent.subKind); + event->kind = ConvertToNodeEventType(subKind); + return true; + } default: TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "failed to convert origin event data"); break; @@ -669,6 +680,8 @@ int32_t ConvertToCInputEventToolType(int32_t originSourceToolType) return static_cast(UI_INPUT_EVENT_TOOL_TYPE_MOUSE); case ORIGIN_INPUT_EVENT_TOOL_TYPE_TOUCHPAD: return static_cast(UI_INPUT_EVENT_TOOL_TYPE_TOUCHPAD); + case ORIGIN_INPUT_EVENT_TOOL_TYPE_JOYSTICK: + return static_cast(UI_INPUT_EVENT_TOOL_TYPE_JOYSTICK); default: break; } diff --git a/interfaces/native/node/node_model.cpp b/interfaces/native/node/node_model.cpp index 9d1d01e3132..55dc2c95aa3 100644 --- a/interfaces/native/node/node_model.cpp +++ b/interfaces/native/node/node_model.cpp @@ -460,6 +460,12 @@ void HandleKeyEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent) uiEvent.inputEvent = &(innerEvent->keyEvent); } +void HandleFocusAxisEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent) +{ + uiEvent.eventTypeId = C_FOCUS_AXIS_EVENT_ID; + uiEvent.inputEvent = &(innerEvent->focusAxisEvent); +} + void HandleInnerNodeEvent(ArkUINodeEvent* innerEvent) { if (!innerEvent) { @@ -496,7 +502,8 @@ void HandleInnerNodeEvent(ArkUINodeEvent* innerEvent) {NODE_ON_TOUCH_INTERCEPT, HandleTouchEvent}, {NODE_ON_MOUSE, HandleMouseEvent}, {NODE_ON_KEY_EVENT, HandleKeyEvent}, - {NODE_ON_KEY_PRE_IME, HandleKeyEvent} + {NODE_ON_KEY_PRE_IME, HandleKeyEvent}, + {NODE_ON_FOCUS_AXIS, HandleFocusAxisEvent} }; auto it = eventHandlers.find(eventType); @@ -553,6 +560,9 @@ int32_t GetNativeNodeEventType(ArkUINodeEvent* innerEvent) case KEY_INPUT_EVENT: subKind = static_cast(innerEvent->keyEvent.subKind); break; + case FOCUS_AXIS_EVENT: + subKind = static_cast(innerEvent->focusAxisEvent.subKind); + break; default: break; /* Empty */ } diff --git a/interfaces/native/node/node_model.h b/interfaces/native/node/node_model.h index 172c72620f4..42c29f0a741 100644 --- a/interfaces/native/node/node_model.h +++ b/interfaces/native/node/node_model.h @@ -147,6 +147,7 @@ void UnregisterOnEvent(); void HandleTouchEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent); void HandleMouseEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent); void HandleKeyEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent); +void HandleFocusAxisEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent); int32_t CheckEvent(ArkUI_NodeEvent* event); void HandleInnerNodeEvent(ArkUINodeEvent* innerEvent); int32_t GetNativeNodeEventType(ArkUINodeEvent* innerEvent); diff --git a/interfaces/native/ui_input_event.h b/interfaces/native/ui_input_event.h index da060865e96..a15feffa6ff 100644 --- a/interfaces/native/ui_input_event.h +++ b/interfaces/native/ui_input_event.h @@ -198,6 +198,30 @@ typedef enum { ARKUI_MODIFIER_KEY_FN = 1 << 3, } ArkUI_ModifierKeyName; +/** + * @brief Defines an enum for the axis types for focus axis events. + * + * @since 15 + */ +enum { + /** ABS_X. */ + UI_FOCUS_AXIS_EVENT_ABS_X = 0, + /** ABS_Y. */ + UI_FOCUS_AXIS_EVENT_ABS_Y = 1, + /** ABS_Z. */ + UI_FOCUS_AXIS_EVENT_ABS_Z = 2, + /** ABS_RZ. */ + UI_FOCUS_AXIS_EVENT_ABS_RZ = 3, + /** ABS_GAS. */ + UI_FOCUS_AXIS_EVENT_ABS_GAS = 4, + /** ABS_BRAKE. */ + UI_FOCUS_AXIS_EVENT_ABS_BRAKE = 5, + /** ABS_HAT0X. */ + UI_FOCUS_AXIS_EVENT_ABS_HAT0X = 6, + /** ABS_HAT0Y. */ + UI_FOCUS_AXIS_EVENT_ABS_HAT0Y = 7, +}; + /** * @brief Obtains the type of this UI input event. * @@ -743,6 +767,28 @@ int32_t OH_ArkUI_UIInputEvent_GetDeviceId(const ArkUI_UIInputEvent* event); int32_t OH_ArkUI_UIInputEvent_GetPressedKeys( const ArkUI_UIInputEvent* event, int32_t* pressedKeyCodes, int32_t* length); +/** + * @brief Obtains the axis value of a focus axis event. + * + * @param event Pointer to an ArkUI_UIInputEvent object. + * @param axis Axis type of the focus axis event. + * @return Returns the axis value of the focus axis event; returns 0.0 if any parameter error occurs. + * @since 15 + */ +double OH_ArkUI_FocusAxisEvent_GetAxisValue(const ArkUI_UIInputEvent* event, int32_t axis); + +/** + * @brief Sets whether to prevent a focus axis event from bubbling up. + * + * @param event Indicates the pointer to the current UI input event. + * @param stopPropagation Indicates whether to stop event propagation. + * @return Returns the result code. + * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. + * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. + * @since 15 + */ +int32_t OH_ArkUI_FocusAxisEvent_SetStopPropagation(const ArkUI_UIInputEvent* event, bool stopPropagation); + #ifdef __cplusplus }; #endif diff --git a/test/unittest/core/pattern/window_scene/mock/mock_mmi_event_convertor.cpp b/test/unittest/core/pattern/window_scene/mock/mock_mmi_event_convertor.cpp index 9df958f75dd..8a1010c6c95 100644 --- a/test/unittest/core/pattern/window_scene/mock/mock_mmi_event_convertor.cpp +++ b/test/unittest/core/pattern/window_scene/mock/mock_mmi_event_convertor.cpp @@ -37,7 +37,7 @@ void ConvertAxisEvent(const std::shared_ptr& pointerEvent, Ax void ConvertKeyEvent(const std::shared_ptr& keyEvent, KeyEvent& event) {} -void ConvertNonPointerAxisEvent(const std::shared_ptr& pointerEvent, NG::NonPointerAxisEvent& event) +void ConvertFocusAxisEvent(const std::shared_ptr& pointerEvent, NG::FocusAxisEvent& event) {} void ConvertPointerEvent(const std::shared_ptr& pointerEvent, DragPointerEvent& event) {} -- Gitee