use crate::{
ClipboardToken, ExternalDropToken, FileDialogDataEvent, FileDialogSelection, ImageId,
ImageUpdateToken, ImageUploadToken, IncomingOpenDataEvent, IncomingOpenItem, IncomingOpenToken,
PointerId, Rect, ShareSheetOutcome, ShareSheetToken, TimerToken, WindowLogicalPosition,
geometry::{Point, Px},
};
mod keyboard;
pub use keyboard::{KeyCode, keycode_to_ascii_lowercase};
mod viewport;
pub use viewport::{ViewportInputEvent, ViewportInputGeometry, ViewportInputKind};
#[cfg(test)]
mod viewport_input_event_tests;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MouseButton {
Left,
Right,
Middle,
Back,
Forward,
Other(u16),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum PointerType {
#[default]
Mouse,
Touch,
Pen,
Unknown,
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Modifiers {
pub shift: bool,
pub ctrl: bool,
pub alt: bool,
pub alt_gr: bool,
pub meta: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ImeEvent {
Enabled,
Disabled,
Commit(String),
Preedit {
text: String,
cursor: Option<(usize, usize)>,
},
DeleteSurrounding {
before_bytes: usize,
after_bytes: usize,
},
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct WebImeBridgeDebugSnapshot {
pub enabled: bool,
pub composing: bool,
pub suppress_next_input: bool,
pub textarea_has_focus: Option<bool>,
pub active_element_tag: Option<String>,
pub position_mode: Option<String>,
pub mount_kind: Option<String>,
pub device_pixel_ratio: Option<f64>,
pub textarea_value_chars: Option<usize>,
pub textarea_selection_start_utf16: Option<u32>,
pub textarea_selection_end_utf16: Option<u32>,
pub textarea_client_width_px: Option<i32>,
pub textarea_client_height_px: Option<i32>,
pub textarea_scroll_width_px: Option<i32>,
pub textarea_scroll_height_px: Option<i32>,
pub last_input_type: Option<String>,
pub last_beforeinput_data: Option<String>,
pub last_input_data: Option<String>,
pub last_key_code: Option<KeyCode>,
pub last_cursor_area: Option<Rect>,
pub last_cursor_anchor_px: Option<(f32, f32)>,
pub last_preedit_text: Option<String>,
pub last_preedit_cursor_utf16: Option<(u32, u32)>,
pub last_commit_text: Option<String>,
pub recent_events: Vec<String>,
pub beforeinput_seen: u64,
pub input_seen: u64,
pub suppressed_input_seen: u64,
pub composition_start_seen: u64,
pub composition_update_seen: u64,
pub composition_end_seen: u64,
pub cursor_area_set_seen: u64,
}
#[derive(Debug, Clone, PartialEq)]
pub enum PointerEvent {
Move {
pointer_id: PointerId,
position: Point,
buttons: MouseButtons,
modifiers: Modifiers,
pointer_type: PointerType,
},
Down {
pointer_id: PointerId,
position: Point,
button: MouseButton,
modifiers: Modifiers,
click_count: u8,
pointer_type: PointerType,
},
Up {
pointer_id: PointerId,
position: Point,
button: MouseButton,
modifiers: Modifiers,
is_click: bool,
click_count: u8,
pointer_type: PointerType,
},
Wheel {
pointer_id: PointerId,
position: Point,
delta: Point,
modifiers: Modifiers,
pointer_type: PointerType,
},
PinchGesture {
pointer_id: PointerId,
position: Point,
delta: f32,
modifiers: Modifiers,
pointer_type: PointerType,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PointerCancelReason {
LeftWindow,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PointerCancelEvent {
pub pointer_id: PointerId,
pub position: Option<Point>,
pub buttons: MouseButtons,
pub modifiers: Modifiers,
pub pointer_type: PointerType,
pub reason: PointerCancelReason,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ExternalDragKind {
EnterFiles(ExternalDragFiles),
OverFiles(ExternalDragFiles),
DropFiles(ExternalDragFiles),
Leave,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExternalDragFiles {
pub token: ExternalDropToken,
pub files: Vec<ExternalDragFile>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExternalDragFile {
pub name: String,
pub size_bytes: Option<u64>,
pub media_type: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExternalDragEvent {
pub position: Point,
pub kind: ExternalDragKind,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExternalDropDataEvent {
pub token: ExternalDropToken,
pub files: Vec<ExternalDropFileData>,
pub errors: Vec<ExternalDropReadError>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExternalDropFileData {
pub name: String,
pub bytes: Vec<u8>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExternalDropReadError {
pub name: String,
pub message: String,
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct ExternalDropReadLimits {
pub max_total_bytes: u64,
pub max_file_bytes: u64,
pub max_files: usize,
}
impl ExternalDropReadLimits {
pub fn capped_by(self, cap: ExternalDropReadLimits) -> ExternalDropReadLimits {
ExternalDropReadLimits {
max_total_bytes: self.max_total_bytes.min(cap.max_total_bytes),
max_file_bytes: self.max_file_bytes.min(cap.max_file_bytes),
max_files: self.max_files.min(cap.max_files),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum InternalDragKind {
Enter,
Over,
Drop,
Leave,
Cancel,
}
#[derive(Debug, Clone, PartialEq)]
pub struct InternalDragEvent {
pub pointer_id: PointerId,
pub position: Point,
pub kind: InternalDragKind,
pub modifiers: Modifiers,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ClipboardAccessErrorKind {
Unavailable,
PermissionDenied,
UserActivationRequired,
Unsupported,
BackendError,
Unknown,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ClipboardAccessError {
pub kind: ClipboardAccessErrorKind,
pub message: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ClipboardWriteOutcome {
Succeeded,
Failed { error: ClipboardAccessError },
}
#[derive(Debug, Clone, PartialEq)]
pub enum Event {
Pointer(PointerEvent),
PointerCancel(PointerCancelEvent),
Timer {
token: TimerToken,
},
Ime(ImeEvent),
ExternalDrag(ExternalDragEvent),
ExternalDropData(ExternalDropDataEvent),
InternalDrag(InternalDragEvent),
KeyDown {
key: KeyCode,
modifiers: Modifiers,
repeat: bool,
},
KeyUp {
key: KeyCode,
modifiers: Modifiers,
},
TextInput(String),
SetTextSelection {
anchor: u32,
focus: u32,
},
ClipboardWriteCompleted {
token: ClipboardToken,
outcome: ClipboardWriteOutcome,
},
ClipboardReadText {
token: ClipboardToken,
text: String,
},
ClipboardReadFailed {
token: ClipboardToken,
error: ClipboardAccessError,
},
ShareSheetCompleted {
token: ShareSheetToken,
outcome: ShareSheetOutcome,
},
PrimarySelectionText {
token: ClipboardToken,
text: String,
},
PrimarySelectionTextUnavailable {
token: ClipboardToken,
},
FileDialogSelection(FileDialogSelection),
FileDialogData(FileDialogDataEvent),
FileDialogCanceled,
IncomingOpenRequest {
token: IncomingOpenToken,
items: Vec<IncomingOpenItem>,
},
IncomingOpenData(IncomingOpenDataEvent),
IncomingOpenUnavailable {
token: IncomingOpenToken,
},
ImageRegistered {
token: ImageUploadToken,
image: ImageId,
width: u32,
height: u32,
},
ImageRegisterFailed {
token: ImageUploadToken,
message: String,
},
ImageUpdateApplied {
token: ImageUpdateToken,
image: ImageId,
},
ImageUpdateDropped {
token: ImageUpdateToken,
image: ImageId,
reason: ImageUpdateDropReason,
},
WindowCloseRequested,
WindowFocusChanged(bool),
WindowScaleFactorChanged(f32),
WindowMoved(WindowLogicalPosition),
WindowResized {
width: Px,
height: Px,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ImageUpdateDropReason {
Coalesced,
StagingBudgetExceeded,
UnknownImage,
InvalidPayload,
RendererNotReady,
Unsupported,
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct MouseButtons {
pub left: bool,
pub right: bool,
pub middle: bool,
}