Multiply input coords by window scale_factor so Retina clicks land

GPUI delivers logical (CSS) pixels but Servo expects device pixels.
On a 2x Retina display the page rendered at half resolution and every
click landed in roughly the upper-left quadrant of the page — the
second independent root cause that surfaces immediately after T1's
show()/focus() lets input reach Servo at all.

Single conversion boundary inside web_surface_geometry.rs:
viewport_dimension, scroll_dimension, and click_coordinate each
multiply once by window.scale_factor() before truncating to integer
device pixels. positive_scale_or_one() guards against a zero/negative/
NaN scale_factor reaching the arithmetic — falling back to 1.0 keeps
coordinates valid even if the platform reports nonsense (system
boundary validation per CLAUDE.md, not internal trust).

scale_factor is plumbed through controller and view layer, sourced
from window.scale_factor() at every record_* boundary so all four
inputs (click, scroll, hover, viewport) stay in sync. Existing tests
pin the 1.0 path; new retina_scale_factor_doubles_every_input_coordinate
locks the 2.0 path against a future regression.

cargo test ely_app --bin ely_app: 104 passed (was 103 + new test).
This commit is contained in:
2026-05-10 01:53:51 -04:00
parent 22ba8517d1
commit c20daf36b9
6 changed files with 136 additions and 39 deletions
@@ -52,9 +52,10 @@ impl ElyShell {
&mut self,
tab_id: TabId,
bounds: Bounds<Pixels>,
scale_factor: f32,
cx: &mut Context<Self>,
) {
if self.web_surfaces.record_viewport_size(&tab_id, bounds) {
if self.web_surfaces.record_viewport_size(&tab_id, bounds, scale_factor) {
cx.notify();
}
}
@@ -64,9 +65,15 @@ impl ElyShell {
tab_id: TabId,
requested_url: String,
delta: Point<Pixels>,
scale_factor: f32,
cx: &mut Context<Self>,
) {
if self.web_surfaces.record_scroll_delta(&tab_id, requested_url.as_str(), delta) {
if self.web_surfaces.record_scroll_delta(
&tab_id,
requested_url.as_str(),
delta,
scale_factor,
) {
cx.notify();
}
}
@@ -75,9 +82,10 @@ impl ElyShell {
&mut self,
tab_id: TabId,
position: Point<Pixels>,
scale_factor: f32,
cx: &mut Context<Self>,
) {
if self.web_surfaces.record_hover_point(&tab_id, position) {
if self.web_surfaces.record_hover_point(&tab_id, position, scale_factor) {
cx.notify();
}
}
@@ -91,7 +99,13 @@ impl ElyShell {
cx: &mut Context<Self>,
) {
self.focus_handle.focus(window);
if self.web_surfaces.record_click_point(&tab_id, requested_url.as_str(), position) {
let scale_factor = window.scale_factor();
if self.web_surfaces.record_click_point(
&tab_id,
requested_url.as_str(),
position,
scale_factor,
) {
cx.notify();
}
}