1 /*
2 * Copyright (c) 2024 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 #include "paste_data_impl.h"
16
17 using namespace OHOS::MiscServices;
18
19 namespace OHOS {
20 namespace MiscServicesCj {
21
GetClassType()22 OHOS::FFI::RuntimeType *PasteDataImpl::GetClassType()
23 {
24 static OHOS::FFI::RuntimeType runtimeType = OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("PasteDataImpl");
25 return &runtimeType;
26 }
27
CreateCjPasteDataObject(std::string mimeType, CJValueType value)28 int64_t CreateCjPasteDataObject(std::string mimeType, CJValueType value)
29 {
30 auto pasteDataImpl = FFI::FFIData::Create<PasteDataImpl>(mimeType, value);
31 return pasteDataImpl->GetID();
32 }
33
PasteDataImpl()34 PasteDataImpl::PasteDataImpl()
35 {
36 value_ = std::make_shared<PasteData>();
37 }
38
PasteDataImpl(std::shared_ptr<MiscServices::PasteData> pasteData)39 PasteDataImpl::PasteDataImpl(std::shared_ptr<MiscServices::PasteData> pasteData)
40 {
41 value_ = pasteData;
42 }
43
PasteDataImpl(std::string mimeType, CJValueType value)44 PasteDataImpl::PasteDataImpl(std::string mimeType, CJValueType value)
45 {
46 if (mimeType == "text/html") {
47 CreateHtmlData(mimeType, value);
48 } else if (mimeType == "text/plain") {
49 CreatePlainTextData(mimeType, value);
50 } else if (mimeType == "text/uri") {
51 CreateUriData(mimeType, value);
52 } else if (mimeType == "pixelMap") {
53 CreatePixelMapData(mimeType, value);
54 } else if (mimeType == "text/want") {
55 CreateWantData(mimeType, value);
56 } else {
57 std::vector<uint8_t> arrayBuf(reinterpret_cast<uint8_t *>(value.arrayBufferData),
58 reinterpret_cast<uint8_t *>(value.arrayBufferData) + value.arrayBufferSize);
59 value_ = PasteboardClient::GetInstance()->CreateKvData(mimeType, arrayBuf);
60 }
61 }
62
GetRealPasteData()63 std::shared_ptr<MiscServices::PasteData> PasteDataImpl::GetRealPasteData()
64 {
65 return value_;
66 }
67
CreateHtmlData(std::string mimeType, CJValueType value)68 void PasteDataImpl::CreateHtmlData(std::string mimeType, CJValueType value)
69 {
70 value_ = PasteboardClient::GetInstance()->CreateHtmlData(value.stringValue);
71 }
72
CreatePlainTextData(std::string mimeType, CJValueType value)73 void PasteDataImpl::CreatePlainTextData(std::string mimeType, CJValueType value)
74 {
75 value_ = PasteboardClient::GetInstance()->CreatePlainTextData(value.stringValue);
76 }
77
CreateUriData(std::string mimeType, CJValueType value)78 void PasteDataImpl::CreateUriData(std::string mimeType, CJValueType value)
79 {
80 value_ = PasteboardClient::GetInstance()->CreateUriData(OHOS::Uri(value.stringValue));
81 }
82
CreatePixelMapData(std::string mimeType, CJValueType value)83 void PasteDataImpl::CreatePixelMapData(std::string mimeType, CJValueType value)
84 {
85 value_ = PasteboardClient::GetInstance()->CreatePixelMapData(value.pixelMap);
86 }
87
CreateWantData(std::string mimeType, CJValueType value)88 void PasteDataImpl::CreateWantData(std::string mimeType, CJValueType value) {}
89
90 } // namespace MiscServicesCj
91 }