mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2025-01-10 02:41:41 +00:00
gesture decoupling
Signed-off-by: quguiren <quguiren@huawei.com>
This commit is contained in:
parent
425bdf8931
commit
294493c799
@ -288,6 +288,7 @@ template("declarative_js_engine") {
|
||||
"jsview/models/flex_model_impl.cpp",
|
||||
"jsview/models/for_each_model_impl.cpp",
|
||||
"jsview/models/gauge_model_impl.cpp",
|
||||
"jsview/models/gesture_model_impl.cpp",
|
||||
"jsview/models/grid_col_model_impl.cpp",
|
||||
"jsview/models/grid_container_model_impl.cpp",
|
||||
"jsview/models/grid_item_model_impl.cpp",
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-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
|
||||
@ -15,34 +15,204 @@
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_gesture.h"
|
||||
|
||||
#include "bridge/declarative_frontend/jsview/models/gesture_model_impl.h"
|
||||
#include "core/components_ng/pattern/gesture/gesture_model_ng.h"
|
||||
#include "frameworks/base/log/ace_scoring_log.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.h"
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h"
|
||||
#include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
|
||||
#include "frameworks/core/components/gesture_listener/gesture_component.h"
|
||||
#include "frameworks/core/components_ng/base/view_stack_processor.h"
|
||||
#include "frameworks/core/components_ng/gestures/gesture_group.h"
|
||||
#include "frameworks/core/components_ng/gestures/long_press_gesture.h"
|
||||
#include "frameworks/core/components_ng/gestures/pan_gesture.h"
|
||||
#include "frameworks/core/components_ng/gestures/pinch_gesture.h"
|
||||
#include "frameworks/core/components_ng/gestures/recognizers/exclusive_recognizer.h"
|
||||
#include "frameworks/core/components_ng/gestures/recognizers/parallel_recognizer.h"
|
||||
#include "frameworks/core/components_ng/gestures/rotation_gesture.h"
|
||||
#include "frameworks/core/components_ng/gestures/swipe_gesture.h"
|
||||
#include "frameworks/core/components_ng/gestures/tap_gesture.h"
|
||||
#include "frameworks/core/gestures/exclusive_recognizer.h"
|
||||
#include "frameworks/core/gestures/gesture_group.h"
|
||||
#include "frameworks/core/gestures/long_press_gesture.h"
|
||||
#include "frameworks/core/gestures/pan_gesture.h"
|
||||
#include "frameworks/core/gestures/parallel_recognizer.h"
|
||||
#include "frameworks/core/gestures/pinch_gesture.h"
|
||||
#include "frameworks/core/gestures/rotation_gesture.h"
|
||||
#include "frameworks/core/gestures/slide_gesture.h"
|
||||
#include "frameworks/core/gestures/tap_gesture.h"
|
||||
#include "frameworks/core/gestures/timeout_gesture.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
namespace OHOS::Ace {
|
||||
std::unique_ptr<GestureModel> GestureModel::instance_ = nullptr;
|
||||
std::mutex GestureModel::mutex_;
|
||||
GestureModel* GestureModel::GetInstance()
|
||||
{
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!instance_) {
|
||||
#ifdef NG_BUILD
|
||||
instance_.reset(new NG::GestureModelNG());
|
||||
#else
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
instance_.reset(new NG::GestureModelNG());
|
||||
} else {
|
||||
instance_.reset(new Framework::GestureModelImpl());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<TapGestureModel> TapGestureModel::instance_ = nullptr;
|
||||
std::mutex TapGestureModel::mutex_;
|
||||
TapGestureModel* TapGestureModel::GetInstance()
|
||||
{
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!instance_) {
|
||||
#ifdef NG_BUILD
|
||||
instance_.reset(new NG::TapGestureModelNG());
|
||||
#else
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
instance_.reset(new NG::TapGestureModelNG());
|
||||
} else {
|
||||
instance_.reset(new Framework::TapGestureModelImpl());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<LongPressGestureModel> LongPressGestureModel::instance_ = nullptr;
|
||||
std::mutex LongPressGestureModel::mutex_;
|
||||
LongPressGestureModel* LongPressGestureModel::GetInstance()
|
||||
{
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!instance_) {
|
||||
#ifdef NG_BUILD
|
||||
instance_.reset(new NG::LongPressGestureModelNG());
|
||||
#else
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
instance_.reset(new NG::LongPressGestureModelNG());
|
||||
} else {
|
||||
instance_.reset(new Framework::LongPressGestureModelImpl());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<PanGestureModel> PanGestureModel::instance_ = nullptr;
|
||||
std::mutex PanGestureModel::mutex_;
|
||||
PanGestureModel* PanGestureModel::GetInstance()
|
||||
{
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!instance_) {
|
||||
#ifdef NG_BUILD
|
||||
instance_.reset(new NG::PanGestureModelNG());
|
||||
#else
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
instance_.reset(new NG::PanGestureModelNG());
|
||||
} else {
|
||||
instance_.reset(new Framework::PanGestureModelImpl());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<SwipeGestureModel> SwipeGestureModel::instance_ = nullptr;
|
||||
std::mutex SwipeGestureModel::mutex_;
|
||||
SwipeGestureModel* SwipeGestureModel::GetInstance()
|
||||
{
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!instance_) {
|
||||
#ifdef NG_BUILD
|
||||
instance_.reset(new NG::SwipeGestureModelNG());
|
||||
#else
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
instance_.reset(new NG::SwipeGestureModelNG());
|
||||
} else {
|
||||
instance_.reset(new Framework::SwipeGestureModelImpl());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<PinchGestureModel> PinchGestureModel::instance_ = nullptr;
|
||||
std::mutex PinchGestureModel::mutex_;
|
||||
PinchGestureModel* PinchGestureModel::GetInstance()
|
||||
{
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!instance_) {
|
||||
#ifdef NG_BUILD
|
||||
instance_.reset(new NG::PinchGestureModelNG());
|
||||
#else
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
instance_.reset(new NG::PinchGestureModelNG());
|
||||
} else {
|
||||
instance_.reset(new Framework::PinchGestureModelImpl());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<RotationGestureModel> RotationGestureModel::instance_ = nullptr;
|
||||
std::mutex RotationGestureModel::mutex_;
|
||||
RotationGestureModel* RotationGestureModel::GetInstance()
|
||||
{
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!instance_) {
|
||||
#ifdef NG_BUILD
|
||||
instance_.reset(new NG::RotationGestureModelNG());
|
||||
#else
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
instance_.reset(new NG::RotationGestureModelNG());
|
||||
} else {
|
||||
instance_.reset(new Framework::RotationGestureModelImpl());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<GestureGroupModel> GestureGroupModel::instance_ = nullptr;
|
||||
std::mutex GestureGroupModel::mutex_;
|
||||
GestureGroupModel* GestureGroupModel::GetInstance()
|
||||
{
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!instance_) {
|
||||
#ifdef NG_BUILD
|
||||
instance_.reset(new NG::GestureGroupModelNG());
|
||||
#else
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
instance_.reset(new NG::GestureGroupModelNG());
|
||||
} else {
|
||||
instance_.reset(new Framework::GestureGroupModelImpl());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return instance_.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<TimeoutGestureModel> TimeoutGestureModel::instance_ = nullptr;
|
||||
std::mutex TimeoutGestureModel::mutex_;
|
||||
TimeoutGestureModel* TimeoutGestureModel::GetInstance()
|
||||
{
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!instance_) {
|
||||
#ifdef NG_BUILD
|
||||
instance_.reset(new NG::TimeoutGestureModelNG());
|
||||
#else
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
instance_.reset(new NG::TimeoutGestureModelNG());
|
||||
} else {
|
||||
instance_.reset(new Framework::TimeoutGestureModelImpl());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return instance_.get();
|
||||
}
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
namespace {
|
||||
constexpr int32_t DEFAULT_TAP_FINGER = 1;
|
||||
constexpr int32_t DEFAULT_TAP_COUNT = 1;
|
||||
@ -71,79 +241,29 @@ constexpr char ROTATION_ANGLE[] = "angle";
|
||||
void JSGesture::Create(const JSCallbackInfo& info)
|
||||
{
|
||||
LOGD("JS gesture create");
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
} else {
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
}
|
||||
|
||||
GesturePriority priority = GesturePriority::Low;
|
||||
int32_t priorityNum = 0;
|
||||
if (info.Length() > 0 && info[0]->IsNumber()) {
|
||||
int32_t priorityNum = info[0]->ToNumber<int32_t>();
|
||||
if (priorityNum > static_cast<int32_t>(GesturePriority::Begin) &&
|
||||
priorityNum < static_cast<int32_t>(GesturePriority::End)) {
|
||||
priority = static_cast<GesturePriority>(priorityNum);
|
||||
}
|
||||
priorityNum = info[0]->ToNumber<int32_t>();
|
||||
}
|
||||
gestureProcessor->SetPriority(priority);
|
||||
|
||||
GestureMask gestureMask = GestureMask::Normal;
|
||||
int32_t gestureMaskNum = 0;
|
||||
if (info.Length() > 1 && info[1]->IsNumber()) {
|
||||
int32_t gestureMaskNum = info[1]->ToNumber<int32_t>();
|
||||
if (gestureMaskNum > static_cast<int32_t>(GestureMask::Begin) &&
|
||||
gestureMaskNum < static_cast<int32_t>(GestureMask::End)) {
|
||||
gestureMask = static_cast<GestureMask>(gestureMaskNum);
|
||||
}
|
||||
gestureMaskNum = info[1]->ToNumber<int32_t>();
|
||||
}
|
||||
gestureProcessor->SetGestureMask(gestureMask);
|
||||
|
||||
GestureModel::GetInstance()->Create(priorityNum, gestureMaskNum);
|
||||
}
|
||||
|
||||
void JSGesture::Finish()
|
||||
{
|
||||
LOGD("JS gesture finish");
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
NG::ViewStackProcessor::GetInstance()->ResetGestureProcessor();
|
||||
|
||||
auto gesture = gestureProcessor->FinishGestureNG();
|
||||
if (!gesture) {
|
||||
LOGE("gesture is not exist when component finish");
|
||||
return;
|
||||
}
|
||||
gesture->SetGestureMask(gestureProcessor->GetGestureMask());
|
||||
gesture->SetPriority(gestureProcessor->GetPriority());
|
||||
auto gestureEventHub = NG::ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
|
||||
if (gestureEventHub) {
|
||||
gestureEventHub->AddGesture(gesture);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = gestureProcessor->FinishGesture();
|
||||
if (!gesture) {
|
||||
LOGE("gesture is not exist when component finish");
|
||||
return;
|
||||
}
|
||||
gesture->SetGestureMask(gestureProcessor->GetGestureMask());
|
||||
gesture->SetPriority(gestureProcessor->GetPriority());
|
||||
auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
|
||||
boxComponent->AddGesture(gestureProcessor->GetPriority(), gesture);
|
||||
GestureModel::GetInstance()->Finish();
|
||||
}
|
||||
|
||||
void JSGesture::Pop()
|
||||
{
|
||||
LOGD("JS gesture pop");
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
gestureProcessor->PopGestureNG();
|
||||
} else {
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
gestureProcessor->PopGesture();
|
||||
};
|
||||
GestureModel::GetInstance()->Pop();
|
||||
}
|
||||
|
||||
void JSTapGesture::Create(const JSCallbackInfo& args)
|
||||
@ -167,16 +287,7 @@ void JSTapGesture::Create(const JSCallbackInfo& args)
|
||||
}
|
||||
|
||||
LOGD("JS Tap gesture created with count %{public}d, fingers %{public}d", countNum, fingersNum);
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::TapGesture>(countNum, fingersNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
} else {
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<TapGesture>(countNum, fingersNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
TapGestureModel::GetInstance()->Create(countNum, fingersNum);
|
||||
}
|
||||
|
||||
void JSLongPressGesture::Create(const JSCallbackInfo& args)
|
||||
@ -204,16 +315,7 @@ void JSLongPressGesture::Create(const JSCallbackInfo& args)
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::LongPressGesture>(fingersNum, repeatResult, durationNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
} else {
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<LongPressGesture>(fingersNum, repeatResult, durationNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
LongPressGestureModel::GetInstance()->Create(fingersNum, repeatResult, durationNum);
|
||||
}
|
||||
|
||||
void JSPanGesture::Create(const JSCallbackInfo& args)
|
||||
@ -222,38 +324,18 @@ void JSPanGesture::Create(const JSCallbackInfo& args)
|
||||
int32_t fingersNum = DEFAULT_PAN_FINGER;
|
||||
double distanceNum = DEFAULT_PAN_DISTANCE;
|
||||
PanDirection panDirection;
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
if (args.Length() <= 0 || !args[0]->IsObject()) {
|
||||
auto gesture = AceType::MakeRefPtr<NG::PanGesture>(fingersNum, panDirection, distanceNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
if (args.Length() <= 0 || !args[0]->IsObject()) {
|
||||
auto gesture = AceType::MakeRefPtr<PanGesture>(fingersNum, panDirection, distanceNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
return;
|
||||
}
|
||||
if (args.Length() <= 0 || !args[0]->IsObject()) {
|
||||
PanGestureModel::GetInstance()->Create(fingersNum, panDirection, distanceNum);
|
||||
return;
|
||||
}
|
||||
|
||||
JSRef<JSObject> obj = JSRef<JSObject>::Cast(args[0]);
|
||||
JSPanGestureOption* panGestureOption = obj->Unwrap<JSPanGestureOption>();
|
||||
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
if (panGestureOption != nullptr) {
|
||||
auto gesture = AceType::MakeRefPtr<NG::PanGesture>(panGestureOption->GetPanGestureOption());
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (panGestureOption != nullptr) {
|
||||
auto gesture = AceType::MakeRefPtr<PanGesture>(panGestureOption->GetPanGestureOption());
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
return;
|
||||
}
|
||||
if (panGestureOption != nullptr) {
|
||||
RefPtr<PanGestureOption> refPanGestureOption = panGestureOption->GetPanGestureOption();
|
||||
PanGestureModel::GetInstance()->SetPanGestureOption(refPanGestureOption);
|
||||
return;
|
||||
}
|
||||
|
||||
JSRef<JSVal> fingers = obj->GetProperty(GESTURE_FINGERS);
|
||||
@ -276,13 +358,7 @@ void JSPanGesture::Create(const JSCallbackInfo& args)
|
||||
}
|
||||
}
|
||||
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
auto gesture = AceType::MakeRefPtr<NG::PanGesture>(fingersNum, panDirection, distanceNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
} else {
|
||||
auto gesture = AceType::MakeRefPtr<PanGesture>(fingersNum, panDirection, distanceNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
PanGestureModel::GetInstance()->Create(fingersNum, panDirection, distanceNum);
|
||||
}
|
||||
|
||||
void JSSwipeGesture::Create(const JSCallbackInfo& args)
|
||||
@ -291,22 +367,11 @@ void JSSwipeGesture::Create(const JSCallbackInfo& args)
|
||||
int32_t fingersNum = DEFAULT_SLIDE_FINGER;
|
||||
double speedNum = DEFAULT_SLIDE_SPEED;
|
||||
SwipeDirection slideDirection;
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
if (args.Length() <= 0 || !args[0]->IsObject()) {
|
||||
auto gesture = AceType::MakeRefPtr<NG::SwipeGesture>(fingersNum, slideDirection, speedNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
if (args.Length() <= 0 || !args[0]->IsObject()) {
|
||||
auto gesture = AceType::MakeRefPtr<SwipeGesture>(fingersNum, slideDirection, speedNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if (args.Length() <= 0 || !args[0]->IsObject()) {
|
||||
SwipeGestureModel::GetInstance()->Create(fingersNum, slideDirection, speedNum);
|
||||
return;
|
||||
}
|
||||
|
||||
JSRef<JSObject> obj = JSRef<JSObject>::Cast(args[0]);
|
||||
JSRef<JSVal> fingers = obj->GetProperty(GESTURE_FINGERS);
|
||||
@ -329,13 +394,7 @@ void JSSwipeGesture::Create(const JSCallbackInfo& args)
|
||||
}
|
||||
}
|
||||
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
auto gesture = AceType::MakeRefPtr<NG::SwipeGesture>(fingersNum, slideDirection, speedNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
} else {
|
||||
auto gesture = AceType::MakeRefPtr<SwipeGesture>(fingersNum, slideDirection, speedNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
SwipeGestureModel::GetInstance()->Create(fingersNum, slideDirection, speedNum);
|
||||
}
|
||||
|
||||
void JSPinchGesture::Create(const JSCallbackInfo& args)
|
||||
@ -358,16 +417,7 @@ void JSPinchGesture::Create(const JSCallbackInfo& args)
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::PinchGesture>(fingersNum, distanceNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
} else {
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<PinchGesture>(fingersNum, distanceNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
};
|
||||
PinchGestureModel::GetInstance()->Create(fingersNum, distanceNum);
|
||||
}
|
||||
|
||||
void JSRotationGesture::Create(const JSCallbackInfo& args)
|
||||
@ -390,16 +440,7 @@ void JSRotationGesture::Create(const JSCallbackInfo& args)
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::RotationGesture>(fingersNum, angleNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
} else {
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<RotationGesture>(fingersNum, angleNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
};
|
||||
RotationGestureModel::GetInstance()->Create(fingersNum, angleNum);
|
||||
}
|
||||
|
||||
void JSGestureGroup::Create(const JSCallbackInfo& args)
|
||||
@ -410,150 +451,58 @@ void JSGestureGroup::Create(const JSCallbackInfo& args)
|
||||
}
|
||||
|
||||
LOGD("Js Gesture group create with mode %{public}d", gestureMode);
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::GestureGroup>(static_cast<GestureMode>(gestureMode));
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
} else {
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<GestureGroup>(static_cast<GestureMode>(gestureMode));
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
};
|
||||
GestureGroupModel::GetInstance()->Create(gestureMode);
|
||||
}
|
||||
|
||||
void JSGesture::JsHandlerOnGestureEvent(JSGestureEvent action, const JSCallbackInfo& args)
|
||||
void JSGesture::JsHandlerOnGestureEvent(Ace::GestureEventAction action, const JSCallbackInfo& args)
|
||||
{
|
||||
if (args.Length() < 1 || !args[0]->IsFunction()) {
|
||||
LOGE("args is not js function");
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = gestureProcessor->TopGestureNG();
|
||||
if (!gesture) {
|
||||
LOGE("top gesture is illegal");
|
||||
return;
|
||||
}
|
||||
RefPtr<JsGestureFunction> handlerFunc = AceType::MakeRefPtr<JsGestureFunction>(JSRef<JSFunc>::Cast(args[0]));
|
||||
|
||||
if (action == JSGestureEvent::CANCEL) {
|
||||
auto onActionCancelFunc = [execCtx = args.GetExecutionContext(), func = std::move(handlerFunc)]() {
|
||||
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
|
||||
auto info = GestureEvent();
|
||||
ACE_SCORING_EVENT("Gesture.onCancel");
|
||||
func->Execute(info);
|
||||
};
|
||||
gesture->SetOnActionCancelId(onActionCancelFunc);
|
||||
return;
|
||||
}
|
||||
|
||||
auto onActionFunc = [execCtx = args.GetExecutionContext(), func = std::move(handlerFunc)](GestureEvent& info) {
|
||||
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
|
||||
ACE_SCORING_EVENT("Gesture.onActionCancel");
|
||||
func->Execute(info);
|
||||
};
|
||||
|
||||
switch (action) {
|
||||
case JSGestureEvent::ACTION:
|
||||
gesture->SetOnActionId(onActionFunc);
|
||||
break;
|
||||
case JSGestureEvent::START:
|
||||
gesture->SetOnActionStartId(onActionFunc);
|
||||
break;
|
||||
case JSGestureEvent::UPDATE:
|
||||
gesture->SetOnActionUpdateId(onActionFunc);
|
||||
break;
|
||||
case JSGestureEvent::END:
|
||||
gesture->SetOnActionEndId(onActionFunc);
|
||||
break;
|
||||
default:
|
||||
LOGW("Unknown gesture action %{public}d", action);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = gestureProcessor->TopGesture();
|
||||
if (!gesture) {
|
||||
LOGE("top gesture is illegal");
|
||||
return;
|
||||
}
|
||||
RefPtr<JsGestureFunction> handlerFunc = AceType::MakeRefPtr<JsGestureFunction>(JSRef<JSFunc>::Cast(args[0]));
|
||||
RefPtr<V2::InspectorFunctionImpl> impl;
|
||||
auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
|
||||
if (!inspector) {
|
||||
LOGE("fail to get inspector for on handle event");
|
||||
return;
|
||||
}
|
||||
impl = inspector->GetInspectorFunctionImpl();
|
||||
|
||||
if (action == JSGestureEvent::CANCEL) {
|
||||
auto onActionCancelFunc = [execCtx = args.GetExecutionContext(), func = std::move(handlerFunc), impl]() {
|
||||
if (action == Ace::GestureEventAction::CANCEL) {
|
||||
auto onActionCancelFunc = [execCtx = args.GetExecutionContext(), func = std::move(handlerFunc)]() {
|
||||
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
|
||||
auto info = GestureEvent();
|
||||
if (impl) {
|
||||
impl->UpdateEventInfo(info);
|
||||
}
|
||||
ACE_SCORING_EVENT("Gesture.onCancel");
|
||||
func->Execute(info);
|
||||
};
|
||||
gesture->SetOnActionCancelId(onActionCancelFunc);
|
||||
GestureModel::GetInstance()->SetOnGestureEvent(onActionCancelFunc);
|
||||
return;
|
||||
}
|
||||
|
||||
auto onActionFunc = [execCtx = args.GetExecutionContext(), func = std::move(handlerFunc), impl](
|
||||
GestureEvent& info) {
|
||||
auto onActionFunc = [execCtx = args.GetExecutionContext(), func = std::move(handlerFunc)](GestureEvent& info) {
|
||||
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
|
||||
if (impl) {
|
||||
impl->UpdateEventInfo(info);
|
||||
}
|
||||
ACE_SCORING_EVENT("Gesture.onActionCancel");
|
||||
func->Execute(info);
|
||||
};
|
||||
|
||||
switch (action) {
|
||||
case JSGestureEvent::ACTION:
|
||||
gesture->SetOnActionId(onActionFunc);
|
||||
break;
|
||||
case JSGestureEvent::START:
|
||||
gesture->SetOnActionStartId(onActionFunc);
|
||||
break;
|
||||
case JSGestureEvent::UPDATE:
|
||||
gesture->SetOnActionUpdateId(onActionFunc);
|
||||
break;
|
||||
case JSGestureEvent::END:
|
||||
gesture->SetOnActionEndId(onActionFunc);
|
||||
break;
|
||||
default:
|
||||
LOGW("Unknown gesture action %{public}d", action);
|
||||
break;
|
||||
}
|
||||
GestureModel::GetInstance()->SetOnActionFunc(onActionFunc, action);
|
||||
}
|
||||
|
||||
void JSGesture::JsHandlerOnAction(const JSCallbackInfo& args)
|
||||
{
|
||||
JSGesture::JsHandlerOnGestureEvent(JSGestureEvent::ACTION, args);
|
||||
JSGesture::JsHandlerOnGestureEvent(Ace::GestureEventAction::ACTION, args);
|
||||
}
|
||||
void JSGesture::JsHandlerOnActionStart(const JSCallbackInfo& args)
|
||||
{
|
||||
JSGesture::JsHandlerOnGestureEvent(JSGestureEvent::START, args);
|
||||
JSGesture::JsHandlerOnGestureEvent(Ace::GestureEventAction::START, args);
|
||||
}
|
||||
void JSGesture::JsHandlerOnActionUpdate(const JSCallbackInfo& args)
|
||||
{
|
||||
JSGesture::JsHandlerOnGestureEvent(JSGestureEvent::UPDATE, args);
|
||||
JSGesture::JsHandlerOnGestureEvent(Ace::GestureEventAction::UPDATE, args);
|
||||
}
|
||||
|
||||
void JSGesture::JsHandlerOnActionEnd(const JSCallbackInfo& args)
|
||||
{
|
||||
JSGesture::JsHandlerOnGestureEvent(JSGestureEvent::END, args);
|
||||
JSGesture::JsHandlerOnGestureEvent(Ace::GestureEventAction::END, args);
|
||||
}
|
||||
void JSGesture::JsHandlerOnActionCancel(const JSCallbackInfo& args)
|
||||
{
|
||||
JSGesture::JsHandlerOnGestureEvent(JSGestureEvent::CANCEL, args);
|
||||
JSGesture::JsHandlerOnGestureEvent(Ace::GestureEventAction::CANCEL, args);
|
||||
}
|
||||
|
||||
void JSPanGestureOption::JSBind(BindingTarget globalObj)
|
||||
@ -720,11 +669,7 @@ void JSTimeoutGesture::Create(const JSCallbackInfo& args)
|
||||
}
|
||||
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
} else {
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
};
|
||||
gestureProcessor = TimeoutGestureModel::GetInstance()->GetGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<TimeoutGesture>(std::chrono::duration<float>(args[0]->ToNumber<float>()));
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
@ -738,5 +683,4 @@ void JSTimeoutGesture::JSBind(BindingTarget globalObj)
|
||||
|
||||
JSClass<JSTimeoutGesture>::Bind<>(globalObj);
|
||||
}
|
||||
|
||||
}; // namespace OHOS::Ace::Framework
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-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
|
||||
@ -16,13 +16,13 @@
|
||||
#ifndef FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JSVIEW_JS_GESTURE_H
|
||||
#define FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JSVIEW_JS_GESTURE_H
|
||||
|
||||
#include "core/components_ng/pattern/gesture/gesture_model.h"
|
||||
#include "core/event/ace_event_handler.h"
|
||||
#include "core/gestures/gesture_info.h"
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_view_abstract.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
class JSGesture : public virtual AceType {
|
||||
DECLARE_ACE_TYPE(JSGesture, AceType);
|
||||
|
||||
@ -43,7 +43,7 @@ public:
|
||||
static void JsHandlerOnActionUpdate(const JSCallbackInfo& args);
|
||||
static void JsHandlerOnActionEnd(const JSCallbackInfo& args);
|
||||
static void JsHandlerOnActionCancel(const JSCallbackInfo& args);
|
||||
static void JsHandlerOnGestureEvent(JSGestureEvent action, const JSCallbackInfo& args);
|
||||
static void JsHandlerOnGestureEvent(Ace::GestureEventAction action, const JSCallbackInfo& args);
|
||||
}; // JSGesture
|
||||
|
||||
class JSTapGesture : public JSGesture {
|
||||
@ -156,6 +156,5 @@ public:
|
||||
static void JSBind(BindingTarget globalObj);
|
||||
};
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
||||
#endif // FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JSVIEW_JS_GESTURE_H
|
||||
|
||||
|
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* 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 "bridge/declarative_frontend/jsview/models/gesture_model_impl.h"
|
||||
|
||||
#include "core/gestures/gesture_group.h"
|
||||
#include "core/gestures/gesture_processor.h"
|
||||
#include "core/gestures/long_press_gesture.h"
|
||||
#include "core/gestures/rotation_gesture.h"
|
||||
#include "core/gestures/pan_gesture.h"
|
||||
#include "core/gestures/pinch_gesture.h"
|
||||
#include "core/gestures/slide_gesture.h"
|
||||
#include "core/gestures/tap_gesture.h"
|
||||
#include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
void GestureModelImpl::Create(int32_t priorityNum, int32_t gestureMaskNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
|
||||
GesturePriority priority = GesturePriority::Low;
|
||||
if (priorityNum > static_cast<int32_t>(GesturePriority::Begin) &&
|
||||
priorityNum < static_cast<int32_t>(GesturePriority::End)) {
|
||||
priority = static_cast<GesturePriority>(priorityNum);
|
||||
}
|
||||
gestureProcessor->SetPriority(priority);
|
||||
|
||||
GestureMask gestureMask = GestureMask::Normal;
|
||||
if (gestureMaskNum > static_cast<int32_t>(GestureMask::Begin) &&
|
||||
gestureMaskNum < static_cast<int32_t>(GestureMask::End)) {
|
||||
gestureMask = static_cast<GestureMask>(gestureMaskNum);
|
||||
}
|
||||
gestureProcessor->SetGestureMask(gestureMask);
|
||||
}
|
||||
|
||||
void GestureModelImpl::Finish()
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = gestureProcessor->FinishGesture();
|
||||
CHECK_NULL_VOID(gesture);
|
||||
gesture->SetGestureMask(gestureProcessor->GetGestureMask());
|
||||
gesture->SetPriority(gestureProcessor->GetPriority());
|
||||
auto boxComponent = ViewStackProcessor::GetInstance()->GetBoxComponent();
|
||||
boxComponent->AddGesture(gestureProcessor->GetPriority(), gesture);
|
||||
}
|
||||
|
||||
void GestureModelImpl::Pop()
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
gestureProcessor->PopGesture();
|
||||
}
|
||||
|
||||
void TapGestureModelImpl::Create(int32_t countNum, int32_t fingersNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<TapGesture>(countNum, fingersNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
|
||||
void LongPressGestureModelImpl::Create(int32_t fingersNum, bool repeatResult, int32_t durationNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<LongPressGesture>(fingersNum, repeatResult, durationNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
|
||||
void PanGestureModelImpl::Create(int32_t fingersNum, const PanDirection& panDirection, double distanceNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<PanGesture>(fingersNum, panDirection, distanceNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
|
||||
void PanGestureModelImpl::SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<PanGesture>(panGestureOption);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
|
||||
void SwipeGestureModelImpl::Create(int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<SwipeGesture>(fingersNum, slideDirection, speedNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
|
||||
void PinchGestureModelImpl::Create(int32_t fingersNum, double distanceNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<PinchGesture>(fingersNum, distanceNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
|
||||
void RotationGestureModelImpl::Create(int32_t fingersNum, double angleNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<RotationGesture>(fingersNum, angleNum);
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
|
||||
void GestureGroupModelImpl::Create(int32_t gestureMode)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = AceType::MakeRefPtr<GestureGroup>(static_cast<GestureMode>(gestureMode));
|
||||
gestureProcessor->PushGesture(gesture);
|
||||
}
|
||||
|
||||
RefPtr<GestureProcessor> TimeoutGestureModelImpl::GetGestureProcessor()
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
return gestureProcessor;
|
||||
}
|
||||
|
||||
void GestureModelImpl::SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = gestureProcessor->TopGesture();
|
||||
CHECK_NULL_VOID(gesture);
|
||||
|
||||
RefPtr<V2::InspectorFunctionImpl> impl;
|
||||
auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
|
||||
CHECK_NULL_VOID(inspector);
|
||||
impl = inspector->GetInspectorFunctionImpl();
|
||||
|
||||
gesture->SetOnActionCancelId([func = std::move(gestureEventNoParameter), impl]() {
|
||||
auto info = GestureEvent();
|
||||
if (impl) {
|
||||
impl->UpdateEventInfo(info);
|
||||
}
|
||||
func();
|
||||
});
|
||||
}
|
||||
|
||||
void GestureModelImpl::SetOnActionFunc(const GestureEventFunc& gestureEventFunc,
|
||||
const Ace::GestureEventAction& action)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = ViewStackProcessor::GetInstance()->GetGestureComponent();
|
||||
auto gesture = gestureProcessor->TopGesture();
|
||||
CHECK_NULL_VOID(gesture);
|
||||
|
||||
RefPtr<V2::InspectorFunctionImpl> impl;
|
||||
auto inspector = ViewStackProcessor::GetInstance()->GetInspectorComposedComponent();
|
||||
CHECK_NULL_VOID(inspector);
|
||||
impl = inspector->GetInspectorFunctionImpl();
|
||||
|
||||
auto onActionFunc = [func = std::move(gestureEventFunc), impl](GestureEvent& info) {
|
||||
if (impl) {
|
||||
impl->UpdateEventInfo(info);
|
||||
}
|
||||
func(info);
|
||||
};
|
||||
|
||||
switch (action) {
|
||||
case Ace::GestureEventAction::ACTION:
|
||||
gesture->SetOnActionId(onActionFunc);
|
||||
break;
|
||||
case Ace::GestureEventAction::START:
|
||||
gesture->SetOnActionStartId(onActionFunc);
|
||||
break;
|
||||
case Ace::GestureEventAction::UPDATE:
|
||||
gesture->SetOnActionUpdateId(onActionFunc);
|
||||
break;
|
||||
case Ace::GestureEventAction::END:
|
||||
gesture->SetOnActionEndId(onActionFunc);
|
||||
break;
|
||||
default:
|
||||
LOGW("Unknown gesture action %{public}d", action);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Ace::Framework
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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_JS_VIEW_MODELS_GESTURE_MODEL_IMPL_H
|
||||
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_GESTURE_MODEL_IMPL_H
|
||||
|
||||
#include "core/components_ng/pattern/gesture/gesture_model.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
class GestureModelImpl : public OHOS::Ace::GestureModel {
|
||||
public:
|
||||
void Create(int32_t priorityNum, int32_t gestureMaskNum) override;
|
||||
void Finish() override;
|
||||
void Pop() override;
|
||||
void SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter) override;
|
||||
void SetOnActionFunc(const GestureEventFunc& gestureEventFunc, const Ace::GestureEventAction& action) override;
|
||||
};
|
||||
|
||||
class TapGestureModelImpl : public OHOS::Ace::TapGestureModel {
|
||||
public:
|
||||
void Create(int32_t countNum, int32_t fingersNum) override;
|
||||
};
|
||||
|
||||
class LongPressGestureModelImpl : public OHOS::Ace::LongPressGestureModel {
|
||||
public:
|
||||
void Create(int32_t fingersNum, bool repeatResult, int32_t durationNum) override;
|
||||
};
|
||||
|
||||
class PanGestureModelImpl : public OHOS::Ace::PanGestureModel {
|
||||
public:
|
||||
void Create(int32_t fingersNum, const PanDirection& panDirection, double distanceNum) override;
|
||||
void SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption) override;
|
||||
};
|
||||
|
||||
class SwipeGestureModelImpl : public OHOS::Ace::SwipeGestureModel {
|
||||
public:
|
||||
void Create(int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum) override;
|
||||
};
|
||||
|
||||
class PinchGestureModelImpl : public OHOS::Ace::PinchGestureModel {
|
||||
public:
|
||||
void Create(int32_t fingersNum, double distanceNum) override;
|
||||
};
|
||||
|
||||
class RotationGestureModelImpl : public OHOS::Ace::RotationGestureModel {
|
||||
public:
|
||||
void Create(int32_t fingersNum, double angleNum) override;
|
||||
};
|
||||
|
||||
class GestureGroupModelImpl : public OHOS::Ace::GestureGroupModel {
|
||||
public:
|
||||
void Create(int32_t gestureMode) override;
|
||||
};
|
||||
|
||||
class ACE_EXPORT TimeoutGestureModelImpl : public OHOS::Ace::TimeoutGestureModel {
|
||||
public:
|
||||
RefPtr<GestureProcessor> GetGestureProcessor() override;
|
||||
};
|
||||
} // namespace OHOS::Ace::Framework
|
||||
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_GESTURE_MODEL_IMPL_H
|
@ -96,6 +96,7 @@ build_component_ng("pattern_ng") {
|
||||
"gauge/gauge_model_ng.cpp",
|
||||
"gauge/gauge_paint_method.cpp",
|
||||
"gauge/gauge_pattern.cpp",
|
||||
"gesture/gesture_model_ng.cpp",
|
||||
"grid/grid_accessibility_property.cpp",
|
||||
"grid/grid_adaptive/grid_adaptive_layout_algorithm.cpp",
|
||||
"grid/grid_event_hub.cpp",
|
||||
|
140
frameworks/core/components_ng/pattern/gesture/gesture_model.h
Normal file
140
frameworks/core/components_ng/pattern/gesture/gesture_model.h
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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_PATTERNS_GESTURE_GESTURE_MODEL_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GESTURE_GESTURE_MODEL_H
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "core/gestures/gesture_processor.h"
|
||||
#include "core/gestures/gesture_info.h"
|
||||
#include "frameworks/base/memory/referenced.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
enum class GestureEventAction { ACTION, START, UPDATE, END, CANCEL };
|
||||
class GestureModel {
|
||||
public:
|
||||
static GestureModel* GetInstance();
|
||||
virtual ~GestureModel() = default;
|
||||
|
||||
virtual void Create(int32_t priorityNum, int32_t gestureMaskNum) = 0;
|
||||
virtual void Finish() = 0;
|
||||
virtual void Pop() = 0;
|
||||
virtual void SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter) = 0;
|
||||
virtual void SetOnActionFunc(const GestureEventFunc& gestureEventFunc, const Ace::GestureEventAction& action) = 0;
|
||||
|
||||
private:
|
||||
static std::unique_ptr<GestureModel> instance_;
|
||||
static std::mutex mutex_;
|
||||
};
|
||||
|
||||
class TapGestureModel {
|
||||
public:
|
||||
static TapGestureModel* GetInstance();
|
||||
virtual ~TapGestureModel() = default;
|
||||
|
||||
virtual void Create(int32_t countNum, int32_t fingersNum) = 0;
|
||||
|
||||
private:
|
||||
static std::unique_ptr<TapGestureModel> instance_;
|
||||
static std::mutex mutex_;
|
||||
};
|
||||
|
||||
class LongPressGestureModel {
|
||||
public:
|
||||
static LongPressGestureModel* GetInstance();
|
||||
virtual ~LongPressGestureModel() = default;
|
||||
|
||||
virtual void Create(int32_t fingersNum, bool repeatResult, int32_t durationNum) = 0;
|
||||
|
||||
private:
|
||||
static std::unique_ptr<LongPressGestureModel> instance_;
|
||||
static std::mutex mutex_;
|
||||
};
|
||||
|
||||
class PanGestureModel {
|
||||
public:
|
||||
static PanGestureModel* GetInstance();
|
||||
virtual ~PanGestureModel() = default;
|
||||
|
||||
virtual void Create(int32_t fingersNum, const PanDirection& panDirection, double distanceNum) = 0;
|
||||
virtual void SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption) = 0;
|
||||
|
||||
private:
|
||||
static std::unique_ptr<PanGestureModel> instance_;
|
||||
static std::mutex mutex_;
|
||||
};
|
||||
|
||||
class SwipeGestureModel {
|
||||
public:
|
||||
static SwipeGestureModel* GetInstance();
|
||||
virtual ~SwipeGestureModel() = default;
|
||||
|
||||
virtual void Create(int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum) = 0;
|
||||
|
||||
private:
|
||||
static std::unique_ptr<SwipeGestureModel> instance_;
|
||||
static std::mutex mutex_;
|
||||
};
|
||||
|
||||
class PinchGestureModel {
|
||||
public:
|
||||
static PinchGestureModel* GetInstance();
|
||||
virtual ~PinchGestureModel() = default;
|
||||
|
||||
virtual void Create(int32_t fingersNum, double distanceNum) = 0;
|
||||
|
||||
private:
|
||||
static std::unique_ptr<PinchGestureModel> instance_;
|
||||
static std::mutex mutex_;
|
||||
};
|
||||
|
||||
class RotationGestureModel {
|
||||
public:
|
||||
static RotationGestureModel* GetInstance();
|
||||
virtual ~RotationGestureModel() = default;
|
||||
|
||||
virtual void Create(int32_t fingersNum, double angleNum) = 0;
|
||||
|
||||
private:
|
||||
static std::unique_ptr<RotationGestureModel> instance_;
|
||||
static std::mutex mutex_;
|
||||
};
|
||||
|
||||
class GestureGroupModel {
|
||||
public:
|
||||
static GestureGroupModel* GetInstance();
|
||||
virtual ~GestureGroupModel() = default;
|
||||
|
||||
virtual void Create(int32_t gestureMode) = 0;
|
||||
|
||||
private:
|
||||
static std::unique_ptr<GestureGroupModel> instance_;
|
||||
static std::mutex mutex_;
|
||||
};
|
||||
|
||||
class TimeoutGestureModel {
|
||||
public:
|
||||
static TimeoutGestureModel* GetInstance();
|
||||
virtual ~TimeoutGestureModel() = default;
|
||||
|
||||
virtual RefPtr<GestureProcessor> GetGestureProcessor() = 0;
|
||||
|
||||
private:
|
||||
static std::unique_ptr<TimeoutGestureModel> instance_;
|
||||
static std::mutex mutex_;
|
||||
};
|
||||
} // namespace OHOS::Ace
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GESTURE_GESTURE_MODEL_H
|
@ -0,0 +1,180 @@
|
||||
/*
|
||||
* 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/pattern/gesture/gesture_model_ng.h"
|
||||
|
||||
#include "core/components_ng/base/view_stack_processor.h"
|
||||
#include "core/components_ng/gestures/gesture_group.h"
|
||||
#include "core/components_ng/gestures/long_press_gesture.h"
|
||||
#include "core/components_ng/gestures/rotation_gesture.h"
|
||||
#include "core/components_ng/gestures/pan_gesture.h"
|
||||
#include "core/components_ng/gestures/pinch_gesture.h"
|
||||
#include "core/components_ng/gestures/swipe_gesture.h"
|
||||
#include "core/components_ng/gestures/tap_gesture.h"
|
||||
#include "core/gestures/gesture_processor.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
void GestureModelNG::Create(int32_t priorityNum, int32_t gestureMaskNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
|
||||
GesturePriority priority = GesturePriority::Low;
|
||||
if (priorityNum > static_cast<int32_t>(GesturePriority::Begin) &&
|
||||
priorityNum < static_cast<int32_t>(GesturePriority::End)) {
|
||||
priority = static_cast<GesturePriority>(priorityNum);
|
||||
}
|
||||
gestureProcessor->SetPriority(priority);
|
||||
|
||||
GestureMask gestureMask = GestureMask::Normal;
|
||||
if (gestureMaskNum > static_cast<int32_t>(GestureMask::Begin) &&
|
||||
gestureMaskNum < static_cast<int32_t>(GestureMask::End)) {
|
||||
gestureMask = static_cast<GestureMask>(gestureMaskNum);
|
||||
}
|
||||
gestureProcessor->SetGestureMask(gestureMask);
|
||||
}
|
||||
|
||||
void GestureModelNG::Finish()
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
NG::ViewStackProcessor::GetInstance()->ResetGestureProcessor();
|
||||
|
||||
auto gesture = gestureProcessor->FinishGestureNG();
|
||||
if (!gesture) {
|
||||
LOGE("gesture is not exist when component finish");
|
||||
return;
|
||||
}
|
||||
gesture->SetGestureMask(gestureProcessor->GetGestureMask());
|
||||
gesture->SetPriority(gestureProcessor->GetPriority());
|
||||
auto gestureEventHub = NG::ViewStackProcessor::GetInstance()->GetMainFrameNodeGestureEventHub();
|
||||
if (gestureEventHub) {
|
||||
gestureEventHub->AddGesture(gesture);
|
||||
}
|
||||
}
|
||||
|
||||
void GestureModelNG::Pop()
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
gestureProcessor->PopGestureNG();
|
||||
}
|
||||
|
||||
void TapGestureModelNG::Create(int32_t countNum, int32_t fingersNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::TapGesture>(countNum, fingersNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
}
|
||||
|
||||
void LongPressGestureModelNG::Create(int32_t fingersNum, bool repeatResult, int32_t durationNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::LongPressGesture>(fingersNum, repeatResult, durationNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
}
|
||||
|
||||
void PanGestureModelNG::Create(int32_t fingersNum, const PanDirection& panDirection, double distanceNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::PanGesture>(fingersNum, panDirection, distanceNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
}
|
||||
|
||||
void PanGestureModelNG::SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::PanGesture>(panGestureOption);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
}
|
||||
|
||||
void SwipeGestureModelNG::Create(int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::SwipeGesture>(fingersNum, slideDirection, speedNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
}
|
||||
|
||||
void PinchGestureModelNG::Create(int32_t fingersNum, double distanceNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::PinchGesture>(fingersNum, distanceNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
}
|
||||
|
||||
void RotationGestureModelNG::Create(int32_t fingersNum, double angleNum)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::RotationGesture>(fingersNum, angleNum);
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
}
|
||||
|
||||
void GestureGroupModelNG::Create(int32_t gestureMode)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = AceType::MakeRefPtr<NG::GestureGroup>(static_cast<GestureMode>(gestureMode));
|
||||
gestureProcessor->PushGestureNG(gesture);
|
||||
}
|
||||
|
||||
RefPtr<GestureProcessor> TimeoutGestureModelNG::GetGestureProcessor()
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
return gestureProcessor;
|
||||
}
|
||||
|
||||
void GestureModelNG::SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = gestureProcessor->TopGestureNG();
|
||||
CHECK_NULL_VOID(gesture);
|
||||
gesture->SetOnActionCancelId(gestureEventNoParameter);
|
||||
}
|
||||
|
||||
void GestureModelNG::SetOnActionFunc(const GestureEventFunc& gestureEventFunc, const Ace::GestureEventAction& action)
|
||||
{
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gesture = gestureProcessor->TopGestureNG();
|
||||
CHECK_NULL_VOID(gesture);
|
||||
|
||||
switch (action) {
|
||||
case Ace::GestureEventAction::ACTION:
|
||||
gesture->SetOnActionId(gestureEventFunc);
|
||||
break;
|
||||
case Ace::GestureEventAction::START:
|
||||
gesture->SetOnActionStartId(gestureEventFunc);
|
||||
break;
|
||||
case Ace::GestureEventAction::UPDATE:
|
||||
gesture->SetOnActionUpdateId(gestureEventFunc);
|
||||
break;
|
||||
case Ace::GestureEventAction::END:
|
||||
gesture->SetOnActionEndId(gestureEventFunc);
|
||||
break;
|
||||
default:
|
||||
LOGW("Unknown gesture action %{public}d", action);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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_PATTERN_GESTURE_GESTURE_VIEW_MODEL_NG_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GESTURE_GESTURE_VIEW_MODEL_NG_H
|
||||
|
||||
#include "core/components_ng/pattern/gesture/gesture_model.h"
|
||||
#include "frameworks/base/utils/macros.h"
|
||||
|
||||
namespace OHOS::Ace::NG {
|
||||
class ACE_EXPORT GestureModelNG : public OHOS::Ace::GestureModel {
|
||||
public:
|
||||
void Create(int32_t priorityNum, int32_t gestureMaskNum) override;
|
||||
void Finish() override;
|
||||
void Pop() override;
|
||||
void SetOnGestureEvent(const GestureEventNoParameter& gestureEventNoParameter) override;
|
||||
void SetOnActionFunc(const GestureEventFunc& gestureEventFunc, const Ace::GestureEventAction& action) override;
|
||||
};
|
||||
|
||||
class ACE_EXPORT TapGestureModelNG : public OHOS::Ace::TapGestureModel {
|
||||
public:
|
||||
void Create(int32_t countNum, int32_t fingersNum) override;
|
||||
};
|
||||
|
||||
class ACE_EXPORT LongPressGestureModelNG : public OHOS::Ace::LongPressGestureModel {
|
||||
public:
|
||||
void Create(int32_t fingersNum, bool repeatResult, int32_t durationNum) override;
|
||||
};
|
||||
|
||||
class ACE_EXPORT PanGestureModelNG : public OHOS::Ace::PanGestureModel {
|
||||
public:
|
||||
void Create(int32_t fingersNum, const PanDirection& panDirection, double distanceNum) override;
|
||||
void SetPanGestureOption(const RefPtr<PanGestureOption>& panGestureOption) override;
|
||||
};
|
||||
|
||||
class ACE_EXPORT SwipeGestureModelNG : public OHOS::Ace::SwipeGestureModel {
|
||||
public:
|
||||
void Create(int32_t fingersNum, const SwipeDirection& slideDirection, double speedNum) override;
|
||||
};
|
||||
|
||||
class ACE_EXPORT PinchGestureModelNG : public OHOS::Ace::PinchGestureModel {
|
||||
public:
|
||||
void Create(int32_t fingersNum, double distanceNum) override;
|
||||
};
|
||||
|
||||
class ACE_EXPORT RotationGestureModelNG : public OHOS::Ace::RotationGestureModel {
|
||||
public:
|
||||
void Create(int32_t fingersNum, double angleNum) override;
|
||||
};
|
||||
|
||||
class ACE_EXPORT GestureGroupModelNG : public OHOS::Ace::GestureGroupModel {
|
||||
public:
|
||||
void Create(int32_t gestureMode) override;
|
||||
};
|
||||
|
||||
class ACE_EXPORT TimeoutGestureModelNG : public OHOS::Ace::TimeoutGestureModel {
|
||||
public:
|
||||
RefPtr<GestureProcessor> GetGestureProcessor() override;
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GESTURE_GESTURE_VIEW_MODEL_NG_H
|
@ -40,6 +40,7 @@
|
||||
#include "core/components_ng/gestures/swipe_gesture.h"
|
||||
#include "core/components_ng/gestures/tap_gesture.h"
|
||||
#include "core/components_ng/layout/layout_property.h"
|
||||
#include "core/components_ng/pattern/gesture/gesture_model_ng.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@ -62,6 +63,10 @@ constexpr double SPECIAL_VALUE_RANGE_CASE2 = -181.0;
|
||||
constexpr double SWIPE_SPEED = 10.0;
|
||||
constexpr double VERTICAL_ANGLE = 90.0;
|
||||
constexpr double HORIZONTAL_ANGLE = 180.0;
|
||||
constexpr int32_t DEFAULT_PAN_FINGER = 1;
|
||||
constexpr double DEFAULT_PAN_DISTANCE = 5.0;
|
||||
constexpr int32_t DEFAULT_SLIDE_FINGER = DEFAULT_PAN_FINGER;
|
||||
constexpr double DEFAULT_SLIDE_SPEED = 100.0;
|
||||
} // namespace
|
||||
|
||||
class GesturesTestNg : public testing::Test {};
|
||||
@ -4621,6 +4626,14 @@ HWTEST_F(GesturesTestNg, GestureGroupTest001, TestSize.Level1)
|
||||
/**
|
||||
* @tc.steps: step1. create GestureGroup.
|
||||
*/
|
||||
GestureGroupModelNG gestureGroupModelNG;
|
||||
gestureGroupModelNG.Create(0);
|
||||
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto gestureGroupNG = AceType::DynamicCast<NG::GestureGroup>(gestureProcessor->TopGestureNG());
|
||||
EXPECT_EQ(gestureGroupNG->mode_, GestureMode::Sequence);
|
||||
|
||||
GestureGroup gestureGroup = GestureGroup(GestureMode::Sequence);
|
||||
|
||||
/**
|
||||
@ -5339,6 +5352,14 @@ HWTEST_F(GesturesTestNg, LongPressGestureTest001, TestSize.Level1)
|
||||
/**
|
||||
* @tc.steps: step1. create LongPressGesture.
|
||||
*/
|
||||
LongPressGestureModelNG longPressGestureModelNG;
|
||||
longPressGestureModelNG.Create(FINGER_NUMBER, false, LONG_PRESS_DURATION);
|
||||
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto longPressGestureNG = AceType::DynamicCast<NG::LongPressGesture>(gestureProcessor->TopGestureNG());
|
||||
EXPECT_EQ(longPressGestureNG->duration_, LONG_PRESS_DURATION);
|
||||
|
||||
LongPressGesture longPressGesture = LongPressGesture(FINGER_NUMBER, false, LONG_PRESS_DURATION, false, false);
|
||||
EXPECT_EQ(longPressGesture.repeat_, false);
|
||||
EXPECT_EQ(longPressGesture.duration_, LONG_PRESS_DURATION);
|
||||
@ -5383,8 +5404,13 @@ HWTEST_F(GesturesTestNg, PinchGestureTest001, TestSize.Level1)
|
||||
/**
|
||||
* @tc.steps: step1. create PinchGestureGesture.
|
||||
*/
|
||||
PinchGesture pinchGesture = PinchGesture(FINGER_NUMBER, PINCH_GESTURE_DISTANCE);
|
||||
EXPECT_EQ(pinchGesture.distance_, PINCH_GESTURE_DISTANCE);
|
||||
PinchGestureModelNG pinchGestureModelNG;
|
||||
pinchGestureModelNG.Create(FINGER_NUMBER, PINCH_GESTURE_DISTANCE);
|
||||
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto pinchGesture = AceType::DynamicCast<NG::PinchGesture>(gestureProcessor->TopGestureNG());
|
||||
EXPECT_EQ(pinchGesture->distance_, PINCH_GESTURE_DISTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -5396,6 +5422,14 @@ HWTEST_F(GesturesTestNg, RotationGestureTest001, TestSize.Level1)
|
||||
/**
|
||||
* @tc.steps: step1. create RotationGestureGesture.
|
||||
*/
|
||||
RotationGestureModelNG rotationGestureModelNG;
|
||||
rotationGestureModelNG.Create(FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
|
||||
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto rotationGestureNG = AceType::DynamicCast<NG::RotationGesture>(gestureProcessor->TopGestureNG());
|
||||
EXPECT_EQ(rotationGestureNG->angle_, ROTATION_GESTURE_ANGLE);
|
||||
|
||||
RotationGesture rotationGesture = RotationGesture(FINGER_NUMBER, ROTATION_GESTURE_ANGLE);
|
||||
EXPECT_EQ(rotationGesture.angle_, ROTATION_GESTURE_ANGLE);
|
||||
|
||||
@ -5436,9 +5470,16 @@ HWTEST_F(GesturesTestNg, TapGestureTest001, TestSize.Level1)
|
||||
/**
|
||||
* @tc.steps: step1. create TapGestureGesture.
|
||||
*/
|
||||
TapGestureModelNG tapGestureModelNG;
|
||||
tapGestureModelNG.Create(COUNT, FINGER_NUMBER);
|
||||
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
auto tapGestureNG = AceType::DynamicCast<NG::TapGesture>(gestureProcessor->TopGestureNG());
|
||||
EXPECT_EQ(tapGestureNG->count_, COUNT);
|
||||
|
||||
TapGesture tapGesture = TapGesture(COUNT, FINGER_NUMBER);
|
||||
EXPECT_EQ(tapGesture.count_, COUNT);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. call CreateRecognizer function and compare result
|
||||
* @tc.steps: case1: not have onActionId
|
||||
@ -5460,4 +5501,43 @@ HWTEST_F(GesturesTestNg, TapGestureTest001, TestSize.Level1)
|
||||
EXPECT_EQ(tapRecognizer->GetPriority(), GesturePriority::Low);
|
||||
EXPECT_EQ(tapRecognizer->GetPriorityMask(), GestureMask::Normal);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GestureTest001
|
||||
* @tc.desc: Test TapGesture CreateRecognizer function
|
||||
*/
|
||||
HWTEST_F(GesturesTestNg, GestureTest001, TestSize.Level1)
|
||||
{
|
||||
GestureModelNG gestureModelNG;
|
||||
gestureModelNG.Create(0, 0);
|
||||
gestureModelNG.Finish();
|
||||
gestureModelNG.Pop();
|
||||
|
||||
RefPtr<GestureProcessor> gestureProcessor;
|
||||
gestureProcessor = NG::ViewStackProcessor::GetInstance()->GetOrCreateGestureProcessor();
|
||||
EXPECT_EQ(gestureProcessor->priority_, GesturePriority::Low);
|
||||
EXPECT_EQ(gestureProcessor->gestureMask_, GestureMask::Normal);
|
||||
|
||||
PanGestureModelNG panGestureModelNG;
|
||||
int32_t fingersNum = DEFAULT_PAN_FINGER;
|
||||
double distanceNum = DEFAULT_PAN_DISTANCE;
|
||||
PanDirection panDirection;
|
||||
panGestureModelNG.Create(fingersNum, panDirection, distanceNum);
|
||||
auto panGestureNG = AceType::DynamicCast<NG::PanGesture>(gestureProcessor->TopGestureNG());
|
||||
EXPECT_EQ(panGestureNG->distance_, distanceNum);
|
||||
|
||||
RefPtr<PanGestureOption> refPanGestureOption = AceType::MakeRefPtr<PanGestureOption>();
|
||||
panGestureModelNG.SetPanGestureOption(refPanGestureOption);
|
||||
|
||||
TimeoutGestureModelNG timeoutGestureModelNG;
|
||||
timeoutGestureModelNG.GetGestureProcessor();
|
||||
|
||||
SwipeGestureModelNG swipeGestureModelNG;
|
||||
fingersNum = DEFAULT_SLIDE_FINGER;
|
||||
double speedNum = DEFAULT_SLIDE_SPEED;
|
||||
SwipeDirection slideDirection;
|
||||
swipeGestureModelNG.Create(fingersNum, slideDirection, speedNum);
|
||||
auto swipeGestureNG = AceType::DynamicCast<NG::SwipeGesture>(gestureProcessor->TopGestureNG());
|
||||
EXPECT_EQ(swipeGestureNG->speed_, speedNum);
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
Loading…
Reference in New Issue
Block a user