web: the keyboard is measured in layout pixels, with a strip where it resizes the page
Review 6 on #181. "The keyboard is up" compared visualViewport.height with innerHeight: a pinch-zoom, which shrinks the visual viewport too, read as a keyboard and raised the capsule; and where a keyboard shrinks the layout viewport itself (interactive-widget=resizes-content, Firefox for Android) the two stay equal and the quick bar never showed. Now the visual viewport is measured in layout pixels (height times scale) against documentElement.clientHeight, and a layout viewport fallen more than 150px short of its tallest at this width, with the caret in the document, gets the strip under the bar. TestWhenTheKeyboardIsUp: zoomed 2x with the caret, no capsule; the layout viewport shrunk 336px, the strip under the bar; back to full height, none. Both the first two failed before this.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+43
−2
internal/docs/brand/phone.js+14 −2internal/docs/phone_sheet_browser_test.go+29 −0
diff --git a/internal/docs/brand/phone.js b/internal/docs/brand/phone.js| index 95ebb75..f404c10 100644 |
| --- a/internal/docs/brand/phone.js |
| +++ b/internal/docs/brand/phone.js |
| @@ -286,10 +286,22 @@ |
| }); |
| } |
| var lastHeight = -1; |
| + // The layout viewport's tallest height at this width: a keyboard that |
| + // shrinks the layout viewport itself (interactive-widget= |
| + // resizes-content, Firefox for Android) leaves the visual viewport as |
| + // tall as it, and shows only as the layout viewport falling short of |
| + // this. |
| + var tallest = 0, tallestAt = -1; |
| function place() { |
| var phone = !compact || compact.matches; |
| var focused = !!editor && editor.contains(document.activeElement); |
| - var up = phone && focused && !!vv && vv.height < window.innerHeight - 150; |
| + var layout = document.documentElement.clientHeight; |
| + if (window.innerWidth !== tallestAt) { tallestAt = window.innerWidth; tallest = 0; } |
| + if (layout > tallest) tallest = layout; |
| + // In layout pixels (height times scale), so a pinch-zoom, which |
| + // shrinks the visual viewport too, is not a keyboard. |
| + var up = phone && focused && !!vv && vv.height * (vv.scale || 1) < layout - 150; |
| + var shrunk = phone && focused && !up && tallest - layout > 150; |
| if (up !== keyboardUp) { keyboardUp = up; fold(); } |
| // The bar stays at the top of what can be seen while the keyboard |
| // is up. Pinch-zoomed (scale not 1), the page is being looked at, |
| @@ -302,7 +314,7 @@ |
| } |
| if (!quick) return; |
| var mode = ""; |
| - if (phone && focused && !sheetOpen()) mode = vv ? (up ? "keyboard" : "") : "strip"; |
| + if (phone && focused && !sheetOpen()) mode = vv && !shrunk ? (up ? "keyboard" : "") : "strip"; |
| if ((quick.getAttribute("data-shown") || "") !== mode) { |
| if (mode) quick.setAttribute("data-shown", mode); |
| else quick.removeAttribute("data-shown"); |
diff --git a/internal/docs/phone_sheet_browser_test.go b/internal/docs/phone_sheet_browser_test.go| index 67a8fed..05d3927 100644 |
| --- a/internal/docs/phone_sheet_browser_test.go |
| +++ b/internal/docs/phone_sheet_browser_test.go |
| @@ -13,6 +13,7 @@ import ( |
| "bytes" |
| "context" |
| "encoding/json" |
| + "math" |
| "net/http" |
| "net/http/httptest" |
| "os" |
| @@ -287,3 +288,31 @@ func TestAPinchZoomLeavesTheBarAlone(t *testing.T) { |
| t.Errorf("pinch-zoomed with the caret: the bar's top at %.1f, want 0", p.BarTop) |
| } |
| } |
| + |
| +// Review 6: when the keyboard is up. A pinch-zoom shrinks the visual |
| +// viewport too, so the threshold is measured in layout pixels (height |
| +// times scale): zoomed, with the caret, there is no capsule. Where a |
| +// keyboard shrinks the layout viewport itself (interactive-widget= |
| +// resizes-content, Firefox for Android) the visual viewport never looks |
| +// short; the quick bar is then the strip under the bar. |
| +func TestWhenTheKeyboardIsUp(t *testing.T) { |
| + s := newSheetRig(t, "simple.bin", "") |
| + s.run("zoomed, the caret", chromedp.Click(chromedp.CSS(`[docs-text] p:first-child`)), do(`__zoom(2, 300)`), settle) |
| + if p := s.probe("zoomed with the caret"); p.Quick != "" { |
| + t.Errorf("pinch-zoomed with the caret and no keyboard: the quick bar is %q, want none", p.Quick) |
| + } |
| + s.run("unzoomed", do(`__zoom(1, 0)`), settle) |
| + // The layout viewport 336px shorter, and the visual one with it. |
| + s.run("resizes-content", command(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: 390, Height: 508, DeviceScaleFactor: 2, Mobile: true}), |
| + settle, do(`__keyboard(0, 0)`), settle) |
| + if p := s.probe("resizes-content"); p.Quick != "strip" || !near(p.QuickTop, p.BarBottom) { |
| + t.Errorf("the layout viewport shrunk by a keyboard: the quick bar is %q at %.1f, want the strip under the bar at %.1f", p.Quick, p.QuickTop, p.BarBottom) |
| + } |
| + s.run("the keyboard down", command(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: 390, Height: 844, DeviceScaleFactor: 2, Mobile: true}), |
| + settle, do(`__keyboard(0, 0)`), settle) |
| + if p := s.probe("the keyboard down"); p.Quick != "" { |
| + t.Errorf("the layout viewport back to full height: the quick bar is %q, want none", p.Quick) |
| + } |
| +} |
| + |
| +func near(a, b float64) bool { return math.Abs(a-b) <= 1.5 } |