123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License.
523b3eb3cSopenharmony_ci * You may obtain a copy of the License at
623b3eb3cSopenharmony_ci *
723b3eb3cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
823b3eb3cSopenharmony_ci *
923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and
1323b3eb3cSopenharmony_ci * limitations under the License.
1423b3eb3cSopenharmony_ci */
1523b3eb3cSopenharmony_ci
1623b3eb3cSopenharmony_ci#include "adapter/preview/entrance/clipboard/clipboard_impl.h"
1723b3eb3cSopenharmony_ci
1823b3eb3cSopenharmony_ci#include "adapter/preview/entrance/ace_preview_helper.h"
1923b3eb3cSopenharmony_ci#include "frameworks/base/utils/utils.h"
2023b3eb3cSopenharmony_ci
2123b3eb3cSopenharmony_cinamespace OHOS::Ace::Platform {
2223b3eb3cSopenharmony_ci
2323b3eb3cSopenharmony_civoid ClipboardImpl::AddPixelMapRecord(const RefPtr<PasteDataMix>& pasteData, const RefPtr<PixelMap>& pixmap) {}
2423b3eb3cSopenharmony_civoid ClipboardImpl::AddImageRecord(const RefPtr<PasteDataMix>& pasteData, const std::string& uri) {}
2523b3eb3cSopenharmony_civoid ClipboardImpl::AddTextRecord(const RefPtr<PasteDataMix>& pasteData, const std::string& selectedStr) {}
2623b3eb3cSopenharmony_civoid ClipboardImpl::AddSpanStringRecord(const RefPtr<PasteDataMix>& pasteData, std::vector<uint8_t>& data) {}
2723b3eb3cSopenharmony_civoid ClipboardImpl::AddMultiTypeRecord(
2823b3eb3cSopenharmony_ci    const RefPtr<PasteDataMix>& pasteData, const RefPtr<MultiTypeRecordMix>& multiTypeRecord) {};
2923b3eb3cSopenharmony_civoid ClipboardImpl::SetData(const RefPtr<PasteDataMix>& pasteData, CopyOptions copyOption) {}
3023b3eb3cSopenharmony_civoid ClipboardImpl::GetData(const std::function<void(const std::string&, bool isLastRecord)>& textCallback,
3123b3eb3cSopenharmony_ci    const std::function<void(const RefPtr<PixelMap>&, bool isLastRecord)>& pixelMapCallback,
3223b3eb3cSopenharmony_ci    const std::function<void(const std::string&, bool isLastRecord)>& urlCallback, bool syncMode)
3323b3eb3cSopenharmony_ci{}
3423b3eb3cSopenharmony_civoid ClipboardImpl::GetSpanStringData(
3523b3eb3cSopenharmony_ci    const std::function<void(std::vector<std::vector<uint8_t>>&, const std::string&, bool&)>& callback, bool syncMode)
3623b3eb3cSopenharmony_ci{}
3723b3eb3cSopenharmony_ci
3823b3eb3cSopenharmony_ciRefPtr<PasteDataMix> ClipboardImpl::CreatePasteDataMix()
3923b3eb3cSopenharmony_ci{
4023b3eb3cSopenharmony_ci    return AceType::MakeRefPtr<PasteDataMix>();
4123b3eb3cSopenharmony_ci}
4223b3eb3cSopenharmony_ci
4323b3eb3cSopenharmony_civoid ClipboardImpl::SetData(const std::string& data, CopyOptions copyOption, bool isDragData)
4423b3eb3cSopenharmony_ci{
4523b3eb3cSopenharmony_ci    CHECK_NULL_VOID(taskExecutor_);
4623b3eb3cSopenharmony_ci    taskExecutor_->PostTask(
4723b3eb3cSopenharmony_ci        [data] {
4823b3eb3cSopenharmony_ci            auto setClipboardData = AcePreviewHelper::GetInstance()->GetCallbackOfSetClipboardData();
4923b3eb3cSopenharmony_ci            if (setClipboardData) {
5023b3eb3cSopenharmony_ci                setClipboardData(data);
5123b3eb3cSopenharmony_ci            }
5223b3eb3cSopenharmony_ci        },
5323b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIClipboardSetData");
5423b3eb3cSopenharmony_ci}
5523b3eb3cSopenharmony_ci
5623b3eb3cSopenharmony_civoid ClipboardImpl::GetData(const std::function<void(const std::string&)>& callback, bool syncMode)
5723b3eb3cSopenharmony_ci{
5823b3eb3cSopenharmony_ci    if (!taskExecutor_ || !callback) {
5923b3eb3cSopenharmony_ci        return;
6023b3eb3cSopenharmony_ci    }
6123b3eb3cSopenharmony_ci    taskExecutor_->PostTask(
6223b3eb3cSopenharmony_ci        [callback] {
6323b3eb3cSopenharmony_ci            auto getClipboardData = AcePreviewHelper::GetInstance()->GetCallbackOfGetClipboardData();
6423b3eb3cSopenharmony_ci            if (callback && getClipboardData) {
6523b3eb3cSopenharmony_ci                callback(getClipboardData());
6623b3eb3cSopenharmony_ci            }
6723b3eb3cSopenharmony_ci        },
6823b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIClipboardGetData");
6923b3eb3cSopenharmony_ci}
7023b3eb3cSopenharmony_ci
7123b3eb3cSopenharmony_civoid ClipboardImpl::HasData(const std::function<void(bool hasData)>& callback)
7223b3eb3cSopenharmony_ci{
7323b3eb3cSopenharmony_ci    if (!taskExecutor_ || !callback) {
7423b3eb3cSopenharmony_ci        return;
7523b3eb3cSopenharmony_ci    }
7623b3eb3cSopenharmony_ci    taskExecutor_->PostTask(
7723b3eb3cSopenharmony_ci        [callback] {
7823b3eb3cSopenharmony_ci            auto getClipboardData = AcePreviewHelper::GetInstance()->GetCallbackOfGetClipboardData();
7923b3eb3cSopenharmony_ci            if (callback && getClipboardData) {
8023b3eb3cSopenharmony_ci                callback(!getClipboardData().empty());
8123b3eb3cSopenharmony_ci            }
8223b3eb3cSopenharmony_ci        },
8323b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIClipboardHasData");
8423b3eb3cSopenharmony_ci}
8523b3eb3cSopenharmony_ci
8623b3eb3cSopenharmony_civoid ClipboardImpl::HasDataType(
8723b3eb3cSopenharmony_ci    const std::function<void(bool hasData)>& callback, const std::vector<std::string>& mimeTypes)
8823b3eb3cSopenharmony_ci{
8923b3eb3cSopenharmony_ci    HasData(callback);
9023b3eb3cSopenharmony_ci}
9123b3eb3cSopenharmony_ci
9223b3eb3cSopenharmony_civoid ClipboardImpl::SetPixelMapData(const RefPtr<PixelMap>& pixmap, CopyOptions copyOption)
9323b3eb3cSopenharmony_ci{
9423b3eb3cSopenharmony_ci    if (!taskExecutor_ || !callbackSetClipboardPixmapData_) {
9523b3eb3cSopenharmony_ci        return;
9623b3eb3cSopenharmony_ci    }
9723b3eb3cSopenharmony_ci    taskExecutor_->PostTask([callbackSetClipboardPixmapData = callbackSetClipboardPixmapData_,
9823b3eb3cSopenharmony_ci                                pixmap] { callbackSetClipboardPixmapData(pixmap); },
9923b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIClipboardSetPixelMapData");
10023b3eb3cSopenharmony_ci}
10123b3eb3cSopenharmony_ci
10223b3eb3cSopenharmony_civoid ClipboardImpl::GetPixelMapData(const std::function<void(const RefPtr<PixelMap>&)>& callback, bool syncMode)
10323b3eb3cSopenharmony_ci{
10423b3eb3cSopenharmony_ci    if (!taskExecutor_ || !callbackGetClipboardPixmapData_ || !callback) {
10523b3eb3cSopenharmony_ci        return;
10623b3eb3cSopenharmony_ci    }
10723b3eb3cSopenharmony_ci    taskExecutor_->PostTask([callbackGetClipboardPixmapData = callbackGetClipboardPixmapData_,
10823b3eb3cSopenharmony_ci                                callback] { callback(callbackGetClipboardPixmapData()); },
10923b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIClipboardGetPixelMapData");
11023b3eb3cSopenharmony_ci}
11123b3eb3cSopenharmony_ci
11223b3eb3cSopenharmony_civoid ClipboardImpl::Clear() {}
11323b3eb3cSopenharmony_ci
11423b3eb3cSopenharmony_civoid ClipboardImpl::RegisterCallbackSetClipboardPixmapData(CallbackSetClipboardPixmapData callback)
11523b3eb3cSopenharmony_ci{
11623b3eb3cSopenharmony_ci    callbackSetClipboardPixmapData_ = callback;
11723b3eb3cSopenharmony_ci}
11823b3eb3cSopenharmony_ci
11923b3eb3cSopenharmony_civoid ClipboardImpl::RegisterCallbackGetClipboardPixmapData(CallbackGetClipboardPixmapData callback)
12023b3eb3cSopenharmony_ci{
12123b3eb3cSopenharmony_ci    callbackGetClipboardPixmapData_ = callback;
12223b3eb3cSopenharmony_ci}
12323b3eb3cSopenharmony_ci} // namespace OHOS::Ace::Platform
124