• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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/js_types.h"
17 
18 namespace OHOS::Ace::Framework {
19 
20 #ifdef USE_ARK_ENGINE
JsStopPropagation(panda::JsiRuntimeCallInfo * info)21 Local<JSValueRef> JsStopPropagation(panda::JsiRuntimeCallInfo *info)
22 {
23     Local<JSValueRef> thisObj = info->GetThisRef();
24     auto eventInfo = static_cast<BaseEventInfo*>(panda::Local<panda::ObjectRef>(thisObj)->GetNativePointerField(0));
25     if (eventInfo) {
26         LOGD("JsStopPropagation is trigger");
27         eventInfo->SetStopPropagation(true);
28     }
29     return JSValueRef::Undefined(info->GetVM());
30 }
31 
JsGetHistoricalPoints(panda::JsiRuntimeCallInfo * info)32 Local<JSValueRef> JsGetHistoricalPoints(panda::JsiRuntimeCallInfo *info)
33 {
34     Local<JSValueRef> thisObj = info->GetThisRef();
35     auto eventInfo = static_cast<TouchEventInfo*>(panda::Local<panda::ObjectRef>(thisObj)->GetNativePointerField(0));
36     if (!eventInfo) {
37         return JSValueRef::Undefined(info->GetVM());
38     }
39     std::list<TouchLocationInfo> history;
40     history = eventInfo->GetHistory();
41     Local<ArrayRef> valueArray = ArrayRef::New(info->GetVM(), history.size());
42     auto index = 0;
43     Local<ObjectRef> objRef = ObjectRef::New(info->GetVM());
44     for (auto const &point : history) {
45         Local<ObjectRef> touchObject = ObjectRef::New(info->GetVM());
46         const OHOS::Ace::Offset& globalLocation = point.GetGlobalLocation();
47         const OHOS::Ace::Offset& localLocation = point.GetLocalLocation();
48         touchObject->Set(info->GetVM(), ToJSValue("id"), ToJSValue(point.GetFingerId()));
49         touchObject->Set(info->GetVM(), ToJSValue("type"),
50             ToJSValue(static_cast<int32_t>(point.GetTouchType())));
51         touchObject->Set(info->GetVM(), ToJSValue("x"), ToJSValue(localLocation.GetX()));
52         touchObject->Set(info->GetVM(), ToJSValue("y"), ToJSValue(localLocation.GetX()));
53         touchObject->Set(info->GetVM(), ToJSValue("screenX"), ToJSValue(globalLocation.GetX()));
54         touchObject->Set(info->GetVM(), ToJSValue("scrennY"), ToJSValue(globalLocation.GetX()));
55 
56         objRef->Set(info->GetVM(), ToJSValue("touchObject"), (touchObject));
57         objRef->Set(info->GetVM(), ToJSValue("size"), ToJSValue(point.GetSize()));
58         objRef->Set(info->GetVM(), ToJSValue("force"), ToJSValue(static_cast<double>(point.GetForce())));
59         objRef->Set(info->GetVM(), ToJSValue("timestamp"),
60             ToJSValue(static_cast<double>(point.GetTimeStamp().time_since_epoch().count())));
61 
62         ArrayRef::SetValueAt(info->GetVM(), valueArray, index++, objRef);
63     }
64 
65     return valueArray;
66 }
67 #endif
68 
69 } // namespace OHOS::Ace::Framework
70