• 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         eventInfo->SetStopPropagation(true);
27     }
28     return JSValueRef::Undefined(info->GetVM());
29 }
30 
JsPreventDefault(panda::JsiRuntimeCallInfo * info)31 Local<JSValueRef> JsPreventDefault(panda::JsiRuntimeCallInfo *info)
32 {
33     Local<JSValueRef> thisObj = info->GetThisRef();
34     auto eventInfo = static_cast<BaseEventInfo*>(panda::Local<panda::ObjectRef>(thisObj)->GetNativePointerField(0));
35     if (eventInfo) {
36         eventInfo->SetPreventDefault(true);
37     }
38     return JSValueRef::Undefined(info->GetVM());
39 }
40 
JsGetHistoricalPoints(panda::JsiRuntimeCallInfo * info)41 Local<JSValueRef> JsGetHistoricalPoints(panda::JsiRuntimeCallInfo *info)
42 {
43     Local<JSValueRef> thisObj = info->GetThisRef();
44     auto eventInfo = static_cast<TouchEventInfo*>(panda::Local<panda::ObjectRef>(thisObj)->GetNativePointerField(0));
45     if (!eventInfo) {
46         return JSValueRef::Undefined(info->GetVM());
47     }
48     std::list<TouchLocationInfo> history;
49     history = eventInfo->GetHistory();
50     Local<ArrayRef> valueArray = ArrayRef::New(info->GetVM(), history.size());
51     auto index = 0;
52     Local<ObjectRef> objRef = ObjectRef::New(info->GetVM());
53     for (auto const &point : history) {
54         Local<ObjectRef> touchObject = ObjectRef::New(info->GetVM());
55         const OHOS::Ace::Offset& globalLocation = point.GetGlobalLocation();
56         const OHOS::Ace::Offset& localLocation = point.GetLocalLocation();
57         const OHOS::Ace::Offset& screenLocation = point.GetScreenLocation();
58         touchObject->Set(info->GetVM(), ToJSValue("id"), ToJSValue(point.GetFingerId()));
59         touchObject->Set(info->GetVM(), ToJSValue("type"), ToJSValue(static_cast<int32_t>(point.GetTouchType())));
60         touchObject->Set(info->GetVM(),
61             ToJSValue("x"), ToJSValue(PipelineBase::Px2VpWithCurrentDensity(localLocation.GetX())));
62         touchObject->Set(info->GetVM(),
63             ToJSValue("y"), ToJSValue(PipelineBase::Px2VpWithCurrentDensity(localLocation.GetY())));
64         touchObject->Set(info->GetVM(),
65             ToJSValue("screenX"), ToJSValue(PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetX())));
66         touchObject->Set(info->GetVM(),
67             ToJSValue("screenY"), ToJSValue(PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetY())));
68         touchObject->Set(info->GetVM(),
69             ToJSValue("windowX"), ToJSValue(PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetX())));
70         touchObject->Set(info->GetVM(),
71             ToJSValue("windowY"), ToJSValue(PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetY())));
72         touchObject->Set(info->GetVM(),
73             ToJSValue("displayX"), ToJSValue(PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetX())));
74         touchObject->Set(info->GetVM(),
75             ToJSValue("displayY"), ToJSValue(PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetY())));
76 
77         objRef->Set(info->GetVM(), ToJSValue("touchObject"), (touchObject));
78         objRef->Set(info->GetVM(), ToJSValue("size"), ToJSValue(point.GetSize()));
79         objRef->Set(info->GetVM(), ToJSValue("force"), ToJSValue(static_cast<double>(point.GetForce())));
80         objRef->Set(info->GetVM(), ToJSValue("timestamp"),
81             ToJSValue(static_cast<double>(point.GetTimeStamp().time_since_epoch().count())));
82 
83         ArrayRef::SetValueAt(info->GetVM(), valueArray, index++, objRef);
84     }
85 
86     return valueArray;
87 }
88 #endif
89 
90 } // namespace OHOS::Ace::Framework
91