• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #ifndef N_NAPI_PASTEDATA_RECORD_H
16 #define N_NAPI_PASTEDATA_RECORD_H
17 
18 #include "napi/native_api.h"
19 #include "napi/native_node_api.h"
20 #include "paste_data.h"
21 #include "paste_data_record.h"
22 #include "pasteboard_client.h"
23 #include "pixel_map_napi.h"
24 #include "uri.h"
25 
26 namespace OHOS {
27 namespace MiscServicesNapi {
28 class PasteDataRecordNapi {
29 public:
30     static napi_value PasteDataRecordInit(napi_env env, napi_value exports);
31     static napi_value New(napi_env env, napi_callback_info info);
32     static napi_status NewInstance(napi_env env, napi_value &instance);
33     static void Destructor(napi_env env, void *nativeObject, void *finalize_hint);
34     static bool NewInstanceByRecord(
35         napi_env env, napi_value &instance, const std::shared_ptr<MiscServices::PasteDataRecord> &record);
36     static bool NewHtmlTextRecordInstance(napi_env env, const std::string &text, napi_value &instance);
37     static bool NewPlainTextRecordInstance(napi_env env, const std::string &text, napi_value &instance);
38     static bool NewPixelMapRecordInstance(
39         napi_env env, const std::shared_ptr<OHOS::Media::PixelMap> pixelMap, napi_value &instance);
40     static bool NewUriRecordInstance(napi_env env, const std::string &text, napi_value &instance);
41     static bool NewWantRecordInstance(
42         napi_env env, const std::shared_ptr<OHOS::AAFwk::Want> want, napi_value &instance);
43     static bool NewKvRecordInstance(
44         napi_env env, const std::string &mimeType, const std::vector<uint8_t> &arrayBuffer, napi_value &instance);
45     static napi_value CreatKvData(napi_env env, std::shared_ptr<MiscServices::MineCustomData> customData);
46     static std::shared_ptr<MiscServices::MineCustomData> GetNativeKvData(napi_env env, napi_value napiValue);
47     napi_value SetNapiKvData(napi_env env, std::shared_ptr<MiscServices::MineCustomData> customData);
48     PasteDataRecordNapi();
49     ~PasteDataRecordNapi();
50 
51     static napi_value ConvertToText(napi_env env, napi_callback_info info);
52     static napi_value ConvertToTextV9(napi_env env, napi_callback_info info);
53     static napi_value ToPlainText(napi_env env, napi_callback_info info);
54 
55     std::shared_ptr<MiscServices::PasteDataRecord> value_;
56 
57 private:
58     void JSFillInstance(napi_env env, napi_value &instance);
59     void SetNamedPropertyByStr(napi_env env, napi_value &instance, const char *propName, const char *propValue);
60     napi_env env_;
61 };
62 } // namespace MiscServicesNapi
63 } // namespace OHOS
64 #endif