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 url::Url;
16use uuid::Uuid;
17
18use crate::{InputMethodType, RgbColor};
19#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
20pub struct EmbedderControlId {
21 pub webview_id: WebViewId,
22 pub pipeline_id: PipelineId,
23 pub index: Epoch,
24}
25
26#[derive(Debug, Deserialize, Serialize)]
27pub enum EmbedderControlRequest {
28 SelectElement(Vec<SelectElementOptionOrOptgroup>, Option<usize>),
30 ColorPicker(RgbColor),
32 FilePicker(FilePickerRequest),
34 InputMethod(InputMethodRequest),
37 ContextMenu(ContextMenuRequest),
39}
40
41#[derive(Clone, Debug, Deserialize, Serialize)]
42pub struct SelectElementOption {
43 pub id: usize,
45 pub label: String,
47 pub is_disabled: bool,
49}
50
51#[derive(Clone, Debug, Deserialize, Serialize)]
53pub enum SelectElementOptionOrOptgroup {
54 Option(SelectElementOption),
55 Optgroup {
56 label: String,
57 options: Vec<SelectElementOption>,
58 },
59}
60
61#[derive(Debug, Deserialize, Serialize)]
64pub struct ContextMenuRequest {
65 pub element_info: ContextMenuElementInformation,
66 pub items: Vec<ContextMenuItem>,
67}
68
69#[derive(Clone, Debug, Deserialize, Serialize)]
71pub enum ContextMenuItem {
72 Item {
73 label: String,
74 action: ContextMenuAction,
75 enabled: bool,
76 },
77 Separator,
78}
79
80#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)]
84pub enum ContextMenuAction {
85 GoBack,
86 GoForward,
87 Reload,
88
89 CopyLink,
90 OpenLinkInNewWebView,
91
92 CopyImageLink,
93 OpenImageInNewView,
94
95 Cut,
96 Copy,
97 Paste,
98 SelectAll,
99}
100
101bitflags! {
102 #[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize)]
103 pub struct ContextMenuElementInformationFlags: u8 {
104 const Link = 1 << 1;
106 const Image = 1 << 2;
108 const EditableText = 1 << 3;
111 const Selection = 1 << 4;
114 }
115}
116
117#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
123pub struct ContextMenuElementInformation {
124 pub flags: ContextMenuElementInformationFlags,
125 pub link_url: Option<Url>,
126 pub image_url: Option<Url>,
127}
128
129#[derive(Debug, Deserialize, Serialize)]
133pub struct InputMethodRequest {
134 pub input_method_type: InputMethodType,
135 pub text: String,
136 pub insertion_point: Option<u32>,
137 pub multiline: bool,
138}
139
140#[derive(Clone, Debug, Deserialize, Serialize)]
143pub struct FilterPattern(pub String);
144
145#[derive(Debug, Deserialize, Serialize)]
146pub struct FilePickerRequest {
147 pub origin: String,
148 pub current_paths: Vec<PathBuf>,
149 pub filter_patterns: Vec<FilterPattern>,
150 pub allow_select_multiple: bool,
151 pub accept_current_paths_for_testing: bool,
152}
153
154#[derive(Debug, Deserialize, Serialize)]
155pub enum EmbedderControlResponse {
156 SelectElement(Option<usize>),
157 ColorPicker(Option<RgbColor>),
158 FilePicker(Option<Vec<SelectedFile>>),
159 ContextMenu(Option<ContextMenuAction>),
160}
161
162#[derive(Debug, Deserialize, Serialize)]
164pub struct SelectedFile {
165 pub id: Uuid,
166 pub filename: PathBuf,
167 pub modified: SystemTime,
168 pub size: u64,
169 pub type_string: String,
171}
172
173#[derive(Deserialize, Serialize)]
174pub enum SimpleDialogRequest {
175 Alert {
176 id: EmbedderControlId,
177 message: String,
178 response_sender: GenericSender<AlertResponse>,
179 },
180 Confirm {
181 id: EmbedderControlId,
182 message: String,
183 response_sender: GenericSender<ConfirmResponse>,
184 },
185 Prompt {
186 id: EmbedderControlId,
187 message: String,
188 default: String,
189 response_sender: GenericSender<PromptResponse>,
190 },
191}
192
193#[derive(Deserialize, PartialEq, Serialize)]
194pub enum AlertResponse {
195 Ok,
196}
197
198#[derive(Deserialize, PartialEq, Serialize)]
199pub enum ConfirmResponse {
200 Ok,
201 Cancel,
202}
203
204#[derive(Deserialize, PartialEq, Serialize)]
205pub enum PromptResponse {
206 Ok(String),
207 Cancel,
208}