• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "js_gesture_event.h"
17 
18 #include "mmi_log.h"
19 #include "napi_constants.h"
20 #include "util_napi.h"
21 
22 namespace OHOS {
23 namespace MMI {
24 namespace {
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "JsGestureEvent" };
26 } // namespace
27 
28 enum class ActionType : int32_t {
29     CANCEL = 0,
30     BEGIN = 1,
31     UPDATE = 2,
32     END = 3,
33 };
34 
GetNapiInt32(napi_env env,int32_t code)35 napi_value JsGestureEvent::GetNapiInt32(napi_env env, int32_t code)
36 {
37     CALL_DEBUG_ENTER;
38     napi_value ret = nullptr;
39     CHKRP(napi_create_int32(env, code, &ret), CREATE_INT32);
40     return ret;
41 }
42 
EnumClassConstructor(napi_env env,napi_callback_info info)43 napi_value JsGestureEvent::EnumClassConstructor(napi_env env, napi_callback_info info)
44 {
45     CALL_DEBUG_ENTER;
46     size_t argc = 0;
47     napi_value args[1] = { 0 };
48     napi_value ret = nullptr;
49     void *data = nullptr;
50     CHKRP(napi_get_cb_info(env, info, &argc, args, &ret, &data), GET_CB_INFO);
51     return ret;
52 }
53 
Export(napi_env env,napi_value exports)54 napi_value JsGestureEvent::Export(napi_env env, napi_value exports)
55 {
56     CALL_DEBUG_ENTER;
57     napi_property_descriptor actionArr[] = {
58         DECLARE_NAPI_STATIC_PROPERTY("CANCEL", GetNapiInt32(env, static_cast<int32_t>(ActionType::CANCEL))),
59         DECLARE_NAPI_STATIC_PROPERTY("BEGIN", GetNapiInt32(env, static_cast<int32_t>(ActionType::BEGIN))),
60         DECLARE_NAPI_STATIC_PROPERTY("UPDATE", GetNapiInt32(env, static_cast<int32_t>(ActionType::UPDATE))),
61         DECLARE_NAPI_STATIC_PROPERTY("END", GetNapiInt32(env, static_cast<int32_t>(ActionType::END))),
62     };
63     napi_value actionType = nullptr;
64     CHKRP(napi_define_class(env, "ActionType", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr,
65         sizeof(actionArr) / sizeof(*actionArr), actionArr, &actionType), DEFINE_CLASS);
66     CHKRP(napi_set_named_property(env, exports, "ActionType", actionType), SET_NAMED_PROPERTY);
67     return exports;
68 }
69 } // namespace MMI
70 } // namespace OHOS