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/functions/js_pan_function.h"
17
18 #include "base/log/log.h"
19 #include "frameworks/bridge/declarative_frontend/jsview/js_view_register.h"
20
21 namespace OHOS::Ace::Framework {
22
createPanInfo(const TouchLocationInfo & info)23 JSRef<JSObject> JsPanFunction::createPanInfo(const TouchLocationInfo& info)
24 {
25 JSRef<JSObject> panInfoObj = JSRef<JSObject>::New();
26 const OHOS::Ace::Offset& globalLocation = info.GetGlobalLocation();
27 const OHOS::Ace::Offset& localLocation = info.GetLocalLocation();
28 panInfoObj->SetProperty<double>("globalX", globalLocation.GetX());
29 panInfoObj->SetProperty<double>("globalY", globalLocation.GetY());
30 panInfoObj->SetProperty<double>("localX", localLocation.GetX());
31 panInfoObj->SetProperty<double>("localY", localLocation.GetY());
32 return panInfoObj;
33 }
34
Execute(const DragStartInfo & info)35 void JsPanFunction::Execute(const DragStartInfo& info)
36 {
37 LOGD("JsPanFunction: eventType[%s]", info.GetType().c_str());
38 JSRef<JSVal> param = createPanInfo(static_cast<TouchLocationInfo>(info));
39 JsFunction::ExecuteJS(1, ¶m);
40 }
41
Execute(const DragUpdateInfo & info)42 void JsPanFunction::Execute(const DragUpdateInfo& info)
43 {
44 LOGD("JsPanFunction: eventType[%s]", info.GetType().c_str());
45 JSRef<JSObject> paramObj = createPanInfo(static_cast<TouchLocationInfo>(info));
46 const OHOS::Ace::Offset& deltaLocation = info.GetDelta();
47 JSRef<JSObject> deltaInfoObj = JSRef<JSObject>::New();
48 deltaInfoObj->SetProperty<double>("x", deltaLocation.GetX());
49 deltaInfoObj->SetProperty<double>("y", deltaLocation.GetY());
50 paramObj->SetPropertyObject("delta", deltaInfoObj);
51 paramObj->SetProperty<double>("mainDelta", info.GetMainDelta());
52
53 JSRef<JSVal> param = paramObj;
54 JsFunction::ExecuteJS(1, ¶m);
55 }
56
Execute(const DragEndInfo & info)57 void JsPanFunction::Execute(const DragEndInfo& info)
58 {
59 LOGD("JsPanFunction: eventType[%s]", info.GetType().c_str());
60
61 JSRef<JSObject> paramObj = createPanInfo(static_cast<TouchLocationInfo>(info));
62 const OHOS::Ace::Velocity& velocityLocation = info.GetVelocity();
63 JSRef<JSObject> velocityInfoObj = JSRef<JSObject>::New();
64 velocityInfoObj->SetProperty<double>("x", velocityLocation.GetVelocityX());
65 velocityInfoObj->SetProperty<double>("y", velocityLocation.GetVelocityY());
66 paramObj->SetPropertyObject("velocity", velocityInfoObj);
67 paramObj->SetProperty<double>("mainVelocity", info.GetMainVelocity());
68
69 JSRef<JSVal> param = paramObj;
70 JsFunction::ExecuteJS(1, ¶m);
71 }
72
Execute()73 void JsPanFunction::Execute()
74 {
75 JsFunction::ExecuteJS();
76 }
77
78 } // namespace OHOS::Ace::Framework
79