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