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 NWEB_DRAG_DATA_H
17 #define NWEB_DRAG_DATA_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "nweb_export.h"
23 
24 namespace OHOS::NWeb {
25 
26 class OHOS_NWEB_EXPORT NWebDragData {
27 public:
28     ///
29     // "Verb" of a drag-and-drop operation as negotiated between the source and
30     // destination. These constants match their equivalents in WebCore's
31     // DragActions.h and should not be renumbered.
32     ///
33     enum class DragOperation : unsigned char {
34         DRAG_OPERATION_NONE = 0,
35         DRAG_OPERATION_COPY = 1,
36         DRAG_OPERATION_LINK = 2,
37         DRAG_OPERATION_GENERIC = 4,
38         DRAG_OPERATION_PRIVATE = 8,
39         DRAG_OPERATION_MOVE = 16,
40         DRAG_OPERATION_DELETE = 32,
41         DRAG_OPERATION_EVERY = UINT_MAX
42     };
43     NWebDragData() = default;
44     virtual ~NWebDragData() = default;
45 
46     // get the link URL that is being dragged.
47     virtual std::string GetLinkURL() = 0;
48 
49     // get the plain text that is being dragged.
50     virtual std::string GetFragmentText() = 0;
51 
52     // get the text/html fragment that is being dragged.
53     virtual std::string GetFragmentHtml() = 0;
54 
55     // get the image representation of drag data.
56     virtual bool GetPixelMapSetting(const void** data, size_t& len, int& width, int& height) = 0;
57 
58     // set the text/html fragment that is being dragged.
59     virtual bool SetFragmentHtml(const std::string& html) = 0;
60 
61     // set the image representation of drag data.
62     virtual bool SetPixelMapSetting(const void* data, size_t len, int width, int height) = 0;
63 
64     // set the link URL that is being dragged.
65     virtual bool SetLinkURL(const std::string& url) = 0;
66 
67     // set the plain text that is being dragged.
68     virtual bool SetFragmentText(const std::string& Text) = 0;
69 
70     // get the title associated with the link that is being dragged.
71     virtual std::string GetLinkTitle() = 0;
72 
73     // set the title associated with the link that is being dragged.
74     virtual bool SetLinkTitle(const std::string& title) = 0;
75 
76     // get the positon of the drag point.
77     virtual void GetDragStartPosition(int& x, int& y) = 0;
78 
79     // is single iamge that is being dragged.
80     virtual bool IsSingleImageContent() = 0;
81 
82     // set the iamge file name that is being dragged.
83     virtual bool SetFileUri(const std::string& uri) = 0;
84 
85     // get the iamge file name that is being dragged.
86     virtual std::string GetImageFileName() = 0;
87 
88     // clear the exist iamge file names.
89     virtual void ClearImageFileNames() = 0;
90 
91     // is drag new style.
IsDragNewStyle()92     virtual bool IsDragNewStyle() {
93         return false;
94     }
95 };
96 
97 } // namespace OHOS::NWeb
98 
99 #endif