1use crate::{
2 ClipboardToken, ExternalDropToken, FileDialogDataEvent, FileDialogSelection, ImageId,
3 ImageUpdateToken, ImageUploadToken, IncomingOpenDataEvent, IncomingOpenItem, IncomingOpenToken,
4 PointerId, Rect, ShareSheetOutcome, ShareSheetToken, TimerToken, WindowLogicalPosition,
5 geometry::{Point, Px},
6};
7
8mod keyboard;
9pub use keyboard::{KeyCode, keycode_to_ascii_lowercase};
10
11mod viewport;
12pub use viewport::{ViewportInputEvent, ViewportInputGeometry, ViewportInputKind};
13
14#[cfg(test)]
15mod viewport_input_event_tests;
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum MouseButton {
19 Left,
20 Right,
21 Middle,
22 Back,
23 Forward,
24 Other(u16),
25}
26
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
33pub enum PointerType {
34 #[default]
35 Mouse,
36 Touch,
37 Pen,
38 Unknown,
39}
40
41#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
42pub struct Modifiers {
43 pub shift: bool,
44 pub ctrl: bool,
45 pub alt: bool,
46 pub alt_gr: bool,
50 pub meta: bool,
51}
52
53#[derive(Debug, Clone, PartialEq)]
54pub enum ImeEvent {
55 Enabled,
56 Disabled,
57 Commit(String),
58 Preedit {
61 text: String,
62 cursor: Option<(usize, usize)>,
63 },
64 DeleteSurrounding {
70 before_bytes: usize,
71 after_bytes: usize,
72 },
73}
74
75#[derive(Debug, Clone, Default, PartialEq)]
79pub struct WebImeBridgeDebugSnapshot {
80 pub enabled: bool,
81 pub composing: bool,
82 pub suppress_next_input: bool,
83
84 pub textarea_has_focus: Option<bool>,
89 pub active_element_tag: Option<String>,
91
92 pub position_mode: Option<String>,
97 pub mount_kind: Option<String>,
101 pub device_pixel_ratio: Option<f64>,
103
104 pub textarea_value_chars: Option<usize>,
109 pub textarea_selection_start_utf16: Option<u32>,
110 pub textarea_selection_end_utf16: Option<u32>,
111 pub textarea_client_width_px: Option<i32>,
112 pub textarea_client_height_px: Option<i32>,
113 pub textarea_scroll_width_px: Option<i32>,
114 pub textarea_scroll_height_px: Option<i32>,
115
116 pub last_input_type: Option<String>,
117 pub last_beforeinput_data: Option<String>,
118 pub last_input_data: Option<String>,
119
120 pub last_key_code: Option<KeyCode>,
121 pub last_cursor_area: Option<Rect>,
122 pub last_cursor_anchor_px: Option<(f32, f32)>,
127
128 pub last_preedit_text: Option<String>,
130 pub last_preedit_cursor_utf16: Option<(u32, u32)>,
132 pub last_commit_text: Option<String>,
134
135 pub recent_events: Vec<String>,
139
140 pub beforeinput_seen: u64,
141 pub input_seen: u64,
142 pub suppressed_input_seen: u64,
143 pub composition_start_seen: u64,
144 pub composition_update_seen: u64,
145 pub composition_end_seen: u64,
146 pub cursor_area_set_seen: u64,
147}
148
149#[derive(Debug, Clone, PartialEq)]
150pub enum PointerEvent {
151 Move {
152 pointer_id: PointerId,
153 position: Point,
154 buttons: MouseButtons,
155 modifiers: Modifiers,
156 pointer_type: PointerType,
157 },
158 Down {
159 pointer_id: PointerId,
160 position: Point,
161 button: MouseButton,
162 modifiers: Modifiers,
163 click_count: u8,
168 pointer_type: PointerType,
169 },
170 Up {
171 pointer_id: PointerId,
172 position: Point,
173 button: MouseButton,
174 modifiers: Modifiers,
175 is_click: bool,
181 click_count: u8,
185 pointer_type: PointerType,
186 },
187 Wheel {
188 pointer_id: PointerId,
189 position: Point,
190 delta: Point,
191 modifiers: Modifiers,
192 pointer_type: PointerType,
193 },
194 PinchGesture {
199 pointer_id: PointerId,
200 position: Point,
201 delta: f32,
202 modifiers: Modifiers,
203 pointer_type: PointerType,
204 },
205}
206
207#[derive(Debug, Clone, Copy, PartialEq, Eq)]
208pub enum PointerCancelReason {
209 LeftWindow,
211}
212
213#[derive(Debug, Clone, PartialEq)]
214pub struct PointerCancelEvent {
215 pub pointer_id: PointerId,
216 pub position: Option<Point>,
218 pub buttons: MouseButtons,
219 pub modifiers: Modifiers,
220 pub pointer_type: PointerType,
221 pub reason: PointerCancelReason,
222}
223
224#[derive(Debug, Clone, PartialEq)]
225pub enum ExternalDragKind {
226 EnterFiles(ExternalDragFiles),
227 OverFiles(ExternalDragFiles),
228 DropFiles(ExternalDragFiles),
229 Leave,
230}
231
232#[derive(Debug, Clone, PartialEq)]
233pub struct ExternalDragFiles {
234 pub token: ExternalDropToken,
235 pub files: Vec<ExternalDragFile>,
236}
237
238#[derive(Debug, Clone, PartialEq)]
239pub struct ExternalDragFile {
240 pub name: String,
241 pub size_bytes: Option<u64>,
246 pub media_type: Option<String>,
250}
251
252#[derive(Debug, Clone, PartialEq)]
253pub struct ExternalDragEvent {
254 pub position: Point,
255 pub kind: ExternalDragKind,
256}
257
258#[derive(Debug, Clone, PartialEq)]
259pub struct ExternalDropDataEvent {
260 pub token: ExternalDropToken,
261 pub files: Vec<ExternalDropFileData>,
262 pub errors: Vec<ExternalDropReadError>,
263}
264
265#[derive(Debug, Clone, PartialEq)]
266pub struct ExternalDropFileData {
267 pub name: String,
268 pub bytes: Vec<u8>,
269}
270
271#[derive(Debug, Clone, PartialEq)]
272pub struct ExternalDropReadError {
273 pub name: String,
274 pub message: String,
275}
276
277#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
278pub struct ExternalDropReadLimits {
279 pub max_total_bytes: u64,
280 pub max_file_bytes: u64,
281 pub max_files: usize,
282}
283
284impl ExternalDropReadLimits {
285 pub fn capped_by(self, cap: ExternalDropReadLimits) -> ExternalDropReadLimits {
286 ExternalDropReadLimits {
287 max_total_bytes: self.max_total_bytes.min(cap.max_total_bytes),
288 max_file_bytes: self.max_file_bytes.min(cap.max_file_bytes),
289 max_files: self.max_files.min(cap.max_files),
290 }
291 }
292}
293
294#[derive(Debug, Clone, Copy, PartialEq)]
295pub enum InternalDragKind {
296 Enter,
297 Over,
298 Drop,
299 Leave,
300 Cancel,
301}
302
303#[derive(Debug, Clone, PartialEq)]
304pub struct InternalDragEvent {
305 pub pointer_id: PointerId,
306 pub position: Point,
307 pub kind: InternalDragKind,
308 pub modifiers: Modifiers,
309}
310
311#[derive(Debug, Clone, Copy, PartialEq, Eq)]
312pub enum ClipboardAccessErrorKind {
313 Unavailable,
314 PermissionDenied,
315 UserActivationRequired,
316 Unsupported,
317 BackendError,
318 Unknown,
319}
320
321#[derive(Debug, Clone, PartialEq, Eq)]
322pub struct ClipboardAccessError {
323 pub kind: ClipboardAccessErrorKind,
324 pub message: Option<String>,
325}
326
327#[derive(Debug, Clone, PartialEq, Eq)]
328pub enum ClipboardWriteOutcome {
329 Succeeded,
330 Failed { error: ClipboardAccessError },
331}
332
333#[derive(Debug, Clone, PartialEq)]
334pub enum Event {
335 Pointer(PointerEvent),
336 PointerCancel(PointerCancelEvent),
337 Timer {
338 token: TimerToken,
339 },
340 Ime(ImeEvent),
341 ExternalDrag(ExternalDragEvent),
342 ExternalDropData(ExternalDropDataEvent),
343 InternalDrag(InternalDragEvent),
344 KeyDown {
345 key: KeyCode,
346 modifiers: Modifiers,
347 repeat: bool,
348 },
349 KeyUp {
350 key: KeyCode,
351 modifiers: Modifiers,
352 },
353 TextInput(String),
354 SetTextSelection {
359 anchor: u32,
360 focus: u32,
361 },
362 ClipboardWriteCompleted {
364 token: ClipboardToken,
365 outcome: ClipboardWriteOutcome,
366 },
367 ClipboardReadText {
369 token: ClipboardToken,
370 text: String,
371 },
372 ClipboardReadFailed {
374 token: ClipboardToken,
375 error: ClipboardAccessError,
376 },
377 ShareSheetCompleted {
379 token: ShareSheetToken,
380 outcome: ShareSheetOutcome,
381 },
382 PrimarySelectionText {
386 token: ClipboardToken,
387 text: String,
388 },
389 PrimarySelectionTextUnavailable {
391 token: ClipboardToken,
392 },
393 FileDialogSelection(FileDialogSelection),
395 FileDialogData(FileDialogDataEvent),
397 FileDialogCanceled,
399 IncomingOpenRequest {
403 token: IncomingOpenToken,
404 items: Vec<IncomingOpenItem>,
405 },
406 IncomingOpenData(IncomingOpenDataEvent),
408 IncomingOpenUnavailable {
410 token: IncomingOpenToken,
411 },
412 ImageRegistered {
414 token: ImageUploadToken,
415 image: ImageId,
416 width: u32,
417 height: u32,
418 },
419 ImageRegisterFailed {
421 token: ImageUploadToken,
422 message: String,
423 },
424 ImageUpdateApplied {
429 token: ImageUpdateToken,
430 image: ImageId,
431 },
432 ImageUpdateDropped {
436 token: ImageUpdateToken,
437 image: ImageId,
438 reason: ImageUpdateDropReason,
439 },
440 WindowCloseRequested,
445 WindowFocusChanged(bool),
447 WindowScaleFactorChanged(f32),
448 WindowMoved(WindowLogicalPosition),
449 WindowResized {
450 width: Px,
451 height: Px,
452 },
453}
454
455#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
456pub enum ImageUpdateDropReason {
457 Coalesced,
458 StagingBudgetExceeded,
459 UnknownImage,
460 InvalidPayload,
461 RendererNotReady,
462 Unsupported,
463}
464
465#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
466pub struct MouseButtons {
467 pub left: bool,
468 pub right: bool,
469 pub middle: bool,
470}