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 #ifndef PASTEBOARD_CLIENT_ADAPTER_H 17 #define PASTEBOARD_CLIENT_ADAPTER_H 18 19 #include <map> 20 #include <memory> 21 #include <vector> 22 23 namespace OHOS::NWeb { 24 enum class ClipBoardImageColorType { 25 COLOR_TYPE_RGBA_8888, 26 COLOR_TYPE_BGRA_8888, 27 COLOR_TYPE_UNKNOWN 28 }; 29 30 enum class ClipBoardImageAlphaType { 31 ALPHA_TYPE_OPAQUE, 32 ALPHA_TYPE_PREMULTIPLIED, 33 ALPHA_TYPE_POSTMULTIPLIED, 34 ALPHA_TYPE_UNKNOWN 35 }; 36 37 typedef struct ClipBoardImageDataTag { 38 ClipBoardImageColorType colorType; 39 ClipBoardImageAlphaType alphaType; 40 uint32_t *data; 41 size_t dataSize; 42 size_t rowBytes; 43 int32_t width; 44 int32_t height; 45 } ClipBoardImageData; 46 47 class PasteDataRecordAdapter; 48 class PasteDataAdapter; 49 using PasteRecordList = std::vector<std::shared_ptr<PasteDataRecordAdapter>>; 50 using PasteCustomData = std::map<std::string, std::vector<uint8_t>>; 51 52 class PasteboardObserverAdapter { 53 public: 54 PasteboardObserverAdapter() = default; 55 56 virtual ~PasteboardObserverAdapter() = default; 57 58 virtual void OnPasteboardChanged() = 0; 59 }; 60 61 class PasteBoardClientAdapter { 62 public: 63 PasteBoardClientAdapter() = default; 64 65 virtual ~PasteBoardClientAdapter() = default; 66 67 virtual bool GetPasteData(PasteRecordList& data) = 0; 68 69 virtual void SetPasteData(const PasteRecordList& data) = 0; 70 71 virtual bool HasPasteData() = 0; 72 73 virtual void Clear() = 0; 74 75 virtual int32_t OpenRemoteUri(const std::string& path) = 0; 76 77 virtual bool IsLocalPaste() const = 0; 78 79 virtual uint32_t GetTokenId() const = 0; 80 81 virtual void AddPasteboardChangedObserver(std::shared_ptr<PasteboardObserverAdapter> callback) = 0; 82 83 virtual void RemovePasteboardChangedObserver(std::shared_ptr<PasteboardObserverAdapter> callback) = 0; 84 }; 85 86 class PasteDataRecordAdapter { 87 public: 88 PasteDataRecordAdapter() = default; 89 90 virtual ~PasteDataRecordAdapter() = default; 91 92 static std::shared_ptr<PasteDataRecordAdapter> NewRecord( 93 const std::string& mimeType); 94 95 static std::shared_ptr<PasteDataRecordAdapter> NewRecord( 96 const std::string& mimeType, 97 std::shared_ptr<std::string> htmlText, 98 std::shared_ptr<std::string> plainText); 99 100 virtual bool SetHtmlText(std::shared_ptr<std::string> htmlText) = 0; 101 102 virtual bool SetPlainText(std::shared_ptr<std::string> plainText) = 0; 103 104 virtual bool SetImgData(std::shared_ptr<ClipBoardImageData> imageData) = 0; 105 106 virtual std::string GetMimeType() = 0; 107 108 virtual std::shared_ptr<std::string> GetHtmlText() = 0; 109 110 virtual std::shared_ptr<std::string> GetPlainText() = 0; 111 112 virtual bool GetImgData(ClipBoardImageData &imageData) = 0; 113 114 virtual bool SetUri(const std::string& uriString) = 0; 115 116 virtual bool SetCustomData(PasteCustomData& data) = 0; 117 118 virtual std::shared_ptr<std::string> GetUri() = 0; 119 120 virtual std::shared_ptr<PasteCustomData> GetCustomData() = 0; 121 }; 122 123 class PasteDataAdapter { 124 public: 125 PasteDataAdapter() = default; 126 127 virtual ~PasteDataAdapter() = default; 128 129 virtual void AddHtmlRecord(const std::string &html) = 0; 130 131 virtual void AddTextRecord(const std::string &text) = 0; 132 133 virtual std::vector<std::string> GetMimeTypes() = 0; 134 135 virtual std::shared_ptr<std::string> GetPrimaryHtml() = 0; 136 137 virtual std::shared_ptr<std::string> GetPrimaryText() = 0; 138 139 virtual std::shared_ptr<std::string> GetPrimaryMimeType() = 0; 140 141 virtual std::shared_ptr<PasteDataRecordAdapter> GetRecordAt(std::size_t index) = 0; 142 143 virtual std::size_t GetRecordCount() = 0; 144 145 virtual PasteRecordList AllRecords() const = 0; 146 }; 147 } 148 #endif