From 830da93f02f441f6765e24ed4317c0a877f884be Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 17 Nov 2026 22:24:02 -0500 Subject: [PATCH 001/379] Contract stubs: craft-atomic, craft-font-catalog, craft-i18n, craft-host, craft-quit, craft-settings, craft-theme, craft-web-host --- Cargo.lock | 2 + crates/atomic/src/lib.rs | 12 ++++++ crates/font-catalog/src/catalog.rs | 6 +++ crates/host/src/files.rs | 11 ++++++ crates/host/src/queue.rs | 15 ++++++- crates/host/src/queue_tests.rs | 12 ++++-- crates/i18n/src/fold.rs | 10 ++++- crates/i18n/src/matcher.rs | 4 +- crates/quit/src/lib.rs | 2 + crates/quit/src/web.rs | 8 ++++ crates/settings/Cargo.toml | 1 + crates/settings/src/error.rs | 2 +- crates/settings/src/files.rs | 33 ++++++++++++++++ crates/settings/src/lib.rs | 2 + crates/settings/src/store.rs | 3 +- crates/settings/src/store/sections.rs | 2 +- crates/web-host/Cargo.toml | 1 + crates/web-host/src/files.rs | 57 +++++++++++++++++++++++++++ crates/web-host/src/lib.rs | 2 + 19 files changed, 176 insertions(+), 9 deletions(-) create mode 100644 crates/quit/src/web.rs create mode 100644 crates/web-host/src/files.rs diff --git a/Cargo.lock b/Cargo.lock index dcdeaed120..c644d01bc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3626,6 +3626,7 @@ dependencies = [ "tempfile", "toml", "toml_edit", + "web-time", ] [[package]] @@ -4221,6 +4222,7 @@ dependencies = [ name = "craft-web-host" version = "0.1.0" dependencies = [ + "craft-host", "wasm-bindgen", "wasm-bindgen-test", "web-sys", diff --git a/crates/atomic/src/lib.rs b/crates/atomic/src/lib.rs index a87a8734d8..2ce72b9322 100644 --- a/crates/atomic/src/lib.rs +++ b/crates/atomic/src/lib.rs @@ -59,6 +59,13 @@ pub trait AtomicFs { /// request mode `0600` for `Private` or `0666` for `PlatformDefault`; the OS applies its /// umask/default ACL. Other platforms keep their native creation behavior. fn create_new(&self, path: &Path, permissions: NewFilePermissions) -> io::Result; + /// Create the stage like [`AtomicFs::create_new`], carrying over the attributes of the file it + /// replaces. `keep` is the destination's `symlink_metadata`, so a replaced link keeps its own + /// attributes, not its target's. The default ignores `keep` and calls `create_new`. + fn create_new_keeping(&self, path: &Path, permissions: NewFilePermissions, keep: Option<&std::fs::Metadata>) -> io::Result { + let _ = keep; + self.create_new(path, permissions) + } /// Flush a written file to durable storage. fn sync(&self, file: &File) -> io::Result<()>; /// Rename `from` over `to`, replacing it atomically. @@ -99,6 +106,11 @@ impl AtomicFs for RealFs { options.open(path) } + fn create_new_keeping(&self, path: &Path, permissions: NewFilePermissions, keep: Option<&std::fs::Metadata>) -> io::Result { + let _ = (path, permissions, keep); + todo!("SH-C33") + } + fn sync(&self, file: &File) -> io::Result<()> { sync_file(file) } diff --git a/crates/font-catalog/src/catalog.rs b/crates/font-catalog/src/catalog.rs index 10663e6afc..09636c391f 100644 --- a/crates/font-catalog/src/catalog.rs +++ b/crates/font-catalog/src/catalog.rs @@ -345,6 +345,12 @@ impl Catalog { } } + /// A catalog of exactly `files`, built on the existing scan with no font folders and no store. + pub fn of_files(files: Vec) -> Catalog { + let _ = files; + todo!("ED-F4b") + } + /// The process's catalog, for [`FontEnv::from_process`]. pub fn global() -> &'static Arc { static GLOBAL: OnceLock> = OnceLock::new(); diff --git a/crates/host/src/files.rs b/crates/host/src/files.rs index 4dce84d993..e74cd5bcaf 100644 --- a/crates/host/src/files.rs +++ b/crates/host/src/files.rs @@ -249,6 +249,12 @@ pub trait Files: Send + Sync { fn write(&self, path: &Path, bytes: &[u8]) -> Result<(), FileError>; /// The folder the last answered pick of `purpose` chose. fn last_folder(&self, purpose: &str) -> Option; + /// Answers the next pick, or the oldest pick still open, with `picked` instead of showing a + /// picker; the answer arrives through [`take_answer`](Files::take_answer) on a later pass. + fn answer_next(&self, picked: Picked) -> Result<(), FileError> { + let _ = picked; + Err(FileError::Unsupported) + } } /// No pickers (every pick answers `Cancelled`); reads and writes go to the file system. The @@ -462,6 +468,11 @@ impl Files for ScriptedFiles { Ok(()) } + fn answer_next(&self, picked: Picked) -> Result<(), FileError> { + let _ = picked; + todo!("WF-W16") + } + fn last_folder(&self, _purpose: &str) -> Option { None } diff --git a/crates/host/src/queue.rs b/crates/host/src/queue.rs index 06cd8d7448..a820aeeab9 100644 --- a/crates/host/src/queue.rs +++ b/crates/host/src/queue.rs @@ -73,6 +73,19 @@ pub struct QueueOptions { pub lanes: usize, /// The name each lane's job is spawned with (a thread name with `ThreadJobs`). pub name: &'static str, + /// Which of two jobs of equal priority runs first. + pub order: QueueOrder, +} + +/// Which job runs first among jobs of equal priority: the one that arrived last or first. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] +pub enum QueueOrder { + /// The newest job runs first. + #[default] + NewestFirst, + /// The oldest job runs first. + OldestFirst, } impl QueueOptions { @@ -92,7 +105,7 @@ impl Default for QueueOptions { /// [`default_lanes`](QueueOptions::default_lanes) lanes named `"craft-queue"`. fn default() -> Self { // new: the default every library queue starts from. - Self { lanes: Self::default_lanes(), name: "craft-queue" } + Self { lanes: Self::default_lanes(), name: "craft-queue", order: QueueOrder::default() } } } diff --git a/crates/host/src/queue_tests.rs b/crates/host/src/queue_tests.rs index b819cc3ea9..9e77dd6d6b 100644 --- a/crates/host/src/queue_tests.rs +++ b/crates/host/src/queue_tests.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; -use crate::queue::{Cancel, Finished, JobQueue, Priority, QueueOptions}; +use crate::queue::{Cancel, Finished, JobQueue, Priority, QueueOptions, QueueOrder}; use crate::{ManualJobs, Wake}; fn queue(lanes: usize) -> (JobQueue<&'static str, &'static str>, Arc, Arc) { @@ -15,7 +15,8 @@ fn queue(lanes: usize) -> (JobQueue<&'static str, &'static str>, Arc let wake = Wake::new(move || { counter.fetch_add(1, Ordering::Relaxed); }); - let queue = JobQueue::new(jobs.clone(), wake, QueueOptions { lanes, name: "test" }); + // P3(pdf-shell-w4): SH-C32 + let queue = JobQueue::new(jobs.clone(), wake, QueueOptions { lanes, name: "test", order: QueueOrder::default() }); (queue, jobs, wakes) } @@ -88,7 +89,12 @@ fn queue_gives_back_a_lane_the_host_dropped() { } } let jobs = Arc::new(Refusing(AtomicUsize::new(0), ManualJobs::new())); - let queue = JobQueue::<&'static str, &'static str>::new(jobs.clone(), Wake::new(|| {}), QueueOptions { lanes: 1, name: "test" }); + // P3(pdf-shell-w4): SH-C32 + let queue = JobQueue::<&'static str, &'static str>::new( + jobs.clone(), + Wake::new(|| {}), + QueueOptions { lanes: 1, name: "test", order: QueueOrder::default() }, + ); queue.submit("a", Priority::VISIBLE, |_| "a"); jobs.0.store(1, Ordering::Relaxed); queue.submit("b", Priority::VISIBLE, |_| "b"); diff --git a/crates/i18n/src/fold.rs b/crates/i18n/src/fold.rs index c1cbc62979..213a909693 100644 --- a/crates/i18n/src/fold.rs +++ b/crates/i18n/src/fold.rs @@ -24,11 +24,15 @@ use icu_normalizer::DecomposingNormalizerBorrowed; use icu_properties::props::{GraphemeExtend, HangulSyllableType}; use icu_properties::{CodePointMapData, CodePointSetData}; +use crate::scripts::{Direction, direction}; + /// Folds text for one locale. Cheap to build and copy. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct Folder { turkic: bool, accents: bool, + #[allow(dead_code)] // P3(pdf-chrome-w1): CH-C3 + rtl: bool, } impl Folder { @@ -36,7 +40,11 @@ impl Folder { /// or `zh-hant` (any case, `-` or `_`). pub fn new(locale: &str) -> Folder { let language = locale.split(['-', '_', '.', '@']).next().unwrap_or_default(); - Folder { turkic: language.eq_ignore_ascii_case("tr") || language.eq_ignore_ascii_case("az"), accents: false } + Folder { + turkic: language.eq_ignore_ascii_case("tr") || language.eq_ignore_ascii_case("az"), + accents: false, + rtl: direction(locale) == Direction::Rtl, + } } /// Accents count: `é` no longer matches `e`, and a match can't end on a letter whose accent it diff --git a/crates/i18n/src/matcher.rs b/crates/i18n/src/matcher.rs index 344763c461..7b15dccfd4 100644 --- a/crates/i18n/src/matcher.rs +++ b/crates/i18n/src/matcher.rs @@ -5,7 +5,7 @@ use crate::fold::{Folded, Folder}; use std::ops::Range; /// How well a text matches, best first: the derived order puts `Whole` before `Prefix` before `WordStart` before -/// `Contains`. +/// `Contains` before `AllWords`. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum Rank { @@ -17,6 +17,8 @@ pub enum Rank { WordStart, /// The query occurs inside a word. Contains, + /// Every word of a multi-word query occurs in the text, in any order (right-to-left locales only). + AllWords, } /// A text that matches the query. diff --git a/crates/quit/src/lib.rs b/crates/quit/src/lib.rs index ef0bc9188d..3bf8bb3a2c 100644 --- a/crates/quit/src/lib.rs +++ b/crates/quit/src/lib.rs @@ -18,6 +18,8 @@ mod close; #[cfg(target_os = "macos")] mod macos; +#[cfg(target_arch = "wasm32")] +pub mod web; pub use close::{CloseAnswer, CloseGuard, CloseScope, GuardStep, QUIT_MENU_ID}; #[cfg(feature = "ui")] diff --git a/crates/quit/src/web.rs b/crates/quit/src/web.rs new file mode 100644 index 0000000000..9918c484b4 --- /dev/null +++ b/crates/quit/src/web.rs @@ -0,0 +1,8 @@ +//! Holding a browser tab open while work is unsaved. + +/// Keeps one `beforeunload` listener that calls `prevent_default` while the last call said +/// `unsaved`. Call it each frame with whether work is at risk. +pub fn hold_leave(unsaved: bool) { + let _ = unsaved; + todo!("SH-C30") +} diff --git a/crates/settings/Cargo.toml b/crates/settings/Cargo.toml index 5bbc50da56..685a6e4770 100644 --- a/crates/settings/Cargo.toml +++ b/crates/settings/Cargo.toml @@ -22,6 +22,7 @@ serde = { version = "1", features = ["derive"] } serde_json = { workspace = true } toml = { version = "1.1", default-features = false, features = ["std", "parse", "serde"] } toml_edit = { version = "0.25", features = ["serde"] } +web-time = "1.1" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] dirs = "7" diff --git a/crates/settings/src/error.rs b/crates/settings/src/error.rs index 86e0ff2a65..996d580f6d 100644 --- a/crates/settings/src/error.rs +++ b/crates/settings/src/error.rs @@ -3,7 +3,7 @@ use std::fmt; use std::io; use std::path::PathBuf; -use std::time::Instant; +use web_time::Instant; /// Why a schema migration step failed. #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/crates/settings/src/files.rs b/crates/settings/src/files.rs index dde6e20586..21c033f205 100644 --- a/crates/settings/src/files.rs +++ b/crates/settings/src/files.rs @@ -71,6 +71,39 @@ impl SettingsFiles for DiskFiles { } } +/// Settings kept in the browser's localStorage, keyed by path: the files of a web build. +#[cfg(target_arch = "wasm32")] +#[derive(Clone, Copy, Debug, Default)] +pub struct BrowserFiles; + +#[cfg(target_arch = "wasm32")] +impl SettingsFiles for BrowserFiles { + fn read(&self, path: &Path) -> io::Result> { + let _ = path; + todo!("SH-C29") + } + + fn write(&self, path: &Path, text: &str) -> io::Result<()> { + let _ = (path, text); + todo!("SH-C29") + } + + fn move_aside(&self, path: &Path) -> io::Result { + let _ = path; + todo!("SH-C29") + } + + fn write_backup(&self, path: &Path, text: &str) -> io::Result<()> { + let _ = (path, text); + todo!("SH-C29") + } + + fn check_writable(&self, dir: &Path) -> io::Result<()> { + let _ = dir; + todo!("SH-C29") + } +} + /// New files are owner-only; on a replace `craft-atomic` keeps the existing file's mode. #[cfg(all(unix, not(target_arch = "wasm32")))] fn restrict_permissions(file: &std::fs::File) -> io::Result<()> { diff --git a/crates/settings/src/lib.rs b/crates/settings/src/lib.rs index e3f3ac261f..39d9df2625 100644 --- a/crates/settings/src/lib.rs +++ b/crates/settings/src/lib.rs @@ -56,6 +56,8 @@ pub mod store; pub mod testing; pub use error::{LoadReport, MigrateError, ReadOnlyReason, SaveStatus, SectionError, SettingsError, Source, TickResult}; +#[cfg(target_arch = "wasm32")] +pub use files::BrowserFiles; #[cfg(not(target_arch = "wasm32"))] pub use files::DiskFiles; pub use files::SettingsFiles; diff --git a/crates/settings/src/store.rs b/crates/settings/src/store.rs index 23efca9a28..1d633d7300 100644 --- a/crates/settings/src/store.rs +++ b/crates/settings/src/store.rs @@ -2,9 +2,10 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; -use std::time::{Duration, Instant}; +use std::time::Duration; use toml_edit::DocumentMut; +use web_time::Instant; use crate::Settings; use crate::document::{self, merge_changes, merge_into, set_schema_version}; diff --git a/crates/settings/src/store/sections.rs b/crates/settings/src/store/sections.rs index 491bf89a78..412ca53ad1 100644 --- a/crates/settings/src/store/sections.rs +++ b/crates/settings/src/store/sections.rs @@ -1,7 +1,7 @@ //! Library sections: tables beside `T`'s keys in the same document. use std::sync::{Arc, Mutex, MutexGuard}; -use std::time::Instant; +use web_time::Instant; use toml_edit::{DocumentMut, Item}; diff --git a/crates/web-host/Cargo.toml b/crates/web-host/Cargo.toml index f3eabdbee2..c4b271f553 100644 --- a/crates/web-host/Cargo.toml +++ b/crates/web-host/Cargo.toml @@ -9,6 +9,7 @@ repository.workspace = true # Already in every web build's Cargo.lock through eframe. [target.'cfg(target_arch = "wasm32")'.dependencies] +craft-host = { workspace = true } wasm-bindgen = "0.2" web-sys = { version = "0.3", features = ["Blob", "CustomEvent", "CustomEventInit", "Element", "Event", "EventTarget", "Location", "MessageEvent", "Window"] } diff --git a/crates/web-host/src/files.rs b/crates/web-host/src/files.rs new file mode 100644 index 0000000000..87161d21aa --- /dev/null +++ b/crates/web-host/src/files.rs @@ -0,0 +1,57 @@ +//! The file service of a web build: pickers through a file input, saves through the host page. + +use std::path::{Path, PathBuf}; + +use craft_host::{FileError, Files, PickId, PickRequest, Picked, Wake}; + +/// The [`Files`] service of a web build. Open and OpenMany go through a file input to +/// [`Picked::Contents`] and a finished read wakes the app; Save answers the name at once and +/// `write` posts to the host page or downloads; Folder is unavailable. +pub struct BrowserFiles { + #[allow(dead_code)] // P3(pdf-shell-w5): SH-C35 + wake: Wake, +} + +impl BrowserFiles { + /// A service that wakes the app through `wake` when a picked file has been read. + pub fn new(wake: Wake) -> Self { + let _ = wake; + todo!("SH-C35") + } +} + +impl Files for BrowserFiles { + fn pick(&self, request: PickRequest) -> PickId { + let _ = request; + todo!("SH-C35") + } + + fn take_answer(&self, id: PickId) -> Option { + let _ = id; + todo!("SH-C35") + } + + fn forget(&self, id: PickId) { + let _ = id; + todo!("SH-C35") + } + + fn pick_pending(&self) -> bool { + todo!("SH-C35") + } + + fn read(&self, path: &Path) -> Result, FileError> { + let _ = path; + todo!("SH-C35") + } + + fn write(&self, path: &Path, bytes: &[u8]) -> Result<(), FileError> { + let _ = (path, bytes); + todo!("SH-C35") + } + + fn last_folder(&self, purpose: &str) -> Option { + let _ = purpose; + todo!("SH-C35") + } +} diff --git a/crates/web-host/src/lib.rs b/crates/web-host/src/lib.rs index 90e2aa0704..3bd078c197 100644 --- a/crates/web-host/src/lib.rs +++ b/crates/web-host/src/lib.rs @@ -32,6 +32,8 @@ use std::cell::{Cell, RefCell}; use std::collections::VecDeque; +#[cfg(target_arch = "wasm32")] +pub mod files; #[cfg(target_arch = "wasm32")] pub mod web; From f0275a082a2f1e7afdd49960318971694dba33c8 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 17 Nov 2026 22:32:06 -0500 Subject: [PATCH 002/379] Contract stubs: craft-behavior, craft-fonts-build, craft-platform, craft-window --- crates/behavior/src/cursor.rs | 2 + crates/behavior/src/frame_step.rs | 10 ++++ crates/behavior/src/geometry/crop.rs | 5 +- crates/behavior/src/geometry/mod.rs | 2 +- crates/behavior/src/geometry/quad.rs | 28 +++++++++++ crates/behavior/src/keys.rs | 56 +++++++++++++++++----- crates/behavior/src/lib.rs | 8 +++- crates/behavior/src/middle_scroll.rs | 59 ++++++++++++++++++++++++ crates/behavior/src/press.rs | 18 ++++++-- crates/behavior/src/sense.rs | 3 ++ crates/behavior/src/wheel.rs | 43 +++++++++++++++++ crates/fonts-build/src/lib.rs | 2 +- crates/fonts-build/src/manifest.rs | 3 ++ crates/platform/src/appearance.rs | 5 ++ crates/platform/src/appearance/reader.rs | 6 +++ crates/platform/src/autosave/recovery.rs | 6 ++- crates/platform/src/autosave_tests.rs | 3 +- crates/platform/src/clipboard/backend.rs | 8 +++- crates/platform/src/clipboard/types.rs | 6 +++ crates/platform/src/lib.rs | 1 + crates/platform/src/open.rs | 35 ++++++++++++++ crates/platform/src/owner_only.rs | 45 ++++++++++++++++++ crates/window/src/policy.rs | 9 ++++ crates/window/src/restore/legacy.rs | 6 +-- 24 files changed, 343 insertions(+), 26 deletions(-) create mode 100644 crates/behavior/src/frame_step.rs create mode 100644 crates/behavior/src/middle_scroll.rs create mode 100644 crates/platform/src/owner_only.rs diff --git a/crates/behavior/src/cursor.rs b/crates/behavior/src/cursor.rs index f6dd7230cf..8c59601407 100644 --- a/crates/behavior/src/cursor.rs +++ b/crates/behavior/src/cursor.rs @@ -342,6 +342,8 @@ pub enum CursorPriority { DropTarget, /// A drag in progress. Drag, + /// Hides the pointer over everything, links included, while a presentation runs. + Hidden, } /// The winning request: the highest priority, the later request on a tie. diff --git a/crates/behavior/src/frame_step.rs b/crates/behavior/src/frame_step.rs new file mode 100644 index 0000000000..a293d5a1ff --- /dev/null +++ b/crates/behavior/src/frame_step.rs @@ -0,0 +1,10 @@ +//! The step of one pass of motion: a Hand glide, a held Zoom press and an autoscroll integrate over it. + +/// The longest step motion integrates, in seconds, so a stalled pass never jumps the view. +pub const FRAME_STEP_MAX: f64 = 0.1; + +/// The step of a pass that came `dt` seconds after the previous one, `dt` being the time between two readings of the +/// caller's pass clock: `dt` within `0..=FRAME_STEP_MAX`, and 0 where it is not a number. +pub fn frame_step(dt: f64) -> f64 { + if dt.is_finite() { dt.clamp(0.0, FRAME_STEP_MAX) } else { 0.0 } +} diff --git a/crates/behavior/src/geometry/crop.rs b/crates/behavior/src/geometry/crop.rs index 153be1ffa5..30bc702e16 100644 --- a/crates/behavior/src/geometry/crop.rs +++ b/crates/behavior/src/geometry/crop.rs @@ -148,8 +148,9 @@ impl CropBox { (w.is_finite() && h.is_finite()).then(|| (w.round().max(1.0), h.round().max(1.0))) } - /// Whether both sides are at least one document unit. - pub fn size_ok(&self) -> bool { + /// Whether both sides are at least `min`, and at least one document unit. + pub fn size_ok(&self, min: f64) -> bool { + let _ = min; // P3(pdf-edit-w4): ED-F9 self.rect.width() >= MIN_FRAME && self.rect.height() >= MIN_FRAME } diff --git a/crates/behavior/src/geometry/mod.rs b/crates/behavior/src/geometry/mod.rs index 24886f10da..60e557877b 100644 --- a/crates/behavior/src/geometry/mod.rs +++ b/crates/behavior/src/geometry/mod.rs @@ -24,7 +24,7 @@ pub use lock::{ pub use marquee::{Constraint, MarqueeGesture, MarqueeRect, fixed_size_pixels, marquee_pixels, square_pixels}; pub use move_gesture::{ConstrainStyle, MoveGesture, MoveValue, StrokeLock}; pub use outside::outside_pieces; -pub use quad::{BoxAllow, BoxDrag, BoxPart, BoxRules, BoxState, Homography, Parts, SKEW_LIMIT, ScaleRule, TransformMode, drag}; +pub use quad::{BoxAllow, BoxDrag, BoxHandles, BoxPart, BoxRules, BoxState, Homography, Parts, SKEW_LIMIT, ScaleRule, TransformMode, drag}; pub use selection_op::SelectionOperation; pub use snap::{ SNAP_PX, SnapGesture, SnapKind, SnapKinds, SnapLine, SnapOptions, SnapTarget, SnapTargets, across_axis, coordinate_across, motion_across, diff --git a/crates/behavior/src/geometry/quad.rs b/crates/behavior/src/geometry/quad.rs index dcf053241c..b7489a3a35 100644 --- a/crates/behavior/src/geometry/quad.rs +++ b/crates/behavior/src/geometry/quad.rs @@ -200,6 +200,21 @@ pub struct BoxRules { /// minimum keeps a scale drag from flipping the box, and a side already shorter than it at /// the press keeps its length as its floor, so a click changes nothing. pub min_side: f64, + /// Which handles the box shows and takes keys and drags for. + pub handles: BoxHandles, +} + +/// Which handles of a box are shown. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] +pub enum BoxHandles { + /// The four corners and the four sides. + #[default] + All, + /// The four corners. + Corners, + /// The right and left sides. + Sides, } impl Default for BoxRules { @@ -211,6 +226,7 @@ impl Default for BoxRules { allow: BoxAllow::default(), rotate_step: 15.0, min_side: 0.0, + handles: BoxHandles::default(), } } } @@ -246,6 +262,18 @@ impl BoxRules { self } + /// The rules with `handles` as the handles the box shows. + pub fn with_handles(mut self, handles: BoxHandles) -> BoxRules { + self.handles = handles; + self + } + + /// Whether the box shows `part`: `Corners` shows the four corners, `Sides` the right and left sides. + pub fn shows(&self, part: BoxPart) -> bool { + let _ = part; + todo!("ED-F5") + } + /// The mode drags follow: a mode the content refuses scales as Free Transform does. pub fn effective_mode(&self) -> TransformMode { let refused = match self.mode { diff --git a/crates/behavior/src/keys.rs b/crates/behavior/src/keys.rs index 5c8bf19daa..e433e164f1 100644 --- a/crates/behavior/src/keys.rs +++ b/crates/behavior/src/keys.rs @@ -7,8 +7,19 @@ use crate::intent::{Granularity, Intent, MoveMods, NavMove}; use craft_host::target::Os; use craft_keymap::{Chord, Key, Mods}; +/// The named key scheme of a reorderable collection. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] +pub enum ReorderKeys { + /// The stacking keys (`REORDER_KEYS`): Cmd+] and Cmd+[. + #[default] + Stacking, + /// Alt with the arrows (`ALT_ARROW_KEYS`). + AltArrows, +} + /// What the focused stop is, as far as the table's rows differ. -#[derive(Clone, Copy, Debug, Default)] +#[derive(Clone, Copy, Debug)] #[non_exhaustive] pub struct KeyRole { /// A value control with a reset value and no text part: Delete resets it. @@ -17,8 +28,10 @@ pub struct KeyRole { pub space: bool, /// A collection that selects several items: Ctrl+Space (Control on macOS) toggles the lead's pick. pub multi_select: bool, - /// A reorderable collection: the stacking keys (`REORDER_KEYS`) move the selected items. - pub reorderable: bool, + /// The scheme whose keys move the selected items of a reorderable collection, `None` when it does not reorder. + pub reorderable: Option, + /// The axis the collection's order is laid out along. + pub reorder_axis: Axis, /// A collection with `CollectionProps.rename`. pub rename: bool, /// `FocusPolicy.pages`: Ctrl+Tab switches pages. @@ -52,6 +65,12 @@ pub struct KeyRole { pub home_row: usize, } +impl Default for KeyRole { + fn default() -> Self { + Self::new() + } +} + impl KeyRole { /// A role with no special rows. pub const fn new() -> KeyRole { @@ -59,7 +78,8 @@ impl KeyRole { resettable: false, space: false, multi_select: false, - reorderable: false, + reorderable: None, + reorder_axis: Axis::Y, rename: false, pages: false, nudge: false, @@ -94,9 +114,15 @@ impl KeyRole { self } - /// The stacking keys move the selected items. - pub const fn reorderable(mut self, on: bool) -> Self { - self.reorderable = on; + /// The scheme's keys move the selected items; `None` when the stop does not reorder. + pub const fn reorderable(mut self, keys: Option) -> Self { + self.reorderable = keys; + self + } + + /// The axis the order is laid out along. + pub const fn reorder_axis(mut self, axis: Axis) -> Self { + self.reorder_axis = axis; self } @@ -221,8 +247,15 @@ pub const REORDER_KEYS: [Chord; 6] = [ Chord::new(Mods { shift: true, ..Mods::CMD }, Key::OpenCurlyBracket), ]; -/// The `Intent::MoveItem` a stacking key asks for, `None` for any other press. -pub fn reorder_intent(key: Key, mods: Mods) -> Option { +/// The four Alt+arrow chords of `ReorderKeys::AltArrows`. +pub const ALT_ARROW_KEYS: [Chord; 4] = + [Chord::new(Mods::ALT, Key::Up), Chord::new(Mods::ALT, Key::Down), Chord::new(Mods::ALT, Key::Left), Chord::new(Mods::ALT, Key::Right)]; + +/// The `Intent::MoveItem` a key of the scheme `keys` asks for in an order laid out along `axis`, `None` for any other +/// press. +pub fn reorder_intent(key: Key, mods: Mods, keys: ReorderKeys, axis: Axis) -> Option { + // P3(pdf-workflows-w1): WF-W3 + let _ = (keys, axis); let chord = Chord::new(mods, key); if !REORDER_KEYS.contains(&chord) { return None; @@ -256,8 +289,9 @@ pub fn intent(os: Os, key: Key, mods: Mods, role: KeyRole) -> Option { if let Some(fine) = fine_move(key, mods, role) { return Some(fine); } - if role.reorderable - && let Some(reorder) = reorder_intent(key, mods) + // P3(pdf-workflows-w1): WF-W4 + if let Some(keys) = role.reorderable + && let Some(reorder) = reorder_intent(key, mods, keys, role.reorder_axis) { return Some(reorder); } diff --git a/crates/behavior/src/lib.rs b/crates/behavior/src/lib.rs index 7ad5665c77..8125639e60 100644 --- a/crates/behavior/src/lib.rs +++ b/crates/behavior/src/lib.rs @@ -23,6 +23,7 @@ pub mod eviction; pub mod fit; pub mod flow; pub mod focus; +pub mod frame_step; pub mod grid; pub mod hit; pub mod input; @@ -33,6 +34,7 @@ pub mod item_source; pub mod keys; pub mod label_column; pub mod layout_memory; +pub mod middle_scroll; pub mod monitor; pub mod motion; pub mod nav; @@ -79,6 +81,7 @@ pub use edit_history::EditHistory; pub use editor::{EditorInput, SurroundingUnit}; pub use flow::{Axis, Flow, Insets}; pub use focus::{CancelRule, KeyOwner, OwnerClass, PressFocus, ScopeKind}; +pub use frame_step::{FRAME_STEP_MAX, frame_step}; pub use grid::{GridCursor, GridMeasure, resolve_columns}; pub use hit::{HitLevel, HitPriority, HitShape, ResolveFor, Shape, Winner, resolve, resolve_mapped}; pub use input::Input; @@ -86,9 +89,10 @@ pub use intent::{AccessRequest, EditCommand, Granularity, Intent, MoveMods, NavM pub use item_layout::{FreeLayout, ItemLayout, LineIndex, SHEET_ZOOM, SheetLayout, SpanLayout, TileLayout}; pub use item_marquee::{MarqueeMode, MarqueeSelect}; pub use item_source::{DisplayOrder, ItemSource, Keyed, Outline, SizeHint, keyed}; -pub use keys::{DropOperation, KeyRole}; +pub use keys::{DropOperation, KeyRole, ReorderKeys}; pub use label_column::{LabelColumn, LabelPlacement}; pub use layout_memory::SizeTween; +pub use middle_scroll::{MiddleButton, MiddleScroll}; pub use monitor::{Monitor, MonitorKey}; pub use motion::{MotionKind, MotionMode, Playback}; pub use nav::{Arrows, Letters, NavOutline, NavShape, NavState, NavStep, Roving, TypeAhead, lead_step, wheel_step}; @@ -115,7 +119,7 @@ pub use value::{ same_in_f32, same_in_f32_at, }; pub use value_drag::{DragWarp, ValueDrag, wrap_value}; -pub use wheel::{GESTURE_GAP, Wheel, WheelFocus, WheelGesture, WheelNotch, WheelPhase, WheelRoom, WheelSource, WheelTaker, WheelUnit}; +pub use wheel::{GESTURE_GAP, Wheel, WheelEase, WheelFocus, WheelGesture, WheelNotch, WheelPhase, WheelRoom, WheelSource, WheelTaker, WheelUnit}; #[cfg(test)] extern crate self as craft_behavior; diff --git a/crates/behavior/src/middle_scroll.rs b/crates/behavior/src/middle_scroll.rs new file mode 100644 index 0000000000..60bf1a9542 --- /dev/null +++ b/crates/behavior/src/middle_scroll.rs @@ -0,0 +1,59 @@ +//! The middle button's auto-scroll latch: the gesture state of one middle press. + +use emath::{Pos2, Vec2}; + +/// What the middle button does over a scroll area. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] +pub enum MiddleButton { + /// Drags the view. + #[default] + Pan, + /// Latches an auto-scroll anchor. + AutoScroll, +} + +/// The auto-scroll latch of one middle press. +#[derive(Clone, Debug, Default, PartialEq)] +#[allow(dead_code)] // P3(pdf-canvas-w2): CV-C8 +pub struct MiddleScroll { + anchor: Option, + held_passes: u32, +} + +impl MiddleScroll { + /// A middle press: inside the scroll area it latches at `at`; a second press ends the latch. + pub fn press(&mut self, at: Pos2, inside: bool) { + let _ = (at, inside); + todo!("CV-C8") + } + + /// The button went up: after two held passes with the pointer past the dead zone the latch ends; an earlier + /// release keeps it. + pub fn release(&mut self) { + todo!("CV-C8") + } + + /// Ends the latch. + pub fn cancel(&mut self) { + todo!("CV-C8") + } + + /// One pass: with this pass's `pointer` and `held` state it counts the held passes past the 15 pt dead zone and + /// returns the vertical scroll for the step `frame_step(dt)`, at `|d|^2.2 × 0.04` points per second, reversed by + /// `invert`. + pub fn step(&mut self, pointer: Pos2, held: bool, dt: f64, invert: bool) -> Vec2 { + let _ = (pointer, held, dt, invert); + todo!("CV-C8") + } + + /// Where the latch is anchored, `None` when there is none. + pub fn anchor(&self) -> Option { + todo!("CV-C8") + } + + /// Whether a latch is active. + pub fn active(&self) -> bool { + todo!("CV-C8") + } +} diff --git a/crates/behavior/src/press.rs b/crates/behavior/src/press.rs index ccd3b16941..d33f1470fe 100644 --- a/crates/behavior/src/press.rs +++ b/crates/behavior/src/press.rs @@ -455,11 +455,14 @@ pub struct PressStep { pub dragging: bool, /// The target released as a click in this pass. pub activated: Option, + /// The start of an open press whose sense has `PASSES_DRAG` and no `DRAG` that moved past slop in this pass: + /// the caller may hand it to the shape below with [`PressMachine::hand_over`]. + pub passes: Option, } impl Default for PressStep { fn default() -> Self { - PressStep { target: None, phase: None, dragging: false, activated: None } + PressStep { target: None, phase: None, dragging: false, activated: None, passes: None } } } @@ -633,7 +636,7 @@ impl PressMachine { } if let Some((target, start, reason)) = cancelled { let phase = PressPhase::Cancel { start, reason }; - return PressStep { target: Some(target), phase: Some(phase), dragging: false, activated: None }; + return PressStep { target: Some(target), phase: Some(phase), dragging: false, activated: None, passes: None }; } if let Some((target, start, at, was_dragging, click)) = released { let phase = PressPhase::Release { start, pos: at, click }; @@ -642,6 +645,7 @@ impl PressMachine { phase: Some(phase), dragging: was_dragging, activated: (click && start.button == PointerButton::Primary).then_some(target), + passes: None, }; } let Some(open) = self.open.as_mut() else { return PressStep::default() }; @@ -656,7 +660,15 @@ impl PressMachine { PressPhase::Held { start: open.start, pos } }; open.reported = true; - PressStep { target: Some(open.target), phase: Some(phase), dragging: open.drag_reported, activated: None } + PressStep { target: Some(open.target), phase: Some(phase), dragging: open.drag_reported, activated: None, passes: None } + } + + /// Makes `target` the open press's target in the pass that reported `passes`, dragging from the same + /// `PressStart`. It returns the `DragStart` step when an earlier pass reported the press, and the `Down` step + /// (the `DragStart` follows in the next pass) when the move past slop came in the pass of the press itself. + pub fn hand_over(&mut self, target: T, sense: Sense) -> Option> { + let _ = (target, sense); + todo!("CV-C12") } } diff --git a/crates/behavior/src/sense.rs b/crates/behavior/src/sense.rs index 077310f662..1ce093c502 100644 --- a/crates/behavior/src/sense.rs +++ b/crates/behavior/src/sense.rs @@ -50,6 +50,9 @@ bitflags! { /// with `DRAG` by a part whose click does nothing a drag could be mistaken for (a transform box's handles). /// The component begins the gesture from `PressPhase::Held`. const FOLLOWS_IN_SLOP = 65536; + /// A shape that clicks and passes its drag: within slop the press stays its click; past slop the drag goes to + /// the shape below it that senses a drag. + const PASSES_DRAG = 131072; } } diff --git a/crates/behavior/src/wheel.rs b/crates/behavior/src/wheel.rs index 625f684bbd..91bbec6723 100644 --- a/crates/behavior/src/wheel.rs +++ b/crates/behavior/src/wheel.rs @@ -86,6 +86,47 @@ pub struct Wheel { pub rotation: f32, /// Rotation of a two-finger touch, in radians. pub touch_rotation: f32, + /// The running gesture's scroll gathered so far, this share included, in its owner's points. + pub gathered: Vec2, + /// Whether the owner marked the running gesture moved (`Pointer::mark_wheel_moved`). + pub moved: bool, +} + +/// The eased motion of a canvas's line wheel: notches gather into owed motion that later passes pay out. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[allow(dead_code)] // P3(pdf-canvas-w4): CV-C2 +pub struct WheelEase { + owed: Vec2, + burst: u32, + last_notch: f64, + last_sign: Vec2, + last_paid: f64, +} + +impl WheelEase { + /// Adds the line pan `pan` of this pass, at time `now`, to the owed motion; a burst of notches under 0.08 s apart + /// accelerates it, a reversal or 0.3 s idle resets the burst. + pub fn feed(&mut self, pan: Vec2, now: f64) { + let _ = (pan, now); + todo!("CV-C2") + } + + /// Drops the owed motion on the axes marked. + pub fn cancel_axis(&mut self, x: bool, y: bool) { + let _ = (x, y); + todo!("CV-C2") + } + + /// The step this pass pays at time `now`: `1 − 0.1^(dt/0.1)` of the owed motion, with `dt` since the last paid pass. + pub fn step(&mut self, now: f64) -> Vec2 { + let _ = now; + todo!("CV-C2") + } + + /// Whether motion is still owed. + pub fn owes(&self) -> bool { + todo!("CV-C2") + } } impl Wheel { @@ -104,6 +145,8 @@ impl Wheel { touch_zoom: 1.0, rotation: 0.0, touch_rotation: 0.0, + gathered: Vec2::ZERO, + moved: false, } } diff --git a/crates/fonts-build/src/lib.rs b/crates/fonts-build/src/lib.rs index c4821bf246..91073a510b 100644 --- a/crates/fonts-build/src/lib.rs +++ b/crates/fonts-build/src/lib.rs @@ -62,7 +62,7 @@ mod sha256; mod tests; pub use embed::{Embed, Error, target_is_wasm}; -pub use manifest::{CJK_SCRIPTS, MONO_ROLE, ManifestEntry, ParseError, UI_ROLE, parse_manifest}; +pub use manifest::{CJK_SCRIPTS, MONO_ROLE, ManifestEntry, ParseError, SIGNATURE_ROLE, UI_ROLE, parse_manifest}; /// A craft-fonts face embedded by [`Embed`]: one line of `fonts/manifest.txt`. /// diff --git a/crates/fonts-build/src/manifest.rs b/crates/fonts-build/src/manifest.rs index c4576aacb9..89ecd8ee7d 100644 --- a/crates/fonts-build/src/manifest.rs +++ b/crates/fonts-build/src/manifest.rs @@ -68,6 +68,9 @@ pub const UI_ROLE: &str = "ui"; /// The `role` of the monospace face (JetBrains Mono): the Monospace stack leads with the embedded face that has it. pub const MONO_ROLE: &str = "mono"; +/// The `role` of a signature face: `FontRef::signature()` selects the embedded faces that have it. +pub const SIGNATURE_ROLE: &str = "signature"; + /// Script tags of the CJK faces, which craft-fonts also ships as interface faces. `Hant` covers /// `Hant-HK`. pub const CJK_SCRIPTS: &[&str] = &["Hans", "Hant", "Jpan", "Kore", "Hani"]; diff --git a/crates/platform/src/appearance.rs b/crates/platform/src/appearance.rs index d92ac9db81..862d168a4b 100644 --- a/crates/platform/src/appearance.rs +++ b/crates/platform/src/appearance.rs @@ -228,6 +228,11 @@ impl Watcher { _ => None, } } + /// GNOME's `text-scaling-factor` through the portal (the gsettings fallback), clamped to 0.5..=3.0. A change + /// raises the generation and wakes, as the other appearance values do. `None` where the platform does not say. + pub fn text_scale(&self) -> Option { + todo!("SH-C24") + } /// Block until the first answer is known, then return it; at most `timeout`. /// /// Returns early, with `current()`, when the portal is absent and the `gsettings` fallback diff --git a/crates/platform/src/appearance/reader.rs b/crates/platform/src/appearance/reader.rs index e554555670..7fc21f27bd 100644 --- a/crates/platform/src/appearance/reader.rs +++ b/crates/platform/src/appearance/reader.rs @@ -118,6 +118,12 @@ impl SystemReader { self.watcher.as_ref().and_then(Watcher::icon_theme) } + /// The desktop text scale as the watcher last heard it; see [`Watcher::text_scale`]. `None` where the platform + /// does not say. + pub fn text_scale(&self) -> Option { + todo!("SH-C24") + } + /// The preferences now, without blocking. pub fn read(&self) -> Reading { let reported = &self.reported; diff --git a/crates/platform/src/autosave/recovery.rs b/crates/platform/src/autosave/recovery.rs index 90e3b84c74..38931bb427 100644 --- a/crates/platform/src/autosave/recovery.rs +++ b/crates/platform/src/autosave/recovery.rs @@ -78,6 +78,9 @@ pub struct RecoveryMeta { pub extension: String, /// The edit revision the copy holds. pub revision: u64, + /// The recovered copy needs a password to open. Old sidecars read as `false`. + #[serde(default)] + pub protected: bool, } /// A copy an earlier run left. @@ -225,7 +228,8 @@ impl RecoveryStore { None if self.owns_key(&key) || self.other_instance_alive() => None, None => copies.first().map(|(ext, path)| { let saved = std::fs::metadata(path).and_then(|m| m.modified()).unwrap_or(SystemTime::UNIX_EPOCH); - let meta = RecoveryMeta { name: key.clone(), original: None, extension: ext.clone(), revision: 0 }; + // P3(pdf-shell-w3): SH-C28 + let meta = RecoveryMeta { name: key.clone(), original: None, extension: ext.clone(), revision: 0, protected: false }; RecoveryEntry { key: key.clone(), meta, saved, path: path.clone() } }), }; diff --git a/crates/platform/src/autosave_tests.rs b/crates/platform/src/autosave_tests.rs index f26ec3891b..7eb9d90208 100644 --- a/crates/platform/src/autosave_tests.rs +++ b/crates/platform/src/autosave_tests.rs @@ -30,7 +30,8 @@ fn doc(id: u64, revision: u64, dirty: bool) -> AutosaveDoc { } fn meta(name: &str, revision: u64) -> RecoveryMeta { - RecoveryMeta { name: name.into(), original: None, extension: "pcraft".into(), revision } + // P3(pdf-shell-w3): SH-C28 + RecoveryMeta { name: name.into(), original: None, extension: "pcraft".into(), revision, protected: false } } // Nothing is due before the interval; then only dirty documents with a new revision and no diff --git a/crates/platform/src/clipboard/backend.rs b/crates/platform/src/clipboard/backend.rs index 1a6a781607..ebd65107ab 100644 --- a/crates/platform/src/clipboard/backend.rs +++ b/crates/platform/src/clipboard/backend.rs @@ -4,7 +4,7 @@ use std::borrow::Cow; use std::path::PathBuf; -use super::convert::{rgba8_flavor, rgba8_image, trim_cr, uri_list}; +use super::convert::{parse_uri_list, rgba8_flavor, rgba8_image, trim_cr, uri_list}; use super::types::{BITMAP, ClipboardError, ClipboardImage, Flavor, HTML, PNG, RGBA8, TEXT, URI_LIST}; /// What a write did. @@ -321,6 +321,7 @@ pub(crate) enum Put { Image(ClipboardImage), Html { html: String, alt: Option }, Text(String), + Files(Vec), } /// The first flavor the system clipboard can hold, as its index in `flavors` and what to put @@ -345,6 +346,7 @@ pub(crate) fn plan_write(flavors: &[Flavor], decode: Option<&Decode>) -> Result< } HTML => return Ok((index, Put::Html { html: text_of(flavor), alt: flavors.iter().find(|f| f.mime == TEXT).map(text_of) })), TEXT => return Ok((index, Put::Text(text_of(flavor)))), + URI_LIST => return Ok((index, Put::Files(parse_uri_list(&text_of(flavor))))), _ => {} } } @@ -371,6 +373,10 @@ impl ClipboardBackend for SystemClipboard { } Put::Html { html, alt } => handle.set_html(html, alt), Put::Text(text) => handle.set_text(text), + Put::Files(files) => { + let _ = files; + todo!("SH-C27") + } } .map_err(system_error)?; Ok(index) diff --git a/crates/platform/src/clipboard/types.rs b/crates/platform/src/clipboard/types.rs index 6107c16084..53fb923c46 100644 --- a/crates/platform/src/clipboard/types.rs +++ b/crates/platform/src/clipboard/types.rs @@ -36,6 +36,12 @@ pub struct Flavor { } impl Flavor { + /// A [`URI_LIST`] flavor (RFC 2483) of the files `paths`. + pub fn files(paths: &[std::path::PathBuf]) -> Flavor { + let _ = paths; + todo!("SH-C27") + } + /// A flavor of `data` with the given MIME type. pub fn new(mime: impl Into>, data: Vec) -> Self { Self { mime: mime.into(), data } diff --git a/crates/platform/src/lib.rs b/crates/platform/src/lib.rs index 13f43a4441..c5cb190ec9 100644 --- a/crates/platform/src/lib.rs +++ b/crates/platform/src/lib.rs @@ -27,6 +27,7 @@ mod message_tests; pub mod open; #[cfg(test)] mod open_tests; +pub mod owner_only; pub mod pacing; #[cfg(feature = "pointer")] pub mod pointer; diff --git a/crates/platform/src/open.rs b/crates/platform/src/open.rs index 6cebea4691..b2700a29d0 100644 --- a/crates/platform/src/open.rs +++ b/crates/platform/src/open.rs @@ -82,6 +82,20 @@ pub enum Intake { /// Where they landed. target: DropTarget, }, + /// The OS asked to open these absolute paths for the app's own action. + OpenFor { + /// The files, absolute and sorted. + paths: Vec, + /// The app's action name. + action: String, + }, + /// A file that arrived as bytes, with no path. + Bytes { + /// The file's name. + name: String, + /// The contents. + bytes: Arc<[u8]>, + }, } /// The sending side of a [`FileIntake`]: `Send + Clone`, for the threads that hear the OS (the @@ -109,6 +123,19 @@ impl IntakeSender { push(&self.queue, Intake::Open(paths)); self.wake.wake(); } + + /// Queues an open request for the app's own `action`, made absolute and sorted as [`open`](Self::open) does, and + /// wakes the UI. Empty input is ignored. + pub fn open_for(&self, paths: Vec, action: impl Into) { + let _ = (paths, action); + todo!("SH-C22") + } + + /// Queues a file that arrived as bytes, and wakes the UI. + pub fn open_bytes(&self, name: String, bytes: Arc<[u8]>) { + let _ = (name, bytes); + todo!("SH-C22") + } } /// Files waiting to be opened, read once per frame on the UI thread (spec Q-S4F-7). @@ -309,6 +336,14 @@ fn reveal_command(platform: &str, path: &Path) -> Result<(&'static str, Vec Result<(), String> { + let _ = target; + todo!("SH-C23") +} + /// Opens a file or an `http(s)` URL with the system's handler (`open`, `rundll32 /// url.dll,FileProtocolHandler`, `xdg-open`), without waiting for it. Not on wasm (the browser /// module opens URLs there). diff --git a/crates/platform/src/owner_only.rs b/crates/platform/src/owner_only.rs new file mode 100644 index 0000000000..404fca0584 --- /dev/null +++ b/crates/platform/src/owner_only.rs @@ -0,0 +1,45 @@ +//! Owner-only files: a token file that only its user can read, as mode 0600 makes it on Unix. On Windows a file +//! inherits its folder's access list, so these functions replace it with the current user and SYSTEM only and read a +//! file with its security descriptor through one handle. + +/// Why the file whose security descriptor is `sddl` (`O:` owner and `D:` access list, in SDDL) can't be trusted as +/// user `me`'s own: it is owned by someone else, it has no access list, or it lets an account other than `me` or SYSTEM +/// use it. `None` means it is `me`'s alone. +pub fn foreign_access(sddl: &str, me: &str) -> Option { + let _ = (sddl, me); + todo!("SH-C26") +} + +/// The SID of the current user, as text. +#[cfg(windows)] +pub fn current_user_sid() -> std::io::Result { + todo!("SH-C26") +} + +/// Replaces the access list of `path` with user `me` and SYSTEM only, makes `me` the owner, and checks the result. +#[cfg(windows)] +pub fn restrict_to_owner(path: &std::path::Path, me: &str) -> std::io::Result<()> { + let _ = (path, me); + todo!("SH-C26") +} + +/// Creates the folder `dir` private to user `me`, so a file created in it is private from the moment it exists. +#[cfg(windows)] +pub fn create_private_dir(dir: &std::path::Path, me: &str) -> std::io::Result<()> { + let _ = (dir, me); + todo!("SH-C26") +} + +/// The security descriptor of `path` in SDDL form. +#[cfg(windows)] +pub fn sddl_of(path: &std::path::Path) -> std::io::Result { + let _ = path; + todo!("SH-C26") +} + +/// Reads at most `max` bytes of `path` and its security descriptor in SDDL form through one handle. +#[cfg(windows)] +pub fn read_with_sddl(path: &std::path::Path, max: u64) -> std::io::Result<(String, Vec)> { + let _ = (path, max); + todo!("SH-C26") +} diff --git a/crates/window/src/policy.rs b/crates/window/src/policy.rs index 6873c5710e..dd4e34820b 100644 --- a/crates/window/src/policy.rs +++ b/crates/window/src/policy.rs @@ -287,6 +287,15 @@ pub fn apply(builder: egui::ViewportBuilder, frame: &Frame) -> egui::ViewportBui } } +/// The commands that move an open window from the frame `from` to `to`, the runtime twin of [`apply`]: `Native` to +/// `Integrated` gives `Decorations(false)`, the reverse `Decorations(true)`, two `Integrated` or two equal frames +/// `[]`. A change to or from `Inset` gives `None`, as egui has no runtime command for its builder-only settings. +#[cfg(feature = "ui")] +pub fn reframe(from: &Frame, to: &Frame) -> Option> { + let _ = (from, to); + todo!("SH-C37") +} + impl From<&crate::Frame> for Frame { /// The old two-way frame as a new one: `Desktop` is `Native`, `App(layout)` is integrated /// with generic captions. diff --git a/crates/window/src/restore/legacy.rs b/crates/window/src/restore/legacy.rs index bf1d862a72..a0dc41f660 100644 --- a/crates/window/src/restore/legacy.rs +++ b/crates/window/src/restore/legacy.rs @@ -18,8 +18,8 @@ use craft_behavior::placement::Placement; /// The placement in an eframe `app.ron` text: its `"window"` entry, with the size converted to /// points at zoom 1 using the `"egui"` entry's `zoom_factor` (1 when absent). pub fn eframe_app_ron(text: &str) -> Option { - let window = ron_string_entry(text, "window")?; - let zoom = ron_string_entry(text, "egui").and_then(|e| number(field(&e, "zoom_factor")?)).unwrap_or(1.0); + let window = eframe_app_ron_entry(text, "window")?; + let zoom = eframe_app_ron_entry(text, "egui").and_then(|e| number(field(&e, "zoom_factor")?)).unwrap_or(1.0); eframe_window_settings(&window, zoom) } @@ -142,7 +142,7 @@ fn vec2(s: &str) -> Option<[f32; 2]> { } /// The string value for `key` in a RON map of strings (`{"key": "value", …}`), unescaped. -fn ron_string_entry(text: &str, key: &str) -> Option { +pub fn eframe_app_ron_entry(text: &str, key: &str) -> Option { let mut literals = string_literals(text).into_iter(); while let Some(k) = literals.next() { let v = literals.next()?; From aafc82051ec9ac5a3c51ada51a35ea0035998f97 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 17 Nov 2026 22:38:38 -0500 Subject: [PATCH 003/379] Contract stubs: craft-ui-contract --- crates/ui-contract/src/contract/body/hooks.rs | 4 +- .../ui-contract/src/contract/body/reorder.rs | 4 +- .../src/contract/collection/props.rs | 21 ++++++++++- .../src/contract/collection/response.rs | 8 +++- crates/ui-contract/src/contract/container.rs | 3 ++ crates/ui-contract/src/contract/cx/pointer.rs | 34 ++++++++++++++++- crates/ui-contract/src/contract/entry.rs | 26 ++++++++++++- crates/ui-contract/src/contract/items.rs | 3 ++ .../ui-contract/src/contract/items/hooks.rs | 4 +- crates/ui-contract/src/contract/mod.rs | 1 + .../ui-contract/src/contract/steps/report.rs | 2 + crates/ui-contract/src/fonts/mod.rs | 6 +++ crates/ui-contract/src/fonts/stack.rs | 5 ++- crates/ui-contract/src/fonts/stack/chain.rs | 2 +- .../src/primitives/auto_scroll_mark.rs | 37 +++++++++++++++++++ crates/ui-contract/src/primitives/draw.rs | 24 +++++++++++- crates/ui-contract/src/primitives/mod.rs | 13 ++++--- .../ui-contract/src/primitives/text_input.rs | 15 ++++++++ .../src/primitives/textures/loader.rs | 3 +- .../src/primitives/textures/mod.rs | 4 +- .../src/primitives/textures/thumbnails.rs | 28 +++++++++++++- .../src/primitives/textures/words.rs | 3 ++ crates/ui-contract/src/runtime/access/emit.rs | 9 +++-- .../ui-contract/src/runtime/commands/board.rs | 9 +++++ .../ui-contract/src/runtime/commands/mod.rs | 3 ++ crates/ui-contract/src/runtime/egui/access.rs | 20 +++++++++- .../src/runtime/egui/access/node.rs | 3 ++ .../src/runtime/egui/access/tree.rs | 14 +++++-- .../ui-contract/src/runtime/egui/injected.rs | 25 +++++++++++++ crates/ui-contract/src/runtime/egui/plugin.rs | 5 +++ crates/ui-contract/src/runtime/env.rs | 2 +- crates/ui-contract/src/runtime/env/system.rs | 6 +++ crates/ui-contract/src/runtime/frame.rs | 3 ++ crates/ui-contract/src/runtime/toast.rs | 15 ++++++++ crates/ui-contract/src/runtime/wheel.rs | 27 ++++++++++++++ .../ui-contract/src/runtime/windows/host.rs | 32 ++++++++++++++++ crates/ui-contract/src/style/cx.rs | 12 ++++++ crates/ui-macros/src/props.rs | 1 + 38 files changed, 407 insertions(+), 29 deletions(-) create mode 100644 crates/ui-contract/src/primitives/auto_scroll_mark.rs diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index e5d94a6f31..5ac65d9d51 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -121,7 +121,9 @@ impl ShapeHooks for BodyHooks<'_> { fn key_role(&self, comp: &C) -> KeyRole { let props = comp.props(Internal::new()); - KeyRole::new().reorderable(props.header.is_some_and(|header| header.band == DragBand::Reorder)).document(props.scroll_owner) + KeyRole::new() + .reorderable(props.header.is_some_and(|header| header.band == DragBand::Reorder).then_some(craft_behavior::ReorderKeys::Stacking)) // P3(pdf-workflows-w1): WF-W4 + .document(props.scroll_owner) } fn position(&self, comp: &C) -> Option { diff --git a/crates/ui-contract/src/contract/body/reorder.rs b/crates/ui-contract/src/contract/body/reorder.rs index 8b2c51f258..e04d8b40ad 100644 --- a/crates/ui-contract/src/contract/body/reorder.rs +++ b/crates/ui-contract/src/contract/body/reorder.rs @@ -28,7 +28,9 @@ impl BodyHooks<'_> { keys::capture(&ctx, id, chord); } while keys::take_claimed(&ctx, id, chord) { - if let Some(intent) = key_table::reorder_intent(chord.key, chord.mods) { + if let Some(intent) = key_table::reorder_intent(chord.key, chord.mods, craft_behavior::ReorderKeys::Stacking, craft_behavior::Axis::Y) + { + // P3(pdf-workflows-w1): WF-W3 cx.core.intents.push(intent); } } diff --git a/crates/ui-contract/src/contract/collection/props.rs b/crates/ui-contract/src/contract/collection/props.rs index 081ae575be..6dea6475bb 100644 --- a/crates/ui-contract/src/contract/collection/props.rs +++ b/crates/ui-contract/src/contract/collection/props.rs @@ -34,12 +34,21 @@ pub struct ReorderRule { /// In a tree, a drop or a stacking-key move may land inside a group, and `ReorderMove::parent` names the group. A row /// that `has_children` is a group; an open group without visible children takes items through the middle of its row. pub into_groups: bool, + /// The key scheme that reorders the collection's items; default `Stacking`. + pub keys: craft_behavior::ReorderKeys, } impl ReorderRule { /// A rule that only moves. pub const fn new() -> Self { - ReorderRule { copy_with_alt: false, into_groups: false } + ReorderRule { copy_with_alt: false, into_groups: false, keys: craft_behavior::ReorderKeys::Stacking } + } + + /// The key scheme that reorders the items. + #[must_use] + pub const fn keys(mut self, keys: craft_behavior::ReorderKeys) -> Self { + self.keys = keys; + self } /// Items may land inside the groups of a tree. @@ -229,6 +238,8 @@ pub struct CollectionProps { pub command_click: bool, /// The distance one wheel notch scrolls the rows; unset, the default notch. pub notch: Option, + /// What a middle press does: pan or latched auto-scroll. + pub middle_button: craft_behavior::MiddleButton, /// The axis the rows overflow along. A collection owns the scroll along it, so it sits only in a scrolling body /// that does not scroll along it too: a strip of tabs (`Axis::X`) sits in a page that scrolls vertically. pub overflow: Axis, @@ -320,6 +331,7 @@ impl CollectionProps { row_height: RowHeight::Control, command_click: false, notch: None, + middle_button: craft_behavior::MiddleButton::Pan, overflow: Axis::Y, pages: false, current: None, @@ -567,6 +579,13 @@ impl CollectionProps { self } + /// What a middle press does: pan, or latched auto-scroll (see [`CollectionProps::middle_button`]). + #[must_use] + pub const fn middle_button(mut self, button: craft_behavior::MiddleButton) -> Self { + self.middle_button = button; + self + } + /// The wheel distance of one notch, with a text line `line` points high: the set notch, else the default. pub fn wheel_notch(&self, line: f32) -> craft_behavior::WheelNotch { self.notch.map_or(craft_behavior::WheelNotch::DEFAULT, |notch| notch.wheel(line)) diff --git a/crates/ui-contract/src/contract/collection/response.rs b/crates/ui-contract/src/contract/collection/response.rs index da4ca07fe1..4d0fae5ac0 100644 --- a/crates/ui-contract/src/contract/collection/response.rs +++ b/crates/ui-contract/src/contract/collection/response.rs @@ -31,6 +31,8 @@ pub struct CollectionResponse { /// While a drag is over the collection, the drop its release would make; `None` when the collection would take /// none. An app previews it (a layer move on the canvas); the drop itself comes as its event. pub pending_drop: Option>, + /// The row under the pointer this pass; `None` during a drag. + pub hovered: Option, } /// The drop a release would make on a collection now. @@ -46,7 +48,7 @@ pub enum PendingDrop { impl CollectionResponse { pub(crate) fn new( response: Response, - ItemsOut { events, shown, activation_clicks, pending_drop }: ItemsOut, + ItemsOut { events, shown, activation_clicks, pending_drop, hovered }: ItemsOut, visible: Range, gestures: Gestures, ) -> Self { @@ -60,6 +62,7 @@ impl CollectionResponse { reorder: gestures.reorder, activation_clicks, pending_drop, + hovered, } } @@ -76,11 +79,12 @@ pub(crate) struct ItemsOut { pub(crate) shown: Vec>, pub(crate) activation_clicks: u8, pub(crate) pending_drop: Option>, + pub(crate) hovered: Option, } impl Default for ItemsOut { fn default() -> Self { - ItemsOut { events: Vec::new(), shown: Vec::new(), activation_clicks: 0, pending_drop: None } + ItemsOut { events: Vec::new(), shown: Vec::new(), activation_clicks: 0, pending_drop: None, hovered: None } } } diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 7dc25b8928..15adf9db80 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -184,6 +184,8 @@ pub enum LeastWidth { DialogSideButton, /// `size.rail.width` per column: a tool rail of this many columns, as wide as the shell slot that holds it. Rail(std::num::NonZeroU8), + /// `size.dock.column`: a fixed side pane is as wide as a dock column. + DockColumn, } impl LeastWidth { @@ -195,6 +197,7 @@ impl LeastWidth { LeastWidth::DialogButton => tokens.size.dialog.button, LeastWidth::DialogSideButton => tokens.size.dialog.side_button, LeastWidth::Rail(columns) => tokens.size.rail.width * f32::from(columns.get()), + LeastWidth::DockColumn => tokens.size.dock.column, } } } diff --git a/crates/ui-contract/src/contract/cx/pointer.rs b/crates/ui-contract/src/contract/cx/pointer.rs index f405877b23..623ae4e1fc 100644 --- a/crates/ui-contract/src/contract/cx/pointer.rs +++ b/crates/ui-contract/src/contract/cx/pointer.rs @@ -7,7 +7,7 @@ use crate::runtime::drag::{self, DragPreview, DropTarget, DropZone, Typed, Windo use crate::runtime::egui::areas; use crate::runtime::{cursor, frame, pointer, wheel}; use craft_behavior::{Cursor, CursorPriority, DropOperation, PartKey, PartRef, PressCancel, PressState, Wheel}; -use egui::{Id, Pos2}; +use egui::{Id, Pos2, Vec2}; use std::any::{Any, TypeId}; use std::ops::Range; use std::sync::Arc; @@ -35,6 +35,14 @@ pub trait Pointer { fn activated_member(&self) -> Option; /// This pass's wheel share, once, with the pointer it came at (`Wheel::at`) in this component's egui layer space (8.3). fn take_wheel(&mut self) -> Option; + /// Marks the wheel gesture this component owns, while it runs, as moved (its view changed): later shares of the + /// gesture report `Wheel::moved`. + fn mark_wheel_moved(&mut self); + /// Feeds `pan`, the line pan this pass gave, to this component's wheel ease and returns the eased step for this + /// pass. `Vec2::ZERO` on a pass with no line pan lets owed motion keep paying. + fn ease_wheel(&mut self, pan: Vec2) -> Vec2; + /// Drops this component's wheel ease and the motion it owes. + fn stop_wheel_ease(&mut self); /// Requests `cursor` at `priority`; the highest priority of the pass wins. fn cursor(&mut self, cursor: impl Into, priority: CursorPriority); /// Ends every captured press of this viewport. @@ -107,6 +115,18 @@ impl Pointer for CxCore<'_> { Some(wheel) } + fn mark_wheel_moved(&mut self) { + wheel::mark_moved(&self.ctx, self.id); + } + + fn ease_wheel(&mut self, pan: Vec2) -> Vec2 { + wheel::ease(&self.ctx, self.id, pan) + } + + fn stop_wheel_ease(&mut self) { + wheel::stop_ease(&self.ctx, self.id); + } + fn cursor(&mut self, cursor: impl Into, priority: CursorPriority) { if self.cursor.as_ref().is_none_or(|(_, held)| priority > *held) { self.cursor = Some((cursor.into(), priority)); @@ -198,6 +218,18 @@ impl Pointer for Cx<'_, C> { self.core.take_wheel() } + fn mark_wheel_moved(&mut self) { + self.core.mark_wheel_moved(); + } + + fn ease_wheel(&mut self, pan: Vec2) -> Vec2 { + self.core.ease_wheel(pan) + } + + fn stop_wheel_ease(&mut self) { + self.core.stop_wheel_ease(); + } + fn cursor(&mut self, cursor: impl Into, priority: CursorPriority) { self.core.cursor(cursor, priority); } diff --git a/crates/ui-contract/src/contract/entry.rs b/crates/ui-contract/src/contract/entry.rs index 51bae9f289..91380c025d 100644 --- a/crates/ui-contract/src/contract/entry.rs +++ b/crates/ui-contract/src/contract/entry.rs @@ -30,6 +30,8 @@ struct Item { icon: Option>, enabled: bool, reason: Option