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_pointer_manager.h"
17
18 #include "napi_constants.h"
19
20 #undef MMI_LOG_TAG
21 #define MMI_LOG_TAG "JsPointerManager"
22
23 namespace OHOS {
24 namespace MMI {
25 namespace {
26 enum class ReturnType {
27 VOID,
28 BOOL,
29 NUMBER,
30 };
31 }
32
TypeOf(napi_env env,napi_value value,napi_valuetype type)33 bool JsCommon::TypeOf(napi_env env, napi_value value, napi_valuetype type)
34 {
35 napi_valuetype valueType = napi_undefined;
36 CHKRF(napi_typeof(env, value, &valueType), TYPEOF);
37 if (valueType != type) {
38 return false;
39 }
40 return true;
41 }
42
~AsyncContext()43 AsyncContext::~AsyncContext()
44 {
45 CALL_DEBUG_ENTER;
46 if (work != nullptr) {
47 CHKRV(napi_delete_async_work(env, work), DELETE_ASYNC_WORK);
48 }
49 if (callback != nullptr && env != nullptr) {
50 CHKRV(napi_delete_reference(env, callback), DELETE_REFERENCE);
51 env = nullptr;
52 }
53 }
54
GetResult(sptr<AsyncContext> asyncContext,napi_value * results,int32_t size)55 static bool GetResult(sptr<AsyncContext> asyncContext, napi_value *results, int32_t size)
56 {
57 CALL_DEBUG_ENTER;
58 int32_t length = 2;
59 if (size < length) {
60 MMI_HILOGE("results size less than 2");
61 return false;
62 }
63 napi_env env = asyncContext->env;
64 if (asyncContext->errorCode != RET_OK) {
65 if (asyncContext->errorCode == RET_ERR) {
66 MMI_HILOGE("Other errors");
67 return false;
68 }
69 NapiError codeMsg;
70 if (!UtilNapiError::GetApiError(asyncContext->errorCode, codeMsg)) {
71 MMI_HILOGE("ErrorCode not found, errCode:%{public}d", asyncContext->errorCode);
72 return false;
73 }
74 napi_value errCode = nullptr;
75 napi_value errMsg = nullptr;
76 napi_value businessError = nullptr;
77 CHKRF(napi_create_int32(env, asyncContext->errorCode, &errCode), CREATE_INT32);
78 CHKRF(napi_create_string_utf8(env, codeMsg.msg.c_str(),
79 NAPI_AUTO_LENGTH, &errMsg), CREATE_STRING_UTF8);
80 CHKRF(napi_create_error(env, nullptr, errMsg, &businessError), CREATE_ERROR);
81 CHKRF(napi_set_named_property(env, businessError, ERR_CODE.c_str(), errCode), SET_NAMED_PROPERTY);
82 results[0] = businessError;
83 } else {
84 CHKRF(napi_get_undefined(env, &results[0]), GET_UNDEFINED);
85 }
86
87 ReturnType resultType;
88 asyncContext->reserve >> resultType;
89 if (resultType == ReturnType::BOOL) {
90 bool temp;
91 asyncContext->reserve >> temp;
92 CHKRF(napi_get_boolean(env, temp, &results[1]), GET_BOOLEAN);
93 } else if (resultType == ReturnType::NUMBER) {
94 int32_t temp = 0;
95 asyncContext->reserve >> temp;
96 CHKRF(napi_create_int32(env, temp, &results[1]), CREATE_INT32);
97 } else {
98 CHKRF(napi_get_undefined(env, &results[1]), GET_UNDEFINED);
99 }
100 return true;
101 }
102
AsyncCallbackWork(sptr<AsyncContext> asyncContext)103 void AsyncCallbackWork(sptr<AsyncContext> asyncContext)
104 {
105 CALL_DEBUG_ENTER;
106 CHKPV(asyncContext);
107 CHKPV(asyncContext->env);
108 napi_env env = asyncContext->env;
109 napi_value resource = nullptr;
110 CHKRV(napi_create_string_utf8(env, "AsyncCallbackWork", NAPI_AUTO_LENGTH, &resource), CREATE_STRING_UTF8);
111 asyncContext->IncStrongRef(nullptr);
112 napi_status status = napi_create_async_work(
113 env, nullptr, resource,
114 [](napi_env env, void* data) {
115 MMI_HILOGD("async_work callback function is called");
116 },
117 [](napi_env env, napi_status status, void* data) {
118 sptr<AsyncContext> asyncContext(static_cast<AsyncContext *>(data));
119 /**
120 * After the asynchronous task is created, the asyncCallbackInfo reference count is reduced
121 * to 0 destruction, so you need to add 1 to the asyncCallbackInfo reference count when the
122 * asynchronous task is created, and subtract 1 from the reference count after the naked
123 * pointer is converted to a pointer when the asynchronous task is executed, the reference
124 * count of the smart pointer is guaranteed to be 1.
125 */
126 asyncContext->DecStrongRef(nullptr);
127 napi_value results[2] = { 0 };
128 int32_t size = 2;
129 if (!GetResult(asyncContext, results, size)) {
130 MMI_HILOGE("Failed to create napi data");
131 return;
132 }
133 if (asyncContext->deferred) {
134 if (asyncContext->errorCode == RET_OK) {
135 CHKRV(napi_resolve_deferred(env, asyncContext->deferred, results[1]), RESOLVE_DEFERRED);
136 } else {
137 CHKRV(napi_reject_deferred(env, asyncContext->deferred, results[0]), REJECT_DEFERRED);
138 }
139 } else {
140 napi_value callback = nullptr;
141 CHKRV(napi_get_reference_value(env, asyncContext->callback, &callback), GET_REFERENCE_VALUE);
142 napi_value callResult = nullptr;
143 CHKRV(napi_call_function(env, nullptr, callback, size, results, &callResult), CALL_FUNCTION);
144 }
145 },
146 asyncContext.GetRefPtr(), &asyncContext->work);
147 if (status != napi_ok ||
148 napi_queue_async_work_with_qos(env, asyncContext->work, napi_qos_t::napi_qos_user_initiated) != napi_ok) {
149 MMI_HILOGE("Create async work failed");
150 asyncContext->DecStrongRef(nullptr);
151 }
152 }
153
SetPointerVisible(napi_env env,bool visible,napi_value handle)154 napi_value JsPointerManager::SetPointerVisible(napi_env env, bool visible, napi_value handle)
155 {
156 CALL_DEBUG_ENTER;
157 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
158 CHKPP(asyncContext);
159
160 asyncContext->errorCode = InputManager::GetInstance()->SetPointerVisible(visible);
161 asyncContext->reserve << ReturnType::VOID;
162
163 napi_value promise = nullptr;
164 if (handle != nullptr) {
165 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
166 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
167 } else {
168 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
169 }
170 AsyncCallbackWork(asyncContext);
171 return promise;
172 }
173
SetPointerVisibleSync(napi_env env,bool visible)174 napi_value JsPointerManager::SetPointerVisibleSync(napi_env env, bool visible)
175 {
176 CALL_DEBUG_ENTER;
177 InputManager::GetInstance()->SetPointerVisible(visible);
178 napi_value result = nullptr;
179 if (napi_get_undefined(env, &result) != napi_ok) {
180 MMI_HILOGE("Get undefined result is failed");
181 return nullptr;
182 }
183 return result;
184 }
185
IsPointerVisible(napi_env env,napi_value handle)186 napi_value JsPointerManager::IsPointerVisible(napi_env env, napi_value handle)
187 {
188 CALL_DEBUG_ENTER;
189 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
190 CHKPP(asyncContext);
191
192 bool visible = InputManager::GetInstance()->IsPointerVisible();
193 asyncContext->errorCode = ERR_OK;
194 asyncContext->reserve << ReturnType::BOOL << visible;
195
196 napi_value promise = nullptr;
197 if (handle != nullptr) {
198 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
199 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
200 } else {
201 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
202 }
203 AsyncCallbackWork(asyncContext);
204 return promise;
205 }
206
IsPointerVisibleSync(napi_env env)207 napi_value JsPointerManager::IsPointerVisibleSync(napi_env env)
208 {
209 CALL_DEBUG_ENTER;
210 bool visible = InputManager::GetInstance()->IsPointerVisible();
211 napi_value result = nullptr;
212 NAPI_CALL(env, napi_get_boolean(env, visible, &result));
213 return result;
214 }
215
SetPointerColor(napi_env env,int32_t color,napi_value handle)216 napi_value JsPointerManager::SetPointerColor(napi_env env, int32_t color, napi_value handle)
217 {
218 CALL_DEBUG_ENTER;
219 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
220 CHKPP(asyncContext);
221 asyncContext->errorCode = InputManager::GetInstance()->SetPointerColor(color);
222 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
223 MMI_HILOGE("Non system applications use system API");
224 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
225 return nullptr;
226 }
227 asyncContext->reserve << ReturnType::VOID;
228 napi_value promise = nullptr;
229 if (handle != nullptr) {
230 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
231 if (napi_get_undefined(env, &promise) != napi_ok) {
232 CHKRP(napi_delete_reference(env, asyncContext->callback), DELETE_REFERENCE);
233 return nullptr;
234 }
235 } else {
236 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
237 }
238 AsyncCallbackWork(asyncContext);
239 return promise;
240 }
241
GetPointerColor(napi_env env,napi_value handle)242 napi_value JsPointerManager::GetPointerColor(napi_env env, napi_value handle)
243 {
244 CALL_DEBUG_ENTER;
245 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
246 CHKPP(asyncContext);
247 int32_t color = 1;
248 asyncContext->errorCode = InputManager::GetInstance()->GetPointerColor(color);
249 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
250 MMI_HILOGE("Non system applications use system API");
251 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
252 return nullptr;
253 }
254 asyncContext->reserve << ReturnType::NUMBER << color;
255 napi_value promise = nullptr;
256 uint32_t initialRefCount = 1;
257 if (handle != nullptr) {
258 CHKRP(napi_create_reference(env, handle, initialRefCount, &asyncContext->callback), CREATE_REFERENCE);
259 if (napi_get_undefined(env, &promise) != napi_ok) {
260 CHKRP(napi_delete_reference(env, asyncContext->callback), DELETE_REFERENCE);
261 return nullptr;
262 }
263 } else {
264 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
265 }
266 AsyncCallbackWork(asyncContext);
267 return promise;
268 }
269
SetPointerColorSync(napi_env env,int32_t color)270 napi_value JsPointerManager::SetPointerColorSync(napi_env env, int32_t color)
271 {
272 CALL_DEBUG_ENTER;
273 auto errorCode = InputManager::GetInstance()->SetPointerColor(color);
274 if (errorCode == COMMON_USE_SYSAPI_ERROR) {
275 MMI_HILOGE("Non system applications use system API");
276 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
277 return nullptr;
278 }
279
280 napi_value result = nullptr;
281 if (napi_get_undefined(env, &result) != napi_ok) {
282 MMI_HILOGE("Get undefined result is failed");
283 return nullptr;
284 }
285 return result;
286 }
287
GetPointerColorSync(napi_env env)288 napi_value JsPointerManager::GetPointerColorSync(napi_env env)
289 {
290 CALL_DEBUG_ENTER;
291 int32_t color = 1;
292 auto errorCode = InputManager::GetInstance()->GetPointerColor(color);
293 if (errorCode == COMMON_USE_SYSAPI_ERROR) {
294 MMI_HILOGE("Non system applications use system API");
295 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
296 return nullptr;
297 }
298 napi_value result = nullptr;
299 NAPI_CALL(env, napi_create_int32(env, color, &result));
300 return result;
301 }
302
SetPointerSpeed(napi_env env,int32_t pointerSpeed,napi_value handle)303 napi_value JsPointerManager::SetPointerSpeed(napi_env env, int32_t pointerSpeed, napi_value handle)
304 {
305 CALL_DEBUG_ENTER;
306 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
307 CHKPP(asyncContext);
308 asyncContext->errorCode = InputManager::GetInstance()->SetPointerSpeed(pointerSpeed);
309 asyncContext->reserve << ReturnType::VOID;
310 napi_value promise = nullptr;
311 if (handle != nullptr) {
312 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
313 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
314 } else {
315 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
316 }
317 AsyncCallbackWork(asyncContext);
318 return promise;
319 }
320
SetPointerSpeedSync(napi_env env,int32_t pointerSpeed)321 napi_value JsPointerManager::SetPointerSpeedSync(napi_env env, int32_t pointerSpeed)
322 {
323 CALL_DEBUG_ENTER;
324 InputManager::GetInstance()->SetPointerSpeed(pointerSpeed);
325 napi_value result = nullptr;
326 if (napi_get_undefined(env, &result) != napi_ok) {
327 MMI_HILOGE("Get undefined result is failed");
328 return nullptr;
329 }
330 return result;
331 }
332
GetPointerSpeed(napi_env env,napi_value handle)333 napi_value JsPointerManager::GetPointerSpeed(napi_env env, napi_value handle)
334 {
335 CALL_DEBUG_ENTER;
336 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
337 CHKPP(asyncContext);
338 int32_t pointerSpeed = 0;
339 asyncContext->errorCode = InputManager::GetInstance()->GetPointerSpeed(pointerSpeed);
340 asyncContext->reserve << ReturnType::NUMBER << pointerSpeed;
341 napi_value promise = nullptr;
342 uint32_t initial_refcount = 1;
343 if (handle != nullptr) {
344 CHKRP(napi_create_reference(env, handle, initial_refcount, &asyncContext->callback), CREATE_REFERENCE);
345 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
346 } else {
347 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
348 }
349 AsyncCallbackWork(asyncContext);
350 return promise;
351 }
352
GetPointerSpeedSync(napi_env env)353 napi_value JsPointerManager::GetPointerSpeedSync(napi_env env)
354 {
355 CALL_DEBUG_ENTER;
356 int32_t pointerSpeed = 0;
357 InputManager::GetInstance()->GetPointerSpeed(pointerSpeed);
358 napi_value result = nullptr;
359 NAPI_CALL(env, napi_create_int32(env, pointerSpeed, &result));
360 return result;
361 }
362
SetMouseScrollRows(napi_env env,int32_t rows,napi_value handle)363 napi_value JsPointerManager::SetMouseScrollRows(napi_env env, int32_t rows, napi_value handle)
364 {
365 CALL_DEBUG_ENTER;
366 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
367 CHKPP(asyncContext);
368 asyncContext->errorCode = InputManager::GetInstance()->SetMouseScrollRows(rows);
369 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
370 MMI_HILOGE("Non system applications use system API");
371 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
372 return nullptr;
373 }
374 asyncContext->reserve << ReturnType::VOID;
375 napi_value promise = nullptr;
376 if (handle != nullptr) {
377 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
378 if (napi_get_undefined(env, &promise) != napi_ok) {
379 CHKRP(napi_delete_reference(env, asyncContext->callback), DELETE_REFERENCE);
380 return nullptr;
381 }
382 } else {
383 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
384 }
385 AsyncCallbackWork(asyncContext);
386 return promise;
387 }
388
GetMouseScrollRows(napi_env env,napi_value handle)389 napi_value JsPointerManager::GetMouseScrollRows(napi_env env, napi_value handle)
390 {
391 CALL_DEBUG_ENTER;
392 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
393 CHKPP(asyncContext);
394 int32_t rows = 3;
395 asyncContext->errorCode = InputManager::GetInstance()->GetMouseScrollRows(rows);
396 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
397 MMI_HILOGE("Non system applications use system API");
398 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
399 return nullptr;
400 }
401 asyncContext->reserve << ReturnType::NUMBER << rows;
402 napi_value promise = nullptr;
403 uint32_t initialRefCount = 1;
404 if (handle != nullptr) {
405 CHKRP(napi_create_reference(env, handle, initialRefCount, &asyncContext->callback), CREATE_REFERENCE);
406 if (napi_get_undefined(env, &promise) != napi_ok) {
407 CHKRP(napi_delete_reference(env, asyncContext->callback), DELETE_REFERENCE);
408 return nullptr;
409 }
410 } else {
411 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
412 }
413 AsyncCallbackWork(asyncContext);
414 return promise;
415 }
416
SetPointerLocation(napi_env env,int32_t x,int32_t y,napi_value handle)417 napi_value JsPointerManager::SetPointerLocation(napi_env env, int32_t x, int32_t y, napi_value handle)
418 {
419 CALL_DEBUG_ENTER;
420 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
421 CHKPP(asyncContext);
422 asyncContext->errorCode = InputManager::GetInstance()->SetPointerLocation(x, y);
423 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
424 MMI_HILOGE("Non system applications use system API");
425 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
426 return nullptr;
427 }
428 asyncContext->reserve << ReturnType::VOID;
429 napi_value promise = nullptr;
430 if (handle != nullptr) {
431 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
432 if (napi_get_undefined(env, &promise) != napi_ok) {
433 CHKRP(napi_delete_reference(env, asyncContext->callback), DELETE_REFERENCE);
434 return nullptr;
435 }
436 } else {
437 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
438 }
439 AsyncCallbackWork(asyncContext);
440 return promise;
441 }
442
SetCustomCursor(napi_env env,int32_t windowId,void * pixelMap,CursorFocus focus)443 napi_value JsPointerManager::SetCustomCursor(napi_env env, int32_t windowId, void* pixelMap, CursorFocus focus)
444 {
445 CALL_DEBUG_ENTER;
446 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
447 CHKPP(asyncContext);
448 asyncContext->errorCode = InputManager::GetInstance()->SetCustomCursor(windowId, pixelMap, focus.x, focus.y);
449 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
450 MMI_HILOGE("Non system applications use system API");
451 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
452 return nullptr;
453 }
454 asyncContext->reserve << ReturnType::VOID;
455 napi_value promise = nullptr;
456 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
457 AsyncCallbackWork(asyncContext);
458 return promise;
459 }
460
SetCustomCursorSync(napi_env env,int32_t windowId,void * pixelMap,CursorFocus focus)461 napi_value JsPointerManager::SetCustomCursorSync(napi_env env, int32_t windowId, void* pixelMap, CursorFocus focus)
462 {
463 CALL_DEBUG_ENTER;
464 InputManager::GetInstance()->SetCustomCursor(windowId, pixelMap, focus.x, focus.y);
465 napi_value result = nullptr;
466 if (napi_get_undefined(env, &result) != napi_ok) {
467 MMI_HILOGE("Get undefined result is failed");
468 return nullptr;
469 }
470 return result;
471 }
472
SetPointerSize(napi_env env,int32_t size,napi_value handle)473 napi_value JsPointerManager::SetPointerSize(napi_env env, int32_t size, napi_value handle)
474 {
475 CALL_DEBUG_ENTER;
476 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
477 CHKPP(asyncContext);
478 asyncContext->errorCode = InputManager::GetInstance()->SetPointerSize(size);
479 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
480 MMI_HILOGE("Non system applications use system API");
481 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
482 return nullptr;
483 }
484 asyncContext->reserve << ReturnType::VOID;
485 napi_value promise = nullptr;
486 if (handle != nullptr) {
487 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
488 if (napi_get_undefined(env, &promise) != napi_ok) {
489 CHKRP(napi_delete_reference(env, asyncContext->callback), DELETE_REFERENCE);
490 return nullptr;
491 }
492 } else {
493 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
494 }
495 AsyncCallbackWork(asyncContext);
496 return promise;
497 }
498
GetPointerSize(napi_env env,napi_value handle)499 napi_value JsPointerManager::GetPointerSize(napi_env env, napi_value handle)
500 {
501 CALL_DEBUG_ENTER;
502 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
503 CHKPP(asyncContext);
504 int32_t size = 1;
505 asyncContext->errorCode = InputManager::GetInstance()->GetPointerSize(size);
506 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
507 MMI_HILOGE("Non system applications use system API");
508 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
509 return nullptr;
510 }
511 asyncContext->reserve << ReturnType::NUMBER << size;
512 napi_value promise = nullptr;
513 uint32_t initialRefCount = 1;
514 if (handle != nullptr) {
515 CHKRP(napi_create_reference(env, handle, initialRefCount, &asyncContext->callback), CREATE_REFERENCE);
516 if (napi_get_undefined(env, &promise) != napi_ok) {
517 CHKRP(napi_delete_reference(env, asyncContext->callback), DELETE_REFERENCE);
518 return nullptr;
519 }
520 } else {
521 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
522 }
523 AsyncCallbackWork(asyncContext);
524 return promise;
525 }
526
SetPointerSizeSync(napi_env env,int32_t size)527 napi_value JsPointerManager::SetPointerSizeSync(napi_env env, int32_t size)
528 {
529 CALL_DEBUG_ENTER;
530 auto errorCode = InputManager::GetInstance()->SetPointerSize(size);
531 if (errorCode == COMMON_USE_SYSAPI_ERROR) {
532 MMI_HILOGE("Non system applications use system API");
533 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
534 return nullptr;
535 }
536
537 napi_value result = nullptr;
538 if (napi_get_undefined(env, &result) != napi_ok) {
539 MMI_HILOGE("Get undefined result is failed");
540 return nullptr;
541 }
542 return result;
543 }
544
GetPointerSizeSync(napi_env env)545 napi_value JsPointerManager::GetPointerSizeSync(napi_env env)
546 {
547 CALL_DEBUG_ENTER;
548 int32_t size = 1;
549 auto errorCode = InputManager::GetInstance()->GetPointerSize(size);
550 if (errorCode == COMMON_USE_SYSAPI_ERROR) {
551 MMI_HILOGE("Non system applications use system API");
552 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
553 return nullptr;
554 }
555 napi_value result = nullptr;
556 NAPI_CALL(env, napi_create_int32(env, size, &result));
557 return result;
558 }
559
SetPointerStyle(napi_env env,int32_t windowid,int32_t pointerStyle,napi_value handle)560 napi_value JsPointerManager::SetPointerStyle(napi_env env, int32_t windowid, int32_t pointerStyle, napi_value handle)
561 {
562 CALL_DEBUG_ENTER;
563 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
564 CHKPP(asyncContext);
565 PointerStyle style;
566 style.id = pointerStyle;
567 asyncContext->errorCode = InputManager::GetInstance()->SetPointerStyle(windowid, style);
568 asyncContext->reserve << ReturnType::VOID;
569
570 napi_value promise = nullptr;
571 if (handle != nullptr) {
572 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
573 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
574 } else {
575 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
576 }
577 AsyncCallbackWork(asyncContext);
578 return promise;
579 }
580
SetPointerStyleSync(napi_env env,int32_t windowid,int32_t pointerStyle)581 napi_value JsPointerManager::SetPointerStyleSync(napi_env env, int32_t windowid, int32_t pointerStyle)
582 {
583 CALL_DEBUG_ENTER;
584 PointerStyle style;
585 style.id = pointerStyle;
586 InputManager::GetInstance()->SetPointerStyle(windowid, style);
587 napi_value result = nullptr;
588 if (napi_get_undefined(env, &result) != napi_ok) {
589 MMI_HILOGE("Get undefined result is failed");
590 return nullptr;
591 }
592 return result;
593 }
594
GetPointerStyle(napi_env env,int32_t windowid,napi_value handle)595 napi_value JsPointerManager::GetPointerStyle(napi_env env, int32_t windowid, napi_value handle)
596 {
597 CALL_DEBUG_ENTER;
598 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
599 CHKPP(asyncContext);
600 PointerStyle pointerStyle;
601 asyncContext->errorCode = InputManager::GetInstance()->GetPointerStyle(windowid, pointerStyle);
602 asyncContext->reserve << ReturnType::NUMBER << pointerStyle.id;
603 napi_value promise = nullptr;
604 if (handle != nullptr) {
605 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
606 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
607 } else {
608 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
609 }
610 AsyncCallbackWork(asyncContext);
611 return promise;
612 }
613
GetPointerStyleSync(napi_env env,int32_t windowid)614 napi_value JsPointerManager::GetPointerStyleSync(napi_env env, int32_t windowid)
615 {
616 CALL_DEBUG_ENTER;
617 PointerStyle pointerStyle;
618 InputManager::GetInstance()->GetPointerStyle(windowid, pointerStyle);
619 napi_value result = nullptr;
620 NAPI_CALL(env, napi_create_int32(env, pointerStyle.id, &result));
621 return result;
622 }
623
EnterCaptureMode(napi_env env,int32_t windowId,napi_value handle)624 napi_value JsPointerManager::EnterCaptureMode(napi_env env, int32_t windowId, napi_value handle)
625 {
626 CALL_DEBUG_ENTER;
627 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
628 if (asyncContext == nullptr) {
629 THROWERR(env, "Create AsyncContext failed");
630 return nullptr;
631 }
632 asyncContext->errorCode = InputManager::GetInstance()->EnterCaptureMode(windowId);
633 asyncContext->reserve << ReturnType::VOID;
634
635 napi_value promise = nullptr;
636 if (handle != nullptr) {
637 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
638 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
639 } else {
640 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
641 }
642 AsyncCallbackWork(asyncContext);
643 return promise;
644 }
645
LeaveCaptureMode(napi_env env,int32_t windowId,napi_value handle)646 napi_value JsPointerManager::LeaveCaptureMode(napi_env env, int32_t windowId, napi_value handle)
647 {
648 CALL_DEBUG_ENTER;
649 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
650 if (asyncContext == nullptr) {
651 THROWERR(env, "Create AsyncContext failed");
652 return nullptr;
653 }
654
655 asyncContext->errorCode = InputManager::GetInstance()->LeaveCaptureMode(windowId);
656 asyncContext->reserve << ReturnType::VOID;
657
658 napi_value promise = nullptr;
659 if (handle != nullptr) {
660 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
661 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
662 } else {
663 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
664 }
665 AsyncCallbackWork(asyncContext);
666 return promise;
667 }
668
SetMousePrimaryButton(napi_env env,int32_t primaryButton,napi_value handle)669 napi_value JsPointerManager::SetMousePrimaryButton(napi_env env, int32_t primaryButton, napi_value handle)
670 {
671 CALL_DEBUG_ENTER;
672 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
673 CHKPP(asyncContext);
674
675 asyncContext->errorCode = InputManager::GetInstance()->SetMousePrimaryButton(primaryButton);
676 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
677 MMI_HILOGE("Non system applications use system API");
678 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
679 return nullptr;
680 }
681 asyncContext->reserve << ReturnType::VOID;
682
683 napi_value promise = nullptr;
684 if (handle != nullptr) {
685 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
686 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
687 } else {
688 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
689 }
690 AsyncCallbackWork(asyncContext);
691 return promise;
692 }
693
GetMousePrimaryButton(napi_env env,napi_value handle)694 napi_value JsPointerManager::GetMousePrimaryButton(napi_env env, napi_value handle)
695 {
696 CALL_DEBUG_ENTER;
697 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
698 CHKPP(asyncContext);
699 int32_t primaryButton = 0;
700 asyncContext->errorCode = InputManager::GetInstance()->GetMousePrimaryButton(primaryButton);
701 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
702 MMI_HILOGE("Non system applications use system API");
703 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
704 return nullptr;
705 }
706 asyncContext->reserve << ReturnType::NUMBER << primaryButton;
707 napi_value promise = nullptr;
708 if (handle != nullptr) {
709 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
710 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
711 } else {
712 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
713 }
714 AsyncCallbackWork(asyncContext);
715 return promise;
716 }
717
SetHoverScrollState(napi_env env,bool state,napi_value handle)718 napi_value JsPointerManager::SetHoverScrollState(napi_env env, bool state, napi_value handle)
719 {
720 CALL_DEBUG_ENTER;
721 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
722 CHKPP(asyncContext);
723
724 asyncContext->errorCode = InputManager::GetInstance()->SetHoverScrollState(state);
725 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
726 MMI_HILOGE("Non system applications use system API");
727 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
728 return nullptr;
729 }
730 asyncContext->reserve << ReturnType::VOID;
731
732 napi_value promise = nullptr;
733 if (handle != nullptr) {
734 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
735 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
736 } else {
737 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
738 }
739 AsyncCallbackWork(asyncContext);
740 return promise;
741 }
742
GetHoverScrollState(napi_env env,napi_value handle)743 napi_value JsPointerManager::GetHoverScrollState(napi_env env, napi_value handle)
744 {
745 CALL_DEBUG_ENTER;
746 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
747 CHKPP(asyncContext);
748
749 bool state;
750 asyncContext->errorCode = InputManager::GetInstance()->GetHoverScrollState(state);
751 if (asyncContext->errorCode == COMMON_USE_SYSAPI_ERROR) {
752 MMI_HILOGE("Non system applications use system API");
753 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
754 return nullptr;
755 }
756 asyncContext->reserve << ReturnType::BOOL << state;
757
758 napi_value promise = nullptr;
759 if (handle != nullptr) {
760 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
761 CHKRP(napi_get_undefined(env, &promise), GET_UNDEFINED);
762 } else {
763 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
764 }
765 AsyncCallbackWork(asyncContext);
766 return promise;
767 }
768
SetTouchpadData(napi_env env,napi_value handle,int32_t errorCode)769 napi_value JsPointerManager::SetTouchpadData(napi_env env, napi_value handle, int32_t errorCode)
770 {
771 CALL_DEBUG_ENTER;
772 if (errorCode == COMMON_USE_SYSAPI_ERROR) {
773 MMI_HILOGE("Non system applications use system API");
774 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
775 return nullptr;
776 }
777
778 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
779 CHKPP(asyncContext);
780
781 asyncContext->errorCode = errorCode;
782 asyncContext->reserve << ReturnType::VOID;
783
784 napi_value promise = nullptr;
785 if (handle != nullptr) {
786 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
787 if (napi_get_undefined(env, &promise) != napi_ok) {
788 CHKRP(napi_delete_reference(env, asyncContext->callback), DELETE_REFERENCE);
789 return nullptr;
790 }
791 } else {
792 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
793 }
794 AsyncCallbackWork(asyncContext);
795 return promise;
796 }
797
GetTouchpadBoolData(napi_env env,napi_value handle,bool data,int32_t errorCode)798 napi_value JsPointerManager::GetTouchpadBoolData(napi_env env, napi_value handle, bool data, int32_t errorCode)
799 {
800 CALL_DEBUG_ENTER;
801 if (errorCode == COMMON_USE_SYSAPI_ERROR) {
802 MMI_HILOGE("Non system applications use system API");
803 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
804 return nullptr;
805 }
806
807 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
808 CHKPP(asyncContext);
809
810 asyncContext->errorCode = errorCode;
811 asyncContext->reserve << ReturnType::BOOL << data;
812
813 napi_value promise = nullptr;
814 if (handle != nullptr) {
815 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
816 if (napi_get_undefined(env, &promise) != napi_ok) {
817 CHKRP(napi_delete_reference(env, asyncContext->callback), DELETE_REFERENCE);
818 return nullptr;
819 }
820 } else {
821 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
822 }
823 AsyncCallbackWork(asyncContext);
824 return promise;
825 }
826
GetTouchpadInt32Data(napi_env env,napi_value handle,int32_t data,int32_t errorCode)827 napi_value JsPointerManager::GetTouchpadInt32Data(napi_env env, napi_value handle, int32_t data, int32_t errorCode)
828 {
829 CALL_DEBUG_ENTER;
830 if (errorCode == COMMON_USE_SYSAPI_ERROR) {
831 MMI_HILOGE("Non system applications use system API");
832 THROWERR_CUSTOM(env, COMMON_USE_SYSAPI_ERROR, "Non system applications use system API");
833 return nullptr;
834 }
835
836 sptr<AsyncContext> asyncContext = new (std::nothrow) AsyncContext(env);
837 CHKPP(asyncContext);
838
839 asyncContext->errorCode = errorCode;
840 asyncContext->reserve << ReturnType::NUMBER << data;
841
842 napi_value promise = nullptr;
843 if (handle != nullptr) {
844 CHKRP(napi_create_reference(env, handle, 1, &asyncContext->callback), CREATE_REFERENCE);
845 if (napi_get_undefined(env, &promise) != napi_ok) {
846 CHKRP(napi_delete_reference(env, asyncContext->callback), DELETE_REFERENCE);
847 return nullptr;
848 }
849 } else {
850 CHKRP(napi_create_promise(env, &asyncContext->deferred, &promise), CREATE_PROMISE);
851 }
852 AsyncCallbackWork(asyncContext);
853 return promise;
854 }
855
SetTouchpadScrollSwitch(napi_env env,bool switchFlag,napi_value handle)856 napi_value JsPointerManager::SetTouchpadScrollSwitch(napi_env env, bool switchFlag, napi_value handle)
857 {
858 CALL_DEBUG_ENTER;
859 int32_t ret = InputManager::GetInstance()->SetTouchpadScrollSwitch(switchFlag);
860 return SetTouchpadData(env, handle, ret);
861 }
862
GetTouchpadScrollSwitch(napi_env env,napi_value handle)863 napi_value JsPointerManager::GetTouchpadScrollSwitch(napi_env env, napi_value handle)
864 {
865 CALL_DEBUG_ENTER;
866 bool switchFlag = true;
867 int32_t ret = InputManager::GetInstance()->GetTouchpadScrollSwitch(switchFlag);
868 return GetTouchpadBoolData(env, handle, switchFlag, ret);
869 }
870
SetTouchpadScrollDirection(napi_env env,bool state,napi_value handle)871 napi_value JsPointerManager::SetTouchpadScrollDirection(napi_env env, bool state, napi_value handle)
872 {
873 CALL_DEBUG_ENTER;
874 int32_t ret = InputManager::GetInstance()->SetTouchpadScrollDirection(state);
875 return SetTouchpadData(env, handle, ret);
876 }
877
GetTouchpadScrollDirection(napi_env env,napi_value handle)878 napi_value JsPointerManager::GetTouchpadScrollDirection(napi_env env, napi_value handle)
879 {
880 CALL_DEBUG_ENTER;
881 bool state = true;
882 int32_t ret = InputManager::GetInstance()->GetTouchpadScrollDirection(state);
883 return GetTouchpadBoolData(env, handle, state, ret);
884 }
885
SetTouchpadTapSwitch(napi_env env,bool switchFlag,napi_value handle)886 napi_value JsPointerManager::SetTouchpadTapSwitch(napi_env env, bool switchFlag, napi_value handle)
887 {
888 CALL_DEBUG_ENTER;
889 int32_t ret = InputManager::GetInstance()->SetTouchpadTapSwitch(switchFlag);
890 return SetTouchpadData(env, handle, ret);
891 }
892
GetTouchpadTapSwitch(napi_env env,napi_value handle)893 napi_value JsPointerManager::GetTouchpadTapSwitch(napi_env env, napi_value handle)
894 {
895 CALL_DEBUG_ENTER;
896 bool switchFlag = true;
897 int32_t ret = InputManager::GetInstance()->GetTouchpadTapSwitch(switchFlag);
898 return GetTouchpadBoolData(env, handle, switchFlag, ret);
899 }
SetTouchpadPointerSpeed(napi_env env,int32_t speed,napi_value handle)900 napi_value JsPointerManager::SetTouchpadPointerSpeed(napi_env env, int32_t speed, napi_value handle)
901 {
902 CALL_DEBUG_ENTER;
903 int32_t ret = InputManager::GetInstance()->SetTouchpadPointerSpeed(speed);
904 return SetTouchpadData(env, handle, ret);
905 }
906
GetTouchpadPointerSpeed(napi_env env,napi_value handle)907 napi_value JsPointerManager::GetTouchpadPointerSpeed(napi_env env, napi_value handle)
908 {
909 CALL_DEBUG_ENTER;
910 int32_t speed = 0;
911 int32_t ret = InputManager::GetInstance()->GetTouchpadPointerSpeed(speed);
912 return GetTouchpadInt32Data(env, handle, speed, ret);
913 }
914
SetTouchpadPinchSwitch(napi_env env,bool switchFlag,napi_value handle)915 napi_value JsPointerManager::SetTouchpadPinchSwitch(napi_env env, bool switchFlag, napi_value handle)
916 {
917 CALL_DEBUG_ENTER;
918 int32_t ret = InputManager::GetInstance()->SetTouchpadPinchSwitch(switchFlag);
919 return SetTouchpadData(env, handle, ret);
920 }
921
GetTouchpadPinchSwitch(napi_env env,napi_value handle)922 napi_value JsPointerManager::GetTouchpadPinchSwitch(napi_env env, napi_value handle)
923 {
924 CALL_DEBUG_ENTER;
925 bool switchFlag = true;
926 int32_t ret = InputManager::GetInstance()->GetTouchpadPinchSwitch(switchFlag);
927 return GetTouchpadBoolData(env, handle, switchFlag, ret);
928 }
929
SetTouchpadSwipeSwitch(napi_env env,bool switchFlag,napi_value handle)930 napi_value JsPointerManager::SetTouchpadSwipeSwitch(napi_env env, bool switchFlag, napi_value handle)
931 {
932 CALL_DEBUG_ENTER;
933 int32_t ret = InputManager::GetInstance()->SetTouchpadSwipeSwitch(switchFlag);
934 return SetTouchpadData(env, handle, ret);
935 }
936
GetTouchpadSwipeSwitch(napi_env env,napi_value handle)937 napi_value JsPointerManager::GetTouchpadSwipeSwitch(napi_env env, napi_value handle)
938 {
939 CALL_DEBUG_ENTER;
940 bool switchFlag = true;
941 int32_t ret = InputManager::GetInstance()->GetTouchpadSwipeSwitch(switchFlag);
942 return GetTouchpadBoolData(env, handle, switchFlag, ret);
943 }
944
SetTouchpadRightClickType(napi_env env,int32_t type,napi_value handle)945 napi_value JsPointerManager::SetTouchpadRightClickType(napi_env env, int32_t type, napi_value handle)
946 {
947 CALL_DEBUG_ENTER;
948 int32_t ret = InputManager::GetInstance()->SetTouchpadRightClickType(type);
949 return SetTouchpadData(env, handle, ret);
950 }
951
GetTouchpadRightClickType(napi_env env,napi_value handle)952 napi_value JsPointerManager::GetTouchpadRightClickType(napi_env env, napi_value handle)
953 {
954 CALL_DEBUG_ENTER;
955 int32_t type = 1;
956 int32_t ret = InputManager::GetInstance()->GetTouchpadRightClickType(type);
957 return GetTouchpadInt32Data(env, handle, type, ret);
958 }
959
SetTouchpadRotateSwitch(napi_env env,bool rotateSwitch,napi_value handle)960 napi_value JsPointerManager::SetTouchpadRotateSwitch(napi_env env, bool rotateSwitch, napi_value handle)
961 {
962 CALL_DEBUG_ENTER;
963 int32_t ret = InputManager::GetInstance()->SetTouchpadRotateSwitch(rotateSwitch);
964 return SetTouchpadData(env, handle, ret);
965 }
966
GetTouchpadRotateSwitch(napi_env env,napi_value handle)967 napi_value JsPointerManager::GetTouchpadRotateSwitch(napi_env env, napi_value handle)
968 {
969 CALL_DEBUG_ENTER;
970 bool rotateSwitch = true;
971 int32_t ret = InputManager::GetInstance()->GetTouchpadRotateSwitch(rotateSwitch);
972 return GetTouchpadBoolData(env, handle, rotateSwitch, ret);
973 }
974
SetTouchpadDoubleTapAndDragState(napi_env env,bool switchFlag,napi_value handle)975 napi_value JsPointerManager::SetTouchpadDoubleTapAndDragState(napi_env env, bool switchFlag, napi_value handle)
976 {
977 CALL_DEBUG_ENTER;
978 int32_t ret = InputManager::GetInstance()->SetTouchpadDoubleTapAndDragState(switchFlag);
979 return SetTouchpadData(env, handle, ret);
980 }
981
GetTouchpadDoubleTapAndDragState(napi_env env,napi_value handle)982 napi_value JsPointerManager::GetTouchpadDoubleTapAndDragState(napi_env env, napi_value handle)
983 {
984 CALL_DEBUG_ENTER;
985 bool switchFlag = true;
986 int32_t ret = InputManager::GetInstance()->GetTouchpadDoubleTapAndDragState(switchFlag);
987 return GetTouchpadBoolData(env, handle, switchFlag, ret);
988 }
989
EnableHardwareCursorStats(napi_env env,bool enable)990 napi_value JsPointerManager::EnableHardwareCursorStats(napi_env env, bool enable)
991 {
992 CALL_DEBUG_ENTER;
993 InputManager::GetInstance()->EnableHardwareCursorStats(enable);
994 napi_value result = nullptr;
995 if (napi_get_undefined(env, &result) != napi_ok) {
996 MMI_HILOGE("Get undefined result is failed");
997 return nullptr;
998 }
999 return result;
1000 }
1001
GetHardwareCursorStats(napi_env env)1002 napi_value JsPointerManager::GetHardwareCursorStats(napi_env env)
1003 {
1004 CALL_DEBUG_ENTER;
1005 uint32_t frameCount = 0;
1006 uint32_t vsyncCount = 0;
1007 InputManager::GetInstance()->GetHardwareCursorStats(frameCount, vsyncCount);
1008 napi_value result = nullptr;
1009 napi_status status = napi_create_object(env, &result);
1010 if (status != napi_ok) {
1011 MMI_HILOGE("Napi create object is failed");
1012 return nullptr;
1013 }
1014 MMI_HILOGD("GetHardwareCursorStats, frameCount:%{public}d, vsyncCount:%{public}d",
1015 frameCount, vsyncCount);
1016 napi_value frameNapiCount;
1017 NAPI_CALL(env, napi_create_uint32(env, frameCount, &frameNapiCount));
1018 napi_value vsyncNapiCount;
1019 NAPI_CALL(env, napi_create_uint32(env, vsyncCount, &vsyncNapiCount));
1020 status = napi_set_named_property(env, result, "frameCount", frameNapiCount);
1021 if (status != napi_ok) {
1022 MMI_HILOGE("Napi set frameCount named property is failed");
1023 return nullptr;
1024 }
1025 status = napi_set_named_property(env, result, "vsyncCount", vsyncNapiCount);
1026 if (status != napi_ok) {
1027 MMI_HILOGE("Napi set vsyncCount named property is failed");
1028 return nullptr;
1029 }
1030 return result;
1031 }
1032 } // namespace MMI
1033 } // namespace OHOS