1bc03f14fSopenharmony_ci/* 2bc03f14fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3bc03f14fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bc03f14fSopenharmony_ci * you may not use this file except in compliance with the License. 5bc03f14fSopenharmony_ci * You may obtain a copy of the License at 6bc03f14fSopenharmony_ci * 7bc03f14fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bc03f14fSopenharmony_ci * 9bc03f14fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bc03f14fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bc03f14fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bc03f14fSopenharmony_ci * See the License for the specific language governing permissions and 13bc03f14fSopenharmony_ci * limitations under the License. 14bc03f14fSopenharmony_ci */ 15bc03f14fSopenharmony_ci#include "paste_data_impl.h" 16bc03f14fSopenharmony_ci 17bc03f14fSopenharmony_ciusing namespace OHOS::MiscServices; 18bc03f14fSopenharmony_ci 19bc03f14fSopenharmony_cinamespace OHOS { 20bc03f14fSopenharmony_cinamespace MiscServicesCj { 21bc03f14fSopenharmony_ci 22bc03f14fSopenharmony_ciOHOS::FFI::RuntimeType *PasteDataImpl::GetClassType() 23bc03f14fSopenharmony_ci{ 24bc03f14fSopenharmony_ci static OHOS::FFI::RuntimeType runtimeType = OHOS::FFI::RuntimeType::Create<OHOS::FFI::FFIData>("PasteDataImpl"); 25bc03f14fSopenharmony_ci return &runtimeType; 26bc03f14fSopenharmony_ci} 27bc03f14fSopenharmony_ci 28bc03f14fSopenharmony_ciint64_t CreateCjPasteDataObject(std::string mimeType, CJValueType value) 29bc03f14fSopenharmony_ci{ 30bc03f14fSopenharmony_ci auto pasteDataImpl = FFI::FFIData::Create<PasteDataImpl>(mimeType, value); 31bc03f14fSopenharmony_ci return pasteDataImpl->GetID(); 32bc03f14fSopenharmony_ci} 33bc03f14fSopenharmony_ci 34bc03f14fSopenharmony_ciPasteDataImpl::PasteDataImpl() 35bc03f14fSopenharmony_ci{ 36bc03f14fSopenharmony_ci value_ = std::make_shared<PasteData>(); 37bc03f14fSopenharmony_ci} 38bc03f14fSopenharmony_ci 39bc03f14fSopenharmony_ciPasteDataImpl::PasteDataImpl(std::shared_ptr<MiscServices::PasteData> pasteData) 40bc03f14fSopenharmony_ci{ 41bc03f14fSopenharmony_ci value_ = pasteData; 42bc03f14fSopenharmony_ci} 43bc03f14fSopenharmony_ci 44bc03f14fSopenharmony_ciPasteDataImpl::PasteDataImpl(std::string mimeType, CJValueType value) 45bc03f14fSopenharmony_ci{ 46bc03f14fSopenharmony_ci if (mimeType == "text/html") { 47bc03f14fSopenharmony_ci CreateHtmlData(mimeType, value); 48bc03f14fSopenharmony_ci } else if (mimeType == "text/plain") { 49bc03f14fSopenharmony_ci CreatePlainTextData(mimeType, value); 50bc03f14fSopenharmony_ci } else if (mimeType == "text/uri") { 51bc03f14fSopenharmony_ci CreateUriData(mimeType, value); 52bc03f14fSopenharmony_ci } else if (mimeType == "pixelMap") { 53bc03f14fSopenharmony_ci CreatePixelMapData(mimeType, value); 54bc03f14fSopenharmony_ci } else if (mimeType == "text/want") { 55bc03f14fSopenharmony_ci CreateWantData(mimeType, value); 56bc03f14fSopenharmony_ci } else { 57bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuf(reinterpret_cast<uint8_t *>(value.arrayBufferData), 58bc03f14fSopenharmony_ci reinterpret_cast<uint8_t *>(value.arrayBufferData) + value.arrayBufferSize); 59bc03f14fSopenharmony_ci value_ = PasteboardClient::GetInstance()->CreateKvData(mimeType, arrayBuf); 60bc03f14fSopenharmony_ci } 61bc03f14fSopenharmony_ci} 62bc03f14fSopenharmony_ci 63bc03f14fSopenharmony_cistd::shared_ptr<MiscServices::PasteData> PasteDataImpl::GetRealPasteData() 64bc03f14fSopenharmony_ci{ 65bc03f14fSopenharmony_ci return value_; 66bc03f14fSopenharmony_ci} 67bc03f14fSopenharmony_ci 68bc03f14fSopenharmony_civoid PasteDataImpl::CreateHtmlData(std::string mimeType, CJValueType value) 69bc03f14fSopenharmony_ci{ 70bc03f14fSopenharmony_ci value_ = PasteboardClient::GetInstance()->CreateHtmlData(value.stringValue); 71bc03f14fSopenharmony_ci} 72bc03f14fSopenharmony_ci 73bc03f14fSopenharmony_civoid PasteDataImpl::CreatePlainTextData(std::string mimeType, CJValueType value) 74bc03f14fSopenharmony_ci{ 75bc03f14fSopenharmony_ci value_ = PasteboardClient::GetInstance()->CreatePlainTextData(value.stringValue); 76bc03f14fSopenharmony_ci} 77bc03f14fSopenharmony_ci 78bc03f14fSopenharmony_civoid PasteDataImpl::CreateUriData(std::string mimeType, CJValueType value) 79bc03f14fSopenharmony_ci{ 80bc03f14fSopenharmony_ci value_ = PasteboardClient::GetInstance()->CreateUriData(OHOS::Uri(value.stringValue)); 81bc03f14fSopenharmony_ci} 82bc03f14fSopenharmony_ci 83bc03f14fSopenharmony_civoid PasteDataImpl::CreatePixelMapData(std::string mimeType, CJValueType value) 84bc03f14fSopenharmony_ci{ 85bc03f14fSopenharmony_ci value_ = PasteboardClient::GetInstance()->CreatePixelMapData(value.pixelMap); 86bc03f14fSopenharmony_ci} 87bc03f14fSopenharmony_ci 88bc03f14fSopenharmony_civoid PasteDataImpl::CreateWantData(std::string mimeType, CJValueType value) {} 89bc03f14fSopenharmony_ci 90bc03f14fSopenharmony_ci} // namespace MiscServicesCj 91bc03f14fSopenharmony_ci}