• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "frameworks/bridge/declarative_frontend/engine/functions/js_touch_test_done_function.h"
17 
18 #include "base/memory/ace_type.h"
19 #include "base/utils/utils.h"
20 #include "bridge/declarative_frontend/engine/functions/js_should_built_in_recognizer_parallel_with_function.h"
21 #include "bridge/declarative_frontend/engine/functions/js_gesture_judge_function.h"
22 #include "core/components/common/layout/constants.h"
23 #include "core/components_ng/gestures/base_gesture_event.h"
24 #include "frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.h"
25 
26 namespace OHOS::Ace::Framework {
27 
Execute(const std::shared_ptr<BaseGestureEvent> & info,const std::list<RefPtr<NG::NGGestureRecognizer>> & others)28 bool JsTouchTestDoneFunction::Execute(
29     const std::shared_ptr<BaseGestureEvent>& info, const std::list<RefPtr<NG::NGGestureRecognizer>>& others)
30 {
31     CHECK_NULL_RETURN(info, false);
32     auto obj = CreateGestureEventObject(info);
33     int32_t paramCount = 2;
34     JSRef<JSVal> params[paramCount];
35     params[0] = obj;
36     JSRef<JSArray> othersArr = JSRef<JSArray>::New();
37     uint32_t othersIdx = 0;
38     for (const auto& item : others) {
39         auto othersObj = JsShouldBuiltInRecognizerParallelWithFunction::CreateRecognizerObject(item);
40         othersArr->SetValueAt(othersIdx++, othersObj);
41     }
42     params[1] = othersArr;
43     JsFunction::ExecuteJS(paramCount, params);
44     return true;
45 }
46 
CreateGestureEventObject(const std::shared_ptr<BaseGestureEvent> & info)47 JSRef<JSObject> JsTouchTestDoneFunction::CreateGestureEventObject(const std::shared_ptr<BaseGestureEvent>& info)
48 {
49     JSRef<JSObjTemplate> objTemp = JSRef<JSObjTemplate>::New();
50     objTemp->SetInternalFieldCount(1);
51     JSRef<JSObject> obj = objTemp->NewInstance();
52     CommonUtils::SetBaseGestureEventInfo(obj, info);
53     JSRef<JSArray> fingerArr = JSRef<JSArray>::New();
54     const std::list<FingerInfo>& fingerList = info->GetFingerList();
55     std::list<FingerInfo> notTouchFingerList;
56     int32_t maxFingerId = -1;
57     for (const FingerInfo& fingerInfo : fingerList) {
58         JSRef<JSObject> element = CommonUtils::CreateFingerInfo(fingerInfo);
59         if (fingerInfo.sourceType_ == SourceType::TOUCH && fingerInfo.sourceTool_ == SourceTool::FINGER) {
60             fingerArr->SetValueAt(fingerInfo.fingerId_, element);
61             if (fingerInfo.fingerId_ > maxFingerId) {
62                 maxFingerId = fingerInfo.fingerId_;
63             }
64         } else {
65             notTouchFingerList.emplace_back(fingerInfo);
66         }
67     }
68     auto idx = maxFingerId + 1;
69     for (const FingerInfo& fingerInfo : notTouchFingerList) {
70         JSRef<JSObject> element = CommonUtils::CreateFingerInfo(fingerInfo);
71         fingerArr->SetValueAt(idx++, element);
72     }
73     obj->SetPropertyObject("fingerList", fingerArr);
74     auto target = CommonUtils::CreateEventTargetObject(info);
75     obj->SetPropertyObject("target", target);
76     obj->Wrap<BaseGestureEvent>(info.get());
77     return obj;
78 }
79 } // namespace OHOS::Ace::Framework
80