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 "hilog_wrapper.h"
17 #include "napi_accessibility_utils.h"
18 #include "napi_accessibility_gesture_pos.h"
19
20 using namespace OHOS;
21 using namespace OHOS::Accessibility;
22
23 napi_value NGesturePos::posCons_ = nullptr;
24
DefineJSGesturePos(napi_env env)25 void NGesturePos::DefineJSGesturePos(napi_env env)
26 {
27 NAPI_CALL_RETURN_VOID(env,
28 napi_define_class(env,
29 "GesturePos",
30 NAPI_AUTO_LENGTH,
31 NGesturePos::JSPosConstructor,
32 nullptr,
33 0,
34 nullptr,
35 &NGesturePos::posCons_));
36 }
37
JSPosConstructor(napi_env env,napi_callback_info info)38 napi_value NGesturePos::JSPosConstructor(napi_env env, napi_callback_info info)
39 {
40 size_t argc = ARGS_SIZE_TWO;
41 napi_value argv[ARGS_SIZE_TWO] = {0};
42 napi_value jsthis = nullptr;
43 NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &jsthis, nullptr));
44 uint32_t x = 0, y = 0;
45 ParseUint32(env, x, argv[PARAM0]);
46 ParseUint32(env, y, argv[PARAM1]);
47 HILOG_INFO("JSPosConstructor, x:%{public}d, y:%{public}d", x, y);
48 napi_set_named_property(env, jsthis, "posX", argv[PARAM0]);
49 napi_set_named_property(env, jsthis, "posY", argv[PARAM1]);
50
51 return jsthis;
52 }