Bug 1849109 - Fix popup sizing with fractional scales. r=stransky

We probably need more fixes on top, I see sometimes we get stuck in a
move-to-rect loop (probably because our gtk call doesn't know about the
fractional scale).

But this fixes the sizing and positioning at least.

Differential Revision: https://phabricator.services.mozilla.com/D228602
This commit is contained in:
Emilio Cobos Álvarez
2024-11-12 16:19:18 +00:00
parent bd5b11bf14
commit ea9d1167bd

View File

@@ -694,27 +694,11 @@ DesktopToLayoutDeviceScale nsWindow::GetDesktopToDeviceScale() {
DesktopToLayoutDeviceScale nsWindow::GetDesktopToDeviceScaleByScreen() {
#ifdef MOZ_WAYLAND
// In Wayland there's no way to get absolute position of the window and use it
// to determine the screen factor of the monitor on which the window is
// placed. The window is notified of the current scale factor but not at this
// point, so the GdkScaleFactor can return wrong value which can lead to wrong
// popup placement. We need to use parent's window scale factor for the new
// one.
if (GdkIsWaylandDisplay()) {
nsView* view = nsView::GetViewFor(this);
if (view) {
nsView* parentView = view->GetParent();
if (parentView) {
nsIWidget* parentWidget = parentView->GetNearestWidget(nullptr);
if (parentWidget) {
return DesktopToLayoutDeviceScale(
parentWidget->RoundsWidgetCoordinatesTo());
}
NS_WARNING("Widget has no parent");
}
} else {
NS_WARNING("Cannot find widget view");
}
// In wayland there's no absolute screen position, so we need to use the
// scale factor of our top level, which is what FractionalScaleFactor does,
// luckily.
return DesktopToLayoutDeviceScale(FractionalScaleFactor());
}
#endif
return nsBaseWidget::GetDesktopToDeviceScale();