1use std::fmt::Debug;
6use std::hash::Hash;
7use std::path::PathBuf;
8use std::time::SystemTime;
9
10use bitflags::bitflags;
11use serde::{Deserialize, Serialize};
12use servo_base::Epoch;
13use servo_base::generic_channel::GenericSender;
14use servo_base::id::{PipelineId, WebViewId};
15use servo_url::ImmutableOrigin;
16use url::Url;
17use uuid::Uuid;
18
19use crate::{InputMethodType, RgbColor};
20
21#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
24pub struct EmbedderControlId {
25 #[doc(hidden)]
26 pub webview_id: WebViewId,
27 #[doc(hidden)]
28 pub pipeline_id: PipelineId,
29 #[doc(hidden)]
30 pub index: Epoch,
31}
32
33#[derive(Debug, Deserialize, Serialize)]
35pub enum EmbedderControlRequest {
36 SelectElement(SelectElementRequest),
38 ColorPicker(RgbColor),
40 FilePicker(FilePickerRequest),
42 InputMethod(InputMethodRequest),
45 ContextMenu(ContextMenuRequest),
47}
48
49#[derive(Clone, Debug, Deserialize, Serialize)]
50pub struct SelectElementOption {
51 pub id: usize,
53 pub label: String,
55 pub is_disabled: bool,
57}
58
59#[derive(Clone, Debug, Deserialize, Serialize)]
61pub enum SelectElementOptionOrOptgroup {
62 Option(SelectElementOption),
63 Optgroup {
64 label: String,
65 options: Vec<SelectElementOption>,
66 },
67}
68
69#[derive(Debug, Deserialize, Serialize)]
72pub struct ContextMenuRequest {
73 pub element_info: ContextMenuElementInformation,
74 pub items: Vec<ContextMenuItem>,
75}
76
77#[derive(Clone, Debug, Deserialize, Serialize)]
79pub enum ContextMenuItem {
80 Item {
81 label: String,
82 action: ContextMenuAction,
83 enabled: bool,
84 },
85 Separator,
86}
87
88#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)]
92pub enum ContextMenuAction {
93 GoBack,
94 GoForward,
95 Reload,
96
97 CopyLink,
98 OpenLinkInNewWebView,
99
100 CopyImageLink,
101 OpenImageInNewView,
102
103 Cut,
104 Copy,
105 Paste,
106 SelectAll,
107}
108
109bitflags! {
110 #[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize)]
111 pub struct ContextMenuElementInformationFlags: u8 {
112 const Link = 1 << 1;
114 const Image = 1 << 2;
116 const EditableText = 1 << 3;
119 const Selection = 1 << 4;
122 }
123}
124
125#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
131pub struct ContextMenuElementInformation {
132 pub flags: ContextMenuElementInformationFlags,
133 pub link_url: Option<Url>,
134 pub image_url: Option<Url>,
135}
136
137#[derive(Debug, Deserialize, Serialize)]
141pub struct InputMethodRequest {
142 pub input_method_type: InputMethodType,
143 pub text: String,
144 pub insertion_point: Option<u32>,
145 pub multiline: bool,
146 pub allow_virtual_keyboard: bool,
147}
148
149#[derive(Clone, Debug, Deserialize, Serialize)]
152pub struct FilterPattern(pub String);
153
154#[derive(Debug, Deserialize, Serialize)]
155pub struct FilePickerRequest {
156 pub origin: ImmutableOrigin,
157 pub current_paths: Vec<PathBuf>,
158 pub filter_patterns: Vec<FilterPattern>,
159 pub allow_select_multiple: bool,
160 pub accept_current_paths_for_testing: bool,
161}
162
163#[derive(Debug, Deserialize, Serialize)]
165pub struct SelectElementRequest {
166 pub options: Vec<SelectElementOptionOrOptgroup>,
167 pub selected_options: Vec<usize>,
168 pub allow_select_multiple: bool,
169}
170
171#[derive(Debug, Deserialize, Serialize)]
172pub enum EmbedderControlResponse {
173 SelectElement(Vec<usize>),
174 ColorPicker(Option<RgbColor>),
175 FilePicker(Option<Vec<SelectedFile>>),
176 ContextMenu(Option<ContextMenuAction>),
177}
178
179#[derive(Debug, Deserialize, Serialize)]
181pub struct SelectedFile {
182 pub id: Uuid,
183 pub filename: PathBuf,
184 pub modified: SystemTime,
185 pub size: u64,
186 pub type_string: String,
188}
189
190#[derive(Deserialize, Serialize)]
192pub enum SimpleDialogRequest {
193 Alert {
194 id: EmbedderControlId,
195 message: String,
196 response_sender: GenericSender<AlertResponse>,
197 },
198 Confirm {
199 id: EmbedderControlId,
200 message: String,
201 response_sender: GenericSender<ConfirmResponse>,
202 },
203 Prompt {
204 id: EmbedderControlId,
205 message: String,
206 default: String,
207 response_sender: GenericSender<PromptResponse>,
208 },
209}
210
211#[derive(Deserialize, PartialEq, Serialize)]
213pub enum AlertResponse {
214 Ok,
215}
216
217#[derive(Deserialize, PartialEq, Serialize)]
219pub enum ConfirmResponse {
220 Ok,
221 Cancel,
222}
223
224#[derive(Deserialize, PartialEq, Serialize)]
226pub enum PromptResponse {
227 Ok(String),
228 Cancel,
229}