Files
cindy/apps/mobile/docs/html-browser-viewport.md
Dash e8bf76c900 fix(mobile): 内置浏览器打开时不再闪旧界面,并补齐深色模式 (#5793)
* fix(mobile): 内置浏览器打开时不再闪旧界面,并补齐深色模式

- 打开 HTML 文件时,文件列表加载期间直接显示浮动浏览器外框,不再先出现旧标题栏
- 浮动按钮与地址栏的玻璃按主题染色,深色模式压在浅色页面上不再变浅
- 网页首次加载完成前隐藏 WebView,底色跟随主题,去掉白屏闪烁与按钮后的白条
- 页面未设置背景时按其自身配色方案绘制 Canvas 底色,声明 color-scheme 的页面在深色下不再白底白字

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(mobile): 收紧页面底色兜底判据,加载期外框禁用无效操作并补测试

- 背景图(含渐变)也算页面自有背景;内联 transparent 不再被误判为已有背景,是否已补底色改用独立标记
- 文件列表加载期的浏览器外框禁用地址编辑和更多菜单
- 补充首次加载前隐藏、换文件或重建渲染进程后重新隐藏,以及底色兜底各分支的测试

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(mobile): 按 alpha 通道判断页面背景是否透明

计算样式会保留透明色的 RGB 通道(如 rgba(255, 0, 0, 0)),改为解析 alpha,并保持不透明 rgb() 不被误判

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* chore(design): rebase 后重新生成设计清单

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(mobile): 页面底色补在 body 上,沿用 body 的 color-scheme

html 透明时 body 背景铺满整个画布,Canvas 按 body 自身(或继承自 html)的配色方案解析,避免只在 body 声明 color-scheme 的页面白底白字

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

---------

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
2026-10-11 20:52:57 +08:00

5.8 KiB

HTML browser viewport

On iOS 26+, local HTML and websites keep a full-size WebView under floating browser controls. The host sets WebKit's public obscuredContentInsets, which adjusts the layout viewport and fixed/sticky positioning without shrinking the native view. Matching scroll-view contentInset values let ordinary document content scroll clear of both toolbars at the start and end. The obscured prop alone does not supply this scroll range. No browser APIs are overridden. The keyboard is handled by WebKit; it is not added to the browser-chrome prop a second time.

Appearance

The WebView's native backing follows the app theme, so the strips under the controls and the area before the first paint match Light or Dark mode. The WebView stays hidden until its first document finishes loading. The native backing would otherwise become the canvas of a page that sets no background. Like Safari, the viewport script therefore paints body with the CSS Canvas system color, but only when neither html nor body has a background color or image (an inline transparent still counts as none). With html transparent, the body color covers the whole canvas and follows body's color-scheme. Unstyled pages stay light. Pages that declare color-scheme follow the system appearance. Pages that set their own background are left unchanged. The floating controls tint their glass with the app theme. Untinted glass adapts to the page behind it and would turn light under light icons in Dark mode.

Android and older iOS retain a bounded WebView fallback. Optional advisory geometry remains available without a page-to-native message handler.

CSS and JavaScript

All lengths are CSS pixels, including when the page is zoomed or has no viewport meta tag.

CSS custom property Meaning
--cindy-viewport-width, --cindy-viewport-height Measured WebView frame
--cindy-controls-top/right/bottom/left Conservative strips occupied by browser controls and device safe areas within that frame
--cindy-inset-top/right/bottom/left Same strips, with keyboard obstruction included
--cindy-available-width, --cindy-available-height Frame minus the obstruction strips, clamped to zero
--cindy-available-top, --cindy-available-left Available rectangle origin in document coordinates, including native scrolling

window.cindyViewport is a read-only, frozen snapshot:

// Every field except version is a CSS length.
{ version: 1, width, height, controls: { top, right, bottom, left },
  insets: { top, right, bottom, left }, availableTop, availableLeft,
  availableWidth, availableHeight }

Read it if present, then listen for window's cindyviewportchange event; event.detail contains the next snapshot. Geometry can arrive after page scripts start. Updates follow native layout, scrolling, rotation, keyboard frame/show/hide and page zoom changes. Each navigated document receives its own installation. Event handlers must be idempotent; delivery can repeat the same geometry after navigation/load.

Full-height application example

<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<style>
  html, body { margin: 0; height: 100%; overflow: hidden; }
  .app { position: absolute;
         top: var(--cindy-available-top, 0px);
         left: var(--cindy-available-left, 0px);
         height: var(--cindy-available-height, 100dvh);
         width: var(--cindy-available-width, 100%);
         display: flex; flex-direction: column; }
  .app > main { flex: 1; min-height: 0; overflow: auto; }
  .app > header, .app > footer { flex: none; }
</style>
<div class="app"><header>Title</header><main>Content</main><footer>Actions</footer></div>

On iOS 26+, the published width/height describe the full native WebView frame. Controls describe the toolbar/safe-area strips, and insets describe their union with keyboard occlusion. Available dimensions exclude those strips. These custom values are advisory; ordinary fixed footers rely on WebKit's native layout. obscuredContentInsets and CSS env(safe-area-inset-*) are distinct APIs; do not assume the latter equals the toolbar height or add toolbar padding twice.

In the older-platform fallback, strips are excluded by native layout, so published controls/insets are zero and available dimensions equal the smaller WebView frame. The full-height example uses document coordinates, not fixed-position offsets. An overlapping floating keyboard conservatively reserves the strip below its top edge in the advisory geometry. Transient menus and share sheets are not included. Page-local properties are not a security boundary.

Native build requirement

The WebView dependency patch adds the prop to Fabric, Paper and TypeScript with an iOS 26 SDK/runtime guard and zero default. Existing selection-menu changes are preserved. This changes the native fingerprint: ship a new binary; an OTA update cannot add this native capability to an old binary. Release/merge still requires the repository's explicit cold-update review.

Address editing

Tapping the address capsule edits the address in place. Submitting a bare domain uses HTTPS; explicit HTTP and HTTPS addresses are supported. Invalid input keeps the editor open. The file preview displays its local path, never its private snapshot bootstrap URL; leaving that path unchanged dismisses editing. The field does not navigate to other local filesystem paths.

Opening a website waits for the file snapshot server to close, then mounts a separate incognito WebView without file access or a page-to-native message handler. The website receives the same advisory viewport geometry. Native website history stays available while the app is inactive. The menu offers Return to file and Copy address; returning to the file starts a fresh snapshot. Copy and share use the website's current URL, including redirects.