!26828 [NDK] interfaces touch and click

Merge pull request !26828 from lisitao/lisitao_c_api_6
This commit is contained in:
openharmony_ci 2024-01-31 06:29:51 +00:00 committed by Gitee
commit 76061fb2eb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 221 additions and 15 deletions

View File

@ -2845,4 +2845,18 @@ void ViewAbstract::SetOnBlur(FrameNode* frameNode, OnBlurFunc &&onBlurCallback)
focusHub->SetOnBlurCallback(std::move(onBlurCallback));
}
void ViewAbstract::SetOnClick(FrameNode* frameNode, GestureEventFunc &&clickEventFunc)
{
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
CHECK_NULL_VOID(gestureHub);
gestureHub->SetUserOnClick(std::move(clickEventFunc));
}
void ViewAbstract::SetOnTouch(FrameNode* frameNode, TouchEventFunc &&touchEventFunc)
{
auto gestureHub = frameNode->GetOrCreateGestureEventHub();
CHECK_NULL_VOID(gestureHub);
gestureHub->SetTouchEvent(std::move(touchEventFunc));
}
} // namespace OHOS::Ace::NG

View File

@ -487,6 +487,8 @@ public:
const OffsetF &oldOrigin, const RectF &rect, const OffsetF &origin)> &&onAreaChanged);
static void SetOnFocus(FrameNode* frameNode, OnFocusFunc &&onFocusCallback);
static void SetOnBlur(FrameNode* frameNode, OnBlurFunc &&onBlurCallback);
static void SetOnClick(FrameNode* frameNode, GestureEventFunc &&clickEventFunc);
static void SetOnTouch(FrameNode* frameNode, TouchEventFunc &&touchEventFunc);
private:
static void AddDragFrameNodeToManager();
};

View File

@ -663,6 +663,7 @@ struct ArkUINodeEvent {
ArkUIAPIEventTextInput textInputEvent;
ArkUIAPIEventGestureAsyncEvent gestureAsyncEvent;
ArkUIStringAsyncEvent stringAsyncEvent;
ArkUITouchEvent touchEvent;
};
};

View File

@ -94,10 +94,10 @@ typedef void (*ComponentAsyncEventHandler)(ArkUINodeHandle node, ArkUI_Int32 eve
*/
/* clang-format off */
const ComponentAsyncEventHandler commonNodeAsyncEventHandlers[] = {
NodeModifier::SetOnAppear,
nullptr,
nullptr,
nullptr,
nullptr,
NodeModifier::SetOnTouch,
NodeModifier::SetOnClick,
nullptr,
NodeModifier::SetOnBlur,
nullptr,

View File

@ -3299,6 +3299,10 @@ void SetMaskPath(ArkUINodeHandle node, ArkUI_CharPtr type, ArkUI_Uint32 fill, Ar
} // namespace
namespace NodeModifier {
namespace {
OHOS::Ace::TouchEventInfo globalEventInfo("global");
}
const ArkUICommonModifier* GetCommonModifier()
{
static const ArkUICommonModifier modifier = { SetBackgroundColor, ResetBackgroundColor, SetWidth, ResetWidth,
@ -3423,5 +3427,102 @@ void SetOnAreaChange(ArkUINodeHandle node, ArkUI_Int32 eventId, void* extraParam
ViewAbstract::SetOnAreaChanged(frameNode, std::move(areaChangeCallback));
}
void SetOnClick(ArkUINodeHandle node, ArkUI_Int32 eventId, void* extraParam)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
auto onEvent = [node, eventId, extraParam](GestureEvent& info) {
ArkUINodeEvent event;
event.kind = ON_CLICK;
event.eventId = eventId;
event.extraParam = extraParam;
Offset globalOffset = info.GetGlobalLocation();
Offset localOffset = info.GetLocalLocation();
Offset screenOffset = info.GetScreenLocation();
//x
event.componentAsyncEvent.data[0].f32 = PipelineBase::Px2VpWithCurrentDensity(localOffset.GetY());
//y
event.componentAsyncEvent.data[1].f32 = PipelineBase::Px2VpWithCurrentDensity(localOffset.GetX());
//timestamp
event.componentAsyncEvent.data[2].f32 = static_cast<double>(info.GetTimeStamp().time_since_epoch().count());
//target width
event.componentAsyncEvent.data[3].f32 = info.GetTarget().area.GetWidth().ConvertToVp();
//target height
event.componentAsyncEvent.data[4].f32 = info.GetTarget().area.GetHeight().ConvertToVp();
const auto& areaLocalOffset = info.GetTarget().area.GetOffset();
const auto& areaOrigin = info.GetTarget().origin;
//target position x
event.componentAsyncEvent.data[5].f32 = areaLocalOffset.GetX().ConvertToVp();
//target position y
event.componentAsyncEvent.data[6].f32 = areaLocalOffset.GetY().ConvertToVp();
//target globalPosition x
event.componentAsyncEvent.data[7].f32 = areaOrigin.GetX().ConvertToVp() + areaLocalOffset.GetX().ConvertToVp();
//target globalPosition y
event.componentAsyncEvent.data[8].f32 = areaOrigin.GetY().ConvertToVp() + areaLocalOffset.GetY().ConvertToVp();
//source
event.componentAsyncEvent.data[9].i32 = static_cast<int32_t>(info.GetSourceDevice());
//windowX
event.componentAsyncEvent.data[10].f32 = PipelineBase::Px2VpWithCurrentDensity(globalOffset.GetX());
//windowY
event.componentAsyncEvent.data[11].f32 = PipelineBase::Px2VpWithCurrentDensity(globalOffset.GetY());
SendArkUIAsyncEvent(&event);
};
ViewAbstract::SetOnClick(frameNode, std::move(onEvent));
}
void SetOnTouch(ArkUINodeHandle node, ArkUI_Int32 eventId, void* extraParam)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
auto onEvent = [node, eventId, extraParam](TouchEventInfo& eventInfo) {
globalEventInfo = eventInfo;
ArkUINodeEvent event;
event.kind = ON_TOUCH;
event.eventId = eventId;
event.extraParam = extraParam;
const std::list<TouchLocationInfo>& changeTouch = eventInfo.GetChangedTouches();
if (changeTouch.size() > 0) {
TouchLocationInfo front = changeTouch.front();
event.touchEvent.action = static_cast<ArkUITouchEventAction>(front.GetTouchType());
const OHOS::Ace::Offset& globalLocation = front.GetGlobalLocation();
const OHOS::Ace::Offset& localLocation = front.GetLocalLocation();
const OHOS::Ace::Offset& screenLocation = front.GetScreenLocation();
event.touchEvent.actionTouch.id = front.GetFingerId();
event.touchEvent.actionTouch.nodeX = PipelineBase::Px2VpWithCurrentDensity(localLocation.GetX());
event.touchEvent.actionTouch.nodeY = PipelineBase::Px2VpWithCurrentDensity(localLocation.GetY());
event.touchEvent.actionTouch.windowX = PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetX());
event.touchEvent.actionTouch.windowY = PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetY());
event.touchEvent.actionTouch.screenX = PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetX());
event.touchEvent.actionTouch.screenY = PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetY());
}
event.touchEvent.timeStamp = static_cast<double>(eventInfo.GetTimeStamp().time_since_epoch().count());
event.touchEvent.sourceType = static_cast<ArkUISourceType>(eventInfo.GetSourceDevice());
auto getTouchPoints = [](ArkUITouchPoint** points)-> ArkUI_Int32 {
const std::list<TouchLocationInfo>& touchList = globalEventInfo.GetTouches();
int index = 0;
for (const auto& touchInfo : touchList) {
const OHOS::Ace::Offset& globalLocation = touchInfo.GetGlobalLocation();
const OHOS::Ace::Offset& localLocation = touchInfo.GetLocalLocation();
const OHOS::Ace::Offset& screenLocation = touchInfo.GetScreenLocation();
ArkUITouchPoint touchPoint;
touchPoint.id = touchInfo.GetFingerId();
touchPoint.nodeX = PipelineBase::Px2VpWithCurrentDensity(localLocation.GetX());
touchPoint.nodeY = PipelineBase::Px2VpWithCurrentDensity(localLocation.GetY());
touchPoint.windowX = PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetX());
touchPoint.windowY = PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetY());
touchPoint.screenX = PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetX());
touchPoint.screenY = PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetY());
points[index++] = &touchPoint;
}
return index;
};
event.touchEvent.getTouches = std::move(getTouchPoints);
SendArkUIAsyncEvent(&event);
};
ViewAbstract::SetOnTouch(frameNode, std::move(onEvent));
}
} // namespace NodeModifier
} // namespace OHOS::Ace::NG

View File

@ -24,5 +24,6 @@ void SetOnAppear(ArkUINodeHandle node, ArkUI_Int32 eventId, void* extraParam);
void SetOnFocus(ArkUINodeHandle node, ArkUI_Int32 eventId, void* extraParam);
void SetOnBlur(ArkUINodeHandle node, ArkUI_Int32 eventId, void* extraParam);
void SetOnAreaChange(ArkUINodeHandle node, ArkUI_Int32 eventId, void* extraParam);
void SetOnClick(ArkUINodeHandle node, ArkUI_Int32 eventId, void* extraParam);
void SetOnTouch(ArkUINodeHandle node, ArkUI_Int32 eventId, void* extraParam);
} // namespace OHOS::Ace::NG::NodeModifier

View File

@ -62,6 +62,10 @@ ArkUI_Int32 ConvertOriginEventType(ArkUI_NodeEventType type)
return ON_DATE_PICKER_DATE_CHANGE;
case NODE_TIME_PICKER_EVENT_ON_CHANGE:
return ON_TIME_PICKER_CHANGE;
case NODE_TOUCH_EVENT:
return ON_TOUCH;
case NODE_ON_CLICK:
return ON_CLICK;
default:
return -1;
}
@ -108,6 +112,10 @@ ArkUI_Int32 ConvertToNodeEventType(ArkUIAsyncEventKind type)
return NODE_DATE_PICKER_EVENT_ON_DATE_CHANGE;
case ON_TIME_PICKER_CHANGE:
return NODE_TIME_PICKER_EVENT_ON_CHANGE;
case ON_TOUCH:
return NODE_TOUCH_EVENT;
case ON_CLICK:
return NODE_ON_CLICK;
default:
return -1;
}

View File

@ -159,6 +159,9 @@ constexpr uint32_t DEFAULT_FIll_COLOR = 0x00000000;
constexpr int32_t DEFAULT_X = 0;
constexpr int32_t DEFAULT_Y = 0;
constexpr int32_t DEFAULT_TRUE = 1;
constexpr int32_t DEFAULT_FALSE = 0;
void ResetAttributeItem()
{
for (int i = 0; i < MAX_ATTRIBUTE_ITEM_LEN; ++i) {
@ -284,6 +287,72 @@ int32_t CheckAttributeItemArray(const ArkUI_AttributeItem* item, int32_t require
return item->size;
}
bool CheckAttributeIsBool(const ArkUI_AttributeItem* item)
{
if (item->size == 0 || item->value[0].i32 != DEFAULT_FALSE ||
item->value[0].i32 != DEFAULT_TRUE) {
return false;
}
return true;
}
bool CheckAttributeIsAlignment(int32_t value)
{
int32_t minEnumValue = static_cast<int32_t>(ArkUI_Alignment::ARKUI_ALIGNMENT_TOP_START);
int32_t maxEnumValue = static_cast<int32_t>(ArkUI_Alignment::ARKUI_ALIGNMENT_BOTTOM_END);
return value >= minEnumValue && value <= maxEnumValue;
}
bool CheckAttributeIsFontWeight(int32_t value)
{
int32_t minEnumValue = static_cast<int32_t>(ArkUI_FontWeight::ARKUI_FONT_WEIGHT_W100);
int32_t maxEnumValue = static_cast<int32_t>(ArkUI_FontWeight::ARKUI_FONT_WEIGHT_REGULAR);
return value >= minEnumValue && value <= maxEnumValue;
}
bool CheckAttributeIsFontStyle(int32_t value)
{
int32_t minEnumValue = static_cast<int32_t>(ArkUI_FontStyle::ARKUI_FONT_STYLE_NORMAL);
int32_t maxEnumValue = static_cast<int32_t>(ArkUI_FontStyle::ARKUI_FONT_STYLE_ITALIC);
return value >= minEnumValue && value <= maxEnumValue;
}
bool CheckAttributeIsTextHeightAdaptivePolicy(int32_t value)
{
int32_t minEnumValue = static_cast<int32_t>(
ArkUI_TextHeightAdaptivePolicy::ARKUI_TEXT_HEIGHT_ADAPTIVE_POLICY_MAX_LINES_FIRST);
int32_t maxEnumValue = static_cast<int32_t>(
ArkUI_TextHeightAdaptivePolicy::ARKUI_TEXT_HEIGHT_ADAPTIVE_POLICY_LAYOUT_CONSTRAINT_FIRST);
return value >= minEnumValue && value <= maxEnumValue;
}
bool CheckAttributeIsCopyOptions(int32_t value)
{
int32_t minEnumValue = static_cast<int32_t>(
ArkUI_CopyOptions::ARKUI_COPY_OPTIONS_NONE);
int32_t maxEnumValue = static_cast<int32_t>(
ArkUI_CopyOptions::ARKUI_COPY_OPTIONS_CROSS_DEVICE);
return value >= minEnumValue && value <= maxEnumValue;
}
bool CheckAttributeIsAnimationCurve(int32_t value)
{
int32_t minEnumValue = static_cast<int32_t>(
ArkUI_AnimationCurve::ARKUI_CURVE_LINEAR);
int32_t maxEnumValue = static_cast<int32_t>(
ArkUI_AnimationCurve::ARKUI_CURVE_FRICTION);
return value >= minEnumValue && value <= maxEnumValue;
}
bool CheckAttributeIsScrollNestedMode(int32_t value)
{
int32_t minEnumValue = static_cast<int32_t>(
ArkUI_ScrollNestedMode::ARKUI_SCROLL_NESTED_MODE_SELF_ONLY);
int32_t maxEnumValue = static_cast<int32_t>(
ArkUI_ScrollNestedMode::ARKUI_SCROLL_NESTED_MODE_PARALLEL);
return value >= minEnumValue && value <= maxEnumValue;
}
bool CheckAttributeString(const ArkUI_AttributeItem* item)
{
CHECK_NULL_RETURN(item, false);
@ -1173,7 +1242,7 @@ void ResetCustomShadow(ArkUI_NodeHandle node)
int32_t SetFocusable(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
if (item->size == 0) {
if (!CheckAttributeIsBool(item)) {
return ERROR_CODE_PARAM_INVALID;
}
auto* fullImpl = GetFullImpl();
@ -1189,7 +1258,7 @@ void ResetFocusable(ArkUI_NodeHandle node)
int32_t SetAccessibilityGroup(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
if (item->size == 0) {
if (!CheckAttributeIsBool(item)) {
return ERROR_CODE_PARAM_INVALID;
}
auto* fullImpl = GetFullImpl();
@ -1253,7 +1322,7 @@ void ResetAccessibilityDescription(ArkUI_NodeHandle node)
int32_t SetDefaultFocus(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
if (item->size == 0) {
if (!CheckAttributeIsBool(item)) {
return ERROR_CODE_PARAM_INVALID;
}
auto* fullImpl = GetFullImpl();
@ -1305,6 +1374,9 @@ int32_t SetOverlay(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
if (item->size > 0) {
values[0] = 1;
if (!CheckAttributeIsAlignment(item->value[0].i32)) {
return ERROR_CODE_PARAM_INVALID;
}
values[1] = item->value[0].i32;
}
@ -2306,15 +2378,14 @@ void ResetScrollEnableScrollInteraction(ArkUI_NodeHandle node)
int32_t SetScrollNestedScroll(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
if (item->size == 0) {
//The size must be greater than 2 and check value is Nested Mode
if (item->size < 2 || !CheckAttributeIsScrollNestedMode(item->value[0].i32) ||
!CheckAttributeIsScrollNestedMode(item->value[1].i32)) {
return ERROR_CODE_PARAM_INVALID;
}
auto* fullImpl = GetFullImpl();
int first = item->value[NUM_0].i32;
int second = 0;
if (item->size > ALLOW_SIZE_1) {
second = item->value[NUM_1].i32;
}
int second = item->value[NUM_1].i32;
fullImpl->getNodeModifiers()->getScrollModifier()->setScrollNestedScroll(node->uiNodeHandle, first, second);
return ERROR_CODE_NO_ERROR;
}
@ -2339,7 +2410,8 @@ int32_t SetScrollTo(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
if (item->size > 2) {
values[4] = item->value[2].i32;
}
if (item->size > 3) {
//check size
if (item->size > 3 || !CheckAttributeIsAnimationCurve(item->value[3].i32)) {
values[5] = item->value[3].i32;
}
if (item->size > 4) {
@ -2746,11 +2818,18 @@ int32_t SetTextFont(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
// weight
int weight = 10; // default
if (item->size > 1) {
if (!CheckAttributeIsFontWeight(item->value[1].i32)) {
return ERROR_CODE_PARAM_INVALID;
}
weight = item->value[1].i32;
}
// style
int style = 0;
if (item->size > 2) {
//get value 2 is font style
if (!CheckAttributeIsFontStyle(item->value[2].i32)) {
return ERROR_CODE_PARAM_INVALID;
}
weight = item->value[2].i32;
}
// family
@ -2785,7 +2864,7 @@ void ResetTextFont(ArkUI_NodeHandle node)
int32_t SetTextHeightAdaptivePolicy(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
if (item->size == 0) {
if (item->size == 0 || !CheckAttributeIsTextHeightAdaptivePolicy(item->value[0].i32)) {
return ERROR_CODE_PARAM_INVALID;
}
auto fullImpl = GetFullImpl();
@ -3226,7 +3305,7 @@ void ResetTextCopyOption(ArkUI_NodeHandle node)
int32_t SetTextCopyOption(ArkUI_NodeHandle node, const ArkUI_AttributeItem* item)
{
if (item->size == NUM_0) {
if (item->size == NUM_0 || !CheckAttributeIsCopyOptions(item->value[0].i32)) {
return ERROR_CODE_PARAM_INVALID;
}
// already check in entry point.