Skip to content

Commit d5f27c3

Browse files
committedMar 4, 2025
Bug 1951508 - Move MaybeRoundToDisplayPixels to nsIWidget. r=stransky
No behavior change, but a bit nicer. Differential Revision: https://phabricator.services.mozilla.com/D240297
1 parent 1c9610e commit d5f27c3

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
lines changed
 

‎view/nsView.cpp

+2-21
Original file line numberDiff line numberDiff line change
@@ -205,26 +205,6 @@ bool nsView::IsEffectivelyVisible() {
205205
return true;
206206
}
207207

208-
// Cocoa and GTK round widget coordinates to the nearest global "display pixel"
209-
// integer value. So we avoid fractional display pixel values by rounding to
210-
// the nearest value that won't yield a fractional display pixel.
211-
static LayoutDeviceIntRect MaybeRoundToDisplayPixels(
212-
const LayoutDeviceIntRect& aRect, TransparencyMode aTransparency,
213-
int32_t aRound) {
214-
if (aRound == 1) {
215-
return aRect;
216-
}
217-
218-
// If the widget doesn't support transparency, we prefer truncating to
219-
// ceiling, so that we don't have extra pixels not painted by our frame.
220-
auto size = aTransparency == TransparencyMode::Opaque
221-
? aRect.Size().TruncatedToMultiple(aRound)
222-
: aRect.Size().CeiledToMultiple(aRound);
223-
Unused << NS_WARN_IF(aTransparency == TransparencyMode::Opaque &&
224-
size != aRect.Size());
225-
return {aRect.TopLeft().RoundedToMultiple(aRound), size};
226-
}
227-
228208
LayoutDeviceIntRect nsView::CalcWidgetBounds(WindowType aType,
229209
TransparencyMode aTransparency) {
230210
int32_t p2a = mViewManager->AppUnitsPerDevPixel();
@@ -268,7 +248,8 @@ LayoutDeviceIntRect nsView::CalcWidgetBounds(WindowType aType,
268248
return idealBounds;
269249
}
270250
const int32_t round = widget->RoundsWidgetCoordinatesTo();
271-
return MaybeRoundToDisplayPixels(idealBounds, aTransparency, round);
251+
return nsIWidget::MaybeRoundToDisplayPixels(idealBounds, aTransparency,
252+
round);
272253
}();
273254

274255
// Compute where the top-left of our widget ended up relative to the parent

‎widget/gtk/nsWindow.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -2044,13 +2044,9 @@ void nsWindow::NativeMoveResizeWaylandPopupCallback(
20442044
GdkPoint parent = WaylandGetParentPosition();
20452045
finalRect.x += parent.x;
20462046
finalRect.y += parent.y;
2047-
auto roundTo = RoundsWidgetCoordinatesTo();
20482047
auto rect = GdkRectToDevicePixels(finalRect);
2049-
// Ensure we do the same rounding that nsView would do, see
2050-
// MaybeRoundToDisplayPixels.
2051-
auto size = !mIsTransparent ? rect.Size().TruncatedToMultiple(roundTo)
2052-
: rect.Size().CeiledToMultiple(roundTo);
2053-
return LayoutDeviceIntRect(rect.TopLeft().RoundedToMultiple(roundTo), size);
2048+
// Ensure we do the same rounding that nsView would do.
2049+
return MaybeRoundToDisplayPixels(rect);
20542050
}();
20552051

20562052
LOG(" new mBounds [%d, %d] -> [%d x %d]", newBounds.x, newBounds.y,

‎widget/nsBaseWidget.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,23 @@ void nsIWidget::RemoveAllChildren() {
444444
}
445445
}
446446

447+
LayoutDeviceIntRect nsIWidget::MaybeRoundToDisplayPixels(
448+
const LayoutDeviceIntRect& aRect, TransparencyMode aTransparency,
449+
int32_t aRound) {
450+
if (aRound == 1) {
451+
return aRect;
452+
}
453+
454+
// If the widget doesn't support transparency, we prefer truncating to
455+
// ceiling, so that we don't have extra pixels not painted by our frame.
456+
auto size = aTransparency == TransparencyMode::Opaque
457+
? aRect.Size().TruncatedToMultiple(aRound)
458+
: aRect.Size().CeiledToMultiple(aRound);
459+
Unused << NS_WARN_IF(aTransparency == TransparencyMode::Opaque &&
460+
size != aRect.Size());
461+
return {aRect.TopLeft().RoundedToMultiple(aRound), size};
462+
}
463+
447464
//-------------------------------------------------------------------------
448465
//
449466
// Accessor functions to get/set the client data

‎widget/nsIWidget.h

+15-7
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,21 @@ class nsIWidget : public nsISupports {
983983
*/
984984
virtual TransparencyMode GetTransparencyMode() = 0;
985985

986+
// Cocoa and GTK round widget coordinates to the nearest global "display
987+
// pixel" integer value; see bug 892994. So we avoid fractional display pixel
988+
// values by rounding to the nearest value that won't yield a fractional
989+
// display pixel.
990+
virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
991+
static LayoutDeviceIntRect MaybeRoundToDisplayPixels(
992+
const LayoutDeviceIntRect& aRect, TransparencyMode aTransparency,
993+
int32_t aRound);
994+
995+
LayoutDeviceIntRect MaybeRoundToDisplayPixels(
996+
const LayoutDeviceIntRect& aRect) {
997+
return MaybeRoundToDisplayPixels(aRect, GetTransparencyMode(),
998+
RoundsWidgetCoordinatesTo());
999+
}
1000+
9861001
/**
9871002
* Set the shadow style of the window.
9881003
*
@@ -1953,13 +1968,6 @@ class nsIWidget : public nsISupports {
19531968
*/
19541969
virtual bool SynchronouslyRepaintOnResize() { return true; }
19551970

1956-
/**
1957-
* Some platforms (only cocoa right now) round widget coordinates to the
1958-
* nearest even pixels (see bug 892994), this function allows us to
1959-
* determine how widget coordinates will be rounded.
1960-
*/
1961-
virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
1962-
19631971
virtual void UpdateZoomConstraints(
19641972
const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
19651973
const mozilla::Maybe<ZoomConstraints>& aConstraints) {};

0 commit comments

Comments
 (0)
Failed to load comments.