inset_embedder/drag_drop.rs
1//! Files dragged from outside the application over a view.
2//!
3//! No dart:ui counterpart: Flutter leaves external drops to plugins. The shape is the one
4//! every desktop toolkit reports — Qt's drag events, wry's `DragDropEvent`, gpui's
5//! `FileDropEvent` — put in `PointerData`'s terms: a view, a phase, a physical position, and
6//! the paths as a batch.
7
8use std::path::PathBuf;
9
10use crate::{Offset, ViewId};
11
12/// One report of an external drag over a view.
13#[derive(Clone, Debug, PartialEq)]
14pub struct DropData {
15 /// The [`crate::View`] the drag is over.
16 pub view_id: ViewId,
17 /// What happened since the last report.
18 pub change: DropChange,
19 /// Where over the view, in physical pixels, when the host knows: a host may report no
20 /// position at all, and none reports one on [`DropChange::Exited`].
21 pub physical_position: Option<Offset>,
22 /// The dragged files: always on [`DropChange::Dropped`], on [`DropChange::Entered`]
23 /// where the system tells the host ahead of the drop, empty otherwise.
24 pub paths: Vec<PathBuf>,
25}
26
27/// The four phases of an external drag, as every toolkit has them.
28#[derive(Clone, Copy, Debug, PartialEq, Eq)]
29pub enum DropChange {
30 /// The drag came over the view.
31 Entered,
32 /// The drag moved over the view.
33 Moved,
34 /// The files were let go over the view.
35 Dropped,
36 /// The drag left the view without dropping.
37 Exited,
38}