Skip to content

Fix browser viewport presets incorrectly scaled by UI zoom - #20962

Merged
AmethystLiang merged 2 commits into
mainfrom
jinjing/sta-7568-bug-browser-viewport-presets-are-incorrectly-scaled-by-orca
Sep 16, 2026
Merged

AmethystLiang merged 2 commits into
mainfrom
jinjing/sta-7568-bug-browser-viewport-presets-are-incorrectly-scaled-by-orca

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​395 $\color{#cf222e}{\Huge{\mathbf{−}}}$​412 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​71 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53

Problem

When Orca's UI zoom is set above 100%, browser viewport presets (like iPhone 14: 390×844) are sized incorrectly. The emulated webpage gets the right dimensions, but Orca scales the surrounding browser frame too, leaving an empty strip beside the content.

Solution

Store preset dimensions as window-DIP CSS variables and compensate during layout with calc(var(--browser-page-viewport-width) / var(--ui-zoom-factor)). This keeps Chromium's emulated viewport at the correct size while the host frame shrinks as UI zoom inflates CSS pixels. Switching back to responsive mode clears the preset and restores 100% width/height.

Extracted zoom-factor calculation into a shared uiZoomFactorFromLevel() helper to replace scattered 1.2 ** level formulas.

Linked Issue

Fixes #20757

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Tested at 110% and 120% UI zoom; frame and webpage both remain 390×844, responsive mode restores correctly.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Browser viewport presets must remain in window DIP (native) coordinates
but scale in CSS pixels as UI zoom changes. Store preset dimensions as
CSS variables in DIP, then divide by the live UI zoom factor in the
stylesheet. Also consolidate zoom factor calculations across the app
to use a shared `uiZoomFactorFromLevel()` function and add
`windowDipToCssPx()` for converting native coordinates to CSS pixels.
@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 309b89fd-769a-4578-a568-591b6ec40d99

📥 Commits

Reviewing files that changed from the base of the PR and between 2c2106f and b015152.

📒 Files selected for processing (11)
  • src/main/window/main-window-state-lifecycle.ts
  • src/renderer/src/assets/main.css
  • src/renderer/src/components/browser-pane/assemble-chrome/browser-page-context-menu.tsx
  • src/renderer/src/components/browser-pane/host-guest/browser-page-viewport.test.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-viewport.ts
  • src/renderer/src/components/settings/SettingsConstants.ts
  • src/renderer/src/hooks/useIpcEvents-zoom-routing.test.ts
  • src/renderer/src/hooks/zoom-routing.test.ts
  • src/renderer/src/lib/ui-zoom.test.ts
  • src/renderer/src/lib/ui-zoom.ts
  • src/shared/ui-zoom-level.ts
💤 Files with no reviewable changes (1)
  • src/renderer/src/hooks/useIpcEvents-zoom-routing.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The change centralizes UI zoom-factor calculations in shared utilities. Renderer zoom publishing, traffic-light positioning, settings percentages, and screen-coordinate conversion use the shared calculations. Browser viewport presets store window-DIP dimensions in CSS variables and divide frame dimensions by the UI zoom factor. Related viewport and zoom-routing tests are updated, and zoom-routing coverage is moved to a new test file.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to b0151

No concrete merge-blocking risk remains; preset sizing retains valid dimensions before zoom publishing.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, solution, linked issue, testing, and scope. However, it omits the required Visual Proof section for a UI behavior change and leaves self-review and cross-platform… Add before-and-after screenshots or a video, or write N/A with a brief reason if visual proof is not applicable. Complete the self-review and cross-platform checklist items, and document any remaining validation such as lint, typecheck, t…
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 9 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: correcting browser viewport preset scaling under UI zoom.
Linked Issues check ✅ Passed The changes meet #20757. setBrowserPageViewportPresetSize stores preset dimensions in --browser-page-viewport-width and --browser-page-viewport-height and does not alter Chromium viewport values…
Out of Scope Changes check ✅ Passed The changes stay connected to #20757. The shared uiZoomFactorFromLevel helper and windowDipToCssPx conversion prevent inconsistent zoom calculations. The updated zoom-routing tests and ui-zoom t…
Full details: Description check

Explanation

The description explains the problem, solution, linked issue, testing, and scope. However, it omits the required Visual Proof section for a UI behavior change and leaves self-review and cross-platform considerations unchecked.

Resolution

Add before-and-after screenshots or a video, or write N/A with a brief reason if visual proof is not applicable. Complete the self-review and cross-platform checklist items, and document any remaining validation such as lint, typecheck, test, and build results or CI coverage.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 9 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one coverage gap worth a look.

Reviewed changes

  • Shared zoom-factor helper — uiZoomFactorFromLevel() and UI_ZOOM_BASE in src/shared/ui-zoom-level.ts replace the scattered 1.2 ** level formulas, adopted by ui-zoom.ts, SettingsConstants.ts, and main-window-state-lifecycle.ts.
  • Preset host sizing fix — browser-page-viewport.ts stores the preset dimensions as window-DIP CSS variables and sizes the content box with calc(... / var(--ui-zoom-factor, 1)); clearing the preset removes the variables and restores 100%.
  • Cursor-coordinate refactor — browser-page-context-menu.tsx now calls windowDipToCssPx(), behaviorally identical to the previous inline 1.2 ** getZoomLevel().
  • Zoom test migration — useIpcEvents-zoom-routing.test.ts is replaced by zoom-routing.test.ts, which drives registerZoomIpcBridge directly and adds clamp/reset/editor-focus cases; ui-zoom.test.ts covers windowDipToCssPx, applyUIZoom, and syncZoomCSSVar.

I ran the three affected suites locally (browser-page-viewport.test.ts, zoom-routing.test.ts, ui-zoom.test.ts) and all 39 tests pass. The compensation direction is correct (host CSS px = window DIP / zoom factor), and the CSS variable stays in sync with the live webFrame level because the main window's zoom only changes through applyUIZoom or syncZoomCSSVar.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Inline width/height styles outrank class rules, preventing the zoom
compensation from applying. Using a class rule ensures the viewport
scales correctly as the UI zoom factor changes.
@AmethystLiang
AmethystLiang force-pushed the jinjing/sta-7568-bug-browser-viewport-presets-are-incorrectly-scaled-by-orca branch from 2c2106f to b015152 Compare September 16, 2026 05:53

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Moved the preset viewport's zoom compensation out of an inline calc() width/height and into a static .browser-page-preset-viewport rule in main.css, applied by class so the stylesheet var(--ui-zoom-factor, 1) division actually takes effect.
  • applyViewportPresetSizeStyles now sets the window-DIP CSS variables, removes any inline width/height, and toggles BROWSER_PAGE_PRESET_VIEWPORT_CLASS_NAME; the non-preset branch removes the class and restores 100%.
  • Added tests pinning the CSS rule body and asserting the host box opts into the class with no inline size, closing the prior review's coverage gap.

The rest of the diff was covered in the prior pass. I re-ran the three affected suites (41 tests, all passing) and check:code-quality:changed reports 0 new findings across the 9 changed files.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@AmethystLiang
AmethystLiang merged commit 7860933 into main Sep 16, 2026
26 of 28 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…20962)

* Fix browser viewport presets scaled incorrectly by UI zoom

Browser viewport presets must remain in window DIP (native) coordinates
but scale in CSS pixels as UI zoom changes. Store preset dimensions as
CSS variables in DIP, then divide by the live UI zoom factor in the
stylesheet. Also consolidate zoom factor calculations across the app
to use a shared `uiZoomFactorFromLevel()` function and add
`windowDipToCssPx()` for converting native coordinates to CSS pixels.

* Move viewport preset zoom compensation to CSS class

Inline width/height styles outrank class rules, preventing the zoom
compensation from applying. Using a class rule ensures the viewport
scales correctly as the UI zoom factor changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Browser viewport presets are incorrectly scaled by Orca UI zoom

1 participant