1 /* 2 * Copyright (c) 2023 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 #ifndef JS_SHORT_KEY_MANAGER_H 17 #define JS_SHORT_KEY_MANAGER_H 18 19 #include <memory> 20 21 #include "napi/native_api.h" 22 #include "napi/native_node_api.h" 23 #include "refbase.h" 24 #include "utils/log.h" 25 26 #include "define_multimodal.h" 27 #include "error_multimodal.h" 28 #include "input_manager.h" 29 #include "napi_constants.h" 30 #include "stream_buffer.h" 31 #include "util_napi.h" 32 #include "util_napi_error.h" 33 34 namespace OHOS { 35 namespace MMI { 36 class JsCommon { 37 public: 38 static bool TypeOf(napi_env env, napi_value value, napi_valuetype type); 39 }; 40 41 struct AsyncContext : RefBase { 42 napi_env env { nullptr }; 43 napi_async_work work { nullptr }; 44 napi_deferred deferred { nullptr }; 45 napi_ref callback { nullptr }; 46 int32_t errorCode { -1 }; 47 StreamBuffer reserve; AsyncContextAsyncContext48 explicit AsyncContext(napi_env env) : env(env) {} 49 ~AsyncContext(); 50 }; 51 52 class JsShortKeyManager final { 53 public: 54 JsShortKeyManager() = default; 55 ~JsShortKeyManager() = default; 56 DISALLOW_COPY_AND_MOVE(JsShortKeyManager); 57 58 void ResetEnv(); 59 napi_value SetKeyDownDuration(napi_env env, const std::string &key, int32_t keyDownDuration, 60 napi_value handle = nullptr); 61 }; 62 } // namespace MMI 63 } // namespace OHOS 64 #endif // JS_SHORT_KEY_MANAGER_H