oficina / slides Public

Keep projector controls inside the viewport

Paul Campbell pushed by paul@keymail.dev 3300471023f7f27a5e4be71cce3c67b00e51d355 parent b555e4d
2 files changed, +95 −7
  • internal/slides/templates/present.html +33 −7
  • internal/slidestest/browser_present_test.go +62 −0

CI passed — run details

diff --git a/internal/slides/templates/present.html b/internal/slides/templates/present.html
index 2323771..548ab55 100644
--- a/internal/slides/templates/present.html
+++ b/internal/slides/templates/present.html
@@ -18,15 +18,17 @@
<meta http-equiv="refresh" content="5">{{end}}
<script defer src="{{asset "static/present.js"}}"></script>
<style>
- /* The stage fills what it is given and keeps the slide's aspect;
- everything else on this page is one line of chrome under it. */
+ /* The projector is a bounded black stage, never a document that can
+ push its remote controls underneath the fold. The controls live on
+ the stage so the slide can use every pixel behind them. */
[slides-surface] {
- box-sizing: border-box;
+ background: #000;
+ block-size: 100dvh;
+ box-sizing: border-box;
display: flex;
- flex-direction: column;
- gap: var(--rst-sp-3);
- min-block-size: 100dvh;
- padding: var(--rst-sp-3);
+ inline-size: 100%;
+ overflow: hidden;
+ position: relative;
}
/* The projector is its own full-screen stage, not a document inside
the ordinary constrained rst-page wrapper. Its capability is what
@@ -39,13 +41,32 @@
padding: 0;
}
[slides-stage] {
+ align-items: center;
+ display: flex;
+ flex: 1 1 auto;
+ inline-size: 100%;
+ justify-content: center;
margin: 0;
+ min-block-size: 0;
+ min-inline-size: 0;
+ }
+ [slides-stage] > [slides-slide] {
+ block-size: min(100dvh, calc(100vw * 9 / 16));
+ inline-size: min(100vw, calc(100dvh * 16 / 9));
+ max-block-size: 100%;
+ max-inline-size: 100%;
}
[slides-bar] {
align-items: center;
+ background: color-mix(in srgb, #000 72%, transparent);
+ bottom: 0;
display: flex;
flex-wrap: wrap;
gap: var(--rst-sp-3);
+ inset-inline: 0;
+ justify-content: center;
+ padding: var(--rst-sp-3);
+ position: absolute;
}
[slides-bar] form {
display: inline;
@@ -67,8 +88,13 @@
visibility: hidden;
}
[slides-blackout] {
+ align-self: center;
+ color: #fff;
font-weight: 600;
margin: 0;
+ position: absolute;
+ text-align: center;
+ z-index: 1;
}
</style>{{end}}
{{define "main"}}<main id="main" slides-present-stage>{{template "content" .}}</main>{{end}}
diff --git a/internal/slidestest/browser_present_test.go b/internal/slidestest/browser_present_test.go
index 13ed87b..6b74425 100644
--- a/internal/slidestest/browser_present_test.go
+++ b/internal/slidestest/browser_present_test.go
@@ -10,16 +10,78 @@
package slidestest
import (
+ "fmt"
"regexp"
"sync/atomic"
"testing"
"time"
+ "github.com/chromedp/cdproto/emulation"
"github.com/chromedp/cdproto/page"
"github.com/chromedp/chromedp"
"github.com/chromedp/chromedp/kb"
)
+// TestBrowserProjectorFitsTheViewport keeps the projector a stage rather
+// than a long document: its slide is bounded by the viewport and its
+// controls are overlaid where the presenter can still reach them.
+func TestBrowserProjectorFitsTheViewport(t *testing.T) {
+ rig, mailer := newRig(t)
+ browserSignIn(t, rig, mailer)
+
+ var deck string
+ rig.Run(chromedp.Evaluate(`(document.querySelector('a[href^="/d/"]')?.getAttribute('href') ?? '')`, &deck))
+ if !deckPath.MatchString(deck) {
+ t.Fatalf("the deck list links no deck: %q", deck)
+ }
+
+ var path string
+ rig.Run(
+ chromedp.Navigate(rig.Origin+deck),
+ chromedp.Click(`form[action$="/present"] button`, chromedp.ByQuery),
+ waitFor(`location.pathname.endsWith('/notes')`),
+ chromedp.Evaluate(`location.pathname + location.search`, &path),
+ )
+ m := notesLocation.FindStringSubmatch(path)
+ if m == nil {
+ t.Fatalf("Present landed on %q, want /p/{session}/notes?t={token}", path)
+ }
+
+ for _, viewport := range []struct{ width, height int }{{1920, 1080}, {1280, 720}} {
+ t.Run(fmt.Sprintf("%dx%d", viewport.width, viewport.height), func(t *testing.T) {
+ var geometry struct {
+ ScrollHeight float64 `json:"scrollHeight"`
+ Viewport float64 `json:"viewport"`
+ ScrollY float64 `json:"scrollY"`
+ Top float64 `json:"top"`
+ Bottom float64 `json:"bottom"`
+ }
+ rig.Run(
+ emulation.SetDeviceMetricsOverride(int64(viewport.width), int64(viewport.height), 1, false),
+ chromedp.Navigate(rig.Origin+m[1]+"?t="+m[2]),
+ chromedp.WaitVisible(`[slides-bar]`, chromedp.ByQuery),
+ chromedp.Evaluate(`(() => {
+ window.scrollTo(0, 1);
+ const controls = document.querySelector('[slides-bar]').getBoundingClientRect();
+ return {
+ scrollHeight: document.documentElement.scrollHeight,
+ viewport: window.innerHeight,
+ scrollY: window.scrollY,
+ top: controls.top,
+ bottom: controls.bottom,
+ };
+ })()`, &geometry),
+ )
+ if geometry.ScrollHeight > geometry.Viewport || geometry.ScrollY != 0 {
+ t.Errorf("projector scrolls: document %.0fpx, viewport %.0fpx, scrollY %.0f", geometry.ScrollHeight, geometry.Viewport, geometry.ScrollY)
+ }
+ if geometry.Top < 0 || geometry.Bottom > geometry.Viewport {
+ t.Errorf("controls are outside the viewport: top %.0fpx, bottom %.0fpx, viewport %.0fpx", geometry.Top, geometry.Bottom, geometry.Viewport)
+ }
+ })
+ }
+}
+
var notesLocation = regexp.MustCompile(`^(/p/[23456789abcdefghjkmnpqrstuvwxyz]{10})/notes\?t=([A-Za-z0-9_-]{43})$`)
// TestBrowserPresentingScreensHoldStill: the presenter view and the