1use std::fmt::Debug;
6use std::hash::Hash;
7use std::path::PathBuf;
8use std::time::SystemTime;
9
10use base::Epoch;
11use base::generic_channel::GenericSender;
12use base::id::{PipelineId, WebViewId};
13use bitflags::bitflags;
14use serde::{Deserialize, Serialize};
15use servo_url::ImmutableOrigin;
16use url::Url;
17use uuid::Uuid;
18
19use crate::{InputMethodType, RgbColor};
20#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
21pub struct EmbedderControlId {
22 pub webview_id: WebViewId,
23 pub pipeline_id: PipelineId,
24 pub index: Epoch,
25}
26
27#[derive(Debug, Deserialize, Serialize)]
28pub enum EmbedderControlRequest {
29 SelectElement(Vec<SelectElementOptionOrOptgroup>, Option<usize>),
31 ColorPicker(RgbColor),
33 FilePicker(FilePickerRequest),
35 InputMethod(InputMethodRequest),
38 ContextMenu(ContextMenuRequest),
40}
41
42#[derive(Clone, Debug, Deserialize, Serialize)]
43pub struct SelectElementOption {
44 pub id: usize,
46 pub label: String,
48 pub is_disabled: bool,
50}
51
52#[derive(Clone, Debug, Deserialize, Serialize)]
54pub enum SelectElementOptionOrOptgroup {
55 Option(SelectElementOption),
56 Optgroup {
57 label: String,
58 options: Vec<SelectElementOption>,
59 },
60}
61
62#[derive(Debug, Deserialize, Serialize)]
65pub struct ContextMenuRequest {
66 pub element_info: ContextMenuElementInformation,
67 pub items: Vec<ContextMenuItem>,
68}
69
70#[derive(Clone, Debug, Deserialize, Serialize)]
72pub enum ContextMenuItem {
73 Item {
74 label: String,
75 action: ContextMenuAction,
76 enabled: bool,
77 },
78 Separator,
79}
80
81#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)]
85pub enum ContextMenuAction {
86 GoBack,
87 GoForward,
88 Reload,
89
90 CopyLink,
91 OpenLinkInNewWebView,
92
93 CopyImageLink,
94 OpenImageInNewView,
95
96 Cut,
97 Copy,
98 Paste,
99 SelectAll,
100}
101
102bitflags! {
103 #[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize)]
104 pub struct ContextMenuElementInformationFlags: u8 {
105 const Link = 1 << 1;
107 const Image = 1 << 2;
109 const EditableText = 1 << 3;
112 const Selection = 1 << 4;
115 }
116}
117
118#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
124pub struct ContextMenuElementInformation {
125 pub flags: ContextMenuElementInformationFlags,
126 pub link_url: Option<Url>,
127 pub image_url: Option<Url>,
128}
129
130#[derive(Debug, Deserialize, Serialize)]
134pub struct InputMethodRequest {
135 pub input_method_type: InputMethodType,
136 pub text: String,
137 pub insertion_point: Option<u32>,
138 pub multiline: bool,
139 pub allow_virtual_keyboard: bool,
140}
141
142#[derive(Clone, Debug, Deserialize, Serialize)]
145pub struct FilterPattern(pub String);
146
147#[derive(Debug, Deserialize, Serialize)]
148pub struct FilePickerRequest {
149 pub origin: ImmutableOrigin,
150 pub current_paths: Vec<PathBuf>,
151 pub filter_patterns: Vec<FilterPattern>,
152 pub allow_select_multiple: bool,
153 pub accept_current_paths_for_testing: bool,
154}
155
156#[derive(Debug, Deserialize, Serialize)]
157pub enum EmbedderControlResponse {
158 SelectElement(Option<usize>),
159 ColorPicker(Option<RgbColor>),
160 FilePicker(Option<Vec<SelectedFile>>),
161 ContextMenu(Option<ContextMenuAction>),
162}
163
164#[derive(Debug, Deserialize, Serialize)]
166pub struct SelectedFile {
167 pub id: Uuid,
168 pub filename: PathBuf,
169 pub modified: SystemTime,
170 pub size: u64,
171 pub type_string: String,
173}
174
175#[derive(Deserialize, Serialize)]
176pub enum SimpleDialogRequest {
177 Alert {
178 id: EmbedderControlId,
179 message: String,
180 response_sender: GenericSender<AlertResponse>,
181 },
182 Confirm {
183 id: EmbedderControlId,
184 message: String,
185 response_sender: GenericSender<ConfirmResponse>,
186 },
187 Prompt {
188 id: EmbedderControlId,
189 message: String,
190 default: String,
191 response_sender: GenericSender<PromptResponse>,
192 },
193}
194
195#[derive(Deserialize, PartialEq, Serialize)]
196pub enum AlertResponse {
197 Ok,
198}
199
200#[derive(Deserialize, PartialEq, Serialize)]
201pub enum ConfirmResponse {
202 Ok,
203 Cancel,
204}
205
206#[derive(Deserialize, PartialEq, Serialize)]
207pub enum PromptResponse {
208 Ok(String),
209 Cancel,
210}