!45503 手势支持配置可支持响应的输入事件源类型

Merge pull request !45503 from wangyaming/master
This commit is contained in:
openharmony_ci 2024-10-19 03:53:46 +00:00 committed by Gitee
commit f7625b6fe1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
25 changed files with 364 additions and 93 deletions

View File

@ -4729,40 +4729,40 @@ class UIGestureEvent {
case CommonGestureType.TAP_GESTURE: {
let tapGesture: TapGestureHandler = gesture as TapGestureHandler;
getUINativeModule().common.addTapGesture(this._nodePtr, priority, mask, tapGesture.gestureTag,
tapGesture.fingers, tapGesture.count, tapGesture.onActionCallback);
tapGesture.allowedTypes, tapGesture.fingers, tapGesture.count, tapGesture.onActionCallback);
break;
}
case CommonGestureType.LONG_PRESS_GESTURE: {
let longPressGesture: LongPressGestureHandler = gesture as LongPressGestureHandler;
getUINativeModule().common.addLongPressGesture(this._nodePtr, priority, mask, longPressGesture.gestureTag,
longPressGesture.fingers, longPressGesture.repeat, longPressGesture.duration,
longPressGesture.allowedTypes, longPressGesture.fingers, longPressGesture.repeat, longPressGesture.duration,
longPressGesture.onActionCallback, longPressGesture.onActionEndCallback, longPressGesture.onActionCancelCallback);
break;
}
case CommonGestureType.PAN_GESTURE: {
let panGesture: PanGestureHandler = gesture as PanGestureHandler;
getUINativeModule().common.addPanGesture(this._nodePtr, priority, mask, panGesture.gestureTag,
panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.onActionStartCallback,
panGesture.allowedTypes, panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.onActionStartCallback,
panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback);
break;
}
case CommonGestureType.SWIPE_GESTURE: {
let swipeGesture: SwipeGestureHandler = gesture as SwipeGestureHandler;
getUINativeModule().common.addSwipeGesture(this._nodePtr, priority, mask, swipeGesture.gestureTag,
swipeGesture.fingers, swipeGesture.direction, swipeGesture.speed, swipeGesture.onActionCallback);
swipeGesture.allowedTypes, swipeGesture.fingers, swipeGesture.direction, swipeGesture.speed, swipeGesture.onActionCallback);
break;
}
case CommonGestureType.PINCH_GESTURE: {
let pinchGesture: PinchGestureHandler = gesture as PinchGestureHandler;
getUINativeModule().common.addPinchGesture(this._nodePtr, priority, mask, pinchGesture.gestureTag,
pinchGesture.fingers, pinchGesture.distance, pinchGesture.onActionStartCallback,
pinchGesture.allowedTypes, pinchGesture.fingers, pinchGesture.distance, pinchGesture.onActionStartCallback,
pinchGesture.onActionUpdateCallback, pinchGesture.onActionEndCallback, pinchGesture.onActionCancelCallback);
break;
}
case CommonGestureType.ROTATION_GESTURE: {
let rotationGesture: RotationGestureHandler = gesture as RotationGestureHandler;
getUINativeModule().common.addRotationGesture(this._nodePtr, priority, mask, rotationGesture.gestureTag,
rotationGesture.fingers, rotationGesture.angle, rotationGesture.onActionStartCallback,
rotationGesture.allowedTypes, rotationGesture.fingers, rotationGesture.angle, rotationGesture.onActionStartCallback,
rotationGesture.onActionUpdateCallback, rotationGesture.onActionEndCallback,
rotationGesture.onActionCancelCallback);
break;
@ -4802,40 +4802,40 @@ function addGestureToGroup(gesture: any, gestureGroupPtr: any) {
switch (gesture.gestureType) {
case CommonGestureType.TAP_GESTURE: {
let tapGesture: TapGestureHandler = gesture as TapGestureHandler;
getUINativeModule().common.addTapGestureToGroup(tapGesture.gestureTag,
getUINativeModule().common.addTapGestureToGroup(tapGesture.gestureTag, tapGesture.allowedTypes,
tapGesture.fingers, tapGesture.count, tapGesture.onActionCallback, gestureGroupPtr);
break;
}
case CommonGestureType.LONG_PRESS_GESTURE: {
let longPressGesture: LongPressGestureHandler = gesture as LongPressGestureHandler;
getUINativeModule().common.addLongPressGestureToGroup(longPressGesture.gestureTag,
getUINativeModule().common.addLongPressGestureToGroup(longPressGesture.gestureTag, longPressGesture.allowedTypes,
longPressGesture.fingers, longPressGesture.repeat, longPressGesture.duration,
longPressGesture.onActionCallback, longPressGesture.onActionEndCallback, longPressGesture.onActionCancelCallback, gestureGroupPtr);
break;
}
case CommonGestureType.PAN_GESTURE: {
let panGesture: PanGestureHandler = gesture as PanGestureHandler;
getUINativeModule().common.addPanGestureToGroup(panGesture.gestureTag,
getUINativeModule().common.addPanGestureToGroup(panGesture.gestureTag, panGesture.allowedTypes,
panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.onActionStartCallback,
panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback, gestureGroupPtr);
break;
}
case CommonGestureType.SWIPE_GESTURE: {
let swipeGesture: SwipeGestureHandler = gesture as SwipeGestureHandler;
getUINativeModule().common.addSwipeGestureToGroup(swipeGesture.gestureTag,
getUINativeModule().common.addSwipeGestureToGroup(swipeGesture.gestureTag, swipeGesture.allowedTypes,
swipeGesture.fingers, swipeGesture.direction, swipeGesture.speed, swipeGesture.onActionCallback, gestureGroupPtr);
break;
}
case CommonGestureType.PINCH_GESTURE: {
let pinchGesture: PinchGestureHandler = gesture as PinchGestureHandler;
getUINativeModule().common.addPinchGestureToGroup(pinchGesture.gestureTag,
getUINativeModule().common.addPinchGestureToGroup(pinchGesture.gestureTag, pinchGesture.allowedTypes,
pinchGesture.fingers, pinchGesture.distance, pinchGesture.onActionStartCallback,
pinchGesture.onActionUpdateCallback, pinchGesture.onActionEndCallback, pinchGesture.onActionCancelCallback, gestureGroupPtr);
break;
}
case CommonGestureType.ROTATION_GESTURE: {
let rotationGesture: RotationGestureHandler = gesture as RotationGestureHandler;
getUINativeModule().common.addRotationGestureToGroup(rotationGesture.gestureTag,
getUINativeModule().common.addRotationGestureToGroup(rotationGesture.gestureTag, rotationGesture.allowedTypes,
rotationGesture.fingers, rotationGesture.angle, rotationGesture.onActionStartCallback,
rotationGesture.onActionUpdateCallback, rotationGesture.onActionEndCallback,
rotationGesture.onActionCancelCallback, gestureGroupPtr);

View File

@ -36,6 +36,7 @@ class TapGestureHandler extends GestureHandler {
fingers?: number;
count?: number;
gestureTag?: string;
allowedTypes?: Array<SourceTool>;
onActionCallback?: Callback<GestureEvent>;
constructor(options?: TapGestureHandlerOptions) {
@ -53,6 +54,10 @@ class TapGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types: Array<SourceTool>) {
this.allowedTypes = types;
return this;
}
}
class LongPressGestureHandler extends GestureHandler {
@ -60,6 +65,7 @@ class LongPressGestureHandler extends GestureHandler {
repeat?: boolean;
duration?: number;
gestureTag?: string;
allowedTypes?: Array<SourceTool>;
onActionCallback?: Callback<GestureEvent>;
onActionEndCallback?: Callback<GestureEvent>;
onActionCancelCallback?: Callback<void>;
@ -91,6 +97,11 @@ class LongPressGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types: Array<SourceTool>) {
this.allowedTypes = types;
return this;
}
}
class PanGestureHandler extends GestureHandler {
@ -98,6 +109,7 @@ class PanGestureHandler extends GestureHandler {
direction?: PanDirection;
distance?: number;
gestureTag?: string;
allowedTypes?: Array<SourceTool>;
onActionStartCallback?: Callback<GestureEvent>;
onActionUpdateCallback?: Callback<GestureEvent>;
onActionEndCallback?: Callback<GestureEvent>;
@ -135,6 +147,11 @@ class PanGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types: Array<SourceTool>) {
this.allowedTypes = types;
return this;
}
}
class SwipeGestureHandler extends GestureHandler {
@ -142,6 +159,7 @@ class SwipeGestureHandler extends GestureHandler {
direction?: SwipeDirection;
speed?: number;
gestureTag?: string;
allowedTypes?: Array<SourceTool>;
onActionCallback?: Callback<GestureEvent>;
constructor(options?: SwipeGestureHandlerOptions) {
super(CommonGestureType.PAN_GESTURE);
@ -161,12 +179,18 @@ class SwipeGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types: Array<SourceTool>) {
this.allowedTypes = types;
return this;
}
}
class PinchGestureHandler extends GestureHandler {
fingers?: number;
distance?: number;
gestureTag?: string;
allowedTypes?: Array<SourceTool>;
onActionStartCallback?: Callback<GestureEvent>;
onActionUpdateCallback?: Callback<GestureEvent>;
onActionEndCallback?: Callback<GestureEvent>;
@ -203,12 +227,18 @@ class PinchGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types: Array<SourceTool>) {
this.allowedTypes = types;
return this;
}
}
class RotationGestureHandler extends GestureHandler {
fingers?: number;
angle?: number;
gestureTag?: string;
allowedTypes?: Array<SourceTool>;
onActionStartCallback?: Callback<GestureEvent>;
onActionUpdateCallback?: Callback<GestureEvent>;
onActionEndCallback?: Callback<GestureEvent>;
@ -245,6 +275,11 @@ class RotationGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types: Array<SourceTool>) {
this.allowedTypes = types;
return this;
}
}
class GestureGroupHandler extends GestureHandler {

View File

@ -4350,6 +4350,10 @@ class TapGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types) {
this.allowedTypes = types;
return this;
}
}
class LongPressGestureHandler extends GestureHandler {
@ -4381,6 +4385,11 @@ class LongPressGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types) {
this.allowedTypes = types;
return this;
}
}
class PanGestureHandler extends GestureHandler {
@ -4417,6 +4426,11 @@ class PanGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types) {
this.allowedTypes = types;
return this;
}
}
class SwipeGestureHandler extends GestureHandler {
@ -4438,6 +4452,11 @@ class SwipeGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types) {
this.allowedTypes = types;
return this;
}
}
class PinchGestureHandler extends GestureHandler {
@ -4473,6 +4492,11 @@ class PinchGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types) {
this.allowedTypes = types;
return this;
}
}
class RotationGestureHandler extends GestureHandler {
@ -4508,6 +4532,11 @@ class RotationGestureHandler extends GestureHandler {
this.gestureTag = tag;
return this;
}
allowedTypes(types) {
this.allowedTypes = types;
return this;
}
}
class GestureGroupHandler extends GestureHandler {
@ -4679,40 +4708,40 @@ class UIGestureEvent {
case CommonGestureType.TAP_GESTURE: {
let tapGesture = gesture;
getUINativeModule().common.addTapGesture(this._nodePtr, priority, mask, tapGesture.gestureTag,
tapGesture.fingers, tapGesture.count, tapGesture.onActionCallback);
tapGesture.allowedTypes, tapGesture.fingers, tapGesture.count, tapGesture.onActionCallback);
break;
}
case CommonGestureType.LONG_PRESS_GESTURE: {
let longPressGesture = gesture;
getUINativeModule().common.addLongPressGesture(this._nodePtr, priority, mask, longPressGesture.gestureTag,
longPressGesture.fingers, longPressGesture.repeat, longPressGesture.duration,
longPressGesture.allowedTypes, longPressGesture.fingers, longPressGesture.repeat, longPressGesture.duration,
longPressGesture.onActionCallback, longPressGesture.onActionEndCallback, longPressGesture.onActionCancelCallback);
break;
}
case CommonGestureType.PAN_GESTURE: {
let panGesture = gesture;
getUINativeModule().common.addPanGesture(this._nodePtr, priority, mask, panGesture.gestureTag,
panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.onActionStartCallback,
panGesture.allowedTypes, panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.onActionStartCallback,
panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback);
break;
}
case CommonGestureType.SWIPE_GESTURE: {
let swipeGesture = gesture;
getUINativeModule().common.addSwipeGesture(this._nodePtr, priority, mask, swipeGesture.gestureTag,
swipeGesture.fingers, swipeGesture.direction, swipeGesture.speed, swipeGesture.onActionCallback);
swipeGesture.allowedTypes, swipeGesture.fingers, swipeGesture.direction, swipeGesture.speed, swipeGesture.onActionCallback);
break;
}
case CommonGestureType.PINCH_GESTURE: {
let pinchGesture = gesture;
getUINativeModule().common.addPinchGesture(this._nodePtr, priority, mask, pinchGesture.gestureTag,
pinchGesture.fingers, pinchGesture.distance, pinchGesture.onActionStartCallback,
pinchGesture.allowedTypes, pinchGesture.fingers, pinchGesture.distance, pinchGesture.onActionStartCallback,
pinchGesture.onActionUpdateCallback, pinchGesture.onActionEndCallback, pinchGesture.onActionCancelCallback);
break;
}
case CommonGestureType.ROTATION_GESTURE: {
let rotationGesture = gesture;
getUINativeModule().common.addRotationGesture(this._nodePtr, priority, mask, rotationGesture.gestureTag,
rotationGesture.fingers, rotationGesture.angle, rotationGesture.onActionStartCallback,
rotationGesture.allowedTypes, rotationGesture.fingers, rotationGesture.angle, rotationGesture.onActionStartCallback,
rotationGesture.onActionUpdateCallback, rotationGesture.onActionEndCallback,
rotationGesture.onActionCancelCallback);
break;
@ -4752,40 +4781,40 @@ function addGestureToGroup(gesture, gestureGroupPtr) {
switch (gesture.gestureType) {
case CommonGestureType.TAP_GESTURE: {
let tapGesture = gesture;
getUINativeModule().common.addTapGestureToGroup(tapGesture.gestureTag,
getUINativeModule().common.addTapGestureToGroup(tapGesture.gestureTag, tapGesture.allowedTypes,
tapGesture.fingers, tapGesture.count, tapGesture.onActionCallback, gestureGroupPtr);
break;
}
case CommonGestureType.LONG_PRESS_GESTURE: {
let longPressGesture = gesture;
getUINativeModule().common.addLongPressGestureToGroup(longPressGesture.gestureTag,
getUINativeModule().common.addLongPressGestureToGroup(longPressGesture.gestureTag, longPressGesture.allowedTypes,
longPressGesture.fingers, longPressGesture.repeat, longPressGesture.duration,
longPressGesture.onActionCallback, longPressGesture.onActionEndCallback, longPressGesture.onActionCancelCallback, gestureGroupPtr);
break;
}
case CommonGestureType.PAN_GESTURE: {
let panGesture = gesture;
getUINativeModule().common.addPanGestureToGroup(panGesture.gestureTag,
getUINativeModule().common.addPanGestureToGroup(panGesture.gestureTag, panGesture.allowedTypes,
panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.onActionStartCallback,
panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback, gestureGroupPtr);
break;
}
case CommonGestureType.SWIPE_GESTURE: {
let swipeGesture = gesture;
getUINativeModule().common.addSwipeGestureToGroup(swipeGesture.gestureTag,
getUINativeModule().common.addSwipeGestureToGroup(swipeGesture.gestureTag, swipeGesture.allowedTypes,
swipeGesture.fingers, swipeGesture.direction, swipeGesture.speed, swipeGesture.onActionCallback, gestureGroupPtr);
break;
}
case CommonGestureType.PINCH_GESTURE: {
let pinchGesture = gesture;
getUINativeModule().common.addPinchGestureToGroup(pinchGesture.gestureTag,
getUINativeModule().common.addPinchGestureToGroup(pinchGesture.gestureTag, pinchGesture.allowedTypes,
pinchGesture.fingers, pinchGesture.distance, pinchGesture.onActionStartCallback,
pinchGesture.onActionUpdateCallback, pinchGesture.onActionEndCallback, pinchGesture.onActionCancelCallback, gestureGroupPtr);
break;
}
case CommonGestureType.ROTATION_GESTURE: {
let rotationGesture = gesture;
getUINativeModule().common.addRotationGestureToGroup(rotationGesture.gestureTag,
getUINativeModule().common.addRotationGestureToGroup(rotationGesture.gestureTag, rotationGesture.allowedTypes,
rotationGesture.fingers, rotationGesture.angle, rotationGesture.onActionStartCallback,
rotationGesture.onActionUpdateCallback, rotationGesture.onActionEndCallback,
rotationGesture.onActionCancelCallback, gestureGroupPtr);

View File

@ -49,6 +49,7 @@ constexpr int NUM_7 = 7;
constexpr int NUM_8 = 8;
constexpr int NUM_9 = 9;
constexpr int NUM_10 = 10;
constexpr int NUM_11 = 11;
constexpr int NUM_13 = 13;
constexpr int SIZE_OF_TWO = 2;
constexpr int SIZE_OF_THREE = 3;
@ -6207,6 +6208,31 @@ void CommonBridge::SetGestureTag(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t
}
}
void CommonBridge::SetGestureAllowedTypes(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber,
ArkUIGesture* gesture)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_VOID(vm);
Local<JSValueRef> typesArg = runtimeCallInfo->GetCallArgRef(argNumber);
if (typesArg.IsNull() || typesArg->IsUndefined() || !typesArg->IsArray(vm)) {
return;
}
auto typesArr = panda::Local<panda::ArrayRef>(typesArg);
auto typesLength = typesArr->Length(vm);
std::set<SourceTool> allowedTypes{};
for (size_t i = 0; i < typesLength; ++i) {
auto type = panda::ArrayRef::GetValueAt(vm, typesArr, i);
if (type->IsNumber()) {
allowedTypes.insert(static_cast<SourceTool>(type->Int32Value(vm)));
}
}
if (allowedTypes.empty()) {
return;
}
auto gesturePtr = Referenced::Claim(reinterpret_cast<Gesture*>(gesture));
gesturePtr->SetAllowedTypes(allowedTypes);
}
void CommonBridge::GetTapGestureValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers,
int32_t& count, double& distanceThreshold, uint32_t argNumber)
{
@ -7188,11 +7214,12 @@ ArkUINativeModuleValue CommonBridge::AddTapGesture(ArkUIRuntimeCallInfo* runtime
int32_t fingers = DEFAULT_TAP_FINGER;
int32_t count = DEFAULT_TAP_COUNT;
double distanceThreshold = DEFAULT_TAP_DISTANCE;
GetTapGestureValue(runtimeCallInfo, fingers, count, distanceThreshold, NUM_4);
GetTapGestureValue(runtimeCallInfo, fingers, count, distanceThreshold, NUM_5);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->
createTapGestureWithDistanceThreshold(count, fingers, distanceThreshold, nullptr);
SetGestureTag(runtimeCallInfo, NUM_3, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_6, gesture);
SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_7, gesture);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
nativeNode, gesture, priority, mask);
return panda::JSValueRef::Undefined(vm);
@ -7212,13 +7239,14 @@ ArkUINativeModuleValue CommonBridge::AddLongPressGesture(ArkUIRuntimeCallInfo* r
int32_t fingers = DEFAULT_LONG_PRESS_FINGER;
bool repeat = false;
int32_t duration = DEFAULT_LONG_PRESS_DURATION;
GetLongPressGestureValue(runtimeCallInfo, fingers, repeat, duration, NUM_4);
GetLongPressGestureValue(runtimeCallInfo, fingers, repeat, duration, NUM_5);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createLongPressGesture(
fingers, repeat, duration, nullptr);
SetGestureTag(runtimeCallInfo, NUM_3, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_7, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_8, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_9, gesture);
SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_8, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_9, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_10, gesture);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
nativeNode, gesture, priority, mask);
return panda::JSValueRef::Undefined(vm);
@ -7238,14 +7266,15 @@ ArkUINativeModuleValue CommonBridge::AddPanGesture(ArkUIRuntimeCallInfo* runtime
int32_t fingers = DEFAULT_PAN_FINGER;
int32_t direction = PanDirection::ALL;
double distance = DEFAULT_PAN_DISTANCE.ConvertToPx();
GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, NUM_4);
GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, NUM_5);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture(
fingers, direction, distance, nullptr);
SetGestureTag(runtimeCallInfo, NUM_3, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_7, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_8, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_9, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_10, gesture);
SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_8, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_9, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_10, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_11, gesture);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
nativeNode, gesture, priority, mask);
return panda::JSValueRef::Undefined(vm);
@ -7265,11 +7294,12 @@ ArkUINativeModuleValue CommonBridge::AddSwipeGesture(ArkUIRuntimeCallInfo* runti
int32_t fingers = DEFAULT_SLIDE_FINGER;
int32_t direction = SwipeDirection::ALL;
double speed = DEFAULT_SLIDE_SPEED;
GetSwipeGestureValue(runtimeCallInfo, fingers, direction, speed, NUM_4);
GetSwipeGestureValue(runtimeCallInfo, fingers, direction, speed, NUM_5);
auto* gesture =
GetArkUINodeModifiers()->getGestureModifier()->createSwipeGestureByModifier(fingers, direction, speed);
SetGestureTag(runtimeCallInfo, NUM_3, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_7, gesture);
SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_8, gesture);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
nativeNode, gesture, priority, mask);
return panda::JSValueRef::Undefined(vm);
@ -7288,13 +7318,14 @@ ArkUINativeModuleValue CommonBridge::AddPinchGesture(ArkUIRuntimeCallInfo* runti
GetGestureCommonValue(runtimeCallInfo, priority, mask);
int32_t fingers = DEFAULT_PINCH_FINGER;
double distance = DEFAULT_PINCH_DISTANCE;
GetPinchGestureValue(runtimeCallInfo, fingers, distance, NUM_4);
GetPinchGestureValue(runtimeCallInfo, fingers, distance, NUM_5);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPinchGesture(fingers, distance, nullptr);
SetGestureTag(runtimeCallInfo, NUM_3, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_6, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_7, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_8, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_9, gesture);
SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_7, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_8, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_9, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_10, gesture);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
nativeNode, gesture, priority, mask);
return panda::JSValueRef::Undefined(vm);
@ -7313,13 +7344,14 @@ ArkUINativeModuleValue CommonBridge::AddRotationGesture(ArkUIRuntimeCallInfo* ru
GetGestureCommonValue(runtimeCallInfo, priority, mask);
int32_t fingers = DEFAULT_ROTATION_FINGER;
double angle = DEFAULT_ROTATION_ANGLE;
GetRotationGestureValue(runtimeCallInfo, fingers, angle, NUM_4);
GetRotationGestureValue(runtimeCallInfo, fingers, angle, NUM_5);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createRotationGesture(fingers, angle, nullptr);
SetGestureTag(runtimeCallInfo, NUM_3, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_6, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_7, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_8, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_9, gesture);
SetGestureAllowedTypes(runtimeCallInfo, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_7, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_8, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_9, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_10, gesture);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToNodeWithRefCountDecrease(
nativeNode, gesture, priority, mask);
return panda::JSValueRef::Undefined(vm);
@ -7344,12 +7376,13 @@ ArkUINativeModuleValue CommonBridge::AddTapGestureToGroup(ArkUIRuntimeCallInfo*
int32_t fingers = DEFAULT_TAP_FINGER;
int32_t count = DEFAULT_TAP_COUNT;
double distanceThreshold = DEFAULT_TAP_DISTANCE;
GetTapGestureValue(runtimeCallInfo, fingers, count, distanceThreshold, NUM_1);
GetTapGestureValue(runtimeCallInfo, fingers, count, distanceThreshold, NUM_2);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->
createTapGestureWithDistanceThreshold(count, fingers, distanceThreshold, nullptr);
SetGestureTag(runtimeCallInfo, NUM_0, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_3, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_4);
SetGestureAllowedTypes(runtimeCallInfo, NUM_1, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_4, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_5);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
return panda::JSValueRef::Undefined(vm);
}
@ -7361,14 +7394,15 @@ ArkUINativeModuleValue CommonBridge::AddLongPressGestureToGroup(ArkUIRuntimeCall
int32_t fingers = DEFAULT_LONG_PRESS_FINGER;
bool repeat = false;
int32_t duration = DEFAULT_LONG_PRESS_DURATION;
GetLongPressGestureValue(runtimeCallInfo, fingers, repeat, duration, NUM_1);
GetLongPressGestureValue(runtimeCallInfo, fingers, repeat, duration, NUM_2);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createLongPressGesture(
fingers, repeat, duration, nullptr);
SetGestureTag(runtimeCallInfo, NUM_0, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_5, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_6, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_7);
SetGestureAllowedTypes(runtimeCallInfo, NUM_1, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_5, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_6, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_7, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_8);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
return panda::JSValueRef::Undefined(vm);
}
@ -7380,15 +7414,16 @@ ArkUINativeModuleValue CommonBridge::AddPanGestureToGroup(ArkUIRuntimeCallInfo*
int32_t fingers = DEFAULT_PAN_FINGER;
int32_t direction = PanDirection::ALL;
double distance = DEFAULT_PAN_DISTANCE.ConvertToPx();
GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, NUM_1);
GetPanGestureValue(runtimeCallInfo, fingers, direction, distance, NUM_2);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPanGesture(
fingers, direction, distance, nullptr);
SetGestureTag(runtimeCallInfo, NUM_0, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_5, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_6, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_7, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_8);
SetGestureAllowedTypes(runtimeCallInfo, NUM_1, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_5, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_6, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_7, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_8, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_9);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
return panda::JSValueRef::Undefined(vm);
}
@ -7400,12 +7435,13 @@ ArkUINativeModuleValue CommonBridge::AddSwipeGestureToGroup(ArkUIRuntimeCallInfo
int32_t fingers = DEFAULT_SLIDE_FINGER;
int32_t direction = SwipeDirection::ALL;
double speed = DEFAULT_SLIDE_SPEED;
GetSwipeGestureValue(runtimeCallInfo, fingers, direction, speed, NUM_1);
GetSwipeGestureValue(runtimeCallInfo, fingers, direction, speed, NUM_2);
auto* gesture =
GetArkUINodeModifiers()->getGestureModifier()->createSwipeGestureByModifier(fingers, direction, speed);
SetGestureTag(runtimeCallInfo, NUM_0, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_4, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_5);
SetGestureAllowedTypes(runtimeCallInfo, NUM_1, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::ACTION, NUM_5, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_6);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
return panda::JSValueRef::Undefined(vm);
}
@ -7416,14 +7452,15 @@ ArkUINativeModuleValue CommonBridge::AddPinchGestureToGroup(ArkUIRuntimeCallInfo
CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
int32_t fingers = DEFAULT_PINCH_FINGER;
double distance = DEFAULT_PINCH_DISTANCE;
GetPinchGestureValue(runtimeCallInfo, fingers, distance, NUM_1);
GetPinchGestureValue(runtimeCallInfo, fingers, distance, NUM_2);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createPinchGesture(fingers, distance, nullptr);
SetGestureTag(runtimeCallInfo, NUM_0, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_3, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_5, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_6, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_7);
SetGestureAllowedTypes(runtimeCallInfo, NUM_1, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_5, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_6, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_7, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_8);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
return panda::JSValueRef::Undefined(vm);
}
@ -7434,14 +7471,15 @@ ArkUINativeModuleValue CommonBridge::AddRotationGestureToGroup(ArkUIRuntimeCallI
CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
int32_t fingers = DEFAULT_ROTATION_FINGER;
double angle = DEFAULT_ROTATION_ANGLE;
GetRotationGestureValue(runtimeCallInfo, fingers, angle, NUM_1);
GetRotationGestureValue(runtimeCallInfo, fingers, angle, NUM_2);
auto* gesture = GetArkUINodeModifiers()->getGestureModifier()->createRotationGesture(fingers, angle, nullptr);
SetGestureTag(runtimeCallInfo, NUM_0, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_3, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_5, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_6, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_7);
SetGestureAllowedTypes(runtimeCallInfo, NUM_1, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::START, NUM_4, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::UPDATE, NUM_5, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::END, NUM_6, gesture);
SetOnGestureEvent(runtimeCallInfo, GestureEventAction::CANCEL, NUM_7, gesture);
auto* group = GetGestureGroup(runtimeCallInfo, NUM_8);
GetArkUINodeModifiers()->getGestureModifier()->addGestureToGestureGroupWithRefCountDecrease(group, gesture);
return panda::JSValueRef::Undefined(vm);
}

View File

@ -268,6 +268,8 @@ public:
static Local<panda::ObjectRef> CreateAreaObject(EcmaVM* vm, const RectF& rect, const OffsetF& origin);
static void GetGestureCommonValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& priority, int32_t& mask);
static void SetGestureTag(ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber, ArkUIGesture* gesture);
static void SetGestureAllowedTypes(
ArkUIRuntimeCallInfo* runtimeCallInfo, uint32_t argNumber, ArkUIGesture* gesture);
static void GetTapGestureValue(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t& fingers,
int32_t& count, double& distanceThreshold, uint32_t argNumber);
static void GetLongPressGestureValue(

View File

@ -507,6 +507,31 @@ void JSGesture::SetTag(const JSCallbackInfo& args)
GestureModel::GetInstance()->SetTag(tag);
}
void JSGesture::SetAllowedTypes(const JSCallbackInfo& args)
{
if (args.Length() < 1) {
return;
}
JSRef<JSVal> jsTypes = args[0];
if (!jsTypes->IsArray()) {
return;
}
JSRef<JSArray> jsTypesArr = JSRef<JSArray>::Cast(jsTypes);
std::set<SourceTool> allowedTypes{};
auto typesArrLength = jsTypesArr->Length();
for (size_t i = 0; i < typesArrLength; ++i) {
auto type = jsTypesArr->GetValueAt(i);
if (type->IsNumber()) {
allowedTypes.insert(static_cast<SourceTool>(type->ToNumber<int32_t>()));
}
}
if (allowedTypes.empty()) {
return;
}
GestureModel::GetInstance()->SetAllowedTypes(allowedTypes);
}
void JSGesture::JsHandlerOnAction(const JSCallbackInfo& args)
{
JSGesture::JsHandlerOnGestureEvent(Ace::GestureEventAction::ACTION, args);
@ -649,6 +674,7 @@ void JSGesture::JSBind(BindingTarget globalObj)
JSClass<JSTapGesture>::Declare("TapGesture");
JSClass<JSTapGesture>::StaticMethod("create", &JSTapGesture::Create, opt);
JSClass<JSTapGesture>::StaticMethod("tag", &JSGesture::SetTag, opt);
JSClass<JSTapGesture>::StaticMethod("allowedTypes", &JSGesture::SetAllowedTypes);
JSClass<JSTapGesture>::StaticMethod("pop", &JSGesture::Pop);
JSClass<JSTapGesture>::StaticMethod("onAction", &JSGesture::JsHandlerOnAction);
JSClass<JSTapGesture>::StaticMethod("onActionUpdate", &JSGesture::JsHandlerOnActionUpdate);
@ -657,6 +683,7 @@ void JSGesture::JSBind(BindingTarget globalObj)
JSClass<JSLongPressGesture>::Declare("LongPressGesture");
JSClass<JSLongPressGesture>::StaticMethod("create", &JSLongPressGesture::Create, opt);
JSClass<JSLongPressGesture>::StaticMethod("tag", &JSGesture::SetTag, opt);
JSClass<JSLongPressGesture>::StaticMethod("allowedTypes", &JSGesture::SetAllowedTypes);
JSClass<JSLongPressGesture>::StaticMethod("pop", &JSGesture::Pop);
JSClass<JSLongPressGesture>::StaticMethod("onAction", &JSGesture::JsHandlerOnAction);
JSClass<JSLongPressGesture>::StaticMethod("onActionEnd", &JSGesture::JsHandlerOnActionEnd);
@ -667,6 +694,7 @@ void JSGesture::JSBind(BindingTarget globalObj)
JSClass<JSPanGesture>::Declare("PanGesture");
JSClass<JSPanGesture>::StaticMethod("create", &JSPanGesture::Create, opt);
JSClass<JSPanGesture>::StaticMethod("tag", &JSGesture::SetTag, opt);
JSClass<JSPanGesture>::StaticMethod("allowedTypes", &JSGesture::SetAllowedTypes);
JSClass<JSPanGesture>::StaticMethod("pop", &JSGesture::Pop);
JSClass<JSPanGesture>::StaticMethod("onActionStart", &JSGesture::JsHandlerOnActionStart);
JSClass<JSPanGesture>::StaticMethod("onActionUpdate", &JSGesture::JsHandlerOnActionUpdate);
@ -677,6 +705,7 @@ void JSGesture::JSBind(BindingTarget globalObj)
JSClass<JSSwipeGesture>::Declare("SwipeGesture");
JSClass<JSSwipeGesture>::StaticMethod("create", &JSSwipeGesture::Create, opt);
JSClass<JSSwipeGesture>::StaticMethod("tag", &JSGesture::SetTag, opt);
JSClass<JSSwipeGesture>::StaticMethod("allowedTypes", &JSGesture::SetAllowedTypes);
JSClass<JSSwipeGesture>::StaticMethod("pop", &JSGesture::Pop);
JSClass<JSSwipeGesture>::StaticMethod("onAction", &JSGesture::JsHandlerOnAction);
JSClass<JSSwipeGesture>::Bind(globalObj);
@ -684,6 +713,7 @@ void JSGesture::JSBind(BindingTarget globalObj)
JSClass<JSPinchGesture>::Declare("PinchGesture");
JSClass<JSPinchGesture>::StaticMethod("create", &JSPinchGesture::Create, opt);
JSClass<JSPinchGesture>::StaticMethod("tag", &JSGesture::SetTag, opt);
JSClass<JSPinchGesture>::StaticMethod("allowedTypes", &JSGesture::SetAllowedTypes);
JSClass<JSPinchGesture>::StaticMethod("pop", &JSGesture::Pop);
JSClass<JSPinchGesture>::StaticMethod("onActionStart", &JSGesture::JsHandlerOnActionStart);
JSClass<JSPinchGesture>::StaticMethod("onActionUpdate", &JSGesture::JsHandlerOnActionUpdate);
@ -694,6 +724,7 @@ void JSGesture::JSBind(BindingTarget globalObj)
JSClass<JSRotationGesture>::Declare("RotationGesture");
JSClass<JSRotationGesture>::StaticMethod("create", &JSRotationGesture::Create, opt);
JSClass<JSRotationGesture>::StaticMethod("tag", &JSGesture::SetTag, opt);
JSClass<JSRotationGesture>::StaticMethod("allowedTypes", &JSGesture::SetAllowedTypes);
JSClass<JSRotationGesture>::StaticMethod("pop", &JSGesture::Pop);
JSClass<JSRotationGesture>::StaticMethod("onActionStart", &JSGesture::JsHandlerOnActionStart);
JSClass<JSRotationGesture>::StaticMethod("onActionUpdate", &JSGesture::JsHandlerOnActionUpdate);

View File

@ -45,6 +45,7 @@ public:
static void JsHandlerOnActionCancel(const JSCallbackInfo& args);
static void JsHandlerOnGestureEvent(Ace::GestureEventAction action, const JSCallbackInfo& args);
static void SetTag(const JSCallbackInfo& args);
static void SetAllowedTypes(const JSCallbackInfo& args);
}; // JSGesture
class JSTapGesture : public JSGesture {

View File

@ -28,6 +28,7 @@ public:
void SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter) override;
void SetOnActionFunc(const GestureEventFunc& gestureEventFunc, const Ace::GestureEventAction& action) override;
void SetTag(const std::string& tag) override {}
void SetAllowedTypes(const std::set<SourceTool>& allowedTypes) override {}
};
class TapGestureModelImpl : public OHOS::Ace::TapGestureModel {

View File

@ -37,6 +37,7 @@ public:
: type_(type), recognizerType_(trueType), isSystemGesture_(isSystemGesture)
{}
explicit GestureInfo(std::string tag) : tag_(std::move(tag)) {}
explicit GestureInfo(std::set<SourceTool> allowedTypes) : allowedTypes_(std::move(allowedTypes)) {}
explicit GestureInfo(GestureTypeName type) : type_(type) {}
explicit GestureInfo(bool isSystemGesture) : isSystemGesture_(isSystemGesture) {}
~GestureInfo() override
@ -57,6 +58,11 @@ public:
return tag_;
}
const std::set<SourceTool>& GetAllowedTypes() const
{
return allowedTypes_;
}
GestureTypeName GetType() const
{
return type_;
@ -77,6 +83,11 @@ public:
tag_ = std::move(tag);
}
void SetAllowedTypes(std::set<SourceTool> allowedTypes)
{
allowedTypes_ = std::move(allowedTypes);
}
void SetType(GestureTypeName type)
{
type_ = type;
@ -144,6 +155,7 @@ public:
private:
std::optional<std::string> tag_;
std::set<SourceTool> allowedTypes_{};
GestureTypeName type_ = GestureTypeName::UNKNOWN;
// used in onGestureRecognizerJudgeBegin
GestureTypeName recognizerType_ = GestureTypeName::UNKNOWN;

View File

@ -166,6 +166,15 @@ public:
}
}
void SetAllowedTypes(std::set<SourceTool> allowedTypes)
{
if (gestureInfo_) {
gestureInfo_->SetAllowedTypes(std::move(allowedTypes));
} else {
gestureInfo_ = MakeRefPtr<GestureInfo>(allowedTypes);
}
}
std::optional<std::string> GetTag()
{
if (gestureInfo_) {
@ -174,6 +183,14 @@ public:
return std::nullopt;
}
std::set<SourceTool> GetAllowedTypes()
{
if (gestureInfo_) {
return gestureInfo_->GetAllowedTypes();
}
return {};
}
virtual int32_t SizeofMe()
{
return 0;

View File

@ -545,6 +545,7 @@ bool ClickRecognizer::ReconcileFrom(const RefPtr<NGGestureRecognizer>& recognize
}
onAction_ = std::move(curr->onAction_);
ReconcileGestureInfoFrom(recognizer);
return true;
}
@ -553,7 +554,8 @@ RefPtr<GestureSnapshot> ClickRecognizer::Dump() const
RefPtr<GestureSnapshot> info = NGGestureRecognizer::Dump();
std::stringstream oss;
oss << "count: " << count_ << ", "
<< "fingers: " << fingers_;
<< "fingers: " << fingers_ << ", "
<< DumpGestureInfo();
info->customInfo = oss.str();
return info;
}

View File

@ -55,6 +55,17 @@ bool NGGestureRecognizer::ShouldResponse()
return true;
}
bool NGGestureRecognizer::IsAllowedType(SourceTool type)
{
// allow all types by default
if (!gestureInfo_) {
return true;
}
auto allowedTypes = gestureInfo_->GetAllowedTypes();
return allowedTypes.empty() || allowedTypes.find(type) != allowedTypes.end();
}
void NGGestureRecognizer::OnRejectBridgeObj()
{
if (bridgeObjList_.empty()) {
@ -71,10 +82,13 @@ void NGGestureRecognizer::OnRejectBridgeObj()
bool NGGestureRecognizer::HandleEvent(const TouchEvent& point)
{
if (!ShouldResponse()) {
if (!IsAllowedType(point.sourceTool) && point.type != TouchType::CANCEL) {
if (point.type == TouchType::DOWN) {
RemoveUnsupportEvent(point.id);
}
return true;
}
if (bridgeMode_) {
if (!ShouldResponse() || bridgeMode_) {
return true;
}
switch (point.type) {
@ -85,11 +99,8 @@ bool NGGestureRecognizer::HandleEvent(const TouchEvent& point)
case TouchType::DOWN: {
deviceId_ = point.deviceId;
deviceType_ = point.sourceType;
if (deviceType_ == SourceType::MOUSE) {
inputEventType_ = InputEventType::MOUSE_BUTTON;
} else {
inputEventType_ = InputEventType::TOUCH_SCREEN;
}
inputEventType_ = deviceType_ == SourceType::MOUSE ? InputEventType::MOUSE_BUTTON :
InputEventType::TOUCH_SCREEN;
auto result = AboutToAddCurrentFingers(point);
if (result) {
HandleTouchDownEvent(point);
@ -123,10 +134,13 @@ bool NGGestureRecognizer::HandleEvent(const TouchEvent& point)
bool NGGestureRecognizer::HandleEvent(const AxisEvent& event)
{
if (!ShouldResponse()) {
if (!IsAllowedType(event.sourceTool) && event.action != AxisAction::CANCEL) {
if (event.action == AxisAction::BEGIN) {
RemoveUnsupportEvent(event.id);
}
return true;
}
if (bridgeMode_) {
if (!ShouldResponse() || bridgeMode_) {
return true;
}
switch (event.action) {
@ -366,6 +380,15 @@ void NGGestureRecognizer::HandleDidAccept()
}
}
void NGGestureRecognizer::ReconcileGestureInfoFrom(const RefPtr<NGGestureRecognizer>& recognizer)
{
CHECK_NULL_VOID(recognizer);
auto currGestureInfo = recognizer->GetGestureInfo();
if (gestureInfo_ && currGestureInfo) {
gestureInfo_->SetAllowedTypes(currGestureInfo->GetAllowedTypes());
}
}
RefPtr<GestureSnapshot> NGGestureRecognizer::Dump() const
{
RefPtr<GestureSnapshot> info = TouchEventTarget::Dump();

View File

@ -432,10 +432,14 @@ protected:
virtual void OnResetStatus() = 0;
virtual void OnSucceedCancel() {}
virtual void RemoveUnsupportEvent(int32_t touchId) {}
bool ShouldResponse() override;
bool IsAllowedType(SourceTool type);
void HandleWillAccept();
void HandleDidAccept();
void ReconcileGestureInfoFrom(const RefPtr<NGGestureRecognizer>& recognizer);
RefereeState refereeState_ = RefereeState::READY;

View File

@ -402,7 +402,7 @@ bool LongPressRecognizer::ReconcileFrom(const RefPtr<NGGestureRecognizer>& recog
onAction_ = std::move(curr->onAction_);
onActionEnd_ = std::move(curr->onActionEnd_);
onActionCancel_ = std::move(curr->onActionCancel_);
ReconcileGestureInfoFrom(recognizer);
return true;
}
@ -434,7 +434,8 @@ RefPtr<GestureSnapshot> LongPressRecognizer::Dump() const
oss << "duration: " << duration_ << ", "
<< "isForDrag: " << isForDrag_ << ", "
<< "repeat: " << repeat_ << ", "
<< "fingers: " << fingers_;
<< "fingers: " << fingers_ << ", "
<< DumpGestureInfo();
info->customInfo = oss.str();
return info;
}

View File

@ -121,4 +121,29 @@ void MultiFingersRecognizer::UpdateTouchPointWithAxisEvent(const AxisEvent& even
touchPoints_[event.id].pointers = { point };
touchPoints_[event.id].pointerEvent = event.pointerEvent;
}
std::string MultiFingersRecognizer::DumpGestureInfo() const
{
std::string infoStr;
infoStr.append("allowedTypes: [");
std::set<SourceTool> allowedTypes = {};
if (gestureInfo_) {
allowedTypes = gestureInfo_->GetAllowedTypes();
}
if (allowedTypes.empty()) {
infoStr.append("all]");
return infoStr;
}
auto it = allowedTypes.begin();
while (it != allowedTypes.end()) {
infoStr.append(std::to_string(static_cast<int32_t>(*it)));
it++;
if (it != allowedTypes.end()) {
infoStr.append(", ");
}
}
infoStr.append("]");
return infoStr;
}
} // namespace OHOS::Ace::NG

View File

@ -78,6 +78,14 @@ protected:
touchPoints_[touchId] = {};
}
void RemoveUnsupportEvent(int32_t touchId) override
{
if (touchPoints_.empty() || touchPoints_.find(touchId) == touchPoints_.end()) {
return;
}
touchPoints_.erase(touchId);
}
void UpdateTouchPointWithAxisEvent(const AxisEvent& event);
void OnFinishGestureReferee(int32_t touchId, bool isBlocked) override;
@ -101,6 +109,8 @@ protected:
return std::find(activeFingers_.begin(), activeFingers_.end(), touchId) != activeFingers_.end();
}
std::string DumpGestureInfo() const;
std::map<int32_t, TouchEvent> touchPoints_;
std::list<FingerInfo> fingerList_;
std::list<int32_t> activeFingers_;

View File

@ -815,7 +815,7 @@ bool PanRecognizer::ReconcileFrom(const RefPtr<NGGestureRecognizer>& recognizer)
onActionUpdate_ = std::move(curr->onActionUpdate_);
onActionEnd_ = std::move(curr->onActionEnd_);
onActionCancel_ = std::move(curr->onActionCancel_);
ReconcileGestureInfoFrom(recognizer);
return true;
}
@ -892,7 +892,8 @@ RefPtr<GestureSnapshot> PanRecognizer::Dump() const
oss << "direction: " << direction_.type << ", "
<< "isForDrag: " << isForDrag_ << ", "
<< "distance: " << distance_ << ", "
<< "fingers: " << fingers_;
<< "fingers: " << fingers_ << ", "
<< DumpGestureInfo();
info->customInfo = oss.str();
return info;
}

View File

@ -485,8 +485,19 @@ bool PinchRecognizer::ReconcileFrom(const RefPtr<NGGestureRecognizer>& recognize
onActionUpdate_ = std::move(curr->onActionUpdate_);
onActionEnd_ = std::move(curr->onActionEnd_);
onActionCancel_ = std::move(curr->onActionCancel_);
ReconcileGestureInfoFrom(recognizer);
return true;
}
RefPtr<GestureSnapshot> PinchRecognizer::Dump() const
{
RefPtr<GestureSnapshot> info = NGGestureRecognizer::Dump();
std::stringstream oss;
oss << "distance: " << distance_ << ", "
<< "fingers: " << fingers_ << ", "
<< DumpGestureInfo();
info->customInfo = oss.str();
return info;
}
} // namespace OHOS::Ace::NG

View File

@ -34,6 +34,8 @@ public:
void OnAccepted() override;
void OnRejected() override;
virtual RefPtr<GestureSnapshot> Dump() const override;
private:
void HandleTouchDownEvent(const TouchEvent& event) override;
void HandleTouchUpEvent(const TouchEvent& event) override;

View File

@ -426,8 +426,19 @@ bool RotationRecognizer::ReconcileFrom(const RefPtr<NGGestureRecognizer>& recogn
onActionUpdate_ = std::move(curr->onActionUpdate_);
onActionEnd_ = std::move(curr->onActionEnd_);
onActionCancel_ = std::move(curr->onActionCancel_);
ReconcileGestureInfoFrom(recognizer);
return true;
}
RefPtr<GestureSnapshot> RotationRecognizer::Dump() const
{
RefPtr<GestureSnapshot> info = NGGestureRecognizer::Dump();
std::stringstream oss;
oss << "angle: " << angle_ << ", "
<< "fingers: " << fingers_ << ", "
<< DumpGestureInfo();
info->customInfo = oss.str();
return info;
}
} // namespace OHOS::Ace::NG

View File

@ -34,6 +34,8 @@ public:
void OnAccepted() override;
void OnRejected() override;
virtual RefPtr<GestureSnapshot> Dump() const override;
private:
void HandleTouchDownEvent(const TouchEvent& event) override;
void HandleTouchUpEvent(const TouchEvent& event) override;

View File

@ -463,6 +463,7 @@ bool SwipeRecognizer::ReconcileFrom(const RefPtr<NGGestureRecognizer>& recognize
}
onAction_ = std::move(curr->onAction_);
ReconcileGestureInfoFrom(recognizer);
return true;
}
@ -472,7 +473,8 @@ RefPtr<GestureSnapshot> SwipeRecognizer::Dump() const
std::stringstream oss;
oss << "direction: " << direction_.type << ", "
<< "speed: " << speed_ << ", "
<< "fingers: " << fingers_;
<< "fingers: " << fingers_ << ", "
<< DumpGestureInfo();
info->customInfo = oss.str();
return info;
}

View File

@ -36,6 +36,7 @@ public:
virtual void SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter) = 0;
virtual void SetOnActionFunc(const GestureEventFunc& gestureEventFunc, const Ace::GestureEventAction& action) = 0;
virtual void SetTag(const std::string& tag) = 0;
virtual void SetAllowedTypes(const std::set<SourceTool>& allowedTypes) = 0;
private:
static std::unique_ptr<GestureModel> instance_;

View File

@ -113,6 +113,15 @@ void GestureModelNG::SetTag(const std::string& tag)
gesture->SetTag(tag);
}
void GestureModelNG::SetAllowedTypes(const std::set<SourceTool>& allowedTypes)
{
RefPtr<GestureProcessor> gestureProcessor;
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
auto gesture = gestureProcessor->TopGestureNG();
CHECK_NULL_VOID(gesture);
gesture->SetAllowedTypes(allowedTypes);
}
void TapGestureModelNG::Create(int32_t countNum, int32_t fingersNum, double distanceThreshold)
{
RefPtr<GestureProcessor> gestureProcessor;

View File

@ -28,6 +28,7 @@ public:
void SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter) override;
void SetOnActionFunc(const GestureEventFunc& gestureEventFunc, const Ace::GestureEventAction& action) override;
void SetTag(const std::string& tag) override;
void SetAllowedTypes(const std::set<SourceTool>& allowedTypes) override;
};
class ACE_EXPORT TapGestureModelNG : public OHOS::Ace::TapGestureModel {