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 "ohos_adapter/bridge/ark_paste_data_record_adapter_wrapper.h"
17
18 #include "ohos_adapter/bridge/ark_clip_board_image_data_adapter_impl.h"
19
20 namespace OHOS::NWeb {
21
NewRecord(const std::string & mimeType)22 std::shared_ptr<PasteDataRecordAdapter> PasteDataRecordAdapter::NewRecord(const std::string& mimeType)
23 {
24 ArkWebString str = ArkWebStringClassToStruct(mimeType);
25 ArkWebRefPtr<ArkWeb::ArkPasteDataRecordAdapter> arkPasteDataRecordAdapter =
26 ArkWeb::ArkPasteDataRecordAdapter::NewRecord(str);
27 ArkWebStringStructRelease(str);
28 return std::make_shared<ArkWeb::ArkPasteDataRecordAdapterWrapper>(arkPasteDataRecordAdapter);
29 }
30
NewRecord(const std::string & mimeType,std::shared_ptr<std::string> htmlText,std::shared_ptr<std::string> plainText)31 std::shared_ptr<PasteDataRecordAdapter> PasteDataRecordAdapter::NewRecord(
32 const std::string& mimeType, std::shared_ptr<std::string> htmlText, std::shared_ptr<std::string> plainText)
33 {
34 ArkWebString str = ArkWebStringClassToStruct(mimeType);
35 ArkWebRefPtr<ArkWeb::ArkPasteDataRecordAdapter> arkPasteDataRecordAdapter =
36 ArkWeb::ArkPasteDataRecordAdapter::NewRecord(str, (void*)(&htmlText), (void*)(&plainText));
37 ArkWebStringStructRelease(str);
38 return std::make_shared<ArkWeb::ArkPasteDataRecordAdapterWrapper>(arkPasteDataRecordAdapter);
39 }
40
41 } // namespace OHOS::NWeb
42
43 namespace OHOS::ArkWeb {
44
ArkPasteDataRecordAdapterWrapper(ArkWebRefPtr<ArkPasteDataRecordAdapter> ref)45 ArkPasteDataRecordAdapterWrapper::ArkPasteDataRecordAdapterWrapper(ArkWebRefPtr<ArkPasteDataRecordAdapter> ref)
46 : ctocpp_(ref)
47 {}
48
SetHtmlText(std::shared_ptr<std::string> htmlText)49 bool ArkPasteDataRecordAdapterWrapper::SetHtmlText(std::shared_ptr<std::string> htmlText)
50 {
51 return ctocpp_->SetHtmlText((void*)(&htmlText));
52 }
53
SetPlainText(std::shared_ptr<std::string> plainText)54 bool ArkPasteDataRecordAdapterWrapper::SetPlainText(std::shared_ptr<std::string> plainText)
55 {
56 return ctocpp_->SetPlainText((void*)(&plainText));
57 }
58
SetImgData(std::shared_ptr<NWeb::ClipBoardImageDataAdapter> imageData)59 bool ArkPasteDataRecordAdapterWrapper::SetImgData(std::shared_ptr<NWeb::ClipBoardImageDataAdapter> imageData)
60 {
61 if (!imageData) {
62 return ctocpp_->SetImgData(nullptr);
63 }
64 return ctocpp_->SetImgData(new ArkClipBoardImageDataAdapterImpl(imageData));
65 }
66
GetMimeType()67 std::string ArkPasteDataRecordAdapterWrapper::GetMimeType()
68 {
69 ArkWebString str = ctocpp_->GetMimeType();
70 std::string result = ArkWebStringStructToClass(str);
71 ArkWebStringStructRelease(str);
72 return result;
73 }
74
GetHtmlText()75 std::shared_ptr<std::string> ArkPasteDataRecordAdapterWrapper::GetHtmlText()
76 {
77 std::shared_ptr<std::string> result;
78 ctocpp_->GetHtmlText((void*)&result);
79 return result;
80 }
81
GetPlainText()82 std::shared_ptr<std::string> ArkPasteDataRecordAdapterWrapper::GetPlainText()
83 {
84 std::shared_ptr<std::string> result;
85 ctocpp_->GetPlainText((void*)&result);
86 return result;
87 }
88
GetImgData(std::shared_ptr<NWeb::ClipBoardImageDataAdapter> imageData)89 bool ArkPasteDataRecordAdapterWrapper::GetImgData(std::shared_ptr<NWeb::ClipBoardImageDataAdapter> imageData)
90 {
91 if (!imageData) {
92 return ctocpp_->GetImgData(nullptr);
93 }
94 return ctocpp_->GetImgData(new ArkClipBoardImageDataAdapterImpl(imageData));
95 }
96
SetUri(const std::string & uriString)97 bool ArkPasteDataRecordAdapterWrapper::SetUri(const std::string& uriString)
98 {
99 ArkWebString str = ArkWebStringClassToStruct(uriString);
100 bool result = ctocpp_->SetUri(str);
101 ArkWebStringStructRelease(str);
102 return result;
103 }
104
SetCustomData(NWeb::PasteCustomData & data)105 bool ArkPasteDataRecordAdapterWrapper::SetCustomData(NWeb::PasteCustomData& data)
106 {
107 return ctocpp_->SetCustomData((void*)(&data));
108 }
109
GetUri()110 std::shared_ptr<std::string> ArkPasteDataRecordAdapterWrapper::GetUri()
111 {
112 std::shared_ptr<std::string> result;
113 ctocpp_->GetUri((void*)&result);
114 return result;
115 }
116
GetCustomData()117 std::shared_ptr<NWeb::PasteCustomData> ArkPasteDataRecordAdapterWrapper::GetCustomData()
118 {
119 std::shared_ptr<NWeb::PasteCustomData> result;
120 ctocpp_->GetCustomData((void*)&result);
121 return result;
122 }
123
124 } // namespace OHOS::ArkWeb
125