• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 enum class CopyOptionMode {
38     NONE = 0,
39     IN_APP = 1,
40     LOCAL_DEVICE = 2,
41     CROSS_DEVICE = 3
42 };
43 
44 typedef struct ClipBoardImageDataTag {
45     ClipBoardImageColorType colorType;
46     ClipBoardImageAlphaType alphaType;
47     uint32_t *data;
48     size_t dataSize;
49     size_t rowBytes;
50     int32_t width;
51     int32_t height;
52 } ClipBoardImageData;
53 
54 class PasteDataRecordAdapter;
55 class PasteDataAdapter;
56 using PasteRecordList = std::vector<std::shared_ptr<PasteDataRecordAdapter>>;
57 using PasteCustomData = std::map<std::string, std::vector<uint8_t>>;
58 
59 class PasteboardObserverAdapter {
60 public:
61     PasteboardObserverAdapter() = default;
62 
63     virtual ~PasteboardObserverAdapter() = default;
64 
65     virtual void OnPasteboardChanged() = 0;
66 };
67 
68 class PasteBoardClientAdapter {
69 public:
70     PasteBoardClientAdapter() = default;
71 
72     virtual ~PasteBoardClientAdapter() = default;
73 
74     virtual bool GetPasteData(PasteRecordList& data) = 0;
75 
76     virtual void SetPasteData(const PasteRecordList& data,
77                               CopyOptionMode copyOption = CopyOptionMode::CROSS_DEVICE) = 0;
78 
79     virtual bool HasPasteData() = 0;
80 
81     virtual void Clear() = 0;
82 
83     virtual int32_t OpenRemoteUri(const std::string& path) = 0;
84 
85     virtual bool IsLocalPaste() const = 0;
86 
87     virtual uint32_t GetTokenId() const = 0;
88 
89     virtual void AddPasteboardChangedObserver(std::shared_ptr<PasteboardObserverAdapter> callback) = 0;
90 
91     virtual void RemovePasteboardChangedObserver(std::shared_ptr<PasteboardObserverAdapter> callback) = 0;
92 };
93 
94 class PasteDataRecordAdapter {
95 public:
96     PasteDataRecordAdapter() = default;
97 
98     virtual ~PasteDataRecordAdapter() = default;
99 
100     static std::shared_ptr<PasteDataRecordAdapter> NewRecord(
101         const std::string& mimeType);
102 
103     static std::shared_ptr<PasteDataRecordAdapter> NewRecord(
104         const std::string& mimeType,
105         std::shared_ptr<std::string> htmlText,
106         std::shared_ptr<std::string> plainText);
107 
108     virtual bool SetHtmlText(std::shared_ptr<std::string> htmlText) = 0;
109 
110     virtual bool SetPlainText(std::shared_ptr<std::string> plainText) = 0;
111 
112     virtual bool SetImgData(std::shared_ptr<ClipBoardImageData> imageData) = 0;
113 
114     virtual std::string GetMimeType() = 0;
115 
116     virtual std::shared_ptr<std::string> GetHtmlText() = 0;
117 
118     virtual std::shared_ptr<std::string> GetPlainText() = 0;
119 
120     virtual bool GetImgData(ClipBoardImageData &imageData) = 0;
121 
122     virtual bool SetUri(const std::string& uriString) = 0;
123 
124     virtual bool SetCustomData(PasteCustomData& data) = 0;
125 
126     virtual std::shared_ptr<std::string> GetUri() = 0;
127 
128     virtual std::shared_ptr<PasteCustomData> GetCustomData() = 0;
129 };
130 
131 class PasteDataAdapter {
132 public:
133     PasteDataAdapter() = default;
134 
135     virtual ~PasteDataAdapter() = default;
136 
137     virtual void AddHtmlRecord(const std::string &html) = 0;
138 
139     virtual void AddTextRecord(const std::string &text) = 0;
140 
141     virtual std::vector<std::string> GetMimeTypes() = 0;
142 
143     virtual std::shared_ptr<std::string> GetPrimaryHtml() = 0;
144 
145     virtual std::shared_ptr<std::string> GetPrimaryText() = 0;
146 
147     virtual std::shared_ptr<std::string> GetPrimaryMimeType() = 0;
148 
149     virtual std::shared_ptr<PasteDataRecordAdapter> GetRecordAt(std::size_t index) = 0;
150 
151     virtual std::size_t GetRecordCount() = 0;
152 
153     virtual PasteRecordList AllRecords() const = 0;
154 };
155 }
156 #endif