diff --git a/frameworks/bridge/declarative_frontend/BUILD.gn b/frameworks/bridge/declarative_frontend/BUILD.gn index 845c859d69b2e848119c2773d6eeaf5cd762c2c3..35c175953f980d79fadbd6be9b30c6f4772b3536 100644 --- a/frameworks/bridge/declarative_frontend/BUILD.gn +++ b/frameworks/bridge/declarative_frontend/BUILD.gn @@ -149,6 +149,7 @@ template("declarative_js_engine") { "engine/functions/js_foreach_function.cpp", "engine/functions/js_function.cpp", "engine/functions/js_gesture_function.cpp", + "engine/functions/js_gesture_judge_function.cpp", "engine/functions/js_hover_function.cpp", "engine/functions/js_key_function.cpp", "engine/functions/js_mouse_function.cpp", @@ -614,6 +615,7 @@ template("declarative_js_engine_ng") { "engine/functions/js_foreach_function.cpp", "engine/functions/js_function.cpp", "engine/functions/js_gesture_function.cpp", + "engine/functions/js_gesture_judge_function.cpp", "engine/functions/js_hover_function.cpp", "engine/functions/js_key_function.cpp", "engine/functions/js_mouse_function.cpp", diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ad42ae4c9c8ae7addea922b4807c7003cdca9ec5 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.h" + +#include "base/memory/ace_type.h" +#include "base/utils/utils.h" +#include "core/components/common/layout/constants.h" +#include "core/components_ng/gestures/base_gesture_event.h" + +namespace OHOS::Ace::Framework { + +GestureJudgeResult JsGestureJudgeFunction::Execute( + const RefPtr& gestureInfo, const std::shared_ptr& info) +{ + JSRef gestureInfoObj = JSRef::New(); + CHECK_NULL_RETURN(gestureInfo, GestureJudgeResult::CONTINUE); + CHECK_NULL_RETURN(info, GestureJudgeResult::CONTINUE); + if (gestureInfo->GetTag().has_value()) { + gestureInfoObj->SetProperty("tag", gestureInfo->GetTag().value()); + } + gestureInfoObj->SetProperty("type", static_cast(gestureInfo->GetType())); + gestureInfoObj->SetProperty("isSystemGesture", gestureInfo->IsSystemGesture()); + + JSRef obj = JSRef::New(); + SetUniqueAttributes(obj, gestureInfo->GetType(), info); + obj->SetProperty("timestamp", info->GetTimeStamp().time_since_epoch().count()); + obj->SetProperty("source", static_cast(info->GetSourceDevice())); + obj->SetProperty("pressure", info->GetForce()); + if (info->GetTiltX().has_value()) { + obj->SetProperty("tiltX", info->GetTiltX().value()); + } + if (info->GetTiltY().has_value()) { + obj->SetProperty("tiltY", info->GetTiltY().value()); + } + obj->SetProperty("sourceTool", static_cast(info->GetSourceTool())); + + JSRef fingerArr = JSRef::New(); + const std::list& fingerList = info->GetFingerList(); + std::list notTouchFingerList; + int32_t maxFingerId = -1; + for (const FingerInfo& fingerInfo : fingerList) { + JSRef element = CreateFingerInfo(fingerInfo); + if (fingerInfo.sourceType_ == SourceType::TOUCH && fingerInfo.sourceTool_ == SourceTool::FINGER) { + fingerArr->SetValueAt(fingerInfo.fingerId_, element); + if (fingerInfo.fingerId_ > maxFingerId) { + maxFingerId = fingerInfo.fingerId_; + } + } else { + notTouchFingerList.emplace_back(fingerInfo); + } + } + auto idx = maxFingerId + 1; + for (const FingerInfo& fingerInfo : notTouchFingerList) { + JSRef element = CreateFingerInfo(fingerInfo); + fingerArr->SetValueAt(idx++, element); + } + obj->SetPropertyObject("fingerList", fingerArr); + auto target = CreateEventTargetObject(info); + obj->SetPropertyObject("target", target); + int32_t paramCount = 2; + JSRef params[paramCount]; + params[0] = gestureInfoObj; + params[1] = obj; + auto jsValue = JsFunction::ExecuteJS(paramCount, params); + auto returnValue = GestureJudgeResult::CONTINUE; + if (jsValue->IsNumber()) { + returnValue = static_cast(jsValue->ToNumber()); + } + return returnValue; +} + +JSRef JsGestureJudgeFunction::CreateFingerInfo(const FingerInfo& fingerInfo) +{ + JSRef fingerInfoObj = JSRef::New(); + const OHOS::Ace::Offset& globalLocation = fingerInfo.globalLocation_; + const OHOS::Ace::Offset& localLocation = fingerInfo.localLocation_; + fingerInfoObj->SetProperty("id", fingerInfo.fingerId_); + fingerInfoObj->SetProperty("globalX", SystemProperties::Px2Vp(globalLocation.GetX())); + fingerInfoObj->SetProperty("globalY", SystemProperties::Px2Vp(globalLocation.GetY())); + fingerInfoObj->SetProperty("localX", SystemProperties::Px2Vp(localLocation.GetX())); + fingerInfoObj->SetProperty("localY", SystemProperties::Px2Vp(localLocation.GetY())); + return fingerInfoObj; +} + +JSRef JsGestureJudgeFunction::CreateEventTargetObject(const std::shared_ptr& info) +{ + JSRef objectTemplate = JSRef::New(); + JSRef target = objectTemplate->NewInstance(); + JSRef area = objectTemplate->NewInstance(); + JSRef offset = objectTemplate->NewInstance(); + JSRef globalOffset = objectTemplate->NewInstance(); + const auto& localOffset = info->GetTarget().area.GetOffset(); + const auto& origin = info->GetTarget().origin; + offset->SetProperty("x", localOffset.GetX().ConvertToVp()); + offset->SetProperty("y", localOffset.GetY().ConvertToVp()); + globalOffset->SetProperty("x", (origin.GetX().ConvertToVp() + localOffset.GetX().ConvertToVp())); + globalOffset->SetProperty("y", (origin.GetY().ConvertToVp() + localOffset.GetY().ConvertToVp())); + area->SetPropertyObject("position", offset); + area->SetPropertyObject("globalPosition", globalOffset); + area->SetProperty("width", info->GetTarget().area.GetWidth().ConvertToVp()); + area->SetProperty("height", info->GetTarget().area.GetHeight().ConvertToVp()); + target->SetPropertyObject("area", area); + return target; +} + +void JsGestureJudgeFunction::SetUniqueAttributes( + JSRef& obj, GestureTypeName typeName, const std::shared_ptr& info) +{ + switch (typeName) { + case OHOS::Ace::GestureTypeName::LONG_PRESS_GESTURE: { + auto longPressGestureEvent = TypeInfoHelper::DynamicCast(info.get()); + if (longPressGestureEvent) { + obj->SetProperty("repeat", longPressGestureEvent->GetRepeat()); + } + break; + } + case OHOS::Ace::GestureTypeName::PAN_GESTURE: { + auto panGestureEvent = TypeInfoHelper::DynamicCast(info.get()); + if (panGestureEvent) { + obj->SetProperty("offsetX", SystemProperties::Px2Vp(panGestureEvent->GetOffsetX())); + obj->SetProperty("offsetY", SystemProperties::Px2Vp(panGestureEvent->GetOffsetY())); + obj->SetProperty( + "velocityX", SystemProperties::Px2Vp(panGestureEvent->GetVelocity().GetVelocityX())); + obj->SetProperty( + "velocityY", SystemProperties::Px2Vp(panGestureEvent->GetVelocity().GetVelocityY())); + obj->SetProperty( + "velocity", SystemProperties::Px2Vp(panGestureEvent->GetVelocity().GetVelocityValue())); + } + break; + } + case OHOS::Ace::GestureTypeName::PINCH_GESTURE: { + auto pinchGestureEvent = TypeInfoHelper::DynamicCast(info.get()); + if (pinchGestureEvent) { + obj->SetProperty("scale", pinchGestureEvent->GetScale()); + obj->SetProperty( + "pinchCenterX", SystemProperties::Px2Vp(pinchGestureEvent->GetPinchCenter().GetX())); + obj->SetProperty( + "pinchCenterY", SystemProperties::Px2Vp(pinchGestureEvent->GetPinchCenter().GetY())); + } + break; + } + case OHOS::Ace::GestureTypeName::ROTATION_GESTURE: { + auto rotationGestureEvent = TypeInfoHelper::DynamicCast(info.get()); + if (rotationGestureEvent) { + obj->SetProperty("angle", rotationGestureEvent->GetAngle()); + } + break; + } + case OHOS::Ace::GestureTypeName::SWIPE_GESTURE: { + auto swipeGestureEvent = TypeInfoHelper::DynamicCast(info.get()); + if (swipeGestureEvent) { + obj->SetProperty("angle", swipeGestureEvent->GetAngle()); + obj->SetProperty("speed", swipeGestureEvent->GetSpeed()); + } + break; + } + default: + break; + } +} +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.h new file mode 100644 index 0000000000000000000000000000000000000000..61c4bfcf5c89a0e16c1c5a46408c0f231550b6d0 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_judge_function.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_GESTURE_JUDGE_FUNCTION_H +#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_GESTURE_JUDGE_FUNCTION_H + +#include +#include + +#include "base/memory/referenced.h" +#include "core/components/common/layout/constants.h" +#include "core/components_ng/gestures/base_gesture_event.h" +#include "core/gestures/gesture_info.h" +#include "frameworks/bridge/declarative_frontend/engine/functions/js_function.h" + +namespace OHOS::Ace::Framework { +class JsGestureJudgeFunction : public JsFunction { + DECLARE_ACE_TYPE(JsGestureJudgeFunction, JsFunction) + +public: + explicit JsGestureJudgeFunction(const JSRef& jsFunction) : JsFunction(JSRef(), jsFunction) {} + + ~JsGestureJudgeFunction() override = default; + + void Execute() override + { + ExecuteJS(); + } + + GestureJudgeResult Execute( + const RefPtr& gestureInfo, const std::shared_ptr& info); + +private: + JSRef CreateFingerInfo(const FingerInfo& fingerInfo); + JSRef CreateEventTargetObject(const std::shared_ptr& info); + void SetUniqueAttributes( + JSRef& obj, GestureTypeName typeName, const std::shared_ptr& info); +}; +} // namespace OHOS::Ace::Framework + +#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_GESTURE_JUDGE_FUNCTION_H diff --git a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js index fca90b1d8c25ebf27ce44b3efe6bff469fe2316c..4d794b545f322dc292d71a05067a87a12bd62463 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js +++ b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js @@ -1253,6 +1253,27 @@ var FunctionKey; FunctionKey[FunctionKey["F12"] = 12] = "F12"; })(FunctionKey || (FunctionKey = {})); +var GestureJudgeResult; +(function (GestureJudgeResult) { + GestureJudgeResult[GestureJudgeResult["CONTINUE"] = 0] = "CONTINUE"; + GestureJudgeResult[GestureJudgeResult["REJECT"] = 1] = "REJECT"; +})(GestureJudgeResult || (GestureJudgeResult = {})); + +var GestureControl; +(function (GestureControl) { + let GestureType; + (function (GestureType) { + GestureType[GestureType["TAP_GESTURE"] = 0] = "TAP_GESTURE"; + GestureType[GestureType["LONG_PRESS_GESTURE"] = 1] = "LONG_PRESS_GESTURE"; + GestureType[GestureType["PAN_GESTURE"] = 2] = "PAN_GESTURE"; + GestureType[GestureType["PINCH_GESTURE"] = 3] = "PINCH_GESTURE"; + GestureType[GestureType["SWIPE_GESTURE"] = 4] = "SWIPE_GESTURE"; + GestureType[GestureType["ROTATION_GESTURE"] = 5] = "ROTATION_GESTURE"; + GestureType[GestureType["DRAG"] = 6] = "DRAG"; + GestureType[GestureType["CLICK"] = 7] = "CLICK"; + })(GestureType = GestureControl.GestureType || (GestureControl.GestureType = {})); +})(GestureControl || (GestureControl = {})); + class SubTabBarStyle { constructor(content) { this.type = 'SubTabBarStyle'; diff --git a/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp b/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp index 6c4134c15cdd4da81d90f539fd5ee7316d5aa60a..8e1dc2b0c457189f0f930ffe4bcba9c123eb8471 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp @@ -477,6 +477,15 @@ void JSGesture::JsHandlerOnGestureEvent(Ace::GestureEventAction action, const JS GestureModel::GetInstance()->SetOnActionFunc(onActionFunc, action); } +void JSGesture::SetTag(const JSCallbackInfo& args) +{ + std::string tag; + if (args.Length() > 0 && args[0]->IsString()) { + tag = args[0]->ToString(); + } + GestureModel::GetInstance()->SetTag(tag); +} + void JSGesture::JsHandlerOnAction(const JSCallbackInfo& args) { JSGesture::JsHandlerOnGestureEvent(Ace::GestureEventAction::ACTION, args); @@ -608,6 +617,7 @@ void JSGesture::JSBind(BindingTarget globalObj) JSClass::Declare("TapGesture"); JSClass::StaticMethod("create", &JSTapGesture::Create, opt); + JSClass::StaticMethod("tag", &JSGesture::SetTag, opt); JSClass::StaticMethod("pop", &JSGesture::Pop); JSClass::StaticMethod("onAction", &JSGesture::JsHandlerOnAction); JSClass::StaticMethod("onActionUpdate", &JSGesture::JsHandlerOnActionUpdate); @@ -615,6 +625,7 @@ void JSGesture::JSBind(BindingTarget globalObj) JSClass::Declare("LongPressGesture"); JSClass::StaticMethod("create", &JSLongPressGesture::Create, opt); + JSClass::StaticMethod("tag", &JSGesture::SetTag, opt); JSClass::StaticMethod("pop", &JSGesture::Pop); JSClass::StaticMethod("onAction", &JSGesture::JsHandlerOnAction); JSClass::StaticMethod("onActionEnd", &JSGesture::JsHandlerOnActionEnd); @@ -624,6 +635,7 @@ void JSGesture::JSBind(BindingTarget globalObj) JSClass::Declare("PanGesture"); JSClass::StaticMethod("create", &JSPanGesture::Create, opt); + JSClass::StaticMethod("tag", &JSGesture::SetTag, opt); JSClass::StaticMethod("pop", &JSGesture::Pop); JSClass::StaticMethod("onActionStart", &JSGesture::JsHandlerOnActionStart); JSClass::StaticMethod("onActionUpdate", &JSGesture::JsHandlerOnActionUpdate); @@ -633,12 +645,14 @@ void JSGesture::JSBind(BindingTarget globalObj) JSClass::Declare("SwipeGesture"); JSClass::StaticMethod("create", &JSSwipeGesture::Create, opt); + JSClass::StaticMethod("tag", &JSGesture::SetTag, opt); JSClass::StaticMethod("pop", &JSGesture::Pop); JSClass::StaticMethod("onAction", &JSGesture::JsHandlerOnAction); JSClass::Bind(globalObj); JSClass::Declare("PinchGesture"); JSClass::StaticMethod("create", &JSPinchGesture::Create, opt); + JSClass::StaticMethod("tag", &JSGesture::SetTag, opt); JSClass::StaticMethod("pop", &JSGesture::Pop); JSClass::StaticMethod("onActionStart", &JSGesture::JsHandlerOnActionStart); JSClass::StaticMethod("onActionUpdate", &JSGesture::JsHandlerOnActionUpdate); @@ -648,6 +662,7 @@ void JSGesture::JSBind(BindingTarget globalObj) JSClass::Declare("RotationGesture"); JSClass::StaticMethod("create", &JSRotationGesture::Create, opt); + JSClass::StaticMethod("tag", &JSGesture::SetTag, opt); JSClass::StaticMethod("pop", &JSGesture::Pop); JSClass::StaticMethod("onActionStart", &JSGesture::JsHandlerOnActionStart); JSClass::StaticMethod("onActionUpdate", &JSGesture::JsHandlerOnActionUpdate); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_gesture.h b/frameworks/bridge/declarative_frontend/jsview/js_gesture.h index d502fdb9cc2df90e5a515d7b54620ffc7c8ff6e6..cf2320381d75bea4aea3353d4303a7755d377130 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_gesture.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_gesture.h @@ -44,6 +44,7 @@ public: static void JsHandlerOnActionEnd(const JSCallbackInfo& args); static void JsHandlerOnActionCancel(const JSCallbackInfo& args); static void JsHandlerOnGestureEvent(Ace::GestureEventAction action, const JSCallbackInfo& args); + static void SetTag(const JSCallbackInfo& args); }; // JSGesture class JSTapGesture : public JSGesture { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp index b5c0f130dc1d7fd0225f20e1aaed1488b4f85616..e48bf1b15b3a0b131a2df0f79f888f0db646b4b0 100755 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp @@ -43,6 +43,7 @@ #include "bridge/declarative_frontend/engine/functions/js_drag_function.h" #include "bridge/declarative_frontend/engine/functions/js_focus_function.h" #include "bridge/declarative_frontend/engine/functions/js_function.h" +#include "bridge/declarative_frontend/engine/functions/js_gesture_judge_function.h" #include "bridge/declarative_frontend/engine/functions/js_hover_function.h" #include "bridge/declarative_frontend/engine/functions/js_key_function.h" #include "bridge/declarative_frontend/engine/functions/js_on_area_change_function.h" @@ -56,6 +57,7 @@ #include "bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h" #include "core/common/resource/resource_manager.h" #include "core/common/resource/resource_object.h" +#include "core/components/common/layout/constants.h" #include "core/components/common/layout/screen_system_manager.h" #include "core/components/common/properties/animation_option.h" #include "core/components/common/properties/border_image.h" @@ -64,6 +66,7 @@ #include "core/components/common/properties/shadow.h" #include "core/components/theme/resource_adapter.h" #include "core/components_ng/base/view_abstract_model.h" +#include "core/components_ng/gestures/base_gesture_event.h" #include "core/components_ng/pattern/menu/menu_pattern.h" #include "core/components_ng/pattern/overlay/modal_style.h" #include "core/components_ng/property/safe_area_insets.h" @@ -5499,6 +5502,7 @@ void JSViewAbstract::JSBind(BindingTarget globalObj) JSClass::StaticMethod("onMouse", &JSViewAbstract::JsOnMouse); JSClass::StaticMethod("onHover", &JSViewAbstract::JsOnHover); JSClass::StaticMethod("onClick", &JSViewAbstract::JsOnClick); + JSClass::StaticMethod("onGestureJudgeBegin", &JSViewAbstract::JsOnGestureJudgeBegin); JSClass::StaticMethod("clickEffect", &JSViewAbstract::JsClickEffect); JSClass::StaticMethod("debugLine", &JSViewAbstract::JsDebugLine); JSClass::StaticMethod("geometryTransition", &JSViewAbstract::JsGeometryTransition); @@ -6148,6 +6152,24 @@ void JSViewAbstract::JsOnClick(const JSCallbackInfo& info) ViewAbstractModel::GetInstance()->SetOnClick(std::move(onTap), std::move(onClick)); } +void JSViewAbstract::JsOnGestureJudgeBegin(const JSCallbackInfo& info) +{ + if (info[0]->IsUndefined() || !info[0]->IsFunction()) { + ViewAbstractModel::GetInstance()->SetOnGestureJudgeBegin(nullptr); + return; + } + + auto jsOnGestureJudgeFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); + auto onGestureJudgefunc = [execCtx = info.GetExecutionContext(), func = jsOnGestureJudgeFunc]( + const RefPtr& gestureInfo, + const std::shared_ptr& info) -> GestureJudgeResult { + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx, GestureJudgeResult::CONTINUE); + ACE_SCORING_EVENT("onGestureJudgeBegin"); + return func->Execute(gestureInfo, info); + }; + ViewAbstractModel::GetInstance()->SetOnGestureJudgeBegin(std::move(onGestureJudgefunc)); +} + void JSViewAbstract::JsClickEffect(const JSCallbackInfo& info) { if (info[0]->IsUndefined() || info[0]->IsNull()) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h index c9f62ef52b952bf9bdd58b724728cbb3a067b94c..aa01defea67c48215557b528d73d8f3403cfe2f8 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h @@ -159,6 +159,7 @@ public: static void JsOnMouse(const JSCallbackInfo& info); static void JsOnHover(const JSCallbackInfo& info); static void JsOnClick(const JSCallbackInfo& info); + static void JsOnGestureJudgeBegin(const JSCallbackInfo& args); static void JsClickEffect(const JSCallbackInfo& info); static void JsRestoreId(int32_t restoreId); static void JsOnVisibleAreaChange(const JSCallbackInfo& info); diff --git a/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.h index 7e8a4ff68f14e912fc5afa6ccc5692c9ee1e2a0d..67ac6ec2c04eebb206c8412a8d67c62cf1f9a1dc 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/gesture_model_impl.h @@ -17,6 +17,7 @@ #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_GESTURE_MODEL_IMPL_H #include "core/components_ng/pattern/gesture/gesture_model.h" +#include "core/components_ng/gestures/gesture_info.h" namespace OHOS::Ace::Framework { class GestureModelImpl : public OHOS::Ace::GestureModel { @@ -26,6 +27,7 @@ public: void Pop() override; void SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter) override; void SetOnActionFunc(const GestureEventFunc& gestureEventFunc, const Ace::GestureEventAction& action) override; + void SetTag(const std::string& tag) override {} }; class TapGestureModelImpl : public OHOS::Ace::TapGestureModel { 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 c9134aae2073edcc000a6a54a3511dde21378074..c29eda4749db3c771e4a8c224ee493c48addf4ce 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/view_abstract_model_impl.h @@ -139,6 +139,7 @@ public: void SetClickEffectLevel(const ClickEffectLevel& level, float scaleValue) override {} void SetOnClick(GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc) override; + void SetOnGestureJudgeBegin(NG::GestureJudgeFunc&& gestureJudgeFunc) override {} void SetOnTouch(TouchEventFunc&& touchEventFunc) override; void SetOnKeyEvent(OnKeyCallbackFunc&& onKeyCallback) override; void SetOnMouse(OnMouseEventFunc&& onMouseEventFunc) override; diff --git a/frameworks/core/components/common/layout/constants.h b/frameworks/core/components/common/layout/constants.h index 41bb8d7ce5c5539832a11c1deae1085de84648e7..ea68a864d09bf9e667a3e94f6636c9cea2a86d25 100644 --- a/frameworks/core/components/common/layout/constants.h +++ b/frameworks/core/components/common/layout/constants.h @@ -620,6 +620,22 @@ enum class TabBarStyle { BOTTOMTABBATSTYLE, }; +enum class GestureJudgeResult { + CONTINUE = 0, + REJECT = 1, +}; + +enum class GestureTypeName { + TAP_GESTURE = 0, + LONG_PRESS_GESTURE = 1, + PAN_GESTURE = 2, + PINCH_GESTURE = 3, + SWIPE_GESTURE = 4, + ROTATION_GESTURE = 5, + DRAG = 6, + CLICK = 7, +}; + enum class ModifierKey { CTRL = 0, SHIFT = 1, diff --git a/frameworks/core/components_ng/base/frame_node.cpp b/frameworks/core/components_ng/base/frame_node.cpp index 515537deab751a62b55c675758cf800073424f6f..543453763a1a8fb3b03f006899f689e7433e7f82 100644 --- a/frameworks/core/components_ng/base/frame_node.cpp +++ b/frameworks/core/components_ng/base/frame_node.cpp @@ -34,6 +34,7 @@ #include "core/components_ng/base/inspector.h" #include "core/components_ng/base/ui_node.h" #include "core/components_ng/event/gesture_event_hub.h" +#include "core/components_ng/event/target_component.h" #include "core/components_ng/layout/layout_algorithm.h" #include "core/components_ng/layout/layout_wrapper.h" #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h" @@ -45,6 +46,7 @@ #include "core/components_ng/syntax/lazy_for_each_node.h" #include "core/components_v2/inspector/inspector_constants.h" #include "core/event/touch_event.h" +#include "core/gestures/gesture_info.h" #include "core/pipeline_ng/pipeline_context.h" #include "core/pipeline_ng/ui_task_scheduler.h" @@ -1578,6 +1580,16 @@ bool FrameNode::IsOutOfTouchTestRegion(const PointF& parentRevertPoint, int32_t HitTestResult FrameNode::TouchTest(const PointF& globalPoint, const PointF& parentLocalPoint, const PointF& parentRevertPoint, const TouchRestrict& touchRestrict, TouchTestResult& result, int32_t touchId) { + auto targetComponent = MakeRefPtr(); + targetComponent->SetNode(WeakClaim(this)); + auto gestureHub = eventHub_->GetGestureEventHub(); + if (gestureHub) { + auto callback = gestureHub->GetOnGestureJudgeBeginCallback(); + if (callback) { + targetComponent->SetOnGestureJudgeBegin(std::move(callback)); + } + } + if (!isActive_ || !eventHub_->IsEnabled() || bypass_) { if (SystemProperties::GetDebugEnabled()) { LOGI("%{public}s is inActive, need't do touch test", GetTag().c_str()); @@ -1695,8 +1707,8 @@ HitTestResult FrameNode::TouchTest(const PointF& globalPoint, const PointF& pare if (gestureHub) { TouchTestResult finalResult; const auto coordinateOffset = globalPoint - localPoint - localTransformOffset; - preventBubbling = gestureHub->ProcessTouchTestHit( - coordinateOffset, touchRestrict, newComingTargets, finalResult, touchId, localPoint); + preventBubbling = gestureHub->ProcessTouchTestHit(coordinateOffset, touchRestrict, newComingTargets, + finalResult, touchId, localPoint, targetComponent); newComingTargets.swap(finalResult); } } else if (touchRestrict.hitTestType == SourceType::MOUSE) { diff --git a/frameworks/core/components_ng/base/view_abstract.cpp b/frameworks/core/components_ng/base/view_abstract.cpp index 266df456590eaac283294324a341a5241964a763..bb9f612099d6cccb24f6a30977a0d4c671ede20c 100644 --- a/frameworks/core/components_ng/base/view_abstract.cpp +++ b/frameworks/core/components_ng/base/view_abstract.cpp @@ -632,6 +632,13 @@ void ViewAbstract::SetOnClick(GestureEventFunc&& clickEventFunc) gestureHub->SetUserOnClick(std::move(clickEventFunc)); } +void ViewAbstract::SetOnGestureJudgeBegin(GestureJudgeFunc&& gestureJudgeFunc) +{ + auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub(); + CHECK_NULL_VOID(gestureHub); + gestureHub->SetOnGestureJudgeBegin(std::move(gestureJudgeFunc)); +} + void ViewAbstract::SetOnTouch(TouchEventFunc&& touchEventFunc) { auto gestureHub = ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub(); diff --git a/frameworks/core/components_ng/base/view_abstract.h b/frameworks/core/components_ng/base/view_abstract.h index ff92f6c9fdb473c03deb4c62a841d14a8c79e7ac..345f03bbbc3ce60ead2f714af11545a2889e8991 100644 --- a/frameworks/core/components_ng/base/view_abstract.h +++ b/frameworks/core/components_ng/base/view_abstract.h @@ -189,6 +189,7 @@ public: // event static void SetOnClick(GestureEventFunc&& clickEventFunc); + static void SetOnGestureJudgeBegin(GestureJudgeFunc&& gestureJudgeFunc); static void SetOnTouch(TouchEventFunc&& touchEventFunc); static void SetOnMouse(OnMouseEventFunc&& onMouseEventFunc); static void SetOnHover(OnHoverFunc&& onHoverEventFunc); diff --git a/frameworks/core/components_ng/base/view_abstract_model.h b/frameworks/core/components_ng/base/view_abstract_model.h index e616d24e8ff8e3eb15d3eba3473e0a5fe924722e..a4a2bc15b4c273a1b4d03cf31a7a4ed626911d83 100644 --- a/frameworks/core/components_ng/base/view_abstract_model.h +++ b/frameworks/core/components_ng/base/view_abstract_model.h @@ -190,6 +190,7 @@ public: // event virtual void SetOnClick(GestureEventFunc&& tapEventFunc, ClickEventFunc&& clickEventFunc) = 0; + virtual void SetOnGestureJudgeBegin(NG::GestureJudgeFunc&& gestureJudgeFunc) = 0; virtual void SetOnTouch(TouchEventFunc&& touchEventFunc) = 0; virtual void SetOnKeyEvent(OnKeyCallbackFunc&& onKeyCallback) = 0; virtual void SetOnMouse(OnMouseEventFunc&& onMouseEventFunc) = 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 b4e24d0680e6eecaf77ba876e74900c061575198..b73f8ac0425a0acf78b1c62b79bbda0d494e63ca 100644 --- a/frameworks/core/components_ng/base/view_abstract_model_ng.h +++ b/frameworks/core/components_ng/base/view_abstract_model_ng.h @@ -656,6 +656,11 @@ public: ViewAbstract::SetOnClick(std::move(tapEventFunc)); } + void SetOnGestureJudgeBegin(NG::GestureJudgeFunc&& gestureJudgeFunc) override + { + ViewAbstract::SetOnGestureJudgeBegin(std::move(gestureJudgeFunc)); + } + void SetOnTouch(TouchEventFunc&& touchEventFunc) override { ViewAbstract::SetOnTouch(std::move(touchEventFunc)); diff --git a/frameworks/core/components_ng/event/BUILD.gn b/frameworks/core/components_ng/event/BUILD.gn index 0165f5a1c1c9bd12ec13296365af7e5c066f90d4..a15694610c4ce271bd497d86a58ed22116dc9b27 100644 --- a/frameworks/core/components_ng/event/BUILD.gn +++ b/frameworks/core/components_ng/event/BUILD.gn @@ -27,6 +27,7 @@ build_component_ng("event_ng") { "pan_event.cpp", "scrollable_event.cpp", "state_style_manager.cpp", + "target_component.cpp", "touch_event.cpp", ] } diff --git a/frameworks/core/components_ng/event/click_event.cpp b/frameworks/core/components_ng/event/click_event.cpp index e0544c69f1906ace52dce9428607f2c563d7380f..eb62ad11833954b18b129551d093f615bbfaee46 100644 --- a/frameworks/core/components_ng/event/click_event.cpp +++ b/frameworks/core/components_ng/event/click_event.cpp @@ -17,10 +17,11 @@ #include "base/utils/utils.h" #include "core/accessibility/accessibility_utils.h" +#include "core/components/common/layout/constants.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/event/gesture_event_hub.h" +#include "core/components_ng/event/gesture_info.h" #include "core/components_ng/gestures/recognizers/click_recognizer.h" -#include "core/pipeline_ng/pipeline_context.h" namespace OHOS::Ace::NG { @@ -42,6 +43,7 @@ void ClickEventActuator::OnCollectTouchTarget(const OffsetF& coordinateOffset, c if (!clickRecognizer_) { clickRecognizer_ = MakeRefPtr(); } + clickRecognizer_->SetGestureInfo(MakeRefPtr(GestureTypeName::CLICK, true)); clickRecognizer_->SetOnAction(GetClickEvent()); clickRecognizer_->SetCoordinateOffset(Offset(coordinateOffset.GetX(), coordinateOffset.GetY())); clickRecognizer_->SetGetEventTargetImpl(getEventTargetImpl); diff --git a/frameworks/core/components_ng/event/drag_event.cpp b/frameworks/core/components_ng/event/drag_event.cpp index 9e4cbf30d1161e10157ecfd0ee0b355bb0f6e5e6..c61c86167d9327575cfafece929cdbe397315e00 100644 --- a/frameworks/core/components_ng/event/drag_event.cpp +++ b/frameworks/core/components_ng/event/drag_event.cpp @@ -20,8 +20,10 @@ #include "core/common/container.h" #include "core/common/interaction/interaction_data.h" #include "core/common/interaction/interaction_interface.h" +#include "core/components/common/layout/constants.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/event/gesture_event_hub.h" +#include "core/components_ng/event/gesture_info.h" #include "core/components_ng/gestures/recognizers/long_press_recognizer.h" #include "core/components_ng/gestures/recognizers/pan_recognizer.h" #include "core/components_ng/gestures/recognizers/sequenced_recognizer.h" @@ -80,9 +82,12 @@ DragEventActuator::DragEventActuator( } panRecognizer_ = MakeRefPtr(fingers_, direction_, distance_); + panRecognizer_->SetGestureInfo(MakeRefPtr(GestureTypeName::DRAG, true)); longPressRecognizer_ = AceType::MakeRefPtr(LONG_PRESS_DURATION, fingers_, false, false); + longPressRecognizer_->SetGestureInfo(MakeRefPtr(GestureTypeName::DRAG, true)); previewLongPressRecognizer_ = AceType::MakeRefPtr(PREVIEW_LONG_PRESS_RECONGNIZER, fingers_, false, false); + previewLongPressRecognizer_->SetGestureInfo(MakeRefPtr(GestureTypeName::DRAG, true)); isNotInPreviewState_ = false; } @@ -117,6 +122,7 @@ void DragEventActuator::OnCollectTouchTarget(const OffsetF& coordinateOffset, co const GetEventTargetImpl& getEventTargetImpl, TouchTestResult& result) { CHECK_NULL_VOID(userCallback_); + isDragUserReject_ = false; auto gestureHub = gestureEventHub_.Upgrade(); CHECK_NULL_VOID(gestureHub); auto frameNode = gestureHub->GetFrameNode(); @@ -307,6 +313,7 @@ void DragEventActuator::OnCollectTouchTarget(const OffsetF& coordinateOffset, co panRecognizer_->SetIsForDrag(true); panRecognizer_->SetMouseDistance(DRAG_PAN_DISTANCE_MOUSE.ConvertToPx()); actionCancel_ = actionCancel; + panRecognizer_->SetCoordinateOffset(Offset(coordinateOffset.GetX(), coordinateOffset.GetY())); panRecognizer_->SetOnActionCancel(actionCancel); #ifdef ENABLE_DRAG_FRAMEWORK if (touchRestrict.sourceType == SourceType::MOUSE) { @@ -414,6 +421,8 @@ void DragEventActuator::OnCollectTouchTarget(const OffsetF& coordinateOffset, co std::vector> recognizers { longPressRecognizer_, panRecognizer_ }; SequencedRecognizer_ = AceType::MakeRefPtr(recognizers); SequencedRecognizer_->RemainChildOnResetStatus(); + previewLongPressRecognizer_->SetCoordinateOffset(Offset(coordinateOffset.GetX(), coordinateOffset.GetY())); + longPressRecognizer_->SetCoordinateOffset(Offset(coordinateOffset.GetX(), coordinateOffset.GetY())); SequencedRecognizer_->SetCoordinateOffset(Offset(coordinateOffset.GetX(), coordinateOffset.GetY())); SequencedRecognizer_->SetGetEventTargetImpl(getEventTargetImpl); result.emplace_back(SequencedRecognizer_); diff --git a/frameworks/core/components_ng/event/drag_event.h b/frameworks/core/components_ng/event/drag_event.h index 50b38bdd2e161b1916616550d29387daca0f841e..ba4168c4d3b9304626cb8fb9e0d9713ea2a16df5 100644 --- a/frameworks/core/components_ng/event/drag_event.h +++ b/frameworks/core/components_ng/event/drag_event.h @@ -158,6 +158,16 @@ public: return isNotInPreviewState_; } + void SetIsDragUserReject(bool isDragUserReject) + { + isDragUserReject_ = isDragUserReject; + } + + bool IsDragUserReject() const + { + return isDragUserReject_; + } + private: WeakPtr gestureEventHub_; RefPtr userCallback_; @@ -175,6 +185,8 @@ private: bool isReceivedLongPress_ = false; bool isNotInPreviewState_ = false; + bool isDragUserReject_ = false; + PanDirection direction_; int32_t fingers_ = 1; float distance_ = 0.0f; diff --git a/frameworks/core/components_ng/event/gesture_event_hub.cpp b/frameworks/core/components_ng/event/gesture_event_hub.cpp index a7b5bb843a09899ae0ec55c58b3257febbc548b5..99207da780acc0bc05a6735a3ada9a6bf84e7724 100644 --- a/frameworks/core/components_ng/event/gesture_event_hub.cpp +++ b/frameworks/core/components_ng/event/gesture_event_hub.cpp @@ -73,7 +73,8 @@ RefPtr GestureEventHub::GetFrameNode() const } bool GestureEventHub::ProcessTouchTestHit(const OffsetF& coordinateOffset, const TouchRestrict& touchRestrict, - TouchTestResult& innerTargets, TouchTestResult& finalResult, int32_t touchId, const PointF& localPoint) + TouchTestResult& innerTargets, TouchTestResult& finalResult, int32_t touchId, const PointF& localPoint, + const RefPtr& targetComponent) { size_t idx = innerTargets.size(); size_t newIdx = 0; @@ -107,6 +108,13 @@ bool GestureEventHub::ProcessTouchTestHit(const OffsetF& coordinateOffset, const auto recognizer = AceType::DynamicCast(item); if (recognizer) { recognizer->BeginReferee(touchId); + recognizer->SetTargetComponent(targetComponent); + if (AceType::InstanceOf(recognizer)) { + auto group = AceType::DynamicCast(recognizer); + if (group) { + group->SetChildrenTargetComponent(targetComponent); + } + } } longPressRecognizers.emplace_back(AceType::DynamicCast(item)); } @@ -130,18 +138,21 @@ bool GestureEventHub::ProcessTouchTestHit(const OffsetF& coordinateOffset, const if (!recognizerGroup && newIdx >= idx) { recognizer->AssignNodeId(host->GetId()); recognizer->AttachFrameNode(WeakPtr(host)); + recognizer->SetTargetComponent(targetComponent); + recognizer->SetIsSystemGesture(true); } recognizer->BeginReferee(touchId); innerRecognizers.push_back(std::move(recognizer)); } else { eventTarget->AssignNodeId(host->GetId()); eventTarget->AttachFrameNode(WeakPtr(host)); + eventTarget->SetTargetComponent(targetComponent); finalResult.push_back(eventTarget); } newIdx++; // not process previous recognizers } - ProcessTouchTestHierarchy(coordinateOffset, touchRestrict, innerRecognizers, finalResult, touchId); + ProcessTouchTestHierarchy(coordinateOffset, touchRestrict, innerRecognizers, finalResult, touchId, targetComponent); return false; } @@ -155,7 +166,8 @@ void GestureEventHub::OnModifyDone() } void GestureEventHub::ProcessTouchTestHierarchy(const OffsetF& coordinateOffset, const TouchRestrict& touchRestrict, - std::list>& innerRecognizers, TouchTestResult& finalResult, int32_t touchId) + std::list>& innerRecognizers, TouchTestResult& finalResult, int32_t touchId, + const RefPtr& targetComponent) { auto host = GetFrameNode(); if (!host) { @@ -180,6 +192,7 @@ void GestureEventHub::ProcessTouchTestHierarchy(const OffsetF& coordinateOffset, innerExclusiveRecognizer_->SetCoordinateOffset(offset); innerExclusiveRecognizer_->BeginReferee(touchId); innerExclusiveRecognizer_->AttachFrameNode(WeakPtr(host)); + innerExclusiveRecognizer_->SetTargetComponent(targetComponent); current = innerExclusiveRecognizer_; } @@ -198,11 +211,13 @@ void GestureEventHub::ProcessTouchTestHierarchy(const OffsetF& coordinateOffset, for (const auto& groupRecognizer : groupRecognizers) { if (groupRecognizer) { groupRecognizer->SetCoordinateOffset(offset); + groupRecognizer->SetTargetComponent(targetComponent); } } } recognizer->AssignNodeId(host->GetId()); recognizer->AttachFrameNode(WeakPtr(host)); + recognizer->SetTargetComponent(targetComponent); recognizer->SetSize(size.Height(), size.Width()); recognizer->SetCoordinateOffset(offset); recognizer->BeginReferee(touchId, true); @@ -229,6 +244,7 @@ void GestureEventHub::ProcessTouchTestHierarchy(const OffsetF& coordinateOffset, externalParallelRecognizer_[parallelIndex]->BeginReferee(touchId); externalParallelRecognizer_[parallelIndex]->AssignNodeId(host->GetId()); externalParallelRecognizer_[parallelIndex]->AttachFrameNode(WeakPtr(host)); + externalParallelRecognizer_[parallelIndex]->SetTargetComponent(targetComponent); current = externalParallelRecognizer_[parallelIndex]; parallelIndex++; } else if (recognizers.size() == 1) { @@ -254,6 +270,7 @@ void GestureEventHub::ProcessTouchTestHierarchy(const OffsetF& coordinateOffset, externalExclusiveRecognizer_[exclusiveIndex]->BeginReferee(touchId); externalExclusiveRecognizer_[exclusiveIndex]->AssignNodeId(host->GetId()); externalExclusiveRecognizer_[exclusiveIndex]->AttachFrameNode(WeakPtr(host)); + externalExclusiveRecognizer_[exclusiveIndex]->SetTargetComponent(targetComponent); current = externalExclusiveRecognizer_[exclusiveIndex]; exclusiveIndex++; } else if (recognizers.size() == 1) { @@ -922,6 +939,11 @@ void GestureEventHub::SetUserOnClick(GestureEventFunc&& clickEvent) SetFocusClickEvent(clickEventActuator_->GetClickEvent()); } +void GestureEventHub::SetOnGestureJudgeBegin(GestureJudgeFunc&& gestureJudgeFunc) +{ + gestureJudgeFunc_ = std::move(gestureJudgeFunc); +} + void GestureEventHub::AddClickEvent(const RefPtr& clickEvent) { CheckClickActuator(); diff --git a/frameworks/core/components_ng/event/gesture_event_hub.h b/frameworks/core/components_ng/event/gesture_event_hub.h index 56b0e7cf509654d96581f0254f3ed37d00ab9be9..827512c828d22bee0f84310abaa938c7162a7781 100644 --- a/frameworks/core/components_ng/event/gesture_event_hub.h +++ b/frameworks/core/components_ng/event/gesture_event_hub.h @@ -28,11 +28,13 @@ #include "core/components_ng/event/long_press_event.h" #include "core/components_ng/event/pan_event.h" #include "core/components_ng/event/scrollable_event.h" +#include "core/components_ng/event/target_component.h" #include "core/components_ng/event/touch_event.h" #include "core/components_ng/gestures/gesture_info.h" #include "core/components_ng/gestures/recognizers/exclusive_recognizer.h" #include "core/components_ng/gestures/recognizers/parallel_recognizer.h" #include "core/components_ng/manager/drag_drop/drag_drop_proxy.h" +#include "core/gestures/gesture_info.h" #ifdef ENABLE_DRAG_FRAMEWORK namespace OHOS::Msdp::DeviceStatus { @@ -219,6 +221,13 @@ public: // Set by user define, which will replace old one. void SetUserOnClick(GestureEventFunc&& clickEvent); + void SetOnGestureJudgeBegin(GestureJudgeFunc&& gestureJudgeFunc); + + GestureJudgeFunc GetOnGestureJudgeBeginCallback() const + { + return gestureJudgeFunc_; + } + // When the event param is undefined, it will clear the callback. void ClearUserOnClick(); void ClearUserOnTouch(); @@ -310,7 +319,8 @@ public: // the return value means prevents event bubbling. bool ProcessTouchTestHit(const OffsetF& coordinateOffset, const TouchRestrict& touchRestrict, - TouchTestResult& innerTargets, TouchTestResult& finalResult, int32_t touchId, const PointF& localPoint); + TouchTestResult& innerTargets, TouchTestResult& finalResult, int32_t touchId, const PointF& localPoint, + const RefPtr& targetComponent); RefPtr GetFrameNode() const; @@ -482,9 +492,15 @@ public: bool IsAllowedDrag(RefPtr eventHub); void HandleNotallowDrag(const GestureEvent& info); + RefPtr GetDragEventActuator() + { + return dragEventActuator_; + } + private: void ProcessTouchTestHierarchy(const OffsetF& coordinateOffset, const TouchRestrict& touchRestrict, - std::list>& innerRecognizers, TouchTestResult& finalResult, int32_t touchId); + std::list>& innerRecognizers, TouchTestResult& finalResult, int32_t touchId, + const RefPtr& targetComponent); void UpdateGestureHierarchy(); @@ -528,6 +544,8 @@ private: GestureEvent gestureInfoForWeb_; bool isReceivedDragGestureInfo_ = false; + GestureJudgeFunc gestureJudgeFunc_; + #ifdef ENABLE_DRAG_FRAMEWORK MenuPreviewMode previewMode_ = MenuPreviewMode::NONE; bool textDraggable_ = false; diff --git a/frameworks/core/components_ng/event/gesture_info.h b/frameworks/core/components_ng/event/gesture_info.h new file mode 100644 index 0000000000000000000000000000000000000000..f645e54e882e9edf5002baf6b02b41e69b7ebfd8 --- /dev/null +++ b/frameworks/core/components_ng/event/gesture_info.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_GESTURE_INFO_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_GESTURE_INFO_H + +#include + +#include "base/memory/ace_type.h" +#include "core/components/common/layout/constants.h" + +namespace OHOS::Ace::NG { + +class ACE_EXPORT GestureInfo : public virtual AceType { + DECLARE_ACE_TYPE(GestureInfo, AceType); + +public: + GestureInfo() = default; + GestureInfo(std::string tag, GestureTypeName type, bool isSystemGesture) + : tag_(std::move(tag)), type_(type), isSystemGesture_(isSystemGesture) + {} + GestureInfo(GestureTypeName type, bool isSystemGesture) : type_(type), isSystemGesture_(isSystemGesture) {} + explicit GestureInfo(std::string tag) : tag_(std::move(tag)) {} + explicit GestureInfo(GestureTypeName type) : type_(type) {} + explicit GestureInfo(bool isSystemGesture) : isSystemGesture_(isSystemGesture) {} + ~GestureInfo() override = default; + + std::optional GetTag() const + { + return tag_; + } + + GestureTypeName GetType() const + { + return type_; + } + + bool IsSystemGesture() const + { + return isSystemGesture_; + } + + void SetTag(std::string tag) + { + tag_ = std::move(tag); + } + + void SetType(GestureTypeName type) + { + type_ = type; + } + + void SetIsSystemGesture(bool isSystemGesture) + { + isSystemGesture_ = isSystemGesture; + } + +private: + std::optional tag_; + GestureTypeName type_; + bool isSystemGesture_ = false; +}; +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_GESTURE_INFO_H diff --git a/frameworks/core/components_ng/event/target_component.cpp b/frameworks/core/components_ng/event/target_component.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f8f904c35931332e925869ec0e287b999ce7ee9f --- /dev/null +++ b/frameworks/core/components_ng/event/target_component.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "core/components_ng/event/target_component.h" + +#include "core/components_ng/base/ui_node.h" +#include "core/components_ng/gestures/recognizers/gesture_recognizer.h" + +namespace OHOS::Ace::NG { + +void TargetComponent::SetNode(const WeakPtr& uiNode) +{ + node_ = uiNode; +} + +void TargetComponent::SetNodeLinkGesture(const RefPtr& nodeLinkGesture) +{ + nodeLinkGesture_ = nodeLinkGesture; +} + +void TargetComponent::SetNodeGesture(const RefPtr& nodeGesture) +{ + nodeGesture_ = nodeGesture; +} + +WeakPtr TargetComponent::GetUINode() +{ + return node_; +} + +void TargetComponent::AddChild(const RefPtr& child) +{ + targetComponentChildren_.emplace_back(child); +} + +void TargetComponent::AddPath(int32_t pathId) +{ + path_.emplace(pathId); +} + +void TargetComponent::SetSourceType(SourceType sourceType) +{ + sourceType_ = sourceType; +} + +void TargetComponent::SetOnGestureJudgeBegin(GestureJudgeFunc&& onGestureJudgeBegin) +{ + onGestureJudgeBegin_ = std::move(onGestureJudgeBegin); +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/event/target_component.h b/frameworks/core/components_ng/event/target_component.h new file mode 100644 index 0000000000000000000000000000000000000000..8e8fe32abe92b87c6e8d80dcc0150f0b2b089b2e --- /dev/null +++ b/frameworks/core/components_ng/event/target_component.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_TARGET_COMPONENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_TARGET_COMPONENT_H + +#include +#include +#include + +#include "base/memory/ace_type.h" +#include "base/memory/referenced.h" +#include "core/components/common/layout/constants.h" +#include "core/components_ng/event/gesture_info.h" +#include "core/components_ng/gestures/base_gesture_event.h" +#include "core/event/ace_events.h" + +namespace OHOS::Ace::NG { + +class UINode; +class NGGestureRecognizer; +using GestureJudgeFunc = std::function& gestureInfo, const std::shared_ptr& info)>; + +class ACE_EXPORT TargetComponent : public virtual AceType { + DECLARE_ACE_TYPE(TargetComponent, AceType); + +public: + TargetComponent() = default; + ~TargetComponent() override = default; + + void SetNode(const WeakPtr& uiNode); + + void SetNodeLinkGesture(const RefPtr& nodeLinkGesture); + + void SetNodeGesture(const RefPtr& nodeGesture); + + WeakPtr GetUINode(); + + void AddChild(const RefPtr& child); + + void AddPath(int32_t pathId); + + void SetSourceType(SourceType sourceType); + + void SetOnGestureJudgeBegin(GestureJudgeFunc&& onGestureJudgeBegin); + + GestureJudgeFunc GetOnGestureJudgeBeginCallback() + { + return onGestureJudgeBegin_; + } + +private: + WeakPtr node_; + RefPtr nodeLinkGesture_; + RefPtr nodeGesture_; + std::list> targetComponentChildren_; + GestureJudgeFunc onGestureJudgeBegin_; + std::set path_; + SourceType sourceType_ = SourceType::TOUCH; +}; +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_TARGET_COMPONENT_H diff --git a/frameworks/core/components_ng/gestures/base_gesture_event.h b/frameworks/core/components_ng/gestures/base_gesture_event.h new file mode 100644 index 0000000000000000000000000000000000000000..902c8f7714cba1db228fe438b091e13ec7674171 --- /dev/null +++ b/frameworks/core/components_ng/gestures/base_gesture_event.h @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_BASE_GESTURE_EVENT_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_BASE_GESTURE_EVENT_H + +#include "core/gestures/gesture_info.h" + +namespace OHOS::Ace { + +class ACE_EXPORT BaseGestureEvent : public BaseEventInfo { + DECLARE_RELATIONSHIP_OF_CLASSES(BaseGestureEvent, BaseEventInfo); + +public: + BaseGestureEvent() : BaseEventInfo("baseGesture") {} + ~BaseGestureEvent() override = default; + + const std::list& GetFingerList() const + { + return fingerList_; + } + + void SetFingerList(const std::list& fingerList) + { + fingerList_ = fingerList; + } + +protected: + std::list fingerList_; +}; + +class ACE_EXPORT TapGestureEvent : public BaseGestureEvent { + DECLARE_RELATIONSHIP_OF_CLASSES(TapGestureEvent, BaseGestureEvent); + +public: + TapGestureEvent() = default; + ~TapGestureEvent() override = default; +}; + +class ACE_EXPORT LongPressGestureEvent : public BaseGestureEvent { + DECLARE_RELATIONSHIP_OF_CLASSES(LongPressGestureEvent, BaseGestureEvent); + +public: + LongPressGestureEvent() = default; + ~LongPressGestureEvent() override = default; + + void SetRepeat(bool repeat) + { + repeat_ = repeat; + } + + bool GetRepeat() const + { + return repeat_; + } + +private: + bool repeat_ = false; +}; + +class ACE_EXPORT PanGestureEvent : public BaseGestureEvent { + DECLARE_RELATIONSHIP_OF_CLASSES(PanGestureEvent, BaseGestureEvent); + +public: + PanGestureEvent() = default; + ~PanGestureEvent() override = default; + + void SetOffsetX(double offsetX) + { + offsetX_ = offsetX; + } + + double GetOffsetX() const + { + return offsetX_; + } + + void SetOffsetY(double offsetY) + { + offsetY_ = offsetY; + } + + double GetOffsetY() const + { + return offsetY_; + } + + void SetVelocity(const Velocity& velocity) + { + velocity_ = velocity; + } + + const Velocity& GetVelocity() const + { + return velocity_; + } + + void SetMainVelocity(double mainVelocity) + { + mainVelocity_ = mainVelocity; + } + + double GetMainVelocity() const + { + return mainVelocity_; + } + +private: + double offsetX_ = 0.0; + double offsetY_ = 0.0; + Velocity velocity_; + double mainVelocity_ = 0.0; +}; + +class ACE_EXPORT PinchGestureEvent : public BaseGestureEvent { + DECLARE_RELATIONSHIP_OF_CLASSES(PinchGestureEvent, BaseGestureEvent); + +public: + PinchGestureEvent() = default; + ~PinchGestureEvent() override = default; + + void SetScale(double scale) + { + scale_ = scale; + } + + double GetScale() const + { + return scale_; + } + + const Offset& GetPinchCenter() const + { + return pinchCenter_; + } + + PinchGestureEvent& SetPinchCenter(const Offset& pinchCenter) + { + pinchCenter_ = pinchCenter; + return *this; + } + +private: + double scale_ = 1.0; + Offset pinchCenter_; +}; + +class ACE_EXPORT RotationGestureEvent : public BaseGestureEvent { + DECLARE_RELATIONSHIP_OF_CLASSES(RotationGestureEvent, BaseGestureEvent); + +public: + RotationGestureEvent() = default; + ~RotationGestureEvent() override = default; + + void SetAngle(double angle) + { + angle_ = angle; + } + + double GetAngle() const + { + return angle_; + } + +private: + double angle_ = 0.0; +}; + +class ACE_EXPORT SwipeGestureEvent : public BaseGestureEvent { + DECLARE_RELATIONSHIP_OF_CLASSES(SwipeGestureEvent, BaseGestureEvent); + +public: + SwipeGestureEvent() = default; + ~SwipeGestureEvent() override = default; + + void SetAngle(double angle) + { + angle_ = angle; + } + + double GetAngle() const + { + return angle_; + } + + void SetSpeed(double speed) + { + speed_ = speed; + } + + double GetSpeed() const + { + return speed_; + } + +private: + double angle_ = 0.0; + double speed_ = 0.0; +}; +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_BASE_GESTURE_EVENT_H \ No newline at end of file diff --git a/frameworks/core/components_ng/gestures/gesture_group.cpp b/frameworks/core/components_ng/gestures/gesture_group.cpp index 11330a75a215cbf250d341469b4fecbf381dd71a..3e3b78b6fb3877c1bd89c949a0c5755d150deca8 100644 --- a/frameworks/core/components_ng/gestures/gesture_group.cpp +++ b/frameworks/core/components_ng/gestures/gesture_group.cpp @@ -51,6 +51,7 @@ RefPtr GestureGroup::CreateRecognizer() DynamicCast(groupRecognizer)->RemainChildOnResetStatus(); groupRecognizer->SetPriority(priority_); groupRecognizer->SetPriorityMask(gestureMask_); + groupRecognizer->SetGestureInfo(gestureInfo_); return groupRecognizer; } diff --git a/frameworks/core/components_ng/gestures/gesture_info.h b/frameworks/core/components_ng/gestures/gesture_info.h index 38547131edc8a07641b897b46fcdeb79b1e66ff5..d04796f478636c287deac8b8f43092bea0a065bd 100644 --- a/frameworks/core/components_ng/gestures/gesture_info.h +++ b/frameworks/core/components_ng/gestures/gesture_info.h @@ -17,19 +17,11 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_GESTURE_INFO_H #include -#include #include -#include -#include -#include "base/geometry/offset.h" -#include "base/geometry/point.h" -#include "base/image/pixel_map.h" #include "base/memory/ace_type.h" -#include "base/utils/event_callback.h" #include "base/utils/macros.h" -#include "base/utils/type_definition.h" -#include "core/event/ace_events.h" +#include "core/components_ng/event/gesture_info.h" #include "core/gestures/gesture_event.h" #include "core/gestures/velocity.h" #include "core/gestures/velocity_tracker.h" @@ -85,6 +77,15 @@ public: return gestureMask_; } + void SetTag(std::string tag) + { + if (gestureInfo_) { + gestureInfo_->SetTag(std::move(tag)); + } else { + gestureInfo_ = MakeRefPtr(tag); + } + } + virtual RefPtr CreateRecognizer() = 0; protected: @@ -96,6 +97,7 @@ protected: std::unique_ptr onActionUpdateId_; std::unique_ptr onActionEndId_; std::unique_ptr onActionCancelId_; + RefPtr gestureInfo_; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/gestures/long_press_gesture.cpp b/frameworks/core/components_ng/gestures/long_press_gesture.cpp index 18fee4263e24416b100420170f21c1e3768aaba6..bf627b74a8f8f8396bef2e6e520d97dfb0a13c6b 100644 --- a/frameworks/core/components_ng/gestures/long_press_gesture.cpp +++ b/frameworks/core/components_ng/gestures/long_press_gesture.cpp @@ -26,6 +26,7 @@ RefPtr LongPressGesture::CreateRecognizer() duration_, fingers_, repeat_, isForDrag_, isDisableMouseLeft_); longPressRecognizer->SetPriority(priority_); longPressRecognizer->SetPriorityMask(gestureMask_); + longPressRecognizer->SetGestureInfo(gestureInfo_); if (onActionId_) { longPressRecognizer->SetOnAction(*onActionId_); } diff --git a/frameworks/core/components_ng/gestures/long_press_gesture.h b/frameworks/core/components_ng/gestures/long_press_gesture.h index 22ec15bb0c1f6acef3785ca3889968e6a0a5ed43..57332078a4df58a6c6c4a37fa57a059b59128428 100644 --- a/frameworks/core/components_ng/gestures/long_press_gesture.h +++ b/frameworks/core/components_ng/gestures/long_press_gesture.h @@ -35,7 +35,13 @@ public: int32_t fingers, bool repeat, int32_t duration, bool isForDrag = false, bool isDisableMouseLeft = false) : Gesture(fingers), repeat_(repeat), duration_(duration), isForDrag_(isForDrag), isDisableMouseLeft_(isDisableMouseLeft) - {} + { + if (gestureInfo_) { + gestureInfo_->SetType(GestureTypeName::LONG_PRESS_GESTURE); + } else { + gestureInfo_ = MakeRefPtr(GestureTypeName::LONG_PRESS_GESTURE); + } + } ~LongPressGesture() override = default; protected: diff --git a/frameworks/core/components_ng/gestures/pan_gesture.cpp b/frameworks/core/components_ng/gestures/pan_gesture.cpp index 99b59568fd034ec6c5bdd1390c393092200ec636..b8da810828984534260f0873825b11d8b074e091 100644 --- a/frameworks/core/components_ng/gestures/pan_gesture.cpp +++ b/frameworks/core/components_ng/gestures/pan_gesture.cpp @@ -50,6 +50,7 @@ RefPtr PanGesture::CreateRecognizer() panRecognizer->SetPriority(priority_); panRecognizer->SetPriorityMask(gestureMask_); + panRecognizer->SetGestureInfo(gestureInfo_); return panRecognizer; } diff --git a/frameworks/core/components_ng/gestures/pan_gesture.h b/frameworks/core/components_ng/gestures/pan_gesture.h index cb8da6bbc361f578a577fad8f724c8cdc2ecd218..bc780cfb89ba497921da0d2f008ece3c39fc69f5 100644 --- a/frameworks/core/components_ng/gestures/pan_gesture.h +++ b/frameworks/core/components_ng/gestures/pan_gesture.h @@ -36,10 +36,20 @@ public: fingers_ = fingers; direction_ = direction; distance_ = distance; + if (gestureInfo_) { + gestureInfo_->SetType(GestureTypeName::PAN_GESTURE); + } else { + gestureInfo_ = MakeRefPtr(GestureTypeName::PAN_GESTURE); + } }; explicit PanGesture(RefPtr panGestureOption) { panGestureOption_ = panGestureOption; + if (gestureInfo_) { + gestureInfo_->SetType(GestureTypeName::PAN_GESTURE); + } else { + gestureInfo_ = MakeRefPtr(GestureTypeName::PAN_GESTURE); + } }; ~PanGesture() override = default; diff --git a/frameworks/core/components_ng/gestures/pinch_gesture.cpp b/frameworks/core/components_ng/gestures/pinch_gesture.cpp index 54e0a6fd9fcb410ab8d44891cebb6b286260ccd4..cc406bc53569649573a8f2f75384ba793ccd980e 100644 --- a/frameworks/core/components_ng/gestures/pinch_gesture.cpp +++ b/frameworks/core/components_ng/gestures/pinch_gesture.cpp @@ -48,6 +48,7 @@ RefPtr PinchGesture::CreateRecognizer() pinchRecognizer->SetPriority(priority_); pinchRecognizer->SetPriorityMask(gestureMask_); + pinchRecognizer->SetGestureInfo(gestureInfo_); return pinchRecognizer; } diff --git a/frameworks/core/components_ng/gestures/pinch_gesture.h b/frameworks/core/components_ng/gestures/pinch_gesture.h index 8f34cb03f31ab99984d43e120a708db7418f492f..a202aa74284f1027e2ba65f6013b340752f66408 100644 --- a/frameworks/core/components_ng/gestures/pinch_gesture.h +++ b/frameworks/core/components_ng/gestures/pinch_gesture.h @@ -31,7 +31,14 @@ class ACE_EXPORT PinchGesture : public Gesture { DECLARE_ACE_TYPE(PinchGesture, Gesture); public: - PinchGesture(int32_t fingers, double distance) : Gesture(fingers), distance_(distance) {} + PinchGesture(int32_t fingers, double distance) : Gesture(fingers), distance_(distance) + { + if (gestureInfo_) { + gestureInfo_->SetType(GestureTypeName::PINCH_GESTURE); + } else { + gestureInfo_ = MakeRefPtr(GestureTypeName::PINCH_GESTURE); + } + } ~PinchGesture() override = default; protected: diff --git a/frameworks/core/components_ng/gestures/recognizers/click_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/click_recognizer.cpp index 393b1a917d75e45c04ba9de99740e4c628f3e061..60ddb1db50021165e67f92d071fea6eaa26d3c96 100644 --- a/frameworks/core/components_ng/gestures/recognizers/click_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/click_recognizer.cpp @@ -19,6 +19,8 @@ #include "base/log/log.h" #include "base/ressched/ressched_report.h" #include "base/utils/utils.h" +#include "core/components/common/layout/constants.h" +#include "core/components_ng/gestures/base_gesture_event.h" #include "core/components_ng/gestures/gesture_referee.h" #include "core/components_ng/gestures/recognizers/gesture_recognizer.h" #include "core/components_ng/gestures/recognizers/multi_fingers_recognizer.h" @@ -134,6 +136,7 @@ void ClickRecognizer::HandleTouchDownEvent(const TouchEvent& event) } ++currentTouchPointsNum_; touchPoints_[event.id] = event; + UpdateFingerListInfo(); if (fingers_ > currentTouchPointsNum_) { // waiting for multi-finger press DeadlineTimer(fingerDeadlineTimer_, MULTI_FINGER_TIMEOUT); @@ -165,6 +168,7 @@ void ClickRecognizer::HandleTouchUpEvent(const TouchEvent& event) } InitGlobalValue(event.sourceType); touchPoints_[event.id] = event; + UpdateFingerListInfo(); --currentTouchPointsNum_; // Check whether multi-finger taps are completed in count_ times if (equalsToFingers_ && (currentTouchPointsNum_ == 0)) { @@ -176,11 +180,16 @@ void ClickRecognizer::HandleTouchUpEvent(const TouchEvent& event) if (tappedCount_ == count_) { TAG_LOGI(AceLogTag::ACE_GESTURE, "This gesture is click, try to accept it"); time_ = event.time; - if (useCatchMode_) { - Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); - } else { + if (!useCatchMode_) { OnAccepted(); + return; } + auto onGestureJudgeBeginResult = TriggerGestureJudgeCallback(); + if (onGestureJudgeBeginResult == GestureJudgeResult::REJECT) { + Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); + return; + } + Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); return; } equalsToFingers_ = false; @@ -211,6 +220,7 @@ void ClickRecognizer::HandleTouchMoveEvent(const TouchEvent& event) TAG_LOGI(AceLogTag::ACE_GESTURE, "This gesture is out of offset, try to reject it"); Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); } + UpdateFingerListInfo(); } void ClickRecognizer::HandleTouchCancelEvent(const TouchEvent& event) @@ -307,6 +317,35 @@ void ClickRecognizer::SendCallbackMsg(const std::unique_ptr& o } } +GestureJudgeResult ClickRecognizer::TriggerGestureJudgeCallback() +{ + auto targetComponent = GetTargetComponent(); + CHECK_NULL_RETURN(targetComponent, GestureJudgeResult::CONTINUE); + auto callback = targetComponent->GetOnGestureJudgeBeginCallback(); + CHECK_NULL_RETURN(callback, GestureJudgeResult::CONTINUE); + auto info = std::make_shared(); + info->SetTimeStamp(time_); + info->SetFingerList(fingerList_); + TouchEvent touchPoint = {}; + if (!touchPoints_.empty()) { + touchPoint = touchPoints_.begin()->second; + } + info->SetSourceDevice(deviceType_); + info->SetTarget(GetEventTarget().value_or(EventTarget())); + if (recognizerTarget_.has_value()) { + info->SetTarget(recognizerTarget_.value()); + } + info->SetForce(touchPoint.force); + if (touchPoint.tiltX.has_value()) { + info->SetTiltX(touchPoint.tiltX.value()); + } + if (touchPoint.tiltY.has_value()) { + info->SetTiltY(touchPoint.tiltY.value()); + } + info->SetSourceTool(touchPoint.sourceTool); + return callback(gestureInfo_, info); +} + bool ClickRecognizer::ReconcileFrom(const RefPtr& recognizer) { RefPtr curr = AceType::DynamicCast(recognizer); @@ -328,7 +367,7 @@ RefPtr ClickRecognizer::Dump() const { RefPtr info = NGGestureRecognizer::Dump(); std::stringstream oss; - oss << "count: " << count_ << ", " + oss << "count: " << count_ << ", " << "fingers: " << fingers_; info->customInfo = oss.str(); return info; diff --git a/frameworks/core/components_ng/gestures/recognizers/click_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/click_recognizer.h index b5b1af87e9dc5606b25fb0d6e3b651c3345587d8..3f4bd07f65913b00893befb56ba13dd29b691f94 100644 --- a/frameworks/core/components_ng/gestures/recognizers/click_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/click_recognizer.h @@ -100,6 +100,7 @@ private: Offset ComputeFocusPoint(); void SendCallbackMsg(const std::unique_ptr& callback); + GestureJudgeResult TriggerGestureJudgeCallback(); bool ExceedSlop(); void InitGlobalValue(SourceType deviceId); diff --git a/frameworks/core/components_ng/gestures/recognizers/gesture_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/gesture_recognizer.h index 4b127f3874bcd04178425ceb158a5b8bb5ea35e9..c950cc31729070499ab406c4ee9642f37dc6ed6d 100644 --- a/frameworks/core/components_ng/gestures/recognizers/gesture_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/gesture_recognizer.h @@ -19,6 +19,7 @@ #include #include "base/memory/referenced.h" +#include "core/components_ng/event/gesture_info.h" #include "core/components_ng/gestures/gesture_info.h" #include "core/components_ng/gestures/gesture_referee.h" #include "core/event/axis_event.h" @@ -238,6 +239,26 @@ public: void AddGestureProcedure(const std::string& procedure) const; // for recognizer group void AddGestureProcedure(const TouchEvent& point, const RefPtr& recognizer) const; + + void SetGestureInfo(const RefPtr& gestureInfo) + { + gestureInfo_ = gestureInfo; + } + + RefPtr GetGestureInfo() + { + return gestureInfo_; + } + + void SetIsSystemGesture(bool isSystemGesture) + { + if (gestureInfo_) { + gestureInfo_->SetIsSystemGesture(isSystemGesture); + } else { + gestureInfo_ = MakeRefPtr(isSystemGesture); + } + } + protected: void Adjudicate(const RefPtr& recognizer, GestureDisposal disposal) { @@ -285,6 +306,8 @@ protected: int32_t transId_ = 0; int32_t currentFingers_ = 0; + RefPtr gestureInfo_; + private: WeakPtr gestureGroup_; }; diff --git a/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp index fc38934911c8e15b643e06b1c68997a6f69fe43b..26d1f1b3a98a16c3f5dbf4534f2e2b4ed9c3df4f 100644 --- a/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp @@ -19,13 +19,15 @@ #include "base/thread/frame_trace_adapter.h" #include "base/utils/time_util.h" #include "base/utils/utils.h" +#include "core/components/common/layout/constants.h" +#include "core/components_ng/base/frame_node.h" +#include "core/components_ng/event/gesture_event_hub.h" +#include "core/components_ng/gestures/base_gesture_event.h" #include "core/components_ng/gestures/gesture_referee.h" #include "core/components_ng/gestures/recognizers/gesture_recognizer.h" #include "core/components_ng/gestures/recognizers/multi_fingers_recognizer.h" #include "core/event/ace_events.h" #include "core/pipeline_ng/pipeline_context.h" -#include "core/components_ng/event/gesture_event_hub.h" -#include "core/components_ng/render/render_context.h" namespace OHOS::Ace::NG { namespace { @@ -117,8 +119,8 @@ void LongPressRecognizer::HandleTouchDownEvent(const TouchEvent& event) int64_t currentTimeStamp = GetSysTimestamp(); int64_t eventTimeStamp = static_cast(event.time.time_since_epoch().count()); if (currentTimeStamp > eventTimeStamp) { - TAG_LOGI(AceLogTag::ACE_GESTURE, - "CurrentTimeStamp is larger than eventTimeStamp, need to minus time spent waiting"); + TAG_LOGI( + AceLogTag::ACE_GESTURE, "CurrentTimeStamp is larger than eventTimeStamp, need to minus time spent waiting"); // nanoseconds to millisceond. curDuration = curDuration - static_cast((currentTimeStamp - eventTimeStamp) / (1000 * 1000)); if (curDuration < 0) { @@ -136,6 +138,7 @@ void LongPressRecognizer::HandleTouchDownEvent(const TouchEvent& event) } globalPoint_ = Point(event.x, event.y); touchPoints_[event.id] = event; + UpdateFingerListInfo(); auto pointsCount = static_cast(touchPoints_.size()); if (pointsCount == fingers_) { @@ -182,7 +185,7 @@ void LongPressRecognizer::HandleTouchMoveEvent(const TouchEvent& event) Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); return; } - + UpdateFingerListInfo(); time_ = event.time; } @@ -201,13 +204,32 @@ void LongPressRecognizer::HandleTouchCancelEvent(const TouchEvent& event) void LongPressRecognizer::HandleOverdueDeadline(bool isCatchMode) { - if (refereeState_ == RefereeState::DETECTING) { - if (isCatchMode) { - Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); - } else { - OnAccepted(); + if (refereeState_ != RefereeState::DETECTING) { + return; + } + if (!isCatchMode) { + OnAccepted(); + return; + } + if (gestureInfo_ && gestureInfo_->GetType() == GestureTypeName::DRAG) { + auto dragEventActuator = GetDragEventActuator(); + CHECK_NULL_VOID(dragEventActuator); + if (dragEventActuator->IsDragUserReject()) { + Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); + return; } } + auto onGestureJudgeBeginResult = TriggerGestureJudgeCallback(); + if (onGestureJudgeBeginResult == GestureJudgeResult::REJECT) { + Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); + if (gestureInfo_ && gestureInfo_->GetType() == GestureTypeName::DRAG) { + auto dragEventActuator = GetDragEventActuator(); + CHECK_NULL_VOID(dragEventActuator); + dragEventActuator->SetIsDragUserReject(true); + } + return; + } + Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); } void LongPressRecognizer::DeadlineTimer(int32_t time, bool isCatchMode) @@ -361,7 +383,7 @@ RefPtr LongPressRecognizer::Dump() const { RefPtr info = NGGestureRecognizer::Dump(); std::stringstream oss; - oss << "duration: " << duration_ << ", " + oss << "duration: " << duration_ << ", " << "isForDrag: " << isForDrag_ << ", " << "repeat: " << repeat_ << ", " << "fingers: " << fingers_; @@ -369,4 +391,47 @@ RefPtr LongPressRecognizer::Dump() const return info; } +GestureJudgeResult LongPressRecognizer::TriggerGestureJudgeCallback() +{ + auto targetComponent = GetTargetComponent(); + CHECK_NULL_RETURN(targetComponent, GestureJudgeResult::CONTINUE); + auto callback = targetComponent->GetOnGestureJudgeBeginCallback(); + CHECK_NULL_RETURN(callback, GestureJudgeResult::CONTINUE); + auto info = std::make_shared(); + info->SetTimeStamp(time_); + info->SetRepeat(repeat_); + info->SetFingerList(fingerList_); + TouchEvent trackPoint = {}; + if (!touchPoints_.empty()) { + trackPoint = touchPoints_.begin()->second; + } + info->SetSourceDevice(deviceType_); + info->SetTarget(GetEventTarget().value_or(EventTarget())); + if (recognizerTarget_.has_value()) { + info->SetTarget(recognizerTarget_.value()); + } + info->SetForce(trackPoint.force); + if (trackPoint.tiltX.has_value()) { + info->SetTiltX(trackPoint.tiltX.value()); + } + if (trackPoint.tiltY.has_value()) { + info->SetTiltY(trackPoint.tiltY.value()); + } + info->SetSourceTool(trackPoint.sourceTool); + return callback(gestureInfo_, info); +} + +RefPtr LongPressRecognizer::GetDragEventActuator() +{ + auto targetComponent = GetTargetComponent(); + CHECK_NULL_RETURN(targetComponent, nullptr); + auto uiNode = targetComponent->GetUINode().Upgrade(); + CHECK_NULL_RETURN(uiNode, nullptr); + auto frameNode = AceType::DynamicCast(uiNode); + CHECK_NULL_RETURN(frameNode, nullptr); + auto gestureEventHub = frameNode->GetOrCreateGestureEventHub(); + CHECK_NULL_RETURN(gestureEventHub, nullptr); + return gestureEventHub->GetDragEventActuator(); +} + } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.h index a8239f2d87d1cda1d4f94dd52170425250e9638c..fa80f402d02317e8c8fb5ed72b92a7e7dbaa89a3 100644 --- a/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.h @@ -20,6 +20,8 @@ #include "base/thread/cancelable_callback.h" #include "core/accessibility/accessibility_utils.h" +#include "core/components_ng/event/drag_event.h" +#include "core/components_ng/gestures/recognizers/gesture_recognizer.h" #include "core/components_ng/gestures/recognizers/multi_fingers_recognizer.h" namespace OHOS::Ace::NG { @@ -104,9 +106,11 @@ private: void DoRepeat(); void StartRepeatTimer(); void SendCallbackMsg(const std::unique_ptr& callback, bool isRepeat); + GestureJudgeResult TriggerGestureJudgeCallback(); void OnResetStatus() override; double ConvertPxToVp(double offset) const; void ThumbnailTimer(int32_t time); + RefPtr GetDragEventActuator(); WeakPtr gestureHub_; CancelableCallback thumbnailTimer_; diff --git a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp index 2c0be64fdbaf91516c5c6d320d6a5f4da52dd254..d16b6050371a0fa5051190caa161e2152ff27260 100644 --- a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp @@ -20,6 +20,7 @@ #include "base/log/log_wrapper.h" #include "base/ressched/ressched_report.h" #include "base/utils/utils.h" +#include "core/components_ng/gestures/base_gesture_event.h" #include "core/components_ng/gestures/gesture_referee.h" #include "core/components_ng/gestures/recognizers/gesture_recognizer.h" #include "core/components_ng/gestures/recognizers/multi_fingers_recognizer.h" @@ -287,7 +288,9 @@ void PanRecognizer::HandleTouchMoveEvent(const TouchEvent& event) if (refereeState_ == RefereeState::DETECTING) { auto result = IsPanGestureAccept(); if (result == GestureAcceptResult::ACCEPT) { - Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); + if (HandlePanAccept()) { + return; + } } else if (result == GestureAcceptResult::REJECT) { Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); } @@ -358,7 +361,9 @@ void PanRecognizer::HandleTouchMoveEvent(const AxisEvent& event) if (refereeState_ == RefereeState::DETECTING) { auto result = IsPanGestureAccept(); if (result == GestureAcceptResult::ACCEPT) { - Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); + if (HandlePanAccept()) { + return; + } } else if (result == GestureAcceptResult::REJECT) { Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); } @@ -373,6 +378,30 @@ void PanRecognizer::HandleTouchMoveEvent(const AxisEvent& event) } } +bool PanRecognizer::HandlePanAccept() +{ + if (gestureInfo_ && gestureInfo_->GetType() == GestureTypeName::DRAG) { + auto dragEventActuator = GetDragEventActuator(); + CHECK_NULL_RETURN(dragEventActuator, true); + if (dragEventActuator->IsDragUserReject()) { + Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); + return true; + } + } + auto onGestureJudgeBeginResult = TriggerGestureJudgeCallback(); + if (onGestureJudgeBeginResult == GestureJudgeResult::REJECT) { + Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); + if (gestureInfo_ && gestureInfo_->GetType() == GestureTypeName::DRAG) { + auto dragEventActuator = GetDragEventActuator(); + CHECK_NULL_RETURN(dragEventActuator, true); + dragEventActuator->SetIsDragUserReject(true); + } + return true; + } + Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); + return false; +} + void PanRecognizer::HandleTouchCancelEvent(const TouchEvent& /*event*/) { if ((refereeState_ != RefereeState::SUCCEED) && (refereeState_ != RefereeState::FAIL)) { @@ -539,6 +568,46 @@ void PanRecognizer::SendCallbackMsg(const std::unique_ptr& cal } } +GestureJudgeResult PanRecognizer::TriggerGestureJudgeCallback() +{ + auto targetComponent = GetTargetComponent(); + CHECK_NULL_RETURN(targetComponent, GestureJudgeResult::CONTINUE); + auto callback = targetComponent->GetOnGestureJudgeBeginCallback(); + CHECK_NULL_RETURN(callback, GestureJudgeResult::CONTINUE); + auto info = std::make_shared(); + info->SetTimeStamp(time_); + UpdateFingerListInfo(); + info->SetFingerList(fingerList_); + info->SetOffsetX(averageDistance_.GetX()); + info->SetOffsetY(averageDistance_.GetY()); + TouchEvent touchPoint = {}; + if (!touchPoints_.empty()) { + touchPoint = touchPoints_.begin()->second; + } + info->SetSourceDevice(deviceType_); + if (inputEventType_ == InputEventType::AXIS) { + info->SetVelocity(Velocity()); + info->SetMainVelocity(0.0); + info->SetSourceTool(lastAxisEvent_.sourceTool); + } else { + info->SetVelocity(velocityTracker_.GetVelocity()); + info->SetMainVelocity(velocityTracker_.GetMainAxisVelocity()); + info->SetSourceTool(lastTouchEvent_.sourceTool); + } + info->SetTarget(GetEventTarget().value_or(EventTarget())); + if (recognizerTarget_.has_value()) { + info->SetTarget(recognizerTarget_.value()); + } + info->SetForce(lastTouchEvent_.force); + if (lastTouchEvent_.tiltX.has_value()) { + info->SetTiltX(lastTouchEvent_.tiltX.value()); + } + if (lastTouchEvent_.tiltY.has_value()) { + info->SetTiltY(lastTouchEvent_.tiltY.value()); + } + return callback(gestureInfo_, info); +} + bool PanRecognizer::ReconcileFrom(const RefPtr& recognizer) { RefPtr curr = AceType::DynamicCast(recognizer); @@ -628,4 +697,17 @@ RefPtr PanRecognizer::Dump() const return info; } +RefPtr PanRecognizer::GetDragEventActuator() +{ + auto targetComponent = GetTargetComponent(); + CHECK_NULL_RETURN(targetComponent, nullptr); + auto uiNode = targetComponent->GetUINode().Upgrade(); + CHECK_NULL_RETURN(uiNode, nullptr); + auto frameNode = AceType::DynamicCast(uiNode); + CHECK_NULL_RETURN(frameNode, nullptr); + auto gestureEventHub = frameNode->GetOrCreateGestureEventHub(); + CHECK_NULL_RETURN(gestureEventHub, nullptr); + return gestureEventHub->GetDragEventActuator(); +} + } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h index 10dd6c1efa511cf7de9b17503ad8057966b426c0..8662ac0df100b095185b3e0c30e5f1ee9bf0fc15 100644 --- a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.h @@ -17,6 +17,7 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_RECOGNIZERS_PAN_RECOGNIZER_H #include +#include "core/components_ng/event/drag_event.h" #include "core/components_ng/gestures/recognizers/multi_fingers_recognizer.h" namespace OHOS::Ace::NG { @@ -99,10 +100,13 @@ private: void UpdateTouchPointInVelocityTracker(const TouchEvent& event, bool end = false); void SendCallbackMsg(const std::unique_ptr& callback); + GestureJudgeResult TriggerGestureJudgeCallback(); void ChangeFingers(int32_t fingers); void ChangeDirection(const PanDirection& direction); void ChangeDistance(double distance); double GetMainAxisDelta(); + RefPtr GetDragEventActuator(); + bool HandlePanAccept(); void OnResetStatus() override; void OnSucceedCancel() override; diff --git a/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.cpp index ff69c82c77b24d059b8236f600c2ce8ed7e32617..14b79abe3c4a529822d3be3235d952e69251e2f1 100644 --- a/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.cpp @@ -18,6 +18,7 @@ #include "base/geometry/offset.h" #include "base/log/log.h" #include "base/ressched/ressched_report.h" +#include "core/components_ng/gestures/base_gesture_event.h" #include "core/components_ng/gestures/gesture_referee.h" #include "core/components_ng/gestures/recognizers/gesture_recognizer.h" #include "core/components_ng/gestures/recognizers/multi_fingers_recognizer.h" @@ -163,6 +164,11 @@ void PinchRecognizer::HandleTouchMoveEvent(const TouchEvent& event) if (refereeState_ == RefereeState::DETECTING) { if (GreatOrEqual(fabs(currentDev_ - initialDev_), distance_)) { scale_ = currentDev_ / initialDev_; + auto onGestureJudgeBeginResult = TriggerGestureJudgeCallback(); + if (onGestureJudgeBeginResult == GestureJudgeResult::REJECT) { + Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); + return; + } Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); } } else if (refereeState_ == RefereeState::SUCCEED) { @@ -216,6 +222,11 @@ void PinchRecognizer::HandleTouchMoveEvent(const AxisEvent& event) } } if (refereeState_ == RefereeState::DETECTING) { + auto onGestureJudgeBeginResult = TriggerGestureJudgeCallback(); + if (onGestureJudgeBeginResult == GestureJudgeResult::REJECT) { + Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); + return; + } Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); } SendCallbackMsg(onActionUpdate_); @@ -332,6 +343,34 @@ void PinchRecognizer::SendCallbackMsg(const std::unique_ptr& c } } +GestureJudgeResult PinchRecognizer::TriggerGestureJudgeCallback() +{ + auto targetComponent = GetTargetComponent(); + CHECK_NULL_RETURN(targetComponent, GestureJudgeResult::CONTINUE); + auto callback = targetComponent->GetOnGestureJudgeBeginCallback(); + CHECK_NULL_RETURN(callback, GestureJudgeResult::CONTINUE); + auto info = std::make_shared(); + info->SetTimeStamp(time_); + UpdateFingerListInfo(); + info->SetFingerList(fingerList_); + info->SetScale(scale_); + info->SetPinchCenter(pinchCenter_); + info->SetSourceDevice(deviceType_); + info->SetTarget(GetEventTarget().value_or(EventTarget())); + if (recognizerTarget_.has_value()) { + info->SetTarget(recognizerTarget_.value()); + } + info->SetForce(lastTouchEvent_.force); + if (lastTouchEvent_.tiltX.has_value()) { + info->SetTiltX(lastTouchEvent_.tiltX.value()); + } + if (lastTouchEvent_.tiltY.has_value()) { + info->SetTiltY(lastTouchEvent_.tiltY.value()); + } + info->SetSourceTool(lastTouchEvent_.sourceTool); + return callback(gestureInfo_, info); +} + bool PinchRecognizer::ReconcileFrom(const RefPtr& recognizer) { RefPtr curr = AceType::DynamicCast(recognizer); diff --git a/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.h index 05aecdd65e2d4883baa9664c562c13febeab8347..7aa4e4148e7f7c9e788a8d92107ffb8a9c07686b 100644 --- a/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/pinch_recognizer.h @@ -49,6 +49,7 @@ private: void OnResetStatus() override; void SendCallbackMsg(const std::unique_ptr& callback); + GestureJudgeResult TriggerGestureJudgeCallback(); Offset ComputePinchCenter(); bool IsCtrlBeingPressed(); diff --git a/frameworks/core/components_ng/gestures/recognizers/recognizer_group.h b/frameworks/core/components_ng/gestures/recognizers/recognizer_group.h index 8d0a6f54c5e6ae43073689ee4d3c172c5bf73bbd..13b3c06fd603419b47b4b2dbb98f9751fec16252 100644 --- a/frameworks/core/components_ng/gestures/recognizers/recognizer_group.h +++ b/frameworks/core/components_ng/gestures/recognizers/recognizer_group.h @@ -123,6 +123,15 @@ public: } } + void SetChildrenTargetComponent(const RefPtr& targetComponent) + { + for (const auto& child : recognizers_) { + if (child) { + child->SetTargetComponent(targetComponent); + } + } + } + protected: void OnBeginGestureReferee(int32_t touchId, bool needUpdateChild = false) override; void OnFinishGestureReferee(int32_t touchId, bool isBlocked = false) override; diff --git a/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.cpp index c58840189339a12d8ac65d521c5f9fb9784741cf..1636d44039be8acb7d538d91d969dc99bec02e96 100644 --- a/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.cpp @@ -17,6 +17,7 @@ #include "base/geometry/offset.h" #include "base/log/log.h" +#include "core/components_ng/gestures/base_gesture_event.h" #include "core/components_ng/gestures/gesture_referee.h" #include "core/components_ng/gestures/recognizers/gesture_recognizer.h" #include "core/components_ng/gestures/recognizers/multi_fingers_recognizer.h" @@ -107,6 +108,11 @@ void RotationRecognizer::HandleTouchMoveEvent(const TouchEvent& event) double diffAngle = fabs((currentAngle_ - initialAngle_)); if (GreatOrEqual(diffAngle, angle_)) { resultAngle_ = ChangeValueRange(currentAngle_ - initialAngle_); + auto onGestureJudgeBeginResult = TriggerGestureJudgeCallback(); + if (onGestureJudgeBeginResult == GestureJudgeResult::REJECT) { + Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); + return; + } Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); } } else if (refereeState_ == RefereeState::SUCCEED) { @@ -199,6 +205,37 @@ void RotationRecognizer::SendCallbackMsg(const std::unique_ptr } } +GestureJudgeResult RotationRecognizer::TriggerGestureJudgeCallback() +{ + auto targetComponent = GetTargetComponent(); + CHECK_NULL_RETURN(targetComponent, GestureJudgeResult::CONTINUE); + auto callback = targetComponent->GetOnGestureJudgeBeginCallback(); + CHECK_NULL_RETURN(callback, GestureJudgeResult::CONTINUE); + auto info = std::make_shared(); + info->SetTimeStamp(time_); + UpdateFingerListInfo(); + info->SetFingerList(fingerList_); + info->SetAngle(resultAngle_); + info->SetSourceDevice(deviceType_); + info->SetTarget(GetEventTarget().value_or(EventTarget())); + if (recognizerTarget_.has_value()) { + info->SetTarget(recognizerTarget_.value()); + } + TouchEvent touchPoint = {}; + if (!touchPoints_.empty()) { + touchPoint = touchPoints_.begin()->second; + } + info->SetForce(touchPoint.force); + if (touchPoint.tiltX.has_value()) { + info->SetTiltX(touchPoint.tiltX.value()); + } + if (touchPoint.tiltY.has_value()) { + info->SetTiltY(touchPoint.tiltY.value()); + } + info->SetSourceTool(touchPoint.sourceTool); + return callback(gestureInfo_, info); +} + bool RotationRecognizer::ReconcileFrom(const RefPtr& recognizer) { RefPtr curr = AceType::DynamicCast(recognizer); diff --git a/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.h index 5f1ac14fa7e7cd90ae0a93ca879d28fb1789f49a..037d4f3f18076b13388201abffc559ce8a47087d 100644 --- a/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/rotation_recognizer.h @@ -44,6 +44,7 @@ private: double ComputeAngle(); void OnResetStatus() override; void SendCallbackMsg(const std::unique_ptr& callback); + GestureJudgeResult TriggerGestureJudgeCallback(); static double ChangeValueRange(double value); double angle_ = 0.0; diff --git a/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp index bc581abc72642fae1df0222f4563e534d2a85edf..fd0e7fa2e9869867aa2d6e9b904e92ae1e129ef4 100644 --- a/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.cpp @@ -22,6 +22,7 @@ #include "base/log/log.h" #include "base/utils/type_definition.h" #include "base/utils/utils.h" +#include "core/components_ng/gestures/base_gesture_event.h" #include "core/components_ng/gestures/gesture_referee.h" #include "core/components_ng/gestures/recognizers/gesture_recognizer.h" #include "core/components_ng/gestures/recognizers/multi_fingers_recognizer.h" @@ -143,11 +144,16 @@ void SwipeRecognizer::HandleTouchUpEvent(const TouchEvent& event) } } else { matchedTouch_.insert(event.id); - if (static_cast(matchedTouch_.size()) == fingers_) { - Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); - } else { + if (static_cast(matchedTouch_.size()) != fingers_) { Adjudicate(AceType::Claim(this), GestureDisposal::PENDING); + return; } + auto onGestureJudgeBeginResult = TriggerGestureJudgeCallback(); + if (onGestureJudgeBeginResult == GestureJudgeResult::REJECT) { + Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); + return; + } + Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); } } } @@ -179,6 +185,11 @@ void SwipeRecognizer::HandleTouchUpEvent(const AxisEvent& event) if (resultSpeed_ < speed_) { Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); } else { + auto onGestureJudgeBeginResult = TriggerGestureJudgeCallback(); + if (onGestureJudgeBeginResult == GestureJudgeResult::REJECT) { + Adjudicate(AceType::Claim(this), GestureDisposal::REJECT); + return; + } Adjudicate(AceType::Claim(this), GestureDisposal::ACCEPT); } } @@ -336,6 +347,40 @@ void SwipeRecognizer::SendCallbackMsg(const std::unique_ptr& c } } +GestureJudgeResult SwipeRecognizer::TriggerGestureJudgeCallback() +{ + auto targetComponent = GetTargetComponent(); + CHECK_NULL_RETURN(targetComponent, GestureJudgeResult::CONTINUE); + auto callback = targetComponent->GetOnGestureJudgeBeginCallback(); + CHECK_NULL_RETURN(callback, GestureJudgeResult::CONTINUE); + auto info = std::make_shared(); + info->SetTimeStamp(time_); + UpdateFingerListInfo(); + info->SetFingerList(fingerList_); + if (deviceType_ == SourceType::MOUSE) { + info->SetSpeed(0.0); + } else { + info->SetSpeed(resultSpeed_); + } + info->SetSourceDevice(deviceType_); + info->SetTarget(GetEventTarget().value_or(EventTarget())); + if (recognizerTarget_.has_value()) { + info->SetTarget(recognizerTarget_.value()); + } + info->SetForce(lastTouchEvent_.force); + if (lastTouchEvent_.tiltX.has_value()) { + info->SetTiltX(lastTouchEvent_.tiltX.value()); + } + if (lastTouchEvent_.tiltY.has_value()) { + info->SetTiltY(lastTouchEvent_.tiltY.value()); + } + info->SetSourceTool(lastTouchEvent_.sourceTool); + if (prevAngle_) { + info->SetAngle(prevAngle_.value()); + } + return callback(gestureInfo_, info); +} + bool SwipeRecognizer::ReconcileFrom(const RefPtr& recognizer) { RefPtr curr = AceType::DynamicCast(recognizer); diff --git a/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.h b/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.h index cdf77c2bb2b7413830b22474e4f66416eaefbbcb..028cfb9ca3e792f1ec17aa8484e02512f7894c6b 100644 --- a/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.h +++ b/frameworks/core/components_ng/gestures/recognizers/swipe_recognizer.h @@ -68,6 +68,7 @@ private: void OnResetStatus() override; void SendCallbackMsg(const std::unique_ptr& callback); + GestureJudgeResult TriggerGestureJudgeCallback(); bool CheckAngle(double angle); diff --git a/frameworks/core/components_ng/gestures/rotation_gesture.cpp b/frameworks/core/components_ng/gestures/rotation_gesture.cpp index 0ccb4f2b64eedef4fe2a1f8972040970330f5ef4..93017a27405535484f6c2297f831b820c5c26383 100644 --- a/frameworks/core/components_ng/gestures/rotation_gesture.cpp +++ b/frameworks/core/components_ng/gestures/rotation_gesture.cpp @@ -29,6 +29,11 @@ RotationGesture::RotationGesture(int32_t fingers, double angle): Gesture(fingers } else { angle_ = angle; } + if (gestureInfo_) { + gestureInfo_->SetType(GestureTypeName::ROTATION_GESTURE); + } else { + gestureInfo_ = MakeRefPtr(GestureTypeName::ROTATION_GESTURE); + } } RefPtr RotationGesture::CreateRecognizer() { @@ -51,6 +56,7 @@ RefPtr RotationGesture::CreateRecognizer() rotationRecognizer->SetPriority(priority_); rotationRecognizer->SetPriorityMask(gestureMask_); + rotationRecognizer->SetGestureInfo(gestureInfo_); return rotationRecognizer; } diff --git a/frameworks/core/components_ng/gestures/rotation_gesture.h b/frameworks/core/components_ng/gestures/rotation_gesture.h index f27c21d75032bd7553ee4377731d22143bf6d529..b6485474b5429a428ef74851c1de462798d48a73 100644 --- a/frameworks/core/components_ng/gestures/rotation_gesture.h +++ b/frameworks/core/components_ng/gestures/rotation_gesture.h @@ -31,7 +31,14 @@ class ACE_EXPORT RotationGesture : public Gesture { DECLARE_ACE_TYPE(RotationGesture, Gesture); public: - RotationGesture() = default; + RotationGesture() + { + if (gestureInfo_) { + gestureInfo_->SetType(GestureTypeName::ROTATION_GESTURE); + } else { + gestureInfo_ = MakeRefPtr(GestureTypeName::ROTATION_GESTURE); + } + } RotationGesture(int32_t fingers, double angle); ~RotationGesture() override = default; diff --git a/frameworks/core/components_ng/gestures/swipe_gesture.cpp b/frameworks/core/components_ng/gestures/swipe_gesture.cpp index d3f7cc929ce7bc0514fad61e03efab67e52338a8..20ea047784068ad7df91c61a9edf2973a9bacc2a 100644 --- a/frameworks/core/components_ng/gestures/swipe_gesture.cpp +++ b/frameworks/core/components_ng/gestures/swipe_gesture.cpp @@ -35,6 +35,7 @@ RefPtr SwipeGesture::CreateRecognizer() swipeRecognizer->SetPriority(priority_); swipeRecognizer->SetPriorityMask(gestureMask_); + swipeRecognizer->SetGestureInfo(gestureInfo_); return swipeRecognizer; } diff --git a/frameworks/core/components_ng/gestures/swipe_gesture.h b/frameworks/core/components_ng/gestures/swipe_gesture.h index 5eadbd8b646325250243864063ce8763819e9b72..63f1fae550be88fe7d15032ef9fd06dfca36c7a2 100644 --- a/frameworks/core/components_ng/gestures/swipe_gesture.h +++ b/frameworks/core/components_ng/gestures/swipe_gesture.h @@ -32,6 +32,11 @@ public: fingers_ = fingers; direction_ = direction; speed_ = speed; + if (gestureInfo_) { + gestureInfo_->SetType(GestureTypeName::SWIPE_GESTURE); + } else { + gestureInfo_ = MakeRefPtr(GestureTypeName::SWIPE_GESTURE); + } }; ~SwipeGesture() override = default; diff --git a/frameworks/core/components_ng/gestures/tap_gesture.cpp b/frameworks/core/components_ng/gestures/tap_gesture.cpp index bdc4a7299e291c7ed8ae1ee5b1d2c7fd0cb7cec2..eb065e74678c935920623bdb02915ee2affc5791 100644 --- a/frameworks/core/components_ng/gestures/tap_gesture.cpp +++ b/frameworks/core/components_ng/gestures/tap_gesture.cpp @@ -28,6 +28,7 @@ RefPtr TapGesture::CreateRecognizer() clickRecognizer->SetPriority(priority_); clickRecognizer->SetPriorityMask(gestureMask_); + clickRecognizer->SetGestureInfo(gestureInfo_); return clickRecognizer; } diff --git a/frameworks/core/components_ng/gestures/tap_gesture.h b/frameworks/core/components_ng/gestures/tap_gesture.h index 32dcdf258def1036a6b209f2d48ee1ca9e42d7bd..546bb37dd7b81ac6f492e3036e546d4a1fbc721c 100644 --- a/frameworks/core/components_ng/gestures/tap_gesture.h +++ b/frameworks/core/components_ng/gestures/tap_gesture.h @@ -1,17 +1,17 @@ /* -* Copyright (c) 2022 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_TAP_GESTURE_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_GESTURES_TAP_GESTURE_H @@ -23,6 +23,8 @@ #include "base/geometry/offset.h" #include "base/memory/ace_type.h" #include "base/utils/macros.h" +#include "core/components/common/layout/constants.h" +#include "core/components_ng/event/gesture_info.h" #include "core/components_ng/gestures/gesture_info.h" namespace OHOS::Ace::NG { @@ -31,8 +33,22 @@ class ACE_EXPORT TapGesture : public Gesture { DECLARE_ACE_TYPE(TapGesture, Gesture); public: - TapGesture() = default; - TapGesture(int32_t count, int32_t fingers) : Gesture(fingers), count_(count) {} + TapGesture() + { + if (gestureInfo_) { + gestureInfo_->SetType(GestureTypeName::TAP_GESTURE); + } else { + gestureInfo_ = MakeRefPtr(GestureTypeName::TAP_GESTURE); + } + } + TapGesture(int32_t count, int32_t fingers) : Gesture(fingers), count_(count) + { + if (gestureInfo_) { + gestureInfo_->SetType(GestureTypeName::TAP_GESTURE); + } else { + gestureInfo_ = MakeRefPtr(GestureTypeName::TAP_GESTURE); + } + } ~TapGesture() override = default; protected: diff --git a/frameworks/core/components_ng/pattern/gesture/gesture_model.h b/frameworks/core/components_ng/pattern/gesture/gesture_model.h index 4352f958caa1d6dfb25a6c9f17eab93c9b6f2bae..4abe22087d2d82e1347844ba8985b7a8e23fc885 100644 --- a/frameworks/core/components_ng/pattern/gesture/gesture_model.h +++ b/frameworks/core/components_ng/pattern/gesture/gesture_model.h @@ -17,9 +17,10 @@ #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GESTURE_GESTURE_MODEL_H #include +#include -#include "core/gestures/gesture_processor.h" #include "core/gestures/gesture_info.h" +#include "core/gestures/gesture_processor.h" #include "frameworks/base/memory/referenced.h" namespace OHOS::Ace { @@ -34,6 +35,7 @@ public: virtual void Pop() = 0; 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; private: static std::unique_ptr instance_; diff --git a/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.cpp b/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.cpp index cac91f96b2e48cdf3ba39800fc8c609fca7da5f3..7d859cceed41a5cac3a13c331e6cd19aeb7fce10 100644 --- a/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.cpp @@ -71,6 +71,15 @@ void GestureModelNG::Pop() gestureProcessor->PopGestureNG(); } +void GestureModelNG::SetTag(const std::string& tag) +{ + RefPtr gestureProcessor; + gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor(); + auto gesture = gestureProcessor->TopGestureNG(); + CHECK_NULL_VOID(gesture); + gesture->SetTag(tag); +} + void TapGestureModelNG::Create(int32_t countNum, int32_t fingersNum) { RefPtr gestureProcessor; diff --git a/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.h b/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.h index ebb134ce74a026f840e723a0823d554d6e06d6aa..26041bd5d1145c0bcd62df2cdcc5bbec107282c7 100644 --- a/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.h +++ b/frameworks/core/components_ng/pattern/gesture/gesture_model_ng.h @@ -27,6 +27,7 @@ public: void Pop() override; void SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter) override; void SetOnActionFunc(const GestureEventFunc& gestureEventFunc, const Ace::GestureEventAction& action) override; + void SetTag(const std::string& tag) override; }; class ACE_EXPORT TapGestureModelNG : public OHOS::Ace::TapGestureModel { diff --git a/frameworks/core/event/touch_event.h b/frameworks/core/event/touch_event.h index f9116d27c0dace7a13e0178f3cbd65ac0def0fa9..2aba869706eaba609c2e9af1bfbf17dfc6f06a12 100755 --- a/frameworks/core/event/touch_event.h +++ b/frameworks/core/event/touch_event.h @@ -21,6 +21,7 @@ #include "base/geometry/offset.h" #include "base/memory/ace_type.h" #include "base/utils/time_util.h" +#include "core/components_ng/event/target_component.h" #include "core/event/ace_events.h" #include "core/event/axis_event.h" @@ -639,6 +640,16 @@ public: return info; } + void SetTargetComponent(const RefPtr& targetComponent) + { + targetComponent_ = targetComponent; + } + + RefPtr GetTargetComponent() + { + return targetComponent_; + } + protected: Offset coordinateOffset_; GetEventTargetImpl getEventTargetImpl_; @@ -649,6 +660,7 @@ protected: int32_t nodeId_ = -1; WeakPtr node_ = nullptr; Axis direction_ = Axis::NONE; + RefPtr targetComponent_; }; using TouchTestResult = std::list>; diff --git a/frameworks/core/gestures/gesture_info.h b/frameworks/core/gestures/gesture_info.h index 319cbf58cd5696752f8e8dc9df1ed31be8e9f801..3cac908bb666ace64e58dcc0ab63fbef1a7b74e7 100644 --- a/frameworks/core/gestures/gesture_info.h +++ b/frameworks/core/gestures/gesture_info.h @@ -31,7 +31,6 @@ #include "base/utils/type_definition.h" #include "core/event/ace_events.h" #include "core/gestures/velocity.h" -#include "core/gestures/velocity_tracker.h" namespace OHOS::Ace { diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 3222bcf877a13a83937d07da074421897ee4a53f..f26b0cc10cf606442a06d4b6fa44e7111ac71933 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -136,6 +136,7 @@ ohos_source_set("ace_components_event") { "$ace_root/frameworks/core/components_ng/event/pan_event.cpp", "$ace_root/frameworks/core/components_ng/event/scrollable_event.cpp", "$ace_root/frameworks/core/components_ng/event/state_style_manager.cpp", + "$ace_root/frameworks/core/components_ng/event/target_component.cpp", "$ace_root/frameworks/core/components_ng/event/touch_event.cpp", ] configs = [ ":ace_unittest_config" ] diff --git a/test/unittest/core/common/ace_engine/BUILD.gn b/test/unittest/core/common/ace_engine/BUILD.gn index 419f0391146e2dcf7452155f50405248418741a3..2a1199b1a9154a5da64613e8d33d7c42651b7023 100644 --- a/test/unittest/core/common/ace_engine/BUILD.gn +++ b/test/unittest/core/common/ace_engine/BUILD.gn @@ -45,6 +45,7 @@ ohos_unittest("ace_engine_special_test") { "$ace_root/frameworks/core/components_ng/event/input_event.cpp", "$ace_root/frameworks/core/components_ng/event/input_event_hub.cpp", "$ace_root/frameworks/core/components_ng/event/state_style_manager.cpp", + "$ace_root/frameworks/core/components_ng/event/target_component.cpp", "$ace_root/frameworks/core/components_ng/event/touch_event.cpp", "$ace_root/frameworks/core/components_ng/gestures/gesture_referee.cpp", "$ace_root/frameworks/core/components_ng/gestures/recognizers/exclusive_recognizer.cpp", diff --git a/test/unittest/core/event/gesture_event_hub_test_ng.cpp b/test/unittest/core/event/gesture_event_hub_test_ng.cpp index 15e0e3656ae2e5df8d74bcfcfa8e8490be6e69d2..3dd02d2dfb4c49de30875df70b4a4e511aaf3eab 100644 --- a/test/unittest/core/event/gesture_event_hub_test_ng.cpp +++ b/test/unittest/core/event/gesture_event_hub_test_ng.cpp @@ -142,7 +142,7 @@ HWTEST_F(GestureEventHubTestNg, GestureEventHubTest002, TestSize.Level1) TouchTestResult innerTargets; TouchTestResult finalResult; auto flag = gestureEventHub->ProcessTouchTestHit( - COORDINATE_OFFSET, touchRestrict, innerTargets, finalResult, TOUCH_ID, PointF()); + COORDINATE_OFFSET, touchRestrict, innerTargets, finalResult, TOUCH_ID, PointF(), nullptr); EXPECT_FALSE(flag); auto sizeOfInnerTargets = static_cast(innerTargets.size()); auto sizeOfFinalResult = static_cast(finalResult.size()); @@ -172,7 +172,7 @@ HWTEST_F(GestureEventHubTestNg, GestureEventHubTest002, TestSize.Level1) * @tc.expected: ProcessTouchTestHit return false, innerTargets & finalResult have one element */ flag = gestureEventHub->ProcessTouchTestHit( - COORDINATE_OFFSET, touchRestrict, innerTargets, finalResult, TOUCH_ID, PointF()); + COORDINATE_OFFSET, touchRestrict, innerTargets, finalResult, TOUCH_ID, PointF(), nullptr); EXPECT_FALSE(flag); sizeOfInnerTargets = static_cast(innerTargets.size()); sizeOfFinalResult = static_cast(finalResult.size()); @@ -701,7 +701,8 @@ HWTEST_F(GestureEventHubTestNg, GestureEventHubTest010, TestSize.Level1) EXPECT_EQ(static_cast(gestureEventHub->externalExclusiveRecognizer_.size()), 1); EXPECT_EQ(static_cast(gestureEventHub->externalParallelRecognizer_.size()), 1); - gestureEventHub->ProcessTouchTestHierarchy(COORDINATE_OFFSET, touchRestrict, innerTargets, finalResult, TOUCH_ID); + gestureEventHub->ProcessTouchTestHierarchy( + COORDINATE_OFFSET, touchRestrict, innerTargets, finalResult, TOUCH_ID, nullptr); EXPECT_TRUE(finalResult.empty()); /** @@ -728,7 +729,8 @@ HWTEST_F(GestureEventHubTestNg, GestureEventHubTest010, TestSize.Level1) gestureEventHub->gestureHierarchy_.emplace_back(clickRecognizer3); gestureEventHub->gestureHierarchy_.emplace_back(clickRecognizer5); - gestureEventHub->ProcessTouchTestHierarchy(COORDINATE_OFFSET, touchRestrict, innerTargets, finalResult, TOUCH_ID); + gestureEventHub->ProcessTouchTestHierarchy( + COORDINATE_OFFSET, touchRestrict, innerTargets, finalResult, TOUCH_ID, nullptr); auto sizeOfFinalResult = static_cast(finalResult.size()); EXPECT_EQ(sizeOfFinalResult, 1); @@ -736,28 +738,32 @@ HWTEST_F(GestureEventHubTestNg, GestureEventHubTest010, TestSize.Level1) std::list> innerTargets2; innerTargets2.emplace_back(clickRecognizer); innerTargets2.emplace_back(clickRecognizer6); - gestureEventHub->ProcessTouchTestHierarchy(COORDINATE_OFFSET, touchRestrict, innerTargets2, finalResult, TOUCH_ID); + gestureEventHub->ProcessTouchTestHierarchy( + COORDINATE_OFFSET, touchRestrict, innerTargets2, finalResult, TOUCH_ID, nullptr); sizeOfFinalResult = static_cast(finalResult.size()); EXPECT_EQ(sizeOfFinalResult, 2); std::list> innerTargets3; innerTargets3.emplace_back(clickRecognizer); innerTargets3.emplace_back(clickRecognizer6); - gestureEventHub->ProcessTouchTestHierarchy(COORDINATE_OFFSET, touchRestrict, innerTargets3, finalResult, TOUCH_ID); + gestureEventHub->ProcessTouchTestHierarchy( + COORDINATE_OFFSET, touchRestrict, innerTargets3, finalResult, TOUCH_ID, nullptr); sizeOfFinalResult = static_cast(finalResult.size()); EXPECT_EQ(sizeOfFinalResult, 3); std::list> innerTargets4; gestureEventHub->gestureHierarchy_.clear(); gestureEventHub->gestureHierarchy_.emplace_back(clickRecognizer4); - gestureEventHub->ProcessTouchTestHierarchy(COORDINATE_OFFSET, touchRestrict, innerTargets4, finalResult, TOUCH_ID); + gestureEventHub->ProcessTouchTestHierarchy( + COORDINATE_OFFSET, touchRestrict, innerTargets4, finalResult, TOUCH_ID, nullptr); sizeOfFinalResult = static_cast(finalResult.size()); EXPECT_EQ(sizeOfFinalResult, 4); std::list> innerTargets5; gestureEventHub->gestureHierarchy_.clear(); gestureEventHub->gestureHierarchy_.emplace_back(clickRecognizer); - gestureEventHub->ProcessTouchTestHierarchy(COORDINATE_OFFSET, touchRestrict, innerTargets5, finalResult, TOUCH_ID); + gestureEventHub->ProcessTouchTestHierarchy( + COORDINATE_OFFSET, touchRestrict, innerTargets5, finalResult, TOUCH_ID, nullptr); sizeOfFinalResult = static_cast(finalResult.size()); EXPECT_EQ(sizeOfFinalResult, 5); } @@ -918,7 +924,7 @@ HWTEST_F(GestureEventHubTestNg, GestureEventHubTest013, TestSize.Level1) guestureEventHub->dragEventActuator_ = AceType::MakeRefPtr( AceType::WeakClaim(AceType::RawPtr(guestureEventHub)), panDirection, 1, 50.0f); auto result = guestureEventHub->ProcessTouchTestHit( - coordinateOffset, touchRestrict, innerTargets, finalResult, 2, localPoint); + coordinateOffset, touchRestrict, innerTargets, finalResult, 2, localPoint, nullptr); EXPECT_FALSE(result); } diff --git a/test/unittest/core/image_provider/BUILD.gn b/test/unittest/core/image_provider/BUILD.gn index e424e0bb3ca2769d610dd13df099867f481c0582..93fea15a19f242ebd7cd6e59202697777b34843b 100644 --- a/test/unittest/core/image_provider/BUILD.gn +++ b/test/unittest/core/image_provider/BUILD.gn @@ -44,6 +44,7 @@ ohos_unittest("image_provider_test_ng") { "$ace_root/frameworks/core/components_ng/event/input_event_hub.cpp", "$ace_root/frameworks/core/components_ng/event/pan_event.cpp", "$ace_root/frameworks/core/components_ng/event/state_style_manager.cpp", + "$ace_root/frameworks/core/components_ng/event/target_component.cpp", "$ace_root/frameworks/core/components_ng/event/touch_event.cpp", "$ace_root/frameworks/core/components_ng/gestures/gesture_referee.cpp", "$ace_root/frameworks/core/components_ng/gestures/recognizers/click_recognizer.cpp", diff --git a/test/unittest/core/pattern/plugin/BUILD.gn b/test/unittest/core/pattern/plugin/BUILD.gn index 19895ee883afbcfea50ee39ba65202fb52451f91..779984b104e08ea716e48fb8bfa2f294700173bf 100644 --- a/test/unittest/core/pattern/plugin/BUILD.gn +++ b/test/unittest/core/pattern/plugin/BUILD.gn @@ -56,6 +56,7 @@ ohos_unittest("plugin_pattern_test_ng") { "$ace_root/frameworks/core/components_ng/event/input_event_hub.cpp", "$ace_root/frameworks/core/components_ng/event/pan_event.cpp", "$ace_root/frameworks/core/components_ng/event/state_style_manager.cpp", + "$ace_root/frameworks/core/components_ng/event/target_component.cpp", "$ace_root/frameworks/core/components_ng/event/touch_event.cpp", "$ace_root/frameworks/core/components_ng/gestures/gesture_referee.cpp", "$ace_root/frameworks/core/components_ng/gestures/recognizers/click_recognizer.cpp", diff --git a/test/unittest/core/pipeline/BUILD.gn b/test/unittest/core/pipeline/BUILD.gn index 3ae9853d1e834ac2827e6fb77a8904736131268b..a82c2ba2e32dbcca254fb8d3e76e9a55fb53b5ba 100644 --- a/test/unittest/core/pipeline/BUILD.gn +++ b/test/unittest/core/pipeline/BUILD.gn @@ -90,6 +90,7 @@ ohos_unittest("pipeline_context_test_ng") { "$ace_root/frameworks/core/components_ng/event/pan_event.cpp", "$ace_root/frameworks/core/components_ng/event/scrollable_event.cpp", "$ace_root/frameworks/core/components_ng/event/state_style_manager.cpp", + "$ace_root/frameworks/core/components_ng/event/target_component.cpp", "$ace_root/frameworks/core/components_ng/event/touch_event.cpp", "$ace_root/frameworks/core/components_ng/gestures/gesture_group.cpp", "$ace_root/frameworks/core/components_ng/gestures/gesture_referee.cpp",