servo/ports/servoshell
Mukilan Thiyagarajan ba67a0a4fb
servoshell: fix issues related to HiDPI (#33529)
The current implementation has 3 main issues related to HiDPI:

1. When the window moves from a screen with scale factor of 1.5 to one
   with 1 and back to 1.5, the minibrowser toolbar actually ends up
   being scaled by a factor of 2.25 instead of 1.5. This is because we
   currently use the [set_pixels_per_point] method on egui's Context,
   but calling this with a value of `ppp` will modify egui's internal
   'zoom factor' to be:
   ```
   zoom_factor = ppp / native_points_per_pixel.
   ```
   where `native_points_per_pixel` is the window system scale factor.
   The idea is egui can calculate the final scale factor for translating
   its logical points to physical pixels as:
   ```
   points_per_pixel = zoom_factor * native_points_per_pixel
   ```
   where zoom_factor is a factor used for Ctrl+Plus, Ctrl+Minus
   behaviour. The problem is when we handle the ScaleFactorChanged winit
   event due to window moving between screens, the
   `native_points_per_pixel` still has the value of the previous
   screen's native scaling factor and not the current screen's factor.
   This seems to be the case even if we pass the ScaleFactorChanged
   event to egui before we call `set_pixels_per_point`.
2. The egui logic for handing Ctrl+Plus, Ctrl+Minus and Ctrl+0 doesn't
   interact well with servoshell's device-pixel-ratio CLI argument which
   allows the user to override the HiDPI factor. For example, Ctrl+0
   will cause egui to reset the zoom_factor to 1.0 instead of the
   override we wanted. Another issue is egui's Ctrl+Plus/Ctrl+Minus
   will scale the minibrowser in increments of 0.10 whereas
   Servo's own page zoom doesn't (it keeps multiplying by 1.1, so the
   actual increments are 0.1, 0.21. 0.33 etc)
3. The inital window size calculation on Linux currently assumes a scale
   factor of 1.0. This means the window doesn't have the expected
   default logical size of 1024*740 on HiDPI systems. On a screen with
   HiDPI factor of 1.5, the logical window size ends up being 682x493.

This change addresses all 3 issues:

For 1,  switch to the `set_zoom_factor` method of egui context
to avoid the issue with scaling by incorrect native_points_per_pixel.
To allow for the device-pixel-ratio override to work, we calculate the
actual zoom_factor as `device-pixel-ratio / window's scaling factor`.

For 2, disable egui's handling of Ctrl+Plus, Ctrl+Minus, Ctrl-0
shortcuts. It is unclear whether the current behaviour of scaling
both the toolbar and the web page was intentional, or just an accident.
This behaviour is also different from other browser where page zoom
doesn't scale the GUI, so it doesn't seem like a regression to me.

For 3, use LogicalSize type of winit which lets the physical size
calulation to be handled by winit using the windows's actual HiDPI
factor instead of hardcoded 1.0.

[set_pixels_per_point]: 1603f05818/crates/egui/src/context.rs (L1886)

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2024-09-24 12:12:23 +00:00
..
desktop servoshell: fix issues related to HiDPI (#33529) 2024-09-24 12:12:23 +00:00
egl ohos: Bundle resource files in hap (#33513) 2024-09-24 04:29:53 +00:00
platform minibrowser: implement HiDPI support (#30343) 2023-09-14 13:24:38 +00:00
backtrace.rs Add OpenHarmony support to servoshell (#32594) 2024-06-28 12:51:50 +00:00
build.rs Set the cfg properly for the production-stripped profile (#32991) 2024-08-09 09:16:51 +00:00
Cargo.toml android/ohos: Fix wrong production cfg (#33488) 2024-09-18 07:42:52 +00:00
crash_handler.rs testing: Trigger a crash more reliably when panicking and hard fail is active (#32947) 2024-08-06 17:43:06 +00:00
lib.rs Plumb selected tracing spans into hitrace (#33324) 2024-09-10 09:03:55 +00:00
main.rs Make tracing available on all platforms, with or without perfetto (#33301) 2024-09-04 12:56:29 +00:00
panic_hook.rs testing: Trigger a crash more reliably when panicking and hard fail is active (#32947) 2024-08-06 17:43:06 +00:00
parser.rs android: Use location_bar_input_to_url instead of re-implementing (#32586) 2024-06-24 15:25:07 +00:00
prefs.rs Allow prefs to be overridden from a file and set WPT-specific prefs from file (#33163) 2024-08-24 06:47:57 +00:00
resources.rs Basic tab strip for the minibrowser (#33100) 2024-08-27 20:17:33 +00:00
test.rs clippy: fix warnings on modules outside components (#31567) 2024-03-07 23:42:39 +00:00