From bd0a21c2de008d945a38eecf26aefaa1ea3520bd Mon Sep 17 00:00:00 2001 From: mtlcl410 <2368091+mtlcl410@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:00:42 +0800 Subject: [PATCH] M3: full screen fills the screen or keeps the page display, and Esc closes the find bar before leaving (#576, #4273, #5302) (#5325) Full screen can fill the screen edge to edge, fixing the fake full screen in #379, or keep the normal page display, via a preference. The forms bar is hidden in full screen. Up-arrow and wheel no longer jump back a page, and Esc closes one thing at a time (the find bar before leaving full screen). Bundles #576, #4273 and #5302. --- crates/ui-egui/src/app.rs | 1 + crates/ui-egui/src/app/control.rs | 14 ++ crates/ui-egui/src/app/keys.rs | 14 +- crates/ui-egui/src/app/prefs.rs | 19 +- crates/ui-egui/src/app/window.rs | 1 + crates/ui-egui/src/canvas.rs | 45 +++-- crates/ui-egui/src/canvas/bars.rs | 7 +- crates/ui-egui/src/canvas/navigation.rs | 41 +++- crates/ui-egui/src/canvas/presenter.rs | 4 +- crates/ui-egui/src/canvas/tests.rs | 100 +++++++++- crates/ui-egui/src/canvas/zoom.rs | 104 ++++++++-- crates/ui-egui/src/dialogs/preferences.rs | 4 + crates/ui-egui/src/lib.rs | 3 + crates/ui-egui/tests/it/view.rs | 222 ++++++++++++++++++++++ parity/acrobat-features.toml | 6 +- 15 files changed, 529 insertions(+), 56 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 6e4a52ccea..3e75cbb5a6 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -110,6 +110,7 @@ impl PdfCraftApp { scroll_speed: scroll_speed::ScrollSpeed::default(), invert_middle_drag: false, animation_effects: motion::AnimationEffects::default(), + full_screen_escape_exits: true, motion: motion::Motion::default(), language: i18n::AUTO.to_string(), ui_scale: None, diff --git a/crates/ui-egui/src/app/control.rs b/crates/ui-egui/src/app/control.rs index a545b4165a..9c416a5c9d 100644 --- a/crates/ui-egui/src/app/control.rs +++ b/crates/ui-egui/src/app/control.rs @@ -191,6 +191,20 @@ impl PdfCraftApp { }; self.set_active_page_gaps(show); } + ("full-screen-escape", _) => { + self.full_screen_escape_exits = match value { + "on" => true, + "off" => false, + _ => return Err("full-screen-escape must be on or off".into()), + }; + } + ("full-screen-fill", _) => { + self.view_defaults.full_screen_fill = match value { + "on" => true, + "off" => false, + _ => return Err("full-screen-fill must be on or off".into()), + }; + } ("default-page-gaps", _) => { self.view_defaults.show_page_gaps = match value { "on" => true, diff --git a/crates/ui-egui/src/app/keys.rs b/crates/ui-egui/src/app/keys.rs index 7471c2f69f..d854709512 100644 --- a/crates/ui-egui/src/app/keys.rs +++ b/crates/ui-egui/src/app/keys.rs @@ -46,8 +46,18 @@ impl PdfCraftApp { if chords { self.registry_shortcuts(ctx); } - // (Esc closes a Combine file shown large first.) - if self.full_screen && self.combine_tab.preview.is_none() && self.page_keys.pressed(ctx, Key::Escape) { + // Esc closes one thing at a time: a Combine file shown large, an open menu, or the camera, + // a selection or the find bar on the page go first, and full screen stays (#5302). With + // the Esc leaves full screen preference off, only ⌘L / Ctrl+L leaves it. + let page_takes_escape = + egui::Popup::is_any_open(ctx) || self.active.and_then(|i| self.views.get(i)).is_some_and(|v| v.escape_closes_something()); + if self.full_screen + && self.full_screen_escape_exits + && self.combine_tab.preview.is_none() + && !page_takes_escape + // Taken: the Esc that leaves full screen closes nothing on the page as well. + && self.page_keys.take(ctx, Key::Escape) + { self.set_full_screen(ctx, false); } if let Some(i) = self.active { diff --git a/crates/ui-egui/src/app/prefs.rs b/crates/ui-egui/src/app/prefs.rs index 9546857d41..618c3e0178 100644 --- a/crates/ui-egui/src/app/prefs.rs +++ b/crates/ui-egui/src/app/prefs.rs @@ -173,6 +173,8 @@ impl PdfCraftApp { v["default_page_gaps"] = serde_json::Value::Bool(self.view_defaults.show_page_gaps); v["recent_limit"] = serde_json::json!(self.recent_limit); v["fill_text_color"] = serde_json::json!(self.fill_text_color); + v["full_screen_fill"] = serde_json::Value::Bool(self.view_defaults.full_screen_fill); + v["full_screen_escape_exits"] = serde_json::Value::Bool(self.full_screen_escape_exits); v["redact_prefs"] = self.redact_defaults.to_json(); v["pinned_tools"] = serde_json::json!(self.pinned_tools); // Set outside json! above, which is at serde_json's macro recursion limit. @@ -308,6 +310,19 @@ impl PdfCraftApp { } } + /// The page gaps and full screen's switches: fill the screen, and whether Esc leaves it. + fn restore_page_display_prefs(&mut self, v: &serde_json::Value) { + if let Some(show) = v["default_page_gaps"].as_bool() { + self.view_defaults.show_page_gaps = show; + } + if let Some(fill) = v["full_screen_fill"].as_bool() { + self.view_defaults.full_screen_fill = fill; + } + if let Some(exits) = v["full_screen_escape_exits"].as_bool() { + self.full_screen_escape_exits = exits; + } + } + /// The Print dialog's papers, each printer's setup and the choices it keeps (#2001). fn restore_print_prefs(&mut self, v: &serde_json::Value) { // The Print dialog's own paper sizes; settings are untrusted, so each custom paper is @@ -384,9 +399,7 @@ impl PdfCraftApp { /// Switches for reopening, window chrome and file watching. fn restore_behavior_prefs(&mut self, v: &serde_json::Value) { - if let Some(show) = v["default_page_gaps"].as_bool() { - self.view_defaults.show_page_gaps = show; - } + self.restore_page_display_prefs(v); if let Ok(units) = serde_json::from_value::(v["units"].clone()) { self.units = units; } diff --git a/crates/ui-egui/src/app/window.rs b/crates/ui-egui/src/app/window.rs index e7035b5000..cc3d83e8bc 100644 --- a/crates/ui-egui/src/app/window.rs +++ b/crates/ui-egui/src/app/window.rs @@ -44,6 +44,7 @@ impl PdfCraftApp { self.full_screen = on; for view in &mut self.views { if on { + view.full_screen_fill = self.view_defaults.full_screen_fill; view.enter_presentation(); } else { view.leave_presentation(); diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 5ef59e76aa..686f7b6798 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -344,12 +344,23 @@ pub struct ViewDefaults { /// Highlight existing fields: a preference in Acrobat, so it carries over to the next /// document and the next session. On for new settings; a stored choice wins. pub highlight_fields: bool, + /// Full screen fills the screen with one page (or spread) at a time, edge to edge; off, it + /// keeps the page display it is entered from (continuous scrolling, say: #4273). + pub full_screen_fill: bool, } impl Default for ViewDefaults { fn default() -> Self { // Single page, scrolling continuously at fit width: the earlier "continuous" default. - Self { layout: PageLayout::Single, continuous: true, show_page_gaps: true, fit: Fit::Width, zoom: 1.0, highlight_fields: true } + Self { + layout: PageLayout::Single, + continuous: true, + show_page_gaps: true, + fit: Fit::Width, + zoom: 1.0, + highlight_fields: true, + full_screen_fill: true, + } } } @@ -553,6 +564,10 @@ pub struct DocView { /// Full screen (Acrobat's Full Screen Mode): the display saved on entering it, while the view /// shows one page or spread at a time, fitted to the screen. `None` outside full screen. presentation: Option, + /// Full screen fills the screen with one page (or spread) at a time, edge to edge (the + /// default); off, it keeps the page display it was entered from. Set from the app's + /// preference before full screen is entered. + pub full_screen_fill: bool, /// Full screen's transitions, display times and pointer (see [`presenter`]). pub(crate) presenter: presenter::Presenter, pages: HashMap, @@ -1078,6 +1093,7 @@ impl DocView { compare_marks: Vec::new(), interface: Default::default(), presentation: None, + full_screen_fill: defaults.full_screen_fill, presenter: Default::default(), pages: HashMap::new(), errors: HashMap::new(), @@ -1272,6 +1288,7 @@ impl DocView { fresh.interface = self.interface; // Still presenting, with the display to go back to on leaving. fresh.presentation = self.presentation.take(); + fresh.full_screen_fill = self.full_screen_fill; // A new document: none of the old one's transition, page or timer carries over. fresh.presenter = Default::default(); fresh.back = std::mem::take(&mut self.back); @@ -1314,6 +1331,7 @@ impl DocView { v.highlight_fields = self.highlight_fields; v.notice_dismissed = self.notice_dismissed; v.scripts_off_noted = self.scripts_off_noted; + v.full_screen_fill = self.full_screen_fill; v.goto = Some((self.current, 0.0)); v } @@ -1578,8 +1596,9 @@ fn paint_page_surface(ui: &mut egui::Ui, view: &mut DocView, frame: &mut PageFra let visible = frame.visible; let info = frame.env.info; let painter = ui.painter(); - // Shadows would darken the preceding page when pages touch. - if view.show_page_gaps && frame.env.show_page_edge_shadows { + // Shadows would darken the preceding page when pages touch; full screen filling the screen + // shows the page alone on black (#576). + if view.show_page_gaps && frame.env.show_page_edge_shadows && !view.fills_screen() { painter.add(egui::epaint::Shadow { offset: [0, 3], blur: 14, spread: 0, color: t.page_shadow }.as_shape(r, CornerRadius::ZERO)); } painter.rect_filled(r, CornerRadius::ZERO, paper); @@ -2295,7 +2314,7 @@ fn anchor_zoom_change(view: &mut DocView, avail: Vec2, old_zoom: f32) { } else if let Some((page, fy, rel_y)) = anchor { view.zoom_anchor = Some((page, 0.5, fy, vec2(avail_width / 2.0, rel_y))); } else { - view.zoom_anchor = Some((view.current, 0.5, 0.0, vec2(avail_width / 2.0, MARGIN))); + view.zoom_anchor = Some((view.current, 0.5, 0.0, vec2(avail_width / 2.0, view.margin()))); } } } @@ -2775,11 +2794,12 @@ fn page_scroll_area(ui: &egui::Ui, view: &mut DocView, geometry: &ScrollGeometry // The page counts with its side gutters, which keep its edge clear of the floating // quick-action bar as the layout does. let (x, w) = (view.last_scroll.x, avail.width()); - let (left, right) = (r.left() - SIDE, r.right() + SIDE); + let gutter = view.side(); + let (left, right) = (r.left() - gutter, r.right() + gutter); // Turned by → / ← at an edge (`goto_side`): a page or spread wider than the window starts at // the edge the reader comes from. let row = shown_row(view, rects).iter().filter_map(|&i| rects.get(i)).copied().reduce(Rect::union).unwrap_or(r); - let (row_left, row_right) = (row.left() - SIDE, row.right() + SIDE); + let (row_left, row_right) = (row.left() - gutter, row.right() + gutter); let target = match side { Some(from_right) if row_right - row_left > w => { if from_right { @@ -3192,16 +3212,17 @@ fn refine_goto_point(mut scroll: egui::ScrollArea, view: &mut DocView, geometry: /// Where the `shown` pages sit in the scroll content, as how far the content starts into the /// layout and how tall it is. Scrolling continuously every page scrolls; otherwise only the -/// current row does, the content being its bounding box plus margins. Pages that fit a view +/// current row does, the content being its bounding box plus `margin` (none while full screen +/// fills the screen). Pages that fit a view /// `view_height` tall sit in its middle, the spare height shared above and below (#5708): the /// content fills the view, so there is nothing to scroll, and starts on a whole physical pixel /// as the layout's pages do, or their edges would blur and the seams between them open. -fn vertical_placement(continuous: bool, rects: &[Rect], shown: &[usize], view_height: f32, pixels_per_point: f32) -> (f32, f32) { +fn vertical_placement(continuous: bool, rects: &[Rect], shown: &[usize], view_height: f32, margin: f32, pixels_per_point: f32) -> (f32, f32) { let Some(r) = shown.iter().filter_map(|&i| rects.get(i)).copied().reduce(Rect::union) else { return (0.0, 0.0) }; if fits_height(r, view_height, pixels_per_point) { return (((r.center().y - view_height / 2.0) * pixels_per_point).round() / pixels_per_point, view_height); } - if continuous { (0.0, r.bottom() + MARGIN) } else { (r.top() - MARGIN, r.height() + 2.0 * MARGIN) } + if continuous { (0.0, r.bottom() + margin) } else { (r.top() - margin, r.height() + 2.0 * margin) } } /// Whether the pages in `r` show whole in a view `view_height` tall, without their margins. @@ -3345,7 +3366,8 @@ pub fn document_area(app: &mut PdfCraftApp, index: usize, ui: &mut egui::Ui) { // row, the jump to the new page scrolled both out of view, a blank frame on every turn forward. let row = shown_row(view, &rects); let visible_pages: Vec = if view.continuous { (0..rects.len()).collect() } else { row.clone() }; - let (y_shift, content_h) = vertical_placement(view.continuous, &rects, &visible_pages, avail.height(), ui.ctx().pixels_per_point()); + let (y_shift, content_h) = + vertical_placement(view.continuous, &rects, &visible_pages, avail.height(), view.margin(), ui.ctx().pixels_per_point()); let mut scroll = page_scroll_area( ui, @@ -3520,7 +3542,8 @@ pub fn document_area(app: &mut PdfCraftApp, index: usize, ui: &mut egui::Ui) { // below the window's top). Within a point, as for wheel paging, so layout rounding // can't hide an edge. let max_y = (out.content_size.y - out.inner_rect.height()).max(0.0); - (page, out.state.clamped_offset().y <= MARGIN - view.page_gap() + 1.0, out.state.clamped_offset().y >= max_y - 1.0) + // Going to a page clamps at 0, which is where a page sits with no margin (full screen). + (page, out.state.clamped_offset().y <= (view.margin() - view.page_gap()).max(0.0) + 1.0, out.state.clamped_offset().y >= max_y - 1.0) }); // Within a point, as above: at an edge of the scrolled content, or of the current page or // spread shown whole that way (in continuous view the content is as wide as the widest page, diff --git a/crates/ui-egui/src/canvas/bars.rs b/crates/ui-egui/src/canvas/bars.rs index 85807e28fe..17ca392463 100644 --- a/crates/ui-egui/src/canvas/bars.rs +++ b/crates/ui-egui/src/canvas/bars.rs @@ -63,7 +63,7 @@ pub(super) enum Notice { /// The notice bar above the pages: a file changed on disk first, then what a historical /// snapshot is, then pages cut at the renderer's limits, then the offer to lock a signature just /// placed, then the signature status bar, a form's scripts having been turned off, security, -/// forms and warnings. +/// forms and warnings. None in full screen. #[allow(clippy::too_many_arguments)] pub(super) fn notices( view: &mut DocView, @@ -75,6 +75,11 @@ pub(super) fn notices( ui: &mut egui::Ui, t: &Tokens, ) -> Option { + // Full screen shows the page and nothing else (#1459), so the notice bar above the pages waits + // until it is left; filling the screen, a bar would push the page past its bottom (#576). + if view.presentation.is_some() { + return None; + } let info = &doc.info; let xfa = doc.xfa.as_ref(); // The file changed on disk while this document has unsaved changes (#431): ask before diff --git a/crates/ui-egui/src/canvas/navigation.rs b/crates/ui-egui/src/canvas/navigation.rs index 1dfadf0963..de72da2564 100644 --- a/crates/ui-egui/src/canvas/navigation.rs +++ b/crates/ui-egui/src/canvas/navigation.rs @@ -207,6 +207,21 @@ impl DocView { } } + /// Whether Esc has something on the page to close: the camera, a form field being filled (its + /// editor closes it), a selection or the find bar ([`shortcuts`] closes the others in that + /// order). Esc closes one thing at a time, so full screen leaves only on an Esc that finds none + /// of them (#5302): from a field, "Esc (press twice)" leaves (*Adobe Acrobat Help*, 2019, + /// p. 248). A search shown in the Search panel isn't on the page: full screen hides the panel, + /// and keeps its search. + pub fn escape_closes_something(&self) -> bool { + self.camera.is_some() + || self.camera_done.is_some() + || self.forms.focus.is_some() + || self.selection.is_some() + || self.all_text + || self.find.as_ref().is_some_and(|f| !f.in_panel) + } + /// Next page (`true`) or previous page. In two-page view this moves a whole spread: the other /// page of the spread is already on screen, so stepping to it wouldn't move the view (#70). pub fn step_page(&mut self, forward: bool) { @@ -383,6 +398,23 @@ fn zoom_shortcuts(view: &mut DocView, pressed: &impl Fn(egui::KeyboardShortcut) } } +/// Esc on the page closes one thing: the camera, then a form field being filled, then a +/// selection, then the find bar ([`DocView::escape_closes_something`] says whether there is one). +fn escape_closes_one(view: &mut DocView) { + if view.camera.is_some() || view.camera_done.is_some() { + view.pending_action = Some(ViewAction::CancelCamera); + } else if view.forms.focus.is_some() { + // A form field being filled takes this Esc: its editor closes it, and nothing else on + // the page closes with it (a selection stays for the next Esc). + } else if view.selection.is_some() || view.all_text { + view.selection = None; + view.all_text = false; + } else if view.presentation.is_none() || view.find.as_ref().is_some_and(|f| !f.in_panel) { + // Full screen hides the Search panel: its search stays for when the panel is back. + view.find = None; + } +} + /// The view's keys: its chords, then its plain keys. `chords`: no menu of the menu bar has the /// keyboard and nothing covers the pages, so chords may run (they wait for a menu, as the /// registered commands' do). An open form field keeps the paging and scrolling keys for itself. @@ -462,14 +494,7 @@ fn view_keys( // An open menu takes Escape first and closes; the selection stays for the next one (#3535). // So does an open field, whose list closes. if key(Key::Escape) && !egui::Popup::is_any_open(ctx) && !field_open { - if view.camera.is_some() || view.camera_done.is_some() { - view.pending_action = Some(ViewAction::CancelCamera); - } else if view.selection.is_some() || view.all_text { - view.selection = None; - view.all_text = false; - } else { - view.find = None; - } + escape_closes_one(view); } // The open field's keys leave the page under it where it is. if field_open { diff --git a/crates/ui-egui/src/canvas/presenter.rs b/crates/ui-egui/src/canvas/presenter.rs index d6c8461bfa..d91da789e0 100644 --- a/crates/ui-egui/src/canvas/presenter.rs +++ b/crates/ui-egui/src/canvas/presenter.rs @@ -127,7 +127,9 @@ pub(super) fn frame( let arriving = view.presenter.turn.as_ref().map(|t| t.to_page); if showing != Some(page) && arriving != Some(page) { // A new page: play its transition from the page before, when there is one to play. - let plays = animates && view.layout == PageLayout::Single && view.rotation == 0; + // Not while scrolling: full screen that keeps a continuous display (Fill screen off, + // #4273) moves between pages by scrolling, with no page to turn from. + let plays = animates && view.layout == PageLayout::Single && !view.continuous && view.rotation == 0; let turn = showing.or(arriving).filter(|_| plays).and_then(|from_page| { let (effect, seconds) = entry(info, page).and_then(effect_of)?; let from = view.pages.get(&from_page)?.tex.clone(); diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index ce99e2764e..c6924c30e5 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -2557,22 +2557,41 @@ fn full_screen_two_page_view_fits_the_spread_it_shows() { assert!(small > windowed * 1.9, "the small spread fills the screen: {small} vs {windowed}"); v.current = 3; v.fit_zoom(&info); - assert!((v.zoom - windowed).abs() < 1e-4, "the large spread fits as before"); + // The large spread fits the screen edge to edge, without the window's margins (#576). + let edge_to_edge = (v.viewport_w - v.page_gap()) / (2.0 * 600.0 * PT); + assert!((v.zoom - edge_to_edge).abs() < 1e-4 && v.zoom > windowed, "the large spread fills the screen: {} vs {edge_to_edge}", v.zoom); v.current = 1; v.fit_zoom(&info); assert_eq!(v.zoom, small, "page 2 is in the first spread"); - // With a cover page: [0] alone, then [1, 2] (the large page decides), then [3]. + // With a cover page: [0] alone, then [1, 2], then [3]. v.cover = true; v.current = 0; v.fit_zoom(&info); assert_eq!(v.zoom, small, "the cover page alone"); + // The mixed spread [1, 2] fits its two pages' own widths side by side, 300 + 600 points, + // and not twice the wider one: here the height decides. v.current = 1; v.fit_zoom(&info); - assert!((v.zoom - windowed).abs() < 1e-4, "page 2 shares a spread with the large page 3"); + let mixed_fit = ((v.viewport_w - v.page_gap()) / (900.0 * PT)).min(v.viewport_h / (800.0 * PT)); + assert!((v.zoom - mixed_fit).abs() < 1e-4 && v.zoom > edge_to_edge, "page 2 shares a spread with the large page 3: {} vs {mixed_fit}", v.zoom); + // And the content is as wide as that spread, so the spread is centred on the screen: room for + // twice the larger page would centre it past the screen's right edge. + let content_w = v.content_width(&info, v.viewport_w); + let rects = v.layout(&info, content_w, 1.0); + let (left, right) = (rects[1].min.x, rects[2].max.x); + assert!(content_w <= v.viewport_w + 0.5, "the spread needs no scrolling: {content_w}"); + assert!(left >= -0.5 && right <= v.viewport_w + 0.5, "the spread is on the screen: {left}..{right}"); + assert!((left - (v.viewport_w - right)).abs() < 1.0, "and centred: {left}..{right}"); + // The cover alone keeps its spread's blank slot, and is on the screen too. + v.current = 0; + v.fit_zoom(&info); + let content_w = v.content_width(&info, v.viewport_w); + let cover = v.layout(&info, content_w, 1.0)[0]; + assert!(cover.min.x >= v.viewport_w / 2.0 && cover.max.x <= v.viewport_w + 0.5, "the cover sits on the right: {cover:?}"); // Scrolling while in full screen fits the document, as scrolling does in the window. (v.continuous, v.current) = (true, 0); v.fit_zoom(&info); - assert!((v.zoom - windowed).abs() < 1e-4, "continuous full screen keeps one zoom"); + assert!((v.zoom - edge_to_edge).abs() < 1e-4, "continuous full screen keeps one zoom"); v.continuous = false; // The cover page is a spread of its own even when the next page is larger. let mixed = DocInfo { pages: vec![page(300.0, 400.0), page(600.0, 800.0), page(600.0, 800.0)], ..Default::default() }; @@ -2585,6 +2604,17 @@ fn full_screen_two_page_view_fits_the_spread_it_shows() { (v.layout, v.continuous) = (PageLayout::TwoUp, false); v.fit_zoom(&info); assert!((v.zoom - windowed).abs() < 1e-4, "in the window, one zoom for the document"); + // With Fill off, full screen keeps the window's display (#4273): two-page view keeps one zoom + // for the document, and its width, as the spreads turn. + let content_w = v.content_width(&info, v.viewport_w); + v.full_screen_fill = false; + v.enter_presentation(); + for current in [0, 1, 3] { + v.current = current; + v.fit_zoom(&info); + assert!((v.zoom - windowed).abs() < 1e-4, "fill off, page {current}: the window's zoom, {} vs {windowed}", v.zoom); + assert_eq!(v.content_width(&info, v.viewport_w), content_w, "fill off, page {current}: the window's width"); + } } #[test] @@ -2853,6 +2883,45 @@ fn a_moved_picture_is_drawn_from_the_fresh_raster_while_a_tile_is_still_stale() h.state_mut().views[0].tiles.clear(); } +/// Review on #5325: one Esc closes one thing. With a form field being filled (a check box that +/// has the focus) and text selected, the page leaves the selection for the next Esc: the field's +/// editor takes this one. +#[test] +fn esc_with_a_field_being_filled_leaves_the_selection() { + let mut v = view(3, PageLayout::Single, true); + v.all_text = true; + v.forms.focus = Some(crate::forms_ui::Focus { + name: "agree".into(), + obj: None, + widget: 0, + text: String::new(), + picked: Vec::new(), + request_focus: false, + select_all: false, + press: None, + calendar: None, + calendar_rect: None, + calendar_text: None, + list: Default::default(), + had_focus: true, + }); + let ctx = egui::Context::default(); + ctx.input_mut(|i| { + i.events.push(egui::Event::Key { + key: egui::Key::Escape, + physical_key: None, + pressed: true, + repeat: false, + modifiers: egui::Modifiers::NONE, + }); + }); + shortcuts(&mut v, &ctx, Default::default(), true, Default::default()); + assert!(v.all_text, "the selection stays while the field takes Esc"); + v.forms.focus = None; + shortcuts(&mut v, &ctx, Default::default(), true, Default::default()); + assert!(!v.all_text, "with no field being filled, Esc clears the selection"); +} + /// Review on #4378: `FitWindow` measures the spread the view shows, its pages side by side /// and as tall as the taller one, with one page in a spread that has only one. #[test] @@ -3187,6 +3256,25 @@ fn a_transition_of_zero_or_negative_length_cuts() { } } +/// Full screen that keeps a continuous display (Fill screen off, #4273) scrolls from page to page: +/// a page's transition doesn't play over the scrolling pages. +#[test] +fn full_screen_that_keeps_scrolling_plays_no_transition() { + use pdfcraft_render::TransitionStyle; + let ctx = egui::Context::default(); + let page = pdfcraft_render::PageInfo { width: 300.0, height: 400.0, label: String::new(), crop: [0.0, 0.0, 300.0, 400.0], rotation: 0 }; + let info = DocInfo { pages: vec![page; 3], transitions: vec![trans(1, Some(TransitionStyle::Wipe), 1.0, None)], ..Default::default() }; + let mut v = DocView::new(DocId(1), &info, ViewDefaults { layout: PageLayout::Single, continuous: true, ..Default::default() }); + v.full_screen_fill = false; + v.enter_presentation(); + assert!(v.continuous(), "Fill screen off keeps continuous scrolling"); + give_raster(&ctx, &mut v, 0); + presenter_frame(&ctx, &mut v, &info, 0.0); + turn_to(&ctx, &mut v, 1); + presenter_frame(&ctx, &mut v, &info, 0.1); + assert!(!v.presenting_a_transition(), "no Wipe over a scrolling display"); +} + /// A style the spec doesn't name is read as its default R, Replace (ISO 32000-2 Table 164: "The /// new page simply replaces the old one with no special transition effect"): the page changes at /// once, and its display time still counts. @@ -3339,10 +3427,10 @@ fn only_pixel_snapping_passes_for_fitting_the_view() { let page = |height: f32| [Rect::from_min_size(pos2(0.0, MARGIN), vec2(300.0, height))]; for ppp in [1.0, 2.0] { let slack = 0.5 / ppp; - let (_, content) = vertical_placement(false, &page(600.0 + slack), &[0], 600.0, ppp); + let (_, content) = vertical_placement(false, &page(600.0 + slack), &[0], 600.0, MARGIN, ppp); assert_eq!(content, 600.0, "at {ppp}x, snapping's half pixel still fits"); for over in [slack + 0.1, 1.0] { - let (shift, content) = vertical_placement(false, &page(600.0 + over), &[0], 600.0, ppp); + let (shift, content) = vertical_placement(false, &page(600.0 + over), &[0], 600.0, MARGIN, ppp); assert_eq!((shift, content), (0.0, 600.0 + over + 2.0 * MARGIN), "at {ppp}x, {over} pt too tall scrolls"); } } diff --git a/crates/ui-egui/src/canvas/zoom.rs b/crates/ui-egui/src/canvas/zoom.rs index e9e2eae82b..2faf836193 100644 --- a/crates/ui-egui/src/canvas/zoom.rs +++ b/crates/ui-egui/src/canvas/zoom.rs @@ -32,15 +32,23 @@ impl DocView { } self.presentation = Some(SavedDisplay { layout: self.layout, continuous: self.continuous, cover: self.cover, fit: self.fit, zoom: self.zoom }); - self.continuous = false; - self.fit = Fit::Page; self.selection = None; self.presenter = Default::default(); - self.goto = Some((self.current, 0.0)); + // Off, the Fill screen preference keeps the display full screen was entered from (#4273), + // and the reading position in it. + if self.full_screen_fill { + self.continuous = false; + self.fit = Fit::Page; + self.goto = Some((self.current, 0.0)); + } else { + self.goto = Some(self.reading_position()); + } } /// Leave full screen: the display from before it comes back, at the page reached meanwhile. + /// From a display full screen kept, at the reading position. pub fn leave_presentation(&mut self) { + let goto = if self.fills_screen() { (self.current, 0.0) } else { self.reading_position() }; let Some(saved) = self.presentation.take() else { return }; self.presenter = Default::default(); self.layout = saved.layout; @@ -48,7 +56,17 @@ impl DocView { self.cover = saved.cover; self.fit = saved.fit; self.zoom = saved.zoom; - self.goto = Some((self.current, 0.0)); + self.goto = Some(goto); + } + + /// Where the reader is, as of the last frame: the page at the top of the document area and + /// the fraction of it scrolled past, or the top of the current page when no page is there. + fn reading_position(&self) -> (usize, f32) { + let top = self.viewport_screen.top(); + self.screen_xforms + .iter() + .find(|(_, xf)| xf.rect.top() <= top && top < xf.rect.bottom() && xf.rect.height() > 0.0) + .map_or((self.current, 0.0), |(p, xf)| (*p, ((top - xf.rect.top()) / xf.rect.height()).clamp(0.0, 1.0))) } /// The display shown outside full screen: the one presenting replaced, or the current one. @@ -72,6 +90,22 @@ impl DocView { self.presentation.is_some() } + /// Whether full screen fills the screen with one page (or spread) at a time: then the page + /// takes the whole screen, with no margin around it (#576). + pub fn fills_screen(&self) -> bool { + self.presentation.is_some() && self.full_screen_fill + } + + /// The space above the first page and below the last: none while full screen fills the screen. + pub(super) fn margin(&self) -> f32 { + if self.fills_screen() { 0.0 } else { MARGIN } + } + + /// The least space beside the pages: none while full screen fills the screen. + pub(super) fn side(&self) -> f32 { + if self.fills_screen() { 0.0 } else { SIDE } + } + /// Whether full screen is playing a page transition (or holding the page before it until the /// next one has rendered). pub fn presenting_a_transition(&self) -> bool { @@ -297,37 +331,52 @@ impl DocView { if self.cover { c.saturating_sub((c + 1) % 2) } else { c - c % 2 } } + /// The display sizes of the spread full screen shows in two-page view (one spread at a time): + /// its two pages, or one alone. `None` in every other display, full screen that keeps the + /// window's display (Fill off, #4273) included: that fits the document as the window does. + fn full_screen_spread(&self, info: &DocInfo) -> Option> { + if !self.fills_screen() || self.layout != PageLayout::TwoUp || self.continuous { + return None; + } + let first = self.spread_first(self.current); + let last = if self.cover && first == 0 { 0 } else { first.saturating_add(1) }; + Some(info.pages.iter().skip(first).take(last - first + 1).map(|p| self.display_size(p)).collect()) + } + pub(super) fn fit_zoom(&mut self, info: &DocInfo) { let largest = |side: fn((f32, f32)) -> f32| info.pages.iter().map(|p| side(self.display_size(p))).fold(1.0, f32::max); let max_w = largest(|s| s.0); - // A single page shown on its own fits that page, and full screen in two-page view fits - // the spread it shows (review on #2070). Every other display (scrolling, or two-page - // view in the window) fits its largest page, so the zoom holds still while pages of - // other sizes scroll or page past. + // A single page shown on its own fits that page, and full screen filling the screen in + // two-page view fits the spread it shows (review on #2070). Every other display + // (scrolling, or two-page view in the window or in a full screen that keeps the window's + // display) fits its largest page, so the zoom holds still while pages of other sizes + // scroll or page past. A spread of two pages fits their own widths side by + // side; a page alone in a spread keeps a spread's room (a cover keeps its blank slot). + let mut spread_w = None; let (w, h) = if self.layout == PageLayout::Single && !self.continuous { info.pages.get(self.current).map_or_else(|| (max_w, largest(|s| s.1)), |p| self.display_size(p)) - } else if self.presentation.is_some() && self.layout == PageLayout::TwoUp && !self.continuous { - let first = self.spread_first(self.current); - let last = if self.cover && first == 0 { 0 } else { first.saturating_add(1) }; - let spread: Vec<(f32, f32)> = info.pages.iter().skip(first).take(last - first + 1).map(|p| self.display_size(p)).collect(); + } else if let Some(spread) = self.full_screen_spread(info) { if spread.is_empty() { (max_w, largest(|s| s.1)) } else { + if let [a, b] = spread.as_slice() { + spread_w = Some((a.0 + b.0).max(1.0)); + } (spread.iter().map(|s| s.0).fold(1.0, f32::max), spread.iter().map(|s| s.1).fold(1.0, f32::max)) } } else { (max_w, largest(|s| s.1)) }; - let avail_w = (self.viewport_w - 2.0 * SIDE).max(100.0); + let avail_w = (self.viewport_w - 2.0 * self.side()).max(100.0); let per_row = if self.layout == PageLayout::TwoUp { 2.0 } else { 1.0 }; + let zw = (avail_w - self.page_gap() * (per_row - 1.0)) / (spread_w.unwrap_or(w * per_row) * PT); match self.fit { - Fit::Width => self.zoom = (avail_w - self.page_gap() * (per_row - 1.0)) / (w * PT * per_row), + Fit::Width => self.zoom = zw, Fit::Page => { - let zw = (avail_w - self.page_gap() * (per_row - 1.0)) / (w * PT * per_row); - let zh = (self.viewport_h - 2.0 * MARGIN) / (h * PT); + let zh = (self.viewport_h - 2.0 * self.margin()) / (h * PT); self.zoom = zw.min(zh); } - Fit::Height => self.zoom = (self.viewport_h - 2.0 * MARGIN) / (h * PT), + Fit::Height => self.zoom = (self.viewport_h - 2.0 * self.margin()) / (h * PT), Fit::None => {} } self.zoom = self.zoom.clamp(0.08, 64.0); @@ -336,11 +385,23 @@ impl DocView { /// Width of the scroll content. Single-page view sizes it to the page it shows, so a /// wider page elsewhere in the document can't push the shown one off-centre. pub(super) fn content_width(&self, info: &DocInfo, avail_w: f32) -> f32 { + // Full screen in two-page view is as wide as the spread it shows, as `fit_zoom` sized it: + // two pages side by side, or a page alone with the room of a spread (a cover keeps its + // blank slot). Room for twice the document's widest page would centre a narrower spread + // past the screen's edge. + if let Some(spread) = self.full_screen_spread(info).filter(|s| !s.is_empty()) { + let s = self.zoom * PT; + let w = match spread.as_slice() { + [a, b] => (a.0 + b.0) * s, + _ => spread.iter().map(|p| p.0).fold(0.0, f32::max) * s * 2.0, + }; + return (w + self.page_gap() + 2.0 * self.side()).max(avail_w); + } let single = (self.layout == PageLayout::Single && !self.continuous).then(|| self.current.min(info.pages.len().saturating_sub(1))); let shown = info.pages.iter().enumerate().filter(|&(i, _)| single.is_none_or(|c| c == i)); let max_w = shown.map(|(_, p)| self.display_size(p).0).fold(0.0, f32::max); let per_row = if self.layout == PageLayout::TwoUp { 2.0 } else { 1.0 }; - (max_w * self.zoom * PT * per_row + 2.0 * SIDE).max(avail_w) + (max_w * self.zoom * PT * per_row + 2.0 * self.side()).max(avail_w) } /// Page rects in content coordinates (origin at the scroll content's top-left). @@ -358,12 +419,13 @@ impl DocView { } }; let mut rects = Vec::with_capacity(info.pages.len()); - let mut y = MARGIN; + let mut y = self.margin(); + let side = self.side(); match self.layout { PageLayout::Single => { for p in &info.pages { let size = page_size(p); - rects.push(Rect::from_min_size(pos2(((content_w - size.x) / 2.0).max(SIDE), y), size)); + rects.push(Rect::from_min_size(pos2(((content_w - size.x) / 2.0).max(side), y), size)); y += size.y + gap; } } @@ -378,7 +440,7 @@ impl DocView { let sizes: Vec = pair.iter().map(page_size).collect(); let row_w: f32 = sizes.iter().map(|v| v.x).sum::() + gap * (sizes.len() as f32 - 1.0); let row_h = sizes.iter().map(|v| v.y).fold(0.0, f32::max); - let mut x = if self.cover && ri == 0 { (content_w / 2.0 + gap / 2.0).max(SIDE) } else { ((content_w - row_w) / 2.0).max(SIDE) }; + let mut x = if self.cover && ri == 0 { (content_w / 2.0 + gap / 2.0).max(side) } else { ((content_w - row_w) / 2.0).max(side) }; for size in sizes { rects.push(Rect::from_min_size(pos2(x, y + (row_h - size.y) / 2.0), size)); x += size.x + gap; diff --git a/crates/ui-egui/src/dialogs/preferences.rs b/crates/ui-egui/src/dialogs/preferences.rs index 02384f6b58..9dd27ef7bf 100644 --- a/crates/ui-egui/src/dialogs/preferences.rs +++ b/crates/ui-egui/src/dialogs/preferences.rs @@ -786,6 +786,10 @@ fn card_documents_and_view(ui: &mut egui::Ui, app: &mut PdfCraftApp, t: &Tokens, app.view_defaults.show_page_gaps = show_page_gaps; } ctx.label_secondary(ui, tl!("Hide gaps to join page edges. Margins inside the PDF remain unchanged."), t); + ctx.checkbox(ui, &mut app.view_defaults.full_screen_fill, tl!("Full screen fills the screen with one page at a time"), t); + ctx.label_secondary(ui, tl!("Turn off to keep the page display, such as continuous scrolling, in full screen."), t); + ctx.checkbox(ui, &mut app.full_screen_escape_exits, tl!("Esc leaves full screen"), t); + ctx.label_secondary(ui, tl!("Turn off so that only Ctrl+L (⌘L on macOS) leaves full screen, as for a kiosk display."), t); ui.add_space(6.0); let mut fit_changed = false; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index d77c7b1eb7..35bfd447b2 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -389,6 +389,9 @@ pub struct PdfCraftApp { pub invert_middle_drag: bool, /// Preferences ▸ Animation effects: on, off, or as the system's animation setting says. pub animation_effects: motion::AnimationEffects, + /// Preferences ▸ Esc leaves full screen (on by default). Off, only ⌘L / Ctrl+L leaves it, as + /// for a kiosk display; Esc still closes the find bar and the like. + pub full_screen_escape_exits: bool, /// Whether the system asked for no animations, and how the desktop app asks it. pub motion: motion::Motion, /// Interface language preference: `auto` (follow the system) or a code from [`i18n::LANGUAGES`]. diff --git a/crates/ui-egui/tests/it/view.rs b/crates/ui-egui/tests/it/view.rs index 196818e462..53c2f2d53e 100644 --- a/crates/ui-egui/tests/it/view.rs +++ b/crates/ui-egui/tests/it/view.rs @@ -2973,6 +2973,228 @@ fn a_document_press_releases_pages_keyboard_focus_without_escape() { assert!(h.state().views[0].selected.is_empty(), "Ctrl+A now belongs to the viewer, not page thumbnails"); } +/// #576: full screen fills the screen with the page: a portrait page fits the screen's height +/// edge to edge, with no margin above or below it, and sits centred across. +#[test] +fn full_screen_fills_the_screen_edge_to_edge() { + let mut h = harness(&[]); + h.key_press_modifiers(Modifiers::COMMAND, Key::L); + h.run_steps(6); + assert!(h.state().full_screen && h.state().views[0].fills_screen()); + let vp = h.state().views[0].viewport_rect(); + let r = rect(&h, 0).expect("page 1 on screen"); + assert!((r.height() - vp.height()).abs() <= 1.0, "the page {r:?} spans the screen's height {vp:?}"); + assert!((r.top() - vp.top()).abs() <= 1.0 && (r.bottom() - vp.bottom()).abs() <= 1.0, "no margin: {r:?} in {vp:?}"); + assert!((r.center().x - vp.center().x).abs() <= 1.0, "centred across: {r:?} in {vp:?}"); +} + +/// With the page filling the screen there is no margin above it, and ↑ and the wheel still go +/// back a page from its top, as ↓ and the wheel go forward from its bottom. +#[test] +fn full_screen_filling_the_screen_goes_back_with_up_and_the_wheel() { + let mut h = harness(&[]); + h.key_press_modifiers(Modifiers::COMMAND, Key::L); + h.run_steps(6); + assert!(h.state().views[0].fills_screen()); + h.key_press(Key::End); + h.run_steps(6); + assert_eq!(h.state().views[0].current, 2); + h.key_press(Key::ArrowUp); + h.run_steps(6); + assert_eq!(h.state().views[0].current, 1, "↑ goes back a page"); + let vp = h.state().views[0].viewport_rect(); + h.hover_at(vp.center()); + h.run_steps(2); + h.event(wheel(MouseWheelUnit::Line, 1.0, TouchPhase::Move)); + h.run_steps(6); + assert_eq!(h.state().views[0].current, 0, "the wheel goes back a page"); +} + +/// #4273: with the "Full screen fills the screen with one page at a time" preference off, full +/// screen keeps the page display it was entered from (continuous scrolling here), and Esc +/// brings the window's display back. +#[test] +fn full_screen_keeps_continuous_scrolling_when_fill_is_off() { + let mut h = harness(&[("layout", "continuous"), ("zoom", "50"), ("full-screen-fill", "off")]); + h.run_steps(4); + h.key_press_modifiers(Modifiers::COMMAND, Key::L); + h.run_steps(6); + let v = &h.state().views[0]; + assert!(h.state().full_screen && v.presenting() && !v.fills_screen()); + assert!(v.continuous(), "still scrolling continuously"); + assert!(rect(&h, 0).is_some() && rect(&h, 1).is_some(), "more than one page on screen"); + assert!((v.zoom - 0.5).abs() < 1e-3, "the zoom stays: {}", v.zoom); + h.key_press(Key::Escape); + h.run_steps(4); + assert!(!h.state().full_screen && h.state().views[0].continuous()); +} + +/// #5302: Esc closes one thing at a time. In full screen with the find bar open, the first Esc +/// closes the find bar and full screen stays; the next one leaves full screen (*Adobe Acrobat +/// Help*, 2019, p. 248: in a form field, "Esc" deselects it and "Esc (press twice)" exits Full +/// Screen mode). +#[test] +fn full_screen_esc_closes_the_find_bar_before_leaving() { + let mut h = harness(&[]); + h.key_press_modifiers(Modifiers::COMMAND, Key::L); + h.run_steps(6); + assert!(h.state().full_screen); + h.state_mut().views[0].open_find(); + h.run_steps(2); + assert!(h.state().views[0].find.is_some()); + h.key_press(Key::Escape); + h.run_steps(2); + assert!(h.state().views[0].find.is_none(), "the first Esc closes the find bar"); + assert!(h.state().full_screen, "and full screen stays"); + h.key_press(Key::Escape); + h.run_steps(2); + assert!(!h.state().full_screen, "the next Esc leaves full screen"); +} + +/// Full screen hides the Search panel, and a search shown there isn't the find bar: the first +/// Esc leaves full screen, and the panel's search is still there afterwards. +#[test] +fn full_screen_esc_leaves_and_keeps_the_search_panels_search() { + let mut h = harness(&[]); + h.state_mut().set_option("panel", "search").unwrap(); + h.state_mut().views[0].open_find(); + h.state_mut().views[0].find.as_mut().expect("find opened").in_panel = true; + h.run_steps(2); + h.key_press_modifiers(Modifiers::COMMAND, Key::L); + h.run_steps(6); + assert!(h.state().full_screen); + h.key_press(Key::Escape); + h.run_steps(2); + assert!(!h.state().full_screen, "the first Esc leaves full screen"); + assert!(h.state().views[0].find.is_some(), "and the Search panel's search stays"); +} + +/// When Esc doesn't leave full screen, it doesn't close the hidden Search panel's search either. +#[test] +fn full_screen_esc_that_stays_keeps_the_search_panels_search() { + let mut h = harness(&[("full-screen-escape", "off")]); + h.state_mut().set_option("panel", "search").unwrap(); + h.state_mut().views[0].open_find(); + h.state_mut().views[0].find.as_mut().expect("find opened").in_panel = true; + h.run_steps(2); + h.key_press_modifiers(Modifiers::COMMAND, Key::L); + h.run_steps(6); + h.key_press(Key::Escape); + h.run_steps(2); + assert!(h.state().full_screen, "Esc doesn't leave full screen"); + assert!(h.state().views[0].find.is_some(), "and the Search panel's search stays"); +} + +/// With the Fill screen preference off, full screen keeps the reading position: half way down +/// page 2, it is still half way down page 2 in full screen and again after leaving. +#[test] +fn full_screen_keeps_the_reading_position_when_fill_is_off() { + let mut h = harness(&[("layout", "continuous"), ("zoom", "200"), ("full-screen-fill", "off")]); + h.run_steps(4); + h.state_mut().views[0].goto = Some((1, 0.5)); + h.run_steps(4); + let above = |h: &Harness<'static, PdfCraftApp>| { + let v = &h.state().views[0]; + v.viewport_rect().top() - rect(h, 1).expect("page 2 on screen").top() + }; + let before = above(&h); + assert!(before > 300.0, "page 2 starts well above the window's top: {before}"); + h.key_press_modifiers(Modifiers::COMMAND, Key::L); + h.run_steps(6); + assert!(h.state().full_screen); + let full = above(&h); + assert!((full - before).abs() < 40.0, "full screen keeps the position: {full} vs {before}"); + h.key_press(Key::Escape); + h.run_steps(6); + assert!(!h.state().full_screen); + let after = above(&h); + assert!((after - before).abs() < 40.0, "and so does leaving it: {after} vs {before}"); +} + +/// With the "Esc leaves full screen" preference off, Esc doesn't leave full screen and only +/// Ctrl+L (⌘L) does (*Adobe Acrobat Help*, 2019, "Full Screen preferences", p. 69: "Escape Key +/// Exits: Lets you exit Full-Screen mode by pressing the Esc key. If this option is not selected, +/// you can exit by pressing Ctrl+L"). +#[test] +fn full_screen_stays_on_esc_when_esc_does_not_leave_it() { + let mut h = harness(&[("full-screen-escape", "off")]); + h.key_press_modifiers(Modifiers::COMMAND, Key::L); + h.run_steps(6); + assert!(h.state().full_screen); + h.key_press(Key::Escape); + h.run_steps(2); + assert!(h.state().full_screen, "Esc doesn't leave full screen"); + h.key_press_modifiers(Modifiers::COMMAND, Key::L); + h.run_steps(4); + assert!(!h.state().full_screen, "Ctrl+L / ⌘L leaves it"); +} + +/// From a form field being filled, the first Esc closes the field and the second leaves full +/// screen: "Esc (press twice)" (*Adobe Acrobat Help*, 2019, "Options for working in forms", +/// p. 248). +#[test] +fn full_screen_esc_from_a_field_closes_the_field_first() { + const FIELD: &[u8] = b"%PDF-1.7 +1 0 obj << /Type /Catalog /Pages 2 0 R /AcroForm << /Fields [4 0 R] >> >> endobj +2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 /MediaBox [0 0 300 400] >> endobj +3 0 obj << /Type /Page /Parent 2 0 R /Annots [4 0 R] >> endobj +4 0 obj << /Type /Annot /Subtype /Widget /FT /Tx /T (name) /Rect [50 100 250 140] /P 3 0 R /F 4 >> endobj +trailer << /Root 1 0 R >> +%%EOF"; + let mut h = harness(&[]); + h.state_mut().open_bytes("field.pdf", None, FIELD.to_vec()).expect("opens"); + h.run_steps(8); + h.key_press_modifiers(Modifiers::COMMAND, Key::L); + h.run_steps(6); + let n = h.state().views.len() - 1; + // Until page 1's raster is in, full screen veils it and the click reaches no field; on a slow + // machine that takes more frames than the six above. + for _ in 0..600 { + if h.state().views[n].presentation_settled() { + break; + } + h.run_steps(1); + } + assert!(h.state().views[n].presentation_settled(), "page 1 is shown"); + let r = h.state().views[n].page_screen_rect(0).expect("page 1 on screen"); + // One page only: the click can't turn away from the field. + click_with(&mut h, egui::pos2(r.left() + r.width() * 0.5, r.top() + r.height() * (400.0 - 120.0) / 400.0), Modifiers::NONE); + assert!(h.ctx.egui_wants_keyboard_input(), "the field is open for typing"); + h.key_press(Key::Escape); + h.run_steps(4); + assert!(h.state().full_screen, "the first Esc closes the field only"); + assert!(!h.ctx.egui_wants_keyboard_input(), "the field is closed"); + h.key_press(Key::Escape); + h.run_steps(4); + assert!(!h.state().full_screen, "the second Esc leaves full screen"); +} + +/// Full screen shows no notice bar above the page (a form's "interactive form fields" notice, here), +/// so a page filling the screen is whole on it; the bar is back on leaving. +#[test] +fn full_screen_hides_the_notice_bar_and_the_page_fits_whole() { + let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_cc| { + let mut app = PdfCraftApp::new(); + app.set_option("language", "en").unwrap(); + app.open_bytes("form.pdf", None, include_bytes!("../data/form.pdf").to_vec()).expect("opens"); + app.set_option("left", "closed").unwrap(); + app.set_option("panel", "none").unwrap(); + app + }); + h.run_steps(8); + let notice = |h: &Harness<'static, PdfCraftApp>| h.query_by_label_contains("interactive form fields").is_some(); + assert!(notice(&h), "the form notice shows in the window"); + h.key_press_modifiers(Modifiers::COMMAND, Key::L); + h.run_steps(6); + assert!(h.state().full_screen && !notice(&h), "no notice bar in full screen"); + let vp = h.state().views[0].viewport_rect(); + let r = rect(&h, 0).expect("page 1 on screen"); + assert!(r.top() >= vp.top() - 1.0 && r.bottom() <= vp.bottom() + 1.0, "the page {r:?} is whole in {vp:?}"); + h.key_press(Key::Escape); + h.run_steps(4); + assert!(notice(&h), "the notice is back after full screen"); +} + /// Delete over the Pages panel with a menu of the menu bar open is the menu's, and the Escape that /// closes a thumbnail's context menu the menu's: no page is deleted, and the page selection stays. /// Delete deleted the selected pages, and the panel took the Escape: it dropped the selection and diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index 69e78702fc..3c411d9813 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -10191,11 +10191,11 @@ title = "Preferences: full screen" area = "N" tier = "P2" milestone = "M14" -status = "planned" +status = "partial" commands = [] tools = [] -evidence = [] -notes = "" +evidence = ["crates/ui-egui/tests/it/view.rs::full_screen_fills_the_screen_edge_to_edge", "crates/ui-egui/tests/it/view.rs::full_screen_keeps_continuous_scrolling_when_fill_is_off", "crates/ui-egui/tests/it/view.rs::full_screen_stays_on_esc_when_esc_does_not_leave_it", "crates/ui-egui/tests/it/view.rs::full_screen_esc_closes_the_find_bar_before_leaving"] +notes = "Two of the full-screen preferences, in Preferences under Documents and view and saved with the others: Full screen fills the screen with one page at a time (on: the page or spread edge to edge, no margin or shadow, #576; off: full screen keeps the page display it was entered from, such as continuous scrolling, #4273) and Esc leaves full screen (off: only Ctrl+L / Cmd+L leaves it). Esc closes an open menu, the camera, a selection or the find bar before it leaves full screen (#5302). Missing: show a navigation bar, left/right click to page as an option, loop after the last page, advance every N seconds, the alert when a document asks for full screen, which monitor, background colour, mouse cursor, default transition and ignoring the document's transitions" [[feature]] id = "misc.prefs-search"