1 /*
2 * Copyright (c) 2024 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_crown_function.h"
17
18 namespace OHOS::Ace::Framework {
19
createCrownEvent(CrownEventInfo & event)20 JSRef<JSObject> JsCrownFunction::createCrownEvent(CrownEventInfo& event)
21 {
22 JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
23 objectTemplate->SetInternalFieldCount(1);
24 JSRef<JSObject> crownEventObj = objectTemplate->NewInstance();
25 crownEventObj->SetProperty<double>("timestamp", static_cast<double>
26 (event.GetTimeStamp().time_since_epoch().count()));
27 crownEventObj->SetProperty<double>("angularVelocity", static_cast<double>(event.GetAngularVelocity()));
28 crownEventObj->SetProperty<double>("degree", static_cast<double>(event.GetDegree()));
29 crownEventObj->SetProperty<int32_t>("action", static_cast<int32_t>(event.GetAction()));
30 crownEventObj->SetPropertyObject("stopPropagation", JSRef<JSFunc>::New<FunctionCallback>(JsStopPropagation));
31 crownEventObj->Wrap<CrownEventInfo>(&event);
32 return crownEventObj;
33 }
34
Execute(OHOS::Ace::CrownEventInfo & event)35 void JsCrownFunction::Execute(OHOS::Ace::CrownEventInfo& event)
36 {
37 JSRef<JSVal> param = JSRef<JSVal>::Cast(createCrownEvent(event));
38 JsFunction::ExecuteJS(1, ¶m);
39 }
40
ExecuteWithValue(OHOS::Ace::CrownEventInfo & event)41 JSRef<JSVal> JsCrownFunction::ExecuteWithValue(OHOS::Ace::CrownEventInfo& event)
42 {
43 JSRef<JSVal> param = JSRef<JSVal>::Cast(createCrownEvent(event));
44 return JsFunction::ExecuteJS(1, ¶m);
45 }
46
47 } // namespace OHOS::Ace::Framework