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_CONTEXT_MENU_PARAMS_H
17 #define NWEB_CONTEXT_MENU_PARAMS_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "nweb_export.h"
23 #include "nweb_touch_handle_state.h"
24 
25 namespace OHOS::NWeb {
26 
27 class OHOS_NWEB_EXPORT NWebContextMenuParams {
28 public:
29     enum ContextMenuTypeFlags {
30         CM_TF_NONE = 0,
31         CM_TF_PAGE = 1 << 0,
32         CM_TF_FRAME = 1 << 1,
33         CM_TF_LINK = 1 << 2,
34         CM_TF_MEDIA = 1 << 3,
35         CM_TF_SELECTION = 1 << 4,
36         CM_TF_EDITABLE = 1 << 5,
37     };
38 
39     enum ContextMenuMediaType {
40         CM_MT_NONE,
41         CM_MT_IMAGE,
42     };
43 
44     enum ContextMenuEditStateFlags {
45         CM_ES_NONE = 0,
46         CM_ES_CAN_CUT = 1 << 0,
47         CM_ES_CAN_COPY = 1 << 1,
48         CM_ES_CAN_PASTE = 1 << 2,
49         CM_ES_CAN_SELECT_ALL = 1 << 3,
50     };
51 
52     enum ContextMenuInputFieldType {
53         CM_IT_NONE = 0,
54         CM_IT_PLAINTEXT = 1,
55         CM_IT_PASSWORD = 2,
56         CM_IT_NUMBER = 3,
57         CM_IT_TELEPHONE = 4,
58         CM_IT_OTHER = 5,
59     };
60 
61     enum ContextMenuSourceType {
62         CM_ST_NONE = 0,
63         CM_ST_MOUSE = 1,
64         CM_ST_LONG_PRESS = 2,
65     };
66 
67     virtual ~NWebContextMenuParams() = default;
68 
69     virtual int32_t GetXCoord() = 0;
70 
71     virtual int32_t GetYCoord() = 0;
72 
73     virtual int32_t GetContextMenuTypeFlags() = 0;
74 
75     virtual std::string GetLinkUrl() = 0;
76 
77     virtual std::string GetUnfilteredLinkUrl() = 0;
78 
79     virtual std::string GetSourceUrl() = 0;
80 
81     virtual bool HasImageContents() = 0;
82 
83     virtual std::string GetTitleText() = 0;
84 
85     virtual std::string GetPageUrl() = 0;
86 
87     virtual ContextMenuMediaType GetMediaType() = 0;
88 
89     virtual bool IsEditable() = 0;
90 
91     virtual int32_t GetEditStateFlags() = 0;
92 
93     virtual ContextMenuSourceType GetSourceType() = 0;
94 
95     virtual ContextMenuInputFieldType GetInputFieldType() = 0;
96 
97     virtual std::string GetSelectionText() = 0;
98 
GetImageRect(int & x,int & y,int & w,int & h)99     virtual void GetImageRect(int& x, int& y, int& w, int& h) {}
100 };
101 
102 class OHOS_NWEB_EXPORT NWebQuickMenuParams {
103 public:
104     enum QuickMenuEditStateFlags {
105         QM_EF_NONE = 0,
106         QM_EF_CAN_ELLIPSIS = 1 << 0,
107         QM_EF_CAN_CUT = 1 << 1,
108         QM_EF_CAN_COPY = 1 << 2,
109         QM_EF_CAN_PASTE = 1 << 3,
110         QM_EF_CAN_SELECT_ALL = 1 << 4,
111     };
112 
113     virtual ~NWebQuickMenuParams() = default;
114 
115     virtual int32_t GetXCoord() = 0;
116 
117     virtual int32_t GetYCoord() = 0;
118 
119     virtual int32_t GetWidth() = 0;
120 
121     virtual int32_t GetHeight() = 0;
122 
123     virtual int32_t GetEditStateFlags() = 0;
124 
125     virtual int32_t GetSelectX() = 0;
126 
127     virtual int32_t GetSelectY() = 0;
128 
129     virtual int32_t GetSelectWidth() = 0;
130 
131     virtual int32_t GetSelectXHeight() = 0;
132 
133     virtual std::shared_ptr<NWebTouchHandleState> GetTouchHandleState(NWebTouchHandleState::TouchHandleType type) = 0;
134 
GetIsLongPressActived()135     virtual bool GetIsLongPressActived() {
136         return false;
137     }
138 };
139 
140 enum MenuEventFlags {
141     EF_NONE = 0,
142     EF_CAPS_LOCK_ON = 1 << 0,
143     EF_SHIFT_DOWN = 1 << 1,
144     EF_CONTROL_DOWN = 1 << 2,
145     EF_ALT_DOWN = 1 << 3,
146     EF_LEFT_MOUSE_BUTTON = 1 << 4,
147     EF_MIDDLE_MOUSE_BUTTON = 1 << 5,
148     EF_RIGHT_MOUSE_BUTTON = 1 << 6,
149 };
150 
151 enum MenuCommandId {
152     CI_IMAGE_COPY = 0,
153     CI_COPY = 1,
154     CI_PASTE = 2,
155     CI_CUT = 3,
156     CI_SELECT_ALL = 4,
157     CI_DELETE = 5,
158 };
159 
160 class OHOS_NWEB_EXPORT NWebContextMenuCallback {
161 public:
162     virtual ~NWebContextMenuCallback() = default;
163 
164     virtual void Continue(int32_t commandId, MenuEventFlags flag) = 0;
165 
166     virtual void Cancel() = 0;
167 };
168 
169 class OHOS_NWEB_EXPORT NWebQuickMenuCallback {
170 public:
171     virtual ~NWebQuickMenuCallback() = default;
172 
173     virtual void Continue(int32_t commandId, MenuEventFlags flag) = 0;
174 
175     virtual void Cancel() = 0;
176 };
177 
178 } // namespace OHOS::NWeb
179 
180 #endif
181