From 2d810dfdc73c04dd43da364c5b08c17877f3f092 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Wed, 18 Nov 2026 12:11:18 +0000 Subject: [PATCH] Contract stubs: save answer records_file, DocumentMap page, UpdateCheckDialog::words (S-L159, S-L162, S-L164) --- crates/automation/src/synthetic.rs | 22 +++++++++++----------- crates/automation/tests/it/synthetic.rs | 12 +++++++----- crates/host/src/files.rs | 10 ++++++++++ crates/update/src/stack_dialogs.rs | 14 ++++++++++++-- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/crates/automation/src/synthetic.rs b/crates/automation/src/synthetic.rs index 90e16fc1b..96024d958 100644 --- a/crates/automation/src/synthetic.rs +++ b/crates/automation/src/synthetic.rs @@ -49,9 +49,9 @@ pub const OFF_SCREEN: &str = "the document point is too far off the screen"; /// The error of a point that is not finite (NaN or infinite): refused at the request, never queued. pub const NOT_FINITE: &str = "the point must be finite"; -/// The application's map from a document point to the screen point its canvas shows it at; `None` when no canvas -/// shows a document. Applications without documents pass `&|_| None`. -pub type DocumentMap<'a> = &'a dyn Fn(Pos2) -> Option; +/// The application's map from a page and a document point on it to the screen point its canvas shows it at; `None` +/// when no canvas shows a document. Applications without documents pass `&|_, _| None`. +pub type DocumentMap<'a> = &'a dyn Fn(usize, Pos2) -> Option; /// A point of a request: screen points, or document points the application maps. #[derive(Clone, Copy, Debug, PartialEq)] @@ -59,8 +59,8 @@ pub type DocumentMap<'a> = &'a dyn Fn(Pos2) -> Option; pub enum At { /// Screen points. Screen(Pos2), - /// Document points. - Document(Pos2), + /// Document points on page `page` (0 when the request names none). + Document(Pos2, usize), } impl At { @@ -70,7 +70,7 @@ impl At { let x = p.number_in("x", "x", range)?.unwrap_or(0.0) as f32; let y = p.number_in("y", "y", range)?.unwrap_or(0.0) as f32; Ok(match p.choice("coordinates", "coordinates", &["screen", "document"])?.unwrap_or("screen") { - "document" => Self::Document(pos2(x, y)), + "document" => Self::Document(pos2(x, y), p.uint_field("page")?.map_or(0, |page| usize::try_from(page).unwrap_or(usize::MAX))), _ => Self::Screen(pos2(x, y)), }) } @@ -81,9 +81,9 @@ impl At { match self { Self::Screen(at) if at.x.is_finite() && at.y.is_finite() => Ok(at), Self::Screen(_) => Err(NOT_FINITE.to_owned()), - Self::Document(at) if !(at.x.is_finite() && at.y.is_finite()) => Err(NOT_FINITE.to_owned()), - Self::Document(at) => { - let on_screen = map(at).ok_or_else(|| NO_DOCUMENT.to_owned())?; + Self::Document(at, _) if !(at.x.is_finite() && at.y.is_finite()) => Err(NOT_FINITE.to_owned()), + Self::Document(at, page) => { + let on_screen = map(page, at).ok_or_else(|| NO_DOCUMENT.to_owned())?; let within = |v: f32| v.is_finite() && f64::from(v.abs()) <= MAX_SCREEN_POINT; if within(on_screen.x) && within(on_screen.y) { Ok(on_screen) } else { Err(OFF_SCREEN.to_owned()) } } @@ -92,7 +92,7 @@ impl At { } /// The point fields every pointer request takes. -const POINT: [&str; 3] = ["x", "y", "coordinates"]; +const POINT: [&str; 4] = ["x", "y", "coordinates", "page"]; /// The modifier fields ([`crate::protocol::KEY_MODIFIERS`], top-level or under `modifiers`). const MODIFIERS: [&str; 5] = ["modifiers", "shift", "alt", "command", "ctrl"]; @@ -263,7 +263,7 @@ impl Release { /// `{button?, key?, x?, y?, coordinates?}`, no other fields. With neither `button` nor `key` everything held is /// released, the modifiers too; both is ``"`button` and `key` exclude each other"``. pub fn from_params(params: &Value) -> Result { - let p = Params(params).only(None, &["button", "key", "x", "y", "coordinates"])?; + let p = Params(params).only(None, &["button", "key", "x", "y", "coordinates", "page"])?; let p = Params(&p); let released = match (button(&p)?, key(&p)?) { (Some(_), Some(_)) => return Err("`button` and `key` exclude each other".into()), diff --git a/crates/automation/tests/it/synthetic.rs b/crates/automation/tests/it/synthetic.rs index a8e99ee5e..35598a92b 100644 --- a/crates/automation/tests/it/synthetic.rs +++ b/crates/automation/tests/it/synthetic.rs @@ -33,7 +33,8 @@ struct Rig { } /// Document points are screen points doubled, as a canvas at 50 % shows them. -fn map(at: Pos2) -> Option { +// P3(platform-w6): S-L162 +fn map(_page: usize, at: Pos2) -> Option { Some(pos2(at.x / 2.0, at.y / 2.0)) } @@ -208,7 +209,8 @@ fn injected_passes_are_the_passes_that_carry_a_step() { fn document_points_need_a_canvas() { let rig = Rig::new(); let host = rig.host(); - let none = |_: Pos2| None; + // P3(platform-w6): S-L162 + let none = |_: usize, _: Pos2| None; let refused = input_method("ui.move", &json!({"x": 1, "y": 1, "coordinates": "document"}), &host, ViewportId::ROOT, &none); assert_eq!(refused, Some(Err(NO_DOCUMENT.to_owned()))); assert!(host.injected_idle()); @@ -341,9 +343,9 @@ fn ui_ime_reaches_a_focused_text_field_as_a_preedit_then_a_commit_in_order() { #[trial] fn a_point_that_is_not_finite_is_refused() { for bad in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY] { - for at in [At::Screen(pos2(bad, 1.0)), At::Screen(pos2(1.0, bad)), At::Document(pos2(bad, 1.0))] { - assert_eq!(at.resolve(&|p| Some(p)), Err(NOT_FINITE.to_owned()), "{at:?}"); + for at in [At::Screen(pos2(bad, 1.0)), At::Screen(pos2(1.0, bad)), At::Document(pos2(bad, 1.0), 0)] { + assert_eq!(at.resolve(&|_, p| Some(p)), Err(NOT_FINITE.to_owned()), "{at:?}"); } } - assert_eq!(At::Screen(pos2(3.0, 4.0)).resolve(&|_| None), Ok(pos2(3.0, 4.0))); + assert_eq!(At::Screen(pos2(3.0, 4.0)).resolve(&|_, _| None), Ok(pos2(3.0, 4.0))); } diff --git a/crates/host/src/files.rs b/crates/host/src/files.rs index 4dd7f51d0..8b363f4c7 100644 --- a/crates/host/src/files.rs +++ b/crates/host/src/files.rs @@ -192,6 +192,16 @@ impl Picked { } } + /// Whether the page now holds the document as the file a finished save wrote: true for a + /// path the service wrote (native hosts, the in-memory fake), false for a browser download + /// and for every answer that is not a written path. The app sets its session path only when + /// this is true. + pub fn records_file(&self) -> bool { + // P3(platform-w4): S-L159 a hosted browser page that holds the file answers true too; the + // variants cannot say so yet. + matches!(self, Picked::Paths(paths) if !paths.is_empty()) + } + /// Every chosen path; on wasm the files' names. Empty when cancelled or unavailable. pub fn paths(&self) -> Vec { match self { diff --git a/crates/update/src/stack_dialogs.rs b/crates/update/src/stack_dialogs.rs index 1206dc6c4..cd577ba8e 100644 --- a/crates/update/src/stack_dialogs.rs +++ b/crates/update/src/stack_dialogs.rs @@ -3,7 +3,7 @@ //! host's `AppInfo` and the words from [`UpdateWords`]. use std::hash::{Hash as _, Hasher as _}; -use std::sync::OnceLock; +use std::sync::{Arc, OnceLock}; use craft_theme::variant::Tone; use craft_ui::buttons::Link; @@ -380,6 +380,8 @@ pub struct UpdateCheckDialog { chosen: Option, open: bool, icon: IconCell, + /// The words the app passed; the scope's [`UpdateWords`] when none. + words: Option>, } impl UpdateCheckDialog { @@ -397,9 +399,17 @@ impl UpdateCheckDialog { chosen: None, open: true, icon: IconCell::new(), + words: None, } } + /// Shows these words instead of the scope's [`UpdateWords`] (an app passes its translated words). + #[must_use] + pub fn words(mut self, words: UpdateWords) -> Self { + self.words = Some(Arc::new(words)); + self + } + /// Sets whether the install can update itself, for an app that knows better than /// [`self_update::is_self_updating`] for the host's app (the dialog asks that when this isn't /// called). Without it Download replaces Update and Restart. @@ -466,7 +476,7 @@ impl UpdateCheckDialog { /// Shows one pass. The choices are the footer buttons' meanings, in the order of the dialog's `picked`. fn present(&mut self, ui: &mut Ui) -> (DialogOutput, Vec) { let env = Env::of(ui); - let words = env.words::(); + let words = self.words.clone().unwrap_or_else(|| env.words::()); let ok = env.words::().ok.clone(); let subject = Subject::of(&env); let self_updating = *self.self_updating.get_or_insert_with(|| subject.app.is_some_and(self_update::is_self_updating));