mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 07:01:24 +00:00
add key callback with ret
Signed-off-by: sd_wu <wudongsheng3@huawei.com>
This commit is contained in:
parent
24730dfcae
commit
6c8901c22f
@ -221,6 +221,16 @@ int32_t OH_NativeXComponent::RegisterKeyEventCallback(void (*callback)(OH_Native
|
||||
return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OH_NativeXComponent::RegisterKeyEventCallbackWithResult(
|
||||
bool (*callback)(OH_NativeXComponent* component, void* window))
|
||||
{
|
||||
if (xcomponentImpl_ == nullptr) {
|
||||
return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
xcomponentImpl_->SetKeyEventCallbackWithResult(callback);
|
||||
return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t OH_NativeXComponent::RegisterBlurEventCallback(void (*callback)(OH_NativeXComponent* component, void* window))
|
||||
{
|
||||
if (xcomponentImpl_ == nullptr) {
|
||||
|
@ -59,6 +59,7 @@ namespace OHOS::Ace {
|
||||
class NativeXComponentImpl : public virtual AceType {
|
||||
DECLARE_ACE_TYPE(NativeXComponentImpl, AceType);
|
||||
using NativeXComponent_Callback = void (*)(OH_NativeXComponent*, void*);
|
||||
using NativeXComponent_CallbackWithResult = bool (*)(OH_NativeXComponent*, void*);
|
||||
using NativeXComponent_UIEventCallback = void (*)(
|
||||
OH_NativeXComponent*, ArkUI_UIInputEvent*, ArkUI_UIInputEvent_Type);
|
||||
using SetExpectedRateRangeEvent_Callback = std::function<void()>;
|
||||
@ -306,6 +307,11 @@ public:
|
||||
return keyEventCallback_;
|
||||
}
|
||||
|
||||
NativeXComponent_CallbackWithResult GetKeyEventCallbackWithResult() const
|
||||
{
|
||||
return keyEventCallbackWithResult_;
|
||||
}
|
||||
|
||||
NativeXComponent_Callback GetBlurEventCallback() const
|
||||
{
|
||||
return blurEventCallback_;
|
||||
@ -331,6 +337,11 @@ public:
|
||||
keyEventCallback_ = callback;
|
||||
}
|
||||
|
||||
void SetKeyEventCallbackWithResult(NativeXComponent_CallbackWithResult callback)
|
||||
{
|
||||
keyEventCallbackWithResult_ = callback;
|
||||
}
|
||||
|
||||
void SetBlurEventCallback(NativeXComponent_Callback callback)
|
||||
{
|
||||
blurEventCallback_ = callback;
|
||||
@ -451,6 +462,7 @@ private:
|
||||
NativeXComponent_Surface_Callback surfaceHideCallback_ = nullptr;
|
||||
NativeXComponent_Callback focusEventCallback_ = nullptr;
|
||||
NativeXComponent_Callback keyEventCallback_ = nullptr;
|
||||
NativeXComponent_CallbackWithResult keyEventCallbackWithResult_ = nullptr;
|
||||
NativeXComponent_Callback blurEventCallback_ = nullptr;
|
||||
NativeXComponent_UIEventCallback uiAxisEventCallback_ = nullptr;
|
||||
std::vector<XComponentTouchPoint> touchPoints_;
|
||||
@ -490,6 +502,7 @@ struct OH_NativeXComponent {
|
||||
int32_t GetDisplayY(size_t pointIndex, float* displayY);
|
||||
int32_t RegisterFocusEventCallback(void (*callback)(OH_NativeXComponent* component, void* window));
|
||||
int32_t RegisterKeyEventCallback(void (*callback)(OH_NativeXComponent* component, void* window));
|
||||
int32_t RegisterKeyEventCallbackWithResult(bool (*callback)(OH_NativeXComponent* component, void* window));
|
||||
int32_t RegisterBlurEventCallback(void (*callback)(OH_NativeXComponent* component, void* window));
|
||||
int32_t GetKeyEvent(OH_NativeXComponent_KeyEvent** keyEvent);
|
||||
int32_t SetExpectedFrameRateRange(OH_NativeXComponent_ExpectedRateRange* range);
|
||||
|
@ -968,6 +968,10 @@ bool XComponentPattern::HandleKeyEvent(const KeyEvent& event)
|
||||
nativeXComponentImpl_->SetKeyEvent(keyEvent);
|
||||
|
||||
auto* surface = const_cast<void*>(nativeXComponentImpl_->GetSurface());
|
||||
const auto keyEventCallbackWithResult = nativeXComponentImpl_->GetKeyEventCallbackWithResult();
|
||||
if (keyEventCallbackWithResult) {
|
||||
return keyEventCallbackWithResult(nativeXComponent_.get(), surface);
|
||||
}
|
||||
const auto keyEventCallback = nativeXComponentImpl_->GetKeyEventCallback();
|
||||
CHECK_NULL_RETURN(keyEventCallback, false);
|
||||
keyEventCallback(nativeXComponent_.get(), surface);
|
||||
|
@ -2386,5 +2386,9 @@
|
||||
{
|
||||
"first_introduced": "14",
|
||||
"name": "OH_ArkUI_ConvertToHtml"
|
||||
},
|
||||
{
|
||||
"first_introduced": "14",
|
||||
"name": "OH_NativeXComponent_RegisterKeyEventCallbackWithResult"
|
||||
}
|
||||
]
|
||||
|
@ -349,6 +349,14 @@ int32_t OH_NativeXComponent_GetNativeAccessibilityProvider(
|
||||
return component->GetAccessibilityProvider(handle);
|
||||
}
|
||||
|
||||
int32_t OH_NativeXComponent_RegisterKeyEventCallbackWithResult(
|
||||
OH_NativeXComponent* component, bool (*callback)(OH_NativeXComponent* component, void* window))
|
||||
{
|
||||
if ((component == nullptr) || (callback == nullptr)) {
|
||||
return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
|
||||
}
|
||||
return component->RegisterKeyEventCallbackWithResult(callback);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
|
@ -818,6 +818,20 @@ OH_NativeXComponent* OH_NativeXComponent_GetNativeXComponent(ArkUI_NodeHandle no
|
||||
int32_t OH_NativeXComponent_GetNativeAccessibilityProvider(
|
||||
OH_NativeXComponent* component, ArkUI_AccessibilityProvider** handle);
|
||||
|
||||
/**
|
||||
* @brief Registers a callback for this <b>OH_NativeXComponent</b> instance.
|
||||
*
|
||||
* @param component Indicates the pointer to this <b>OH_NativeXComponent</b> instance.
|
||||
* @param callback Indicates the pointer to a key event callback with result.
|
||||
* @return Returns the status code of the execution.
|
||||
* {@link OH_NATIVEXCOMPONENT_RESULT_SUCCESS} the callback function is successfully registered.\n
|
||||
* {@link OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER} component is nullptr or callback is nullptr.\n
|
||||
* @since 14
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OH_NativeXComponent_RegisterKeyEventCallbackWithResult(
|
||||
OH_NativeXComponent* component, bool (*callback)(OH_NativeXComponent* component, void* window));
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user